Skip to contentSkip to conversation

ipipe: Clean up per-CPU host timers on hotplug

PATCH New Jan Kiszka 1 participant 1 message Feb 25, 2019 High-resolution timers, timer wheel, clockevents

lore
Share & tools
lore

Jan Kiszka

author
#0 lore raw

PATCH 1/1 ipipe: Clean up per-CPU host timers on hotplug

From: Jan Kiszka <[email protected]>

When a CPU is unplugged, make sure to drop all per-CPU ipipe timer devices when removing the CPU. Otherwise, we will corrupt the device list when re-registering the host timer on CPU onlining.

---
 include/linux/ipipe_tickdev.h |  5 +++++
 kernel/ipipe/timer.c          | 15 +++++++++++++++
 kernel/time/clockevents.c     |  5 ++++-
 3 files changed, 24 insertions(+), 1 deletion(-)
include/linux/ipipe_tickdev.h +5 -0
index 90395095e115..e222e839c3be 100644
@@ -102,6 +102,11 @@ extern unsigned long __ipipe_hrtimer_freq;
  */
 void ipipe_host_timer_register(struct clock_event_device *clkevt);
 
+/*
+ * Called by tick_cleanup_dead_cpu, to drop per-CPU timer devices
+ */
+void ipipe_host_timer_cleanup(struct clock_event_device *clkevt);
+
 /*
  * Register a standalone ipipe timer
  */
kernel/ipipe/timer.c +15 -0
index bbb3c8f4a7ab..5532be93e951 100644
@@ -145,6 +145,21 @@ void ipipe_host_timer_register(struct clock_event_device *evtdev)
 	ipipe_timer_register(timer);
 }
 
+#ifdef CONFIG_HOTPLUG_CPU
+void ipipe_host_timer_cleanup(struct clock_event_device *evtdev)
+{
+	struct ipipe_timer *timer = evtdev->ipipe_timer;
+	unsigned long flags;
+
+	if (timer == NULL)
+		return;
+
+	raw_spin_lock_irqsave(&lock, flags);
+	list_del(&timer->link);
+	raw_spin_unlock_irqrestore(&lock, flags);
+}
+#endif /* CONFIG_HOTPLUG_CPU */
+
 /*
  * register a timer: maintain them in a list sorted by rating
  */
kernel/time/clockevents.c +4 -1
index fd6894afff6b..1db5e25abde3 100644
@@ -630,8 +630,10 @@ void tick_cleanup_dead_cpu(int cpu)
 	 * Unregister the clock event devices which were
 	 * released from the users in the notify chain.
 	 */
-	list_for_each_entry_safe(dev, tmp, &clockevents_released, list)
+	list_for_each_entry_safe(dev, tmp, &clockevents_released, list) {
 		list_del(&dev->list);
+		ipipe_host_timer_cleanup(dev);
+	}
 	/*
 	 * Now check whether the CPU has left unused per cpu devices
 	 */
@@ -641,6 +643,7 @@ void tick_cleanup_dead_cpu(int cpu)
 		    !tick_is_broadcast_device(dev)) {
 			BUG_ON(!clockevent_state_detached(dev));
 			list_del(&dev->list);
+			ipipe_host_timer_cleanup(dev);
 		}
 	}
 	raw_spin_unlock_irqrestore(&clockevents_lock, flags);
Signature · 1 line
2.16.4