Skip to contentSkip to conversation

clockevents_notify() removal

PATCH Superseded Rafael J. Wysocki 11 participants 90 messages Apr 1, 2015 – Apr 30, 2015

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

cover clockevents_notify() removal

Hi,

This is the next batch of patches from Thomas that remove clockevents_notify().

I've reordered the set (to put more stratightforward things to the front) and rebased it on top of the timers material currently queued up for 4.1.

This series in based on the bleeding-edge branch of the linux-pm tree (which for all practical purposes is my linux-next branch with timers/core from tip merged into it).

Please let me know how to proceed with these.

Thanks,
Rafael

#1 lore raw

PATCH 1/20 clockevents: Provide explicit broadcast control functions

From: Thomas Gleixner <[email protected]>

clockevents_notify() is a leftover from the early design of the clockevents facility. It's really not a notification mechanism, it's a multiplex call. We are way better off to have explicit calls instead of this monstrosity.

Split out the broadcast control into a separate function and provide inline helpers. Switch clockevents_notify() over. This will go away once all callers are converted.

This also gets rid of the nested locking of clockevents_lock and broadcast_lock. The broadcast control functions do not require clockevents_lock. Only the managing functions (setup/shutdown/suspend/resume of the broadcast device require clockevents_lock.

---
 include/linux/tick.h         |   25 +++++++++++++++++
 kernel/time/clockevents.c    |    6 +++-
 kernel/time/tick-broadcast.c |   62 ++++++++++++++++++-------------------------
 kernel/time/tick-internal.h  |    2 -
 4 files changed, 57 insertions(+), 38 deletions(-)
include/linux/tick.h +25 -0
Index: linux-pm/include/linux/tick.h
===================================================================
@@ -36,6 +36,31 @@ extern void tick_irq_enter(void);
 static inline void tick_irq_enter(void) { }
 #endif
 
+enum tick_broadcast_mode {
+	TICK_BROADCAST_OFF,
+	TICK_BROADCAST_ON,
+	TICK_BROADCAST_FORCE,
+};
+
+#ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
+extern void tick_broadcast_control(enum tick_broadcast_mode mode);
+#else
+static inline void tick_broadcast_control(enum tick_broadcast_mode mode) { }
+#endif /* BROADCAST */
+
+static inline void tick_broadcast_enable(void)
+{
+	tick_broadcast_control(TICK_BROADCAST_ON);
+}
+static inline void tick_broadcast_disable(void)
+{
+	tick_broadcast_control(TICK_BROADCAST_OFF);
+}
+static inline void tick_broadcast_force(void)
+{
+	tick_broadcast_control(TICK_BROADCAST_FORCE);
+}
+
 #ifdef CONFIG_NO_HZ_COMMON
 extern int tick_nohz_tick_stopped(void);
 extern void tick_nohz_idle_enter(void);
kernel/time/clockevents.c +5 -1
Index: linux-pm/kernel/time/clockevents.c
===================================================================
@@ -656,9 +656,13 @@ int clockevents_notify(unsigned long rea
 
 	switch (reason) {
 	case CLOCK_EVT_NOTIFY_BROADCAST_ON:
+		tick_broadcast_enable();
+		break;
 	case CLOCK_EVT_NOTIFY_BROADCAST_OFF:
+		tick_broadcast_disable();
+		break;
 	case CLOCK_EVT_NOTIFY_BROADCAST_FORCE:
-		tick_broadcast_on_off(reason, arg);
+		tick_broadcast_force();
 		break;
 
 	case CLOCK_EVT_NOTIFY_BROADCAST_ENTER:
kernel/time/tick-broadcast.c +27 -35

105 lines not on this page · raw message

kernel/time/tick-internal.h +0 -2
Index: linux-pm/kernel/time/tick-internal.h
===================================================================
@@ -85,7 +85,6 @@ static inline int tick_check_oneshot_cha
 extern int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu);
 extern void tick_install_broadcast_device(struct clock_event_device *dev);
 extern int tick_is_broadcast_device(struct clock_event_device *dev);
-extern void tick_broadcast_on_off(unsigned long reason, int *oncpu);
 extern void tick_shutdown_broadcast(unsigned int *cpup);
 extern void tick_suspend_broadcast(void);
 extern void tick_resume_broadcast(void);
@@ -100,7 +99,6 @@ static inline void tick_install_broadcas
 static inline int tick_is_broadcast_device(struct clock_event_device *dev) { return 0; }
 static inline int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu) { return 0; }
 static inline void tick_do_periodic_broadcast(struct clock_event_device *d) { }
-static inline void tick_broadcast_on_off(unsigned long reason, int *oncpu) { }
 static inline void tick_shutdown_broadcast(unsigned int *cpup) { }
 static inline void tick_suspend_broadcast(void) { }
 static inline void tick_resume_broadcast(void) { }
#2 lore raw

PATCH 2/20 x86, amd_idle: Use explicit broadcast control function

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Replace the clockevents_notify() call with an explicit function call.

---
 arch/x86/kernel/process.c |    9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
arch/x86/kernel/process.c +3 -6
Index: linux-pm/arch/x86/kernel/process.c
===================================================================
@@ -9,7 +9,7 @@
 #include <linux/sched.h>
 #include <linux/module.h>
 #include <linux/pm.h>
-#include <linux/clockchips.h>
+#include <linux/tick.h>
 #include <linux/random.h>
 #include <linux/user-return-notifier.h>
 #include <linux/dmi.h>
@@ -377,11 +377,8 @@ static void amd_e400_idle(void)
 
 		if (!cpumask_test_cpu(cpu, amd_e400_c1e_mask)) {
 			cpumask_set_cpu(cpu, amd_e400_c1e_mask);
-			/*
-			 * Force broadcast so ACPI can not interfere.
-			 */
-			clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_FORCE,
-					   &cpu);
+			/* Force broadcast so ACPI can not interfere. */
+			tick_broadcast_force();
 			pr_info("Switch to broadcast mode on CPU%d\n", cpu);
 		}
 		clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &cpu);
#3 lore raw

PATCH 3/20 ACPI / PAD: Use explicit broadcast control function

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Replace the clockevents_notify() call with an explicit function call.

---
 drivers/acpi/acpi_pad.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/acpi/acpi_pad.c +2 -3
Index: linux-pm/drivers/acpi/acpi_pad.c
===================================================================
@@ -26,7 +26,7 @@
 #include <linux/kthread.h>
 #include <linux/freezer.h>
 #include <linux/cpu.h>
-#include <linux/clockchips.h>
+#include <linux/tick.h>
 #include <linux/slab.h>
 #include <linux/acpi.h>
 #include <asm/mwait.h>
@@ -172,9 +172,8 @@ static int power_saving_thread(void *dat
 				mark_tsc_unstable("TSC halts in idle");
 				tsc_marked_unstable = 1;
 			}
-			clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ON, &cpu);
-
 			local_irq_disable();
+			tick_broadcast_enable();
 			cpu = smp_processor_id();
 			clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &cpu);
 			stop_critical_timings();
#4 lore raw

PATCH 4/20 ACPI / processor: Use explicit broadcast control function

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Replace the clockevents_notify() call with an explicit function call.

---
 drivers/acpi/processor_idle.c |   11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/acpi/processor_idle.c +5 -6
Index: linux-pm/drivers/acpi/processor_idle.c
===================================================================
@@ -32,7 +32,7 @@
 #include <linux/acpi.h>
 #include <linux/dmi.h>
 #include <linux/sched.h>       /* need_resched() */
-#include <linux/clockchips.h>
+#include <linux/tick.h>
 #include <linux/cpuidle.h>
 #include <linux/syscore_ops.h>
 #include <acpi/processor.h>
@@ -157,12 +157,11 @@ static void lapic_timer_check_state(int
 static void __lapic_timer_propagate_broadcast(void *arg)
 {
 	struct acpi_processor *pr = (struct acpi_processor *) arg;
-	unsigned long reason;
 
-	reason = pr->power.timer_broadcast_on_state < INT_MAX ?
-		CLOCK_EVT_NOTIFY_BROADCAST_ON : CLOCK_EVT_NOTIFY_BROADCAST_OFF;
-
-	clockevents_notify(reason, &pr->id);
+	if (pr->power.timer_broadcast_on_state < INT_MAX)
+		tick_broadcast_enable();
+	else
+		tick_broadcast_disable();
 }
 
 static void lapic_timer_propagate_broadcast(struct acpi_processor *pr)
#5 lore raw

PATCH 5/20 cpuidle: Use explicit broadcast control function

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Replace the clockevents_notify() call with an explicit function call.

---
 drivers/cpuidle/driver.c |   25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)
drivers/cpuidle/driver.c +12 -13
Index: linux-pm/drivers/cpuidle/driver.c
===================================================================
@@ -13,7 +13,7 @@
 #include <linux/sched.h>
 #include <linux/cpuidle.h>
 #include <linux/cpumask.h>
-#include <linux/clockchips.h>
+#include <linux/tick.h>
 
 #include "cpuidle.h"
 
@@ -130,21 +130,20 @@ static inline void __cpuidle_unset_drive
 #endif
 
 /**
- * cpuidle_setup_broadcast_timer - enable/disable the broadcast timer
+ * cpuidle_setup_broadcast_timer - enable/disable the broadcast timer on a cpu
  * @arg: a void pointer used to match the SMP cross call API
  *
- * @arg is used as a value of type 'long' with one of the two values:
- * - CLOCK_EVT_NOTIFY_BROADCAST_ON
- * - CLOCK_EVT_NOTIFY_BROADCAST_OFF
- *
- * Set the broadcast timer notification for the current CPU.  This function
- * is executed per CPU by an SMP cross call.  It not supposed to be called
- * directly.
+ * If @arg is NULL broadcast is disabled otherwise enabled
+ *
+ * This function is executed per CPU by an SMP cross call.  It's not
+ * supposed to be called directly.
  */
 static void cpuidle_setup_broadcast_timer(void *arg)
 {
-	int cpu = smp_processor_id();
-	clockevents_notify((long)(arg), &cpu);
+	if (arg)
+		tick_broadcast_enable();
+	else
+		tick_broadcast_disable();
 }
 
 /**
@@ -239,7 +238,7 @@ static int __cpuidle_register_driver(str
 
 	if (drv->bctimer)
 		on_each_cpu_mask(drv->cpumask, cpuidle_setup_broadcast_timer,
-				 (void *)CLOCK_EVT_NOTIFY_BROADCAST_ON, 1);
+				 (void *)1, 1);
 
 	poll_idle_init(drv);
 
@@ -263,7 +262,7 @@ static void __cpuidle_unregister_driver(
 	if (drv->bctimer) {
 		drv->bctimer = 0;
 		on_each_cpu_mask(drv->cpumask, cpuidle_setup_broadcast_timer,
-				 (void *)CLOCK_EVT_NOTIFY_BROADCAST_OFF, 1);
+				 NULL, 1);
 	}
 
 	__cpuidle_unset_driver(drv);
#6 lore raw

PATCH 6/20 intel_idle: Use explicit broadcast control function

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Replace the clockevents_notify() call with an explicit function call.

---
 drivers/idle/intel_idle.c |   13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/idle/intel_idle.c +6 -7
Index: linux-pm/drivers/idle/intel_idle.c
===================================================================
@@ -55,7 +55,7 @@
 
 #include <linux/kernel.h>
 #include <linux/cpuidle.h>
-#include <linux/clockchips.h>
+#include <linux/tick.h>
 #include <trace/events/power.h>
 #include <linux/sched.h>
 #include <linux/notifier.h>
@@ -668,13 +668,12 @@ static void intel_idle_freeze(struct cpu
 
 static void __setup_broadcast_timer(void *arg)
 {
-	unsigned long reason = (unsigned long)arg;
-	int cpu = smp_processor_id();
-
-	reason = reason ?
-		CLOCK_EVT_NOTIFY_BROADCAST_ON : CLOCK_EVT_NOTIFY_BROADCAST_OFF;
+	unsigned long on = (unsigned long)arg;
 
-	clockevents_notify(reason, &cpu);
+	if (on)
+		tick_broadcast_enable();
+	else
+		tick_broadcast_disable();
 }
 
 static int cpu_hotplug_notify(struct notifier_block *n,
#7 lore raw

PATCH 7/20 ARM: OMAP: Use explicit broadcast control function

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Replace the clockevents_notify() call with an explicit function call.

---
 arch/arm/mach-omap2/cpuidle44xx.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
arch/arm/mach-omap2/cpuidle44xx.c +2 -3
Index: linux-pm/arch/arm/mach-omap2/cpuidle44xx.c
===================================================================
@@ -14,7 +14,7 @@
 #include <linux/cpuidle.h>
 #include <linux/cpu_pm.h>
 #include <linux/export.h>
-#include <linux/clockchips.h>
+#include <linux/tick.h>
 
 #include <asm/cpuidle.h>
 
@@ -183,8 +183,7 @@ fail:
  */
 static void omap_setup_broadcast_timer(void *arg)
 {
-	int cpu = smp_processor_id();
-	clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ON, &cpu);
+	tick_broadcast_enable();
 }
 
 static struct cpuidle_driver omap4_idle_driver = {
#8 lore raw

PATCH 8/20 clockevents: Remove the broadcast control leftovers

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

All users converted. Remove the notify leftovers.

---
 include/linux/clockchips.h |    3 ---
 kernel/time/clockevents.c  |   10 ----------
 2 files changed, 13 deletions(-)
include/linux/clockchips.h +0 -3
Index: linux-pm/include/linux/clockchips.h
===================================================================
@@ -11,9 +11,6 @@
 /* Clock event notification values */
 enum clock_event_nofitiers {
 	CLOCK_EVT_NOTIFY_ADD,
-	CLOCK_EVT_NOTIFY_BROADCAST_ON,
-	CLOCK_EVT_NOTIFY_BROADCAST_OFF,
-	CLOCK_EVT_NOTIFY_BROADCAST_FORCE,
 	CLOCK_EVT_NOTIFY_BROADCAST_ENTER,
 	CLOCK_EVT_NOTIFY_BROADCAST_EXIT,
 	CLOCK_EVT_NOTIFY_CPU_DYING,
kernel/time/clockevents.c +0 -10
Index: linux-pm/kernel/time/clockevents.c
===================================================================
@@ -655,16 +655,6 @@ int clockevents_notify(unsigned long rea
 	raw_spin_lock_irqsave(&clockevents_lock, flags);
 
 	switch (reason) {
-	case CLOCK_EVT_NOTIFY_BROADCAST_ON:
-		tick_broadcast_enable();
-		break;
-	case CLOCK_EVT_NOTIFY_BROADCAST_OFF:
-		tick_broadcast_disable();
-		break;
-	case CLOCK_EVT_NOTIFY_BROADCAST_FORCE:
-		tick_broadcast_force();
-		break;
-
 	case CLOCK_EVT_NOTIFY_BROADCAST_ENTER:
 	case CLOCK_EVT_NOTIFY_BROADCAST_EXIT:
 		ret = tick_broadcast_oneshot_control(reason);
#9 lore raw

PATCH 9/20 clockevents: Provide explicit broadcast oneshot control functions

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

clockevents_notify() is a leftover from the early design of the clockevents facility. It's really not a notification mechanism, it's a multiplex call. We are way better off to have explicit calls instead of this monstrosity.

Split out the broadcast oneshot control into a separate function and provide inline helpers. Switch clockevents_notify() over. This will go away once all callers are converted.

This also gets rid of the nested locking of clockevents_lock and broadcast_lock. The broadcast oneshot control functions do not require clockevents_lock. Only the managing functions (setup/shutdown/suspend/resume of the broadcast device require clockevents_lock.

Cc Tony Lindgren <[email protected]>
Cc Stephen Warren <[email protected]>
Cc Thierry Reding <[email protected]>
Cc Alexandre Courbot <[email protected]>
Cc Daniel Lezcano <[email protected]>
Cc Len Brown <[email protected]>
---
 include/linux/tick.h         |   19 +++++++++++++++++++
 kernel/time/clockevents.c    |    4 +++-
 kernel/time/tick-broadcast.c |   28 +++++++++++++++++-----------
 kernel/time/tick-internal.h  |    2 --
 4 files changed, 39 insertions(+), 14 deletions(-)
include/linux/tick.h +19 -0
Index: linux-pm/include/linux/tick.h
===================================================================
@@ -42,12 +42,23 @@ enum tick_broadcast_mode {
 	TICK_BROADCAST_FORCE,
 };
 
+enum tick_broadcast_state {
+	TICK_BROADCAST_EXIT,
+	TICK_BROADCAST_ENTER,
+};
+
 #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
 extern void tick_broadcast_control(enum tick_broadcast_mode mode);
 #else
 static inline void tick_broadcast_control(enum tick_broadcast_mode mode) { }
 #endif /* BROADCAST */
 
+#if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
+extern int tick_broadcast_oneshot_control(enum tick_broadcast_state state);
+#else
+static inline int tick_broadcast_oneshot_control(enum tick_broadcast_state state) { return 0; }
+#endif
+
 static inline void tick_broadcast_enable(void)
 {
 	tick_broadcast_control(TICK_BROADCAST_ON);
@@ -60,6 +71,14 @@ static inline void tick_broadcast_force(
 {
 	tick_broadcast_control(TICK_BROADCAST_FORCE);
 }
+static inline int tick_broadcast_enter(void)
+{
+	return tick_broadcast_oneshot_control(TICK_BROADCAST_ENTER);
+}
+static inline void tick_broadcast_exit(void)
+{
+	tick_broadcast_oneshot_control(TICK_BROADCAST_EXIT);
+}
 
 #ifdef CONFIG_NO_HZ_COMMON
 extern int tick_nohz_tick_stopped(void);
kernel/time/clockevents.c +3 -1
Index: linux-pm/kernel/time/clockevents.c
===================================================================
@@ -656,8 +656,10 @@ int clockevents_notify(unsigned long rea
 
 	switch (reason) {
 	case CLOCK_EVT_NOTIFY_BROADCAST_ENTER:
+		tick_broadcast_enter();
+		break;
 	case CLOCK_EVT_NOTIFY_BROADCAST_EXIT:
-		ret = tick_broadcast_oneshot_control(reason);
+		tick_broadcast_exit();
 		break;
 
 	case CLOCK_EVT_NOTIFY_CPU_DYING:
kernel/time/tick-broadcast.c +17 -11
Index: linux-pm/kernel/time/tick-broadcast.c
===================================================================
@@ -682,18 +682,23 @@ static void broadcast_move_bc(int deadcp
 	clockevents_program_event(bc, bc->next_event, 1);
 }
 
-/*
- * Powerstate information: The system enters/leaves a state, where
- * affected devices might stop
+/**
+ * tick_broadcast_oneshot_control - Enter/exit broadcast oneshot mode
+ * @state:	The target state (enter/exit)
+ *
+ * The system enters/leaves a state, where affected devices might stop
  * Returns 0 on success, -EBUSY if the cpu is used to broadcast wakeups.
+ *
+ * Called with interrupts disabled, so clockevents_lock is not
+ * required here because the local clock event device cannot go away
+ * under us.
  */
-int tick_broadcast_oneshot_control(unsigned long reason)
+int tick_broadcast_oneshot_control(enum tick_broadcast_state state)
 {
 	struct clock_event_device *bc, *dev;
 	struct tick_device *td;
-	unsigned long flags;
-	ktime_t now;
 	int cpu, ret = 0;
+	ktime_t now;
 
 	/*
 	 * Periodic mode does not care about the enter/exit of power
@@ -706,17 +711,17 @@ int tick_broadcast_oneshot_control(unsig
 	 * We are called with preemtion disabled from the depth of the
 	 * idle code, so we can't be moved away.
 	 */
-	cpu = smp_processor_id();
-	td = &per_cpu(tick_cpu_device, cpu);
+	td = this_cpu_ptr(&tick_cpu_device);
 	dev = td->evtdev;
 
 	if (!(dev->features & CLOCK_EVT_FEAT_C3STOP))
 		return 0;
 
+	raw_spin_lock(&tick_broadcast_lock);
 	bc = tick_broadcast_device.evtdev;
+	cpu = smp_processor_id();
 
-	raw_spin_lock_irqsave(&tick_broadcast_lock, flags);
-	if (reason == CLOCK_EVT_NOTIFY_BROADCAST_ENTER) {
+	if (state == TICK_BROADCAST_ENTER) {
 		if (!cpumask_test_and_set_cpu(cpu, tick_broadcast_oneshot_mask)) {
 			WARN_ON_ONCE(cpumask_test_cpu(cpu, tick_broadcast_pending_mask));
 			broadcast_shutdown_local(bc, dev);
@@ -808,9 +813,10 @@ int tick_broadcast_oneshot_control(unsig
 		}
 	}
 out:
-	raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags);
+	raw_spin_unlock(&tick_broadcast_lock);
 	return ret;
 }
+EXPORT_SYMBOL_GPL(tick_broadcast_oneshot_control);
 
 /*
  * Reset the one shot broadcast for a cpu
kernel/time/tick-internal.h +0 -2
Index: linux-pm/kernel/time/tick-internal.h
===================================================================
@@ -118,7 +118,6 @@ static inline void tick_set_periodic_han
 /* Functions related to oneshot broadcasting */
 #if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
 extern void tick_broadcast_setup_oneshot(struct clock_event_device *bc);
-extern int tick_broadcast_oneshot_control(unsigned long reason);
 extern void tick_broadcast_switch_to_oneshot(void);
 extern void tick_shutdown_broadcast_oneshot(unsigned int *cpup);
 extern int tick_broadcast_oneshot_active(void);
@@ -127,7 +126,6 @@ bool tick_broadcast_oneshot_available(vo
 extern struct cpumask *tick_get_broadcast_oneshot_mask(void);
 #else /* BROADCAST && ONESHOT */
 static inline void tick_broadcast_setup_oneshot(struct clock_event_device *bc) { BUG(); }
-static inline int tick_broadcast_oneshot_control(unsigned long reason) { return 0; }
 static inline void tick_broadcast_switch_to_oneshot(void) { }
 static inline void tick_shutdown_broadcast_oneshot(unsigned int *cpup) { }
 static inline int tick_broadcast_oneshot_active(void) { return 0; }
#10 lore raw

PATCH 10/20 x86, amd_idle: Use explicit broadcast oneshot control functions

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Replace the clockevents_notify() call with an explicit function call.

---
 arch/x86/kernel/process.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/process.c +2 -2
Index: linux-pm/arch/x86/kernel/process.c
===================================================================
@@ -381,7 +381,7 @@ static void amd_e400_idle(void)
 			tick_broadcast_force();
 			pr_info("Switch to broadcast mode on CPU%d\n", cpu);
 		}
-		clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &cpu);
+		tick_broadcast_enter();
 
 		default_idle();
 
@@ -390,7 +390,7 @@ static void amd_e400_idle(void)
 		 * called with interrupts disabled.
 		 */
 		local_irq_disable();
-		clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &cpu);
+		tick_broadcast_exit();
 		local_irq_enable();
 	} else
 		default_idle();
#11 lore raw

PATCH 11/20 ACPI / PAD: Use explicit broadcast oneshot control function

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Replace the clockevents_notify() call with an explicit function call.

---
 drivers/acpi/acpi_pad.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/acpi/acpi_pad.c +2 -4
Index: linux-pm/drivers/acpi/acpi_pad.c
===================================================================
@@ -150,7 +150,6 @@ static int power_saving_thread(void *dat
 	sched_setscheduler(current, SCHED_RR, &param);
 
 	while (!kthread_should_stop()) {
-		int cpu;
 		unsigned long expire_time;
 
 		try_to_freeze();
@@ -174,14 +173,13 @@ static int power_saving_thread(void *dat
 			}
 			local_irq_disable();
 			tick_broadcast_enable();
-			cpu = smp_processor_id();
-			clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &cpu);
+			tick_broadcast_enter();
 			stop_critical_timings();
 
 			mwait_idle_with_hints(power_saving_mwait_eax, 1);
 
 			start_critical_timings();
-			clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &cpu);
+			tick_broadcast_exit();
 			local_irq_enable();
 
 			if (time_before(expire_time, jiffies)) {
#12 lore raw

PATCH 12/20 ACPI / processor: Use explicit broadcast controll function

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Replace the clockevents_notify() call with an explicit function call.

---
 drivers/acpi/processor_idle.c |    9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/acpi/processor_idle.c +4 -5
Index: linux-pm/drivers/acpi/processor_idle.c
===================================================================
@@ -178,11 +178,10 @@ static void lapic_timer_state_broadcast(
 	int state = cx - pr->power.states;
 
 	if (state >= pr->power.timer_broadcast_on_state) {
-		unsigned long reason;
-
-		reason = broadcast ?  CLOCK_EVT_NOTIFY_BROADCAST_ENTER :
-			CLOCK_EVT_NOTIFY_BROADCAST_EXIT;
-		clockevents_notify(reason, &pr->id);
+		if (broadcast)
+			tick_broadcast_enter();
+		else
+			tick_broadcast_exit();
 	}
 }
 
#13 lore raw

PATCH 13/20 intel_idle: Use explicit broadcast oneshot control function

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Replace the clockevents_notify() call with an explicit function call.

---
 drivers/idle/intel_idle.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/idle/intel_idle.c +2 -2
Index: linux-pm/drivers/idle/intel_idle.c
===================================================================
@@ -638,12 +638,12 @@ static int intel_idle(struct cpuidle_dev
 		leave_mm(cpu);
 
 	if (!(lapic_timer_reliable_states & (1 << (cstate))))
-		clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &cpu);
+		tick_broadcast_enter();
 
 	mwait_idle_with_hints(eax, ecx);
 
 	if (!(lapic_timer_reliable_states & (1 << (cstate))))
-		clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &cpu);
+		tick_broadcast_exit();
 
 	return index;
 }
#14 lore raw

PATCH 14/20 ARM: OMAP: Use explicit broadcast oneshot control function

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Replace the clockevents_notify() call with an explicit function call.

---
 arch/arm/mach-omap2/cpuidle44xx.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
arch/arm/mach-omap2/cpuidle44xx.c +2 -3
Index: linux-pm/arch/arm/mach-omap2/cpuidle44xx.c
===================================================================
@@ -83,7 +83,6 @@ static int omap_enter_idle_coupled(struc
 {
 	struct idle_statedata *cx = state_ptr + index;
 	u32 mpuss_can_lose_context = 0;
-	int cpu_id = smp_processor_id();
 
 	/*
 	 * CPU0 has to wait and stay ON until CPU1 is OFF state.
@@ -111,7 +110,7 @@ static int omap_enter_idle_coupled(struc
 	mpuss_can_lose_context = (cx->mpu_state == PWRDM_POWER_RET) &&
 				 (cx->mpu_logic_state == PWRDM_POWER_OFF);
 
-	clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &cpu_id);
+	tick_broadcast_enter();
 
 	/*
 	 * Call idle CPU PM enter notifier chain so that
@@ -168,7 +167,7 @@ static int omap_enter_idle_coupled(struc
 	if (dev->cpu == 0 && mpuss_can_lose_context)
 		cpu_cluster_pm_exit();
 
-	clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &cpu_id);
+	tick_broadcast_exit();
 
 fail:
 	cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
#15 lore raw

PATCH 15/20 ARM: tegra: Use explicit broadcast oneshot control function

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Replace the clockevents_notify() call with an explicit function call.

Cc Stephen Warren <[email protected]>
Cc Thierry Reding <[email protected]>
Cc Alexandre Courbot <[email protected]>
---
 arch/arm/mach-tegra/cpuidle-tegra114.c |    6 +++---
 arch/arm/mach-tegra/cpuidle-tegra20.c  |   10 +++++-----
 arch/arm/mach-tegra/cpuidle-tegra30.c  |   10 +++++-----
 3 files changed, 13 insertions(+), 13 deletions(-)
arch/arm/mach-tegra/cpuidle-tegra114.c +3 -3
Index: linux-pm/arch/arm/mach-tegra/cpuidle-tegra114.c
===================================================================
@@ -15,7 +15,7 @@
  */
 
 #include <asm/firmware.h>
-#include <linux/clockchips.h>
+#include <linux/tick.h>
 #include <linux/cpuidle.h>
 #include <linux/cpu_pm.h>
 #include <linux/kernel.h>
@@ -44,7 +44,7 @@ static int tegra114_idle_power_down(stru
 	tegra_set_cpu_in_lp2();
 	cpu_pm_enter();
 
-	clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &dev->cpu);
+	tick_broadcast_enter();
 
 	call_firmware_op(prepare_idle);
 
@@ -52,7 +52,7 @@ static int tegra114_idle_power_down(stru
 	if (call_firmware_op(do_idle, 0) == -ENOSYS)
 		cpu_suspend(0, tegra30_sleep_cpu_secondary_finish);
 
-	clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &dev->cpu);
+	tick_broadcast_exit();
 
 	cpu_pm_exit();
 	tegra_clear_cpu_in_lp2();
arch/arm/mach-tegra/cpuidle-tegra20.c +5 -5
Index: linux-pm/arch/arm/mach-tegra/cpuidle-tegra20.c
===================================================================
@@ -20,7 +20,7 @@
  */
 
 #include <linux/clk/tegra.h>
-#include <linux/clockchips.h>
+#include <linux/tick.h>
 #include <linux/cpuidle.h>
 #include <linux/cpu_pm.h>
 #include <linux/kernel.h>
@@ -135,11 +135,11 @@ static bool tegra20_cpu_cluster_power_do
 	if (tegra20_reset_cpu_1() || !tegra_cpu_rail_off_ready())
 		return false;
 
-	clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &dev->cpu);
+	tick_broadcast_enter();
 
 	tegra_idle_lp2_last();
 
-	clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &dev->cpu);
+	tick_broadcast_exit();
 
 	if (cpu_online(1))
 		tegra20_wake_cpu1_from_reset();
@@ -152,13 +152,13 @@ static bool tegra20_idle_enter_lp2_cpu_1
 					 struct cpuidle_driver *drv,
 					 int index)
 {
-	clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &dev->cpu);
+	tick_broadcast_enter();
 
 	cpu_suspend(0, tegra20_sleep_cpu_secondary_finish);
 
 	tegra20_cpu_clear_resettable();
 
-	clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &dev->cpu);
+	tick_broadcast_exit();
 
 	return true;
 }
arch/arm/mach-tegra/cpuidle-tegra30.c +5 -5
Index: linux-pm/arch/arm/mach-tegra/cpuidle-tegra30.c
===================================================================
@@ -20,7 +20,7 @@
  */
 
 #include <linux/clk/tegra.h>
-#include <linux/clockchips.h>
+#include <linux/tick.h>
 #include <linux/cpuidle.h>
 #include <linux/cpu_pm.h>
 #include <linux/kernel.h>
@@ -75,11 +75,11 @@ static bool tegra30_cpu_cluster_power_do
 		return false;
 	}
 
-	clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &dev->cpu);
+	tick_broadcast_enter();
 
 	tegra_idle_lp2_last();
 
-	clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &dev->cpu);
+	tick_broadcast_exit();
 
 	return true;
 }
