aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorPeter Zijlstra <a.p.zijlstra@chello.nl>2008-09-20 17:38:02 -0400
committerIngo Molnar <mingo@elte.hu>2008-09-22 10:28:32 -0400
commit15afe09bf496ae10c989e1a375a6b5da7bd3e16e (patch)
tree4565659d1084e357eea42e6321a4d304ac950faa /kernel
parent09b22a2f678ae733801b888c44756d0abd686b8a (diff)
sched: wakeup preempt when small overlap
Lin Ming reported a 10% OLTP regression against 2.6.27-rc4. The difference seems to come from different preemption agressiveness, which affects the cache footprint of the workload and its effective cache trashing. Aggresively preempt a task if its avg overlap is very small, this should avoid the task going to sleep and find it still running when we schedule back to it - saving a wakeup. Reported-by: Lin Ming <ming.m.lin@intel.com> Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/sched.c12
-rw-r--r--kernel/sched_fair.c13
-rw-r--r--kernel/sched_features.h1
-rw-r--r--kernel/sched_idletask.c6
-rw-r--r--kernel/sched_rt.c2
5 files changed, 21 insertions, 13 deletions
diff --git a/kernel/sched.c b/kernel/sched.c
index 0d8905a1b8ca..ad9d39b021f8 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -604,9 +604,9 @@ struct rq {
604 604
605static DEFINE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues); 605static DEFINE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues);
606 606
607static inline void check_preempt_curr(struct rq *rq, struct task_struct *p) 607static inline void check_preempt_curr(struct rq *rq, struct task_struct *p, int sync)
608{ 608{
609 rq->curr->sched_class->check_preempt_curr(rq, p); 609 rq->curr->sched_class->check_preempt_curr(rq, p, sync);
610} 610}
611 611
612static inline int cpu_of(struct rq *rq) 612static inline int cpu_of(struct rq *rq)
@@ -2282,7 +2282,7 @@ out_running:
2282 trace_mark(kernel_sched_wakeup, 2282 trace_mark(kernel_sched_wakeup,
2283 "pid %d state %ld ## rq %p task %p rq->curr %p", 2283 "pid %d state %ld ## rq %p task %p rq->curr %p",
2284 p->pid, p->state, rq, p, rq->curr); 2284 p->pid, p->state, rq, p, rq->curr);
2285 check_preempt_curr(rq, p); 2285 check_preempt_curr(rq, p, sync);
2286 2286
2287 p->state = TASK_RUNNING; 2287 p->state = TASK_RUNNING;
2288#ifdef CONFIG_SMP 2288#ifdef CONFIG_SMP
@@ -2417,7 +2417,7 @@ void wake_up_new_task(struct task_struct *p, unsigned long clone_flags)
2417 trace_mark(kernel_sched_wakeup_new, 2417 trace_mark(kernel_sched_wakeup_new,
2418 "pid %d state %ld ## rq %p task %p rq->curr %p", 2418 "pid %d state %ld ## rq %p task %p rq->curr %p",
2419 p->pid, p->state, rq, p, rq->curr); 2419 p->pid, p->state, rq, p, rq->curr);
2420 check_preempt_curr(rq, p); 2420 check_preempt_curr(rq, p, 0);
2421#ifdef CONFIG_SMP 2421#ifdef CONFIG_SMP
2422 if (p->sched_class->task_wake_up) 2422 if (p->sched_class->task_wake_up)
2423 p->sched_class->task_wake_up(rq, p); 2423 p->sched_class->task_wake_up(rq, p);
@@ -2877,7 +2877,7 @@ static void pull_task(struct rq *src_rq, struct task_struct *p,
2877 * Note that idle threads have a prio of MAX_PRIO, for this test 2877 * Note that idle threads have a prio of MAX_PRIO, for this test
2878 * to be always true for them. 2878 * to be always true for them.
2879 */ 2879 */
2880 check_preempt_curr(this_rq, p); 2880 check_preempt_curr(this_rq, p, 0);
2881} 2881}
2882 2882
2883/* 2883/*
@@ -6007,7 +6007,7 @@ static int __migrate_task(struct task_struct *p, int src_cpu, int dest_cpu)
6007 set_task_cpu(p, dest_cpu); 6007 set_task_cpu(p, dest_cpu);
6008 if (on_rq) { 6008 if (on_rq) {
6009 activate_task(rq_dest, p, 0); 6009 activate_task(rq_dest, p, 0);
6010 check_preempt_curr(rq_dest, p); 6010 check_preempt_curr(rq_dest, p, 0);
6011 } 6011 }
6012done: 6012done:
6013 ret = 1; 6013 ret = 1;
diff --git a/kernel/sched_fair.c b/kernel/sched_fair.c
index a10ac0bcee64..7328383690f1 100644
--- a/kernel/sched_fair.c
+++ b/kernel/sched_fair.c
@@ -1331,7 +1331,7 @@ static inline int depth_se(struct sched_entity *se)
1331/* 1331/*
1332 * Preempt the current task with a newly woken task if needed: 1332 * Preempt the current task with a newly woken task if needed:
1333 */ 1333 */
1334static void check_preempt_wakeup(struct rq *rq, struct task_struct *p) 1334static void check_preempt_wakeup(struct rq *rq, struct task_struct *p, int sync)
1335{ 1335{
1336 struct task_struct *curr = rq->curr; 1336 struct task_struct *curr = rq->curr;
1337 struct cfs_rq *cfs_rq = task_cfs_rq(curr); 1337 struct cfs_rq *cfs_rq = task_cfs_rq(curr);
@@ -1367,6 +1367,13 @@ static void check_preempt_wakeup(struct rq *rq, struct task_struct *p)
1367 if (!sched_feat(WAKEUP_PREEMPT)) 1367 if (!sched_feat(WAKEUP_PREEMPT))
1368 return; 1368 return;
1369 1369
1370 if (sched_feat(WAKEUP_OVERLAP) && sync &&
1371 se->avg_overlap < sysctl_sched_migration_cost &&
1372 pse->avg_overlap < sysctl_sched_migration_cost) {
1373 resched_task(curr);
1374 return;
1375 }
1376
1370 /* 1377 /*
1371 * preemption test can be made between sibling entities who are in the 1378 * preemption test can be made between sibling entities who are in the
1372 * same cfs_rq i.e who have a common parent. Walk up the hierarchy of 1379 * same cfs_rq i.e who have a common parent. Walk up the hierarchy of
@@ -1649,7 +1656,7 @@ static void prio_changed_fair(struct rq *rq, struct task_struct *p,
1649 if (p->prio > oldprio) 1656 if (p->prio > oldprio)
1650 resched_task(rq->curr); 1657 resched_task(rq->curr);
1651 } else 1658 } else
1652 check_preempt_curr(rq, p); 1659 check_preempt_curr(rq, p, 0);
1653} 1660}
1654 1661
1655/* 1662/*
@@ -1666,7 +1673,7 @@ static void switched_to_fair(struct rq *rq, struct task_struct *p,
1666 if (running) 1673 if (running)
1667 resched_task(rq->curr); 1674 resched_task(rq->curr);
1668 else 1675 else
1669 check_preempt_curr(rq, p); 1676 check_preempt_curr(rq, p, 0);
1670} 1677}
1671 1678
1672/* Account for a task changing its policy or group. 1679/* Account for a task changing its policy or group.
diff --git a/kernel/sched_features.h b/kernel/sched_features.h
index 9353ca78154e..bf027a7accf8 100644
--- a/kernel/sched_features.h
+++ b/kernel/sched_features.h
@@ -11,3 +11,4 @@ SCHED_FEAT(ASYM_GRAN, 1)
11SCHED_FEAT(LB_BIAS, 1) 11SCHED_FEAT(LB_BIAS, 1)
12SCHED_FEAT(LB_WAKEUP_UPDATE, 1) 12SCHED_FEAT(LB_WAKEUP_UPDATE, 1)
13SCHED_FEAT(ASYM_EFF_LOAD, 1) 13SCHED_FEAT(ASYM_EFF_LOAD, 1)
14SCHED_FEAT(WAKEUP_OVERLAP, 1)
diff --git a/kernel/sched_idletask.c b/kernel/sched_idletask.c
index 3a4f92dbbe66..dec4ccabe2f5 100644
--- a/kernel/sched_idletask.c
+++ b/kernel/sched_idletask.c
@@ -14,7 +14,7 @@ static int select_task_rq_idle(struct task_struct *p, int sync)
14/* 14/*
15 * Idle tasks are unconditionally rescheduled: 15 * Idle tasks are unconditionally rescheduled:
16 */ 16 */
17static void check_preempt_curr_idle(struct rq *rq, struct task_struct *p) 17static void check_preempt_curr_idle(struct rq *rq, struct task_struct *p, int sync)
18{ 18{
19 resched_task(rq->idle); 19 resched_task(rq->idle);
20} 20}
@@ -76,7 +76,7 @@ static void switched_to_idle(struct rq *rq, struct task_struct *p,
76 if (running) 76 if (running)
77 resched_task(rq->curr); 77 resched_task(rq->curr);
78 else 78 else
79 check_preempt_curr(rq, p); 79 check_preempt_curr(rq, p, 0);
80} 80}
81 81
82static void prio_changed_idle(struct rq *rq, struct task_struct *p, 82static void prio_changed_idle(struct rq *rq, struct task_struct *p,
@@ -93,7 +93,7 @@ static void prio_changed_idle(struct rq *rq, struct task_struct *p,
93 if (p->prio > oldprio) 93 if (p->prio > oldprio)
94 resched_task(rq->curr); 94 resched_task(rq->curr);
95 } else 95 } else
96 check_preempt_curr(rq, p); 96 check_preempt_curr(rq, p, 0);
97} 97}
98 98
99/* 99/*
diff --git a/kernel/sched_rt.c b/kernel/sched_rt.c
index 552310798dad..6d2d0a5d030b 100644
--- a/kernel/sched_rt.c
+++ b/kernel/sched_rt.c
@@ -783,7 +783,7 @@ static void check_preempt_equal_prio(struct rq *rq, struct task_struct *p)
783/* 783/*
784 * Preempt the current task with a newly woken task if needed: 784 * Preempt the current task with a newly woken task if needed:
785 */ 785 */
786static void check_preempt_curr_rt(struct rq *rq, struct task_struct *p) 786static void check_preempt_curr_rt(struct rq *rq, struct task_struct *p, int sync)
787{ 787{
788 if (p->prio < rq->curr->prio) { 788 if (p->prio < rq->curr->prio) {
789 resched_task(rq->curr); 789 resched_task(rq->curr);