aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/sched/core.c
diff options
context:
space:
mode:
authorPeter Zijlstra <peterz@infradead.org>2013-08-14 08:55:31 -0400
committerIngo Molnar <mingo@kernel.org>2013-09-25 08:07:49 -0400
commitf27dde8deef33c9e58027df11ceab2198601d6a6 (patch)
tree31793590541baf5b9998b5ca0cc459b757a7cbcf /kernel/sched/core.c
parent4a2b4b222743bb07fedf985b884550f2ca067ea9 (diff)
sched: Add NEED_RESCHED to the preempt_count
In order to combine the preemption and need_resched test we need to fold the need_resched information into the preempt_count value. Since the NEED_RESCHED flag is set across CPUs this needs to be an atomic operation, however we very much want to avoid making preempt_count atomic, therefore we keep the existing TIF_NEED_RESCHED infrastructure in place but at 3 sites test it and fold its value into preempt_count; namely: - resched_task() when setting TIF_NEED_RESCHED on the current task - scheduler_ipi() when resched_task() sets TIF_NEED_RESCHED on a remote task it follows it up with a reschedule IPI and we can modify the cpu local preempt_count from there. - cpu_idle_loop() for when resched_task() found tsk_is_polling(). We use an inverted bitmask to indicate need_resched so that a 0 means both need_resched and !atomic. Also remove the barrier() in preempt_enable() between preempt_enable_no_resched() and preempt_check_resched() to avoid having to reload the preemption value and allow the compiler to use the flags of the previuos decrement. I couldn't come up with any sane reason for this barrier() to be there as preempt_enable_no_resched() already has a barrier() before doing the decrement. Suggested-by: Ingo Molnar <mingo@kernel.org> Signed-off-by: Peter Zijlstra <peterz@infradead.org> Link: http://lkml.kernel.org/n/tip-7a7m5qqbn5pmwnd4wko9u6da@git.kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'kernel/sched/core.c')
-rw-r--r--kernel/sched/core.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index fe89afac4d09..ee61f5affd20 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -525,8 +525,10 @@ void resched_task(struct task_struct *p)
525 set_tsk_need_resched(p); 525 set_tsk_need_resched(p);
526 526
527 cpu = task_cpu(p); 527 cpu = task_cpu(p);
528 if (cpu == smp_processor_id()) 528 if (cpu == smp_processor_id()) {
529 set_preempt_need_resched();
529 return; 530 return;
531 }
530 532
531 /* NEED_RESCHED must be visible before we test polling */ 533 /* NEED_RESCHED must be visible before we test polling */
532 smp_mb(); 534 smp_mb();
@@ -1391,6 +1393,14 @@ static void sched_ttwu_pending(void)
1391 1393
1392void scheduler_ipi(void) 1394void scheduler_ipi(void)
1393{ 1395{
1396 /*
1397 * Fold TIF_NEED_RESCHED into the preempt_count; anybody setting
1398 * TIF_NEED_RESCHED remotely (for the first time) will also send
1399 * this IPI.
1400 */
1401 if (tif_need_resched())
1402 set_preempt_need_resched();
1403
1394 if (llist_empty(&this_rq()->wake_list) 1404 if (llist_empty(&this_rq()->wake_list)
1395 && !tick_nohz_full_cpu(smp_processor_id()) 1405 && !tick_nohz_full_cpu(smp_processor_id())
1396 && !got_nohz_idle_kick()) 1406 && !got_nohz_idle_kick())
@@ -1714,7 +1724,7 @@ void sched_fork(struct task_struct *p)
1714#endif 1724#endif
1715#ifdef CONFIG_PREEMPT_COUNT 1725#ifdef CONFIG_PREEMPT_COUNT
1716 /* Want to start with kernel preemption disabled. */ 1726 /* Want to start with kernel preemption disabled. */
1717 task_thread_info(p)->preempt_count = 1; 1727 task_thread_info(p)->preempt_count = PREEMPT_DISABLED;
1718#endif 1728#endif
1719#ifdef CONFIG_SMP 1729#ifdef CONFIG_SMP
1720 plist_node_init(&p->pushable_tasks, MAX_PRIO); 1730 plist_node_init(&p->pushable_tasks, MAX_PRIO);
@@ -2425,6 +2435,7 @@ need_resched:
2425 put_prev_task(rq, prev); 2435 put_prev_task(rq, prev);
2426 next = pick_next_task(rq); 2436 next = pick_next_task(rq);
2427 clear_tsk_need_resched(prev); 2437 clear_tsk_need_resched(prev);
2438 clear_preempt_need_resched();
2428 rq->skip_clock_update = 0; 2439 rq->skip_clock_update = 0;
2429 2440
2430 if (likely(prev != next)) { 2441 if (likely(prev != next)) {
@@ -2536,11 +2547,10 @@ EXPORT_SYMBOL(preempt_schedule);
2536 */ 2547 */
2537asmlinkage void __sched preempt_schedule_irq(void) 2548asmlinkage void __sched preempt_schedule_irq(void)
2538{ 2549{
2539 struct thread_info *ti = current_thread_info();
2540 enum ctx_state prev_state; 2550 enum ctx_state prev_state;
2541 2551
2542 /* Catch callers which need to be fixed */ 2552 /* Catch callers which need to be fixed */
2543 BUG_ON(ti->preempt_count || !irqs_disabled()); 2553 BUG_ON(preempt_count() || !irqs_disabled());
2544 2554
2545 prev_state = exception_enter(); 2555 prev_state = exception_enter();
2546 2556
@@ -4207,7 +4217,7 @@ void init_idle(struct task_struct *idle, int cpu)
4207 raw_spin_unlock_irqrestore(&rq->lock, flags); 4217 raw_spin_unlock_irqrestore(&rq->lock, flags);
4208 4218
4209 /* Set the preempt count _outside_ the spinlocks! */ 4219 /* Set the preempt count _outside_ the spinlocks! */
4210 task_thread_info(idle)->preempt_count = 0; 4220 task_thread_info(idle)->preempt_count = PREEMPT_ENABLED;
4211 4221
4212 /* 4222 /*
4213 * The idle tasks have their own, simple scheduling class: 4223 * The idle tasks have their own, simple scheduling class: