From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6821021A444 for ; Mon, 2 Jun 2025 15:18:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748877542; cv=none; b=mpiewgdP3r7HAl8DMpf52Ri0LNTDEgrV31tExrJHC9LH2HAZV9QTd0EqtgyA009ukqAU1EXifguMIwvgYobnpGXEMcIvDOrVq5q4e8YbH2CscGVto7TTmpj7BviqTMXsQFbfOxdO4gYI3JWTlbjEKwsuK+2MKacMGzLcK8oUjQ0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748877542; c=relaxed/simple; bh=oFAT+NNKGnh5VXgaLf8krwrz5XSrHjhFetyALYSIt7M=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=AYG6eA7/F8K09zsZ76+Deqrfm2mHMjKxWkDztN/Fv1paZi8Ib1nNcJjyCVfAvzZmhR8ZK6MtN5h44KFAJdxXOuMaRymz88/X9AEBHn0bbZTi2sT0qBfJpohciJ3P/iVlK6wMiD7aa1JbAA5BEVWf3/C5MRJ1mKY1xJyRERK+YTc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=hU+rxaRj; arc=none smtp.client-ip=209.85.128.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="hU+rxaRj" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-450dd065828so19343705e9.2 for ; Mon, 02 Jun 2025 08:18:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1748877538; x=1749482338; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=IUg1jDrh7o13xIeD5Z16HH35vSn20OCOm1MqSRrAi94=; b=hU+rxaRjiBH8xcwMXgSB+l4qIkG1HkLaVP6j+LFVWVqwVwDZBBJGvyPJgzLWDdv7mE VrAnJEvohap10Ncq54pnb/oVQmjzbuqFRO3aoreqOC0r4MQrR3VjzCKon/UgNpULpAOG HTfZp92bSHfXQOTPt+EuMhC0MG11rC3ACkM9a3krAIBclFU3erTondo/nXTxLrIjBRBf 2W04mbOeTjK2qf6ri32Q5WbJK8cm002VsGG2b4UM7yP9UxvfAs1D29Q1Z+pfoxBplUOg Nm5W/OKUxyUseVIvnVytekk+/5SEbOL2BFjgipzscEpZaaErP/wYcf4Rjy5gZnMH93MZ Owlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748877538; x=1749482338; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=IUg1jDrh7o13xIeD5Z16HH35vSn20OCOm1MqSRrAi94=; b=Z8NllKYWE6OAYbf27stQynWLZuf1KV8EckdwvWH4LCHWWTmqSRXT4RPTaYEhMIfgQR 0ciXXGSdlPYDoQWBCdeymzgovT+HKTRoDDD2tCwyFwATq0L5rlSaauuRLdLMZPoCSlUR 8qQebbG719PC7i9GMRg4qgt2rw/Xvlb0/OQS5pYWWZLuSKoQtUkRLor7tu5bPDbXDevF l7rnzt5LGcqvJIRwHALMep57KS5IKHNOT84a8NxrD0z0CkMFy22h9ldRfox7NLnX52Dv c94TRIvNDqHYAJdP0I05dYFxZRquiBcKsgrFfzCnpaHjWk4EwokLIVczhbUjIpB0OPb7 fd9w== X-Forwarded-Encrypted: i=1; AJvYcCUi0zfR8ofivtAVsMZumzh++GfkBoWwG2VnP1sT3NKkJzrLZpaTAiLGbgtiiCUoIOH3UkxEc2Wxi5pVrn4=@vger.kernel.org X-Gm-Message-State: AOJu0Yz/36JRZEgZPIdEoUiGQ3glM1DfbmQHkEIkzAMHhdVaRaYL76wQ hN1WZBZv3MgG8+27guVO4Go4piR/0LDH+m7Wj6G3Z1A2HIl4eBU/GkcXPOZ8RMPJttU= X-Gm-Gg: ASbGnct4+9+gHmv2nvUTlpDFT7NU9M8wIuSyCjXTQn6eUgE2pQwy9Efpm65l3G4XfiV nIM2SkEYOqwEe1d1bkWPpTR+Pi1jQFjOUQnBYv1W8xoBy/q8U2gDV4hft+YtdlRziksiBhA/pc/ xwc5ZtMs6JvTigLIF/Y7nvaJa5/9gx4gEb8hUWF/l/BrXHtrcZ5fHKPnidHkcbDYhKKAiW2XJ2J avDHLMKYlUpKx2xbBVcJfqda5JQnEj/uwLI/pLhBK5YxhNg1siC5mFybinze1zIPcjgyjEMCXPz 41UZgWD77ezBRoaLRLpTPYUqWdxOyB3HirS9+zMujGCR92rieQH7SFkFESwIy79XHIizSj3hn1Z Vsm2Ecis3CllC X-Google-Smtp-Source: AGHT+IGd9hG5YHfH76nGmto9bsoX9DJOOYs0jiBYnyQonK2UIDx2uNqiKNlTaeCJzRAT0d46DtaI3w== X-Received: by 2002:a05:600c:4fce:b0:450:d367:c385 with SMTP id 5b1f17b1804b1-450d886f21bmr129966005e9.16.1748877537630; Mon, 02 Jun 2025 08:18:57 -0700 (PDT) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a4efe74111sm15619844f8f.56.2025.06.02.08.18.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Jun 2025 08:18:57 -0700 (PDT) From: Daniel Lezcano To: daniel.lezcano@linaro.org, tglx@linutronix.de Cc: Jim Cromie , Maxime Coquelin , Alexandre Torgue , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Thierry Reding , Jonathan Hunter , "Peter Zijlstra (Intel)" , Marco Elver , Nam Cao , linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-tegra@vger.kernel.org, John Stulz , Will McVicker , Peter Griffin , Saravan Kanna Subject: [PATCH v1 0/7] Setting the scene to convert the timers into modules Date: Mon, 2 Jun 2025 17:18:44 +0200 Message-ID: <20250602151853.1942521-1-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The timer drivers are all compiled-in. The initial pre-requisite is to have them available as soon as possible in the boot process. While this statement made sense a long time ago, the platforms have today multiple timers for different purposes along with architected timers which are initialized very early. For example, a timer can be used as a backup timer when the local timers are belonging to a power domain which is shutted down, or used a watchdog timer when the counter are shared, or also as a pulse width modulation counter. Another use case is the platform user may want to switch to a timer different from the architected timers because they have interesting characteristics in the context of a dedicated platform (eg. automotive). In some existing drivers, there is already the code to load and unload a timer driver even if the Kconfig does not allow that. It means, the need is there but partially upstream. There were multiple attempts to configure the timer drivers into modules but it faced the fact that we were unsure if it is correctly supported by the time framework. After investigating deeper in the core code it appears we have everything set for the modularization of the timer drivers. - When a clocksource is registered with a better rating, the current clocksource is swapped with the new one. The userspace allows to change the current clocksource via sysfs - A clocksource can be unregistered - When a clockevent is registered with a better rating, it becomes the active one - A clockevent can not be unregistered A timer driver can be loaded later because of all the supported above. However unloading is unsupported because a clockevent can not be unregistered and that will lead to a crash. But if the timer driver has the module owner set, the core framework will handle the refcount correctly and will prevent to unload the module if a clockevent is registered. All the refcounting is working in different use cases. - A clocksource is the current clocksource, the refcount is held - A current clocksource is switched to another one, the refcount is released - A broadcast timer is registered, the refcount is held - A local timer is registered, the refcount is held Consequently, it is possible to unload a module which is only used as a clocksource. As soon as a clockevent is registered, the refcount is held and can not be released thus preventing the module to be unloaded. That mechanism ensure it is safe to convert the different timer drivers into modules. This series adds the module owner in the different driver which are initialized with the module_platform_driver() function and export the symbols for the sched_clock_register() function. Cc: Jim Cromie Cc: Daniel Lezcano Cc: Thomas Gleixner Cc: Maxime Coquelin Cc: Alexandre Torgue Cc: Chen-Yu Tsai Cc: Jernej Skrabec Cc: Samuel Holland Cc: Thierry Reding Cc: Jonathan Hunter Cc: "Peter Zijlstra (Intel)" Cc: Marco Elver Cc: Nam Cao Cc: linux-kernel@vger.kernel.org Cc: linux-stm32@st-md-mailman.stormreply.com Cc: linux-arm-kernel@lists.infradead.org Cc: linux-sunxi@lists.linux.dev Cc: linux-tegra@vger.kernel.org Cc: John Stulz Cc: Will McVicker Cc: Peter Griffin Cc: Saravan Kanna Daniel Lezcano (7): clocksource/drivers/scx200: Add module owner clocksource/drivers/stm32-lp: Add module owner clocksource/drivers/sun5i: Add module owner clocksource/drivers/tegra186: Add module owner clocksource/drivers/stm: Add module owner clocksource/drivers/cs5535: Add module owner time: Export symbol for sched_clock register function drivers/clocksource/scx200_hrt.c | 1 + drivers/clocksource/timer-cs5535.c | 1 + drivers/clocksource/timer-nxp-stm.c | 2 ++ drivers/clocksource/timer-stm32-lp.c | 1 + drivers/clocksource/timer-sun5i.c | 2 ++ drivers/clocksource/timer-tegra186.c | 3 +++ kernel/time/sched_clock.c | 4 ++-- 7 files changed, 12 insertions(+), 2 deletions(-) -- 2.43.0