@@ -89,13 +89,13 @@ static bool tegra30_cpu_core_power_down(
 					struct cpuidle_driver *drv,
 					int index)
 {
-	clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &dev->cpu);
+	tick_broadcast_enter();
 
 	smp_wmb();
 
 	cpu_suspend(0, tegra30_sleep_cpu_secondary_finish);
 
-	clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &dev->cpu);
+	tick_broadcast_exit();
 
 	return true;
 }
#16 lore raw

PATCH 16/20 sched/idle: Use explicit broadcast oneshot control function

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Replace the clockevents_notify() call with an explicit function call.

---
 kernel/sched/idle.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
kernel/sched/idle.c +2 -3
Index: linux-pm/kernel/sched/idle.c
===================================================================
@@ -158,8 +158,7 @@ static void cpuidle_idle_call(void)
 	 * is used from another cpu as a broadcast timer, this call may
 	 * fail if it is not available
 	 */
-	if (broadcast &&
-	    clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &dev->cpu))
+	if (broadcast && tick_broadcast_enter())
 		goto use_default;
 
 	/* Take note of the planned idle state. */
@@ -176,7 +175,7 @@ static void cpuidle_idle_call(void)
 	idle_set_state(this_rq(), NULL);
 
 	if (broadcast)
-		clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &dev->cpu);
+		tick_broadcast_exit();
 
 	/*
 	 * Give the governor an opportunity to reflect on the outcome
#17 lore raw

Re: [PATCH 16/20] sched/idle: Use explicit broadcast oneshot control function

Quoted 6 lines · Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Replace the clockevents_notify() call with an explicit function call.

For some reason this makes my Ux500 system arbitrarily hang, especially during boot. Bisected down to this commit. Since the entire changeset is removing the notifications altogether I can't just revert it.

Disabling CONFIG_CPU_IDLE removes the problem.

Tried registering a stub driver (I just #if 0 all the code in drivers/cpuidle/cpuidle-ux500.c) it still crashes.

That makes me think something inside the cpuidle subsystem is locking up after this, but my other idea is that the timer may be involved in some way, like this is stressing the timer in some new yet untested way.

Has anyone else seen problems with this or is it only ux500?

I'm looking closer at it but feel a bit clueless...

Yours,
Linus Walleij

#18 lore raw

Re: [PATCH 16/20] sched/idle: Use explicit broadcast oneshot control function

Quoted 24 lines · Linus Walleij
Quoted 6 lines · Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Replace the clockevents_notify() call with an explicit function call.

For some reason this makes my Ux500 system arbitrarily hang, especially during boot. Bisected down to this commit. Since the entire changeset is removing the notifications altogether I can't just revert it.

Disabling CONFIG_CPU_IDLE removes the problem.

Tried registering a stub driver (I just #if 0 all the code in drivers/cpuidle/cpuidle-ux500.c) it still crashes.

That makes me think something inside the cpuidle subsystem is locking up after this, but my other idea is that the timer may be involved in some way, like this is stressing the timer in some new yet untested way.

Quoted 5 lines

Has anyone else seen problems with this or is it only ux500?

I'm looking closer at it but feel a bit clueless...

Yes I am too in similar situation with my Vexpress platform. I did report with the lockdep logs[1] before v4.1-rc1. I still see the issue with v4.1-rc1.

Regards,
Sudeep

[1] https://lkml.org/lkml/2015/4/23/329

#19 lore raw

Re: [PATCH 16/20] sched/idle: Use explicit broadcast oneshot control function

In reply to Linus Walleij
Quoted 24 lines · Linus Walleij
Quoted 6 lines · Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Replace the clockevents_notify() call with an explicit function call.

For some reason this makes my Ux500 system arbitrarily hang, especially during boot. Bisected down to this commit. Since the entire changeset is removing the notifications altogether I can't just revert it.

Disabling CONFIG_CPU_IDLE removes the problem.

Tried registering a stub driver (I just #if 0 all the code in drivers/cpuidle/cpuidle-ux500.c) it still crashes.

That makes me think something inside the cpuidle subsystem is locking up after this, but my other idea is that the timer may be involved in some way, like this is stressing the timer in some new yet untested way.

Quoted 4 lines

Has anyone else seen problems with this or is it only ux500?

I'm looking closer at it but feel a bit clueless...

If you keep the #if 0 and remove the CPUIDLE_FLAG_TIMER_STOP flag, does it still crash ?

Quoted 4 lines

To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 10 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

--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#20 lore raw

Re: [PATCH 16/20] sched/idle: Use explicit broadcast oneshot control function

Quoted 27 lines · Daniel Lezcano
Quoted 26 lines · Linus Walleij
Quoted 7 lines · Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Replace the clockevents_notify() call with an explicit function call.

For some reason this makes my Ux500 system arbitrarily hang, especially during boot. Bisected down to this commit. Since the entire changeset is removing the notifications altogether I can't just revert it.

Disabling CONFIG_CPU_IDLE removes the problem.

Tried registering a stub driver (I just #if 0 all the code in drivers/cpuidle/cpuidle-ux500.c) it still crashes.

That makes me think something inside the cpuidle subsystem is locking up after this, but my other idea is that the timer may be involved in some way, like this is stressing the timer in some new yet untested way.

Quoted 7 lines
Quoted 3 lines

Has anyone else seen problems with this or is it only ux500?

I'm looking closer at it but feel a bit clueless...

If you keep the #if 0 and remove the CPUIDLE_FLAG_TIMER_STOP flag, does it still crash ?

At-least I observed issue only when I am using hardware broadcast timer. It doesn't hang when I am using hrtimer as broadcast timer in which case one of the cpu will be not enter deeper idle states that lose timer. I will rerun on v4.1-rc1 and post the complete log.

Regards,
Sudeep

#21 lore raw

Re: [PATCH 16/20] sched/idle: Use explicit broadcast oneshot control function

Quoted 38 lines · Sudeep Holla
Quoted 35 lines · Daniel Lezcano
Quoted 31 lines · Linus Walleij
Quoted 7 lines · Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Replace the clockevents_notify() call with an explicit function call.

For some reason this makes my Ux500 system arbitrarily hang, especially during boot. Bisected down to this commit. Since the entire changeset is removing the notifications altogether I can't just revert it.

Disabling CONFIG_CPU_IDLE removes the problem.

Tried registering a stub driver (I just #if 0 all the code in drivers/cpuidle/cpuidle-ux500.c) it still crashes.

That makes me think something inside the cpuidle subsystem is locking up after this, but my other idea is that the timer may be involved in some way, like this is stressing the timer in some new yet untested way.

Has anyone else seen problems with this or is it only ux500?

I'm looking closer at it but feel a bit clueless...

Quoted 8 lines
Quoted 3 lines

If you keep the #if 0 and remove the CPUIDLE_FLAG_TIMER_STOP flag, does it still crash ?

At-least I observed issue only when I am using hardware broadcast timer. It doesn't hang when I am using hrtimer as broadcast timer in which case one of the cpu will be not enter deeper idle states that lose timer. I will rerun on v4.1-rc1 and post the complete log.

So the bug here is that cpuidle_enter() enables interrupts, so the assumption about them being not enabled made by tick_broadcast_oneshot_control() is actually not valid.

It looks like we need to acquire the clockevents_lock at least in this particular case. Let me see where to put it and I'll send a patch for testing.

Rafael

#22 lore raw

Re: [PATCH 16/20] sched/idle: Use explicit broadcast oneshot control function

Quoted 6 lines · Rafael J. Wysocki

Sudeep:

Quoted 4 lines

At-least I observed issue only when I am using hardware broadcast timer. It doesn't hang when I am using hrtimer as broadcast timer in which case one of the cpu will be not enter deeper idle states that lose timer. I will rerun on v4.1-rc1 and post the complete log.

Quoted 7 lines

So the bug here is that cpuidle_enter() enables interrupts, so the assumption about them being not enabled made by tick_broadcast_oneshot_control() is actually not valid.

It looks like we need to acquire the clockevents_lock at least in this particular case. Let me see where to put it and I'll send a patch for testing.

Aha that looks very much like it. Put me on the patch and I'll take it for a spin.

Yours,
Linus Walleij

#23 lore raw

Re: [PATCH 16/20] sched/idle: Use explicit broadcast oneshot control function

Quoted 11 lines · Linus Walleij
Quoted 10 lines · Rafael J. Wysocki

Sudeep:

Quoted 4 lines

At-least I observed issue only when I am using hardware broadcast timer. It doesn't hang when I am using hrtimer as broadcast timer in which case one of the cpu will be not enter deeper idle states that lose timer. I will rerun on v4.1-rc1 and post the complete log.

So the bug here is that cpuidle_enter() enables interrupts, so the assumption about them being not enabled made by tick_broadcast_oneshot_control() is actually not valid.

Quoted 6 lines
Quoted 3 lines

It looks like we need to acquire the clockevents_lock at least in this particular case. Let me see where to put it and I'll send a patch for testing.

Aha that looks very much like it. Put me on the patch and I'll take it for a spin.

OK, so something like the below for starters (the _irqsave variant is used to avoid adding one more WARN_ON(irqs_disabled()) in there).

I haven't tested it, but then I can't reproduce the original issue in the first place.

---
 include/linux/clockchips.h |    2 ++
 kernel/sched/idle.c        |    2 +-
 kernel/time/clockevents.c  |   15 +++++++++++++++
 3 files changed, 18 insertions(+), 1 deletion(-)
include/linux/clockchips.h +2 -0
Index: linux-pm/include/linux/clockchips.h
===================================================================
@@ -198,9 +198,11 @@ extern int tick_receive_broadcast(void);
 # if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
 extern void tick_setup_hrtimer_broadcast(void);
 extern int tick_check_broadcast_expired(void);
+extern void tick_broadcast_exit_idle(void);
 # else
 static inline int tick_check_broadcast_expired(void) { return 0; }
 static inline void tick_setup_hrtimer_broadcast(void) { }
+static inline void tick_broadcast_exit_idle(void) { }
 # endif
 
 extern int clockevents_notify(unsigned long reason, void *arg);
kernel/time/clockevents.c +15 -0
Index: linux-pm/kernel/time/clockevents.c
===================================================================
@@ -735,6 +735,21 @@ static ssize_t sysfs_unbind_tick_dev(str
 static DEVICE_ATTR(unbind_device, 0200, NULL, sysfs_unbind_tick_dev);
 
 #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
+/**
+ * tick_broadcast_exit_idle - Broadcast oneshot mode exit for the idle loop.
+ *
+ * The idle loop exits the broadcast oneshot mode with interrupts enabled, so
+ * clockevents_lock needs to be acquired around that.
+ */
+void tick_broadcast_exit_idle(void)
+{
+	unsigned long flags;
+
+	raw_spin_lock_irqsave(&clockevents_lock, flags);
+	tick_broadcast_exit();
+	raw_spin_unlock_irqrestore(&clockevents_lock, flags);
+}
+
 static struct device tick_bc_dev = {
 	.init_name	= "broadcast",
 	.id		= 0,
kernel/sched/idle.c +1 -1
Index: linux-pm/kernel/sched/idle.c
===================================================================
@@ -175,7 +175,7 @@ static void cpuidle_idle_call(void)
 	idle_set_state(this_rq(), NULL);
 
 	if (broadcast)
-		tick_broadcast_exit();
+		tick_broadcast_exit_idle();
 
 	/*
 	 * Give the governor an opportunity to reflect on the outcome
#24 lore raw

Re: [PATCH 16/20] sched/idle: Use explicit broadcast oneshot control function

Quoted 16 lines · Rafael J. Wysocki
Quoted 15 lines · Linus Walleij
Quoted 13 lines · Rafael J. Wysocki

Sudeep:

Quoted 4 lines

At-least I observed issue only when I am using hardware broadcast timer. It doesn't hang when I am using hrtimer as broadcast timer in which case one of the cpu will be not enter deeper idle states that lose timer. I will rerun on v4.1-rc1 and post the complete log.

So the bug here is that cpuidle_enter() enables interrupts, so the assumption about them being not enabled made by tick_broadcast_oneshot_control() is actually not valid.

It looks like we need to acquire the clockevents_lock at least in this particular case. Let me see where to put it and I'll send a patch for testing.

Quoted 8 lines
Quoted 2 lines

Aha that looks very much like it. Put me on the patch and I'll take it for a spin.

OK, so something like the below for starters (the _irqsave variant is used to avoid adding one more WARN_ON(irqs_disabled()) in there).

I haven't tested it, but then I can't reproduce the original issue in the first place.

Of course, the whole "broadcast" thing could be done from cpuidle_enter() in the first place, but then we could not avoid the problem with the cpuidle *callback* enabling interrupts possibly in there anyway (not to mention the "coupled" stuff).

Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
#25 lore raw

Re: [PATCH 16/20] sched/idle: Use explicit broadcast oneshot control function

Quoted 23 lines · Rafael J. Wysocki
Quoted 22 lines · Rafael J. Wysocki
Quoted 11 lines · Linus Walleij
Quoted 10 lines · Rafael J. Wysocki

Sudeep:

Quoted 4 lines

At-least I observed issue only when I am using hardware broadcast timer. It doesn't hang when I am using hrtimer as broadcast timer in which case one of the cpu will be not enter deeper idle states that lose timer. I will rerun on v4.1-rc1 and post the complete log.

So the bug here is that cpuidle_enter() enables interrupts, so the assumption about them being not enabled made by tick_broadcast_oneshot_control() is actually not valid.

Quoted 6 lines
Quoted 3 lines

It looks like we need to acquire the clockevents_lock at least in this particular case. Let me see where to put it and I'll send a patch for testing.

Aha that looks very much like it. Put me on the patch and I'll take it for a spin.

OK, so something like the below for starters (the _irqsave variant is used to avoid adding one more WARN_ON(irqs_disabled()) in there).

Quoted 7 lines
Quoted 2 lines

I haven't tested it, but then I can't reproduce the original issue in the first place.

Of course, the whole "broadcast" thing could be done from cpuidle_enter() in the first place, but then we could not avoid the problem with the cpuidle *callback* enabling interrupts possibly in there anyway (not to mention the "coupled" stuff).

That said, if the given state is marked with CPUIDLE_FLAG_TIMER_STOP, I really wouldn't expect it to re-enable interrupts on exit and the "coupled" thing seems to be fundamentally at odds with that flag either.

So it should be possible to move the "broadcast" logic into the cpuidle layer, which I'm going to try to do.

Please test the patch I've sent, though, as it should bring the code back to where it was before the clockevents_notify() removal and it'd be good to verify that.

Rafael

#26 lore raw

Re: [PATCH 16/20] sched/idle: Use explicit broadcast oneshot control function

Quoted 32 lines · Rafael J. Wysocki
Quoted 23 lines · Rafael J. Wysocki
Quoted 22 lines · Rafael J. Wysocki
Quoted 11 lines · Linus Walleij
Quoted 10 lines · Rafael J. Wysocki

Sudeep:

Quoted 4 lines

At-least I observed issue only when I am using hardware broadcast timer. It doesn't hang when I am using hrtimer as broadcast timer in which case one of the cpu will be not enter deeper idle states that lose timer. I will rerun on v4.1-rc1 and post the complete log.

So the bug here is that cpuidle_enter() enables interrupts, so the assumption about them being not enabled made by tick_broadcast_oneshot_control() is actually not valid.

Quoted 6 lines
Quoted 3 lines

It looks like we need to acquire the clockevents_lock at least in this particular case. Let me see where to put it and I'll send a patch for testing.

Aha that looks very much like it. Put me on the patch and I'll take it for a spin.

OK, so something like the below for starters (the _irqsave variant is used to avoid adding one more WARN_ON(irqs_disabled()) in there).

Quoted 7 lines
Quoted 2 lines

I haven't tested it, but then I can't reproduce the original issue in the first place.

Of course, the whole "broadcast" thing could be done from cpuidle_enter() in the first place, but then we could not avoid the problem with the cpuidle *callback* enabling interrupts possibly in there anyway (not to mention the "coupled" stuff).

Quoted 7 lines

That said, if the given state is marked with CPUIDLE_FLAG_TIMER_STOP, I really wouldn't expect it to re-enable interrupts on exit and the "coupled" thing seems to be fundamentally at odds with that flag either.

So it should be possible to move the "broadcast" logic into the cpuidle layer, which I'm going to try to do.

Makes sense.

Quoted 4 lines

Please test the patch I've sent, though, as it should bring the code back to where it was before the clockevents_notify() removal and it'd be good to verify that.

I tested your patch and it works now. Anyways I am continuing to run stress tests on my board. I will report if I find any issues.

Regards,
Sudeep

#27 lore raw

Re: [PATCH 16/20] sched/idle: Use explicit broadcast oneshot control function

Quoted 44 lines · Sudeep Holla
Quoted 32 lines · Rafael J. Wysocki
Quoted 23 lines · Rafael J. Wysocki
Quoted 22 lines · Rafael J. Wysocki
Quoted 11 lines · Linus Walleij
Quoted 10 lines · Rafael J. Wysocki

Sudeep:

Quoted 4 lines

At-least I observed issue only when I am using hardware broadcast timer. It doesn't hang when I am using hrtimer as broadcast timer in which case one of the cpu will be not enter deeper idle states that lose timer. I will rerun on v4.1-rc1 and post the complete log.

So the bug here is that cpuidle_enter() enables interrupts, so the assumption about them being not enabled made by tick_broadcast_oneshot_control() is actually not valid.

Quoted 6 lines
Quoted 3 lines

It looks like we need to acquire the clockevents_lock at least in this particular case. Let me see where to put it and I'll send a patch for testing.

Aha that looks very much like it. Put me on the patch and I'll take it for a spin.

OK, so something like the below for starters (the _irqsave variant is used to avoid adding one more WARN_ON(irqs_disabled()) in there).

Quoted 7 lines
Quoted 2 lines

I haven't tested it, but then I can't reproduce the original issue in the first place.

Of course, the whole "broadcast" thing could be done from cpuidle_enter() in the first place, but then we could not avoid the problem with the cpuidle *callback* enabling interrupts possibly in there anyway (not to mention the "coupled" stuff).

Quoted 7 lines

That said, if the given state is marked with CPUIDLE_FLAG_TIMER_STOP, I really wouldn't expect it to re-enable interrupts on exit and the "coupled" thing seems to be fundamentally at odds with that flag either.

So it should be possible to move the "broadcast" logic into the cpuidle layer, which I'm going to try to do.

Makes sense.

Quoted 7 lines
Quoted 4 lines

Please test the patch I've sent, though, as it should bring the code back to where it was before the clockevents_notify() removal and it'd be good to verify that.

I tested your patch and it works now. Anyways I am continuing to run stress tests on my board. I will report if I find any issues.

Great, thanks!

Below is the patch I came up with in the meantime.

This moves the "switch to broadcast" timer logic into cpuidle_enter_state() which allows tick_broadcast_exit() to be called directly with interrupts disabled (as required), but it also adds a fallback branch reflecting the 4.0 and earlier behavior for idle states that enable interrupts on exit from their ->enter callbacks.

I'm not aware of any valid cases when CPUIDLE_FLAG_TIMER_STOP can be set for such states, but people may try to add stuff like that in the future, so it's better to catch that (hence the WARN_ON_ONCE) and do our best to handle it gracefully anyway, IMO.

The "if (entered_state == -EBUSY)" check is conservative. It may be better to do "if (entered_state < 0)" and fall back to the default on all errors, but that's not what we do today (I guess the concern would be "what if the state ->enter returns an error after entering and exiting the idle state, in which case we may miss a wakeup event if we fall back to the default").

---
 drivers/cpuidle/cpuidle.c  |   16 ++++++++++++++++
 include/linux/clockchips.h |    2 ++
 kernel/sched/idle.c        |   16 ++--------------
 kernel/time/clockevents.c  |   13 +++++++++++++
 4 files changed, 33 insertions(+), 14 deletions(-)
include/linux/clockchips.h +2 -0
Index: linux-pm/include/linux/clockchips.h
===================================================================
@@ -198,9 +198,11 @@ extern int tick_receive_broadcast(void);
 # if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
 extern void tick_setup_hrtimer_broadcast(void);
 extern int tick_check_broadcast_expired(void);
+extern void tick_broadcast_exit_idle_fallback(void);
 # else
 static inline int tick_check_broadcast_expired(void) { return 0; }
 static inline void tick_setup_hrtimer_broadcast(void) { }
+static inline void tick_broadcast_exit_idle_fallback(void) { }
 # endif
 
 extern int clockevents_notify(unsigned long reason, void *arg);
kernel/time/clockevents.c +13 -0
Index: linux-pm/kernel/time/clockevents.c
===================================================================
@@ -735,6 +735,19 @@ static ssize_t sysfs_unbind_tick_dev(str
 static DEVICE_ATTR(unbind_device, 0200, NULL, sysfs_unbind_tick_dev);
 
 #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
+/**
+ * tick_broadcast_exit_idle_fallback - Fallback broadcast oneshot mode exit.
+ *
+ * Called from within the CPU idle subsystem when exiting the broadcast oneshot
+ * mode with interrupts enabled (fallback case only).
+ */
+void tick_broadcast_exit_idle_fallback(void)
+{
+	raw_spin_lock_irq(&clockevents_lock);
+	tick_broadcast_exit();
+	raw_spin_unlock_irq(&clockevents_lock);
+}
+
 static struct device tick_bc_dev = {
 	.init_name	= "broadcast",
 	.id		= 0,
kernel/sched/idle.c +2 -14
Index: linux-pm/kernel/sched/idle.c
===================================================================
@@ -81,7 +81,6 @@ static void cpuidle_idle_call(void)
 	struct cpuidle_device *dev = __this_cpu_read(cpuidle_devices);
 	struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev);
 	int next_state, entered_state;
-	unsigned int broadcast;
 	bool reflect;
 
 	/*
@@ -150,17 +149,6 @@ static void cpuidle_idle_call(void)
 		goto exit_idle;
 	}
 
-	broadcast = drv->states[next_state].flags & CPUIDLE_FLAG_TIMER_STOP;
-
-	/*
-	 * Tell the time framework to switch to a broadcast timer
-	 * because our local timer will be shutdown. If a local timer
-	 * is used from another cpu as a broadcast timer, this call may
-	 * fail if it is not available
-	 */
-	if (broadcast && tick_broadcast_enter())
-		goto use_default;
-
 	/* Take note of the planned idle state. */
 	idle_set_state(this_rq(), &drv->states[next_state]);
 
@@ -174,8 +162,8 @@ static void cpuidle_idle_call(void)
 	/* The cpu is no longer idle or about to enter idle. */
 	idle_set_state(this_rq(), NULL);
 
-	if (broadcast)
-		tick_broadcast_exit();
+	if (entered_state == -EBUSY)
+		goto use_default;
 
 	/*
 	 * Give the governor an opportunity to reflect on the outcome
drivers/cpuidle/cpuidle.c +16 -0
Index: linux-pm/drivers/cpuidle/cpuidle.c
===================================================================
@@ -158,9 +158,18 @@ int cpuidle_enter_state(struct cpuidle_d
 	int entered_state;
 
 	struct cpuidle_state *target_state = &drv->states[index];
+	bool broadcast = !!(target_state->flags & CPUIDLE_FLAG_TIMER_STOP);
 	ktime_t time_start, time_end;
 	s64 diff;
 
+	/*
+	 * Tell the time framework to switch to a broadcast timer because our
+	 * local timer will be shut down.  If a local timer is used from another
+	 * CPU as a broadcast timer, this call may fail if it is not available.
+	 */
+	if (broadcast && tick_broadcast_enter())
+		return -EBUSY;
+
 	trace_cpu_idle_rcuidle(index, dev->cpu);
 	time_start = ktime_get();
 
@@ -169,6 +178,13 @@ int cpuidle_enter_state(struct cpuidle_d
 	time_end = ktime_get();
 	trace_cpu_idle_rcuidle(PWR_EVENT_EXIT, dev->cpu);
 
+	if (broadcast) {
+		if (WARN_ON_ONCE(!irqs_disabled()))
+			tick_broadcast_exit_idle_fallback();
+		else
+			tick_broadcast_exit();
+	}
+
 	if (!cpuidle_state_is_coupled(dev, drv, entered_state))
 		local_irq_enable();
 
#28 lore raw

Re: [PATCH 16/20] sched/idle: Use explicit broadcast oneshot control function

Quoted 69 lines · Rafael J. Wysocki
Quoted 44 lines · Sudeep Holla
Quoted 32 lines · Rafael J. Wysocki
Quoted 23 lines · Rafael J. Wysocki
Quoted 22 lines · Rafael J. Wysocki
Quoted 11 lines · Linus Walleij
Quoted 10 lines · Rafael J. Wysocki

Sudeep:

Quoted 4 lines

At-least I observed issue only when I am using hardware broadcast timer. It doesn't hang when I am using hrtimer as broadcast timer in which case one of the cpu will be not enter deeper idle states that lose timer. I will rerun on v4.1-rc1 and post the complete log.

So the bug here is that cpuidle_enter() enables interrupts, so the assumption about them being not enabled made by tick_broadcast_oneshot_control() is actually not valid.

Quoted 6 lines
Quoted 3 lines

It looks like we need to acquire the clockevents_lock at least in this particular case. Let me see where to put it and I'll send a patch for testing.

Aha that looks very much like it. Put me on the patch and I'll take it for a spin.

OK, so something like the below for starters (the _irqsave variant is used to avoid adding one more WARN_ON(irqs_disabled()) in there).

Quoted 7 lines
Quoted 2 lines

I haven't tested it, but then I can't reproduce the original issue in the first place.

Of course, the whole "broadcast" thing could be done from cpuidle_enter() in the first place, but then we could not avoid the problem with the cpuidle *callback* enabling interrupts possibly in there anyway (not to mention the "coupled" stuff).

Quoted 7 lines

That said, if the given state is marked with CPUIDLE_FLAG_TIMER_STOP, I really wouldn't expect it to re-enable interrupts on exit and the "coupled" thing seems to be fundamentally at odds with that flag either.

So it should be possible to move the "broadcast" logic into the cpuidle layer, which I'm going to try to do.

Makes sense.

Quoted 7 lines
Quoted 4 lines

Please test the patch I've sent, though, as it should bring the code back to where it was before the clockevents_notify() removal and it'd be good to verify that.

I tested your patch and it works now. Anyways I am continuing to run stress tests on my board. I will report if I find any issues.

Great, thanks!

Below is the patch I came up with in the meantime.

This moves the "switch to broadcast" timer logic into cpuidle_enter_state() which allows tick_broadcast_exit() to be called directly with interrupts disabled (as required), but it also adds a fallback branch reflecting the 4.0 and earlier behavior for idle states that enable interrupts on exit from their ->enter callbacks.

I'm not aware of any valid cases when CPUIDLE_FLAG_TIMER_STOP can be set for such states, but people may try to add stuff like that in the future, so it's better to catch that (hence the WARN_ON_ONCE) and do our best to handle it gracefully anyway, IMO.

Quoted 6 lines

The "if (entered_state == -EBUSY)" check is conservative. It may be better to do "if (entered_state < 0)" and fall back to the default on all errors, but that's not what we do today (I guess the concern would be "what if the state ->enter returns an error after entering and exiting the idle state, in which case we may miss a wakeup event if we fall back to the default").

Actually, if my understanding of things is correct (the local clock event device cannot go away from under code executed with interrupts disabled on the local CPU), the simplified one below should be sufficient.

---
 drivers/cpuidle/cpuidle.c |   16 ++++++++++++++++
 kernel/sched/idle.c       |   16 ++--------------
 2 files changed, 18 insertions(+), 14 deletions(-)
kernel/sched/idle.c +2 -14
Index: linux-pm/kernel/sched/idle.c
===================================================================
@@ -81,7 +81,6 @@ static void cpuidle_idle_call(void)
 	struct cpuidle_device *dev = __this_cpu_read(cpuidle_devices);
 	struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev);
 	int next_state, entered_state;
-	unsigned int broadcast;
 	bool reflect;
 
 	/*
@@ -150,17 +149,6 @@ static void cpuidle_idle_call(void)
 		goto exit_idle;
 	}
 
-	broadcast = drv->states[next_state].flags & CPUIDLE_FLAG_TIMER_STOP;
-
-	/*
-	 * Tell the time framework to switch to a broadcast timer
-	 * because our local timer will be shutdown. If a local timer
-	 * is used from another cpu as a broadcast timer, this call may
-	 * fail if it is not available
-	 */
-	if (broadcast && tick_broadcast_enter())
-		goto use_default;
-
 	/* Take note of the planned idle state. */
 	idle_set_state(this_rq(), &drv->states[next_state]);
 
@@ -174,8 +162,8 @@ static void cpuidle_idle_call(void)
 	/* The cpu is no longer idle or about to enter idle. */
 	idle_set_state(this_rq(), NULL);
 
-	if (broadcast)
-		tick_broadcast_exit();
+	if (entered_state == -EBUSY)
+		goto use_default;
 
 	/*
 	 * Give the governor an opportunity to reflect on the outcome
drivers/cpuidle/cpuidle.c +16 -0
Index: linux-pm/drivers/cpuidle/cpuidle.c
===================================================================
@@ -158,9 +158,18 @@ int cpuidle_enter_state(struct cpuidle_d
 	int entered_state;
 
 	struct cpuidle_state *target_state = &drv->states[index];
+	bool broadcast = !!(target_state->flags & CPUIDLE_FLAG_TIMER_STOP);
 	ktime_t time_start, time_end;
 	s64 diff;
 
+	/*
+	 * Tell the time framework to switch to a broadcast timer because our
+	 * local timer will be shut down.  If a local timer is used from another
+	 * CPU as a broadcast timer, this call may fail if it is not available.
+	 */
+	if (broadcast && tick_broadcast_enter())
+		return -EBUSY;
+
 	trace_cpu_idle_rcuidle(index, dev->cpu);
 	time_start = ktime_get();
 
@@ -169,6 +178,13 @@ int cpuidle_enter_state(struct cpuidle_d
 	time_end = ktime_get();
 	trace_cpu_idle_rcuidle(PWR_EVENT_EXIT, dev->cpu);
 
+	if (broadcast) {
+		if (WARN_ON_ONCE(!irqs_disabled()))
+			local_irq_disable();
+
+		tick_broadcast_exit();
+	}
+
 	if (!cpuidle_state_is_coupled(dev, drv, entered_state))
 		local_irq_enable();
 
Tested-by
#29 lore raw

Re: [PATCH 16/20] sched/idle: Use explicit broadcast oneshot control function

Quoted 23 lines · Rafael J. Wysocki
Quoted 14 lines · Rafael J. Wysocki

Below is the patch I came up with in the meantime.

This moves the "switch to broadcast" timer logic into cpuidle_enter_state() which allows tick_broadcast_exit() to be called directly with interrupts disabled (as required), but it also adds a fallback branch reflecting the 4.0 and earlier behavior for idle states that enable interrupts on exit from their ->enter callbacks.

I'm not aware of any valid cases when CPUIDLE_FLAG_TIMER_STOP can be set for such states, but people may try to add stuff like that in the future, so it's better to catch that (hence the WARN_ON_ONCE) and do our best to handle it gracefully anyway, IMO.

Quoted 6 lines

The "if (entered_state == -EBUSY)" check is conservative. It may be better to do "if (entered_state < 0)" and fall back to the default on all errors, but that's not what we do today (I guess the concern would be "what if the state ->enter returns an error after entering and exiting the idle state, in which case we may miss a wakeup event if we fall back to the default").

Quoted 3 lines

Actually, if my understanding of things is correct (the local clock event device cannot go away from under code executed with interrupts disabled on the local CPU), the simplified one below should be sufficient.

Rock solid, after this patch the issues are gone and system stable. Using it as stabilizer base for all v4.2 work now.

Excellent work Rafael!

Yours,
Linus Walleij

maintainer Acked-by
#30 lore raw

Re: [PATCH 16/20] sched/idle: Use explicit broadcast oneshot control function

In reply to Rafael J. Wysocki
Quoted 21 lines · Rafael J. Wysocki
Quoted 14 lines

Below is the patch I came up with in the meantime.

This moves the "switch to broadcast" timer logic into cpuidle_enter_state() which allows tick_broadcast_exit() to be called directly with interrupts disabled (as required), but it also adds a fallback branch reflecting the 4.0 and earlier behavior for idle states that enable interrupts on exit from their ->enter callbacks.

I'm not aware of any valid cases when CPUIDLE_FLAG_TIMER_STOP can be set for such states, but people may try to add stuff like that in the future, so it's better to catch that (hence the WARN_ON_ONCE) and do our best to handle it gracefully anyway, IMO.

Quoted 6 lines

The "if (entered_state == -EBUSY)" check is conservative. It may be better to do "if (entered_state < 0)" and fall back to the default on all errors, but that's not what we do today (I guess the concern would be "what if the state ->enter returns an error after entering and exiting the idle state, in which case we may miss a wakeup event if we fall back to the default").

Quoted 3 lines

Actually, if my understanding of things is correct (the local clock event device cannot go away from under code executed with interrupts disabled on the local CPU), the simplified one below should be sufficient.

Afaict both tick_broadcast_{enter,exit}() end up calling tick_broadcast_oneshot_control() which is serialized with the tick_broadcast_lock.

But yes, the local device is strictly managed from the local cpu, so any other CPU wanting to muck with it would have to IPI and therefore disabling the local IRQs would make it safe.

Quoted 84 lines
---
 drivers/cpuidle/cpuidle.c |   16 ++++++++++++++++
 kernel/sched/idle.c       |   16 ++--------------
 2 files changed, 18 insertions(+), 14 deletions(-)

Index: linux-pm/kernel/sched/idle.c
===================================================================

kernel/sched/idle.c +2 -14
@@ -81,7 +81,6 @@ static void cpuidle_idle_call(void)
 	struct cpuidle_device *dev = __this_cpu_read(cpuidle_devices);
 	struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev);
 	int next_state, entered_state;
-	unsigned int broadcast;
 	bool reflect;
 
 	/*
@@ -150,17 +149,6 @@ static void cpuidle_idle_call(void)
 		goto exit_idle;
 	}
 
-	broadcast = drv->states[next_state].flags & CPUIDLE_FLAG_TIMER_STOP;
-
-	/*
-	 * Tell the time framework to switch to a broadcast timer
-	 * because our local timer will be shutdown. If a local timer
-	 * is used from another cpu as a broadcast timer, this call may
-	 * fail if it is not available
-	 */
-	if (broadcast && tick_broadcast_enter())
-		goto use_default;
-
 	/* Take note of the planned idle state. */
 	idle_set_state(this_rq(), &drv->states[next_state]);
 
@@ -174,8 +162,8 @@ static void cpuidle_idle_call(void)
 	/* The cpu is no longer idle or about to enter idle. */
 	idle_set_state(this_rq(), NULL);
 
-	if (broadcast)
-		tick_broadcast_exit();
+	if (entered_state == -EBUSY)
+		goto use_default;
 
 	/*
 	 * Give the governor an opportunity to reflect on the outcome

Index: linux-pm/drivers/cpuidle/cpuidle.c
===================================================================

drivers/cpuidle/cpuidle.c +16 -0
@@ -158,9 +158,18 @@ int cpuidle_enter_state(struct cpuidle_d
 	int entered_state;
 
 	struct cpuidle_state *target_state = &drv->states[index];
+	bool broadcast = !!(target_state->flags & CPUIDLE_FLAG_TIMER_STOP);
 	ktime_t time_start, time_end;
 	s64 diff;
 
+	/*
+	 * Tell the time framework to switch to a broadcast timer because our
+	 * local timer will be shut down.  If a local timer is used from another
+	 * CPU as a broadcast timer, this call may fail if it is not available.
+	 */
+	if (broadcast && tick_broadcast_enter())
+		return -EBUSY;
+
 	trace_cpu_idle_rcuidle(index, dev->cpu);
 	time_start = ktime_get();
 
@@ -169,6 +178,13 @@ int cpuidle_enter_state(struct cpuidle_d
 	time_end = ktime_get();
 	trace_cpu_idle_rcuidle(PWR_EVENT_EXIT, dev->cpu);
 
+	if (broadcast) {
+		if (WARN_ON_ONCE(!irqs_disabled()))
+			local_irq_disable();
+
+		tick_broadcast_exit();
+	}
+
 	if (!cpuidle_state_is_coupled(dev, drv, entered_state))
 		local_irq_enable();
 
#31 lore raw

Re: [PATCH 16/20] sched/idle: Use explicit broadcast oneshot control function

In reply to Rafael J. Wysocki
Quoted 77 lines · Rafael J. Wysocki
Quoted 69 lines · Rafael J. Wysocki
Quoted 44 lines · Sudeep Holla
Quoted 32 lines · Rafael J. Wysocki
Quoted 23 lines · Rafael J. Wysocki
Quoted 22 lines · Rafael J. Wysocki
Quoted 11 lines · Linus Walleij
Quoted 10 lines · Rafael J. Wysocki

Sudeep:

Quoted 4 lines

At-least I observed issue only when I am using hardware broadcast timer. It doesn't hang when I am using hrtimer as broadcast timer in which case one of the cpu will be not enter deeper idle states that lose timer. I will rerun on v4.1-rc1 and post the complete log.

So the bug here is that cpuidle_enter() enables interrupts, so the assumption about them being not enabled made by tick_broadcast_oneshot_control() is actually not valid.

Quoted 6 lines
Quoted 3 lines

It looks like we need to acquire the clockevents_lock at least in this particular case. Let me see where to put it and I'll send a patch for testing.

Aha that looks very much like it. Put me on the patch and I'll take it for a spin.

OK, so something like the below for starters (the _irqsave variant is used to avoid adding one more WARN_ON(irqs_disabled()) in there).

Quoted 7 lines
Quoted 2 lines

I haven't tested it, but then I can't reproduce the original issue in the first place.

Of course, the whole "broadcast" thing could be done from cpuidle_enter() in the first place, but then we could not avoid the problem with the cpuidle *callback* enabling interrupts possibly in there anyway (not to mention the "coupled" stuff).

Quoted 7 lines

That said, if the given state is marked with CPUIDLE_FLAG_TIMER_STOP, I really wouldn't expect it to re-enable interrupts on exit and the "coupled" thing seems to be fundamentally at odds with that flag either.

So it should be possible to move the "broadcast" logic into the cpuidle layer, which I'm going to try to do.

Makes sense.

Quoted 7 lines
Quoted 4 lines

Please test the patch I've sent, though, as it should bring the code back to where it was before the clockevents_notify() removal and it'd be good to verify that.

I tested your patch and it works now. Anyways I am continuing to run stress tests on my board. I will report if I find any issues.

Great, thanks!

Below is the patch I came up with in the meantime.

This moves the "switch to broadcast" timer logic into cpuidle_enter_state() which allows tick_broadcast_exit() to be called directly with interrupts disabled (as required), but it also adds a fallback branch reflecting the 4.0 and earlier behavior for idle states that enable interrupts on exit from their ->enter callbacks.

I'm not aware of any valid cases when CPUIDLE_FLAG_TIMER_STOP can be set for such states, but people may try to add stuff like that in the future, so it's better to catch that (hence the WARN_ON_ONCE) and do our best to handle it gracefully anyway, IMO.

Quoted 6 lines

The "if (entered_state == -EBUSY)" check is conservative. It may be better to do "if (entered_state < 0)" and fall back to the default on all errors, but that's not what we do today (I guess the concern would be "what if the state ->enter returns an error after entering and exiting the idle state, in which case we may miss a wakeup event if we fall back to the default").

Quoted 3 lines

Actually, if my understanding of things is correct (the local clock event device cannot go away from under code executed with interrupts disabled on the local CPU), the simplified one below should be sufficient.

Quoted 84 lines
---
  drivers/cpuidle/cpuidle.c |   16 ++++++++++++++++
  kernel/sched/idle.c       |   16 ++--------------
  2 files changed, 18 insertions(+), 14 deletions(-)

Index: linux-pm/kernel/sched/idle.c
===================================================================

kernel/sched/idle.c +2 -14
@@ -81,7 +81,6 @@ static void cpuidle_idle_call(void)
  	struct cpuidle_device *dev = __this_cpu_read(cpuidle_devices);
  	struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev);
  	int next_state, entered_state;
-	unsigned int broadcast;
  	bool reflect;
 
  	/*
@@ -150,17 +149,6 @@ static void cpuidle_idle_call(void)
  		goto exit_idle;
  	}
 
-	broadcast = drv->states[next_state].flags & CPUIDLE_FLAG_TIMER_STOP;
-
-	/*
-	 * Tell the time framework to switch to a broadcast timer
-	 * because our local timer will be shutdown. If a local timer
-	 * is used from another cpu as a broadcast timer, this call may
-	 * fail if it is not available
-	 */
-	if (broadcast && tick_broadcast_enter())
-		goto use_default;
-
  	/* Take note of the planned idle state. */
  	idle_set_state(this_rq(), &drv->states[next_state]);
 
@@ -174,8 +162,8 @@ static void cpuidle_idle_call(void)
  	/* The cpu is no longer idle or about to enter idle. */
  	idle_set_state(this_rq(), NULL);
 
-	if (broadcast)
-		tick_broadcast_exit();
+	if (entered_state == -EBUSY)
+		goto use_default;
 
  	/*
  	 * Give the governor an opportunity to reflect on the outcome

Index: linux-pm/drivers/cpuidle/cpuidle.c
===================================================================

drivers/cpuidle/cpuidle.c +16 -0
@@ -158,9 +158,18 @@ int cpuidle_enter_state(struct cpuidle_d
  	int entered_state;
 
  	struct cpuidle_state *target_state = &drv->states[index];
+	bool broadcast = !!(target_state->flags & CPUIDLE_FLAG_TIMER_STOP);
  	ktime_t time_start, time_end;
  	s64 diff;
 
+	/*
+	 * Tell the time framework to switch to a broadcast timer because our
+	 * local timer will be shut down.  If a local timer is used from another
+	 * CPU as a broadcast timer, this call may fail if it is not available.
+	 */
+	if (broadcast && tick_broadcast_enter())
+		return -EBUSY;
+
  	trace_cpu_idle_rcuidle(index, dev->cpu);
  	time_start = ktime_get();
 
@@ -169,6 +178,13 @@ int cpuidle_enter_state(struct cpuidle_d
  	time_end = ktime_get();
  	trace_cpu_idle_rcuidle(PWR_EVENT_EXIT, dev->cpu);
 
+	if (broadcast) {
+		if (WARN_ON_ONCE(!irqs_disabled()))
+			local_irq_disable();
+
+		tick_broadcast_exit();
+	}
+
  	if (!cpuidle_state_is_coupled(dev, drv, entered_state))
  		local_irq_enable();
 
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
Tested-by
#32 lore raw

Re: [PATCH 16/20] sched/idle: Use explicit broadcast oneshot control function

In reply to Rafael J. Wysocki

Hi Rafael,

Quoted 1 line · Rafael J. Wysocki

On Wednesday, April 29, 2015 02:50:22 AM Rafael J. Wysocki wrote:

[...]

Quoted 22 lines
Quoted 15 lines

Below is the patch I came up with in the meantime.

This moves the "switch to broadcast" timer logic into cpuidle_enter_state() which allows tick_broadcast_exit() to be called directly with interrupts disabled (as required), but it also adds a fallback branch reflecting the 4.0 and earlier behavior for idle states that enable interrupts on exit from their ->enter callbacks.

I'm not aware of any valid cases when CPUIDLE_FLAG_TIMER_STOP can be set for such states, but people may try to add stuff like that in the future, so it's better to catch that (hence the WARN_ON_ONCE) and do our best to handle it gracefully anyway, IMO.

Quoted 6 lines

The "if (entered_state == -EBUSY)" check is conservative. It may be better to do "if (entered_state < 0)" and fall back to the default on all errors, but that's not what we do today (I guess the concern would be "what if the state ->enter returns an error after entering and exiting the idle state, in which case we may miss a wakeup event if we fall back to the default").

Quoted 4 lines

Actually, if my understanding of things is correct (the local clock event device cannot go away from under code executed with interrupts disabled on the local CPU), the simplified one below should be sufficient.

Regards,
Sudeep

#33 lore raw

PATCH 1/1 cpuidle: Run tick_broadcast_exit() with disabled interrupts

From: Rafael J. Wysocki <[email protected]>

Commit 335f49196fd6 (sched/idle: Use explicit broadcast oneshot control function) replaced clockevents_notify() invocations in cpuidle_idle_call() with direct calls to tick_broadcast_enter() and tick_broadcast_exit(), but it overlooked the fact that interrupts were already enabled before calling the latter which led to functional breakage on systems using idle states with the CPUIDLE_FLAG_TIMER_STOP flag set.

Fix that by moving the invocations of tick_broadcast_enter() and tick_broadcast_exit() down into cpuidle_enter_state() where interrupts are still disabled when tick_broadcast_exit() is called. Also ensure that interrupts will be disabled before running tick_broadcast_exit() even if they have been enabled by the idle state's ->enter callback. Trigger a WARN_ON_ONCE() in that case, as we generally don't want that to happen for states with CPUIDLE_FLAG_TIMER_STOP set.

Fixes 335f49196fd6 (sched/idle: Use explicit broadcast oneshot control function)
Reported-and-tested-by Linus Walleij <[email protected]>
Reported-and-tested-by Sudeep Holla <[email protected]>

---

Thanks for the testing and ACKs, here it goes again with all tags and a changelog.

If anything is missing/incorrect, please let me know ASAP as I'm going to push this to Linus in a couple of days.

---
 drivers/cpuidle/cpuidle.c |   16 ++++++++++++++++
 kernel/sched/idle.c       |   16 ++--------------
 2 files changed, 18 insertions(+), 14 deletions(-)
kernel/sched/idle.c +2 -14
Index: linux-pm/kernel/sched/idle.c
===================================================================
@@ -81,7 +81,6 @@ static void cpuidle_idle_call(void)
 	struct cpuidle_device *dev = __this_cpu_read(cpuidle_devices);
 	struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev);
 	int next_state, entered_state;
-	unsigned int broadcast;
 	bool reflect;
 
 	/*
@@ -150,17 +149,6 @@ static void cpuidle_idle_call(void)
 		goto exit_idle;
 	}
 
-	broadcast = drv->states[next_state].flags & CPUIDLE_FLAG_TIMER_STOP;
-
-	/*
-	 * Tell the time framework to switch to a broadcast timer
-	 * because our local timer will be shutdown. If a local timer
-	 * is used from another cpu as a broadcast timer, this call may
-	 * fail if it is not available
-	 */
-	if (broadcast && tick_broadcast_enter())
-		goto use_default;
-
 	/* Take note of the planned idle state. */
 	idle_set_state(this_rq(), &drv->states[next_state]);
 
@@ -174,8 +162,8 @@ static void cpuidle_idle_call(void)
 	/* The cpu is no longer idle or about to enter idle. */
 	idle_set_state(this_rq(), NULL);
 
-	if (broadcast)
-		tick_broadcast_exit();
+	if (entered_state == -EBUSY)
+		goto use_default;
 
 	/*
 	 * Give the governor an opportunity to reflect on the outcome
drivers/cpuidle/cpuidle.c +16 -0
Index: linux-pm/drivers/cpuidle/cpuidle.c
===================================================================
@@ -158,9 +158,18 @@ int cpuidle_enter_state(struct cpuidle_d
 	int entered_state;
 
 	struct cpuidle_state *target_state = &drv->states[index];
+	bool broadcast = !!(target_state->flags & CPUIDLE_FLAG_TIMER_STOP);
 	ktime_t time_start, time_end;
 	s64 diff;
 
+	/*
+	 * Tell the time framework to switch to a broadcast timer because our
+	 * local timer will be shut down.  If a local timer is used from another
+	 * CPU as a broadcast timer, this call may fail if it is not available.
+	 */
+	if (broadcast && tick_broadcast_enter())
+		return -EBUSY;
+
 	trace_cpu_idle_rcuidle(index, dev->cpu);
 	time_start = ktime_get();
 
@@ -169,6 +178,13 @@ int cpuidle_enter_state(struct cpuidle_d
 	time_end = ktime_get();
 	trace_cpu_idle_rcuidle(PWR_EVENT_EXIT, dev->cpu);
 
+	if (broadcast) {
+		if (WARN_ON_ONCE(!irqs_disabled()))
+			local_irq_disable();
+
+		tick_broadcast_exit();
+	}
+
 	if (!cpuidle_state_is_coupled(dev, drv, entered_state))
 		local_irq_enable();
 
Reviewed-by on v1 1/1
#34 lore raw

Re: [PATCH][Fix] cpuidle: Run tick_broadcast_exit() with disabled interrupts

Quoted 106 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Commit 335f49196fd6 (sched/idle: Use explicit broadcast oneshot control function) replaced clockevents_notify() invocations in cpuidle_idle_call() with direct calls to tick_broadcast_enter() and tick_broadcast_exit(), but it overlooked the fact that interrupts were already enabled before calling the latter which led to functional breakage on systems using idle states with the CPUIDLE_FLAG_TIMER_STOP flag set.

Fix that by moving the invocations of tick_broadcast_enter() and tick_broadcast_exit() down into cpuidle_enter_state() where interrupts are still disabled when tick_broadcast_exit() is called. Also ensure that interrupts will be disabled before running tick_broadcast_exit() even if they have been enabled by the idle state's ->enter callback. Trigger a WARN_ON_ONCE() in that case, as we generally don't want that to happen for states with CPUIDLE_FLAG_TIMER_STOP set.

Fixes 335f49196fd6 (sched/idle: Use explicit broadcast oneshot control function)
Reported-and-tested-by Linus Walleij <[email protected]>
Reported-and-tested-by Sudeep Holla <[email protected]>

---

Thanks for the testing and ACKs, here it goes again with all tags and a changelog.

If anything is missing/incorrect, please let me know ASAP as I'm going to push this to Linus in a couple of days.

---
 drivers/cpuidle/cpuidle.c |   16 ++++++++++++++++
 kernel/sched/idle.c       |   16 ++--------------
 2 files changed, 18 insertions(+), 14 deletions(-)

Index: linux-pm/kernel/sched/idle.c
===================================================================

kernel/sched/idle.c +2 -14
@@ -81,7 +81,6 @@ static void cpuidle_idle_call(void)
 	struct cpuidle_device *dev = __this_cpu_read(cpuidle_devices);
 	struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev);
 	int next_state, entered_state;
-	unsigned int broadcast;
 	bool reflect;
 
 	/*
@@ -150,17 +149,6 @@ static void cpuidle_idle_call(void)
 		goto exit_idle;
 	}
 
-	broadcast = drv->states[next_state].flags & CPUIDLE_FLAG_TIMER_STOP;
-
-	/*
-	 * Tell the time framework to switch to a broadcast timer
-	 * because our local timer will be shutdown. If a local timer
-	 * is used from another cpu as a broadcast timer, this call may
-	 * fail if it is not available
-	 */
-	if (broadcast && tick_broadcast_enter())
-		goto use_default;
-
 	/* Take note of the planned idle state. */
 	idle_set_state(this_rq(), &drv->states[next_state]);
 
@@ -174,8 +162,8 @@ static void cpuidle_idle_call(void)
 	/* The cpu is no longer idle or about to enter idle. */
 	idle_set_state(this_rq(), NULL);
 
-	if (broadcast)
-		tick_broadcast_exit();
+	if (entered_state == -EBUSY)
+		goto use_default;
 
 	/*
 	 * Give the governor an opportunity to reflect on the outcome

Index: linux-pm/drivers/cpuidle/cpuidle.c
===================================================================

drivers/cpuidle/cpuidle.c +9 -0
@@ -158,9 +158,18 @@ int cpuidle_enter_state(struct cpuidle_d
 	int entered_state;
 
 	struct cpuidle_state *target_state = &drv->states[index];
+	bool broadcast = !!(target_state->flags & CPUIDLE_FLAG_TIMER_STOP);
 	ktime_t time_start, time_end;
 	s64 diff;
 
+	/*
+	 * Tell the time framework to switch to a broadcast timer because our
+	 * local timer will be shut down.  If a local timer is used from another
+	 * CPU as a broadcast timer, this call may fail if it is not available.
+	 */
+	if (broadcast && tick_broadcast_enter())
+		return -EBUSY;
+
 	trace_cpu_idle_rcuidle(index, dev->cpu);
 	time_start = ktime_get();
 
@@ -169,6 +178,13 @@ int cpuidle_enter_state(struct cpuidle_d
 	time_end = ktime_get();
 	trace_cpu_idle_rcuidle(PWR_EVENT_EXIT, dev->cpu);
 

drivers/cpuidle/cpuidle.c int cpuidle_enter_state(struct cpuidle_d · line 190

Quoted 10 lines
drivers/cpuidle/cpuidle.c +7 -0
+	if (broadcast) {
+		if (WARN_ON_ONCE(!irqs_disabled()))
+			local_irq_disable();
+
+		tick_broadcast_exit();
+	}
+
 	if (!cpuidle_state_is_coupled(dev, drv, entered_state))
 		local_irq_enable();
 
Quoted 6 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Tested-by on v1 1/1
#35 lore raw

Re: [PATCH][Fix] cpuidle: Run tick_broadcast_exit() with disabled interrupts

In reply to Rafael J. Wysocki
Quoted 10 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Commit 335f49196fd6 (sched/idle: Use explicit broadcast oneshot control function) replaced clockevents_notify() invocations in cpuidle_idle_call() with direct calls to tick_broadcast_enter() and tick_broadcast_exit(), but it overlooked the fact that interrupts were already enabled before calling the latter which led to functional breakage on systems using idle states with the CPUIDLE_FLAG_TIMER_STOP flag set.

Quoted 8 lines

Fix that by moving the invocations of tick_broadcast_enter() and tick_broadcast_exit() down into cpuidle_enter_state() where interrupts are still disabled when tick_broadcast_exit() is called. Also ensure that interrupts will be disabled before running tick_broadcast_exit() even if they have been enabled by the idle state's ->enter callback. Trigger a WARN_ON_ONCE() in that case, as we generally don't want that to happen for states with CPUIDLE_FLAG_TIMER_STOP set.

Incidentally I was debugging this issue as well when I saw this thread.

And it turns out that I did report this issue 2 months ago:
http://article.gmane.org/gmane.linux.kernel/1892049
What happened?

Quoted 6 lines
Fixes 335f49196fd6 (sched/idle: Use explicit broadcast oneshot control function)
Reported-and-tested-by Linus Walleij <[email protected]>
Reported-and-tested-by Sudeep Holla <[email protected]>
Quoted 99 lines

---

Thanks for the testing and ACKs, here it goes again with all tags and a changelog.

If anything is missing/incorrect, please let me know ASAP as I'm going to push this to Linus in a couple of days.

---
 drivers/cpuidle/cpuidle.c |   16 ++++++++++++++++
 kernel/sched/idle.c       |   16 ++--------------
 2 files changed, 18 insertions(+), 14 deletions(-)

Index: linux-pm/kernel/sched/idle.c
===================================================================

kernel/sched/idle.c +2 -14
@@ -81,7 +81,6 @@ static void cpuidle_idle_call(void)
 	struct cpuidle_device *dev = __this_cpu_read(cpuidle_devices);
 	struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev);
 	int next_state, entered_state;
-	unsigned int broadcast;
 	bool reflect;
 
 	/*
@@ -150,17 +149,6 @@ static void cpuidle_idle_call(void)
 		goto exit_idle;
 	}
 
-	broadcast = drv->states[next_state].flags & CPUIDLE_FLAG_TIMER_STOP;
-
-	/*
-	 * Tell the time framework to switch to a broadcast timer
-	 * because our local timer will be shutdown. If a local timer
-	 * is used from another cpu as a broadcast timer, this call may
-	 * fail if it is not available
-	 */
-	if (broadcast && tick_broadcast_enter())
-		goto use_default;
-
 	/* Take note of the planned idle state. */
 	idle_set_state(this_rq(), &drv->states[next_state]);
 
@@ -174,8 +162,8 @@ static void cpuidle_idle_call(void)
 	/* The cpu is no longer idle or about to enter idle. */
 	idle_set_state(this_rq(), NULL);
 
-	if (broadcast)
-		tick_broadcast_exit();
+	if (entered_state == -EBUSY)
+		goto use_default;
 
 	/*
 	 * Give the governor an opportunity to reflect on the outcome

Index: linux-pm/drivers/cpuidle/cpuidle.c
===================================================================

drivers/cpuidle/cpuidle.c +16 -1
@@ -158,9 +158,18 @@ int cpuidle_enter_state(struct cpuidle_d
 	int entered_state;
 
 	struct cpuidle_state *target_state = &drv->states[index];
+	bool broadcast = !!(target_state->flags & CPUIDLE_FLAG_TIMER_STOP);
 	ktime_t time_start, time_end;
 	s64 diff;
 
+	/*
+	 * Tell the time framework to switch to a broadcast timer because our
+	 * local timer will be shut down.  If a local timer is used from another
+	 * CPU as a broadcast timer, this call may fail if it is not available.
+	 */
+	if (broadcast && tick_broadcast_enter())
+		return -EBUSY;
+
 	trace_cpu_idle_rcuidle(index, dev->cpu);
 	time_start = ktime_get();
 
@@ -169,6 +178,13 @@ int cpuidle_enter_state(struct cpuidle_d
 	time_end = ktime_get();
 	trace_cpu_idle_rcuidle(PWR_EVENT_EXIT, dev->cpu);
 
+	if (broadcast) {
+		if (WARN_ON_ONCE(!irqs_disabled()))
+			local_irq_disable();
+
+		tick_broadcast_exit();
+	}
+
 	if (!cpuidle_state_is_coupled(dev, drv, entered_state))
 		local_irq_enable();
 
 
--

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

#36 lore raw

Re: [PATCH][Fix] cpuidle: Run tick_broadcast_exit() with disabled interrupts

Quoted 21 lines · Nicolas Pitre
Quoted 10 lines · Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Commit 335f49196fd6 (sched/idle: Use explicit broadcast oneshot control function) replaced clockevents_notify() invocations in cpuidle_idle_call() with direct calls to tick_broadcast_enter() and tick_broadcast_exit(), but it overlooked the fact that interrupts were already enabled before calling the latter which led to functional breakage on systems using idle states with the CPUIDLE_FLAG_TIMER_STOP flag set.

Quoted 8 lines

Fix that by moving the invocations of tick_broadcast_enter() and tick_broadcast_exit() down into cpuidle_enter_state() where interrupts are still disabled when tick_broadcast_exit() is called. Also ensure that interrupts will be disabled before running tick_broadcast_exit() even if they have been enabled by the idle state's ->enter callback. Trigger a WARN_ON_ONCE() in that case, as we generally don't want that to happen for states with CPUIDLE_FLAG_TIMER_STOP set.

Quoted 5 lines

Incidentally I was debugging this issue as well when I saw this thread.

And it turns out that I did report this issue 2 months ago:
http://article.gmane.org/gmane.linux.kernel/1892049
What happened?

The patch series had been picked up by someone else (me), reordered and rebased in the meantime and your report was missed. Sorry about that.

Quoted 8 lines
Quoted 6 lines
Fixes 335f49196fd6 (sched/idle: Use explicit broadcast oneshot control function)
Reported-and-tested-by Linus Walleij <[email protected]>
Reported-and-tested-by Sudeep Holla <[email protected]>

Thanks!

Signature · 2 lines
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
Reviewed-by
#37 lore raw

Re: [PATCH 16/20] sched/idle: Use explicit broadcast oneshot control function

In reply to Rafael J. Wysocki
Quoted 155 lines · Rafael J. Wysocki
Quoted 69 lines · Rafael J. Wysocki
Quoted 44 lines · Sudeep Holla
Quoted 32 lines · Rafael J. Wysocki
Quoted 23 lines · Rafael J. Wysocki
Quoted 22 lines · Rafael J. Wysocki
Quoted 11 lines · Linus Walleij
Quoted 10 lines · Rafael J. Wysocki

Sudeep:

Quoted 4 lines

At-least I observed issue only when I am using hardware broadcast timer. It doesn't hang when I am using hrtimer as broadcast timer in which case one of the cpu will be not enter deeper idle states that lose timer. I will rerun on v4.1-rc1 and post the complete log.

So the bug here is that cpuidle_enter() enables interrupts, so the assumption about them being not enabled made by tick_broadcast_oneshot_control() is actually not valid.

Quoted 6 lines
Quoted 3 lines

It looks like we need to acquire the clockevents_lock at least in this particular case. Let me see where to put it and I'll send a patch for testing.

Aha that looks very much like it. Put me on the patch and I'll take it for a spin.

OK, so something like the below for starters (the _irqsave variant is used to avoid adding one more WARN_ON(irqs_disabled()) in there).

Quoted 7 lines
Quoted 2 lines

I haven't tested it, but then I can't reproduce the original issue in the first place.

Of course, the whole "broadcast" thing could be done from cpuidle_enter() in the first place, but then we could not avoid the problem with the cpuidle *callback* enabling interrupts possibly in there anyway (not to mention the "coupled" stuff).

Quoted 7 lines

That said, if the given state is marked with CPUIDLE_FLAG_TIMER_STOP, I really wouldn't expect it to re-enable interrupts on exit and the "coupled" thing seems to be fundamentally at odds with that flag either.

So it should be possible to move the "broadcast" logic into the cpuidle layer, which I'm going to try to do.

Makes sense.

Quoted 7 lines
Quoted 4 lines

Please test the patch I've sent, though, as it should bring the code back to where it was before the clockevents_notify() removal and it'd be good to verify that.

I tested your patch and it works now. Anyways I am continuing to run stress tests on my board. I will report if I find any issues.

Great, thanks!

Below is the patch I came up with in the meantime.

This moves the "switch to broadcast" timer logic into cpuidle_enter_state() which allows tick_broadcast_exit() to be called directly with interrupts disabled (as required), but it also adds a fallback branch reflecting the 4.0 and earlier behavior for idle states that enable interrupts on exit from their ->enter callbacks.

I'm not aware of any valid cases when CPUIDLE_FLAG_TIMER_STOP can be set for such states, but people may try to add stuff like that in the future, so it's better to catch that (hence the WARN_ON_ONCE) and do our best to handle it gracefully anyway, IMO.

Quoted 6 lines

The "if (entered_state == -EBUSY)" check is conservative. It may be better to do "if (entered_state < 0)" and fall back to the default on all errors, but that's not what we do today (I guess the concern would be "what if the state ->enter returns an error after entering and exiting the idle state, in which case we may miss a wakeup event if we fall back to the default").

Actually, if my understanding of things is correct (the local clock event device cannot go away from under code executed with interrupts disabled on the local CPU), the simplified one below should be sufficient.

---
 drivers/cpuidle/cpuidle.c |   16 ++++++++++++++++
 kernel/sched/idle.c       |   16 ++--------------
 2 files changed, 18 insertions(+), 14 deletions(-)

Index: linux-pm/kernel/sched/idle.c
===================================================================

kernel/sched/idle.c +2 -14
@@ -81,7 +81,6 @@ static void cpuidle_idle_call(void)
 	struct cpuidle_device *dev = __this_cpu_read(cpuidle_devices);
 	struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev);
 	int next_state, entered_state;
-	unsigned int broadcast;
 	bool reflect;
 
 	/*
@@ -150,17 +149,6 @@ static void cpuidle_idle_call(void)
 		goto exit_idle;
 	}
 
-	broadcast = drv->states[next_state].flags & CPUIDLE_FLAG_TIMER_STOP;
-
-	/*
-	 * Tell the time framework to switch to a broadcast timer
-	 * because our local timer will be shutdown. If a local timer
-	 * is used from another cpu as a broadcast timer, this call may
-	 * fail if it is not available
-	 */
-	if (broadcast && tick_broadcast_enter())
-		goto use_default;
-
 	/* Take note of the planned idle state. */
 	idle_set_state(this_rq(), &drv->states[next_state]);
 
@@ -174,8 +162,8 @@ static void cpuidle_idle_call(void)
 	/* The cpu is no longer idle or about to enter idle. */
 	idle_set_state(this_rq(), NULL);
 
-	if (broadcast)
-		tick_broadcast_exit();
+	if (entered_state == -EBUSY)
+		goto use_default;
 
 	/*
 	 * Give the governor an opportunity to reflect on the outcome

Index: linux-pm/drivers/cpuidle/cpuidle.c
===================================================================

drivers/cpuidle/cpuidle.c +9 -0
@@ -158,9 +158,18 @@ int cpuidle_enter_state(struct cpuidle_d
 	int entered_state;
 
 	struct cpuidle_state *target_state = &drv->states[index];
+	bool broadcast = !!(target_state->flags & CPUIDLE_FLAG_TIMER_STOP);
 	ktime_t time_start, time_end;
 	s64 diff;
 
+	/*
+	 * Tell the time framework to switch to a broadcast timer because our
+	 * local timer will be shut down.  If a local timer is used from another
+	 * CPU as a broadcast timer, this call may fail if it is not available.
+	 */
+	if (broadcast && tick_broadcast_enter())
+		return -EBUSY;
+
 	trace_cpu_idle_rcuidle(index, dev->cpu);
 	time_start = ktime_get();
 
@@ -169,6 +178,13 @@ int cpuidle_enter_state(struct cpuidle_d
 	time_end = ktime_get();
 	trace_cpu_idle_rcuidle(PWR_EVENT_EXIT, dev->cpu);
 

drivers/cpuidle/cpuidle.c int cpuidle_enter_state(struct cpuidle_d · line 190

Quoted 10 lines
drivers/cpuidle/cpuidle.c +7 -0
+	if (broadcast) {
+		if (WARN_ON_ONCE(!irqs_disabled()))
+			local_irq_disable();
+
+		tick_broadcast_exit();
+	}
+
 	if (!cpuidle_state_is_coupled(dev, drv, entered_state))
 		local_irq_enable();
 

Looks good.

Quoted 5 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#38 lore raw

Re: [PATCH 16/20] sched/idle: Use explicit broadcast oneshot control function

In reply to Rafael J. Wysocki

Hi Rafael,

Quoted 1 line · Rafael J. Wysocki

On Tue, Apr 28, 2015 at 12:42 PM, Sudeep Holla <[email protected]> wrote:

[...]

Quoted 6 lines
Quoted 5 lines

At-least I observed issue only when I am using hardware broadcast timer. It doesn't hang when I am using hrtimer as broadcast timer in which case one of the cpu will be not enter deeper idle states that lose timer. I will rerun on v4.1-rc1 and post the complete log.

Quoted 8 lines

So the bug here is that cpuidle_enter() enables interrupts, so the assumption about them being not enabled made by tick_broadcast_oneshot_control() is actually not valid.

It looks like we need to acquire the clockevents_lock at least in this particular case. Let me see where to put it and I'll send a patch for testing.

Thanks for looking at this, I can also help in testing. Sending the complete log again with v4.1-rc1 if it's any useful.

Regards,
Sudeep

--->8

BUG: spinlock lockup suspected on CPU#0, swapper/0/0
 lock: tick_broadcast_lock+0x0/0x40, .magic: dead4ead, .owner: 
swapper/0/0, .owner_cpu: 0
CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.1.0-rc1 #16
Hardware name: ARM-Versatile Express
[<c0014b1d>] (unwind_backtrace) from [<c0011659>] (show_stack+0x11/0x14)
[<c0011659>] (show_stack) from [<c05192ed>] (dump_stack+0x6d/0x78)
[<c05192ed>] (dump_stack) from [<c005c897>] (do_raw_spin_lock+0xc3/0x144)
[<c005c897>] (do_raw_spin_lock) from [<c00811f9>] (tick_handle_oneshot_broadcast+0x25/0x164)
[<c00811f9>] (tick_handle_oneshot_broadcast) from [<c001dd21>] (sp804_timer_interrupt+0x31/0x34)
[<c001dd21>] (sp804_timer_interrupt) from [<c0067ee1>] (handle_irq_event_percpu+0x45/0x154)
[<c0067ee1>] (handle_irq_event_percpu) from [<c006801f>] (handle_irq_event+0x2f/0x44)
[<c006801f>] (handle_irq_event) from [<c0069edb>] (handle_fasteoi_irq+0x6f/0xf0)
[<c0069edb>] (handle_fasteoi_irq) from [<c00677c7>] (generic_handle_irq+0x23/0x2c)
[<c00677c7>] (generic_handle_irq) from [<c0067a0d>] (__handle_domain_irq+0x45/0x84)
[<c0067a0d>] (__handle_domain_irq) from [<c0009303>] (gic_handle_irq+0x27/0x50)
[<c0009303>] (gic_handle_irq) from [<c0011eff>] (__irq_svc+0x3f/0x64)
Exception stack(0xc07ebf08 to 0xc07ebf50)

bf00: 00000000 c1038814 00000001 00000001 c07f3f80 ee78dec0
bf20: 00000000 c1038810 00000000 00000001 c07ebf88 c0520fc8 00000000 c07ebf50
bf40: c008151d c02e104e 40000173 ffffffff
[<c0011eff>] (__irq_svc) from [<c02e104e>] (_test_and_clear_bit+0x26/0x48) [<c02e104e>] (_test_and_clear_bit) from [<c008151d>] (tick_broadcast_oneshot_control+0x159/0x1ec) [<c008151d>] (tick_broadcast_oneshot_control) from [<c0050273>] (cpu_startup_entry+0x2c3/0x2f8) [<c0050273>] (cpu_startup_entry) from [<c0782a47>] (start_kernel+0x327/0x330)

BUG: spinlock lockup suspected on CPU#3, swapper/3/0
BUG: spinlock lockup suspected on CPU#4, swapper/4/0
 lock: tick_broadcast_lock+0x0/0x40, .magic: dead4ead, .owner: 
swapper/0/0, .owner_cpu: 0
CPU: 4 PID: 0 Comm: swapper/4 Not tainted 4.1.0-rc1 #16
Hardware name: ARM-Versatile Express
[<c0014b1d>] (unwind_backtrace) from [<c0011659>] (show_stack+0x11/0x14)
[<c0011659>] (show_stack) from [<c05192ed>] (dump_stack+0x6d/0x78)
BUG: spinlock lockup suspected on CPU#2, swapper/2/0
[<c05192ed>] (dump_stack) from [<c005c897>] (do_raw_spin_lock+0xc3/0x144)
 lock: tick_broadcast_lock+0x0/0x40, .magic: dead4ead, .owner: 

swapper/0/0, .owner_cpu: 0
[<c005c897>] (do_raw_spin_lock) from [<c0081409>] (tick_broadcast_oneshot_control+0x45/0x1ec) [<c0081409>] (tick_broadcast_oneshot_control) from [<c0050273>] (cpu_startup_entry+0x2c3/0x2f8) [<c0050273>] (cpu_startup_entry) from [<800093d1>] (0x800093d1)

CPU: 2 PID: 0 Comm: swapper/2 Not tainted 4.1.0-rc1 #16
Hardware name: ARM-Versatile Express
[<c0014b1d>] (unwind_backtrace) from [<c0011659>] (show_stack+0x11/0x14)
[<c0011659>] (show_stack) from [<c05192ed>] (dump_stack+0x6d/0x78)
[<c05192ed>] (dump_stack) from [<c005c897>] (do_raw_spin_lock+0xc3/0x144)
[<c005c897>] (do_raw_spin_lock) from [<c0081409>] (tick_broadcast_oneshot_control+0x45/0x1ec)
[<c0081409>] (tick_broadcast_oneshot_control) from [<c0050273>] (cpu_startup_entry+0x2c3/0x2f8)
[<c0050273>] (cpu_startup_entry) from [<800093d1>] (0x800093d1)
 lock: tick_broadcast_lock+0x0/0x40, .magic: dead4ead, .owner: 
swapper/0/0, .owner_cpu: 0
CPU: 3 PID: 0 Comm: swapper/3 Not tainted 4.1.0-rc1 #16
Hardware name: ARM-Versatile Express
[<c0014b1d>] (unwind_backtrace) from [<c0011659>] (show_stack+0x11/0x14)
[<c0011659>] (show_stack) from [<c05192ed>] (dump_stack+0x6d/0x78)
[<c05192ed>] (dump_stack) from [<c005c897>] (do_raw_spin_lock+0xc3/0x144)
[<c005c897>] (do_raw_spin_lock) from [<c0081409>] (tick_broadcast_oneshot_control+0x45/0x1ec)
[<c0081409>] (tick_broadcast_oneshot_control) from [<c0050273>] (cpu_startup_entry+0x2c3/0x2f8)

[<c0050273>] (cpu_startup_entry) from [<800093d1>] (0x800093d1)

#39 lore raw

PATCH 17/20 clockevents: Remove broadcast oneshot control leftovers

In reply to Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

All users converted. Remove the notify leftovers.

---
 include/linux/clockchips.h |    2 --
 kernel/time/clockevents.c  |    7 -------
 2 files changed, 9 deletions(-)
include/linux/clockchips.h +0 -2
Index: linux-pm/include/linux/clockchips.h
===================================================================
@@ -11,8 +11,6 @@
 /* Clock event notification values */
 enum clock_event_nofitiers {
 	CLOCK_EVT_NOTIFY_ADD,
-	CLOCK_EVT_NOTIFY_BROADCAST_ENTER,
-	CLOCK_EVT_NOTIFY_BROADCAST_EXIT,
 	CLOCK_EVT_NOTIFY_CPU_DYING,
 	CLOCK_EVT_NOTIFY_CPU_DEAD,
 };
kernel/time/clockevents.c +0 -7
Index: linux-pm/kernel/time/clockevents.c
===================================================================
@@ -655,13 +655,6 @@ int clockevents_notify(unsigned long rea
 	raw_spin_lock_irqsave(&clockevents_lock, flags);
 
 	switch (reason) {
-	case CLOCK_EVT_NOTIFY_BROADCAST_ENTER:
-		tick_broadcast_enter();
-		break;
-	case CLOCK_EVT_NOTIFY_BROADCAST_EXIT:
-		tick_broadcast_exit();
-		break;
-
 	case CLOCK_EVT_NOTIFY_CPU_DYING:
 		tick_handover_do_timer(arg);
 		break;
#40 lore raw

PATCH 18/20 clockevents: Make tick handover explicit

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

clockevents_notify() is a leftover from the early design of the clockevents facility. It's really not a notification mechanism, it's a multiplex call. We are way better off to have explicit calls instead of this monstrosity.

Split out the tick_handover call and invoke it explicitely from the hotplug code. Temporary solution will be cleaned up in later patches.

---
 include/linux/clockchips.h  |    1 -
 include/linux/tick.h        |    2 ++
 kernel/cpu.c                |    3 +++
 kernel/time/clockevents.c   |    4 ----
 kernel/time/hrtimer.c       |    4 ----
 kernel/time/tick-common.c   |    9 ++++++---
 kernel/time/tick-internal.h |    1 -
 7 files changed, 11 insertions(+), 13 deletions(-)
include/linux/clockchips.h +0 -1
Index: linux-pm/include/linux/clockchips.h
===================================================================
@@ -11,7 +11,6 @@
 /* Clock event notification values */
 enum clock_event_nofitiers {
 	CLOCK_EVT_NOTIFY_ADD,
-	CLOCK_EVT_NOTIFY_CPU_DYING,
 	CLOCK_EVT_NOTIFY_CPU_DEAD,
 };
 
include/linux/tick.h +2 -0
Index: linux-pm/include/linux/tick.h
===================================================================
@@ -19,12 +19,14 @@ extern void tick_unfreeze(void);
 extern void tick_suspend_local(void);
 /* Should be core only, but XEN resume magic and ARM BL switcher require it */
 extern void tick_resume_local(void);
+extern void tick_handover_do_timer(void);
 #else /* CONFIG_GENERIC_CLOCKEVENTS */
 static inline void tick_init(void) { }
 static inline void tick_freeze(void) { }
 static inline void tick_unfreeze(void) { }
 static inline void tick_suspend_local(void) { }
 static inline void tick_resume_local(void) { }
+static inline void tick_handover_do_timer(void) { }
 #endif /* !CONFIG_GENERIC_CLOCKEVENTS */
 
 #ifdef CONFIG_TICK_ONESHOT
kernel/cpu.c +3 -0
Index: linux-pm/kernel/cpu.c
===================================================================
@@ -20,6 +20,7 @@
 #include <linux/gfp.h>
 #include <linux/suspend.h>
 #include <linux/lockdep.h>
+#include <linux/tick.h>
 #include <trace/events/power.h>
 
 #include "smpboot.h"
@@ -338,6 +339,8 @@ static int __ref take_cpu_down(void *_pa
 		return err;
 
 	cpu_notify(CPU_DYING | param->mod, param->hcpu);
+	/* Give up timekeeping duties */
+	tick_handover_do_timer();
 	/* Park the stopper thread */
 	kthread_park(current);
 	return 0;
kernel/time/clockevents.c +0 -4
Index: linux-pm/kernel/time/clockevents.c
===================================================================
@@ -655,10 +655,6 @@ int clockevents_notify(unsigned long rea
 	raw_spin_lock_irqsave(&clockevents_lock, flags);
 
 	switch (reason) {
-	case CLOCK_EVT_NOTIFY_CPU_DYING:
-		tick_handover_do_timer(arg);
-		break;
-
 	case CLOCK_EVT_NOTIFY_CPU_DEAD:
 		tick_shutdown_broadcast_oneshot(arg);
 		tick_shutdown_broadcast(arg);
kernel/time/hrtimer.c +0 -4
Index: linux-pm/kernel/time/hrtimer.c
===================================================================
@@ -1707,10 +1707,6 @@ static int hrtimer_cpu_notify(struct not
 		break;
 
 #ifdef CONFIG_HOTPLUG_CPU
-	case CPU_DYING:
-	case CPU_DYING_FROZEN:
-		clockevents_notify(CLOCK_EVT_NOTIFY_CPU_DYING, &scpu);
-		break;
 	case CPU_DEAD:
 	case CPU_DEAD_FROZEN:
 	{
kernel/time/tick-common.c +6 -3
Index: linux-pm/kernel/time/tick-common.c
===================================================================
@@ -332,20 +332,23 @@ out_bc:
 	tick_install_broadcast_device(newdev);
 }
 
+#ifdef CONFIG_HOTPLUG_CPU
 /*
  * Transfer the do_timer job away from a dying cpu.
  *
- * Called with interrupts disabled.
+ * Called with interrupts disabled. Not locking required. If
+ * tick_do_timer_cpu is owned by this cpu, nothing can change it.
  */
-void tick_handover_do_timer(int *cpup)
+void tick_handover_do_timer(void)
 {
-	if (*cpup == tick_do_timer_cpu) {
+	if (tick_do_timer_cpu == smp_processor_id()) {
 		int cpu = cpumask_first(cpu_online_mask);
 
 		tick_do_timer_cpu = (cpu < nr_cpu_ids) ? cpu :
 			TICK_DO_TIMER_NONE;
 	}
 }
+#endif
 
 /*
  * Shutdown an event device on a given cpu:
kernel/time/tick-internal.h +0 -1
Index: linux-pm/kernel/time/tick-internal.h
===================================================================
@@ -20,7 +20,6 @@ extern int tick_do_timer_cpu __read_most
 extern void tick_setup_periodic(struct clock_event_device *dev, int broadcast);
 extern void tick_handle_periodic(struct clock_event_device *dev);
 extern void tick_check_new_device(struct clock_event_device *dev);
-extern void tick_handover_do_timer(int *cpup);
 extern void tick_shutdown(unsigned int *cpup);
 extern void tick_suspend(void);
 extern void tick_resume(void);
#41 lore raw

PATCH 19/20 clockevents: Cleanup dead cpu explicitely

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

clockevents_notify() is a leftover from the early design of the clockevents facility. It's really not a notification mechanism, it's a multiplex call. We are way better off to have explicit calls instead of this monstrosity.

Split out the cleanup function for a dead cpu and invoke it directly from the cpu down code. Make it conditional on CPU_HOTPLUG as well.

Temporary change, will be refined in the future.

[ rjw: Rebased, added clockevents_notify() removal ]
---
 include/linux/clockchips.h   |    6 -----
 include/linux/tick.h         |    2 +
 kernel/cpu.c                 |    1 
 kernel/time/clockevents.c    |   51 +++++++++++++++++--------------------------
 kernel/time/hrtimer.c        |    3 --
 kernel/time/tick-broadcast.c |   29 ++++++++++++------------
 kernel/time/tick-common.c    |    6 ++---
 kernel/time/tick-internal.h  |   10 ++++----
 8 files changed, 47 insertions(+), 61 deletions(-)
include/linux/clockchips.h +0 -6
Index: linux-pm/include/linux/clockchips.h
===================================================================
@@ -8,12 +8,6 @@
 #ifndef _LINUX_CLOCKCHIPS_H
 #define _LINUX_CLOCKCHIPS_H
 
-/* Clock event notification values */
-enum clock_event_nofitiers {
-	CLOCK_EVT_NOTIFY_ADD,
-	CLOCK_EVT_NOTIFY_CPU_DEAD,
-};
-
 #ifdef CONFIG_GENERIC_CLOCKEVENTS
 
 #include <linux/clocksource.h>
include/linux/tick.h +2 -0
Index: linux-pm/include/linux/tick.h
===================================================================
@@ -20,6 +20,7 @@ extern void tick_suspend_local(void);
 /* Should be core only, but XEN resume magic and ARM BL switcher require it */
 extern void tick_resume_local(void);
 extern void tick_handover_do_timer(void);
+extern void tick_cleanup_dead_cpu(int cpu);
 #else /* CONFIG_GENERIC_CLOCKEVENTS */
 static inline void tick_init(void) { }
 static inline void tick_freeze(void) { }
@@ -27,6 +28,7 @@ static inline void tick_unfreeze(void) {
 static inline void tick_suspend_local(void) { }
 static inline void tick_resume_local(void) { }
 static inline void tick_handover_do_timer(void) { }
+static inline void tick_cleanup_dead_cpu(int cpu) { }
 #endif /* !CONFIG_GENERIC_CLOCKEVENTS */
 
 #ifdef CONFIG_TICK_ONESHOT
kernel/cpu.c +1 -0
Index: linux-pm/kernel/cpu.c
===================================================================
@@ -418,6 +418,7 @@ static int __ref _cpu_down(unsigned int
 	__cpu_die(cpu);
 
 	/* CPU is completely dead: tell everyone.  Too late to complain. */
+	tick_cleanup_dead_cpu(cpu);
 	cpu_notify_nofail(CPU_DEAD | mod, hcpu);
 
 	check_for_tasks(cpu);
kernel/time/clockevents.c +21 -30

70 lines not on this page · raw message

kernel/time/hrtimer.c +0 -3
Index: linux-pm/kernel/time/hrtimer.c
===================================================================
@@ -1709,11 +1709,8 @@ static int hrtimer_cpu_notify(struct not
 #ifdef CONFIG_HOTPLUG_CPU
 	case CPU_DEAD:
 	case CPU_DEAD_FROZEN:
-	{
-		clockevents_notify(CLOCK_EVT_NOTIFY_CPU_DEAD, &scpu);
 		migrate_hrtimers(scpu);
 		break;
-	}
 #endif
 
 	default:
kernel/time/tick-broadcast.c +15 -14
Index: linux-pm/kernel/time/tick-broadcast.c
===================================================================
@@ -410,14 +410,14 @@ void tick_set_periodic_handler(struct cl
 		dev->event_handler = tick_handle_periodic_broadcast;
 }
 
+#ifdef CONFIG_HOTPLUG_CPU
 /*
  * Remove a CPU from broadcasting
  */
-void tick_shutdown_broadcast(unsigned int *cpup)
+void tick_shutdown_broadcast(unsigned int cpu)
 {
 	struct clock_event_device *bc;
 	unsigned long flags;
-	unsigned int cpu = *cpup;
 
 	raw_spin_lock_irqsave(&tick_broadcast_lock, flags);
 
@@ -432,6 +432,7 @@ void tick_shutdown_broadcast(unsigned in
 
 	raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags);
 }
+#endif
 
 void tick_suspend_broadcast(void)
 {
@@ -672,16 +673,6 @@ static void broadcast_shutdown_local(str
 	clockevents_set_state(dev, CLOCK_EVT_STATE_SHUTDOWN);
 }
 
-static void broadcast_move_bc(int deadcpu)
-{
-	struct clock_event_device *bc = tick_broadcast_device.evtdev;
-
-	if (!bc || !broadcast_needs_cpu(bc, deadcpu))
-		return;
-	/* This moves the broadcast assignment to this cpu */
-	clockevents_program_event(bc, bc->next_event, 1);
-}
-
 /**
  * tick_broadcast_oneshot_control - Enter/exit broadcast oneshot mode
  * @state:	The target state (enter/exit)
@@ -903,14 +894,23 @@ void tick_broadcast_switch_to_oneshot(vo
 	raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags);
 }
 
+#ifdef CONFIG_HOTPLUG_CPU
+static void broadcast_move_bc(int deadcpu)
+{
+	struct clock_event_device *bc = tick_broadcast_device.evtdev;
+
+	if (!bc || !broadcast_needs_cpu(bc, deadcpu))
+		return;
+	/* This moves the broadcast assignment to this cpu */
+	clockevents_program_event(bc, bc->next_event, 1);
+}
 
 /*
  * Remove a dead CPU from broadcasting
  */
-void tick_shutdown_broadcast_oneshot(unsigned int *cpup)
+void tick_shutdown_broadcast_oneshot(unsigned int cpu)
 {
 	unsigned long flags;
-	unsigned int cpu = *cpup;
 
 	raw_spin_lock_irqsave(&tick_broadcast_lock, flags);
 
@@ -926,6 +926,7 @@ void tick_shutdown_broadcast_oneshot(uns
 
 	raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags);
 }
+#endif
 
 /*
  * Check, whether the broadcast device is in one shot mode
kernel/time/tick-common.c +3 -3
Index: linux-pm/kernel/time/tick-common.c
===================================================================
@@ -348,7 +348,6 @@ void tick_handover_do_timer(void)
 			TICK_DO_TIMER_NONE;
 	}
 }
-#endif
 
 /*
  * Shutdown an event device on a given cpu:
@@ -357,9 +356,9 @@ void tick_handover_do_timer(void)
  * access the hardware device itself.
  * We just set the mode and remove it from the lists.
  */
-void tick_shutdown(unsigned int *cpup)
+void tick_shutdown(unsigned int cpu)
 {
-	struct tick_device *td = &per_cpu(tick_cpu_device, *cpup);
+	struct tick_device *td = &per_cpu(tick_cpu_device, cpu);
 	struct clock_event_device *dev = td->evtdev;
 
 	td->mode = TICKDEV_MODE_PERIODIC;
@@ -375,6 +374,7 @@ void tick_shutdown(unsigned int *cpup)
 		td->evtdev = NULL;
 	}
 }
+#endif
 
 /**
  * tick_suspend_local - Suspend the local tick device
kernel/time/tick-internal.h +5 -5
Index: linux-pm/kernel/time/tick-internal.h
===================================================================
@@ -20,7 +20,7 @@ extern int tick_do_timer_cpu __read_most
 extern void tick_setup_periodic(struct clock_event_device *dev, int broadcast);
 extern void tick_handle_periodic(struct clock_event_device *dev);
 extern void tick_check_new_device(struct clock_event_device *dev);
-extern void tick_shutdown(unsigned int *cpup);
+extern void tick_shutdown(unsigned int cpu);
 extern void tick_suspend(void);
 extern void tick_resume(void);
 extern bool tick_check_replacement(struct clock_event_device *curdev,
@@ -84,7 +84,7 @@ static inline int tick_check_oneshot_cha
 extern int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu);
 extern void tick_install_broadcast_device(struct clock_event_device *dev);
 extern int tick_is_broadcast_device(struct clock_event_device *dev);
-extern void tick_shutdown_broadcast(unsigned int *cpup);
+extern void tick_shutdown_broadcast(unsigned int cpu);
 extern void tick_suspend_broadcast(void);
 extern void tick_resume_broadcast(void);
 extern bool tick_resume_check_broadcast(void);
@@ -98,7 +98,7 @@ static inline void tick_install_broadcas
 static inline int tick_is_broadcast_device(struct clock_event_device *dev) { return 0; }
 static inline int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu) { return 0; }
 static inline void tick_do_periodic_broadcast(struct clock_event_device *d) { }
-static inline void tick_shutdown_broadcast(unsigned int *cpup) { }
+static inline void tick_shutdown_broadcast(unsigned int cpu) { }
 static inline void tick_suspend_broadcast(void) { }
 static inline void tick_resume_broadcast(void) { }
 static inline bool tick_resume_check_broadcast(void) { return false; }
@@ -118,7 +118,7 @@ static inline void tick_set_periodic_han
 #if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
 extern void tick_broadcast_setup_oneshot(struct clock_event_device *bc);
 extern void tick_broadcast_switch_to_oneshot(void);
-extern void tick_shutdown_broadcast_oneshot(unsigned int *cpup);
+extern void tick_shutdown_broadcast_oneshot(unsigned int cpu);
 extern int tick_broadcast_oneshot_active(void);
 extern void tick_check_oneshot_broadcast_this_cpu(void);
 bool tick_broadcast_oneshot_available(void);
@@ -126,7 +126,7 @@ extern struct cpumask *tick_get_broadcas
 #else /* BROADCAST && ONESHOT */
 static inline void tick_broadcast_setup_oneshot(struct clock_event_device *bc) { BUG(); }
 static inline void tick_broadcast_switch_to_oneshot(void) { }
-static inline void tick_shutdown_broadcast_oneshot(unsigned int *cpup) { }
+static inline void tick_shutdown_broadcast_oneshot(unsigned int cpu) { }
 static inline int tick_broadcast_oneshot_active(void) { return 0; }
 static inline void tick_check_oneshot_broadcast_this_cpu(void) { }
 static inline bool tick_broadcast_oneshot_available(void) { return tick_oneshot_possible(); }
#42 lore raw

PATCH 20/20 timekeeping: Get rid of stale comment

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Arch specific management of xtime/jiffies/wall_to_monotonic is gone for quite a while. Zap the stale comment.

---
 kernel/time/timekeeping.c |    4 ----
 1 file changed, 4 deletions(-)
kernel/time/timekeeping.c +0 -4
Index: linux-pm/kernel/time/timekeeping.c
===================================================================
@@ -1307,10 +1307,6 @@ void timekeeping_inject_sleeptime64(stru
 
 /**
  * timekeeping_resume - Resumes the generic timekeeping subsystem.
- *
- * This is for the generic clocksource timekeeping.
- * xtime/wall_to_monotonic/jiffies/etc are
- * still managed by arch specific suspend/resume code.
  */
 void timekeeping_resume(void)
 {
Acked-by on v1 20/20
#43 lore raw

Re: [PATCH 20/20] timekeeping: Get rid of stale comment

Quoted 8 lines · Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Arch specific management of xtime/jiffies/wall_to_monotonic is gone for quite a while. Zap the stale comment.

thanks
-john

maintainer
#44 lore raw
In reply to Rafael J. Wysocki
Quoted 4 lines · Rafael J. Wysocki

Hi,

This is the next batch of patches from Thomas that remove clockevents_notify().

Quoted 8 lines

I've reordered the set (to put more stratightforward things to the front) and rebased it on top of the timers material currently queued up for 4.1.

This series in based on the bleeding-edge branch of the linux-pm tree (which for all practical purposes is my linux-next branch with timers/core from tip merged into it).

Please let me know how to proceed with these.

Would you mind to resend these merged on top of the very latest tip:timers/core (or tip:master) tree?

These changes conflict (mildly) with the other series from Thomas which needed some fixes/enhancements.

Thanks,

Ingo

#45 lore raw
Quoted 14 lines · Ingo Molnar
Quoted 11 lines · Rafael J. Wysocki

Hi,

This is the next batch of patches from Thomas that remove clockevents_notify().

I've reordered the set (to put more stratightforward things to the front) and rebased it on top of the timers material currently queued up for 4.1.

This series in based on the bleeding-edge branch of the linux-pm tree (which for all practical purposes is my linux-next branch with timers/core from tip merged into it).

Quoted 7 lines
Quoted 1 line

Please let me know how to proceed with these.

Would you mind to resend these merged on top of the very latest tip:timers/core (or tip:master) tree?

These changes conflict (mildly) with the other series from Thomas which needed some fixes/enhancements.

I'll do that later today.

This series also depends on:

http://git.kernel.org/cgit/linux/kernel/git/rafael/linux-pm.git/commit/?h=acpi-pad&id=6e9f8b5f1f319cbdb4cfe3696fc74fbe39318960

which is in my acpi-pad branch at the moment, but I'll add it to the front of the series in case you prefer to apply it directly.

Thanks,
Rafael

#46 lore raw

v2 cover clockevents_notify() removal

Quoted 23 lines · Rafael J. Wysocki
Quoted 14 lines · Ingo Molnar
Quoted 11 lines · Rafael J. Wysocki

Hi,

This is the next batch of patches from Thomas that remove clockevents_notify().

I've reordered the set (to put more stratightforward things to the front) and rebased it on top of the timers material currently queued up for 4.1.

This series in based on the bleeding-edge branch of the linux-pm tree (which for all practical purposes is my linux-next branch with timers/core from tip merged into it).

Quoted 7 lines
Quoted 1 line

Please let me know how to proceed with these.

Would you mind to resend these merged on top of the very latest tip:timers/core (or tip:master) tree?

These changes conflict (mildly) with the other series from Thomas which needed some fixes/enhancements.

Quoted 8 lines

I'll do that later today.

This series also depends on:

http://git.kernel.org/cgit/linux/kernel/git/rafael/linux-pm.git/commit/?h=acpi-pad&id=6e9f8b5f1f319cbdb4cfe3696fc74fbe39318960

which is in my acpi-pad branch at the moment, but I'll add it to the front of the series in case you prefer to apply it directly.

The patches follow as per the above. [2-21/21] rebased on top of the current timers/core.

Thanks,
Rafael

#47 lore raw

PATCH v2 1/21 ACPI / PAD: Remove the local APIC nonsense

From: Thomas Gleixner <[email protected]>

While looking through the (ab)use of the clockevents_notify() function I stumbled over the following gem in the acpi_pad code:

  if (lapic_detected_unstable && !lapic_marked_unstable) {
     /* LAPIC could halt in idle, so notify users */
     for_each_online_cpu(i)
       clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ON, &i);
     lapic_marked_unstable = 1;
  }

This code calls on the cpu which detects the lapic unstable condition first clockevents_notify() to tell the core code that the broadcast should be enabled on all online cpus. Brilliant stuff that as it notifies the core code a num_online_cpus() times that the broadcast should be enabled on the current cpu.

This probably has never been noticed because that code got never tested with NOHZ=n and HIGHRES_TIMER=n or it just worked by chance because one of the other mechanisms told the core in the right way that the local apic timer is wreckaged.

Sigh, this is:

- The 4th incarnation of idle drivers which has their own mechanism to detect and deal with X86_FEATURE_ARAT.

- The 2nd incarnation of fake idle mechanisms with a different set of brainmelting bugs.

- Has been merged against an explicit NAK of the scheduler maintainer with the promise to improve it over time.

- Another example of featuritis driven trainwreck engineering.

- Another pointless waste of my time.

Fix this nonsense by removing that lapic detection and notification logic and simply call into the clockevents code unconditonally. The ARAT feature is marked in the lapic clockevent already so the core code will just ignore the requests and return.

---

drivers/acpi/acpi_pad.c +5 -21
index c7b105c0e1d3..1686e9f756fd 100644
@@ -41,8 +41,6 @@ static unsigned long power_saving_mwait_eax;
 
 static unsigned char tsc_detected_unstable;
 static unsigned char tsc_marked_unstable;
-static unsigned char lapic_detected_unstable;
-static unsigned char lapic_marked_unstable;
 
 static void power_saving_mwait_init(void)
 {
@@ -82,13 +80,10 @@ static void power_saving_mwait_init(void)
 		 */
 		if (!boot_cpu_has(X86_FEATURE_NONSTOP_TSC))
 			tsc_detected_unstable = 1;
-		if (!boot_cpu_has(X86_FEATURE_ARAT))
-			lapic_detected_unstable = 1;
 		break;
 	default:
-		/* TSC & LAPIC could halt in idle */
+		/* TSC could halt in idle */
 		tsc_detected_unstable = 1;
-		lapic_detected_unstable = 1;
 	}
 #endif
 }
@@ -177,28 +172,17 @@ static int power_saving_thread(void *data)
 				mark_tsc_unstable("TSC halts in idle");
 				tsc_marked_unstable = 1;
 			}
-			if (lapic_detected_unstable && !lapic_marked_unstable) {
-				int i;
-				/* LAPIC could halt in idle, so notify users */
-				for_each_online_cpu(i)
-					clockevents_notify(
-						CLOCK_EVT_NOTIFY_BROADCAST_ON,
-						&i);
-				lapic_marked_unstable = 1;
-			}
+			clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ON, &cpu);
+
 			local_irq_disable();
 			cpu = smp_processor_id();
-			if (lapic_marked_unstable)
-				clockevents_notify(
-					CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &cpu);
+			clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &cpu);
 			stop_critical_timings();
 
 			mwait_idle_with_hints(power_saving_mwait_eax, 1);
 
 			start_critical_timings();
-			if (lapic_marked_unstable)
-				clockevents_notify(
-					CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &cpu);
+			clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &cpu);
 			local_irq_enable();
 
 			if (time_before(expire_time, jiffies)) {
#48 lore raw

[tip:timers/core] ACPI/PAD: Remove the local APIC nonsense

ACPI/PAD: Remove the local APIC nonsense
Commit-ID:  3ff70551a942b4c1d3c2e96e31a5c6e369a6d0be
Gitweb:     http://git.kernel.org/tip/3ff70551a942b4c1d3c2e96e31a5c6e369a6d0be
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Fri, 3 Apr 2015 01:46:34 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 3 Apr 2015 08:44:31 +0200

ACPI/PAD: Remove the local APIC nonsense

While looking through the (ab)use of the clockevents_notify() function I stumbled over the following gem in the acpi_pad code:

  if (lapic_detected_unstable && !lapic_marked_unstable) {
     /* LAPIC could halt in idle, so notify users */
     for_each_online_cpu(i)
       clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ON, &i);
     lapic_marked_unstable = 1;
  }

This code calls on the cpu which detects the lapic unstable condition first clockevents_notify() to tell the core code that the broadcast should be enabled on all online cpus. Brilliant stuff that as it notifies the core code a num_online_cpus() times that the broadcast should be enabled on the current cpu.

This probably has never been noticed because that code got never tested with NOHZ=n and HIGHRES_TIMER=n or it just worked by chance because one of the other mechanisms told the core in the right way that the local apic timer is wreckaged.

Sigh, this is:

- The 4th incarnation of idle drivers which has their own mechanism to detect and deal with X86_FEATURE_ARAT.

- The 2nd incarnation of fake idle mechanisms with a different set of brainmelting bugs.

- Has been merged against an explicit NAK of the scheduler maintainer with the promise to improve it over time.

- Another example of featuritis driven trainwreck engineering.

- Another pointless waste of my time.

Fix this nonsense by removing that lapic detection and notification logic and simply call into the clockevents code unconditonally. The ARAT feature is marked in the lapic clockevent already so the core code will just ignore the requests and return.

---
 drivers/acpi/acpi_pad.c | 26 +++++---------------------
 1 file changed, 5 insertions(+), 21 deletions(-)
drivers/acpi/acpi_pad.c +5 -21
index c7b105c..1686e9f 100644
@@ -41,8 +41,6 @@ static unsigned long power_saving_mwait_eax;
 
 static unsigned char tsc_detected_unstable;
 static unsigned char tsc_marked_unstable;
-static unsigned char lapic_detected_unstable;
-static unsigned char lapic_marked_unstable;
 
 static void power_saving_mwait_init(void)
 {
@@ -82,13 +80,10 @@ static void power_saving_mwait_init(void)
 		 */
 		if (!boot_cpu_has(X86_FEATURE_NONSTOP_TSC))
 			tsc_detected_unstable = 1;
-		if (!boot_cpu_has(X86_FEATURE_ARAT))
-			lapic_detected_unstable = 1;
 		break;
 	default:
-		/* TSC & LAPIC could halt in idle */
+		/* TSC could halt in idle */
 		tsc_detected_unstable = 1;
-		lapic_detected_unstable = 1;
 	}
 #endif
 }
@@ -177,28 +172,17 @@ static int power_saving_thread(void *data)
 				mark_tsc_unstable("TSC halts in idle");
 				tsc_marked_unstable = 1;
 			}
-			if (lapic_detected_unstable && !lapic_marked_unstable) {
-				int i;
-				/* LAPIC could halt in idle, so notify users */
-				for_each_online_cpu(i)
-					clockevents_notify(
-						CLOCK_EVT_NOTIFY_BROADCAST_ON,
-						&i);
-				lapic_marked_unstable = 1;
-			}
+			clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ON, &cpu);
+
 			local_irq_disable();
 			cpu = smp_processor_id();
-			if (lapic_marked_unstable)
-				clockevents_notify(
-					CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &cpu);
+			clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &cpu);
 			stop_critical_timings();
 
 			mwait_idle_with_hints(power_saving_mwait_eax, 1);
 
 			start_critical_timings();
-			if (lapic_marked_unstable)
-				clockevents_notify(
-					CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &cpu);
+			clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &cpu);
 			local_irq_enable();
 
 			if (time_before(expire_time, jiffies)) {
#49 lore raw

PATCH v2 2/21 clockevents: Provide explicit broadcast control functions

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

clockevents_notify() is a leftover from the early design of the clockevents facility. It's really not a notification mechanism, it's a multiplex call. We are way better off to have explicit calls instead of this monstrosity.

Split out the broadcast control into a separate function and provide inline helpers. Switch clockevents_notify() over. This will go away once all callers are converted.

This also gets rid of the nested locking of clockevents_lock and broadcast_lock. The broadcast control functions do not require clockevents_lock. Only the managing functions (setup/shutdown/suspend/resume of the broadcast device require clockevents_lock.

---
 include/linux/tick.h         |   25 +++++++++++++++++
 kernel/time/clockevents.c    |    6 +++-
 kernel/time/tick-broadcast.c |   62 ++++++++++++++++++-------------------------
 kernel/time/tick-internal.h  |    2 -
 4 files changed, 57 insertions(+), 38 deletions(-)
include/linux/tick.h +25 -0
Index: linux-pm/include/linux/tick.h
===================================================================
@@ -42,6 +42,31 @@ extern void hotplug_cpu__broadcast_tick_
 static inline void hotplug_cpu__broadcast_tick_pull(int dead_cpu) { }
 #endif
 
+enum tick_broadcast_mode {
+	TICK_BROADCAST_OFF,
+	TICK_BROADCAST_ON,
+	TICK_BROADCAST_FORCE,
+};
+
+#ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
+extern void tick_broadcast_control(enum tick_broadcast_mode mode);
+#else
+static inline void tick_broadcast_control(enum tick_broadcast_mode mode) { }
+#endif /* BROADCAST */
+
+static inline void tick_broadcast_enable(void)
+{
+	tick_broadcast_control(TICK_BROADCAST_ON);
+}
+static inline void tick_broadcast_disable(void)
+{
+	tick_broadcast_control(TICK_BROADCAST_OFF);
+}
+static inline void tick_broadcast_force(void)
+{
+	tick_broadcast_control(TICK_BROADCAST_FORCE);
+}
+
 #ifdef CONFIG_NO_HZ_COMMON
 extern int tick_nohz_tick_stopped(void);
 extern void tick_nohz_idle_enter(void);
kernel/time/clockevents.c +5 -1
Index: linux-pm/kernel/time/clockevents.c
===================================================================
@@ -656,9 +656,13 @@ int clockevents_notify(unsigned long rea
 
 	switch (reason) {
 	case CLOCK_EVT_NOTIFY_BROADCAST_ON:
+		tick_broadcast_enable();
+		break;
 	case CLOCK_EVT_NOTIFY_BROADCAST_OFF:
+		tick_broadcast_disable();
+		break;
 	case CLOCK_EVT_NOTIFY_BROADCAST_FORCE:
-		tick_broadcast_on_off(reason, arg);
+		tick_broadcast_force();
 		break;
 
 	case CLOCK_EVT_NOTIFY_BROADCAST_ENTER:
kernel/time/tick-broadcast.c +27 -35

105 lines not on this page · raw message

kernel/time/tick-internal.h +0 -2
Index: linux-pm/kernel/time/tick-internal.h
===================================================================
@@ -53,7 +53,6 @@ extern ssize_t sysfs_get_uname(const cha
 extern int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu);
 extern void tick_install_broadcast_device(struct clock_event_device *dev);
 extern int tick_is_broadcast_device(struct clock_event_device *dev);
-extern void tick_broadcast_on_off(unsigned long reason, int *oncpu);
 extern void tick_shutdown_broadcast(unsigned int *cpup);
 extern void tick_suspend_broadcast(void);
 extern void tick_resume_broadcast(void);
@@ -68,7 +67,6 @@ static inline void tick_install_broadcas
 static inline int tick_is_broadcast_device(struct clock_event_device *dev) { return 0; }
 static inline int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu) { return 0; }
 static inline void tick_do_periodic_broadcast(struct clock_event_device *d) { }
-static inline void tick_broadcast_on_off(unsigned long reason, int *oncpu) { }
 static inline void tick_shutdown_broadcast(unsigned int *cpup) { }
 static inline void tick_suspend_broadcast(void) { }
 static inline void tick_resume_broadcast(void) { }
#50 lore raw

[tip:timers/core] clockevents: Provide explicit broadcast control functions

clockevents: Provide explicit broadcast control functions
Commit-ID:  592a438ff3fea61d303c5784c209b3f1fd3e16df
Gitweb:     http://git.kernel.org/tip/592a438ff3fea61d303c5784c209b3f1fd3e16df
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Fri, 3 Apr 2015 02:01:10 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 3 Apr 2015 08:44:31 +0200

clockevents: Provide explicit broadcast control functions

clockevents_notify() is a leftover from the early design of the clockevents facility. It's really not a notification mechanism, it's a multiplex call. We are way better off to have explicit calls instead of this monstrosity.

Split out the broadcast control into a separate function and provide inline helpers. Switch clockevents_notify() over. This will go away once all callers are converted.

This also gets rid of the nested locking of clockevents_lock and broadcast_lock. The broadcast control functions do not require clockevents_lock. Only the managing functions (setup/shutdown/suspend/resume of the broadcast device require clockevents_lock.

---
 include/linux/tick.h         | 25 ++++++++++++++++++
 kernel/time/clockevents.c    |  6 ++++-
 kernel/time/tick-broadcast.c | 62 +++++++++++++++++++-------------------------
 kernel/time/tick-internal.h  |  2 --
 4 files changed, 57 insertions(+), 38 deletions(-)
include/linux/tick.h +25 -0
index f9ff225..4bb2363 100644
@@ -42,6 +42,31 @@ extern void hotplug_cpu__broadcast_tick_pull(int dead_cpu);
 static inline void hotplug_cpu__broadcast_tick_pull(int dead_cpu) { }
 #endif
 
+enum tick_broadcast_mode {
+	TICK_BROADCAST_OFF,
+	TICK_BROADCAST_ON,
+	TICK_BROADCAST_FORCE,
+};
+
+#ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
+extern void tick_broadcast_control(enum tick_broadcast_mode mode);
+#else
+static inline void tick_broadcast_control(enum tick_broadcast_mode mode) { }
+#endif /* BROADCAST */
+
+static inline void tick_broadcast_enable(void)
+{
+	tick_broadcast_control(TICK_BROADCAST_ON);
+}
+static inline void tick_broadcast_disable(void)
+{
+	tick_broadcast_control(TICK_BROADCAST_OFF);
+}
+static inline void tick_broadcast_force(void)
+{
+	tick_broadcast_control(TICK_BROADCAST_FORCE);
+}
+
 #ifdef CONFIG_NO_HZ_COMMON
 extern int tick_nohz_tick_stopped(void);
 extern void tick_nohz_idle_enter(void);
kernel/time/clockevents.c +5 -1
index 7af6148..599ff8d 100644
@@ -656,9 +656,13 @@ int clockevents_notify(unsigned long reason, void *arg)
 
 	switch (reason) {
 	case CLOCK_EVT_NOTIFY_BROADCAST_ON:
+		tick_broadcast_enable();
+		break;
 	case CLOCK_EVT_NOTIFY_BROADCAST_OFF:
+		tick_broadcast_disable();
+		break;
 	case CLOCK_EVT_NOTIFY_BROADCAST_FORCE:
-		tick_broadcast_on_off(reason, arg);
+		tick_broadcast_force();
 		break;
 
 	case CLOCK_EVT_NOTIFY_BROADCAST_ENTER:
kernel/time/tick-broadcast.c +27 -35

105 lines not on this page · raw message

kernel/time/tick-internal.h +0 -2
index b6ba0a4..62e331d 100644
@@ -53,7 +53,6 @@ extern ssize_t sysfs_get_uname(const char *buf, char *dst, size_t cnt);
 extern int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu);
 extern void tick_install_broadcast_device(struct clock_event_device *dev);
 extern int tick_is_broadcast_device(struct clock_event_device *dev);
-extern void tick_broadcast_on_off(unsigned long reason, int *oncpu);
 extern void tick_shutdown_broadcast(unsigned int *cpup);
 extern void tick_suspend_broadcast(void);
 extern void tick_resume_broadcast(void);
@@ -68,7 +67,6 @@ static inline void tick_install_broadcast_device(struct clock_event_device *dev)
 static inline int tick_is_broadcast_device(struct clock_event_device *dev) { return 0; }
 static inline int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu) { return 0; }
 static inline void tick_do_periodic_broadcast(struct clock_event_device *d) { }
-static inline void tick_broadcast_on_off(unsigned long reason, int *oncpu) { }
 static inline void tick_shutdown_broadcast(unsigned int *cpup) { }
 static inline void tick_suspend_broadcast(void) { }
 static inline void tick_resume_broadcast(void) { }
#51 lore raw

PATCH v2 3/21 x86, amd_idle: Use explicit broadcast control function

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Replace the clockevents_notify() call with an explicit function call.

---
 arch/x86/kernel/process.c |    9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
arch/x86/kernel/process.c +3 -6
Index: linux-pm/arch/x86/kernel/process.c
===================================================================
@@ -9,7 +9,7 @@
 #include <linux/sched.h>
 #include <linux/module.h>
 #include <linux/pm.h>
-#include <linux/clockchips.h>
+#include <linux/tick.h>
 #include <linux/random.h>
 #include <linux/user-return-notifier.h>
 #include <linux/dmi.h>
@@ -377,11 +377,8 @@ static void amd_e400_idle(void)
 
 		if (!cpumask_test_cpu(cpu, amd_e400_c1e_mask)) {
 			cpumask_set_cpu(cpu, amd_e400_c1e_mask);
-			/*
-			 * Force broadcast so ACPI can not interfere.
-			 */
-			clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_FORCE,
-					   &cpu);
+			/* Force broadcast so ACPI can not interfere. */
+			tick_broadcast_force();
 			pr_info("Switch to broadcast mode on CPU%d\n", cpu);
 		}
 		clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &cpu);
#52 lore raw

[tip:timers/core] x86/amd/idle, clockevents: Use explicit broadcast control function

x86/amd/idle, clockevents: Use explicit broadcast control function
Commit-ID:  162a688e84df49c5bcc855a5e5bf812d0ec89ad5
Gitweb:     http://git.kernel.org/tip/162a688e84df49c5bcc855a5e5bf812d0ec89ad5
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Fri, 3 Apr 2015 02:01:28 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 3 Apr 2015 08:44:31 +0200

x86/amd/idle, clockevents: Use explicit broadcast control function

Replace the clockevents_notify() call with an explicit function call.

---
 arch/x86/kernel/process.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
arch/x86/kernel/process.c +3 -6
index 046e2d6..e94b733 100644
@@ -9,7 +9,7 @@
 #include <linux/sched.h>
 #include <linux/module.h>
 #include <linux/pm.h>
-#include <linux/clockchips.h>
+#include <linux/tick.h>
 #include <linux/random.h>
 #include <linux/user-return-notifier.h>
 #include <linux/dmi.h>
@@ -377,11 +377,8 @@ static void amd_e400_idle(void)
 
 		if (!cpumask_test_cpu(cpu, amd_e400_c1e_mask)) {
 			cpumask_set_cpu(cpu, amd_e400_c1e_mask);
-			/*
-			 * Force broadcast so ACPI can not interfere.
-			 */
-			clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_FORCE,
-					   &cpu);
+			/* Force broadcast so ACPI can not interfere. */
+			tick_broadcast_force();
 			pr_info("Switch to broadcast mode on CPU%d\n", cpu);
 		}
 		clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &cpu);
#53 lore raw

PATCH v2 4/21 ACPI / PAD: Use explicit broadcast control function

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Replace the clockevents_notify() call with an explicit function call.

---
 drivers/acpi/acpi_pad.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/acpi/acpi_pad.c +2 -3
Index: linux-pm/drivers/acpi/acpi_pad.c
===================================================================
@@ -26,7 +26,7 @@
 #include <linux/kthread.h>
 #include <linux/freezer.h>
 #include <linux/cpu.h>
-#include <linux/clockchips.h>
+#include <linux/tick.h>
 #include <linux/slab.h>
 #include <linux/acpi.h>
 #include <asm/mwait.h>
@@ -172,9 +172,8 @@ static int power_saving_thread(void *dat
 				mark_tsc_unstable("TSC halts in idle");
 				tsc_marked_unstable = 1;
 			}
-			clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ON, &cpu);
-
 			local_irq_disable();
+			tick_broadcast_enable();
 			cpu = smp_processor_id();
 			clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &cpu);
 			stop_critical_timings();
#54 lore raw

[tip:timers/core] ACPI/PAD: Use explicit broadcast control function

ACPI/PAD: Use explicit broadcast control function
Commit-ID:  979081e7440056da28b19e57acf20098caf49103
Gitweb:     http://git.kernel.org/tip/979081e7440056da28b19e57acf20098caf49103
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Fri, 3 Apr 2015 02:01:49 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 3 Apr 2015 08:44:32 +0200

ACPI/PAD: Use explicit broadcast control function

Replace the clockevents_notify() call with an explicit function call.

---
 drivers/acpi/acpi_pad.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/acpi/acpi_pad.c +2 -3
index 1686e9f..244dbc9 100644
@@ -26,7 +26,7 @@
 #include <linux/kthread.h>
 #include <linux/freezer.h>
 #include <linux/cpu.h>
-#include <linux/clockchips.h>
+#include <linux/tick.h>
 #include <linux/slab.h>
 #include <linux/acpi.h>
 #include <asm/mwait.h>
@@ -172,9 +172,8 @@ static int power_saving_thread(void *data)
 				mark_tsc_unstable("TSC halts in idle");
 				tsc_marked_unstable = 1;
 			}
