Skip to contentSkip to conversation

Setting the scene to convert the timers into modules

PATCH Applied Daniel Lezcano 6 participants 34 messages Jun 2, 2025 – Aug 13, 2025

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover Setting the scene to convert the timers into modules

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 <[email protected]>
Cc Daniel Lezcano <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Maxime Coquelin <[email protected]>
Cc Alexandre Torgue <[email protected]>
Cc Chen-Yu Tsai <[email protected]>
Cc Jernej Skrabec <[email protected]>
Cc Samuel Holland <[email protected]>
Cc Thierry Reding <[email protected]>
Cc Jonathan Hunter <[email protected]>
Cc "Peter Zijlstra (Intel)" <[email protected]>
Cc Marco Elver <[email protected]>
Cc Nam Cao <[email protected]>
Cc John Stulz <[email protected]>
Cc Will McVicker <[email protected]>
Cc Peter Griffin <[email protected]>
Cc Saravan Kanna <[email protected]>

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(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/7 clocksource/drivers/scx200: Add module owner

The conversion to modules requires a correct handling of the module refcount in order to prevent to unload it if it is in use. That is especially true with the clockevents where there is no function to unregister them.

The core time framework correctly handles the module refcount with the different clocksource and clockevents if the module owner is set.

Add the module owner to make sure the core framework will prevent stupid things happening when the driver will be converted into a module.

---
 drivers/clocksource/scx200_hrt.c | 1 +
 1 file changed, 1 insertion(+)
drivers/clocksource/scx200_hrt.c +1 -0
index c3536fffbe9a..5a99801a1657 100644
@@ -52,6 +52,7 @@ static struct clocksource cs_hrt = {
 	.mask		= CLOCKSOURCE_MASK(32),
 	.flags		= CLOCK_SOURCE_IS_CONTINUOUS,
 	/* mult, shift are set based on mhz27 flag */
+	.owner		= THIS_MODULE,
 };
 
 static int __init init_hrt_clocksource(void)
Signature · 1 line
2.43.0
Reviewed-by on v1 1/7
#2 lore raw

Re: [PATCH v1 1/7] clocksource/drivers/scx200: Add module owner

Quoted 5 lines · Daniel Lezcano

The conversion to modules requires a correct handling of the module refcount in order to prevent to unload it if it is in use. That is especially true with the clockevents where there is no function to unregister them.

Quoted 8 lines

The core time framework correctly handles the module refcount with the different clocksource and clockevents if the module owner is set.

Add the module owner to make sure the core framework will prevent stupid things happening when the driver will be converted into a module.

Thanks,
Will

Quoted 19 lines
---
 drivers/clocksource/scx200_hrt.c | 1 +
 1 file changed, 1 insertion(+)
drivers/clocksource/scx200_hrt.c +1 -0
index c3536fffbe9a..5a99801a1657 100644
@@ -52,6 +52,7 @@ static struct clocksource cs_hrt = {
 	.mask		= CLOCKSOURCE_MASK(32),
 	.flags		= CLOCK_SOURCE_IS_CONTINUOUS,
 	/* mult, shift are set based on mhz27 flag */
+	.owner		= THIS_MODULE,
 };
 
 static int __init init_hrt_clocksource(void)
Signature · 1 line
2.43.0
merge bot Applied
#3 lore raw

[tip: timers/clocksource] clocksource/drivers/scx200: Add module owner

In reply to Daniel Lezcano
The following commit has been merged into the timers/clocksource branch of tip:

The following commit has been merged into the timers/clocksource branch of tip:

Commit-ID:     3fcc11a56f762b01063a9013613afc09a785778b
Gitweb:        https://git.kernel.org/tip/3fcc11a56f762b01063a9013613afc09a785778b
Author:        Daniel Lezcano <[email protected]>
AuthorDate:    Mon, 02 Jun 2025 17:18:45 +02:00
Committer:     Daniel Lezcano <[email protected]>
CommitterDate: Thu, 10 Jul 2025 11:28:29 +02:00

clocksource/drivers/scx200: Add module owner

The conversion to modules requires a correct handling of the module refcount in order to prevent to unload it if it is in use. That is especially true with the clockevents where there is no function to unregister them.

The core time framework correctly handles the module refcount with the different clocksource and clockevents if the module owner is set.

Add the module owner to make sure the core framework will prevent stupid things happening when the driver will be converted into a module.

---
 drivers/clocksource/scx200_hrt.c | 1 +
 1 file changed, 1 insertion(+)
drivers/clocksource/scx200_hrt.c +1 -0
index c3536ff..5a99801 100644
@@ -52,6 +52,7 @@ static struct clocksource cs_hrt = {
 	.mask		= CLOCKSOURCE_MASK(32),
 	.flags		= CLOCK_SOURCE_IS_CONTINUOUS,
 	/* mult, shift are set based on mhz27 flag */
+	.owner		= THIS_MODULE,
 };
 
 static int __init init_hrt_clocksource(void)
merge bot Applied
#4 lore raw

[tip: timers/clocksource] clocksource/drivers/scx200: Add module owner

In reply to Daniel Lezcano
The following commit has been merged into the timers/clocksource branch of tip:

The following commit has been merged into the timers/clocksource branch of tip:

Commit-ID:     32095e3f3c0affe59a1a465ed19ae9a24f5fb44a
Gitweb:        https://git.kernel.org/tip/32095e3f3c0affe59a1a465ed19ae9a24f5fb44a
Author:        Daniel Lezcano <[email protected]>
AuthorDate:    Mon, 02 Jun 2025 17:18:45 +02:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Fri, 25 Jul 2025 11:42:32 +02:00

clocksource/drivers/scx200: Add module owner

The conversion to modules requires a correct handling of the module refcount in order to prevent to unload it if it is in use. That is especially true with clockevents where there is no function to unregister them.

The core time framework correctly handles the module refcount with the different clocksource and clockevents if the module owner is set.

Add the module owner to make sure the core framework will prevent stupid things happening when the driver will be converted into a module.

---
 drivers/clocksource/scx200_hrt.c | 1 +
 1 file changed, 1 insertion(+)
drivers/clocksource/scx200_hrt.c +1 -0
index c3536ff..5a99801 100644
@@ -52,6 +52,7 @@ static struct clocksource cs_hrt = {
 	.mask		= CLOCKSOURCE_MASK(32),
 	.flags		= CLOCK_SOURCE_IS_CONTINUOUS,
 	/* mult, shift are set based on mhz27 flag */
+	.owner		= THIS_MODULE,
 };
 
 static int __init init_hrt_clocksource(void)
#5 lore raw

PATCH 2/7 clocksource/drivers/stm32-lp: Add module owner

In reply to Daniel Lezcano

The conversion to modules requires a correct handling of the module refcount in order to prevent to unload it if it is in use. That is especially true with the clockevents where there is no function to unregister them.

The core time framework correctly handles the module refcount with the different clocksource and clockevents if the module owner is set.

Add the module owner to make sure the core framework will prevent stupid things happening when the driver will be converted into a module.

---
 drivers/clocksource/timer-stm32-lp.c | 1 +
 1 file changed, 1 insertion(+)
drivers/clocksource/timer-stm32-lp.c +1 -0
index 928da2f6de69..cf1423ca00d0 100644
@@ -159,6 +159,7 @@ static void stm32_clkevent_lp_init(struct stm32_lp_private *priv,
 	priv->clkevt.rating = STM32_LP_RATING;
 	priv->clkevt.suspend = stm32_clkevent_lp_suspend;
 	priv->clkevt.resume = stm32_clkevent_lp_resume;
+	priv->clkevt.owner = THIS_MODULE;
 
 	clockevents_config_and_register(&priv->clkevt, rate, 0x1,
 					STM32_LPTIM_MAX_ARR);
Signature · 1 line
2.43.0
Reviewed-by on v1 2/7
#6 lore raw

Re: [PATCH v1 2/7] clocksource/drivers/stm32-lp: Add module owner

Quoted 5 lines · Daniel Lezcano

The conversion to modules requires a correct handling of the module refcount in order to prevent to unload it if it is in use. That is especially true with the clockevents where there is no function to unregister them.

Quoted 8 lines

The core time framework correctly handles the module refcount with the different clocksource and clockevents if the module owner is set.

Add the module owner to make sure the core framework will prevent stupid things happening when the driver will be converted into a module.

Thanks,
Will

Quoted 19 lines
---
 drivers/clocksource/timer-stm32-lp.c | 1 +
 1 file changed, 1 insertion(+)
drivers/clocksource/timer-stm32-lp.c +1 -0
index 928da2f6de69..cf1423ca00d0 100644
@@ -159,6 +159,7 @@ static void stm32_clkevent_lp_init(struct stm32_lp_private *priv,
 	priv->clkevt.rating = STM32_LP_RATING;
 	priv->clkevt.suspend = stm32_clkevent_lp_suspend;
 	priv->clkevt.resume = stm32_clkevent_lp_resume;
+	priv->clkevt.owner = THIS_MODULE;
 
 	clockevents_config_and_register(&priv->clkevt, rate, 0x1,
 					STM32_LPTIM_MAX_ARR);
Signature · 1 line
2.43.0
merge bot Applied
#7 lore raw

[tip: timers/clocksource] clocksource/drivers/stm32-lp: Add module owner

In reply to Daniel Lezcano
The following commit has been merged into the timers/clocksource branch of tip:

The following commit has been merged into the timers/clocksource branch of tip:

Commit-ID:     0625a7e5e34e952352bc81a305e5308c0a9cafcd
Gitweb:        https://git.kernel.org/tip/0625a7e5e34e952352bc81a305e5308c0a9cafcd
Author:        Daniel Lezcano <[email protected]>
AuthorDate:    Mon, 02 Jun 2025 17:18:46 +02:00
Committer:     Daniel Lezcano <[email protected]>
CommitterDate: Thu, 10 Jul 2025 11:28:29 +02:00

clocksource/drivers/stm32-lp: Add module owner

The conversion to modules requires a correct handling of the module refcount in order to prevent to unload it if it is in use. That is especially true with the clockevents where there is no function to unregister them.

The core time framework correctly handles the module refcount with the different clocksource and clockevents if the module owner is set.

Add the module owner to make sure the core framework will prevent stupid things happening when the driver will be converted into a module.

---
 drivers/clocksource/timer-stm32-lp.c | 1 +
 1 file changed, 1 insertion(+)
drivers/clocksource/timer-stm32-lp.c +1 -0
index 6e7944f..c2a699f 100644
@@ -211,6 +211,7 @@ static void stm32_clkevent_lp_init(struct stm32_lp_private *priv,
 	priv->clkevt.rating = STM32_LP_RATING;
 	priv->clkevt.suspend = stm32_clkevent_lp_suspend;
 	priv->clkevt.resume = stm32_clkevent_lp_resume;
+	priv->clkevt.owner = THIS_MODULE;
 
 	clockevents_config_and_register(&priv->clkevt, rate, 0x1,
 					STM32_LPTIM_MAX_ARR);
merge bot Applied
#8 lore raw

[tip: timers/clocksource] clocksource/drivers/stm32-lp: Add module owner

In reply to Daniel Lezcano
The following commit has been merged into the timers/clocksource branch of tip:

The following commit has been merged into the timers/clocksource branch of tip:

Commit-ID:     d3362af84d0c3aa02d3ebd0600c3a2640b2bd06a
Gitweb:        https://git.kernel.org/tip/d3362af84d0c3aa02d3ebd0600c3a2640b2bd06a
Author:        Daniel Lezcano <[email protected]>
AuthorDate:    Mon, 02 Jun 2025 17:18:46 +02:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Fri, 25 Jul 2025 11:43:10 +02:00

clocksource/drivers/stm32-lp: Add module owner

The conversion to modules requires a correct handling of the module refcount in order to prevent to unload it if it is in use. That is especially true with clockevents where there is no function to unregister them.

The core time framework correctly handles the module refcount with the different clocksource and clockevents if the module owner is set.

Add the module owner to make sure the core framework will prevent stupid things happening when the driver will be converted into a module.

---
 drivers/clocksource/timer-stm32-lp.c | 1 +
 1 file changed, 1 insertion(+)
drivers/clocksource/timer-stm32-lp.c +1 -0
index 6e7944f..c2a699f 100644
@@ -211,6 +211,7 @@ static void stm32_clkevent_lp_init(struct stm32_lp_private *priv,
 	priv->clkevt.rating = STM32_LP_RATING;
 	priv->clkevt.suspend = stm32_clkevent_lp_suspend;
 	priv->clkevt.resume = stm32_clkevent_lp_resume;
+	priv->clkevt.owner = THIS_MODULE;
 
 	clockevents_config_and_register(&priv->clkevt, rate, 0x1,
 					STM32_LPTIM_MAX_ARR);
#9 lore raw

PATCH 3/7 clocksource/drivers/sun5i: Add module owner

In reply to Daniel Lezcano

The conversion to modules requires a correct handling of the module refcount in order to prevent to unload it if it is in use. That is especially true with the clockevents where there is no function to unregister them.

The core time framework correctly handles the module refcount with the different clocksource and clockevents if the module owner is set.

Add the module owner to make sure the core framework will prevent stupid things happening when the driver will be converted into a module.

---
 drivers/clocksource/timer-sun5i.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/clocksource/timer-sun5i.c +2 -0
index 6b48a9006444..f827d3f98f60 100644
@@ -185,6 +185,7 @@ static int sun5i_setup_clocksource(struct platform_device *pdev,
 	cs->clksrc.read = sun5i_clksrc_read;
 	cs->clksrc.mask = CLOCKSOURCE_MASK(32);
 	cs->clksrc.flags = CLOCK_SOURCE_IS_CONTINUOUS;
+	cs->clksrc.owner = THIS_MODULE;
 
 	ret = clocksource_register_hz(&cs->clksrc, rate);
 	if (ret) {
@@ -214,6 +215,7 @@ static int sun5i_setup_clockevent(struct platform_device *pdev,
 	ce->clkevt.rating = 340;
 	ce->clkevt.irq = irq;
 	ce->clkevt.cpumask = cpu_possible_mask;
+	ce->clkevt.owner = THIS_MODULE;
 
 	/* Enable timer0 interrupt */
 	val = readl(base + TIMER_IRQ_EN_REG);
Signature · 1 line
2.43.0
Acked-by on v1 3/7
#10 lore raw

Re: [PATCH v1 3/7] clocksource/drivers/sun5i: Add module owner

Quoted 6 lines · Daniel Lezcano

The conversion to modules requires a correct handling of the module refcount in order to prevent to unload it if it is in use. That is especially true with the clockevents where there is no function to unregister them.

Quoted 8 lines

The core time framework correctly handles the module refcount with the different clocksource and clockevents if the module owner is set.

Add the module owner to make sure the core framework will prevent stupid things happening when the driver will be converted into a module.

Reviewed-by on v1 3/7
#11 lore raw

Re: [PATCH v1 3/7] clocksource/drivers/sun5i: Add module owner

In reply to Daniel Lezcano
Quoted 5 lines · Daniel Lezcano

The conversion to modules requires a correct handling of the module refcount in order to prevent to unload it if it is in use. That is especially true with the clockevents where there is no function to unregister them.

Quoted 8 lines

The core time framework correctly handles the module refcount with the different clocksource and clockevents if the module owner is set.

Add the module owner to make sure the core framework will prevent stupid things happening when the driver will be converted into a module.

Thanks,
Will

Quoted 27 lines
---
 drivers/clocksource/timer-sun5i.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/clocksource/timer-sun5i.c +2 -0
index 6b48a9006444..f827d3f98f60 100644
@@ -185,6 +185,7 @@ static int sun5i_setup_clocksource(struct platform_device *pdev,
 	cs->clksrc.read = sun5i_clksrc_read;
 	cs->clksrc.mask = CLOCKSOURCE_MASK(32);
 	cs->clksrc.flags = CLOCK_SOURCE_IS_CONTINUOUS;
+	cs->clksrc.owner = THIS_MODULE;
 
 	ret = clocksource_register_hz(&cs->clksrc, rate);
 	if (ret) {
@@ -214,6 +215,7 @@ static int sun5i_setup_clockevent(struct platform_device *pdev,
 	ce->clkevt.rating = 340;
 	ce->clkevt.irq = irq;
 	ce->clkevt.cpumask = cpu_possible_mask;
+	ce->clkevt.owner = THIS_MODULE;
 
 	/* Enable timer0 interrupt */
 	val = readl(base + TIMER_IRQ_EN_REG);
Signature · 1 line
2.43.0
merge bot Applied
#12 lore raw

[tip: timers/clocksource] clocksource/drivers/sun5i: Add module owner

In reply to Daniel Lezcano
The following commit has been merged into the timers/clocksource branch of tip:

The following commit has been merged into the timers/clocksource branch of tip:

Commit-ID:     562eb6fe7f32dd3e032c057c6593124b7afbff19
Gitweb:        https://git.kernel.org/tip/562eb6fe7f32dd3e032c057c6593124b7afbff19
Author:        Daniel Lezcano <[email protected]>
AuthorDate:    Mon, 02 Jun 2025 17:18:47 +02:00
Committer:     Daniel Lezcano <[email protected]>
CommitterDate: Thu, 10 Jul 2025 11:28:29 +02:00

clocksource/drivers/sun5i: Add module owner

The conversion to modules requires a correct handling of the module refcount in order to prevent to unload it if it is in use. That is especially true with the clockevents where there is no function to unregister them.

The core time framework correctly handles the module refcount with the different clocksource and clockevents if the module owner is set.

Add the module owner to make sure the core framework will prevent stupid things happening when the driver will be converted into a module.

---
 drivers/clocksource/timer-sun5i.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/clocksource/timer-sun5i.c +2 -0
index 6b48a90..f827d3f 100644
@@ -185,6 +185,7 @@ static int sun5i_setup_clocksource(struct platform_device *pdev,
 	cs->clksrc.read = sun5i_clksrc_read;
 	cs->clksrc.mask = CLOCKSOURCE_MASK(32);
 	cs->clksrc.flags = CLOCK_SOURCE_IS_CONTINUOUS;
+	cs->clksrc.owner = THIS_MODULE;
 
 	ret = clocksource_register_hz(&cs->clksrc, rate);
 	if (ret) {
@@ -214,6 +215,7 @@ static int sun5i_setup_clockevent(struct platform_device *pdev,
 	ce->clkevt.rating = 340;
 	ce->clkevt.irq = irq;
 	ce->clkevt.cpumask = cpu_possible_mask;
+	ce->clkevt.owner = THIS_MODULE;
 
 	/* Enable timer0 interrupt */
 	val = readl(base + TIMER_IRQ_EN_REG);
merge bot Applied
#13 lore raw

[tip: timers/clocksource] clocksource/drivers/sun5i: Add module owner

In reply to Daniel Lezcano
The following commit has been merged into the timers/clocksource branch of tip:

The following commit has been merged into the timers/clocksource branch of tip:

Commit-ID:     d89048fedbe7a13056497a2bd93e28981e17c6fe
Gitweb:        https://git.kernel.org/tip/d89048fedbe7a13056497a2bd93e28981e17c6fe
Author:        Daniel Lezcano <[email protected]>
AuthorDate:    Mon, 02 Jun 2025 17:18:47 +02:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Fri, 25 Jul 2025 11:43:18 +02:00

clocksource/drivers/sun5i: Add module owner

The conversion to modules requires a correct handling of the module refcount in order to prevent to unload it if it is in use. That is especially true with clockevents where there is no function to unregister them.

The core time framework correctly handles the module refcount with the different clocksource and clockevents if the module owner is set.

Add the module owner to make sure the core framework will prevent stupid things happening when the driver will be converted into a module.

---
 drivers/clocksource/timer-sun5i.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/clocksource/timer-sun5i.c +2 -0
index 6b48a90..f827d3f 100644
@@ -185,6 +185,7 @@ static int sun5i_setup_clocksource(struct platform_device *pdev,
 	cs->clksrc.read = sun5i_clksrc_read;
 	cs->clksrc.mask = CLOCKSOURCE_MASK(32);
 	cs->clksrc.flags = CLOCK_SOURCE_IS_CONTINUOUS;
+	cs->clksrc.owner = THIS_MODULE;
 
 	ret = clocksource_register_hz(&cs->clksrc, rate);
 	if (ret) {
@@ -214,6 +215,7 @@ static int sun5i_setup_clockevent(struct platform_device *pdev,
 	ce->clkevt.rating = 340;
 	ce->clkevt.irq = irq;
 	ce->clkevt.cpumask = cpu_possible_mask;
+	ce->clkevt.owner = THIS_MODULE;
 
 	/* Enable timer0 interrupt */
 	val = readl(base + TIMER_IRQ_EN_REG);
#14 lore raw

PATCH 4/7 clocksource/drivers/tegra186: Add module owner

In reply to Daniel Lezcano

The conversion to modules requires a correct handling of the module refcount in order to prevent to unload it if it is in use. That is especially true with the clockevents where there is no function to unregister them.

The core time framework correctly handles the module refcount with the different clocksource and clockevents if the module owner is set.

Add the module owner to make sure the core framework will prevent stupid things happening when the driver will be converted into a module.

---
 drivers/clocksource/timer-tegra186.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/clocksource/timer-tegra186.c +3 -0
index e5394f98a02e..56a5342bcf78 100644
@@ -373,6 +373,7 @@ static int tegra186_timer_tsc_init(struct tegra186_timer *tegra)
 	tegra->tsc.read = tegra186_timer_tsc_read;
 	tegra->tsc.mask = CLOCKSOURCE_MASK(56);
 	tegra->tsc.flags = CLOCK_SOURCE_IS_CONTINUOUS;
+	tegra->tsc.owner = THIS_MODULE;
 
 	return clocksource_register_hz(&tegra->tsc, 31250000);
 }
@@ -392,6 +393,7 @@ static int tegra186_timer_osc_init(struct tegra186_timer *tegra)
 	tegra->osc.read = tegra186_timer_osc_read;
 	tegra->osc.mask = CLOCKSOURCE_MASK(32);
 	tegra->osc.flags = CLOCK_SOURCE_IS_CONTINUOUS;
+	tegra->osc.owner = THIS_MODULE;
 
 	return clocksource_register_hz(&tegra->osc, 38400000);
 }
@@ -411,6 +413,7 @@ static int tegra186_timer_usec_init(struct tegra186_timer *tegra)
 	tegra->usec.read = tegra186_timer_usec_read;
 	tegra->usec.mask = CLOCKSOURCE_MASK(32);
 	tegra->usec.flags = CLOCK_SOURCE_IS_CONTINUOUS;
+	tegra->usec.owner = THIS_MODULE;
 
 	return clocksource_register_hz(&tegra->usec, USEC_PER_SEC);
 }
Signature · 1 line
2.43.0
Reviewed-by on v1 4/7
#15 lore raw

Re: [PATCH v1 4/7] clocksource/drivers/tegra186: Add module owner

Quoted 5 lines · Daniel Lezcano

The conversion to modules requires a correct handling of the module refcount in order to prevent to unload it if it is in use. That is especially true with the clockevents where there is no function to unregister them.

Quoted 8 lines

The core time framework correctly handles the module refcount with the different clocksource and clockevents if the module owner is set.

Add the module owner to make sure the core framework will prevent stupid things happening when the driver will be converted into a module.

Thanks,
Will

Quoted 35 lines
---
 drivers/clocksource/timer-tegra186.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/clocksource/timer-tegra186.c +3 -0
index e5394f98a02e..56a5342bcf78 100644
@@ -373,6 +373,7 @@ static int tegra186_timer_tsc_init(struct tegra186_timer *tegra)
 	tegra->tsc.read = tegra186_timer_tsc_read;
 	tegra->tsc.mask = CLOCKSOURCE_MASK(56);
 	tegra->tsc.flags = CLOCK_SOURCE_IS_CONTINUOUS;
+	tegra->tsc.owner = THIS_MODULE;
 
 	return clocksource_register_hz(&tegra->tsc, 31250000);
 }
@@ -392,6 +393,7 @@ static int tegra186_timer_osc_init(struct tegra186_timer *tegra)
 	tegra->osc.read = tegra186_timer_osc_read;
 	tegra->osc.mask = CLOCKSOURCE_MASK(32);
 	tegra->osc.flags = CLOCK_SOURCE_IS_CONTINUOUS;
+	tegra->osc.owner = THIS_MODULE;
 
 	return clocksource_register_hz(&tegra->osc, 38400000);
 }
@@ -411,6 +413,7 @@ static int tegra186_timer_usec_init(struct tegra186_timer *tegra)
 	tegra->usec.read = tegra186_timer_usec_read;
 	tegra->usec.mask = CLOCKSOURCE_MASK(32);
 	tegra->usec.flags = CLOCK_SOURCE_IS_CONTINUOUS;
+	tegra->usec.owner = THIS_MODULE;
 
 	return clocksource_register_hz(&tegra->usec, USEC_PER_SEC);
 }
Signature · 1 line
2.43.0
merge bot Applied
#16 lore raw

[tip: timers/clocksource] clocksource/drivers/tegra186: Add module owner

In reply to Daniel Lezcano
The following commit has been merged into the timers/clocksource branch of tip:

The following commit has been merged into the timers/clocksource branch of tip:

Commit-ID:     dc8b1ad53317512f840fb81e4054db560950bc80
Gitweb:        https://git.kernel.org/tip/dc8b1ad53317512f840fb81e4054db560950bc80
Author:        Daniel Lezcano <[email protected]>
AuthorDate:    Mon, 02 Jun 2025 17:18:48 +02:00
Committer:     Daniel Lezcano <[email protected]>
CommitterDate: Thu, 10 Jul 2025 11:28:29 +02:00

clocksource/drivers/tegra186: Add module owner

The conversion to modules requires a correct handling of the module refcount in order to prevent to unload it if it is in use. That is especially true with the clockevents where there is no function to unregister them.

The core time framework correctly handles the module refcount with the different clocksource and clockevents if the module owner is set.

Add the module owner to make sure the core framework will prevent stupid things happening when the driver will be converted into a module.

---
 drivers/clocksource/timer-tegra186.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/clocksource/timer-tegra186.c +3 -0
index e5394f9..56a5342 100644
@@ -373,6 +373,7 @@ static int tegra186_timer_tsc_init(struct tegra186_timer *tegra)
 	tegra->tsc.read = tegra186_timer_tsc_read;
 	tegra->tsc.mask = CLOCKSOURCE_MASK(56);
 	tegra->tsc.flags = CLOCK_SOURCE_IS_CONTINUOUS;
+	tegra->tsc.owner = THIS_MODULE;
 
 	return clocksource_register_hz(&tegra->tsc, 31250000);
 }
@@ -392,6 +393,7 @@ static int tegra186_timer_osc_init(struct tegra186_timer *tegra)
 	tegra->osc.read = tegra186_timer_osc_read;
 	tegra->osc.mask = CLOCKSOURCE_MASK(32);
 	tegra->osc.flags = CLOCK_SOURCE_IS_CONTINUOUS;
+	tegra->osc.owner = THIS_MODULE;
 
 	return clocksource_register_hz(&tegra->osc, 38400000);
 }
@@ -411,6 +413,7 @@ static int tegra186_timer_usec_init(struct tegra186_timer *tegra)
 	tegra->usec.read = tegra186_timer_usec_read;
 	tegra->usec.mask = CLOCKSOURCE_MASK(32);
 	tegra->usec.flags = CLOCK_SOURCE_IS_CONTINUOUS;
+	tegra->usec.owner = THIS_MODULE;
 
 	return clocksource_register_hz(&tegra->usec, USEC_PER_SEC);
 }
merge bot Applied
#17 lore raw

[tip: timers/clocksource] clocksource/drivers/tegra186: Add module owner

In reply to Daniel Lezcano
The following commit has been merged into the timers/clocksource branch of tip:

The following commit has been merged into the timers/clocksource branch of tip:

Commit-ID:     6d92fe9b423c19e6ec6dcbf71528a4bbbb7bf814
Gitweb:        https://git.kernel.org/tip/6d92fe9b423c19e6ec6dcbf71528a4bbbb7bf814
Author:        Daniel Lezcano <[email protected]>
AuthorDate:    Mon, 02 Jun 2025 17:18:48 +02:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Fri, 25 Jul 2025 11:43:25 +02:00

clocksource/drivers/tegra186: Add module owner

The conversion to modules requires a correct handling of the module refcount in order to prevent to unload it if it is in use. That is especially true with clockevents where there is no function to unregister them.

The core time framework correctly handles the module refcount with the different clocksource and clockevents if the module owner is set.

Add the module owner to make sure the core framework will prevent stupid things happening when the driver will be converted into a module.

---
 drivers/clocksource/timer-tegra186.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/clocksource/timer-tegra186.c +3 -0
index e5394f9..56a5342 100644
@@ -373,6 +373,7 @@ static int tegra186_timer_tsc_init(struct tegra186_timer *tegra)
 	tegra->tsc.read = tegra186_timer_tsc_read;
 	tegra->tsc.mask = CLOCKSOURCE_MASK(56);
 	tegra->tsc.flags = CLOCK_SOURCE_IS_CONTINUOUS;
+	tegra->tsc.owner = THIS_MODULE;
 
 	return clocksource_register_hz(&tegra->tsc, 31250000);
 }
@@ -392,6 +393,7 @@ static int tegra186_timer_osc_init(struct tegra186_timer *tegra)
 	tegra->osc.read = tegra186_timer_osc_read;
 	tegra->osc.mask = CLOCKSOURCE_MASK(32);
 	tegra->osc.flags = CLOCK_SOURCE_IS_CONTINUOUS;
+	tegra->osc.owner = THIS_MODULE;
 
 	return clocksource_register_hz(&tegra->osc, 38400000);
 }
@@ -411,6 +413,7 @@ static int tegra186_timer_usec_init(struct tegra186_timer *tegra)
 	tegra->usec.read = tegra186_timer_usec_read;
 	tegra->usec.mask = CLOCKSOURCE_MASK(32);
 	tegra->usec.flags = CLOCK_SOURCE_IS_CONTINUOUS;
+	tegra->usec.owner = THIS_MODULE;
 
 	return clocksource_register_hz(&tegra->usec, USEC_PER_SEC);
 }
#18 lore raw

PATCH 5/7 clocksource/drivers/stm: Add module owner

In reply to Daniel Lezcano

The conversion to modules requires a correct handling of the module refcount in order to prevent to unload it if it is in use. That is especially true with the clockevents where there is no function to unregister them.

The core time framework correctly handles the module refcount with the different clocksource and clockevents if the module owner is set.

Add the module owner to make sure the core framework will prevent stupid things happening when the driver will be converted into a module.

---
 drivers/clocksource/timer-nxp-stm.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/clocksource/timer-nxp-stm.c +2 -0
index d7ccf9001729..bbc40623728f 100644
@@ -201,6 +201,7 @@ static int __init nxp_stm_clocksource_init(struct device *dev, struct stm_timer
 	stm_timer->cs.resume = nxp_stm_clocksource_resume;
 	stm_timer->cs.mask = CLOCKSOURCE_MASK(32);
 	stm_timer->cs.flags = CLOCK_SOURCE_IS_CONTINUOUS;
+	stm_timer->cs.owner = THIS_MODULE;
 
 	ret = clocksource_register_hz(&stm_timer->cs, stm_timer->rate);
 	if (ret)
@@ -314,6 +315,7 @@ static int __init nxp_stm_clockevent_per_cpu_init(struct device *dev, struct stm
 	stm_timer->ced.cpumask = cpumask_of(cpu);
 	stm_timer->ced.rating = 460;
 	stm_timer->ced.irq = irq;
+	stm_timer->ced.owner = THIS_MODULE;
 
 	per_cpu(stm_timers, cpu) = stm_timer;
 
Signature · 1 line
2.43.0
Reviewed-by on v1 5/7
#19 lore raw

Re: [PATCH v1 5/7] clocksource/drivers/stm: Add module owner

Quoted 5 lines · Daniel Lezcano

The conversion to modules requires a correct handling of the module refcount in order to prevent to unload it if it is in use. That is especially true with the clockevents where there is no function to unregister them.

Quoted 8 lines

The core time framework correctly handles the module refcount with the different clocksource and clockevents if the module owner is set.

Add the module owner to make sure the core framework will prevent stupid things happening when the driver will be converted into a module.

Thanks,
Will

Quoted 27 lines
---
 drivers/clocksource/timer-nxp-stm.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/clocksource/timer-nxp-stm.c +2 -0
index d7ccf9001729..bbc40623728f 100644
@@ -201,6 +201,7 @@ static int __init nxp_stm_clocksource_init(struct device *dev, struct stm_timer
 	stm_timer->cs.resume = nxp_stm_clocksource_resume;
 	stm_timer->cs.mask = CLOCKSOURCE_MASK(32);
 	stm_timer->cs.flags = CLOCK_SOURCE_IS_CONTINUOUS;
+	stm_timer->cs.owner = THIS_MODULE;
 
 	ret = clocksource_register_hz(&stm_timer->cs, stm_timer->rate);
 	if (ret)
@@ -314,6 +315,7 @@ static int __init nxp_stm_clockevent_per_cpu_init(struct device *dev, struct stm
 	stm_timer->ced.cpumask = cpumask_of(cpu);
 	stm_timer->ced.rating = 460;
 	stm_timer->ced.irq = irq;
+	stm_timer->ced.owner = THIS_MODULE;
 
 	per_cpu(stm_timers, cpu) = stm_timer;
 
Signature · 1 line
2.43.0
merge bot Applied
#20 lore raw

[tip: timers/clocksource] clocksource/drivers/stm: Add module owner

In reply to Daniel Lezcano
The following commit has been merged into the timers/clocksource branch of tip:

The following commit has been merged into the timers/clocksource branch of tip:

Commit-ID:     dba0cbb3373cb8cd4c58fe4a1a1e79c8c40df773
Gitweb:        https://git.kernel.org/tip/dba0cbb3373cb8cd4c58fe4a1a1e79c8c40df773
Author:        Daniel Lezcano <[email protected]>
AuthorDate:    Mon, 02 Jun 2025 17:18:49 +02:00
Committer:     Daniel Lezcano <[email protected]>
CommitterDate: Thu, 10 Jul 2025 11:28:29 +02:00

clocksource/drivers/stm: Add module owner

The conversion to modules requires a correct handling of the module refcount in order to prevent to unload it if it is in use. That is especially true with the clockevents where there is no function to unregister them.

The core time framework correctly handles the module refcount with the different clocksource and clockevents if the module owner is set.

Add the module owner to make sure the core framework will prevent stupid things happening when the driver will be converted into a module.

---
 drivers/clocksource/timer-nxp-stm.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/clocksource/timer-nxp-stm.c +2 -0
index d7ccf90..bbc4062 100644
@@ -201,6 +201,7 @@ static int __init nxp_stm_clocksource_init(struct device *dev, struct stm_timer 
 	stm_timer->cs.resume = nxp_stm_clocksource_resume;
 	stm_timer->cs.mask = CLOCKSOURCE_MASK(32);
 	stm_timer->cs.flags = CLOCK_SOURCE_IS_CONTINUOUS;
+	stm_timer->cs.owner = THIS_MODULE;
 
 	ret = clocksource_register_hz(&stm_timer->cs, stm_timer->rate);
 	if (ret)
@@ -314,6 +315,7 @@ static int __init nxp_stm_clockevent_per_cpu_init(struct device *dev, struct stm
 	stm_timer->ced.cpumask = cpumask_of(cpu);
 	stm_timer->ced.rating = 460;
 	stm_timer->ced.irq = irq;
+	stm_timer->ced.owner = THIS_MODULE;
 
 	per_cpu(stm_timers, cpu) = stm_timer;
 
merge bot Applied
#21 lore raw

[tip: timers/clocksource] clocksource/drivers/stm: Add module owner

In reply to Daniel Lezcano
The following commit has been merged into the timers/clocksource branch of tip:

The following commit has been merged into the timers/clocksource branch of tip:

Commit-ID:     7a449b9d1dfad2a0163d4d4b0d817e09e564648e
Gitweb:        https://git.kernel.org/tip/7a449b9d1dfad2a0163d4d4b0d817e09e564648e
Author:        Daniel Lezcano <[email protected]>
AuthorDate:    Mon, 02 Jun 2025 17:18:49 +02:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Fri, 25 Jul 2025 11:43:32 +02:00

clocksource/drivers/stm: Add module owner

The conversion to modules requires a correct handling of the module refcount in order to prevent to unload it if it is in use. That is especially true with clockevents where there is no function to unregister them.

The core time framework correctly handles the module refcount with the different clocksource and clockevents if the module owner is set.

Add the module owner to make sure the core framework will prevent stupid things happening when the driver will be converted into a module.

---
 drivers/clocksource/timer-nxp-stm.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/clocksource/timer-nxp-stm.c +2 -0
index d7ccf90..bbc4062 100644
@@ -201,6 +201,7 @@ static int __init nxp_stm_clocksource_init(struct device *dev, struct stm_timer 
 	stm_timer->cs.resume = nxp_stm_clocksource_resume;
 	stm_timer->cs.mask = CLOCKSOURCE_MASK(32);
 	stm_timer->cs.flags = CLOCK_SOURCE_IS_CONTINUOUS;
+	stm_timer->cs.owner = THIS_MODULE;
 
 	ret = clocksource_register_hz(&stm_timer->cs, stm_timer->rate);
 	if (ret)
@@ -314,6 +315,7 @@ static int __init nxp_stm_clockevent_per_cpu_init(struct device *dev, struct stm
 	stm_timer->ced.cpumask = cpumask_of(cpu);
 	stm_timer->ced.rating = 460;
 	stm_timer->ced.irq = irq;
+	stm_timer->ced.owner = THIS_MODULE;
 
 	per_cpu(stm_timers, cpu) = stm_timer;
 
#22 lore raw

PATCH 6/7 clocksource/drivers/cs5535: Add module owner

In reply to Daniel Lezcano

The conversion to modules requires a correct handling of the module refcount in order to prevent to unload it if it is in use. That is especially true with the clockevents where there is no function to unregister them.

The core time framework correctly handles the module refcount with the different clocksource and clockevents if the module owner is set.

Add the module owner to make sure the core framework will prevent stupid things happening when the driver will be converted into a module.

---
 drivers/clocksource/timer-cs5535.c | 1 +
 1 file changed, 1 insertion(+)
drivers/clocksource/timer-cs5535.c +1 -0
index d47acfe848ae..8af666c39890 100644
@@ -101,6 +101,7 @@ static struct clock_event_device cs5535_clockevent = {
 	.tick_resume = mfgpt_shutdown,
 	.set_next_event = mfgpt_next_event,
 	.rating = 250,
+	.owner = THIS_MODULE,
 };
 
 static irqreturn_t mfgpt_tick(int irq, void *dev_id)
Signature · 1 line
2.43.0
Reviewed-by on v1 6/7
#23 lore raw

Re: [PATCH v1 6/7] clocksource/drivers/cs5535: Add module owner

Quoted 5 lines · Daniel Lezcano

The conversion to modules requires a correct handling of the module refcount in order to prevent to unload it if it is in use. That is especially true with the clockevents where there is no function to unregister them.

Quoted 8 lines

The core time framework correctly handles the module refcount with the different clocksource and clockevents if the module owner is set.

Add the module owner to make sure the core framework will prevent stupid things happening when the driver will be converted into a module.

Thanks,
Will

Quoted 19 lines
---
 drivers/clocksource/timer-cs5535.c | 1 +
 1 file changed, 1 insertion(+)
drivers/clocksource/timer-cs5535.c +1 -0
index d47acfe848ae..8af666c39890 100644
@@ -101,6 +101,7 @@ static struct clock_event_device cs5535_clockevent = {
 	.tick_resume = mfgpt_shutdown,
 	.set_next_event = mfgpt_next_event,
 	.rating = 250,
+	.owner = THIS_MODULE,
 };
 
 static irqreturn_t mfgpt_tick(int irq, void *dev_id)
Signature · 1 line
2.43.0
merge bot Applied
#24 lore raw

[tip: timers/clocksource] clocksource/drivers/cs5535: Add module owner

In reply to Daniel Lezcano
The following commit has been merged into the timers/clocksource branch of tip:

The following commit has been merged into the timers/clocksource branch of tip:

Commit-ID:     fcacf38b9e4408619b2f499ac7cbdfac8eefe668
Gitweb:        https://git.kernel.org/tip/fcacf38b9e4408619b2f499ac7cbdfac8eefe668
Author:        Daniel Lezcano <[email protected]>
AuthorDate:    Mon, 02 Jun 2025 17:18:50 +02:00
Committer:     Daniel Lezcano <[email protected]>
CommitterDate: Thu, 10 Jul 2025 11:28:29 +02:00

clocksource/drivers/cs5535: Add module owner

The conversion to modules requires a correct handling of the module refcount in order to prevent to unload it if it is in use. That is especially true with the clockevents where there is no function to unregister them.

The core time framework correctly handles the module refcount with the different clocksource and clockevents if the module owner is set.

Add the module owner to make sure the core framework will prevent stupid things happening when the driver will be converted into a module.

---
 drivers/clocksource/timer-cs5535.c | 1 +
 1 file changed, 1 insertion(+)
drivers/clocksource/timer-cs5535.c +1 -0
index d47acfe..8af666c 100644
@@ -101,6 +101,7 @@ static struct clock_event_device cs5535_clockevent = {
 	.tick_resume = mfgpt_shutdown,
 	.set_next_event = mfgpt_next_event,
 	.rating = 250,
+	.owner = THIS_MODULE,
 };
 
 static irqreturn_t mfgpt_tick(int irq, void *dev_id)
merge bot Applied
#25 lore raw

[tip: timers/clocksource] clocksource/drivers/cs5535: Add module owner

In reply to Daniel Lezcano
The following commit has been merged into the timers/clocksource branch of tip:

The following commit has been merged into the timers/clocksource branch of tip:

Commit-ID:     667b41e7364742120484ed5cca73d7cd77f3b10e
Gitweb:        https://git.kernel.org/tip/667b41e7364742120484ed5cca73d7cd77f3b10e
Author:        Daniel Lezcano <[email protected]>
AuthorDate:    Mon, 02 Jun 2025 17:18:50 +02:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Fri, 25 Jul 2025 11:43:38 +02:00

clocksource/drivers/cs5535: Add module owner

The conversion to modules requires a correct handling of the module refcount in order to prevent to unload it if it is in use. That is especially true with clockevents where there is no function to unregister them.

The core time framework correctly handles the module refcount with the different clocksource and clockevents if the module owner is set.

Add the module owner to make sure the core framework will prevent stupid things happening when the driver will be converted into a module.

---
 drivers/clocksource/timer-cs5535.c | 1 +
 1 file changed, 1 insertion(+)
drivers/clocksource/timer-cs5535.c +1 -0
index d47acfe..8af666c 100644
@@ -101,6 +101,7 @@ static struct clock_event_device cs5535_clockevent = {
 	.tick_resume = mfgpt_shutdown,
 	.set_next_event = mfgpt_next_event,
 	.rating = 250,
+	.owner = THIS_MODULE,
 };
 
 static irqreturn_t mfgpt_tick(int irq, void *dev_id)
#26 lore raw

PATCH 7/7 time: Export symbol for sched_clock register function

In reply to Daniel Lezcano

The timer drivers could be converted into modules. The different functions to register the clocksource or the clockevent are already exporting their symbols for modules but the sched_clock_register() function is missing.

Export the symbols so the drivers using this function can be converted into modules.

---
 kernel/time/sched_clock.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/time/sched_clock.c +2 -2
index cc15fe293719..cc1afec306b3 100644
@@ -174,8 +174,7 @@ static enum hrtimer_restart sched_clock_poll(struct hrtimer *hrt)
 	return HRTIMER_RESTART;
 }
 
-void __init
-sched_clock_register(u64 (*read)(void), int bits, unsigned long rate)
+void sched_clock_register(u64 (*read)(void), int bits, unsigned long rate)
 {
 	u64 res, wrap, new_mask, new_epoch, cyc, ns;
 	u32 new_mult, new_shift;
@@ -247,6 +246,7 @@ sched_clock_register(u64 (*read)(void), int bits, unsigned long rate)
 
 	pr_debug("Registered %pS as sched_clock source\n", read);
 }
+EXPORT_SYMBOL_GPL(sched_clock_register);
 
 void __init generic_sched_clock_init(void)
 {
Signature · 1 line
2.43.0
Reviewed-by on v1 7/7
#27 lore raw

Re: [PATCH v1 7/7] time: Export symbol for sched_clock register function

Quoted 9 lines · Daniel Lezcano

The timer drivers could be converted into modules. The different functions to register the clocksource or the clockevent are already exporting their symbols for modules but the sched_clock_register() function is missing.

Export the symbols so the drivers using this function can be converted into modules.

Thanks,
Will

Quoted 29 lines
---
 kernel/time/sched_clock.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/time/sched_clock.c +2 -2
index cc15fe293719..cc1afec306b3 100644
@@ -174,8 +174,7 @@ static enum hrtimer_restart sched_clock_poll(struct hrtimer *hrt)
 	return HRTIMER_RESTART;
 }
 
-void __init
-sched_clock_register(u64 (*read)(void), int bits, unsigned long rate)
+void sched_clock_register(u64 (*read)(void), int bits, unsigned long rate)
 {
 	u64 res, wrap, new_mask, new_epoch, cyc, ns;
 	u32 new_mult, new_shift;
@@ -247,6 +246,7 @@ sched_clock_register(u64 (*read)(void), int bits, unsigned long rate)
 
 	pr_debug("Registered %pS as sched_clock source\n", read);
 }
+EXPORT_SYMBOL_GPL(sched_clock_register);
 
 void __init generic_sched_clock_init(void)
 {
Signature · 1 line
2.43.0
Acked-by on v1 7/7
#28 lore raw

Re: [PATCH v1 7/7] time: Export symbol for sched_clock register function

In reply to Daniel Lezcano
Quoted 8 lines · Daniel Lezcano

The timer drivers could be converted into modules. The different functions to register the clocksource or the clockevent are already exporting their symbols for modules but the sched_clock_register() function is missing.

Export the symbols so the drivers using this function can be converted into modules.

Thanks for chasing down all the details around this issue Daniel!

merge bot Applied
#30 lore raw

[tip: timers/clocksource] time/sched_clock: Export symbol for sched_clock register function

In reply to Daniel Lezcano
The following commit has been merged into the timers/clocksource branch of tip:

The following commit has been merged into the timers/clocksource branch of tip:

Commit-ID:     1bc6a9b86eaa9d9da346ce4c137952c1782ac94d
Gitweb:        https://git.kernel.org/tip/1bc6a9b86eaa9d9da346ce4c137952c1782ac94d
Author:        Daniel Lezcano <[email protected]>
AuthorDate:    Mon, 02 Jun 2025 17:18:51 +02:00
Committer:     Daniel Lezcano <[email protected]>
CommitterDate: Thu, 10 Jul 2025 11:28:29 +02:00

time/sched_clock: Export symbol for sched_clock register function

The timer drivers could be converted into modules. The different functions to register the clocksource or the clockevent are already exporting their symbols for modules but the sched_clock_register() function is missing.

Export the symbols so the drivers using this function can be converted into modules.

---
 kernel/time/sched_clock.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/time/sched_clock.c +2 -2
index cc15fe2..cc1afec 100644
@@ -174,8 +174,7 @@ static enum hrtimer_restart sched_clock_poll(struct hrtimer *hrt)
 	return HRTIMER_RESTART;
 }
 
-void __init
-sched_clock_register(u64 (*read)(void), int bits, unsigned long rate)
+void sched_clock_register(u64 (*read)(void), int bits, unsigned long rate)
 {
 	u64 res, wrap, new_mask, new_epoch, cyc, ns;
 	u32 new_mult, new_shift;
@@ -247,6 +246,7 @@ sched_clock_register(u64 (*read)(void), int bits, unsigned long rate)
 
 	pr_debug("Registered %pS as sched_clock source\n", read);
 }
+EXPORT_SYMBOL_GPL(sched_clock_register);
 
 void __init generic_sched_clock_init(void)
 {
merge bot Applied
#31 lore raw

[tip: timers/clocksource] time/sched_clock: Export symbol for sched_clock_register() function

In reply to Daniel Lezcano
The following commit has been merged into the timers/clocksource branch of tip:

The following commit has been merged into the timers/clocksource branch of tip:

Commit-ID:     84deaa77d5dbecdca1f6a12107080a2a2870dd52
Gitweb:        https://git.kernel.org/tip/84deaa77d5dbecdca1f6a12107080a2a2870dd52
Author:        Daniel Lezcano <[email protected]>
AuthorDate:    Mon, 02 Jun 2025 17:18:51 +02:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Fri, 25 Jul 2025 11:43:43 +02:00

time/sched_clock: Export symbol for sched_clock_register() function

Timer drivers could be converted into modules. The different functions to register the clocksource or the clockevent are already exporting their symbols for modules, but the sched_clock_register() function is missing.

Export the symbol so the drivers using this function can be converted into modules.

---
 kernel/time/sched_clock.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
kernel/time/sched_clock.c +2 -2
index cc15fe2..cc1afec 100644
@@ -174,8 +174,7 @@ static enum hrtimer_restart sched_clock_poll(struct hrtimer *hrt)
 	return HRTIMER_RESTART;
 }
 
-void __init
-sched_clock_register(u64 (*read)(void), int bits, unsigned long rate)
+void sched_clock_register(u64 (*read)(void), int bits, unsigned long rate)
 {
 	u64 res, wrap, new_mask, new_epoch, cyc, ns;
 	u32 new_mult, new_shift;
@@ -247,6 +246,7 @@ sched_clock_register(u64 (*read)(void), int bits, unsigned long rate)
 
 	pr_debug("Registered %pS as sched_clock source\n", read);
 }
+EXPORT_SYMBOL_GPL(sched_clock_register);
 
 void __init generic_sched_clock_init(void)
 {
#32 lore raw
In reply to Daniel Lezcano
Quoted 57 lines · Daniel Lezcano

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.

Quoted 7 lines

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.

Thanks Daniel for taking the time to dig into this deeper to help identify how we can safely convert the timer drivers to modules! The series LGTM. I'll go ahead and address the review comments on my MCT series and rebase it on top of your patch series.

Thanks,
Will

<cut>

#33 lore raw
In reply to Daniel Lezcano

Hi Thomas,

was this series dropped ?

I'm not able to find it in v6.17-rc1 but it is in the master branch of the tip tree (v6.16-rc7)

Quoted 106 lines · Daniel Lezcano

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 <[email protected]>
Cc Daniel Lezcano <[email protected]>
Cc Thomas Gleixner <[email protected]>
Cc Maxime Coquelin <[email protected]>
Cc Alexandre Torgue <[email protected]>
Cc Chen-Yu Tsai <[email protected]>
Cc Jernej Skrabec <[email protected]>
Cc Samuel Holland <[email protected]>
Cc Thierry Reding <[email protected]>
Cc Jonathan Hunter <[email protected]>
Cc "Peter Zijlstra (Intel)" <[email protected]>
Cc Marco Elver <[email protected]>
Cc Nam Cao <[email protected]>
Cc John Stulz <[email protected]>
Cc Will McVicker <[email protected]>
Cc Peter Griffin <[email protected]>
Cc Saravan Kanna <[email protected]>

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(-)
Signature · 5 lines
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs

Follow Linaro:  <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog