Skip to contentSkip to conversation

Some kernel/time cleanups

PATCH In review Peter Zijlstra 13 participants 106 messages Feb 16, 2015 – Apr 3, 2015

Subsystems (17)
lore
Share & tools
lore

Peter Zijlstra

author maintainer
#0 lore raw

cover Some kernel/time cleanups

Hi,

While working with Rafael on the suspend to idle machinery Thomas made these cleanups; since one might as well clean code up while you've done the work of thinking through it again.

As it stands there's very little overlap between Rafael's series and this one aside from a few trivial fixups. So we'll merge them seperately.

---
 arch/arm/common/bL_switcher.c          |  16 +--
 arch/arm/kernel/smp.c                  |   2 +-
 arch/arm/mach-omap2/cpuidle44xx.c      |  10 +-
 arch/arm/mach-tegra/cpuidle-tegra114.c |   6 +-
 arch/arm/mach-tegra/cpuidle-tegra20.c  |  10 +-
 arch/arm/mach-tegra/cpuidle-tegra30.c  |  10 +-
 arch/arm64/Kconfig                     |   1 +
 arch/arm64/kernel/smp.c                |   1 +
 arch/arm64/kernel/time.c               |   2 +-
 arch/mips/kernel/smp.c                 |   1 +
 arch/powerpc/Kconfig                   |   1 +
 arch/powerpc/kernel/smp.c              |   1 +
 arch/powerpc/kernel/time.c             |   2 +-
 arch/x86/kernel/process.c              |  13 +--
 arch/x86/xen/suspend.c                 |  11 +-
 drivers/acpi/acpi_pad.c                |  29 +----
 drivers/acpi/processor_idle.c          |  20 ++--
 drivers/cpuidle/driver.c               |  23 ++--
 drivers/idle/intel_idle.c              |  17 ++-
 include/linux/clockchips.h             |  65 +----------
 include/linux/clocksource.h            |   2 -
 include/linux/tick.h                   | 200 ++++++++++++++-------------------
 kernel/cpu.c                           |   4 +
 kernel/sched/idle.c                    |   5 +-
 kernel/time/Kconfig                    |  10 +-
 kernel/time/Makefile                   |  12 +-
 kernel/time/clockevents.c              |  95 +++++-----------
 kernel/time/clocksource.c              |   2 +
 kernel/time/hrtimer.c                  |   9 +-
 kernel/time/jiffies.c                  |   2 +-
 kernel/time/ntp.c                      |   1 -
 kernel/time/tick-broadcast.c           | 194 ++++++++++++++++++--------------
 kernel/time/tick-common.c              |  89 ++++++++++-----
 kernel/time/tick-internal.h            | 189 +++++++++++++------------------
 kernel/time/tick-sched.c               |   7 +-
 kernel/time/timekeeping.c              |  12 +-
 kernel/time/timekeeping.h              |  10 ++
 kernel/time/timer_list.c               |   2 +-
 38 files changed, 477 insertions(+), 609 deletions(-)
author maintainer
#1 lore raw

PATCH 1/35 ACPI/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.

Cc "Rafael J. Wysocki" <[email protected]>
Cc Len Brown <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 drivers/acpi/acpi_pad.c |   26 +++++---------------------
 1 file changed, 5 insertions(+), 21 deletions(-)
drivers/acpi/acpi_pad.c +5 -21
Index: linux/drivers/acpi/acpi_pad.c
===================================================================
@@ -41,8 +41,6 @@ static unsigned long power_saving_mwait_
 
 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 *dat
 				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)) {
Acked-by on v1 1/35
#2 lore raw

Re: [PATCH 01/35] ACPI/acpi_pad: Remove the local apic nonsense

Quoted 38 lines · Peter Zijlstra

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.

Quoted 7 lines

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.

Cc "Rafael J. Wysocki" <[email protected]>
Quoted 74 lines
Cc Len Brown <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 drivers/acpi/acpi_pad.c |   26 +++++---------------------
 1 file changed, 5 insertions(+), 21 deletions(-)

Index: linux/drivers/acpi/acpi_pad.c
===================================================================

drivers/acpi/acpi_pad.c +5 -22
@@ -41,8 +41,6 @@ static unsigned long power_saving_mwait_
 
 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 *dat
 				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)) {
 
 
--

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

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

Re: [PATCH 01/35] ACPI/acpi_pad: Remove the local apic nonsense

Quoted 44 lines · Rafael J. Wysocki
Quoted 43 lines · Peter Zijlstra

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.

Quoted 4 lines
Quoted 2 lines
Cc "Rafael J. Wysocki" <[email protected]>

Or I can apply it right away if you want me to.

Rafael

author maintainer
#4 lore raw

PATCH 2/35 clockevents: Remove CONFIG_GENERIC_CLOCKEVENTS_BUILD

In reply to Peter Zijlstra

From: Thomas Gleixner <[email protected]>

This option was for simpler migration to the clock events code. Most architectures have been converted and the option has been disfunctional as a standalone option for quite some time. Remove it.

---
 include/linux/clockchips.h  |    9 +++------
 kernel/time/Kconfig         |    6 ------
 kernel/time/Makefile        |    6 ++----
 kernel/time/clockevents.c   |    3 ---
 kernel/time/tick-internal.h |    4 ++--
 5 files changed, 7 insertions(+), 21 deletions(-)
include/linux/clockchips.h +3 -6
Index: linux/include/linux/clockchips.h
===================================================================
@@ -22,7 +22,7 @@ enum clock_event_nofitiers {
 	CLOCK_EVT_NOTIFY_CPU_DEAD,
 };
 
-#ifdef CONFIG_GENERIC_CLOCKEVENTS_BUILD
+#ifdef CONFIG_GENERIC_CLOCKEVENTS
 
 #include <linux/clocksource.h>
 #include <linux/cpumask.h>
@@ -194,13 +194,9 @@ static inline int tick_check_broadcast_e
 static inline void tick_setup_hrtimer_broadcast(void) {};
 #endif
 
-#ifdef CONFIG_GENERIC_CLOCKEVENTS
 extern int clockevents_notify(unsigned long reason, void *arg);
-#else
-static inline int clockevents_notify(unsigned long reason, void *arg) { return 0; }
-#endif
 
-#else /* CONFIG_GENERIC_CLOCKEVENTS_BUILD */
+#else /* CONFIG_GENERIC_CLOCKEVENTS */
 
 static inline void clockevents_suspend(void) {}
 static inline void clockevents_resume(void) {}
@@ -208,6 +204,7 @@ static inline void clockevents_resume(vo
 static inline int clockevents_notify(unsigned long reason, void *arg) { return 0; }
 static inline int tick_check_broadcast_expired(void) { return 0; }
 static inline void tick_setup_hrtimer_broadcast(void) {};
+static inline int clockevents_notify(unsigned long reason, void *arg) { return 0; }
 
 #endif
 
kernel/time/Kconfig +0 -6
Index: linux/kernel/time/Kconfig
===================================================================
@@ -33,12 +33,6 @@ config ARCH_USES_GETTIMEOFFSET
 config GENERIC_CLOCKEVENTS
 	bool
 
-# Migration helper. Builds, but does not invoke
-config GENERIC_CLOCKEVENTS_BUILD
-	bool
-	default y
-	depends on GENERIC_CLOCKEVENTS
-
 # Architecture can handle broadcast in a driver-agnostic way
 config ARCH_HAS_TICK_BROADCAST
 	bool
kernel/time/Makefile +2 -4
Index: linux/kernel/time/Makefile
===================================================================
@@ -2,15 +2,13 @@ obj-y += time.o timer.o hrtimer.o itimer
 obj-y += timekeeping.o ntp.o clocksource.o jiffies.o timer_list.o
 obj-y += timeconv.o posix-clock.o alarmtimer.o
 
-obj-$(CONFIG_GENERIC_CLOCKEVENTS_BUILD)		+= clockevents.o
-obj-$(CONFIG_GENERIC_CLOCKEVENTS)		+= tick-common.o
+obj-$(CONFIG_GENERIC_CLOCKEVENTS)		+= clockevents.o tick-common.o
 ifeq ($(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST),y)
  obj-y						+= tick-broadcast.o
  obj-$(CONFIG_TICK_ONESHOT)			+= tick-broadcast-hrtimer.o
 endif
 obj-$(CONFIG_GENERIC_SCHED_CLOCK)		+= sched_clock.o
-obj-$(CONFIG_TICK_ONESHOT)			+= tick-oneshot.o
-obj-$(CONFIG_TICK_ONESHOT)			+= tick-sched.o
+obj-$(CONFIG_TICK_ONESHOT)			+= tick-oneshot.o tick-sched.o
 obj-$(CONFIG_TIMER_STATS)			+= timer_stats.o
 obj-$(CONFIG_DEBUG_FS)				+= timekeeping_debug.o
 obj-$(CONFIG_TEST_UDELAY)			+= test_udelay.o
kernel/time/clockevents.c +0 -3
Index: linux/kernel/time/clockevents.c
===================================================================
@@ -541,7 +541,6 @@ void clockevents_resume(void)
 			dev->resume(dev);
 }
 
-#ifdef CONFIG_GENERIC_CLOCKEVENTS
 /**
  * clockevents_notify - notification about relevant events
  * Returns 0 on success, any other value on error
@@ -727,5 +726,3 @@ static int __init clockevents_init_sysfs
 }
 device_initcall(clockevents_init_sysfs);
 #endif /* SYSFS */
-
-#endif /* GENERIC_CLOCK_EVENTS */
kernel/time/tick-internal.h +2 -2
Index: linux/kernel/time/tick-internal.h
===================================================================
@@ -10,7 +10,7 @@ extern seqlock_t jiffies_lock;
 
 #define CS_NAME_LEN	32
 
-#ifdef CONFIG_GENERIC_CLOCKEVENTS_BUILD
+#ifdef CONFIG_GENERIC_CLOCKEVENTS
 
 #define TICK_DO_TIMER_NONE	-1
 #define TICK_DO_TIMER_BOOT	-2
@@ -166,7 +166,7 @@ static inline int tick_device_is_functio
 
 int __clockevents_update_freq(struct clock_event_device *dev, u32 freq);
 
-#endif
+#endif /* GENERIC_CLOCKEVENTS */
 
 extern void do_timer(unsigned long ticks);
 extern void update_wall_time(void);
author maintainer
#5 lore raw

PATCH 3/35 tick: Cleanup internal header files

In reply to Peter Zijlstra

From: Thomas Gleixner <[email protected]>

Move clocksource related stuff to timekeeping.h and remove the pointless include from ntp.c

---
 kernel/time/clocksource.c   |    2 +-
 kernel/time/jiffies.c       |    2 +-
 kernel/time/ntp.c           |    1 -
 kernel/time/tick-internal.h |    6 ------
 kernel/time/timekeeping.h   |    7 +++++++
 5 files changed, 9 insertions(+), 9 deletions(-)
kernel/time/clocksource.c +1 -1
Index: linux/kernel/time/clocksource.c
===================================================================
@@ -31,7 +31,7 @@
 #include <linux/tick.h>
 #include <linux/kthread.h>
 
-#include "tick-internal.h"
+#include "timekeeping.h"
 #include "timekeeping_internal.h"
 
 void timecounter_init(struct timecounter *tc,
kernel/time/jiffies.c +1 -1
Index: linux/kernel/time/jiffies.c
===================================================================
@@ -25,7 +25,7 @@
 #include <linux/module.h>
 #include <linux/init.h>
 
-#include "tick-internal.h"
+#include "timekeeping.h"
 
 /* The Jiffies based clocksource is the lowest common
  * denominator clock source which should function on
kernel/time/ntp.c +0 -1
Index: linux/kernel/time/ntp.c
===================================================================
@@ -17,7 +17,6 @@
 #include <linux/module.h>
 #include <linux/rtc.h>
 
-#include "tick-internal.h"
 #include "ntp_internal.h"
 
 /*
kernel/time/tick-internal.h +0 -6
Index: linux/kernel/time/tick-internal.h
===================================================================
@@ -6,10 +6,6 @@
 
 #include "timekeeping.h"
 
-extern seqlock_t jiffies_lock;
-
-#define CS_NAME_LEN	32
-
 #ifdef CONFIG_GENERIC_CLOCKEVENTS
 
 #define TICK_DO_TIMER_NONE	-1
@@ -168,5 +164,3 @@ int __clockevents_update_freq(struct clo
 
 #endif /* GENERIC_CLOCKEVENTS */
 
-extern void do_timer(unsigned long ticks);
-extern void update_wall_time(void);
kernel/time/timekeeping.h +7 -0
Index: linux/kernel/time/timekeeping.h
===================================================================
@@ -17,4 +17,11 @@ extern s32 timekeeping_get_tai_offset(vo
 extern void timekeeping_set_tai_offset(s32 tai_offset);
 extern void timekeeping_clocktai(struct timespec *ts);
 
+extern void do_timer(unsigned long ticks);
+extern void update_wall_time(void);
+
+extern seqlock_t jiffies_lock;
+
+#define CS_NAME_LEN	32
+
 #endif
author maintainer
#6 lore raw

PATCH 4/35 tick: Cleanup internal header file

In reply to Peter Zijlstra

From: Thomas Gleixner <[email protected]>

tick-internal.h is pretty confusing as a lot of the stub inlines are there several times.

Distangle the maze and make clear functional sections.

---
 kernel/time/tick-internal.h |  145 ++++++++++++++------------------------------
 1 file changed, 49 insertions(+), 96 deletions(-)
kernel/time/tick-internal.h +49 -96
Index: linux/kernel/time/tick-internal.h
===================================================================
@@ -27,13 +27,18 @@ extern bool tick_check_replacement(struc
 				   struct clock_event_device *newdev);
 extern void tick_install_replacement(struct clock_event_device *dev);
 
-extern void clockevents_shutdown(struct clock_event_device *dev);
+/* Check, if the device is functional or a dummy for broadcast */
+static inline int tick_device_is_functional(struct clock_event_device *dev)
+{
+	return !(dev->features & CLOCK_EVT_FEAT_DUMMY);
+}
 
+extern void clockevents_shutdown(struct clock_event_device *dev);
+extern int __clockevents_update_freq(struct clock_event_device *dev, u32 freq);
 extern ssize_t sysfs_get_uname(const char *buf, char *dst, size_t cnt);
+#endif /* GENERIC_CLOCKEVENTS */
 
-/*
- * NO_HZ / high resolution timer shared code
- */
+/* Oneshot related functions */
 #ifdef CONFIG_TICK_ONESHOT
 extern void tick_setup_oneshot(struct clock_event_device *newdev,
 			       void (*handler)(struct clock_event_device *),
@@ -42,69 +47,19 @@ extern int tick_program_event(ktime_t ex
 extern void tick_oneshot_notify(void);
 extern int tick_switch_to_oneshot(void (*handler)(struct clock_event_device *));
 extern void tick_resume_oneshot(void);
-# ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
-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_resume_broadcast_oneshot(struct clock_event_device *bc);
-extern int tick_broadcast_oneshot_active(void);
-extern void tick_check_oneshot_broadcast_this_cpu(void);
-bool tick_broadcast_oneshot_available(void);
-# else /* BROADCAST */
-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; }
-static inline void tick_check_oneshot_broadcast_this_cpu(void) { }
-static inline bool tick_broadcast_oneshot_available(void) { return true; }
-# endif /* !BROADCAST */
-
+static inline bool tick_oneshot_possible(void) { return true; }
 #else /* !ONESHOT */
 static inline
 void tick_setup_oneshot(struct clock_event_device *newdev,
 			void (*handler)(struct clock_event_device *),
-			ktime_t nextevt)
-{
-	BUG();
-}
-static inline void tick_resume_oneshot(void)
-{
-	BUG();
-}
-static inline int tick_program_event(ktime_t expires, int force)
-{
-	return 0;
-}
+			ktime_t nextevt) { BUG(); }
+static inline void tick_resume_oneshot(void) { BUG(); }
+static inline int tick_program_event(ktime_t expires, int force) { return 0; }
 static inline void tick_oneshot_notify(void) { }
-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_shutdown_broadcast_oneshot(unsigned int *cpup) { }
-static inline int tick_resume_broadcast_oneshot(struct clock_event_device *bc)
-{
-	return 0;
-}
-static inline int tick_broadcast_oneshot_active(void) { return 0; }
-static inline bool tick_broadcast_oneshot_available(void) { return false; }
+static inline bool tick_oneshot_possible(void) { return false; }
 #endif /* !TICK_ONESHOT */
 
-/* NO_HZ_FULL internal */
-#ifdef CONFIG_NO_HZ_FULL
-extern void tick_nohz_init(void);
-# else
-static inline void tick_nohz_init(void) { }
-#endif
-
-/*
- * Broadcasting support
- */
+/* Broadcasting support */
 #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
 extern int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu);
 extern void tick_install_broadcast_device(struct clock_event_device *dev);
@@ -114,53 +69,51 @@ extern void tick_shutdown_broadcast(unsi
 extern void tick_suspend_broadcast(void);
 extern int tick_resume_broadcast(void);
 extern void tick_broadcast_init(void);
-extern void
-tick_set_periodic_handler(struct clock_event_device *dev, int broadcast);
-int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq);
-
+extern void tick_set_periodic_handler(struct clock_event_device *dev, int broadcast);
+extern int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq);
 #else /* !BROADCAST */
-
-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_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 int tick_resume_broadcast(void) { return 0; }
 static inline void tick_broadcast_init(void) { }
-static inline int tick_broadcast_update_freq(struct clock_event_device *dev,
-					     u32 freq) { return -ENODEV; }
+static inline int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq) { return -ENODEV; }
 
-/*
- * Set the periodic handler in non broadcast mode
- */
-static inline void tick_set_periodic_handler(struct clock_event_device *dev,
-					     int broadcast)
+/* Set the periodic handler in non broadcast mode */
+static inline void tick_set_periodic_handler(struct clock_event_device *dev, int broadcast)
 {
 	dev->event_handler = tick_handle_periodic;
 }
 #endif /* !BROADCAST */
 
-/*
- * Check, if the device is functional or a dummy for broadcast
- */
-static inline int tick_device_is_functional(struct clock_event_device *dev)
-{
-	return !(dev->features & CLOCK_EVT_FEAT_DUMMY);
-}
-
-int __clockevents_update_freq(struct clock_event_device *dev, u32 freq);
-
-#endif /* GENERIC_CLOCKEVENTS */
+/* 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_resume_broadcast_oneshot(struct clock_event_device *bc);
+extern int tick_broadcast_oneshot_active(void);
+extern void tick_check_oneshot_broadcast_this_cpu(void);
+bool tick_broadcast_oneshot_available(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_resume_broadcast_oneshot(struct clock_event_device *bc) { return 0; }
+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(); }
+#endif /* !BROADCAST && ONESHOT */
 
+/* NO_HZ_FULL internal */
+#ifdef CONFIG_NO_HZ_FULL
+extern void tick_nohz_init(void);
+# else
+static inline void tick_nohz_init(void) { }
+#endif
author maintainer
#7 lore raw

PATCH 5/35 tick: Move core only declarations and functions to core

In reply to Peter Zijlstra

From: Thomas Gleixner <[email protected]>

No point to expose everything to the world. People just believe such functions can be abused for whatever purposes. Sigh.

---
 include/linux/clockchips.h  |   15 ++---
 include/linux/tick.h        |  130 +++++---------------------------------------
 kernel/time/clocksource.c   |    2 
 kernel/time/hrtimer.c       |    2 
 kernel/time/tick-internal.h |   15 +++++
 kernel/time/tick-sched.c    |    7 ++
 kernel/time/tick-sched.h    |   64 +++++++++++++++++++++
 kernel/time/timer_list.c    |    2 
 8 files changed, 110 insertions(+), 127 deletions(-)
include/linux/clockchips.h +6 -9
Index: linux/include/linux/clockchips.h
===================================================================
@@ -158,15 +158,6 @@ extern void clockevents_config_and_regis
 
 extern int clockevents_update_freq(struct clock_event_device *ce, u32 freq);
 
-extern void clockevents_exchange_device(struct clock_event_device *old,
-					struct clock_event_device *new);
-extern void clockevents_set_mode(struct clock_event_device *dev,
-				 enum clock_event_mode mode);
-extern int clockevents_program_event(struct clock_event_device *dev,
-				     ktime_t expires, bool force);
-
-extern void clockevents_handle_noop(struct clock_event_device *dev);
-
 static inline void
 clockevents_calc_mult_shift(struct clock_event_device *ce, u32 freq, u32 minsec)
 {
@@ -174,6 +165,12 @@ clockevents_calc_mult_shift(struct clock
 				      freq, minsec);
 }
 
+/* Should be core only, but is abused by arm bl_switcher */
+extern void clockevents_set_mode(struct clock_event_device *dev,
+				 enum clock_event_mode mode);
+extern int clockevents_program_event(struct clock_event_device *dev,
+				     ktime_t expires, bool force);
+
 extern void clockevents_suspend(void);
 extern void clockevents_resume(void);
 
include/linux/tick.h +16 -114

176 lines not on this page · raw message

kernel/time/clocksource.c +1 -1
Index: linux/kernel/time/clocksource.c
===================================================================
@@ -31,7 +31,7 @@
 #include <linux/tick.h>
 #include <linux/kthread.h>
 
-#include "timekeeping.h"
+#include "tick-internal.h"
 #include "timekeeping_internal.h"
 
 void timecounter_init(struct timecounter *tc,
kernel/time/hrtimer.c +1 -1
Index: linux/kernel/time/hrtimer.c
===================================================================
@@ -54,7 +54,7 @@
 
 #include <trace/events/timer.h>
 
-#include "timekeeping.h"
+#include "tick-internal.h"
 
 /*
  * The timer bases:
kernel/time/tick-internal.h +15 -0
Index: linux/kernel/time/tick-internal.h
===================================================================
@@ -5,6 +5,7 @@
 #include <linux/tick.h>
 
 #include "timekeeping.h"
+#include "tick-sched.h"
 
 #ifdef CONFIG_GENERIC_CLOCKEVENTS
 
@@ -26,6 +27,7 @@ extern void tick_resume(void);
 extern bool tick_check_replacement(struct clock_event_device *curdev,
 				   struct clock_event_device *newdev);
 extern void tick_install_replacement(struct clock_event_device *dev);
+extern int tick_is_oneshot_available(void);
 
 /* Check, if the device is functional or a dummy for broadcast */
 static inline int tick_device_is_functional(struct clock_event_device *dev)
@@ -34,6 +36,9 @@ static inline int tick_device_is_functio
 }
 
 extern void clockevents_shutdown(struct clock_event_device *dev);
+extern void clockevents_exchange_device(struct clock_event_device *old,
+					struct clock_event_device *new);
+extern void clockevents_handle_noop(struct clock_event_device *dev);
 extern int __clockevents_update_freq(struct clock_event_device *dev, u32 freq);
 extern ssize_t sysfs_get_uname(const char *buf, char *dst, size_t cnt);
 #endif /* GENERIC_CLOCKEVENTS */
@@ -48,6 +53,10 @@ extern void tick_oneshot_notify(void);
 extern int tick_switch_to_oneshot(void (*handler)(struct clock_event_device *));
 extern void tick_resume_oneshot(void);
 static inline bool tick_oneshot_possible(void) { return true; }
+extern int tick_oneshot_mode_active(void);
+extern void tick_clock_notify(void);
+extern int tick_check_oneshot_change(int allow_nohz);
+extern int tick_init_highres(void);
 #else /* !ONESHOT */
 static inline
 void tick_setup_oneshot(struct clock_event_device *newdev,
@@ -57,6 +66,9 @@ static inline void tick_resume_oneshot(v
 static inline int tick_program_event(ktime_t expires, int force) { return 0; }
 static inline void tick_oneshot_notify(void) { }
 static inline bool tick_oneshot_possible(void) { return false; }
+static inline int tick_oneshot_mode_active(void) { return 0; }
+static inline void tick_clock_notify(void) { }
+static inline int tick_check_oneshot_change(int allow_nohz) { return 0; }
 #endif /* !TICK_ONESHOT */
 
 /* Broadcasting support */
@@ -71,6 +83,8 @@ extern int tick_resume_broadcast(void);
 extern void tick_broadcast_init(void);
 extern void tick_set_periodic_handler(struct clock_event_device *dev, int broadcast);
 extern int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq);
+extern struct tick_device *tick_get_broadcast_device(void);
+extern struct cpumask *tick_get_broadcast_mask(void);
 #else /* !BROADCAST */
 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; }
@@ -100,6 +114,7 @@ extern int tick_resume_broadcast_oneshot
 extern int tick_broadcast_oneshot_active(void);
 extern void tick_check_oneshot_broadcast_this_cpu(void);
 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; }
kernel/time/tick-sched.c +6 -1
Index: linux/kernel/time/tick-sched.c
===================================================================
@@ -34,7 +34,7 @@
 /*
  * Per cpu nohz control structure
  */
-DEFINE_PER_CPU(struct tick_sched, tick_cpu_sched);
+static DEFINE_PER_CPU(struct tick_sched, tick_cpu_sched);
 
 /*
  * The time, when the last jiffy update happened. Protected by jiffies_lock.
@@ -423,6 +423,11 @@ static int __init setup_tick_nohz(char *
 
 __setup("nohz=", setup_tick_nohz);
 
+int tick_nohz_tick_stopped(void)
+{
+	return __this_cpu_read(tick_cpu_sched.tick_stopped);
+}
+
 /**
  * tick_nohz_update_jiffies - update jiffies when idle was interrupted
  *
kernel/time/tick-sched.h new file +64 -0

64 lines not on this page · raw message

kernel/time/timer_list.c +1 -1
Index: linux/kernel/time/timer_list.c
===================================================================
@@ -16,10 +16,10 @@
 #include <linux/sched.h>
 #include <linux/seq_file.h>
 #include <linux/kallsyms.h>
-#include <linux/tick.h>
 
 #include <asm/uaccess.h>
 
+#include "tick-internal.h"
 
 struct timer_list_iter {
 	int cpu;
author maintainer
#8 lore raw

PATCH 6/35 clockevents: Remove extra local_irq_save in clockevents_exchange_device()

In reply to Peter Zijlstra

From: Thomas Gleixner <[email protected]>

Called with clockevents_lock held and interrupts disabled already.

---
 kernel/time/clockevents.c |    7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
kernel/time/clockevents.c +2 -5
Index: linux/kernel/time/clockevents.c
===================================================================
@@ -491,14 +491,12 @@ void clockevents_handle_noop(struct cloc
  * @old:	device to release (can be NULL)
  * @new:	device to request (can be NULL)
  *
- * Called from the notifier chain. clockevents_lock is held already
+ * Called from various tick functions with clockevents_lock held and
+ * interrupts disabled.
  */
 void clockevents_exchange_device(struct clock_event_device *old,
 				 struct clock_event_device *new)
 {
-	unsigned long flags;
-
-	local_irq_save(flags);
 	/*
 	 * Caller releases a clock event device. We queue it into the
 	 * released list and do a notify add later.
@@ -514,7 +512,6 @@ void clockevents_exchange_device(struct
 		BUG_ON(new->mode != CLOCK_EVT_MODE_UNUSED);
 		clockevents_shutdown(new);
 	}
-	local_irq_restore(flags);
 }
 
 /**
author maintainer
#9 lore raw

PATCH 7/35 clockevents: Make suspend/resume calls explicit

In reply to Peter Zijlstra

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 suspend/resume() calls and invoke them directly from the call sites.

No locking required at this point because these calls happen with interrupts disabled and a single cpu online.

---
 arch/x86/xen/suspend.c      |   11 ++++-------
 include/linux/clockchips.h  |    2 --
 include/linux/tick.h        |    3 +++
 kernel/time/clockevents.c   |    9 ---------
 kernel/time/tick-common.c   |   23 +++++++++++++++++++++--
 kernel/time/tick-internal.h |    3 ++-
 kernel/time/timekeeping.c   |    6 ++----
 7 files changed, 32 insertions(+), 25 deletions(-)
arch/x86/xen/suspend.c +4 -7
Index: linux/arch/x86/xen/suspend.c
===================================================================
@@ -1,5 +1,5 @@
 #include <linux/types.h>
-#include <linux/clockchips.h>
+#include <linux/tick.h>
 
 #include <xen/interface/xen.h>
 #include <xen/grant_table.h>
@@ -81,17 +81,14 @@ void xen_arch_post_suspend(int cancelled
 
 static void xen_vcpu_notify_restore(void *data)
 {
-	unsigned long reason = (unsigned long)data;
-
 	/* Boot processor notified via generic timekeeping_resume() */
-	if ( smp_processor_id() == 0)
+	if (smp_processor_id() == 0)
 		return;
 
-	clockevents_notify(reason, NULL);
+	tick_resume();
 }
 
 void xen_arch_resume(void)
 {
-	on_each_cpu(xen_vcpu_notify_restore,
-		    (void *)CLOCK_EVT_NOTIFY_RESUME, 1);
+	on_each_cpu(xen_vcpu_notify_restore, NULL, 1);
 }
include/linux/clockchips.h +0 -2
Index: linux/include/linux/clockchips.h
===================================================================
@@ -16,8 +16,6 @@ enum clock_event_nofitiers {
 	CLOCK_EVT_NOTIFY_BROADCAST_FORCE,
 	CLOCK_EVT_NOTIFY_BROADCAST_ENTER,
 	CLOCK_EVT_NOTIFY_BROADCAST_EXIT,
-	CLOCK_EVT_NOTIFY_SUSPEND,
-	CLOCK_EVT_NOTIFY_RESUME,
 	CLOCK_EVT_NOTIFY_CPU_DYING,
 	CLOCK_EVT_NOTIFY_CPU_DEAD,
 };
include/linux/tick.h +3 -0
Index: linux/include/linux/tick.h
===================================================================
@@ -27,8 +27,11 @@ extern struct tick_device *tick_get_devi
 
 #ifdef CONFIG_GENERIC_CLOCKEVENTS
 extern void __init tick_init(void);
+/* Should be core only, but XEN resume magic abuses this interface */
+extern void tick_resume(void);
 #else /* CONFIG_GENERIC_CLOCKEVENTS */
 static inline void tick_init(void) { }
+static inline void tick_resume(void) { }
 #endif /* !CONFIG_GENERIC_CLOCKEVENTS */
 
 #ifdef CONFIG_TICK_ONESHOT
kernel/time/clockevents.c +0 -9
Index: linux/kernel/time/clockevents.c
===================================================================
@@ -566,15 +566,6 @@ int clockevents_notify(unsigned long rea
 		tick_handover_do_timer(arg);
 		break;
 
-	case CLOCK_EVT_NOTIFY_SUSPEND:
-		tick_suspend();
-		tick_suspend_broadcast();
-		break;
-
-	case CLOCK_EVT_NOTIFY_RESUME:
-		tick_resume();
-		break;
-
 	case CLOCK_EVT_NOTIFY_CPU_DEAD:
 		tick_shutdown_broadcast_oneshot(arg);
 		tick_shutdown_broadcast(arg);
kernel/time/tick-common.c +21 -2
Index: linux/kernel/time/tick-common.c
===================================================================
@@ -372,18 +372,37 @@ void tick_shutdown(unsigned int *cpup)
 	}
 }
 
+/**
+ * tick_suspend - Suspend the tick and the broadcast device
+ *
+ * Called from syscore_suspend() via timekeeping_suspend with only one
+ * CPU online and interrupts disabled.
+ *
+ * No locks required. Nothing can change the per cpu device.
+ */
 void tick_suspend(void)
 {
 	struct tick_device *td = this_cpu_ptr(&tick_cpu_device);
 
 	clockevents_shutdown(td->evtdev);
+	tick_suspend_broadcast();
 }
 
+/**
+ * tick_resume - Resume the tick and the broadcast device
+ *
+ * Called from syscore_resume() via timekeeping_resume with only one
+ * CPU online and interrupts disabled.
+ *
+ * No locks required. Nothing can change the per cpu device.
+ */
 void tick_resume(void)
 {
-	struct tick_device *td = this_cpu_ptr(&tick_cpu_device);
-	int broadcast = tick_resume_broadcast();
+	struct tick_device *td;
+	int broadcast;
 
+	broadcast = tick_resume_broadcast();
+	td = this_cpu_ptr(&tick_cpu_device);
 	clockevents_set_mode(td->evtdev, CLOCK_EVT_MODE_RESUME);
 
 	if (!broadcast) {
kernel/time/tick-internal.h +2 -1
Index: linux/kernel/time/tick-internal.h
===================================================================
@@ -23,7 +23,6 @@ extern void tick_check_new_device(struct
 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);
 extern bool tick_check_replacement(struct clock_event_device *curdev,
 				   struct clock_event_device *newdev);
 extern void tick_install_replacement(struct clock_event_device *dev);
@@ -41,6 +40,8 @@ extern void clockevents_exchange_device(
 extern void clockevents_handle_noop(struct clock_event_device *dev);
 extern int __clockevents_update_freq(struct clock_event_device *dev, u32 freq);
 extern ssize_t sysfs_get_uname(const char *buf, char *dst, size_t cnt);
+#else
+static inline void tick_suspend(void) { }
 #endif /* GENERIC_CLOCKEVENTS */
 
 /* Oneshot related functions */
kernel/time/timekeeping.c +2 -4
Index: linux/kernel/time/timekeeping.c
===================================================================
@@ -1245,9 +1245,7 @@ static void timekeeping_resume(void)
 
 	touch_softlockup_watchdog();
 
-	clockevents_notify(CLOCK_EVT_NOTIFY_RESUME, NULL);
-
-	/* Resume hrtimers */
+	tick_resume();
 	hrtimers_resume();
 }
 
@@ -1299,7 +1297,7 @@ static int timekeeping_suspend(void)
 	write_seqcount_end(&tk_core.seq);
 	raw_spin_unlock_irqrestore(&timekeeper_lock, flags);
 
-	clockevents_notify(CLOCK_EVT_NOTIFY_SUSPEND, NULL);
+	tick_suspend();
 	clocksource_suspend();
 	clockevents_suspend();
 
#10 lore raw

Re: [PATCH 07/35] clockevents: Make suspend/resume calls explicit

Quoted 23 lines · Peter Zijlstra

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 suspend/resume() calls and invoke them directly from the call sites.

No locking required at this point because these calls happen with interrupts disabled and a single cpu online.

---
 arch/x86/xen/suspend.c      |   11 ++++-------
 include/linux/clockchips.h  |    2 --
 include/linux/tick.h        |    3 +++
 kernel/time/clockevents.c   |    9 ---------
 kernel/time/tick-common.c   |   23 +++++++++++++++++++++--
 kernel/time/tick-internal.h |    3 ++-
 kernel/time/timekeeping.c   |    6 ++----
 7 files changed, 32 insertions(+), 25 deletions(-)

[cut]

Quoted 16 lines

Index: linux/include/linux/tick.h
===================================================================

include/linux/tick.h +3 -0
@@ -27,8 +27,11 @@ extern struct tick_device *tick_get_devi
 
 #ifdef CONFIG_GENERIC_CLOCKEVENTS
 extern void __init tick_init(void);
+/* Should be core only, but XEN resume magic abuses this interface */
+extern void tick_resume(void);
 #else /* CONFIG_GENERIC_CLOCKEVENTS */
 static inline void tick_init(void) { }
+static inline void tick_resume(void) { }
 #endif /* !CONFIG_GENERIC_CLOCKEVENTS */
 
 #ifdef CONFIG_TICK_ONESHOT

[cut]

Quoted 14 lines

Index: linux/kernel/time/tick-common.c
===================================================================

kernel/time/tick-common.c +6 -0
@@ -372,18 +372,37 @@ void tick_shutdown(unsigned int *cpup)
 	}
 }
 
