linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tick: Remove unreasonable detached state set in tick_shutdown()
@ 2025-08-07  3:59 Bibo Mao
  2025-08-11  3:57 ` Bibo Mao
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Bibo Mao @ 2025-08-07  3:59 UTC (permalink / raw)
  To: Anna-Maria Behnsen, Frederic Weisbecker, Ingo Molnar,
	Thomas Gleixner
  Cc: linux-kernel

Function clockevents_switch_state() will check whether it has already
switched to specified state, do nothing if it has.

In function tick_shutdown(), it will set detached state at first and
call clockevents_switch_state() in clockevents_exchange_device(). The
function clockevents_switch_state() will do nothing since it is already
detached state. So the tick timer device will not be shutdown when CPU
is offline. In guest VM system, timer interrupt will prevent vCPU to sleep
if vCPU is hot removed.

Here remove state set before calling clockevents_exchange_device(),
its state will be set in function clockevents_switch_state() if it
succeeds to do so.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
 kernel/time/tick-common.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/kernel/time/tick-common.c b/kernel/time/tick-common.c
index 9a3859443c04..eb9b777f5492 100644
--- a/kernel/time/tick-common.c
+++ b/kernel/time/tick-common.c
@@ -424,11 +424,6 @@ void tick_shutdown(unsigned int cpu)
 
 	td->mode = TICKDEV_MODE_PERIODIC;
 	if (dev) {
-		/*
-		 * Prevent that the clock events layer tries to call
-		 * the set mode function!
-		 */
-		clockevent_set_state(dev, CLOCK_EVT_STATE_DETACHED);
 		clockevents_exchange_device(dev, NULL);
 		dev->event_handler = clockevents_handle_noop;
 		td->evtdev = NULL;

base-commit: 7e161a991ea71e6ec526abc8f40c6852ebe3d946
-- 
2.39.3


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] tick: Remove unreasonable detached state set in tick_shutdown()
  2025-08-07  3:59 [PATCH] tick: Remove unreasonable detached state set in tick_shutdown() Bibo Mao
@ 2025-08-11  3:57 ` Bibo Mao
  2025-09-02 14:00   ` Frederic Weisbecker
  2025-09-02 13:50 ` Frederic Weisbecker
  2025-09-02 14:07 ` Frederic Weisbecker
  2 siblings, 1 reply; 6+ messages in thread
From: Bibo Mao @ 2025-08-11  3:57 UTC (permalink / raw)
  To: Anna-Maria Behnsen, Frederic Weisbecker, Ingo Molnar,
	Thomas Gleixner
  Cc: linux-kernel

Hi,

Previously tick_shutdown() is called in BP, percpu timer cannot be 
shutdown in BP. Now it is called in AP, percpu timer can be shutdown in 
AP itself.

And there is another method, like other architectures add hotplug event 
callbak to shutdown percpu timer such as CPUHP_AP_LOONGARCH_TIMER_STARTING.

Which one do you prefer?

Regards
Bibo Mao

On 2025/8/7 上午11:59, Bibo Mao wrote:
> Function clockevents_switch_state() will check whether it has already
> switched to specified state, do nothing if it has.
> 
> In function tick_shutdown(), it will set detached state at first and
> call clockevents_switch_state() in clockevents_exchange_device(). The
> function clockevents_switch_state() will do nothing since it is already
> detached state. So the tick timer device will not be shutdown when CPU
> is offline. In guest VM system, timer interrupt will prevent vCPU to sleep
> if vCPU is hot removed.
> 
> Here remove state set before calling clockevents_exchange_device(),
> its state will be set in function clockevents_switch_state() if it
> succeeds to do so.
> 
> Signed-off-by: Bibo Mao <maobibo@loongson.cn>
> ---
>   kernel/time/tick-common.c | 5 -----
>   1 file changed, 5 deletions(-)
> 
> diff --git a/kernel/time/tick-common.c b/kernel/time/tick-common.c
> index 9a3859443c04..eb9b777f5492 100644
> --- a/kernel/time/tick-common.c
> +++ b/kernel/time/tick-common.c
> @@ -424,11 +424,6 @@ void tick_shutdown(unsigned int cpu)
>   
>   	td->mode = TICKDEV_MODE_PERIODIC;
>   	if (dev) {
> -		/*
> -		 * Prevent that the clock events layer tries to call
> -		 * the set mode function!
> -		 */
> -		clockevent_set_state(dev, CLOCK_EVT_STATE_DETACHED);
>   		clockevents_exchange_device(dev, NULL);
>   		dev->event_handler = clockevents_handle_noop;
>   		td->evtdev = NULL;
> 
> base-commit: 7e161a991ea71e6ec526abc8f40c6852ebe3d946
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] tick: Remove unreasonable detached state set in tick_shutdown()
  2025-08-07  3:59 [PATCH] tick: Remove unreasonable detached state set in tick_shutdown() Bibo Mao
  2025-08-11  3:57 ` Bibo Mao