-			clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ON, &cpu);
-
 			local_irq_disable();
+			tick_broadcast_enable();
 			cpu = smp_processor_id();
 			clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &cpu);
 			stop_critical_timings();
#55 lore raw

PATCH v2 5/21 ACPI / processor: Use explicit broadcast control function

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Replace the clockevents_notify() call with an explicit function call.

---
 drivers/acpi/processor_idle.c |   11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/acpi/processor_idle.c +5 -6
Index: linux-pm/drivers/acpi/processor_idle.c
===================================================================
@@ -32,7 +32,7 @@
 #include <linux/acpi.h>
 #include <linux/dmi.h>
 #include <linux/sched.h>       /* need_resched() */
-#include <linux/clockchips.h>
+#include <linux/tick.h>
 #include <linux/cpuidle.h>
 #include <linux/syscore_ops.h>
 #include <acpi/processor.h>
@@ -157,12 +157,11 @@ static void lapic_timer_check_state(int
 static void __lapic_timer_propagate_broadcast(void *arg)
 {
 	struct acpi_processor *pr = (struct acpi_processor *) arg;
-	unsigned long reason;
 
-	reason = pr->power.timer_broadcast_on_state < INT_MAX ?
-		CLOCK_EVT_NOTIFY_BROADCAST_ON : CLOCK_EVT_NOTIFY_BROADCAST_OFF;
-
-	clockevents_notify(reason, &pr->id);
+	if (pr->power.timer_broadcast_on_state < INT_MAX)
+		tick_broadcast_enable();
+	else
+		tick_broadcast_disable();
 }
 
 static void lapic_timer_propagate_broadcast(struct acpi_processor *pr)
#56 lore raw

[tip:timers/core] ACPI/processor: Use explicit broadcast control function

ACPI/processor: Use explicit broadcast control function
Commit-ID:  ee41eebf9cef624b2e766a4b8688eeeedb65114c
Gitweb:     http://git.kernel.org/tip/ee41eebf9cef624b2e766a4b8688eeeedb65114c
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Fri, 3 Apr 2015 02:02:00 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 3 Apr 2015 08:44:32 +0200

ACPI/processor: Use explicit broadcast control function

Replace the clockevents_notify() call with an explicit function call.

---
 drivers/acpi/processor_idle.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/acpi/processor_idle.c +5 -6
index c6bb9f1..be54797 100644
@@ -32,7 +32,7 @@
 #include <linux/acpi.h>
 #include <linux/dmi.h>
 #include <linux/sched.h>       /* need_resched() */
-#include <linux/clockchips.h>
+#include <linux/tick.h>
 #include <linux/cpuidle.h>
 #include <linux/syscore_ops.h>
 #include <acpi/processor.h>
@@ -157,12 +157,11 @@ static void lapic_timer_check_state(int state, struct acpi_processor *pr,
 static void __lapic_timer_propagate_broadcast(void *arg)
 {
 	struct acpi_processor *pr = (struct acpi_processor *) arg;
-	unsigned long reason;
 
-	reason = pr->power.timer_broadcast_on_state < INT_MAX ?
-		CLOCK_EVT_NOTIFY_BROADCAST_ON : CLOCK_EVT_NOTIFY_BROADCAST_OFF;
-
-	clockevents_notify(reason, &pr->id);
+	if (pr->power.timer_broadcast_on_state < INT_MAX)
+		tick_broadcast_enable();
+	else
+		tick_broadcast_disable();
 }
 
 static void lapic_timer_propagate_broadcast(struct acpi_processor *pr)
#57 lore raw

PATCH v2 6/21 cpuidle: Use explicit broadcast control function

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Replace the clockevents_notify() call with an explicit function call.

---
 drivers/cpuidle/driver.c |   25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)
drivers/cpuidle/driver.c +12 -13
Index: linux-pm/drivers/cpuidle/driver.c
===================================================================
@@ -13,7 +13,7 @@
 #include <linux/sched.h>
 #include <linux/cpuidle.h>
 #include <linux/cpumask.h>
-#include <linux/clockchips.h>
+#include <linux/tick.h>
 
 #include "cpuidle.h"
 
@@ -130,21 +130,20 @@ static inline void __cpuidle_unset_drive
 #endif
 
 /**
- * cpuidle_setup_broadcast_timer - enable/disable the broadcast timer
+ * cpuidle_setup_broadcast_timer - enable/disable the broadcast timer on a cpu
  * @arg: a void pointer used to match the SMP cross call API
  *
- * @arg is used as a value of type 'long' with one of the two values:
- * - CLOCK_EVT_NOTIFY_BROADCAST_ON
- * - CLOCK_EVT_NOTIFY_BROADCAST_OFF
- *
- * Set the broadcast timer notification for the current CPU.  This function
- * is executed per CPU by an SMP cross call.  It not supposed to be called
- * directly.
+ * If @arg is NULL broadcast is disabled otherwise enabled
+ *
+ * This function is executed per CPU by an SMP cross call.  It's not
+ * supposed to be called directly.
  */
 static void cpuidle_setup_broadcast_timer(void *arg)
 {
-	int cpu = smp_processor_id();
-	clockevents_notify((long)(arg), &cpu);
+	if (arg)
+		tick_broadcast_enable();
+	else
+		tick_broadcast_disable();
 }
 
 /**
@@ -239,7 +238,7 @@ static int __cpuidle_register_driver(str
 
 	if (drv->bctimer)
 		on_each_cpu_mask(drv->cpumask, cpuidle_setup_broadcast_timer,
-				 (void *)CLOCK_EVT_NOTIFY_BROADCAST_ON, 1);
+				 (void *)1, 1);
 
 	poll_idle_init(drv);
 
@@ -263,7 +262,7 @@ static void __cpuidle_unregister_driver(
 	if (drv->bctimer) {
 		drv->bctimer = 0;
 		on_each_cpu_mask(drv->cpumask, cpuidle_setup_broadcast_timer,
-				 (void *)CLOCK_EVT_NOTIFY_BROADCAST_OFF, 1);
+				 NULL, 1);
 	}
 
 	__cpuidle_unset_driver(drv);
#58 lore raw

[tip:timers/core] cpuidle: Use explicit broadcast control function

cpuidle: Use explicit broadcast control function
Commit-ID:  ee7a1438b548fb5e206058d6bd0e2a5adf081dbf
Gitweb:     http://git.kernel.org/tip/ee7a1438b548fb5e206058d6bd0e2a5adf081dbf
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Fri, 3 Apr 2015 02:02:18 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 3 Apr 2015 08:44:32 +0200

cpuidle: Use explicit broadcast control function

Replace the clockevents_notify() call with an explicit function call.

---
 drivers/cpuidle/driver.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)
drivers/cpuidle/driver.c +11 -12
index 2697e87..5db1478 100644
@@ -13,7 +13,7 @@
 #include <linux/sched.h>
 #include <linux/cpuidle.h>
 #include <linux/cpumask.h>
-#include <linux/clockchips.h>
+#include <linux/tick.h>
 
 #include "cpuidle.h"
 
@@ -130,21 +130,20 @@ static inline void __cpuidle_unset_driver(struct cpuidle_driver *drv)
 #endif
 
 /**
- * cpuidle_setup_broadcast_timer - enable/disable the broadcast timer
+ * cpuidle_setup_broadcast_timer - enable/disable the broadcast timer on a cpu
  * @arg: a void pointer used to match the SMP cross call API
  *
- * @arg is used as a value of type 'long' with one of the two values:
- * - CLOCK_EVT_NOTIFY_BROADCAST_ON
- * - CLOCK_EVT_NOTIFY_BROADCAST_OFF
+ * If @arg is NULL broadcast is disabled otherwise enabled
  *
- * Set the broadcast timer notification for the current CPU.  This function
- * is executed per CPU by an SMP cross call.  It not supposed to be called
- * directly.
+ * This function is executed per CPU by an SMP cross call.  It's not
+ * supposed to be called directly.
  */
 static void cpuidle_setup_broadcast_timer(void *arg)
 {
-	int cpu = smp_processor_id();
-	clockevents_notify((long)(arg), &cpu);
+	if (arg)
+		tick_broadcast_enable();
+	else
+		tick_broadcast_disable();
 }
 
 /**
@@ -239,7 +238,7 @@ static int __cpuidle_register_driver(struct cpuidle_driver *drv)
 
 	if (drv->bctimer)
 		on_each_cpu_mask(drv->cpumask, cpuidle_setup_broadcast_timer,
-				 (void *)CLOCK_EVT_NOTIFY_BROADCAST_ON, 1);
+				 (void *)1, 1);
 
 	poll_idle_init(drv);
 
@@ -263,7 +262,7 @@ static void __cpuidle_unregister_driver(struct cpuidle_driver *drv)
 	if (drv->bctimer) {
 		drv->bctimer = 0;
 		on_each_cpu_mask(drv->cpumask, cpuidle_setup_broadcast_timer,
-				 (void *)CLOCK_EVT_NOTIFY_BROADCAST_OFF, 1);
+				 NULL, 1);
 	}
 
 	__cpuidle_unset_driver(drv);
#59 lore raw

PATCH v2 7/21 intel_idle: Use explicit broadcast control function

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Replace the clockevents_notify() call with an explicit function call.

---
 drivers/idle/intel_idle.c |   13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/idle/intel_idle.c +6 -7
Index: linux-pm/drivers/idle/intel_idle.c
===================================================================
@@ -55,7 +55,7 @@
 
 #include <linux/kernel.h>
 #include <linux/cpuidle.h>
-#include <linux/clockchips.h>
+#include <linux/tick.h>
 #include <trace/events/power.h>
 #include <linux/sched.h>
 #include <linux/notifier.h>
@@ -665,13 +665,12 @@ static void intel_idle_freeze(struct cpu
 
 static void __setup_broadcast_timer(void *arg)
 {
-	unsigned long reason = (unsigned long)arg;
-	int cpu = smp_processor_id();
-
-	reason = reason ?
-		CLOCK_EVT_NOTIFY_BROADCAST_ON : CLOCK_EVT_NOTIFY_BROADCAST_OFF;
+	unsigned long on = (unsigned long)arg;
 
-	clockevents_notify(reason, &cpu);
+	if (on)
+		tick_broadcast_enable();
+	else
+		tick_broadcast_disable();
 }
 
 static int cpu_hotplug_notify(struct notifier_block *n,
#60 lore raw

[tip:timers/core] intel_idle: Use explicit broadcast control function

intel_idle: Use explicit broadcast control function
Commit-ID:  76962caa4b691ad09556903602143fc8b16802ae
Gitweb:     http://git.kernel.org/tip/76962caa4b691ad09556903602143fc8b16802ae
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Fri, 3 Apr 2015 02:02:34 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 3 Apr 2015 08:44:32 +0200

intel_idle: Use explicit broadcast control function

Replace the clockevents_notify() call with an explicit function call.

---
 drivers/idle/intel_idle.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/idle/intel_idle.c +6 -7
index b0e5852..93f84f7 100644
@@ -55,7 +55,7 @@
 
 #include <linux/kernel.h>
 #include <linux/cpuidle.h>
-#include <linux/clockchips.h>
+#include <linux/tick.h>
 #include <trace/events/power.h>
 #include <linux/sched.h>
 #include <linux/notifier.h>
@@ -665,13 +665,12 @@ static void intel_idle_freeze(struct cpuidle_device *dev,
 
 static void __setup_broadcast_timer(void *arg)
 {
-	unsigned long reason = (unsigned long)arg;
-	int cpu = smp_processor_id();
-
-	reason = reason ?
-		CLOCK_EVT_NOTIFY_BROADCAST_ON : CLOCK_EVT_NOTIFY_BROADCAST_OFF;
+	unsigned long on = (unsigned long)arg;
 
-	clockevents_notify(reason, &cpu);
+	if (on)
+		tick_broadcast_enable();
+	else
+		tick_broadcast_disable();
 }
 
 static int cpu_hotplug_notify(struct notifier_block *n,
#61 lore raw

PATCH v2 8/21 ARM: OMAP: Use explicit broadcast control function

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Replace the clockevents_notify() call with an explicit function call.

---
 arch/arm/mach-omap2/cpuidle44xx.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
arch/arm/mach-omap2/cpuidle44xx.c +2 -3
Index: linux-pm/arch/arm/mach-omap2/cpuidle44xx.c
===================================================================
@@ -14,7 +14,7 @@
 #include <linux/cpuidle.h>
 #include <linux/cpu_pm.h>
 #include <linux/export.h>
-#include <linux/clockchips.h>
+#include <linux/tick.h>
 
 #include <asm/cpuidle.h>
 
@@ -183,8 +183,7 @@ fail:
  */
 static void omap_setup_broadcast_timer(void *arg)
 {
-	int cpu = smp_processor_id();
-	clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ON, &cpu);
+	tick_broadcast_enable();
 }
 
 static struct cpuidle_driver omap4_idle_driver = {
#62 lore raw

[tip:timers/core] ARM: OMAP: Use explicit broadcast control function

ARM: OMAP: Use explicit broadcast control function
Commit-ID:  fa8589fe3bfafadd80677c8eabae97dc5dab22c0
Gitweb:     http://git.kernel.org/tip/fa8589fe3bfafadd80677c8eabae97dc5dab22c0
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Fri, 3 Apr 2015 02:02:47 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 3 Apr 2015 08:44:33 +0200

ARM: OMAP: Use explicit broadcast control function

Replace the clockevents_notify() call with an explicit function call.

---
 arch/arm/mach-omap2/cpuidle44xx.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
arch/arm/mach-omap2/cpuidle44xx.c +2 -3
index 01e398a..9284dc5 100644
@@ -14,7 +14,7 @@
 #include <linux/cpuidle.h>
 #include <linux/cpu_pm.h>
 #include <linux/export.h>
-#include <linux/clockchips.h>
+#include <linux/tick.h>
 
 #include <asm/cpuidle.h>
 #include <asm/proc-fns.h>
@@ -184,8 +184,7 @@ fail:
  */
 static void omap_setup_broadcast_timer(void *arg)
 {
-	int cpu = smp_processor_id();
-	clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ON, &cpu);
+	tick_broadcast_enable();
 }
 
 static struct cpuidle_driver omap4_idle_driver = {
#63 lore raw

PATCH v2 9/21 clockevents: Remove the broadcast control leftovers

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

All users converted. Remove the notify leftovers.

---
 include/linux/clockchips.h |    3 ---
 kernel/time/clockevents.c  |   10 ----------
 2 files changed, 13 deletions(-)
include/linux/clockchips.h +0 -3
Index: linux-pm/include/linux/clockchips.h
===================================================================
@@ -11,9 +11,6 @@
 /* Clock event notification values */
 enum clock_event_nofitiers {
 	CLOCK_EVT_NOTIFY_ADD,
-	CLOCK_EVT_NOTIFY_BROADCAST_ON,
-	CLOCK_EVT_NOTIFY_BROADCAST_OFF,
-	CLOCK_EVT_NOTIFY_BROADCAST_FORCE,
 	CLOCK_EVT_NOTIFY_BROADCAST_ENTER,
 	CLOCK_EVT_NOTIFY_BROADCAST_EXIT,
 	CLOCK_EVT_NOTIFY_CPU_DYING,
kernel/time/clockevents.c +0 -10
Index: linux-pm/kernel/time/clockevents.c
===================================================================
@@ -655,16 +655,6 @@ int clockevents_notify(unsigned long rea
 	raw_spin_lock_irqsave(&clockevents_lock, flags);
 
 	switch (reason) {
-	case CLOCK_EVT_NOTIFY_BROADCAST_ON:
-		tick_broadcast_enable();
-		break;
-	case CLOCK_EVT_NOTIFY_BROADCAST_OFF:
-		tick_broadcast_disable();
-		break;
-	case CLOCK_EVT_NOTIFY_BROADCAST_FORCE:
-		tick_broadcast_force();
-		break;
-
 	case CLOCK_EVT_NOTIFY_BROADCAST_ENTER:
 	case CLOCK_EVT_NOTIFY_BROADCAST_EXIT:
 		ret = tick_broadcast_oneshot_control(reason);
#64 lore raw

[tip:timers/core] clockevents: Remove the broadcast control leftovers

clockevents: Remove the broadcast control leftovers
Commit-ID:  89feddbfe7023ccfb4a6d7f5e3f5161d91b28b18
Gitweb:     http://git.kernel.org/tip/89feddbfe7023ccfb4a6d7f5e3f5161d91b28b18
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Fri, 3 Apr 2015 02:03:42 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 3 Apr 2015 08:44:33 +0200

clockevents: Remove the broadcast control leftovers

All users converted. Remove the notify leftovers.

---
 include/linux/clockchips.h |  3 ---
 kernel/time/clockevents.c  | 10 ----------
 2 files changed, 13 deletions(-)
include/linux/clockchips.h +0 -3
index caeca76..438fafa 100644
@@ -11,9 +11,6 @@
 /* Clock event notification values */
 enum clock_event_nofitiers {
 	CLOCK_EVT_NOTIFY_ADD,
-	CLOCK_EVT_NOTIFY_BROADCAST_ON,
-	CLOCK_EVT_NOTIFY_BROADCAST_OFF,
-	CLOCK_EVT_NOTIFY_BROADCAST_FORCE,
 	CLOCK_EVT_NOTIFY_BROADCAST_ENTER,
 	CLOCK_EVT_NOTIFY_BROADCAST_EXIT,
 	CLOCK_EVT_NOTIFY_CPU_DYING,
kernel/time/clockevents.c +0 -10
index 599ff8d..dba0b83 100644
@@ -655,16 +655,6 @@ int clockevents_notify(unsigned long reason, void *arg)
 	raw_spin_lock_irqsave(&clockevents_lock, flags);
 
 	switch (reason) {
-	case CLOCK_EVT_NOTIFY_BROADCAST_ON:
-		tick_broadcast_enable();
-		break;
-	case CLOCK_EVT_NOTIFY_BROADCAST_OFF:
-		tick_broadcast_disable();
-		break;
-	case CLOCK_EVT_NOTIFY_BROADCAST_FORCE:
-		tick_broadcast_force();
-		break;
-
 	case CLOCK_EVT_NOTIFY_BROADCAST_ENTER:
 	case CLOCK_EVT_NOTIFY_BROADCAST_EXIT:
 		ret = tick_broadcast_oneshot_control(reason);
#65 lore raw

PATCH v2 10/21 clockevents: Provide explicit broadcast oneshot control functions

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

clockevents_notify() is a leftover from the early design of the clockevents facility. It's really not a notification mechanism, it's a multiplex call. We are way better off to have explicit calls instead of this monstrosity.

Split out the broadcast oneshot control into a separate function and provide inline helpers. Switch clockevents_notify() over. This will go away once all callers are converted.

This also gets rid of the nested locking of clockevents_lock and broadcast_lock. The broadcast oneshot control functions do not require clockevents_lock. Only the managing functions (setup/shutdown/suspend/resume of the broadcast device require clockevents_lock.

Cc Tony Lindgren <[email protected]>
Cc Stephen Warren <[email protected]>
Cc Thierry Reding <[email protected]>
Cc Alexandre Courbot <[email protected]>
Cc Daniel Lezcano <[email protected]>
Cc Len Brown <[email protected]>
---
 include/linux/tick.h         |   19 +++++++++++++++++++
 kernel/time/clockevents.c    |    4 +++-
 kernel/time/tick-broadcast.c |   28 +++++++++++++++++-----------
 kernel/time/tick-internal.h  |    2 --
 4 files changed, 39 insertions(+), 14 deletions(-)
include/linux/tick.h +19 -0
Index: linux-pm/include/linux/tick.h
===================================================================
@@ -48,12 +48,23 @@ enum tick_broadcast_mode {
 	TICK_BROADCAST_FORCE,
 };
 
+enum tick_broadcast_state {
+	TICK_BROADCAST_EXIT,
+	TICK_BROADCAST_ENTER,
+};
+
 #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
 extern void tick_broadcast_control(enum tick_broadcast_mode mode);
 #else
 static inline void tick_broadcast_control(enum tick_broadcast_mode mode) { }
 #endif /* BROADCAST */
 
+#if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
+extern int tick_broadcast_oneshot_control(enum tick_broadcast_state state);
+#else
+static inline int tick_broadcast_oneshot_control(enum tick_broadcast_state state) { return 0; }
+#endif
+
 static inline void tick_broadcast_enable(void)
 {
 	tick_broadcast_control(TICK_BROADCAST_ON);
@@ -66,6 +77,14 @@ static inline void tick_broadcast_force(
 {
 	tick_broadcast_control(TICK_BROADCAST_FORCE);
 }
+static inline int tick_broadcast_enter(void)
+{
+	return tick_broadcast_oneshot_control(TICK_BROADCAST_ENTER);
+}
+static inline void tick_broadcast_exit(void)
+{
+	tick_broadcast_oneshot_control(TICK_BROADCAST_EXIT);
+}
 
 #ifdef CONFIG_NO_HZ_COMMON
 extern int tick_nohz_tick_stopped(void);
kernel/time/clockevents.c +3 -1
Index: linux-pm/kernel/time/clockevents.c
===================================================================
@@ -656,8 +656,10 @@ int clockevents_notify(unsigned long rea
 
 	switch (reason) {
 	case CLOCK_EVT_NOTIFY_BROADCAST_ENTER:
+		tick_broadcast_enter();
+		break;
 	case CLOCK_EVT_NOTIFY_BROADCAST_EXIT:
-		ret = tick_broadcast_oneshot_control(reason);
+		tick_broadcast_exit();
 		break;
 
 	case CLOCK_EVT_NOTIFY_CPU_DYING:
kernel/time/tick-broadcast.c +17 -11
Index: linux-pm/kernel/time/tick-broadcast.c
===================================================================
@@ -687,18 +687,23 @@ void hotplug_cpu__broadcast_tick_pull(in
 	raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags);
 }
 
-/*
- * Powerstate information: The system enters/leaves a state, where
- * affected devices might stop
+/**
+ * tick_broadcast_oneshot_control - Enter/exit broadcast oneshot mode
+ * @state:	The target state (enter/exit)
+ *
+ * The system enters/leaves a state, where affected devices might stop
  * Returns 0 on success, -EBUSY if the cpu is used to broadcast wakeups.
+ *
+ * Called with interrupts disabled, so clockevents_lock is not
+ * required here because the local clock event device cannot go away
+ * under us.
  */
-int tick_broadcast_oneshot_control(unsigned long reason)
+int tick_broadcast_oneshot_control(enum tick_broadcast_state state)
 {
 	struct clock_event_device *bc, *dev;
 	struct tick_device *td;
-	unsigned long flags;
-	ktime_t now;
 	int cpu, ret = 0;
+	ktime_t now;
 
 	/*
 	 * Periodic mode does not care about the enter/exit of power
@@ -711,17 +716,17 @@ int tick_broadcast_oneshot_control(unsig
 	 * We are called with preemtion disabled from the depth of the
 	 * idle code, so we can't be moved away.
 	 */
-	cpu = smp_processor_id();
-	td = &per_cpu(tick_cpu_device, cpu);
+	td = this_cpu_ptr(&tick_cpu_device);
 	dev = td->evtdev;
 
 	if (!(dev->features & CLOCK_EVT_FEAT_C3STOP))
 		return 0;
 
+	raw_spin_lock(&tick_broadcast_lock);
 	bc = tick_broadcast_device.evtdev;
+	cpu = smp_processor_id();
 
-	raw_spin_lock_irqsave(&tick_broadcast_lock, flags);
-	if (reason == CLOCK_EVT_NOTIFY_BROADCAST_ENTER) {
+	if (state == TICK_BROADCAST_ENTER) {
 		if (!cpumask_test_and_set_cpu(cpu, tick_broadcast_oneshot_mask)) {
 			WARN_ON_ONCE(cpumask_test_cpu(cpu, tick_broadcast_pending_mask));
 			broadcast_shutdown_local(bc, dev);
@@ -813,9 +818,10 @@ int tick_broadcast_oneshot_control(unsig
 		}
 	}
 out:
-	raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags);
+	raw_spin_unlock(&tick_broadcast_lock);
 	return ret;
 }
+EXPORT_SYMBOL_GPL(tick_broadcast_oneshot_control);
 
 /*
  * Reset the one shot broadcast for a cpu
kernel/time/tick-internal.h +0 -2
Index: linux-pm/kernel/time/tick-internal.h
===================================================================
@@ -119,7 +119,6 @@ static inline int tick_check_oneshot_cha
 /* Functions related to oneshot broadcasting */
 #if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
 extern void tick_broadcast_setup_oneshot(struct clock_event_device *bc);
-extern int tick_broadcast_oneshot_control(unsigned long reason);
 extern void tick_broadcast_switch_to_oneshot(void);
 extern void tick_shutdown_broadcast_oneshot(unsigned int *cpup);
 extern int tick_broadcast_oneshot_active(void);
@@ -128,7 +127,6 @@ bool tick_broadcast_oneshot_available(vo
 extern struct cpumask *tick_get_broadcast_oneshot_mask(void);
 #else /* !(BROADCAST && ONESHOT): */
 static inline void tick_broadcast_setup_oneshot(struct clock_event_device *bc) { BUG(); }
-static inline int tick_broadcast_oneshot_control(unsigned long reason) { return 0; }
 static inline void tick_broadcast_switch_to_oneshot(void) { }
 static inline void tick_shutdown_broadcast_oneshot(unsigned int *cpup) { }
 static inline int tick_broadcast_oneshot_active(void) { return 0; }
#66 lore raw

[tip:timers/core] clockevents: Provide explicit broadcast oneshot control functions

clockevents: Provide explicit broadcast oneshot control functions
Commit-ID:  1fe5d5c3c9ba0c4ade18e3325cba0ffe35127941
Gitweb:     http://git.kernel.org/tip/1fe5d5c3c9ba0c4ade18e3325cba0ffe35127941
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Fri, 3 Apr 2015 02:05:15 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 3 Apr 2015 08:44:33 +0200

clockevents: Provide explicit broadcast oneshot control functions

clockevents_notify() is a leftover from the early design of the clockevents facility. It's really not a notification mechanism, it's a multiplex call. We are way better off to have explicit calls instead of this monstrosity.

Split out the broadcast oneshot control into a separate function and provide inline helpers. Switch clockevents_notify() over. This will go away once all callers are converted.

This also gets rid of the nested locking of clockevents_lock and broadcast_lock. The broadcast oneshot control functions do not require clockevents_lock. Only the managing functions (setup/shutdown/suspend/resume of the broadcast device require clockevents_lock.

---
 include/linux/tick.h         | 19 +++++++++++++++++++
 kernel/time/clockevents.c    |  4 +++-
 kernel/time/tick-broadcast.c | 28 +++++++++++++++++-----------
 kernel/time/tick-internal.h  |  2 --
 4 files changed, 39 insertions(+), 14 deletions(-)
include/linux/tick.h +19 -0
index 4bb2363..6119321 100644
@@ -48,12 +48,23 @@ enum tick_broadcast_mode {
 	TICK_BROADCAST_FORCE,
 };
 
+enum tick_broadcast_state {
+	TICK_BROADCAST_EXIT,
+	TICK_BROADCAST_ENTER,
+};
+
 #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
 extern void tick_broadcast_control(enum tick_broadcast_mode mode);
 #else
 static inline void tick_broadcast_control(enum tick_broadcast_mode mode) { }
 #endif /* BROADCAST */
 
+#if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
+extern int tick_broadcast_oneshot_control(enum tick_broadcast_state state);
+#else
+static inline int tick_broadcast_oneshot_control(enum tick_broadcast_state state) { return 0; }
+#endif
+
 static inline void tick_broadcast_enable(void)
 {
 	tick_broadcast_control(TICK_BROADCAST_ON);
@@ -66,6 +77,14 @@ static inline void tick_broadcast_force(void)
 {
 	tick_broadcast_control(TICK_BROADCAST_FORCE);
 }
+static inline int tick_broadcast_enter(void)
+{
+	return tick_broadcast_oneshot_control(TICK_BROADCAST_ENTER);
+}
+static inline void tick_broadcast_exit(void)
+{
+	tick_broadcast_oneshot_control(TICK_BROADCAST_EXIT);
+}
 
 #ifdef CONFIG_NO_HZ_COMMON
 extern int tick_nohz_tick_stopped(void);
kernel/time/clockevents.c +3 -1
index dba0b83..7791b1c 100644
@@ -656,8 +656,10 @@ int clockevents_notify(unsigned long reason, void *arg)
 
 	switch (reason) {
 	case CLOCK_EVT_NOTIFY_BROADCAST_ENTER:
+		tick_broadcast_enter();
+		break;
 	case CLOCK_EVT_NOTIFY_BROADCAST_EXIT:
-		ret = tick_broadcast_oneshot_control(reason);
+		tick_broadcast_exit();
 		break;
 
 	case CLOCK_EVT_NOTIFY_CPU_DYING:
kernel/time/tick-broadcast.c +17 -11
index 1a0bee0..55e43f2 100644
@@ -687,18 +687,23 @@ void hotplug_cpu__broadcast_tick_pull(int deadcpu)
 	raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags);
 }
 
-/*
- * Powerstate information: The system enters/leaves a state, where
- * affected devices might stop
+/**
+ * tick_broadcast_oneshot_control - Enter/exit broadcast oneshot mode
+ * @state:	The target state (enter/exit)
+ *
+ * The system enters/leaves a state, where affected devices might stop
  * Returns 0 on success, -EBUSY if the cpu is used to broadcast wakeups.
+ *
+ * Called with interrupts disabled, so clockevents_lock is not
+ * required here because the local clock event device cannot go away
+ * under us.
  */
-int tick_broadcast_oneshot_control(unsigned long reason)
+int tick_broadcast_oneshot_control(enum tick_broadcast_state state)
 {
 	struct clock_event_device *bc, *dev;
 	struct tick_device *td;
-	unsigned long flags;
-	ktime_t now;
 	int cpu, ret = 0;
+	ktime_t now;
 
 	/*
 	 * Periodic mode does not care about the enter/exit of power
@@ -711,17 +716,17 @@ int tick_broadcast_oneshot_control(unsigned long reason)
 	 * We are called with preemtion disabled from the depth of the
 	 * idle code, so we can't be moved away.
 	 */
-	cpu = smp_processor_id();
-	td = &per_cpu(tick_cpu_device, cpu);
+	td = this_cpu_ptr(&tick_cpu_device);
 	dev = td->evtdev;
 
 	if (!(dev->features & CLOCK_EVT_FEAT_C3STOP))
 		return 0;
 
+	raw_spin_lock(&tick_broadcast_lock);
 	bc = tick_broadcast_device.evtdev;
+	cpu = smp_processor_id();
 
-	raw_spin_lock_irqsave(&tick_broadcast_lock, flags);
-	if (reason == CLOCK_EVT_NOTIFY_BROADCAST_ENTER) {
+	if (state == TICK_BROADCAST_ENTER) {
 		if (!cpumask_test_and_set_cpu(cpu, tick_broadcast_oneshot_mask)) {
 			WARN_ON_ONCE(cpumask_test_cpu(cpu, tick_broadcast_pending_mask));
 			broadcast_shutdown_local(bc, dev);
@@ -813,9 +818,10 @@ int tick_broadcast_oneshot_control(unsigned long reason)
 		}
 	}
 out:
-	raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags);
+	raw_spin_unlock(&tick_broadcast_lock);
 	return ret;
 }
+EXPORT_SYMBOL_GPL(tick_broadcast_oneshot_control);
 
 /*
  * Reset the one shot broadcast for a cpu
kernel/time/tick-internal.h +0 -2
index 62e331d..0266f9d 100644
@@ -117,7 +117,6 @@ static inline int tick_check_oneshot_change(int allow_nohz) { return 0; }
 /* Functions related to oneshot broadcasting */
 #if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
 extern void tick_broadcast_setup_oneshot(struct clock_event_device *bc);
-extern int tick_broadcast_oneshot_control(unsigned long reason);
 extern void tick_broadcast_switch_to_oneshot(void);
 extern void tick_shutdown_broadcast_oneshot(unsigned int *cpup);
 extern int tick_broadcast_oneshot_active(void);
@@ -126,7 +125,6 @@ bool tick_broadcast_oneshot_available(void);
 extern struct cpumask *tick_get_broadcast_oneshot_mask(void);
 #else /* !(BROADCAST && ONESHOT): */
 static inline void tick_broadcast_setup_oneshot(struct clock_event_device *bc) { BUG(); }
-static inline int tick_broadcast_oneshot_control(unsigned long reason) { return 0; }
 static inline void tick_broadcast_switch_to_oneshot(void) { }
 static inline void tick_shutdown_broadcast_oneshot(unsigned int *cpup) { }
 static inline int tick_broadcast_oneshot_active(void) { return 0; }
#67 lore raw

PATCH v2 11/21 x86, amd_idle: Use explicit broadcast oneshot control functions

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Replace the clockevents_notify() call with an explicit function call.

---
 arch/x86/kernel/process.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/process.c +2 -2
Index: linux-pm/arch/x86/kernel/process.c
===================================================================
@@ -381,7 +381,7 @@ static void amd_e400_idle(void)
 			tick_broadcast_force();
 			pr_info("Switch to broadcast mode on CPU%d\n", cpu);
 		}
-		clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &cpu);
+		tick_broadcast_enter();
 
 		default_idle();
 
@@ -390,7 +390,7 @@ static void amd_e400_idle(void)
 		 * called with interrupts disabled.
 		 */
 		local_irq_disable();
-		clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &cpu);
+		tick_broadcast_exit();
 		local_irq_enable();
 	} else
 		default_idle();
#68 lore raw

[tip:timers/core] x86/amd/idle, clockevents: Use explicit broadcast oneshot control functions

x86/amd/idle, clockevents: Use explicit broadcast oneshot control functions
Commit-ID:  435c350e8197488f12c97e7df28a9c2199bd1673
Gitweb:     http://git.kernel.org/tip/435c350e8197488f12c97e7df28a9c2199bd1673
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Fri, 3 Apr 2015 02:05:53 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 3 Apr 2015 08:44:34 +0200

x86/amd/idle, clockevents: Use explicit broadcast oneshot control functions

Replace the clockevents_notify() call with an explicit function call.

---
 arch/x86/kernel/process.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/process.c +2 -2
index e94b733..2f43c62 100644
@@ -381,7 +381,7 @@ static void amd_e400_idle(void)
 			tick_broadcast_force();
 			pr_info("Switch to broadcast mode on CPU%d\n", cpu);
 		}
-		clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &cpu);
+		tick_broadcast_enter();
 
 		default_idle();
 
@@ -390,7 +390,7 @@ static void amd_e400_idle(void)
 		 * called with interrupts disabled.
 		 */
 		local_irq_disable();
-		clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &cpu);
+		tick_broadcast_exit();
 		local_irq_enable();
 	} else
 		default_idle();
#69 lore raw

PATCH v2 12/21 ACPI / PAD: Use explicit broadcast oneshot control function

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Replace the clockevents_notify() call with an explicit function call.

---
 drivers/acpi/acpi_pad.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/acpi/acpi_pad.c +2 -4
Index: linux-pm/drivers/acpi/acpi_pad.c
===================================================================
@@ -150,7 +150,6 @@ static int power_saving_thread(void *dat
 	sched_setscheduler(current, SCHED_RR, &param);
 
 	while (!kthread_should_stop()) {
-		int cpu;
 		unsigned long expire_time;
 
 		try_to_freeze();
@@ -174,14 +173,13 @@ static int power_saving_thread(void *dat
 			}
 			local_irq_disable();
 			tick_broadcast_enable();
-			cpu = smp_processor_id();
-			clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &cpu);
+			tick_broadcast_enter();
 			stop_critical_timings();
 
 			mwait_idle_with_hints(power_saving_mwait_eax, 1);
 
 			start_critical_timings();
-			clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &cpu);
+			tick_broadcast_exit();
 			local_irq_enable();
 
 			if (time_before(expire_time, jiffies)) {
#70 lore raw

[tip:timers/core] ACPI/PAD: Use explicit broadcast oneshot control function

ACPI/PAD: Use explicit broadcast oneshot control function
Commit-ID:  c79521354e71a1fbcee040ee3147cadc0f8e3c97
Gitweb:     http://git.kernel.org/tip/c79521354e71a1fbcee040ee3147cadc0f8e3c97
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Fri, 3 Apr 2015 02:06:37 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 3 Apr 2015 08:44:34 +0200

ACPI/PAD: Use explicit broadcast oneshot control function

Replace the clockevents_notify() call with an explicit function call.

---
 drivers/acpi/acpi_pad.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/acpi/acpi_pad.c +2 -4
index 244dbc9..6bc9cbc 100644
@@ -150,7 +150,6 @@ static int power_saving_thread(void *data)
 	sched_setscheduler(current, SCHED_RR, &param);
 
 	while (!kthread_should_stop()) {
-		int cpu;
 		unsigned long expire_time;
 
 		try_to_freeze();
@@ -174,14 +173,13 @@ static int power_saving_thread(void *data)
 			}
 			local_irq_disable();
 			tick_broadcast_enable();
-			cpu = smp_processor_id();
-			clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &cpu);
+			tick_broadcast_enter();
 			stop_critical_timings();
 
 			mwait_idle_with_hints(power_saving_mwait_eax, 1);
 
 			start_critical_timings();
-			clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &cpu);
+			tick_broadcast_exit();
 			local_irq_enable();
 
 			if (time_before(expire_time, jiffies)) {
#71 lore raw

PATCH v2 13/21 ACPI / processor: Use explicit broadcast controll function

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Replace the clockevents_notify() call with an explicit function call.

---
 drivers/acpi/processor_idle.c |    9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/acpi/processor_idle.c +4 -5
Index: linux-pm/drivers/acpi/processor_idle.c
===================================================================
@@ -178,11 +178,10 @@ static void lapic_timer_state_broadcast(
 	int state = cx - pr->power.states;
 
 	if (state >= pr->power.timer_broadcast_on_state) {
-		unsigned long reason;
-
-		reason = broadcast ?  CLOCK_EVT_NOTIFY_BROADCAST_ENTER :
-			CLOCK_EVT_NOTIFY_BROADCAST_EXIT;
-		clockevents_notify(reason, &pr->id);
+		if (broadcast)
+			tick_broadcast_enter();
+		else
+			tick_broadcast_exit();
 	}
 }
 
#72 lore raw

[tip:timers/core] ACPI/idle: Use explicit broadcast control function

ACPI/idle: Use explicit broadcast control function
Commit-ID:  7815701c5cd7276b712d898b3cf49c55e587dbb1
Gitweb:     http://git.kernel.org/tip/7815701c5cd7276b712d898b3cf49c55e587dbb1
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Fri, 3 Apr 2015 02:12:03 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 3 Apr 2015 08:44:34 +0200

ACPI/idle: Use explicit broadcast control function

Replace the clockevents_notify() call with an explicit function call.

---
 drivers/acpi/processor_idle.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/acpi/processor_idle.c +4 -5
index be54797..5335519 100644
@@ -178,11 +178,10 @@ static void lapic_timer_state_broadcast(struct acpi_processor *pr,
 	int state = cx - pr->power.states;
 
 	if (state >= pr->power.timer_broadcast_on_state) {
-		unsigned long reason;
-
-		reason = broadcast ?  CLOCK_EVT_NOTIFY_BROADCAST_ENTER :
-			CLOCK_EVT_NOTIFY_BROADCAST_EXIT;
-		clockevents_notify(reason, &pr->id);
+		if (broadcast)
+			tick_broadcast_enter();
+		else
+			tick_broadcast_exit();
 	}
 }
 
#73 lore raw

PATCH v2 14/21 intel_idle: Use explicit broadcast oneshot control function

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Replace the clockevents_notify() call with an explicit function call.

---
 drivers/idle/intel_idle.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/idle/intel_idle.c +2 -2
Index: linux-pm/drivers/idle/intel_idle.c
===================================================================
@@ -638,12 +638,12 @@ static int intel_idle(struct cpuidle_dev
 		leave_mm(cpu);
 
 	if (!(lapic_timer_reliable_states & (1 << (cstate))))
-		clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &cpu);
+		tick_broadcast_enter();
 
 	mwait_idle_with_hints(eax, ecx);
 
 	if (!(lapic_timer_reliable_states & (1 << (cstate))))
-		clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &cpu);
+		tick_broadcast_exit();
 
 	return index;
 }
#74 lore raw

[tip:timers/core] intel_idle: Use explicit broadcast oneshot control function

intel_idle: Use explicit broadcast oneshot control function
Commit-ID:  f6cee191fc6b286f9056a13456c4c8ade0aeb890
Gitweb:     http://git.kernel.org/tip/f6cee191fc6b286f9056a13456c4c8ade0aeb890
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Fri, 3 Apr 2015 02:14:23 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 3 Apr 2015 08:44:35 +0200

intel_idle: Use explicit broadcast oneshot control function

Replace the clockevents_notify() call with an explicit function call.

---
 drivers/idle/intel_idle.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/idle/intel_idle.c +2 -2
index 93f84f7..5c979d0 100644
@@ -638,12 +638,12 @@ static int intel_idle(struct cpuidle_device *dev,
 		leave_mm(cpu);
 
 	if (!(lapic_timer_reliable_states & (1 << (cstate))))
-		clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &cpu);
+		tick_broadcast_enter();
 
 	mwait_idle_with_hints(eax, ecx);
 
 	if (!(lapic_timer_reliable_states & (1 << (cstate))))
-		clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &cpu);
+		tick_broadcast_exit();
 
 	return index;
 }
#75 lore raw

PATCH v2 15/21 ARM: OMAP: Use explicit broadcast oneshot control function

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Replace the clockevents_notify() call with an explicit function call.

---
 arch/arm/mach-omap2/cpuidle44xx.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
arch/arm/mach-omap2/cpuidle44xx.c +2 -3
Index: linux-pm/arch/arm/mach-omap2/cpuidle44xx.c
===================================================================
@@ -83,7 +83,6 @@ static int omap_enter_idle_coupled(struc
 {
 	struct idle_statedata *cx = state_ptr + index;
 	u32 mpuss_can_lose_context = 0;
-	int cpu_id = smp_processor_id();
 
 	/*
 	 * CPU0 has to wait and stay ON until CPU1 is OFF state.
@@ -111,7 +110,7 @@ static int omap_enter_idle_coupled(struc
 	mpuss_can_lose_context = (cx->mpu_state == PWRDM_POWER_RET) &&
 				 (cx->mpu_logic_state == PWRDM_POWER_OFF);
 
-	clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &cpu_id);
+	tick_broadcast_enter();
 
 	/*
 	 * Call idle CPU PM enter notifier chain so that
@@ -168,7 +167,7 @@ static int omap_enter_idle_coupled(struc
 	if (dev->cpu == 0 && mpuss_can_lose_context)
 		cpu_cluster_pm_exit();
 
-	clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &cpu_id);
+	tick_broadcast_exit();
 
 fail:
 	cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
#76 lore raw

[tip:timers/core] ARM: OMAP: Use explicit broadcast oneshot control function

ARM: OMAP: Use explicit broadcast oneshot control function
Commit-ID:  fb7f0398a98020def9429ddd7b4a8fc2d948b092
Gitweb:     http://git.kernel.org/tip/fb7f0398a98020def9429ddd7b4a8fc2d948b092
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Fri, 3 Apr 2015 02:31:29 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 3 Apr 2015 08:44:35 +0200

ARM: OMAP: Use explicit broadcast oneshot control function

Replace the clockevents_notify() call with an explicit function call.

---
 arch/arm/mach-omap2/cpuidle44xx.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
arch/arm/mach-omap2/cpuidle44xx.c +2 -3
index 9284dc5..57d4298 100644
@@ -84,7 +84,6 @@ static int omap_enter_idle_coupled(struct cpuidle_device *dev,
 {
 	struct idle_statedata *cx = state_ptr + index;
 	u32 mpuss_can_lose_context = 0;
-	int cpu_id = smp_processor_id();
 
 	/*
 	 * CPU0 has to wait and stay ON until CPU1 is OFF state.
@@ -112,7 +111,7 @@ static int omap_enter_idle_coupled(struct cpuidle_device *dev,
 	mpuss_can_lose_context = (cx->mpu_state == PWRDM_POWER_RET) &&
 				 (cx->mpu_logic_state == PWRDM_POWER_OFF);
 
-	clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &cpu_id);
+	tick_broadcast_enter();
 
 	/*
 	 * Call idle CPU PM enter notifier chain so that
@@ -169,7 +168,7 @@ static int omap_enter_idle_coupled(struct cpuidle_device *dev,
 	if (dev->cpu == 0 && mpuss_can_lose_context)
 		cpu_cluster_pm_exit();
 
-	clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &cpu_id);
+	tick_broadcast_exit();
 
 fail:
 	cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
#77 lore raw

PATCH v2 16/21 ARM: tegra: Use explicit broadcast oneshot control function

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Replace the clockevents_notify() call with an explicit function call.

Cc Stephen Warren <[email protected]>
Cc Thierry Reding <[email protected]>
Cc Alexandre Courbot <[email protected]>
---
 arch/arm/mach-tegra/cpuidle-tegra114.c |    6 +++---
 arch/arm/mach-tegra/cpuidle-tegra20.c  |   10 +++++-----
 arch/arm/mach-tegra/cpuidle-tegra30.c  |   10 +++++-----
 3 files changed, 13 insertions(+), 13 deletions(-)
arch/arm/mach-tegra/cpuidle-tegra114.c +3 -3
Index: linux-pm/arch/arm/mach-tegra/cpuidle-tegra114.c
===================================================================
@@ -15,7 +15,7 @@
  */
 
 #include <asm/firmware.h>
-#include <linux/clockchips.h>
+#include <linux/tick.h>
 #include <linux/cpuidle.h>
 #include <linux/cpu_pm.h>
 #include <linux/kernel.h>
@@ -44,7 +44,7 @@ static int tegra114_idle_power_down(stru
 	tegra_set_cpu_in_lp2();
 	cpu_pm_enter();
 
-	clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &dev->cpu);
+	tick_broadcast_enter();
 
 	call_firmware_op(prepare_idle);
 
@@ -52,7 +52,7 @@ static int tegra114_idle_power_down(stru
 	if (call_firmware_op(do_idle, 0) == -ENOSYS)
 		cpu_suspend(0, tegra30_sleep_cpu_secondary_finish);
 
-	clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &dev->cpu);
+	tick_broadcast_exit();
 
 	cpu_pm_exit();
 	tegra_clear_cpu_in_lp2();
arch/arm/mach-tegra/cpuidle-tegra20.c +5 -5
Index: linux-pm/arch/arm/mach-tegra/cpuidle-tegra20.c
===================================================================
@@ -20,7 +20,7 @@
  */
 
 #include <linux/clk/tegra.h>
-#include <linux/clockchips.h>
+#include <linux/tick.h>
 #include <linux/cpuidle.h>
 #include <linux/cpu_pm.h>
 #include <linux/kernel.h>
@@ -135,11 +135,11 @@ static bool tegra20_cpu_cluster_power_do
 	if (tegra20_reset_cpu_1() || !tegra_cpu_rail_off_ready())
 		return false;
 
-	clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &dev->cpu);
+	tick_broadcast_enter();
 
 	tegra_idle_lp2_last();
 
-	clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &dev->cpu);
+	tick_broadcast_exit();
 
 	if (cpu_online(1))
 		tegra20_wake_cpu1_from_reset();
@@ -152,13 +152,13 @@ static bool tegra20_idle_enter_lp2_cpu_1
 					 struct cpuidle_driver *drv,
 					 int index)
 {
-	clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &dev->cpu);
+	tick_broadcast_enter();
 
 	cpu_suspend(0, tegra20_sleep_cpu_secondary_finish);
 
 	tegra20_cpu_clear_resettable();
 