+/**
+ * tick_suspend - Suspend the tick and the broadcast device
+ *
+ * Called from syscore_suspend() via timekeeping_suspend with only one
+ * CPU online and interrupts disabled.
+ *

kernel/time/tick-common.c void tick_shutdown(unsigned int *cpup) · line 390

Quoted 10 lines
kernel/time/tick-common.c +3 -0
+ * No locks required. Nothing can change the per cpu device.
+ */
 void tick_suspend(void)
 {
 	struct tick_device *td = this_cpu_ptr(&tick_cpu_device);
 
 	clockevents_shutdown(td->evtdev);
+	tick_suspend_broadcast();
 }
 

The above will slightly conflict with that commit of mine:

http://git.kernel.org/cgit/linux/kernel/git/rafael/linux-pm.git/commit/?h=linux-next&id=124cf9117c5f93cc5b324530b7e105b09c729d5d

but that's not a big deal I guess.

Rafael

author maintainer
#11 lore raw

PATCH 8/35 tick: Make tick_resume_broadcast_oneshot static

In reply to Peter Zijlstra

From: Thomas Gleixner <[email protected]>

Solely used in tick-broadcast.c and the return value is hardcoded
0. Make it static and void.

---
 kernel/time/tick-broadcast.c |    7 ++++---
 kernel/time/tick-internal.h  |    2 --
 2 files changed, 4 insertions(+), 5 deletions(-)
kernel/time/tick-broadcast.c +4 -3
Index: linux/kernel/time/tick-broadcast.c
===================================================================
@@ -37,8 +37,10 @@ static int tick_broadcast_force;
 
 #ifdef CONFIG_TICK_ONESHOT
 static void tick_broadcast_clear_oneshot(int cpu);
+static void tick_resume_broadcast_oneshot(struct clock_event_device *bc);
 #else
 static inline void tick_broadcast_clear_oneshot(int cpu) { }
+static inline void tick_resume_broadcast_oneshot(struct clock_event_device *bc) { }
 #endif
 
 /*
@@ -475,7 +477,7 @@ int tick_resume_broadcast(void)
 			break;
 		case TICKDEV_MODE_ONESHOT:
 			if (!cpumask_empty(tick_broadcast_mask))
-				broadcast = tick_resume_broadcast_oneshot(bc);
+				tick_resume_broadcast_oneshot(bc);
 			break;
 		}
 	}
@@ -541,10 +543,9 @@ static int tick_broadcast_set_event(stru
 	return ret;
 }
 
-int tick_resume_broadcast_oneshot(struct clock_event_device *bc)
+static void tick_resume_broadcast_oneshot(struct clock_event_device *bc)
 {
 	clockevents_set_mode(bc, CLOCK_EVT_MODE_ONESHOT);
-	return 0;
 }
 
 /*
kernel/time/tick-internal.h +0 -2
Index: linux/kernel/time/tick-internal.h
===================================================================
@@ -111,7 +111,6 @@ extern void tick_broadcast_setup_oneshot
 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_resume_broadcast_oneshot(struct clock_event_device *bc);
 extern int tick_broadcast_oneshot_active(void);
 extern void tick_check_oneshot_broadcast_this_cpu(void);
 bool tick_broadcast_oneshot_available(void);
@@ -121,7 +120,6 @@ static inline void tick_broadcast_setup_
 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_resume_broadcast_oneshot(struct clock_event_device *bc) { return 0; }
 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(); }
author maintainer
#12 lore raw

PATCH 9/35 tick/xen: Provide and use tick_resume_local()

In reply to Peter Zijlstra

From: Thomas Gleixner <[email protected]>

Xen calls on every cpu into tick_resume() which is just wrong. tick_resume() is for the syscore global suspend/resume invocation. What XEN really wants is a per cpu local resume function, but yes, its simpler to just use something which works by chance and let those who want to change that code deal with the fallout.

Provide a tick_resume_local() function and use it in XEN.

Cc Konrad Rzeszutek Wilk <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc David Vrabel <[email protected]>
---
 arch/x86/xen/suspend.c       |    2 +-
 include/linux/tick.h         |    6 +++---
 kernel/time/tick-broadcast.c |   27 ++++++++++++++++++++-------
 kernel/time/tick-common.c    |   28 +++++++++++++++++++---------
 kernel/time/tick-internal.h  |    8 ++++++--
 5 files changed, 49 insertions(+), 22 deletions(-)
arch/x86/xen/suspend.c +1 -1
Index: linux/arch/x86/xen/suspend.c
===================================================================
@@ -85,7 +85,7 @@ static void xen_vcpu_notify_restore(void
 	if (smp_processor_id() == 0)
 		return;
 
-	tick_resume();
+	tick_resume_local();
 }
 
 void xen_arch_resume(void)
include/linux/tick.h +3 -3
Index: linux/include/linux/tick.h
===================================================================
@@ -27,11 +27,11 @@ extern struct tick_device *tick_get_devi
 
 #ifdef CONFIG_GENERIC_CLOCKEVENTS
 extern void __init tick_init(void);
-/* Should be core only, but XEN resume magic abuses this interface */
-extern void tick_resume(void);
+/* Should be core only, but XEN resume magic requires this */
+extern void tick_resume_local(void);
 #else /* CONFIG_GENERIC_CLOCKEVENTS */
 static inline void tick_init(void) { }
-static inline void tick_resume(void) { }
+static inline void tick_resume_local(void) { }
 #endif /* !CONFIG_GENERIC_CLOCKEVENTS */
 
 #ifdef CONFIG_TICK_ONESHOT
kernel/time/tick-broadcast.c +20 -7
Index: linux/kernel/time/tick-broadcast.c
===================================================================
@@ -455,11 +455,29 @@ void tick_suspend_broadcast(void)
 	raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags);
 }
 
-int tick_resume_broadcast(void)
+/*
+ * This is called from tick_resume_local() on a resuming cpu. That's *
+ * called from the core resume function and the magic XEN resume hackery.
+ *
+ * It's intended to be called from tick_unfreeze_local() if the
+ * freezer folks figure out to guarantee that this is called before
+ * they reenable interrupts.
+ *
+ * In none of these cases the broadcast device mode can change and the
+ * bit of the resuming cpu in the broadcast mask is safe as well.
+ */
+bool tick_resume_check_broadcast(void)
+{
+	if (tick_broadcast_device.mode == TICKDEV_MODE_ONESHOT)
+		return false;
+	else
+		return cpumask_test_cpu(smp_processor_id(), tick_broadcast_mask);
+}
+
+void tick_resume_broadcast(void)
 {
 	struct clock_event_device *bc;
 	unsigned long flags;
-	int broadcast = 0;
 
 	raw_spin_lock_irqsave(&tick_broadcast_lock, flags);
 
@@ -472,8 +490,6 @@ int tick_resume_broadcast(void)
 		case TICKDEV_MODE_PERIODIC:
 			if (!cpumask_empty(tick_broadcast_mask))
 				tick_broadcast_start_periodic(bc);
-			broadcast = cpumask_test_cpu(smp_processor_id(),
-						     tick_broadcast_mask);
 			break;
 		case TICKDEV_MODE_ONESHOT:
 			if (!cpumask_empty(tick_broadcast_mask))
@@ -482,11 +498,8 @@ int tick_resume_broadcast(void)
 		}
 	}
 	raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags);
-
-	return broadcast;
 }
 
-
 #ifdef CONFIG_TICK_ONESHOT
 
 static cpumask_var_t tick_broadcast_oneshot_mask;
kernel/time/tick-common.c +19 -9
Index: linux/kernel/time/tick-common.c
===================================================================
@@ -389,22 +389,18 @@ void tick_suspend(void)
 }
 
 /**
- * tick_resume - Resume the tick and the broadcast device
+ * tick_resume_local - Resume the local tick device
  *
- * Called from syscore_resume() via timekeeping_resume with only one
- * CPU online and interrupts disabled.
+ * Called from the local cpu for unfreeze or XEN resume magic
  *
  * No locks required. Nothing can change the per cpu device.
  */
-void tick_resume(void)
+void tick_resume_local(void)
 {
-	struct tick_device *td;
-	int broadcast;
+	struct tick_device *td = this_cpu_ptr(&tick_cpu_device);
+	bool broadcast = tick_resume_check_broadcast();
 
-	broadcast = tick_resume_broadcast();
-	td = this_cpu_ptr(&tick_cpu_device);
 	clockevents_set_mode(td->evtdev, CLOCK_EVT_MODE_RESUME);
-
 	if (!broadcast) {
 		if (td->mode == TICKDEV_MODE_PERIODIC)
 			tick_setup_periodic(td->evtdev, 0);
@@ -414,6 +410,20 @@ void tick_resume(void)
 }
 
 /**
+ * tick_resume - Resume the tick and the broadcast device
+ *
+ * Called from syscore_resume() via timekeeping_resume with only one
+ * CPU online and interrupts disabled.
+ *
+ * No locks required. Nothing can change the per cpu device.
+ */
+void tick_resume(void)
+{
+	tick_resume_broadcast();
+	tick_resume_local();
+}
+
+/**
  * tick_init - initialize the tick control
  */
 void __init tick_init(void)
kernel/time/tick-internal.h +6 -2
Index: linux/kernel/time/tick-internal.h
===================================================================
@@ -23,6 +23,7 @@ extern void tick_check_new_device(struct
 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);
 extern bool tick_check_replacement(struct clock_event_device *curdev,
 				   struct clock_event_device *newdev);
 extern void tick_install_replacement(struct clock_event_device *dev);
@@ -42,6 +43,7 @@ extern int __clockevents_update_freq(str
 extern ssize_t sysfs_get_uname(const char *buf, char *dst, size_t cnt);
 #else
 static inline void tick_suspend(void) { }
+static inline void tick_resume(void) { }
 #endif /* GENERIC_CLOCKEVENTS */
 
 /* Oneshot related functions */
@@ -80,7 +82,8 @@ extern int tick_is_broadcast_device(stru
 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 int tick_resume_broadcast(void);
+extern void tick_resume_broadcast(void);
+extern bool tick_resume_check_broadcast(void);
 extern void tick_broadcast_init(void);
 extern void tick_set_periodic_handler(struct clock_event_device *dev, int broadcast);
 extern int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq);
@@ -94,7 +97,8 @@ static inline void tick_do_periodic_broa
 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 int tick_resume_broadcast(void) { return 0; }
+static inline void tick_resume_broadcast(void) { }
+static inline bool tick_resume_check_broadcast(void) { return false; }
 static inline void tick_broadcast_init(void) { }
 static inline int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq) { return -ENODEV; }
 
Acked-by on v1 9/35
#13 lore raw

Re: [PATCH 09/35] tick/xen: Provide and use tick_resume_local()

Quoted 10 lines · Peter Zijlstra

From: Thomas Gleixner <[email protected]>

Xen calls on every cpu into tick_resume() which is just wrong. tick_resume() is for the syscore global suspend/resume invocation. What XEN really wants is a per cpu local resume function, but yes, its simpler to just use something which works by chance and let those who want to change that code deal with the fallout.

Provide a tick_resume_local() function and use it in XEN.

David

author maintainer
#14 lore raw

PATCH 10/35 clockevents: Make tick handover explicit

In reply to Peter Zijlstra

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/include/linux/clockchips.h
===================================================================
@@ -16,7 +16,6 @@ enum clock_event_nofitiers {
 	CLOCK_EVT_NOTIFY_BROADCAST_FORCE,
 	CLOCK_EVT_NOTIFY_BROADCAST_ENTER,
 	CLOCK_EVT_NOTIFY_BROADCAST_EXIT,
-	CLOCK_EVT_NOTIFY_CPU_DYING,
 	CLOCK_EVT_NOTIFY_CPU_DEAD,
 };
 
include/linux/tick.h +2 -0
Index: linux/include/linux/tick.h
===================================================================
@@ -29,9 +29,11 @@ extern struct tick_device *tick_get_devi
 extern void __init tick_init(void);
 /* Should be core only, but XEN resume magic requires this */
 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_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/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"
@@ -348,6 +349,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/kernel/time/clockevents.c
===================================================================
@@ -562,10 +562,6 @@ int clockevents_notify(unsigned long rea
 		ret = tick_broadcast_oneshot_control(reason);
 		break;
 
-	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/kernel/time/hrtimer.c
===================================================================
@@ -1715,10 +1715,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/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/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);
author maintainer
#15 lore raw

PATCH 11/35 clockevents: Cleanup dead cpu explicitely

In reply to Peter Zijlstra

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 later patches.

---
 include/linux/clockchips.h   |    1 
 include/linux/tick.h         |    2 +
 kernel/cpu.c                 |    1 
 kernel/time/clockevents.c    |   61 +++++++++++++++++++++++++------------------
 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, 62 insertions(+), 51 deletions(-)
include/linux/clockchips.h +0 -1
Index: linux/include/linux/clockchips.h
===================================================================
@@ -16,7 +16,6 @@ enum clock_event_nofitiers {
 	CLOCK_EVT_NOTIFY_BROADCAST_FORCE,
 	CLOCK_EVT_NOTIFY_BROADCAST_ENTER,
 	CLOCK_EVT_NOTIFY_BROADCAST_EXIT,
-	CLOCK_EVT_NOTIFY_CPU_DEAD,
 };
 
 #ifdef CONFIG_GENERIC_CLOCKEVENTS
include/linux/tick.h +2 -0
Index: linux/include/linux/tick.h
===================================================================
@@ -30,10 +30,12 @@ extern void __init tick_init(void);
 /* Should be core only, but XEN resume magic requires this */
 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_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/kernel/cpu.c
===================================================================
@@ -428,6 +428,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 +36 -25

80 lines not on this page · raw message

kernel/time/hrtimer.c +0 -3
Index: linux/kernel/time/hrtimer.c
===================================================================
@@ -1717,11 +1717,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/kernel/time/tick-broadcast.c
===================================================================
@@ -418,14 +418,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);
 
@@ -440,6 +440,7 @@ void tick_shutdown_broadcast(unsigned in
 
 	raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags);
 }
+#endif
 
 void tick_suspend_broadcast(void)
 {
@@ -683,16 +684,6 @@ static void broadcast_shutdown_local(str
 	clockevents_set_mode(dev, CLOCK_EVT_MODE_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);
-}
-
 /*
  * Powerstate information: The system enters/leaves a state, where
  * affected devices might stop
@@ -908,14 +899,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);
 
@@ -931,6 +931,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/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;
@@ -374,6 +373,7 @@ void tick_shutdown(unsigned int *cpup)
 		td->evtdev = NULL;
 	}
 }
+#endif
 
 /**
  * tick_suspend - Suspend the tick and the broadcast device
kernel/time/tick-internal.h +5 -5
Index: linux/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,
@@ -79,7 +79,7 @@ extern int tick_device_uses_broadcast(st
 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_shutdown_broadcast(unsigned int cpu);
 extern void tick_suspend_broadcast(void);
 extern void tick_resume_broadcast(void);
 extern bool tick_resume_check_broadcast(void);
@@ -94,7 +94,7 @@ static inline int tick_is_broadcast_devi
 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_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; }
@@ -113,7 +113,7 @@ static inline void tick_set_periodic_han
 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 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);
@@ -122,7 +122,7 @@ extern struct cpumask *tick_get_broadcas
 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 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(); }
author maintainer
#16 lore raw

PATCH 12/35 clockevents: Provide explicit broadcast control function

In reply to Peter Zijlstra

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.

Cc Tony Lindgren <[email protected]>
Cc Fenghua Yu <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Len Brown <[email protected]>
Cc Daniel Lezcano <[email protected]>
---
 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/include/linux/tick.h
===================================================================
@@ -47,6 +47,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/kernel/time/clockevents.c
===================================================================
@@ -586,9 +586,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/kernel/time/tick-internal.h
===================================================================
@@ -78,7 +78,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 cpu);
 extern void tick_suspend_broadcast(void);
 extern void tick_resume_broadcast(void);
@@ -93,7 +92,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 cpu) { }
 static inline void tick_suspend_broadcast(void) { }
 static inline void tick_resume_broadcast(void) { }
Acked-by on v1 12/35
#17 lore raw

Re: [PATCH 12/35] clockevents: Provide explicit broadcast control function

On 02/16/2015 01:14 PM, Peter Zijlstra wrote:

[ patch is not inlined in my email ].

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
maintainer Tested-by on v1 12/35
#18 lore raw

Re: [PATCH 12/35] clockevents: Provide explicit broadcast control function

In reply to Peter Zijlstra
Quoted 11 lines · Peter Zijlstra

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.

Quoted 5 lines

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.

Seems to still behave for my off-idle PM tests after a quick try on Peter's timers/core branch. Might be too late, but just in case it's not:

author maintainer
#19 lore raw

PATCH 13/35 x86, amd_idle: Use explicit broadcast control functions

In reply to Peter Zijlstra

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/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>
@@ -376,11 +376,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);
author maintainer
#20 lore raw

PATCH 14/35 ACPI / PAD: Use explicit broadcast control function

In reply to Peter Zijlstra

From: Thomas Gleixner <[email protected]>

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

Cc Fenghua Yu <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Len Brown <[email protected]>
---
 drivers/acpi/acpi_pad.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/acpi/acpi_pad.c +2 -3
Index: linux/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();
author maintainer
#21 lore raw

PATCH 15/35 ACPI/ processor_idle: Use explicit broadcast controll function

In reply to Peter Zijlstra

From: Thomas Gleixner <[email protected]>

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

Cc Fenghua Yu <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Len Brown <[email protected]>
---
 drivers/acpi/processor_idle.c |   11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/acpi/processor_idle.c +5 -6
Index: linux/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)
author maintainer
#22 lore raw

PATCH 16/35 cpuidle: Use explicit broadcast control function

In reply to Peter Zijlstra

From: Thomas Gleixner <[email protected]>

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

Cc "Rafael J. Wysocki" <[email protected]>
Cc Daniel Lezcano <[email protected]>
---
 drivers/cpuidle/driver.c |   25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)
drivers/cpuidle/driver.c +12 -13
Index: linux/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);
Acked-by on v1 16/35
#23 lore raw

Re: [PATCH 16/35] cpuidle: Use explicit broadcast control function

On 02/16/2015 01:14 PM, Peter Zijlstra wrote:

[ patch not inline ]

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
author maintainer
#24 lore raw

PATCH 17/35 intel_idle: Use explicit broadcast control function

In reply to Peter Zijlstra

From: Thomas Gleixner <[email protected]>

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

Cc Fenghua Yu <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Len Brown <[email protected]>
---
 drivers/idle/intel_idle.c |   13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/idle/intel_idle.c +6 -7
Index: linux/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>
@@ -594,13 +594,12 @@ static int intel_idle(struct cpuidle_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,
author maintainer
#25 lore raw

PATCH 18/35 ARM: OMAP: Use explicit broadcast control function

In reply to Peter Zijlstra

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/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>
 #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 = {
maintainer Tested-by on v1 18/35
#26 lore raw

Re: [PATCH 18/35] ARM: OMAP: Use explicit broadcast control function

Quoted 6 lines · Peter Zijlstra

From: Thomas Gleixner <[email protected]>

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

This too seems to work just fine:

Quoted 29 lines
---
 arch/arm/mach-omap2/cpuidle44xx.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Index: linux/arch/arm/mach-omap2/cpuidle44xx.c
===================================================================

arch/arm/mach-omap2/cpuidle44xx.c +2 -3
@@ -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 = {
author maintainer
#27 lore raw

PATCH 19/35 clockevents: Remove the broadcast control leftovers

In reply to Peter Zijlstra

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/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,
 };
kernel/time/clockevents.c +0 -10
Index: linux/kernel/time/clockevents.c
===================================================================
@@ -585,16 +585,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);
author maintainer
#28 lore raw

PATCH 20/35 clockevents: Provide explicit broadcast oneshot control function

In reply to Peter Zijlstra

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 "Rafael J. Wysocki" <[email protected]>
Cc Fenghua Yu <[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/include/linux/tick.h
===================================================================
@@ -53,12 +53,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);
@@ -71,6 +82,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/kernel/time/clockevents.c
===================================================================
@@ -586,8 +586,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;
 
 	default:
kernel/time/tick-broadcast.c +17 -11
Index: linux/kernel/time/tick-broadcast.c
===================================================================
@@ -676,18 +676,23 @@ static void broadcast_shutdown_local(str
 	clockevents_set_mode(dev, CLOCK_EVT_MODE_SHUTDOWN);
 }
 
-/*
- * 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
@@ -700,17 +705,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);
@@ -802,9 +807,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/kernel/time/tick-internal.h
===================================================================
@@ -109,7 +109,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 cpu);
 extern int tick_broadcast_oneshot_active(void);
@@ -118,7 +117,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 cpu) { }
 static inline int tick_broadcast_oneshot_active(void) { return 0; }
maintainer Tested-by on v1 20/35
#29 lore raw

Re: [PATCH 20/35] clockevents: Provide explicit broadcast oneshot control function

Quoted 11 lines · Peter Zijlstra

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.

Quoted 5 lines

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.

Still works for me:

author maintainer
#30 lore raw

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

In reply to Peter Zijlstra

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/arch/x86/kernel/process.c
===================================================================
@@ -380,7 +380,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();
 
@@ -389,7 +389,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();
author maintainer
#31 lore raw

PATCH 22/35 ACPI / PAD: Use explicit broadcast oneshot control function

In reply to Peter Zijlstra

From: Thomas Gleixner <[email protected]>

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

Cc Fenghua Yu <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Len Brown <[email protected]>
---
 drivers/acpi/acpi_pad.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/acpi/acpi_pad.c +2 -4
Index: linux/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)) {
author maintainer
#32 lore raw

PATCH 23/35 ACPI/ processor_idle: Use explicit broadcast oneshot controll function

In reply to Peter Zijlstra

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/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();
 	}
 }
 
author maintainer
#33 lore raw

PATCH 24/35 intel_idle: Use explicit broadcast oneshot control function

In reply to Peter Zijlstra

From: Thomas Gleixner <[email protected]>

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

Cc Fenghua Yu <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Len Brown <[email protected]>
---
 drivers/idle/intel_idle.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/idle/intel_idle.c +2 -2
Index: linux/drivers/idle/intel_idle.c
===================================================================
@@ -582,12 +582,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;
 }
author maintainer
#34 lore raw

PATCH 25/35 ARM: OMAP: Use explicit broadcast oneshot control function

In reply to Peter Zijlstra

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/arch/arm/mach-omap2/cpuidle44xx.c
===================================================================
@@ -84,7 +84,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.
@@ -112,7 +111,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
@@ -169,7 +168,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);
maintainer Tested-by on v1 25/35
#35 lore raw

Re: [PATCH 25/35] ARM: OMAP: Use explicit broadcast oneshot control function

Quoted 6 lines · Peter Zijlstra

From: Thomas Gleixner <[email protected]>

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

Works for me:

Quoted 36 lines
---
 arch/arm/mach-omap2/cpuidle44xx.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

Index: linux/arch/arm/mach-omap2/cpuidle44xx.c
===================================================================

arch/arm/mach-omap2/cpuidle44xx.c +2 -3
@@ -84,7 +84,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.
@@ -112,7 +111,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
@@ -169,7 +168,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);
author maintainer
#36 lore raw

PATCH 26/35 ARM: tegra: Use explicit broadcast oneshot control function

In reply to Peter Zijlstra

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/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/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>
@@ -136,11 +136,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();
@@ -153,13 +153,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/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>
@@ -76,11 +76,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;
 }
@@ -90,13 +90,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;
 }
author maintainer
#37 lore raw

PATCH 27/35 sched/idle: Use explicit broadcast oneshot control function

In reply to Peter Zijlstra

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/kernel/sched/idle.c
===================================================================
@@ -143,8 +143,7 @@ use_default:
 	 * 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. */
@@ -161,7 +160,7 @@ use_default:
 	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
#38 lore raw

Re: [PATCH 27/35] sched/idle: Use explicit broadcast oneshot control function

Quoted 5 lines · Peter Zijlstra

From: Thomas Gleixner <[email protected]>

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

This patch makes my test system hang solid after letting it sit idle for 5 to 15 minutes. Reverting it and this issue goes away.

The explicit function call is not an equivalent replacement. In clockevents_notify() the clockevents_lock is held across the call to tick_broadcast_enter() or tick_broadcast_exit(). This patch drops the locking.

Quoted 36 lines
---
 kernel/sched/idle.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

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

kernel/sched/idle.c +2 -4
@@ -143,8 +143,7 @@ use_default:
 	 * 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. */
@@ -161,7 +160,7 @@ use_default:
 	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
 
 
--

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/

author maintainer
#39 lore raw

Re: [PATCH 27/35] sched/idle: Use explicit broadcast oneshot control function

Quoted 8 lines · Nicolas Pitre
Quoted 5 lines · Peter Zijlstra

From: Thomas Gleixner <[email protected]>

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

Quoted 7 lines

This patch makes my test system hang solid after letting it sit idle for 5 to 15 minutes. Reverting it and this issue goes away.

The explicit function call is not an equivalent replacement. In clockevents_notify() the clockevents_lock is held across the call to tick_broadcast_enter() or tick_broadcast_exit(). This patch drops the locking.

Yeah, the Changelog introducing the explicit call states as much. I'll have to go figure out why that matters here.

author maintainer
#40 lore raw

PATCH 28/35 clockevents: Remove the broadcast oneshot control leftovers

In reply to Peter Zijlstra

From: Thomas Gleixner <[email protected]>

All users converted. Remove the notify leftovers.

---
 include/linux/clockchips.h |   12 ------------
 kernel/time/clockevents.c  |   27 ---------------------------
 2 files changed, 39 deletions(-)
include/linux/clockchips.h +0 -12
Index: linux/include/linux/clockchips.h
===================================================================
@@ -8,19 +8,11 @@
 #ifndef _LINUX_CLOCKCHIPS_H
 #define _LINUX_CLOCKCHIPS_H
 
-/* Clock event notification values */
-enum clock_event_nofitiers {
-	CLOCK_EVT_NOTIFY_ADD,
-	CLOCK_EVT_NOTIFY_BROADCAST_ENTER,
-	CLOCK_EVT_NOTIFY_BROADCAST_EXIT,
-};
-
 #ifdef CONFIG_GENERIC_CLOCKEVENTS
 
 #include <linux/clocksource.h>
 #include <linux/cpumask.h>
 #include <linux/ktime.h>
-#include <linux/notifier.h>
 
 struct clock_event_device;
 struct module;
@@ -184,17 +176,13 @@ static inline int tick_check_broadcast_e
 static inline void tick_setup_hrtimer_broadcast(void) {};
 #endif
 
-extern int clockevents_notify(unsigned long reason, void *arg);
-
 #else /* CONFIG_GENERIC_CLOCKEVENTS */
 
 static inline void clockevents_suspend(void) {}
 static inline void clockevents_resume(void) {}
 
-static inline int clockevents_notify(unsigned long reason, void *arg) { return 0; }
 static inline int tick_check_broadcast_expired(void) { return 0; }
 static inline void tick_setup_hrtimer_broadcast(void) {};
-static inline int clockevents_notify(unsigned long reason, void *arg) { return 0; }
 
 #endif
 
kernel/time/clockevents.c +0 -27
Index: linux/kernel/time/clockevents.c
===================================================================
@@ -573,33 +573,6 @@ void tick_cleanup_dead_cpu(int cpu)
 }
 #endif
 
-/**
- * clockevents_notify - notification about relevant events
- * Returns 0 on success, any other value on error
- */
-int clockevents_notify(unsigned long reason, void *arg)
-{
-	unsigned long flags;
-	int ret = 0;
-
-	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;
-
-	default:
-		break;
-	}
-	raw_spin_unlock_irqrestore(&clockevents_lock, flags);
-	return ret;
-}
-EXPORT_SYMBOL_GPL(clockevents_notify);
-
 #ifdef CONFIG_SYSFS
 struct bus_type clockevents_subsys = {
 	.name		= "clockevents",
author maintainer
#41 lore raw

PATCH 29/35 tick/timekeeping: Make PM_SLEEP related code conditional

In reply to Peter Zijlstra

From: Thomas Gleixner <[email protected]>

No point in compiling this in if PM_SLEEP=n

---
 include/linux/clockchips.h   |    6 ------
 include/linux/clocksource.h  |    2 --
 kernel/time/clockevents.c    |    2 ++
 kernel/time/clocksource.c    |    2 ++
 kernel/time/tick-broadcast.c |   12 ++++++------
 kernel/time/tick-common.c    |    2 ++
 kernel/time/tick-internal.h  |    4 ++++
 kernel/time/timekeeping.c    |    2 ++
 kernel/time/timekeeping.h    |    3 +++
 9 files changed, 21 insertions(+), 14 deletions(-)
include/linux/clockchips.h +0 -6
Index: linux/include/linux/clockchips.h
===================================================================
@@ -156,9 +156,6 @@ extern void clockevents_set_mode(struct
 extern int clockevents_program_event(struct clock_event_device *dev,
 				     ktime_t expires, bool force);
 
-extern void clockevents_suspend(void);
-extern void clockevents_resume(void);
-
 #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
 #ifdef CONFIG_ARCH_HAS_TICK_BROADCAST
 extern void tick_broadcast(const struct cpumask *mask);
@@ -178,9 +175,6 @@ static inline void tick_setup_hrtimer_br
 
 #else /* CONFIG_GENERIC_CLOCKEVENTS */
 
-static inline void clockevents_suspend(void) {}
-static inline void clockevents_resume(void) {}
-
 static inline int tick_check_broadcast_expired(void) { return 0; }
 static inline void tick_setup_hrtimer_broadcast(void) {};
 
include/linux/clocksource.h +0 -2
Index: linux/include/linux/clocksource.h
===================================================================
@@ -285,8 +285,6 @@ extern int clocksource_unregister(struct
 extern void clocksource_touch_watchdog(void);
 extern struct clocksource* clocksource_get_next(void);
 extern void clocksource_change_rating(struct clocksource *cs, int rating);
-extern void clocksource_suspend(void);
-extern void clocksource_resume(void);
 extern struct clocksource * __init clocksource_default_clock(void);
 extern void clocksource_mark_unstable(struct clocksource *cs);
 
kernel/time/clockevents.c +2 -0
Index: linux/kernel/time/clockevents.c
===================================================================
@@ -514,6 +514,7 @@ void clockevents_exchange_device(struct
 	}
 }
 
+#ifdef CONFIG_PM_SLEEP
 /**
  * clockevents_suspend - suspend clock devices
  */
@@ -537,6 +538,7 @@ void clockevents_resume(void)
 		if (dev->resume)
 			dev->resume(dev);
 }
+#endif
 
 #ifdef CONFIG_HOTPLUG_CPU
 /**
kernel/time/clocksource.c +2 -0
Index: linux/kernel/time/clocksource.c
===================================================================
@@ -485,6 +485,7 @@ void clocksource_mark_unstable(struct cl
 
 #endif /* CONFIG_CLOCKSOURCE_WATCHDOG */
 
+#ifdef CONFIG_PM_SLEEP
 /**
  * clocksource_suspend - suspend the clocksource(s)
  */
@@ -510,6 +511,7 @@ void clocksource_resume(void)
 
 	clocksource_resume_watchdog();
 }
+#endif
 
 /**
  * clocksource_touch_watchdog - Update watchdog
kernel/time/tick-broadcast.c +6 -6
Index: linux/kernel/time/tick-broadcast.c
===================================================================
@@ -37,7 +37,10 @@ static int tick_broadcast_forced;
 
 #ifdef CONFIG_TICK_ONESHOT
 static void tick_broadcast_clear_oneshot(int cpu);
-static void tick_resume_broadcast_oneshot(struct clock_event_device *bc);
+static inline void tick_resume_broadcast_oneshot(struct clock_event_device *bc)
+{
+	clockevents_set_mode(bc, CLOCK_EVT_MODE_ONESHOT);
+}
 #else
 static inline void tick_broadcast_clear_oneshot(int cpu) { }
 static inline void tick_resume_broadcast_oneshot(struct clock_event_device *bc) { }
@@ -434,6 +437,7 @@ void tick_shutdown_broadcast(unsigned in
 }
 #endif
 
+#ifdef CONFIG_PM_SLEEP
 void tick_suspend_broadcast(void)
 {
 	struct clock_event_device *bc;
@@ -492,6 +496,7 @@ void tick_resume_broadcast(void)
 	}
 	raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags);
 }
+#endif
 
 #ifdef CONFIG_TICK_ONESHOT
 
@@ -549,11 +554,6 @@ static int tick_broadcast_set_event(stru
 	return ret;
 }
 
-static void tick_resume_broadcast_oneshot(struct clock_event_device *bc)
-{
-	clockevents_set_mode(bc, CLOCK_EVT_MODE_ONESHOT);
-}
-
 /*
  * Called from irq_enter() when idle was interrupted to reenable the
  * per cpu device.
kernel/time/tick-common.c +2 -0
Index: linux/kernel/time/tick-common.c
===================================================================
@@ -375,6 +375,7 @@ void tick_shutdown(unsigned int cpu)
 }
 #endif
 
+#ifdef CONFIG_PM_SLEEP
 /**
  * tick_suspend - Suspend the tick and the broadcast device
  *
@@ -425,6 +426,7 @@ void tick_resume(void)
 	tick_resume_broadcast();
 	tick_resume_local();
 }
+#endif
 
 /**
  * tick_init - initialize the tick control
kernel/time/tick-internal.h +4 -0
Index: linux/kernel/time/tick-internal.h
===================================================================
@@ -39,10 +39,14 @@ extern void clockevents_exchange_device(
 					struct clock_event_device *new);
 extern void clockevents_handle_noop(struct clock_event_device *dev);
 extern int __clockevents_update_freq(struct clock_event_device *dev, u32 freq);
+extern void clockevents_suspend(void);
+extern void clockevents_resume(void);
 extern ssize_t sysfs_get_uname(const char *buf, char *dst, size_t cnt);
 #else
 static inline void tick_suspend(void) { }
 static inline void tick_resume(void) { }
+static inline void clockevents_suspend(void) {}
+static inline void clockevents_resume(void) {}
 #endif /* GENERIC_CLOCKEVENTS */
 
 /* Oneshot related functions */
kernel/time/timekeeping.c +2 -0
Index: linux/kernel/time/timekeeping.c
===================================================================
@@ -1100,6 +1100,7 @@ void __init timekeeping_init(void)
 	raw_spin_unlock_irqrestore(&timekeeper_lock, flags);
 }
 
+#ifdef CONFIG_PM_SLEEP
 /* time in seconds when suspend began */
 static struct timespec64 timekeeping_suspend_time;
 
@@ -1316,6 +1317,7 @@ static int __init timekeeping_init_ops(v
 	return 0;
 }
 device_initcall(timekeeping_init_ops);
