aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/sched.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/sched.c')
-rw-r--r--kernel/sched.c59
1 files changed, 44 insertions, 15 deletions
diff --git a/kernel/sched.c b/kernel/sched.c
index 3f6bd1112900..b18f231a4875 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -75,7 +75,7 @@
75 */ 75 */
76unsigned long long __attribute__((weak)) sched_clock(void) 76unsigned long long __attribute__((weak)) sched_clock(void)
77{ 77{
78 return (unsigned long long)jiffies * (1000000000 / HZ); 78 return (unsigned long long)jiffies * (NSEC_PER_SEC / HZ);
79} 79}
80 80
81/* 81/*
@@ -99,8 +99,8 @@ unsigned long long __attribute__((weak)) sched_clock(void)
99/* 99/*
100 * Some helpers for converting nanosecond timing to jiffy resolution 100 * Some helpers for converting nanosecond timing to jiffy resolution
101 */ 101 */
102#define NS_TO_JIFFIES(TIME) ((unsigned long)(TIME) / (1000000000 / HZ)) 102#define NS_TO_JIFFIES(TIME) ((unsigned long)(TIME) / (NSEC_PER_SEC / HZ))
103#define JIFFIES_TO_NS(TIME) ((TIME) * (1000000000 / HZ)) 103#define JIFFIES_TO_NS(TIME) ((TIME) * (NSEC_PER_SEC / HZ))
104 104
105#define NICE_0_LOAD SCHED_LOAD_SCALE 105#define NICE_0_LOAD SCHED_LOAD_SCALE
106#define NICE_0_SHIFT SCHED_LOAD_SHIFT 106#define NICE_0_SHIFT SCHED_LOAD_SHIFT
@@ -460,7 +460,6 @@ enum {
460 SCHED_FEAT_TREE_AVG = 4, 460 SCHED_FEAT_TREE_AVG = 4,
461 SCHED_FEAT_APPROX_AVG = 8, 461 SCHED_FEAT_APPROX_AVG = 8,
462 SCHED_FEAT_WAKEUP_PREEMPT = 16, 462 SCHED_FEAT_WAKEUP_PREEMPT = 16,
463 SCHED_FEAT_PREEMPT_RESTRICT = 32,
464}; 463};
465 464
466const_debug unsigned int sysctl_sched_features = 465const_debug unsigned int sysctl_sched_features =
@@ -468,12 +467,17 @@ const_debug unsigned int sysctl_sched_features =
468 SCHED_FEAT_START_DEBIT * 1 | 467 SCHED_FEAT_START_DEBIT * 1 |
469 SCHED_FEAT_TREE_AVG * 0 | 468 SCHED_FEAT_TREE_AVG * 0 |
470 SCHED_FEAT_APPROX_AVG * 0 | 469 SCHED_FEAT_APPROX_AVG * 0 |
471 SCHED_FEAT_WAKEUP_PREEMPT * 1 | 470 SCHED_FEAT_WAKEUP_PREEMPT * 1;
472 SCHED_FEAT_PREEMPT_RESTRICT * 1;
473 471
474#define sched_feat(x) (sysctl_sched_features & SCHED_FEAT_##x) 472#define sched_feat(x) (sysctl_sched_features & SCHED_FEAT_##x)
475 473
476/* 474/*
475 * Number of tasks to iterate in a single balance run.
476 * Limited because this is done with IRQs disabled.
477 */
478const_debug unsigned int sysctl_sched_nr_migrate = 32;
479
480/*
477 * For kernel-internal use: high-speed (but slightly incorrect) per-cpu 481 * For kernel-internal use: high-speed (but slightly incorrect) per-cpu
478 * clock constructed from sched_clock(): 482 * clock constructed from sched_clock():
479 */ 483 */
@@ -2237,7 +2241,7 @@ balance_tasks(struct rq *this_rq, int this_cpu, struct rq *busiest,
2237 enum cpu_idle_type idle, int *all_pinned, 2241 enum cpu_idle_type idle, int *all_pinned,
2238 int *this_best_prio, struct rq_iterator *iterator) 2242 int *this_best_prio, struct rq_iterator *iterator)
2239{ 2243{
2240 int pulled = 0, pinned = 0, skip_for_load; 2244 int loops = 0, pulled = 0, pinned = 0, skip_for_load;
2241 struct task_struct *p; 2245 struct task_struct *p;
2242 long rem_load_move = max_load_move; 2246 long rem_load_move = max_load_move;
2243 2247
@@ -2251,10 +2255,10 @@ balance_tasks(struct rq *this_rq, int this_cpu, struct rq *busiest,
2251 */ 2255 */
2252 p = iterator->start(iterator->arg); 2256 p = iterator->start(iterator->arg);
2253next: 2257next:
2254 if (!p) 2258 if (!p || loops++ > sysctl_sched_nr_migrate)
2255 goto out; 2259 goto out;
2256 /* 2260 /*
2257 * To help distribute high priority tasks accross CPUs we don't 2261 * To help distribute high priority tasks across CPUs we don't
2258 * skip a task if it will be the highest priority task (i.e. smallest 2262 * skip a task if it will be the highest priority task (i.e. smallest
2259 * prio value) on its new queue regardless of its load weight 2263 * prio value) on its new queue regardless of its load weight
2260 */ 2264 */
@@ -2271,8 +2275,7 @@ next:
2271 rem_load_move -= p->se.load.weight; 2275 rem_load_move -= p->se.load.weight;
2272 2276
2273 /* 2277 /*
2274 * We only want to steal up to the prescribed number of tasks 2278 * We only want to steal up to the prescribed amount of weighted load.
2275 * and the prescribed amount of weighted load.
2276 */ 2279 */
2277 if (rem_load_move > 0) { 2280 if (rem_load_move > 0) {
2278 if (p->prio < *this_best_prio) 2281 if (p->prio < *this_best_prio)
@@ -4992,6 +4995,32 @@ void __cpuinit init_idle(struct task_struct *idle, int cpu)
4992 */ 4995 */
4993cpumask_t nohz_cpu_mask = CPU_MASK_NONE; 4996cpumask_t nohz_cpu_mask = CPU_MASK_NONE;
4994 4997
4998/*
4999 * Increase the granularity value when there are more CPUs,
5000 * because with more CPUs the 'effective latency' as visible
5001 * to users decreases. But the relationship is not linear,
5002 * so pick a second-best guess by going with the log2 of the
5003 * number of CPUs.
5004 *
5005 * This idea comes from the SD scheduler of Con Kolivas:
5006 */
5007static inline void sched_init_granularity(void)
5008{
5009 unsigned int factor = 1 + ilog2(num_online_cpus());
5010 const unsigned long limit = 200000000;
5011
5012 sysctl_sched_min_granularity *= factor;
5013 if (sysctl_sched_min_granularity > limit)
5014 sysctl_sched_min_granularity = limit;
5015
5016 sysctl_sched_latency *= factor;
5017 if (sysctl_sched_latency > limit)
5018 sysctl_sched_latency = limit;
5019
5020 sysctl_sched_wakeup_granularity *= factor;
5021 sysctl_sched_batch_wakeup_granularity *= factor;
5022}
5023
4995#ifdef CONFIG_SMP 5024#ifdef CONFIG_SMP
4996/* 5025/*
4997 * This is how migration works: 5026 * This is how migration works:
@@ -5621,7 +5650,7 @@ static struct notifier_block __cpuinitdata migration_notifier = {
5621 .priority = 10 5650 .priority = 10
5622}; 5651};
5623 5652
5624int __init migration_init(void) 5653void __init migration_init(void)
5625{ 5654{
5626 void *cpu = (void *)(long)smp_processor_id(); 5655 void *cpu = (void *)(long)smp_processor_id();
5627 int err; 5656 int err;
@@ -5631,8 +5660,6 @@ int __init migration_init(void)
5631 BUG_ON(err == NOTIFY_BAD); 5660 BUG_ON(err == NOTIFY_BAD);
5632 migration_call(&migration_notifier, CPU_ONLINE, cpu); 5661 migration_call(&migration_notifier, CPU_ONLINE, cpu);
5633 register_cpu_notifier(&migration_notifier); 5662 register_cpu_notifier(&migration_notifier);
5634
5635 return 0;
5636} 5663}
5637#endif 5664#endif
5638 5665
@@ -6688,10 +6715,12 @@ void __init sched_init_smp(void)
6688 /* Move init over to a non-isolated CPU */ 6715 /* Move init over to a non-isolated CPU */
6689 if (set_cpus_allowed(current, non_isolated_cpus) < 0) 6716 if (set_cpus_allowed(current, non_isolated_cpus) < 0)
6690 BUG(); 6717 BUG();
6718 sched_init_granularity();
6691} 6719}
6692#else 6720#else
6693void __init sched_init_smp(void) 6721void __init sched_init_smp(void)
6694{ 6722{
6723 sched_init_granularity();
6695} 6724}
6696#endif /* CONFIG_SMP */ 6725#endif /* CONFIG_SMP */
6697 6726
@@ -7228,7 +7257,7 @@ static u64 cpu_usage_read(struct cgroup *cgrp, struct cftype *cft)
7228 spin_unlock_irqrestore(&cpu_rq(i)->lock, flags); 7257 spin_unlock_irqrestore(&cpu_rq(i)->lock, flags);
7229 } 7258 }
7230 /* Convert from ns to ms */ 7259 /* Convert from ns to ms */
7231 do_div(res, 1000000); 7260 do_div(res, NSEC_PER_MSEC);
7232 7261
7233 return res; 7262 return res;
7234} 7263}