-	clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &dev->cpu);
+	tick_broadcast_exit();
 
 	return true;
 }
arch/arm/mach-tegra/cpuidle-tegra30.c +5 -5
Index: linux-pm/arch/arm/mach-tegra/cpuidle-tegra30.c
===================================================================
@@ -20,7 +20,7 @@
  */
 
 #include <linux/clk/tegra.h>
-#include <linux/clockchips.h>
+#include <linux/tick.h>
 #include <linux/cpuidle.h>
 #include <linux/cpu_pm.h>
 #include <linux/kernel.h>
@@ -75,11 +75,11 @@ static bool tegra30_cpu_cluster_power_do
 		return false;
 	}
 
-	clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &dev->cpu);
+	tick_broadcast_enter();
 
 	tegra_idle_lp2_last();
 
-	clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &dev->cpu);
+	tick_broadcast_exit();
 
 	return true;
 }
@@ -89,13 +89,13 @@ static bool tegra30_cpu_core_power_down(
 					struct cpuidle_driver *drv,
 					int index)
 {
-	clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &dev->cpu);
+	tick_broadcast_enter();
 
 	smp_wmb();
 
 	cpu_suspend(0, tegra30_sleep_cpu_secondary_finish);
 
-	clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &dev->cpu);
+	tick_broadcast_exit();
 
 	return true;
 }