+#endif
 
 /*
  * Apply a multiplier adjustment to the timekeeper
kernel/time/timekeeping.h +3 -0
Index: linux/kernel/time/timekeeping.h
===================================================================
@@ -20,6 +20,9 @@ extern void timekeeping_clocktai(struct
 extern void do_timer(unsigned long ticks);
 extern void update_wall_time(void);
 
+extern void clocksource_suspend(void);
+extern void clocksource_resume(void);
+
 extern seqlock_t jiffies_lock;
 
 #define CS_NAME_LEN	32
author maintainer
#42 lore raw

PATCH 30/35 timekeeping: Get rid of stale comment

In reply to Peter Zijlstra

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/kernel/time/timekeeping.c
===================================================================
@@ -1166,10 +1166,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.
  */
 static void timekeeping_resume(void)
 {
author maintainer
#43 lore raw

PATCH 31/35 clockevents: Consolidate tick_shutdown()

In reply to Peter Zijlstra

From: Thomas Gleixner <[email protected]>

No point in having 3 global functions in the clockevents code if we can chain them internally.

---
 kernel/time/clockevents.c    |    2 --
 kernel/time/tick-broadcast.c |   21 ++++++++++++---------
 kernel/time/tick-common.c    |    3 +++
 kernel/time/tick-internal.h  |    2 --
 4 files changed, 15 insertions(+), 13 deletions(-)
kernel/time/clockevents.c +0 -2
Index: linux/kernel/time/clockevents.c
===================================================================
@@ -551,8 +551,6 @@ void tick_cleanup_dead_cpu(int cpu)
 
 	raw_spin_lock_irqsave(&clockevents_lock, flags);
 
-	tick_shutdown_broadcast_oneshot(cpu);
-	tick_shutdown_broadcast(cpu);
 	tick_shutdown(cpu);
 	/*
 	 * Unregister the clock event devices which were
kernel/time/tick-broadcast.c +12 -9
Index: linux/kernel/time/tick-broadcast.c
===================================================================
@@ -46,6 +46,12 @@ static inline void tick_broadcast_clear_
 static inline void tick_resume_broadcast_oneshot(struct clock_event_device *bc) { }
 #endif
 
+#if defined(CONFIG_TICK_ONESHOT) && defined (CONFIG_HOTPLUG_CPU)
+static void tick_shutdown_broadcast_oneshot(unsigned int cpu);
+#else
+static inline void tick_shutdown_broadcast_oneshot(unsigned int cpu) { }
+#endif
+
 /*
  * Debugging: see timer_list.c
  */
@@ -424,15 +430,17 @@ void tick_shutdown_broadcast(unsigned in
 
 	raw_spin_lock_irqsave(&tick_broadcast_lock, flags);
 
-	bc = tick_broadcast_device.evtdev;
 	cpumask_clear_cpu(cpu, tick_broadcast_mask);
 	cpumask_clear_cpu(cpu, tick_broadcast_on);
 
+	bc = tick_broadcast_device.evtdev;
 	if (tick_broadcast_device.mode == TICKDEV_MODE_PERIODIC) {
 		if (bc && cpumask_empty(tick_broadcast_mask))
 			clockevents_shutdown(bc);
 	}
 
+	tick_shutdown_broadcast_oneshot(cpu);
+
 	raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags);
 }
 #endif
@@ -909,14 +917,11 @@ static void broadcast_move_bc(int deadcp
 }
 
 /*
- * Remove a dead CPU from broadcasting
+ * Remove a dead CPU from broadcasting, called with broadcast lock
+ * held.
  */
-void tick_shutdown_broadcast_oneshot(unsigned int cpu)
+static void tick_shutdown_broadcast_oneshot(unsigned int cpu)
 {
-	unsigned long flags;
-
-	raw_spin_lock_irqsave(&tick_broadcast_lock, flags);
-
 	/*
 	 * Clear the broadcast masks for the dead cpu, but do not stop
 	 * the broadcast device!
@@ -926,8 +931,6 @@ void tick_shutdown_broadcast_oneshot(uns
 	cpumask_clear_cpu(cpu, tick_broadcast_force_mask);
 
 	broadcast_move_bc(cpu);
-
-	raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags);
 }
 #endif
 
kernel/time/tick-common.c +3 -0
Index: linux/kernel/time/tick-common.c
===================================================================
@@ -361,6 +361,9 @@ void tick_shutdown(unsigned int cpu)
 	struct tick_device *td = &per_cpu(tick_cpu_device, cpu);
 	struct clock_event_device *dev = td->evtdev;
 
+	/* Remove the CPU from the broadcast machinery */
+	tick_shutdown_broadcast(cpu);
+
 	td->mode = TICKDEV_MODE_PERIODIC;
 	if (dev) {
 		/*
kernel/time/tick-internal.h +0 -2
Index: linux/kernel/time/tick-internal.h
===================================================================
@@ -114,7 +114,6 @@ 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 cpu);
 extern int tick_broadcast_oneshot_active(void);
 extern void tick_check_oneshot_broadcast_this_cpu(void);
 bool tick_broadcast_oneshot_available(void);
@@ -122,7 +121,6 @@ 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 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(); }
author maintainer
#44 lore raw

PATCH 32/35 clockevents: Fix cpu down race for hrtimer based broadcasting

In reply to Peter Zijlstra

From: Thomas Gleixner <[email protected]>

Preeti reported a cpu down race with hrtimer based broadcasting:

Assume CPU1 is the CPU which holds the hrtimer broadcasting duty before it is taken down.

CPU0 CPU1
cpu_down()
takedown_cpu()
disable_interrupts()
cpu_die()

  while (CPU1 != DEAD) {
    msleep(100);
      switch_to_idle()
        stop_cpu_timer()
          schedule_broadcast()

}

tick_cleanup_dead_cpu()
take_over_broadcast()

So after CPU1 disabled interrupts it cannot handle the broadcast hrtimer anymore, so CPU0 will be stuck forever.

Doing a "while (CPU1 != DEAD) msleep(100);" periodic poll is silly at best, but we need to fix that nevertheless.

Split the tick cleanup into two pieces:

1) Shutdown and remove all per cpu clockevent devices from takedown_cpu()

This is done carefully with respect to existing arch code which works around the shortcoming of the clockevents core code in interesting ways. We really want a separate callback for this to cleanup the workarounds, but that's not scope of this patch

2) Takeover the broadcast duty explicitely before calling cpu_die()

This is a temporary workaround as well. What we really want is a callback in the clockevent device which allows us to do that from the dying CPU by pushing the hrtimer onto a different cpu. That might involve an IPI and is definitely more complex than this immediate fix.

---
 include/linux/tick.h         |    9 +++++----
 kernel/cpu.c                 |    6 +++---
 kernel/time/clockevents.c    |   30 ++++++++++++++++++------------
 kernel/time/tick-broadcast.c |   32 ++++++++++++++++++++++----------
 kernel/time/tick-common.c    |   34 ++++++++++++----------------------
 kernel/time/tick-internal.h  |    6 +++---
 6 files changed, 63 insertions(+), 54 deletions(-)
include/linux/tick.h +5 -4
Index: linux/include/linux/tick.h
===================================================================
@@ -29,13 +29,12 @@ extern struct tick_device *tick_get_devi
 extern void __init tick_init(void);
 /* Should be core only, but XEN resume magic requires this */
 extern void tick_resume_local(void);
-extern void tick_handover_do_timer(void);
-extern void tick_cleanup_dead_cpu(int cpu);
+/* CPU hotplug */
+extern void tick_shutdown_local(void);
 #else /* CONFIG_GENERIC_CLOCKEVENTS */
 static inline void tick_init(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) { }
+static inline void tick_shutdown_local(void) { }
 #endif /* !CONFIG_GENERIC_CLOCKEVENTS */
 
 #ifdef CONFIG_TICK_ONESHOT
@@ -66,8 +65,10 @@ static inline void tick_broadcast_contro
 
 #if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
 extern int tick_broadcast_oneshot_control(enum tick_broadcast_state state);
+extern void tick_takeover(int deadcpu);
 #else
 static inline int tick_broadcast_oneshot_control(enum tick_broadcast_state state) { return 0; }
+static inline void tick_takeover(int deadcpu) { }
 #endif
 
 static inline void tick_broadcast_enable(void)
kernel/cpu.c +3 -3
Index: linux/kernel/cpu.c
===================================================================
@@ -349,8 +349,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();
+	/* Shutdown the per cpu tick */
+	tick_shutdown_local();
 	/* Park the stopper thread */
 	kthread_park(current);
 	return 0;
@@ -428,7 +428,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);
+	tick_takeover(cpu);
 	cpu_notify_nofail(CPU_DEAD | mod, hcpu);
 
 	check_for_tasks(cpu);
kernel/time/clockevents.c +18 -12
Index: linux/kernel/time/clockevents.c
===================================================================
@@ -541,26 +541,32 @@ void clockevents_resume(void)
 #endif
 
 #ifdef CONFIG_HOTPLUG_CPU
-/**
- * tick_cleanup_dead_cpu - Cleanup the tick and clockevents of a dead cpu
+/*
+ * Cleanup the clock events devices on the dying cpu. curdev is the
+ * current installed tick device on that cpu
  */
-void tick_cleanup_dead_cpu(int cpu)
+void clockevents_cleanup_dying_cpu(struct clock_event_device *curdev)
 {
 	struct clock_event_device *dev, *tmp;
 	unsigned long flags;
+	int cpu;
 
 	raw_spin_lock_irqsave(&clockevents_lock, flags);
-
-	tick_shutdown(cpu);
-	/*
-	 * Unregister the clock event devices which were
-	 * released from the users in the notify chain.
-	 */
-	list_for_each_entry_safe(dev, tmp, &clockevents_released, list)
-		list_del(&dev->list);
+	if (!curdev)
+		goto cleanup;
 	/*
-	 * Now check whether the CPU has left unused per cpu devices
+	 * We cannot call the set mode function here at the moment
+	 * because existing architecture cpu down code shuts down
+	 * stuff already and we cannot interfere with that. So we just
+	 * set the mode to unused for now.
 	 */
+	curdev->mode = CLOCK_EVT_MODE_UNUSED;
+	list_del(&curdev->list);
+	module_put(curdev->owner);
+
+cleanup:
+	/* Remove the unused percpu devices from the list */
+	cpu = smp_processor_id();
 	list_for_each_entry_safe(dev, tmp, &clockevent_devices, list) {
 		if (cpumask_test_cpu(cpu, dev->cpumask) &&
 		    cpumask_weight(dev->cpumask) == 1 &&
kernel/time/tick-broadcast.c +22 -10
Index: linux/kernel/time/tick-broadcast.c
===================================================================
@@ -421,15 +421,17 @@ void tick_set_periodic_handler(struct cl
 
 #ifdef CONFIG_HOTPLUG_CPU
 /*
- * Remove a CPU from broadcasting
+ * Remove a CPU from broadcasting. Called from the dying cpu.
  */
-void tick_shutdown_broadcast(unsigned int cpu)
+void tick_shutdown_broadcast(void)
 {
 	struct clock_event_device *bc;
 	unsigned long flags;
+	int cpu;
 
 	raw_spin_lock_irqsave(&tick_broadcast_lock, flags);
 
+	cpu = smp_processor_id();
 	cpumask_clear_cpu(cpu, tick_broadcast_mask);
 	cpumask_clear_cpu(cpu, tick_broadcast_on);
 
@@ -906,14 +908,26 @@ void tick_broadcast_switch_to_oneshot(vo
 }
 
 #ifdef CONFIG_HOTPLUG_CPU
-static void broadcast_move_bc(int deadcpu)
+/*
+ * Called from the cpu hotplug code after a cpu is dead. This ensures
+ * that a hrtimer based broad cast device is taken over.
+ *
+ * FIXME: This should go away. We should replace this by a mechanism
+ * which pushes the hrtimer over to a different cpu from
+ * tick_shutdown_broadcast_oneshot()
+ */
+void tick_broadcast_takeover_bc(int deadcpu)
 {
-	struct clock_event_device *bc = tick_broadcast_device.evtdev;
+	struct clock_event_device *bc;
+	unsigned long flags;
 
-	if (!bc || !broadcast_needs_cpu(bc, deadcpu))
-		return;
-	/* This moves the broadcast assignment to this cpu */
-	clockevents_program_event(bc, bc->next_event, 1);
+	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);
 }
 
 /*
@@ -929,8 +943,6 @@ static void tick_shutdown_broadcast_ones
 	cpumask_clear_cpu(cpu, tick_broadcast_oneshot_mask);
 	cpumask_clear_cpu(cpu, tick_broadcast_pending_mask);
 	cpumask_clear_cpu(cpu, tick_broadcast_force_mask);
-
-	broadcast_move_bc(cpu);
 }
 #endif
 
kernel/time/tick-common.c +12 -22
Index: linux/kernel/time/tick-common.c
===================================================================
@@ -336,10 +336,10 @@ out_bc:
 /*
  * Transfer the do_timer job away from a dying cpu.
  *
- * Called with interrupts disabled. Not locking required. If
- * tick_do_timer_cpu is owned by this cpu, nothing can change it.
+ * No locking required. If tick_do_timer_cpu is owned by this cpu,
+ * nothing can change it.
  */
-void tick_handover_do_timer(void)
+static void tick_handover_do_timer(void)
 {
 	if (tick_do_timer_cpu == smp_processor_id()) {
 		int cpu = cpumask_first(cpu_online_mask);
@@ -349,32 +349,22 @@ void tick_handover_do_timer(void)
 	}
 }
 
-/*
- * Shutdown an event device on a given cpu:
+/**
+ * tick_shutdown_local - Shutdown the tick related functions on a cpu
  *
- * This is called on a life CPU, when a CPU is dead. So we cannot
- * access the hardware device itself.
- * We just set the mode and remove it from the lists.
+ * This is called from the dying cpu.
  */
-void tick_shutdown(unsigned int cpu)
+void tick_shutdown_local(void)
 {
-	struct tick_device *td = &per_cpu(tick_cpu_device, cpu);
-	struct clock_event_device *dev = td->evtdev;
+	struct tick_device *td = this_cpu_ptr(&tick_cpu_device);
 
 	/* Remove the CPU from the broadcast machinery */
-	tick_shutdown_broadcast(cpu);
+	tick_shutdown_broadcast();
 
+	clockevents_cleanup_dying_cpu(td->evtdev);
 	td->mode = TICKDEV_MODE_PERIODIC;
-	if (dev) {
-		/*
-		 * Prevent that the clock events layer tries to call
-		 * the set mode function!
-		 */
-		dev->mode = CLOCK_EVT_MODE_UNUSED;
-		clockevents_exchange_device(dev, NULL);
-		dev->event_handler = clockevents_handle_noop;
-		td->evtdev = NULL;
-	}
+
+	tick_handover_do_timer();
 }
 #endif
 
kernel/time/tick-internal.h +3 -3
Index: linux/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_shutdown(unsigned int cpu);
 extern void tick_suspend(void);
 extern void tick_resume(void);
 extern bool tick_check_replacement(struct clock_event_device *curdev,
@@ -38,6 +37,7 @@ extern void clockevents_shutdown(struct
 extern void clockevents_exchange_device(struct clock_event_device *old,
 					struct clock_event_device *new);
 extern void clockevents_handle_noop(struct clock_event_device *dev);
+extern void clockevents_cleanup_dying_cpu(struct clock_event_device *dev);
 extern int __clockevents_update_freq(struct clock_event_device *dev, u32 freq);
 extern void clockevents_suspend(void);
 extern void clockevents_resume(void);
@@ -82,7 +82,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 cpu);
+extern void tick_shutdown_broadcast(void);
 extern void tick_suspend_broadcast(void);
 extern void tick_resume_broadcast(void);
 extern bool tick_resume_check_broadcast(void);
@@ -96,7 +96,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 cpu) { }
+static inline void tick_shutdown_broadcast(void) { }
 static inline void tick_suspend_broadcast(void) { }
 static inline void tick_resume_broadcast(void) { }
 static inline bool tick_resume_check_broadcast(void) { return false; }
#45 lore raw

Re: [PATCH 32/35] clockevents: Fix cpu down race for hrtimer based broadcasting

Quoted 8 lines · Peter Zijlstra

kernel/cpu.c static int __ref _cpu_down(unsigned int · line 431

Quoted 8 lines

From: Thomas Gleixner <[email protected]>

kernel/cpu.c +1 -1
@@ -428,7 +428,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);
+	tick_takeover(cpu);

Why is tick_handover() called after __cpu_die()? And the function tick_takeover() is not introduced until the next patch. tick_broadcast_takeover_bc() is the function used instead in this patch.

Regards
Preeti U Murthy

author maintainer
#46 lore raw

Re: [PATCH 32/35] clockevents: Fix cpu down race for hrtimer based broadcasting

Quoted 4 lines · Preeti U Murthy
Quoted 1 line · Peter Zijlstra
Quoted 1 line

From: Thomas Gleixner <[email protected]>

Quoted 8 lines
Quoted 6 lines

kernel/cpu.c static int __ref _cpu_down(unsigned int · line 431

Quoted 6 lines
kernel/cpu.c +1 -1
@@ -428,7 +428,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);
+	tick_takeover(cpu);

Why is tick_handover() called after __cpu_die()?

See: [PATCH 11/35] clockevents: Cleanup dead cpu explicitely it used to be a CPU_DEAD notifier.

But, I think, the actual reason would be that you cannot be sure its not still ticking until its actually proper dead and buried, so trying to take over a tick from a cpu that's still ticking is... well, suspect.

Quoted 3 lines

And the function tick_takeover()
is not introduced until the next patch. tick_broadcast_takeover_bc() is the function used instead in this patch.

Indeed so; let me correct that for bisection's sake.

#47 lore raw

Re: [PATCH 32/35] clockevents: Fix cpu down race for hrtimer based broadcasting

Quoted 1 line · Peter Zijlstra
Quoted 1 line

[PATCH 11/35] clockevents: Cleanup dead cpu explicitely

Quoted 13 lines · Preeti U Murthy
Quoted 12 lines · Peter Zijlstra
Quoted 9 lines

kernel/cpu.c static int __ref _cpu_down(unsigned int · line 431

Quoted 9 lines

From: Thomas Gleixner <[email protected]>

kernel/cpu.c +1 -1
@@ -428,7 +428,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);
+	tick_takeover(cpu);

Why is tick_handover() called after __cpu_die()?

Quoted 6 lines

See: [PATCH 11/35] clockevents: Cleanup dead cpu explicitely it used to be a CPU_DEAD notifier.

But, I think, the actual reason would be that you cannot be sure its not still ticking until its actually proper dead and buried, so trying to take over a tick from a cpu that's still ticking is... well, suspect.

Look at the changelog, it explains why tick_takeover must be called *before* __cpu_die(). The above hunk is not solving the issue, it is equivalent to the scenario where we took over broadcast duty in the CPU_DEAD phase as a consequence of which the cpu doing the hotplug operation is stuck sleeping forever. Cleanup functions can be handled after __cpu_die() for the reason that you mention above.

Regards
Preeti U Murthy

author maintainer
#48 lore raw

Re: [PATCH 32/35] clockevents: Fix cpu down race for hrtimer based broadcasting

Quoted 2 lines · Preeti U Murthy

Look at the changelog,

Heh, yah, clearly I tl;dr'd that. Indeed.

Quoted 2 lines

it explains why tick_takeover must be called
*before* __cpu_die().

Since you reported this, can you test if things work if you move that function call to before __cpu_die() ?

I _think_ it should be fine, but what do I know ;-)

#49 lore raw

Re: [PATCH 32/35] clockevents: Fix cpu down race for hrtimer based broadcasting

Quoted 11 lines · Peter Zijlstra
Quoted 2 lines · Preeti U Murthy

Look at the changelog,

Heh, yah, clearly I tl;dr'd that. Indeed.

Quoted 2 lines

it explains why tick_takeover must be called
*before* __cpu_die().

Since you reported this, can you test if things work if you move that function call to before __cpu_die() ?

Yes it does. I had tested and posted out a patch to fix the issue here:https://lkml.org/lkml/2015/1/30/821. I see now that tglx proposes to get rid of "taking over" tick duties going forward, rather "handing over" tick duties would be better. So the patch in the above link would not be acceptable. But minus the taking over of the do_timer, the cpu doing the hotplug takes over broadcast duty before __cpu_die() in this patch. This design works.

Regards
Preeti U Murthy

Quoted 3 lines

I _think_ it should be fine, but what do I know ;-)

author maintainer
#50 lore raw

Re: [PATCH 32/35] clockevents: Fix cpu down race for hrtimer based broadcasting

Quoted 13 lines · Preeti U Murthy
Quoted 11 lines · Peter Zijlstra
Quoted 2 lines · Preeti U Murthy

Look at the changelog,

Heh, yah, clearly I tl;dr'd that. Indeed.

Quoted 2 lines

it explains why tick_takeover must be called
*before* __cpu_die().

Since you reported this, can you test if things work if you move that function call to before __cpu_die() ?

Quoted 7 lines

Yes it does. I had tested and posted out a patch to fix the issue here:https://lkml.org/lkml/2015/1/30/821. I see now that tglx proposes to get rid of "taking over" tick duties going forward, rather "handing over" tick duties would be better. So the patch in the above link would not be acceptable. But minus the taking over of the do_timer, the cpu doing the hotplug takes over broadcast duty before __cpu_die() in this patch. This design works.

Great, /me amends patch.

#51 lore raw

Re: [PATCH 32/35] clockevents: Fix cpu down race for hrtimer based broadcasting

In reply to Peter Zijlstra
Quoted 40 lines · Peter Zijlstra

From: Thomas Gleixner <[email protected]>

Preeti reported a cpu down race with hrtimer based broadcasting:

Assume CPU1 is the CPU which holds the hrtimer broadcasting duty before it is taken down.

CPU0 CPU1
cpu_down()
takedown_cpu()
disable_interrupts()
cpu_die()

  while (CPU1 != DEAD) {
    msleep(100);
      switch_to_idle()
        stop_cpu_timer()
          schedule_broadcast()

}

tick_cleanup_dead_cpu()
take_over_broadcast()

So after CPU1 disabled interrupts it cannot handle the broadcast hrtimer anymore, so CPU0 will be stuck forever.

Doing a "while (CPU1 != DEAD) msleep(100);" periodic poll is silly at best, but we need to fix that nevertheless.

Split the tick cleanup into two pieces:

1) Shutdown and remove all per cpu clockevent devices from takedown_cpu()

This is done carefully with respect to existing arch code which works around the shortcoming of the clockevents core code in interesting ways. We really want a separate callback for this to cleanup the workarounds, but that's not scope of this patch

2) Takeover the broadcast duty explicitely before calling cpu_die()

Quoted 8 lines

This is a temporary workaround as well. What we really want is a callback in the clockevent device which allows us to do that from the dying CPU by pushing the hrtimer onto a different cpu. That might involve an IPI and is definitely more complex than this immediate fix.

This breaks the b.L switcher disabling code which essentially does:

static void bL_switcher_restore_cpus(void)

{
        int i;

        for_each_cpu(i, &bL_switcher_removed_logical_cpus) {
                struct device *cpu_dev = get_cpu_device(i);
                int ret = device_online(cpu_dev);
                if (ret)
                        dev_err(cpu_dev, "switcher: unable to restore CPU\n");
        }
}

However, as soon as one new CPU becomes online, the following crash occurs on that CPU:

[  547.858031] ------------[ cut here ]------------
[  547.871868] kernel BUG at kernel/time/hrtimer.c:1249!
[  547.886991] Internal error: Oops - BUG: 0 [#1] SMP THUMB2
[  547.903155] Modules linked in:
[  547.912303] CPU: 2 PID: 0 Comm: swapper/2 Not tainted 3.19.0-rc5-00058-gdd7a65fbc5 #527
[...]
[  548.599060] [<c005a1c2>] (hrtimer_interrupt) from [<c00639db>] (tick_do_broadcast.constprop.8+0x8f/0x90)
[  548.627482] [<c00639db>] (tick_do_broadcast.constprop.8) from [<c0063acd>] (tick_handle_oneshot_broadcast+0xf1/0x168)
[  548.659290] [<c0063acd>] (tick_handle_oneshot_broadcast) from [<c001a07f>] (sp804_timer_interrupt+0x2b/0x30)
[  548.688755] [<c001a07f>] (sp804_timer_interrupt) from [<c004ee9b>] (handle_irq_event_percpu+0x37/0x130)
[  548.716916] [<c004ee9b>] (handle_irq_event_percpu) from [<c004efc7>] (handle_irq_event+0x33/0x48)
[  548.743511] [<c004efc7>] (handle_irq_event) from [<c0050c1d>] (handle_fasteoi_irq+0x69/0xe4)
[  548.768804] [<c0050c1d>] (handle_fasteoi_irq) from [<c004e835>] (generic_handle_irq+0x1d/0x28)
[  548.794619] [<c004e835>] (generic_handle_irq) from [<c004ea17>] (__handle_domain_irq+0x3f/0x80)
[  548.820694] [<c004ea17>] (__handle_domain_irq) from [<c00084f5>] (gic_handle_irq+0x21/0x4c)
[  548.845729] [<c00084f5>] (gic_handle_irq) from [<c04521db>] (__irq_svc+0x3b/0x5c)

The corresponding code is:

void hrtimer_interrupt(struct clock_event_device *dev)

{
        struct hrtimer_cpu_base *cpu_base = this_cpu_ptr(&hrtimer_bases);
        ktime_t expires_next, now, entry_time, delta;
        int i, retries = 0;

        BUG_ON(!cpu_base->hres_active);

[...]

Reverting this patch "fixes" the problem.

Nicolas

author maintainer
#52 lore raw

Re: [PATCH 32/35] clockevents: Fix cpu down race for hrtimer based broadcasting

Quoted 4 lines · Nicolas Pitre

This breaks the b.L switcher disabling code which essentially does:

static void bL_switcher_restore_cpus(void)

Quoted 10 lines
{
        int i;

        for_each_cpu(i, &bL_switcher_removed_logical_cpus) {
                struct device *cpu_dev = get_cpu_device(i);
                int ret = device_online(cpu_dev);
                if (ret)
                        dev_err(cpu_dev, "switcher: unable to restore CPU\n");
        }
}

Just so I understand, this device_{on,ofF}line() stuff is basically just cpu_{up,down}() but obfuscated through the device model nonsense, right?

Also it seems bL_switcher_enable() relies on lock_device_hotplug() to stabilize the online cpu mask; it does not, only the hotplug lock does.

I'm having a very hard time trying to follow wth this thing all is doing; its using hotplug but its also doing magic with cpu_suspend().

/me confused..

#53 lore raw

Re: [PATCH 32/35] clockevents: Fix cpu down race for hrtimer based broadcasting

Quoted 16 lines · Peter Zijlstra
Quoted 4 lines · Nicolas Pitre

This breaks the b.L switcher disabling code which essentially does:

static void bL_switcher_restore_cpus(void)

Quoted 10 lines
{
        int i;

        for_each_cpu(i, &bL_switcher_removed_logical_cpus) {
                struct device *cpu_dev = get_cpu_device(i);
                int ret = device_online(cpu_dev);
                if (ret)
                        dev_err(cpu_dev, "switcher: unable to restore CPU\n");
        }
}
Quoted 2 lines

Just so I understand, this device_{on,ofF}line() stuff is basically just cpu_{up,down}() but obfuscated through the device model nonsense, right?

Right. Before commit 3f8517e793 cpu_{up,down}() were used directly.

Quoted 2 lines

Also it seems bL_switcher_enable() relies on lock_device_hotplug() to stabilize the online cpu mask; it does not, only the hotplug lock does.

This is there to prevent any concurrent hotplug operations via sysfs. Once the switcher is active, we deny hotplugging operations on any physical CPU the switcher has removed.

Quoted 2 lines

I'm having a very hard time trying to follow wth this thing all is doing; its using hotplug but its also doing magic with cpu_suspend().

You're fully aware of the on-going work on the scheduler to better support the big.LITTLE architecture amongst other things. The switcher is an interim solution where one big CPU is paired with one little CPU, and that pair is conceptually used as one logical CPU where only one of the big or little physical CPU runs at a time. Those logical CPUs have identical capacities therefore the current scheduler may works well with them.

The switch between the two physical CPUs is abstracted behind an extended cpufreq scale i.e. when cpufreq asks for a frequency exceeding the little CPU then a transparent switch is made to the big CPU. The transparent switch is performed by suspending the current CPU and immediately resuming the same context on the other CPU, hence the cpu_suspend() usage.

The switcher is runtime activated. To do so, one physical CPU per logical pairing is hotplugged out so the system considers only the "logical" CPUs. When the switcher is disabled, those CPUs are brought back online.

Quoted 1 line

/me confused..

If you want more background info, you may have a look at this article:

http://lwn.net/Articles/481055/

Or just ask away.

Nicolas

author maintainer
#54 lore raw

Re: [PATCH 32/35] clockevents: Fix cpu down race for hrtimer based broadcasting

Quoted 10 lines · Nicolas Pitre
Quoted 2 lines

I'm having a very hard time trying to follow wth this thing all is doing; its using hotplug but its also doing magic with cpu_suspend().

You're fully aware of the on-going work on the scheduler to better support the big.LITTLE architecture amongst other things. The switcher is an interim solution where one big CPU is paired with one little CPU, and that pair is conceptually used as one logical CPU where only one of the big or little physical CPU runs at a time. Those logical CPUs have identical capacities therefore the current scheduler may works well with them.

Yeah, I'm aware of roughly what and why its doing things.

But I was trying to piece together how exactly stuff gets done so I could figure out why that patch broke stuff.

So while it appears to use the regular hotplug code for some of the work, it also has some extra magic on top to affect the actual switcheroo of the cpu.

In any case, having had a second look I think I might have some ideas:

- bL_switcher_enable() -- enables the whole switcher thing and disables half the cpus with hot-un-plug, creates a mapping etc..

- bL_switcher_disable() -- disabled the whole switcher thing and gives us back all our cpus with hot-plug.

When the switcher is enabled; we switch by this magic cpu_suspend() call that saves the entire cpu state and allows you to restore it on another cpu.

You muck about with the tick; you disable it before cpu_suspend() and re-enable it after on the target cpu. You further reprogram the interrupt routing from the old to the new cpu.

But that appears to be it, no more. I suppose the tick is special because its the only per-cpu device?

The reported function that fails: bL_switcher_restore_cpus() is called in the error paths of the former and the main path in the latter to make the 'stolen' cpus re-appear.

The patch in question somehow makes that go boom.

Now what all do you need to do to make it go boom? Just enable/disable the switcher once and it'll explode? Or does it need to do actual switches while it is enabled?

The place where it explodes is a bit surprising, it thinks hrtimers are not enabled even though its calling into hrtimer code on that cpu...

#55 lore raw

Re: [PATCH 32/35] clockevents: Fix cpu down race for hrtimer based broadcasting

Quoted 12 lines · Peter Zijlstra

In any case, having had a second look I think I might have some ideas:

- bL_switcher_enable() -- enables the whole switcher thing and disables half the cpus with hot-un-plug, creates a mapping etc..

- bL_switcher_disable() -- disabled the whole switcher thing and gives us back all our cpus with hot-plug.

When the switcher is enabled; we switch by this magic cpu_suspend() call that saves the entire cpu state and allows you to restore it on another cpu.

Quoted 5 lines

You muck about with the tick; you disable it before cpu_suspend() and re-enable it after on the target cpu. You further reprogram the interrupt routing from the old to the new cpu.

But that appears to be it, no more.

Exact.

Quoted 1 line

I suppose the tick is special because its the only per-cpu device?

Right.

Quoted 10 lines

The reported function that fails: bL_switcher_restore_cpus() is called in the error paths of the former and the main path in the latter to make the 'stolen' cpus re-appear.

The patch in question somehow makes that go boom.

Now what all do you need to do to make it go boom? Just enable/disable the switcher once and it'll explode? Or does it need to do actual switches while it is enabled?

It gets automatically enabled during boot. Then several switches are performed while user space is brought up. If I manually disable it via /sys then it goes boom.

Quoted 6 lines

The place where it explodes is a bit surprising, it thinks hrtimers are not enabled even though its calling into hrtimer code on that cpu...

#56 lore raw

Re: [PATCH 32/35] clockevents: Fix cpu down race for hrtimer based broadcasting

Quoted 9 lines · Nicolas Pitre
Quoted 7 lines · Peter Zijlstra

The reported function that fails: bL_switcher_restore_cpus() is called in the error paths of the former and the main path in the latter to make the 'stolen' cpus re-appear.

The patch in question somehow makes that go boom.

Quoted 7 lines
Quoted 3 lines

Now what all do you need to do to make it go boom? Just enable/disable the switcher once and it'll explode? Or does it need to do actual switches while it is enabled?

It gets automatically enabled during boot. Then several switches are performed while user space is brought up. If I manually disable it via /sys then it goes boom.

OK. Forget the bL switcher. I configured it out of my kernel and then managed to get the same crash by simply hotplugging out one CPU and plugging it back in.

$ echo 0 > /sys/devices/system/cpu/cpu2/online
[CPU2 gone]
$ echo 1 > /sys/devices/system/cpu/cpu2/online
[Boom!]

Nicolas

#57 lore raw

Re: [PATCH 32/35] clockevents: Fix cpu down race for hrtimer based broadcasting

Quoted 19 lines · Nicolas Pitre
Quoted 9 lines · Nicolas Pitre
Quoted 7 lines · Peter Zijlstra

The reported function that fails: bL_switcher_restore_cpus() is called in the error paths of the former and the main path in the latter to make the 'stolen' cpus re-appear.

The patch in question somehow makes that go boom.

Quoted 7 lines
Quoted 3 lines

Now what all do you need to do to make it go boom? Just enable/disable the switcher once and it'll explode? Or does it need to do actual switches while it is enabled?

It gets automatically enabled during boot. Then several switches are performed while user space is brought up. If I manually disable it via /sys then it goes boom.

Quoted 10 lines

OK. Forget the bL switcher. I configured it out of my kernel and then managed to get the same crash by simply hotplugging out one CPU and plugging it back in.

$ echo 0 > /sys/devices/system/cpu/cpu2/online
[CPU2 gone]
$ echo 1 > /sys/devices/system/cpu/cpu2/online
[Boom!]

I saw an issue with this patch as well. I tried to do an smt mode switch on a power machine, i.e varying the number of hyperthreads on an SMT 8 system, and the system hangs. Worse, there are no softlockup messages/warnings/bug_ons reported. I am digging into this issue.

A couple of points though. Looking at the patch, I see that we are shutting down tick device of the hotplugged out cpu *much before* migrating the timers and hrtimers from it. Migration of timers is done in the CPU_DEAD phase, while we shutdown tick devices in the CPU_DYING phase. There is quite a bit of a gap here. Earlier we would do both in a single notification.

Another point is that the tick devices are shutdown before the hotplugged out cpu actually dies in __cpu_die(). At first look none of these two points should create any issues. But since we are noticing problems with this patch, I thought it would be best to put them forth.

But why are tick devices being shutdown that early ? Is there any specific advantage to this? Taking/handing over tick duties should be done before __cpu_die(), but shutdown of tick devices should be done after this phase. This seems more natural, doesn't it?

Regards
Preeti U Murthy

Quoted 2 lines

Nicolas

#58 lore raw

Re: [PATCH 32/35] clockevents: Fix cpu down race for hrtimer based broadcasting

Quoted 47 lines · Preeti U Murthy
Quoted 19 lines · Nicolas Pitre
Quoted 9 lines · Nicolas Pitre
Quoted 7 lines · Peter Zijlstra

The reported function that fails: bL_switcher_restore_cpus() is called in the error paths of the former and the main path in the latter to make the 'stolen' cpus re-appear.

The patch in question somehow makes that go boom.

Quoted 7 lines
Quoted 3 lines

Now what all do you need to do to make it go boom? Just enable/disable the switcher once and it'll explode? Or does it need to do actual switches while it is enabled?

It gets automatically enabled during boot. Then several switches are performed while user space is brought up. If I manually disable it via /sys then it goes boom.

Quoted 10 lines

OK. Forget the bL switcher. I configured it out of my kernel and then managed to get the same crash by simply hotplugging out one CPU and plugging it back in.

$ echo 0 > /sys/devices/system/cpu/cpu2/online
[CPU2 gone]
$ echo 1 > /sys/devices/system/cpu/cpu2/online
[Boom!]

I saw an issue with this patch as well. I tried to do an smt mode switch on a power machine, i.e varying the number of hyperthreads on an SMT 8 system, and the system hangs. Worse, there are no softlockup messages/warnings/bug_ons reported. I am digging into this issue.

A couple of points though. Looking at the patch, I see that we are shutting down tick device of the hotplugged out cpu *much before* migrating the timers and hrtimers from it. Migration of timers is done in the CPU_DEAD phase, while we shutdown tick devices in the CPU_DYING phase. There is quite a bit of a gap here. Earlier we would do both in a single notification.

Another point is that the tick devices are shutdown before the hotplugged out cpu actually dies in __cpu_die(). At first look none of these two points should create any issues. But since we are noticing problems with this patch, I thought it would be best to put them forth.

Quoted 4 lines

But why are tick devices being shutdown that early ? Is there any specific advantage to this? Taking/handing over tick duties should be done before __cpu_die(), but shutdown of tick devices should be done after this phase. This seems more natural, doesn't it?

The problem reported in the changelog of this patch is causing severe regressions very frequently on our machines for certain usecases. It would help to put in a fix in place first and then follow that up with these cleanups. A fix on the below lines :

---------------------------------------------------------------------

clockevents: Fix cpu down race for hrtimer based broadcasting

---
 include/linux/tick.h         |   10 +++++++---
 kernel/cpu.c                 |    2 ++
 kernel/time/tick-broadcast.c |   19 +++++++++++--------
 3 files changed, 20 insertions(+), 11 deletions(-)
include/linux/tick.h +7 -3
index eda850c..8735776 100644
@@ -91,14 +91,18 @@ extern void tick_cancel_sched_timer(int cpu);
 static inline void tick_cancel_sched_timer(int cpu) { }
 # endif
 
-# ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
+# if defined CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
 extern struct tick_device *tick_get_broadcast_device(void);
 extern struct cpumask *tick_get_broadcast_mask(void);
 
-#  ifdef CONFIG_TICK_ONESHOT
+#  if defined CONFIG_TICK_ONESHOT
 extern struct cpumask *tick_get_broadcast_oneshot_mask(void);
+extern void tick_takeover(int deadcpu);
+# else
+static void tick_takeover(int deadcpu) {}
 #  endif
-
+# else
+static void tick_takeover(int deadcpu) {}
 # endif /* BROADCAST */
 
 # ifdef CONFIG_TICK_ONESHOT
kernel/cpu.c +2 -0
index 1972b16..f9ca351 100644
@@ -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"
@@ -411,6 +412,7 @@ static int __ref _cpu_down(unsigned int cpu, int tasks_frozen)
 	while (!idle_cpu(cpu))
 		cpu_relax();
 
+	tick_takeover(cpu);
 	/* This actually kills the CPU. */
 	__cpu_die(cpu);
 
kernel/time/tick-broadcast.c +11 -8
index 066f0ec..0fd6634 100644
@@ -669,14 +669,19 @@ static void broadcast_shutdown_local(struct clock_event_device *bc,
 	clockevents_set_mode(dev, CLOCK_EVT_MODE_SHUTDOWN);
 }
 
-static void broadcast_move_bc(int deadcpu)
+void tick_takeover(int deadcpu)
 {
-	struct clock_event_device *bc = tick_broadcast_device.evtdev;
+	struct clock_event_device *bc;
+	unsigned long flags;
 
-	if (!bc || !broadcast_needs_cpu(bc, deadcpu))
-		return;
-	/* This moves the broadcast assignment to this cpu */
-	clockevents_program_event(bc, bc->next_event, 1);
+	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);
 }
 
 /*
@@ -913,8 +918,6 @@ void tick_shutdown_broadcast_oneshot(unsigned int *cpup)
 	cpumask_clear_cpu(cpu, tick_broadcast_pending_mask);
 	cpumask_clear_cpu(cpu, tick_broadcast_force_mask);
 
-	broadcast_move_bc(cpu);
-
 	raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags);
 }
 

Regards
Preeti U Murthy

Quoted 7 lines

Regards
Preeti U Murthy

Quoted 2 lines

Nicolas

author maintainer
#59 lore raw

Re: [PATCH 32/35] clockevents: Fix cpu down race for hrtimer based broadcasting

Quoted 4 lines · Preeti U Murthy

The problem reported in the changelog of this patch is causing severe regressions very frequently on our machines for certain usecases. It would help to put in a fix in place first and then follow that up with these cleanups. A fix on the below lines :

Regression how? Neither Thomas' Changelog, nor yours mention its a regression.

If its a (recent) Regression you need to have a Fixes tag at the very least. So when was this broken and by which patch?

#60 lore raw

Re: [PATCH 32/35] clockevents: Fix cpu down race for hrtimer based broadcasting

Quoted 6 lines · Peter Zijlstra
Quoted 4 lines · Preeti U Murthy

The problem reported in the changelog of this patch is causing severe regressions very frequently on our machines for certain usecases. It would help to put in a fix in place first and then follow that up with these cleanups. A fix on the below lines :

Quoted 6 lines

Regression how? Neither Thomas' Changelog, nor yours mention its a regression.

If its a (recent) Regression you need to have a Fixes tag at the very least. So when was this broken and by which patch?

It was found recently when doing a hotplug stress test on POWER, that the machine hits lockups spewing

NMI watchdog: BUG: soft lockup - CPU#20 stuck for 23s! [swapper/20:0]

or

INFO: rcu_sched detected stalls on CPUs/tasks: { 2 7 8 9 10 11 12 13 14 15

16 17 18 19 20 21 22 23 2
4 25 26 27 28 29 30 31} (detected by 6, t=2102 jiffies, g=1617, c=1616, q=1441)

and many other messages about lockups.

This issue was reported here:
http://linuxppc.10917.n7.nabble.com/offlining-cpus-breakage-td88619.html
and was traced to
commit 7cba160ad789a powernv/cpuidle: Redesign idle states management, which exposed the loophole in commit 5d1638acb9f6(tick: Introduce hrtimer based broadcast) and is reported in the changelog of the patch.

Regards
Preeti U Murthy

maintainer
#61 lore raw

Re: [PATCH 32/35] clockevents: Fix cpu down race for hrtimer based broadcasting

Quoted 26 lines · Preeti U Murthy
Quoted 6 lines · Peter Zijlstra
Quoted 4 lines · Preeti U Murthy

The problem reported in the changelog of this patch is causing severe regressions very frequently on our machines for certain usecases. It would help to put in a fix in place first and then follow that up with these cleanups. A fix on the below lines :

Quoted 6 lines

Regression how? Neither Thomas' Changelog, nor yours mention its a regression.

If its a (recent) Regression you need to have a Fixes tag at the very least. So when was this broken and by which patch?

It was found recently when doing a hotplug stress test on POWER, that the machine hits lockups spewing

NMI watchdog: BUG: soft lockup - CPU#20 stuck for 23s! [swapper/20:0]

or

INFO: rcu_sched detected stalls on CPUs/tasks: { 2 7 8 9 10 11 12 13 14 15

16 17 18 19 20 21 22 23 2
4 25 26 27 28 29 30 31} (detected by 6, t=2102 jiffies, g=1617, c=1616, q=1441)

Quoted 8 lines

and many other messages about lockups.

This issue was reported here:
http://linuxppc.10917.n7.nabble.com/offlining-cpus-breakage-td88619.html
and was traced to
commit 7cba160ad789a powernv/cpuidle: Redesign idle states management, which exposed the loophole in commit 5d1638acb9f6(tick: Introduce hrtimer based broadcast) and is reported in the changelog of the patch.

Please send the patch with an updated changelog.

Thanks,

Ingo

#62 lore raw

Re: [PATCH 32/35] clockevents: Fix cpu down race for hrtimer based broadcasting

In reply to Peter Zijlstra

Hi Peter, Ingo, Thomas,

Can you please take a look at the conversation on this thread ? This fix is urgent.

Regards
Preeti U Murthy

Quoted 12 lines · Peter Zijlstra
Quoted 4 lines · Preeti U Murthy

The problem reported in the changelog of this patch is causing severe regressions very frequently on our machines for certain usecases. It would help to put in a fix in place first and then follow that up with these cleanups. A fix on the below lines :

Regression how? Neither Thomas' Changelog, nor yours mention its a regression.

If its a (recent) Regression you need to have a Fixes tag at the very least. So when was this broken and by which patch?

#63 lore raw

Re: [PATCH 32/35] clockevents: Fix cpu down race for hrtimer based broadcasting

Ping.

Quoted 21 lines · Preeti U Murthy

Hi Peter, Ingo, Thomas,

Can you please take a look at the conversation on this thread ? This fix is urgent.

Regards
Preeti U Murthy

Quoted 12 lines · Peter Zijlstra
Quoted 4 lines · Preeti U Murthy

The problem reported in the changelog of this patch is causing severe regressions very frequently on our machines for certain usecases. It would help to put in a fix in place first and then follow that up with these cleanups. A fix on the below lines :

Regression how? Neither Thomas' Changelog, nor yours mention its a regression.

If its a (recent) Regression you need to have a Fixes tag at the very least. So when was this broken and by which patch?

author maintainer
#64 lore raw

PATCH 33/35 tick: Make hrtimer broadcasting opt-in

In reply to Peter Zijlstra

From: Thomas Gleixner <[email protected]>

We keep adding unconditional stuff to the core code which just bloats the text and data size for no value. hrtimer based broadcasting is currently only used on arm64 and powerpc. Make it conditional.

While at it move these tick related interfaces out of the clockchips header file.

Cc Preeti U Murthy <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Benjamin Herrenschmidt <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
---
 arch/arm/kernel/smp.c        |    2 +-
 arch/arm64/Kconfig           |    1 +
 arch/arm64/kernel/smp.c      |    1 +
 arch/arm64/kernel/time.c     |    2 +-
 arch/mips/kernel/smp.c       |    1 +
 arch/powerpc/Kconfig         |    1 +
 arch/powerpc/kernel/smp.c    |    1 +
 arch/powerpc/kernel/time.c   |    2 +-
 include/linux/clockchips.h   |   26 +-------------------------
 include/linux/tick.h         |   25 +++++++++++++++++++++++--
 kernel/time/Kconfig          |    4 ++++
 kernel/time/Makefile         |    6 ++----
 kernel/time/tick-broadcast.c |    4 +++-
 13 files changed, 41 insertions(+), 35 deletions(-)
arch/arm/kernel/smp.c +1 -1
Index: linux/arch/arm/kernel/smp.c
===================================================================
@@ -22,7 +22,7 @@
 #include <linux/seq_file.h>
 #include <linux/irq.h>
 #include <linux/percpu.h>
-#include <linux/clockchips.h>
+#include <linux/tick.h>
 #include <linux/completion.h>
 #include <linux/cpufreq.h>
 #include <linux/irq_work.h>
arch/arm64/Kconfig +1 -0
Index: linux/arch/arm64/Kconfig
===================================================================
@@ -25,6 +25,7 @@ config ARM64
 	select GENERIC_ALLOCATOR
 	select GENERIC_CLOCKEVENTS
 	select GENERIC_CLOCKEVENTS_BROADCAST if SMP
+	select GENERIC_CLOCKEVENTS_HRTIMER_BROADCAST if SMP
 	select GENERIC_CPU_AUTOPROBE
 	select GENERIC_EARLY_IOREMAP
 	select GENERIC_IRQ_PROBE
arch/arm64/kernel/smp.c +1 -0
Index: linux/arch/arm64/kernel/smp.c
===================================================================
@@ -36,6 +36,7 @@
 #include <linux/completion.h>
 #include <linux/of.h>
 #include <linux/irq_work.h>
+#include <linux/tick.h>
 
 #include <asm/alternative.h>
 #include <asm/atomic.h>
arch/arm64/kernel/time.c +1 -1
Index: linux/arch/arm64/kernel/time.c
===================================================================
@@ -18,11 +18,11 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <linux/clockchips.h>
 #include <linux/export.h>
 #include <linux/kernel.h>
 #include <linux/interrupt.h>
 #include <linux/time.h>
+#include <linux/tick.h>
 #include <linux/init.h>
 #include <linux/sched.h>
 #include <linux/smp.h>
arch/mips/kernel/smp.c +1 -0
Index: linux/arch/mips/kernel/smp.c
===================================================================
@@ -33,6 +33,7 @@
 #include <linux/cpu.h>
 #include <linux/err.h>
 #include <linux/ftrace.h>
+#include <linux/tick.h>
 
 #include <linux/atomic.h>
 #include <asm/cpu.h>
arch/powerpc/Kconfig +1 -0
Index: linux/arch/powerpc/Kconfig
===================================================================
@@ -135,6 +135,7 @@ config PPC
 	select GENERIC_TIME_VSYSCALL_OLD
 	select GENERIC_CLOCKEVENTS
 	select GENERIC_CLOCKEVENTS_BROADCAST if SMP
+	select GENERIC_CLOCKEVENTS_HRTIMER_BROADCAST if SMP
 	select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
 	select GENERIC_STRNCPY_FROM_USER
 	select GENERIC_STRNLEN_USER
arch/powerpc/kernel/smp.c +1 -0
Index: linux/arch/powerpc/kernel/smp.c
===================================================================
@@ -31,6 +31,7 @@
 #include <linux/cpu.h>
 #include <linux/notifier.h>
 #include <linux/topology.h>
+#include <linux/tick.h>
 
 #include <asm/ptrace.h>
 #include <linux/atomic.h>
arch/powerpc/kernel/time.c +1 -1
Index: linux/arch/powerpc/kernel/time.c
===================================================================
@@ -42,7 +42,7 @@
 #include <linux/timex.h>
 #include <linux/kernel_stat.h>
 #include <linux/time.h>
-#include <linux/clockchips.h>
+#include <linux/tick.h>
 #include <linux/init.h>
 #include <linux/profile.h>
 #include <linux/cpu.h>
include/linux/clockchips.h +1 -25
Index: linux/include/linux/clockchips.h
===================================================================
@@ -155,29 +155,5 @@ extern void clockevents_set_mode(struct
 				 enum clock_event_mode mode);
 extern int clockevents_program_event(struct clock_event_device *dev,
 				     ktime_t expires, bool force);
-
-#ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
-#ifdef CONFIG_ARCH_HAS_TICK_BROADCAST
-extern void tick_broadcast(const struct cpumask *mask);
-#else
-#define tick_broadcast	NULL
-#endif
-extern int tick_receive_broadcast(void);
-#endif
-
-#if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
-extern void tick_setup_hrtimer_broadcast(void);
-extern int tick_check_broadcast_expired(void);
-#else
-static inline int tick_check_broadcast_expired(void) { return 0; }
-static inline void tick_setup_hrtimer_broadcast(void) {};
-#endif
-
-#else /* CONFIG_GENERIC_CLOCKEVENTS */
-
-static inline int tick_check_broadcast_expired(void) { return 0; }
-static inline void tick_setup_hrtimer_broadcast(void) {};
-
-#endif
-
+#endif /* CONFIG_GENERIC_CLOCKEVENTS */
 #endif
include/linux/tick.h +23 -2
Index: linux/include/linux/tick.h
===================================================================
@@ -65,10 +65,8 @@ static inline void tick_broadcast_contro
 
 #if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
 extern int tick_broadcast_oneshot_control(enum tick_broadcast_state state);
-extern void tick_takeover(int deadcpu);
 #else
 static inline int tick_broadcast_oneshot_control(enum tick_broadcast_state state) { return 0; }
-static inline void tick_takeover(int deadcpu) { }
 #endif
 
 static inline void tick_broadcast_enable(void)
@@ -181,4 +179,27 @@ static inline void tick_nohz_task_switch
 		__tick_nohz_task_switch(tsk);
 }
 
+#ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
+#ifdef CONFIG_ARCH_HAS_TICK_BROADCAST
+extern void tick_broadcast(const struct cpumask *mask);
+#else
+#define tick_broadcast	NULL
+#endif
+extern int tick_receive_broadcast(void);
+#endif
+
+#if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
+extern int tick_check_broadcast_expired(void);
+#else
+static inline int tick_check_broadcast_expired(void) { return 0; }
+#endif
+
+#ifdef CONFIG_GENERIC_CLOCKEVENTS_HRTIMER_BROADCAST
+extern void tick_setup_hrtimer_broadcast(void);
+extern void tick_takeover(int deadcpu);
+#else
+static inline void tick_setup_hrtimer_broadcast(void) { };
+static inline void tick_takeover(int deadcpu) { }
+#endif
+
 #endif
kernel/time/Kconfig +4 -0
Index: linux/kernel/time/Kconfig
===================================================================
@@ -42,6 +42,10 @@ config GENERIC_CLOCKEVENTS_BROADCAST
 	bool
 	depends on GENERIC_CLOCKEVENTS
 
+config GENERIC_CLOCKEVENTS_HRTIMER_BROADCAST
+	bool
+	depends on GENERIC_CLOCKEVENTS && TICK_ONESHOT
+
 # Automatically adjust the min. reprogramming time for
 # clock event device
 config GENERIC_CLOCKEVENTS_MIN_ADJUST
kernel/time/Makefile +2 -4
Index: linux/kernel/time/Makefile
===================================================================
@@ -3,10 +3,8 @@ obj-y += timekeeping.o ntp.o clocksource
 obj-y += timeconv.o posix-clock.o alarmtimer.o
 
 obj-$(CONFIG_GENERIC_CLOCKEVENTS)		+= clockevents.o tick-common.o
-ifeq ($(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST),y)
- obj-y						+= tick-broadcast.o
- obj-$(CONFIG_TICK_ONESHOT)			+= tick-broadcast-hrtimer.o
-endif
+obj-$(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST)	+= tick-broadcast.o
+obj-$(CONFIG_GENERIC_CLOCKEVENTS_HRTIMER_BROADCAST)	+= tick-broadcast-hrtimer.o
 obj-$(CONFIG_GENERIC_SCHED_CLOCK)		+= sched_clock.o
 obj-$(CONFIG_TICK_ONESHOT)			+= tick-oneshot.o tick-sched.o
 obj-$(CONFIG_TIMER_STATS)			+= timer_stats.o
kernel/time/tick-broadcast.c +3 -1
Index: linux/kernel/time/tick-broadcast.c
===================================================================
@@ -908,6 +908,7 @@ void tick_broadcast_switch_to_oneshot(vo
 }
 
 #ifdef CONFIG_HOTPLUG_CPU
+#ifdef CONFIG_GENERIC_CLOCKEVENTS_HRTIMER_BROADCAST
 /*
  * Called from the cpu hotplug code after a cpu is dead. This ensures
  * that a hrtimer based broad cast device is taken over.
@@ -916,7 +917,7 @@ void tick_broadcast_switch_to_oneshot(vo
  * which pushes the hrtimer over to a different cpu from
  * tick_shutdown_broadcast_oneshot()
  */
-void tick_broadcast_takeover_bc(int deadcpu)
+void tick_takeover(int deadcpu)
 {
 	struct clock_event_device *bc;
 	unsigned long flags;
@@ -929,6 +930,7 @@ void tick_broadcast_takeover_bc(int dead
 	}
 	raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags);
 }
