Skip to contentSkip to conversation

tick/broadcast: Allow later probed device enter oneshot mode

PATCH Superseded Jindong Yue 2 participants 3 messages Mar 29, 2021 – Mar 30, 2021 Nohz, dynticks support

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tick/broadcast: Allow later probed device enter oneshot mode

Broadcast device is switched to oneshot mode in hrtimer_switch_to_hres() -> tick_broadcast_switch_to_oneshot(). After high resolution timers are enabled, new installed broadcast device has no chance to switch mode.

This issue happens in below situation:
In order to make broadcast clock source driver build as module, use module_platform_driver() to replace TIMER_OF_DECLARE(). This will make clock source driver probed later than high resolution timers enabled.

---
 kernel/time/tick-broadcast.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
kernel/time/tick-broadcast.c +14 -1
index e51778c312f1..f38a7544cb5b 100644
@@ -47,6 +47,7 @@ static inline void tick_resume_broadcast_oneshot(struct clock_event_device *bc)
 static inline void tick_broadcast_oneshot_offline(unsigned int cpu) { }
 # endif
 #endif
+static void tick_handle_oneshot_broadcast(struct clock_event_device *dev);
 
 /*
  * Debugging: see timer_list.c
@@ -115,8 +116,20 @@ void tick_install_broadcast_device(struct clock_event_device *dev)
 	 * notification the systems stays stuck in periodic mode
 	 * forever.
 	 */
-	if (dev->features & CLOCK_EVT_FEAT_ONESHOT)
+	if (dev->features & CLOCK_EVT_FEAT_ONESHOT) {
 		tick_clock_notify();
+
+		/*
+		 * If new broadcast device is installed after high resolution
+		 * timers enabled, it can not switch to oneshot mode anymore.
+		 * Here give it a chance.
+		 */
+		if (tick_broadcast_oneshot_active() &&
+		    dev->event_handler != tick_handle_oneshot_broadcast) {
+			tick_broadcast_switch_to_oneshot();
+		}
+	}
+
 }
 
 /*
Signature · 1 line
2.17.1
#1 lore raw

kernel/time/tick-broadcast.c void tick_install_broadcast_device(struct clock_event_device *dev) · line 120

Quoted 9 lines · Jindong Yue

/*
* Debugging: see timer_list.c

kernel/time/tick-broadcast.c +1 -1
@@ -115,8 +116,20 @@ void tick_install_broadcast_device(struct clock_event_device *dev)
 	 * notification the systems stays stuck in periodic mode
 	 * forever.
 	 */
-	if (dev->features & CLOCK_EVT_FEAT_ONESHOT)
+	if (dev->features & CLOCK_EVT_FEAT_ONESHOT) {
 		tick_clock_notify();

If the kernel runs in oneshot mode already, then calling tick_clock_notify() does not make sense.

kernel/time/tick-broadcast.c void tick_install_broadcast_device(struct clock_event_device *dev) · line 124

Quoted 3 lines
kernel/time/tick-broadcast.c +3 -0
+		/*
+		 * If new broadcast device is installed after high resolution
+		 * timers enabled, it can not switch to oneshot mode anymore.

This is not restricted to high resolution timers. The point is that the mode is ONESHOT which might be either HIGHRES or NOHZ or both.

kernel/time/tick-broadcast.c void tick_install_broadcast_device(struct clock_event_device *dev) · line 128

Quoted 3 lines
kernel/time/tick-broadcast.c +3 -0
+		 */
+		if (tick_broadcast_oneshot_active() &&
+		    dev->event_handler != tick_handle_oneshot_broadcast) {

How would that condition ever be false for a newly installed device?

Review void tick_install_broadcast_device(struct clock_event_device *dev) · line 128

Quoted 2 lines
(quoted diff) +2 -0
+			tick_broadcast_switch_to_oneshot();
+		}

So what you really want is:

        if (!(dev->features & CLOCK_EVT_FEAT_ONESHOT))
        	return;

        if (tick_broadcast_oneshot_active()) {
		tick_broadcast_switch_to_oneshot();
                return;
        }

        tick_clock_notify();

Thanks,

tglx

author
#2 lore raw
Quoted 24 lines

-----Original Message-----
From: Thomas Gleixner <[email protected]>
Sent: Tuesday, March 30, 2021 5:18 AM
To: J.d. Yue <[email protected]>
Cc: [email protected]; [email protected]; [email protected]
Subject: [EXT] Re: [PATCH] tick/broadcast: Allow later probed device enter oneshot mode

Caution: EXT Email

Review void tick_install_broadcast_device(struct

Quoted 3 lines · Jindong Yue

/*
* Debugging: see timer_list.c

(quoted diff) +0 -0
@@ -115,8 +116,20 @@ void tick_install_broadcast_device(struct

clock_event_device *dev)

kernel/time/tick-broadcast.c void tick_install_broadcast_device(struct clock_event_device *dev) · line 120

Quoted 6 lines
kernel/time/tick-broadcast.c +1 -1
       * notification the systems stays stuck in periodic mode
       * forever.
       */
-     if (dev->features & CLOCK_EVT_FEAT_ONESHOT)
+     if (dev->features & CLOCK_EVT_FEAT_ONESHOT) {
              tick_clock_notify();
Quoted 2 lines

If the kernel runs in oneshot mode already, then calling tick_clock_notify() does not make sense.

Yes, there should be more check before tick_clock_notify().

Quoted 8 lines

kernel/time/tick-broadcast.c void tick_install_broadcast_device(struct clock_event_device *dev)

Quoted 4 lines
kernel/time/tick-broadcast.c +3 -0
+             /*
+              * If new broadcast device is installed after high resolution
+              * timers enabled, it can not switch to oneshot mode

anymore.

This is not restricted to high resolution timers. The point is that the mode is ONESHOT which might be either HIGHRES or NOHZ or both.

Got it, after kernel enters ONESHOT mode, new registered broadcast device can't be switched to ONESHOT mode.

Quoted 7 lines

kernel/time/tick-broadcast.c void tick_install_broadcast_device(struct clock_event_device *dev)

Quoted 5 lines
kernel/time/tick-broadcast.c +4 -0
+              */
+             if (tick_broadcast_oneshot_active() &&
+                 dev->event_handler != tick_handle_oneshot_broadcast)
+ {

How would that condition ever be false for a newly installed device?

Okay, will remove this condition.

Quoted 16 lines

Review void tick_install_broadcast_device(struct · line 129

Quoted 3 lines
(quoted diff) +2 -0
+                     tick_broadcast_switch_to_oneshot();
+             }

So what you really want is:

        if (!(dev->features & CLOCK_EVT_FEAT_ONESHOT))
                return;

        if (tick_broadcast_oneshot_active()) {
                tick_broadcast_switch_to_oneshot();
                return;
        }

        tick_clock_notify();
Quoted 3 lines

Thanks,

tglx

Thanks for your quick review and advice. I will test this code locally and send V2 patch later. Jindong