Skip to contentSkip to conversation

tick/broadcast: Allow later registered device enter oneshot mode

PATCH Superseded Jindong Yue 2 participants 3 messages Mar 31, 2021 Nohz, dynticks support

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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

Broadcast device is switched to oneshot mode in tick_switch_to_oneshot() -> tick_broadcast_switch_to_oneshot().

If build broadcast clock event device driver as module, and install it after system enters oneshot mode, then it will stay in periodic mode forever.

This patch allows such broadcast device switch to oneshot mode when register.

---

v2 changes:
- Remove below condition check before switch new installed broadcast device to oneshot mode:
dev->event_handler != tick_handle_oneshot_broadcast
- Put tick_clock_notify() after check system not runs in oneshot mode

---
 kernel/time/tick-broadcast.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
kernel/time/tick-broadcast.c +15 -2
index 36d7464c8962..c5e67685b0af 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
@@ -107,6 +108,19 @@ void tick_install_broadcast_device(struct clock_event_device *dev)
 	tick_broadcast_device.evtdev = dev;
 	if (!cpumask_empty(tick_broadcast_mask))
 		tick_broadcast_start_periodic(dev);
+
+	if (!(dev->features & CLOCK_EVT_FEAT_ONESHOT))
+		return;
+
+	/*
+	 * If system already runs in oneshot mode, switch new registered
+	 * broadcast device to oneshot mode explicitly if possiable.
+	 */
+	if (tick_broadcast_oneshot_active()) {
+		tick_broadcast_switch_to_oneshot();
+		return;
+	}
+
 	/*
 	 * Inform all cpus about this. We might be in a situation
 	 * where we did not switch to oneshot mode because the per cpu
@@ -115,8 +129,7 @@ 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)
-		tick_clock_notify();
+	tick_clock_notify();
 }
 
 /*
Signature · 1 line
2.17.1
#1 lore raw

kernel/time/tick-broadcast.c static inline void tick_resume_broadcast_oneshot(struct clock_event_device *bc) · line 50

Quoted 7 lines · Jindong Yue
kernel/time/tick-broadcast.c +1 -0
@@ -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);

Leftover ...

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

Quoted 12 lines
kernel/time/tick-broadcast.c +6 -0
 /*
  * Debugging: see timer_list.c
@@ -107,6 +108,19 @@ void tick_install_broadcast_device(struct clock_event_device *dev)
 	tick_broadcast_device.evtdev = dev;
 	if (!cpumask_empty(tick_broadcast_mask))
 		tick_broadcast_start_periodic(dev);
+
+	if (!(dev->features & CLOCK_EVT_FEAT_ONESHOT))
+		return;
+
+	/*
+	 * If system already runs in oneshot mode, switch new registered

the system .... the newly registered

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

Quoted 1 line
kernel/time/tick-broadcast.c +1 -0
+	 * broadcast device to oneshot mode explicitly if possiable.

s/possible/possiable/

But the 'if possible' makes no sense here. The above check for CLOCK_EVT_FEAT_ONESHOT established that it _is_ possible. So just remove the 'if ...'.

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

Quoted 5 lines
kernel/time/tick-broadcast.c +5 -0
+	 */
+	if (tick_broadcast_oneshot_active()) {
+		tick_broadcast_switch_to_oneshot();
+		return;
+	}

Thanks,

tglx

author
#2 lore raw
Quoted 12 lines

-----Original Message-----
From: Thomas Gleixner <[email protected]>
Sent: Wednesday, March 31, 2021 4:07 PM
To: J.d. Yue <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; J.d. Yue <[email protected]>
Subject: [EXT] Re: [PATCH v2] tick/broadcast: Allow later registered device enter oneshot mode

Caution: EXT Email

On Wed, Mar 31 2021 at 09:10, Jindong Yue wrote:

Quoted 10 lines

kernel/time/tick-broadcast.c

Quoted 8 lines
kernel/time/tick-broadcast.c +0 -0
@@ -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

kernel/time/tick-broadcast.c +2 -0
+static void tick_handle_oneshot_broadcast(struct clock_event_device
+*dev);

Leftover ...

Removed in v3.

Quoted 17 lines

kernel/time/tick-broadcast.c void tick_install_broadcast_device(struct

Quoted 4 lines

/*
* Debugging: see timer_list.c

kernel/time/tick-broadcast.c +0 -0
@@ -107,6 +108,19 @@ 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 116

Quoted 9 lines
kernel/time/tick-broadcast.c +6 -0
      tick_broadcast_device.evtdev = dev;
      if (!cpumask_empty(tick_broadcast_mask))
              tick_broadcast_start_periodic(dev);
+
+     if (!(dev->features & CLOCK_EVT_FEAT_ONESHOT))
+             return;
+
+     /*
+      * If system already runs in oneshot mode, switch new registered

the system .... the newly registered

Quoted 7 lines

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

Quoted 1 line
kernel/time/tick-broadcast.c +1 -0
+      * broadcast device to oneshot mode explicitly if possiable.

s/possible/possiable/

But the 'if possible' makes no sense here. The above check for CLOCK_EVT_FEAT_ONESHOT established that it _is_ possible. So just remove the 'if ...'.

I should be more careful ...
Please check v3 patch.

Thanks
Jindong

Quoted 10 lines

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

Quoted 6 lines
kernel/time/tick-broadcast.c +5 -0
+      */
+     if (tick_broadcast_oneshot_active()) {
+             tick_broadcast_switch_to_oneshot();
+             return;
+     }

Thanks,

tglx