#78 lore raw

[tip:timers/core] ARM: Tegra: Use explicit broadcast oneshot control function

ARM: Tegra: Use explicit broadcast oneshot control function
Commit-ID:  a0b4122447a3c1a467ce4e4f1bb863e1170394d5
Gitweb:     http://git.kernel.org/tip/a0b4122447a3c1a467ce4e4f1bb863e1170394d5
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Fri, 3 Apr 2015 02:32:14 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 3 Apr 2015 08:44:35 +0200

ARM: Tegra: Use explicit broadcast oneshot control function

Replace the clockevents_notify() call with an explicit function call.

---
 arch/arm/mach-tegra/cpuidle-tegra114.c |  6 +++---
 arch/arm/mach-tegra/cpuidle-tegra20.c  | 10 +++++-----
 arch/arm/mach-tegra/cpuidle-tegra30.c  | 10 +++++-----
 3 files changed, 13 insertions(+), 13 deletions(-)
arch/arm/mach-tegra/cpuidle-tegra114.c +3 -3
index f2b586d..155807f 100644
@@ -15,7 +15,7 @@
  */
 
 #include <asm/firmware.h>
-#include <linux/clockchips.h>
+#include <linux/tick.h>
 #include <linux/cpuidle.h>
 #include <linux/cpu_pm.h>
 #include <linux/kernel.h>
