Skip to content

Commit a06df06

Browse files
Daniel Lezcanorafaeljw
authored andcommitted
cpuidle: initialize the broadcast timer framework
The commit 89878baa73f0f1c679355006bd8632e5d78f96c2 introduced the CPUIDLE_FLAG_TIMER_STOP flag where we specify a specific idle state stops the local timer. Now use this flag to check at init time if one state will need the broadcast timer and, in this case, setup the broadcast timer framework. That prevents multiple code duplication in the drivers. Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 4dbad81 commit a06df06

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

‎drivers/cpuidle/driver.c‎

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <linux/mutex.h>
1212
#include <linux/module.h>
1313
#include <linux/cpuidle.h>
14+
#include <linux/cpumask.h>
15+
#include <linux/clockchips.h>
1416

1517
#include "cpuidle.h"
1618

@@ -19,9 +21,28 @@ DEFINE_SPINLOCK(cpuidle_driver_lock);
1921
static void __cpuidle_set_cpu_driver(struct cpuidle_driver *drv, int cpu);
2022
static struct cpuidle_driver * __cpuidle_get_cpu_driver(int cpu);
2123

22-
static void __cpuidle_driver_init(struct cpuidle_driver *drv)
24+
static void cpuidle_setup_broadcast_timer(void *arg)
2325
{
26+
int cpu = smp_processor_id();
27+
clockevents_notify((long)(arg), &cpu);
28+
}
29+
30+
static void __cpuidle_driver_init(struct cpuidle_driver *drv, int cpu)
31+
{
32+
int i;
33+
2434
drv->refcnt = 0;
35+
36+
for (i = drv->state_count - 1; i >= 0 ; i--) {
37+
38+
if (!(drv->states[i].flags & CPUIDLE_FLAG_TIMER_STOP))
39+
continue;
40+
41+
drv->bctimer = 1;
42+
on_each_cpu_mask(get_cpu_mask(cpu), cpuidle_setup_broadcast_timer,
43+
(void *)CLOCK_EVT_NOTIFY_BROADCAST_ON, 1);
44+
break;
45+
}
2546
}
2647

2748
static int __cpuidle_register_driver(struct cpuidle_driver *drv, int cpu)
@@ -35,7 +56,7 @@ static int __cpuidle_register_driver(struct cpuidle_driver *drv, int cpu)
3556
if (__cpuidle_get_cpu_driver(cpu))
3657
return -EBUSY;
3758

38-
__cpuidle_driver_init(drv);
59+
__cpuidle_driver_init(drv, cpu);
3960

4061
__cpuidle_set_cpu_driver(drv, cpu);
4162

@@ -49,6 +70,12 @@ static void __cpuidle_unregister_driver(struct cpuidle_driver *drv, int cpu)
4970

5071
if (!WARN_ON(drv->refcnt > 0))
5172
__cpuidle_set_cpu_driver(NULL, cpu);
73+
74+
if (drv->bctimer) {
75+
drv->bctimer = 0;
76+
on_each_cpu_mask(get_cpu_mask(cpu), cpuidle_setup_broadcast_timer,
77+
(void *)CLOCK_EVT_NOTIFY_BROADCAST_OFF, 1);
78+
}
5279
}
5380

5481
#ifdef CONFIG_CPU_IDLE_MULTIPLE_DRIVERS

‎include/linux/cpuidle.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ struct cpuidle_driver {
107107

108108
/* set to 1 to use the core cpuidle time keeping (for all states). */
109109
unsigned int en_core_tk_irqen:1;
110+
/* used by the cpuidle framework to setup the broadcast timer */
111+
unsigned int bctimer:1;
110112
/* states array must be ordered in decreasing power consumption */
111113
struct cpuidle_state states[CPUIDLE_STATE_MAX];
112114
int state_count;

0 commit comments

Comments
 (0)