aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/sched.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/sched.c')
-rw-r--r--kernel/sched.c1046
1 files changed, 532 insertions, 514 deletions
diff --git a/kernel/sched.c b/kernel/sched.c
index 7729c4bbc8ba..4ed9f588faa6 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -487,14 +487,14 @@ struct rt_rq {
487 */ 487 */
488struct root_domain { 488struct root_domain {
489 atomic_t refcount; 489 atomic_t refcount;
490 cpumask_t span; 490 cpumask_var_t span;
491 cpumask_t online; 491 cpumask_var_t online;
492 492
493 /* 493 /*
494 * The "RT overload" flag: it gets set if a CPU has more than 494 * The "RT overload" flag: it gets set if a CPU has more than
495 * one runnable RT task. 495 * one runnable RT task.
496 */ 496 */
497 cpumask_t rto_mask; 497 cpumask_var_t rto_mask;
498 atomic_t rto_count; 498 atomic_t rto_count;
499#ifdef CONFIG_SMP 499#ifdef CONFIG_SMP
500 struct cpupri cpupri; 500 struct cpupri cpupri;
@@ -709,45 +709,18 @@ static __read_mostly char *sched_feat_names[] = {
709 709
710#undef SCHED_FEAT 710#undef SCHED_FEAT
711 711
712static int sched_feat_open(struct inode *inode, struct file *filp) 712static int sched_feat_show(struct seq_file *m, void *v)
713{
714 filp->private_data = inode->i_private;
715 return 0;
716}
717
718static ssize_t
719sched_feat_read(struct file *filp, char __user *ubuf,
720 size_t cnt, loff_t *ppos)
721{ 713{
722 char *buf;
723 int r = 0;
724 int len = 0;
725 int i; 714 int i;
726 715
727 for (i = 0; sched_feat_names[i]; i++) { 716 for (i = 0; sched_feat_names[i]; i++) {
728 len += strlen(sched_feat_names[i]); 717 if (!(sysctl_sched_features & (1UL << i)))
729 len += 4; 718 seq_puts(m, "NO_");
730 } 719 seq_printf(m, "%s ", sched_feat_names[i]);
731
732 buf = kmalloc(len + 2, GFP_KERNEL);
733 if (!buf)
734 return -ENOMEM;
735
736 for (i = 0; sched_feat_names[i]; i++) {
737 if (sysctl_sched_features & (1UL << i))
738 r += sprintf(buf + r, "%s ", sched_feat_names[i]);
739 else
740 r += sprintf(buf + r, "NO_%s ", sched_feat_names[i]);
741 } 720 }
721 seq_puts(m, "\n");
742 722
743 r += sprintf(buf + r, "\n"); 723 return 0;
744 WARN_ON(r >= len + 2);
745
746 r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r);
747
748 kfree(buf);
749
750 return r;
751} 724}
752 725
753static ssize_t 726static ssize_t
@@ -792,10 +765,17 @@ sched_feat_write(struct file *filp, const char __user *ubuf,
792 return cnt; 765 return cnt;
793} 766}
794 767
768static int sched_feat_open(struct inode *inode, struct file *filp)
769{
770 return single_open(filp, sched_feat_show, NULL);
771}
772
795static struct file_operations sched_feat_fops = { 773static struct file_operations sched_feat_fops = {
796 .open = sched_feat_open, 774 .open = sched_feat_open,
797 .read = sched_feat_read, 775 .write = sched_feat_write,
798 .write = sched_feat_write, 776 .read = seq_read,
777 .llseek = seq_lseek,
778 .release = single_release,
799}; 779};
800 780
801static __init int sched_init_debug(void) 781static __init int sched_init_debug(void)
@@ -1480,27 +1460,13 @@ static void
1480update_group_shares_cpu(struct task_group *tg, int cpu, 1460update_group_shares_cpu(struct task_group *tg, int cpu,
1481 unsigned long sd_shares, unsigned long sd_rq_weight) 1461 unsigned long sd_shares, unsigned long sd_rq_weight)
1482{ 1462{
1483 int boost = 0;
1484 unsigned long shares; 1463 unsigned long shares;
1485 unsigned long rq_weight; 1464 unsigned long rq_weight;
1486 1465
1487 if (!tg->se[cpu]) 1466 if (!tg->se[cpu])
1488 return; 1467 return;
1489 1468
1490 rq_weight = tg->cfs_rq[cpu]->load.weight; 1469 rq_weight = tg->cfs_rq[cpu]->rq_weight;
1491
1492 /*
1493 * If there are currently no tasks on the cpu pretend there is one of
1494 * average load so that when a new task gets to run here it will not
1495 * get delayed by group starvation.
1496 */
1497 if (!rq_weight) {
1498 boost = 1;
1499 rq_weight = NICE_0_LOAD;
1500 }
1501
1502 if (unlikely(rq_weight > sd_rq_weight))
1503 rq_weight = sd_rq_weight;
1504 1470
1505 /* 1471 /*
1506 * \Sum shares * rq_weight 1472 * \Sum shares * rq_weight
@@ -1508,7 +1474,7 @@ update_group_shares_cpu(struct task_group *tg, int cpu,
1508 * \Sum rq_weight 1474 * \Sum rq_weight
1509 * 1475 *
1510 */ 1476 */
1511 shares = (sd_shares * rq_weight) / (sd_rq_weight + 1); 1477 shares = (sd_shares * rq_weight) / sd_rq_weight;
1512 shares = clamp_t(unsigned long, shares, MIN_SHARES, MAX_SHARES); 1478 shares = clamp_t(unsigned long, shares, MIN_SHARES, MAX_SHARES);
1513 1479
1514 if (abs(shares - tg->se[cpu]->load.weight) > 1480 if (abs(shares - tg->se[cpu]->load.weight) >
@@ -1517,11 +1483,7 @@ update_group_shares_cpu(struct task_group *tg, int cpu,
1517 unsigned long flags; 1483 unsigned long flags;
1518 1484
1519 spin_lock_irqsave(&rq->lock, flags); 1485 spin_lock_irqsave(&rq->lock, flags);
1520 /* 1486 tg->cfs_rq[cpu]->shares = shares;
1521 * record the actual number of shares, not the boosted amount.
1522 */
1523 tg->cfs_rq[cpu]->shares = boost ? 0 : shares;
1524 tg->cfs_rq[cpu]->rq_weight = rq_weight;
1525 1487
1526 __set_se_shares(tg->se[cpu], shares); 1488 __set_se_shares(tg->se[cpu], shares);
1527 spin_unlock_irqrestore(&rq->lock, flags); 1489 spin_unlock_irqrestore(&rq->lock, flags);
@@ -1535,13 +1497,23 @@ update_group_shares_cpu(struct task_group *tg, int cpu,
1535 */ 1497 */
1536static int tg_shares_up(struct task_group *tg, void *data) 1498static int tg_shares_up(struct task_group *tg, void *data)
1537{ 1499{
1538 unsigned long rq_weight = 0; 1500 unsigned long weight, rq_weight = 0;
1539 unsigned long shares = 0; 1501 unsigned long shares = 0;
1540 struct sched_domain *sd = data; 1502 struct sched_domain *sd = data;
1541 int i; 1503 int i;
1542 1504
1543 for_each_cpu_mask(i, sd->span) { 1505 for_each_cpu(i, sched_domain_span(sd)) {
1544 rq_weight += tg->cfs_rq[i]->load.weight; 1506 /*
1507 * If there are currently no tasks on the cpu pretend there
1508 * is one of average load so that when a new task gets to
1509 * run here it will not get delayed by group starvation.
1510 */
1511 weight = tg->cfs_rq[i]->load.weight;
1512 if (!weight)
1513 weight = NICE_0_LOAD;
1514
1515 tg->cfs_rq[i]->rq_weight = weight;
1516 rq_weight += weight;
1545 shares += tg->cfs_rq[i]->shares; 1517 shares += tg->cfs_rq[i]->shares;
1546 } 1518 }
1547 1519
@@ -1551,10 +1523,7 @@ static int tg_shares_up(struct task_group *tg, void *data)
1551 if (!sd->parent || !(sd->parent->flags & SD_LOAD_BALANCE)) 1523 if (!sd->parent || !(sd->parent->flags & SD_LOAD_BALANCE))
1552 shares = tg->shares; 1524 shares = tg->shares;
1553 1525
1554 if (!rq_weight) 1526 for_each_cpu(i, sched_domain_span(sd))
1555 rq_weight = cpus_weight(sd->span) * NICE_0_LOAD;
1556
1557 for_each_cpu_mask(i, sd->span)
1558 update_group_shares_cpu(tg, i, shares, rq_weight); 1527 update_group_shares_cpu(tg, i, shares, rq_weight);
1559 1528
1560 return 0; 1529 return 0;
@@ -2085,15 +2054,17 @@ find_idlest_group(struct sched_domain *sd, struct task_struct *p, int this_cpu)
2085 int i; 2054 int i;
2086 2055
2087 /* Skip over this group if it has no CPUs allowed */ 2056 /* Skip over this group if it has no CPUs allowed */
2088 if (!cpus_intersects(group->cpumask, p->cpus_allowed)) 2057 if (!cpumask_intersects(sched_group_cpus(group),
2058 &p->cpus_allowed))
2089 continue; 2059 continue;
2090 2060
2091 local_group = cpu_isset(this_cpu, group->cpumask); 2061 local_group = cpumask_test_cpu(this_cpu,
2062 sched_group_cpus(group));
2092 2063
2093 /* Tally up the load of all CPUs in the group */ 2064 /* Tally up the load of all CPUs in the group */
2094 avg_load = 0; 2065 avg_load = 0;
2095 2066
2096 for_each_cpu_mask_nr(i, group->cpumask) { 2067 for_each_cpu(i, sched_group_cpus(group)) {
2097 /* Bias balancing toward cpus of our domain */ 2068 /* Bias balancing toward cpus of our domain */
2098 if (local_group) 2069 if (local_group)
2099 load = source_load(i, load_idx); 2070 load = source_load(i, load_idx);
@@ -2125,17 +2096,14 @@ find_idlest_group(struct sched_domain *sd, struct task_struct *p, int this_cpu)
2125 * find_idlest_cpu - find the idlest cpu among the cpus in group. 2096 * find_idlest_cpu - find the idlest cpu among the cpus in group.
2126 */ 2097 */
2127static int 2098static int
2128find_idlest_cpu(struct sched_group *group, struct task_struct *p, int this_cpu, 2099find_idlest_cpu(struct sched_group *group, struct task_struct *p, int this_cpu)
2129 cpumask_t *tmp)
2130{ 2100{
2131 unsigned long load, min_load = ULONG_MAX; 2101 unsigned long load, min_load = ULONG_MAX;
2132 int idlest = -1; 2102 int idlest = -1;
2133 int i; 2103 int i;
2134 2104
2135 /* Traverse only the allowed CPUs */ 2105 /* Traverse only the allowed CPUs */
2136 cpus_and(*tmp, group->cpumask, p->cpus_allowed); 2106 for_each_cpu_and(i, sched_group_cpus(group), &p->cpus_allowed) {
2137
2138 for_each_cpu_mask_nr(i, *tmp) {
2139 load = weighted_cpuload(i); 2107 load = weighted_cpuload(i);
2140 2108
2141 if (load < min_load || (load == min_load && i == this_cpu)) { 2109 if (load < min_load || (load == min_load && i == this_cpu)) {
@@ -2177,7 +2145,6 @@ static int sched_balance_self(int cpu, int flag)
2177 update_shares(sd); 2145 update_shares(sd);
2178 2146
2179 while (sd) { 2147 while (sd) {
2180 cpumask_t span, tmpmask;
2181 struct sched_group *group; 2148 struct sched_group *group;
2182 int new_cpu, weight; 2149 int new_cpu, weight;
2183 2150
@@ -2186,14 +2153,13 @@ static int sched_balance_self(int cpu, int flag)
2186 continue; 2153 continue;
2187 } 2154 }
2188 2155
2189 span = sd->span;
2190 group = find_idlest_group(sd, t, cpu); 2156 group = find_idlest_group(sd, t, cpu);
2191 if (!group) { 2157 if (!group) {
2192 sd = sd->child; 2158 sd = sd->child;
2193 continue; 2159 continue;
2194 } 2160 }
2195 2161
2196 new_cpu = find_idlest_cpu(group, t, cpu, &tmpmask); 2162 new_cpu = find_idlest_cpu(group, t, cpu);
2197 if (new_cpu == -1 || new_cpu == cpu) { 2163 if (new_cpu == -1 || new_cpu == cpu) {
2198 /* Now try balancing at a lower domain level of cpu */ 2164 /* Now try balancing at a lower domain level of cpu */
2199 sd = sd->child; 2165 sd = sd->child;
@@ -2202,10 +2168,10 @@ static int sched_balance_self(int cpu, int flag)
2202 2168
2203 /* Now try balancing at a lower domain level of new_cpu */ 2169 /* Now try balancing at a lower domain level of new_cpu */
2204 cpu = new_cpu; 2170 cpu = new_cpu;
2171 weight = cpumask_weight(sched_domain_span(sd));
2205 sd = NULL; 2172 sd = NULL;
2206 weight = cpus_weight(span);
2207 for_each_domain(cpu, tmp) { 2173 for_each_domain(cpu, tmp) {
2208 if (weight <= cpus_weight(tmp->span)) 2174 if (weight <= cpumask_weight(sched_domain_span(tmp)))
2209 break; 2175 break;
2210 if (tmp->flags & flag) 2176 if (tmp->flags & flag)
2211 sd = tmp; 2177 sd = tmp;
@@ -2250,7 +2216,7 @@ static int try_to_wake_up(struct task_struct *p, unsigned int state, int sync)
2250 cpu = task_cpu(p); 2216 cpu = task_cpu(p);
2251 2217
2252 for_each_domain(this_cpu, sd) { 2218 for_each_domain(this_cpu, sd) {
2253 if (cpu_isset(cpu, sd->span)) { 2219 if (cpumask_test_cpu(cpu, sched_domain_span(sd))) {
2254 update_shares(sd); 2220 update_shares(sd);
2255 break; 2221 break;
2256 } 2222 }
@@ -2298,7 +2264,7 @@ static int try_to_wake_up(struct task_struct *p, unsigned int state, int sync)
2298 else { 2264 else {
2299 struct sched_domain *sd; 2265 struct sched_domain *sd;
2300 for_each_domain(this_cpu, sd) { 2266 for_each_domain(this_cpu, sd) {
2301 if (cpu_isset(cpu, sd->span)) { 2267 if (cpumask_test_cpu(cpu, sched_domain_span(sd))) {
2302 schedstat_inc(sd, ttwu_wake_remote); 2268 schedstat_inc(sd, ttwu_wake_remote);
2303 break; 2269 break;
2304 } 2270 }
@@ -2844,7 +2810,7 @@ static int double_lock_balance(struct rq *this_rq, struct rq *busiest)
2844 return ret; 2810 return ret;
2845} 2811}
2846 2812
2847static void double_unlock_balance(struct rq *this_rq, struct rq *busiest) 2813static inline void double_unlock_balance(struct rq *this_rq, struct rq *busiest)
2848 __releases(busiest->lock) 2814 __releases(busiest->lock)
2849{ 2815{
2850 spin_unlock(&busiest->lock); 2816 spin_unlock(&busiest->lock);
@@ -2864,7 +2830,7 @@ static void sched_migrate_task(struct task_struct *p, int dest_cpu)
2864 struct rq *rq; 2830 struct rq *rq;
2865 2831
2866 rq = task_rq_lock(p, &flags); 2832 rq = task_rq_lock(p, &flags);
2867 if (!cpu_isset(dest_cpu, p->cpus_allowed) 2833 if (!cpumask_test_cpu(dest_cpu, &p->cpus_allowed)
2868 || unlikely(!cpu_active(dest_cpu))) 2834 || unlikely(!cpu_active(dest_cpu)))
2869 goto out; 2835 goto out;
2870 2836
@@ -2930,7 +2896,7 @@ int can_migrate_task(struct task_struct *p, struct rq *rq, int this_cpu,
2930 * 2) cannot be migrated to this CPU due to cpus_allowed, or 2896 * 2) cannot be migrated to this CPU due to cpus_allowed, or
2931 * 3) are cache-hot on their current CPU. 2897 * 3) are cache-hot on their current CPU.
2932 */ 2898 */
2933 if (!cpu_isset(this_cpu, p->cpus_allowed)) { 2899 if (!cpumask_test_cpu(this_cpu, &p->cpus_allowed)) {
2934 schedstat_inc(p, se.nr_failed_migrations_affine); 2900 schedstat_inc(p, se.nr_failed_migrations_affine);
2935 return 0; 2901 return 0;
2936 } 2902 }
@@ -3105,7 +3071,7 @@ static int move_one_task(struct rq *this_rq, int this_cpu, struct rq *busiest,
3105static struct sched_group * 3071static struct sched_group *
3106find_busiest_group(struct sched_domain *sd, int this_cpu, 3072find_busiest_group(struct sched_domain *sd, int this_cpu,
3107 unsigned long *imbalance, enum cpu_idle_type idle, 3073 unsigned long *imbalance, enum cpu_idle_type idle,
3108 int *sd_idle, const cpumask_t *cpus, int *balance) 3074 int *sd_idle, const struct cpumask *cpus, int *balance)
3109{ 3075{
3110 struct sched_group *busiest = NULL, *this = NULL, *group = sd->groups; 3076 struct sched_group *busiest = NULL, *this = NULL, *group = sd->groups;
3111 unsigned long max_load, avg_load, total_load, this_load, total_pwr; 3077 unsigned long max_load, avg_load, total_load, this_load, total_pwr;
@@ -3141,10 +3107,11 @@ find_busiest_group(struct sched_domain *sd, int this_cpu,
3141 unsigned long sum_avg_load_per_task; 3107 unsigned long sum_avg_load_per_task;
3142 unsigned long avg_load_per_task; 3108 unsigned long avg_load_per_task;
3143 3109
3144 local_group = cpu_isset(this_cpu, group->cpumask); 3110 local_group = cpumask_test_cpu(this_cpu,
3111 sched_group_cpus(group));
3145 3112
3146 if (local_group) 3113 if (local_group)
3147 balance_cpu = first_cpu(group->cpumask); 3114 balance_cpu = cpumask_first(sched_group_cpus(group));
3148 3115
3149 /* Tally up the load of all CPUs in the group */ 3116 /* Tally up the load of all CPUs in the group */
3150 sum_weighted_load = sum_nr_running = avg_load = 0; 3117 sum_weighted_load = sum_nr_running = avg_load = 0;
@@ -3153,13 +3120,8 @@ find_busiest_group(struct sched_domain *sd, int this_cpu,
3153 max_cpu_load = 0; 3120 max_cpu_load = 0;
3154 min_cpu_load = ~0UL; 3121 min_cpu_load = ~0UL;
3155 3122
3156 for_each_cpu_mask_nr(i, group->cpumask) { 3123 for_each_cpu_and(i, sched_group_cpus(group), cpus) {
3157 struct rq *rq; 3124 struct rq *rq = cpu_rq(i);
3158
3159 if (!cpu_isset(i, *cpus))
3160 continue;
3161
3162 rq = cpu_rq(i);
3163 3125
3164 if (*sd_idle && rq->nr_running) 3126 if (*sd_idle && rq->nr_running)
3165 *sd_idle = 0; 3127 *sd_idle = 0;
@@ -3270,8 +3232,8 @@ find_busiest_group(struct sched_domain *sd, int this_cpu,
3270 */ 3232 */
3271 if ((sum_nr_running < min_nr_running) || 3233 if ((sum_nr_running < min_nr_running) ||
3272 (sum_nr_running == min_nr_running && 3234 (sum_nr_running == min_nr_running &&
3273 first_cpu(group->cpumask) < 3235 cpumask_first(sched_group_cpus(group)) <
3274 first_cpu(group_min->cpumask))) { 3236 cpumask_first(sched_group_cpus(group_min)))) {
3275 group_min = group; 3237 group_min = group;
3276 min_nr_running = sum_nr_running; 3238 min_nr_running = sum_nr_running;
3277 min_load_per_task = sum_weighted_load / 3239 min_load_per_task = sum_weighted_load /
@@ -3286,8 +3248,8 @@ find_busiest_group(struct sched_domain *sd, int this_cpu,
3286 if (sum_nr_running <= group_capacity - 1) { 3248 if (sum_nr_running <= group_capacity - 1) {
3287 if (sum_nr_running > leader_nr_running || 3249 if (sum_nr_running > leader_nr_running ||
3288 (sum_nr_running == leader_nr_running && 3250 (sum_nr_running == leader_nr_running &&
3289 first_cpu(group->cpumask) > 3251 cpumask_first(sched_group_cpus(group)) >
3290 first_cpu(group_leader->cpumask))) { 3252 cpumask_first(sched_group_cpus(group_leader)))) {
3291 group_leader = group; 3253 group_leader = group;
3292 leader_nr_running = sum_nr_running; 3254 leader_nr_running = sum_nr_running;
3293 } 3255 }
@@ -3426,16 +3388,16 @@ ret:
3426 */ 3388 */
3427static struct rq * 3389static struct rq *
3428find_busiest_queue(struct sched_group *group, enum cpu_idle_type idle, 3390find_busiest_queue(struct sched_group *group, enum cpu_idle_type idle,
3429 unsigned long imbalance, const cpumask_t *cpus) 3391 unsigned long imbalance, const struct cpumask *cpus)
3430{ 3392{
3431 struct rq *busiest = NULL, *rq; 3393 struct rq *busiest = NULL, *rq;
3432 unsigned long max_load = 0; 3394 unsigned long max_load = 0;
3433 int i; 3395 int i;
3434 3396
3435 for_each_cpu_mask_nr(i, group->cpumask) { 3397 for_each_cpu(i, sched_group_cpus(group)) {
3436 unsigned long wl; 3398 unsigned long wl;
3437 3399
3438 if (!cpu_isset(i, *cpus)) 3400 if (!cpumask_test_cpu(i, cpus))
3439 continue; 3401 continue;
3440 3402
3441 rq = cpu_rq(i); 3403 rq = cpu_rq(i);
@@ -3465,7 +3427,7 @@ find_busiest_queue(struct sched_group *group, enum cpu_idle_type idle,
3465 */ 3427 */
3466static int load_balance(int this_cpu, struct rq *this_rq, 3428static int load_balance(int this_cpu, struct rq *this_rq,
3467 struct sched_domain *sd, enum cpu_idle_type idle, 3429 struct sched_domain *sd, enum cpu_idle_type idle,
3468 int *balance, cpumask_t *cpus) 3430 int *balance, struct cpumask *cpus)
3469{ 3431{
3470 int ld_moved, all_pinned = 0, active_balance = 0, sd_idle = 0; 3432 int ld_moved, all_pinned = 0, active_balance = 0, sd_idle = 0;
3471 struct sched_group *group; 3433 struct sched_group *group;
@@ -3473,7 +3435,7 @@ static int load_balance(int this_cpu, struct rq *this_rq,
3473 struct rq *busiest; 3435 struct rq *busiest;
3474 unsigned long flags; 3436 unsigned long flags;
3475 3437
3476 cpus_setall(*cpus); 3438 cpumask_setall(cpus);
3477 3439
3478 /* 3440 /*
3479 * When power savings policy is enabled for the parent domain, idle 3441 * When power savings policy is enabled for the parent domain, idle
@@ -3533,8 +3495,8 @@ redo:
3533 3495
3534 /* All tasks on this runqueue were pinned by CPU affinity */ 3496 /* All tasks on this runqueue were pinned by CPU affinity */
3535 if (unlikely(all_pinned)) { 3497 if (unlikely(all_pinned)) {
3536 cpu_clear(cpu_of(busiest), *cpus); 3498 cpumask_clear_cpu(cpu_of(busiest), cpus);
3537 if (!cpus_empty(*cpus)) 3499 if (!cpumask_empty(cpus))
3538 goto redo; 3500 goto redo;
3539 goto out_balanced; 3501 goto out_balanced;
3540 } 3502 }
@@ -3551,7 +3513,8 @@ redo:
3551 /* don't kick the migration_thread, if the curr 3513 /* don't kick the migration_thread, if the curr
3552 * task on busiest cpu can't be moved to this_cpu 3514 * task on busiest cpu can't be moved to this_cpu
3553 */ 3515 */
3554 if (!cpu_isset(this_cpu, busiest->curr->cpus_allowed)) { 3516 if (!cpumask_test_cpu(this_cpu,
3517 &busiest->curr->cpus_allowed)) {
3555 spin_unlock_irqrestore(&busiest->lock, flags); 3518 spin_unlock_irqrestore(&busiest->lock, flags);
3556 all_pinned = 1; 3519 all_pinned = 1;
3557 goto out_one_pinned; 3520 goto out_one_pinned;
@@ -3626,7 +3589,7 @@ out:
3626 */ 3589 */
3627static int 3590static int
3628load_balance_newidle(int this_cpu, struct rq *this_rq, struct sched_domain *sd, 3591load_balance_newidle(int this_cpu, struct rq *this_rq, struct sched_domain *sd,
3629 cpumask_t *cpus) 3592 struct cpumask *cpus)
3630{ 3593{
3631 struct sched_group *group; 3594 struct sched_group *group;
3632 struct rq *busiest = NULL; 3595 struct rq *busiest = NULL;
@@ -3635,7 +3598,7 @@ load_balance_newidle(int this_cpu, struct rq *this_rq, struct sched_domain *sd,
3635 int sd_idle = 0; 3598 int sd_idle = 0;
3636 int all_pinned = 0; 3599 int all_pinned = 0;
3637 3600
3638 cpus_setall(*cpus); 3601 cpumask_setall(cpus);
3639 3602
3640 /* 3603 /*
3641 * When power savings policy is enabled for the parent domain, idle 3604 * When power savings policy is enabled for the parent domain, idle
@@ -3679,8 +3642,8 @@ redo:
3679 double_unlock_balance(this_rq, busiest); 3642 double_unlock_balance(this_rq, busiest);
3680 3643
3681 if (unlikely(all_pinned)) { 3644 if (unlikely(all_pinned)) {
3682 cpu_clear(cpu_of(busiest), *cpus); 3645 cpumask_clear_cpu(cpu_of(busiest), cpus);
3683 if (!cpus_empty(*cpus)) 3646 if (!cpumask_empty(cpus))
3684 goto redo; 3647 goto redo;
3685 } 3648 }
3686 } 3649 }
@@ -3715,7 +3678,10 @@ static void idle_balance(int this_cpu, struct rq *this_rq)
3715 struct sched_domain *sd; 3678 struct sched_domain *sd;
3716 int pulled_task = -1; 3679 int pulled_task = -1;
3717 unsigned long next_balance = jiffies + HZ; 3680 unsigned long next_balance = jiffies + HZ;
3718 cpumask_t tmpmask; 3681 cpumask_var_t tmpmask;
3682
3683 if (!alloc_cpumask_var(&tmpmask, GFP_ATOMIC))
3684 return;
3719 3685
3720 for_each_domain(this_cpu, sd) { 3686 for_each_domain(this_cpu, sd) {
3721 unsigned long interval; 3687 unsigned long interval;
@@ -3726,7 +3692,7 @@ static void idle_balance(int this_cpu, struct rq *this_rq)
3726 if (sd->flags & SD_BALANCE_NEWIDLE) 3692 if (sd->flags & SD_BALANCE_NEWIDLE)
3727 /* If we've pulled tasks over stop searching: */ 3693 /* If we've pulled tasks over stop searching: */
3728 pulled_task = load_balance_newidle(this_cpu, this_rq, 3694 pulled_task = load_balance_newidle(this_cpu, this_rq,
3729 sd, &tmpmask); 3695 sd, tmpmask);
3730 3696
3731 interval = msecs_to_jiffies(sd->balance_interval); 3697 interval = msecs_to_jiffies(sd->balance_interval);
3732 if (time_after(next_balance, sd->last_balance + interval)) 3698 if (time_after(next_balance, sd->last_balance + interval))
@@ -3741,6 +3707,7 @@ static void idle_balance(int this_cpu, struct rq *this_rq)
3741 */ 3707 */
3742 this_rq->next_balance = next_balance; 3708 this_rq->next_balance = next_balance;
3743 } 3709 }
3710 free_cpumask_var(tmpmask);
3744} 3711}
3745 3712
3746/* 3713/*
@@ -3778,7 +3745,7 @@ static void active_load_balance(struct rq *busiest_rq, int busiest_cpu)
3778 /* Search for an sd spanning us and the target CPU. */ 3745 /* Search for an sd spanning us and the target CPU. */
3779 for_each_domain(target_cpu, sd) { 3746 for_each_domain(target_cpu, sd) {
3780 if ((sd->flags & SD_LOAD_BALANCE) && 3747 if ((sd->flags & SD_LOAD_BALANCE) &&
3781 cpu_isset(busiest_cpu, sd->span)) 3748 cpumask_test_cpu(busiest_cpu, sched_domain_span(sd)))
3782 break; 3749 break;
3783 } 3750 }
3784 3751
@@ -3797,10 +3764,9 @@ static void active_load_balance(struct rq *busiest_rq, int busiest_cpu)
3797#ifdef CONFIG_NO_HZ 3764#ifdef CONFIG_NO_HZ
3798static struct { 3765static struct {
3799 atomic_t load_balancer; 3766 atomic_t load_balancer;
3800 cpumask_t cpu_mask; 3767 cpumask_var_t cpu_mask;
3801} nohz ____cacheline_aligned = { 3768} nohz ____cacheline_aligned = {
3802 .load_balancer = ATOMIC_INIT(-1), 3769 .load_balancer = ATOMIC_INIT(-1),
3803 .cpu_mask = CPU_MASK_NONE,
3804}; 3770};
3805 3771
3806/* 3772/*
@@ -3828,7 +3794,7 @@ int select_nohz_load_balancer(int stop_tick)
3828 int cpu = smp_processor_id(); 3794 int cpu = smp_processor_id();
3829 3795
3830 if (stop_tick) { 3796 if (stop_tick) {
3831 cpu_set(cpu, nohz.cpu_mask); 3797 cpumask_set_cpu(cpu, nohz.cpu_mask);
3832 cpu_rq(cpu)->in_nohz_recently = 1; 3798 cpu_rq(cpu)->in_nohz_recently = 1;
3833 3799
3834 /* 3800 /*
@@ -3842,7 +3808,7 @@ int select_nohz_load_balancer(int stop_tick)
3842 } 3808 }
3843 3809
3844 /* time for ilb owner also to sleep */ 3810 /* time for ilb owner also to sleep */
3845 if (cpus_weight(nohz.cpu_mask) == num_online_cpus()) { 3811 if (cpumask_weight(nohz.cpu_mask) == num_online_cpus()) {
3846 if (atomic_read(&nohz.load_balancer) == cpu) 3812 if (atomic_read(&nohz.load_balancer) == cpu)
3847 atomic_set(&nohz.load_balancer, -1); 3813 atomic_set(&nohz.load_balancer, -1);
3848 return 0; 3814 return 0;
@@ -3855,10 +3821,10 @@ int select_nohz_load_balancer(int stop_tick)
3855 } else if (atomic_read(&nohz.load_balancer) == cpu) 3821 } else if (atomic_read(&nohz.load_balancer) == cpu)
3856 return 1; 3822 return 1;
3857 } else { 3823 } else {
3858 if (!cpu_isset(cpu, nohz.cpu_mask)) 3824 if (!cpumask_test_cpu(cpu, nohz.cpu_mask))
3859 return 0; 3825 return 0;
3860 3826
3861 cpu_clear(cpu, nohz.cpu_mask); 3827 cpumask_clear_cpu(cpu, nohz.cpu_mask);
3862 3828
3863 if (atomic_read(&nohz.load_balancer) == cpu) 3829 if (atomic_read(&nohz.load_balancer) == cpu)
3864 if (atomic_cmpxchg(&nohz.load_balancer, cpu, -1) != cpu) 3830 if (atomic_cmpxchg(&nohz.load_balancer, cpu, -1) != cpu)
@@ -3886,7 +3852,11 @@ static void rebalance_domains(int cpu, enum cpu_idle_type idle)
3886 unsigned long next_balance = jiffies + 60*HZ; 3852 unsigned long next_balance = jiffies + 60*HZ;
3887 int update_next_balance = 0; 3853 int update_next_balance = 0;
3888 int need_serialize; 3854 int need_serialize;
3889 cpumask_t tmp; 3855 cpumask_var_t tmp;
3856
3857 /* Fails alloc? Rebalancing probably not a priority right now. */
3858 if (!alloc_cpumask_var(&tmp, GFP_ATOMIC))
3859 return;
3890 3860
3891 for_each_domain(cpu, sd) { 3861 for_each_domain(cpu, sd) {
3892 if (!(sd->flags & SD_LOAD_BALANCE)) 3862 if (!(sd->flags & SD_LOAD_BALANCE))
@@ -3911,7 +3881,7 @@ static void rebalance_domains(int cpu, enum cpu_idle_type idle)
3911 } 3881 }
3912 3882
3913 if (time_after_eq(jiffies, sd->last_balance + interval)) { 3883 if (time_after_eq(jiffies, sd->last_balance + interval)) {
3914 if (load_balance(cpu, rq, sd, idle, &balance, &tmp)) { 3884 if (load_balance(cpu, rq, sd, idle, &balance, tmp)) {
3915 /* 3885 /*
3916 * We've pulled tasks over so either we're no 3886 * We've pulled tasks over so either we're no
3917 * longer idle, or one of our SMT siblings is 3887 * longer idle, or one of our SMT siblings is
@@ -3945,6 +3915,8 @@ out:
3945 */ 3915 */
3946 if (likely(update_next_balance)) 3916 if (likely(update_next_balance))
3947 rq->next_balance = next_balance; 3917 rq->next_balance = next_balance;
3918
3919 free_cpumask_var(tmp);
3948} 3920}
3949 3921
3950/* 3922/*
@@ -3969,12 +3941,13 @@ static void run_rebalance_domains(struct softirq_action *h)
3969 */ 3941 */
3970 if (this_rq->idle_at_tick && 3942 if (this_rq->idle_at_tick &&
3971 atomic_read(&nohz.load_balancer) == this_cpu) { 3943 atomic_read(&nohz.load_balancer) == this_cpu) {
3972 cpumask_t cpus = nohz.cpu_mask;
3973 struct rq *rq; 3944 struct rq *rq;
3974 int balance_cpu; 3945 int balance_cpu;
3975 3946
3976 cpu_clear(this_cpu, cpus); 3947 for_each_cpu(balance_cpu, nohz.cpu_mask) {
3977 for_each_cpu_mask_nr(balance_cpu, cpus) { 3948 if (balance_cpu == this_cpu)
3949 continue;
3950
3978 /* 3951 /*
3979 * If this cpu gets work to do, stop the load balancing 3952 * If this cpu gets work to do, stop the load balancing
3980 * work being done for other cpus. Next load 3953 * work being done for other cpus. Next load
@@ -4012,7 +3985,7 @@ static inline void trigger_load_balance(struct rq *rq, int cpu)
4012 rq->in_nohz_recently = 0; 3985 rq->in_nohz_recently = 0;
4013 3986
4014 if (atomic_read(&nohz.load_balancer) == cpu) { 3987 if (atomic_read(&nohz.load_balancer) == cpu) {
4015 cpu_clear(cpu, nohz.cpu_mask); 3988 cpumask_clear_cpu(cpu, nohz.cpu_mask);
4016 atomic_set(&nohz.load_balancer, -1); 3989 atomic_set(&nohz.load_balancer, -1);
4017 } 3990 }
4018 3991
@@ -4025,7 +3998,7 @@ static inline void trigger_load_balance(struct rq *rq, int cpu)
4025 * TBD: Traverse the sched domains and nominate 3998 * TBD: Traverse the sched domains and nominate
4026 * the nearest cpu in the nohz.cpu_mask. 3999 * the nearest cpu in the nohz.cpu_mask.
4027 */ 4000 */
4028 int ilb = first_cpu(nohz.cpu_mask); 4001 int ilb = cpumask_first(nohz.cpu_mask);
4029 4002
4030 if (ilb < nr_cpu_ids) 4003 if (ilb < nr_cpu_ids)
4031 resched_cpu(ilb); 4004 resched_cpu(ilb);
@@ -4037,7 +4010,7 @@ static inline void trigger_load_balance(struct rq *rq, int cpu)
4037 * cpus with ticks stopped, is it time for that to stop? 4010 * cpus with ticks stopped, is it time for that to stop?
4038 */ 4011 */
4039 if (rq->idle_at_tick && atomic_read(&nohz.load_balancer) == cpu && 4012 if (rq->idle_at_tick && atomic_read(&nohz.load_balancer) == cpu &&
4040 cpus_weight(nohz.cpu_mask) == num_online_cpus()) { 4013 cpumask_weight(nohz.cpu_mask) == num_online_cpus()) {
4041 resched_cpu(cpu); 4014 resched_cpu(cpu);
4042 return; 4015 return;
4043 } 4016 }
@@ -4047,7 +4020,7 @@ static inline void trigger_load_balance(struct rq *rq, int cpu)
4047 * someone else, then no need raise the SCHED_SOFTIRQ 4020 * someone else, then no need raise the SCHED_SOFTIRQ
4048 */ 4021 */
4049 if (rq->idle_at_tick && atomic_read(&nohz.load_balancer) != cpu && 4022 if (rq->idle_at_tick && atomic_read(&nohz.load_balancer) != cpu &&
4050 cpu_isset(cpu, nohz.cpu_mask)) 4023 cpumask_test_cpu(cpu, nohz.cpu_mask))
4051 return; 4024 return;
4052#endif 4025#endif
4053 if (time_after_eq(jiffies, rq->next_balance)) 4026 if (time_after_eq(jiffies, rq->next_balance))
@@ -4209,7 +4182,6 @@ void account_steal_time(struct task_struct *p, cputime_t steal)
4209 4182
4210 if (p == rq->idle) { 4183 if (p == rq->idle) {
4211 p->stime = cputime_add(p->stime, steal); 4184 p->stime = cputime_add(p->stime, steal);
4212 account_group_system_time(p, steal);
4213 if (atomic_read(&rq->nr_iowait) > 0) 4185 if (atomic_read(&rq->nr_iowait) > 0)
4214 cpustat->iowait = cputime64_add(cpustat->iowait, tmp); 4186 cpustat->iowait = cputime64_add(cpustat->iowait, tmp);
4215 else 4187 else
@@ -4345,7 +4317,7 @@ void __kprobes sub_preempt_count(int val)
4345 /* 4317 /*
4346 * Underflow? 4318 * Underflow?
4347 */ 4319 */
4348 if (DEBUG_LOCKS_WARN_ON(val > preempt_count())) 4320 if (DEBUG_LOCKS_WARN_ON(val > preempt_count() - (!!kernel_locked())))
4349 return; 4321 return;
4350 /* 4322 /*
4351 * Is the spinlock portion underflowing? 4323 * Is the spinlock portion underflowing?
@@ -5406,10 +5378,9 @@ out_unlock:
5406 return retval; 5378 return retval;
5407} 5379}
5408 5380
5409long sched_setaffinity(pid_t pid, const cpumask_t *in_mask) 5381long sched_setaffinity(pid_t pid, const struct cpumask *in_mask)
5410{ 5382{
5411 cpumask_t cpus_allowed; 5383 cpumask_var_t cpus_allowed, new_mask;
5412 cpumask_t new_mask = *in_mask;
5413 struct task_struct *p; 5384 struct task_struct *p;
5414 int retval; 5385 int retval;
5415 5386
@@ -5431,6 +5402,14 @@ long sched_setaffinity(pid_t pid, const cpumask_t *in_mask)
5431 get_task_struct(p); 5402 get_task_struct(p);
5432 read_unlock(&tasklist_lock); 5403 read_unlock(&tasklist_lock);
5433 5404
5405 if (!alloc_cpumask_var(&cpus_allowed, GFP_KERNEL)) {
5406 retval = -ENOMEM;
5407 goto out_put_task;
5408 }
5409 if (!alloc_cpumask_var(&new_mask, GFP_KERNEL)) {
5410 retval = -ENOMEM;
5411 goto out_free_cpus_allowed;
5412 }
5434 retval = -EPERM; 5413 retval = -EPERM;
5435 if ((current->euid != p->euid) && (current->euid != p->uid) && 5414 if ((current->euid != p->euid) && (current->euid != p->uid) &&
5436 !capable(CAP_SYS_NICE)) 5415 !capable(CAP_SYS_NICE))
@@ -5440,37 +5419,41 @@ long sched_setaffinity(pid_t pid, const cpumask_t *in_mask)
5440 if (retval) 5419 if (retval)
5441 goto out_unlock; 5420 goto out_unlock;
5442 5421
5443 cpuset_cpus_allowed(p, &cpus_allowed); 5422 cpuset_cpus_allowed(p, cpus_allowed);
5444 cpus_and(new_mask, new_mask, cpus_allowed); 5423 cpumask_and(new_mask, in_mask, cpus_allowed);
5445 again: 5424 again:
5446 retval = set_cpus_allowed_ptr(p, &new_mask); 5425 retval = set_cpus_allowed_ptr(p, new_mask);
5447 5426
5448 if (!retval) { 5427 if (!retval) {
5449 cpuset_cpus_allowed(p, &cpus_allowed); 5428 cpuset_cpus_allowed(p, cpus_allowed);
5450 if (!cpus_subset(new_mask, cpus_allowed)) { 5429 if (!cpumask_subset(new_mask, cpus_allowed)) {
5451 /* 5430 /*
5452 * We must have raced with a concurrent cpuset 5431 * We must have raced with a concurrent cpuset
5453 * update. Just reset the cpus_allowed to the 5432 * update. Just reset the cpus_allowed to the
5454 * cpuset's cpus_allowed 5433 * cpuset's cpus_allowed
5455 */ 5434 */
5456 new_mask = cpus_allowed; 5435 cpumask_copy(new_mask, cpus_allowed);
5457 goto again; 5436 goto again;
5458 } 5437 }
5459 } 5438 }
5460out_unlock: 5439out_unlock:
5440 free_cpumask_var(new_mask);
5441out_free_cpus_allowed:
5442 free_cpumask_var(cpus_allowed);
5443out_put_task:
5461 put_task_struct(p); 5444 put_task_struct(p);
5462 put_online_cpus(); 5445 put_online_cpus();
5463 return retval; 5446 return retval;
5464} 5447}
5465 5448
5466static int get_user_cpu_mask(unsigned long __user *user_mask_ptr, unsigned len, 5449static int get_user_cpu_mask(unsigned long __user *user_mask_ptr, unsigned len,
5467 cpumask_t *new_mask) 5450 struct cpumask *new_mask)
5468{ 5451{
5469 if (len < sizeof(cpumask_t)) { 5452 if (len < cpumask_size())
5470 memset(new_mask, 0, sizeof(cpumask_t)); 5453 cpumask_clear(new_mask);
5471 } else if (len > sizeof(cpumask_t)) { 5454 else if (len > cpumask_size())
5472 len = sizeof(cpumask_t); 5455 len = cpumask_size();
5473 } 5456
5474 return copy_from_user(new_mask, user_mask_ptr, len) ? -EFAULT : 0; 5457 return copy_from_user(new_mask, user_mask_ptr, len) ? -EFAULT : 0;
5475} 5458}
5476 5459
@@ -5483,17 +5466,20 @@ static int get_user_cpu_mask(unsigned long __user *user_mask_ptr, unsigned len,
5483asmlinkage long sys_sched_setaffinity(pid_t pid, unsigned int len, 5466asmlinkage long sys_sched_setaffinity(pid_t pid, unsigned int len,
5484 unsigned long __user *user_mask_ptr) 5467 unsigned long __user *user_mask_ptr)
5485{ 5468{
5486 cpumask_t new_mask; 5469 cpumask_var_t new_mask;
5487 int retval; 5470 int retval;
5488 5471
5489 retval = get_user_cpu_mask(user_mask_ptr, len, &new_mask); 5472 if (!alloc_cpumask_var(&new_mask, GFP_KERNEL))
5490 if (retval) 5473 return -ENOMEM;
5491 return retval;
5492 5474
5493 return sched_setaffinity(pid, &new_mask); 5475 retval = get_user_cpu_mask(user_mask_ptr, len, new_mask);
5476 if (retval == 0)
5477 retval = sched_setaffinity(pid, new_mask);
5478 free_cpumask_var(new_mask);
5479 return retval;
5494} 5480}
5495 5481
5496long sched_getaffinity(pid_t pid, cpumask_t *mask) 5482long sched_getaffinity(pid_t pid, struct cpumask *mask)
5497{ 5483{
5498 struct task_struct *p; 5484 struct task_struct *p;
5499 int retval; 5485 int retval;
@@ -5510,7 +5496,7 @@ long sched_getaffinity(pid_t pid, cpumask_t *mask)
5510 if (retval) 5496 if (retval)
5511 goto out_unlock; 5497 goto out_unlock;
5512 5498
5513 cpus_and(*mask, p->cpus_allowed, cpu_online_map); 5499 cpumask_and(mask, &p->cpus_allowed, cpu_online_mask);
5514 5500
5515out_unlock: 5501out_unlock:
5516 read_unlock(&tasklist_lock); 5502 read_unlock(&tasklist_lock);
@@ -5529,19 +5515,24 @@ asmlinkage long sys_sched_getaffinity(pid_t pid, unsigned int len,
5529 unsigned long __user *user_mask_ptr) 5515 unsigned long __user *user_mask_ptr)
5530{ 5516{
5531 int ret; 5517 int ret;
5532 cpumask_t mask; 5518 cpumask_var_t mask;
5533 5519
5534 if (len < sizeof(cpumask_t)) 5520 if (len < cpumask_size())
5535 return -EINVAL; 5521 return -EINVAL;
5536 5522
5537 ret = sched_getaffinity(pid, &mask); 5523 if (!alloc_cpumask_var(&mask, GFP_KERNEL))
5538 if (ret < 0) 5524 return -ENOMEM;
5539 return ret;
5540 5525
5541 if (copy_to_user(user_mask_ptr, &mask, sizeof(cpumask_t))) 5526 ret = sched_getaffinity(pid, mask);
5542 return -EFAULT; 5527 if (ret == 0) {
5528 if (copy_to_user(user_mask_ptr, mask, cpumask_size()))
5529 ret = -EFAULT;
5530 else
5531 ret = cpumask_size();
5532 }
5533 free_cpumask_var(mask);
5543 5534
5544 return sizeof(cpumask_t); 5535 return ret;
5545} 5536}
5546 5537
5547/** 5538/**
@@ -5883,7 +5874,7 @@ void __cpuinit init_idle(struct task_struct *idle, int cpu)
5883 idle->se.exec_start = sched_clock(); 5874 idle->se.exec_start = sched_clock();
5884 5875
5885 idle->prio = idle->normal_prio = MAX_PRIO; 5876 idle->prio = idle->normal_prio = MAX_PRIO;
5886 idle->cpus_allowed = cpumask_of_cpu(cpu); 5877 cpumask_copy(&idle->cpus_allowed, cpumask_of(cpu));
5887 __set_task_cpu(idle, cpu); 5878 __set_task_cpu(idle, cpu);
5888 5879
5889 rq->curr = rq->idle = idle; 5880 rq->curr = rq->idle = idle;
@@ -5910,9 +5901,9 @@ void __cpuinit init_idle(struct task_struct *idle, int cpu)
5910 * indicates which cpus entered this state. This is used 5901 * indicates which cpus entered this state. This is used
5911 * in the rcu update to wait only for active cpus. For system 5902 * in the rcu update to wait only for active cpus. For system
5912 * which do not switch off the HZ timer nohz_cpu_mask should 5903 * which do not switch off the HZ timer nohz_cpu_mask should
5913 * always be CPU_MASK_NONE. 5904 * always be CPU_BITS_NONE.
5914 */ 5905 */
5915cpumask_t nohz_cpu_mask = CPU_MASK_NONE; 5906cpumask_var_t nohz_cpu_mask;
5916 5907
5917/* 5908/*
5918 * Increase the granularity value when there are more CPUs, 5909 * Increase the granularity value when there are more CPUs,
@@ -5967,7 +5958,7 @@ static inline void sched_init_granularity(void)
5967 * task must not exit() & deallocate itself prematurely. The 5958 * task must not exit() & deallocate itself prematurely. The
5968 * call is not atomic; no spinlocks may be held. 5959 * call is not atomic; no spinlocks may be held.
5969 */ 5960 */
5970int set_cpus_allowed_ptr(struct task_struct *p, const cpumask_t *new_mask) 5961int set_cpus_allowed_ptr(struct task_struct *p, const struct cpumask *new_mask)
5971{ 5962{
5972 struct migration_req req; 5963 struct migration_req req;
5973 unsigned long flags; 5964 unsigned long flags;
@@ -5975,13 +5966,13 @@ int set_cpus_allowed_ptr(struct task_struct *p, const cpumask_t *new_mask)
5975 int ret = 0; 5966 int ret = 0;
5976 5967
5977 rq = task_rq_lock(p, &flags); 5968 rq = task_rq_lock(p, &flags);
5978 if (!cpus_intersects(*new_mask, cpu_online_map)) { 5969 if (!cpumask_intersects(new_mask, cpu_online_mask)) {
5979 ret = -EINVAL; 5970 ret = -EINVAL;
5980 goto out; 5971 goto out;
5981 } 5972 }
5982 5973
5983 if (unlikely((p->flags & PF_THREAD_BOUND) && p != current && 5974 if (unlikely((p->flags & PF_THREAD_BOUND) && p != current &&
5984 !cpus_equal(p->cpus_allowed, *new_mask))) { 5975 !cpumask_equal(&p->cpus_allowed, new_mask))) {
5985 ret = -EINVAL; 5976 ret = -EINVAL;
5986 goto out; 5977 goto out;
5987 } 5978 }
@@ -5989,15 +5980,15 @@ int set_cpus_allowed_ptr(struct task_struct *p, const cpumask_t *new_mask)
5989 if (p->sched_class->set_cpus_allowed) 5980 if (p->sched_class->set_cpus_allowed)
5990 p->sched_class->set_cpus_allowed(p, new_mask); 5981 p->sched_class->set_cpus_allowed(p, new_mask);
5991 else { 5982 else {
5992 p->cpus_allowed = *new_mask; 5983 cpumask_copy(&p->cpus_allowed, new_mask);
5993 p->rt.nr_cpus_allowed = cpus_weight(*new_mask); 5984 p->rt.nr_cpus_allowed = cpumask_weight(new_mask);
5994 } 5985 }
5995 5986
5996 /* Can the task run on the task's current CPU? If so, we're done */ 5987 /* Can the task run on the task's current CPU? If so, we're done */
5997 if (cpu_isset(task_cpu(p), *new_mask)) 5988 if (cpumask_test_cpu(task_cpu(p), new_mask))
5998 goto out; 5989 goto out;
5999 5990
6000 if (migrate_task(p, any_online_cpu(*new_mask), &req)) { 5991 if (migrate_task(p, cpumask_any_and(cpu_online_mask, new_mask), &req)) {
6001 /* Need help from migration thread: drop lock and wait. */ 5992 /* Need help from migration thread: drop lock and wait. */
6002 task_rq_unlock(rq, &flags); 5993 task_rq_unlock(rq, &flags);
6003 wake_up_process(rq->migration_thread); 5994 wake_up_process(rq->migration_thread);
@@ -6039,7 +6030,7 @@ static int __migrate_task(struct task_struct *p, int src_cpu, int dest_cpu)
6039 if (task_cpu(p) != src_cpu) 6030 if (task_cpu(p) != src_cpu)
6040 goto done; 6031 goto done;
6041 /* Affinity changed (again). */ 6032 /* Affinity changed (again). */
6042 if (!cpu_isset(dest_cpu, p->cpus_allowed)) 6033 if (!cpumask_test_cpu(dest_cpu, &p->cpus_allowed))
6043 goto fail; 6034 goto fail;
6044 6035
6045 on_rq = p->se.on_rq; 6036 on_rq = p->se.on_rq;
@@ -6133,54 +6124,46 @@ static int __migrate_task_irq(struct task_struct *p, int src_cpu, int dest_cpu)
6133 6124
6134/* 6125/*
6135 * Figure out where task on dead CPU should go, use force if necessary. 6126 * Figure out where task on dead CPU should go, use force if necessary.
6136 * NOTE: interrupts should be disabled by the caller
6137 */ 6127 */
6138static void move_task_off_dead_cpu(int dead_cpu, struct task_struct *p) 6128static void move_task_off_dead_cpu(int dead_cpu, struct task_struct *p)
6139{ 6129{
6140 unsigned long flags;
6141 cpumask_t mask;
6142 struct rq *rq;
6143 int dest_cpu; 6130 int dest_cpu;
6131 /* FIXME: Use cpumask_of_node here. */
6132 cpumask_t _nodemask = node_to_cpumask(cpu_to_node(dead_cpu));
6133 const struct cpumask *nodemask = &_nodemask;
6134
6135again:
6136 /* Look for allowed, online CPU in same node. */
6137 for_each_cpu_and(dest_cpu, nodemask, cpu_online_mask)
6138 if (cpumask_test_cpu(dest_cpu, &p->cpus_allowed))
6139 goto move;
6140
6141 /* Any allowed, online CPU? */
6142 dest_cpu = cpumask_any_and(&p->cpus_allowed, cpu_online_mask);
6143 if (dest_cpu < nr_cpu_ids)
6144 goto move;
6145
6146 /* No more Mr. Nice Guy. */
6147 if (dest_cpu >= nr_cpu_ids) {
6148 cpuset_cpus_allowed_locked(p, &p->cpus_allowed);
6149 dest_cpu = cpumask_any_and(cpu_online_mask, &p->cpus_allowed);
6144 6150
6145 do { 6151 /*
6146 /* On same node? */ 6152 * Don't tell them about moving exiting tasks or
6147 mask = node_to_cpumask(cpu_to_node(dead_cpu)); 6153 * kernel threads (both mm NULL), since they never
6148 cpus_and(mask, mask, p->cpus_allowed); 6154 * leave kernel.
6149 dest_cpu = any_online_cpu(mask); 6155 */
6150 6156 if (p->mm && printk_ratelimit()) {
6151 /* On any allowed CPU? */ 6157 printk(KERN_INFO "process %d (%s) no "
6152 if (dest_cpu >= nr_cpu_ids) 6158 "longer affine to cpu%d\n",
6153 dest_cpu = any_online_cpu(p->cpus_allowed); 6159 task_pid_nr(p), p->comm, dead_cpu);
6154
6155 /* No more Mr. Nice Guy. */
6156 if (dest_cpu >= nr_cpu_ids) {
6157 cpumask_t cpus_allowed;
6158
6159 cpuset_cpus_allowed_locked(p, &cpus_allowed);
6160 /*
6161 * Try to stay on the same cpuset, where the
6162 * current cpuset may be a subset of all cpus.
6163 * The cpuset_cpus_allowed_locked() variant of
6164 * cpuset_cpus_allowed() will not block. It must be
6165 * called within calls to cpuset_lock/cpuset_unlock.
6166 */
6167 rq = task_rq_lock(p, &flags);
6168 p->cpus_allowed = cpus_allowed;
6169 dest_cpu = any_online_cpu(p->cpus_allowed);
6170 task_rq_unlock(rq, &flags);
6171
6172 /*
6173 * Don't tell them about moving exiting tasks or
6174 * kernel threads (both mm NULL), since they never
6175 * leave kernel.
6176 */
6177 if (p->mm && printk_ratelimit()) {
6178 printk(KERN_INFO "process %d (%s) no "
6179 "longer affine to cpu%d\n",
6180 task_pid_nr(p), p->comm, dead_cpu);
6181 }
6182 } 6160 }
6183 } while (!__migrate_task_irq(p, dead_cpu, dest_cpu)); 6161 }
6162
6163move:
6164 /* It can have affinity changed while we were choosing. */
6165 if (unlikely(!__migrate_task_irq(p, dead_cpu, dest_cpu)))
6166 goto again;
6184} 6167}
6185 6168
6186/* 6169/*
@@ -6192,7 +6175,7 @@ static void move_task_off_dead_cpu(int dead_cpu, struct task_struct *p)
6192 */ 6175 */
6193static void migrate_nr_uninterruptible(struct rq *rq_src) 6176static void migrate_nr_uninterruptible(struct rq *rq_src)
6194{ 6177{
6195 struct rq *rq_dest = cpu_rq(any_online_cpu(*CPU_MASK_ALL_PTR)); 6178 struct rq *rq_dest = cpu_rq(cpumask_any(cpu_online_mask));
6196 unsigned long flags; 6179 unsigned long flags;
6197 6180
6198 local_irq_save(flags); 6181 local_irq_save(flags);
@@ -6482,7 +6465,7 @@ static void set_rq_online(struct rq *rq)
6482 if (!rq->online) { 6465 if (!rq->online) {
6483 const struct sched_class *class; 6466 const struct sched_class *class;
6484 6467
6485 cpu_set(rq->cpu, rq->rd->online); 6468 cpumask_set_cpu(rq->cpu, rq->rd->online);
6486 rq->online = 1; 6469 rq->online = 1;
6487 6470
6488 for_each_class(class) { 6471 for_each_class(class) {
@@ -6502,7 +6485,7 @@ static void set_rq_offline(struct rq *rq)
6502 class->rq_offline(rq); 6485 class->rq_offline(rq);
6503 } 6486 }
6504 6487
6505 cpu_clear(rq->cpu, rq->rd->online); 6488 cpumask_clear_cpu(rq->cpu, rq->rd->online);
6506 rq->online = 0; 6489 rq->online = 0;
6507 } 6490 }
6508} 6491}
@@ -6543,7 +6526,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
6543 rq = cpu_rq(cpu); 6526 rq = cpu_rq(cpu);
6544 spin_lock_irqsave(&rq->lock, flags); 6527 spin_lock_irqsave(&rq->lock, flags);
6545 if (rq->rd) { 6528 if (rq->rd) {
6546 BUG_ON(!cpu_isset(cpu, rq->rd->span)); 6529 BUG_ON(!cpumask_test_cpu(cpu, rq->rd->span));
6547 6530
6548 set_rq_online(rq); 6531 set_rq_online(rq);
6549 } 6532 }
@@ -6557,7 +6540,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
6557 break; 6540 break;
6558 /* Unbind it from offline cpu so it can run. Fall thru. */ 6541 /* Unbind it from offline cpu so it can run. Fall thru. */
6559 kthread_bind(cpu_rq(cpu)->migration_thread, 6542 kthread_bind(cpu_rq(cpu)->migration_thread,
6560 any_online_cpu(cpu_online_map)); 6543 cpumask_any(cpu_online_mask));
6561 kthread_stop(cpu_rq(cpu)->migration_thread); 6544 kthread_stop(cpu_rq(cpu)->migration_thread);
6562 cpu_rq(cpu)->migration_thread = NULL; 6545 cpu_rq(cpu)->migration_thread = NULL;
6563 break; 6546 break;
@@ -6605,7 +6588,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
6605 rq = cpu_rq(cpu); 6588 rq = cpu_rq(cpu);
6606 spin_lock_irqsave(&rq->lock, flags); 6589 spin_lock_irqsave(&rq->lock, flags);
6607 if (rq->rd) { 6590 if (rq->rd) {
6608 BUG_ON(!cpu_isset(cpu, rq->rd->span)); 6591 BUG_ON(!cpumask_test_cpu(cpu, rq->rd->span));
6609 set_rq_offline(rq); 6592 set_rq_offline(rq);
6610 } 6593 }
6611 spin_unlock_irqrestore(&rq->lock, flags); 6594 spin_unlock_irqrestore(&rq->lock, flags);
@@ -6643,36 +6626,14 @@ early_initcall(migration_init);
6643 6626
6644#ifdef CONFIG_SCHED_DEBUG 6627#ifdef CONFIG_SCHED_DEBUG
6645 6628
6646static inline const char *sd_level_to_string(enum sched_domain_level lvl)
6647{
6648 switch (lvl) {
6649 case SD_LV_NONE:
6650 return "NONE";
6651 case SD_LV_SIBLING:
6652 return "SIBLING";
6653 case SD_LV_MC:
6654 return "MC";
6655 case SD_LV_CPU:
6656 return "CPU";
6657 case SD_LV_NODE:
6658 return "NODE";
6659 case SD_LV_ALLNODES:
6660 return "ALLNODES";
6661 case SD_LV_MAX:
6662 return "MAX";
6663
6664 }
6665 return "MAX";
6666}
6667
6668static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level, 6629static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level,
6669 cpumask_t *groupmask) 6630 struct cpumask *groupmask)
6670{ 6631{
6671 struct sched_group *group = sd->groups; 6632 struct sched_group *group = sd->groups;
6672 char str[256]; 6633 char str[256];
6673 6634
6674 cpulist_scnprintf(str, sizeof(str), sd->span); 6635 cpulist_scnprintf(str, sizeof(str), *sched_domain_span(sd));
6675 cpus_clear(*groupmask); 6636 cpumask_clear(groupmask);
6676 6637
6677 printk(KERN_DEBUG "%*s domain %d: ", level, "", level); 6638 printk(KERN_DEBUG "%*s domain %d: ", level, "", level);
6678 6639
@@ -6684,14 +6645,13 @@ static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level,
6684 return -1; 6645 return -1;
6685 } 6646 }
6686 6647
6687 printk(KERN_CONT "span %s level %s\n", 6648 printk(KERN_CONT "span %s level %s\n", str, sd->name);
6688 str, sd_level_to_string(sd->level));
6689 6649
6690 if (!cpu_isset(cpu, sd->span)) { 6650 if (!cpumask_test_cpu(cpu, sched_domain_span(sd))) {
6691 printk(KERN_ERR "ERROR: domain->span does not contain " 6651 printk(KERN_ERR "ERROR: domain->span does not contain "
6692 "CPU%d\n", cpu); 6652 "CPU%d\n", cpu);
6693 } 6653 }
6694 if (!cpu_isset(cpu, group->cpumask)) { 6654 if (!cpumask_test_cpu(cpu, sched_group_cpus(group))) {
6695 printk(KERN_ERR "ERROR: domain->groups does not contain" 6655 printk(KERN_ERR "ERROR: domain->groups does not contain"
6696 " CPU%d\n", cpu); 6656 " CPU%d\n", cpu);
6697 } 6657 }
@@ -6711,31 +6671,32 @@ static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level,
6711 break; 6671 break;
6712 } 6672 }
6713 6673
6714 if (!cpus_weight(group->cpumask)) { 6674 if (!cpumask_weight(sched_group_cpus(group))) {
6715 printk(KERN_CONT "\n"); 6675 printk(KERN_CONT "\n");
6716 printk(KERN_ERR "ERROR: empty group\n"); 6676 printk(KERN_ERR "ERROR: empty group\n");
6717 break; 6677 break;
6718 } 6678 }
6719 6679
6720 if (cpus_intersects(*groupmask, group->cpumask)) { 6680 if (cpumask_intersects(groupmask, sched_group_cpus(group))) {
6721 printk(KERN_CONT "\n"); 6681 printk(KERN_CONT "\n");
6722 printk(KERN_ERR "ERROR: repeated CPUs\n"); 6682 printk(KERN_ERR "ERROR: repeated CPUs\n");
6723 break; 6683 break;
6724 } 6684 }
6725 6685
6726 cpus_or(*groupmask, *groupmask, group->cpumask); 6686 cpumask_or(groupmask, groupmask, sched_group_cpus(group));
6727 6687
6728 cpulist_scnprintf(str, sizeof(str), group->cpumask); 6688 cpulist_scnprintf(str, sizeof(str), *sched_group_cpus(group));
6729 printk(KERN_CONT " %s", str); 6689 printk(KERN_CONT " %s", str);
6730 6690
6731 group = group->next; 6691 group = group->next;
6732 } while (group != sd->groups); 6692 } while (group != sd->groups);
6733 printk(KERN_CONT "\n"); 6693 printk(KERN_CONT "\n");
6734 6694
6735 if (!cpus_equal(sd->span, *groupmask)) 6695 if (!cpumask_equal(sched_domain_span(sd), groupmask))
6736 printk(KERN_ERR "ERROR: groups don't span domain->span\n"); 6696 printk(KERN_ERR "ERROR: groups don't span domain->span\n");
6737 6697
6738 if (sd->parent && !cpus_subset(*groupmask, sd->parent->span)) 6698 if (sd->parent &&
6699 !cpumask_subset(groupmask, sched_domain_span(sd->parent)))
6739 printk(KERN_ERR "ERROR: parent span is not a superset " 6700 printk(KERN_ERR "ERROR: parent span is not a superset "
6740 "of domain->span\n"); 6701 "of domain->span\n");
6741 return 0; 6702 return 0;
@@ -6743,7 +6704,7 @@ static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level,
6743 6704
6744static void sched_domain_debug(struct sched_domain *sd, int cpu) 6705static void sched_domain_debug(struct sched_domain *sd, int cpu)
6745{ 6706{
6746 cpumask_t *groupmask; 6707 cpumask_var_t groupmask;
6747 int level = 0; 6708 int level = 0;
6748 6709
6749 if (!sd) { 6710 if (!sd) {
@@ -6753,8 +6714,7 @@ static void sched_domain_debug(struct sched_domain *sd, int cpu)
6753 6714
6754 printk(KERN_DEBUG "CPU%d attaching sched-domain:\n", cpu); 6715 printk(KERN_DEBUG "CPU%d attaching sched-domain:\n", cpu);
6755 6716
6756 groupmask = kmalloc(sizeof(cpumask_t), GFP_KERNEL); 6717 if (!alloc_cpumask_var(&groupmask, GFP_KERNEL)) {
6757 if (!groupmask) {
6758 printk(KERN_DEBUG "Cannot load-balance (out of memory)\n"); 6718 printk(KERN_DEBUG "Cannot load-balance (out of memory)\n");
6759 return; 6719 return;
6760 } 6720 }
@@ -6767,7 +6727,7 @@ static void sched_domain_debug(struct sched_domain *sd, int cpu)
6767 if (!sd) 6727 if (!sd)
6768 break; 6728 break;
6769 } 6729 }
6770 kfree(groupmask); 6730 free_cpumask_var(groupmask);
6771} 6731}
6772#else /* !CONFIG_SCHED_DEBUG */ 6732#else /* !CONFIG_SCHED_DEBUG */
6773# define sched_domain_debug(sd, cpu) do { } while (0) 6733# define sched_domain_debug(sd, cpu) do { } while (0)
@@ -6775,7 +6735,7 @@ static void sched_domain_debug(struct sched_domain *sd, int cpu)
6775 6735
6776static int sd_degenerate(struct sched_domain *sd) 6736static int sd_degenerate(struct sched_domain *sd)
6777{ 6737{
6778 if (cpus_weight(sd->span) == 1) 6738 if (cpumask_weight(sched_domain_span(sd)) == 1)
6779 return 1; 6739 return 1;
6780 6740
6781 /* Following flags need at least 2 groups */ 6741 /* Following flags need at least 2 groups */
@@ -6806,7 +6766,7 @@ sd_parent_degenerate(struct sched_domain *sd, struct sched_domain *parent)
6806 if (sd_degenerate(parent)) 6766 if (sd_degenerate(parent))
6807 return 1; 6767 return 1;
6808 6768
6809 if (!cpus_equal(sd->span, parent->span)) 6769 if (!cpumask_equal(sched_domain_span(sd), sched_domain_span(parent)))
6810 return 0; 6770 return 0;
6811 6771
6812 /* Does parent contain flags not in child? */ 6772 /* Does parent contain flags not in child? */
@@ -6828,6 +6788,16 @@ sd_parent_degenerate(struct sched_domain *sd, struct sched_domain *parent)
6828 return 1; 6788 return 1;
6829} 6789}
6830 6790
6791static void free_rootdomain(struct root_domain *rd)
6792{
6793 cpupri_cleanup(&rd->cpupri);
6794
6795 free_cpumask_var(rd->rto_mask);
6796 free_cpumask_var(rd->online);
6797 free_cpumask_var(rd->span);
6798 kfree(rd);
6799}
6800
6831static void rq_attach_root(struct rq *rq, struct root_domain *rd) 6801static void rq_attach_root(struct rq *rq, struct root_domain *rd)
6832{ 6802{
6833 unsigned long flags; 6803 unsigned long flags;
@@ -6837,38 +6807,63 @@ static void rq_attach_root(struct rq *rq, struct root_domain *rd)
6837 if (rq->rd) { 6807 if (rq->rd) {
6838 struct root_domain *old_rd = rq->rd; 6808 struct root_domain *old_rd = rq->rd;
6839 6809
6840 if (cpu_isset(rq->cpu, old_rd->online)) 6810 if (cpumask_test_cpu(rq->cpu, old_rd->online))
6841 set_rq_offline(rq); 6811 set_rq_offline(rq);
6842 6812
6843 cpu_clear(rq->cpu, old_rd->span); 6813 cpumask_clear_cpu(rq->cpu, old_rd->span);
6844 6814
6845 if (atomic_dec_and_test(&old_rd->refcount)) 6815 if (atomic_dec_and_test(&old_rd->refcount))
6846 kfree(old_rd); 6816 free_rootdomain(old_rd);
6847 } 6817 }
6848 6818
6849 atomic_inc(&rd->refcount); 6819 atomic_inc(&rd->refcount);
6850 rq->rd = rd; 6820 rq->rd = rd;
6851 6821
6852 cpu_set(rq->cpu, rd->span); 6822 cpumask_set_cpu(rq->cpu, rd->span);
6853 if (cpu_isset(rq->cpu, cpu_online_map)) 6823 if (cpumask_test_cpu(rq->cpu, cpu_online_mask))
6854 set_rq_online(rq); 6824 set_rq_online(rq);
6855 6825
6856 spin_unlock_irqrestore(&rq->lock, flags); 6826 spin_unlock_irqrestore(&rq->lock, flags);
6857} 6827}
6858 6828
6859static void init_rootdomain(struct root_domain *rd) 6829static int init_rootdomain(struct root_domain *rd, bool bootmem)
6860{ 6830{
6861 memset(rd, 0, sizeof(*rd)); 6831 memset(rd, 0, sizeof(*rd));
6862 6832
6863 cpus_clear(rd->span); 6833 if (bootmem) {
6864 cpus_clear(rd->online); 6834 alloc_bootmem_cpumask_var(&def_root_domain.span);
6835 alloc_bootmem_cpumask_var(&def_root_domain.online);
6836 alloc_bootmem_cpumask_var(&def_root_domain.rto_mask);
6837 cpupri_init(&rd->cpupri, true);
6838 return 0;
6839 }
6840
6841 if (!alloc_cpumask_var(&rd->span, GFP_KERNEL))
6842 goto free_rd;
6843 if (!alloc_cpumask_var(&rd->online, GFP_KERNEL))
6844 goto free_span;
6845 if (!alloc_cpumask_var(&rd->rto_mask, GFP_KERNEL))
6846 goto free_online;
6847
6848 if (cpupri_init(&rd->cpupri, false) != 0)
6849 goto free_rto_mask;
6850 return 0;
6865 6851
6866 cpupri_init(&rd->cpupri); 6852free_rto_mask:
6853 free_cpumask_var(rd->rto_mask);
6854free_online:
6855 free_cpumask_var(rd->online);
6856free_span:
6857 free_cpumask_var(rd->span);
6858free_rd:
6859 kfree(rd);
6860 return -ENOMEM;
6867} 6861}
6868 6862
6869static void init_defrootdomain(void) 6863static void init_defrootdomain(void)
6870{ 6864{
6871 init_rootdomain(&def_root_domain); 6865 init_rootdomain(&def_root_domain, true);
6866
6872 atomic_set(&def_root_domain.refcount, 1); 6867 atomic_set(&def_root_domain.refcount, 1);
6873} 6868}
6874 6869
@@ -6880,7 +6875,10 @@ static struct root_domain *alloc_rootdomain(void)
6880 if (!rd) 6875 if (!rd)
6881 return NULL; 6876 return NULL;
6882 6877
6883 init_rootdomain(rd); 6878 if (init_rootdomain(rd, false) != 0) {
6879 kfree(rd);
6880 return NULL;
6881 }
6884 6882
6885 return rd; 6883 return rd;
6886} 6884}
@@ -6922,19 +6920,12 @@ cpu_attach_domain(struct sched_domain *sd, struct root_domain *rd, int cpu)
6922} 6920}
6923 6921
6924/* cpus with isolated domains */ 6922/* cpus with isolated domains */
6925static cpumask_t cpu_isolated_map = CPU_MASK_NONE; 6923static cpumask_var_t cpu_isolated_map;
6926 6924
6927/* Setup the mask of cpus configured for isolated domains */ 6925/* Setup the mask of cpus configured for isolated domains */
6928static int __init isolated_cpu_setup(char *str) 6926static int __init isolated_cpu_setup(char *str)
6929{ 6927{
6930 static int __initdata ints[NR_CPUS]; 6928 cpulist_parse(str, *cpu_isolated_map);
6931 int i;
6932
6933 str = get_options(str, ARRAY_SIZE(ints), ints);
6934 cpus_clear(cpu_isolated_map);
6935 for (i = 1; i <= ints[0]; i++)
6936 if (ints[i] < NR_CPUS)
6937 cpu_set(ints[i], cpu_isolated_map);
6938 return 1; 6929 return 1;
6939} 6930}
6940 6931
@@ -6943,42 +6934,43 @@ __setup("isolcpus=", isolated_cpu_setup);
6943/* 6934/*
6944 * init_sched_build_groups takes the cpumask we wish to span, and a pointer 6935 * init_sched_build_groups takes the cpumask we wish to span, and a pointer
6945 * to a function which identifies what group(along with sched group) a CPU 6936 * to a function which identifies what group(along with sched group) a CPU
6946 * belongs to. The return value of group_fn must be a >= 0 and < NR_CPUS 6937 * belongs to. The return value of group_fn must be a >= 0 and < nr_cpu_ids
6947 * (due to the fact that we keep track of groups covered with a cpumask_t). 6938 * (due to the fact that we keep track of groups covered with a struct cpumask).
6948 * 6939 *
6949 * init_sched_build_groups will build a circular linked list of the groups 6940 * init_sched_build_groups will build a circular linked list of the groups
6950 * covered by the given span, and will set each group's ->cpumask correctly, 6941 * covered by the given span, and will set each group's ->cpumask correctly,
6951 * and ->cpu_power to 0. 6942 * and ->cpu_power to 0.
6952 */ 6943 */
6953static void 6944static void
6954init_sched_build_groups(const cpumask_t *span, const cpumask_t *cpu_map, 6945init_sched_build_groups(const struct cpumask *span,
6955 int (*group_fn)(int cpu, const cpumask_t *cpu_map, 6946 const struct cpumask *cpu_map,
6947 int (*group_fn)(int cpu, const struct cpumask *cpu_map,
6956 struct sched_group **sg, 6948 struct sched_group **sg,
6957 cpumask_t *tmpmask), 6949 struct cpumask *tmpmask),
6958 cpumask_t *covered, cpumask_t *tmpmask) 6950 struct cpumask *covered, struct cpumask *tmpmask)
6959{ 6951{
6960 struct sched_group *first = NULL, *last = NULL; 6952 struct sched_group *first = NULL, *last = NULL;
6961 int i; 6953 int i;
6962 6954
6963 cpus_clear(*covered); 6955 cpumask_clear(covered);
6964 6956
6965 for_each_cpu_mask_nr(i, *span) { 6957 for_each_cpu(i, span) {
6966 struct sched_group *sg; 6958 struct sched_group *sg;
6967 int group = group_fn(i, cpu_map, &sg, tmpmask); 6959 int group = group_fn(i, cpu_map, &sg, tmpmask);
6968 int j; 6960 int j;
6969 6961
6970 if (cpu_isset(i, *covered)) 6962 if (cpumask_test_cpu(i, covered))
6971 continue; 6963 continue;
6972 6964
6973 cpus_clear(sg->cpumask); 6965 cpumask_clear(sched_group_cpus(sg));
6974 sg->__cpu_power = 0; 6966 sg->__cpu_power = 0;
6975 6967
6976 for_each_cpu_mask_nr(j, *span) { 6968 for_each_cpu(j, span) {
6977 if (group_fn(j, cpu_map, NULL, tmpmask) != group) 6969 if (group_fn(j, cpu_map, NULL, tmpmask) != group)
6978 continue; 6970 continue;
6979 6971
6980 cpu_set(j, *covered); 6972 cpumask_set_cpu(j, covered);
6981 cpu_set(j, sg->cpumask); 6973 cpumask_set_cpu(j, sched_group_cpus(sg));
6982 } 6974 }
6983 if (!first) 6975 if (!first)
6984 first = sg; 6976 first = sg;
@@ -7042,9 +7034,10 @@ static int find_next_best_node(int node, nodemask_t *used_nodes)
7042 * should be one that prevents unnecessary balancing, but also spreads tasks 7034 * should be one that prevents unnecessary balancing, but also spreads tasks
7043 * out optimally. 7035 * out optimally.
7044 */ 7036 */
7045static void sched_domain_node_span(int node, cpumask_t *span) 7037static void sched_domain_node_span(int node, struct cpumask *span)
7046{ 7038{
7047 nodemask_t used_nodes; 7039 nodemask_t used_nodes;
7040 /* FIXME: use cpumask_of_node() */
7048 node_to_cpumask_ptr(nodemask, node); 7041 node_to_cpumask_ptr(nodemask, node);
7049 int i; 7042 int i;
7050 7043
@@ -7066,18 +7059,33 @@ static void sched_domain_node_span(int node, cpumask_t *span)
7066int sched_smt_power_savings = 0, sched_mc_power_savings = 0; 7059int sched_smt_power_savings = 0, sched_mc_power_savings = 0;
7067 7060
7068/* 7061/*
7062 * The cpus mask in sched_group and sched_domain hangs off the end.
7063 * FIXME: use cpumask_var_t or dynamic percpu alloc to avoid wasting space
7064 * for nr_cpu_ids < CONFIG_NR_CPUS.
7065 */
7066struct static_sched_group {
7067 struct sched_group sg;
7068 DECLARE_BITMAP(cpus, CONFIG_NR_CPUS);
7069};
7070
7071struct static_sched_domain {
7072 struct sched_domain sd;
7073 DECLARE_BITMAP(span, CONFIG_NR_CPUS);
7074};
7075
7076/*
7069 * SMT sched-domains: 7077 * SMT sched-domains:
7070 */ 7078 */
7071#ifdef CONFIG_SCHED_SMT 7079#ifdef CONFIG_SCHED_SMT
7072static DEFINE_PER_CPU(struct sched_domain, cpu_domains); 7080static DEFINE_PER_CPU(struct static_sched_domain, cpu_domains);
7073static DEFINE_PER_CPU(struct sched_group, sched_group_cpus); 7081static DEFINE_PER_CPU(struct static_sched_group, sched_group_cpus);
7074 7082
7075static int 7083static int
7076cpu_to_cpu_group(int cpu, const cpumask_t *cpu_map, struct sched_group **sg, 7084cpu_to_cpu_group(int cpu, const struct cpumask *cpu_map,
7077 cpumask_t *unused) 7085 struct sched_group **sg, struct cpumask *unused)
7078{ 7086{
7079 if (sg) 7087 if (sg)
7080 *sg = &per_cpu(sched_group_cpus, cpu); 7088 *sg = &per_cpu(sched_group_cpus, cpu).sg;
7081 return cpu; 7089 return cpu;
7082} 7090}
7083#endif /* CONFIG_SCHED_SMT */ 7091#endif /* CONFIG_SCHED_SMT */
@@ -7086,56 +7094,55 @@ cpu_to_cpu_group(int cpu, const cpumask_t *cpu_map, struct sched_group **sg,
7086 * multi-core sched-domains: 7094 * multi-core sched-domains:
7087 */ 7095 */
7088#ifdef CONFIG_SCHED_MC 7096#ifdef CONFIG_SCHED_MC
7089static DEFINE_PER_CPU(struct sched_domain, core_domains); 7097static DEFINE_PER_CPU(struct static_sched_domain, core_domains);
7090static DEFINE_PER_CPU(struct sched_group, sched_group_core); 7098static DEFINE_PER_CPU(struct static_sched_group, sched_group_core);
7091#endif /* CONFIG_SCHED_MC */ 7099#endif /* CONFIG_SCHED_MC */
7092 7100
7093#if defined(CONFIG_SCHED_MC) && defined(CONFIG_SCHED_SMT) 7101#if defined(CONFIG_SCHED_MC) && defined(CONFIG_SCHED_SMT)
7094static int 7102static int
7095cpu_to_core_group(int cpu, const cpumask_t *cpu_map, struct sched_group **sg, 7103cpu_to_core_group(int cpu, const struct cpumask *cpu_map,
7096 cpumask_t *mask) 7104 struct sched_group **sg, struct cpumask *mask)
7097{ 7105{
7098 int group; 7106 int group;
7099 7107
7100 *mask = per_cpu(cpu_sibling_map, cpu); 7108 cpumask_and(mask, &per_cpu(cpu_sibling_map, cpu), cpu_map);
7101 cpus_and(*mask, *mask, *cpu_map); 7109 group = cpumask_first(mask);
7102 group = first_cpu(*mask);
7103 if (sg) 7110 if (sg)
7104 *sg = &per_cpu(sched_group_core, group); 7111 *sg = &per_cpu(sched_group_core, group).sg;
7105 return group; 7112 return group;
7106} 7113}
7107#elif defined(CONFIG_SCHED_MC) 7114#elif defined(CONFIG_SCHED_MC)
7108static int 7115static int
7109cpu_to_core_group(int cpu, const cpumask_t *cpu_map, struct sched_group **sg, 7116cpu_to_core_group(int cpu, const struct cpumask *cpu_map,
7110 cpumask_t *unused) 7117 struct sched_group **sg, struct cpumask *unused)
7111{ 7118{
7112 if (sg) 7119 if (sg)
7113 *sg = &per_cpu(sched_group_core, cpu); 7120 *sg = &per_cpu(sched_group_core, cpu).sg;
7114 return cpu; 7121 return cpu;
7115} 7122}
7116#endif 7123#endif
7117 7124
7118static DEFINE_PER_CPU(struct sched_domain, phys_domains); 7125static DEFINE_PER_CPU(struct static_sched_domain, phys_domains);
7119static DEFINE_PER_CPU(struct sched_group, sched_group_phys); 7126static DEFINE_PER_CPU(struct static_sched_group, sched_group_phys);
7120 7127
7121static int 7128static int
7122cpu_to_phys_group(int cpu, const cpumask_t *cpu_map, struct sched_group **sg, 7129cpu_to_phys_group(int cpu, const struct cpumask *cpu_map,
7123 cpumask_t *mask) 7130 struct sched_group **sg, struct cpumask *mask)
7124{ 7131{
7125 int group; 7132 int group;
7126#ifdef CONFIG_SCHED_MC 7133#ifdef CONFIG_SCHED_MC
7134 /* FIXME: Use cpu_coregroup_mask. */
7127 *mask = cpu_coregroup_map(cpu); 7135 *mask = cpu_coregroup_map(cpu);
7128 cpus_and(*mask, *mask, *cpu_map); 7136 cpus_and(*mask, *mask, *cpu_map);
7129 group = first_cpu(*mask); 7137 group = cpumask_first(mask);
7130#elif defined(CONFIG_SCHED_SMT) 7138#elif defined(CONFIG_SCHED_SMT)
7131 *mask = per_cpu(cpu_sibling_map, cpu); 7139 cpumask_and(mask, &per_cpu(cpu_sibling_map, cpu), cpu_map);
7132 cpus_and(*mask, *mask, *cpu_map); 7140 group = cpumask_first(mask);
7133 group = first_cpu(*mask);
7134#else 7141#else
7135 group = cpu; 7142 group = cpu;
7136#endif 7143#endif
7137 if (sg) 7144 if (sg)
7138 *sg = &per_cpu(sched_group_phys, group); 7145 *sg = &per_cpu(sched_group_phys, group).sg;
7139 return group; 7146 return group;
7140} 7147}
7141 7148
@@ -7149,19 +7156,21 @@ static DEFINE_PER_CPU(struct sched_domain, node_domains);
7149static struct sched_group ***sched_group_nodes_bycpu; 7156static struct sched_group ***sched_group_nodes_bycpu;
7150 7157
7151static DEFINE_PER_CPU(struct sched_domain, allnodes_domains); 7158static DEFINE_PER_CPU(struct sched_domain, allnodes_domains);
7152static DEFINE_PER_CPU(struct sched_group, sched_group_allnodes); 7159static DEFINE_PER_CPU(struct static_sched_group, sched_group_allnodes);
7153 7160
7154static int cpu_to_allnodes_group(int cpu, const cpumask_t *cpu_map, 7161static int cpu_to_allnodes_group(int cpu, const struct cpumask *cpu_map,
7155 struct sched_group **sg, cpumask_t *nodemask) 7162 struct sched_group **sg,
7163 struct cpumask *nodemask)
7156{ 7164{
7157 int group; 7165 int group;
7166 /* FIXME: use cpumask_of_node */
7167 node_to_cpumask_ptr(pnodemask, cpu_to_node(cpu));
7158 7168
7159 *nodemask = node_to_cpumask(cpu_to_node(cpu)); 7169 cpumask_and(nodemask, pnodemask, cpu_map);
7160 cpus_and(*nodemask, *nodemask, *cpu_map); 7170 group = cpumask_first(nodemask);
7161 group = first_cpu(*nodemask);
7162 7171
7163 if (sg) 7172 if (sg)
7164 *sg = &per_cpu(sched_group_allnodes, group); 7173 *sg = &per_cpu(sched_group_allnodes, group).sg;
7165 return group; 7174 return group;
7166} 7175}
7167 7176
@@ -7173,11 +7182,11 @@ static void init_numa_sched_groups_power(struct sched_group *group_head)
7173 if (!sg) 7182 if (!sg)
7174 return; 7183 return;
7175 do { 7184 do {
7176 for_each_cpu_mask_nr(j, sg->cpumask) { 7185 for_each_cpu(j, sched_group_cpus(sg)) {
7177 struct sched_domain *sd; 7186 struct sched_domain *sd;
7178 7187
7179 sd = &per_cpu(phys_domains, j); 7188 sd = &per_cpu(phys_domains, j).sd;
7180 if (j != first_cpu(sd->groups->cpumask)) { 7189 if (j != cpumask_first(sched_group_cpus(sd->groups))) {
7181 /* 7190 /*
7182 * Only add "power" once for each 7191 * Only add "power" once for each
7183 * physical package. 7192 * physical package.
@@ -7194,11 +7203,12 @@ static void init_numa_sched_groups_power(struct sched_group *group_head)
7194 7203
7195#ifdef CONFIG_NUMA 7204#ifdef CONFIG_NUMA
7196/* Free memory allocated for various sched_group structures */ 7205/* Free memory allocated for various sched_group structures */
7197static void free_sched_groups(const cpumask_t *cpu_map, cpumask_t *nodemask) 7206static void free_sched_groups(const struct cpumask *cpu_map,
7207 struct cpumask *nodemask)
7198{ 7208{
7199 int cpu, i; 7209 int cpu, i;
7200 7210
7201 for_each_cpu_mask_nr(cpu, *cpu_map) { 7211 for_each_cpu(cpu, cpu_map) {
7202 struct sched_group **sched_group_nodes 7212 struct sched_group **sched_group_nodes
7203 = sched_group_nodes_bycpu[cpu]; 7213 = sched_group_nodes_bycpu[cpu];
7204 7214
@@ -7207,10 +7217,11 @@ static void free_sched_groups(const cpumask_t *cpu_map, cpumask_t *nodemask)
7207 7217
7208 for (i = 0; i < nr_node_ids; i++) { 7218 for (i = 0; i < nr_node_ids; i++) {
7209 struct sched_group *oldsg, *sg = sched_group_nodes[i]; 7219 struct sched_group *oldsg, *sg = sched_group_nodes[i];
7220 /* FIXME: Use cpumask_of_node */
7221 node_to_cpumask_ptr(pnodemask, i);
7210 7222
7211 *nodemask = node_to_cpumask(i); 7223 cpus_and(*nodemask, *pnodemask, *cpu_map);
7212 cpus_and(*nodemask, *nodemask, *cpu_map); 7224 if (cpumask_empty(nodemask))
7213 if (cpus_empty(*nodemask))
7214 continue; 7225 continue;
7215 7226
7216 if (sg == NULL) 7227 if (sg == NULL)
@@ -7228,7 +7239,8 @@ next_sg:
7228 } 7239 }
7229} 7240}
7230#else /* !CONFIG_NUMA */ 7241#else /* !CONFIG_NUMA */
7231static void free_sched_groups(const cpumask_t *cpu_map, cpumask_t *nodemask) 7242static void free_sched_groups(const struct cpumask *cpu_map,
7243 struct cpumask *nodemask)
7232{ 7244{
7233} 7245}
7234#endif /* CONFIG_NUMA */ 7246#endif /* CONFIG_NUMA */
@@ -7254,7 +7266,7 @@ static void init_sched_groups_power(int cpu, struct sched_domain *sd)
7254 7266
7255 WARN_ON(!sd || !sd->groups); 7267 WARN_ON(!sd || !sd->groups);
7256 7268
7257 if (cpu != first_cpu(sd->groups->cpumask)) 7269 if (cpu != cpumask_first(sched_group_cpus(sd->groups)))
7258 return; 7270 return;
7259 7271
7260 child = sd->child; 7272 child = sd->child;
@@ -7319,40 +7331,6 @@ SD_INIT_FUNC(CPU)
7319 SD_INIT_FUNC(MC) 7331 SD_INIT_FUNC(MC)
7320#endif 7332#endif
7321 7333
7322/*
7323 * To minimize stack usage kmalloc room for cpumasks and share the
7324 * space as the usage in build_sched_domains() dictates. Used only
7325 * if the amount of space is significant.
7326 */
7327struct allmasks {
7328 cpumask_t tmpmask; /* make this one first */
7329 union {
7330 cpumask_t nodemask;
7331 cpumask_t this_sibling_map;
7332 cpumask_t this_core_map;
7333 };
7334 cpumask_t send_covered;
7335
7336#ifdef CONFIG_NUMA
7337 cpumask_t domainspan;
7338 cpumask_t covered;
7339 cpumask_t notcovered;
7340#endif
7341};
7342
7343#if NR_CPUS > 128
7344#define SCHED_CPUMASK_ALLOC 1
7345#define SCHED_CPUMASK_FREE(v) kfree(v)
7346#define SCHED_CPUMASK_DECLARE(v) struct allmasks *v
7347#else
7348#define SCHED_CPUMASK_ALLOC 0
7349#define SCHED_CPUMASK_FREE(v)
7350#define SCHED_CPUMASK_DECLARE(v) struct allmasks _v, *v = &_v
7351#endif
7352
7353#define SCHED_CPUMASK_VAR(v, a) cpumask_t *v = (cpumask_t *) \
7354 ((unsigned long)(a) + offsetof(struct allmasks, v))
7355
7356static int default_relax_domain_level = -1; 7334static int default_relax_domain_level = -1;
7357 7335
7358static int __init setup_relax_domain_level(char *str) 7336static int __init setup_relax_domain_level(char *str)
@@ -7392,17 +7370,38 @@ static void set_domain_attribute(struct sched_domain *sd,
7392 * Build sched domains for a given set of cpus and attach the sched domains 7370 * Build sched domains for a given set of cpus and attach the sched domains
7393 * to the individual cpus 7371 * to the individual cpus
7394 */ 7372 */
7395static int __build_sched_domains(const cpumask_t *cpu_map, 7373static int __build_sched_domains(const struct cpumask *cpu_map,
7396 struct sched_domain_attr *attr) 7374 struct sched_domain_attr *attr)
7397{ 7375{
7398 int i; 7376 int i, err = -ENOMEM;
7399 struct root_domain *rd; 7377 struct root_domain *rd;
7400 SCHED_CPUMASK_DECLARE(allmasks); 7378 cpumask_var_t nodemask, this_sibling_map, this_core_map, send_covered,
7401 cpumask_t *tmpmask; 7379 tmpmask;
7402#ifdef CONFIG_NUMA 7380#ifdef CONFIG_NUMA
7381 cpumask_var_t domainspan, covered, notcovered;
7403 struct sched_group **sched_group_nodes = NULL; 7382 struct sched_group **sched_group_nodes = NULL;
7404 int sd_allnodes = 0; 7383 int sd_allnodes = 0;
7405 7384
7385 if (!alloc_cpumask_var(&domainspan, GFP_KERNEL))
7386 goto out;
7387 if (!alloc_cpumask_var(&covered, GFP_KERNEL))
7388 goto free_domainspan;
7389 if (!alloc_cpumask_var(&notcovered, GFP_KERNEL))
7390 goto free_covered;
7391#endif
7392
7393 if (!alloc_cpumask_var(&nodemask, GFP_KERNEL))
7394 goto free_notcovered;
7395 if (!alloc_cpumask_var(&this_sibling_map, GFP_KERNEL))
7396 goto free_nodemask;
7397 if (!alloc_cpumask_var(&this_core_map, GFP_KERNEL))
7398 goto free_this_sibling_map;
7399 if (!alloc_cpumask_var(&send_covered, GFP_KERNEL))
7400 goto free_this_core_map;
7401 if (!alloc_cpumask_var(&tmpmask, GFP_KERNEL))
7402 goto free_send_covered;
7403
7404#ifdef CONFIG_NUMA
7406 /* 7405 /*
7407 * Allocate the per-node list of sched groups 7406 * Allocate the per-node list of sched groups
7408 */ 7407 */
@@ -7410,55 +7409,37 @@ static int __build_sched_domains(const cpumask_t *cpu_map,
7410 GFP_KERNEL); 7409 GFP_KERNEL);
7411 if (!sched_group_nodes) { 7410 if (!sched_group_nodes) {
7412 printk(KERN_WARNING "Can not alloc sched group node list\n"); 7411 printk(KERN_WARNING "Can not alloc sched group node list\n");
7413 return -ENOMEM; 7412 goto free_tmpmask;
7414 } 7413 }
7415#endif 7414#endif
7416 7415
7417 rd = alloc_rootdomain(); 7416 rd = alloc_rootdomain();
7418 if (!rd) { 7417 if (!rd) {
7419 printk(KERN_WARNING "Cannot alloc root domain\n"); 7418 printk(KERN_WARNING "Cannot alloc root domain\n");
7420#ifdef CONFIG_NUMA 7419 goto free_sched_groups;
7421 kfree(sched_group_nodes);
7422#endif
7423 return -ENOMEM;
7424 }
7425
7426#if SCHED_CPUMASK_ALLOC
7427 /* get space for all scratch cpumask variables */
7428 allmasks = kmalloc(sizeof(*allmasks), GFP_KERNEL);
7429 if (!allmasks) {
7430 printk(KERN_WARNING "Cannot alloc cpumask array\n");
7431 kfree(rd);
7432#ifdef CONFIG_NUMA
7433 kfree(sched_group_nodes);
7434#endif
7435 return -ENOMEM;
7436 } 7420 }
7437#endif
7438 tmpmask = (cpumask_t *)allmasks;
7439
7440 7421
7441#ifdef CONFIG_NUMA 7422#ifdef CONFIG_NUMA
7442 sched_group_nodes_bycpu[first_cpu(*cpu_map)] = sched_group_nodes; 7423 sched_group_nodes_bycpu[cpumask_first(cpu_map)] = sched_group_nodes;
7443#endif 7424#endif
7444 7425
7445 /* 7426 /*
7446 * Set up domains for cpus specified by the cpu_map. 7427 * Set up domains for cpus specified by the cpu_map.
7447 */ 7428 */
7448 for_each_cpu_mask_nr(i, *cpu_map) { 7429 for_each_cpu(i, cpu_map) {
7449 struct sched_domain *sd = NULL, *p; 7430 struct sched_domain *sd = NULL, *p;
7450 SCHED_CPUMASK_VAR(nodemask, allmasks);
7451 7431
7432 /* FIXME: use cpumask_of_node */
7452 *nodemask = node_to_cpumask(cpu_to_node(i)); 7433 *nodemask = node_to_cpumask(cpu_to_node(i));
7453 cpus_and(*nodemask, *nodemask, *cpu_map); 7434 cpus_and(*nodemask, *nodemask, *cpu_map);
7454 7435
7455#ifdef CONFIG_NUMA 7436#ifdef CONFIG_NUMA
7456 if (cpus_weight(*cpu_map) > 7437 if (cpumask_weight(cpu_map) >
7457 SD_NODES_PER_DOMAIN*cpus_weight(*nodemask)) { 7438 SD_NODES_PER_DOMAIN*cpumask_weight(nodemask)) {
7458 sd = &per_cpu(allnodes_domains, i); 7439 sd = &per_cpu(allnodes_domains, i);
7459 SD_INIT(sd, ALLNODES); 7440 SD_INIT(sd, ALLNODES);
7460 set_domain_attribute(sd, attr); 7441 set_domain_attribute(sd, attr);
7461 sd->span = *cpu_map; 7442 cpumask_copy(sched_domain_span(sd), cpu_map);
7462 cpu_to_allnodes_group(i, cpu_map, &sd->groups, tmpmask); 7443 cpu_to_allnodes_group(i, cpu_map, &sd->groups, tmpmask);
7463 p = sd; 7444 p = sd;
7464 sd_allnodes = 1; 7445 sd_allnodes = 1;
@@ -7468,18 +7449,19 @@ static int __build_sched_domains(const cpumask_t *cpu_map,
7468 sd = &per_cpu(node_domains, i); 7449 sd = &per_cpu(node_domains, i);
7469 SD_INIT(sd, NODE); 7450 SD_INIT(sd, NODE);
7470 set_domain_attribute(sd, attr); 7451 set_domain_attribute(sd, attr);
7471 sched_domain_node_span(cpu_to_node(i), &sd->span); 7452 sched_domain_node_span(cpu_to_node(i), sched_domain_span(sd));
7472 sd->parent = p; 7453 sd->parent = p;
7473 if (p) 7454 if (p)
7474 p->child = sd; 7455 p->child = sd;
7475 cpus_and(sd->span, sd->span, *cpu_map); 7456 cpumask_and(sched_domain_span(sd),
7457 sched_domain_span(sd), cpu_map);
7476#endif 7458#endif
7477 7459
7478 p = sd; 7460 p = sd;
7479 sd = &per_cpu(phys_domains, i); 7461 sd = &per_cpu(phys_domains, i).sd;
7480 SD_INIT(sd, CPU); 7462 SD_INIT(sd, CPU);
7481 set_domain_attribute(sd, attr); 7463 set_domain_attribute(sd, attr);
7482 sd->span = *nodemask; 7464 cpumask_copy(sched_domain_span(sd), nodemask);
7483 sd->parent = p; 7465 sd->parent = p;
7484 if (p) 7466 if (p)
7485 p->child = sd; 7467 p->child = sd;
@@ -7487,11 +7469,12 @@ static int __build_sched_domains(const cpumask_t *cpu_map,
7487 7469
7488#ifdef CONFIG_SCHED_MC 7470#ifdef CONFIG_SCHED_MC
7489 p = sd; 7471 p = sd;
7490 sd = &per_cpu(core_domains, i); 7472 sd = &per_cpu(core_domains, i).sd;
7491 SD_INIT(sd, MC); 7473 SD_INIT(sd, MC);
7492 set_domain_attribute(sd, attr); 7474 set_domain_attribute(sd, attr);
7493 sd->span = cpu_coregroup_map(i); 7475 *sched_domain_span(sd) = cpu_coregroup_map(i);
7494 cpus_and(sd->span, sd->span, *cpu_map); 7476 cpumask_and(sched_domain_span(sd),
7477 sched_domain_span(sd), cpu_map);
7495 sd->parent = p; 7478 sd->parent = p;
7496 p->child = sd; 7479 p->child = sd;
7497 cpu_to_core_group(i, cpu_map, &sd->groups, tmpmask); 7480 cpu_to_core_group(i, cpu_map, &sd->groups, tmpmask);
@@ -7499,11 +7482,11 @@ static int __build_sched_domains(const cpumask_t *cpu_map,
7499 7482
7500#ifdef CONFIG_SCHED_SMT 7483#ifdef CONFIG_SCHED_SMT
7501 p = sd; 7484 p = sd;
7502 sd = &per_cpu(cpu_domains, i); 7485 sd = &per_cpu(cpu_domains, i).sd;
7503 SD_INIT(sd, SIBLING); 7486 SD_INIT(sd, SIBLING);
7504 set_domain_attribute(sd, attr); 7487 set_domain_attribute(sd, attr);
7505 sd->span = per_cpu(cpu_sibling_map, i); 7488 cpumask_and(sched_domain_span(sd),
7506 cpus_and(sd->span, sd->span, *cpu_map); 7489 &per_cpu(cpu_sibling_map, i), cpu_map);
7507 sd->parent = p; 7490 sd->parent = p;
7508 p->child = sd; 7491 p->child = sd;
7509 cpu_to_cpu_group(i, cpu_map, &sd->groups, tmpmask); 7492 cpu_to_cpu_group(i, cpu_map, &sd->groups, tmpmask);
@@ -7512,13 +7495,10 @@ static int __build_sched_domains(const cpumask_t *cpu_map,
7512 7495
7513#ifdef CONFIG_SCHED_SMT 7496#ifdef CONFIG_SCHED_SMT
7514 /* Set up CPU (sibling) groups */ 7497 /* Set up CPU (sibling) groups */
7515 for_each_cpu_mask_nr(i, *cpu_map) { 7498 for_each_cpu(i, cpu_map) {
7516 SCHED_CPUMASK_VAR(this_sibling_map, allmasks); 7499 cpumask_and(this_sibling_map,
7517 SCHED_CPUMASK_VAR(send_covered, allmasks); 7500 &per_cpu(cpu_sibling_map, i), cpu_map);
7518 7501 if (i != cpumask_first(this_sibling_map))
7519 *this_sibling_map = per_cpu(cpu_sibling_map, i);
7520 cpus_and(*this_sibling_map, *this_sibling_map, *cpu_map);
7521 if (i != first_cpu(*this_sibling_map))
7522 continue; 7502 continue;
7523 7503
7524 init_sched_build_groups(this_sibling_map, cpu_map, 7504 init_sched_build_groups(this_sibling_map, cpu_map,
@@ -7529,13 +7509,11 @@ static int __build_sched_domains(const cpumask_t *cpu_map,
7529 7509
7530#ifdef CONFIG_SCHED_MC 7510#ifdef CONFIG_SCHED_MC
7531 /* Set up multi-core groups */ 7511 /* Set up multi-core groups */
7532 for_each_cpu_mask_nr(i, *cpu_map) { 7512 for_each_cpu(i, cpu_map) {
7533 SCHED_CPUMASK_VAR(this_core_map, allmasks); 7513 /* FIXME: Use cpu_coregroup_mask */
7534 SCHED_CPUMASK_VAR(send_covered, allmasks);
7535
7536 *this_core_map = cpu_coregroup_map(i); 7514 *this_core_map = cpu_coregroup_map(i);
7537 cpus_and(*this_core_map, *this_core_map, *cpu_map); 7515 cpus_and(*this_core_map, *this_core_map, *cpu_map);
7538 if (i != first_cpu(*this_core_map)) 7516 if (i != cpumask_first(this_core_map))
7539 continue; 7517 continue;
7540 7518
7541 init_sched_build_groups(this_core_map, cpu_map, 7519 init_sched_build_groups(this_core_map, cpu_map,
@@ -7546,12 +7524,10 @@ static int __build_sched_domains(const cpumask_t *cpu_map,
7546 7524
7547 /* Set up physical groups */ 7525 /* Set up physical groups */
7548 for (i = 0; i < nr_node_ids; i++) { 7526 for (i = 0; i < nr_node_ids; i++) {
7549 SCHED_CPUMASK_VAR(nodemask, allmasks); 7527 /* FIXME: Use cpumask_of_node */
7550 SCHED_CPUMASK_VAR(send_covered, allmasks);
7551
7552 *nodemask = node_to_cpumask(i); 7528 *nodemask = node_to_cpumask(i);
7553 cpus_and(*nodemask, *nodemask, *cpu_map); 7529 cpus_and(*nodemask, *nodemask, *cpu_map);
7554 if (cpus_empty(*nodemask)) 7530 if (cpumask_empty(nodemask))
7555 continue; 7531 continue;
7556 7532
7557 init_sched_build_groups(nodemask, cpu_map, 7533 init_sched_build_groups(nodemask, cpu_map,
@@ -7562,8 +7538,6 @@ static int __build_sched_domains(const cpumask_t *cpu_map,
7562#ifdef CONFIG_NUMA 7538#ifdef CONFIG_NUMA
7563 /* Set up node groups */ 7539 /* Set up node groups */
7564 if (sd_allnodes) { 7540 if (sd_allnodes) {
7565 SCHED_CPUMASK_VAR(send_covered, allmasks);
7566
7567 init_sched_build_groups(cpu_map, cpu_map, 7541 init_sched_build_groups(cpu_map, cpu_map,
7568 &cpu_to_allnodes_group, 7542 &cpu_to_allnodes_group,
7569 send_covered, tmpmask); 7543 send_covered, tmpmask);
@@ -7572,58 +7546,58 @@ static int __build_sched_domains(const cpumask_t *cpu_map,
7572 for (i = 0; i < nr_node_ids; i++) { 7546 for (i = 0; i < nr_node_ids; i++) {
7573 /* Set up node groups */ 7547 /* Set up node groups */
7574 struct sched_group *sg, *prev; 7548 struct sched_group *sg, *prev;
7575 SCHED_CPUMASK_VAR(nodemask, allmasks);
7576 SCHED_CPUMASK_VAR(domainspan, allmasks);
7577 SCHED_CPUMASK_VAR(covered, allmasks);
7578 int j; 7549 int j;
7579 7550
7551 /* FIXME: Use cpumask_of_node */
7580 *nodemask = node_to_cpumask(i); 7552 *nodemask = node_to_cpumask(i);
7581 cpus_clear(*covered); 7553 cpumask_clear(covered);
7582 7554
7583 cpus_and(*nodemask, *nodemask, *cpu_map); 7555 cpus_and(*nodemask, *nodemask, *cpu_map);
7584 if (cpus_empty(*nodemask)) { 7556 if (cpumask_empty(nodemask)) {
7585 sched_group_nodes[i] = NULL; 7557 sched_group_nodes[i] = NULL;
7586 continue; 7558 continue;
7587 } 7559 }
7588 7560
7589 sched_domain_node_span(i, domainspan); 7561 sched_domain_node_span(i, domainspan);
7590 cpus_and(*domainspan, *domainspan, *cpu_map); 7562 cpumask_and(domainspan, domainspan, cpu_map);
7591 7563
7592 sg = kmalloc_node(sizeof(struct sched_group), GFP_KERNEL, i); 7564 sg = kmalloc_node(sizeof(struct sched_group) + cpumask_size(),
7565 GFP_KERNEL, i);
7593 if (!sg) { 7566 if (!sg) {
7594 printk(KERN_WARNING "Can not alloc domain group for " 7567 printk(KERN_WARNING "Can not alloc domain group for "
7595 "node %d\n", i); 7568 "node %d\n", i);
7596 goto error; 7569 goto error;
7597 } 7570 }
7598 sched_group_nodes[i] = sg; 7571 sched_group_nodes[i] = sg;
7599 for_each_cpu_mask_nr(j, *nodemask) { 7572 for_each_cpu(j, nodemask) {
7600 struct sched_domain *sd; 7573 struct sched_domain *sd;
7601 7574
7602 sd = &per_cpu(node_domains, j); 7575 sd = &per_cpu(node_domains, j);
7603 sd->groups = sg; 7576 sd->groups = sg;
7604 } 7577 }
7605 sg->__cpu_power = 0; 7578 sg->__cpu_power = 0;
7606 sg->cpumask = *nodemask; 7579 cpumask_copy(sched_group_cpus(sg), nodemask);
7607 sg->next = sg; 7580 sg->next = sg;
7608 cpus_or(*covered, *covered, *nodemask); 7581 cpumask_or(covered, covered, nodemask);
7609 prev = sg; 7582 prev = sg;
7610 7583
7611 for (j = 0; j < nr_node_ids; j++) { 7584 for (j = 0; j < nr_node_ids; j++) {
7612 SCHED_CPUMASK_VAR(notcovered, allmasks);
7613 int n = (i + j) % nr_node_ids; 7585 int n = (i + j) % nr_node_ids;
7586 /* FIXME: Use cpumask_of_node */
7614 node_to_cpumask_ptr(pnodemask, n); 7587 node_to_cpumask_ptr(pnodemask, n);
7615 7588
7616 cpus_complement(*notcovered, *covered); 7589 cpumask_complement(notcovered, covered);
7617 cpus_and(*tmpmask, *notcovered, *cpu_map); 7590 cpumask_and(tmpmask, notcovered, cpu_map);
7618 cpus_and(*tmpmask, *tmpmask, *domainspan); 7591 cpumask_and(tmpmask, tmpmask, domainspan);
7619 if (cpus_empty(*tmpmask)) 7592 if (cpumask_empty(tmpmask))
7620 break; 7593 break;
7621 7594
7622 cpus_and(*tmpmask, *tmpmask, *pnodemask); 7595 cpumask_and(tmpmask, tmpmask, pnodemask);
7623 if (cpus_empty(*tmpmask)) 7596 if (cpumask_empty(tmpmask))
7624 continue; 7597 continue;
7625 7598
7626 sg = kmalloc_node(sizeof(struct sched_group), 7599 sg = kmalloc_node(sizeof(struct sched_group) +
7600 cpumask_size(),
7627 GFP_KERNEL, i); 7601 GFP_KERNEL, i);
7628 if (!sg) { 7602 if (!sg) {
7629 printk(KERN_WARNING 7603 printk(KERN_WARNING
@@ -7631,9 +7605,9 @@ static int __build_sched_domains(const cpumask_t *cpu_map,
7631 goto error; 7605 goto error;
7632 } 7606 }
7633 sg->__cpu_power = 0; 7607 sg->__cpu_power = 0;
7634 sg->cpumask = *tmpmask; 7608 cpumask_copy(sched_group_cpus(sg), tmpmask);
7635 sg->next = prev->next; 7609 sg->next = prev->next;
7636 cpus_or(*covered, *covered, *tmpmask); 7610 cpumask_or(covered, covered, tmpmask);
7637 prev->next = sg; 7611 prev->next = sg;
7638 prev = sg; 7612 prev = sg;
7639 } 7613 }
@@ -7642,22 +7616,22 @@ static int __build_sched_domains(const cpumask_t *cpu_map,
7642 7616
7643 /* Calculate CPU power for physical packages and nodes */ 7617 /* Calculate CPU power for physical packages and nodes */
7644#ifdef CONFIG_SCHED_SMT 7618#ifdef CONFIG_SCHED_SMT
7645 for_each_cpu_mask_nr(i, *cpu_map) { 7619 for_each_cpu(i, cpu_map) {
7646 struct sched_domain *sd = &per_cpu(cpu_domains, i); 7620 struct sched_domain *sd = &per_cpu(cpu_domains, i).sd;
7647 7621
7648 init_sched_groups_power(i, sd); 7622 init_sched_groups_power(i, sd);
7649 } 7623 }
7650#endif 7624#endif
7651#ifdef CONFIG_SCHED_MC 7625#ifdef CONFIG_SCHED_MC
7652 for_each_cpu_mask_nr(i, *cpu_map) { 7626 for_each_cpu(i, cpu_map) {
7653 struct sched_domain *sd = &per_cpu(core_domains, i); 7627 struct sched_domain *sd = &per_cpu(core_domains, i).sd;
7654 7628
7655 init_sched_groups_power(i, sd); 7629 init_sched_groups_power(i, sd);
7656 } 7630 }
7657#endif 7631#endif
7658 7632
7659 for_each_cpu_mask_nr(i, *cpu_map) { 7633 for_each_cpu(i, cpu_map) {
7660 struct sched_domain *sd = &per_cpu(phys_domains, i); 7634 struct sched_domain *sd = &per_cpu(phys_domains, i).sd;
7661 7635
7662 init_sched_groups_power(i, sd); 7636 init_sched_groups_power(i, sd);
7663 } 7637 }
@@ -7669,53 +7643,78 @@ static int __build_sched_domains(const cpumask_t *cpu_map,
7669 if (sd_allnodes) { 7643 if (sd_allnodes) {
7670 struct sched_group *sg; 7644 struct sched_group *sg;
7671 7645
7672 cpu_to_allnodes_group(first_cpu(*cpu_map), cpu_map, &sg, 7646 cpu_to_allnodes_group(cpumask_first(cpu_map), cpu_map, &sg,
7673 tmpmask); 7647 tmpmask);
7674 init_numa_sched_groups_power(sg); 7648 init_numa_sched_groups_power(sg);
7675 } 7649 }
7676#endif 7650#endif
7677 7651
7678 /* Attach the domains */ 7652 /* Attach the domains */
7679 for_each_cpu_mask_nr(i, *cpu_map) { 7653 for_each_cpu(i, cpu_map) {
7680 struct sched_domain *sd; 7654 struct sched_domain *sd;
7681#ifdef CONFIG_SCHED_SMT 7655#ifdef CONFIG_SCHED_SMT
7682 sd = &per_cpu(cpu_domains, i); 7656 sd = &per_cpu(cpu_domains, i).sd;
7683#elif defined(CONFIG_SCHED_MC) 7657#elif defined(CONFIG_SCHED_MC)
7684 sd = &per_cpu(core_domains, i); 7658 sd = &per_cpu(core_domains, i).sd;
7685#else 7659#else
7686 sd = &per_cpu(phys_domains, i); 7660 sd = &per_cpu(phys_domains, i).sd;
7687#endif 7661#endif
7688 cpu_attach_domain(sd, rd, i); 7662 cpu_attach_domain(sd, rd, i);
7689 } 7663 }
7690 7664
7691 SCHED_CPUMASK_FREE((void *)allmasks); 7665 err = 0;
7692 return 0; 7666
7667free_tmpmask:
7668 free_cpumask_var(tmpmask);
7669free_send_covered:
7670 free_cpumask_var(send_covered);
7671free_this_core_map:
7672 free_cpumask_var(this_core_map);
7673free_this_sibling_map:
7674 free_cpumask_var(this_sibling_map);
7675free_nodemask:
7676 free_cpumask_var(nodemask);
7677free_notcovered:
7678#ifdef CONFIG_NUMA
7679 free_cpumask_var(notcovered);
7680free_covered:
7681 free_cpumask_var(covered);
7682free_domainspan:
7683 free_cpumask_var(domainspan);
7684out:
7685#endif
7686 return err;
7687
7688free_sched_groups:
7689#ifdef CONFIG_NUMA
7690 kfree(sched_group_nodes);
7691#endif
7692 goto free_tmpmask;
7693 7693
7694#ifdef CONFIG_NUMA 7694#ifdef CONFIG_NUMA
7695error: 7695error:
7696 free_sched_groups(cpu_map, tmpmask); 7696 free_sched_groups(cpu_map, tmpmask);
7697 SCHED_CPUMASK_FREE((void *)allmasks); 7697 free_rootdomain(rd);
7698 kfree(rd); 7698 goto free_tmpmask;
7699 return -ENOMEM;
7700#endif 7699#endif
7701} 7700}
7702 7701
7703static int build_sched_domains(const cpumask_t *cpu_map) 7702static int build_sched_domains(const struct cpumask *cpu_map)
7704{ 7703{
7705 return __build_sched_domains(cpu_map, NULL); 7704 return __build_sched_domains(cpu_map, NULL);
7706} 7705}
7707 7706
7708static cpumask_t *doms_cur; /* current sched domains */ 7707static struct cpumask *doms_cur; /* current sched domains */
7709static int ndoms_cur; /* number of sched domains in 'doms_cur' */ 7708static int ndoms_cur; /* number of sched domains in 'doms_cur' */
7710static struct sched_domain_attr *dattr_cur; 7709static struct sched_domain_attr *dattr_cur;
7711 /* attribues of custom domains in 'doms_cur' */ 7710 /* attribues of custom domains in 'doms_cur' */
7712 7711
7713/* 7712/*
7714 * Special case: If a kmalloc of a doms_cur partition (array of 7713 * Special case: If a kmalloc of a doms_cur partition (array of
7715 * cpumask_t) fails, then fallback to a single sched domain, 7714 * cpumask) fails, then fallback to a single sched domain,
7716 * as determined by the single cpumask_t fallback_doms. 7715 * as determined by the single cpumask fallback_doms.
7717 */ 7716 */
7718static cpumask_t fallback_doms; 7717static cpumask_var_t fallback_doms;
7719 7718
7720void __attribute__((weak)) arch_update_cpu_topology(void) 7719void __attribute__((weak)) arch_update_cpu_topology(void)
7721{ 7720{
@@ -7726,16 +7725,16 @@ void __attribute__((weak)) arch_update_cpu_topology(void)
7726 * For now this just excludes isolated cpus, but could be used to 7725 * For now this just excludes isolated cpus, but could be used to
7727 * exclude other special cases in the future. 7726 * exclude other special cases in the future.
7728 */ 7727 */
7729static int arch_init_sched_domains(const cpumask_t *cpu_map) 7728static int arch_init_sched_domains(const struct cpumask *cpu_map)
7730{ 7729{
7731 int err; 7730 int err;
7732 7731
7733 arch_update_cpu_topology(); 7732 arch_update_cpu_topology();
7734 ndoms_cur = 1; 7733 ndoms_cur = 1;
7735 doms_cur = kmalloc(sizeof(cpumask_t), GFP_KERNEL); 7734 doms_cur = kmalloc(cpumask_size(), GFP_KERNEL);
7736 if (!doms_cur) 7735 if (!doms_cur)
7737 doms_cur = &fallback_doms; 7736 doms_cur = fallback_doms;
7738 cpus_andnot(*doms_cur, *cpu_map, cpu_isolated_map); 7737 cpumask_andnot(doms_cur, cpu_map, cpu_isolated_map);
7739 dattr_cur = NULL; 7738 dattr_cur = NULL;
7740 err = build_sched_domains(doms_cur); 7739 err = build_sched_domains(doms_cur);
7741 register_sched_domain_sysctl(); 7740 register_sched_domain_sysctl();
@@ -7743,8 +7742,8 @@ static int arch_init_sched_domains(const cpumask_t *cpu_map)
7743 return err; 7742 return err;
7744} 7743}
7745 7744
7746static void arch_destroy_sched_domains(const cpumask_t *cpu_map, 7745static void arch_destroy_sched_domains(const struct cpumask *cpu_map,
7747 cpumask_t *tmpmask) 7746 struct cpumask *tmpmask)
7748{ 7747{
7749 free_sched_groups(cpu_map, tmpmask); 7748 free_sched_groups(cpu_map, tmpmask);
7750} 7749}
@@ -7753,17 +7752,16 @@ static void arch_destroy_sched_domains(const cpumask_t *cpu_map,
7753 * Detach sched domains from a group of cpus specified in cpu_map 7752 * Detach sched domains from a group of cpus specified in cpu_map
7754 * These cpus will now be attached to the NULL domain 7753 * These cpus will now be attached to the NULL domain
7755 */ 7754 */
7756static void detach_destroy_domains(const cpumask_t *cpu_map) 7755static void detach_destroy_domains(const struct cpumask *cpu_map)
7757{ 7756{
7758 cpumask_t tmpmask; 7757 /* Save because hotplug lock held. */
7758 static DECLARE_BITMAP(tmpmask, CONFIG_NR_CPUS);
7759 int i; 7759 int i;
7760 7760
7761 unregister_sched_domain_sysctl(); 7761 for_each_cpu(i, cpu_map)
7762
7763 for_each_cpu_mask_nr(i, *cpu_map)
7764 cpu_attach_domain(NULL, &def_root_domain, i); 7762 cpu_attach_domain(NULL, &def_root_domain, i);
7765 synchronize_sched(); 7763 synchronize_sched();
7766 arch_destroy_sched_domains(cpu_map, &tmpmask); 7764 arch_destroy_sched_domains(cpu_map, to_cpumask(tmpmask));
7767} 7765}
7768 7766
7769/* handle null as "default" */ 7767/* handle null as "default" */
@@ -7788,7 +7786,7 @@ static int dattrs_equal(struct sched_domain_attr *cur, int idx_cur,
7788 * doms_new[] to the current sched domain partitioning, doms_cur[]. 7786 * doms_new[] to the current sched domain partitioning, doms_cur[].
7789 * It destroys each deleted domain and builds each new domain. 7787 * It destroys each deleted domain and builds each new domain.
7790 * 7788 *
7791 * 'doms_new' is an array of cpumask_t's of length 'ndoms_new'. 7789 * 'doms_new' is an array of cpumask's of length 'ndoms_new'.
7792 * The masks don't intersect (don't overlap.) We should setup one 7790 * The masks don't intersect (don't overlap.) We should setup one
7793 * sched domain for each mask. CPUs not in any of the cpumasks will 7791 * sched domain for each mask. CPUs not in any of the cpumasks will
7794 * not be load balanced. If the same cpumask appears both in the 7792 * not be load balanced. If the same cpumask appears both in the
@@ -7802,13 +7800,14 @@ static int dattrs_equal(struct sched_domain_attr *cur, int idx_cur,
7802 * the single partition 'fallback_doms', it also forces the domains 7800 * the single partition 'fallback_doms', it also forces the domains
7803 * to be rebuilt. 7801 * to be rebuilt.
7804 * 7802 *
7805 * If doms_new == NULL it will be replaced with cpu_online_map. 7803 * If doms_new == NULL it will be replaced with cpu_online_mask.
7806 * ndoms_new == 0 is a special case for destroying existing domains, 7804 * ndoms_new == 0 is a special case for destroying existing domains,
7807 * and it will not create the default domain. 7805 * and it will not create the default domain.
7808 * 7806 *
7809 * Call with hotplug lock held 7807 * Call with hotplug lock held
7810 */ 7808 */
7811void partition_sched_domains(int ndoms_new, cpumask_t *doms_new, 7809/* FIXME: Change to struct cpumask *doms_new[] */
7810void partition_sched_domains(int ndoms_new, struct cpumask *doms_new,
7812 struct sched_domain_attr *dattr_new) 7811 struct sched_domain_attr *dattr_new)
7813{ 7812{
7814 int i, j, n; 7813 int i, j, n;
@@ -7823,7 +7822,7 @@ void partition_sched_domains(int ndoms_new, cpumask_t *doms_new,
7823 /* Destroy deleted domains */ 7822 /* Destroy deleted domains */
7824 for (i = 0; i < ndoms_cur; i++) { 7823 for (i = 0; i < ndoms_cur; i++) {
7825 for (j = 0; j < n; j++) { 7824 for (j = 0; j < n; j++) {
7826 if (cpus_equal(doms_cur[i], doms_new[j]) 7825 if (cpumask_equal(&doms_cur[i], &doms_new[j])
7827 && dattrs_equal(dattr_cur, i, dattr_new, j)) 7826 && dattrs_equal(dattr_cur, i, dattr_new, j))
7828 goto match1; 7827 goto match1;
7829 } 7828 }
@@ -7835,15 +7834,15 @@ match1:
7835 7834
7836 if (doms_new == NULL) { 7835 if (doms_new == NULL) {
7837 ndoms_cur = 0; 7836 ndoms_cur = 0;
7838 doms_new = &fallback_doms; 7837 doms_new = fallback_doms;
7839 cpus_andnot(doms_new[0], cpu_online_map, cpu_isolated_map); 7838 cpumask_andnot(&doms_new[0], cpu_online_mask, cpu_isolated_map);
7840 dattr_new = NULL; 7839 WARN_ON_ONCE(dattr_new);
7841 } 7840 }
7842 7841
7843 /* Build new domains */ 7842 /* Build new domains */
7844 for (i = 0; i < ndoms_new; i++) { 7843 for (i = 0; i < ndoms_new; i++) {
7845 for (j = 0; j < ndoms_cur; j++) { 7844 for (j = 0; j < ndoms_cur; j++) {
7846 if (cpus_equal(doms_new[i], doms_cur[j]) 7845 if (cpumask_equal(&doms_new[i], &doms_cur[j])
7847 && dattrs_equal(dattr_new, i, dattr_cur, j)) 7846 && dattrs_equal(dattr_new, i, dattr_cur, j))
7848 goto match2; 7847 goto match2;
7849 } 7848 }
@@ -7855,7 +7854,7 @@ match2:
7855 } 7854 }
7856 7855
7857 /* Remember the new sched domains */ 7856 /* Remember the new sched domains */
7858 if (doms_cur != &fallback_doms) 7857 if (doms_cur != fallback_doms)
7859 kfree(doms_cur); 7858 kfree(doms_cur);
7860 kfree(dattr_cur); /* kfree(NULL) is safe */ 7859 kfree(dattr_cur); /* kfree(NULL) is safe */
7861 doms_cur = doms_new; 7860 doms_cur = doms_new;
@@ -7995,7 +7994,9 @@ static int update_runtime(struct notifier_block *nfb,
7995 7994
7996void __init sched_init_smp(void) 7995void __init sched_init_smp(void)
7997{ 7996{
7998 cpumask_t non_isolated_cpus; 7997 cpumask_var_t non_isolated_cpus;
7998
7999 alloc_cpumask_var(&non_isolated_cpus, GFP_KERNEL);
7999 8000
8000#if defined(CONFIG_NUMA) 8001#if defined(CONFIG_NUMA)
8001 sched_group_nodes_bycpu = kzalloc(nr_cpu_ids * sizeof(void **), 8002 sched_group_nodes_bycpu = kzalloc(nr_cpu_ids * sizeof(void **),
@@ -8004,10 +8005,10 @@ void __init sched_init_smp(void)
8004#endif 8005#endif
8005 get_online_cpus(); 8006 get_online_cpus();
8006 mutex_lock(&sched_domains_mutex); 8007 mutex_lock(&sched_domains_mutex);
8007 arch_init_sched_domains(&cpu_online_map); 8008 arch_init_sched_domains(cpu_online_mask);
8008 cpus_andnot(non_isolated_cpus, cpu_possible_map, cpu_isolated_map); 8009 cpumask_andnot(non_isolated_cpus, cpu_possible_mask, cpu_isolated_map);
8009 if (cpus_empty(non_isolated_cpus)) 8010 if (cpumask_empty(non_isolated_cpus))
8010 cpu_set(smp_processor_id(), non_isolated_cpus); 8011 cpumask_set_cpu(smp_processor_id(), non_isolated_cpus);
8011 mutex_unlock(&sched_domains_mutex); 8012 mutex_unlock(&sched_domains_mutex);
8012 put_online_cpus(); 8013 put_online_cpus();
8013 8014
@@ -8022,9 +8023,13 @@ void __init sched_init_smp(void)
8022 init_hrtick(); 8023 init_hrtick();
8023 8024
8024 /* Move init over to a non-isolated CPU */ 8025 /* Move init over to a non-isolated CPU */
8025 if (set_cpus_allowed_ptr(current, &non_isolated_cpus) < 0) 8026 if (set_cpus_allowed_ptr(current, non_isolated_cpus) < 0)
8026 BUG(); 8027 BUG();
8027 sched_init_granularity(); 8028 sched_init_granularity();
8029 free_cpumask_var(non_isolated_cpus);
8030
8031 alloc_cpumask_var(&fallback_doms, GFP_KERNEL);
8032 init_sched_rt_class();
8028} 8033}
8029#else 8034#else
8030void __init sched_init_smp(void) 8035void __init sched_init_smp(void)
@@ -8339,6 +8344,15 @@ void __init sched_init(void)
8339 */ 8344 */
8340 current->sched_class = &fair_sched_class; 8345 current->sched_class = &fair_sched_class;
8341 8346
8347 /* Allocate the nohz_cpu_mask if CONFIG_CPUMASK_OFFSTACK */
8348 alloc_bootmem_cpumask_var(&nohz_cpu_mask);
8349#ifdef CONFIG_SMP
8350#ifdef CONFIG_NO_HZ
8351 alloc_bootmem_cpumask_var(&nohz.cpu_mask);
8352#endif
8353 alloc_bootmem_cpumask_var(&cpu_isolated_map);
8354#endif /* SMP */
8355
8342 scheduler_running = 1; 8356 scheduler_running = 1;
8343} 8357}
8344 8358
@@ -8497,7 +8511,7 @@ static
8497int alloc_fair_sched_group(struct task_group *tg, struct task_group *parent) 8511int alloc_fair_sched_group(struct task_group *tg, struct task_group *parent)
8498{ 8512{
8499 struct cfs_rq *cfs_rq; 8513 struct cfs_rq *cfs_rq;
8500 struct sched_entity *se, *parent_se; 8514 struct sched_entity *se;
8501 struct rq *rq; 8515 struct rq *rq;
8502 int i; 8516 int i;
8503 8517
@@ -8513,18 +8527,17 @@ int alloc_fair_sched_group(struct task_group *tg, struct task_group *parent)
8513 for_each_possible_cpu(i) { 8527 for_each_possible_cpu(i) {
8514 rq = cpu_rq(i); 8528 rq = cpu_rq(i);
8515 8529
8516 cfs_rq = kmalloc_node(sizeof(struct cfs_rq), 8530 cfs_rq = kzalloc_node(sizeof(struct cfs_rq),
8517 GFP_KERNEL|__GFP_ZERO, cpu_to_node(i)); 8531 GFP_KERNEL, cpu_to_node(i));
8518 if (!cfs_rq) 8532 if (!cfs_rq)
8519 goto err; 8533 goto err;
8520 8534
8521 se = kmalloc_node(sizeof(struct sched_entity), 8535 se = kzalloc_node(sizeof(struct sched_entity),
8522 GFP_KERNEL|__GFP_ZERO, cpu_to_node(i)); 8536 GFP_KERNEL, cpu_to_node(i));
8523 if (!se) 8537 if (!se)
8524 goto err; 8538 goto err;
8525 8539
8526 parent_se = parent ? parent->se[i] : NULL; 8540 init_tg_cfs_entry(tg, cfs_rq, se, i, 0, parent->se[i]);
8527 init_tg_cfs_entry(tg, cfs_rq, se, i, 0, parent_se);
8528 } 8541 }
8529 8542
8530 return 1; 8543 return 1;
@@ -8585,7 +8598,7 @@ static
8585int alloc_rt_sched_group(struct task_group *tg, struct task_group *parent) 8598int alloc_rt_sched_group(struct task_group *tg, struct task_group *parent)
8586{ 8599{
8587 struct rt_rq *rt_rq; 8600 struct rt_rq *rt_rq;
8588 struct sched_rt_entity *rt_se, *parent_se; 8601 struct sched_rt_entity *rt_se;
8589 struct rq *rq; 8602 struct rq *rq;
8590 int i; 8603 int i;
8591 8604
@@ -8602,18 +8615,17 @@ int alloc_rt_sched_group(struct task_group *tg, struct task_group *parent)
8602 for_each_possible_cpu(i) { 8615 for_each_possible_cpu(i) {
8603 rq = cpu_rq(i); 8616 rq = cpu_rq(i);
8604 8617
8605 rt_rq = kmalloc_node(sizeof(struct rt_rq), 8618 rt_rq = kzalloc_node(sizeof(struct rt_rq),
8606 GFP_KERNEL|__GFP_ZERO, cpu_to_node(i)); 8619 GFP_KERNEL, cpu_to_node(i));
8607 if (!rt_rq) 8620 if (!rt_rq)
8608 goto err; 8621 goto err;
8609 8622
8610 rt_se = kmalloc_node(sizeof(struct sched_rt_entity), 8623 rt_se = kzalloc_node(sizeof(struct sched_rt_entity),
8611 GFP_KERNEL|__GFP_ZERO, cpu_to_node(i)); 8624 GFP_KERNEL, cpu_to_node(i));
8612 if (!rt_se) 8625 if (!rt_se)
8613 goto err; 8626 goto err;
8614 8627
8615 parent_se = parent ? parent->rt_se[i] : NULL; 8628 init_tg_rt_entry(tg, rt_rq, rt_se, i, 0, parent->rt_se[i]);
8616 init_tg_rt_entry(tg, rt_rq, rt_se, i, 0, parent_se);
8617 } 8629 }
8618 8630
8619 return 1; 8631 return 1;
@@ -9256,11 +9268,12 @@ struct cgroup_subsys cpu_cgroup_subsys = {
9256 * (balbir@in.ibm.com). 9268 * (balbir@in.ibm.com).
9257 */ 9269 */
9258 9270
9259/* track cpu usage of a group of tasks */ 9271/* track cpu usage of a group of tasks and its child groups */
9260struct cpuacct { 9272struct cpuacct {
9261 struct cgroup_subsys_state css; 9273 struct cgroup_subsys_state css;
9262 /* cpuusage holds pointer to a u64-type object on every cpu */ 9274 /* cpuusage holds pointer to a u64-type object on every cpu */
9263 u64 *cpuusage; 9275 u64 *cpuusage;
9276 struct cpuacct *parent;
9264}; 9277};
9265 9278
9266struct cgroup_subsys cpuacct_subsys; 9279struct cgroup_subsys cpuacct_subsys;
@@ -9294,6 +9307,9 @@ static struct cgroup_subsys_state *cpuacct_create(
9294 return ERR_PTR(-ENOMEM); 9307 return ERR_PTR(-ENOMEM);
9295 } 9308 }
9296 9309
9310 if (cgrp->parent)
9311 ca->parent = cgroup_ca(cgrp->parent);
9312
9297 return &ca->css; 9313 return &ca->css;
9298} 9314}
9299 9315
@@ -9373,14 +9389,16 @@ static int cpuacct_populate(struct cgroup_subsys *ss, struct cgroup *cgrp)
9373static void cpuacct_charge(struct task_struct *tsk, u64 cputime) 9389static void cpuacct_charge(struct task_struct *tsk, u64 cputime)
9374{ 9390{
9375 struct cpuacct *ca; 9391 struct cpuacct *ca;
9392 int cpu;
9376 9393
9377 if (!cpuacct_subsys.active) 9394 if (!cpuacct_subsys.active)
9378 return; 9395 return;
9379 9396
9397 cpu = task_cpu(tsk);
9380 ca = task_ca(tsk); 9398 ca = task_ca(tsk);
9381 if (ca) {
9382 u64 *cpuusage = percpu_ptr(ca->cpuusage, task_cpu(tsk));
9383 9399
9400 for (; ca; ca = ca->parent) {
9401 u64 *cpuusage = percpu_ptr(ca->cpuusage, cpu);
9384 *cpuusage += cputime; 9402 *cpuusage += cputime;
9385 } 9403 }
9386} 9404}