@@ -44,7 +44,7 @@ static int tegra114_idle_power_down(struct cpuidle_device *dev,
 	tegra_set_cpu_in_lp2();
 	cpu_pm_enter();
 
-	clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &dev->cpu);
+	tick_broadcast_enter();
 
 	call_firmware_op(prepare_idle);
 
@@ -52,7 +52,7 @@ static int tegra114_idle_power_down(struct cpuidle_device *dev,
 	if (call_firmware_op(do_idle, 0) == -ENOSYS)
 		cpu_suspend(0, tegra30_sleep_cpu_secondary_finish);
 
-	clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &dev->cpu);
+	tick_broadcast_exit();
 
 	cpu_pm_exit();
 	tegra_clear_cpu_in_lp2();
arch/arm/mach-tegra/cpuidle-tegra20.c +5 -5
index 4f25a7c..48844ae 100644
@@ -20,7 +20,7 @@
  */
 
 #include <linux/clk/tegra.h>
-#include <linux/clockchips.h>
+#include <linux/tick.h>
 #include <linux/cpuidle.h>
 #include <linux/cpu_pm.h>
 #include <linux/kernel.h>
@@ -136,11 +136,11 @@ static bool tegra20_cpu_cluster_power_down(struct cpuidle_device *dev,
 	if (tegra20_reset_cpu_1() || !tegra_cpu_rail_off_ready())
 		return false;
 
-	clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &dev->cpu);
+	tick_broadcast_enter();
 
 	tegra_idle_lp2_last();
 
