diff options
author | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2016-12-01 08:39:51 -0500 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2016-12-01 08:39:51 -0500 |
commit | 4e28ec3d5fe0b994fe87b2406d75d9c351ef4940 (patch) | |
tree | af6fbb01ca736ff7e9f57bed685508bd74fc7cac | |
parent | a2c1bc645e87346150516b3abf1933ed29d0f48b (diff) | |
parent | 6af33995318fdfb4914fb1c5e67450fdb3d32084 (diff) |
Merge back earlier cpuidle material for v4.10.
-rw-r--r-- | MAINTAINERS | 3 | ||||
-rw-r--r-- | drivers/cpuidle/cpuidle-powernv.c | 2 | ||||
-rw-r--r-- | drivers/cpuidle/cpuidle.c | 13 | ||||
-rw-r--r-- | drivers/cpuidle/dt_idle_states.c | 6 | ||||
-rw-r--r-- | drivers/cpuidle/governor.c | 4 | ||||
-rw-r--r-- | drivers/cpuidle/governors/ladder.c | 2 | ||||
-rw-r--r-- | drivers/cpuidle/governors/menu.c | 2 | ||||
-rw-r--r-- | include/linux/cpu.h | 2 | ||||
-rw-r--r-- | include/linux/cpuidle.h | 9 | ||||
-rw-r--r-- | include/linux/sched.h | 3 | ||||
-rw-r--r-- | kernel/fork.c | 2 | ||||
-rw-r--r-- | kernel/sched/core.c | 1 | ||||
-rw-r--r-- | kernel/sched/idle.c | 175 |
13 files changed, 143 insertions, 81 deletions
diff --git a/MAINTAINERS b/MAINTAINERS index 8d4148406923..3c7348536c56 100644 --- a/MAINTAINERS +++ b/MAINTAINERS | |||
@@ -3380,6 +3380,7 @@ M: Daniel Lezcano <daniel.lezcano@linaro.org> | |||
3380 | L: linux-pm@vger.kernel.org | 3380 | L: linux-pm@vger.kernel.org |
3381 | S: Maintained | 3381 | S: Maintained |
3382 | T: git git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git | 3382 | T: git git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git |
3383 | B: https://bugzilla.kernel.org | ||
3383 | F: drivers/cpuidle/* | 3384 | F: drivers/cpuidle/* |
3384 | F: include/linux/cpuidle.h | 3385 | F: include/linux/cpuidle.h |
3385 | 3386 | ||
@@ -6289,9 +6290,11 @@ S: Maintained | |||
6289 | F: drivers/platform/x86/intel-vbtn.c | 6290 | F: drivers/platform/x86/intel-vbtn.c |
6290 | 6291 | ||
6291 | INTEL IDLE DRIVER | 6292 | INTEL IDLE DRIVER |
6293 | M: Jacob Pan <jacob.jun.pan@linux.intel.com> | ||
6292 | M: Len Brown <lenb@kernel.org> | 6294 | M: Len Brown <lenb@kernel.org> |
6293 | L: linux-pm@vger.kernel.org | 6295 | L: linux-pm@vger.kernel.org |
6294 | T: git git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux.git | 6296 | T: git git://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux.git |
6297 | B: https://bugzilla.kernel.org | ||
6295 | S: Supported | 6298 | S: Supported |
6296 | F: drivers/idle/intel_idle.c | 6299 | F: drivers/idle/intel_idle.c |
6297 | 6300 | ||
diff --git a/drivers/cpuidle/cpuidle-powernv.c b/drivers/cpuidle/cpuidle-powernv.c index 7fe442ca38f4..0835a37a5f3a 100644 --- a/drivers/cpuidle/cpuidle-powernv.c +++ b/drivers/cpuidle/cpuidle-powernv.c | |||
@@ -22,7 +22,7 @@ | |||
22 | 22 | ||
23 | #define POWERNV_THRESHOLD_LATENCY_NS 200000 | 23 | #define POWERNV_THRESHOLD_LATENCY_NS 200000 |
24 | 24 | ||
25 | struct cpuidle_driver powernv_idle_driver = { | 25 | static struct cpuidle_driver powernv_idle_driver = { |
26 | .name = "powernv_idle", | 26 | .name = "powernv_idle", |
27 | .owner = THIS_MODULE, | 27 | .owner = THIS_MODULE, |
28 | }; | 28 | }; |
diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c index c73207abb5a4..afc005b917fe 100644 --- a/drivers/cpuidle/cpuidle.c +++ b/drivers/cpuidle/cpuidle.c | |||
@@ -97,7 +97,17 @@ static int find_deepest_state(struct cpuidle_driver *drv, | |||
97 | return ret; | 97 | return ret; |
98 | } | 98 | } |
99 | 99 | ||
100 | #ifdef CONFIG_SUSPEND | 100 | /* Set the current cpu to use the deepest idle state, override governors */ |
101 | void cpuidle_use_deepest_state(bool enable) | ||
102 | { | ||
103 | struct cpuidle_device *dev; | ||
104 | |||
105 | preempt_disable(); | ||
106 | dev = cpuidle_get_device(); | ||
107 | dev->use_deepest_state = enable; | ||
108 | preempt_enable(); | ||
109 | } | ||
110 | |||
101 | /** | 111 | /** |
102 | * cpuidle_find_deepest_state - Find the deepest available idle state. | 112 | * cpuidle_find_deepest_state - Find the deepest available idle state. |
103 | * @drv: cpuidle driver for the given CPU. | 113 | * @drv: cpuidle driver for the given CPU. |
@@ -109,6 +119,7 @@ int cpuidle_find_deepest_state(struct cpuidle_driver *drv, | |||
109 | return find_deepest_state(drv, dev, UINT_MAX, 0, false); | 119 | return find_deepest_state(drv, dev, UINT_MAX, 0, false); |
110 | } | 120 | } |
111 | 121 | ||
122 | #ifdef CONFIG_SUSPEND | ||
112 | static void enter_freeze_proper(struct cpuidle_driver *drv, | 123 | static void enter_freeze_proper(struct cpuidle_driver *drv, |
113 | struct cpuidle_device *dev, int index) | 124 | struct cpuidle_device *dev, int index) |
114 | { | 125 | { |
diff --git a/drivers/cpuidle/dt_idle_states.c b/drivers/cpuidle/dt_idle_states.c index a5c111b67f37..ffca4fc0061d 100644 --- a/drivers/cpuidle/dt_idle_states.c +++ b/drivers/cpuidle/dt_idle_states.c | |||
@@ -38,6 +38,12 @@ static int init_state_node(struct cpuidle_state *idle_state, | |||
38 | * state enter function. | 38 | * state enter function. |
39 | */ | 39 | */ |
40 | idle_state->enter = match_id->data; | 40 | idle_state->enter = match_id->data; |
41 | /* | ||
42 | * Since this is not a "coupled" state, it's safe to assume interrupts | ||
43 | * won't be enabled when it exits allowing the tick to be frozen | ||
44 | * safely. So enter() can be also enter_freeze() callback. | ||
45 | */ | ||
46 | idle_state->enter_freeze = match_id->data; | ||
41 | 47 | ||
42 | err = of_property_read_u32(state_node, "wakeup-latency-us", | 48 | err = of_property_read_u32(state_node, "wakeup-latency-us", |
43 | &idle_state->exit_latency); | 49 | &idle_state->exit_latency); |
diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c index fb9f511cca23..4e78263e34a4 100644 --- a/drivers/cpuidle/governor.c +++ b/drivers/cpuidle/governor.c | |||
@@ -9,7 +9,6 @@ | |||
9 | */ | 9 | */ |
10 | 10 | ||
11 | #include <linux/mutex.h> | 11 | #include <linux/mutex.h> |
12 | #include <linux/module.h> | ||
13 | #include <linux/cpuidle.h> | 12 | #include <linux/cpuidle.h> |
14 | 13 | ||
15 | #include "cpuidle.h" | 14 | #include "cpuidle.h" |
@@ -53,14 +52,11 @@ int cpuidle_switch_governor(struct cpuidle_governor *gov) | |||
53 | if (cpuidle_curr_governor) { | 52 | if (cpuidle_curr_governor) { |
54 | list_for_each_entry(dev, &cpuidle_detected_devices, device_list) | 53 | list_for_each_entry(dev, &cpuidle_detected_devices, device_list) |
55 | cpuidle_disable_device(dev); | 54 | cpuidle_disable_device(dev); |
56 | module_put(cpuidle_curr_governor->owner); | ||
57 | } | 55 | } |
58 | 56 | ||
59 | cpuidle_curr_governor = gov; | 57 | cpuidle_curr_governor = gov; |
60 | 58 | ||
61 | if (gov) { | 59 | if (gov) { |
62 | if (!try_module_get(cpuidle_curr_governor->owner)) | ||
63 | return -EINVAL; | ||
64 | list_for_each_entry(dev, &cpuidle_detected_devices, device_list) | 60 | list_for_each_entry(dev, &cpuidle_detected_devices, device_list) |
65 | cpuidle_enable_device(dev); | 61 | cpuidle_enable_device(dev); |
66 | cpuidle_install_idle_handler(); | 62 | cpuidle_install_idle_handler(); |
diff --git a/drivers/cpuidle/governors/ladder.c b/drivers/cpuidle/governors/ladder.c index 63bd5a403e22..fe8f08948fcb 100644 --- a/drivers/cpuidle/governors/ladder.c +++ b/drivers/cpuidle/governors/ladder.c | |||
@@ -15,7 +15,6 @@ | |||
15 | #include <linux/kernel.h> | 15 | #include <linux/kernel.h> |
16 | #include <linux/cpuidle.h> | 16 | #include <linux/cpuidle.h> |
17 | #include <linux/pm_qos.h> | 17 | #include <linux/pm_qos.h> |
18 | #include <linux/module.h> | ||
19 | #include <linux/jiffies.h> | 18 | #include <linux/jiffies.h> |
20 | #include <linux/tick.h> | 19 | #include <linux/tick.h> |
21 | 20 | ||
@@ -177,7 +176,6 @@ static struct cpuidle_governor ladder_governor = { | |||
177 | .enable = ladder_enable_device, | 176 | .enable = ladder_enable_device, |
178 | .select = ladder_select_state, | 177 | .select = ladder_select_state, |
179 | .reflect = ladder_reflect, | 178 | .reflect = ladder_reflect, |
180 | .owner = THIS_MODULE, | ||
181 | }; | 179 | }; |
182 | 180 | ||
183 | /** | 181 | /** |
diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c index 03d38c291de6..d9b5b9398a0f 100644 --- a/drivers/cpuidle/governors/menu.c +++ b/drivers/cpuidle/governors/menu.c | |||
@@ -19,7 +19,6 @@ | |||
19 | #include <linux/tick.h> | 19 | #include <linux/tick.h> |
20 | #include <linux/sched.h> | 20 | #include <linux/sched.h> |
21 | #include <linux/math64.h> | 21 | #include <linux/math64.h> |
22 | #include <linux/module.h> | ||
23 | 22 | ||
24 | /* | 23 | /* |
25 | * Please note when changing the tuning values: | 24 | * Please note when changing the tuning values: |
@@ -484,7 +483,6 @@ static struct cpuidle_governor menu_governor = { | |||
484 | .enable = menu_enable_device, | 483 | .enable = menu_enable_device, |
485 | .select = menu_select, | 484 | .select = menu_select, |
486 | .reflect = menu_reflect, | 485 | .reflect = menu_reflect, |
487 | .owner = THIS_MODULE, | ||
488 | }; | 486 | }; |
489 | 487 | ||
490 | /** | 488 | /** |
diff --git a/include/linux/cpu.h b/include/linux/cpu.h index b886dc17f2f3..ac0efae38072 100644 --- a/include/linux/cpu.h +++ b/include/linux/cpu.h | |||
@@ -245,6 +245,8 @@ void arch_cpu_idle_dead(void); | |||
245 | int cpu_report_state(int cpu); | 245 | int cpu_report_state(int cpu); |
246 | int cpu_check_up_prepare(int cpu); | 246 | int cpu_check_up_prepare(int cpu); |
247 | void cpu_set_state_online(int cpu); | 247 | void cpu_set_state_online(int cpu); |
248 | void play_idle(unsigned long duration_ms); | ||
249 | |||
248 | #ifdef CONFIG_HOTPLUG_CPU | 250 | #ifdef CONFIG_HOTPLUG_CPU |
249 | bool cpu_wait_death(unsigned int cpu, int seconds); | 251 | bool cpu_wait_death(unsigned int cpu, int seconds); |
250 | bool cpu_report_death(void); | 252 | bool cpu_report_death(void); |
diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h index bb31373c3478..da346f2817a8 100644 --- a/include/linux/cpuidle.h +++ b/include/linux/cpuidle.h | |||
@@ -74,6 +74,7 @@ struct cpuidle_driver_kobj; | |||
74 | struct cpuidle_device { | 74 | struct cpuidle_device { |
75 | unsigned int registered:1; | 75 | unsigned int registered:1; |
76 | unsigned int enabled:1; | 76 | unsigned int enabled:1; |
77 | unsigned int use_deepest_state:1; | ||
77 | unsigned int cpu; | 78 | unsigned int cpu; |
78 | 79 | ||
79 | int last_residency; | 80 | int last_residency; |
@@ -192,11 +193,12 @@ static inline struct cpuidle_driver *cpuidle_get_cpu_driver( | |||
192 | static inline struct cpuidle_device *cpuidle_get_device(void) {return NULL; } | 193 | static inline struct cpuidle_device *cpuidle_get_device(void) {return NULL; } |
193 | #endif | 194 | #endif |
194 | 195 | ||
195 | #if defined(CONFIG_CPU_IDLE) && defined(CONFIG_SUSPEND) | 196 | #ifdef CONFIG_CPU_IDLE |
196 | extern int cpuidle_find_deepest_state(struct cpuidle_driver *drv, | 197 | extern int cpuidle_find_deepest_state(struct cpuidle_driver *drv, |
197 | struct cpuidle_device *dev); | 198 | struct cpuidle_device *dev); |
198 | extern int cpuidle_enter_freeze(struct cpuidle_driver *drv, | 199 | extern int cpuidle_enter_freeze(struct cpuidle_driver *drv, |
199 | struct cpuidle_device *dev); | 200 | struct cpuidle_device *dev); |
201 | extern void cpuidle_use_deepest_state(bool enable); | ||
200 | #else | 202 | #else |
201 | static inline int cpuidle_find_deepest_state(struct cpuidle_driver *drv, | 203 | static inline int cpuidle_find_deepest_state(struct cpuidle_driver *drv, |
202 | struct cpuidle_device *dev) | 204 | struct cpuidle_device *dev) |
@@ -204,6 +206,9 @@ static inline int cpuidle_find_deepest_state(struct cpuidle_driver *drv, | |||
204 | static inline int cpuidle_enter_freeze(struct cpuidle_driver *drv, | 206 | static inline int cpuidle_enter_freeze(struct cpuidle_driver *drv, |
205 | struct cpuidle_device *dev) | 207 | struct cpuidle_device *dev) |
206 | {return -ENODEV; } | 208 | {return -ENODEV; } |
209 | static inline void cpuidle_use_deepest_state(bool enable) | ||
210 | { | ||
211 | } | ||
207 | #endif | 212 | #endif |
208 | 213 | ||
209 | /* kernel/sched/idle.c */ | 214 | /* kernel/sched/idle.c */ |
@@ -235,8 +240,6 @@ struct cpuidle_governor { | |||
235 | int (*select) (struct cpuidle_driver *drv, | 240 | int (*select) (struct cpuidle_driver *drv, |
236 | struct cpuidle_device *dev); | 241 | struct cpuidle_device *dev); |
237 | void (*reflect) (struct cpuidle_device *dev, int index); | 242 | void (*reflect) (struct cpuidle_device *dev, int index); |
238 | |||
239 | struct module *owner; | ||
240 | }; | 243 | }; |
241 | 244 | ||
242 | #ifdef CONFIG_CPU_IDLE | 245 | #ifdef CONFIG_CPU_IDLE |
diff --git a/include/linux/sched.h b/include/linux/sched.h index e9c009dc3a4a..a3d338e15b17 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h | |||
@@ -2254,6 +2254,7 @@ extern void thread_group_cputime_adjusted(struct task_struct *p, cputime_t *ut, | |||
2254 | /* | 2254 | /* |
2255 | * Per process flags | 2255 | * Per process flags |
2256 | */ | 2256 | */ |
2257 | #define PF_IDLE 0x00000002 /* I am an IDLE thread */ | ||
2257 | #define PF_EXITING 0x00000004 /* getting shut down */ | 2258 | #define PF_EXITING 0x00000004 /* getting shut down */ |
2258 | #define PF_EXITPIDONE 0x00000008 /* pi exit done on shut down */ | 2259 | #define PF_EXITPIDONE 0x00000008 /* pi exit done on shut down */ |
2259 | #define PF_VCPU 0x00000010 /* I'm a virtual CPU */ | 2260 | #define PF_VCPU 0x00000010 /* I'm a virtual CPU */ |
@@ -2611,7 +2612,7 @@ extern struct task_struct *idle_task(int cpu); | |||
2611 | */ | 2612 | */ |
2612 | static inline bool is_idle_task(const struct task_struct *p) | 2613 | static inline bool is_idle_task(const struct task_struct *p) |
2613 | { | 2614 | { |
2614 | return p->pid == 0; | 2615 | return !!(p->flags & PF_IDLE); |
2615 | } | 2616 | } |
2616 | extern struct task_struct *curr_task(int cpu); | 2617 | extern struct task_struct *curr_task(int cpu); |
2617 | extern void ia64_set_curr_task(int cpu, struct task_struct *p); | 2618 | extern void ia64_set_curr_task(int cpu, struct task_struct *p); |
diff --git a/kernel/fork.c b/kernel/fork.c index 997ac1d584f7..a8eb821d1d4b 100644 --- a/kernel/fork.c +++ b/kernel/fork.c | |||
@@ -1540,7 +1540,7 @@ static __latent_entropy struct task_struct *copy_process( | |||
1540 | goto bad_fork_cleanup_count; | 1540 | goto bad_fork_cleanup_count; |
1541 | 1541 | ||
1542 | delayacct_tsk_init(p); /* Must remain after dup_task_struct() */ | 1542 | delayacct_tsk_init(p); /* Must remain after dup_task_struct() */ |
1543 | p->flags &= ~(PF_SUPERPRIV | PF_WQ_WORKER); | 1543 | p->flags &= ~(PF_SUPERPRIV | PF_WQ_WORKER | PF_IDLE); |
1544 | p->flags |= PF_FORKNOEXEC; | 1544 | p->flags |= PF_FORKNOEXEC; |
1545 | INIT_LIST_HEAD(&p->children); | 1545 | INIT_LIST_HEAD(&p->children); |
1546 | INIT_LIST_HEAD(&p->sibling); | 1546 | INIT_LIST_HEAD(&p->sibling); |
diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 154fd689fe02..c95fbcd9fe1f 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c | |||
@@ -5279,6 +5279,7 @@ void init_idle(struct task_struct *idle, int cpu) | |||
5279 | __sched_fork(0, idle); | 5279 | __sched_fork(0, idle); |
5280 | idle->state = TASK_RUNNING; | 5280 | idle->state = TASK_RUNNING; |
5281 | idle->se.exec_start = sched_clock(); | 5281 | idle->se.exec_start = sched_clock(); |
5282 | idle->flags |= PF_IDLE; | ||
5282 | 5283 | ||
5283 | kasan_unpoison_task_stack(idle); | 5284 | kasan_unpoison_task_stack(idle); |
5284 | 5285 | ||
diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c index 1d8718d5300d..6a4bae0a649d 100644 --- a/kernel/sched/idle.c +++ b/kernel/sched/idle.c | |||
@@ -164,11 +164,14 @@ static void cpuidle_idle_call(void) | |||
164 | * timekeeping to prevent timer interrupts from kicking us out of idle | 164 | * timekeeping to prevent timer interrupts from kicking us out of idle |
165 | * until a proper wakeup interrupt happens. | 165 | * until a proper wakeup interrupt happens. |
166 | */ | 166 | */ |
167 | if (idle_should_freeze()) { | 167 | |
168 | entered_state = cpuidle_enter_freeze(drv, dev); | 168 | if (idle_should_freeze() || dev->use_deepest_state) { |
169 | if (entered_state > 0) { | 169 | if (idle_should_freeze()) { |
170 | local_irq_enable(); | 170 | entered_state = cpuidle_enter_freeze(drv, dev); |
171 | goto exit_idle; | 171 | if (entered_state > 0) { |
172 | local_irq_enable(); | ||
173 | goto exit_idle; | ||
174 | } | ||
172 | } | 175 | } |
173 | 176 | ||
174 | next_state = cpuidle_find_deepest_state(drv, dev); | 177 | next_state = cpuidle_find_deepest_state(drv, dev); |
@@ -202,76 +205,65 @@ exit_idle: | |||
202 | * | 205 | * |
203 | * Called with polling cleared. | 206 | * Called with polling cleared. |
204 | */ | 207 | */ |
205 | static void cpu_idle_loop(void) | 208 | static void do_idle(void) |
206 | { | 209 | { |
207 | int cpu = smp_processor_id(); | 210 | /* |
208 | 211 | * If the arch has a polling bit, we maintain an invariant: | |
209 | while (1) { | 212 | * |
210 | /* | 213 | * Our polling bit is clear if we're not scheduled (i.e. if rq->curr != |
211 | * If the arch has a polling bit, we maintain an invariant: | 214 | * rq->idle). This means that, if rq->idle has the polling bit set, |
212 | * | 215 | * then setting need_resched is guaranteed to cause the CPU to |
213 | * Our polling bit is clear if we're not scheduled (i.e. if | 216 | * reschedule. |
214 | * rq->curr != rq->idle). This means that, if rq->idle has | 217 | */ |
215 | * the polling bit set, then setting need_resched is | ||
216 | * guaranteed to cause the cpu to reschedule. | ||
217 | */ | ||
218 | |||
219 | __current_set_polling(); | ||
220 | quiet_vmstat(); | ||
221 | tick_nohz_idle_enter(); | ||
222 | 218 | ||
223 | while (!need_resched()) { | 219 | __current_set_polling(); |
224 | check_pgt_cache(); | 220 | tick_nohz_idle_enter(); |
225 | rmb(); | ||
226 | 221 | ||
227 | if (cpu_is_offline(cpu)) { | 222 | while (!need_resched()) { |
228 | cpuhp_report_idle_dead(); | 223 | check_pgt_cache(); |
229 | arch_cpu_idle_dead(); | 224 | rmb(); |
230 | } | ||
231 | 225 | ||
232 | local_irq_disable(); | 226 | if (cpu_is_offline(smp_processor_id())) { |
233 | arch_cpu_idle_enter(); | 227 | cpuhp_report_idle_dead(); |
234 | 228 | arch_cpu_idle_dead(); | |
235 | /* | ||
236 | * In poll mode we reenable interrupts and spin. | ||
237 | * | ||
238 | * Also if we detected in the wakeup from idle | ||
239 | * path that the tick broadcast device expired | ||
240 | * for us, we don't want to go deep idle as we | ||
241 | * know that the IPI is going to arrive right | ||
242 | * away | ||
243 | */ | ||
244 | if (cpu_idle_force_poll || tick_check_broadcast_expired()) | ||
245 | cpu_idle_poll(); | ||
246 | else | ||
247 | cpuidle_idle_call(); | ||
248 | |||
249 | arch_cpu_idle_exit(); | ||
250 | } | 229 | } |
251 | 230 | ||
252 | /* | 231 | local_irq_disable(); |
253 | * Since we fell out of the loop above, we know | 232 | arch_cpu_idle_enter(); |
254 | * TIF_NEED_RESCHED must be set, propagate it into | ||
255 | * PREEMPT_NEED_RESCHED. | ||
256 | * | ||
257 | * This is required because for polling idle loops we will | ||
258 | * not have had an IPI to fold the state for us. | ||
259 | */ | ||
260 | preempt_set_need_resched(); | ||
261 | tick_nohz_idle_exit(); | ||
262 | __current_clr_polling(); | ||
263 | 233 | ||
264 | /* | 234 | /* |
265 | * We promise to call sched_ttwu_pending and reschedule | 235 | * In poll mode we reenable interrupts and spin. Also if we |
266 | * if need_resched is set while polling is set. That | 236 | * detected in the wakeup from idle path that the tick |
267 | * means that clearing polling needs to be visible | 237 | * broadcast device expired for us, we don't want to go deep |
268 | * before doing these things. | 238 | * idle as we know that the IPI is going to arrive right away. |
269 | */ | 239 | */ |
270 | smp_mb__after_atomic(); | 240 | if (cpu_idle_force_poll || tick_check_broadcast_expired()) |
271 | 241 | cpu_idle_poll(); | |
272 | sched_ttwu_pending(); | 242 | else |
273 | schedule_preempt_disabled(); | 243 | cpuidle_idle_call(); |
244 | arch_cpu_idle_exit(); | ||
274 | } | 245 | } |
246 | |||
247 | /* | ||
248 | * Since we fell out of the loop above, we know TIF_NEED_RESCHED must | ||
249 | * be set, propagate it into PREEMPT_NEED_RESCHED. | ||
250 | * | ||
251 | * This is required because for polling idle loops we will not have had | ||
252 | * an IPI to fold the state for us. | ||
253 | */ | ||
254 | preempt_set_need_resched(); | ||
255 | tick_nohz_idle_exit(); | ||
256 | __current_clr_polling(); | ||
257 | |||
258 | /* | ||
259 | * We promise to call sched_ttwu_pending() and reschedule if | ||
260 | * need_resched() is set while polling is set. That means that clearing | ||
261 | * polling needs to be visible before doing these things. | ||
262 | */ | ||
263 | smp_mb__after_atomic(); | ||
264 | |||
265 | sched_ttwu_pending(); | ||
266 | schedule_preempt_disabled(); | ||
275 | } | 267 | } |
276 | 268 | ||
277 | bool cpu_in_idle(unsigned long pc) | 269 | bool cpu_in_idle(unsigned long pc) |
@@ -280,6 +272,56 @@ bool cpu_in_idle(unsigned long pc) | |||
280 | pc < (unsigned long)__cpuidle_text_end; | 272 | pc < (unsigned long)__cpuidle_text_end; |
281 | } | 273 | } |
282 | 274 | ||
275 | struct idle_timer { | ||
276 | struct hrtimer timer; | ||
277 | int done; | ||
278 | }; | ||
279 | |||
280 | static enum hrtimer_restart idle_inject_timer_fn(struct hrtimer *timer) | ||
281 | { | ||
282 | struct idle_timer *it = container_of(timer, struct idle_timer, timer); | ||
283 | |||
284 | WRITE_ONCE(it->done, 1); | ||
285 | set_tsk_need_resched(current); | ||
286 | |||
287 | return HRTIMER_NORESTART; | ||
288 | } | ||
289 | |||
290 | void play_idle(unsigned long duration_ms) | ||
291 | { | ||
292 | struct idle_timer it; | ||
293 | |||
294 | /* | ||
295 | * Only FIFO tasks can disable the tick since they don't need the forced | ||
296 | * preemption. | ||
297 | */ | ||
298 | WARN_ON_ONCE(current->policy != SCHED_FIFO); | ||
299 | WARN_ON_ONCE(current->nr_cpus_allowed != 1); | ||
300 | WARN_ON_ONCE(!(current->flags & PF_KTHREAD)); | ||
301 | WARN_ON_ONCE(!(current->flags & PF_NO_SETAFFINITY)); | ||
302 | WARN_ON_ONCE(!duration_ms); | ||
303 | |||
304 | rcu_sleep_check(); | ||
305 | preempt_disable(); | ||
306 | current->flags |= PF_IDLE; | ||
307 | cpuidle_use_deepest_state(true); | ||
308 | |||
309 | it.done = 0; | ||
310 | hrtimer_init_on_stack(&it.timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); | ||
311 | it.timer.function = idle_inject_timer_fn; | ||
312 | hrtimer_start(&it.timer, ms_to_ktime(duration_ms), HRTIMER_MODE_REL_PINNED); | ||
313 | |||
314 | while (!READ_ONCE(it.done)) | ||
315 | do_idle(); | ||
316 | |||
317 | cpuidle_use_deepest_state(false); | ||
318 | current->flags &= ~PF_IDLE; | ||
319 | |||
320 | preempt_fold_need_resched(); | ||
321 | preempt_enable(); | ||
322 | } | ||
323 | EXPORT_SYMBOL_GPL(play_idle); | ||
324 | |||
283 | void cpu_startup_entry(enum cpuhp_state state) | 325 | void cpu_startup_entry(enum cpuhp_state state) |
284 | { | 326 | { |
285 | /* | 327 | /* |
@@ -299,5 +341,6 @@ void cpu_startup_entry(enum cpuhp_state state) | |||
299 | #endif | 341 | #endif |
300 | arch_cpu_idle_prepare(); | 342 | arch_cpu_idle_prepare(); |
301 | cpuhp_online_idle(state); | 343 | cpuhp_online_idle(state); |
302 | cpu_idle_loop(); | 344 | while (1) |
345 | do_idle(); | ||
303 | } | 346 | } |