@ 2025-09-02 13:50 ` Frederic Weisbecker
  2025-09-02 14:07 ` Frederic Weisbecker
  2 siblings, 0 replies; 6+ messages in thread
From: Frederic Weisbecker @ 2025-09-02 13:50 UTC (permalink / raw)
  To: Bibo Mao; +Cc: Anna-Maria Behnsen, Ingo Molnar, Thomas Gleixner, linux-kernel

Le Thu, Aug 07, 2025 at 11:59:54AM +0800, Bibo Mao a écrit :
> Function clockevents_switch_state() will check whether it has already
> switched to specified state, do nothing if it has.
> 
> In function tick_shutdown(), it will set detached state at first and
> call clockevents_switch_state() in clockevents_exchange_device(). The
> function clockevents_switch_state() will do nothing since it is already
> detached state. So the tick timer device will not be shutdown when CPU
> is offline. In guest VM system, timer interrupt will prevent vCPU to sleep
> if vCPU is hot removed.
> 
> Here remove state set before calling clockevents_exchange_device(),
> its state will be set in function clockevents_switch_state() if it
> succeeds to do so.
> 
> Signed-off-by: Bibo Mao <maobibo@loongson.cn>

Good catch. Looking back, it has been that way since the introduction
of clockevents and tick. Therefore it's not a regression and probably
not worth a Fixes: tag.

Reviewed-by: Frederic Weisbecker <frederic@kernel.org>

-- 
Frederic Weisbecker
SUSE Labs

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] tick: Remove unreasonable detached state set in tick_shutdown()
  2025-08-11  3:57 ` Bibo Mao
@ 2025-09-02 14:00   ` Frederic Weisbecker
  0 siblings, 0 replies; 6+ messages in thread
From: Frederic Weisbecker @ 2025-09-02 14:00 UTC (permalink / raw)
  To: Bibo Mao; +Cc: Anna-Maria Behnsen, Ingo Molnar, Thomas Gleixner, linux-kernel

Le Mon, Aug 11, 2025 at 11:57:20AM +0800, Bibo Mao a écrit :
> Hi,
> 
> Previously tick_shutdown() is called in BP, percpu timer cannot be shutdown
> in BP. Now it is called in AP, percpu timer can be shutdown in AP itself.

Ok, one more reason for not backporting it to stable then.

> 
> And there is another method, like other architectures add hotplug event
> callbak to shutdown percpu timer such as CPUHP_AP_LOONGARCH_TIMER_STARTING.
> 
> Which one do you prefer?

I prefer your fix that works for every clockevents. We want the active clockevent
to be stopped by the time we reach CPUHP_AP_OFFLINE.

If you add a loongarch hotplug callback, it must be for architecture
specifics.

Thanks.

-- 
Frederic Weisbecker
SUSE Labs

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] tick: Remove unreasonable detached state set in tick_shutdown()
  2025-08-07  3:59 [PATCH] tick: Remove unreasonable detached state set in tick_shutdown() Bibo Mao
  2025-08-11  3:57 ` Bibo Mao
  2025-09-02 13:50 ` Frederic Weisbecker
@ 2025-09-02 14:07 ` Frederic Weisbecker
  2025-09-03  9:36   ` Bibo Mao
  2 siblings, 1 reply; 6+ messages in thread
From: Frederic Weisbecker @ 2025-09-02 14:07 UTC (permalink / raw)
  To: Bibo Mao; +Cc: Anna-Maria Behnsen, Ingo Molnar, Thomas Gleixner, linux-kernel

Le Thu, Aug 07, 2025 at 11:59:54AM +0800, Bibo Mao a écrit :
> Function clockevents_switch_state() will check whether it has already
> switched to specified state, do nothing if it has.
> 
> In function tick_shutdown(), it will set detached state at first and
> call clockevents_switch_state() in clockevents_exchange_device(). The
> function clockevents_switch_state() will do nothing since it is already
> detached state. So the tick timer device will not be shutdown when CPU
> is offline. In guest VM system, timer interrupt will prevent vCPU to sleep
> if vCPU is hot removed.
> 
> Here remove state set before calling clockevents_exchange_device(),
> its state will be set in function clockevents_switch_state() if it
> succeeds to do so.
> 
> Signed-off-by: Bibo Mao <maobibo@loongson.cn>

On a second thought, it may need the following tags:

Fixes: bf9a001fb8e4 ("clocksource/drivers/timer-tegra: Remove clockevents shutdown call on offlining")
Fixes: cd165ce8314f ("clocksource/drivers/qcom: Remove clockevents shutdown call on offlining")
Fixes: 30f8c70a85bc ("clocksource/drivers/armada-370-xp: Remove clockevents shutdown call on offlining")
Fixes: ba23b6c7f974 ("clocksource/drivers/exynos_mct: Remove clockevents shutdown call on offlining")
Fixes: 15b810e0496e ("clocksource/drivers/arm_global_timer: Remove clockevents shutdown call on offlining")
Fixes: 78b5c2ca5f27 ("clocksource/drivers/arm_arch_timer: Remove clockevents shutdown call on offlining")
Fixes: 900053d9eedf ("ARM: smp_twd: Remove clockevents shutdown call on offlining")

Because those commits removed shutdown calls made from drivers that assumed the
core would do on their behalf. But it was not the case before your fix.

Thanks!

-- 
Frederic Weisbecker
SUSE Labs

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] tick: Remove unreasonable detached state set in tick_shutdown()
  2025-09-02 14:07 ` Frederic Weisbecker
@ 2025-09-03  9:36   ` Bibo Mao
  0 siblings, 0 replies; 6+ messages in thread
From: Bibo Mao @ 2025-09-03  9:36 UTC (permalink / raw)
  To: Frederic Weisbecker
  Cc: Anna-Maria Behnsen, Ingo Molnar, Thomas Gleixner, linux-kernel



On 2025/9/2 下午10:07, Frederic Weisbecker wrote:
> Le Thu, Aug 07, 2025 at 11:59:54AM +0800, Bibo Mao a écrit :
>> Function clockevents_switch_state() will check whether it has already
>> switched to specified state, do nothing if it has.
>>
>> In function tick_shutdown(), it will set detached state at first and
>> call clockevents_switch_state() in clockevents_exchange_device(). The
>> function clockevents_switch_state() will do nothing since it is already
>> detached state. So the tick timer device will not be shutdown when CPU
>> is offline. In guest VM system, timer interrupt will prevent vCPU to sleep
>> if vCPU is hot removed.
>>
>> Here remove state set before calling clockevents_exchange_device(),
>> its state will be set in function clockevents_switch_state() if it
>> succeeds to do so.
>>
>> Signed-off-by: Bibo Mao <maobibo@loongson.cn>
> 
> On a second thought, it may need the following tags:
> 
> Fixes: bf9a001fb8e4 ("clocksource/drivers/timer-tegra: Remove clockevents shutdown call on offlining")
> Fixes: cd165ce8314f ("clocksource/drivers/qcom: Remove clockevents shutdown call on offlining")
> Fixes: 30f8c70a85bc ("clocksource/drivers/armada-370-xp: Remove clockevents shutdown call on offlining")
> Fixes: ba23b6c7f974 ("clocksource/drivers/exynos_mct: Remove clockevents shutdown call on offlining")
> Fixes: 15b810e0496e ("clocksource/drivers/arm_global_timer: Remove clockevents shutdown call on offlining")
> Fixes: 78b5c2ca5f27 ("clocksource/drivers/arm_arch_timer: Remove clockevents shutdown call on offlining")
> Fixes: 900053d9eedf ("ARM: smp_twd: Remove clockevents shutdown call on offlining")
> 
> Because those commits removed shutdown calls made from drivers that assumed the
> core would do on their behalf. But it was not the case before your fix.
Ok, will add these fixes tags in next version.

Regards
Bibo Mao
> 
> Thanks!
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-09-03  9:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-07  3:59 [PATCH] tick: Remove unreasonable detached state set in tick_shutdown() Bibo Mao
2025-08-11  3:57 ` Bibo Mao
2025-09-02 14:00   ` Frederic Weisbecker
2025-09-02 13:50 ` Frederic Weisbecker
2025-09-02 14:07 ` Frederic Weisbecker
2025-09-03  9:36   ` Bibo Mao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).