time/cpuidle: Support in tick broadcast framework in absence of external clock device
Subsystems (3)
v3 cover time/cpuidle: Support in tick broadcast framework in absence of external clock device
On some architectures, the local timers of CPUs stop in deep idle states. They will need to depend on an external clock device to wake them up. However certain implementations of archs do not have an external clock device.
This patchset provides support in the tick broadcast framework for such architectures so as to enable the CPUs to get into deep idle.
Presently we are in need of this support on certain implementations of PowerPC. This patchset has thus been tested on the same.
V1: https://lkml.org/lkml/2013/12/12/687.
V2: https://lkml.org/lkml/2014/1/24/28
Changes in V3:
1. Modified comments and code around programming of the broadcast hrtimer.
---
Preeti U Murthy (2):
time: Change the return type of clockevents_notify() to integer time/cpuidle:Handle failed call to BROADCAST_ENTER on archs with CPUIDLE_FLAG_TIMER_STOP set
Thomas Gleixner (1):
tick/cpuidle: Initialize hrtimer mode of broadcast
drivers/cpuidle/cpuidle.c | 38 +++++++----- include/linux/clockchips.h | 15 ++++- kernel/time/Makefile | 2 - kernel/time/clockevents.c | 8 ++- kernel/time/tick-broadcast-hrtimer.c | 105 ++++++++++++++++++++++++++++++++++ kernel/time/tick-broadcast.c | 51 ++++++++++++++++- kernel/time/tick-internal.h | 6 +- 7 files changed, 197 insertions(+), 28 deletions(-) create mode 100644 kernel/time/tick-broadcast-hrtimer.c
PATCH v3 1/3 time: Change the return type of clockevents_notify() to integer
The broadcast framework can potentially be made use of by archs which do not have an external clock device as well. Then, it is required that one of the CPUs need to handle the broadcasting of wakeup IPIs to the CPUs in deep idle. As a result its local timers should remain functional all the time. For such a CPU, the BROADCAST_ENTER notification has to fail indicating that its clock device cannot be shutdown. To make way for this support, change the return type of tick_broadcast_oneshot_control() and hence clockevents_notify() to indicate such scenarios.
---
include/linux/clockchips.h | 6 +++--- kernel/time/clockevents.c | 8 +++++--- kernel/time/tick-broadcast.c | 6 ++++-- kernel/time/tick-internal.h | 6 +++--- 4 files changed, 15 insertions(+), 11 deletions(-)
include/linux/clockchips.h +3 -3
@@ -186,9 +186,9 @@ static inline int tick_check_broadcast_expired(void) { return 0; }#endif #ifdef CONFIG_GENERIC_CLOCKEVENTS -extern void clockevents_notify (unsigned long reason,void *arg); +extern int clockevents_notify (unsigned long reason,void *arg);#else -static inline void clockevents_notify (unsigned long reason,void *arg) {} +static inline int clockevents_notify (unsigned long reason,void *arg) {return 0 ; }#endif #else /* CONFIG_GENERIC_CLOCKEVENTS_BUILD */
@@ -196,7 +196,7 @@ static inline void clockevents_notify(unsigned long reason, void *arg) {}static inline void clockevents_suspend (void ) {}static inline void clockevents_resume (void ) {} -static inline void clockevents_notify (unsigned long reason,void *arg) {} +static inline int clockevents_notify (unsigned long reason,void *arg) {return 0 ; }static inline int tick_check_broadcast_expired (void ) {return 0 ; }#endif
kernel/time/clockevents.c +5 -3
@@ -524,12 +524,13 @@ void clockevents_resume(void)#ifdef CONFIG_GENERIC_CLOCKEVENTS /** * clockevents_notify - notification about relevant events +* Returns 0 on success, any other value on error */ -void clockevents_notify (unsigned long reason,void *arg) +int clockevents_notify (unsigned long reason,void *arg) {struct clock_event_device *dev, *tmp;unsigned long flags; -int cpu; +int cpu, ret =0 ;raw_spin_lock_irqsave (&clockevents_lock, flags);
@@ -542,7 +543,7 @@ void clockevents_notify(unsigned long reason, void *arg)case CLOCK_EVT_NOTIFY_BROADCAST_ENTER :case CLOCK_EVT_NOTIFY_BROADCAST_EXIT : -tick_broadcast_oneshot_control (reason); + ret =tick_broadcast_oneshot_control (reason);break ;case CLOCK_EVT_NOTIFY_CPU_DYING :
@@ -585,6 +586,7 @@ void clockevents_notify(unsigned long reason, void *arg)break ; }raw_spin_unlock_irqrestore (&clockevents_lock, flags); +return ret; }EXPORT_SYMBOL_GPL (clockevents_notify);
kernel/time/tick-broadcast.c +4 -2
@@ -633,14 +633,15 @@ again:/* * Powerstate information: The system enters/leaves a state, where * affected devices might stop +* Returns 0 on success, -EBUSY if the cpu is used to broadcast wakeups. */ -void tick_broadcast_oneshot_control (unsigned long reason) +int tick_broadcast_oneshot_control (unsigned long reason) {struct clock_event_device *bc, *dev;struct tick_device *td;unsigned long flags;ktime_t now; -int cpu; +int cpu, ret =0 ;/* * Periodic mode does not care about the enter/exit of power
@@ -746,6 +747,7 @@ void tick_broadcast_oneshot_control(unsigned long reason) } out:raw_spin_unlock_irqrestore (&tick_broadcast_lock, flags); +return ret; }/*
kernel/time/tick-internal.h +3 -3
@@ -46,7 +46,7 @@ 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 void tick_broadcast_oneshot_control (unsigned long reason); +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);
@@ -58,7 +58,7 @@ static inline void tick_broadcast_setup_oneshot(struct clock_event_device *bc) {BUG (); } -static inline void tick_broadcast_oneshot_control (unsigned long reason) { } +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 ; }
@@ -87,7 +87,7 @@ static inline void tick_broadcast_setup_oneshot(struct clock_event_device *bc) {BUG (); } -static inline void tick_broadcast_oneshot_control (unsigned long reason) { } +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) {
PATCH v3 2/3 tick/cpuidle: Initialize hrtimer mode of broadcast
In reply to Preeti U MurthyFrom: Thomas Gleixner <[email protected]>
On some architectures, in certain CPU deep idle states the local timers stop. An external clock device is used to wakeup these CPUs. The kernel support for the wakeup of these CPUs is provided by the tick broadcast framework by using the external clock device as the wakeup source.
However not all implementations of architectures provide such an external clock device. This patch includes support in the broadcast framework to handle the wakeup of the CPUs in deep idle states on such systems by queuing a hrtimer on one of the CPUs, which is meant to handle the wakeup of CPUs in deep idle states.
This patchset introduces a pseudo clock device which can be registered by the archs as tick_broadcast_device in the absence of a real external clock device. Once registered, the broadcast framework will work as is for these architectures as long as the archs take care of the BROADCAST_ENTER notification failing for one of the CPUs. This CPU is made the stand by CPU to handle wakeup of the CPUs in deep idle and it *must not enter deep idle states*.
The CPU with the earliest wakeup is chosen to be this CPU. Hence this way the stand by CPU dynamically moves around and so does the hrtimer which is queued to trigger at the next earliest wakeup time. This is consistent with the case where an external clock device is present. The smp affinity of this clock device is set to the CPU with the earliest wakeup. This patchset handles the hotplug of the stand by CPU as well by moving the hrtimer on to the CPU handling the CPU_DEAD notification.
---
include/linux/clockchips.h | 9 +++ kernel/time/Makefile | 2 - kernel/time/tick-broadcast-hrtimer.c | 105 ++++++++++++++++++++++++++++++++++ kernel/time/tick-broadcast.c | 45 ++++++++++++++- 4 files changed, 159 insertions(+), 2 deletions(-) create mode 100644 kernel/time/tick-broadcast-hrtimer.c
include/linux/clockchips.h +9 -0
@@ -62,6 +62,11 @@ enum clock_event_mode {#define CLOCK_EVT_FEAT_DYNIRQ 0x000020#define CLOCK_EVT_FEAT_PERCPU 0x000040 +/* +* Clockevent device is based on a hrtimer for broadcast +*/ +#define CLOCK_EVT_FEAT_HRTIMER 0x000080 +/** * struct clock_event_device - clock event device descriptor * @event_handler: Assigned by the framework to be called by the low
@@ -83,6 +88,7 @@ enum clock_event_mode {* @name: ptr to clock event name * @rating: variable to rate clock event devices * @irq: IRQ number (only for non CPU local devices) +* @bound_on: Bound on CPU * @cpumask: cpumask to indicate for which CPUs this device works * @list: list head for the management code * @owner: module reference
@@ -113,6 +119,7 @@ struct clock_event_device {const char *name;int rating;int irq; +int bound_on;const struct cpumask *cpumask;struct list_head list;struct module *owner;
@@ -180,9 +187,11 @@ 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 void tick_setup_hrtimer_broadcast (void ) {};#endif #ifdef CONFIG_GENERIC_CLOCKEVENTS
kernel/time/Makefile +1 -1
@@ -3,7 +3,7 @@ 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_BROADCAST) += tick-broadcast.o +obj-$(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) += tick-broadcast.o tick-broadcast-hrtimer.o obj-$(CONFIG_GENERIC_SCHED_CLOCK) += sched_clock.o obj-$(CONFIG_TICK_ONESHOT) += tick-oneshot.o obj-$(CONFIG_TICK_ONESHOT) += tick-sched.o
kernel/time/tick-broadcast-hrtimer.c new file +105 -0
105 lines not on this page · raw message
kernel/time/tick-broadcast.c +44 -1
69 lines not on this page · raw message
Re: [PATCH V3 2/3] tick/cpuidle: Initialize hrtimer mode of broadcast
On Thu, 6 Feb 2014, Preeti U Murthy wrote:
Compiler warnings are not so important, right?
kernel/time/tick-broadcast.c: In function ‘tick_broadcast_oneshot_control’:kernel/time/tick-broadcast.c:700:3: warning: ‘return’ with no value, in function returning non-void [-Wreturn-type] kernel/time/tick-broadcast.c:711:3: warning: ‘return’ with no value, in function returning non-void [-Wreturn-type]
Review
Quoted 5 lines
(quoted diff) +5
-0+ /* + * If the current CPU owns the hrtimer broadcast + * mechanism, it cannot go deep idle. + */ + ret = broadcast_needs_cpu(bc, cpu);
So we leave the CPU in the broadcast mask, just to force another call to the notify code right away to remove it again. Wouldn't it be more clever to clear the flag right away? That would make the changes to the cpuidle code simpler. Delta patch below.
Thanks,
tglx
---
kernel/time/tick-broadcast.c +8 -3
@@ -697,7 +697,7 @@ int tick_broadcast_oneshot_control(unsig* states */ if (tick_broadcast_device.mode ==TICKDEV_MODE_PERIODIC ) -return ; +return 0 ;/* * We are called with preemtion disabled from the depth of the
@@ -708,7 +708,7 @@ int tick_broadcast_oneshot_control(unsig dev = td->evtdev;if (!(dev->features &CLOCK_EVT_FEAT_C3STOP )) -return ; +return 0 ; bc = tick_broadcast_device.evtdev;
@@ -731,9 +731,14 @@ int tick_broadcast_oneshot_control(unsig }/* * If the current CPU owns the hrtimer broadcast -* mechanism, it cannot go deep idle. +* mechanism, it cannot go deep idle and we remove the +* CPU from the broadcast mask. We don't have to go +* through the EXIT path as the local timer is not +* shutdown. */ ret =broadcast_needs_cpu (bc, cpu); +if (ret) +cpumask_clear_cpu (cpu, tick_broadcast_oneshot_mask); }else {if (cpumask_test_and_clear_cpu (cpu, tick_broadcast_oneshot_mask)) {clockevents_set_mode (dev,CLOCK_EVT_MODE_ONESHOT );
Re: [PATCH V3 2/3] tick/cpuidle: Initialize hrtimer mode of broadcast
Hi Thomas,
Quoted 7 lines · Thomas Gleixner
On Thu, 6 Feb 2014, Preeti U Murthy wrote:
Compiler warnings are not so important, right?
kernel/time/tick-broadcast.c: In function ‘tick_broadcast_oneshot_control’:kernel/time/tick-broadcast.c:700:3: warning: ‘return’ with no value, in function returning non-void [-Wreturn-type]kernel/time/tick-broadcast.c:711:3: warning: ‘return’ with no value, in function returning non-void [-Wreturn-type]
My apologies for this, will make sure this will not repeat. On compilation I did not receive any warnings with the additional compile time flags too.I compiled it on powerpc. Let me look into why the warnings did not show up. Nevertheless I should have taken care of this even by simply looking at the code.
Quoted 11 lines
Review
Quoted 6 lines
(quoted diff) +5
-0+ /* + * If the current CPU owns the hrtimer broadcast + * mechanism, it cannot go deep idle. + */ + ret = broadcast_needs_cpu(bc, cpu);So we leave the CPU in the broadcast mask, just to force another call to the notify code right away to remove it again. Wouldn't it be more clever to clear the flag right away? That would make the changes to the cpuidle code simpler. Delta patch below.
You are right.
Quoted 34 lines
Thanks,
tglx
---kernel/time/tick-broadcast.c +3
-3@@ -697,7 +697,7 @@ int tick_broadcast_oneshot_control(unsig* states */ if (tick_broadcast_device.mode ==TICKDEV_MODE_PERIODIC ) -return ; +return 0 ;/* * We are called with preemtion disabled from the depth of the @@ -708,7 +708,7 @@ int tick_broadcast_oneshot_control(unsig dev = td->evtdev;if (!(dev->features &CLOCK_EVT_FEAT_C3STOP )) -return ; +return 0 ; bc = tick_broadcast_device.evtdev;@@ -731,9 +731,14 @@ int tick_broadcast_oneshot_control(unsig }/* * If the current CPU owns the hrtimer broadcast -* mechanism, it cannot go deep idle. +* mechanism, it cannot go deep idle and we remove the
kernel/time/tick-broadcast.c int tick_broadcast_oneshot_control(unsig · line 744
Quoted 10 lines
kernel/time/tick-broadcast.c +5
-0+* CPU from the broadcast mask. We don't have to go +* through the EXIT path as the local timer is not +* shutdown. */ ret =broadcast_needs_cpu (bc, cpu); +if (ret) +cpumask_clear_cpu (cpu, tick_broadcast_oneshot_mask); }else {if (cpumask_test_and_clear_cpu (cpu, tick_broadcast_oneshot_mask)) {clockevents_set_mode (dev,CLOCK_EVT_MODE_ONESHOT );
The cpuidle patch then is below. The trace_cpu_idle_rcuidle() functions have been moved around so that the broadcast CPU does not trace any idle event and that the symmetry between the trace functions and the call to the broadcast framework is maintained. Wow, it does become very simple :)
time/cpuidle:Handle failed call to BROADCAST_ENTER on archs with CPUIDLE_FLAG_TIMER_STOP set
From: Preeti U Murthy <[email protected]>
Some archs set the CPUIDLE_FLAG_TIMER_STOP flag for idle states in which the local timers stop. The cpuidle_idle_call() currently handles such idle states by calling into the broadcast framework so as to wakeup CPUs at their next wakeup event. With the hrtimer mode of broadcast, the BROADCAST_ENTER call into the broadcast frameowork can fail for archs that do not have an external clock device to handle wakeups and the CPU in question has to thus be made the stand by CPU. This patch handles such cases by failing the call into cpuidle so that the arch can take some default action. The arch will certainly not enter a similar idle state because a failed cpuidle call will also implicitly indicate that the broadcast framework has not registered this CPU to be woken up. Hence we are safe if we fail the cpuidle call.
In the process move the functions that trace idle statistics just before and after the entry and exit into idle states respectively. In other scenarios where the call to cpuidle fails, we end up not tracing idle entry and exit since a decision on an idle state could not be taken. Similarly when the call to broadcast framework fails, we skip tracing idle statistics because we are in no further position to take a decision on an alternative idle state to enter into.
--- drivers/cpuidle/cpuidle.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/cpuidle/cpuidle.c +8 -6
@@ -140,12 +140,14 @@ int cpuidle_idle_call(void)return 0 ; } -trace_cpu_idle_rcuidle (next_state, dev->cpu); - broadcast = !!(drv->states[next_state].flags &CPUIDLE_FLAG_TIMER_STOP ); -if (broadcast) -clockevents_notify (CLOCK_EVT_NOTIFY_BROADCAST_ENTER , &dev->cpu); +if (broadcast && +clockevents_notify (CLOCK_EVT_NOTIFY_BROADCAST_ENTER , &dev->cpu)) +return -EBUSY ; + + +trace_cpu_idle_rcuidle (next_state, dev->cpu);if (cpuidle_state_is_coupled (dev, drv, next_state)) entered_state = cpuidle_enter_state_coupled(dev, drv,
@@ -153,11 +155,11 @@ int cpuidle_idle_call(void)else entered_state =cpuidle_enter_state (dev, drv, next_state); +trace_cpu_idle_rcuidle (PWR_EVENT_EXIT , dev->cpu); +if (broadcast)clockevents_notify (CLOCK_EVT_NOTIFY_BROADCAST_EXIT , &dev->cpu); -trace_cpu_idle_rcuidle (PWR_EVENT_EXIT , dev->cpu); -/* give the governor an opportunity to reflect on the outcome */ if (cpuidle_curr_governor->reflect) cpuidle_curr_governor->reflect (dev, entered_state);
Thank you
Regards
Preeti U Murthy
Re: [PATCH V3 2/3] tick/cpuidle: Initialize hrtimer mode of broadcast
Quoted 9 lines · Preeti U Murthy
Quoted 7 lines · Thomas Gleixner
On Thu, 6 Feb 2014, Preeti U Murthy wrote:
Compiler warnings are not so important, right?
kernel/time/tick-broadcast.c: In function ‘tick_broadcast_oneshot_control’:kernel/time/tick-broadcast.c:700:3: warning: ‘return’ with no value, in function returning non-void [-Wreturn-type]kernel/time/tick-broadcast.c:711:3: warning: ‘return’ with no value, in function returning non-void [-Wreturn-type]
Quoted 5 lines
My apologies for this, will make sure this will not repeat. On compilation I did not receive any warnings with the additional compile time flags too.I compiled it on powerpc. Let me look into why the warnings did not show up. Nevertheless I should have taken care of this even by simply looking at the code.
Huch, PPC seems to have an extra stupid version of gcc :)
Quoted 4 lines
The cpuidle patch then is below. The
trace_cpu_idle_rcuidle()functions have been moved around so that the broadcast CPU does not trace any idle event and that the symmetry between the trace functions and the call to the broadcast framework is maintained. Wow, it does become very simple :)
Indeed :)
Care to resend the whole lot with all fixes applied and perhaps compile tested on x86 :)
Thanks,
tglx
PATCH v3 3/3 time/cpuidle:Handle failed call to BROADCAST_ENTER on archs with CPUIDLE_FLAG_TIMER_STOP set
In reply to Preeti U MurthySome archs set the CPUIDLE_FLAG_TIMER_STOP flag for idle states in which the local timers stop. The cpuidle_idle_call() currently handles such idle states by calling into the broadcast framework so as to wakeup CPUs at their next wakeup event. With the hrtimer mode of broadcast, the BROADCAST_ENTER call into the broadcast frameowork can fail for archs that do not have an external clock device to handle wakeups and the CPU in question has to thus be made the stand by CPU. This patch handles such cases by failing the call into cpuidle so that the arch can take some default action. The arch will certainly not enter a similar idle state because a failed cpuidle call will also implicitly indicate that the broadcast framework has not registered this CPU to be woken up. Hence we are safe if we fail the cpuidle call.
In the process move the functions that trace idle statistics just before and after the entry and exit into idle states respectively. In other scenarios where the call to cpuidle fails, we end up not tracing idle entry and exit since a decision on an idle state could not be taken. Similarly when the call to broadcast framework fails, we skip tracing idle statistics because we are in no further position to take a decision on an alternative idle state to enter into.
---
drivers/cpuidle/cpuidle.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-)
drivers/cpuidle/cpuidle.c +23 -15
@@ -117,15 +117,19 @@ int cpuidle_idle_call(void) {struct cpuidle_device *dev =__this_cpu_read (cpuidle_devices);struct cpuidle_driver *drv; -int next_state, entered_state; -bool broadcast; +int next_state, entered_state, ret =0 ; +bool broadcast = false; -if (off || !initialized) -return -ENODEV ; +if (off || !initialized) { + ret = -ENODEV ; + goto out; + }/* check if the device is ready */ -if (!dev || !dev->enabled) -return -EBUSY ; +if (!dev || !dev->enabled) { + ret = -EBUSY ; + goto out; + } drv =cpuidle_get_cpu_driver (dev);
@@ -137,15 +141,18 @@ int cpuidle_idle_call(void)if (cpuidle_curr_governor->reflect) cpuidle_curr_governor->reflect (dev, next_state);local_irq_enable (); -return 0 ; + goto out; } -trace_cpu_idle_rcuidle (next_state, dev->cpu); - broadcast = !!(drv->states[next_state].flags &CPUIDLE_FLAG_TIMER_STOP ); -if (broadcast) -clockevents_notify (CLOCK_EVT_NOTIFY_BROADCAST_ENTER , &dev->cpu); +if (broadcast) { + ret =clockevents_notify (CLOCK_EVT_NOTIFY_BROADCAST_ENTER , &dev->cpu); +if (ret) + goto out; + } + +trace_cpu_idle_rcuidle (next_state, dev->cpu);if (cpuidle_state_is_coupled (dev, drv, next_state)) entered_state = cpuidle_enter_state_coupled(dev, drv,
@@ -153,16 +160,17 @@ int cpuidle_idle_call(void)else entered_state =cpuidle_enter_state (dev, drv, next_state); -if (broadcast) -clockevents_notify (CLOCK_EVT_NOTIFY_BROADCAST_EXIT , &dev->cpu); -trace_cpu_idle_rcuidle (PWR_EVENT_EXIT , dev->cpu);/* give the governor an opportunity to reflect on the outcome */ if (cpuidle_curr_governor->reflect) cpuidle_curr_governor->reflect (dev, entered_state); -return 0 ; +out:if (broadcast) +clockevents_notify (CLOCK_EVT_NOTIFY_BROADCAST_EXIT , &dev->cpu); + + +return ret; }/**
Re: [PATCH V3 3/3] time/cpuidle:Handle failed call to BROADCAST_ENTER on archs with CPUIDLE_FLAG_TIMER_STOP set
Quoted 20 lines · Preeti U Murthy
Some archs set the
CPUIDLE_FLAG_TIMER_STOPflag for idle states in which the local timers stop. Thecpuidle_idle_call()currently handles such idle states by calling into the broadcast framework so as to wakeup CPUs at their next wakeup event. With the hrtimer mode of broadcast, theBROADCAST_ENTERcall into the broadcast frameowork can fail for archs that do not have an external clock device to handle wakeups and the CPU in question has to thus be made the stand by CPU. This patch handles such cases by failing the call into cpuidle so that the arch can take some default action. The arch will certainly not enter a similar idle state because a failed cpuidle call will also implicitly indicate that the broadcast framework has not registered this CPU to be woken up. Hence we are safe if we fail the cpuidle call.In the process move the functions that trace idle statistics just before and after the entry and exit into idle states respectively. In other scenarios where the call to cpuidle fails, we end up not tracing idle entry and exit since a decision on an idle state could not be taken. Similarly when the call to broadcast framework fails, we skip tracing idle statistics because we are in no further position to take a decision on an alternative idle state to enter into.
Quoted 1 line
Signed-off-by Preeti U Murthy <[email protected]>
The cpuidle changes in this patch look reasonable to me, but I guess you'd like it to go in via tip along with the rest of the series, so
Quoted 86 lines
---
drivers/cpuidle/cpuidle.c | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-)drivers/cpuidle/cpuidle.c +23
-16@@ -117,15 +117,19 @@ int cpuidle_idle_call(void) {struct cpuidle_device *dev =__this_cpu_read (cpuidle_devices);struct cpuidle_driver *drv; -int next_state, entered_state; -bool broadcast; +int next_state, entered_state, ret =0 ; +bool broadcast = false; -if (off || !initialized) -return -ENODEV ; +if (off || !initialized) { + ret = -ENODEV ; + goto out; + }/* check if the device is ready */ -if (!dev || !dev->enabled) -return -EBUSY ; +if (!dev || !dev->enabled) { + ret = -EBUSY ; + goto out; + } drv =cpuidle_get_cpu_driver (dev);@@ -137,15 +141,18 @@ int cpuidle_idle_call(void)if (cpuidle_curr_governor->reflect) cpuidle_curr_governor->reflect (dev, next_state);local_irq_enable (); -return 0 ; + goto out; } -trace_cpu_idle_rcuidle (next_state, dev->cpu); - broadcast = !!(drv->states[next_state].flags &CPUIDLE_FLAG_TIMER_STOP ); -if (broadcast) -clockevents_notify (CLOCK_EVT_NOTIFY_BROADCAST_ENTER , &dev->cpu); +if (broadcast) { + ret =clockevents_notify (CLOCK_EVT_NOTIFY_BROADCAST_ENTER , &dev->cpu); +if (ret) + goto out; + } + +trace_cpu_idle_rcuidle (next_state, dev->cpu);if (cpuidle_state_is_coupled (dev, drv, next_state)) entered_state = cpuidle_enter_state_coupled(dev, drv,@@ -153,16 +160,17 @@ int cpuidle_idle_call(void)else entered_state =cpuidle_enter_state (dev, drv, next_state); -if (broadcast) -clockevents_notify (CLOCK_EVT_NOTIFY_BROADCAST_EXIT , &dev->cpu); -trace_cpu_idle_rcuidle (PWR_EVENT_EXIT , dev->cpu);/* give the governor an opportunity to reflect on the outcome */ if (cpuidle_curr_governor->reflect) cpuidle_curr_governor->reflect (dev, entered_state); -return 0 ; +out:if (broadcast) +clockevents_notify (CLOCK_EVT_NOTIFY_BROADCAST_EXIT , &dev->cpu); + + +return ret; }/** -- To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
I speak only for myself. Rafael J. Wysocki, Intel Open Source Technology Center.