blob: dd1c7e9d7fb080a752041c5807ec038593590f0d [file] [log] [blame]
Ingo Molnarbb44e5d2007-07-09 18:51:58 +02001/*
2 * Real-Time Scheduling Class (mapped to the SCHED_FIFO and SCHED_RR
3 * policies)
4 */
5
Peter Zijlstra029632f2011-10-25 10:00:11 +02006#include "sched.h"
7
8#include <linux/slab.h>
9
10static int do_sched_rt_period_timer(struct rt_bandwidth *rt_b, int overrun);
11
12struct rt_bandwidth def_rt_bandwidth;
13
14static enum hrtimer_restart sched_rt_period_timer(struct hrtimer *timer)
15{
16 struct rt_bandwidth *rt_b =
17 container_of(timer, struct rt_bandwidth, rt_period_timer);
18 ktime_t now;
19 int overrun;
20 int idle = 0;
21
22 for (;;) {
23 now = hrtimer_cb_get_time(timer);
24 overrun = hrtimer_forward(timer, now, rt_b->rt_period);
25
26 if (!overrun)
27 break;
28
29 idle = do_sched_rt_period_timer(rt_b, overrun);
30 }
31
32 return idle ? HRTIMER_NORESTART : HRTIMER_RESTART;
33}
34
35void init_rt_bandwidth(struct rt_bandwidth *rt_b, u64 period, u64 runtime)
36{
37 rt_b->rt_period = ns_to_ktime(period);
38 rt_b->rt_runtime = runtime;
39
40 raw_spin_lock_init(&rt_b->rt_runtime_lock);
41
42 hrtimer_init(&rt_b->rt_period_timer,
43 CLOCK_MONOTONIC, HRTIMER_MODE_REL);
44 rt_b->rt_period_timer.function = sched_rt_period_timer;
45}
46
47static void start_rt_bandwidth(struct rt_bandwidth *rt_b)
48{
49 if (!rt_bandwidth_enabled() || rt_b->rt_runtime == RUNTIME_INF)
50 return;
51
52 if (hrtimer_active(&rt_b->rt_period_timer))
53 return;
54
55 raw_spin_lock(&rt_b->rt_runtime_lock);
56 start_bandwidth_timer(&rt_b->rt_period_timer, rt_b->rt_period);
57 raw_spin_unlock(&rt_b->rt_runtime_lock);
58}
59
60void init_rt_rq(struct rt_rq *rt_rq, struct rq *rq)
61{
62 struct rt_prio_array *array;
63 int i;
64
65 array = &rt_rq->active;
66 for (i = 0; i < MAX_RT_PRIO; i++) {
67 INIT_LIST_HEAD(array->queue + i);
68 __clear_bit(i, array->bitmap);
69 }
70 /* delimiter for bitsearch: */
71 __set_bit(MAX_RT_PRIO, array->bitmap);
72
73#if defined CONFIG_SMP
74 rt_rq->highest_prio.curr = MAX_RT_PRIO;
75 rt_rq->highest_prio.next = MAX_RT_PRIO;
76 rt_rq->rt_nr_migratory = 0;
77 rt_rq->overloaded = 0;
78 plist_head_init(&rt_rq->pushable_tasks);
79#endif
80
81 rt_rq->rt_time = 0;
82 rt_rq->rt_throttled = 0;
83 rt_rq->rt_runtime = 0;
84 raw_spin_lock_init(&rt_rq->rt_runtime_lock);
85}
86
Gregory Haskins398a1532009-01-14 09:10:04 -050087#ifdef CONFIG_RT_GROUP_SCHED
Peter Zijlstra029632f2011-10-25 10:00:11 +020088static void destroy_rt_bandwidth(struct rt_bandwidth *rt_b)
89{
90 hrtimer_cancel(&rt_b->rt_period_timer);
91}
Gregory Haskins398a1532009-01-14 09:10:04 -050092
Peter Zijlstraa1ba4d82009-04-01 18:40:15 +020093#define rt_entity_is_task(rt_se) (!(rt_se)->my_q)
94
Peter Zijlstra8f488942009-07-24 12:25:30 +020095static inline struct task_struct *rt_task_of(struct sched_rt_entity *rt_se)
96{
97#ifdef CONFIG_SCHED_DEBUG
98 WARN_ON_ONCE(!rt_entity_is_task(rt_se));
99#endif
100 return container_of(rt_se, struct task_struct, rt);
101}
102
Gregory Haskins398a1532009-01-14 09:10:04 -0500103static inline struct rq *rq_of_rt_rq(struct rt_rq *rt_rq)
104{
105 return rt_rq->rq;
106}
107
108static inline struct rt_rq *rt_rq_of_se(struct sched_rt_entity *rt_se)
109{
110 return rt_se->rt_rq;
111}
112
Peter Zijlstra029632f2011-10-25 10:00:11 +0200113void free_rt_sched_group(struct task_group *tg)
114{
115 int i;
116
117 if (tg->rt_se)
118 destroy_rt_bandwidth(&tg->rt_bandwidth);
119
120 for_each_possible_cpu(i) {
121 if (tg->rt_rq)
122 kfree(tg->rt_rq[i]);
123 if (tg->rt_se)
124 kfree(tg->rt_se[i]);
125 }
126
127 kfree(tg->rt_rq);
128 kfree(tg->rt_se);
129}
130
131void init_tg_rt_entry(struct task_group *tg, struct rt_rq *rt_rq,
132 struct sched_rt_entity *rt_se, int cpu,
133 struct sched_rt_entity *parent)
134{
135 struct rq *rq = cpu_rq(cpu);
136
137 rt_rq->highest_prio.curr = MAX_RT_PRIO;
138 rt_rq->rt_nr_boosted = 0;
139 rt_rq->rq = rq;
140 rt_rq->tg = tg;
141
142 tg->rt_rq[cpu] = rt_rq;
143 tg->rt_se[cpu] = rt_se;
144
145 if (!rt_se)
146 return;
147
148 if (!parent)
149 rt_se->rt_rq = &rq->rt;
150 else
151 rt_se->rt_rq = parent->my_q;
152
153 rt_se->my_q = rt_rq;
154 rt_se->parent = parent;
155 INIT_LIST_HEAD(&rt_se->run_list);
156}
157
158int alloc_rt_sched_group(struct task_group *tg, struct task_group *parent)
159{
160 struct rt_rq *rt_rq;
161 struct sched_rt_entity *rt_se;
162 int i;
163
164 tg->rt_rq = kzalloc(sizeof(rt_rq) * nr_cpu_ids, GFP_KERNEL);
165 if (!tg->rt_rq)
166 goto err;
167 tg->rt_se = kzalloc(sizeof(rt_se) * nr_cpu_ids, GFP_KERNEL);
168 if (!tg->rt_se)
169 goto err;
170
171 init_rt_bandwidth(&tg->rt_bandwidth,
172 ktime_to_ns(def_rt_bandwidth.rt_period), 0);
173
174 for_each_possible_cpu(i) {
175 rt_rq = kzalloc_node(sizeof(struct rt_rq),
176 GFP_KERNEL, cpu_to_node(i));
177 if (!rt_rq)
178 goto err;
179
180 rt_se = kzalloc_node(sizeof(struct sched_rt_entity),
181 GFP_KERNEL, cpu_to_node(i));
182 if (!rt_se)
183 goto err_free_rq;
184
185 init_rt_rq(rt_rq, cpu_rq(i));
186 rt_rq->rt_runtime = tg->rt_bandwidth.rt_runtime;
187 init_tg_rt_entry(tg, rt_rq, rt_se, i, parent->rt_se[i]);
188 }
189
190 return 1;
191
192err_free_rq:
193 kfree(rt_rq);
194err:
195 return 0;
196}
197
Gregory Haskins398a1532009-01-14 09:10:04 -0500198#else /* CONFIG_RT_GROUP_SCHED */
199
Peter Zijlstraa1ba4d82009-04-01 18:40:15 +0200200#define rt_entity_is_task(rt_se) (1)
201
Peter Zijlstra8f488942009-07-24 12:25:30 +0200202static inline struct task_struct *rt_task_of(struct sched_rt_entity *rt_se)
203{
204 return container_of(rt_se, struct task_struct, rt);
205}
206
Gregory Haskins398a1532009-01-14 09:10:04 -0500207static inline struct rq *rq_of_rt_rq(struct rt_rq *rt_rq)
208{
209 return container_of(rt_rq, struct rq, rt);
210}
211
212static inline struct rt_rq *rt_rq_of_se(struct sched_rt_entity *rt_se)
213{
214 struct task_struct *p = rt_task_of(rt_se);
215 struct rq *rq = task_rq(p);
216
217 return &rq->rt;
218}
219
Peter Zijlstra029632f2011-10-25 10:00:11 +0200220void free_rt_sched_group(struct task_group *tg) { }
221
222int alloc_rt_sched_group(struct task_group *tg, struct task_group *parent)
223{
224 return 1;
225}
Gregory Haskins398a1532009-01-14 09:10:04 -0500226#endif /* CONFIG_RT_GROUP_SCHED */
227
Steven Rostedt4fd29172008-01-25 21:08:06 +0100228#ifdef CONFIG_SMP
Ingo Molnar84de4272008-01-25 21:08:15 +0100229
Gregory Haskins637f5082008-01-25 21:08:18 +0100230static inline int rt_overloaded(struct rq *rq)
Steven Rostedt4fd29172008-01-25 21:08:06 +0100231{
Gregory Haskins637f5082008-01-25 21:08:18 +0100232 return atomic_read(&rq->rd->rto_count);
Steven Rostedt4fd29172008-01-25 21:08:06 +0100233}
Ingo Molnar84de4272008-01-25 21:08:15 +0100234
Steven Rostedt4fd29172008-01-25 21:08:06 +0100235static inline void rt_set_overload(struct rq *rq)
236{
Gregory Haskins1f11eb62008-06-04 15:04:05 -0400237 if (!rq->online)
238 return;
239
Rusty Russellc6c49272008-11-25 02:35:05 +1030240 cpumask_set_cpu(rq->cpu, rq->rd->rto_mask);
Steven Rostedt4fd29172008-01-25 21:08:06 +0100241 /*
242 * Make sure the mask is visible before we set
243 * the overload count. That is checked to determine
244 * if we should look at the mask. It would be a shame
245 * if we looked at the mask, but the mask was not
246 * updated yet.
247 */
248 wmb();
Gregory Haskins637f5082008-01-25 21:08:18 +0100249 atomic_inc(&rq->rd->rto_count);
Steven Rostedt4fd29172008-01-25 21:08:06 +0100250}
Ingo Molnar84de4272008-01-25 21:08:15 +0100251
Steven Rostedt4fd29172008-01-25 21:08:06 +0100252static inline void rt_clear_overload(struct rq *rq)
253{
Gregory Haskins1f11eb62008-06-04 15:04:05 -0400254 if (!rq->online)
255 return;
256
Steven Rostedt4fd29172008-01-25 21:08:06 +0100257 /* the order here really doesn't matter */
Gregory Haskins637f5082008-01-25 21:08:18 +0100258 atomic_dec(&rq->rd->rto_count);
Rusty Russellc6c49272008-11-25 02:35:05 +1030259 cpumask_clear_cpu(rq->cpu, rq->rd->rto_mask);
Steven Rostedt4fd29172008-01-25 21:08:06 +0100260}
Gregory Haskins73fe6aa2008-01-25 21:08:07 +0100261
Gregory Haskins398a1532009-01-14 09:10:04 -0500262static void update_rt_migration(struct rt_rq *rt_rq)
Gregory Haskins73fe6aa2008-01-25 21:08:07 +0100263{
Peter Zijlstraa1ba4d82009-04-01 18:40:15 +0200264 if (rt_rq->rt_nr_migratory && rt_rq->rt_nr_total > 1) {
Gregory Haskins398a1532009-01-14 09:10:04 -0500265 if (!rt_rq->overloaded) {
266 rt_set_overload(rq_of_rt_rq(rt_rq));
267 rt_rq->overloaded = 1;
Gregory Haskinscdc8eb92008-01-25 21:08:23 +0100268 }
Gregory Haskins398a1532009-01-14 09:10:04 -0500269 } else if (rt_rq->overloaded) {
270 rt_clear_overload(rq_of_rt_rq(rt_rq));
271 rt_rq->overloaded = 0;
Gregory Haskins637f5082008-01-25 21:08:18 +0100272 }
Gregory Haskins73fe6aa2008-01-25 21:08:07 +0100273}
Steven Rostedt4fd29172008-01-25 21:08:06 +0100274
Gregory Haskins398a1532009-01-14 09:10:04 -0500275static void inc_rt_migration(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq)
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100276{
Peter Zijlstraa1ba4d82009-04-01 18:40:15 +0200277 if (!rt_entity_is_task(rt_se))
278 return;
279
280 rt_rq = &rq_of_rt_rq(rt_rq)->rt;
281
282 rt_rq->rt_nr_total++;
Gregory Haskins398a1532009-01-14 09:10:04 -0500283 if (rt_se->nr_cpus_allowed > 1)
284 rt_rq->rt_nr_migratory++;
285
286 update_rt_migration(rt_rq);
Peter Zijlstra6f505b12008-01-25 21:08:30 +0100287}
288
Gregory Haskins398a1532009-01-14 09:10:04 -0500289static void dec_rt_migration(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq)
290{
Peter Zijlstraa1ba4d82009-04-01 18:40:15 +0200291 if (!rt_entity_is_task(rt_se))
292 return;
293
294 rt_rq = &rq_of_rt_rq(rt_rq)->rt;
295
296 rt_rq->rt_nr_total--;
Gregory Haskins398a1532009-01-14 09:10:04 -0500297 if (rt_se->nr_cpus_allowed > 1)
298 rt_rq->rt_nr_migratory--;
299
300 update_rt_migration(rt_rq);
301}
302
Steven Rostedt5181f4a2011-06-16 21:55:23 -0400303static inline int has_pushable_tasks(struct rq *rq)
304{
305 return !plist_head_empty(&rq->rt.pushable_tasks);
306}
307
Gregory Haskins917b6272008-12-29 09:39:53 -0500308static void enqueue_pushable_task(struct rq *rq, struct task_struct *p)
309{
310 plist_del(&p->pushable_tasks, &rq->rt.pushable_tasks);
311 plist_node_init(&p->pushable_tasks, p->prio);
312 plist_add(&p->pushable_tasks, &rq->rt.pushable_tasks);
Steven Rostedt5181f4a2011-06-16 21:55:23 -0400313
314 /* Update the highest prio pushable task */
315 if (p->prio < rq->rt.highest_prio.next)
316 rq->rt.highest_prio.next = p->prio;
Gregory Haskins917b6272008-12-29 09:39:53 -0500317}
318
319static void dequeue_pushable_task(struct rq *rq, struct task_struct *p)
320{
321 plist_del(&p->pushable_tasks, &rq->rt.pushable_tasks);
Gregory Haskins917b6272008-12-29 09:39:53 -0500322
Steven Rostedt5181f4a2011-06-16 21:55:23 -0400323 /* Update the new highest prio pushable task */
324 if (has_pushable_tasks(rq)) {
325 p = plist_first_entry(&rq->rt.pushable_tasks,
326 struct task_struct, pushable_tasks);
327 rq->rt.highest_prio.next = p->prio;
328 } else
329 rq->rt.highest_prio.next = MAX_RT_PRIO;
Ingo Molnarbcf08df2008-04-19 12:11:10 +0200330}
331
Gregory Haskins917b6272008-12-29 09:39:53 -0500332#else
333
Peter Zijlstraceacc2c2009-01-16 14:46:40 +0100334static inline void enqueue_pushable_task(struct rq *rq, struct task_struct *p)
335{
336}
337
338static inline void dequeue_pushable_task(struct rq *rq, struct task_struct *p)
339{
340}
341
Gregory Haskinsb07430a2009-01-14 08:55:39 -0500342static inline
Peter Zijlstraceacc2c2009-01-16 14:46:40 +0100343void inc_rt_migration(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq)
344{
345}
346
Gregory Haskinsb07430a2009-01-14 08:55:39 -0500347static inline
Peter Zijlstraceacc2c2009-01-16 14:46:40 +0100348void dec_rt_migration(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq)
349{
350}
Gregory Haskins917b6272008-12-29 09:39:53 -0500351
Ingo Molnarbb44e5d2007-07-09 18:51:58 +0200352#endif /* CONFIG_SMP */
353
Peter Zijlstra6f505b12008-01-25 21:08:30 +0100354static inline int on_rt_rq(struct sched_rt_entity *rt_se)
355{
356 return !list_empty(&rt_se->run_list);
357}
358
Peter Zijlstra052f1dc2008-02-13 15:45:40 +0100359#ifdef CONFIG_RT_GROUP_SCHED
Peter Zijlstra6f505b12008-01-25 21:08:30 +0100360
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100361static inline u64 sched_rt_runtime(struct rt_rq *rt_rq)
Peter Zijlstra6f505b12008-01-25 21:08:30 +0100362{
363 if (!rt_rq->tg)
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100364 return RUNTIME_INF;
Peter Zijlstra6f505b12008-01-25 21:08:30 +0100365
Peter Zijlstraac086bc2008-04-19 19:44:58 +0200366 return rt_rq->rt_runtime;
367}
368
369static inline u64 sched_rt_period(struct rt_rq *rt_rq)
370{
371 return ktime_to_ns(rt_rq->tg->rt_bandwidth.rt_period);
Peter Zijlstra6f505b12008-01-25 21:08:30 +0100372}
373
Cheng Xuec514c42011-05-14 14:20:02 +0800374typedef struct task_group *rt_rq_iter_t;
375
Yong Zhang1c09ab02011-06-28 10:51:31 +0800376static inline struct task_group *next_task_group(struct task_group *tg)
377{
378 do {
379 tg = list_entry_rcu(tg->list.next,
380 typeof(struct task_group), list);
381 } while (&tg->list != &task_groups && task_group_is_autogroup(tg));
382
383 if (&tg->list == &task_groups)
384 tg = NULL;
385
386 return tg;
387}
388
389#define for_each_rt_rq(rt_rq, iter, rq) \
390 for (iter = container_of(&task_groups, typeof(*iter), list); \
391 (iter = next_task_group(iter)) && \
392 (rt_rq = iter->rt_rq[cpu_of(rq)]);)
Cheng Xuec514c42011-05-14 14:20:02 +0800393
Peter Zijlstra3d4b47b2010-11-15 15:47:01 -0800394static inline void list_add_leaf_rt_rq(struct rt_rq *rt_rq)
395{
396 list_add_rcu(&rt_rq->leaf_rt_rq_list,
397 &rq_of_rt_rq(rt_rq)->leaf_rt_rq_list);
398}
399
400static inline void list_del_leaf_rt_rq(struct rt_rq *rt_rq)
401{
402 list_del_rcu(&rt_rq->leaf_rt_rq_list);
403}
404
Peter Zijlstra6f505b12008-01-25 21:08:30 +0100405#define for_each_leaf_rt_rq(rt_rq, rq) \
Bharata B Rao80f40ee2008-12-15 11:56:48 +0530406 list_for_each_entry_rcu(rt_rq, &rq->leaf_rt_rq_list, leaf_rt_rq_list)
Peter Zijlstra6f505b12008-01-25 21:08:30 +0100407
Peter Zijlstra6f505b12008-01-25 21:08:30 +0100408#define for_each_sched_rt_entity(rt_se) \
409 for (; rt_se; rt_se = rt_se->parent)
410
411static inline struct rt_rq *group_rt_rq(struct sched_rt_entity *rt_se)
412{
413 return rt_se->my_q;
414}
415
Thomas Gleixner37dad3f2010-01-20 20:59:01 +0000416static void enqueue_rt_entity(struct sched_rt_entity *rt_se, bool head);
Peter Zijlstra6f505b12008-01-25 21:08:30 +0100417static void dequeue_rt_entity(struct sched_rt_entity *rt_se);
418
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100419static void sched_rt_rq_enqueue(struct rt_rq *rt_rq)
Peter Zijlstra6f505b12008-01-25 21:08:30 +0100420{
Dario Faggiolif6121f42008-10-03 17:40:46 +0200421 struct task_struct *curr = rq_of_rt_rq(rt_rq)->curr;
Yong Zhang74b7eb52010-01-29 14:57:52 +0800422 struct sched_rt_entity *rt_se;
423
Balbir Singh0c3b9162011-03-03 17:04:35 +0530424 int cpu = cpu_of(rq_of_rt_rq(rt_rq));
425
426 rt_se = rt_rq->tg->rt_se[cpu];
Peter Zijlstra6f505b12008-01-25 21:08:30 +0100427
Dario Faggiolif6121f42008-10-03 17:40:46 +0200428 if (rt_rq->rt_nr_running) {
429 if (rt_se && !on_rt_rq(rt_se))
Thomas Gleixner37dad3f2010-01-20 20:59:01 +0000430 enqueue_rt_entity(rt_se, false);
Gregory Haskinse864c492008-12-29 09:39:49 -0500431 if (rt_rq->highest_prio.curr < curr->prio)
Peter Zijlstra10203872008-01-25 21:08:32 +0100432 resched_task(curr);
Peter Zijlstra6f505b12008-01-25 21:08:30 +0100433 }
434}
435
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100436static void sched_rt_rq_dequeue(struct rt_rq *rt_rq)
Peter Zijlstra6f505b12008-01-25 21:08:30 +0100437{
Yong Zhang74b7eb52010-01-29 14:57:52 +0800438 struct sched_rt_entity *rt_se;
Balbir Singh0c3b9162011-03-03 17:04:35 +0530439 int cpu = cpu_of(rq_of_rt_rq(rt_rq));
Yong Zhang74b7eb52010-01-29 14:57:52 +0800440
Balbir Singh0c3b9162011-03-03 17:04:35 +0530441 rt_se = rt_rq->tg->rt_se[cpu];
Peter Zijlstra6f505b12008-01-25 21:08:30 +0100442
443 if (rt_se && on_rt_rq(rt_se))
444 dequeue_rt_entity(rt_se);
445}
446
Peter Zijlstra23b0fdf2008-02-13 15:45:39 +0100447static inline int rt_rq_throttled(struct rt_rq *rt_rq)
448{
449 return rt_rq->rt_throttled && !rt_rq->rt_nr_boosted;
450}
451
452static int rt_se_boosted(struct sched_rt_entity *rt_se)
453{
454 struct rt_rq *rt_rq = group_rt_rq(rt_se);
455 struct task_struct *p;
456
457 if (rt_rq)
458 return !!rt_rq->rt_nr_boosted;
459
460 p = rt_task_of(rt_se);
461 return p->prio != p->normal_prio;
462}
463
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200464#ifdef CONFIG_SMP
Rusty Russellc6c49272008-11-25 02:35:05 +1030465static inline const struct cpumask *sched_rt_period_mask(void)
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200466{
467 return cpu_rq(smp_processor_id())->rd->span;
468}
469#else
Rusty Russellc6c49272008-11-25 02:35:05 +1030470static inline const struct cpumask *sched_rt_period_mask(void)
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200471{
Rusty Russellc6c49272008-11-25 02:35:05 +1030472 return cpu_online_mask;
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200473}
474#endif
475
476static inline
477struct rt_rq *sched_rt_period_rt_rq(struct rt_bandwidth *rt_b, int cpu)
478{
479 return container_of(rt_b, struct task_group, rt_bandwidth)->rt_rq[cpu];
480}
481
Peter Zijlstraac086bc2008-04-19 19:44:58 +0200482static inline struct rt_bandwidth *sched_rt_bandwidth(struct rt_rq *rt_rq)
483{
484 return &rt_rq->tg->rt_bandwidth;
485}
486
Dhaval Giani55e12e52008-06-24 23:39:43 +0530487#else /* !CONFIG_RT_GROUP_SCHED */
Peter Zijlstra6f505b12008-01-25 21:08:30 +0100488
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100489static inline u64 sched_rt_runtime(struct rt_rq *rt_rq)
Peter Zijlstra6f505b12008-01-25 21:08:30 +0100490{
Peter Zijlstraac086bc2008-04-19 19:44:58 +0200491 return rt_rq->rt_runtime;
492}
493
494static inline u64 sched_rt_period(struct rt_rq *rt_rq)
495{
496 return ktime_to_ns(def_rt_bandwidth.rt_period);
Peter Zijlstra6f505b12008-01-25 21:08:30 +0100497}
498
Cheng Xuec514c42011-05-14 14:20:02 +0800499typedef struct rt_rq *rt_rq_iter_t;
500
501#define for_each_rt_rq(rt_rq, iter, rq) \
502 for ((void) iter, rt_rq = &rq->rt; rt_rq; rt_rq = NULL)
503
Peter Zijlstra3d4b47b2010-11-15 15:47:01 -0800504static inline void list_add_leaf_rt_rq(struct rt_rq *rt_rq)
505{
506}
507
508static inline void list_del_leaf_rt_rq(struct rt_rq *rt_rq)
509{
510}
511
Peter Zijlstra6f505b12008-01-25 21:08:30 +0100512#define for_each_leaf_rt_rq(rt_rq, rq) \
513 for (rt_rq = &rq->rt; rt_rq; rt_rq = NULL)
514
Peter Zijlstra6f505b12008-01-25 21:08:30 +0100515#define for_each_sched_rt_entity(rt_se) \
516 for (; rt_se; rt_se = NULL)
517
518static inline struct rt_rq *group_rt_rq(struct sched_rt_entity *rt_se)
519{
520 return NULL;
521}
522
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100523static inline void sched_rt_rq_enqueue(struct rt_rq *rt_rq)
Peter Zijlstra6f505b12008-01-25 21:08:30 +0100524{
John Blackwoodf3ade832008-08-26 15:09:43 -0400525 if (rt_rq->rt_nr_running)
526 resched_task(rq_of_rt_rq(rt_rq)->curr);
Peter Zijlstra6f505b12008-01-25 21:08:30 +0100527}
528
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100529static inline void sched_rt_rq_dequeue(struct rt_rq *rt_rq)
Peter Zijlstra6f505b12008-01-25 21:08:30 +0100530{
531}
532
Peter Zijlstra23b0fdf2008-02-13 15:45:39 +0100533static inline int rt_rq_throttled(struct rt_rq *rt_rq)
534{
535 return rt_rq->rt_throttled;
536}
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200537
Rusty Russellc6c49272008-11-25 02:35:05 +1030538static inline const struct cpumask *sched_rt_period_mask(void)
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200539{
Rusty Russellc6c49272008-11-25 02:35:05 +1030540 return cpu_online_mask;
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200541}
542
543static inline
544struct rt_rq *sched_rt_period_rt_rq(struct rt_bandwidth *rt_b, int cpu)
545{
546 return &cpu_rq(cpu)->rt;
547}
548
Peter Zijlstraac086bc2008-04-19 19:44:58 +0200549static inline struct rt_bandwidth *sched_rt_bandwidth(struct rt_rq *rt_rq)
550{
551 return &def_rt_bandwidth;
552}
553
Dhaval Giani55e12e52008-06-24 23:39:43 +0530554#endif /* CONFIG_RT_GROUP_SCHED */
Peter Zijlstra6f505b12008-01-25 21:08:30 +0100555
Peter Zijlstrab79f3832008-06-19 14:22:25 +0200556#ifdef CONFIG_SMP
Peter Zijlstra78333cd2008-09-23 15:33:43 +0200557/*
558 * We ran out of runtime, see if we can borrow some from our neighbours.
559 */
Peter Zijlstrab79f3832008-06-19 14:22:25 +0200560static int do_balance_runtime(struct rt_rq *rt_rq)
Peter Zijlstraac086bc2008-04-19 19:44:58 +0200561{
562 struct rt_bandwidth *rt_b = sched_rt_bandwidth(rt_rq);
Shawn Bohrer89960fe2013-01-14 11:55:31 -0600563 struct root_domain *rd = rq_of_rt_rq(rt_rq)->rd;
Peter Zijlstraac086bc2008-04-19 19:44:58 +0200564 int i, weight, more = 0;
565 u64 rt_period;
566
Rusty Russellc6c49272008-11-25 02:35:05 +1030567 weight = cpumask_weight(rd->span);
Peter Zijlstraac086bc2008-04-19 19:44:58 +0200568
Thomas Gleixner0986b112009-11-17 15:32:06 +0100569 raw_spin_lock(&rt_b->rt_runtime_lock);
Peter Zijlstraac086bc2008-04-19 19:44:58 +0200570 rt_period = ktime_to_ns(rt_b->rt_period);
Rusty Russellc6c49272008-11-25 02:35:05 +1030571 for_each_cpu(i, rd->span) {
Peter Zijlstraac086bc2008-04-19 19:44:58 +0200572 struct rt_rq *iter = sched_rt_period_rt_rq(rt_b, i);
573 s64 diff;
574
575 if (iter == rt_rq)
576 continue;
577
Thomas Gleixner0986b112009-11-17 15:32:06 +0100578 raw_spin_lock(&iter->rt_runtime_lock);
Peter Zijlstra78333cd2008-09-23 15:33:43 +0200579 /*
580 * Either all rqs have inf runtime and there's nothing to steal
581 * or __disable_runtime() below sets a specific rq to inf to
582 * indicate its been disabled and disalow stealing.
583 */
Peter Zijlstra7def2be2008-06-05 14:49:58 +0200584 if (iter->rt_runtime == RUNTIME_INF)
585 goto next;
586
Peter Zijlstra78333cd2008-09-23 15:33:43 +0200587 /*
588 * From runqueues with spare time, take 1/n part of their
589 * spare time, but no more than our period.
590 */
Peter Zijlstraac086bc2008-04-19 19:44:58 +0200591 diff = iter->rt_runtime - iter->rt_time;
592 if (diff > 0) {
Peter Zijlstra58838cf2008-07-24 12:43:13 +0200593 diff = div_u64((u64)diff, weight);
Peter Zijlstraac086bc2008-04-19 19:44:58 +0200594 if (rt_rq->rt_runtime + diff > rt_period)
595 diff = rt_period - rt_rq->rt_runtime;
596 iter->rt_runtime -= diff;
597 rt_rq->rt_runtime += diff;
598 more = 1;
599 if (rt_rq->rt_runtime == rt_period) {
Thomas Gleixner0986b112009-11-17 15:32:06 +0100600 raw_spin_unlock(&iter->rt_runtime_lock);
Peter Zijlstraac086bc2008-04-19 19:44:58 +0200601 break;
602 }
603 }
Peter Zijlstra7def2be2008-06-05 14:49:58 +0200604next:
Thomas Gleixner0986b112009-11-17 15:32:06 +0100605 raw_spin_unlock(&iter->rt_runtime_lock);
Peter Zijlstraac086bc2008-04-19 19:44:58 +0200606 }
Thomas Gleixner0986b112009-11-17 15:32:06 +0100607 raw_spin_unlock(&rt_b->rt_runtime_lock);
Peter Zijlstraac086bc2008-04-19 19:44:58 +0200608
609 return more;
610}
Peter Zijlstra7def2be2008-06-05 14:49:58 +0200611
Peter Zijlstra78333cd2008-09-23 15:33:43 +0200612/*
613 * Ensure this RQ takes back all the runtime it lend to its neighbours.
614 */
Peter Zijlstra7def2be2008-06-05 14:49:58 +0200615static void __disable_runtime(struct rq *rq)
616{
617 struct root_domain *rd = rq->rd;
Cheng Xuec514c42011-05-14 14:20:02 +0800618 rt_rq_iter_t iter;
Peter Zijlstra7def2be2008-06-05 14:49:58 +0200619 struct rt_rq *rt_rq;
620
621 if (unlikely(!scheduler_running))
622 return;
623
Cheng Xuec514c42011-05-14 14:20:02 +0800624 for_each_rt_rq(rt_rq, iter, rq) {
Peter Zijlstra7def2be2008-06-05 14:49:58 +0200625 struct rt_bandwidth *rt_b = sched_rt_bandwidth(rt_rq);
626 s64 want;
627 int i;
628
Thomas Gleixner0986b112009-11-17 15:32:06 +0100629 raw_spin_lock(&rt_b->rt_runtime_lock);
630 raw_spin_lock(&rt_rq->rt_runtime_lock);
Peter Zijlstra78333cd2008-09-23 15:33:43 +0200631 /*
632 * Either we're all inf and nobody needs to borrow, or we're
633 * already disabled and thus have nothing to do, or we have
634 * exactly the right amount of runtime to take out.
635 */
Peter Zijlstra7def2be2008-06-05 14:49:58 +0200636 if (rt_rq->rt_runtime == RUNTIME_INF ||
637 rt_rq->rt_runtime == rt_b->rt_runtime)
638 goto balanced;
Thomas Gleixner0986b112009-11-17 15:32:06 +0100639 raw_spin_unlock(&rt_rq->rt_runtime_lock);
Peter Zijlstra7def2be2008-06-05 14:49:58 +0200640
Peter Zijlstra78333cd2008-09-23 15:33:43 +0200641 /*
642 * Calculate the difference between what we started out with
643 * and what we current have, that's the amount of runtime
644 * we lend and now have to reclaim.
645 */
Peter Zijlstra7def2be2008-06-05 14:49:58 +0200646 want = rt_b->rt_runtime - rt_rq->rt_runtime;
647
Peter Zijlstra78333cd2008-09-23 15:33:43 +0200648 /*
649 * Greedy reclaim, take back as much as we can.
650 */
Rusty Russellc6c49272008-11-25 02:35:05 +1030651 for_each_cpu(i, rd->span) {
Peter Zijlstra7def2be2008-06-05 14:49:58 +0200652 struct rt_rq *iter = sched_rt_period_rt_rq(rt_b, i);
653 s64 diff;
654
Peter Zijlstra78333cd2008-09-23 15:33:43 +0200655 /*
656 * Can't reclaim from ourselves or disabled runqueues.
657 */
Peter Zijlstraf1679d02008-08-14 15:49:00 +0200658 if (iter == rt_rq || iter->rt_runtime == RUNTIME_INF)
Peter Zijlstra7def2be2008-06-05 14:49:58 +0200659 continue;
660
Thomas Gleixner0986b112009-11-17 15:32:06 +0100661 raw_spin_lock(&iter->rt_runtime_lock);
Peter Zijlstra7def2be2008-06-05 14:49:58 +0200662 if (want > 0) {
663 diff = min_t(s64, iter->rt_runtime, want);
664 iter->rt_runtime -= diff;
665 want -= diff;
666 } else {
667 iter->rt_runtime -= want;
668 want -= want;
669 }
Thomas Gleixner0986b112009-11-17 15:32:06 +0100670 raw_spin_unlock(&iter->rt_runtime_lock);
Peter Zijlstra7def2be2008-06-05 14:49:58 +0200671
672 if (!want)
673 break;
674 }
675
Thomas Gleixner0986b112009-11-17 15:32:06 +0100676 raw_spin_lock(&rt_rq->rt_runtime_lock);
Peter Zijlstra78333cd2008-09-23 15:33:43 +0200677 /*
678 * We cannot be left wanting - that would mean some runtime
679 * leaked out of the system.
680 */
Peter Zijlstra7def2be2008-06-05 14:49:58 +0200681 BUG_ON(want);
682balanced:
Peter Zijlstra78333cd2008-09-23 15:33:43 +0200683 /*
684 * Disable all the borrow logic by pretending we have inf
685 * runtime - in which case borrowing doesn't make sense.
686 */
Peter Zijlstra7def2be2008-06-05 14:49:58 +0200687 rt_rq->rt_runtime = RUNTIME_INF;
Thomas Gleixner0986b112009-11-17 15:32:06 +0100688 raw_spin_unlock(&rt_rq->rt_runtime_lock);
689 raw_spin_unlock(&rt_b->rt_runtime_lock);
Peter Zijlstra7def2be2008-06-05 14:49:58 +0200690 }
691}
692
693static void disable_runtime(struct rq *rq)
694{
695 unsigned long flags;
696
Thomas Gleixner05fa7852009-11-17 14:28:38 +0100697 raw_spin_lock_irqsave(&rq->lock, flags);
Peter Zijlstra7def2be2008-06-05 14:49:58 +0200698 __disable_runtime(rq);
Thomas Gleixner05fa7852009-11-17 14:28:38 +0100699 raw_spin_unlock_irqrestore(&rq->lock, flags);
Peter Zijlstra7def2be2008-06-05 14:49:58 +0200700}
701
702static void __enable_runtime(struct rq *rq)
703{
Cheng Xuec514c42011-05-14 14:20:02 +0800704 rt_rq_iter_t iter;
Peter Zijlstra7def2be2008-06-05 14:49:58 +0200705 struct rt_rq *rt_rq;
706
707 if (unlikely(!scheduler_running))
708 return;
709
Peter Zijlstra78333cd2008-09-23 15:33:43 +0200710 /*
711 * Reset each runqueue's bandwidth settings
712 */
Cheng Xuec514c42011-05-14 14:20:02 +0800713 for_each_rt_rq(rt_rq, iter, rq) {
Peter Zijlstra7def2be2008-06-05 14:49:58 +0200714 struct rt_bandwidth *rt_b = sched_rt_bandwidth(rt_rq);
715
Thomas Gleixner0986b112009-11-17 15:32:06 +0100716 raw_spin_lock(&rt_b->rt_runtime_lock);
717 raw_spin_lock(&rt_rq->rt_runtime_lock);
Peter Zijlstra7def2be2008-06-05 14:49:58 +0200718 rt_rq->rt_runtime = rt_b->rt_runtime;
719 rt_rq->rt_time = 0;
Zhang, Yanminbaf25732008-09-09 11:26:33 +0800720 rt_rq->rt_throttled = 0;
Thomas Gleixner0986b112009-11-17 15:32:06 +0100721 raw_spin_unlock(&rt_rq->rt_runtime_lock);
722 raw_spin_unlock(&rt_b->rt_runtime_lock);
Peter Zijlstra7def2be2008-06-05 14:49:58 +0200723 }
724}
725
726static void enable_runtime(struct rq *rq)
727{
728 unsigned long flags;
729
Thomas Gleixner05fa7852009-11-17 14:28:38 +0100730 raw_spin_lock_irqsave(&rq->lock, flags);
Peter Zijlstra7def2be2008-06-05 14:49:58 +0200731 __enable_runtime(rq);
Thomas Gleixner05fa7852009-11-17 14:28:38 +0100732 raw_spin_unlock_irqrestore(&rq->lock, flags);
Peter Zijlstra7def2be2008-06-05 14:49:58 +0200733}
734
Peter Zijlstra029632f2011-10-25 10:00:11 +0200735int update_runtime(struct notifier_block *nfb, unsigned long action, void *hcpu)
736{
737 int cpu = (int)(long)hcpu;
738
739 switch (action) {
740 case CPU_DOWN_PREPARE:
741 case CPU_DOWN_PREPARE_FROZEN:
742 disable_runtime(cpu_rq(cpu));
743 return NOTIFY_OK;
744
745 case CPU_DOWN_FAILED:
746 case CPU_DOWN_FAILED_FROZEN:
747 case CPU_ONLINE:
748 case CPU_ONLINE_FROZEN:
749 enable_runtime(cpu_rq(cpu));
750 return NOTIFY_OK;
751
752 default:
753 return NOTIFY_DONE;
754 }
755}
756
Peter Zijlstraeff65492008-06-19 14:22:26 +0200757static int balance_runtime(struct rt_rq *rt_rq)
758{
759 int more = 0;
760
Peter Zijlstra4a6184c2011-10-06 22:39:14 +0200761 if (!sched_feat(RT_RUNTIME_SHARE))
762 return more;
763
Peter Zijlstraeff65492008-06-19 14:22:26 +0200764 if (rt_rq->rt_time > rt_rq->rt_runtime) {
Thomas Gleixner0986b112009-11-17 15:32:06 +0100765 raw_spin_unlock(&rt_rq->rt_runtime_lock);
Peter Zijlstraeff65492008-06-19 14:22:26 +0200766 more = do_balance_runtime(rt_rq);
Thomas Gleixner0986b112009-11-17 15:32:06 +0100767 raw_spin_lock(&rt_rq->rt_runtime_lock);
Peter Zijlstraeff65492008-06-19 14:22:26 +0200768 }
769
770 return more;
771}
Dhaval Giani55e12e52008-06-24 23:39:43 +0530772#else /* !CONFIG_SMP */
Peter Zijlstraeff65492008-06-19 14:22:26 +0200773static inline int balance_runtime(struct rt_rq *rt_rq)
774{
775 return 0;
776}
Dhaval Giani55e12e52008-06-24 23:39:43 +0530777#endif /* CONFIG_SMP */
Peter Zijlstra6f505b12008-01-25 21:08:30 +0100778
779static int do_sched_rt_period_timer(struct rt_bandwidth *rt_b, int overrun)
780{
Peter Zijlstra42c62a52011-10-18 22:03:48 +0200781 int i, idle = 1, throttled = 0;
Rusty Russellc6c49272008-11-25 02:35:05 +1030782 const struct cpumask *span;
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200783
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200784 span = sched_rt_period_mask();
Mike Galbraith1e5c13e2012-08-07 10:02:38 +0200785#ifdef CONFIG_RT_GROUP_SCHED
786 /*
787 * FIXME: isolated CPUs should really leave the root task group,
788 * whether they are isolcpus or were isolated via cpusets, lest
789 * the timer run on a CPU which does not service all runqueues,
790 * potentially leaving other CPUs indefinitely throttled. If
791 * isolation is really required, the user will turn the throttle
792 * off to kill the perturbations it causes anyway. Meanwhile,
793 * this maintains functionality for boot and/or troubleshooting.
794 */
795 if (rt_b == &root_task_group.rt_bandwidth)
796 span = cpu_online_mask;
797#endif
Rusty Russellc6c49272008-11-25 02:35:05 +1030798 for_each_cpu(i, span) {
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200799 int enqueue = 0;
800 struct rt_rq *rt_rq = sched_rt_period_rt_rq(rt_b, i);
801 struct rq *rq = rq_of_rt_rq(rt_rq);
802
Thomas Gleixner05fa7852009-11-17 14:28:38 +0100803 raw_spin_lock(&rq->lock);
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200804 if (rt_rq->rt_time) {
805 u64 runtime;
806
Thomas Gleixner0986b112009-11-17 15:32:06 +0100807 raw_spin_lock(&rt_rq->rt_runtime_lock);
Peter Zijlstraeff65492008-06-19 14:22:26 +0200808 if (rt_rq->rt_throttled)
809 balance_runtime(rt_rq);
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200810 runtime = rt_rq->rt_runtime;
811 rt_rq->rt_time -= min(rt_rq->rt_time, overrun*runtime);
812 if (rt_rq->rt_throttled && rt_rq->rt_time < runtime) {
813 rt_rq->rt_throttled = 0;
814 enqueue = 1;
Mike Galbraith61eadef2011-04-29 08:36:50 +0200815
816 /*
817 * Force a clock update if the CPU was idle,
818 * lest wakeup -> unthrottle time accumulate.
819 */
820 if (rt_rq->rt_nr_running && rq->curr == rq->idle)
821 rq->skip_clock_update = -1;
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200822 }
823 if (rt_rq->rt_time || rt_rq->rt_nr_running)
824 idle = 0;
Thomas Gleixner0986b112009-11-17 15:32:06 +0100825 raw_spin_unlock(&rt_rq->rt_runtime_lock);
Balbir Singh0c3b9162011-03-03 17:04:35 +0530826 } else if (rt_rq->rt_nr_running) {
Peter Zijlstra8a8cde12008-06-19 14:22:28 +0200827 idle = 0;
Balbir Singh0c3b9162011-03-03 17:04:35 +0530828 if (!rt_rq_throttled(rt_rq))
829 enqueue = 1;
830 }
Peter Zijlstra42c62a52011-10-18 22:03:48 +0200831 if (rt_rq->rt_throttled)
832 throttled = 1;
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200833
834 if (enqueue)
835 sched_rt_rq_enqueue(rt_rq);
Thomas Gleixner05fa7852009-11-17 14:28:38 +0100836 raw_spin_unlock(&rq->lock);
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200837 }
838
Peter Zijlstra42c62a52011-10-18 22:03:48 +0200839 if (!throttled && (!rt_bandwidth_enabled() || rt_b->rt_runtime == RUNTIME_INF))
840 return 1;
841
Peter Zijlstrad0b27fa2008-04-19 19:44:57 +0200842 return idle;
843}
844
Peter Zijlstra6f505b12008-01-25 21:08:30 +0100845static inline int rt_se_prio(struct sched_rt_entity *rt_se)
846{
Peter Zijlstra052f1dc2008-02-13 15:45:40 +0100847#ifdef CONFIG_RT_GROUP_SCHED
Peter Zijlstra6f505b12008-01-25 21:08:30 +0100848 struct rt_rq *rt_rq = group_rt_rq(rt_se);
849
850 if (rt_rq)
Gregory Haskinse864c492008-12-29 09:39:49 -0500851 return rt_rq->highest_prio.curr;
Peter Zijlstra6f505b12008-01-25 21:08:30 +0100852#endif
853
854 return rt_task_of(rt_se)->prio;
855}
856
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100857static int sched_rt_runtime_exceeded(struct rt_rq *rt_rq)
Peter Zijlstra6f505b12008-01-25 21:08:30 +0100858{
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100859 u64 runtime = sched_rt_runtime(rt_rq);
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100860
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100861 if (rt_rq->rt_throttled)
Peter Zijlstra23b0fdf2008-02-13 15:45:39 +0100862 return rt_rq_throttled(rt_rq);
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100863
Shan Hai5b680fd2011-11-29 11:03:56 +0800864 if (runtime >= sched_rt_period(rt_rq))
Peter Zijlstraac086bc2008-04-19 19:44:58 +0200865 return 0;
866
Peter Zijlstrab79f3832008-06-19 14:22:25 +0200867 balance_runtime(rt_rq);
868 runtime = sched_rt_runtime(rt_rq);
869 if (runtime == RUNTIME_INF)
870 return 0;
Peter Zijlstraac086bc2008-04-19 19:44:58 +0200871
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100872 if (rt_rq->rt_time > runtime) {
Peter Zijlstra7abc63b2011-10-18 22:03:48 +0200873 struct rt_bandwidth *rt_b = sched_rt_bandwidth(rt_rq);
874
875 /*
876 * Don't actually throttle groups that have no runtime assigned
877 * but accrue some time due to boosting.
878 */
879 if (likely(rt_b->rt_runtime)) {
Peter Zijlstra3ccf3e82012-02-27 10:47:00 +0100880 static bool once = false;
881
Peter Zijlstra7abc63b2011-10-18 22:03:48 +0200882 rt_rq->rt_throttled = 1;
Peter Zijlstra3ccf3e82012-02-27 10:47:00 +0100883
884 if (!once) {
885 once = true;
886 printk_sched("sched: RT throttling activated\n");
887 }
Peter Zijlstra7abc63b2011-10-18 22:03:48 +0200888 } else {
889 /*
890 * In case we did anyway, make it go away,
891 * replenishment is a joke, since it will replenish us
892 * with exactly 0 ns.
893 */
894 rt_rq->rt_time = 0;
895 }
896
Peter Zijlstra23b0fdf2008-02-13 15:45:39 +0100897 if (rt_rq_throttled(rt_rq)) {
Peter Zijlstra9f0c1e52008-02-13 15:45:39 +0100898 sched_rt_rq_dequeue(rt_rq);
Peter Zijlstra23b0fdf2008-02-13 15:45:39 +0100899 return 1;
900 }
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100901 }
902
903 return 0;
904}
905
Ingo Molnarbb44e5d2007-07-09 18:51:58 +0200906/*
907 * Update the current task's runtime statistics. Skip current tasks that
908 * are not in our scheduling class.
909 */
Alexey Dobriyana9957442007-10-15 17:00:13 +0200910static void update_curr_rt(struct rq *rq)
Ingo Molnarbb44e5d2007-07-09 18:51:58 +0200911{
912 struct task_struct *curr = rq->curr;
Peter Zijlstra6f505b12008-01-25 21:08:30 +0100913 struct sched_rt_entity *rt_se = &curr->rt;
914 struct rt_rq *rt_rq = rt_rq_of_se(rt_se);
Ingo Molnarbb44e5d2007-07-09 18:51:58 +0200915 u64 delta_exec;
916
Peter Zijlstra06c3bc62011-02-02 13:19:48 +0100917 if (curr->sched_class != &rt_sched_class)
Ingo Molnarbb44e5d2007-07-09 18:51:58 +0200918 return;
919
Venkatesh Pallipadi305e6832010-10-04 17:03:21 -0700920 delta_exec = rq->clock_task - curr->se.exec_start;
Ingo Molnarbb44e5d2007-07-09 18:51:58 +0200921 if (unlikely((s64)delta_exec < 0))
922 delta_exec = 0;
Ingo Molnar6cfb0d52007-08-02 17:41:40 +0200923
Peter Zijlstra42c62a52011-10-18 22:03:48 +0200924 schedstat_set(curr->se.statistics.exec_max,
925 max(curr->se.statistics.exec_max, delta_exec));
Ingo Molnarbb44e5d2007-07-09 18:51:58 +0200926
927 curr->se.sum_exec_runtime += delta_exec;
Frank Mayharf06febc2008-09-12 09:54:39 -0700928 account_group_exec_runtime(curr, delta_exec);
929
Venkatesh Pallipadi305e6832010-10-04 17:03:21 -0700930 curr->se.exec_start = rq->clock_task;
Srivatsa Vaddagirid842de82007-12-02 20:04:49 +0100931 cpuacct_charge(curr, delta_exec);
Peter Zijlstrafa85ae22008-01-25 21:08:29 +0100932
Peter Zijlstrae9e92502009-09-01 10:34:37 +0200933 sched_rt_avg_update(rq, delta_exec);
934
Peter Zijlstra0b148fa2008-08-19 12:33:04 +0200935 if (!rt_bandwidth_enabled())
936 return;
937
Dhaval Giani354d60c2008-04-19 19:44:59 +0200938 for_each_sched_rt_entity(rt_se) {
939 rt_rq = rt_rq_of_se(rt_se);
940
Peter Zijlstracc2991c2008-08-19 12:33:03 +0200941 if (sched_rt_runtime(rt_rq) != RUNTIME_INF) {
Thomas Gleixner0986b112009-11-17 15:32:06 +0100942 raw_spin_lock(&rt_rq->rt_runtime_lock);
Peter Zijlstracc2991c2008-08-19 12:33:03 +0200943 rt_rq->rt_time += delta_exec;
944 if (sched_rt_runtime_exceeded(rt_rq))
945 resched_task(curr);
Thomas Gleixner0986b112009-11-17 15:32:06 +0100946 raw_spin_unlock(&rt_rq->rt_runtime_lock);
Peter Zijlstracc2991c2008-08-19 12:33:03 +0200947 }
Dhaval Giani354d60c2008-04-19 19:44:59 +0200948 }
Ingo Molnarbb44e5d2007-07-09 18:51:58 +0200949}
950
Gregory Haskins398a1532009-01-14 09:10:04 -0500951#if defined CONFIG_SMP
Gregory Haskinse864c492008-12-29 09:39:49 -0500952
Gregory Haskins398a1532009-01-14 09:10:04 -0500953static void
954inc_rt_prio_smp(struct rt_rq *rt_rq, int prio, int prev_prio)
Steven Rostedt63489e42008-01-25 21:08:03 +0100955{
Gregory Haskins4d984272008-12-29 09:39:49 -0500956 struct rq *rq = rq_of_rt_rq(rt_rq);
Gregory Haskins4d984272008-12-29 09:39:49 -0500957
Kirill Tkhai3f887892013-11-27 19:59:13 +0400958#ifdef CONFIG_RT_GROUP_SCHED
959 /*
960 * Change rq's cpupri only if rt_rq is the top queue.
961 */
962 if (&rq->rt != rt_rq)
963 return;
964#endif
Steven Rostedt5181f4a2011-06-16 21:55:23 -0400965 if (rq->online && prio < prev_prio)
966 cpupri_set(&rq->rd->cpupri, rq->cpu, prio);
Steven Rostedt63489e42008-01-25 21:08:03 +0100967}
Peter Zijlstra6f505b12008-01-25 21:08:30 +0100968
Gregory Haskins398a1532009-01-14 09:10:04 -0500969static void
970dec_rt_prio_smp(struct rt_rq *rt_rq, int prio, int prev_prio)
Steven Rostedt63489e42008-01-25 21:08:03 +0100971{
Gregory Haskins4d984272008-12-29 09:39:49 -0500972 struct rq *rq = rq_of_rt_rq(rt_rq);
Gregory Haskins6e0534f2008-05-12 21:21:01 +0200973
Kirill Tkhai3f887892013-11-27 19:59:13 +0400974#ifdef CONFIG_RT_GROUP_SCHED
975 /*
976 * Change rq's cpupri only if rt_rq is the top queue.
977 */
978 if (&rq->rt != rt_rq)
979 return;
980#endif
Gregory Haskins398a1532009-01-14 09:10:04 -0500981 if (rq->online && rt_rq->highest_prio.curr != prev_prio)
982 cpupri_set(&rq->rd->cpupri, rq->cpu, rt_rq->highest_prio.curr);
983}
984
985#else /* CONFIG_SMP */
986
987static inline
988void inc_rt_prio_smp(struct rt_rq *rt_rq, int prio, int prev_prio) {}
989static inline
990void dec_rt_prio_smp(struct rt_rq *rt_rq, int prio, int prev_prio) {}
991
992#endif /* CONFIG_SMP */
993
Steven Rostedt63489e42008-01-25 21:08:03 +0100994#if defined CONFIG_SMP || defined CONFIG_RT_GROUP_SCHED
Gregory Haskins398a1532009-01-14 09:10:04 -0500995static void
996inc_rt_prio(struct rt_rq *rt_rq, int prio)
997{
998 int prev_prio = rt_rq->highest_prio.curr;
Steven Rostedt63489e42008-01-25 21:08:03 +0100999
Gregory Haskins398a1532009-01-14 09:10:04 -05001000 if (prio < prev_prio)
1001 rt_rq->highest_prio.curr = prio;
1002
1003 inc_rt_prio_smp(rt_rq, prio, prev_prio);
1004}
1005
1006static void
1007dec_rt_prio(struct rt_rq *rt_rq, int prio)
1008{
1009 int prev_prio = rt_rq->highest_prio.curr;
1010
1011 if (rt_rq->rt_nr_running) {
1012
1013 WARN_ON(prio < prev_prio);
Gregory Haskinse864c492008-12-29 09:39:49 -05001014
1015 /*
Gregory Haskins398a1532009-01-14 09:10:04 -05001016 * This may have been our highest task, and therefore
1017 * we may have some recomputation to do
Gregory Haskinse864c492008-12-29 09:39:49 -05001018 */
Gregory Haskins398a1532009-01-14 09:10:04 -05001019 if (prio == prev_prio) {
Gregory Haskinse864c492008-12-29 09:39:49 -05001020 struct rt_prio_array *array = &rt_rq->active;
1021
1022 rt_rq->highest_prio.curr =
Steven Rostedt764a9d62008-01-25 21:08:04 +01001023 sched_find_first_bit(array->bitmap);
Gregory Haskinse864c492008-12-29 09:39:49 -05001024 }
1025
Steven Rostedt764a9d62008-01-25 21:08:04 +01001026 } else
Gregory Haskinse864c492008-12-29 09:39:49 -05001027 rt_rq->highest_prio.curr = MAX_RT_PRIO;
Gregory Haskins73fe6aa2008-01-25 21:08:07 +01001028
Gregory Haskins398a1532009-01-14 09:10:04 -05001029 dec_rt_prio_smp(rt_rq, prio, prev_prio);
1030}
Gregory Haskins1f11eb62008-06-04 15:04:05 -04001031
Gregory Haskins398a1532009-01-14 09:10:04 -05001032#else
1033
1034static inline void inc_rt_prio(struct rt_rq *rt_rq, int prio) {}
1035static inline void dec_rt_prio(struct rt_rq *rt_rq, int prio) {}
1036
1037#endif /* CONFIG_SMP || CONFIG_RT_GROUP_SCHED */
1038
Gregory Haskins73fe6aa2008-01-25 21:08:07 +01001039#ifdef CONFIG_RT_GROUP_SCHED
Gregory Haskins398a1532009-01-14 09:10:04 -05001040
1041static void
1042inc_rt_group(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq)
1043{
Gregory Haskins73fe6aa2008-01-25 21:08:07 +01001044 if (rt_se_boosted(rt_se))
Steven Rostedt764a9d62008-01-25 21:08:04 +01001045 rt_rq->rt_nr_boosted++;
Peter Zijlstra052f1dc2008-02-13 15:45:40 +01001046
Peter Zijlstra23b0fdf2008-02-13 15:45:39 +01001047 if (rt_rq->tg)
1048 start_rt_bandwidth(&rt_rq->tg->rt_bandwidth);
Gregory Haskins398a1532009-01-14 09:10:04 -05001049}
1050
1051static void
1052dec_rt_group(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq)
1053{
Peter Zijlstra23b0fdf2008-02-13 15:45:39 +01001054 if (rt_se_boosted(rt_se))
1055 rt_rq->rt_nr_boosted--;
1056
1057 WARN_ON(!rt_rq->rt_nr_running && rt_rq->rt_nr_boosted);
Gregory Haskins398a1532009-01-14 09:10:04 -05001058}
1059
1060#else /* CONFIG_RT_GROUP_SCHED */
1061
1062static void
1063inc_rt_group(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq)
1064{
Ingo Molnarbb44e5d2007-07-09 18:51:58 +02001065 start_rt_bandwidth(&def_rt_bandwidth);
Gregory Haskins398a1532009-01-14 09:10:04 -05001066}
1067
1068static inline
1069void dec_rt_group(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq) {}
1070
1071#endif /* CONFIG_RT_GROUP_SCHED */
1072
1073static inline
1074void inc_rt_tasks(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq)
1075{
1076 int prio = rt_se_prio(rt_se);
1077
1078 WARN_ON(!rt_prio(prio));
1079 rt_rq->rt_nr_running++;
1080
1081 inc_rt_prio(rt_rq, prio);
1082 inc_rt_migration(rt_se, rt_rq);
1083 inc_rt_group(rt_se, rt_rq);
Ingo Molnarbb44e5d2007-07-09 18:51:58 +02001084}
1085
Peter Zijlstra23b0fdf2008-02-13 15:45:39 +01001086static inline
1087void dec_rt_tasks(struct sched_rt_entity *rt_se, struct rt_rq *rt_rq)
1088{
Ingo Molnarbb44e5d2007-07-09 18:51:58 +02001089 WARN_ON(!rt_prio(rt_se_prio(rt_se)));
Peter Zijlstra6f505b12008-01-25 21:08:30 +01001090 WARN_ON(!rt_rq->rt_nr_running);
Ingo Molnarbb44e5d2007-07-09 18:51:58 +02001091 rt_rq->rt_nr_running--;
Ingo Molnarbb44e5d2007-07-09 18:51:58 +02001092
Gregory Haskins398a1532009-01-14 09:10:04 -05001093 dec_rt_prio(rt_rq, rt_se_prio(rt_se));
1094 dec_rt_migration(rt_se, rt_rq);
1095 dec_rt_group(rt_se, rt_rq);
Ingo Molnarbb44e5d2007-07-09 18:51:58 +02001096}
1097
Thomas Gleixner37dad3f2010-01-20 20:59:01 +00001098static void __enqueue_rt_entity(struct sched_rt_entity *rt_se, bool head)
Ingo Molnarbb44e5d2007-07-09 18:51:58 +02001099{
Peter Zijlstra6f505b12008-01-25 21:08:30 +01001100 struct rt_rq *rt_rq = rt_rq_of_se(rt_se);
1101 struct rt_prio_array *array = &rt_rq->active;
1102 struct rt_rq *group_rq = group_rt_rq(rt_se);
Dmitry Adamushko20b63312008-06-11 00:58:30 +02001103 struct list_head *queue = array->queue + rt_se_prio(rt_se);
Ingo Molnarbb44e5d2007-07-09 18:51:58 +02001104
Peter Zijlstraad2a3f12008-06-19 09:06:57 +02001105 /*
1106 * Don't enqueue the group if its throttled, or when empty.
1107 * The latter is a consequence of the former when a child group
1108 * get throttled and the current group doesn't have any other
1109 * active members.
1110 */
1111 if (group_rq && (rt_rq_throttled(group_rq) || !group_rq->rt_nr_running))
Peter Zijlstra6f505b12008-01-25 21:08:30 +01001112 return;
Ingo Molnarbb44e5d2007-07-09 18:51:58 +02001113
Peter Zijlstra3d4b47b2010-11-15 15:47:01 -08001114 if (!rt_rq->rt_nr_running)
1115 list_add_leaf_rt_rq(rt_rq);
1116
Thomas Gleixner37dad3f2010-01-20 20:59:01 +00001117 if (head)
1118 list_add(&rt_se->run_list, queue);
1119 else
1120 list_add_tail(&rt_se->run_list, queue);
Peter Zijlstra6f505b12008-01-25 21:08:30 +01001121 __set_bit(rt_se_prio(rt_se), array->bitmap);
Peter Zijlstra78f2c7d2008-01-25 21:08:27 +01001122
Peter Zijlstra6f505b12008-01-25 21:08:30 +01001123 inc_rt_tasks(rt_se, rt_rq);
1124}
1125
Peter Zijlstraad2a3f12008-06-19 09:06:57 +02001126static void __dequeue_rt_entity(struct sched_rt_entity *rt_se)
Peter Zijlstra6f505b12008-01-25 21:08:30 +01001127{
1128 struct rt_rq *rt_rq = rt_rq_of_se(rt_se);
1129 struct rt_prio_array *array = &rt_rq->active;
1130
1131 list_del_init(&rt_se->run_list);
1132 if (list_empty(array->queue + rt_se_prio(rt_se)))
1133 __clear_bit(rt_se_prio(rt_se), array->bitmap);
1134
1135 dec_rt_tasks(rt_se, rt_rq);
Peter Zijlstra3d4b47b2010-11-15 15:47:01 -08001136 if (!rt_rq->rt_nr_running)
1137 list_del_leaf_rt_rq(rt_rq);
Peter Zijlstra6f505b12008-01-25 21:08:30 +01001138}
1139
1140/*
1141 * Because the prio of an upper entry depends on the lower
1142 * entries, we must remove entries top - down.
Peter Zijlstra6f505b12008-01-25 21:08:30 +01001143 */
Peter Zijlstraad2a3f12008-06-19 09:06:57 +02001144static void dequeue_rt_stack(struct sched_rt_entity *rt_se)
Peter Zijlstra6f505b12008-01-25 21:08:30 +01001145{
Peter Zijlstraad2a3f12008-06-19 09:06:57 +02001146 struct sched_rt_entity *back = NULL;
Peter Zijlstra6f505b12008-01-25 21:08:30 +01001147
Peter Zijlstra58d6c2d2008-04-19 19:45:00 +02001148 for_each_sched_rt_entity(rt_se) {
1149 rt_se->back = back;
1150 back = rt_se;
1151 }
1152
1153 for (rt_se = back; rt_se; rt_se = rt_se->back) {
1154 if (on_rt_rq(rt_se))
Peter Zijlstraad2a3f12008-06-19 09:06:57 +02001155 __dequeue_rt_entity(rt_se);
1156 }
1157}
1158
Thomas Gleixner37dad3f2010-01-20 20:59:01 +00001159static void enqueue_rt_entity(struct sched_rt_entity *rt_se, bool head)
Peter Zijlstraad2a3f12008-06-19 09:06:57 +02001160{
1161 dequeue_rt_stack(rt_se);
1162 for_each_sched_rt_entity(rt_se)
Thomas Gleixner37dad3f2010-01-20 20:59:01 +00001163 __enqueue_rt_entity(rt_se, head);
Peter Zijlstraad2a3f12008-06-19 09:06:57 +02001164}
1165
1166static void dequeue_rt_entity(struct sched_rt_entity *rt_se)
1167{
1168 dequeue_rt_stack(rt_se);
1169
1170 for_each_sched_rt_entity(rt_se) {
1171 struct rt_rq *rt_rq = group_rt_rq(rt_se);
1172
1173 if (rt_rq && rt_rq->rt_nr_running)
Thomas Gleixner37dad3f2010-01-20 20:59:01 +00001174 __enqueue_rt_entity(rt_se, false);
Peter Zijlstra58d6c2d2008-04-19 19:45:00 +02001175 }
Ingo Molnarbb44e5d2007-07-09 18:51:58 +02001176}
1177
1178/*
1179 * Adding/removing a task to/from a priority array:
1180 */
Thomas Gleixnerea87bb72010-01-20 20:58:57 +00001181static void
Peter Zijlstra371fd7e2010-03-24 16:38:48 +01001182enqueue_task_rt(struct rq *rq, struct task_struct *p, int flags)
Peter Zijlstra6f505b12008-01-25 21:08:30 +01001183{
1184 struct sched_rt_entity *rt_se = &p->rt;
1185
Peter Zijlstra371fd7e2010-03-24 16:38:48 +01001186 if (flags & ENQUEUE_WAKEUP)
Peter Zijlstra6f505b12008-01-25 21:08:30 +01001187 rt_se->timeout = 0;
1188
Peter Zijlstra371fd7e2010-03-24 16:38:48 +01001189 enqueue_rt_entity(rt_se, flags & ENQUEUE_HEAD);
Peter Zijlstrac09595f2008-06-27 13:41:14 +02001190
Gregory Haskins917b6272008-12-29 09:39:53 -05001191 if (!task_current(rq, p) && p->rt.nr_cpus_allowed > 1)
1192 enqueue_pushable_task(rq, p);
Paul Turner953bfcd2011-07-21 09:43:27 -07001193
1194 inc_nr_running(rq);
Peter Zijlstra6f505b12008-01-25 21:08:30 +01001195}
1196
Peter Zijlstra371fd7e2010-03-24 16:38:48 +01001197static void dequeue_task_rt(struct rq *rq, struct task_struct *p, int flags)
Ingo Molnarbb44e5d2007-07-09 18:51:58 +02001198{
Peter Zijlstra6f505b12008-01-25 21:08:30 +01001199 struct sched_rt_entity *rt_se = &p->rt;
Ingo Molnarbb44e5d2007-07-09 18:51:58 +02001200
1201 update_curr_rt(rq);
Peter Zijlstraad2a3f12008-06-19 09:06:57 +02001202 dequeue_rt_entity(rt_se);
Peter Zijlstrac09595f2008-06-27 13:41:14 +02001203
Gregory Haskins917b6272008-12-29 09:39:53 -05001204 dequeue_pushable_task(rq, p);
Paul Turner953bfcd2011-07-21 09:43:27 -07001205
1206 dec_nr_running(rq);
Ingo Molnarbb44e5d2007-07-09 18:51:58 +02001207}
1208
1209/*
Richard Weinberger60686312011-11-12 18:07:57 +01001210 * Put task to the head or the end of the run list without the overhead of
1211 * dequeue followed by enqueue.
Ingo Molnarbb44e5d2007-07-09 18:51:58 +02001212 */
Dmitry Adamushko7ebefa82008-07-01 23:32:15 +02001213static void
1214requeue_rt_entity(struct rt_rq *rt_rq, struct sched_rt_entity *rt_se, int head)
Ingo Molnarbb44e5d2007-07-09 18:51:58 +02001215{
Ingo Molnar1cdad712008-06-19 09:09:15 +02001216 if (on_rt_rq(rt_se)) {
Dmitry Adamushko7ebefa82008-07-01 23:32:15 +02001217 struct rt_prio_array *array = &rt_rq->active;
1218 struct list_head *queue = array->queue + rt_se_prio(rt_se);
1219
1220 if (head)
1221 list_move(&rt_se->run_list, queue);
1222 else
1223 list_move_tail(&rt_se->run_list, queue);
Ingo Molnar1cdad712008-06-19 09:09:15 +02001224 }
Ingo Molnarbb44e5d2007-07-09 18:51:58 +02001225}
1226
Dmitry Adamushko7ebefa82008-07-01 23:32:15 +02001227static void requeue_task_rt(struct rq *rq, struct task_struct *p, int head)
Peter Zijlstra6f505b12008-01-25 21:08:30 +01001228{
1229 struct sched_rt_entity *rt_se = &p->rt;
1230 struct rt_rq *rt_rq;
1231
1232 for_each_sched_rt_entity(rt_se) {
1233 rt_rq = rt_rq_of_se(rt_se);
Dmitry Adamushko7ebefa82008-07-01 23:32:15 +02001234 requeue_rt_entity(rt_rq, rt_se, head);
Peter Zijlstra6f505b12008-01-25 21:08:30 +01001235 }
1236}
1237
1238static void yield_task_rt(struct rq *rq)
Ingo Molnarbb44e5d2007-07-09 18:51:58 +02001239{
Dmitry Adamushko7ebefa82008-07-01 23:32:15 +02001240 requeue_task_rt(rq, rq->curr, 0);
Ingo Molnarbb44e5d2007-07-09 18:51:58 +02001241}
1242
Gregory Haskinse7693a32008-01-25 21:08:09 +01001243#ifdef CONFIG_SMP
Gregory Haskins318e0892008-01-25 21:08:10 +01001244static int find_lowest_rq(struct task_struct *task);
1245
Peter Zijlstra0017d732010-03-24 18:34:10 +01001246static int
Peter Zijlstra7608dec2011-04-05 17:23:46 +02001247select_task_rq_rt(struct task_struct *p, int sd_flag, int flags)
Gregory Haskinse7693a32008-01-25 21:08:09 +01001248{
Peter Zijlstra7608dec2011-04-05 17:23:46 +02001249 struct task_struct *curr;
1250 struct rq *rq;
1251 int cpu;
1252
Peter Zijlstra7608dec2011-04-05 17:23:46 +02001253 cpu = task_cpu(p);
Steven Rostedtc37495f2011-06-16 21:55:22 -04001254
Mike Galbraith76854c72011-11-22 15:18:24 +01001255 if (p->rt.nr_cpus_allowed == 1)
1256 goto out;
1257
Steven Rostedtc37495f2011-06-16 21:55:22 -04001258 /* For anything but wake ups, just return the task_cpu */
1259 if (sd_flag != SD_BALANCE_WAKE && sd_flag != SD_BALANCE_FORK)
1260 goto out;
1261
Peter Zijlstra7608dec2011-04-05 17:23:46 +02001262 rq = cpu_rq(cpu);
1263
1264 rcu_read_lock();
1265 curr = ACCESS_ONCE(rq->curr); /* unlocked access */
1266
Gregory Haskins318e0892008-01-25 21:08:10 +01001267 /*
Peter Zijlstra7608dec2011-04-05 17:23:46 +02001268 * If the current task on @p's runqueue is an RT task, then
Steven Rostedte1f47d82008-01-25 21:08:12 +01001269 * try to see if we can wake this RT task up on another
1270 * runqueue. Otherwise simply start this RT task
1271 * on its current runqueue.
1272 *
Steven Rostedt43fa5462010-09-20 22:40:03 -04001273 * We want to avoid overloading runqueues. If the woken
1274 * task is a higher priority, then it will stay on this CPU
1275 * and the lower prio task should be moved to another CPU.
1276 * Even though this will probably make the lower prio task
1277 * lose its cache, we do not want to bounce a higher task
1278 * around just because it gave up its CPU, perhaps for a
1279 * lock?
1280 *
1281 * For equal prio tasks, we just let the scheduler sort it out.
Peter Zijlstra7608dec2011-04-05 17:23:46 +02001282 *
Gregory Haskins318e0892008-01-25 21:08:10 +01001283 * Otherwise, just let it ride on the affined RQ and the
1284 * post-schedule router will push the preempted task away
Peter Zijlstra7608dec2011-04-05 17:23:46 +02001285 *
1286 * This test is optimistic, if we get it wrong the load-balancer
1287 * will have to sort it out.
Gregory Haskins318e0892008-01-25 21:08:10 +01001288 */
Peter Zijlstra7608dec2011-04-05 17:23:46 +02001289 if (curr && unlikely(rt_task(curr)) &&
1290 (curr->rt.nr_cpus_allowed < 2 ||
Shawn Bohrer3be209a2011-09-12 09:28:04 -05001291 curr->prio <= p->prio) &&
Peter Zijlstra7608dec2011-04-05 17:23:46 +02001292 (p->rt.nr_cpus_allowed > 1)) {
1293 int target = find_lowest_rq(p);
1294
1295 if (target != -1)
1296 cpu = target;
1297 }
1298 rcu_read_unlock();
1299
Steven Rostedtc37495f2011-06-16 21:55:22 -04001300out:
Peter Zijlstra7608dec2011-04-05 17:23:46 +02001301 return cpu;
Gregory Haskinse7693a32008-01-25 21:08:09 +01001302}
Dmitry Adamushko7ebefa82008-07-01 23:32:15 +02001303
1304static void check_preempt_equal_prio(struct rq *rq, struct task_struct *p)
1305{
Dmitry Adamushko7ebefa82008-07-01 23:32:15 +02001306 if (rq->curr->rt.nr_cpus_allowed == 1)
1307 return;
1308
Rusty Russell13b8bd02009-03-25 15:01:22 +10301309 if (p->rt.nr_cpus_allowed != 1
1310 && cpupri_find(&rq->rd->cpupri, p, NULL))
Dmitry Adamushko7ebefa82008-07-01 23:32:15 +02001311 return;
1312
Rusty Russell13b8bd02009-03-25 15:01:22 +10301313 if (!cpupri_find(&rq->rd->cpupri, rq->curr, NULL))
1314 return;
Dmitry Adamushko7ebefa82008-07-01 23:32:15 +02001315
1316 /*
1317 * There appears to be other cpus that can accept
1318 * current and none to run 'p', so lets reschedule
1319 * to try and push current away:
1320 */
1321 requeue_task_rt(rq, p, 1);
1322 resched_task(rq->curr);
1323}
1324
Gregory Haskinse7693a32008-01-25 21:08:09 +01001325#endif /* CONFIG_SMP */
1326
Ingo Molnarbb44e5d2007-07-09 18:51:58 +02001327/*
1328 * Preempt the current task with a newly woken task if needed:
1329 */
Peter Zijlstra7d478722009-09-14 19:55:44 +02001330static void check_preempt_curr_rt(struct rq *rq, struct task_struct *p, int flags)
Ingo Molnarbb44e5d2007-07-09 18:51:58 +02001331{
Gregory Haskins45c01e82008-05-12 21:20:41 +02001332 if (p->prio < rq->curr->prio) {
Ingo Molnarbb44e5d2007-07-09 18:51:58 +02001333 resched_task(rq->curr);
Gregory Haskins45c01e82008-05-12 21:20:41 +02001334 return;
1335 }
1336
1337#ifdef CONFIG_SMP
1338 /*
1339 * If:
1340 *
1341 * - the newly woken task is of equal priority to the current task
1342 * - the newly woken task is non-migratable while current is migratable
1343 * - current will be preempted on the next reschedule
1344 *
1345 * we should check to see if current can readily move to a different
1346 * cpu. If so, we will reschedule to allow the push logic to try
1347 * to move current somewhere else, making room for our non-migratable
1348 * task.
1349 */
Hillf Danton8dd0de82011-06-14 18:36:24 -04001350 if (p->prio == rq->curr->prio && !test_tsk_need_resched(rq->curr))
Dmitry Adamushko7ebefa82008-07-01 23:32:15 +02001351 check_preempt_equal_prio(rq, p);
Gregory Haskins45c01e82008-05-12 21:20:41 +02001352#endif
Ingo Molnarbb44e5d2007-07-09 18:51:58 +02001353}
1354
Peter Zijlstra6f505b12008-01-25 21:08:30 +01001355static struct sched_rt_entity *pick_next_rt_entity(struct rq *rq,
1356 struct rt_rq *rt_rq)
Ingo Molnarbb44e5d2007-07-09 18:51:58 +02001357{
Peter Zijlstra6f505b12008-01-25 21:08:30 +01001358 struct rt_prio_array *array = &rt_rq->active;
1359 struct sched_rt_entity *next = NULL;
Ingo Molnarbb44e5d2007-07-09 18:51:58 +02001360 struct list_head *queue;
1361 int idx;
1362
1363 idx = sched_find_first_bit(array->bitmap);
Peter Zijlstra6f505b12008-01-25 21:08:30 +01001364 BUG_ON(idx >= MAX_RT_PRIO);
Ingo Molnarbb44e5d2007-07-09 18:51:58 +02001365
1366 queue = array->queue + idx;
Peter Zijlstra6f505b12008-01-25 21:08:30 +01001367 next = list_entry(queue->next, struct sched_rt_entity, run_list);
Dmitry Adamushko326587b2008-01-25 21:08:34 +01001368
Ingo Molnarbb44e5d2007-07-09 18:51:58 +02001369 return next;
1370}
1371
Gregory Haskins917b6272008-12-29 09:39:53 -05001372static struct task_struct *_pick_next_task_rt(struct rq *rq)
Peter Zijlstra6f505b12008-01-25 21:08:30 +01001373{
1374 struct sched_rt_entity *rt_se;
1375 struct task_struct *p;
1376 struct rt_rq *rt_rq;
1377
Peter Zijlstra6f505b12008-01-25 21:08:30 +01001378 rt_rq = &rq->rt;
1379
Steven Rostedt8e54a2c2010-12-06 11:28:30 -05001380 if (!rt_rq->rt_nr_running)
Peter Zijlstra6f505b12008-01-25 21:08:30 +01001381 return NULL;
1382
Peter Zijlstra23b0fdf2008-02-13 15:45:39 +01001383 if (rt_rq_throttled(rt_rq))
Peter Zijlstra6f505b12008-01-25 21:08:30 +01001384 return NULL;
1385
1386 do {
1387 rt_se = pick_next_rt_entity(rq, rt_rq);
Dmitry Adamushko326587b2008-01-25 21:08:34 +01001388 BUG_ON(!rt_se);
Peter Zijlstra6f505b12008-01-25 21:08:30 +01001389 rt_rq = group_rt_rq(rt_se);
1390 } while (rt_rq);
1391
1392 p = rt_task_of(rt_se);
Venkatesh Pallipadi305e6832010-10-04 17:03:21 -07001393 p->se.exec_start = rq->clock_task;
Gregory Haskins917b6272008-12-29 09:39:53 -05001394
1395 return p;
1396}
1397
1398static struct task_struct *pick_next_task_rt(struct rq *rq)
1399{
1400 struct task_struct *p = _pick_next_task_rt(rq);
1401
1402 /* The running task is never eligible for pushing */
1403 if (p)
1404 dequeue_pushable_task(rq, p);
1405
Ingo Molnarbcf08df2008-04-19 12:11:10 +02001406#ifdef CONFIG_SMP
Gregory Haskins3f029d32009-07-29 11:08:47 -04001407 /*
1408 * We detect this state here so that we can avoid taking the RQ
1409 * lock again later if there is no need to push
1410 */
1411 rq->post_schedule = has_pushable_tasks(rq);
Ingo Molnarbcf08df2008-04-19 12:11:10 +02001412#endif
Gregory Haskins3f029d32009-07-29 11:08:47 -04001413
Peter Zijlstra6f505b12008-01-25 21:08:30 +01001414 return p;
1415}
1416
Ingo Molnar31ee5292007-08-09 11:16:49 +02001417static void put_prev_task_rt(struct rq *rq, struct task_struct *p)
Ingo Molnarbb44e5d2007-07-09 18:51:58 +02001418{
Ingo Molnarf1e14ef2007-08-09 11:16:48 +02001419 update_curr_rt(rq);
Gregory Haskins917b6272008-12-29 09:39:53 -05001420
1421 /*
1422 * The previous task needs to be made eligible for pushing
1423 * if it is still active
1424 */
Peter Zijlstrafd2f4412011-04-05 17:23:44 +02001425 if (on_rt_rq(&p->rt) && p->rt.nr_cpus_allowed > 1)
Gregory Haskins917b6272008-12-29 09:39:53 -05001426 enqueue_pushable_task(rq, p);
Ingo Molnarbb44e5d2007-07-09 18:51:58 +02001427}
1428
Peter Williams681f3e62007-10-24 18:23:51 +02001429#ifdef CONFIG_SMP
Peter Zijlstra6f505b12008-01-25 21:08:30 +01001430
Steven Rostedte8fa1362008-01-25 21:08:05 +01001431/* Only try algorithms three times */
1432#define RT_MAX_TRIES 3
1433
Steven Rostedtf65eda42008-01-25 21:08:07 +01001434static int pick_rt_task(struct rq *rq, struct task_struct *p, int cpu)
1435{
1436 if (!task_running(rq, p) &&
Peter Zijlstrafa17b502011-06-16 12:23:22 +02001437 (cpu < 0 || cpumask_test_cpu(cpu, tsk_cpus_allowed(p))) &&
Peter Zijlstra6f505b12008-01-25 21:08:30 +01001438 (p->rt.nr_cpus_allowed > 1))
Steven Rostedtf65eda42008-01-25 21:08:07 +01001439 return 1;
1440 return 0;
1441}
1442
Steven Rostedte8fa1362008-01-25 21:08:05 +01001443/* Return the second highest RT task, NULL otherwise */
Ingo Molnar79064fb2008-01-25 21:08:14 +01001444static struct task_struct *pick_next_highest_task_rt(struct rq *rq, int cpu)
Steven Rostedte8fa1362008-01-25 21:08:05 +01001445{
Peter Zijlstra6f505b12008-01-25 21:08:30 +01001446 struct task_struct *next = NULL;
1447 struct sched_rt_entity *rt_se;
1448 struct rt_prio_array *array;
1449 struct rt_rq *rt_rq;
Steven Rostedte8fa1362008-01-25 21:08:05 +01001450 int idx;
1451
Peter Zijlstra6f505b12008-01-25 21:08:30 +01001452 for_each_leaf_rt_rq(rt_rq, rq) {
1453 array = &rt_rq->active;
1454 idx = sched_find_first_bit(array->bitmap);
Peter Zijlstra49246272010-10-17 21:46:10 +02001455next_idx:
Peter Zijlstra6f505b12008-01-25 21:08:30 +01001456 if (idx >= MAX_RT_PRIO)
1457 continue;
Michael J Wang1b028ab2012-03-19 22:26:19 +00001458 if (next && next->prio <= idx)
Peter Zijlstra6f505b12008-01-25 21:08:30 +01001459 continue;
1460 list_for_each_entry(rt_se, array->queue + idx, run_list) {
Peter Zijlstra3d074672010-03-10 17:07:24 +01001461 struct task_struct *p;
1462
1463 if (!rt_entity_is_task(rt_se))
1464 continue;
1465
1466 p = rt_task_of(rt_se);
Peter Zijlstra6f505b12008-01-25 21:08:30 +01001467 if (pick_rt_task(rq, p, cpu)) {
1468 next = p;
1469 break;
1470 }
1471 }
1472 if (!next) {
1473 idx = find_next_bit(array->bitmap, MAX_RT_PRIO, idx+1);
1474 goto next_idx;
1475 }
Steven Rostedte8fa1362008-01-25 21:08:05 +01001476 }
1477
Steven Rostedte8fa1362008-01-25 21:08:05 +01001478 return next;
1479}
1480
Rusty Russell0e3900e2008-11-25 02:35:13 +10301481static DEFINE_PER_CPU(cpumask_var_t, local_cpu_mask);
Steven Rostedte8fa1362008-01-25 21:08:05 +01001482
Gregory Haskins6e1254d2008-01-25 21:08:11 +01001483static int find_lowest_rq(struct task_struct *task)
1484{
1485 struct sched_domain *sd;
Rusty Russell96f874e2008-11-25 02:35:14 +10301486 struct cpumask *lowest_mask = __get_cpu_var(local_cpu_mask);
Gregory Haskins6e1254d2008-01-25 21:08:11 +01001487 int this_cpu = smp_processor_id();
1488 int cpu = task_cpu(task);
1489
Steven Rostedt0da938c2011-06-14 18:36:25 -04001490 /* Make sure the mask is initialized first */
1491 if (unlikely(!lowest_mask))
1492 return -1;
1493
Gregory Haskins6e0534f2008-05-12 21:21:01 +02001494 if (task->rt.nr_cpus_allowed == 1)
1495 return -1; /* No other targets possible */
1496
1497 if (!cpupri_find(&task_rq(task)->rd->cpupri, task, lowest_mask))
Gregory Haskins06f90db2008-01-25 21:08:13 +01001498 return -1; /* No targets found */
1499
1500 /*
Gregory Haskins6e1254d2008-01-25 21:08:11 +01001501 * At this point we have built a mask of cpus representing the
1502 * lowest priority tasks in the system. Now we want to elect
1503 * the best one based on our affinity and topology.
1504 *
1505 * We prioritize the last cpu that the task executed on since
1506 * it is most likely cache-hot in that location.
1507 */
Rusty Russell96f874e2008-11-25 02:35:14 +10301508 if (cpumask_test_cpu(cpu, lowest_mask))
Gregory Haskins6e1254d2008-01-25 21:08:11 +01001509 return cpu;
1510
1511 /*
1512 * Otherwise, we consult the sched_domains span maps to figure
1513 * out which cpu is logically closest to our hot cache data.
1514 */
Rusty Russelle2c88062009-11-03 14:53:15 +10301515 if (!cpumask_test_cpu(this_cpu, lowest_mask))
1516 this_cpu = -1; /* Skip this_cpu opt if not among lowest */
Gregory Haskins6e1254d2008-01-25 21:08:11 +01001517
Xiaotian Fengcd4ae6a2011-04-22 18:53:54 +08001518 rcu_read_lock();
Rusty Russelle2c88062009-11-03 14:53:15 +10301519 for_each_domain(cpu, sd) {
1520 if (sd->flags & SD_WAKE_AFFINE) {
1521 int best_cpu;
Gregory Haskins6e1254d2008-01-25 21:08:11 +01001522
Rusty Russelle2c88062009-11-03 14:53:15 +10301523 /*
1524 * "this_cpu" is cheaper to preempt than a
1525 * remote processor.
1526 */
1527 if (this_cpu != -1 &&
Xiaotian Fengcd4ae6a2011-04-22 18:53:54 +08001528 cpumask_test_cpu(this_cpu, sched_domain_span(sd))) {
1529 rcu_read_unlock();
Rusty Russelle2c88062009-11-03 14:53:15 +10301530 return this_cpu;
Xiaotian Fengcd4ae6a2011-04-22 18:53:54 +08001531 }
Gregory Haskins6e1254d2008-01-25 21:08:11 +01001532
Rusty Russelle2c88062009-11-03 14:53:15 +10301533 best_cpu = cpumask_first_and(lowest_mask,
1534 sched_domain_span(sd));
Xiaotian Fengcd4ae6a2011-04-22 18:53:54 +08001535 if (best_cpu < nr_cpu_ids) {
1536 rcu_read_unlock();
Rusty Russelle2c88062009-11-03 14:53:15 +10301537 return best_cpu;
Xiaotian Fengcd4ae6a2011-04-22 18:53:54 +08001538 }
Gregory Haskins6e1254d2008-01-25 21:08:11 +01001539 }
1540 }
Xiaotian Fengcd4ae6a2011-04-22 18:53:54 +08001541 rcu_read_unlock();
Gregory Haskins6e1254d2008-01-25 21:08:11 +01001542
1543 /*
1544 * And finally, if there were no matches within the domains
1545 * just give the caller *something* to work with from the compatible
1546 * locations.
1547 */
Rusty Russelle2c88062009-11-03 14:53:15 +10301548 if (this_cpu != -1)
1549 return this_cpu;
1550
1551 cpu = cpumask_any(lowest_mask);
1552 if (cpu < nr_cpu_ids)
1553 return cpu;
1554 return -1;
Gregory Haskins07b40322008-01-25 21:08:10 +01001555}
1556
Steven Rostedte8fa1362008-01-25 21:08:05 +01001557/* Will lock the rq it finds */
Ingo Molnar4df64c02008-01-25 21:08:15 +01001558static struct rq *find_lock_lowest_rq(struct task_struct *task, struct rq *rq)
Steven Rostedte8fa1362008-01-25 21:08:05 +01001559{
1560 struct rq *lowest_rq = NULL;
Steven Rostedte8fa1362008-01-25 21:08:05 +01001561 int tries;
Ingo Molnar4df64c02008-01-25 21:08:15 +01001562 int cpu;
Steven Rostedte8fa1362008-01-25 21:08:05 +01001563
1564 for (tries = 0; tries < RT_MAX_TRIES; tries++) {
Gregory Haskins07b40322008-01-25 21:08:10 +01001565 cpu = find_lowest_rq(task);
Steven Rostedte8fa1362008-01-25 21:08:05 +01001566
Gregory Haskins2de0b462008-01-25 21:08:10 +01001567 if ((cpu == -1) || (cpu == rq->cpu))
Steven Rostedte8fa1362008-01-25 21:08:05 +01001568 break;
1569
Gregory Haskins07b40322008-01-25 21:08:10 +01001570 lowest_rq = cpu_rq(cpu);
1571
Steven Rostedte8fa1362008-01-25 21:08:05 +01001572 /* if the prio of this runqueue changed, try again */
Gregory Haskins07b40322008-01-25 21:08:10 +01001573 if (double_lock_balance(rq, lowest_rq)) {
Steven Rostedte8fa1362008-01-25 21:08:05 +01001574 /*
1575 * We had to unlock the run queue. In
1576 * the mean time, task could have
1577 * migrated already or had its affinity changed.
1578 * Also make sure that it wasn't scheduled on its rq.
1579 */
Gregory Haskins07b40322008-01-25 21:08:10 +01001580 if (unlikely(task_rq(task) != rq ||
Rusty Russell96f874e2008-11-25 02:35:14 +10301581 !cpumask_test_cpu(lowest_rq->cpu,
Peter Zijlstrafa17b502011-06-16 12:23:22 +02001582 tsk_cpus_allowed(task)) ||
Gregory Haskins07b40322008-01-25 21:08:10 +01001583 task_running(rq, task) ||
Peter Zijlstrafd2f4412011-04-05 17:23:44 +02001584 !task->on_rq)) {
Ingo Molnar4df64c02008-01-25 21:08:15 +01001585
Thomas Gleixner05fa7852009-11-17 14:28:38 +01001586 raw_spin_unlock(&lowest_rq->lock);
Steven Rostedte8fa1362008-01-25 21:08:05 +01001587 lowest_rq = NULL;
1588 break;
1589 }
1590 }
1591
1592 /* If this rq is still suitable use it. */
Gregory Haskinse864c492008-12-29 09:39:49 -05001593 if (lowest_rq->rt.highest_prio.curr > task->prio)
Steven Rostedte8fa1362008-01-25 21:08:05 +01001594 break;
1595
1596 /* try again */
Peter Zijlstra1b12bbc2008-08-11 09:30:22 +02001597 double_unlock_balance(rq, lowest_rq);
Steven Rostedte8fa1362008-01-25 21:08:05 +01001598 lowest_rq = NULL;
1599 }
1600
1601 return lowest_rq;
1602}
1603
Gregory Haskins917b6272008-12-29 09:39:53 -05001604static struct task_struct *pick_next_pushable_task(struct rq *rq)
1605{
1606 struct task_struct *p;
1607
1608 if (!has_pushable_tasks(rq))
1609 return NULL;
1610
1611 p = plist_first_entry(&rq->rt.pushable_tasks,
1612 struct task_struct, pushable_tasks);
1613
1614 BUG_ON(rq->cpu != task_cpu(p));
1615 BUG_ON(task_current(rq, p));
1616 BUG_ON(p->rt.nr_cpus_allowed <= 1);
1617
Peter Zijlstrafd2f4412011-04-05 17:23:44 +02001618 BUG_ON(!p->on_rq);
Gregory Haskins917b6272008-12-29 09:39:53 -05001619 BUG_ON(!rt_task(p));
1620
1621 return p;
1622}
1623
Steven Rostedte8fa1362008-01-25 21:08:05 +01001624/*
1625 * If the current CPU has more than one RT task, see if the non
1626 * running task can migrate over to a CPU that is running a task
1627 * of lesser priority.
1628 */
Gregory Haskins697f0a42008-01-25 21:08:09 +01001629static int push_rt_task(struct rq *rq)
Steven Rostedte8fa1362008-01-25 21:08:05 +01001630{
1631 struct task_struct *next_task;
1632 struct rq *lowest_rq;
Hillf Danton311e8002011-06-16 21:55:20 -04001633 int ret = 0;
Steven Rostedte8fa1362008-01-25 21:08:05 +01001634
Gregory Haskinsa22d7fc2008-01-25 21:08:12 +01001635 if (!rq->rt.overloaded)
1636 return 0;
1637
Gregory Haskins917b6272008-12-29 09:39:53 -05001638 next_task = pick_next_pushable_task(rq);
Steven Rostedte8fa1362008-01-25 21:08:05 +01001639 if (!next_task)
1640 return 0;
1641
Chanho Mincb297a32012-01-05 20:00:19 +09001642#ifdef __ARCH_WANT_INTERRUPTS_ON_CTXSW
1643 if (unlikely(task_running(rq, next_task)))
1644 return 0;
1645#endif
1646
Peter Zijlstra49246272010-10-17 21:46:10 +02001647retry:
Gregory Haskins697f0a42008-01-25 21:08:09 +01001648 if (unlikely(next_task == rq->curr)) {
Steven Rostedtf65eda42008-01-25 21:08:07 +01001649 WARN_ON(1);
Steven Rostedte8fa1362008-01-25 21:08:05 +01001650 return 0;
Steven Rostedtf65eda42008-01-25 21:08:07 +01001651 }
Steven Rostedte8fa1362008-01-25 21:08:05 +01001652
1653 /*
1654 * It's possible that the next_task slipped in of
1655 * higher priority than current. If that's the case
1656 * just reschedule current.
1657 */
Gregory Haskins697f0a42008-01-25 21:08:09 +01001658 if (unlikely(next_task->prio < rq->curr->prio)) {
1659 resched_task(rq->curr);
Steven Rostedte8fa1362008-01-25 21:08:05 +01001660 return 0;
1661 }
1662
Gregory Haskins697f0a42008-01-25 21:08:09 +01001663 /* We might release rq lock */
Steven Rostedte8fa1362008-01-25 21:08:05 +01001664 get_task_struct(next_task);
1665
1666 /* find_lock_lowest_rq locks the rq if found */
Gregory Haskins697f0a42008-01-25 21:08:09 +01001667 lowest_rq = find_lock_lowest_rq(next_task, rq);
Steven Rostedte8fa1362008-01-25 21:08:05 +01001668 if (!lowest_rq) {
1669 struct task_struct *task;
1670 /*
Hillf Danton311e8002011-06-16 21:55:20 -04001671 * find_lock_lowest_rq releases rq->lock
Gregory Haskins15635132008-12-29 09:39:53 -05001672 * so it is possible that next_task has migrated.
1673 *
1674 * We need to make sure that the task is still on the same
1675 * run-queue and is also still the next task eligible for
1676 * pushing.
Steven Rostedte8fa1362008-01-25 21:08:05 +01001677 */
Gregory Haskins917b6272008-12-29 09:39:53 -05001678 task = pick_next_pushable_task(rq);
Gregory Haskins15635132008-12-29 09:39:53 -05001679 if (task_cpu(next_task) == rq->cpu && task == next_task) {
1680 /*
Hillf Danton311e8002011-06-16 21:55:20 -04001681 * The task hasn't migrated, and is still the next
1682 * eligible task, but we failed to find a run-queue
1683 * to push it to. Do not retry in this case, since
1684 * other cpus will pull from us when ready.
Gregory Haskins15635132008-12-29 09:39:53 -05001685 */
Gregory Haskins15635132008-12-29 09:39:53 -05001686 goto out;
Steven Rostedte8fa1362008-01-25 21:08:05 +01001687 }
Gregory Haskins917b6272008-12-29 09:39:53 -05001688
Gregory Haskins15635132008-12-29 09:39:53 -05001689 if (!task)
1690 /* No more tasks, just exit */
1691 goto out;
1692
Gregory Haskins917b6272008-12-29 09:39:53 -05001693 /*
Gregory Haskins15635132008-12-29 09:39:53 -05001694 * Something has shifted, try again.
Gregory Haskins917b6272008-12-29 09:39:53 -05001695 */
Gregory Haskins15635132008-12-29 09:39:53 -05001696 put_task_struct(next_task);
1697 next_task = task;
1698 goto retry;
Steven Rostedte8fa1362008-01-25 21:08:05 +01001699 }
1700
Gregory Haskins697f0a42008-01-25 21:08:09 +01001701 deactivate_task(rq, next_task, 0);
Steven Rostedte8fa1362008-01-25 21:08:05 +01001702 set_task_cpu(next_task, lowest_rq->cpu);
1703 activate_task(lowest_rq, next_task, 0);
Hillf Danton311e8002011-06-16 21:55:20 -04001704 ret = 1;
Steven Rostedte8fa1362008-01-25 21:08:05 +01001705
1706 resched_task(lowest_rq->curr);
1707
Peter Zijlstra1b12bbc2008-08-11 09:30:22 +02001708 double_unlock_balance(rq, lowest_rq);
Steven Rostedte8fa1362008-01-25 21:08:05 +01001709
Steven Rostedte8fa1362008-01-25 21:08:05 +01001710out:
1711 put_task_struct(next_task);
1712
Hillf Danton311e8002011-06-16 21:55:20 -04001713 return ret;
Steven Rostedte8fa1362008-01-25 21:08:05 +01001714}
1715
Steven Rostedte8fa1362008-01-25 21:08:05 +01001716static void push_rt_tasks(struct rq *rq)
1717{
1718 /* push_rt_task will return true if it moved an RT */
1719 while (push_rt_task(rq))
1720 ;
1721}
1722
Steven Rostedtf65eda42008-01-25 21:08:07 +01001723static int pull_rt_task(struct rq *this_rq)
1724{
Ingo Molnar80bf3172008-01-25 21:08:17 +01001725 int this_cpu = this_rq->cpu, ret = 0, cpu;
Gregory Haskinsa8728942008-12-29 09:39:49 -05001726 struct task_struct *p;
Steven Rostedtf65eda42008-01-25 21:08:07 +01001727 struct rq *src_rq;
Steven Rostedtf65eda42008-01-25 21:08:07 +01001728
Gregory Haskins637f5082008-01-25 21:08:18 +01001729 if (likely(!rt_overloaded(this_rq)))
Steven Rostedtf65eda42008-01-25 21:08:07 +01001730 return 0;
1731
Rusty Russellc6c49272008-11-25 02:35:05 +10301732 for_each_cpu(cpu, this_rq->rd->rto_mask) {
Steven Rostedtf65eda42008-01-25 21:08:07 +01001733 if (this_cpu == cpu)
1734 continue;
1735
1736 src_rq = cpu_rq(cpu);
Gregory Haskins74ab8e42008-12-29 09:39:50 -05001737
1738 /*
1739 * Don't bother taking the src_rq->lock if the next highest
1740 * task is known to be lower-priority than our current task.
1741 * This may look racy, but if this value is about to go
1742 * logically higher, the src_rq will push this task away.
1743 * And if its going logically lower, we do not care
1744 */
1745 if (src_rq->rt.highest_prio.next >=
1746 this_rq->rt.highest_prio.curr)
1747 continue;
1748
Steven Rostedtf65eda42008-01-25 21:08:07 +01001749 /*
1750 * We can potentially drop this_rq's lock in
1751 * double_lock_balance, and another CPU could
Gregory Haskinsa8728942008-12-29 09:39:49 -05001752 * alter this_rq
Steven Rostedtf65eda42008-01-25 21:08:07 +01001753 */
Gregory Haskinsa8728942008-12-29 09:39:49 -05001754 double_lock_balance(this_rq, src_rq);
Steven Rostedtf65eda42008-01-25 21:08:07 +01001755
1756 /*
1757 * Are there still pullable RT tasks?
1758 */
Mike Galbraith614ee1f2008-01-25 21:08:30 +01001759 if (src_rq->rt.rt_nr_running <= 1)
1760 goto skip;
Steven Rostedtf65eda42008-01-25 21:08:07 +01001761
Steven Rostedtf65eda42008-01-25 21:08:07 +01001762 p = pick_next_highest_task_rt(src_rq, this_cpu);
1763
1764 /*
1765 * Do we have an RT task that preempts
1766 * the to-be-scheduled task?
1767 */
Gregory Haskinsa8728942008-12-29 09:39:49 -05001768 if (p && (p->prio < this_rq->rt.highest_prio.curr)) {
Steven Rostedtf65eda42008-01-25 21:08:07 +01001769 WARN_ON(p == src_rq->curr);
Peter Zijlstrafd2f4412011-04-05 17:23:44 +02001770 WARN_ON(!p->on_rq);
Steven Rostedtf65eda42008-01-25 21:08:07 +01001771
1772 /*
1773 * There's a chance that p is higher in priority
1774 * than what's currently running on its cpu.
1775 * This is just that p is wakeing up and hasn't
1776 * had a chance to schedule. We only pull
1777 * p if it is lower in priority than the
Gregory Haskinsa8728942008-12-29 09:39:49 -05001778 * current task on the run queue
Steven Rostedtf65eda42008-01-25 21:08:07 +01001779 */
Gregory Haskinsa8728942008-12-29 09:39:49 -05001780 if (p->prio < src_rq->curr->prio)
Mike Galbraith614ee1f2008-01-25 21:08:30 +01001781 goto skip;
Steven Rostedtf65eda42008-01-25 21:08:07 +01001782
1783 ret = 1;
1784
1785 deactivate_task(src_rq, p, 0);
1786 set_task_cpu(p, this_cpu);
1787 activate_task(this_rq, p, 0);
1788 /*
1789 * We continue with the search, just in
1790 * case there's an even higher prio task
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001791 * in another runqueue. (low likelihood
Steven Rostedtf65eda42008-01-25 21:08:07 +01001792 * but possible)
Steven Rostedtf65eda42008-01-25 21:08:07 +01001793 */
Steven Rostedtf65eda42008-01-25 21:08:07 +01001794 }
Peter Zijlstra49246272010-10-17 21:46:10 +02001795skip:
Peter Zijlstra1b12bbc2008-08-11 09:30:22 +02001796 double_unlock_balance(this_rq, src_rq);
Steven Rostedtf65eda42008-01-25 21:08:07 +01001797 }
1798
1799 return ret;
1800}
1801
Steven Rostedt9a897c52008-01-25 21:08:22 +01001802static void pre_schedule_rt(struct rq *rq, struct task_struct *prev)
Steven Rostedtf65eda42008-01-25 21:08:07 +01001803{
1804 /* Try to pull RT tasks here if we lower this rq's prio */
Yong Zhang33c3d6c2010-02-09 14:43:59 -05001805 if (rq->rt.highest_prio.curr > prev->prio)
Steven Rostedtf65eda42008-01-25 21:08:07 +01001806 pull_rt_task(rq);
1807}
1808
Steven Rostedt9a897c52008-01-25 21:08:22 +01001809static void post_schedule_rt(struct rq *rq)
Steven Rostedte8fa1362008-01-25 21:08:05 +01001810{
Gregory Haskins967fc042008-12-29 09:39:52 -05001811 push_rt_tasks(rq);
Steven Rostedte8fa1362008-01-25 21:08:05 +01001812}
1813
Gregory Haskins8ae121a2008-04-23 07:13:29 -04001814/*
1815 * If we are not running and we are not going to reschedule soon, we should
1816 * try to push tasks away now
1817 */
Peter Zijlstraefbbd052009-12-16 18:04:40 +01001818static void task_woken_rt(struct rq *rq, struct task_struct *p)
Steven Rostedt4642daf2008-01-25 21:08:07 +01001819{
Steven Rostedt9a897c52008-01-25 21:08:22 +01001820 if (!task_running(rq, p) &&
Gregory Haskins8ae121a2008-04-23 07:13:29 -04001821 !test_tsk_need_resched(rq->curr) &&
Gregory Haskins917b6272008-12-29 09:39:53 -05001822 has_pushable_tasks(rq) &&
Steven Rostedtb3bc2112010-09-20 22:40:04 -04001823 p->rt.nr_cpus_allowed > 1 &&
Steven Rostedt43fa5462010-09-20 22:40:03 -04001824 rt_task(rq->curr) &&
Steven Rostedtb3bc2112010-09-20 22:40:04 -04001825 (rq->curr->rt.nr_cpus_allowed < 2 ||
Shawn Bohrer3be209a2011-09-12 09:28:04 -05001826 rq->curr->prio <= p->prio))
Steven Rostedt4642daf2008-01-25 21:08:07 +01001827 push_rt_tasks(rq);
1828}
1829
Mike Traviscd8ba7c2008-03-26 14:23:49 -07001830static void set_cpus_allowed_rt(struct task_struct *p,
Rusty Russell96f874e2008-11-25 02:35:14 +10301831 const struct cpumask *new_mask)
Gregory Haskins73fe6aa2008-01-25 21:08:07 +01001832{
Rusty Russell96f874e2008-11-25 02:35:14 +10301833 int weight = cpumask_weight(new_mask);
Gregory Haskins73fe6aa2008-01-25 21:08:07 +01001834
1835 BUG_ON(!rt_task(p));
1836
1837 /*
1838 * Update the migration status of the RQ if we have an RT task
1839 * which is running AND changing its weight value.
1840 */
Peter Zijlstrafd2f4412011-04-05 17:23:44 +02001841 if (p->on_rq && (weight != p->rt.nr_cpus_allowed)) {
Gregory Haskins73fe6aa2008-01-25 21:08:07 +01001842 struct rq *rq = task_rq(p);
1843
Gregory Haskins917b6272008-12-29 09:39:53 -05001844 if (!task_current(rq, p)) {
1845 /*
1846 * Make sure we dequeue this task from the pushable list
1847 * before going further. It will either remain off of
1848 * the list because we are no longer pushable, or it
1849 * will be requeued.
1850 */
1851 if (p->rt.nr_cpus_allowed > 1)
1852 dequeue_pushable_task(rq, p);
1853
1854 /*
1855 * Requeue if our weight is changing and still > 1
1856 */
1857 if (weight > 1)
1858 enqueue_pushable_task(rq, p);
1859
1860 }
1861
Peter Zijlstra6f505b12008-01-25 21:08:30 +01001862 if ((p->rt.nr_cpus_allowed <= 1) && (weight > 1)) {
Gregory Haskins73fe6aa2008-01-25 21:08:07 +01001863 rq->rt.rt_nr_migratory++;
Peter Zijlstra6f505b12008-01-25 21:08:30 +01001864 } else if ((p->rt.nr_cpus_allowed > 1) && (weight <= 1)) {
Gregory Haskins73fe6aa2008-01-25 21:08:07 +01001865 BUG_ON(!rq->rt.rt_nr_migratory);
1866 rq->rt.rt_nr_migratory--;
1867 }
1868
Gregory Haskins398a1532009-01-14 09:10:04 -05001869 update_rt_migration(&rq->rt);
Gregory Haskins73fe6aa2008-01-25 21:08:07 +01001870 }
Gregory Haskins73fe6aa2008-01-25 21:08:07 +01001871}
Ingo Molnardeeeccd2008-01-25 21:08:15 +01001872
Ingo Molnarbdd7c812008-01-25 21:08:18 +01001873/* Assumes rq->lock is held */
Gregory Haskins1f11eb62008-06-04 15:04:05 -04001874static void rq_online_rt(struct rq *rq)
Ingo Molnarbdd7c812008-01-25 21:08:18 +01001875{
1876 if (rq->rt.overloaded)
1877 rt_set_overload(rq);
Gregory Haskins6e0534f2008-05-12 21:21:01 +02001878
Peter Zijlstra7def2be2008-06-05 14:49:58 +02001879 __enable_runtime(rq);
1880
Gregory Haskinse864c492008-12-29 09:39:49 -05001881 cpupri_set(&rq->rd->cpupri, rq->cpu, rq->rt.highest_prio.curr);
Ingo Molnarbdd7c812008-01-25 21:08:18 +01001882}
1883
1884/* Assumes rq->lock is held */
Gregory Haskins1f11eb62008-06-04 15:04:05 -04001885static void rq_offline_rt(struct rq *rq)
Ingo Molnarbdd7c812008-01-25 21:08:18 +01001886{
1887 if (rq->rt.overloaded)
1888 rt_clear_overload(rq);
Gregory Haskins6e0534f2008-05-12 21:21:01 +02001889
Peter Zijlstra7def2be2008-06-05 14:49:58 +02001890 __disable_runtime(rq);
1891
Gregory Haskins6e0534f2008-05-12 21:21:01 +02001892 cpupri_set(&rq->rd->cpupri, rq->cpu, CPUPRI_INVALID);
Ingo Molnarbdd7c812008-01-25 21:08:18 +01001893}
Steven Rostedtcb469842008-01-25 21:08:22 +01001894
1895/*
1896 * When switch from the rt queue, we bring ourselves to a position
1897 * that we might want to pull RT tasks from other runqueues.
1898 */
Peter Zijlstrada7a7352011-01-17 17:03:27 +01001899static void switched_from_rt(struct rq *rq, struct task_struct *p)
Steven Rostedtcb469842008-01-25 21:08:22 +01001900{
1901 /*
1902 * If there are other RT tasks then we will reschedule
1903 * and the scheduling of the other RT tasks will handle
1904 * the balancing. But if we are the last RT task
1905 * we may need to handle the pulling of RT tasks
1906 * now.
1907 */
Peter Zijlstrafd2f4412011-04-05 17:23:44 +02001908 if (p->on_rq && !rq->rt.rt_nr_running)
Steven Rostedtcb469842008-01-25 21:08:22 +01001909 pull_rt_task(rq);
1910}
Rusty Russell3d8cbdf2008-11-25 09:58:41 +10301911
Peter Zijlstra029632f2011-10-25 10:00:11 +02001912void init_sched_rt_class(void)
Rusty Russell3d8cbdf2008-11-25 09:58:41 +10301913{
1914 unsigned int i;
1915
Peter Zijlstra029632f2011-10-25 10:00:11 +02001916 for_each_possible_cpu(i) {
Yinghai Lueaa95842009-06-06 14:51:36 -07001917 zalloc_cpumask_var_node(&per_cpu(local_cpu_mask, i),
Mike Travis6ca09df2008-12-31 18:08:45 -08001918 GFP_KERNEL, cpu_to_node(i));
Peter Zijlstra029632f2011-10-25 10:00:11 +02001919 }
Rusty Russell3d8cbdf2008-11-25 09:58:41 +10301920}
Steven Rostedte8fa1362008-01-25 21:08:05 +01001921#endif /* CONFIG_SMP */
Ingo Molnarbb44e5d2007-07-09 18:51:58 +02001922
Steven Rostedtcb469842008-01-25 21:08:22 +01001923/*
1924 * When switching a task to RT, we may overload the runqueue
1925 * with RT tasks. In this case we try to push them off to
1926 * other runqueues.
1927 */
Peter Zijlstrada7a7352011-01-17 17:03:27 +01001928static void switched_to_rt(struct rq *rq, struct task_struct *p)
Steven Rostedtcb469842008-01-25 21:08:22 +01001929{
1930 int check_resched = 1;
1931
1932 /*
1933 * If we are already running, then there's nothing
1934 * that needs to be done. But if we are not running
1935 * we may need to preempt the current running task.
1936 * If that current running task is also an RT task
1937 * then see if we can move to another run queue.
1938 */
Peter Zijlstrafd2f4412011-04-05 17:23:44 +02001939 if (p->on_rq && rq->curr != p) {
Steven Rostedtcb469842008-01-25 21:08:22 +01001940#ifdef CONFIG_SMP
1941 if (rq->rt.overloaded && push_rt_task(rq) &&
1942 /* Don't resched if we changed runqueues */
1943 rq != task_rq(p))
1944 check_resched = 0;
1945#endif /* CONFIG_SMP */
1946 if (check_resched && p->prio < rq->curr->prio)
1947 resched_task(rq->curr);
1948 }
1949}
1950
1951/*
1952 * Priority of the task has changed. This may cause
1953 * us to initiate a push or pull.
1954 */
Peter Zijlstrada7a7352011-01-17 17:03:27 +01001955static void
1956prio_changed_rt(struct rq *rq, struct task_struct *p, int oldprio)
Steven Rostedtcb469842008-01-25 21:08:22 +01001957{
Peter Zijlstrafd2f4412011-04-05 17:23:44 +02001958 if (!p->on_rq)
Peter Zijlstrada7a7352011-01-17 17:03:27 +01001959 return;
1960
1961 if (rq->curr == p) {
Steven Rostedtcb469842008-01-25 21:08:22 +01001962#ifdef CONFIG_SMP
1963 /*
1964 * If our priority decreases while running, we
1965 * may need to pull tasks to this runqueue.
1966 */
1967 if (oldprio < p->prio)
1968 pull_rt_task(rq);
1969 /*
1970 * If there's a higher priority task waiting to run
Steven Rostedt6fa46fa2008-03-05 10:00:12 -05001971 * then reschedule. Note, the above pull_rt_task
1972 * can release the rq lock and p could migrate.
1973 * Only reschedule if p is still on the same runqueue.
Steven Rostedtcb469842008-01-25 21:08:22 +01001974 */
Gregory Haskinse864c492008-12-29 09:39:49 -05001975 if (p->prio > rq->rt.highest_prio.curr && rq->curr == p)
Steven Rostedtcb469842008-01-25 21:08:22 +01001976 resched_task(p);
1977#else
1978 /* For UP simply resched on drop of prio */
1979 if (oldprio < p->prio)
1980 resched_task(p);
1981#endif /* CONFIG_SMP */
1982 } else {
1983 /*
1984 * This task is not running, but if it is
1985 * greater than the current running task
1986 * then reschedule.
1987 */
1988 if (p->prio < rq->curr->prio)
1989 resched_task(rq->curr);
1990 }
1991}
1992
Peter Zijlstra78f2c7d2008-01-25 21:08:27 +01001993static void watchdog(struct rq *rq, struct task_struct *p)
1994{
1995 unsigned long soft, hard;
1996
Jiri Slaby78d7d402010-03-05 13:42:54 -08001997 /* max may change after cur was read, this will be fixed next tick */
1998 soft = task_rlimit(p, RLIMIT_RTTIME);
1999 hard = task_rlimit_max(p, RLIMIT_RTTIME);
Peter Zijlstra78f2c7d2008-01-25 21:08:27 +01002000
2001 if (soft != RLIM_INFINITY) {
2002 unsigned long next;
2003
2004 p->rt.timeout++;
2005 next = DIV_ROUND_UP(min(soft, hard), USEC_PER_SEC/HZ);
Peter Zijlstra5a52dd52008-01-25 21:08:32 +01002006 if (p->rt.timeout > next)
Frank Mayharf06febc2008-09-12 09:54:39 -07002007 p->cputime_expires.sched_exp = p->se.sum_exec_runtime;
Peter Zijlstra78f2c7d2008-01-25 21:08:27 +01002008 }
2009}
Steven Rostedtcb469842008-01-25 21:08:22 +01002010
Peter Zijlstra8f4d37e2008-01-25 21:08:29 +01002011static void task_tick_rt(struct rq *rq, struct task_struct *p, int queued)
Ingo Molnarbb44e5d2007-07-09 18:51:58 +02002012{
Colin Cross21b53ba2012-05-16 21:34:23 -07002013 struct sched_rt_entity *rt_se = &p->rt;
2014
Peter Zijlstra67e2be02007-12-20 15:01:17 +01002015 update_curr_rt(rq);
2016
Peter Zijlstra78f2c7d2008-01-25 21:08:27 +01002017 watchdog(rq, p);
2018
Ingo Molnarbb44e5d2007-07-09 18:51:58 +02002019 /*
2020 * RR tasks need a special form of timeslice management.
2021 * FIFO tasks have no timeslices.
2022 */
2023 if (p->policy != SCHED_RR)
2024 return;
2025
Peter Zijlstrafa717062008-01-25 21:08:27 +01002026 if (--p->rt.time_slice)
Ingo Molnarbb44e5d2007-07-09 18:51:58 +02002027 return;
2028
Hiroshi Shimamotode5bdff2012-02-16 14:52:21 +09002029 p->rt.time_slice = RR_TIMESLICE;
Ingo Molnarbb44e5d2007-07-09 18:51:58 +02002030
Dmitry Adamushko98fbc792007-08-24 20:39:10 +02002031 /*
Colin Cross21b53ba2012-05-16 21:34:23 -07002032 * Requeue to the end of queue if we (and all of our ancestors) are the
2033 * only element on the queue
Dmitry Adamushko98fbc792007-08-24 20:39:10 +02002034 */
Colin Cross21b53ba2012-05-16 21:34:23 -07002035 for_each_sched_rt_entity(rt_se) {
2036 if (rt_se->run_list.prev != rt_se->run_list.next) {
2037 requeue_task_rt(rq, p, 0);
2038 set_tsk_need_resched(p);
2039 return;
2040 }
Dmitry Adamushko98fbc792007-08-24 20:39:10 +02002041 }
Ingo Molnarbb44e5d2007-07-09 18:51:58 +02002042}
2043
Srivatsa Vaddagiri83b699e2007-10-15 17:00:08 +02002044static void set_curr_task_rt(struct rq *rq)
2045{
2046 struct task_struct *p = rq->curr;
2047
Venkatesh Pallipadi305e6832010-10-04 17:03:21 -07002048 p->se.exec_start = rq->clock_task;
Gregory Haskins917b6272008-12-29 09:39:53 -05002049
2050 /* The running task is never eligible for pushing */
2051 dequeue_pushable_task(rq, p);
Srivatsa Vaddagiri83b699e2007-10-15 17:00:08 +02002052}
2053
H Hartley Sweeten6d686f42010-01-13 20:21:52 -07002054static unsigned int get_rr_interval_rt(struct rq *rq, struct task_struct *task)
Peter Williams0d721ce2009-09-21 01:31:53 +00002055{
2056 /*
2057 * Time slice is 0 for SCHED_FIFO tasks
2058 */
2059 if (task->policy == SCHED_RR)
Hiroshi Shimamotode5bdff2012-02-16 14:52:21 +09002060 return RR_TIMESLICE;
Peter Williams0d721ce2009-09-21 01:31:53 +00002061 else
2062 return 0;
2063}
2064
Peter Zijlstra029632f2011-10-25 10:00:11 +02002065const struct sched_class rt_sched_class = {
Ingo Molnar5522d5d2007-10-15 17:00:12 +02002066 .next = &fair_sched_class,
Ingo Molnarbb44e5d2007-07-09 18:51:58 +02002067 .enqueue_task = enqueue_task_rt,
2068 .dequeue_task = dequeue_task_rt,
2069 .yield_task = yield_task_rt,
2070
2071 .check_preempt_curr = check_preempt_curr_rt,
2072
2073 .pick_next_task = pick_next_task_rt,
2074 .put_prev_task = put_prev_task_rt,
2075
Peter Williams681f3e62007-10-24 18:23:51 +02002076#ifdef CONFIG_SMP
Li Zefan4ce72a22008-10-22 15:25:26 +08002077 .select_task_rq = select_task_rq_rt,
2078
Gregory Haskins73fe6aa2008-01-25 21:08:07 +01002079 .set_cpus_allowed = set_cpus_allowed_rt,
Gregory Haskins1f11eb62008-06-04 15:04:05 -04002080 .rq_online = rq_online_rt,
2081 .rq_offline = rq_offline_rt,
Steven Rostedt9a897c52008-01-25 21:08:22 +01002082 .pre_schedule = pre_schedule_rt,
2083 .post_schedule = post_schedule_rt,
Peter Zijlstraefbbd052009-12-16 18:04:40 +01002084 .task_woken = task_woken_rt,
Steven Rostedtcb469842008-01-25 21:08:22 +01002085 .switched_from = switched_from_rt,
Peter Williams681f3e62007-10-24 18:23:51 +02002086#endif
Ingo Molnarbb44e5d2007-07-09 18:51:58 +02002087
Srivatsa Vaddagiri83b699e2007-10-15 17:00:08 +02002088 .set_curr_task = set_curr_task_rt,
Ingo Molnarbb44e5d2007-07-09 18:51:58 +02002089 .task_tick = task_tick_rt,
Steven Rostedtcb469842008-01-25 21:08:22 +01002090
Peter Williams0d721ce2009-09-21 01:31:53 +00002091 .get_rr_interval = get_rr_interval_rt,
2092
Steven Rostedtcb469842008-01-25 21:08:22 +01002093 .prio_changed = prio_changed_rt,
2094 .switched_to = switched_to_rt,
Ingo Molnarbb44e5d2007-07-09 18:51:58 +02002095};
Peter Zijlstraada18de2008-06-19 14:22:24 +02002096
2097#ifdef CONFIG_SCHED_DEBUG
2098extern void print_rt_rq(struct seq_file *m, int cpu, struct rt_rq *rt_rq);
2099
Peter Zijlstra029632f2011-10-25 10:00:11 +02002100void print_rt_stats(struct seq_file *m, int cpu)
Peter Zijlstraada18de2008-06-19 14:22:24 +02002101{
Cheng Xuec514c42011-05-14 14:20:02 +08002102 rt_rq_iter_t iter;
Peter Zijlstraada18de2008-06-19 14:22:24 +02002103 struct rt_rq *rt_rq;
2104
2105 rcu_read_lock();
Cheng Xuec514c42011-05-14 14:20:02 +08002106 for_each_rt_rq(rt_rq, iter, cpu_rq(cpu))
Peter Zijlstraada18de2008-06-19 14:22:24 +02002107 print_rt_rq(m, cpu, rt_rq);
2108 rcu_read_unlock();
2109}
Dhaval Giani55e12e52008-06-24 23:39:43 +05302110#endif /* CONFIG_SCHED_DEBUG */