+#endif
 
 /*
  * Remove a dead CPU from broadcasting, called with broadcast lock
Reviewed-by on v1 33/35
#66 lore raw

Re: [PATCH 33/35] tick: Make hrtimer broadcasting opt-in

In reply to Peter Zijlstra
Quoted 6 lines · Peter Zijlstra

From: Thomas Gleixner <[email protected]>

We keep adding unconditional stuff to the core code which just bloats the text and data size for no value. hrtimer based broadcasting is currently only used on arm64 and powerpc. Make it conditional.

Quoted 8 lines

While at it move these tick related interfaces out of the clockchips header file.

Cc Preeti U Murthy <[email protected]>
Cc Michael Ellerman <[email protected]>
Cc Benjamin Herrenschmidt <[email protected]>
Cc Lorenzo Pieralisi <[email protected]>
Quoted 261 lines
---
 arch/arm/kernel/smp.c        |    2 +-
 arch/arm64/Kconfig           |    1 +
 arch/arm64/kernel/smp.c      |    1 +
 arch/arm64/kernel/time.c     |    2 +-
 arch/mips/kernel/smp.c       |    1 +
 arch/powerpc/Kconfig         |    1 +
 arch/powerpc/kernel/smp.c    |    1 +
 arch/powerpc/kernel/time.c   |    2 +-
 include/linux/clockchips.h   |   26 +-------------------------
 include/linux/tick.h         |   25 +++++++++++++++++++++++--
 kernel/time/Kconfig          |    4 ++++
 kernel/time/Makefile         |    6 ++----
 kernel/time/tick-broadcast.c |    4 +++-
 13 files changed, 41 insertions(+), 35 deletions(-)

Index: linux/arch/arm/kernel/smp.c
===================================================================

arch/arm/kernel/smp.c +1 -1
@@ -22,7 +22,7 @@
 #include <linux/seq_file.h>
 #include <linux/irq.h>
 #include <linux/percpu.h>
-#include <linux/clockchips.h>
+#include <linux/tick.h>
 #include <linux/completion.h>
 #include <linux/cpufreq.h>
 #include <linux/irq_work.h>

Index: linux/arch/arm64/Kconfig
===================================================================

arch/arm64/Kconfig +1 -0
@@ -25,6 +25,7 @@ config ARM64
 	select GENERIC_ALLOCATOR
 	select GENERIC_CLOCKEVENTS
 	select GENERIC_CLOCKEVENTS_BROADCAST if SMP
+	select GENERIC_CLOCKEVENTS_HRTIMER_BROADCAST if SMP
 	select GENERIC_CPU_AUTOPROBE
 	select GENERIC_EARLY_IOREMAP
 	select GENERIC_IRQ_PROBE

Index: linux/arch/arm64/kernel/smp.c
===================================================================

arch/arm64/kernel/smp.c +1 -0
@@ -36,6 +36,7 @@
 #include <linux/completion.h>
 #include <linux/of.h>
 #include <linux/irq_work.h>
+#include <linux/tick.h>
 
 #include <asm/alternative.h>
 #include <asm/atomic.h>

Index: linux/arch/arm64/kernel/time.c
===================================================================

arch/arm64/kernel/time.c +1 -1
@@ -18,11 +18,11 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include <linux/clockchips.h>
 #include <linux/export.h>
 #include <linux/kernel.h>
 #include <linux/interrupt.h>
 #include <linux/time.h>
+#include <linux/tick.h>
 #include <linux/init.h>
 #include <linux/sched.h>
 #include <linux/smp.h>

Index: linux/arch/mips/kernel/smp.c
===================================================================

arch/mips/kernel/smp.c +1 -0
@@ -33,6 +33,7 @@
 #include <linux/cpu.h>
 #include <linux/err.h>
 #include <linux/ftrace.h>
+#include <linux/tick.h>
 
 #include <linux/atomic.h>
 #include <asm/cpu.h>

Index: linux/arch/powerpc/Kconfig
===================================================================

arch/powerpc/Kconfig +1 -0
@@ -135,6 +135,7 @@ config PPC
 	select GENERIC_TIME_VSYSCALL_OLD
 	select GENERIC_CLOCKEVENTS
 	select GENERIC_CLOCKEVENTS_BROADCAST if SMP
+	select GENERIC_CLOCKEVENTS_HRTIMER_BROADCAST if SMP
 	select ARCH_HAS_TICK_BROADCAST if GENERIC_CLOCKEVENTS_BROADCAST
 	select GENERIC_STRNCPY_FROM_USER
 	select GENERIC_STRNLEN_USER

Index: linux/arch/powerpc/kernel/smp.c
===================================================================

arch/powerpc/kernel/smp.c +1 -0
@@ -31,6 +31,7 @@
 #include <linux/cpu.h>
 #include <linux/notifier.h>
 #include <linux/topology.h>
+#include <linux/tick.h>
 
 #include <asm/ptrace.h>
 #include <linux/atomic.h>

Index: linux/arch/powerpc/kernel/time.c
===================================================================

arch/powerpc/kernel/time.c +1 -1
@@ -42,7 +42,7 @@
 #include <linux/timex.h>
 #include <linux/kernel_stat.h>
 #include <linux/time.h>
-#include <linux/clockchips.h>
+#include <linux/tick.h>
 #include <linux/init.h>
 #include <linux/profile.h>
 #include <linux/cpu.h>

Index: linux/include/linux/clockchips.h
===================================================================

include/linux/clockchips.h +1 -25
@@ -155,29 +155,5 @@ extern void clockevents_set_mode(struct
 				 enum clock_event_mode mode);
 extern int clockevents_program_event(struct clock_event_device *dev,
 				     ktime_t expires, bool force);
-
-#ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
-#ifdef CONFIG_ARCH_HAS_TICK_BROADCAST
-extern void tick_broadcast(const struct cpumask *mask);
-#else
-#define tick_broadcast	NULL
-#endif
-extern int tick_receive_broadcast(void);
-#endif
-
-#if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
-extern void tick_setup_hrtimer_broadcast(void);
-extern int tick_check_broadcast_expired(void);
-#else
-static inline int tick_check_broadcast_expired(void) { return 0; }
-static inline void tick_setup_hrtimer_broadcast(void) {};
-#endif
-
-#else /* CONFIG_GENERIC_CLOCKEVENTS */
-
-static inline int tick_check_broadcast_expired(void) { return 0; }
-static inline void tick_setup_hrtimer_broadcast(void) {};
-
-#endif
-
+#endif /* CONFIG_GENERIC_CLOCKEVENTS */
 #endif

Index: linux/include/linux/tick.h
===================================================================

include/linux/tick.h +23 -2
@@ -65,10 +65,8 @@ static inline void tick_broadcast_contro
 
 #if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
 extern int tick_broadcast_oneshot_control(enum tick_broadcast_state state);
-extern void tick_takeover(int deadcpu);
 #else
 static inline int tick_broadcast_oneshot_control(enum tick_broadcast_state state) { return 0; }
-static inline void tick_takeover(int deadcpu) { }
 #endif
 
 static inline void tick_broadcast_enable(void)
@@ -181,4 +179,27 @@ static inline void tick_nohz_task_switch
 		__tick_nohz_task_switch(tsk);
 }
 
+#ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
+#ifdef CONFIG_ARCH_HAS_TICK_BROADCAST
+extern void tick_broadcast(const struct cpumask *mask);
+#else
+#define tick_broadcast	NULL
+#endif
+extern int tick_receive_broadcast(void);
+#endif
+
+#if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
+extern int tick_check_broadcast_expired(void);
+#else
+static inline int tick_check_broadcast_expired(void) { return 0; }
+#endif
+
+#ifdef CONFIG_GENERIC_CLOCKEVENTS_HRTIMER_BROADCAST
+extern void tick_setup_hrtimer_broadcast(void);
+extern void tick_takeover(int deadcpu);
+#else
+static inline void tick_setup_hrtimer_broadcast(void) { };
+static inline void tick_takeover(int deadcpu) { }
+#endif
+
 #endif

Index: linux/kernel/time/Kconfig
===================================================================

kernel/time/Kconfig +4 -0
@@ -42,6 +42,10 @@ config GENERIC_CLOCKEVENTS_BROADCAST
 	bool
 	depends on GENERIC_CLOCKEVENTS
 
+config GENERIC_CLOCKEVENTS_HRTIMER_BROADCAST
+	bool
+	depends on GENERIC_CLOCKEVENTS && TICK_ONESHOT
+
 # Automatically adjust the min. reprogramming time for
 # clock event device
 config GENERIC_CLOCKEVENTS_MIN_ADJUST

Index: linux/kernel/time/Makefile
===================================================================

kernel/time/Makefile +2 -4
@@ -3,10 +3,8 @@ obj-y += timekeeping.o ntp.o clocksource
 obj-y += timeconv.o posix-clock.o alarmtimer.o
 
 obj-$(CONFIG_GENERIC_CLOCKEVENTS)		+= clockevents.o tick-common.o
-ifeq ($(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST),y)
- obj-y						+= tick-broadcast.o
- obj-$(CONFIG_TICK_ONESHOT)			+= tick-broadcast-hrtimer.o
-endif
+obj-$(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST)	+= tick-broadcast.o
+obj-$(CONFIG_GENERIC_CLOCKEVENTS_HRTIMER_BROADCAST)	+= tick-broadcast-hrtimer.o
 obj-$(CONFIG_GENERIC_SCHED_CLOCK)		+= sched_clock.o
 obj-$(CONFIG_TICK_ONESHOT)			+= tick-oneshot.o tick-sched.o
 obj-$(CONFIG_TIMER_STATS)			+= timer_stats.o

Index: linux/kernel/time/tick-broadcast.c
===================================================================

kernel/time/tick-broadcast.c +3 -1
@@ -908,6 +908,7 @@ void tick_broadcast_switch_to_oneshot(vo
 }
 
 #ifdef CONFIG_HOTPLUG_CPU
+#ifdef CONFIG_GENERIC_CLOCKEVENTS_HRTIMER_BROADCAST
 /*
  * Called from the cpu hotplug code after a cpu is dead. This ensures
  * that a hrtimer based broad cast device is taken over.
@@ -916,7 +917,7 @@ void tick_broadcast_switch_to_oneshot(vo
  * which pushes the hrtimer over to a different cpu from
  * tick_shutdown_broadcast_oneshot()
  */
-void tick_broadcast_takeover_bc(int deadcpu)
+void tick_takeover(int deadcpu)
 {
 	struct clock_event_device *bc;
 	unsigned long flags;
@@ -929,6 +930,7 @@ void tick_broadcast_takeover_bc(int dead
 	}
 	raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags);
 }
+#endif
 
 /*
  * Remove a dead CPU from broadcasting, called with broadcast lock
author maintainer
#67 lore raw

PATCH 34/35 tick: Provide tick_suspend_local()

In reply to Peter Zijlstra

From: Thomas Gleixner <[email protected]>

This function is intended to use by the freezer once the freezer folks solved their race issues. Also required to get rid of the ARM BL switcher tick hackery.

Cc Nicolas Pitre <[email protected]>
Cc Russell King <[email protected]>
---
 include/linux/tick.h      |    3 +++
 kernel/time/tick-common.c |   18 +++++++++++++++---
 2 files changed, 18 insertions(+), 3 deletions(-)
include/linux/tick.h +3 -0
Index: linux/include/linux/tick.h
===================================================================
@@ -27,12 +27,15 @@ extern struct tick_device *tick_get_devi
 
 #ifdef CONFIG_GENERIC_CLOCKEVENTS
 extern void __init tick_init(void);
+/* Should be core only, but arm BL switcher has its homebrewn implementation */
+extern void tick_suspend_local(void);
 /* Should be core only, but XEN resume magic requires this */
 extern void tick_resume_local(void);
 /* CPU hotplug */
 extern void tick_shutdown_local(void);
 #else /* CONFIG_GENERIC_CLOCKEVENTS */
 static inline void tick_init(void) { }
+static inline void tick_suspend_local(void) { }
 static inline void tick_resume_local(void) { }
 static inline void tick_shutdown_local(void) { }
 #endif /* !CONFIG_GENERIC_CLOCKEVENTS */
kernel/time/tick-common.c +15 -3
Index: linux/kernel/time/tick-common.c
===================================================================
@@ -370,6 +370,20 @@ void tick_shutdown_local(void)
 
 #ifdef CONFIG_PM_SLEEP
 /**
+ * tick_suspend_local - Suspend the local tick device
+ *
+ * Called from the local cpu for freeze with interrupts disabled.
+ *
+ * No locks required. Nothing can change the per cpu device.
+ */
+void tick_suspend_local(void)
+{
+	struct tick_device *td = this_cpu_ptr(&tick_cpu_device);
+
+	clockevents_shutdown(td->evtdev);
+}
+
+/**
  * tick_suspend - Suspend the tick and the broadcast device
  *
  * Called from syscore_suspend() via timekeeping_suspend with only one
@@ -379,9 +393,7 @@ void tick_shutdown_local(void)
  */
 void tick_suspend(void)
 {
-	struct tick_device *td = this_cpu_ptr(&tick_cpu_device);
-
-	clockevents_shutdown(td->evtdev);
+	tick_suspend_local();
 	tick_suspend_broadcast();
 }
 
#68 lore raw

Re: [PATCH 34/35] tick: Provide tick_suspend_local()

Quoted 5 lines · Peter Zijlstra

From: Thomas Gleixner <[email protected]>

This function is intended to use by the freezer once the freezer folks solved their race issues. Also required to get rid of the ARM BL switcher tick hackery.

Totally agree with the patch(es), but I noticed that the ARM bL switcher does not depend on PM_SLEEP, so I do not think you can compile tick_{suspend/resume}_local() out if !PM_SLEEP, unless dependency is enforced by the ARM bL switcher config but I do not think that the config dependency really exists, Nico please correct me if I am wrong.

Lorenzo

Quoted 74 lines
Cc Nicolas Pitre <[email protected]>
Cc Russell King <[email protected]>
---
 include/linux/tick.h      |    3 +++
 kernel/time/tick-common.c |   18 +++++++++++++++---
 2 files changed, 18 insertions(+), 3 deletions(-)

Index: linux/include/linux/tick.h
===================================================================

include/linux/tick.h +3 -0
@@ -27,12 +27,15 @@ extern struct tick_device *tick_get_devi
 
 #ifdef CONFIG_GENERIC_CLOCKEVENTS
 extern void __init tick_init(void);
+/* Should be core only, but arm BL switcher has its homebrewn implementation */
+extern void tick_suspend_local(void);
 /* Should be core only, but XEN resume magic requires this */
 extern void tick_resume_local(void);
 /* CPU hotplug */
 extern void tick_shutdown_local(void);
 #else /* CONFIG_GENERIC_CLOCKEVENTS */
 static inline void tick_init(void) { }
+static inline void tick_suspend_local(void) { }
 static inline void tick_resume_local(void) { }
 static inline void tick_shutdown_local(void) { }
 #endif /* !CONFIG_GENERIC_CLOCKEVENTS */

Index: linux/kernel/time/tick-common.c
===================================================================

kernel/time/tick-common.c +15 -4
@@ -370,6 +370,20 @@ void tick_shutdown_local(void)
 
 #ifdef CONFIG_PM_SLEEP
 /**
+ * tick_suspend_local - Suspend the local tick device
+ *
+ * Called from the local cpu for freeze with interrupts disabled.
+ *
+ * No locks required. Nothing can change the per cpu device.
+ */
+void tick_suspend_local(void)
+{
+	struct tick_device *td = this_cpu_ptr(&tick_cpu_device);
+
+	clockevents_shutdown(td->evtdev);
+}
+
+/**
  * tick_suspend - Suspend the tick and the broadcast device
  *
  * Called from syscore_suspend() via timekeeping_suspend with only one
@@ -379,9 +393,7 @@ void tick_shutdown_local(void)
  */
 void tick_suspend(void)
 {
-	struct tick_device *td = this_cpu_ptr(&tick_cpu_device);
-
-	clockevents_shutdown(td->evtdev);
+	tick_suspend_local();
 	tick_suspend_broadcast();
 }
 
 
 
--

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/

#69 lore raw

Re: [PATCH 34/35] tick: Provide tick_suspend_local()

