diff options
author | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-08-25 14:25:29 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-08-25 14:25:29 -0400 |
commit | a3ce8ea66ae9379235334a989ed78a1ea518b0b3 (patch) | |
tree | 88bef2140c00ec607f2d222e953ed380999eb4a6 | |
parent | f2154eef2a926435cdf79156cd361092d6cba91e (diff) | |
parent | 172ac3dbb7d3e528ac53d08a34df88d1ac53c534 (diff) |
Merge git://git.kernel.org/pub/scm/linux/kernel/git/mingo/linux-2.6-sched
* git://git.kernel.org/pub/scm/linux/kernel/git/mingo/linux-2.6-sched:
sched: cleanup, sched_granularity -> sched_min_granularity
sched: adaptive scheduler granularity
sched: fix CONFIG_SCHED_DEBUG dependency of lockdep sysctls
-rw-r--r-- | include/linux/sched.h | 3 | ||||
-rw-r--r-- | kernel/sched.c | 16 | ||||
-rw-r--r-- | kernel/sched_fair.c | 77 | ||||
-rw-r--r-- | kernel/sysctl.c | 33 |
4 files changed, 99 insertions, 30 deletions
diff --git a/include/linux/sched.h b/include/linux/sched.h index ba78807eab91..bd6a0320a770 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h | |||
@@ -1399,7 +1399,8 @@ static inline void idle_task_exit(void) {} | |||
1399 | 1399 | ||
1400 | extern void sched_idle_next(void); | 1400 | extern void sched_idle_next(void); |
1401 | 1401 | ||
1402 | extern unsigned int sysctl_sched_granularity; | 1402 | extern unsigned int sysctl_sched_latency; |
1403 | extern unsigned int sysctl_sched_min_granularity; | ||
1403 | extern unsigned int sysctl_sched_wakeup_granularity; | 1404 | extern unsigned int sysctl_sched_wakeup_granularity; |
1404 | extern unsigned int sysctl_sched_batch_wakeup_granularity; | 1405 | extern unsigned int sysctl_sched_batch_wakeup_granularity; |
1405 | extern unsigned int sysctl_sched_stat_granularity; | 1406 | extern unsigned int sysctl_sched_stat_granularity; |
diff --git a/kernel/sched.c b/kernel/sched.c index 6798328a2e0e..a40ab657ad19 100644 --- a/kernel/sched.c +++ b/kernel/sched.c | |||
@@ -4911,14 +4911,18 @@ cpumask_t nohz_cpu_mask = CPU_MASK_NONE; | |||
4911 | static inline void sched_init_granularity(void) | 4911 | static inline void sched_init_granularity(void) |
4912 | { | 4912 | { |
4913 | unsigned int factor = 1 + ilog2(num_online_cpus()); | 4913 | unsigned int factor = 1 + ilog2(num_online_cpus()); |
4914 | const unsigned long gran_limit = 100000000; | 4914 | const unsigned long limit = 100000000; |
4915 | 4915 | ||
4916 | sysctl_sched_granularity *= factor; | 4916 | sysctl_sched_min_granularity *= factor; |
4917 | if (sysctl_sched_granularity > gran_limit) | 4917 | if (sysctl_sched_min_granularity > limit) |
4918 | sysctl_sched_granularity = gran_limit; | 4918 | sysctl_sched_min_granularity = limit; |
4919 | 4919 | ||
4920 | sysctl_sched_runtime_limit = sysctl_sched_granularity * 5; | 4920 | sysctl_sched_latency *= factor; |
4921 | sysctl_sched_wakeup_granularity = sysctl_sched_granularity / 2; | 4921 | if (sysctl_sched_latency > limit) |
4922 | sysctl_sched_latency = limit; | ||
4923 | |||
4924 | sysctl_sched_runtime_limit = sysctl_sched_latency * 5; | ||
4925 | sysctl_sched_wakeup_granularity = sysctl_sched_latency / 2; | ||
4922 | } | 4926 | } |
4923 | 4927 | ||
4924 | #ifdef CONFIG_SMP | 4928 | #ifdef CONFIG_SMP |
diff --git a/kernel/sched_fair.c b/kernel/sched_fair.c index 4d6b7e2df2aa..ee3771850aaf 100644 --- a/kernel/sched_fair.c +++ b/kernel/sched_fair.c | |||
@@ -15,23 +15,32 @@ | |||
15 | * | 15 | * |
16 | * Scaled math optimizations by Thomas Gleixner | 16 | * Scaled math optimizations by Thomas Gleixner |
17 | * Copyright (C) 2007, Thomas Gleixner <tglx@linutronix.de> | 17 | * Copyright (C) 2007, Thomas Gleixner <tglx@linutronix.de> |
18 | * | ||
19 | * Adaptive scheduling granularity, math enhancements by Peter Zijlstra | ||
20 | * Copyright (C) 2007 Red Hat, Inc., Peter Zijlstra <pzijlstr@redhat.com> | ||
18 | */ | 21 | */ |
19 | 22 | ||
20 | /* | 23 | /* |
21 | * Preemption granularity: | 24 | * Targeted preemption latency for CPU-bound tasks: |
22 | * (default: 10 msec, units: nanoseconds) | 25 | * (default: 20ms, units: nanoseconds) |
23 | * | 26 | * |
24 | * NOTE: this granularity value is not the same as the concept of | 27 | * NOTE: this latency value is not the same as the concept of |
25 | * 'timeslice length' - timeslices in CFS will typically be somewhat | 28 | * 'timeslice length' - timeslices in CFS are of variable length. |
26 | * larger than this value. (to see the precise effective timeslice | 29 | * (to see the precise effective timeslice length of your workload, |
27 | * length of your workload, run vmstat and monitor the context-switches | 30 | * run vmstat and monitor the context-switches field) |
28 | * field) | ||
29 | * | 31 | * |
30 | * On SMP systems the value of this is multiplied by the log2 of the | 32 | * On SMP systems the value of this is multiplied by the log2 of the |
31 | * number of CPUs. (i.e. factor 2x on 2-way systems, 3x on 4-way | 33 | * number of CPUs. (i.e. factor 2x on 2-way systems, 3x on 4-way |
32 | * systems, 4x on 8-way systems, 5x on 16-way systems, etc.) | 34 | * systems, 4x on 8-way systems, 5x on 16-way systems, etc.) |
35 | * Targeted preemption latency for CPU-bound tasks: | ||
33 | */ | 36 | */ |
34 | unsigned int sysctl_sched_granularity __read_mostly = 10000000UL; | 37 | unsigned int sysctl_sched_latency __read_mostly = 20000000ULL; |
38 | |||
39 | /* | ||
40 | * Minimal preemption granularity for CPU-bound tasks: | ||
41 | * (default: 2 msec, units: nanoseconds) | ||
42 | */ | ||
43 | unsigned int sysctl_sched_min_granularity __read_mostly = 2000000ULL; | ||
35 | 44 | ||
36 | /* | 45 | /* |
37 | * SCHED_BATCH wake-up granularity. | 46 | * SCHED_BATCH wake-up granularity. |
@@ -213,6 +222,49 @@ static struct sched_entity *__pick_next_entity(struct cfs_rq *cfs_rq) | |||
213 | */ | 222 | */ |
214 | 223 | ||
215 | /* | 224 | /* |
225 | * Calculate the preemption granularity needed to schedule every | ||
226 | * runnable task once per sysctl_sched_latency amount of time. | ||
227 | * (down to a sensible low limit on granularity) | ||
228 | * | ||
229 | * For example, if there are 2 tasks running and latency is 10 msecs, | ||
230 | * we switch tasks every 5 msecs. If we have 3 tasks running, we have | ||
231 | * to switch tasks every 3.33 msecs to get a 10 msecs observed latency | ||
232 | * for each task. We do finer and finer scheduling up to until we | ||
233 | * reach the minimum granularity value. | ||
234 | * | ||
235 | * To achieve this we use the following dynamic-granularity rule: | ||
236 | * | ||
237 | * gran = lat/nr - lat/nr/nr | ||
238 | * | ||
239 | * This comes out of the following equations: | ||
240 | * | ||
241 | * kA1 + gran = kB1 | ||
242 | * kB2 + gran = kA2 | ||
243 | * kA2 = kA1 | ||
244 | * kB2 = kB1 - d + d/nr | ||
245 | * lat = d * nr | ||
246 | * | ||
247 | * Where 'k' is key, 'A' is task A (waiting), 'B' is task B (running), | ||
248 | * '1' is start of time, '2' is end of time, 'd' is delay between | ||
249 | * 1 and 2 (during which task B was running), 'nr' is number of tasks | ||
250 | * running, 'lat' is the the period of each task. ('lat' is the | ||
251 | * sched_latency that we aim for.) | ||
252 | */ | ||
253 | static long | ||
254 | sched_granularity(struct cfs_rq *cfs_rq) | ||
255 | { | ||
256 | unsigned int gran = sysctl_sched_latency; | ||
257 | unsigned int nr = cfs_rq->nr_running; | ||
258 | |||
259 | if (nr > 1) { | ||
260 | gran = gran/nr - gran/nr/nr; | ||
261 | gran = max(gran, sysctl_sched_min_granularity); | ||
262 | } | ||
263 | |||
264 | return gran; | ||
265 | } | ||
266 | |||
267 | /* | ||
216 | * We rescale the rescheduling granularity of tasks according to their | 268 | * We rescale the rescheduling granularity of tasks according to their |
217 | * nice level, but only linearly, not exponentially: | 269 | * nice level, but only linearly, not exponentially: |
218 | */ | 270 | */ |
@@ -302,7 +354,7 @@ __update_curr(struct cfs_rq *cfs_rq, struct sched_entity *curr) | |||
302 | delta_fair = calc_delta_fair(delta_exec, lw); | 354 | delta_fair = calc_delta_fair(delta_exec, lw); |
303 | delta_mine = calc_delta_mine(delta_exec, curr->load.weight, lw); | 355 | delta_mine = calc_delta_mine(delta_exec, curr->load.weight, lw); |
304 | 356 | ||
305 | if (cfs_rq->sleeper_bonus > sysctl_sched_granularity) { | 357 | if (cfs_rq->sleeper_bonus > sysctl_sched_latency) { |
306 | delta = min((u64)delta_mine, cfs_rq->sleeper_bonus); | 358 | delta = min((u64)delta_mine, cfs_rq->sleeper_bonus); |
307 | delta = min(delta, (unsigned long)( | 359 | delta = min(delta, (unsigned long)( |
308 | (long)sysctl_sched_runtime_limit - curr->wait_runtime)); | 360 | (long)sysctl_sched_runtime_limit - curr->wait_runtime)); |
@@ -689,7 +741,8 @@ static void entity_tick(struct cfs_rq *cfs_rq, struct sched_entity *curr) | |||
689 | if (next == curr) | 741 | if (next == curr) |
690 | return; | 742 | return; |
691 | 743 | ||
692 | __check_preempt_curr_fair(cfs_rq, next, curr, sysctl_sched_granularity); | 744 | __check_preempt_curr_fair(cfs_rq, next, curr, |
745 | sched_granularity(cfs_rq)); | ||
693 | } | 746 | } |
694 | 747 | ||
695 | /************************************************** | 748 | /************************************************** |
@@ -1034,7 +1087,7 @@ static void task_new_fair(struct rq *rq, struct task_struct *p) | |||
1034 | * it will preempt the parent: | 1087 | * it will preempt the parent: |
1035 | */ | 1088 | */ |
1036 | p->se.fair_key = current->se.fair_key - | 1089 | p->se.fair_key = current->se.fair_key - |
1037 | niced_granularity(&rq->curr->se, sysctl_sched_granularity) - 1; | 1090 | niced_granularity(&rq->curr->se, sched_granularity(cfs_rq)) - 1; |
1038 | /* | 1091 | /* |
1039 | * The first wait is dominated by the child-runs-first logic, | 1092 | * The first wait is dominated by the child-runs-first logic, |
1040 | * so do not credit it with that waiting time yet: | 1093 | * so do not credit it with that waiting time yet: |
@@ -1047,7 +1100,7 @@ static void task_new_fair(struct rq *rq, struct task_struct *p) | |||
1047 | * -granularity/2, so initialize the task with that: | 1100 | * -granularity/2, so initialize the task with that: |
1048 | */ | 1101 | */ |
1049 | if (sysctl_sched_features & SCHED_FEAT_START_DEBIT) | 1102 | if (sysctl_sched_features & SCHED_FEAT_START_DEBIT) |
1050 | p->se.wait_runtime = -((long)sysctl_sched_granularity / 2); | 1103 | p->se.wait_runtime = -(sched_granularity(cfs_rq) / 2); |
1051 | 1104 | ||
1052 | __enqueue_entity(cfs_rq, se); | 1105 | __enqueue_entity(cfs_rq, se); |
1053 | } | 1106 | } |
diff --git a/kernel/sysctl.c b/kernel/sysctl.c index 9029690f4fae..6ace893c17c9 100644 --- a/kernel/sysctl.c +++ b/kernel/sysctl.c | |||
@@ -222,8 +222,19 @@ static ctl_table kern_table[] = { | |||
222 | #ifdef CONFIG_SCHED_DEBUG | 222 | #ifdef CONFIG_SCHED_DEBUG |
223 | { | 223 | { |
224 | .ctl_name = CTL_UNNUMBERED, | 224 | .ctl_name = CTL_UNNUMBERED, |
225 | .procname = "sched_granularity_ns", | 225 | .procname = "sched_min_granularity_ns", |
226 | .data = &sysctl_sched_granularity, | 226 | .data = &sysctl_sched_min_granularity, |
227 | .maxlen = sizeof(unsigned int), | ||
228 | .mode = 0644, | ||
229 | .proc_handler = &proc_dointvec_minmax, | ||
230 | .strategy = &sysctl_intvec, | ||
231 | .extra1 = &min_sched_granularity_ns, | ||
232 | .extra2 = &max_sched_granularity_ns, | ||
233 | }, | ||
234 | { | ||
235 | .ctl_name = CTL_UNNUMBERED, | ||
236 | .procname = "sched_latency_ns", | ||
237 | .data = &sysctl_sched_latency, | ||
227 | .maxlen = sizeof(unsigned int), | 238 | .maxlen = sizeof(unsigned int), |
228 | .mode = 0644, | 239 | .mode = 0644, |
229 | .proc_handler = &proc_dointvec_minmax, | 240 | .proc_handler = &proc_dointvec_minmax, |
@@ -283,6 +294,15 @@ static ctl_table kern_table[] = { | |||
283 | .mode = 0644, | 294 | .mode = 0644, |
284 | .proc_handler = &proc_dointvec, | 295 | .proc_handler = &proc_dointvec, |
285 | }, | 296 | }, |
297 | { | ||
298 | .ctl_name = CTL_UNNUMBERED, | ||
299 | .procname = "sched_features", | ||
300 | .data = &sysctl_sched_features, | ||
301 | .maxlen = sizeof(unsigned int), | ||
302 | .mode = 0644, | ||
303 | .proc_handler = &proc_dointvec, | ||
304 | }, | ||
305 | #endif | ||
286 | #ifdef CONFIG_PROVE_LOCKING | 306 | #ifdef CONFIG_PROVE_LOCKING |
287 | { | 307 | { |
288 | .ctl_name = CTL_UNNUMBERED, | 308 | .ctl_name = CTL_UNNUMBERED, |
@@ -304,15 +324,6 @@ static ctl_table kern_table[] = { | |||
304 | }, | 324 | }, |
305 | #endif | 325 | #endif |
306 | { | 326 | { |
307 | .ctl_name = CTL_UNNUMBERED, | ||
308 | .procname = "sched_features", | ||
309 | .data = &sysctl_sched_features, | ||
310 | .maxlen = sizeof(unsigned int), | ||
311 | .mode = 0644, | ||
312 | .proc_handler = &proc_dointvec, | ||
313 | }, | ||
314 | #endif | ||
315 | { | ||
316 | .ctl_name = KERN_PANIC, | 327 | .ctl_name = KERN_PANIC, |
317 | .procname = "panic", | 328 | .procname = "panic", |
318 | .data = &panic_timeout, | 329 | .data = &panic_timeout, |