-	clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &dev->cpu);
+	tick_broadcast_exit();
 
 	if (cpu_online(1))
 		tegra20_wake_cpu1_from_reset();
@@ -153,13 +153,13 @@ static bool tegra20_idle_enter_lp2_cpu_1(struct cpuidle_device *dev,
 					 struct cpuidle_driver *drv,
 					 int index)
 {
-	clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &dev->cpu);
+	tick_broadcast_enter();
 
 	cpu_suspend(0, tegra20_sleep_cpu_secondary_finish);
 
 	tegra20_cpu_clear_resettable();
 
-	clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &dev->cpu);
+	tick_broadcast_exit();
 
 	return true;
 }
arch/arm/mach-tegra/cpuidle-tegra30.c +5 -5
index f8815ed..84d809a 100644
@@ -20,7 +20,7 @@
  */
 
 #include <linux/clk/tegra.h>
-#include <linux/clockchips.h>
+#include <linux/tick.h>
 #include <linux/cpuidle.h>
 #include <linux/cpu_pm.h>
 #include <linux/kernel.h>
@@ -76,11 +76,11 @@ static bool tegra30_cpu_cluster_power_down(struct cpuidle_device *dev,
 		return false;
 	}
 
-	clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &dev->cpu);
+	tick_broadcast_enter();
 
 	tegra_idle_lp2_last();
 
-	clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &dev->cpu);
+	tick_broadcast_exit();
 
 	return true;
 }
@@ -90,13 +90,13 @@ static bool tegra30_cpu_core_power_down(struct cpuidle_device *dev,
 					struct cpuidle_driver *drv,
 					int index)
 {
-	clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &dev->cpu);
+	tick_broadcast_enter();
 
 	smp_wmb();
 
 	cpu_suspend(0, tegra30_sleep_cpu_secondary_finish);
 
-	clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &dev->cpu);
+	tick_broadcast_exit();
 
 	return true;
 }
#79 lore raw

PATCH v2 17/21 sched/idle: Use explicit broadcast oneshot control function

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Replace the clockevents_notify() call with an explicit function call.

---
 kernel/sched/idle.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
kernel/sched/idle.c +2 -3
Index: linux-pm/kernel/sched/idle.c
===================================================================
@@ -158,8 +158,7 @@ static void cpuidle_idle_call(void)
 	 * is used from another cpu as a broadcast timer, this call may
 	 * fail if it is not available
 	 */
-	if (broadcast &&
-	    clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &dev->cpu))
+	if (broadcast && tick_broadcast_enter())
 		goto use_default;
 
 	/* Take note of the planned idle state. */
@@ -176,7 +175,7 @@ static void cpuidle_idle_call(void)
 	idle_set_state(this_rq(), NULL);
 
 	if (broadcast)
-		clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &dev->cpu);
+		tick_broadcast_exit();
 
 	/*
 	 * Give the governor an opportunity to reflect on the outcome
#80 lore raw

[tip:timers/core] sched/idle: Use explicit broadcast oneshot control function

sched/idle: Use explicit broadcast oneshot control function
Commit-ID:  335f49196fd6011521f078cb44f445847e5aa183
Gitweb:     http://git.kernel.org/tip/335f49196fd6011521f078cb44f445847e5aa183
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Fri, 3 Apr 2015 02:34:49 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 3 Apr 2015 08:44:36 +0200

sched/idle: Use explicit broadcast oneshot control function

Replace the clockevents_notify() call with an explicit function call.

---
 kernel/sched/idle.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
kernel/sched/idle.c +2 -3
index 80014a1..4d207d2 100644
@@ -158,8 +158,7 @@ static void cpuidle_idle_call(void)
 	 * is used from another cpu as a broadcast timer, this call may
 	 * fail if it is not available
 	 */
-	if (broadcast &&
-	    clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &dev->cpu))
+	if (broadcast && tick_broadcast_enter())
 		goto use_default;
 
 	/* Take note of the planned idle state. */
@@ -176,7 +175,7 @@ static void cpuidle_idle_call(void)
 	idle_set_state(this_rq(), NULL);
 
 	if (broadcast)
-		clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &dev->cpu);
+		tick_broadcast_exit();
 
 	/*
 	 * Give the governor an opportunity to reflect on the outcome
#81 lore raw

PATCH v2 18/21 clockevents: Remove broadcast oneshot control leftovers

In reply to Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

All users converted. Remove the notify leftovers.

---
 include/linux/clockchips.h |    2 --
 kernel/time/clockevents.c  |    7 -------
 2 files changed, 9 deletions(-)
include/linux/clockchips.h +0 -2
Index: linux-pm/include/linux/clockchips.h
===================================================================
@@ -11,8 +11,6 @@
 /* Clock event notification values */
 enum clock_event_nofitiers {
 	CLOCK_EVT_NOTIFY_ADD,
-	CLOCK_EVT_NOTIFY_BROADCAST_ENTER,
-	CLOCK_EVT_NOTIFY_BROADCAST_EXIT,
 	CLOCK_EVT_NOTIFY_CPU_DYING,
 	CLOCK_EVT_NOTIFY_CPU_DEAD,
 };