Quoted 7 lines · Lorenzo Pieralisi
Quoted 5 lines · Peter Zijlstra

From: Thomas Gleixner <[email protected]>

This function is intended to use by the freezer once the freezer folks solved their race issues. Also required to get rid of the ARM BL switcher tick hackery.

Quoted 6 lines

Totally agree with the patch(es), but I noticed that the ARM bL switcher does not depend on PM_SLEEP, so I do not think you can compile tick_{suspend/resume}_local() out if !PM_SLEEP, unless dependency is enforced by the ARM bL switcher config but I do not think that the config dependency really exists, Nico please correct me if I am wrong.

The ARM bL switcher does not depend on PM_SUSPEND nor does it enforce it because it currently doesn't need it. So yeah, either PM_SUSPEND is selected bringing quite a lot of code with it, or another symbol is used for those functions (CONFIG_HOTPLUG_CPU maybe?).

Nicolas

#70 lore raw

Re: [PATCH 34/35] tick: Provide tick_suspend_local()

Quoted 16 lines · Nicolas Pitre
Quoted 7 lines · Lorenzo Pieralisi
Quoted 5 lines · Peter Zijlstra

From: Thomas Gleixner <[email protected]>

This function is intended to use by the freezer once the freezer folks solved their race issues. Also required to get rid of the ARM BL switcher tick hackery.

Quoted 6 lines

Totally agree with the patch(es), but I noticed that the ARM bL switcher does not depend on PM_SLEEP, so I do not think you can compile tick_{suspend/resume}_local() out if !PM_SLEEP, unless dependency is enforced by the ARM bL switcher config but I do not think that the config dependency really exists, Nico please correct me if I am wrong.

Quoted 4 lines

The ARM bL switcher does not depend on PM_SUSPEND nor does it enforce it because it currently doesn't need it. So yeah, either PM_SUSPEND is selected bringing quite a lot of code with it, or another symbol is used for those functions (CONFIG_HOTPLUG_CPU maybe?).

Note the same problem exists with arch/x86/xen/suspend.c that calls tick_resume_local() yet this file is not subject to a dependency on CONFIG_PM_SUSPEND.

Nicolas

author maintainer
#71 lore raw

Re: [PATCH 34/35] tick: Provide tick_suspend_local()

In reply to Lorenzo Pieralisi
Quoted 7 lines · Lorenzo Pieralisi
Quoted 5 lines · Peter Zijlstra

From: Thomas Gleixner <[email protected]>

This function is intended to use by the freezer once the freezer folks solved their race issues. Also required to get rid of the ARM BL switcher tick hackery.

Quoted 6 lines

Totally agree with the patch(es), but I noticed that the ARM bL switcher does not depend on PM_SLEEP, so I do not think you can compile tick_{suspend/resume}_local() out if !PM_SLEEP, unless dependency is enforced by the ARM bL switcher config but I do not think that the config dependency really exists, Nico please correct me if I am wrong.

Ah I see, the headers seem to do the right thing and declare the function in core (GENERIC_CLOCKEVENTS) with a comment.

But then the patch continues defining the functions under PM_SLEEP.

I wonder why the build robot has not reported fail on this..

Would the below make sense?

---

kernel/time/tick-common.c +15 -15
@@ -368,7 +368,6 @@ void tick_shutdown_local(void)
 }
 #endif
 
-#ifdef CONFIG_PM_SLEEP
 /**
  * tick_suspend_local - Suspend the local tick device
  *
@@ -384,20 +383,6 @@ void tick_suspend_local(void)
 }
 
 /**
- * tick_suspend - Suspend the tick and the broadcast device
- *
- * Called from syscore_suspend() via timekeeping_suspend with only one
- * CPU online and interrupts disabled.
- *
- * No locks required. Nothing can change the per cpu device.
- */
-void tick_suspend(void)
-{
-	tick_suspend_local();
-	tick_suspend_broadcast();
-}
-
-/**
  * tick_resume_local - Resume the local tick device
  *
  * Called from the local cpu for unfreeze or XEN resume magic
@@ -418,6 +403,21 @@ void tick_resume_local(void)
 	}
 }
 
+#ifdef CONFIG_PM_SLEEP
+/**
+ * tick_suspend - Suspend the tick and the broadcast device
+ *
+ * Called from syscore_suspend() via timekeeping_suspend with only one
+ * CPU online and interrupts disabled.
+ *
+ * No locks required. Nothing can change the per cpu device.
+ */
+void tick_suspend(void)
+{
+	tick_suspend_local();
+	tick_suspend_broadcast();
+}
+
 /**
  * tick_resume - Resume the tick and the broadcast device
  *
#72 lore raw

Re: [PATCH 34/35] tick: Provide tick_suspend_local()

Quoted 15 lines · Peter Zijlstra
Quoted 7 lines · Lorenzo Pieralisi
Quoted 5 lines · Peter Zijlstra

From: Thomas Gleixner <[email protected]>

This function is intended to use by the freezer once the freezer folks solved their race issues. Also required to get rid of the ARM BL switcher tick hackery.

Quoted 6 lines

Totally agree with the patch(es), but I noticed that the ARM bL switcher does not depend on PM_SLEEP, so I do not think you can compile tick_{suspend/resume}_local() out if !PM_SLEEP, unless dependency is enforced by the ARM bL switcher config but I do not think that the config dependency really exists, Nico please correct me if I am wrong.

Quoted 8 lines

Ah I see, the headers seem to do the right thing and declare the function in core (GENERIC_CLOCKEVENTS) with a comment.

But then the patch continues defining the functions under PM_SLEEP.

I wonder why the build robot has not reported fail on this..

Would the below make sense?

That needs to be done on top of the suspend-to-idle material that has just been merged.

Why don't you drop the PM_SLEEP-related changes from the series for the time being and let's clean things up top of it? That should be more straightforward I think.

Rafael

#73 lore raw

Re: [PATCH 34/35] tick: Provide tick_suspend_local()

In reply to Peter Zijlstra
Quoted 15 lines · Peter Zijlstra
Quoted 7 lines · Lorenzo Pieralisi
Quoted 5 lines · Peter Zijlstra

From: Thomas Gleixner <[email protected]>

This function is intended to use by the freezer once the freezer folks solved their race issues. Also required to get rid of the ARM BL switcher tick hackery.

Quoted 6 lines

Totally agree with the patch(es), but I noticed that the ARM bL switcher does not depend on PM_SLEEP, so I do not think you can compile tick_{suspend/resume}_local() out if !PM_SLEEP, unless dependency is enforced by the ARM bL switcher config but I do not think that the config dependency really exists, Nico please correct me if I am wrong.

Quoted 8 lines

Ah I see, the headers seem to do the right thing and declare the function in core (GENERIC_CLOCKEVENTS) with a comment.

But then the patch continues defining the functions under PM_SLEEP.

I wonder why the build robot has not reported fail on this..

Would the below make sense?

Yes, but please see Rafael's remark, whatever makes it easier for you.

Thanks,
Lorenzo

Quoted 56 lines

---

kernel/time/tick-common.c +15 -15
@@ -368,7 +368,6 @@ void tick_shutdown_local(void)
 }
 #endif
 
-#ifdef CONFIG_PM_SLEEP
 /**
  * tick_suspend_local - Suspend the local tick device
  *
@@ -384,20 +383,6 @@ void tick_suspend_local(void)
 }
 
 /**
- * tick_suspend - Suspend the tick and the broadcast device
- *
- * Called from syscore_suspend() via timekeeping_suspend with only one
- * CPU online and interrupts disabled.
- *
- * No locks required. Nothing can change the per cpu device.
- */
-void tick_suspend(void)
-{
-	tick_suspend_local();
-	tick_suspend_broadcast();
-}
-
-/**
  * tick_resume_local - Resume the local tick device
  *
  * Called from the local cpu for unfreeze or XEN resume magic
@@ -418,6 +403,21 @@ void tick_resume_local(void)
 	}
 }
 
+#ifdef CONFIG_PM_SLEEP
+/**
+ * tick_suspend - Suspend the tick and the broadcast device
+ *
+ * Called from syscore_suspend() via timekeeping_suspend with only one
+ * CPU online and interrupts disabled.
+ *
+ * No locks required. Nothing can change the per cpu device.
+ */
+void tick_suspend(void)
+{
+	tick_suspend_local();
+	tick_suspend_broadcast();
+}
+
 /**
  * tick_resume - Resume the tick and the broadcast device
  *
author maintainer
#74 lore raw

PATCH 35/35 arm: bl_switcher: Kill tick suspend hackery

In reply to Peter Zijlstra

From: Thomas Gleixner <[email protected]>

Sure it's simple to abuse random functions and data structures and let the people who made the mistake to put the declarations into a global header file deal with the fallout.

Adding a tick_suspend/resume_local() pair to the core code would have been a trivial thing to do.

Use the new tick_suspend/resume_local() and get rid of the homebrewn hackery. The check for the cpumask is completely pointless. There is no harm to suspend a per cpu tick device unconditionally. If that's a real issue then we fix it proper at the core level and not with some completely undocumented hacks in some random arch code.

Move the tick internals to the core code, now that this nuisance is gone.

Cc Nicolas Pitre <[email protected]>
Cc Russell King <[email protected]>
---
 arch/arm/common/bL_switcher.c |   16 ++--------------
 include/linux/clockchips.h    |    6 ------
 include/linux/tick.h          |   18 ++----------------
 kernel/time/tick-internal.h   |    5 +++++
 kernel/time/tick-sched.h      |   10 ++++++++++
 5 files changed, 19 insertions(+), 36 deletions(-)
arch/arm/common/bL_switcher.c +2 -14
Index: linux/arch/arm/common/bL_switcher.c
===================================================================
@@ -151,8 +151,6 @@ static int bL_switch_to(unsigned int new
 	unsigned int mpidr, this_cpu, that_cpu;
 	unsigned int ob_mpidr, ob_cpu, ob_cluster, ib_mpidr, ib_cpu, ib_cluster;
 	struct completion inbound_alive;
-	struct tick_device *tdev;
-	enum clock_event_mode tdev_mode;
 	long volatile *handshake_ptr;
 	int ipi_nr, ret;
 
@@ -219,13 +217,7 @@ static int bL_switch_to(unsigned int new
 	/* redirect GIC's SGIs to our counterpart */
 	gic_migrate_target(bL_gic_id[ib_cpu][ib_cluster]);
 
-	tdev = tick_get_device(this_cpu);
-	if (tdev && !cpumask_equal(tdev->evtdev->cpumask, cpumask_of(this_cpu)))
-		tdev = NULL;
-	if (tdev) {
-		tdev_mode = tdev->evtdev->mode;
-		clockevents_set_mode(tdev->evtdev, CLOCK_EVT_MODE_SHUTDOWN);
-	}
+	tick_suspend_local();
 
 	ret = cpu_pm_enter();
 
@@ -251,11 +243,7 @@ static int bL_switch_to(unsigned int new
 
 	ret = cpu_pm_exit();
 
-	if (tdev) {
-		clockevents_set_mode(tdev->evtdev, tdev_mode);
-		clockevents_program_event(tdev->evtdev,
-					  tdev->evtdev->next_event, 1);
-	}
+	tick_resume_local();
 
 	trace_cpu_migrate_finish(ktime_get_real_ns(), ib_mpidr);
 	local_fiq_enable();
include/linux/clockchips.h +0 -6
Index: linux/include/linux/clockchips.h
===================================================================
@@ -149,11 +149,5 @@ clockevents_calc_mult_shift(struct clock
 	return clocks_calc_mult_shift(&ce->mult, &ce->shift, NSEC_PER_SEC,
 				      freq, minsec);
 }
-
-/* Should be core only, but is abused by arm bl_switcher */
-extern void clockevents_set_mode(struct clock_event_device *dev,
-				 enum clock_event_mode mode);
-extern int clockevents_program_event(struct clock_event_device *dev,
-				     ktime_t expires, bool force);
 #endif /* CONFIG_GENERIC_CLOCKEVENTS */
 #endif
include/linux/tick.h +2 -16
Index: linux/include/linux/tick.h
===================================================================
@@ -11,25 +11,11 @@
 #include <linux/cpumask.h>
 #include <linux/sched.h>
 
-/* ARM BL switcher abuse support */
-#ifdef CONFIG_GENERIC_CLOCKEVENTS
-enum tick_device_mode {
-	TICKDEV_MODE_PERIODIC,
-	TICKDEV_MODE_ONESHOT,
-};
-
-struct tick_device {
-	struct clock_event_device *evtdev;
-	enum tick_device_mode mode;
-};
-extern struct tick_device *tick_get_device(int cpu);
-#endif
-
 #ifdef CONFIG_GENERIC_CLOCKEVENTS
 extern void __init tick_init(void);
-/* Should be core only, but arm BL switcher has its homebrewn implementation */
+/* Should be core only, but arm BL switcher requires it */
 extern void tick_suspend_local(void);
-/* Should be core only, but XEN resume magic requires this */
+/* Should be core only, but XEN resume magic and arm BL switcher require it */
 extern void tick_resume_local(void);
 /* CPU hotplug */
 extern void tick_shutdown_local(void);
kernel/time/tick-internal.h +5 -0
Index: linux/kernel/time/tick-internal.h
===================================================================
@@ -26,6 +26,7 @@ extern bool tick_check_replacement(struc
 				   struct clock_event_device *newdev);
 extern void tick_install_replacement(struct clock_event_device *dev);
 extern int tick_is_oneshot_available(void);
+extern struct tick_device *tick_get_device(int cpu);
 
 /* Check, if the device is functional or a dummy for broadcast */
 static inline int tick_device_is_functional(struct clock_event_device *dev)
@@ -36,6 +37,10 @@ static inline int tick_device_is_functio
 extern void clockevents_shutdown(struct clock_event_device *dev);
 extern void clockevents_exchange_device(struct clock_event_device *old,
 					struct clock_event_device *new);
+extern void clockevents_set_mode(struct clock_event_device *dev,
+				 enum clock_event_mode mode);
+extern int clockevents_program_event(struct clock_event_device *dev,
+				     ktime_t expires, bool force);
 extern void clockevents_handle_noop(struct clock_event_device *dev);
 extern void clockevents_cleanup_dying_cpu(struct clock_event_device *dev);
 extern int __clockevents_update_freq(struct clock_event_device *dev, u32 freq);
kernel/time/tick-sched.h +10 -0
Index: linux/kernel/time/tick-sched.h
===================================================================
@@ -3,6 +3,16 @@
 
 #include <linux/hrtimer.h>
 
+enum tick_device_mode {
+	TICKDEV_MODE_PERIODIC,
+	TICKDEV_MODE_ONESHOT,
+};
+
+struct tick_device {
+	struct clock_event_device *evtdev;
+	enum tick_device_mode mode;
+};
+
 enum tick_nohz_mode {
 	NOHZ_MODE_INACTIVE,
 	NOHZ_MODE_LOWRES,
Acked-by on the v1 series
#75 lore raw
In reply to Peter Zijlstra
Quoted 8 lines · Peter Zijlstra

Hi,

While working with Rafael on the suspend to idle machinery Thomas made these cleanups; since one might as well clean code up while you've done the work of thinking through it again.

As it stands there's very little overlap between Rafael's series and this one aside from a few trivial fixups. So we'll merge them seperately.

Yes, except for the one patch where I can see the overlap (reply sent), there should be no collisions. We may want to compile more stuff conditional on PM_SLEEP (or even SUSPEND for that matter), but that can be fixed up later quite easily.

So for all the series:

#76 lore raw

cover Some kernel/time cleanups (related to timer_suspend/resume)

In reply to Peter Zijlstra

Hi,

Quoted 8 lines · Peter Zijlstra

Hi,

While working with Rafael on the suspend to idle machinery Thomas made these cleanups; since one might as well clean code up while you've done the work of thinking through it again.

As it stands there's very little overlap between Rafael's series and this one aside from a few trivial fixups. So we'll merge them seperately.

Since some of the original Thomas' patches needed to be rebased on top of the suspend-to-idle material that went in during the 4.0 merge window, I did that with the patches related to the suspending/resuming of ticks which follow.

Thanks,
Rafael

#77 lore raw

PATCH 1/9 clockevents: Remove CONFIG_GENERIC_CLOCKEVENTS_BUILD

From: Thomas Gleixner <[email protected]>

This option was for simpler migration to the clock events code. Most architectures have been converted and the option has been disfunctional as a standalone option for quite some time. Remove it.

---
 include/linux/clockchips.h  |    9 +++------
 kernel/time/Kconfig         |    6 ------
 kernel/time/Makefile        |    6 ++----
 kernel/time/clockevents.c   |    3 ---
 kernel/time/tick-internal.h |    4 ++--
 5 files changed, 7 insertions(+), 21 deletions(-)
include/linux/clockchips.h +3 -6
Index: linux-pm/include/linux/clockchips.h
===================================================================
@@ -22,7 +22,7 @@ enum clock_event_nofitiers {
 	CLOCK_EVT_NOTIFY_CPU_DEAD,
 };
 
-#ifdef CONFIG_GENERIC_CLOCKEVENTS_BUILD
+#ifdef CONFIG_GENERIC_CLOCKEVENTS
 
 #include <linux/clocksource.h>
 #include <linux/cpumask.h>
@@ -194,13 +194,9 @@ static inline int tick_check_broadcast_e
 static inline void tick_setup_hrtimer_broadcast(void) {};
 #endif
 
-#ifdef CONFIG_GENERIC_CLOCKEVENTS
 extern int clockevents_notify(unsigned long reason, void *arg);
-#else
-static inline int clockevents_notify(unsigned long reason, void *arg) { return 0; }
-#endif
 
-#else /* CONFIG_GENERIC_CLOCKEVENTS_BUILD */
+#else /* CONFIG_GENERIC_CLOCKEVENTS */
 
 static inline void clockevents_suspend(void) {}
 static inline void clockevents_resume(void) {}
@@ -208,6 +204,7 @@ static inline void clockevents_resume(vo
 static inline int clockevents_notify(unsigned long reason, void *arg) { return 0; }
 static inline int tick_check_broadcast_expired(void) { return 0; }
 static inline void tick_setup_hrtimer_broadcast(void) {};
+static inline int clockevents_notify(unsigned long reason, void *arg) { return 0; }
 
 #endif
 
kernel/time/Kconfig +0 -6
Index: linux-pm/kernel/time/Kconfig
===================================================================
@@ -33,12 +33,6 @@ config ARCH_USES_GETTIMEOFFSET
 config GENERIC_CLOCKEVENTS
 	bool
 
-# Migration helper. Builds, but does not invoke
-config GENERIC_CLOCKEVENTS_BUILD
-	bool
-	default y
-	depends on GENERIC_CLOCKEVENTS
-
 # Architecture can handle broadcast in a driver-agnostic way
 config ARCH_HAS_TICK_BROADCAST
 	bool
kernel/time/Makefile +2 -4
Index: linux-pm/kernel/time/Makefile
===================================================================
@@ -2,15 +2,13 @@ obj-y += time.o timer.o hrtimer.o itimer
 obj-y += timekeeping.o ntp.o clocksource.o jiffies.o timer_list.o
 obj-y += timeconv.o timecounter.o posix-clock.o alarmtimer.o
 
-obj-$(CONFIG_GENERIC_CLOCKEVENTS_BUILD)		+= clockevents.o
-obj-$(CONFIG_GENERIC_CLOCKEVENTS)		+= tick-common.o
+obj-$(CONFIG_GENERIC_CLOCKEVENTS)		+= clockevents.o tick-common.o
 ifeq ($(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST),y)
  obj-y						+= tick-broadcast.o
  obj-$(CONFIG_TICK_ONESHOT)			+= tick-broadcast-hrtimer.o
 endif
 obj-$(CONFIG_GENERIC_SCHED_CLOCK)		+= sched_clock.o
-obj-$(CONFIG_TICK_ONESHOT)			+= tick-oneshot.o
-obj-$(CONFIG_TICK_ONESHOT)			+= tick-sched.o
+obj-$(CONFIG_TICK_ONESHOT)			+= tick-oneshot.o tick-sched.o
 obj-$(CONFIG_TIMER_STATS)			+= timer_stats.o
 obj-$(CONFIG_DEBUG_FS)				+= timekeeping_debug.o
 obj-$(CONFIG_TEST_UDELAY)			+= test_udelay.o
kernel/time/clockevents.c +0 -3
Index: linux-pm/kernel/time/clockevents.c
===================================================================
@@ -541,7 +541,6 @@ void clockevents_resume(void)
 			dev->resume(dev);
 }
 
-#ifdef CONFIG_GENERIC_CLOCKEVENTS
 /**
  * clockevents_notify - notification about relevant events
  * Returns 0 on success, any other value on error
@@ -727,5 +726,3 @@ static int __init clockevents_init_sysfs
 }
 device_initcall(clockevents_init_sysfs);
 #endif /* SYSFS */
-
-#endif /* GENERIC_CLOCK_EVENTS */
kernel/time/tick-internal.h +2 -2
Index: linux-pm/kernel/time/tick-internal.h
===================================================================
@@ -10,7 +10,7 @@ extern seqlock_t jiffies_lock;
 
 #define CS_NAME_LEN	32
 
-#ifdef CONFIG_GENERIC_CLOCKEVENTS_BUILD
+#ifdef CONFIG_GENERIC_CLOCKEVENTS
 
 #define TICK_DO_TIMER_NONE	-1
 #define TICK_DO_TIMER_BOOT	-2
@@ -166,7 +166,7 @@ static inline int tick_device_is_functio
 
 int __clockevents_update_freq(struct clock_event_device *dev, u32 freq);
 
-#endif
+#endif /* GENERIC_CLOCKEVENTS */
 
 extern void do_timer(unsigned long ticks);
 extern void update_wall_time(void);
#78 lore raw

[tip:timers/core] clockevents: Remove CONFIG_GENERIC_CLOCKEVENTS_BUILD

clockevents: Remove CONFIG_GENERIC_CLOCKEVENTS_BUILD
Commit-ID:  9f083b74df3a7eaa100b456f2dc195512daf728e
Gitweb:     http://git.kernel.org/tip/9f083b74df3a7eaa100b456f2dc195512daf728e
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Wed, 25 Mar 2015 13:05:19 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 1 Apr 2015 14:22:57 +0200

clockevents: Remove CONFIG_GENERIC_CLOCKEVENTS_BUILD

This option was for simpler migration to the clock events code. Most architectures have been converted and the option has been disfunctional as a standalone option for quite some time. Remove it.

---
 include/linux/clockchips.h  | 9 +++------
 kernel/time/Kconfig         | 6 ------
 kernel/time/Makefile        | 6 ++----
 kernel/time/clockevents.c   | 3 ---
 kernel/time/tick-internal.h | 4 ++--
 5 files changed, 7 insertions(+), 21 deletions(-)
include/linux/clockchips.h +3 -6
index e20232c..5797513 100644
@@ -22,7 +22,7 @@ enum clock_event_nofitiers {
 	CLOCK_EVT_NOTIFY_CPU_DEAD,
 };
 
-#ifdef CONFIG_GENERIC_CLOCKEVENTS_BUILD
+#ifdef CONFIG_GENERIC_CLOCKEVENTS
 
 #include <linux/clocksource.h>
 #include <linux/cpumask.h>
@@ -229,13 +229,9 @@ static inline int tick_check_broadcast_expired(void) { return 0; }
 static inline void tick_setup_hrtimer_broadcast(void) {};
 #endif
 
-#ifdef CONFIG_GENERIC_CLOCKEVENTS
 extern int clockevents_notify(unsigned long reason, void *arg);
-#else
-static inline int clockevents_notify(unsigned long reason, void *arg) { return 0; }
-#endif
 
-#else /* CONFIG_GENERIC_CLOCKEVENTS_BUILD */
+#else /* CONFIG_GENERIC_CLOCKEVENTS */
 
 static inline void clockevents_suspend(void) {}
 static inline void clockevents_resume(void) {}
@@ -243,6 +239,7 @@ static inline void clockevents_resume(void) {}
 static inline int clockevents_notify(unsigned long reason, void *arg) { return 0; }
 static inline int tick_check_broadcast_expired(void) { return 0; }
 static inline void tick_setup_hrtimer_broadcast(void) {};
+static inline int clockevents_notify(unsigned long reason, void *arg) { return 0; }
 
 #endif
 
kernel/time/Kconfig +0 -6
index d626dc9..579ce1b 100644
@@ -33,12 +33,6 @@ config ARCH_USES_GETTIMEOFFSET
 config GENERIC_CLOCKEVENTS
 	bool
 
-# Migration helper. Builds, but does not invoke
-config GENERIC_CLOCKEVENTS_BUILD
-	bool
-	default y
-	depends on GENERIC_CLOCKEVENTS
-
 # Architecture can handle broadcast in a driver-agnostic way
 config ARCH_HAS_TICK_BROADCAST
 	bool
kernel/time/Makefile +2 -4
index c09c078..01f0312 100644
@@ -2,15 +2,13 @@ obj-y += time.o timer.o hrtimer.o itimer.o posix-timers.o posix-cpu-timers.o
 obj-y += timekeeping.o ntp.o clocksource.o jiffies.o timer_list.o
 obj-y += timeconv.o timecounter.o posix-clock.o alarmtimer.o
 
-obj-$(CONFIG_GENERIC_CLOCKEVENTS_BUILD)		+= clockevents.o
-obj-$(CONFIG_GENERIC_CLOCKEVENTS)		+= tick-common.o
+obj-$(CONFIG_GENERIC_CLOCKEVENTS)		+= clockevents.o tick-common.o
 ifeq ($(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST),y)
  obj-y						+= tick-broadcast.o
  obj-$(CONFIG_TICK_ONESHOT)			+= tick-broadcast-hrtimer.o
 endif
 obj-$(CONFIG_GENERIC_SCHED_CLOCK)		+= sched_clock.o
-obj-$(CONFIG_TICK_ONESHOT)			+= tick-oneshot.o
-obj-$(CONFIG_TICK_ONESHOT)			+= tick-sched.o
+obj-$(CONFIG_TICK_ONESHOT)			+= tick-oneshot.o tick-sched.o
 obj-$(CONFIG_TIMER_STATS)			+= timer_stats.o
 obj-$(CONFIG_DEBUG_FS)				+= timekeeping_debug.o
 obj-$(CONFIG_TEST_UDELAY)			+= test_udelay.o
kernel/time/clockevents.c +0 -3
index 73689df..3531bee 100644
@@ -645,7 +645,6 @@ void clockevents_resume(void)
 			dev->resume(dev);
 }
 
-#ifdef CONFIG_GENERIC_CLOCKEVENTS
 /**
  * clockevents_notify - notification about relevant events
  * Returns 0 on success, any other value on error
@@ -831,5 +830,3 @@ static int __init clockevents_init_sysfs(void)
 }
 device_initcall(clockevents_init_sysfs);
 #endif /* SYSFS */
-
-#endif /* GENERIC_CLOCK_EVENTS */
kernel/time/tick-internal.h +2 -2
index 98700e4..c7b75be 100644
@@ -10,7 +10,7 @@ extern seqlock_t jiffies_lock;
 
 #define CS_NAME_LEN	32
 
-#ifdef CONFIG_GENERIC_CLOCKEVENTS_BUILD
+#ifdef CONFIG_GENERIC_CLOCKEVENTS
 
 #define TICK_DO_TIMER_NONE	-1
 #define TICK_DO_TIMER_BOOT	-2
@@ -167,7 +167,7 @@ static inline int tick_device_is_functional(struct clock_event_device *dev)
 
 int __clockevents_update_freq(struct clock_event_device *dev, u32 freq);
 
-#endif
+#endif /* GENERIC_CLOCKEVENTS */
 
 extern void do_timer(unsigned long ticks);
 extern void update_wall_time(void);
#79 lore raw

PATCH 2/9 tick: Move clocksource related stuff to timekeeping.h

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Move clocksource related stuff to timekeeping.h and remove the pointless include from ntp.c

---
 kernel/time/clocksource.c   |    2 +-
 kernel/time/jiffies.c       |    2 +-
 kernel/time/ntp.c           |    1 -
 kernel/time/tick-internal.h |    6 ------
 kernel/time/timekeeping.h   |    7 +++++++
 5 files changed, 9 insertions(+), 9 deletions(-)
kernel/time/clocksource.c +1 -1
Index: linux-pm/kernel/time/clocksource.c
===================================================================
@@ -31,7 +31,7 @@
 #include <linux/tick.h>
 #include <linux/kthread.h>
 
-#include "tick-internal.h"
+#include "timekeeping.h"
 #include "timekeeping_internal.h"
 
 /**
kernel/time/jiffies.c +1 -1
Index: linux-pm/kernel/time/jiffies.c
===================================================================
@@ -25,7 +25,7 @@
 #include <linux/module.h>
 #include <linux/init.h>
 
-#include "tick-internal.h"
+#include "timekeeping.h"
 
 /* The Jiffies based clocksource is the lowest common
  * denominator clock source which should function on
kernel/time/ntp.c +0 -1
Index: linux-pm/kernel/time/ntp.c
===================================================================
@@ -17,7 +17,6 @@
 #include <linux/module.h>
 #include <linux/rtc.h>
 
-#include "tick-internal.h"
 #include "ntp_internal.h"
 
 /*
kernel/time/tick-internal.h +0 -6
Index: linux-pm/kernel/time/tick-internal.h
===================================================================
@@ -6,10 +6,6 @@
 
 #include "timekeeping.h"
 
-extern seqlock_t jiffies_lock;
-
-#define CS_NAME_LEN	32
-
 #ifdef CONFIG_GENERIC_CLOCKEVENTS
 
 #define TICK_DO_TIMER_NONE	-1
@@ -168,5 +164,3 @@ int __clockevents_update_freq(struct clo
 
 #endif /* GENERIC_CLOCKEVENTS */
 
-extern void do_timer(unsigned long ticks);
-extern void update_wall_time(void);
kernel/time/timekeeping.h +7 -0
Index: linux-pm/kernel/time/timekeeping.h
===================================================================
@@ -19,4 +19,11 @@ extern void timekeeping_clocktai(struct
 extern int timekeeping_suspend(void);
 extern void timekeeping_resume(void);
 
+extern void do_timer(unsigned long ticks);
+extern void update_wall_time(void);
+
+extern seqlock_t jiffies_lock;
+
+#define CS_NAME_LEN	32
+
 #endif
#80 lore raw

[tip:timers/core] tick: Move clocksource related stuff to timekeeping.h

tick: Move clocksource related stuff to timekeeping.h
Commit-ID:  bfb83b27519aa7ed9510f601a8f825a2c1484bc2
Gitweb:     http://git.kernel.org/tip/bfb83b27519aa7ed9510f601a8f825a2c1484bc2
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Wed, 25 Mar 2015 13:06:04 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 1 Apr 2015 14:22:58 +0200

tick: Move clocksource related stuff to timekeeping.h

Move clocksource related stuff to timekeeping.h and remove the pointless include from ntp.c

---
 kernel/time/clocksource.c   | 2 +-
 kernel/time/jiffies.c       | 2 +-
 kernel/time/ntp.c           | 1 -
 kernel/time/tick-internal.h | 6 ------
 kernel/time/timekeeping.h   | 7 +++++++
 5 files changed, 9 insertions(+), 9 deletions(-)
kernel/time/clocksource.c +1 -1
index c3be3c7..8b4010f 100644
@@ -31,7 +31,7 @@
 #include <linux/tick.h>
 #include <linux/kthread.h>
 
-#include "tick-internal.h"
+#include "timekeeping.h"
 #include "timekeeping_internal.h"
 
 /**
kernel/time/jiffies.c +1 -1
index c4bb518..347fecf 100644
@@ -25,7 +25,7 @@
 #include <linux/module.h>
 #include <linux/init.h>
 
-#include "tick-internal.h"
+#include "timekeeping.h"
 
 /* The Jiffies based clocksource is the lowest common
  * denominator clock source which should function on
kernel/time/ntp.c +0 -1
index 0f60b08..9ad60d0 100644
@@ -17,7 +17,6 @@
 #include <linux/module.h>
 #include <linux/rtc.h>
 
-#include "tick-internal.h"
 #include "ntp_internal.h"
 
 /*
kernel/time/tick-internal.h +0 -6
index c7b75be..cba5214 100644
@@ -6,10 +6,6 @@
 
 #include "timekeeping.h"
 
-extern seqlock_t jiffies_lock;
-
-#define CS_NAME_LEN	32
-
 #ifdef CONFIG_GENERIC_CLOCKEVENTS
 
 #define TICK_DO_TIMER_NONE	-1
@@ -169,5 +165,3 @@ int __clockevents_update_freq(struct clock_event_device *dev, u32 freq);
 
 #endif /* GENERIC_CLOCKEVENTS */
 
-extern void do_timer(unsigned long ticks);
-extern void update_wall_time(void);
kernel/time/timekeeping.h +7 -0
index 1d91416..ead8794 100644
@@ -19,4 +19,11 @@ extern void timekeeping_clocktai(struct timespec *ts);
 extern int timekeeping_suspend(void);
 extern void timekeeping_resume(void);
 
+extern void do_timer(unsigned long ticks);
+extern void update_wall_time(void);
+
+extern seqlock_t jiffies_lock;
+
+#define CS_NAME_LEN	32
+
 #endif
#81 lore raw

PATCH 3/9 tick: Simplify tick-internal.h

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

tick-internal.h is pretty confusing as a lot of the stub inlines are there several times.

Distangle the maze and make clear functional sections.

---
 kernel/time/tick-internal.h |  145 ++++++++++++++------------------------------
 1 file changed, 49 insertions(+), 96 deletions(-)
kernel/time/tick-internal.h +49 -96
Index: linux-pm/kernel/time/tick-internal.h
===================================================================
@@ -27,13 +27,18 @@ extern bool tick_check_replacement(struc
 				   struct clock_event_device *newdev);
 extern void tick_install_replacement(struct clock_event_device *dev);
 
-extern void clockevents_shutdown(struct clock_event_device *dev);
+/* Check, if the device is functional or a dummy for broadcast */
+static inline int tick_device_is_functional(struct clock_event_device *dev)
+{
+	return !(dev->features & CLOCK_EVT_FEAT_DUMMY);
+}
 
+extern void clockevents_shutdown(struct clock_event_device *dev);
+extern int __clockevents_update_freq(struct clock_event_device *dev, u32 freq);
 extern ssize_t sysfs_get_uname(const char *buf, char *dst, size_t cnt);
+#endif /* GENERIC_CLOCKEVENTS */
 
-/*
- * NO_HZ / high resolution timer shared code
- */
+/* Oneshot related functions */
 #ifdef CONFIG_TICK_ONESHOT
 extern void tick_setup_oneshot(struct clock_event_device *newdev,
 			       void (*handler)(struct clock_event_device *),
@@ -42,69 +47,19 @@ extern int tick_program_event(ktime_t ex
 extern void tick_oneshot_notify(void);
 extern int tick_switch_to_oneshot(void (*handler)(struct clock_event_device *));
 extern void tick_resume_oneshot(void);
-# ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
-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_resume_broadcast_oneshot(struct clock_event_device *bc);
-extern int tick_broadcast_oneshot_active(void);
-extern void tick_check_oneshot_broadcast_this_cpu(void);
-bool tick_broadcast_oneshot_available(void);
-# else /* BROADCAST */
-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; }
-static inline void tick_check_oneshot_broadcast_this_cpu(void) { }
-static inline bool tick_broadcast_oneshot_available(void) { return true; }
-# endif /* !BROADCAST */
-
+static inline bool tick_oneshot_possible(void) { return true; }
 #else /* !ONESHOT */
 static inline
 void tick_setup_oneshot(struct clock_event_device *newdev,
 			void (*handler)(struct clock_event_device *),
-			ktime_t nextevt)
-{
-	BUG();
-}
-static inline void tick_resume_oneshot(void)
-{
-	BUG();
-}
-static inline int tick_program_event(ktime_t expires, int force)
-{
-	return 0;
-}
+			ktime_t nextevt) { BUG(); }
+static inline void tick_resume_oneshot(void) { BUG(); }
+static inline int tick_program_event(ktime_t expires, int force) { return 0; }
 static inline void tick_oneshot_notify(void) { }
-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_shutdown_broadcast_oneshot(unsigned int *cpup) { }
-static inline int tick_resume_broadcast_oneshot(struct clock_event_device *bc)
-{
-	return 0;
-}
-static inline int tick_broadcast_oneshot_active(void) { return 0; }
-static inline bool tick_broadcast_oneshot_available(void) { return false; }
+static inline bool tick_oneshot_possible(void) { return false; }
 #endif /* !TICK_ONESHOT */
 
-/* NO_HZ_FULL internal */
-#ifdef CONFIG_NO_HZ_FULL
-extern void tick_nohz_init(void);
-# else
-static inline void tick_nohz_init(void) { }
-#endif
-
-/*
- * Broadcasting support
- */
+/* Broadcasting support */
 #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
 extern int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu);
 extern void tick_install_broadcast_device(struct clock_event_device *dev);
@@ -114,53 +69,51 @@ extern void tick_shutdown_broadcast(unsi
 extern void tick_suspend_broadcast(void);
 extern int tick_resume_broadcast(void);
 extern void tick_broadcast_init(void);
-extern void
-tick_set_periodic_handler(struct clock_event_device *dev, int broadcast);
-int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq);
-
+extern void tick_set_periodic_handler(struct clock_event_device *dev, int broadcast);
+extern int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq);
 #else /* !BROADCAST */
