diff options
| -rw-r--r-- | include/linux/sched.h | 34 | ||||
| -rw-r--r-- | kernel/sched.c | 39 | ||||
| -rw-r--r-- | kernel/sched_fair.c | 52 |
3 files changed, 82 insertions, 43 deletions
diff --git a/include/linux/sched.h b/include/linux/sched.h index 340f5ee57334..aaf71e08222c 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h | |||
| @@ -786,17 +786,39 @@ enum cpu_idle_type { | |||
| 786 | }; | 786 | }; |
| 787 | 787 | ||
| 788 | /* | 788 | /* |
| 789 | * sched-domains (multiprocessor balancing) declarations: | 789 | * Increase resolution of nice-level calculations for 64-bit architectures. |
| 790 | * The extra resolution improves shares distribution and load balancing of | ||
| 791 | * low-weight task groups (eg. nice +19 on an autogroup), deeper taskgroup | ||
| 792 | * hierarchies, especially on larger systems. This is not a user-visible change | ||
| 793 | * and does not change the user-interface for setting shares/weights. | ||
| 794 | * | ||
| 795 | * We increase resolution only if we have enough bits to allow this increased | ||
| 796 | * resolution (i.e. BITS_PER_LONG > 32). The costs for increasing resolution | ||
| 797 | * when BITS_PER_LONG <= 32 are pretty high and the returns do not justify the | ||
| 798 | * increased costs. | ||
| 790 | */ | 799 | */ |
| 800 | #if BITS_PER_LONG > 32 | ||
| 801 | # define SCHED_LOAD_RESOLUTION 10 | ||
| 802 | # define scale_load(w) ((w) << SCHED_LOAD_RESOLUTION) | ||
| 803 | # define scale_load_down(w) ((w) >> SCHED_LOAD_RESOLUTION) | ||
| 804 | #else | ||
| 805 | # define SCHED_LOAD_RESOLUTION 0 | ||
| 806 | # define scale_load(w) (w) | ||
| 807 | # define scale_load_down(w) (w) | ||
| 808 | #endif | ||
| 791 | 809 | ||
| 792 | /* | 810 | #define SCHED_LOAD_SHIFT (10 + SCHED_LOAD_RESOLUTION) |
| 793 | * Increase resolution of nice-level calculations: | ||
| 794 | */ | ||
| 795 | #define SCHED_LOAD_SHIFT 10 | ||
| 796 | #define SCHED_LOAD_SCALE (1L << SCHED_LOAD_SHIFT) | 811 | #define SCHED_LOAD_SCALE (1L << SCHED_LOAD_SHIFT) |
| 797 | 812 | ||
| 798 | #define SCHED_LOAD_SCALE_FUZZ SCHED_LOAD_SCALE | 813 | /* |
| 814 | * Increase resolution of cpu_power calculations | ||
| 815 | */ | ||
| 816 | #define SCHED_POWER_SHIFT 10 | ||
| 817 | #define SCHED_POWER_SCALE (1L << SCHED_POWER_SHIFT) | ||
| 799 | 818 | ||
| 819 | /* | ||
| 820 | * sched-domains (multiprocessor balancing) declarations: | ||
| 821 | */ | ||
| 800 | #ifdef CONFIG_SMP | 822 | #ifdef CONFIG_SMP |
| 801 | #define SD_LOAD_BALANCE 0x0001 /* Do load balancing on this domain. */ | 823 | #define SD_LOAD_BALANCE 0x0001 /* Do load balancing on this domain. */ |
| 802 | #define SD_BALANCE_NEWIDLE 0x0002 /* Balance when about to become idle */ | 824 | #define SD_BALANCE_NEWIDLE 0x0002 /* Balance when about to become idle */ |
diff --git a/kernel/sched.c b/kernel/sched.c index 0516af415085..2d12893b8b0f 100644 --- a/kernel/sched.c +++ b/kernel/sched.c | |||
| @@ -293,7 +293,7 @@ static DEFINE_SPINLOCK(task_group_lock); | |||
| 293 | * limitation from this.) | 293 | * limitation from this.) |
| 294 | */ | 294 | */ |
| 295 | #define MIN_SHARES 2 | 295 | #define MIN_SHARES 2 |
| 296 | #define MAX_SHARES (1UL << 18) | 296 | #define MAX_SHARES (1UL << (18 + SCHED_LOAD_RESOLUTION)) |
| 297 | 297 | ||
| 298 | static int root_task_group_load = ROOT_TASK_GROUP_LOAD; | 298 | static int root_task_group_load = ROOT_TASK_GROUP_LOAD; |
| 299 | #endif | 299 | #endif |
| @@ -1330,13 +1330,25 @@ calc_delta_mine(unsigned long delta_exec, unsigned long weight, | |||
| 1330 | { | 1330 | { |
| 1331 | u64 tmp; | 1331 | u64 tmp; |
| 1332 | 1332 | ||
| 1333 | tmp = (u64)delta_exec * weight; | 1333 | /* |
| 1334 | * weight can be less than 2^SCHED_LOAD_RESOLUTION for task group sched | ||
| 1335 | * entities since MIN_SHARES = 2. Treat weight as 1 if less than | ||
| 1336 | * 2^SCHED_LOAD_RESOLUTION. | ||
| 1337 | */ | ||
| 1338 | if (likely(weight > (1UL << SCHED_LOAD_RESOLUTION))) | ||
| 1339 | tmp = (u64)delta_exec * scale_load_down(weight); | ||
| 1340 | else | ||
| 1341 | tmp = (u64)delta_exec; | ||
| 1334 | 1342 | ||
| 1335 | if (!lw->inv_weight) { | 1343 | if (!lw->inv_weight) { |
| 1336 | if (BITS_PER_LONG > 32 && unlikely(lw->weight >= WMULT_CONST)) | 1344 | unsigned long w = scale_load_down(lw->weight); |
| 1345 | |||
| 1346 | if (BITS_PER_LONG > 32 && unlikely(w >= WMULT_CONST)) | ||
| 1337 | lw->inv_weight = 1; | 1347 | lw->inv_weight = 1; |
| 1348 | else if (unlikely(!w)) | ||
| 1349 | lw->inv_weight = WMULT_CONST; | ||
| 1338 | else | 1350 | else |
| 1339 | lw->inv_weight = WMULT_CONST / lw->weight; | 1351 | lw->inv_weight = WMULT_CONST / w; |
| 1340 | } | 1352 | } |
| 1341 | 1353 | ||
| 1342 | /* | 1354 | /* |
| @@ -1778,17 +1790,20 @@ static void dec_nr_running(struct rq *rq) | |||
| 1778 | 1790 | ||
| 1779 | static void set_load_weight(struct task_struct *p) | 1791 | static void set_load_weight(struct task_struct *p) |
| 1780 | { | 1792 | { |
| 1793 | int prio = p->static_prio - MAX_RT_PRIO; | ||
| 1794 | struct load_weight *load = &p->se.load; | ||
| 1795 | |||
| 1781 | /* | 1796 | /* |
| 1782 | * SCHED_IDLE tasks get minimal weight: | 1797 | * SCHED_IDLE tasks get minimal weight: |
| 1783 | */ | 1798 | */ |
| 1784 | if (p->policy == SCHED_IDLE) { | 1799 | if (p->policy == SCHED_IDLE) { |
| 1785 | p->se.load.weight = WEIGHT_IDLEPRIO; | 1800 | load->weight = scale_load(WEIGHT_IDLEPRIO); |
| 1786 | p->se.load.inv_weight = WMULT_IDLEPRIO; | 1801 | load->inv_weight = WMULT_IDLEPRIO; |
| 1787 | return; | 1802 | return; |
| 1788 | } | 1803 | } |
| 1789 | 1804 | ||
| 1790 | p->se.load.weight = prio_to_weight[p->static_prio - MAX_RT_PRIO]; | 1805 | load->weight = scale_load(prio_to_weight[prio]); |
| 1791 | p->se.load.inv_weight = prio_to_wmult[p->static_prio - MAX_RT_PRIO]; | 1806 | load->inv_weight = prio_to_wmult[prio]; |
| 1792 | } | 1807 | } |
| 1793 | 1808 | ||
| 1794 | static void enqueue_task(struct rq *rq, struct task_struct *p, int flags) | 1809 | static void enqueue_task(struct rq *rq, struct task_struct *p, int flags) |
| @@ -6527,7 +6542,7 @@ static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level, | |||
| 6527 | cpulist_scnprintf(str, sizeof(str), sched_group_cpus(group)); | 6542 | cpulist_scnprintf(str, sizeof(str), sched_group_cpus(group)); |
| 6528 | 6543 | ||
| 6529 | printk(KERN_CONT " %s", str); | 6544 | printk(KERN_CONT " %s", str); |
| 6530 | if (group->cpu_power != SCHED_LOAD_SCALE) { | 6545 | if (group->cpu_power != SCHED_POWER_SCALE) { |
| 6531 | printk(KERN_CONT " (cpu_power = %d)", | 6546 | printk(KERN_CONT " (cpu_power = %d)", |
| 6532 | group->cpu_power); | 6547 | group->cpu_power); |
| 6533 | } | 6548 | } |
| @@ -7902,7 +7917,7 @@ void __init sched_init(void) | |||
| 7902 | #ifdef CONFIG_SMP | 7917 | #ifdef CONFIG_SMP |
| 7903 | rq->sd = NULL; | 7918 | rq->sd = NULL; |
| 7904 | rq->rd = NULL; | 7919 | rq->rd = NULL; |
| 7905 | rq->cpu_power = SCHED_LOAD_SCALE; | 7920 | rq->cpu_power = SCHED_POWER_SCALE; |
| 7906 | rq->post_schedule = 0; | 7921 | rq->post_schedule = 0; |
| 7907 | rq->active_balance = 0; | 7922 | rq->active_balance = 0; |
| 7908 | rq->next_balance = jiffies; | 7923 | rq->next_balance = jiffies; |
| @@ -8806,14 +8821,14 @@ cpu_cgroup_exit(struct cgroup_subsys *ss, struct cgroup *cgrp, | |||
| 8806 | static int cpu_shares_write_u64(struct cgroup *cgrp, struct cftype *cftype, | 8821 | static int cpu_shares_write_u64(struct cgroup *cgrp, struct cftype *cftype, |
| 8807 | u64 shareval) | 8822 | u64 shareval) |
| 8808 | { | 8823 | { |
| 8809 | return sched_group_set_shares(cgroup_tg(cgrp), shareval); | 8824 | return sched_group_set_shares(cgroup_tg(cgrp), scale_load(shareval)); |
| 8810 | } | 8825 | } |
| 8811 | 8826 | ||
| 8812 | static u64 cpu_shares_read_u64(struct cgroup *cgrp, struct cftype *cft) | 8827 | static u64 cpu_shares_read_u64(struct cgroup *cgrp, struct cftype *cft) |
| 8813 | { | 8828 | { |
| 8814 | struct task_group *tg = cgroup_tg(cgrp); | 8829 | struct task_group *tg = cgroup_tg(cgrp); |
| 8815 | 8830 | ||
| 8816 | return (u64) tg->shares; | 8831 | return (u64) scale_load_down(tg->shares); |
| 8817 | } | 8832 | } |
| 8818 | #endif /* CONFIG_FAIR_GROUP_SCHED */ | 8833 | #endif /* CONFIG_FAIR_GROUP_SCHED */ |
| 8819 | 8834 | ||
diff --git a/kernel/sched_fair.c b/kernel/sched_fair.c index 37f22626225e..e32a9b70ee9c 100644 --- a/kernel/sched_fair.c +++ b/kernel/sched_fair.c | |||
| @@ -1584,7 +1584,7 @@ find_idlest_group(struct sched_domain *sd, struct task_struct *p, | |||
| 1584 | } | 1584 | } |
| 1585 | 1585 | ||
| 1586 | /* Adjust by relative CPU power of the group */ | 1586 | /* Adjust by relative CPU power of the group */ |
| 1587 | avg_load = (avg_load * SCHED_LOAD_SCALE) / group->cpu_power; | 1587 | avg_load = (avg_load * SCHED_POWER_SCALE) / group->cpu_power; |
| 1588 | 1588 | ||
| 1589 | if (local_group) { | 1589 | if (local_group) { |
| 1590 | this_load = avg_load; | 1590 | this_load = avg_load; |
| @@ -1722,7 +1722,7 @@ select_task_rq_fair(struct task_struct *p, int sd_flag, int wake_flags) | |||
| 1722 | nr_running += cpu_rq(i)->cfs.nr_running; | 1722 | nr_running += cpu_rq(i)->cfs.nr_running; |
| 1723 | } | 1723 | } |
| 1724 | 1724 | ||
| 1725 | capacity = DIV_ROUND_CLOSEST(power, SCHED_LOAD_SCALE); | 1725 | capacity = DIV_ROUND_CLOSEST(power, SCHED_POWER_SCALE); |
| 1726 | 1726 | ||
| 1727 | if (tmp->flags & SD_POWERSAVINGS_BALANCE) | 1727 | if (tmp->flags & SD_POWERSAVINGS_BALANCE) |
| 1728 | nr_running /= 2; | 1728 | nr_running /= 2; |
| @@ -2570,7 +2570,7 @@ static inline int check_power_save_busiest_group(struct sd_lb_stats *sds, | |||
| 2570 | 2570 | ||
| 2571 | unsigned long default_scale_freq_power(struct sched_domain *sd, int cpu) | 2571 | unsigned long default_scale_freq_power(struct sched_domain *sd, int cpu) |