kernel/time/clockevents.c +0 -7
Index: linux-pm/kernel/time/clockevents.c
===================================================================
@@ -655,13 +655,6 @@ int clockevents_notify(unsigned long rea
 	raw_spin_lock_irqsave(&clockevents_lock, flags);
 
 	switch (reason) {
-	case CLOCK_EVT_NOTIFY_BROADCAST_ENTER:
-		tick_broadcast_enter();
-		break;
-	case CLOCK_EVT_NOTIFY_BROADCAST_EXIT:
-		tick_broadcast_exit();
-		break;
-
 	case CLOCK_EVT_NOTIFY_CPU_DYING:
 		tick_handover_do_timer(arg);
 		break;
#82 lore raw

[tip:timers/core] clockevents: Remove broadcast oneshot control leftovers

clockevents: Remove broadcast oneshot control leftovers
Commit-ID:  ffa48c0d76803057ee89bf220305466d74256d7b
Gitweb:     http://git.kernel.org/tip/ffa48c0d76803057ee89bf220305466d74256d7b
Author:     Rafael J. Wysocki <[email protected]>
AuthorDate: Fri, 3 Apr 2015 02:36:10 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 3 Apr 2015 08:44:36 +0200

clockevents: Remove broadcast oneshot control leftovers

Now that all users are converted over to explicit calls into the clockevents state machine, remove the notification chain leftovers.

Original-from: Thomas Gleixner <[email protected]>

---
 include/linux/clockchips.h | 2 --
 kernel/time/clockevents.c  | 7 -------
 2 files changed, 9 deletions(-)
include/linux/clockchips.h +0 -2
index 438fafa..f97f498 100644
@@ -11,8 +11,6 @@
 /* Clock event notification values */
 enum clock_event_nofitiers {
 	CLOCK_EVT_NOTIFY_ADD,
-	CLOCK_EVT_NOTIFY_BROADCAST_ENTER,
-	CLOCK_EVT_NOTIFY_BROADCAST_EXIT,
 	CLOCK_EVT_NOTIFY_CPU_DYING,
 	CLOCK_EVT_NOTIFY_CPU_DEAD,
 };
kernel/time/clockevents.c +0 -7
index 7791b1c..be9abf3 100644
@@ -655,13 +655,6 @@ int clockevents_notify(unsigned long reason, void *arg)
 	raw_spin_lock_irqsave(&clockevents_lock, flags);
 
 	switch (reason) {
-	case CLOCK_EVT_NOTIFY_BROADCAST_ENTER:
-		tick_broadcast_enter();
-		break;
-	case CLOCK_EVT_NOTIFY_BROADCAST_EXIT:
-		tick_broadcast_exit();
-		break;
-
 	case CLOCK_EVT_NOTIFY_CPU_DYING:
 		tick_handover_do_timer(arg);
 		break;
#83 lore raw

PATCH v2 19/21 clockevents: Make tick handover explicit

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

clockevents_notify() is a leftover from the early design of the clockevents facility. It's really not a notification mechanism, it's a multiplex call. We are way better off to have explicit calls instead of this monstrosity.

Split out the tick_handover call and invoke it explicitely from the hotplug code. Temporary solution will be cleaned up in later patches.

---
 include/linux/clockchips.h  |    1 -
 include/linux/tick.h        |    2 ++
 kernel/cpu.c                |    2 ++
 kernel/time/clockevents.c   |    4 ----
 kernel/time/hrtimer.c       |    4 ----
 kernel/time/tick-common.c   |    9 ++++++---
 kernel/time/tick-internal.h |    1 -
 7 files changed, 10 insertions(+), 13 deletions(-)
include/linux/clockchips.h +0 -1
Index: linux-pm/include/linux/clockchips.h
===================================================================
@@ -11,7 +11,6 @@
 /* Clock event notification values */
 enum clock_event_nofitiers {
 	CLOCK_EVT_NOTIFY_ADD,
-	CLOCK_EVT_NOTIFY_CPU_DYING,
 	CLOCK_EVT_NOTIFY_CPU_DEAD,
 };
 
include/linux/tick.h +2 -0
Index: linux-pm/include/linux/tick.h
===================================================================
@@ -19,12 +19,14 @@ extern void tick_unfreeze(void);
 extern void tick_suspend_local(void);
 /* Should be core only, but XEN resume magic and ARM BL switcher require it */
 extern void tick_resume_local(void);
+extern void tick_handover_do_timer(void);
 #else /* CONFIG_GENERIC_CLOCKEVENTS */
 static inline void tick_init(void) { }
 static inline void tick_freeze(void) { }
 static inline void tick_unfreeze(void) { }
 static inline void tick_suspend_local(void) { }
 static inline void tick_resume_local(void) { }
+static inline void tick_handover_do_timer(void) { }
 #endif /* !CONFIG_GENERIC_CLOCKEVENTS */
 
 #ifdef CONFIG_TICK_ONESHOT
kernel/cpu.c +2 -0
Index: linux-pm/kernel/cpu.c
===================================================================
@@ -339,6 +339,8 @@ static int __ref take_cpu_down(void *_pa
 		return err;
 
 	cpu_notify(CPU_DYING | param->mod, param->hcpu);
+	/* Give up timekeeping duties */
+	tick_handover_do_timer();
 	/* Park the stopper thread */
 	kthread_park(current);
 	return 0;
kernel/time/clockevents.c +0 -4
Index: linux-pm/kernel/time/clockevents.c
===================================================================
@@ -655,10 +655,6 @@ int clockevents_notify(unsigned long rea
 	raw_spin_lock_irqsave(&clockevents_lock, flags);
 
 	switch (reason) {
-	case CLOCK_EVT_NOTIFY_CPU_DYING:
-		tick_handover_do_timer(arg);
-		break;
-
 	case CLOCK_EVT_NOTIFY_CPU_DEAD:
 		tick_shutdown_broadcast_oneshot(arg);
 		tick_shutdown_broadcast(arg);
kernel/time/hrtimer.c +0 -4
Index: linux-pm/kernel/time/hrtimer.c
===================================================================
@@ -1707,10 +1707,6 @@ static int hrtimer_cpu_notify(struct not
 		break;
 
 #ifdef CONFIG_HOTPLUG_CPU
-	case CPU_DYING:
-	case CPU_DYING_FROZEN:
-		clockevents_notify(CLOCK_EVT_NOTIFY_CPU_DYING, &scpu);
-		break;
 	case CPU_DEAD:
 	case CPU_DEAD_FROZEN:
 	{
kernel/time/tick-common.c +6 -3
Index: linux-pm/kernel/time/tick-common.c
===================================================================
@@ -332,20 +332,23 @@ out_bc:
 	tick_install_broadcast_device(newdev);
 }
 
+#ifdef CONFIG_HOTPLUG_CPU
 /*
  * Transfer the do_timer job away from a dying cpu.
  *
- * Called with interrupts disabled.
+ * Called with interrupts disabled. Not locking required. If
+ * tick_do_timer_cpu is owned by this cpu, nothing can change it.
  */
-void tick_handover_do_timer(int *cpup)
+void tick_handover_do_timer(void)
 {
-	if (*cpup == tick_do_timer_cpu) {
+	if (tick_do_timer_cpu == smp_processor_id()) {
 		int cpu = cpumask_first(cpu_online_mask);
 
 		tick_do_timer_cpu = (cpu < nr_cpu_ids) ? cpu :
 			TICK_DO_TIMER_NONE;
 	}
 }
+#endif
 
 /*
  * Shutdown an event device on a given cpu:
kernel/time/tick-internal.h +0 -1
Index: linux-pm/kernel/time/tick-internal.h
===================================================================
@@ -20,7 +20,6 @@ extern int tick_do_timer_cpu __read_most
 extern void tick_setup_periodic(struct clock_event_device *dev, int broadcast);
 extern void tick_handle_periodic(struct clock_event_device *dev);
 extern void tick_check_new_device(struct clock_event_device *dev);
-extern void tick_handover_do_timer(int *cpup);
 extern void tick_shutdown(unsigned int *cpup);
 extern void tick_suspend(void);
 extern void tick_resume(void);
#84 lore raw

[tip:timers/core] clockevents: Make tick handover explicit

clockevents: Make tick handover explicit
Commit-ID:  52c063d1adbc16c76e70fffa20727fcd4e9343b3
Gitweb:     http://git.kernel.org/tip/52c063d1adbc16c76e70fffa20727fcd4e9343b3
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Fri, 3 Apr 2015 02:37:24 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 3 Apr 2015 08:44:36 +0200

clockevents: Make tick handover explicit

clockevents_notify() is a leftover from the early design of the clockevents facility. It's really not a notification mechanism, it's a multiplex call. We are way better off to have explicit calls instead of this monstrosity.

Split out the tick_handover call and invoke it explicitely from the hotplug code. Temporary solution will be cleaned up in later patches.

---
 include/linux/clockchips.h  | 1 -
 include/linux/tick.h        | 2 ++
 kernel/cpu.c                | 2 ++
 kernel/time/clockevents.c   | 4 ----
 kernel/time/hrtimer.c       | 4 ----
 kernel/time/tick-common.c   | 9 ++++++---
 kernel/time/tick-internal.h | 1 -
 7 files changed, 10 insertions(+), 13 deletions(-)
include/linux/clockchips.h +0 -1
index f97f498..f4bde22 100644
@@ -11,7 +11,6 @@
 /* Clock event notification values */
 enum clock_event_nofitiers {
 	CLOCK_EVT_NOTIFY_ADD,
-	CLOCK_EVT_NOTIFY_CPU_DYING,
 	CLOCK_EVT_NOTIFY_CPU_DEAD,
 };
 
include/linux/tick.h +2 -0
index 6119321..2c68fa3 100644
@@ -19,12 +19,14 @@ extern void tick_unfreeze(void);
 extern void tick_suspend_local(void);
 /* Should be core only, but XEN resume magic and ARM BL switcher require it */
 extern void tick_resume_local(void);
+extern void tick_handover_do_timer(void);
 #else /* CONFIG_GENERIC_CLOCKEVENTS */
 static inline void tick_init(void) { }
 static inline void tick_freeze(void) { }
 static inline void tick_unfreeze(void) { }
 static inline void tick_suspend_local(void) { }
 static inline void tick_resume_local(void) { }
+static inline void tick_handover_do_timer(void) { }
 #endif /* !CONFIG_GENERIC_CLOCKEVENTS */
 
 #ifdef CONFIG_TICK_ONESHOT
kernel/cpu.c +2 -0
index af5db20..eba7eaa 100644
@@ -339,6 +339,8 @@ static int __ref take_cpu_down(void *_param)
 		return err;
 
 	cpu_notify(CPU_DYING | param->mod, param->hcpu);
+	/* Give up timekeeping duties */
+	tick_handover_do_timer();
 	/* Park the stopper thread */
 	kthread_park(current);
 	return 0;
kernel/time/clockevents.c +0 -4
index be9abf3..88fb3b9 100644
@@ -655,10 +655,6 @@ int clockevents_notify(unsigned long reason, void *arg)
 	raw_spin_lock_irqsave(&clockevents_lock, flags);
 
 	switch (reason) {
-	case CLOCK_EVT_NOTIFY_CPU_DYING:
-		tick_handover_do_timer(arg);
-		break;
-
 	case CLOCK_EVT_NOTIFY_CPU_DEAD:
 		tick_shutdown_broadcast_oneshot(arg);
 		tick_shutdown_broadcast(arg);
kernel/time/hrtimer.c +0 -4
index 721d29b..6a7a64e 100644
@@ -1707,10 +1707,6 @@ static int hrtimer_cpu_notify(struct notifier_block *self,
 		break;
 
 #ifdef CONFIG_HOTPLUG_CPU
-	case CPU_DYING:
-	case CPU_DYING_FROZEN:
-		clockevents_notify(CLOCK_EVT_NOTIFY_CPU_DYING, &scpu);
-		break;
 	case CPU_DEAD:
 	case CPU_DEAD_FROZEN:
 	{
kernel/time/tick-common.c +6 -3
index e28ba5c..055c868 100644
@@ -332,20 +332,23 @@ out_bc:
 	tick_install_broadcast_device(newdev);
 }
 
+#ifdef CONFIG_HOTPLUG_CPU
 /*
  * Transfer the do_timer job away from a dying cpu.
  *
- * Called with interrupts disabled.
+ * Called with interrupts disabled. Not locking required. If
+ * tick_do_timer_cpu is owned by this cpu, nothing can change it.
  */
-void tick_handover_do_timer(int *cpup)
+void tick_handover_do_timer(void)
 {
-	if (*cpup == tick_do_timer_cpu) {
+	if (tick_do_timer_cpu == smp_processor_id()) {
 		int cpu = cpumask_first(cpu_online_mask);
 
 		tick_do_timer_cpu = (cpu < nr_cpu_ids) ? cpu :
 			TICK_DO_TIMER_NONE;
 	}
 }
+#endif
 
 /*
  * Shutdown an event device on a given cpu:
kernel/time/tick-internal.h +0 -1
index 0266f9d..aabcb5d 100644
@@ -20,7 +20,6 @@ extern int tick_do_timer_cpu __read_mostly;
 extern void tick_setup_periodic(struct clock_event_device *dev, int broadcast);
 extern void tick_handle_periodic(struct clock_event_device *dev);
 extern void tick_check_new_device(struct clock_event_device *dev);
-extern void tick_handover_do_timer(int *cpup);
 extern void tick_shutdown(unsigned int *cpup);
 extern void tick_suspend(void);
 extern void tick_resume(void);
#85 lore raw

PATCH v2 20/21 clockevents: Cleanup dead cpu explicitely

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

clockevents_notify() is a leftover from the early design of the clockevents facility. It's really not a notification mechanism, it's a multiplex call. We are way better off to have explicit calls instead of this monstrosity.

Split out the cleanup function for a dead cpu and invoke it directly from the cpu down code. Make it conditional on CPU_HOTPLUG as well.

Temporary change, will be refined in the future.

[ rjw: Rebased, added clockevents_notify() removal ]
---
 include/linux/clockchips.h   |    6 -----
 include/linux/tick.h         |    2 +
 kernel/cpu.c                 |    1 
 kernel/time/clockevents.c    |   51 +++++++++++++++++--------------------------
 kernel/time/hrtimer.c        |    3 --
 kernel/time/tick-broadcast.c |   39 ++++++++++++++++----------------
 kernel/time/tick-common.c    |    6 ++---
 kernel/time/tick-internal.h  |   10 ++++----
 8 files changed, 52 insertions(+), 66 deletions(-)
include/linux/clockchips.h +0 -6
Index: linux-pm/include/linux/clockchips.h
===================================================================
@@ -8,12 +8,6 @@
 #ifndef _LINUX_CLOCKCHIPS_H
 #define _LINUX_CLOCKCHIPS_H
 
-/* Clock event notification values */
-enum clock_event_nofitiers {
-	CLOCK_EVT_NOTIFY_ADD,
-	CLOCK_EVT_NOTIFY_CPU_DEAD,
-};
-
 #ifdef CONFIG_GENERIC_CLOCKEVENTS
 
 # include <linux/clocksource.h>
include/linux/tick.h +2 -0
Index: linux-pm/include/linux/tick.h
===================================================================
@@ -20,6 +20,7 @@ extern void tick_suspend_local(void);
 /* Should be core only, but XEN resume magic and ARM BL switcher require it */
 extern void tick_resume_local(void);
 extern void tick_handover_do_timer(void);
+extern void tick_cleanup_dead_cpu(int cpu);
 #else /* CONFIG_GENERIC_CLOCKEVENTS */
 static inline void tick_init(void) { }
 static inline void tick_freeze(void) { }
@@ -27,6 +28,7 @@ static inline void tick_unfreeze(void) {
 static inline void tick_suspend_local(void) { }
 static inline void tick_resume_local(void) { }
 static inline void tick_handover_do_timer(void) { }
+static inline void tick_cleanup_dead_cpu(int cpu) { }
 #endif /* !CONFIG_GENERIC_CLOCKEVENTS */
 
 #ifdef CONFIG_TICK_ONESHOT
kernel/cpu.c +1 -0
Index: linux-pm/kernel/cpu.c
===================================================================
@@ -419,6 +419,7 @@ static int __ref _cpu_down(unsigned int
 	__cpu_die(cpu);
 
 	/* CPU is completely dead: tell everyone.  Too late to complain. */
+	tick_cleanup_dead_cpu(cpu);
 	cpu_notify_nofail(CPU_DEAD | mod, hcpu);
 
 	check_for_tasks(cpu);
kernel/time/clockevents.c +21 -30

70 lines not on this page · raw message

kernel/time/hrtimer.c +0 -3
Index: linux-pm/kernel/time/hrtimer.c
===================================================================
@@ -1709,11 +1709,8 @@ static int hrtimer_cpu_notify(struct not
 #ifdef CONFIG_HOTPLUG_CPU
 	case CPU_DEAD:
 	case CPU_DEAD_FROZEN:
-	{
-		clockevents_notify(CLOCK_EVT_NOTIFY_CPU_DEAD, &scpu);
 		migrate_hrtimers(scpu);
 		break;
-	}
 #endif
 
 	default:
kernel/time/tick-broadcast.c +20 -19
Index: linux-pm/kernel/time/tick-broadcast.c
===================================================================
@@ -410,14 +410,14 @@ void tick_set_periodic_handler(struct cl
 		dev->event_handler = tick_handle_periodic_broadcast;
 }
 
+#ifdef CONFIG_HOTPLUG_CPU
 /*
  * Remove a CPU from broadcasting
  */
-void tick_shutdown_broadcast(unsigned int *cpup)
+void tick_shutdown_broadcast(unsigned int cpu)
 {
 	struct clock_event_device *bc;
 	unsigned long flags;
-	unsigned int cpu = *cpup;
 
 	raw_spin_lock_irqsave(&tick_broadcast_lock, flags);
 
@@ -432,6 +432,7 @@ void tick_shutdown_broadcast(unsigned in
 
 	raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags);
 }
+#endif
 
 void tick_suspend_broadcast(void)
 {
@@ -672,21 +673,6 @@ static void broadcast_shutdown_local(str
 	clockevents_set_state(dev, CLOCK_EVT_STATE_SHUTDOWN);
 }
 
-void hotplug_cpu__broadcast_tick_pull(int deadcpu)
-{
-	struct clock_event_device *bc;
-	unsigned long flags;
-
-	raw_spin_lock_irqsave(&tick_broadcast_lock, flags);
-	bc = tick_broadcast_device.evtdev;
-
-	if (bc && broadcast_needs_cpu(bc, deadcpu)) {
-		/* This moves the broadcast assignment to this CPU: */
-		clockevents_program_event(bc, bc->next_event, 1);
-	}
-	raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags);
-}
-
 /**
  * tick_broadcast_oneshot_control - Enter/exit broadcast oneshot mode
  * @state:	The target state (enter/exit)
@@ -908,14 +894,28 @@ void tick_broadcast_switch_to_oneshot(vo
 	raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags);
 }
 
+#ifdef CONFIG_HOTPLUG_CPU
+void hotplug_cpu__broadcast_tick_pull(int deadcpu)
+{
+	struct clock_event_device *bc;
+	unsigned long flags;
+
+	raw_spin_lock_irqsave(&tick_broadcast_lock, flags);
+	bc = tick_broadcast_device.evtdev;
+
+	if (bc && broadcast_needs_cpu(bc, deadcpu)) {
+		/* This moves the broadcast assignment to this CPU: */
+		clockevents_program_event(bc, bc->next_event, 1);
+	}
+	raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags);
+}
 
 /*
  * Remove a dead CPU from broadcasting
  */
-void tick_shutdown_broadcast_oneshot(unsigned int *cpup)
+void tick_shutdown_broadcast_oneshot(unsigned int cpu)
 {
 	unsigned long flags;
-	unsigned int cpu = *cpup;
 
 	raw_spin_lock_irqsave(&tick_broadcast_lock, flags);
 
@@ -929,6 +929,7 @@ void tick_shutdown_broadcast_oneshot(uns
 
 	raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags);
 }
+#endif
 
 /*
  * Check, whether the broadcast device is in one shot mode
kernel/time/tick-common.c +3 -3
Index: linux-pm/kernel/time/tick-common.c
===================================================================
@@ -348,7 +348,6 @@ void tick_handover_do_timer(void)
 			TICK_DO_TIMER_NONE;
 	}
 }
-#endif
 
 /*
  * Shutdown an event device on a given cpu:
@@ -357,9 +356,9 @@ void tick_handover_do_timer(void)
  * access the hardware device itself.
  * We just set the mode and remove it from the lists.
  */
-void tick_shutdown(unsigned int *cpup)
+void tick_shutdown(unsigned int cpu)
 {
-	struct tick_device *td = &per_cpu(tick_cpu_device, *cpup);
+	struct tick_device *td = &per_cpu(tick_cpu_device, cpu);
 	struct clock_event_device *dev = td->evtdev;
 
 	td->mode = TICKDEV_MODE_PERIODIC;
@@ -375,6 +374,7 @@ void tick_shutdown(unsigned int *cpup)
 		td->evtdev = NULL;
 	}
 }
+#endif
 
 /**
  * tick_suspend_local - Suspend the local tick device
kernel/time/tick-internal.h +5 -5
Index: linux-pm/kernel/time/tick-internal.h
===================================================================
@@ -20,7 +20,7 @@ extern int tick_do_timer_cpu __read_most
 extern void tick_setup_periodic(struct clock_event_device *dev, int broadcast);
 extern void tick_handle_periodic(struct clock_event_device *dev);
 extern void tick_check_new_device(struct clock_event_device *dev);
-extern void tick_shutdown(unsigned int *cpup);
+extern void tick_shutdown(unsigned int cpu);
 extern void tick_suspend(void);
 extern void tick_resume(void);
 extern bool tick_check_replacement(struct clock_event_device *curdev,
@@ -52,7 +52,7 @@ extern ssize_t sysfs_get_uname(const cha
 extern int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu);
 extern void tick_install_broadcast_device(struct clock_event_device *dev);
 extern int tick_is_broadcast_device(struct clock_event_device *dev);
-extern void tick_shutdown_broadcast(unsigned int *cpup);
+extern void tick_shutdown_broadcast(unsigned int cpu);
 extern void tick_suspend_broadcast(void);
 extern void tick_resume_broadcast(void);
 extern bool tick_resume_check_broadcast(void);
@@ -66,7 +66,7 @@ static inline void tick_install_broadcas
 static inline int tick_is_broadcast_device(struct clock_event_device *dev) { return 0; }
 static inline int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu) { return 0; }
 static inline void tick_do_periodic_broadcast(struct clock_event_device *d) { }
-static inline void tick_shutdown_broadcast(unsigned int *cpup) { }
+static inline void tick_shutdown_broadcast(unsigned int cpu) { }
 static inline void tick_suspend_broadcast(void) { }
 static inline void tick_resume_broadcast(void) { }
 static inline bool tick_resume_check_broadcast(void) { return false; }
@@ -119,7 +119,7 @@ static inline int tick_check_oneshot_cha
 #if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
 extern void tick_broadcast_setup_oneshot(struct clock_event_device *bc);
 extern void tick_broadcast_switch_to_oneshot(void);
-extern void tick_shutdown_broadcast_oneshot(unsigned int *cpup);
+extern void tick_shutdown_broadcast_oneshot(unsigned int cpu);
 extern int tick_broadcast_oneshot_active(void);
 extern void tick_check_oneshot_broadcast_this_cpu(void);
 bool tick_broadcast_oneshot_available(void);
@@ -127,7 +127,7 @@ extern struct cpumask *tick_get_broadcas
 #else /* !(BROADCAST && ONESHOT): */
 static inline void tick_broadcast_setup_oneshot(struct clock_event_device *bc) { BUG(); }
 static inline void tick_broadcast_switch_to_oneshot(void) { }
-static inline void tick_shutdown_broadcast_oneshot(unsigned int *cpup) { }
+static inline void tick_shutdown_broadcast_oneshot(unsigned int cpu) { }
 static inline int tick_broadcast_oneshot_active(void) { return 0; }
 static inline void tick_check_oneshot_broadcast_this_cpu(void) { }
 static inline bool tick_broadcast_oneshot_available(void) { return tick_oneshot_possible(); }
#86 lore raw

[tip:timers/core] clockevents: Cleanup dead cpu explicitely

clockevents: Cleanup dead cpu explicitely
Commit-ID:  a49b116dcb1265f238f3169507424257b0519069
Gitweb:     http://git.kernel.org/tip/a49b116dcb1265f238f3169507424257b0519069
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Fri, 3 Apr 2015 02:38:05 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 3 Apr 2015 08:44:37 +0200

clockevents: Cleanup dead cpu explicitely

clockevents_notify() is a leftover from the early design of the clockevents facility. It's really not a notification mechanism, it's a multiplex call. We are way better off to have explicit calls instead of this monstrosity.

Split out the cleanup function for a dead cpu and invoke it directly from the cpu down code. Make it conditional on CPU_HOTPLUG as well.

Temporary change, will be refined in the future.

---
 include/linux/clockchips.h   |  6 ------
 include/linux/tick.h         |  2 ++
 kernel/cpu.c                 |  1 +
 kernel/time/clockevents.c    | 51 ++++++++++++++++++--------------------------
 kernel/time/hrtimer.c        |  3 ---
 kernel/time/tick-broadcast.c | 39 ++++++++++++++++-----------------
 kernel/time/tick-common.c    |  6 +++---
 kernel/time/tick-internal.h  | 10 ++++-----
 8 files changed, 52 insertions(+), 66 deletions(-)
include/linux/clockchips.h +0 -6
index f4bde22..96c280b 100644
@@ -8,12 +8,6 @@
 #ifndef _LINUX_CLOCKCHIPS_H
 #define _LINUX_CLOCKCHIPS_H
 
-/* Clock event notification values */
-enum clock_event_nofitiers {
-	CLOCK_EVT_NOTIFY_ADD,
-	CLOCK_EVT_NOTIFY_CPU_DEAD,
-};
-
 #ifdef CONFIG_GENERIC_CLOCKEVENTS
 
 # include <linux/clocksource.h>
include/linux/tick.h +2 -0
index 2c68fa3..f8492da5 100644
@@ -20,6 +20,7 @@ extern void tick_suspend_local(void);
 /* Should be core only, but XEN resume magic and ARM BL switcher require it */
 extern void tick_resume_local(void);
 extern void tick_handover_do_timer(void);
+extern void tick_cleanup_dead_cpu(int cpu);
 #else /* CONFIG_GENERIC_CLOCKEVENTS */
 static inline void tick_init(void) { }
 static inline void tick_freeze(void) { }
@@ -27,6 +28,7 @@ static inline void tick_unfreeze(void) { }
 static inline void tick_suspend_local(void) { }
 static inline void tick_resume_local(void) { }
 static inline void tick_handover_do_timer(void) { }
+static inline void tick_cleanup_dead_cpu(int cpu) { }
 #endif /* !CONFIG_GENERIC_CLOCKEVENTS */
 
 #ifdef CONFIG_TICK_ONESHOT
kernel/cpu.c +1 -0
index eba7eaa..82eea9c 100644
@@ -419,6 +419,7 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen)
 	__cpu_die(cpu);
 
 	/* CPU is completely dead: tell everyone.  Too late to complain. */
+	tick_cleanup_dead_cpu(cpu);
 	cpu_notify_nofail(CPU_DEAD | mod, hcpu);
 
 	check_for_tasks(cpu);
kernel/time/clockevents.c +21 -30

70 lines not on this page · raw message

kernel/time/hrtimer.c +0 -3
index 6a7a64e..76d4bd9 100644
@@ -1709,11 +1709,8 @@ static int hrtimer_cpu_notify(struct notifier_block *self,
 #ifdef CONFIG_HOTPLUG_CPU
 	case CPU_DEAD:
 	case CPU_DEAD_FROZEN:
-	{
-		clockevents_notify(CLOCK_EVT_NOTIFY_CPU_DEAD, &scpu);
 		migrate_hrtimers(scpu);
 		break;
-	}
 #endif
 
 	default:
kernel/time/tick-broadcast.c +20 -19
index 55e43f2..7e8ca4f 100644
@@ -410,14 +410,14 @@ void tick_set_periodic_handler(struct clock_event_device *dev, int broadcast)
 		dev->event_handler = tick_handle_periodic_broadcast;
 }
 
+#ifdef CONFIG_HOTPLUG_CPU
 /*
  * Remove a CPU from broadcasting
  */
-void tick_shutdown_broadcast(unsigned int *cpup)
+void tick_shutdown_broadcast(unsigned int cpu)
 {
 	struct clock_event_device *bc;
 	unsigned long flags;
-	unsigned int cpu = *cpup;
 
 	raw_spin_lock_irqsave(&tick_broadcast_lock, flags);
 
@@ -432,6 +432,7 @@ void tick_shutdown_broadcast(unsigned int *cpup)
 
 	raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags);
 }
+#endif
 
 void tick_suspend_broadcast(void)
 {
@@ -672,21 +673,6 @@ static void broadcast_shutdown_local(struct clock_event_device *bc,
 	clockevents_set_state(dev, CLOCK_EVT_STATE_SHUTDOWN);
 }
 
-void hotplug_cpu__broadcast_tick_pull(int deadcpu)
-{
-	struct clock_event_device *bc;
-	unsigned long flags;
-
-	raw_spin_lock_irqsave(&tick_broadcast_lock, flags);
-	bc = tick_broadcast_device.evtdev;
-
-	if (bc && broadcast_needs_cpu(bc, deadcpu)) {
-		/* This moves the broadcast assignment to this CPU: */
-		clockevents_program_event(bc, bc->next_event, 1);
-	}
-	raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags);
-}
-
 /**
  * tick_broadcast_oneshot_control - Enter/exit broadcast oneshot mode
  * @state:	The target state (enter/exit)
@@ -908,14 +894,28 @@ void tick_broadcast_switch_to_oneshot(void)
 	raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags);
 }
 
+#ifdef CONFIG_HOTPLUG_CPU
+void hotplug_cpu__broadcast_tick_pull(int deadcpu)
+{
+	struct clock_event_device *bc;
+	unsigned long flags;
+
+	raw_spin_lock_irqsave(&tick_broadcast_lock, flags);
+	bc = tick_broadcast_device.evtdev;
+
+	if (bc && broadcast_needs_cpu(bc, deadcpu)) {
+		/* This moves the broadcast assignment to this CPU: */
+		clockevents_program_event(bc, bc->next_event, 1);
+	}
+	raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags);
+}
 
 /*
  * Remove a dead CPU from broadcasting
  */
-void tick_shutdown_broadcast_oneshot(unsigned int *cpup)
+void tick_shutdown_broadcast_oneshot(unsigned int cpu)
 {
 	unsigned long flags;
-	unsigned int cpu = *cpup;
 
 	raw_spin_lock_irqsave(&tick_broadcast_lock, flags);
 
@@ -929,6 +929,7 @@ void tick_shutdown_broadcast_oneshot(unsigned int *cpup)
 
 	raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags);
 }
+#endif
 
 /*
  * Check, whether the broadcast device is in one shot mode
kernel/time/tick-common.c +3 -3
index 055c868..fac3e98 100644
@@ -348,7 +348,6 @@ void tick_handover_do_timer(void)
 			TICK_DO_TIMER_NONE;
 	}
 }
-#endif
 
 /*
  * Shutdown an event device on a given cpu:
@@ -357,9 +356,9 @@ void tick_handover_do_timer(void)
  * access the hardware device itself.
  * We just set the mode and remove it from the lists.
  */
-void tick_shutdown(unsigned int *cpup)
+void tick_shutdown(unsigned int cpu)
 {
-	struct tick_device *td = &per_cpu(tick_cpu_device, *cpup);
+	struct tick_device *td = &per_cpu(tick_cpu_device, cpu);
 	struct clock_event_device *dev = td->evtdev;
 
 	td->mode = TICKDEV_MODE_PERIODIC;
@@ -375,6 +374,7 @@ void tick_shutdown(unsigned int *cpup)
 		td->evtdev = NULL;
 	}
 }
+#endif
 
 /**
  * tick_suspend_local - Suspend the local tick device
kernel/time/tick-internal.h +5 -5
index aabcb5d..b64fdd8 100644
@@ -20,7 +20,7 @@ extern int tick_do_timer_cpu __read_mostly;
 extern void tick_setup_periodic(struct clock_event_device *dev, int broadcast);
 extern void tick_handle_periodic(struct clock_event_device *dev);
 extern void tick_check_new_device(struct clock_event_device *dev);
-extern void tick_shutdown(unsigned int *cpup);
+extern void tick_shutdown(unsigned int cpu);
 extern void tick_suspend(void);
 extern void tick_resume(void);
 extern bool tick_check_replacement(struct clock_event_device *curdev,
@@ -52,7 +52,7 @@ extern ssize_t sysfs_get_uname(const char *buf, char *dst, size_t cnt);
 extern int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu);
 extern void tick_install_broadcast_device(struct clock_event_device *dev);
 extern int tick_is_broadcast_device(struct clock_event_device *dev);
-extern void tick_shutdown_broadcast(unsigned int *cpup);
+extern void tick_shutdown_broadcast(unsigned int cpu);
 extern void tick_suspend_broadcast(void);
 extern void tick_resume_broadcast(void);
 extern bool tick_resume_check_broadcast(void);
@@ -66,7 +66,7 @@ static inline void tick_install_broadcast_device(struct clock_event_device *dev)
 static inline int tick_is_broadcast_device(struct clock_event_device *dev) { return 0; }
 static inline int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu) { return 0; }
 static inline void tick_do_periodic_broadcast(struct clock_event_device *d) { }
-static inline void tick_shutdown_broadcast(unsigned int *cpup) { }
+static inline void tick_shutdown_broadcast(unsigned int cpu) { }
 static inline void tick_suspend_broadcast(void) { }
 static inline void tick_resume_broadcast(void) { }
 static inline bool tick_resume_check_broadcast(void) { return false; }
@@ -117,7 +117,7 @@ static inline int tick_check_oneshot_change(int allow_nohz) { return 0; }
 #if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
 extern void tick_broadcast_setup_oneshot(struct clock_event_device *bc);
 extern void tick_broadcast_switch_to_oneshot(void);
-extern void tick_shutdown_broadcast_oneshot(unsigned int *cpup);
+extern void tick_shutdown_broadcast_oneshot(unsigned int cpu);
 extern int tick_broadcast_oneshot_active(void);
 extern void tick_check_oneshot_broadcast_this_cpu(void);
 bool tick_broadcast_oneshot_available(void);
@@ -125,7 +125,7 @@ extern struct cpumask *tick_get_broadcast_oneshot_mask(void);
 #else /* !(BROADCAST && ONESHOT): */
 static inline void tick_broadcast_setup_oneshot(struct clock_event_device *bc) { BUG(); }
 static inline void tick_broadcast_switch_to_oneshot(void) { }
-static inline void tick_shutdown_broadcast_oneshot(unsigned int *cpup) { }
+static inline void tick_shutdown_broadcast_oneshot(unsigned int cpu) { }
 static inline int tick_broadcast_oneshot_active(void) { return 0; }
 static inline void tick_check_oneshot_broadcast_this_cpu(void) { }
 static inline bool tick_broadcast_oneshot_available(void) { return tick_oneshot_possible(); }
#87 lore raw

PATCH v2 21/21 timekeeping: Get rid of stale comment

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Arch specific management of xtime/jiffies/wall_to_monotonic is gone for quite a while. Zap the stale comment.

---
 kernel/time/timekeeping.c |    4 ----
 1 file changed, 4 deletions(-)
kernel/time/timekeeping.c +0 -4
Index: linux-pm/kernel/time/timekeeping.c
===================================================================
@@ -1307,10 +1307,6 @@ void timekeeping_inject_sleeptime64(stru
 
 /**
  * timekeeping_resume - Resumes the generic timekeeping subsystem.
- *
- * This is for the generic clocksource timekeeping.
- * xtime/wall_to_monotonic/jiffies/etc are
- * still managed by arch specific suspend/resume code.
  */
 void timekeeping_resume(void)
 {
#88 lore raw

[tip:timers/core] timekeeping: Get rid of stale comment

timekeeping: Get rid of stale comment
Commit-ID:  347c6f6dda1098318088feb8e60188f0161e743d
Gitweb:     http://git.kernel.org/tip/347c6f6dda1098318088feb8e60188f0161e743d
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Fri, 3 Apr 2015 02:39:05 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 3 Apr 2015 08:44:37 +0200

timekeeping: Get rid of stale comment

Arch specific management of xtime/jiffies/wall_to_monotonic is gone for quite a while. Zap the stale comment.

---
 kernel/time/timekeeping.c | 4 ----
 1 file changed, 4 deletions(-)
kernel/time/timekeeping.c +0 -4
index 79b9bc6..946acb7 100644
@@ -1354,10 +1354,6 @@ void timekeeping_inject_sleeptime64(struct timespec64 *delta)
 
 /**
  * timekeeping_resume - Resumes the generic timekeeping subsystem.
- *
- * This is for the generic clocksource timekeeping.
- * xtime/wall_to_monotonic/jiffies/etc are
- * still managed by arch specific suspend/resume code.
  */
 void timekeeping_resume(void)
 {
maintainer
#89 lore raw
In reply to Rafael J. Wysocki
Quoted 28 lines · Rafael J. Wysocki
Quoted 27 lines · Rafael J. Wysocki
Quoted 14 lines · Ingo Molnar
Quoted 11 lines · Rafael J. Wysocki

Hi,

This is the next batch of patches from Thomas that remove clockevents_notify().

I've reordered the set (to put more stratightforward things to the front) and rebased it on top of the timers material currently queued up for 4.1.

This series in based on the bleeding-edge branch of the linux-pm tree (which for all practical purposes is my linux-next branch with timers/core from tip merged into it).

Quoted 7 lines
Quoted 1 line

Please let me know how to proceed with these.

Would you mind to resend these merged on top of the very latest tip:timers/core (or tip:master) tree?

These changes conflict (mildly) with the other series from Thomas which needed some fixes/enhancements.

I'll do that later today.

This series also depends on:

Quoted 7 lines
Quoted 4 lines

http://git.kernel.org/cgit/linux/kernel/git/rafael/linux-pm.git/commit/?h=acpi-pad&id=6e9f8b5f1f319cbdb4cfe3696fc74fbe39318960

which is in my acpi-pad branch at the moment, but I'll add it to the front of the series in case you prefer to apply it directly.

The patches follow as per the above. [2-21/21] rebased on top of the current timers/core.

Thanks! I picked them up into tip:timers/core and will push them out after some testing.

Thanks,

Ingo