-
-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_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 int tick_resume_broadcast(void) { return 0; }
 static inline void tick_broadcast_init(void) { }
-static inline int tick_broadcast_update_freq(struct clock_event_device *dev,
-					     u32 freq) { return -ENODEV; }
+static inline int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq) { return -ENODEV; }
 
-/*
- * Set the periodic handler in non broadcast mode
- */
-static inline void tick_set_periodic_handler(struct clock_event_device *dev,
-					     int broadcast)
+/* Set the periodic handler in non broadcast mode */
+static inline void tick_set_periodic_handler(struct clock_event_device *dev, int broadcast)
 {
 	dev->event_handler = tick_handle_periodic;
 }
 #endif /* !BROADCAST */
 
-/*
- * Check, if the device is functional or a dummy for broadcast
- */
-static inline int tick_device_is_functional(struct clock_event_device *dev)
-{
-	return !(dev->features & CLOCK_EVT_FEAT_DUMMY);
-}
-
-int __clockevents_update_freq(struct clock_event_device *dev, u32 freq);
-
-#endif /* GENERIC_CLOCKEVENTS */
+/* 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_resume_broadcast_oneshot(struct clock_event_device *bc);
+extern int tick_broadcast_oneshot_active(void);
+extern void tick_check_oneshot_broadcast_this_cpu(void);
+bool tick_broadcast_oneshot_available(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_resume_broadcast_oneshot(struct clock_event_device *bc) { return 0; }
+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(); }
+#endif /* !BROADCAST && ONESHOT */
 
+/* NO_HZ_FULL internal */
+#ifdef CONFIG_NO_HZ_FULL
+extern void tick_nohz_init(void);
+# else
+static inline void tick_nohz_init(void) { }
+#endif
#82 lore raw

[tip:timers/core] tick: Simplify tick-internal.h

tick: Simplify tick-internal.h
Commit-ID:  b7475eb599ddb2e8cab2dc86ff38a9507463ad6b
Gitweb:     http://git.kernel.org/tip/b7475eb599ddb2e8cab2dc86ff38a9507463ad6b
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Wed, 25 Mar 2015 13:06:47 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 1 Apr 2015 14:22:58 +0200

tick: Simplify tick-internal.h

tick-internal.h is pretty confusing as a lot of the stub inlines are there several times.

Distangle the maze and make clear functional sections.

---
 kernel/time/tick-internal.h | 145 +++++++++++++++-----------------------------
 1 file changed, 49 insertions(+), 96 deletions(-)
kernel/time/tick-internal.h +49 -96
index cba5214..d86eb8d 100644
@@ -27,14 +27,19 @@ extern bool tick_check_replacement(struct clock_event_device *curdev,
 				   struct clock_event_device *newdev);
 extern void tick_install_replacement(struct clock_event_device *dev);
 
-extern void clockevents_shutdown(struct clock_event_device *dev);
 extern int clockevents_tick_resume(struct clock_event_device *dev);
+/* Check, if the device is functional or a dummy for broadcast */
+static inline int tick_device_is_functional(struct clock_event_device *dev)
+{
+	return !(dev->features & CLOCK_EVT_FEAT_DUMMY);
+}
 
+extern void clockevents_shutdown(struct clock_event_device *dev);
+extern int __clockevents_update_freq(struct clock_event_device *dev, u32 freq);
 extern ssize_t sysfs_get_uname(const char *buf, char *dst, size_t cnt);
+#endif /* GENERIC_CLOCKEVENTS */
 
-/*
- * NO_HZ / high resolution timer shared code
- */
+/* Oneshot related functions */
 #ifdef CONFIG_TICK_ONESHOT
 extern void tick_setup_oneshot(struct clock_event_device *newdev,
 			       void (*handler)(struct clock_event_device *),
@@ -43,69 +48,19 @@ extern int tick_program_event(ktime_t expires, int force);
 extern void tick_oneshot_notify(void);
 extern int tick_switch_to_oneshot(void (*handler)(struct clock_event_device *));
 extern void tick_resume_oneshot(void);
-# ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
-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_resume_broadcast_oneshot(struct clock_event_device *bc);
-extern int tick_broadcast_oneshot_active(void);
-extern void tick_check_oneshot_broadcast_this_cpu(void);
-bool tick_broadcast_oneshot_available(void);
-# else /* BROADCAST */
-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; }
-static inline void tick_check_oneshot_broadcast_this_cpu(void) { }
-static inline bool tick_broadcast_oneshot_available(void) { return true; }
-# endif /* !BROADCAST */
-
+static inline bool tick_oneshot_possible(void) { return true; }
 #else /* !ONESHOT */
 static inline
 void tick_setup_oneshot(struct clock_event_device *newdev,
 			void (*handler)(struct clock_event_device *),
-			ktime_t nextevt)
-{
-	BUG();
-}
-static inline void tick_resume_oneshot(void)
-{
-	BUG();
-}
-static inline int tick_program_event(ktime_t expires, int force)
-{
-	return 0;
-}
+			ktime_t nextevt) { BUG(); }
+static inline void tick_resume_oneshot(void) { BUG(); }
+static inline int tick_program_event(ktime_t expires, int force) { return 0; }
 static inline void tick_oneshot_notify(void) { }
-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_shutdown_broadcast_oneshot(unsigned int *cpup) { }
-static inline int tick_resume_broadcast_oneshot(struct clock_event_device *bc)
-{
-	return 0;
-}
-static inline int tick_broadcast_oneshot_active(void) { return 0; }
-static inline bool tick_broadcast_oneshot_available(void) { return false; }
+static inline bool tick_oneshot_possible(void) { return false; }
 #endif /* !TICK_ONESHOT */
 
-/* NO_HZ_FULL internal */
-#ifdef CONFIG_NO_HZ_FULL
-extern void tick_nohz_init(void);
-# else
-static inline void tick_nohz_init(void) { }
-#endif
-
-/*
- * Broadcasting support
- */
+/* Broadcasting support */
 #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
 extern int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu);
 extern void tick_install_broadcast_device(struct clock_event_device *dev);
@@ -115,53 +70,51 @@ extern void tick_shutdown_broadcast(unsigned int *cpup);
 extern void tick_suspend_broadcast(void);
 extern int tick_resume_broadcast(void);
 extern void tick_broadcast_init(void);
-extern void
-tick_set_periodic_handler(struct clock_event_device *dev, int broadcast);
-int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq);
-
+extern void tick_set_periodic_handler(struct clock_event_device *dev, int broadcast);
+extern int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq);
 #else /* !BROADCAST */
-
-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_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 int tick_resume_broadcast(void) { return 0; }
 static inline void tick_broadcast_init(void) { }
-static inline int tick_broadcast_update_freq(struct clock_event_device *dev,
-					     u32 freq) { return -ENODEV; }
+static inline int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq) { return -ENODEV; }
 
-/*
- * Set the periodic handler in non broadcast mode
- */
-static inline void tick_set_periodic_handler(struct clock_event_device *dev,
-					     int broadcast)
+/* Set the periodic handler in non broadcast mode */
+static inline void tick_set_periodic_handler(struct clock_event_device *dev, int broadcast)
 {
 	dev->event_handler = tick_handle_periodic;
 }
 #endif /* !BROADCAST */
 
-/*
- * Check, if the device is functional or a dummy for broadcast
- */
-static inline int tick_device_is_functional(struct clock_event_device *dev)
-{
-	return !(dev->features & CLOCK_EVT_FEAT_DUMMY);
-}
-
-int __clockevents_update_freq(struct clock_event_device *dev, u32 freq);
-
-#endif /* GENERIC_CLOCKEVENTS */
+/* 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_resume_broadcast_oneshot(struct clock_event_device *bc);
+extern int tick_broadcast_oneshot_active(void);
+extern void tick_check_oneshot_broadcast_this_cpu(void);
+bool tick_broadcast_oneshot_available(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_resume_broadcast_oneshot(struct clock_event_device *bc) { return 0; }
+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(); }
+#endif /* !BROADCAST && ONESHOT */
 
+/* NO_HZ_FULL internal */
+#ifdef CONFIG_NO_HZ_FULL
+extern void tick_nohz_init(void);
+# else
+static inline void tick_nohz_init(void) { }
+#endif
#83 lore raw

PATCH 4/9 tick: Move core only declarations and functions to core

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

No point to expose everything to the world. People just believe such functions can be abused for whatever purposes. Sigh.

Cc Nicolas Pitre <[email protected]>
[ rjw: Rebased on top of 4.0-rc5 ]
---
 include/linux/clockchips.h  |   15 +---
 include/linux/tick.h        |  134 +++++---------------------------------------
 kernel/time/clocksource.c   |    2 
 kernel/time/hrtimer.c       |    2 
 kernel/time/tick-internal.h |   15 ++++
 kernel/time/tick-sched.c    |    7 +-
 kernel/time/tick-sched.h    |   64 +++++++++++++++++++++
 kernel/time/timer_list.c    |    2 
 8 files changed, 112 insertions(+), 129 deletions(-)
include/linux/clockchips.h +6 -9
Index: linux-pm/include/linux/clockchips.h
===================================================================
@@ -158,15 +158,6 @@ extern void clockevents_config_and_regis
 
 extern int clockevents_update_freq(struct clock_event_device *ce, u32 freq);
 
-extern void clockevents_exchange_device(struct clock_event_device *old,
-					struct clock_event_device *new);
-extern void clockevents_set_mode(struct clock_event_device *dev,
-				 enum clock_event_mode mode);
-extern int clockevents_program_event(struct clock_event_device *dev,
-				     ktime_t expires, bool force);
-
-extern void clockevents_handle_noop(struct clock_event_device *dev);
-
 static inline void
 clockevents_calc_mult_shift(struct clock_event_device *ce, u32 freq, u32 minsec)
 {
@@ -174,6 +165,12 @@ clockevents_calc_mult_shift(struct clock
 				      freq, minsec);
 }
 
+/* Should be core only, but is abused by arm bl_switcher */
+extern void clockevents_set_mode(struct clock_event_device *dev,
+				 enum clock_event_mode mode);
+extern int clockevents_program_event(struct clock_event_device *dev,
+				     ktime_t expires, bool force);
+
 extern void clockevents_suspend(void);
 extern void clockevents_resume(void);
 
include/linux/tick.h +18 -116

178 lines not on this page · raw message

kernel/time/clocksource.c +1 -1
Index: linux-pm/kernel/time/clocksource.c
===================================================================
@@ -31,7 +31,7 @@
 #include <linux/tick.h>
 #include <linux/kthread.h>
 
-#include "timekeeping.h"
+#include "tick-internal.h"
 #include "timekeeping_internal.h"
 
 /**
kernel/time/hrtimer.c +1 -1
Index: linux-pm/kernel/time/hrtimer.c
===================================================================
@@ -54,7 +54,7 @@
 
 #include <trace/events/timer.h>
 
-#include "timekeeping.h"
+#include "tick-internal.h"
 
 /*
  * The timer bases:
kernel/time/tick-internal.h +15 -0
Index: linux-pm/kernel/time/tick-internal.h
===================================================================
@@ -5,6 +5,7 @@
 #include <linux/tick.h>
 
 #include "timekeeping.h"
+#include "tick-sched.h"
 
 #ifdef CONFIG_GENERIC_CLOCKEVENTS
 
@@ -26,6 +27,7 @@ extern void tick_resume(void);
 extern bool tick_check_replacement(struct clock_event_device *curdev,
 				   struct clock_event_device *newdev);
 extern void tick_install_replacement(struct clock_event_device *dev);
+extern int tick_is_oneshot_available(void);
 
 /* Check, if the device is functional or a dummy for broadcast */
 static inline int tick_device_is_functional(struct clock_event_device *dev)
@@ -34,6 +36,9 @@ static inline int tick_device_is_functio
 }
 
 extern void clockevents_shutdown(struct clock_event_device *dev);
+extern void clockevents_exchange_device(struct clock_event_device *old,
+					struct clock_event_device *new);
+extern void clockevents_handle_noop(struct clock_event_device *dev);
 extern int __clockevents_update_freq(struct clock_event_device *dev, u32 freq);
 extern ssize_t sysfs_get_uname(const char *buf, char *dst, size_t cnt);
 #endif /* GENERIC_CLOCKEVENTS */
@@ -48,6 +53,10 @@ extern void tick_oneshot_notify(void);
 extern int tick_switch_to_oneshot(void (*handler)(struct clock_event_device *));
 extern void tick_resume_oneshot(void);
 static inline bool tick_oneshot_possible(void) { return true; }
+extern int tick_oneshot_mode_active(void);
+extern void tick_clock_notify(void);
+extern int tick_check_oneshot_change(int allow_nohz);
+extern int tick_init_highres(void);
 #else /* !ONESHOT */
 static inline
 void tick_setup_oneshot(struct clock_event_device *newdev,
@@ -57,6 +66,9 @@ static inline void tick_resume_oneshot(v
 static inline int tick_program_event(ktime_t expires, int force) { return 0; }
 static inline void tick_oneshot_notify(void) { }
 static inline bool tick_oneshot_possible(void) { return false; }
+static inline int tick_oneshot_mode_active(void) { return 0; }
+static inline void tick_clock_notify(void) { }
+static inline int tick_check_oneshot_change(int allow_nohz) { return 0; }
 #endif /* !TICK_ONESHOT */
 
 /* Broadcasting support */
@@ -71,6 +83,8 @@ extern int tick_resume_broadcast(void);
 extern void tick_broadcast_init(void);
 extern void tick_set_periodic_handler(struct clock_event_device *dev, int broadcast);
 extern int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq);
+extern struct tick_device *tick_get_broadcast_device(void);
+extern struct cpumask *tick_get_broadcast_mask(void);
 #else /* !BROADCAST */
 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; }
@@ -100,6 +114,7 @@ extern int tick_resume_broadcast_oneshot
 extern int tick_broadcast_oneshot_active(void);
 extern void tick_check_oneshot_broadcast_this_cpu(void);
 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; }
kernel/time/tick-sched.c +6 -1
Index: linux-pm/kernel/time/tick-sched.c
===================================================================
@@ -34,7 +34,7 @@
 /*
  * Per cpu nohz control structure
  */
-DEFINE_PER_CPU(struct tick_sched, tick_cpu_sched);
+static DEFINE_PER_CPU(struct tick_sched, tick_cpu_sched);
 
 /*
  * The time, when the last jiffy update happened. Protected by jiffies_lock.
@@ -416,6 +416,11 @@ static int __init setup_tick_nohz(char *
 
 __setup("nohz=", setup_tick_nohz);
 
+int tick_nohz_tick_stopped(void)
+{
+	return __this_cpu_read(tick_cpu_sched.tick_stopped);
+}
+
 /**
  * tick_nohz_update_jiffies - update jiffies when idle was interrupted
  *
kernel/time/tick-sched.h new file +64 -0

64 lines not on this page · raw message

kernel/time/timer_list.c +1 -1
Index: linux-pm/kernel/time/timer_list.c
===================================================================
@@ -16,10 +16,10 @@
 #include <linux/sched.h>
 #include <linux/seq_file.h>
 #include <linux/kallsyms.h>
-#include <linux/tick.h>
 
 #include <asm/uaccess.h>
 
+#include "tick-internal.h"
 
 struct timer_list_iter {
 	int cpu;
#84 lore raw

[tip:timers/core] tick: Move core only declarations and functions to core

tick: Move core only declarations and functions to core
Commit-ID:  c1797baf6880174f899ce3960d0598f5bbeeb7ff
Gitweb:     http://git.kernel.org/tip/c1797baf6880174f899ce3960d0598f5bbeeb7ff
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Wed, 25 Mar 2015 13:07:37 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 1 Apr 2015 14:22:58 +0200

tick: Move core only declarations and functions to core

No point to expose everything to the world. People just believe such functions can be abused for whatever purposes. Sigh.

[ Rebased on top of 4.0-rc5 ]
Cc Nicolas Pitre <[email protected]>
Cc Peter Zijlstra <[email protected]>
[ Merged to latest timers/core ]
---
 include/linux/clockchips.h  |  15 ++---
 include/linux/tick.h        | 134 ++++++--------------------------------------
 kernel/time/clocksource.c   |   2 +-
 kernel/time/hrtimer.c       |   2 +-
 kernel/time/tick-internal.h |  15 +++++
 kernel/time/tick-sched.c    |   7 ++-
 kernel/time/tick-sched.h    |  64 +++++++++++++++++++++
 kernel/time/timer_list.c    |   2 +-
 8 files changed, 112 insertions(+), 129 deletions(-)
include/linux/clockchips.h +6 -9
index 5797513..bc3af82 100644
@@ -193,15 +193,6 @@ extern void clockevents_config_and_register(struct clock_event_device *dev,
 
 extern int clockevents_update_freq(struct clock_event_device *ce, u32 freq);
 
-extern void clockevents_exchange_device(struct clock_event_device *old,
-					struct clock_event_device *new);
-extern void clockevents_set_state(struct clock_event_device *dev,
-				  enum clock_event_state state);
-extern int clockevents_program_event(struct clock_event_device *dev,
-				     ktime_t expires, bool force);
-
-extern void clockevents_handle_noop(struct clock_event_device *dev);
-
 static inline void
 clockevents_calc_mult_shift(struct clock_event_device *ce, u32 freq, u32 minsec)
 {
@@ -209,6 +200,12 @@ clockevents_calc_mult_shift(struct clock_event_device *ce, u32 freq, u32 minsec)
 				      freq, minsec);
 }
 
+/* Should be core only, but is abused by arm bl_switcher */
+extern void clockevents_set_state(struct clock_event_device *dev,
+				 enum clock_event_state state);
+extern int clockevents_program_event(struct clock_event_device *dev,
+				     ktime_t expires, bool force);
+
 extern void clockevents_suspend(void);
 extern void clockevents_resume(void);
 
include/linux/tick.h +18 -116

178 lines not on this page · raw message

kernel/time/clocksource.c +1 -1
index 8b4010f..c3be3c7 100644
@@ -31,7 +31,7 @@
 #include <linux/tick.h>
 #include <linux/kthread.h>
 
-#include "timekeeping.h"
+#include "tick-internal.h"
 #include "timekeeping_internal.h"
 
 /**
kernel/time/hrtimer.c +1 -1
index bee0c1f..721d29b 100644
@@ -54,7 +54,7 @@
 
 #include <trace/events/timer.h>
 
-#include "timekeeping.h"
+#include "tick-internal.h"
 
 /*
  * The timer bases:
kernel/time/tick-internal.h +15 -0
index d86eb8d..dd2c45d 100644
@@ -5,6 +5,7 @@
 #include <linux/tick.h>
 
 #include "timekeeping.h"
+#include "tick-sched.h"
 
 #ifdef CONFIG_GENERIC_CLOCKEVENTS
 
@@ -26,6 +27,7 @@ extern void tick_resume(void);
 extern bool tick_check_replacement(struct clock_event_device *curdev,
 				   struct clock_event_device *newdev);
 extern void tick_install_replacement(struct clock_event_device *dev);
+extern int tick_is_oneshot_available(void);
 
 extern int clockevents_tick_resume(struct clock_event_device *dev);
 /* Check, if the device is functional or a dummy for broadcast */
@@ -35,6 +37,9 @@ static inline int tick_device_is_functional(struct clock_event_device *dev)
 }
 
 extern void clockevents_shutdown(struct clock_event_device *dev);
+extern void clockevents_exchange_device(struct clock_event_device *old,
+					struct clock_event_device *new);
+extern void clockevents_handle_noop(struct clock_event_device *dev);
 extern int __clockevents_update_freq(struct clock_event_device *dev, u32 freq);
 extern ssize_t sysfs_get_uname(const char *buf, char *dst, size_t cnt);
 #endif /* GENERIC_CLOCKEVENTS */
@@ -49,6 +54,10 @@ extern void tick_oneshot_notify(void);
 extern int tick_switch_to_oneshot(void (*handler)(struct clock_event_device *));
 extern void tick_resume_oneshot(void);
 static inline bool tick_oneshot_possible(void) { return true; }
+extern int tick_oneshot_mode_active(void);
+extern void tick_clock_notify(void);
+extern int tick_check_oneshot_change(int allow_nohz);
+extern int tick_init_highres(void);
 #else /* !ONESHOT */
 static inline
 void tick_setup_oneshot(struct clock_event_device *newdev,
@@ -58,6 +67,9 @@ static inline void tick_resume_oneshot(void) { BUG(); }
 static inline int tick_program_event(ktime_t expires, int force) { return 0; }
 static inline void tick_oneshot_notify(void) { }
 static inline bool tick_oneshot_possible(void) { return false; }
+static inline int tick_oneshot_mode_active(void) { return 0; }
+static inline void tick_clock_notify(void) { }
+static inline int tick_check_oneshot_change(int allow_nohz) { return 0; }
 #endif /* !TICK_ONESHOT */
 
 /* Broadcasting support */
@@ -72,6 +84,8 @@ extern int tick_resume_broadcast(void);
 extern void tick_broadcast_init(void);
 extern void tick_set_periodic_handler(struct clock_event_device *dev, int broadcast);
 extern int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq);
+extern struct tick_device *tick_get_broadcast_device(void);
+extern struct cpumask *tick_get_broadcast_mask(void);
 #else /* !BROADCAST */
 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; }
@@ -101,6 +115,7 @@ extern int tick_resume_broadcast_oneshot(struct clock_event_device *bc);
 extern int tick_broadcast_oneshot_active(void);
 extern void tick_check_oneshot_broadcast_this_cpu(void);
 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; }
kernel/time/tick-sched.c +6 -1
index a4c4eda..9142591 100644
@@ -34,7 +34,7 @@
 /*
  * Per cpu nohz control structure
  */
-DEFINE_PER_CPU(struct tick_sched, tick_cpu_sched);
+static DEFINE_PER_CPU(struct tick_sched, tick_cpu_sched);
 
 /*
  * The time, when the last jiffy update happened. Protected by jiffies_lock.
@@ -416,6 +416,11 @@ static int __init setup_tick_nohz(char *str)
 
 __setup("nohz=", setup_tick_nohz);
 
+int tick_nohz_tick_stopped(void)
+{
+	return __this_cpu_read(tick_cpu_sched.tick_stopped);
+}
+
 /**
  * tick_nohz_update_jiffies - update jiffies when idle was interrupted
  *
kernel/time/tick-sched.h new file +64 -0

64 lines not on this page · raw message

kernel/time/timer_list.c +1 -1
index 05aa559..e878c2e 100644
@@ -16,10 +16,10 @@
 #include <linux/sched.h>
 #include <linux/seq_file.h>
 #include <linux/kallsyms.h>
-#include <linux/tick.h>
 
 #include <asm/uaccess.h>
 
+#include "tick-internal.h"
 
 struct timer_list_iter {
 	int cpu;
#85 lore raw

PATCH 5/9 clockevents: Remove extra local_irq_save in clockevents_exchange_device()

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Called with clockevents_lock held and interrupts disabled already.

---
 kernel/time/clockevents.c |    7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
kernel/time/clockevents.c +2 -5
Index: linux/kernel/time/clockevents.c
===================================================================
@@ -491,14 +491,12 @@ void clockevents_handle_noop(struct cloc
  * @old:	device to release (can be NULL)
  * @new:	device to request (can be NULL)
  *
- * Called from the notifier chain. clockevents_lock is held already
+ * Called from various tick functions with clockevents_lock held and
+ * interrupts disabled.
  */
 void clockevents_exchange_device(struct clock_event_device *old,
 				 struct clock_event_device *new)
 {
-	unsigned long flags;
-
-	local_irq_save(flags);
 	/*
 	 * Caller releases a clock event device. We queue it into the
 	 * released list and do a notify add later.
@@ -514,7 +512,6 @@ void clockevents_exchange_device(struct
 		BUG_ON(new->mode != CLOCK_EVT_MODE_UNUSED);
 		clockevents_shutdown(new);
 	}
-	local_irq_restore(flags);
 }
 
 /**
#86 lore raw

[tip:timers/core] clockevents: Remove extra local_irq_save() in clockevents_exchange_device()

clockevents: Remove extra local_irq_save() in clockevents_exchange_device()
Commit-ID:  db6f672ef11d7a3c5aa128a3c3e57c92580a25f7
Gitweb:     http://git.kernel.org/tip/db6f672ef11d7a3c5aa128a3c3e57c92580a25f7
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Wed, 25 Mar 2015 13:08:27 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 1 Apr 2015 14:22:59 +0200

clockevents: Remove extra local_irq_save() in clockevents_exchange_device()

Called with 'clockevents_lock' held and interrupts disabled already.

---
 kernel/time/clockevents.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
kernel/time/clockevents.c +2 -5
index 3531bee..b730027 100644
@@ -595,14 +595,12 @@ void clockevents_handle_noop(struct clock_event_device *dev)
  * @old:	device to release (can be NULL)
  * @new:	device to request (can be NULL)
  *
- * Called from the notifier chain. clockevents_lock is held already
+ * Called from various tick functions with clockevents_lock held and
+ * interrupts disabled.
  */
 void clockevents_exchange_device(struct clock_event_device *old,
 				 struct clock_event_device *new)
 {
-	unsigned long flags;
-
-	local_irq_save(flags);
 	/*
 	 * Caller releases a clock event device. We queue it into the
 	 * released list and do a notify add later.
@@ -618,7 +616,6 @@ void clockevents_exchange_device(struct clock_event_device *old,
 		BUG_ON(new->state != CLOCK_EVT_STATE_DETACHED);
 		clockevents_shutdown(new);
 	}
-	local_irq_restore(flags);
 }
 
 /**
#87 lore raw

PATCH 6/9 clockevents: Make suspend/resume calls 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 suspend/resume() calls and invoke them directly from the call sites.

No locking required at this point because these calls happen with interrupts disabled and a single cpu online.

[ rjw: Rebased on top of 4.0-rc5 ]
---
 arch/x86/xen/suspend.c      |   11 ++++-------
 include/linux/clockchips.h  |    2 --
 include/linux/tick.h        |    3 +++
 kernel/time/clockevents.c   |    9 ---------
 kernel/time/tick-common.c   |   26 +++++++++++++++++++++++---
 kernel/time/tick-internal.h |    3 ++-
 kernel/time/timekeeping.c   |    6 ++----
 7 files changed, 34 insertions(+), 26 deletions(-)
arch/x86/xen/suspend.c +4 -7
Index: linux-pm/arch/x86/xen/suspend.c
===================================================================
@@ -1,5 +1,5 @@
 #include <linux/types.h>
-#include <linux/clockchips.h>
+#include <linux/tick.h>
 
 #include <xen/interface/xen.h>
 #include <xen/grant_table.h>
@@ -81,17 +81,14 @@ void xen_arch_post_suspend(int cancelled
 
 static void xen_vcpu_notify_restore(void *data)
 {
-	unsigned long reason = (unsigned long)data;
-
 	/* Boot processor notified via generic timekeeping_resume() */
-	if ( smp_processor_id() == 0)
+	if (smp_processor_id() == 0)
 		return;
 
-	clockevents_notify(reason, NULL);
+	tick_resume();
 }
 
 void xen_arch_resume(void)
 {
-	on_each_cpu(xen_vcpu_notify_restore,
-		    (void *)CLOCK_EVT_NOTIFY_RESUME, 1);
+	on_each_cpu(xen_vcpu_notify_restore, NULL, 1);
 }
include/linux/clockchips.h +0 -2
Index: linux-pm/include/linux/clockchips.h
===================================================================
@@ -16,8 +16,6 @@ enum clock_event_nofitiers {
 	CLOCK_EVT_NOTIFY_BROADCAST_FORCE,
 	CLOCK_EVT_NOTIFY_BROADCAST_ENTER,
 	CLOCK_EVT_NOTIFY_BROADCAST_EXIT,
-	CLOCK_EVT_NOTIFY_SUSPEND,
-	CLOCK_EVT_NOTIFY_RESUME,
 	CLOCK_EVT_NOTIFY_CPU_DYING,
 	CLOCK_EVT_NOTIFY_CPU_DEAD,
 };
include/linux/tick.h +3 -0
Index: linux-pm/include/linux/tick.h
===================================================================
@@ -29,10 +29,13 @@ extern struct tick_device *tick_get_devi
 extern void __init tick_init(void);
 extern void tick_freeze(void);
 extern void tick_unfreeze(void);
+/* Should be core only, but XEN resume magic abuses this interface */
+extern void tick_resume(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_resume(void) { }
 #endif /* !CONFIG_GENERIC_CLOCKEVENTS */
 
 #ifdef CONFIG_TICK_ONESHOT
kernel/time/clockevents.c +0 -9
Index: linux-pm/kernel/time/clockevents.c
===================================================================
@@ -566,15 +566,6 @@ int clockevents_notify(unsigned long rea
 		tick_handover_do_timer(arg);
 		break;
 
-	case CLOCK_EVT_NOTIFY_SUSPEND:
-		tick_suspend();
-		tick_suspend_broadcast();
-		break;
-
-	case CLOCK_EVT_NOTIFY_RESUME:
-		tick_resume();
-		break;
-
 	case CLOCK_EVT_NOTIFY_CPU_DEAD:
 		tick_shutdown_broadcast_oneshot(arg);
 		tick_shutdown_broadcast(arg);
kernel/time/tick-common.c +23 -3
Index: linux-pm/kernel/time/tick-common.c
===================================================================
@@ -372,18 +372,39 @@ void tick_shutdown(unsigned int *cpup)
 	}
 }
 
+/**
+ * tick_suspend - Suspend the tick and the broadcast device
+ *
+ * Called from syscore_suspend() via timekeeping_suspend with only one
+ * CPU online and interrupts disabled or from tick_unfreeze() under
+ * tick_freeze_lock.
+ *
+ * No locks required. Nothing can change the per cpu device.
+ */
 void tick_suspend(void)
 {
 	struct tick_device *td = this_cpu_ptr(&tick_cpu_device);
 
 	clockevents_shutdown(td->evtdev);
+	tick_suspend_broadcast();
 }
 
+/**
+ * tick_resume - Resume the tick and the broadcast device
+ *
+ * Called from syscore_resume() via timekeeping_resume with only one
+ * CPU online and interrupts disabled or from tick_unfreeze() under
+ * tick_freeze_lock.
+ *
+ * No locks required. Nothing can change the per cpu device.
+ */
 void tick_resume(void)
 {
-	struct tick_device *td = this_cpu_ptr(&tick_cpu_device);
-	int broadcast = tick_resume_broadcast();
+	struct tick_device *td;
+	int broadcast;
 
+	broadcast = tick_resume_broadcast();
+	td = this_cpu_ptr(&tick_cpu_device);
 	clockevents_set_mode(td->evtdev, CLOCK_EVT_MODE_RESUME);
 
 	if (!broadcast) {
@@ -420,7 +441,6 @@ void tick_freeze(void)
 		timekeeping_suspend_count++;
 	} else {
 		tick_suspend();
-		tick_suspend_broadcast();
 	}
 
 	raw_spin_unlock(&tick_freeze_lock);
kernel/time/tick-internal.h +2 -1
Index: linux-pm/kernel/time/tick-internal.h
===================================================================
@@ -23,7 +23,6 @@ extern void tick_check_new_device(struct
 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);
 extern bool tick_check_replacement(struct clock_event_device *curdev,
 				   struct clock_event_device *newdev);
 extern void tick_install_replacement(struct clock_event_device *dev);
@@ -41,6 +40,8 @@ extern void clockevents_exchange_device(
 extern void clockevents_handle_noop(struct clock_event_device *dev);
 extern int __clockevents_update_freq(struct clock_event_device *dev, u32 freq);
 extern ssize_t sysfs_get_uname(const char *buf, char *dst, size_t cnt);
+#else
+static inline void tick_suspend(void) { }
 #endif /* GENERIC_CLOCKEVENTS */
 
 /* Oneshot related functions */
kernel/time/timekeeping.c +2 -4
Index: linux-pm/kernel/time/timekeeping.c
===================================================================
@@ -1272,9 +1272,7 @@ void timekeeping_resume(void)
 
 	touch_softlockup_watchdog();
 
-	clockevents_notify(CLOCK_EVT_NOTIFY_RESUME, NULL);
-
-	/* Resume hrtimers */
+	tick_resume();
 	hrtimers_resume();
 }
 
@@ -1327,7 +1325,7 @@ int timekeeping_suspend(void)
 	write_seqcount_end(&tk_core.seq);
 	raw_spin_unlock_irqrestore(&timekeeper_lock, flags);
 
-	clockevents_notify(CLOCK_EVT_NOTIFY_SUSPEND, NULL);
+	tick_suspend();
 	clocksource_suspend();
 	clockevents_suspend();
 
#88 lore raw

[tip:timers/core] clockevents: Make suspend/resume calls explicit

clockevents: Make suspend/resume calls explicit
Commit-ID:  4ffee521f36390c7720d493591b764ca35c8030b
Gitweb:     http://git.kernel.org/tip/4ffee521f36390c7720d493591b764ca35c8030b
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Wed, 25 Mar 2015 13:09:16 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 1 Apr 2015 14:22:59 +0200

clockevents: Make suspend/resume calls 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 suspend/resume() calls and invoke them directly from the call sites.

No locking required at this point because these calls happen with interrupts disabled and a single cpu online.

[ Rebased on top of 4.0-rc5. ]
Cc Peter Zijlstra <[email protected]>
[ Rebased on top of latest timers/core. ]
---
 arch/x86/xen/suspend.c      | 11 ++++-------
 include/linux/clockchips.h  |  2 --
 include/linux/tick.h        |  3 +++
 kernel/time/clockevents.c   |  9 ---------
 kernel/time/tick-common.c   | 26 +++++++++++++++++++++++---
 kernel/time/tick-internal.h |  3 ++-
 kernel/time/timekeeping.c   |  6 ++----
 7 files changed, 34 insertions(+), 26 deletions(-)
arch/x86/xen/suspend.c +4 -7
index c4df9db..033e428 100644
@@ -1,5 +1,5 @@
 #include <linux/types.h>
-#include <linux/clockchips.h>
+#include <linux/tick.h>
 
 #include <xen/interface/xen.h>
 #include <xen/grant_table.h>
@@ -81,17 +81,14 @@ void xen_arch_post_suspend(int cancelled)
 
 static void xen_vcpu_notify_restore(void *data)
 {
-	unsigned long reason = (unsigned long)data;
-
 	/* Boot processor notified via generic timekeeping_resume() */
-	if ( smp_processor_id() == 0)
+	if (smp_processor_id() == 0)
 		return;
 
-	clockevents_notify(reason, NULL);
+	tick_resume();
 }
 
 void xen_arch_resume(void)
 {
-	on_each_cpu(xen_vcpu_notify_restore,
-		    (void *)CLOCK_EVT_NOTIFY_RESUME, 1);
+	on_each_cpu(xen_vcpu_notify_restore, NULL, 1);
 }
include/linux/clockchips.h +0 -2
index bc3af82..50ce975 100644
@@ -16,8 +16,6 @@ enum clock_event_nofitiers {
 	CLOCK_EVT_NOTIFY_BROADCAST_FORCE,
 	CLOCK_EVT_NOTIFY_BROADCAST_ENTER,
 	CLOCK_EVT_NOTIFY_BROADCAST_EXIT,
-	CLOCK_EVT_NOTIFY_SUSPEND,
-	CLOCK_EVT_NOTIFY_RESUME,
 	CLOCK_EVT_NOTIFY_CPU_DYING,
 	CLOCK_EVT_NOTIFY_CPU_DEAD,
 };
include/linux/tick.h +3 -0
index f9a2d26..7e07e0e 100644
@@ -29,10 +29,13 @@ extern struct tick_device *tick_get_device(int cpu);
 extern void __init tick_init(void);
 extern void tick_freeze(void);
 extern void tick_unfreeze(void);
+/* Should be core only, but XEN resume magic abuses this interface */
+extern void tick_resume(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_resume(void) { }
 #endif /* !CONFIG_GENERIC_CLOCKEVENTS */
 
 #ifdef CONFIG_TICK_ONESHOT
kernel/time/clockevents.c +0 -9
index b730027..7af6148 100644
@@ -670,15 +670,6 @@ int clockevents_notify(unsigned long reason, void *arg)
 		tick_handover_do_timer(arg);
 		break;
 
-	case CLOCK_EVT_NOTIFY_SUSPEND:
-		tick_suspend();
-		tick_suspend_broadcast();
-		break;
-
-	case CLOCK_EVT_NOTIFY_RESUME:
-		tick_resume();
-		break;
-
 	case CLOCK_EVT_NOTIFY_CPU_DEAD:
 		tick_shutdown_broadcast_oneshot(arg);
 		tick_shutdown_broadcast(arg);
kernel/time/tick-common.c +23 -3
index a5b8771..1a60c2a 100644
@@ -373,18 +373,39 @@ void tick_shutdown(unsigned int *cpup)
 	}
 }
 
+/**
+ * tick_suspend - Suspend the tick and the broadcast device
+ *
+ * Called from syscore_suspend() via timekeeping_suspend with only one
+ * CPU online and interrupts disabled or from tick_unfreeze() under
+ * tick_freeze_lock.
+ *
+ * No locks required. Nothing can change the per cpu device.
+ */
 void tick_suspend(void)
 {
 	struct tick_device *td = this_cpu_ptr(&tick_cpu_device);
 
 	clockevents_shutdown(td->evtdev);
+	tick_suspend_broadcast();
 }
 
+/**
+ * tick_resume - Resume the tick and the broadcast device
+ *
+ * Called from syscore_resume() via timekeeping_resume with only one
+ * CPU online and interrupts disabled or from tick_unfreeze() under
+ * tick_freeze_lock.
+ *
+ * No locks required. Nothing can change the per cpu device.
+ */
 void tick_resume(void)
 {
-	struct tick_device *td = this_cpu_ptr(&tick_cpu_device);
-	int broadcast = tick_resume_broadcast();
+	struct tick_device *td;
+	int broadcast;
 
+	broadcast = tick_resume_broadcast();
+	td = this_cpu_ptr(&tick_cpu_device);
 	clockevents_tick_resume(td->evtdev);
 
 	if (!broadcast) {
@@ -416,7 +437,6 @@ void tick_freeze(void)
 		timekeeping_suspend();
 	} else {
 		tick_suspend();
-		tick_suspend_broadcast();
 	}
 
 	raw_spin_unlock(&tick_freeze_lock);
kernel/time/tick-internal.h +2 -1
index dd2c45d..85a9571 100644
@@ -23,7 +23,6 @@ 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);
 extern bool tick_check_replacement(struct clock_event_device *curdev,
 				   struct clock_event_device *newdev);
 extern void tick_install_replacement(struct clock_event_device *dev);
@@ -42,6 +41,8 @@ extern void clockevents_exchange_device(struct clock_event_device *old,
 extern void clockevents_handle_noop(struct clock_event_device *dev);
 extern int __clockevents_update_freq(struct clock_event_device *dev, u32 freq);
 extern ssize_t sysfs_get_uname(const char *buf, char *dst, size_t cnt);
+#else
+static inline void tick_suspend(void) { }
 #endif /* GENERIC_CLOCKEVENTS */
 
 /* Oneshot related functions */
kernel/time/timekeeping.c +2 -4
index c3fcff0..5b12292 100644
@@ -1389,9 +1389,7 @@ void timekeeping_resume(void)
 
 	touch_softlockup_watchdog();
 
-	clockevents_notify(CLOCK_EVT_NOTIFY_RESUME, NULL);
-
-	/* Resume hrtimers */
+	tick_resume();
 	hrtimers_resume();
 }
 
@@ -1444,7 +1442,7 @@ int timekeeping_suspend(void)
 	write_seqcount_end(&tk_core.seq);
 	raw_spin_unlock_irqrestore(&timekeeper_lock, flags);
 
-	clockevents_notify(CLOCK_EVT_NOTIFY_SUSPEND, NULL);
+	tick_suspend();
 	clocksource_suspend();
 	clockevents_suspend();
 
#89 lore raw

PATCH 7/9 tick: Make tick_resume_broadcast_oneshot static

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Solely used in tick-broadcast.c and the return value is hardcoded 0. Make it static and void.

---
 kernel/time/tick-broadcast.c |    7 ++++---
 kernel/time/tick-internal.h  |    2 --
 2 files changed, 4 insertions(+), 5 deletions(-)
kernel/time/tick-broadcast.c +4 -3
Index: linux-pm/kernel/time/tick-broadcast.c
===================================================================
@@ -37,8 +37,10 @@ static int tick_broadcast_force;
 
 #ifdef CONFIG_TICK_ONESHOT
 static void tick_broadcast_clear_oneshot(int cpu);
+static void tick_resume_broadcast_oneshot(struct clock_event_device *bc);
 #else
 static inline void tick_broadcast_clear_oneshot(int cpu) { }
+static inline void tick_resume_broadcast_oneshot(struct clock_event_device *bc) { }
 #endif
 
 /*
@@ -475,7 +477,7 @@ int tick_resume_broadcast(void)
 			break;
 		case TICKDEV_MODE_ONESHOT:
 			if (!cpumask_empty(tick_broadcast_mask))
-				broadcast = tick_resume_broadcast_oneshot(bc);
+				tick_resume_broadcast_oneshot(bc);
 			break;
 		}
 	}
@@ -541,10 +543,9 @@ static int tick_broadcast_set_event(stru
 	return ret;
 }
 
-int tick_resume_broadcast_oneshot(struct clock_event_device *bc)
+static void tick_resume_broadcast_oneshot(struct clock_event_device *bc)
 {
 	clockevents_set_mode(bc, CLOCK_EVT_MODE_ONESHOT);
-	return 0;
 }
 
 /*
kernel/time/tick-internal.h +0 -2
Index: linux-pm/kernel/time/tick-internal.h
===================================================================
@@ -111,7 +111,6 @@ extern void tick_broadcast_setup_oneshot
 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_resume_broadcast_oneshot(struct clock_event_device *bc);
 extern int tick_broadcast_oneshot_active(void);
 extern void tick_check_oneshot_broadcast_this_cpu(void);
 bool tick_broadcast_oneshot_available(void);
@@ -121,7 +120,6 @@ static inline void tick_broadcast_setup_
 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_resume_broadcast_oneshot(struct clock_event_device *bc) { return 0; }
 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(); }
#90 lore raw

[tip:timers/core] tick: Make tick_resume_broadcast_oneshot() static

tick: Make tick_resume_broadcast_oneshot() static
Commit-ID:  080873ce2d1abd8c0a2b8c87bfa0762546a6b713
Gitweb:     http://git.kernel.org/tip/080873ce2d1abd8c0a2b8c87bfa0762546a6b713
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Wed, 25 Mar 2015 13:09:55 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 1 Apr 2015 14:22:59 +0200

tick: Make tick_resume_broadcast_oneshot() static

Solely used in tick-broadcast.c and the return value is hardcoded 0. Make it static and void.

---
 kernel/time/tick-broadcast.c | 7 ++++---
 kernel/time/tick-internal.h  | 2 --
 2 files changed, 4 insertions(+), 5 deletions(-)
kernel/time/tick-broadcast.c +4 -3
index f0f8ee9..60e6c23 100644
@@ -37,8 +37,10 @@ static int tick_broadcast_force;
 
 #ifdef CONFIG_TICK_ONESHOT
 static void tick_broadcast_clear_oneshot(int cpu);
+static void tick_resume_broadcast_oneshot(struct clock_event_device *bc);
 #else
 static inline void tick_broadcast_clear_oneshot(int cpu) { }
+static inline void tick_resume_broadcast_oneshot(struct clock_event_device *bc) { }
 #endif
 
 /*
@@ -475,7 +477,7 @@ int tick_resume_broadcast(void)
 			break;
 		case TICKDEV_MODE_ONESHOT:
 			if (!cpumask_empty(tick_broadcast_mask))
-				broadcast = tick_resume_broadcast_oneshot(bc);
+				tick_resume_broadcast_oneshot(bc);
 			break;
 		}
 	}
@@ -541,10 +543,9 @@ static int tick_broadcast_set_event(struct clock_event_device *bc, int cpu,
 	return ret;
 }
 
-int tick_resume_broadcast_oneshot(struct clock_event_device *bc)
+static void tick_resume_broadcast_oneshot(struct clock_event_device *bc)
 {
 	clockevents_set_state(bc, CLOCK_EVT_STATE_ONESHOT);
-	return 0;
 }
 
 /*
kernel/time/tick-internal.h +0 -2
index 85a9571..5c9f0ee 100644
@@ -112,7 +112,6 @@ 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_resume_broadcast_oneshot(struct clock_event_device *bc);
 extern int tick_broadcast_oneshot_active(void);
 extern void tick_check_oneshot_broadcast_this_cpu(void);
 bool tick_broadcast_oneshot_available(void);
@@ -122,7 +121,6 @@ static inline void tick_broadcast_setup_oneshot(struct clock_event_device *bc) {
 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_resume_broadcast_oneshot(struct clock_event_device *bc) { return 0; }
 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(); }
#91 lore raw

PATCH 8/9 tick/xen: Provide and use tick_suspend_local() and tick_resume_local()

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Xen calls on every cpu into tick_resume() which is just wrong. tick_resume() is for the syscore global suspend/resume invocation. What XEN really wants is a per cpu local resume function.

Provide a tick_resume_local() function and use it in XEN.

Also provide a complementary tick_suspend_local() and modify tick_unfreeze() and tick_freeze(), respectively, to use the new local tick resume/suspend functions.

Cc Konrad Rzeszutek Wilk <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc David Vrabel <[email protected]>
[ rjw: Combined two patches, rebased, modified subject/changelog ]
---
 arch/x86/xen/suspend.c       |    2 -
 include/linux/tick.h         |    6 ++--
 kernel/time/tick-broadcast.c |   24 ++++++++++++------
 kernel/time/tick-common.c    |   57 +++++++++++++++++++++++++++++--------------
 kernel/time/tick-internal.h  |    8 ++++--
 5 files changed, 66 insertions(+), 31 deletions(-)
arch/x86/xen/suspend.c +1 -1
Index: linux-pm/arch/x86/xen/suspend.c
===================================================================
@@ -85,7 +85,7 @@ static void xen_vcpu_notify_restore(void
 	if (smp_processor_id() == 0)
 		return;
 
-	tick_resume();
+	tick_resume_local();
 }
 
 void xen_arch_resume(void)
include/linux/tick.h +3 -3
Index: linux-pm/include/linux/tick.h
===================================================================
@@ -29,13 +29,13 @@ extern struct tick_device *tick_get_devi
 extern void __init tick_init(void);
 extern void tick_freeze(void);
 extern void tick_unfreeze(void);
-/* Should be core only, but XEN resume magic abuses this interface */
-extern void tick_resume(void);
+/* Should be core only, but XEN resume magic requires this */
+extern void tick_resume_local(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_resume(void) { }
+static inline void tick_resume_local(void) { }
 #endif /* !CONFIG_GENERIC_CLOCKEVENTS */
 
 #ifdef CONFIG_TICK_ONESHOT
kernel/time/tick-broadcast.c +17 -7
Index: linux-pm/kernel/time/tick-broadcast.c
===================================================================
@@ -455,11 +455,26 @@ void tick_suspend_broadcast(void)
 	raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags);
 }
 
-int tick_resume_broadcast(void)
+/*
+ * This is called from tick_resume_local() on a resuming CPU. That's
+ * called from the core resume function, tick_unfreeze() and the magic XEN
+ * resume hackery.
+ *
+ * In none of these cases the broadcast device mode can change and the
+ * bit of the resuming CPU in the broadcast mask is safe as well.
+ */
+bool tick_resume_check_broadcast(void)
+{
+	if (tick_broadcast_device.mode == TICKDEV_MODE_ONESHOT)
+		return false;
+	else
+		return cpumask_test_cpu(smp_processor_id(), tick_broadcast_mask);
+}
+
+void tick_resume_broadcast(void)
 {
 	struct clock_event_device *bc;
 	unsigned long flags;
-	int broadcast = 0;
 
 	raw_spin_lock_irqsave(&tick_broadcast_lock, flags);
 
@@ -472,8 +487,6 @@ int tick_resume_broadcast(void)
 		case TICKDEV_MODE_PERIODIC:
 			if (!cpumask_empty(tick_broadcast_mask))
 				tick_broadcast_start_periodic(bc);
-			broadcast = cpumask_test_cpu(smp_processor_id(),
-						     tick_broadcast_mask);
 			break;
 		case TICKDEV_MODE_ONESHOT:
 			if (!cpumask_empty(tick_broadcast_mask))
@@ -482,11 +495,8 @@ int tick_resume_broadcast(void)
 		}
 	}
 	raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags);
-
-	return broadcast;
 }
 
-
 #ifdef CONFIG_TICK_ONESHOT
 
 static cpumask_var_t tick_broadcast_oneshot_mask;
kernel/time/tick-common.c +39 -18

99 lines not on this page · raw message

kernel/time/tick-internal.h +6 -2
Index: linux-pm/kernel/time/tick-internal.h
===================================================================
@@ -23,6 +23,7 @@ extern void tick_check_new_device(struct
 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);
 extern bool tick_check_replacement(struct clock_event_device *curdev,
 				   struct clock_event_device *newdev);
 extern void tick_install_replacement(struct clock_event_device *dev);
@@ -42,6 +43,7 @@ extern int __clockevents_update_freq(str
 extern ssize_t sysfs_get_uname(const char *buf, char *dst, size_t cnt);
 #else
 static inline void tick_suspend(void) { }
+static inline void tick_resume(void) { }
 #endif /* GENERIC_CLOCKEVENTS */
 
 /* Oneshot related functions */
@@ -80,7 +82,8 @@ extern int tick_is_broadcast_device(stru
 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 int tick_resume_broadcast(void);
+extern void tick_resume_broadcast(void);
+extern bool tick_resume_check_broadcast(void);
 extern void tick_broadcast_init(void);
 extern void tick_set_periodic_handler(struct clock_event_device *dev, int broadcast);
 extern int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq);
@@ -94,7 +97,8 @@ static inline void tick_do_periodic_broa
 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 int tick_resume_broadcast(void) { return 0; }
+static inline void tick_resume_broadcast(void) { }
+static inline bool tick_resume_check_broadcast(void) { return false; }
 static inline void tick_broadcast_init(void) { }
 static inline int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq) { return -ENODEV; }
 
#92 lore raw

Re: [PATCH 08/09] tick/xen: Provide and use tick_suspend_local() and tick_resume_local()

Quoted 31 lines · Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Xen calls on every cpu into tick_resume() which is just wrong. tick_resume() is for the syscore global suspend/resume invocation. What XEN really wants is a per cpu local resume function.

Provide a tick_resume_local() function and use it in XEN.

Also provide a complementary tick_suspend_local() and modify tick_unfreeze() and tick_freeze(), respectively, to use the new local tick resume/suspend functions.

Cc Konrad Rzeszutek Wilk <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc David Vrabel <[email protected]>
[ rjw: Combined two patches, rebased, modified subject/changelog ]
---
 arch/x86/xen/suspend.c       |    2 -
 include/linux/tick.h         |    6 ++--
 kernel/time/tick-broadcast.c |   24 ++++++++++++------
 kernel/time/tick-common.c    |   57 +++++++++++++++++++++++++++++--------------
 kernel/time/tick-internal.h  |    8 ++++--
 5 files changed, 66 insertions(+), 31 deletions(-)

Index: linux-pm/arch/x86/xen/suspend.c
===================================================================

arch/x86/xen/suspend.c static void xen_vcpu_notify_restore(void · line 88

Quoted 5 lines
arch/x86/xen/suspend.c +1 -1
@@ -85,7 +85,7 @@ static void xen_vcpu_notify_restore(void
 	if (smp_processor_id() == 0)
 		return;
 
-	tick_resume();
+	tick_resume_local();

I am looking at Linus's tree and I see:

82 static void xen_vcpu_notify_restore(void *data)
83 {
84 unsigned long reason = (unsigned long)data;
85
86 /* Boot processor notified via generic timekeeping_resume() */
87 if ( smp_processor_id() == 0)
88 return;
89
90 clockevents_notify(reason, NULL);
91 }

So there must be another patch that altered the clockevents_notify?

Is there an git tree with all of these patches?

Quoted 226 lines
arch/x86/xen/suspend.c +0 -0
 }
 
 void xen_arch_resume(void)

Index: linux-pm/include/linux/tick.h
===================================================================

include/linux/tick.h +3 -3
@@ -29,13 +29,13 @@ extern struct tick_device *tick_get_devi
 extern void __init tick_init(void);
 extern void tick_freeze(void);
 extern void tick_unfreeze(void);
-/* Should be core only, but XEN resume magic abuses this interface */
-extern void tick_resume(void);
+/* Should be core only, but XEN resume magic requires this */
+extern void tick_resume_local(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_resume(void) { }
+static inline void tick_resume_local(void) { }
 #endif /* !CONFIG_GENERIC_CLOCKEVENTS */
 
 #ifdef CONFIG_TICK_ONESHOT

Index: linux-pm/kernel/time/tick-broadcast.c
===================================================================

kernel/time/tick-broadcast.c +17 -7
@@ -455,11 +455,26 @@ void tick_suspend_broadcast(void)
 	raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags);
 }
 
-int tick_resume_broadcast(void)
+/*
+ * This is called from tick_resume_local() on a resuming CPU. That's
+ * called from the core resume function, tick_unfreeze() and the magic XEN
+ * resume hackery.
+ *
+ * In none of these cases the broadcast device mode can change and the
+ * bit of the resuming CPU in the broadcast mask is safe as well.
+ */
+bool tick_resume_check_broadcast(void)
+{
+	if (tick_broadcast_device.mode == TICKDEV_MODE_ONESHOT)
+		return false;
+	else
+		return cpumask_test_cpu(smp_processor_id(), tick_broadcast_mask);
+}
+
+void tick_resume_broadcast(void)
 {
 	struct clock_event_device *bc;
 	unsigned long flags;
-	int broadcast = 0;
 
 	raw_spin_lock_irqsave(&tick_broadcast_lock, flags);
 
@@ -472,8 +487,6 @@ int tick_resume_broadcast(void)
 		case TICKDEV_MODE_PERIODIC:
 			if (!cpumask_empty(tick_broadcast_mask))
 				tick_broadcast_start_periodic(bc);
-			broadcast = cpumask_test_cpu(smp_processor_id(),
-						     tick_broadcast_mask);
 			break;
 		case TICKDEV_MODE_ONESHOT:
 			if (!cpumask_empty(tick_broadcast_mask))
@@ -482,11 +495,8 @@ int tick_resume_broadcast(void)
 		}
 	}
 	raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags);
-
-	return broadcast;
 }
 
-
 #ifdef CONFIG_TICK_ONESHOT
 
 static cpumask_var_t tick_broadcast_oneshot_mask;

Index: linux-pm/kernel/time/tick-common.c
===================================================================

kernel/time/tick-common.c +39 -18
@@ -373,40 +373,32 @@ void tick_shutdown(unsigned int *cpup)
 }
 
 /**
- * tick_suspend - Suspend the tick and the broadcast device
+ * tick_suspend_local - Suspend the local tick device
  *
- * Called from syscore_suspend() via timekeeping_suspend with only one
- * CPU online and interrupts disabled or from tick_unfreeze() under
- * tick_freeze_lock.
+ * Called from the local cpu for freeze with interrupts disabled.
  *
  * No locks required. Nothing can change the per cpu device.
  */
-void tick_suspend(void)
+static void tick_suspend_local(void)
 {
 	struct tick_device *td = this_cpu_ptr(&tick_cpu_device);
 
 	clockevents_shutdown(td->evtdev);
-	tick_suspend_broadcast();
 }
 
 /**
- * tick_resume - Resume the tick and the broadcast device
+ * tick_resume_local - Resume the local tick device
  *
- * Called from syscore_resume() via timekeeping_resume with only one
- * CPU online and interrupts disabled or from tick_unfreeze() under
- * tick_freeze_lock.
+ * Called from the local CPU for unfreeze or XEN resume magic.
  *
  * No locks required. Nothing can change the per cpu device.
  */
-void tick_resume(void)
+void tick_resume_local(void)
 {
-	struct tick_device *td;
-	int broadcast;
+	struct tick_device *td = this_cpu_ptr(&tick_cpu_device);
+	bool broadcast = tick_resume_check_broadcast();
 
-	broadcast = tick_resume_broadcast();
-	td = this_cpu_ptr(&tick_cpu_device);
 	clockevents_set_mode(td->evtdev, CLOCK_EVT_MODE_RESUME);
-
 	if (!broadcast) {
 		if (td->mode == TICKDEV_MODE_PERIODIC)
 			tick_setup_periodic(td->evtdev, 0);
@@ -415,6 +407,35 @@ void tick_resume(void)
 	}
 }
 
+/**
+ * tick_suspend - Suspend the tick and the broadcast device
+ *
+ * Called from syscore_suspend() via timekeeping_suspend with only one
+ * CPU online and interrupts disabled or from tick_unfreeze() under
+ * tick_freeze_lock.
+ *
+ * No locks required. Nothing can change the per cpu device.
+ */
+void tick_suspend(void)
+{
+	tick_suspend_local();
+	tick_suspend_broadcast();
+}
+
+/**
+ * tick_resume - Resume the tick and the broadcast device
+ *
+ * Called from syscore_resume() via timekeeping_resume with only one
+ * CPU online and interrupts disabled.
+ *
+ * No locks required. Nothing can change the per cpu device.
+ */
+void tick_resume(void)
+{
+	tick_resume_broadcast();
+	tick_resume_local();
+}
+
 static DEFINE_RAW_SPINLOCK(tick_freeze_lock);
 static unsigned int tick_freeze_depth;
 
@@ -440,7 +461,7 @@ void tick_freeze(void)
 		timekeeping_suspend();
 		timekeeping_suspend_count++;
 	} else {
-		tick_suspend();
+		tick_suspend_local();
 	}
 
 	raw_spin_unlock(&tick_freeze_lock);
@@ -465,7 +486,7 @@ void tick_unfreeze(void)
 			smp_processor_id(), tick_freeze_depth,
 			timekeeping_suspend_count);
 	} else {
-		tick_resume();
+		tick_resume_local();
 	}
 	tick_freeze_depth--;
 

Index: linux-pm/kernel/time/tick-internal.h
===================================================================

kernel/time/tick-internal.h +6 -2
@@ -23,6 +23,7 @@ extern void tick_check_new_device(struct
 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);
 extern bool tick_check_replacement(struct clock_event_device *curdev,
 				   struct clock_event_device *newdev);
 extern void tick_install_replacement(struct clock_event_device *dev);
@@ -42,6 +43,7 @@ extern int __clockevents_update_freq(str
 extern ssize_t sysfs_get_uname(const char *buf, char *dst, size_t cnt);
 #else
 static inline void tick_suspend(void) { }
+static inline void tick_resume(void) { }
 #endif /* GENERIC_CLOCKEVENTS */
 
 /* Oneshot related functions */
@@ -80,7 +82,8 @@ extern int tick_is_broadcast_device(stru
 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 int tick_resume_broadcast(void);
+extern void tick_resume_broadcast(void);
+extern bool tick_resume_check_broadcast(void);
 extern void tick_broadcast_init(void);
 extern void tick_set_periodic_handler(struct clock_event_device *dev, int broadcast);
 extern int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq);
@@ -94,7 +97,8 @@ static inline void tick_do_periodic_broa
 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 int tick_resume_broadcast(void) { return 0; }
+static inline void tick_resume_broadcast(void) { }
+static inline bool tick_resume_check_broadcast(void) { return false; }
 static inline void tick_broadcast_init(void) { }
 static inline int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq) { return -ENODEV; }
 
#93 lore raw

Re: [PATCH 08/09] tick/xen: Provide and use tick_suspend_local() and tick_resume_local()

Quoted 51 lines · Konrad Rzeszutek Wilk
Quoted 31 lines · Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Xen calls on every cpu into tick_resume() which is just wrong. tick_resume() is for the syscore global suspend/resume invocation. What XEN really wants is a per cpu local resume function.

Provide a tick_resume_local() function and use it in XEN.

Also provide a complementary tick_suspend_local() and modify tick_unfreeze() and tick_freeze(), respectively, to use the new local tick resume/suspend functions.

Cc Konrad Rzeszutek Wilk <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc David Vrabel <[email protected]>
[ rjw: Combined two patches, rebased, modified subject/changelog ]
---
 arch/x86/xen/suspend.c       |    2 -
 include/linux/tick.h         |    6 ++--
 kernel/time/tick-broadcast.c |   24 ++++++++++++------
 kernel/time/tick-common.c    |   57 +++++++++++++++++++++++++++++--------------
 kernel/time/tick-internal.h  |    8 ++++--
 5 files changed, 66 insertions(+), 31 deletions(-)

Index: linux-pm/arch/x86/xen/suspend.c
===================================================================

arch/x86/xen/suspend.c static void xen_vcpu_notify_restore(void · line 88

Quoted 5 lines
arch/x86/xen/suspend.c +1 -1
@@ -85,7 +85,7 @@ static void xen_vcpu_notify_restore(void
 	if (smp_processor_id() == 0)
 		return;
 
-	tick_resume();
+	tick_resume_local();

I am looking at Linus's tree and I see:

82 static void xen_vcpu_notify_restore(void *data)
83 {
84 unsigned long reason = (unsigned long)data;
85
86 /* Boot processor notified via generic timekeeping_resume() */
87 if ( smp_processor_id() == 0)
88 return;
89
90 clockevents_notify(reason, NULL);
91 }

Quoted 1 line

So there must be another patch that altered the clockevents_notify?

Yes, there is. It is the [06/09] in this series
(https://patchwork.kernel.org/patch/6090631/).

I should have CCed it to you too, sorry about that.

Quoted 1 line

Is there an git tree with all of these patches?

Not yet, but they all are in the linux-pm patchwork at

https://patchwork.kernel.org/project/linux-pm/list/

I can create a branch in the linux-pm.git tree for them if that helps, please let me know.

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

Re: [PATCH 08/09] tick/xen: Provide and use tick_suspend_local() and tick_resume_local()

Quoted 52 lines · Rafael J. Wysocki
Quoted 51 lines · Konrad Rzeszutek Wilk
Quoted 31 lines · Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Xen calls on every cpu into tick_resume() which is just wrong. tick_resume() is for the syscore global suspend/resume invocation. What XEN really wants is a per cpu local resume function.

Provide a tick_resume_local() function and use it in XEN.

Also provide a complementary tick_suspend_local() and modify tick_unfreeze() and tick_freeze(), respectively, to use the new local tick resume/suspend functions.

Cc Konrad Rzeszutek Wilk <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc David Vrabel <[email protected]>
[ rjw: Combined two patches, rebased, modified subject/changelog ]
---
 arch/x86/xen/suspend.c       |    2 -
 include/linux/tick.h         |    6 ++--
 kernel/time/tick-broadcast.c |   24 ++++++++++++------
 kernel/time/tick-common.c    |   57 +++++++++++++++++++++++++++++--------------
 kernel/time/tick-internal.h  |    8 ++++--
 5 files changed, 66 insertions(+), 31 deletions(-)

Index: linux-pm/arch/x86/xen/suspend.c
===================================================================

arch/x86/xen/suspend.c static void xen_vcpu_notify_restore(void · line 88

Quoted 5 lines
arch/x86/xen/suspend.c +1 -1
@@ -85,7 +85,7 @@ static void xen_vcpu_notify_restore(void
 	if (smp_processor_id() == 0)
 		return;
 
-	tick_resume();
+	tick_resume_local();

I am looking at Linus's tree and I see:

82 static void xen_vcpu_notify_restore(void *data)
83 {
84 unsigned long reason = (unsigned long)data;
85
86 /* Boot processor notified via generic timekeeping_resume() */
87 if ( smp_processor_id() == 0)
88 return;
89
90 clockevents_notify(reason, NULL);
91 }

Quoted 6 lines
Quoted 1 line

So there must be another patch that altered the clockevents_notify?

Yes, there is. It is the [06/09] in this series
(https://patchwork.kernel.org/patch/6090631/).

I should have CCed it to you too, sorry about that.

That is alright.

Quoted 9 lines
Quoted 2 lines

Is there an git tree with all of these patches?

Not yet, but they all are in the linux-pm patchwork at

https://patchwork.kernel.org/project/linux-pm/list/

I can create a branch in the linux-pm.git tree for them if that helps, please let me know.

If it is not too much trouble..

Thank you.

Quoted 5 lines
Signature · 3 lines
-- 
I speak only for myself.
Rafael J. Wysocki, Intel Open Source Technology Center.
#95 lore raw

Re: [PATCH 08/09] tick/xen: Provide and use tick_suspend_local() and tick_resume_local()

Quoted 64 lines · Konrad Rzeszutek Wilk
Quoted 52 lines · Rafael J. Wysocki
Quoted 51 lines · Konrad Rzeszutek Wilk
Quoted 31 lines · Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Xen calls on every cpu into tick_resume() which is just wrong. tick_resume() is for the syscore global suspend/resume invocation. What XEN really wants is a per cpu local resume function.

Provide a tick_resume_local() function and use it in XEN.

Also provide a complementary tick_suspend_local() and modify tick_unfreeze() and tick_freeze(), respectively, to use the new local tick resume/suspend functions.

Cc Konrad Rzeszutek Wilk <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc David Vrabel <[email protected]>
[ rjw: Combined two patches, rebased, modified subject/changelog ]
---
 arch/x86/xen/suspend.c       |    2 -
 include/linux/tick.h         |    6 ++--
 kernel/time/tick-broadcast.c |   24 ++++++++++++------
 kernel/time/tick-common.c    |   57 +++++++++++++++++++++++++++++--------------
 kernel/time/tick-internal.h  |    8 ++++--
 5 files changed, 66 insertions(+), 31 deletions(-)

Index: linux-pm/arch/x86/xen/suspend.c
===================================================================

arch/x86/xen/suspend.c static void xen_vcpu_notify_restore(void · line 88

Quoted 5 lines
arch/x86/xen/suspend.c +1 -1
@@ -85,7 +85,7 @@ static void xen_vcpu_notify_restore(void
 	if (smp_processor_id() == 0)
 		return;
 
-	tick_resume();
+	tick_resume_local();

I am looking at Linus's tree and I see:

82 static void xen_vcpu_notify_restore(void *data)
83 {
84 unsigned long reason = (unsigned long)data;
85
86 /* Boot processor notified via generic timekeeping_resume() */
87 if ( smp_processor_id() == 0)
88 return;
89
90 clockevents_notify(reason, NULL);
91 }

Quoted 6 lines
Quoted 1 line

So there must be another patch that altered the clockevents_notify?

Yes, there is. It is the [06/09] in this series
(https://patchwork.kernel.org/patch/6090631/).

I should have CCed it to you too, sorry about that.

That is alright.

Quoted 3 lines
Quoted 2 lines

Is there an git tree with all of these patches?

Quoted 8 lines
Quoted 6 lines

Not yet, but they all are in the linux-pm patchwork at

https://patchwork.kernel.org/project/linux-pm/list/

I can create a branch in the linux-pm.git tree for them if that helps, please let me know.

If it is not too much trouble..

Done:

git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git tick-pm

Also turns out that the $subject patch was actually on top of some debug stuff I have in tick_freeze()/tick_unfreeze(), so here goes a cleaned-up updated.

---
From: Thomas Gleixner <[email protected]>
Subject: tick/xen: Provide and use tick_suspend_local() and tick_resume_local()

Xen calls on every cpu into tick_resume() which is just wrong. tick_resume() is for the syscore global suspend/resume invocation. What XEN really wants is a per cpu local resume function.

Provide a tick_resume_local() function and use it in XEN.

Also provide a complementary tick_suspend_local() and modify tick_unfreeze() and tick_freeze(), respectively, to use the new local tick resume/suspend functions.

Cc Konrad Rzeszutek Wilk <[email protected]>
Cc Boris Ostrovsky <[email protected]>
Cc David Vrabel <[email protected]>
[ rjw: Combined two patches, rebased, modified subject/changelog ]
---
 arch/x86/xen/suspend.c       |    2 -
 include/linux/tick.h         |    6 ++--
 kernel/time/tick-broadcast.c |   24 +++++++++++-----
 kernel/time/tick-common.c    |   62 ++++++++++++++++++++++++++++---------------
 kernel/time/tick-internal.h  |    8 ++++-
 5 files changed, 68 insertions(+), 34 deletions(-)
arch/x86/xen/suspend.c +1 -1
Index: linux-pm/arch/x86/xen/suspend.c
===================================================================
@@ -85,7 +85,7 @@ static void xen_vcpu_notify_restore(void
 	if (smp_processor_id() == 0)
 		return;
 
-	tick_resume();
+	tick_resume_local();
 }
 
 void xen_arch_resume(void)
include/linux/tick.h +3 -3
Index: linux-pm/include/linux/tick.h
===================================================================
@@ -29,13 +29,13 @@ extern struct tick_device *tick_get_devi
 extern void __init tick_init(void);
 extern void tick_freeze(void);
 extern void tick_unfreeze(void);
-/* Should be core only, but XEN resume magic abuses this interface */
-extern void tick_resume(void);
+/* Should be core only, but XEN resume magic requires this */
+extern void tick_resume_local(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_resume(void) { }
+static inline void tick_resume_local(void) { }
 #endif /* !CONFIG_GENERIC_CLOCKEVENTS */
 
 #ifdef CONFIG_TICK_ONESHOT
kernel/time/tick-broadcast.c +17 -7
Index: linux-pm/kernel/time/tick-broadcast.c
===================================================================
@@ -455,11 +455,26 @@ void tick_suspend_broadcast(void)
 	raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags);
 }
 
-int tick_resume_broadcast(void)
+/*
+ * This is called from tick_resume_local() on a resuming CPU. That's
+ * called from the core resume function, tick_unfreeze() and the magic XEN
+ * resume hackery.
+ *
+ * In none of these cases the broadcast device mode can change and the
+ * bit of the resuming CPU in the broadcast mask is safe as well.
+ */
+bool tick_resume_check_broadcast(void)
+{
+	if (tick_broadcast_device.mode == TICKDEV_MODE_ONESHOT)
+		return false;
+	else
+		return cpumask_test_cpu(smp_processor_id(), tick_broadcast_mask);
+}
+
+void tick_resume_broadcast(void)
 {
 	struct clock_event_device *bc;
 	unsigned long flags;
-	int broadcast = 0;
 
 	raw_spin_lock_irqsave(&tick_broadcast_lock, flags);
 
@@ -472,8 +487,6 @@ int tick_resume_broadcast(void)
 		case TICKDEV_MODE_PERIODIC:
 			if (!cpumask_empty(tick_broadcast_mask))
 				tick_broadcast_start_periodic(bc);
-			broadcast = cpumask_test_cpu(smp_processor_id(),
-						     tick_broadcast_mask);
 			break;
 		case TICKDEV_MODE_ONESHOT:
 			if (!cpumask_empty(tick_broadcast_mask))
@@ -482,11 +495,8 @@ int tick_resume_broadcast(void)
 		}
 	}
 	raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags);
-
-	return broadcast;
 }
 
-
 #ifdef CONFIG_TICK_ONESHOT
 
 static cpumask_var_t tick_broadcast_oneshot_mask;
kernel/time/tick-common.c +41 -21

105 lines not on this page · raw message

kernel/time/tick-internal.h +6 -2
Index: linux-pm/kernel/time/tick-internal.h
===================================================================
@@ -23,6 +23,7 @@ extern void tick_check_new_device(struct
 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);
 extern bool tick_check_replacement(struct clock_event_device *curdev,
 				   struct clock_event_device *newdev);
 extern void tick_install_replacement(struct clock_event_device *dev);
@@ -42,6 +43,7 @@ extern int __clockevents_update_freq(str
 extern ssize_t sysfs_get_uname(const char *buf, char *dst, size_t cnt);
 #else
 static inline void tick_suspend(void) { }
+static inline void tick_resume(void) { }
 #endif /* GENERIC_CLOCKEVENTS */
 
 /* Oneshot related functions */
@@ -80,7 +82,8 @@ extern int tick_is_broadcast_device(stru
 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 int tick_resume_broadcast(void);
+extern void tick_resume_broadcast(void);
+extern bool tick_resume_check_broadcast(void);
 extern void tick_broadcast_init(void);
 extern void tick_set_periodic_handler(struct clock_event_device *dev, int broadcast);
 extern int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq);
@@ -94,7 +97,8 @@ static inline void tick_do_periodic_broa
 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 int tick_resume_broadcast(void) { return 0; }
+static inline void tick_resume_broadcast(void) { }
+static inline bool tick_resume_check_broadcast(void) { return false; }
 static inline void tick_broadcast_init(void) { }
 static inline int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq) { return -ENODEV; }
 
#96 lore raw

[tip:timers/core] tick/xen: Provide and use tick_suspend_local() and tick_resume_local()

In reply to Rafael J. Wysocki
tick/xen: Provide and use tick_suspend_local() and tick_resume_local()
Commit-ID:  f46481d0a7cb942b84145acb80ad43bdb1ff8eb4
Gitweb:     http://git.kernel.org/tip/f46481d0a7cb942b84145acb80ad43bdb1ff8eb4
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Wed, 25 Mar 2015 13:11:04 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 1 Apr 2015 14:23:00 +0200

tick/xen: Provide and use tick_suspend_local() and tick_resume_local()

Xen calls on every cpu into tick_resume() which is just wrong. tick_resume() is for the syscore global suspend/resume invocation. What XEN really wants is a per cpu local resume function.

Provide a tick_resume_local() function and use it in XEN.

Also provide a complementary tick_suspend_local() and modify tick_unfreeze() and tick_freeze(), respectively, to use the new local tick resume/suspend functions.

[ Combined two patches, rebased, modified subject/changelog. ]
Cc Boris Ostrovsky <[email protected]>
Cc David Vrabel <[email protected]>
Cc Konrad Rzeszutek Wilk <[email protected]>
Cc Peter Zijlstra <[email protected]>
[ Merged to latest timers/core. ]
---
 arch/x86/xen/suspend.c       |  2 +-
 include/linux/tick.h         |  6 ++---
 kernel/time/tick-broadcast.c | 24 +++++++++++++------
 kernel/time/tick-common.c    | 55 ++++++++++++++++++++++++++++++--------------
 kernel/time/tick-internal.h  |  8 +++++--
 5 files changed, 65 insertions(+), 30 deletions(-)
arch/x86/xen/suspend.c +1 -1
index 033e428..d949769 100644
@@ -85,7 +85,7 @@ static void xen_vcpu_notify_restore(void *data)
 	if (smp_processor_id() == 0)
 		return;
 
-	tick_resume();
+	tick_resume_local();
 }
 
 void xen_arch_resume(void)
include/linux/tick.h +3 -3
index 7e07e0e..a3d4d28 100644
@@ -29,13 +29,13 @@ extern struct tick_device *tick_get_device(int cpu);
 extern void __init tick_init(void);
 extern void tick_freeze(void);
 extern void tick_unfreeze(void);
-/* Should be core only, but XEN resume magic abuses this interface */
-extern void tick_resume(void);
+/* Should be core only, but XEN resume magic requires this */
+extern void tick_resume_local(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_resume(void) { }
+static inline void tick_resume_local(void) { }
 #endif /* !CONFIG_GENERIC_CLOCKEVENTS */
 
 #ifdef CONFIG_TICK_ONESHOT
kernel/time/tick-broadcast.c +17 -7
index 60e6c23..19cfb38 100644
@@ -455,11 +455,26 @@ void tick_suspend_broadcast(void)
 	raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags);
 }
 
-int tick_resume_broadcast(void)
+/*
+ * This is called from tick_resume_local() on a resuming CPU. That's
+ * called from the core resume function, tick_unfreeze() and the magic XEN
+ * resume hackery.
+ *
+ * In none of these cases the broadcast device mode can change and the
+ * bit of the resuming CPU in the broadcast mask is safe as well.
+ */
+bool tick_resume_check_broadcast(void)
+{
+	if (tick_broadcast_device.mode == TICKDEV_MODE_ONESHOT)
+		return false;
+	else
+		return cpumask_test_cpu(smp_processor_id(), tick_broadcast_mask);
+}
+
+void tick_resume_broadcast(void)
 {
 	struct clock_event_device *bc;
 	unsigned long flags;
-	int broadcast = 0;
 
 	raw_spin_lock_irqsave(&tick_broadcast_lock, flags);
 
@@ -472,8 +487,6 @@ int tick_resume_broadcast(void)
 		case TICKDEV_MODE_PERIODIC:
 			if (!cpumask_empty(tick_broadcast_mask))
 				tick_broadcast_start_periodic(bc);
-			broadcast = cpumask_test_cpu(smp_processor_id(),
-						     tick_broadcast_mask);
 			break;
 		case TICKDEV_MODE_ONESHOT:
 			if (!cpumask_empty(tick_broadcast_mask))
@@ -482,11 +495,8 @@ int tick_resume_broadcast(void)
 		}
 	}
 	raw_spin_unlock_irqrestore(&tick_broadcast_lock, flags);
-
-	return broadcast;
 }
 
-
 #ifdef CONFIG_TICK_ONESHOT
 
 static cpumask_var_t tick_broadcast_oneshot_mask;
kernel/time/tick-common.c +38 -17

91 lines not on this page · raw message

kernel/time/tick-internal.h +6 -2
index 5c9f0ee..6ba7bce 100644
@@ -23,6 +23,7 @@ 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);
 extern bool tick_check_replacement(struct clock_event_device *curdev,
 				   struct clock_event_device *newdev);
 extern void tick_install_replacement(struct clock_event_device *dev);
@@ -43,6 +44,7 @@ extern int __clockevents_update_freq(struct clock_event_device *dev, u32 freq);
 extern ssize_t sysfs_get_uname(const char *buf, char *dst, size_t cnt);
 #else
 static inline void tick_suspend(void) { }
+static inline void tick_resume(void) { }
 #endif /* GENERIC_CLOCKEVENTS */
 
 /* Oneshot related functions */
@@ -81,7 +83,8 @@ 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 int tick_resume_broadcast(void);
+extern void tick_resume_broadcast(void);
+extern bool tick_resume_check_broadcast(void);
 extern void tick_broadcast_init(void);
 extern void tick_set_periodic_handler(struct clock_event_device *dev, int broadcast);
 extern int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq);
@@ -95,7 +98,8 @@ 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 int tick_resume_broadcast(void) { return 0; }
+static inline void tick_resume_broadcast(void) { }
+static inline bool tick_resume_check_broadcast(void) { return false; }
 static inline void tick_broadcast_init(void) { }
 static inline int tick_broadcast_update_freq(struct clock_event_device *dev, u32 freq) { return -ENODEV; }
 
#97 lore raw

PATCH 1/1 timers / PM: Fix up tick_unfreeze()

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

A recent conflict resolution has left tick_resume() in tick_unfreeze() which leads to an unbalanced execution of tick_resume_broadcast() every time that function runs.

Fix that by replacing the tick_resume() in tick_unfreeze() with tick_resume_local() as appropriate.

---
 kernel/time/tick-common.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/time/tick-common.c +1 -1
Index: linux-pm/kernel/time/tick-common.c
===================================================================
@@ -482,7 +482,7 @@ void tick_unfreeze(void)
 	if (tick_freeze_depth == num_online_cpus())
 		timekeeping_resume();
 	else
-		tick_resume();
+		tick_resume_local();
 
 	tick_freeze_depth--;
 
#98 lore raw

PATCH 1/1 timers / PM: Drop unnecessary braces from tick_freeze()

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

Some braces in tick_freeze() are not necessary, so drop them.

---
 kernel/time/tick-common.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
kernel/time/tick-common.c +2 -3
Index: linux-pm/kernel/time/tick-common.c
===================================================================
@@ -457,11 +457,10 @@ void tick_freeze(void)
 	raw_spin_lock(&tick_freeze_lock);
 
 	tick_freeze_depth++;
-	if (tick_freeze_depth == num_online_cpus()) {
+	if (tick_freeze_depth == num_online_cpus())
 		timekeeping_suspend();
-	} else {
+	else
 		tick_suspend_local();
-	}
 
 	raw_spin_unlock(&tick_freeze_lock);
 }
#99 lore raw

[tip:timers/core] timers/PM: Drop unnecessary braces from tick_freeze()

timers/PM: Drop unnecessary braces from tick_freeze()
Commit-ID:  def747087e83aa5f6a71582cfa71e18341988688
Gitweb:     http://git.kernel.org/tip/def747087e83aa5f6a71582cfa71e18341988688
Author:     Rafael J. Wysocki <[email protected]>
AuthorDate: Fri, 3 Apr 2015 15:31:32 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 3 Apr 2015 15:15:52 +0200

timers/PM: Drop unnecessary braces from tick_freeze()

Some braces in tick_freeze() are not necessary, so drop them.

---
 kernel/time/tick-common.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
kernel/time/tick-common.c +2 -3
index ad66a51..3ae6afa 100644
@@ -457,11 +457,10 @@ void tick_freeze(void)
 	raw_spin_lock(&tick_freeze_lock);
 
 	tick_freeze_depth++;
-	if (tick_freeze_depth == num_online_cpus()) {
+	if (tick_freeze_depth == num_online_cpus())
 		timekeeping_suspend();
-	} else {
+	else
 		tick_suspend_local();
-	}
 
 	raw_spin_unlock(&tick_freeze_lock);
 }
#100 lore raw

[tip:timers/core] timers/PM: Fix up tick_unfreeze()

In reply to Rafael J. Wysocki
timers/PM: Fix up tick_unfreeze()
Commit-ID:  422fe7502e3f16dc1c680f22d31f59f022edc10d
Gitweb:     http://git.kernel.org/tip/422fe7502e3f16dc1c680f22d31f59f022edc10d
Author:     Rafael J. Wysocki <[email protected]>
AuthorDate: Fri, 3 Apr 2015 15:21:51 +0200
Committer:  Ingo Molnar <[email protected]>
CommitDate: Fri, 3 Apr 2015 15:15:51 +0200

timers/PM: Fix up tick_unfreeze()

A recent conflict resolution has left tick_resume() in tick_unfreeze() which leads to an unbalanced execution of tick_resume_broadcast() every time that function runs.

Fix that by replacing the tick_resume() in tick_unfreeze() with tick_resume_local() as appropriate.

---
 kernel/time/tick-common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/time/tick-common.c +1 -1
index fac3e98..ad66a51 100644
@@ -482,7 +482,7 @@ void tick_unfreeze(void)
 	if (tick_freeze_depth == num_online_cpus())
 		timekeeping_resume();
 	else
-		tick_resume();
+		tick_resume_local();
 
 	tick_freeze_depth--;
 
#101 lore raw

PATCH 9/9 arm: bl_switcher: Kill tick suspend hackery

In reply to Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Use the new tick_suspend/resume_local() and get rid of the homebrewn implementation of these in the ARM bL switcher. The check for the cpumask is completely pointless. There is no harm to suspend a per cpu tick device unconditionally. If that's a real issue then we fix it proper at the core level and not with some completely undocumented hacks in some random core code.

Move the tick internals to the core code, now that this nuisance is gone.

Cc Nicolas Pitre <[email protected]>
Cc Russell King <[email protected]>
[ rjw: Rebase, changelog ]
---
 arch/arm/common/bL_switcher.c |   16 ++--------------
 include/linux/clockchips.h    |    6 ------
 include/linux/tick.h          |   19 ++++---------------
 kernel/time/tick-common.c     |    2 +-
 kernel/time/tick-internal.h   |    5 +++++
 kernel/time/tick-sched.h      |   10 ++++++++++
 6 files changed, 22 insertions(+), 36 deletions(-)
include/linux/tick.h +4 -15
Index: linux-pm/include/linux/tick.h
===================================================================
@@ -11,30 +11,19 @@
 #include <linux/cpumask.h>
 #include <linux/sched.h>
 
-/* ARM BL switcher abuse support */
-#ifdef CONFIG_GENERIC_CLOCKEVENTS
-enum tick_device_mode {
-	TICKDEV_MODE_PERIODIC,
-	TICKDEV_MODE_ONESHOT,
-};
-
-struct tick_device {
-	struct clock_event_device *evtdev;
-	enum tick_device_mode mode;
-};
-extern struct tick_device *tick_get_device(int cpu);
-#endif
-
 #ifdef CONFIG_GENERIC_CLOCKEVENTS
 extern void __init tick_init(void);
 extern void tick_freeze(void);
 extern void tick_unfreeze(void);
-/* Should be core only, but XEN resume magic requires this */
+/* Should be core only, but ARM BL switcher requires it */
+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);
 #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) { }
 #endif /* !CONFIG_GENERIC_CLOCKEVENTS */
 
arch/arm/common/bL_switcher.c +2 -14
Index: linux-pm/arch/arm/common/bL_switcher.c
===================================================================
@@ -151,8 +151,6 @@ static int bL_switch_to(unsigned int new
 	unsigned int mpidr, this_cpu, that_cpu;
 	unsigned int ob_mpidr, ob_cpu, ob_cluster, ib_mpidr, ib_cpu, ib_cluster;
 	struct completion inbound_alive;
-	struct tick_device *tdev;
-	enum clock_event_mode tdev_mode;
 	long volatile *handshake_ptr;
 	int ipi_nr, ret;
 
@@ -219,13 +217,7 @@ static int bL_switch_to(unsigned int new
 	/* redirect GIC's SGIs to our counterpart */
 	gic_migrate_target(bL_gic_id[ib_cpu][ib_cluster]);
 
-	tdev = tick_get_device(this_cpu);
-	if (tdev && !cpumask_equal(tdev->evtdev->cpumask, cpumask_of(this_cpu)))
-		tdev = NULL;
-	if (tdev) {
-		tdev_mode = tdev->evtdev->mode;
-		clockevents_set_mode(tdev->evtdev, CLOCK_EVT_MODE_SHUTDOWN);
-	}
+	tick_suspend_local();
 
 	ret = cpu_pm_enter();
 
@@ -251,11 +243,7 @@ static int bL_switch_to(unsigned int new
 
 	ret = cpu_pm_exit();
 
-	if (tdev) {
-		clockevents_set_mode(tdev->evtdev, tdev_mode);
-		clockevents_program_event(tdev->evtdev,
-					  tdev->evtdev->next_event, 1);
-	}
+	tick_resume_local();
 
 	trace_cpu_migrate_finish(ktime_get_real_ns(), ib_mpidr);
 	local_fiq_enable();
include/linux/clockchips.h +0 -6
Index: linux-pm/include/linux/clockchips.h
===================================================================
@@ -163,12 +163,6 @@ clockevents_calc_mult_shift(struct clock
 				      freq, minsec);
 }
 
-/* Should be core only, but is abused by arm bl_switcher */
-extern void clockevents_set_mode(struct clock_event_device *dev,
-				 enum clock_event_mode mode);
-extern int clockevents_program_event(struct clock_event_device *dev,
-				     ktime_t expires, bool force);
-
 extern void clockevents_suspend(void);
 extern void clockevents_resume(void);
 
kernel/time/tick-internal.h +5 -0
Index: linux-pm/kernel/time/tick-internal.h
===================================================================
@@ -28,6 +28,7 @@ extern bool tick_check_replacement(struc
 				   struct clock_event_device *newdev);
 extern void tick_install_replacement(struct clock_event_device *dev);
 extern int tick_is_oneshot_available(void);
+extern struct tick_device *tick_get_device(int cpu);
 
 /* Check, if the device is functional or a dummy for broadcast */
 static inline int tick_device_is_functional(struct clock_event_device *dev)
@@ -38,6 +39,10 @@ static inline int tick_device_is_functio
 extern void clockevents_shutdown(struct clock_event_device *dev);
 extern void clockevents_exchange_device(struct clock_event_device *old,
 					struct clock_event_device *new);
+extern void clockevents_set_mode(struct clock_event_device *dev,
+				 enum clock_event_mode mode);
+extern int clockevents_program_event(struct clock_event_device *dev,
+				     ktime_t expires, bool force);
 extern void clockevents_handle_noop(struct clock_event_device *dev);
 extern int __clockevents_update_freq(struct clock_event_device *dev, u32 freq);
 extern ssize_t sysfs_get_uname(const char *buf, char *dst, size_t cnt);
kernel/time/tick-sched.h +10 -0
Index: linux-pm/kernel/time/tick-sched.h
===================================================================
@@ -3,6 +3,16 @@
 
 #include <linux/hrtimer.h>
 
+enum tick_device_mode {
+	TICKDEV_MODE_PERIODIC,
+	TICKDEV_MODE_ONESHOT,
+};
+
+struct tick_device {
+	struct clock_event_device *evtdev;
+	enum tick_device_mode mode;
+};
+
 enum tick_nohz_mode {
 	NOHZ_MODE_INACTIVE,
 	NOHZ_MODE_LOWRES,
kernel/time/tick-common.c +1 -1
Index: linux-pm/kernel/time/tick-common.c
===================================================================
@@ -379,7 +379,7 @@ void tick_shutdown(unsigned int *cpup)
  *
  * No locks required. Nothing can change the per cpu device.
  */
-static void tick_suspend_local(void)
+void tick_suspend_local(void)
 {
 	struct tick_device *td = this_cpu_ptr(&tick_cpu_device);
 
Acked-by on v1 9/9
#102 lore raw

Re: [PATCH 09/09] arm: bl_switcher: Kill tick suspend hackery

Quoted 9 lines · Rafael J. Wysocki

From: Thomas Gleixner <[email protected]>

Use the new tick_suspend/resume_local() and get rid of the homebrewn implementation of these in the ARM bL switcher. The check for the cpumask is completely pointless. There is no harm to suspend a per cpu tick device unconditionally. If that's a real issue then we fix it proper at the core level and not with some completely undocumented hacks in some random core code.

Quoted 8 lines

Move the tick internals to the core code, now that this nuisance is gone.

Cc Nicolas Pitre <[email protected]>
Cc Russell King <[email protected]>
[ rjw: Rebase, changelog ]
Quoted 165 lines
---
 arch/arm/common/bL_switcher.c |   16 ++--------------
 include/linux/clockchips.h    |    6 ------
 include/linux/tick.h          |   19 ++++---------------
 kernel/time/tick-common.c     |    2 +-
 kernel/time/tick-internal.h   |    5 +++++
 kernel/time/tick-sched.h      |   10 ++++++++++
 6 files changed, 22 insertions(+), 36 deletions(-)

Index: linux-pm/include/linux/tick.h
===================================================================

include/linux/tick.h +4 -15
@@ -11,30 +11,19 @@
 #include <linux/cpumask.h>
 #include <linux/sched.h>
 
-/* ARM BL switcher abuse support */
-#ifdef CONFIG_GENERIC_CLOCKEVENTS
-enum tick_device_mode {
-	TICKDEV_MODE_PERIODIC,
-	TICKDEV_MODE_ONESHOT,
-};
-
-struct tick_device {
-	struct clock_event_device *evtdev;
-	enum tick_device_mode mode;
-};
-extern struct tick_device *tick_get_device(int cpu);
-#endif
-
 #ifdef CONFIG_GENERIC_CLOCKEVENTS
 extern void __init tick_init(void);
 extern void tick_freeze(void);
 extern void tick_unfreeze(void);
-/* Should be core only, but XEN resume magic requires this */
+/* Should be core only, but ARM BL switcher requires it */
+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);
 #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) { }
 #endif /* !CONFIG_GENERIC_CLOCKEVENTS */
 

Index: linux-pm/arch/arm/common/bL_switcher.c
===================================================================

arch/arm/common/bL_switcher.c +2 -14
@@ -151,8 +151,6 @@ static int bL_switch_to(unsigned int new
 	unsigned int mpidr, this_cpu, that_cpu;
 	unsigned int ob_mpidr, ob_cpu, ob_cluster, ib_mpidr, ib_cpu, ib_cluster;
 	struct completion inbound_alive;
-	struct tick_device *tdev;
-	enum clock_event_mode tdev_mode;
 	long volatile *handshake_ptr;
 	int ipi_nr, ret;
 
@@ -219,13 +217,7 @@ static int bL_switch_to(unsigned int new
 	/* redirect GIC's SGIs to our counterpart */
 	gic_migrate_target(bL_gic_id[ib_cpu][ib_cluster]);
 
-	tdev = tick_get_device(this_cpu);
-	if (tdev && !cpumask_equal(tdev->evtdev->cpumask, cpumask_of(this_cpu)))
-		tdev = NULL;
-	if (tdev) {
-		tdev_mode = tdev->evtdev->mode;
-		clockevents_set_mode(tdev->evtdev, CLOCK_EVT_MODE_SHUTDOWN);
-	}
+	tick_suspend_local();
 
 	ret = cpu_pm_enter();
 
@@ -251,11 +243,7 @@ static int bL_switch_to(unsigned int new
 
 	ret = cpu_pm_exit();
 
-	if (tdev) {
-		clockevents_set_mode(tdev->evtdev, tdev_mode);
-		clockevents_program_event(tdev->evtdev,
-					  tdev->evtdev->next_event, 1);
-	}
+	tick_resume_local();
 
 	trace_cpu_migrate_finish(ktime_get_real_ns(), ib_mpidr);
 	local_fiq_enable();

Index: linux-pm/include/linux/clockchips.h
===================================================================

include/linux/clockchips.h +0 -6
@@ -163,12 +163,6 @@ clockevents_calc_mult_shift(struct clock
 				      freq, minsec);
 }
 
-/* Should be core only, but is abused by arm bl_switcher */
-extern void clockevents_set_mode(struct clock_event_device *dev,
-				 enum clock_event_mode mode);
-extern int clockevents_program_event(struct clock_event_device *dev,
-				     ktime_t expires, bool force);
-
 extern void clockevents_suspend(void);
 extern void clockevents_resume(void);
 

Index: linux-pm/kernel/time/tick-internal.h
===================================================================

kernel/time/tick-internal.h +5 -0
@@ -28,6 +28,7 @@ extern bool tick_check_replacement(struc
 				   struct clock_event_device *newdev);
 extern void tick_install_replacement(struct clock_event_device *dev);
 extern int tick_is_oneshot_available(void);
+extern struct tick_device *tick_get_device(int cpu);
 
 /* Check, if the device is functional or a dummy for broadcast */
 static inline int tick_device_is_functional(struct clock_event_device *dev)
@@ -38,6 +39,10 @@ static inline int tick_device_is_functio
 extern void clockevents_shutdown(struct clock_event_device *dev);
 extern void clockevents_exchange_device(struct clock_event_device *old,
 					struct clock_event_device *new);
+extern void clockevents_set_mode(struct clock_event_device *dev,
+				 enum clock_event_mode mode);
+extern int clockevents_program_event(struct clock_event_device *dev,
+				     ktime_t expires, bool force);
 extern void clockevents_handle_noop(struct clock_event_device *dev);
 extern int __clockevents_update_freq(struct clock_event_device *dev, u32 freq);
 extern ssize_t sysfs_get_uname(const char *buf, char *dst, size_t cnt);

Index: linux-pm/kernel/time/tick-sched.h
===================================================================

kernel/time/tick-sched.h +10 -0
@@ -3,6 +3,16 @@
 
 #include <linux/hrtimer.h>
 
+enum tick_device_mode {
+	TICKDEV_MODE_PERIODIC,
+	TICKDEV_MODE_ONESHOT,
+};
+
+struct tick_device {
+	struct clock_event_device *evtdev;
+	enum tick_device_mode mode;
+};
+
 enum tick_nohz_mode {
 	NOHZ_MODE_INACTIVE,
 	NOHZ_MODE_LOWRES,

Index: linux-pm/kernel/time/tick-common.c
===================================================================

kernel/time/tick-common.c +1 -1
@@ -379,7 +379,7 @@ void tick_shutdown(unsigned int *cpup)
  *
  * No locks required. Nothing can change the per cpu device.
  */
-static void tick_suspend_local(void)
+void tick_suspend_local(void)
 {
 	struct tick_device *td = this_cpu_ptr(&tick_cpu_device);
 
#103 lore raw

[tip:timers/core] arm/bL_switcher: Kill tick suspend hackery

In reply to Rafael J. Wysocki
arm/bL_switcher: Kill tick suspend hackery
Commit-ID:  7270d11c56f594af4d166b2988421cd8ed933dc1
Gitweb:     http://git.kernel.org/tip/7270d11c56f594af4d166b2988421cd8ed933dc1
Author:     Thomas Gleixner <[email protected]>
AuthorDate: Wed, 25 Mar 2015 13:11:52 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 1 Apr 2015 14:23:00 +0200

arm/bL_switcher: Kill tick suspend hackery

Use the new tick_suspend/resume_local() and get rid of the homebrewn implementation of these in the ARM bL switcher. The check for the cpumask is completely pointless. There is no harm to suspend a per cpu tick device unconditionally. If that's a real issue then we fix it proper at the core level and not with some completely undocumented hacks in some random core code.

Move the tick internals to the core code, now that this nuisance is gone.

---
 arch/arm/common/bL_switcher.c | 16 ++--------------
 include/linux/clockchips.h    |  6 ------
 include/linux/tick.h          | 19 ++++---------------
 kernel/time/tick-common.c     |  2 +-
 kernel/time/tick-internal.h   |  5 +++++
 kernel/time/tick-sched.h      | 10 ++++++++++
 6 files changed, 22 insertions(+), 36 deletions(-)
arch/arm/common/bL_switcher.c +2 -14
index d4f970a..37dc0fe 100644
@@ -151,8 +151,6 @@ static int bL_switch_to(unsigned int new_cluster_id)
 	unsigned int mpidr, this_cpu, that_cpu;
 	unsigned int ob_mpidr, ob_cpu, ob_cluster, ib_mpidr, ib_cpu, ib_cluster;
 	struct completion inbound_alive;
-	struct tick_device *tdev;
-	enum clock_event_state tdev_state;
 	long volatile *handshake_ptr;
 	int ipi_nr, ret;
 
@@ -219,13 +217,7 @@ static int bL_switch_to(unsigned int new_cluster_id)
 	/* redirect GIC's SGIs to our counterpart */
 	gic_migrate_target(bL_gic_id[ib_cpu][ib_cluster]);
 
-	tdev = tick_get_device(this_cpu);
-	if (tdev && !cpumask_equal(tdev->evtdev->cpumask, cpumask_of(this_cpu)))
-		tdev = NULL;
-	if (tdev) {
-		tdev_state = tdev->evtdev->state;
-		clockevents_set_state(tdev->evtdev, CLOCK_EVT_STATE_SHUTDOWN);
-	}
+	tick_suspend_local();
 
 	ret = cpu_pm_enter();
 
@@ -251,11 +243,7 @@ static int bL_switch_to(unsigned int new_cluster_id)
 
 	ret = cpu_pm_exit();
 
-	if (tdev) {
-		clockevents_set_state(tdev->evtdev, tdev_state);
-		clockevents_program_event(tdev->evtdev,
-					  tdev->evtdev->next_event, 1);
-	}
+	tick_resume_local();
 
 	trace_cpu_migrate_finish(ktime_get_real_ns(), ib_mpidr);
 	local_fiq_enable();
include/linux/clockchips.h +0 -6
index 50ce975..3ac7e2d 100644
@@ -198,12 +198,6 @@ clockevents_calc_mult_shift(struct clock_event_device *ce, u32 freq, u32 minsec)
 				      freq, minsec);
 }
 
-/* Should be core only, but is abused by arm bl_switcher */
-extern void clockevents_set_state(struct clock_event_device *dev,
-				 enum clock_event_state state);
-extern int clockevents_program_event(struct clock_event_device *dev,
-				     ktime_t expires, bool force);
-
 extern void clockevents_suspend(void);
 extern void clockevents_resume(void);
 
include/linux/tick.h +4 -15
index a3d4d28..589868b 100644
@@ -11,30 +11,19 @@
 #include <linux/cpumask.h>
 #include <linux/sched.h>
 
-/* ARM BL switcher abuse support */
-#ifdef CONFIG_GENERIC_CLOCKEVENTS
-enum tick_device_mode {
-	TICKDEV_MODE_PERIODIC,
-	TICKDEV_MODE_ONESHOT,
-};
-
-struct tick_device {
-	struct clock_event_device *evtdev;
-	enum tick_device_mode mode;
-};
-extern struct tick_device *tick_get_device(int cpu);
-#endif
-
 #ifdef CONFIG_GENERIC_CLOCKEVENTS
 extern void __init tick_init(void);
 extern void tick_freeze(void);
 extern void tick_unfreeze(void);
-/* Should be core only, but XEN resume magic requires this */
+/* Should be core only, but ARM BL switcher requires it */
+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);
 #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) { }
 #endif /* !CONFIG_GENERIC_CLOCKEVENTS */
 
kernel/time/tick-common.c +1 -1
index da796d6..e28ba5c 100644
@@ -380,7 +380,7 @@ void tick_shutdown(unsigned int *cpup)
  *
  * No locks required. Nothing can change the per cpu device.
  */
-static void tick_suspend_local(void)
+void tick_suspend_local(void)
 {
 	struct tick_device *td = this_cpu_ptr(&tick_cpu_device);
 
kernel/time/tick-internal.h +5 -0
index 6ba7bce..5fc2daf 100644
@@ -28,6 +28,7 @@ extern bool tick_check_replacement(struct clock_event_device *curdev,
 				   struct clock_event_device *newdev);
 extern void tick_install_replacement(struct clock_event_device *dev);
 extern int tick_is_oneshot_available(void);
+extern struct tick_device *tick_get_device(int cpu);
 
 extern int clockevents_tick_resume(struct clock_event_device *dev);
 /* Check, if the device is functional or a dummy for broadcast */
@@ -39,6 +40,10 @@ static inline int tick_device_is_functional(struct clock_event_device *dev)
 extern void clockevents_shutdown(struct clock_event_device *dev);
 extern void clockevents_exchange_device(struct clock_event_device *old,
 					struct clock_event_device *new);
+extern void clockevents_set_state(struct clock_event_device *dev,
+				 enum clock_event_state state);
+extern int clockevents_program_event(struct clock_event_device *dev,
+				     ktime_t expires, bool force);
 extern void clockevents_handle_noop(struct clock_event_device *dev);
 extern int __clockevents_update_freq(struct clock_event_device *dev, u32 freq);
 extern ssize_t sysfs_get_uname(const char *buf, char *dst, size_t cnt);
kernel/time/tick-sched.h +10 -0
index 9307432..28b5da3 100644
@@ -3,6 +3,16 @@
 
 #include <linux/hrtimer.h>
 
+enum tick_device_mode {
+	TICKDEV_MODE_PERIODIC,
+	TICKDEV_MODE_ONESHOT,
+};
+
+struct tick_device {
+	struct clock_event_device *evtdev;
+	enum tick_device_mode mode;
+};
+
 enum tick_nohz_mode {
 	NOHZ_MODE_INACTIVE,
 	NOHZ_MODE_LOWRES,
#104 lore raw

Re: [PATCH 00/09] Some kernel/time cleanups (related to timer_suspend/resume)

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

Hi,

Quoted 6 lines · Peter Zijlstra

Hi,

While working with Rafael on the suspend to idle machinery Thomas made these cleanups; since one might as well clean code up while you've done the work of thinking through it again.

Quoted 7 lines
Quoted 2 lines

As it stands there's very little overlap between Rafael's series and this one aside from a few trivial fixups. So we'll merge them seperately.

Since some of the original Thomas' patches needed to be rebased on top of the suspend-to-idle material that went in during the 4.0 merge window, I did that with the patches related to the suspending/resuming of ticks which follow.

I forgot to mention that I'd tested these vs suspend-to-idle and suspend-to-RAM on a couple of different systems and they don't seem to break anything for me.

Also I have a plan to make the compilation of some PM-related stuff conditional on CONFIG_PM_SLEEP etc. on top of these.

Rafael

#105 lore raw

[GIT PULL] kernel/time cleanups (related to tick_suspend/resume)

In reply to Rafael J. Wysocki

Hi Ingo,

Please pull from

git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git tick-pm

to receive kernel/time cleanups related to tick_suspend/resume from Thomas Gleixner that I've rebased on top of the Linus' tree and reworked slightly.

There will be a conflict between this branch and tip that can be resolved with the help of the patch from Stephen Rothwell available at:

http://marc.info/?l=linux-kernel&m=142778874014355&w=4

Kind regards,
Rafael