aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/sched.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/sched.c')
-rw-r--r--kernel/sched.c897
1 files changed, 484 insertions, 413 deletions
diff --git a/kernel/sched.c b/kernel/sched.c
index ad7b93be5691..e00c92d22655 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -118,6 +118,12 @@
118 */ 118 */
119#define RUNTIME_INF ((u64)~0ULL) 119#define RUNTIME_INF ((u64)~0ULL)
120 120
121DEFINE_TRACE(sched_wait_task);
122DEFINE_TRACE(sched_wakeup);
123DEFINE_TRACE(sched_wakeup_new);
124DEFINE_TRACE(sched_switch);
125DEFINE_TRACE(sched_migrate_task);
126
121#ifdef CONFIG_SMP 127#ifdef CONFIG_SMP
122/* 128/*
123 * Divide a load by a sched group cpu_power : (load / sg->__cpu_power) 129 * Divide a load by a sched group cpu_power : (load / sg->__cpu_power)
@@ -491,14 +497,14 @@ struct rt_rq {
491 */ 497 */
492struct root_domain { 498struct root_domain {
493 atomic_t refcount; 499 atomic_t refcount;
494 cpumask_t span; 500 cpumask_var_t span;
495 cpumask_t online; 501 cpumask_var_t online;
496 502
497 /* 503 /*
498 * The "RT overload" flag: it gets set if a CPU has more than 504 * The "RT overload" flag: it gets set if a CPU has more than
499 * one runnable RT task. 505 * one runnable RT task.
500 */ 506 */
501 cpumask_t rto_mask; 507 cpumask_var_t rto_mask;
502 atomic_t rto_count; 508 atomic_t rto_count;
503#ifdef CONFIG_SMP 509#ifdef CONFIG_SMP
504 struct cpupri cpupri; 510 struct cpupri cpupri;
@@ -1506,7 +1512,7 @@ static int tg_shares_up(struct task_group *tg, void *data)
1506 struct sched_domain *sd = data; 1512 struct sched_domain *sd = data;
1507 int i; 1513 int i;
1508 1514
1509 for_each_cpu_mask(i, sd->span) { 1515 for_each_cpu(i, sched_domain_span(sd)) {
1510 /* 1516 /*
1511 * If there are currently no tasks on the cpu pretend there 1517 * If there are currently no tasks on the cpu pretend there
1512 * is one of average load so that when a new task gets to 1518 * is one of average load so that when a new task gets to
@@ -1527,7 +1533,7 @@ static int tg_shares_up(struct task_group *tg, void *data)
1527 if (!sd->parent || !(sd->parent->flags & SD_LOAD_BALANCE)) 1533 if (!sd->parent || !(sd->parent->flags & SD_LOAD_BALANCE))
1528 shares = tg->shares; 1534 shares = tg->shares;
1529 1535
1530 for_each_cpu_mask(i, sd->span) 1536 for_each_cpu(i, sched_domain_span(sd))
1531 update_group_shares_cpu(tg, i, shares, rq_weight); 1537 update_group_shares_cpu(tg, i, shares, rq_weight);
1532 1538
1533 return 0; 1539 return 0;
@@ -2091,15 +2097,17 @@ find_idlest_group(struct sched_domain *sd, struct task_struct *p, int this_cpu)
2091 int i; 2097 int i;
2092 2098
2093 /* Skip over this group if it has no CPUs allowed */ 2099 /* Skip over this group if it has no CPUs allowed */
2094 if (!cpus_intersects(group->cpumask, p->cpus_allowed)) 2100 if (!cpumask_intersects(sched_group_cpus(group),
2101 &p->cpus_allowed))
2095 continue; 2102 continue;
2096 2103
2097 local_group = cpu_isset(this_cpu, group->cpumask); 2104 local_group = cpumask_test_cpu(this_cpu,
2105 sched_group_cpus(group));
2098 2106
2099 /* Tally up the load of all CPUs in the group */ 2107 /* Tally up the load of all CPUs in the group */
2100 avg_load = 0; 2108 avg_load = 0;
2101 2109
2102 for_each_cpu_mask_nr(i, group->cpumask) { 2110 for_each_cpu(i, sched_group_cpus(group)) {
2103 /* Bias balancing toward cpus of our domain */ 2111 /* Bias balancing toward cpus of our domain */
2104 if (local_group) 2112 if (local_group)
2105 load = source_load(i, load_idx); 2113 load = source_load(i, load_idx);
@@ -2131,17 +2139,14 @@ find_idlest_group(struct sched_domain *sd, struct task_struct *p, int this_cpu)
2131 * find_idlest_cpu - find the idlest cpu among the cpus in group. 2139 * find_idlest_cpu - find the idlest cpu among the cpus in group.
2132 */ 2140 */
2133static int 2141static int
2134find_idlest_cpu(struct sched_group *group, struct task_struct *p, int this_cpu, 2142find_idlest_cpu(struct sched_group *group, struct task_struct *p, int this_cpu)
2135 cpumask_t *tmp)
2136{ 2143{
2137 unsigned long load, min_load = ULONG_MAX; 2144 unsigned long load, min_load = ULONG_MAX;
2138 int idlest = -1; 2145 int idlest = -1;
2139 int i; 2146 int i;
2140 2147
2141 /* Traverse only the allowed CPUs */ 2148 /* Traverse only the allowed CPUs */
2142 cpus_and(*tmp, group->cpumask, p->cpus_allowed); 2149 for_each_cpu_and(i, sched_group_cpus(group), &p->cpus_allowed) {
2143
2144 for_each_cpu_mask_nr(i, *tmp) {
2145 load = weighted_cpuload(i); 2150 load = weighted_cpuload(i);
2146 2151
2147 if (load < min_load || (load == min_load && i == this_cpu)) { 2152 if (load < min_load || (load == min_load && i == this_cpu)) {
@@ -2183,7 +2188,6 @@ static int sched_balance_self(int cpu, int flag)
2183 update_shares(sd); 2188 update_shares(sd);
2184 2189
2185 while (sd) { 2190 while (sd) {
2186 cpumask_t span, tmpmask;
2187 struct sched_group *group; 2191 struct sched_group *group;
2188 int new_cpu, weight; 2192 int new_cpu, weight;
2189 2193
@@ -2192,14 +2196,13 @@ static int sched_balance_self(int cpu, int flag)
2192 continue; 2196 continue;
2193 } 2197 }
2194 2198
2195 span = sd->span;
2196 group = find_idlest_group(sd, t, cpu); 2199 group = find_idlest_group(sd, t, cpu);
2197 if (!group) { 2200 if (!group) {
2198 sd = sd->child; 2201 sd = sd->child;
2199 continue; 2202 continue;
2200 } 2203 }
2201 2204
2202 new_cpu = find_idlest_cpu(group, t, cpu, &tmpmask); 2205 new_cpu = find_idlest_cpu(group, t, cpu);
2203 if (new_cpu == -1 || new_cpu == cpu) { 2206 if (new_cpu == -1 || new_cpu == cpu) {
2204 /* Now try balancing at a lower domain level of cpu */ 2207 /* Now try balancing at a lower domain level of cpu */
2205 sd = sd->child; 2208 sd = sd->child;
@@ -2208,10 +2211,10 @@ static int sched_balance_self(int cpu, int flag)
2208 2211
2209 /* Now try balancing at a lower domain level of new_cpu */ 2212 /* Now try balancing at a lower domain level of new_cpu */
2210 cpu = new_cpu; 2213 cpu = new_cpu;
2214 weight = cpumask_weight(sched_domain_span(sd));
2211 sd = NULL; 2215 sd = NULL;
2212 weight = cpus_weight(span);
2213 for_each_domain(cpu, tmp) { 2216 for_each_domain(cpu, tmp) {
2214 if (weight <= cpus_weight(tmp->span)) 2217 if (weight <= cpumask_weight(sched_domain_span(tmp)))
2215 break; 2218 break;
2216 if (tmp->flags & flag) 2219 if (tmp->flags & flag)
2217 sd = tmp; 2220 sd = tmp;
@@ -2256,7 +2259,7 @@ static int try_to_wake_up(struct task_struct *p, unsigned int state, int sync)
2256 cpu = task_cpu(p); 2259 cpu = task_cpu(p);
2257 2260
2258 for_each_domain(this_cpu, sd) { 2261 for_each_domain(this_cpu, sd) {
2259 if (cpu_isset(cpu, sd->span)) { 2262 if (cpumask_test_cpu(cpu, sched_domain_span(sd))) {
2260 update_shares(sd); 2263 update_shares(sd);
2261 break; 2264 break;
2262 } 2265 }
@@ -2304,7 +2307,7 @@ static int try_to_wake_up(struct task_struct *p, unsigned int state, int sync)
2304 else { 2307 else {
2305 struct sched_domain *sd; 2308 struct sched_domain *sd;
2306 for_each_domain(this_cpu, sd) { 2309 for_each_domain(this_cpu, sd) {
2307 if (cpu_isset(cpu, sd->span)) { 2310 if (cpumask_test_cpu(cpu, sched_domain_span(sd))) {
2308 schedstat_inc(sd, ttwu_wake_remote); 2311 schedstat_inc(sd, ttwu_wake_remote);
2309 break; 2312 break;
2310 } 2313 }
@@ -2836,7 +2839,7 @@ static void sched_migrate_task(struct task_struct *p, int dest_cpu)
2836 struct rq *rq; 2839 struct rq *rq;
2837 2840
2838 rq = task_rq_lock(p, &flags); 2841 rq = task_rq_lock(p, &flags);
2839 if (!cpu_isset(dest_cpu, p->cpus_allowed) 2842 if (!cpumask_test_cpu(dest_cpu, &p->cpus_allowed)
2840 || unlikely(!cpu_active(dest_cpu))) 2843 || unlikely(!cpu_active(dest_cpu)))
2841 goto out; 2844 goto out;
2842 2845
@@ -2902,7 +2905,7 @@ int can_migrate_task(struct task_struct *p, struct rq *rq, int this_cpu,
2902 * 2) cannot be migrated to this CPU due to cpus_allowed, or 2905 * 2) cannot be migrated to this CPU due to cpus_allowed, or
2903 * 3) are cache-hot on their current CPU. 2906 * 3) are cache-hot on their current CPU.
2904 */ 2907 */
2905 if (!cpu_isset(this_cpu, p->cpus_allowed)) { 2908 if (!cpumask_test_cpu(this_cpu, &p->cpus_allowed)) {
2906 schedstat_inc(p, se.nr_failed_migrations_affine); 2909 schedstat_inc(p, se.nr_failed_migrations_affine);
2907 return 0; 2910 return 0;
2908 } 2911 }
@@ -3077,7 +3080,7 @@ static int move_one_task(struct rq *this_rq, int this_cpu, struct rq *busiest,
3077static struct sched_group * 3080static struct sched_group *
3078find_busiest_group(struct sched_domain *sd, int this_cpu, 3081find_busiest_group(struct sched_domain *sd, int this_cpu,
3079 unsigned long *imbalance, enum cpu_idle_type idle, 3082 unsigned long *imbalance, enum cpu_idle_type idle,
3080 int *sd_idle, const cpumask_t *cpus, int *balance) 3083 int *sd_idle, const struct cpumask *cpus, int *balance)
3081{ 3084{
3082 struct sched_group *busiest = NULL, *this = NULL, *group = sd->groups; 3085 struct sched_group *busiest = NULL, *this = NULL, *group = sd->groups;
3083 unsigned long max_load, avg_load, total_load, this_load, total_pwr; 3086 unsigned long max_load, avg_load, total_load, this_load, total_pwr;
@@ -3113,10 +3116,11 @@ find_busiest_group(struct sched_domain *sd, int this_cpu,
3113 unsigned long sum_avg_load_per_task; 3116 unsigned long sum_avg_load_per_task;
3114 unsigned long avg_load_per_task; 3117 unsigned long avg_load_per_task;
3115 3118
3116 local_group = cpu_isset(this_cpu, group->cpumask); 3119 local_group = cpumask_test_cpu(this_cpu,
3120 sched_group_cpus(group));
3117 3121
3118 if (local_group) 3122 if (local_group)
3119 balance_cpu = first_cpu(group->cpumask); 3123 balance_cpu = cpumask_first(sched_group_cpus(group));
3120 3124
3121 /* Tally up the load of all CPUs in the group */ 3125 /* Tally up the load of all CPUs in the group */
3122 sum_weighted_load = sum_nr_running = avg_load = 0; 3126 sum_weighted_load = sum_nr_running = avg_load = 0;
@@ -3125,13 +3129,8 @@ find_busiest_group(struct sched_domain *sd, int this_cpu,
3125 max_cpu_load = 0; 3129 max_cpu_load = 0;
3126 min_cpu_load = ~0UL; 3130 min_cpu_load = ~0UL;
3127 3131
3128 for_each_cpu_mask_nr(i, group->cpumask) { 3132 for_each_cpu_and(i, sched_group_cpus(group), cpus) {
3129 struct rq *rq; 3133 struct rq *rq = cpu_rq(i);
3130
3131 if (!cpu_isset(i, *cpus))
3132 continue;
3133
3134 rq = cpu_rq(i);
3135 3134
3136 if (*sd_idle && rq->nr_running) 3135 if (*sd_idle && rq->nr_running)
3137 *sd_idle = 0; 3136 *sd_idle = 0;
@@ -3242,8 +3241,8 @@ find_busiest_group(struct sched_domain *sd, int this_cpu,
3242 */ 3241 */
3243 if ((sum_nr_running < min_nr_running) || 3242 if ((sum_nr_running < min_nr_running) ||
3244 (sum_nr_running == min_nr_running && 3243 (sum_nr_running == min_nr_running &&
3245 first_cpu(group->cpumask) < 3244 cpumask_first(sched_group_cpus(group)) <
3246 first_cpu(group_min->cpumask))) { 3245 cpumask_first(sched_group_cpus(group_min)))) {
3247 group_min = group; 3246 group_min = group;
3248 min_nr_running = sum_nr_running; 3247 min_nr_running = sum_nr_running;
3249 min_load_per_task = sum_weighted_load / 3248 min_load_per_task = sum_weighted_load /
@@ -3258,8 +3257,8 @@ find_busiest_group(struct sched_domain *sd, int this_cpu,
3258 if (sum_nr_running <= group_capacity - 1) { 3257 if (sum_nr_running <= group_capacity - 1) {
3259 if (sum_nr_running > leader_nr_running || 3258 if (sum_nr_running > leader_nr_running ||
3260 (sum_nr_running == leader_nr_running && 3259 (sum_nr_running == leader_nr_running &&
3261 first_cpu(group->cpumask) > 3260 cpumask_first(sched_group_cpus(group)) >
3262 first_cpu(group_leader->cpumask))) { 3261 cpumask_first(sched_group_cpus(group_leader)))) {
3263 group_leader = group; 3262 group_leader = group;
3264 leader_nr_running = sum_nr_running; 3263 leader_nr_running = sum_nr_running;
3265 } 3264 }
@@ -3398,16 +3397,16 @@ ret:
3398 */ 3397 */
3399static struct rq * 3398static struct rq *
3400find_busiest_queue(struct sched_group *group, enum cpu_idle_type idle, 3399find_busiest_queue(struct sched_group *group, enum cpu_idle_type idle,
3401 unsigned long imbalance, const cpumask_t *cpus) 3400 unsigned long imbalance, const struct cpumask *cpus)
3402{ 3401{
3403 struct rq *busiest = NULL, *rq; 3402 struct rq *busiest = NULL, *rq;
3404 unsigned long max_load = 0; 3403 unsigned long max_load = 0;
3405 int i; 3404 int i;
3406 3405
3407 for_each_cpu_mask_nr(i, group->cpumask) { 3406 for_each_cpu(i, sched_group_cpus(group)) {
3408 unsigned long wl; 3407 unsigned long wl;
3409 3408
3410 if (!cpu_isset(i, *cpus)) 3409 if (!cpumask_test_cpu(i, cpus))
3411 continue; 3410 continue;
3412 3411
3413 rq = cpu_rq(i); 3412 rq = cpu_rq(i);
@@ -3437,7 +3436,7 @@ find_busiest_queue(struct sched_group *group, enum cpu_idle_type idle,
3437 */ 3436 */
3438static int load_balance(int this_cpu, struct rq *this_rq, 3437static int load_balance(int this_cpu, struct rq *this_rq,
3439 struct sched_domain *sd, enum cpu_idle_type idle, 3438 struct sched_domain *sd, enum cpu_idle_type idle,
3440 int *balance, cpumask_t *cpus) 3439 int *balance, struct cpumask *cpus)
3441{ 3440{
3442 int ld_moved, all_pinned = 0, active_balance = 0, sd_idle = 0; 3441 int ld_moved, all_pinned = 0, active_balance = 0, sd_idle = 0;
3443 struct sched_group *group; 3442 struct sched_group *group;
@@ -3445,7 +3444,7 @@ static int load_balance(int this_cpu, struct rq *this_rq,
3445 struct rq *busiest; 3444 struct rq *busiest;
3446 unsigned long flags; 3445 unsigned long flags;
3447 3446
3448 cpus_setall(*cpus); 3447 cpumask_setall(cpus);
3449 3448
3450 /* 3449 /*
3451 * When power savings policy is enabled for the parent domain, idle 3450 * When power savings policy is enabled for the parent domain, idle
@@ -3505,8 +3504,8 @@ redo:
3505 3504
3506 /* All tasks on this runqueue were pinned by CPU affinity */ 3505 /* All tasks on this runqueue were pinned by CPU affinity */
3507 if (unlikely(all_pinned)) { 3506 if (unlikely(all_pinned)) {
3508 cpu_clear(cpu_of(busiest), *cpus); 3507 cpumask_clear_cpu(cpu_of(busiest), cpus);
3509 if (!cpus_empty(*cpus)) 3508 if (!cpumask_empty(cpus))
3510 goto redo; 3509 goto redo;
3511 goto out_balanced; 3510 goto out_balanced;
3512 } 3511 }
@@ -3523,7 +3522,8 @@ redo:
3523 /* don't kick the migration_thread, if the curr 3522 /* don't kick the migration_thread, if the curr
3524 * task on busiest cpu can't be moved to this_cpu 3523 * task on busiest cpu can't be moved to this_cpu
3525 */ 3524 */
3526 if (!cpu_isset(this_cpu, busiest->curr->cpus_allowed)) { 3525 if (!cpumask_test_cpu(this_cpu,
3526 &busiest->curr->cpus_allowed)) {
3527 spin_unlock_irqrestore(&busiest->lock, flags); 3527 spin_unlock_irqrestore(&busiest->lock, flags);
3528 all_pinned = 1; 3528 all_pinned = 1;
3529 goto out_one_pinned; 3529 goto out_one_pinned;
@@ -3598,7 +3598,7 @@ out:
3598 */ 3598 */
3599static int 3599static int
3600load_balance_newidle(int this_cpu, struct rq *this_rq, struct sched_domain *sd, 3600load_balance_newidle(int this_cpu, struct rq *this_rq, struct sched_domain *sd,
3601 cpumask_t *cpus) 3601 struct cpumask *cpus)
3602{ 3602{
3603 struct sched_group *group; 3603 struct sched_group *group;
3604 struct rq *busiest = NULL; 3604 struct rq *busiest = NULL;
@@ -3607,7 +3607,7 @@ load_balance_newidle(int this_cpu, struct rq *this_rq, struct sched_domain *sd,
3607 int sd_idle = 0; 3607 int sd_idle = 0;
3608 int all_pinned = 0; 3608 int all_pinned = 0;
3609 3609
3610 cpus_setall(*cpus); 3610 cpumask_setall(cpus);
3611 3611
3612 /* 3612 /*
3613 * When power savings policy is enabled for the parent domain, idle 3613 * When power savings policy is enabled for the parent domain, idle
@@ -3651,8 +3651,8 @@ redo:
3651 double_unlock_balance(this_rq, busiest); 3651 double_unlock_balance(this_rq, busiest);
3652 3652
3653 if (unlikely(all_pinned)) { 3653 if (unlikely(all_pinned)) {
3654 cpu_clear(cpu_of(busiest), *cpus); 3654 cpumask_clear_cpu(cpu_of(busiest), cpus);
3655 if (!cpus_empty(*cpus)) 3655 if (!cpumask_empty(cpus))
3656 goto redo; 3656 goto redo;
3657 } 3657 }
3658 } 3658 }
@@ -3687,7 +3687,10 @@ static void idle_balance(int this_cpu, struct rq *this_rq)
3687 struct sched_domain *sd; 3687 struct sched_domain *sd;
3688 int pulled_task = 0; 3688 int pulled_task = 0;
3689 unsigned long next_balance = jiffies + HZ; 3689 unsigned long next_balance = jiffies + HZ;
3690 cpumask_t tmpmask; 3690 cpumask_var_t tmpmask;
3691
3692 if (!alloc_cpumask_var(&tmpmask, GFP_ATOMIC))
3693 return;
3691 3694
3692 for_each_domain(this_cpu, sd) { 3695 for_each_domain(this_cpu, sd) {
3693 unsigned long interval; 3696 unsigned long interval;
@@ -3698,7 +3701,7 @@ static void idle_balance(int this_cpu, struct rq *this_rq)
3698 if (sd->flags & SD_BALANCE_NEWIDLE) 3701 if (sd->flags & SD_BALANCE_NEWIDLE)
3699 /* If we've pulled tasks over stop searching: */ 3702 /* If we've pulled tasks over stop searching: */
3700 pulled_task = load_balance_newidle(this_cpu, this_rq, 3703 pulled_task = load_balance_newidle(this_cpu, this_rq,
3701 sd, &tmpmask); 3704 sd, tmpmask);
3702 3705
3703 interval = msecs_to_jiffies(sd->balance_interval); 3706 interval = msecs_to_jiffies(sd->balance_interval);
3704 if (time_after(next_balance, sd->last_balance + interval)) 3707 if (time_after(next_balance, sd->last_balance + interval))
@@ -3713,6 +3716,7 @@ static void idle_balance(int this_cpu, struct rq *this_rq)
3713 */ 3716 */
3714 this_rq->next_balance = next_balance; 3717 this_rq->next_balance = next_balance;
3715 } 3718 }
3719 free_cpumask_var(tmpmask);
3716} 3720}
3717 3721
3718/* 3722/*
@@ -3750,7 +3754,7 @@ static void active_load_balance(struct rq *busiest_rq, int busiest_cpu)
3750 /* Search for an sd spanning us and the target CPU. */ 3754 /* Search for an sd spanning us and the target CPU. */
3751 for_each_domain(target_cpu, sd) { 3755 for_each_domain(target_cpu, sd) {
3752 if ((sd->flags & SD_LOAD_BALANCE) && 3756 if ((sd->flags & SD_LOAD_BALANCE) &&
3753 cpu_isset(busiest_cpu, sd->span)) 3757 cpumask_test_cpu(busiest_cpu, sched_domain_span(sd)))
3754 break; 3758 break;
3755 } 3759 }
3756 3760
@@ -3769,10 +3773,9 @@ static void active_load_balance(struct rq *busiest_rq, int busiest_cpu)
3769#ifdef CONFIG_NO_HZ 3773#ifdef CONFIG_NO_HZ
3770static struct { 3774static struct {
3771 atomic_t load_balancer; 3775 atomic_t load_balancer;
3772 cpumask_t cpu_mask; 3776 cpumask_var_t cpu_mask;
3773} nohz ____cacheline_aligned = { 3777} nohz ____cacheline_aligned = {
3774 .load_balancer = ATOMIC_INIT(-1), 3778 .load_balancer = ATOMIC_INIT(-1),
3775 .cpu_mask = CPU_MASK_NONE,
3776}; 3779};
3777 3780
3778/* 3781/*
@@ -3800,7 +3803,7 @@ int select_nohz_load_balancer(int stop_tick)
3800 int cpu = smp_processor_id(); 3803 int cpu = smp_processor_id();
3801 3804
3802 if (stop_tick) { 3805 if (stop_tick) {
3803 cpu_set(cpu, nohz.cpu_mask); 3806 cpumask_set_cpu(cpu, nohz.cpu_mask);
3804 cpu_rq(cpu)->in_nohz_recently = 1; 3807 cpu_rq(cpu)->in_nohz_recently = 1;
3805 3808
3806 /* 3809 /*
@@ -3814,7 +3817,7 @@ int select_nohz_load_balancer(int stop_tick)
3814 } 3817 }
3815 3818
3816 /* time for ilb owner also to sleep */ 3819 /* time for ilb owner also to sleep */
3817 if (cpus_weight(nohz.cpu_mask) == num_online_cpus()) { 3820 if (cpumask_weight(nohz.cpu_mask) == num_online_cpus()) {
3818 if (atomic_read(&nohz.load_balancer) == cpu) 3821 if (atomic_read(&nohz.load_balancer) == cpu)
3819 atomic_set(&nohz.load_balancer, -1); 3822 atomic_set(&nohz.load_balancer, -1);
3820 return 0; 3823 return 0;
@@ -3827,10 +3830,10 @@ int select_nohz_load_balancer(int stop_tick)
3827 } else if (atomic_read(&nohz.load_balancer) == cpu) 3830 } else if (atomic_read(&nohz.load_balancer) == cpu)
3828 return 1; 3831 return 1;
3829 } else { 3832 } else {
3830 if (!cpu_isset(cpu, nohz.cpu_mask)) 3833 if (!cpumask_test_cpu(cpu, nohz.cpu_mask))
3831 return 0; 3834 return 0;
3832 3835
3833 cpu_clear(cpu, nohz.cpu_mask); 3836 cpumask_clear_cpu(cpu, nohz.cpu_mask);
3834 3837
3835 if (atomic_read(&nohz.load_balancer) == cpu) 3838 if (atomic_read(&nohz.load_balancer) == cpu)
3836 if (atomic_cmpxchg(&nohz.load_balancer, cpu, -1) != cpu) 3839 if (atomic_cmpxchg(&nohz.load_balancer, cpu, -1) != cpu)
@@ -3858,7 +3861,11 @@ static void rebalance_domains(int cpu, enum cpu_idle_type idle)
3858 unsigned long next_balance = jiffies + 60*HZ; 3861 unsigned long next_balance = jiffies + 60*HZ;
3859 int update_next_balance = 0; 3862 int update_next_balance = 0;
3860 int need_serialize; 3863 int need_serialize;
3861 cpumask_t tmp; 3864 cpumask_var_t tmp;
3865
3866 /* Fails alloc? Rebalancing probably not a priority right now. */
3867 if (!alloc_cpumask_var(&tmp, GFP_ATOMIC))
3868 return;
3862 3869
3863 for_each_domain(cpu, sd) { 3870 for_each_domain(cpu, sd) {
3864 if (!(sd->flags & SD_LOAD_BALANCE)) 3871 if (!(sd->flags & SD_LOAD_BALANCE))
@@ -3883,7 +3890,7 @@ static void rebalance_domains(int cpu, enum cpu_idle_type idle)
3883 } 3890 }
3884 3891
3885 if (time_after_eq(jiffies, sd->last_balance + interval)) { 3892 if (time_after_eq(jiffies, sd->last_balance + interval)) {
3886 if (load_balance(cpu, rq, sd, idle, &balance, &tmp)) { 3893 if (load_balance(cpu, rq, sd, idle, &balance, tmp)) {
3887 /* 3894 /*
3888 * We've pulled tasks over so either we're no 3895 * We've pulled tasks over so either we're no
3889 * longer idle, or one of our SMT siblings is 3896 * longer idle, or one of our SMT siblings is
@@ -3917,6 +3924,8 @@ out:
3917 */ 3924 */
3918 if (likely(update_next_balance)) 3925 if (likely(update_next_balance))
3919 rq->next_balance = next_balance; 3926 rq->next_balance = next_balance;
3927
3928 free_cpumask_var(tmp);
3920} 3929}
3921 3930
3922/* 3931/*
@@ -3941,12 +3950,13 @@ static void run_rebalance_domains(struct softirq_action *h)
3941 */ 3950 */
3942 if (this_rq->idle_at_tick && 3951 if (this_rq->idle_at_tick &&
3943 atomic_read(&nohz.load_balancer) == this_cpu) { 3952 atomic_read(&nohz.load_balancer) == this_cpu) {
3944 cpumask_t cpus = nohz.cpu_mask;
3945 struct rq *rq; 3953 struct rq *rq;
3946 int balance_cpu; 3954 int balance_cpu;
3947 3955
3948 cpu_clear(this_cpu, cpus); 3956 for_each_cpu(balance_cpu, nohz.cpu_mask) {
3949 for_each_cpu_mask_nr(balance_cpu, cpus) { 3957 if (balance_cpu == this_cpu)
3958 continue;
3959
3950 /* 3960 /*
3951 * If this cpu gets work to do, stop the load balancing 3961 * If this cpu gets work to do, stop the load balancing
3952 * work being done for other cpus. Next load 3962 * work being done for other cpus. Next load
@@ -3984,7 +3994,7 @@ static inline void trigger_load_balance(struct rq *rq, int cpu)
3984 rq->in_nohz_recently = 0; 3994 rq->in_nohz_recently = 0;
3985 3995
3986 if (atomic_read(&nohz.load_balancer) == cpu) { 3996 if (atomic_read(&nohz.load_balancer) == cpu) {
3987 cpu_clear(cpu, nohz.cpu_mask); 3997 cpumask_clear_cpu(cpu, nohz.cpu_mask);
3988 atomic_set(&nohz.load_balancer, -1); 3998 atomic_set(&nohz.load_balancer, -1);
3989 } 3999 }
3990 4000
@@ -3997,7 +4007,7 @@ static inline void trigger_load_balance(struct rq *rq, int cpu)
3997 * TBD: Traverse the sched domains and nominate 4007 * TBD: Traverse the sched domains and nominate
3998 * the nearest cpu in the nohz.cpu_mask. 4008 * the nearest cpu in the nohz.cpu_mask.
3999 */ 4009 */
4000 int ilb = first_cpu(nohz.cpu_mask); 4010 int ilb = cpumask_first(nohz.cpu_mask);
4001 4011
4002 if (ilb < nr_cpu_ids) 4012 if (ilb < nr_cpu_ids)
4003 resched_cpu(ilb); 4013 resched_cpu(ilb);
@@ -4009,7 +4019,7 @@ static inline void trigger_load_balance(struct rq *rq, int cpu)
4009 * cpus with ticks stopped, is it time for that to stop? 4019 * cpus with ticks stopped, is it time for that to stop?
4010 */ 4020 */
4011 if (rq->idle_at_tick && atomic_read(&nohz.load_balancer) == cpu && 4021 if (rq->idle_at_tick && atomic_read(&nohz.load_balancer) == cpu &&
4012 cpus_weight(nohz.cpu_mask) == num_online_cpus()) { 4022 cpumask_weight(nohz.cpu_mask) == num_online_cpus()) {
4013 resched_cpu(cpu); 4023 resched_cpu(cpu);
4014 return; 4024 return;
4015 } 4025 }
@@ -4019,7 +4029,7 @@ static inline void trigger_load_balance(struct rq *rq, int cpu)
4019 * someone else, then no need raise the SCHED_SOFTIRQ 4029 * someone else, then no need raise the SCHED_SOFTIRQ
4020 */ 4030 */
4021 if (rq->idle_at_tick && atomic_read(&nohz.load_balancer) != cpu && 4031 if (rq->idle_at_tick && atomic_read(&nohz.load_balancer) != cpu &&
4022 cpu_isset(cpu, nohz.cpu_mask)) 4032 cpumask_test_cpu(cpu, nohz.cpu_mask))
4023 return; 4033 return;
4024#endif 4034#endif
4025 if (time_after_eq(jiffies, rq->next_balance)) 4035 if (time_after_eq(jiffies, rq->next_balance))
@@ -4181,7 +4191,6 @@ void account_steal_time(struct task_struct *p, cputime_t steal)
4181 4191
4182 if (p == rq->idle) { 4192 if (p == rq->idle) {
4183 p->stime = cputime_add(p->stime, steal); 4193 p->stime = cputime_add(p->stime, steal);
4184 account_group_system_time(p, steal);
4185 if (atomic_read(&rq->nr_iowait) > 0) 4194 if (atomic_read(&rq->nr_iowait) > 0)
4186 cpustat->iowait = cputime64_add(cpustat->iowait, tmp); 4195 cpustat->iowait = cputime64_add(cpustat->iowait, tmp);
4187 else 4196 else
@@ -4317,7 +4326,7 @@ void __kprobes sub_preempt_count(int val)
4317 /* 4326 /*
4318 * Underflow? 4327 * Underflow?
4319 */ 4328 */
4320 if (DEBUG_LOCKS_WARN_ON(val > preempt_count())) 4329 if (DEBUG_LOCKS_WARN_ON(val > preempt_count() - (!!kernel_locked())))
4321 return; 4330 return;
4322 /* 4331 /*
4323 * Is the spinlock portion underflowing? 4332 * Is the spinlock portion underflowing?
@@ -5378,10 +5387,9 @@ out_unlock:
5378 return retval; 5387 return retval;
5379} 5388}
5380 5389
5381long sched_setaffinity(pid_t pid, const cpumask_t *in_mask) 5390long sched_setaffinity(pid_t pid, const struct cpumask *in_mask)
5382{ 5391{
5383 cpumask_t cpus_allowed; 5392 cpumask_var_t cpus_allowed, new_mask;
5384 cpumask_t new_mask = *in_mask;
5385 struct task_struct *p; 5393 struct task_struct *p;
5386 int retval; 5394 int retval;
5387 5395
@@ -5403,6 +5411,14 @@ long sched_setaffinity(pid_t pid, const cpumask_t *in_mask)
5403 get_task_struct(p); 5411 get_task_struct(p);
5404 read_unlock(&tasklist_lock); 5412 read_unlock(&tasklist_lock);
5405 5413
5414 if (!alloc_cpumask_var(&cpus_allowed, GFP_KERNEL)) {
5415 retval = -ENOMEM;
5416 goto out_put_task;
5417 }
5418 if (!alloc_cpumask_var(&new_mask, GFP_KERNEL)) {
5419 retval = -ENOMEM;
5420 goto out_free_cpus_allowed;
5421 }
5406 retval = -EPERM; 5422 retval = -EPERM;
5407 if ((current->euid != p->euid) && (current->euid != p->uid) && 5423 if ((current->euid != p->euid) && (current->euid != p->uid) &&
5408 !capable(CAP_SYS_NICE)) 5424 !capable(CAP_SYS_NICE))
@@ -5412,37 +5428,41 @@ long sched_setaffinity(pid_t pid, const cpumask_t *in_mask)
5412 if (retval) 5428 if (retval)
5413 goto out_unlock; 5429 goto out_unlock;
5414 5430
5415 cpuset_cpus_allowed(p, &cpus_allowed); 5431 cpuset_cpus_allowed(p, cpus_allowed);
5416 cpus_and(new_mask, new_mask, cpus_allowed); 5432 cpumask_and(new_mask, in_mask, cpus_allowed);
5417 again: 5433 again:
5418 retval = set_cpus_allowed_ptr(p, &new_mask); 5434 retval = set_cpus_allowed_ptr(p, new_mask);
5419 5435
5420 if (!retval) { 5436 if (!retval) {
5421 cpuset_cpus_allowed(p, &cpus_allowed); 5437 cpuset_cpus_allowed(p, cpus_allowed);
5422 if (!cpus_subset(new_mask, cpus_allowed)) { 5438 if (!cpumask_subset(new_mask, cpus_allowed)) {
5423 /* 5439 /*
5424 * We must have raced with a concurrent cpuset 5440 * We must have raced with a concurrent cpuset
5425 * update. Just reset the cpus_allowed to the 5441 * update. Just reset the cpus_allowed to the
5426 * cpuset's cpus_allowed 5442 * cpuset's cpus_allowed
5427 */ 5443 */
5428 new_mask = cpus_allowed; 5444 cpumask_copy(new_mask, cpus_allowed);
5429 goto again; 5445 goto again;
5430 } 5446 }
5431 } 5447 }
5432out_unlock: 5448out_unlock:
5449 free_cpumask_var(new_mask);
5450out_free_cpus_allowed:
5451 free_cpumask_var(cpus_allowed);
5452out_put_task:
5433 put_task_struct(p); 5453 put_task_struct(p);
5434 put_online_cpus(); 5454 put_online_cpus();
5435 return retval; 5455 return retval;
5436} 5456}
5437 5457
5438static int get_user_cpu_mask(unsigned long __user *user_mask_ptr, unsigned len, 5458static int get_user_cpu_mask(unsigned long __user *user_mask_ptr, unsigned len,
5439 cpumask_t *new_mask) 5459 struct cpumask *new_mask)
5440{ 5460{
5441 if (len < sizeof(cpumask_t)) { 5461 if (len < cpumask_size())
5442 memset(new_mask, 0, sizeof(cpumask_t)); 5462 cpumask_clear(new_mask);
5443 } else if (len > sizeof(cpumask_t)) { 5463 else if (len > cpumask_size())
5444 len = sizeof(cpumask_t); 5464 len = cpumask_size();
5445 } 5465
5446 return copy_from_user(new_mask, user_mask_ptr, len) ? -EFAULT : 0; 5466 return copy_from_user(new_mask, user_mask_ptr, len) ? -EFAULT : 0;
5447} 5467}
5448 5468
@@ -5455,17 +5475,20 @@ static int get_user_cpu_mask(unsigned long __user *user_mask_ptr, unsigned len,
5455asmlinkage long sys_sched_setaffinity(pid_t pid, unsigned int len, 5475asmlinkage long sys_sched_setaffinity(pid_t pid, unsigned int len,
5456 unsigned long __user *user_mask_ptr) 5476 unsigned long __user *user_mask_ptr)
5457{ 5477{
5458 cpumask_t new_mask; 5478 cpumask_var_t new_mask;
5459 int retval; 5479 int retval;
5460 5480
5461 retval = get_user_cpu_mask(user_mask_ptr, len, &new_mask); 5481 if (!alloc_cpumask_var(&new_mask, GFP_KERNEL))
5462 if (retval) 5482 return -ENOMEM;
5463 return retval;
5464 5483
5465 return sched_setaffinity(pid, &new_mask); 5484 retval = get_user_cpu_mask(user_mask_ptr, len, new_mask);
5485 if (retval == 0)
5486 retval = sched_setaffinity(pid, new_mask);
5487 free_cpumask_var(new_mask);
5488 return retval;
5466} 5489}
5467 5490
5468long sched_getaffinity(pid_t pid, cpumask_t *mask) 5491long sched_getaffinity(pid_t pid, struct cpumask *mask)
5469{ 5492{
5470 struct task_struct *p; 5493 struct task_struct *p;
5471 int retval; 5494 int retval;
@@ -5482,7 +5505,7 @@ long sched_getaffinity(pid_t pid, cpumask_t *mask)
5482 if (retval) 5505 if (retval)
5483 goto out_unlock; 5506 goto out_unlock;
5484 5507
5485 cpus_and(*mask, p->cpus_allowed, cpu_online_map); 5508 cpumask_and(mask, &p->cpus_allowed, cpu_online_mask);
5486 5509
5487out_unlock: 5510out_unlock:
5488 read_unlock(&tasklist_lock); 5511 read_unlock(&tasklist_lock);
@@ -5501,19 +5524,24 @@ asmlinkage long sys_sched_getaffinity(pid_t pid, unsigned int len,
5501 unsigned long __user *user_mask_ptr) 5524 unsigned long __user *user_mask_ptr)
5502{ 5525{
5503 int ret; 5526 int ret;
5504 cpumask_t mask; 5527 cpumask_var_t mask;
5505 5528
5506 if (len < sizeof(cpumask_t)) 5529 if (len < cpumask_size())
5507 return -EINVAL; 5530 return -EINVAL;
5508 5531
5509 ret = sched_getaffinity(pid, &mask); 5532 if (!alloc_cpumask_var(&mask, GFP_KERNEL))
5510 if (ret < 0) 5533 return -ENOMEM;
5511 return ret;
5512 5534
5513 if (copy_to_user(user_mask_ptr, &mask, sizeof(cpumask_t))) 5535 ret = sched_getaffinity(pid, mask);
5514 return -EFAULT; 5536 if (ret == 0) {
5537 if (copy_to_user(user_mask_ptr, mask, cpumask_size()))
5538 ret = -EFAULT;
5539 else
5540 ret = cpumask_size();
5541 }
5542 free_cpumask_var(mask);
5515 5543
5516 return sizeof(cpumask_t); 5544 return ret;
5517} 5545}
5518 5546
5519/** 5547/**
@@ -5855,7 +5883,7 @@ void __cpuinit init_idle(struct task_struct *idle, int cpu)
5855 idle->se.exec_start = sched_clock(); 5883 idle->se.exec_start = sched_clock();
5856 5884
5857 idle->prio = idle->normal_prio = MAX_PRIO; 5885 idle->prio = idle->normal_prio = MAX_PRIO;
5858 idle->cpus_allowed = cpumask_of_cpu(cpu); 5886 cpumask_copy(&idle->cpus_allowed, cpumask_of(cpu));
5859 __set_task_cpu(idle, cpu); 5887 __set_task_cpu(idle, cpu);
5860 5888
5861 rq->curr = rq->idle = idle; 5889 rq->curr = rq->idle = idle;
@@ -5874,6 +5902,7 @@ void __cpuinit init_idle(struct task_struct *idle, int cpu)
5874 * The idle tasks have their own, simple scheduling class: 5902 * The idle tasks have their own, simple scheduling class:
5875 */ 5903 */
5876 idle->sched_class = &idle_sched_class; 5904 idle->sched_class = &idle_sched_class;
5905 ftrace_graph_init_task(idle);
5877} 5906}
5878 5907
5879/* 5908/*
@@ -5881,9 +5910,9 @@ void __cpuinit init_idle(struct task_struct *idle, int cpu)
5881 * indicates which cpus entered this state. This is used 5910 * indicates which cpus entered this state. This is used
5882 * in the rcu update to wait only for active cpus. For system 5911 * in the rcu update to wait only for active cpus. For system
5883 * which do not switch off the HZ timer nohz_cpu_mask should 5912 * which do not switch off the HZ timer nohz_cpu_mask should
5884 * always be CPU_MASK_NONE. 5913 * always be CPU_BITS_NONE.
5885 */ 5914 */
5886cpumask_t nohz_cpu_mask = CPU_MASK_NONE; 5915cpumask_var_t nohz_cpu_mask;
5887 5916
5888/* 5917/*
5889 * Increase the granularity value when there are more CPUs, 5918 * Increase the granularity value when there are more CPUs,
@@ -5938,7 +5967,7 @@ static inline void sched_init_granularity(void)
5938 * task must not exit() & deallocate itself prematurely. The 5967 * task must not exit() & deallocate itself prematurely. The
5939 * call is not atomic; no spinlocks may be held. 5968 * call is not atomic; no spinlocks may be held.
5940 */ 5969 */
5941int set_cpus_allowed_ptr(struct task_struct *p, const cpumask_t *new_mask) 5970int set_cpus_allowed_ptr(struct task_struct *p, const struct cpumask *new_mask)
5942{ 5971{
5943 struct migration_req req; 5972 struct migration_req req;
5944 unsigned long flags; 5973 unsigned long flags;
@@ -5946,13 +5975,13 @@ int set_cpus_allowed_ptr(struct task_struct *p, const cpumask_t *new_mask)
5946 int ret = 0; 5975 int ret = 0;
5947 5976
5948 rq = task_rq_lock(p, &flags); 5977 rq = task_rq_lock(p, &flags);
5949 if (!cpus_intersects(*new_mask, cpu_online_map)) { 5978 if (!cpumask_intersects(new_mask, cpu_online_mask)) {
5950 ret = -EINVAL; 5979 ret = -EINVAL;
5951 goto out; 5980 goto out;
5952 } 5981 }
5953 5982
5954 if (unlikely((p->flags & PF_THREAD_BOUND) && p != current && 5983 if (unlikely((p->flags & PF_THREAD_BOUND) && p != current &&
5955 !cpus_equal(p->cpus_allowed, *new_mask))) { 5984 !cpumask_equal(&p->cpus_allowed, new_mask))) {
5956 ret = -EINVAL; 5985 ret = -EINVAL;
5957 goto out; 5986 goto out;
5958 } 5987 }
@@ -5960,15 +5989,15 @@ int set_cpus_allowed_ptr(struct task_struct *p, const cpumask_t *new_mask)
5960 if (p->sched_class->set_cpus_allowed) 5989 if (p->sched_class->set_cpus_allowed)
5961 p->sched_class->set_cpus_allowed(p, new_mask); 5990 p->sched_class->set_cpus_allowed(p, new_mask);
5962 else { 5991 else {
5963 p->cpus_allowed = *new_mask; 5992 cpumask_copy(&p->cpus_allowed, new_mask);
5964 p->rt.nr_cpus_allowed = cpus_weight(*new_mask); 5993 p->rt.nr_cpus_allowed = cpumask_weight(new_mask);
5965 } 5994 }
5966 5995
5967 /* Can the task run on the task's current CPU? If so, we're done */ 5996 /* Can the task run on the task's current CPU? If so, we're done */
5968 if (cpu_isset(task_cpu(p), *new_mask)) 5997 if (cpumask_test_cpu(task_cpu(p), new_mask))
5969 goto out; 5998 goto out;
5970 5999
5971 if (migrate_task(p, any_online_cpu(*new_mask), &req)) { 6000 if (migrate_task(p, cpumask_any_and(cpu_online_mask, new_mask), &req)) {
5972 /* Need help from migration thread: drop lock and wait. */ 6001 /* Need help from migration thread: drop lock and wait. */
5973 task_rq_unlock(rq, &flags); 6002 task_rq_unlock(rq, &flags);
5974 wake_up_process(rq->migration_thread); 6003 wake_up_process(rq->migration_thread);
@@ -6010,7 +6039,7 @@ static int __migrate_task(struct task_struct *p, int src_cpu, int dest_cpu)
6010 if (task_cpu(p) != src_cpu) 6039 if (task_cpu(p) != src_cpu)
6011 goto done; 6040 goto done;
6012 /* Affinity changed (again). */ 6041 /* Affinity changed (again). */
6013 if (!cpu_isset(dest_cpu, p->cpus_allowed)) 6042 if (!cpumask_test_cpu(dest_cpu, &p->cpus_allowed))
6014 goto fail; 6043 goto fail;
6015 6044
6016 on_rq = p->se.on_rq; 6045 on_rq = p->se.on_rq;
@@ -6107,50 +6136,43 @@ static int __migrate_task_irq(struct task_struct *p, int src_cpu, int dest_cpu)
6107 */ 6136 */
6108static void move_task_off_dead_cpu(int dead_cpu, struct task_struct *p) 6137static void move_task_off_dead_cpu(int dead_cpu, struct task_struct *p)
6109{ 6138{
6110 unsigned long flags;
6111 cpumask_t mask;
6112 struct rq *rq;
6113 int dest_cpu; 6139 int dest_cpu;
6140 /* FIXME: Use cpumask_of_node here. */
6141 cpumask_t _nodemask = node_to_cpumask(cpu_to_node(dead_cpu));
6142 const struct cpumask *nodemask = &_nodemask;
6143
6144again:
6145 /* Look for allowed, online CPU in same node. */
6146 for_each_cpu_and(dest_cpu, nodemask, cpu_online_mask)
6147 if (cpumask_test_cpu(dest_cpu, &p->cpus_allowed))
6148 goto move;
6149
6150 /* Any allowed, online CPU? */
6151 dest_cpu = cpumask_any_and(&p->cpus_allowed, cpu_online_mask);
6152 if (dest_cpu < nr_cpu_ids)
6153 goto move;
6154
6155 /* No more Mr. Nice Guy. */
6156 if (dest_cpu >= nr_cpu_ids) {
6157 cpuset_cpus_allowed_locked(p, &p->cpus_allowed);
6158 dest_cpu = cpumask_any_and(cpu_online_mask, &p->cpus_allowed);
6114 6159
6115 do { 6160 /*
6116 /* On same node? */ 6161 * Don't tell them about moving exiting tasks or
6117 mask = node_to_cpumask(cpu_to_node(dead_cpu)); 6162 * kernel threads (both mm NULL), since they never
6118 cpus_and(mask, mask, p->cpus_allowed); 6163 * leave kernel.
6119 dest_cpu = any_online_cpu(mask); 6164 */
6120 6165 if (p->mm && printk_ratelimit()) {
6121 /* On any allowed CPU? */ 6166 printk(KERN_INFO "process %d (%s) no "
6122 if (dest_cpu >= nr_cpu_ids) 6167 "longer affine to cpu%d\n",
6123 dest_cpu = any_online_cpu(p->cpus_allowed); 6168 task_pid_nr(p), p->comm, dead_cpu);
6124
6125 /* No more Mr. Nice Guy. */
6126 if (dest_cpu >= nr_cpu_ids) {
6127 cpumask_t cpus_allowed;
6128
6129 cpuset_cpus_allowed_locked(p, &cpus_allowed);
6130 /*
6131 * Try to stay on the same cpuset, where the
6132 * current cpuset may be a subset of all cpus.
6133 * The cpuset_cpus_allowed_locked() variant of
6134 * cpuset_cpus_allowed() will not block. It must be
6135 * called within calls to cpuset_lock/cpuset_unlock.
6136 */
6137 rq = task_rq_lock(p, &flags);
6138 p->cpus_allowed = cpus_allowed;
6139 dest_cpu = any_online_cpu(p->cpus_allowed);
6140 task_rq_unlock(rq, &flags);
6141
6142 /*
6143 * Don't tell them about moving exiting tasks or
6144 * kernel threads (both mm NULL), since they never
6145 * leave kernel.
6146 */
6147 if (p->mm && printk_ratelimit()) {
6148 printk(KERN_INFO "process %d (%s) no "
6149 "longer affine to cpu%d\n",
6150 task_pid_nr(p), p->comm, dead_cpu);
6151 }
6152 } 6169 }
6153 } while (!__migrate_task_irq(p, dead_cpu, dest_cpu)); 6170 }
6171
6172move:
6173 /* It can have affinity changed while we were choosing. */
6174 if (unlikely(!__migrate_task_irq(p, dead_cpu, dest_cpu)))
6175 goto again;
6154} 6176}
6155 6177
6156/* 6178/*
@@ -6162,7 +6184,7 @@ static void move_task_off_dead_cpu(int dead_cpu, struct task_struct *p)
6162 */ 6184 */
6163static void migrate_nr_uninterruptible(struct rq *rq_src) 6185static void migrate_nr_uninterruptible(struct rq *rq_src)
6164{ 6186{
6165 struct rq *rq_dest = cpu_rq(any_online_cpu(*CPU_MASK_ALL_PTR)); 6187 struct rq *rq_dest = cpu_rq(cpumask_any(cpu_online_mask));
6166 unsigned long flags; 6188 unsigned long flags;
6167 6189
6168 local_irq_save(flags); 6190 local_irq_save(flags);
@@ -6452,7 +6474,7 @@ static void set_rq_online(struct rq *rq)
6452 if (!rq->online) { 6474 if (!rq->online) {
6453 const struct sched_class *class; 6475 const struct sched_class *class;
6454 6476
6455 cpu_set(rq->cpu, rq->rd->online); 6477 cpumask_set_cpu(rq->cpu, rq->rd->online);
6456 rq->online = 1; 6478 rq->online = 1;
6457 6479
6458 for_each_class(class) { 6480 for_each_class(class) {
@@ -6472,7 +6494,7 @@ static void set_rq_offline(struct rq *rq)
6472 class->rq_offline(rq); 6494 class->rq_offline(rq);
6473 } 6495 }
6474 6496
6475 cpu_clear(rq->cpu, rq->rd->online); 6497 cpumask_clear_cpu(rq->cpu, rq->rd->online);
6476 rq->online = 0; 6498 rq->online = 0;
6477 } 6499 }
6478} 6500}
@@ -6513,7 +6535,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
6513 rq = cpu_rq(cpu); 6535 rq = cpu_rq(cpu);
6514 spin_lock_irqsave(&rq->lock, flags); 6536 spin_lock_irqsave(&rq->lock, flags);
6515 if (rq->rd) { 6537 if (rq->rd) {
6516 BUG_ON(!cpu_isset(cpu, rq->rd->span)); 6538 BUG_ON(!cpumask_test_cpu(cpu, rq->rd->span));
6517 6539
6518 set_rq_online(rq); 6540 set_rq_online(rq);
6519 } 6541 }
@@ -6527,7 +6549,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
6527 break; 6549 break;
6528 /* Unbind it from offline cpu so it can run. Fall thru. */ 6550 /* Unbind it from offline cpu so it can run. Fall thru. */
6529 kthread_bind(cpu_rq(cpu)->migration_thread, 6551 kthread_bind(cpu_rq(cpu)->migration_thread,
6530 any_online_cpu(cpu_online_map)); 6552 cpumask_any(cpu_online_mask));
6531 kthread_stop(cpu_rq(cpu)->migration_thread); 6553 kthread_stop(cpu_rq(cpu)->migration_thread);
6532 cpu_rq(cpu)->migration_thread = NULL; 6554 cpu_rq(cpu)->migration_thread = NULL;
6533 break; 6555 break;
@@ -6577,7 +6599,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
6577 rq = cpu_rq(cpu); 6599 rq = cpu_rq(cpu);
6578 spin_lock_irqsave(&rq->lock, flags); 6600 spin_lock_irqsave(&rq->lock, flags);
6579 if (rq->rd) { 6601 if (rq->rd) {
6580 BUG_ON(!cpu_isset(cpu, rq->rd->span)); 6602 BUG_ON(!cpumask_test_cpu(cpu, rq->rd->span));
6581 set_rq_offline(rq); 6603 set_rq_offline(rq);
6582 } 6604 }
6583 spin_unlock_irqrestore(&rq->lock, flags); 6605 spin_unlock_irqrestore(&rq->lock, flags);
@@ -6616,13 +6638,13 @@ early_initcall(migration_init);
6616#ifdef CONFIG_SCHED_DEBUG 6638#ifdef CONFIG_SCHED_DEBUG
6617 6639
6618static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level, 6640static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level,
6619 cpumask_t *groupmask) 6641 struct cpumask *groupmask)
6620{ 6642{
6621 struct sched_group *group = sd->groups; 6643 struct sched_group *group = sd->groups;
6622 char str[256]; 6644 char str[256];
6623 6645
6624 cpulist_scnprintf(str, sizeof(str), sd->span); 6646 cpulist_scnprintf(str, sizeof(str), *sched_domain_span(sd));
6625 cpus_clear(*groupmask); 6647 cpumask_clear(groupmask);
6626 6648
6627 printk(KERN_DEBUG "%*s domain %d: ", level, "", level); 6649 printk(KERN_DEBUG "%*s domain %d: ", level, "", level);
6628 6650
@@ -6636,11 +6658,11 @@ static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level,
6636 6658
6637 printk(KERN_CONT "span %s level %s\n", str, sd->name); 6659 printk(KERN_CONT "span %s level %s\n", str, sd->name);
6638 6660
6639 if (!cpu_isset(cpu, sd->span)) { 6661 if (!cpumask_test_cpu(cpu, sched_domain_span(sd))) {
6640 printk(KERN_ERR "ERROR: domain->span does not contain " 6662 printk(KERN_ERR "ERROR: domain->span does not contain "
6641 "CPU%d\n", cpu); 6663 "CPU%d\n", cpu);
6642 } 6664 }
6643 if (!cpu_isset(cpu, group->cpumask)) { 6665 if (!cpumask_test_cpu(cpu, sched_group_cpus(group))) {
6644 printk(KERN_ERR "ERROR: domain->groups does not contain" 6666 printk(KERN_ERR "ERROR: domain->groups does not contain"
6645 " CPU%d\n", cpu); 6667 " CPU%d\n", cpu);
6646 } 6668 }
@@ -6660,31 +6682,32 @@ static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level,
6660 break; 6682 break;
6661 } 6683 }
6662 6684
6663 if (!cpus_weight(group->cpumask)) { 6685 if (!cpumask_weight(sched_group_cpus(group))) {
6664 printk(KERN_CONT "\n"); 6686 printk(KERN_CONT "\n");
6665 printk(KERN_ERR "ERROR: empty group\n"); 6687 printk(KERN_ERR "ERROR: empty group\n");
6666 break; 6688 break;
6667 } 6689 }
6668 6690
6669 if (cpus_intersects(*groupmask, group->cpumask)) { 6691 if (cpumask_intersects(groupmask, sched_group_cpus(group))) {
6670 printk(KERN_CONT "\n"); 6692 printk(KERN_CONT "\n");
6671 printk(KERN_ERR "ERROR: repeated CPUs\n"); 6693 printk(KERN_ERR "ERROR: repeated CPUs\n");
6672 break; 6694 break;
6673 } 6695 }
6674 6696
6675 cpus_or(*groupmask, *groupmask, group->cpumask); 6697 cpumask_or(groupmask, groupmask, sched_group_cpus(group));
6676 6698
6677 cpulist_scnprintf(str, sizeof(str), group->cpumask); 6699 cpulist_scnprintf(str, sizeof(str), *sched_group_cpus(group));
6678 printk(KERN_CONT " %s", str); 6700 printk(KERN_CONT " %s", str);
6679 6701
6680 group = group->next; 6702 group = group->next;
6681 } while (group != sd->groups); 6703 } while (group != sd->groups);
6682 printk(KERN_CONT "\n"); 6704 printk(KERN_CONT "\n");
6683 6705
6684 if (!cpus_equal(sd->span, *groupmask)) 6706 if (!cpumask_equal(sched_domain_span(sd), groupmask))
6685 printk(KERN_ERR "ERROR: groups don't span domain->span\n"); 6707 printk(KERN_ERR "ERROR: groups don't span domain->span\n");
6686 6708
6687 if (sd->parent && !cpus_subset(*groupmask, sd->parent->span)) 6709 if (sd->parent &&
6710 !cpumask_subset(groupmask, sched_domain_span(sd->parent)))
6688 printk(KERN_ERR "ERROR: parent span is not a superset " 6711 printk(KERN_ERR "ERROR: parent span is not a superset "
6689 "of domain->span\n"); 6712 "of domain->span\n");
6690 return 0; 6713 return 0;
@@ -6692,7 +6715,7 @@ static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level,
6692 6715
6693static void sched_domain_debug(struct sched_domain *sd, int cpu) 6716static void sched_domain_debug(struct sched_domain *sd, int cpu)
6694{ 6717{
6695 cpumask_t *groupmask; 6718 cpumask_var_t groupmask;
6696 int level = 0; 6719 int level = 0;
6697 6720
6698 if (!sd) { 6721 if (!sd) {
@@ -6702,8 +6725,7 @@ static void sched_domain_debug(struct sched_domain *sd, int cpu)
6702 6725
6703 printk(KERN_DEBUG "CPU%d attaching sched-domain:\n", cpu); 6726 printk(KERN_DEBUG "CPU%d attaching sched-domain:\n", cpu);
6704 6727
6705 groupmask = kmalloc(sizeof(cpumask_t), GFP_KERNEL); 6728 if (!alloc_cpumask_var(&groupmask, GFP_KERNEL)) {
6706 if (!groupmask) {
6707 printk(KERN_DEBUG "Cannot load-balance (out of memory)\n"); 6729 printk(KERN_DEBUG "Cannot load-balance (out of memory)\n");
6708 return; 6730 return;
6709 } 6731 }
@@ -6716,7 +6738,7 @@ static void sched_domain_debug(struct sched_domain *sd, int cpu)
6716 if (!sd) 6738 if (!sd)
6717 break; 6739 break;
6718 } 6740 }
6719 kfree(groupmask); 6741 free_cpumask_var(groupmask);
6720} 6742}
6721#else /* !CONFIG_SCHED_DEBUG */ 6743#else /* !CONFIG_SCHED_DEBUG */
6722# define sched_domain_debug(sd, cpu) do { } while (0) 6744# define sched_domain_debug(sd, cpu) do { } while (0)
@@ -6724,7 +6746,7 @@ static void sched_domain_debug(struct sched_domain *sd, int cpu)
6724 6746
6725static int sd_degenerate(struct sched_domain *sd) 6747static int sd_degenerate(struct sched_domain *sd)
6726{ 6748{
6727 if (cpus_weight(sd->span) == 1) 6749 if (cpumask_weight(sched_domain_span(sd)) == 1)
6728 return 1; 6750 return 1;
6729 6751
6730 /* Following flags need at least 2 groups */ 6752 /* Following flags need at least 2 groups */
@@ -6755,7 +6777,7 @@ sd_parent_degenerate(struct sched_domain *sd, struct sched_domain *parent)
6755 if (sd_degenerate(parent)) 6777 if (sd_degenerate(parent))
6756 return 1; 6778 return 1;
6757 6779
6758 if (!cpus_equal(sd->span, parent->span)) 6780 if (!cpumask_equal(sched_domain_span(sd), sched_domain_span(parent)))
6759 return 0; 6781 return 0;
6760 6782
6761 /* Does parent contain flags not in child? */ 6783 /* Does parent contain flags not in child? */
@@ -6779,6 +6801,16 @@ sd_parent_degenerate(struct sched_domain *sd, struct sched_domain *parent)
6779 return 1; 6801 return 1;
6780} 6802}
6781 6803
6804static void free_rootdomain(struct root_domain *rd)
6805{
6806 cpupri_cleanup(&rd->cpupri);
6807
6808 free_cpumask_var(rd->rto_mask);
6809 free_cpumask_var(rd->online);
6810 free_cpumask_var(rd->span);
6811 kfree(rd);
6812}
6813
6782static void rq_attach_root(struct rq *rq, struct root_domain *rd) 6814static void rq_attach_root(struct rq *rq, struct root_domain *rd)
6783{ 6815{
6784 unsigned long flags; 6816 unsigned long flags;
@@ -6788,38 +6820,63 @@ static void rq_attach_root(struct rq *rq, struct root_domain *rd)
6788 if (rq->rd) { 6820 if (rq->rd) {
6789 struct root_domain *old_rd = rq->rd; 6821 struct root_domain *old_rd = rq->rd;
6790 6822
6791 if (cpu_isset(rq->cpu, old_rd->online)) 6823 if (cpumask_test_cpu(rq->cpu, old_rd->online))
6792 set_rq_offline(rq); 6824 set_rq_offline(rq);
6793 6825
6794 cpu_clear(rq->cpu, old_rd->span); 6826 cpumask_clear_cpu(rq->cpu, old_rd->span);
6795 6827
6796 if (atomic_dec_and_test(&old_rd->refcount)) 6828 if (atomic_dec_and_test(&old_rd->refcount))
6797 kfree(old_rd); 6829 free_rootdomain(old_rd);
6798 } 6830 }
6799 6831
6800 atomic_inc(&rd->refcount); 6832 atomic_inc(&rd->refcount);
6801 rq->rd = rd; 6833 rq->rd = rd;
6802 6834
6803 cpu_set(rq->cpu, rd->span); 6835 cpumask_set_cpu(rq->cpu, rd->span);
6804 if (cpu_isset(rq->cpu, cpu_online_map)) 6836 if (cpumask_test_cpu(rq->cpu, cpu_online_mask))
6805 set_rq_online(rq); 6837 set_rq_online(rq);
6806 6838
6807 spin_unlock_irqrestore(&rq->lock, flags); 6839 spin_unlock_irqrestore(&rq->lock, flags);
6808} 6840}
6809 6841
6810static void init_rootdomain(struct root_domain *rd) 6842static int init_rootdomain(struct root_domain *rd, bool bootmem)
6811{ 6843{
6812 memset(rd, 0, sizeof(*rd)); 6844 memset(rd, 0, sizeof(*rd));
6813 6845
6814 cpus_clear(rd->span); 6846 if (bootmem) {
6815 cpus_clear(rd->online); 6847 alloc_bootmem_cpumask_var(&def_root_domain.span);
6848 alloc_bootmem_cpumask_var(&def_root_domain.online);
6849 alloc_bootmem_cpumask_var(&def_root_domain.rto_mask);
6850 cpupri_init(&rd->cpupri, true);
6851 return 0;
6852 }
6853
6854 if (!alloc_cpumask_var(&rd->span, GFP_KERNEL))
6855 goto free_rd;
6856 if (!alloc_cpumask_var(&rd->online, GFP_KERNEL))
6857 goto free_span;
6858 if (!alloc_cpumask_var(&rd->rto_mask, GFP_KERNEL))
6859 goto free_online;
6860
6861 if (cpupri_init(&rd->cpupri, false) != 0)
6862 goto free_rto_mask;
6863 return 0;
6816 6864
6817 cpupri_init(&rd->cpupri); 6865free_rto_mask:
6866 free_cpumask_var(rd->rto_mask);
6867free_online:
6868 free_cpumask_var(rd->online);
6869free_span:
6870 free_cpumask_var(rd->span);
6871free_rd:
6872 kfree(rd);
6873 return -ENOMEM;
6818} 6874}
6819 6875
6820static void init_defrootdomain(void) 6876static void init_defrootdomain(void)
6821{ 6877{
6822 init_rootdomain(&def_root_domain); 6878 init_rootdomain(&def_root_domain, true);
6879
6823 atomic_set(&def_root_domain.refcount, 1); 6880 atomic_set(&def_root_domain.refcount, 1);
6824} 6881}
6825 6882
@@ -6831,7 +6888,10 @@ static struct root_domain *alloc_rootdomain(void)
6831 if (!rd) 6888 if (!rd)
6832 return NULL; 6889 return NULL;
6833 6890
6834 init_rootdomain(rd); 6891 if (init_rootdomain(rd, false) != 0) {
6892 kfree(rd);
6893 return NULL;
6894 }
6835 6895
6836 return rd; 6896 return rd;
6837} 6897}
@@ -6873,19 +6933,12 @@ cpu_attach_domain(struct sched_domain *sd, struct root_domain *rd, int cpu)
6873} 6933}
6874 6934
6875/* cpus with isolated domains */ 6935/* cpus with isolated domains */
6876static cpumask_t cpu_isolated_map = CPU_MASK_NONE; 6936static cpumask_var_t cpu_isolated_map;
6877 6937
6878/* Setup the mask of cpus configured for isolated domains */ 6938/* Setup the mask of cpus configured for isolated domains */
6879static int __init isolated_cpu_setup(char *str) 6939static int __init isolated_cpu_setup(char *str)
6880{ 6940{
6881 static int __initdata ints[NR_CPUS]; 6941 cpulist_parse(str, *cpu_isolated_map);
6882 int i;
6883
6884 str = get_options(str, ARRAY_SIZE(ints), ints);
6885 cpus_clear(cpu_isolated_map);
6886 for (i = 1; i <= ints[0]; i++)
6887 if (ints[i] < NR_CPUS)
6888 cpu_set(ints[i], cpu_isolated_map);
6889 return 1; 6942 return 1;
6890} 6943}
6891 6944
@@ -6894,42 +6947,43 @@ __setup("isolcpus=", isolated_cpu_setup);
6894/* 6947/*
6895 * init_sched_build_groups takes the cpumask we wish to span, and a pointer 6948 * init_sched_build_groups takes the cpumask we wish to span, and a pointer
6896 * to a function which identifies what group(along with sched group) a CPU 6949 * to a function which identifies what group(along with sched group) a CPU
6897 * belongs to. The return value of group_fn must be a >= 0 and < NR_CPUS 6950 * belongs to. The return value of group_fn must be a >= 0 and < nr_cpu_ids
6898 * (due to the fact that we keep track of groups covered with a cpumask_t). 6951 * (due to the fact that we keep track of groups covered with a struct cpumask).
6899 * 6952 *
6900 * init_sched_build_groups will build a circular linked list of the groups 6953 * init_sched_build_groups will build a circular linked list of the groups
6901 * covered by the given span, and will set each group's ->cpumask correctly, 6954 * covered by the given span, and will set each group's ->cpumask correctly,
6902 * and ->cpu_power to 0. 6955 * and ->cpu_power to 0.
6903 */ 6956 */
6904static void 6957static void
6905init_sched_build_groups(const cpumask_t *span, const cpumask_t *cpu_map, 6958init_sched_build_groups(const struct cpumask *span,
6906 int (*group_fn)(int cpu, const cpumask_t *cpu_map, 6959 const struct cpumask *cpu_map,
6960 int (*group_fn)(int cpu, const struct cpumask *cpu_map,
6907 struct sched_group **sg, 6961 struct sched_group **sg,
6908 cpumask_t *tmpmask), 6962 struct cpumask *tmpmask),
6909 cpumask_t *covered, cpumask_t *tmpmask) 6963 struct cpumask *covered, struct cpumask *tmpmask)
6910{ 6964{
6911 struct sched_group *first = NULL, *last = NULL; 6965 struct sched_group *first = NULL, *last = NULL;
6912 int i; 6966 int i;
6913 6967
6914 cpus_clear(*covered); 6968 cpumask_clear(covered);
6915 6969
6916 for_each_cpu_mask_nr(i, *span) { 6970 for_each_cpu(i, span) {
6917 struct sched_group *sg; 6971 struct sched_group *sg;
6918 int group = group_fn(i, cpu_map, &sg, tmpmask); 6972 int group = group_fn(i, cpu_map, &sg, tmpmask);
6919 int j; 6973 int j;
6920 6974
6921 if (cpu_isset(i, *covered)) 6975 if (cpumask_test_cpu(i, covered))
6922 continue; 6976 continue;
6923 6977
6924 cpus_clear(sg->cpumask); 6978 cpumask_clear(sched_group_cpus(sg));
6925 sg->__cpu_power = 0; 6979 sg->__cpu_power = 0;
6926 6980
6927 for_each_cpu_mask_nr(j, *span) { 6981 for_each_cpu(j, span) {
6928 if (group_fn(j, cpu_map, NULL, tmpmask) != group) 6982 if (group_fn(j, cpu_map, NULL, tmpmask) != group)
6929 continue; 6983 continue;
6930 6984
6931 cpu_set(j, *covered); 6985 cpumask_set_cpu(j, covered);
6932 cpu_set(j, sg->cpumask); 6986 cpumask_set_cpu(j, sched_group_cpus(sg));
6933 } 6987 }
6934 if (!first) 6988 if (!first)
6935 first = sg; 6989 first = sg;
@@ -6993,9 +7047,10 @@ static int find_next_best_node(int node, nodemask_t *used_nodes)
6993 * should be one that prevents unnecessary balancing, but also spreads tasks 7047 * should be one that prevents unnecessary balancing, but also spreads tasks
6994 * out optimally. 7048 * out optimally.
6995 */ 7049 */
6996static void sched_domain_node_span(int node, cpumask_t *span) 7050static void sched_domain_node_span(int node, struct cpumask *span)
6997{ 7051{
6998 nodemask_t used_nodes; 7052 nodemask_t used_nodes;
7053 /* FIXME: use cpumask_of_node() */
6999 node_to_cpumask_ptr(nodemask, node); 7054 node_to_cpumask_ptr(nodemask, node);
7000 int i; 7055 int i;
7001 7056
@@ -7017,18 +7072,33 @@ static void sched_domain_node_span(int node, cpumask_t *span)
7017int sched_smt_power_savings = 0, sched_mc_power_savings = 0; 7072int sched_smt_power_savings = 0, sched_mc_power_savings = 0;
7018 7073
7019/* 7074/*
7075 * The cpus mask in sched_group and sched_domain hangs off the end.
7076 * FIXME: use cpumask_var_t or dynamic percpu alloc to avoid wasting space
7077 * for nr_cpu_ids < CONFIG_NR_CPUS.
7078 */
7079struct static_sched_group {
7080 struct sched_group sg;
7081 DECLARE_BITMAP(cpus, CONFIG_NR_CPUS);
7082};
7083
7084struct static_sched_domain {
7085 struct sched_domain sd;
7086 DECLARE_BITMAP(span, CONFIG_NR_CPUS);
7087};
7088
7089/*
7020 * SMT sched-domains: 7090 * SMT sched-domains:
7021 */ 7091 */
7022#ifdef CONFIG_SCHED_SMT 7092#ifdef CONFIG_SCHED_SMT
7023static DEFINE_PER_CPU(struct sched_domain, cpu_domains); 7093static DEFINE_PER_CPU(struct static_sched_domain, cpu_domains);
7024static DEFINE_PER_CPU(struct sched_group, sched_group_cpus); 7094static DEFINE_PER_CPU(struct static_sched_group, sched_group_cpus);
7025 7095
7026static int 7096static int
7027cpu_to_cpu_group(int cpu, const cpumask_t *cpu_map, struct sched_group **sg, 7097cpu_to_cpu_group(int cpu, const struct cpumask *cpu_map,
7028 cpumask_t *unused) 7098 struct sched_group **sg, struct cpumask *unused)
7029{ 7099{
7030 if (sg) 7100 if (sg)
7031 *sg = &per_cpu(sched_group_cpus, cpu); 7101 *sg = &per_cpu(sched_group_cpus, cpu).sg;
7032 return cpu; 7102 return cpu;
7033} 7103}
7034#endif /* CONFIG_SCHED_SMT */ 7104#endif /* CONFIG_SCHED_SMT */
@@ -7037,56 +7107,55 @@ cpu_to_cpu_group(int cpu, const cpumask_t *cpu_map, struct sched_group **sg,
7037 * multi-core sched-domains: 7107 * multi-core sched-domains:
7038 */ 7108 */
7039#ifdef CONFIG_SCHED_MC 7109#ifdef CONFIG_SCHED_MC
7040static DEFINE_PER_CPU(struct sched_domain, core_domains); 7110static DEFINE_PER_CPU(struct static_sched_domain, core_domains);
7041static DEFINE_PER_CPU(struct sched_group, sched_group_core); 7111static DEFINE_PER_CPU(struct static_sched_group, sched_group_core);
7042#endif /* CONFIG_SCHED_MC */ 7112#endif /* CONFIG_SCHED_MC */
7043 7113
7044#if defined(CONFIG_SCHED_MC) && defined(CONFIG_SCHED_SMT) 7114#if defined(CONFIG_SCHED_MC) && defined(CONFIG_SCHED_SMT)
7045static int 7115static int
7046cpu_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,
7047 cpumask_t *mask) 7117 struct sched_group **sg, struct cpumask *mask)
7048{ 7118{
7049 int group; 7119 int group;
7050 7120
7051 *mask = per_cpu(cpu_sibling_map, cpu); 7121 cpumask_and(mask, &per_cpu(cpu_sibling_map, cpu), cpu_map);
7052 cpus_and(*mask, *mask, *cpu_map); 7122 group = cpumask_first(mask);
7053 group = first_cpu(*mask);
7054 if (sg) 7123 if (sg)
7055 *sg = &per_cpu(sched_group_core, group); 7124 *sg = &per_cpu(sched_group_core, group).sg;
7056 return group; 7125 return group;
7057} 7126}
7058#elif defined(CONFIG_SCHED_MC) 7127#elif defined(CONFIG_SCHED_MC)
7059static int 7128static int
7060cpu_to_core_group(int cpu, const cpumask_t *cpu_map, struct sched_group **sg, 7129cpu_to_core_group(int cpu, const struct cpumask *cpu_map,
7061 cpumask_t *unused) 7130 struct sched_group **sg, struct cpumask *unused)
7062{ 7131{
7063 if (sg) 7132 if (sg)
7064 *sg = &per_cpu(sched_group_core, cpu); 7133 *sg = &per_cpu(sched_group_core, cpu).sg;
7065 return cpu; 7134 return cpu;
7066} 7135}
7067#endif 7136#endif
7068 7137
7069static DEFINE_PER_CPU(struct sched_domain, phys_domains); 7138static DEFINE_PER_CPU(struct static_sched_domain, phys_domains);
7070static DEFINE_PER_CPU(struct sched_group, sched_group_phys); 7139static DEFINE_PER_CPU(struct static_sched_group, sched_group_phys);
7071 7140
7072static int 7141static int
7073cpu_to_phys_group(int cpu, const cpumask_t *cpu_map, struct sched_group **sg, 7142cpu_to_phys_group(int cpu, const struct cpumask *cpu_map,
7074 cpumask_t *mask) 7143 struct sched_group **sg, struct cpumask *mask)
7075{ 7144{
7076 int group; 7145 int group;
7077#ifdef CONFIG_SCHED_MC 7146#ifdef CONFIG_SCHED_MC
7147 /* FIXME: Use cpu_coregroup_mask. */
7078 *mask = cpu_coregroup_map(cpu); 7148 *mask = cpu_coregroup_map(cpu);
7079 cpus_and(*mask, *mask, *cpu_map); 7149 cpus_and(*mask, *mask, *cpu_map);
7080 group = first_cpu(*mask); 7150 group = cpumask_first(mask);
7081#elif defined(CONFIG_SCHED_SMT) 7151#elif defined(CONFIG_SCHED_SMT)
7082 *mask = per_cpu(cpu_sibling_map, cpu); 7152 cpumask_and(mask, &per_cpu(cpu_sibling_map, cpu), cpu_map);
7083 cpus_and(*mask, *mask, *cpu_map); 7153 group = cpumask_first(mask);
7084 group = first_cpu(*mask);
7085#else 7154#else
7086 group = cpu; 7155 group = cpu;
7087#endif 7156#endif
7088 if (sg) 7157 if (sg)
7089 *sg = &per_cpu(sched_group_phys, group); 7158 *sg = &per_cpu(sched_group_phys, group).sg;
7090 return group; 7159 return group;
7091} 7160}
7092 7161
@@ -7100,19 +7169,21 @@ static DEFINE_PER_CPU(struct sched_domain, node_domains);
7100static struct sched_group ***sched_group_nodes_bycpu; 7169static struct sched_group ***sched_group_nodes_bycpu;
7101 7170
7102static DEFINE_PER_CPU(struct sched_domain, allnodes_domains); 7171static DEFINE_PER_CPU(struct sched_domain, allnodes_domains);
7103static DEFINE_PER_CPU(struct sched_group, sched_group_allnodes); 7172static DEFINE_PER_CPU(struct static_sched_group, sched_group_allnodes);
7104 7173
7105static int cpu_to_allnodes_group(int cpu, const cpumask_t *cpu_map, 7174static int cpu_to_allnodes_group(int cpu, const struct cpumask *cpu_map,
7106 struct sched_group **sg, cpumask_t *nodemask) 7175 struct sched_group **sg,
7176 struct cpumask *nodemask)
7107{ 7177{
7108 int group; 7178 int group;
7179 /* FIXME: use cpumask_of_node */
7180 node_to_cpumask_ptr(pnodemask, cpu_to_node(cpu));
7109 7181
7110 *nodemask = node_to_cpumask(cpu_to_node(cpu)); 7182 cpumask_and(nodemask, pnodemask, cpu_map);
7111 cpus_and(*nodemask, *nodemask, *cpu_map); 7183 group = cpumask_first(nodemask);
7112 group = first_cpu(*nodemask);
7113 7184
7114 if (sg) 7185 if (sg)
7115 *sg = &per_cpu(sched_group_allnodes, group); 7186 *sg = &per_cpu(sched_group_allnodes, group).sg;
7116 return group; 7187 return group;
7117} 7188}
7118 7189
@@ -7124,11 +7195,11 @@ static void init_numa_sched_groups_power(struct sched_group *group_head)
7124 if (!sg) 7195 if (!sg)
7125 return; 7196 return;
7126 do { 7197 do {
7127 for_each_cpu_mask_nr(j, sg->cpumask) { 7198 for_each_cpu(j, sched_group_cpus(sg)) {
7128 struct sched_domain *sd; 7199 struct sched_domain *sd;
7129 7200
7130 sd = &per_cpu(phys_domains, j); 7201 sd = &per_cpu(phys_domains, j).sd;
7131 if (j != first_cpu(sd->groups->cpumask)) { 7202 if (j != cpumask_first(sched_group_cpus(sd->groups))) {
7132 /* 7203 /*
7133 * Only add "power" once for each 7204 * Only add "power" once for each
7134 * physical package. 7205 * physical package.
@@ -7145,11 +7216,12 @@ static void init_numa_sched_groups_power(struct sched_group *group_head)
7145 7216
7146#ifdef CONFIG_NUMA 7217#ifdef CONFIG_NUMA
7147/* Free memory allocated for various sched_group structures */ 7218/* Free memory allocated for various sched_group structures */
7148static void free_sched_groups(const cpumask_t *cpu_map, cpumask_t *nodemask) 7219static void free_sched_groups(const struct cpumask *cpu_map,
7220 struct cpumask *nodemask)
7149{ 7221{
7150 int cpu, i; 7222 int cpu, i;
7151 7223
7152 for_each_cpu_mask_nr(cpu, *cpu_map) { 7224 for_each_cpu(cpu, cpu_map) {
7153 struct sched_group **sched_group_nodes 7225 struct sched_group **sched_group_nodes
7154 = sched_group_nodes_bycpu[cpu]; 7226 = sched_group_nodes_bycpu[cpu];
7155 7227
@@ -7158,10 +7230,11 @@ static void free_sched_groups(const cpumask_t *cpu_map, cpumask_t *nodemask)
7158 7230
7159 for (i = 0; i < nr_node_ids; i++) { 7231 for (i = 0; i < nr_node_ids; i++) {
7160 struct sched_group *oldsg, *sg = sched_group_nodes[i]; 7232 struct sched_group *oldsg, *sg = sched_group_nodes[i];
7233 /* FIXME: Use cpumask_of_node */
7234 node_to_cpumask_ptr(pnodemask, i);
7161 7235
7162 *nodemask = node_to_cpumask(i); 7236 cpus_and(*nodemask, *pnodemask, *cpu_map);
7163 cpus_and(*nodemask, *nodemask, *cpu_map); 7237 if (cpumask_empty(nodemask))
7164 if (cpus_empty(*nodemask))
7165 continue; 7238 continue;
7166 7239
7167 if (sg == NULL) 7240 if (sg == NULL)
@@ -7179,7 +7252,8 @@ next_sg:
7179 } 7252 }
7180} 7253}
7181#else /* !CONFIG_NUMA */ 7254#else /* !CONFIG_NUMA */
7182static void free_sched_groups(const cpumask_t *cpu_map, cpumask_t *nodemask) 7255static void free_sched_groups(const struct cpumask *cpu_map,
7256 struct cpumask *nodemask)
7183{ 7257{
7184} 7258}
7185#endif /* CONFIG_NUMA */ 7259#endif /* CONFIG_NUMA */
@@ -7205,7 +7279,7 @@ static void init_sched_groups_power(int cpu, struct sched_domain *sd)
7205 7279
7206 WARN_ON(!sd || !sd->groups); 7280 WARN_ON(!sd || !sd->groups);
7207 7281
7208 if (cpu != first_cpu(sd->groups->cpumask)) 7282 if (cpu != cpumask_first(sched_group_cpus(sd->groups)))
7209 return; 7283 return;
7210 7284
7211 child = sd->child; 7285 child = sd->child;
@@ -7270,48 +7344,6 @@ SD_INIT_FUNC(CPU)
7270 SD_INIT_FUNC(MC) 7344 SD_INIT_FUNC(MC)
7271#endif 7345#endif
7272 7346
7273/*
7274 * To minimize stack usage kmalloc room for cpumasks and share the
7275 * space as the usage in build_sched_domains() dictates. Used only
7276 * if the amount of space is significant.
7277 */
7278struct allmasks {
7279 cpumask_t tmpmask; /* make this one first */
7280 union {
7281 cpumask_t nodemask;
7282 cpumask_t this_sibling_map;
7283 cpumask_t this_core_map;
7284 };
7285 cpumask_t send_covered;
7286
7287#ifdef CONFIG_NUMA
7288 cpumask_t domainspan;
7289 cpumask_t covered;
7290 cpumask_t notcovered;
7291#endif
7292};
7293
7294#if NR_CPUS > 128
7295#define SCHED_CPUMASK_DECLARE(v) struct allmasks *v
7296static inline void sched_cpumask_alloc(struct allmasks **masks)
7297{
7298 *masks = kmalloc(sizeof(**masks), GFP_KERNEL);
7299}
7300static inline void sched_cpumask_free(struct allmasks *masks)
7301{
7302 kfree(masks);
7303}
7304#else
7305#define SCHED_CPUMASK_DECLARE(v) struct allmasks _v, *v = &_v
7306static inline void sched_cpumask_alloc(struct allmasks **masks)
7307{ }
7308static inline void sched_cpumask_free(struct allmasks *masks)
7309{ }
7310#endif
7311
7312#define SCHED_CPUMASK_VAR(v, a) cpumask_t *v = (cpumask_t *) \
7313 ((unsigned long)(a) + offsetof(struct allmasks, v))
7314
7315static int default_relax_domain_level = -1; 7347static int default_relax_domain_level = -1;
7316 7348
7317static int __init setup_relax_domain_level(char *str) 7349static int __init setup_relax_domain_level(char *str)
@@ -7351,17 +7383,38 @@ static void set_domain_attribute(struct sched_domain *sd,
7351 * Build sched domains for a given set of cpus and attach the sched domains 7383 * Build sched domains for a given set of cpus and attach the sched domains
7352 * to the individual cpus 7384 * to the individual cpus
7353 */ 7385 */
7354static int __build_sched_domains(const cpumask_t *cpu_map, 7386static int __build_sched_domains(const struct cpumask *cpu_map,
7355 struct sched_domain_attr *attr) 7387 struct sched_domain_attr *attr)
7356{ 7388{
7357 int i; 7389 int i, err = -ENOMEM;
7358 struct root_domain *rd; 7390 struct root_domain *rd;
7359 SCHED_CPUMASK_DECLARE(allmasks); 7391 cpumask_var_t nodemask, this_sibling_map, this_core_map, send_covered,
7360 cpumask_t *tmpmask; 7392 tmpmask;
7361#ifdef CONFIG_NUMA 7393#ifdef CONFIG_NUMA
7394 cpumask_var_t domainspan, covered, notcovered;
7362 struct sched_group **sched_group_nodes = NULL; 7395 struct sched_group **sched_group_nodes = NULL;
7363 int sd_allnodes = 0; 7396 int sd_allnodes = 0;
7364 7397
7398 if (!alloc_cpumask_var(&domainspan, GFP_KERNEL))
7399 goto out;
7400 if (!alloc_cpumask_var(&covered, GFP_KERNEL))
7401 goto free_domainspan;
7402 if (!alloc_cpumask_var(&notcovered, GFP_KERNEL))
7403 goto free_covered;
7404#endif
7405
7406 if (!alloc_cpumask_var(&nodemask, GFP_KERNEL))
7407 goto free_notcovered;
7408 if (!alloc_cpumask_var(&this_sibling_map, GFP_KERNEL))
7409 goto free_nodemask;
7410 if (!alloc_cpumask_var(&this_core_map, GFP_KERNEL))
7411 goto free_this_sibling_map;
7412 if (!alloc_cpumask_var(&send_covered, GFP_KERNEL))
7413 goto free_this_core_map;
7414 if (!alloc_cpumask_var(&tmpmask, GFP_KERNEL))
7415 goto free_send_covered;
7416
7417#ifdef CONFIG_NUMA
7365 /* 7418 /*
7366 * Allocate the per-node list of sched groups 7419 * Allocate the per-node list of sched groups
7367 */ 7420 */
@@ -7369,54 +7422,37 @@ static int __build_sched_domains(const cpumask_t *cpu_map,
7369 GFP_KERNEL); 7422 GFP_KERNEL);
7370 if (!sched_group_nodes) { 7423 if (!sched_group_nodes) {
7371 printk(KERN_WARNING "Can not alloc sched group node list\n"); 7424 printk(KERN_WARNING "Can not alloc sched group node list\n");
7372 return -ENOMEM; 7425 goto free_tmpmask;
7373 } 7426 }
7374#endif 7427#endif
7375 7428
7376 rd = alloc_rootdomain(); 7429 rd = alloc_rootdomain();
7377 if (!rd) { 7430 if (!rd) {
7378 printk(KERN_WARNING "Cannot alloc root domain\n"); 7431 printk(KERN_WARNING "Cannot alloc root domain\n");
7379#ifdef CONFIG_NUMA 7432 goto free_sched_groups;
7380 kfree(sched_group_nodes);
7381#endif
7382 return -ENOMEM;
7383 } 7433 }
7384 7434
7385 /* get space for all scratch cpumask variables */
7386 sched_cpumask_alloc(&allmasks);
7387 if (!allmasks) {
7388 printk(KERN_WARNING "Cannot alloc cpumask array\n");
7389 kfree(rd);
7390#ifdef CONFIG_NUMA 7435#ifdef CONFIG_NUMA
7391 kfree(sched_group_nodes); 7436 sched_group_nodes_bycpu[cpumask_first(cpu_map)] = sched_group_nodes;
7392#endif
7393 return -ENOMEM;
7394 }
7395
7396 tmpmask = (cpumask_t *)allmasks;
7397
7398
7399#ifdef CONFIG_NUMA
7400 sched_group_nodes_bycpu[first_cpu(*cpu_map)] = sched_group_nodes;
7401#endif 7437#endif
7402 7438
7403 /* 7439 /*
7404 * Set up domains for cpus specified by the cpu_map. 7440 * Set up domains for cpus specified by the cpu_map.
7405 */ 7441 */
7406 for_each_cpu_mask_nr(i, *cpu_map) { 7442 for_each_cpu(i, cpu_map) {
7407 struct sched_domain *sd = NULL, *p; 7443 struct sched_domain *sd = NULL, *p;
7408 SCHED_CPUMASK_VAR(nodemask, allmasks);
7409 7444
7445 /* FIXME: use cpumask_of_node */
7410 *nodemask = node_to_cpumask(cpu_to_node(i)); 7446 *nodemask = node_to_cpumask(cpu_to_node(i));
7411 cpus_and(*nodemask, *nodemask, *cpu_map); 7447 cpus_and(*nodemask, *nodemask, *cpu_map);
7412 7448
7413#ifdef CONFIG_NUMA 7449#ifdef CONFIG_NUMA
7414 if (cpus_weight(*cpu_map) > 7450 if (cpumask_weight(cpu_map) >
7415 SD_NODES_PER_DOMAIN*cpus_weight(*nodemask)) { 7451 SD_NODES_PER_DOMAIN*cpumask_weight(nodemask)) {
7416 sd = &per_cpu(allnodes_domains, i); 7452 sd = &per_cpu(allnodes_domains, i);
7417 SD_INIT(sd, ALLNODES); 7453 SD_INIT(sd, ALLNODES);
7418 set_domain_attribute(sd, attr); 7454 set_domain_attribute(sd, attr);
7419 sd->span = *cpu_map; 7455 cpumask_copy(sched_domain_span(sd), cpu_map);
7420 cpu_to_allnodes_group(i, cpu_map, &sd->groups, tmpmask); 7456 cpu_to_allnodes_group(i, cpu_map, &sd->groups, tmpmask);
7421 p = sd; 7457 p = sd;
7422 sd_allnodes = 1; 7458 sd_allnodes = 1;
@@ -7426,18 +7462,19 @@ static int __build_sched_domains(const cpumask_t *cpu_map,
7426 sd = &per_cpu(node_domains, i); 7462 sd = &per_cpu(node_domains, i);
7427 SD_INIT(sd, NODE); 7463 SD_INIT(sd, NODE);
7428 set_domain_attribute(sd, attr); 7464 set_domain_attribute(sd, attr);
7429 sched_domain_node_span(cpu_to_node(i), &sd->span); 7465 sched_domain_node_span(cpu_to_node(i), sched_domain_span(sd));
7430 sd->parent = p; 7466 sd->parent = p;
7431 if (p) 7467 if (p)
7432 p->child = sd; 7468 p->child = sd;
7433 cpus_and(sd->span, sd->span, *cpu_map); 7469 cpumask_and(sched_domain_span(sd),
7470 sched_domain_span(sd), cpu_map);
7434#endif 7471#endif
7435 7472
7436 p = sd; 7473 p = sd;
7437 sd = &per_cpu(phys_domains, i); 7474 sd = &per_cpu(phys_domains, i).sd;
7438 SD_INIT(sd, CPU); 7475 SD_INIT(sd, CPU);
7439 set_domain_attribute(sd, attr); 7476 set_domain_attribute(sd, attr);
7440 sd->span = *nodemask; 7477 cpumask_copy(sched_domain_span(sd), nodemask);
7441 sd->parent = p; 7478 sd->parent = p;
7442 if (p) 7479 if (p)
7443 p->child = sd; 7480 p->child = sd;
@@ -7445,11 +7482,12 @@ static int __build_sched_domains(const cpumask_t *cpu_map,
7445 7482
7446#ifdef CONFIG_SCHED_MC 7483#ifdef CONFIG_SCHED_MC
7447 p = sd; 7484 p = sd;
7448 sd = &per_cpu(core_domains, i); 7485 sd = &per_cpu(core_domains, i).sd;
7449 SD_INIT(sd, MC); 7486 SD_INIT(sd, MC);
7450 set_domain_attribute(sd, attr); 7487 set_domain_attribute(sd, attr);
7451 sd->span = cpu_coregroup_map(i); 7488 *sched_domain_span(sd) = cpu_coregroup_map(i);
7452 cpus_and(sd->span, sd->span, *cpu_map); 7489 cpumask_and(sched_domain_span(sd),
7490 sched_domain_span(sd), cpu_map);
7453 sd->parent = p; 7491 sd->parent = p;
7454 p->child = sd; 7492 p->child = sd;
7455 cpu_to_core_group(i, cpu_map, &sd->groups, tmpmask); 7493 cpu_to_core_group(i, cpu_map, &sd->groups, tmpmask);
@@ -7457,11 +7495,11 @@ static int __build_sched_domains(const cpumask_t *cpu_map,
7457 7495
7458#ifdef CONFIG_SCHED_SMT 7496#ifdef CONFIG_SCHED_SMT
7459 p = sd; 7497 p = sd;
7460 sd = &per_cpu(cpu_domains, i); 7498 sd = &per_cpu(cpu_domains, i).sd;
7461 SD_INIT(sd, SIBLING); 7499 SD_INIT(sd, SIBLING);
7462 set_domain_attribute(sd, attr); 7500 set_domain_attribute(sd, attr);
7463 sd->span = per_cpu(cpu_sibling_map, i); 7501 cpumask_and(sched_domain_span(sd),
7464 cpus_and(sd->span, sd->span, *cpu_map); 7502 &per_cpu(cpu_sibling_map, i), cpu_map);
7465 sd->parent = p; 7503 sd->parent = p;
7466 p->child = sd; 7504 p->child = sd;
7467 cpu_to_cpu_group(i, cpu_map, &sd->groups, tmpmask); 7505 cpu_to_cpu_group(i, cpu_map, &sd->groups, tmpmask);
@@ -7470,13 +7508,10 @@ static int __build_sched_domains(const cpumask_t *cpu_map,
7470 7508
7471#ifdef CONFIG_SCHED_SMT 7509#ifdef CONFIG_SCHED_SMT
7472 /* Set up CPU (sibling) groups */ 7510 /* Set up CPU (sibling) groups */
7473 for_each_cpu_mask_nr(i, *cpu_map) { 7511 for_each_cpu(i, cpu_map) {
7474 SCHED_CPUMASK_VAR(this_sibling_map, allmasks); 7512 cpumask_and(this_sibling_map,
7475 SCHED_CPUMASK_VAR(send_covered, allmasks); 7513 &per_cpu(cpu_sibling_map, i), cpu_map);
7476 7514 if (i != cpumask_first(this_sibling_map))
7477 *this_sibling_map = per_cpu(cpu_sibling_map, i);
7478 cpus_and(*this_sibling_map, *this_sibling_map, *cpu_map);
7479 if (i != first_cpu(*this_sibling_map))
7480 continue; 7515 continue;
7481 7516
7482 init_sched_build_groups(this_sibling_map, cpu_map, 7517 init_sched_build_groups(this_sibling_map, cpu_map,
@@ -7487,13 +7522,11 @@ static int __build_sched_domains(const cpumask_t *cpu_map,
7487 7522
7488#ifdef CONFIG_SCHED_MC 7523#ifdef CONFIG_SCHED_MC
7489 /* Set up multi-core groups */ 7524 /* Set up multi-core groups */
7490 for_each_cpu_mask_nr(i, *cpu_map) { 7525 for_each_cpu(i, cpu_map) {
7491 SCHED_CPUMASK_VAR(this_core_map, allmasks); 7526 /* FIXME: Use cpu_coregroup_mask */
7492 SCHED_CPUMASK_VAR(send_covered, allmasks);
7493
7494 *this_core_map = cpu_coregroup_map(i); 7527 *this_core_map = cpu_coregroup_map(i);
7495 cpus_and(*this_core_map, *this_core_map, *cpu_map); 7528 cpus_and(*this_core_map, *this_core_map, *cpu_map);
7496 if (i != first_cpu(*this_core_map)) 7529 if (i != cpumask_first(this_core_map))
7497 continue; 7530 continue;
7498 7531
7499 init_sched_build_groups(this_core_map, cpu_map, 7532 init_sched_build_groups(this_core_map, cpu_map,
@@ -7504,12 +7537,10 @@ static int __build_sched_domains(const cpumask_t *cpu_map,
7504 7537
7505 /* Set up physical groups */ 7538 /* Set up physical groups */
7506 for (i = 0; i < nr_node_ids; i++) { 7539 for (i = 0; i < nr_node_ids; i++) {
7507 SCHED_CPUMASK_VAR(nodemask, allmasks); 7540 /* FIXME: Use cpumask_of_node */
7508 SCHED_CPUMASK_VAR(send_covered, allmasks);
7509
7510 *nodemask = node_to_cpumask(i); 7541 *nodemask = node_to_cpumask(i);
7511 cpus_and(*nodemask, *nodemask, *cpu_map); 7542 cpus_and(*nodemask, *nodemask, *cpu_map);
7512 if (cpus_empty(*nodemask)) 7543 if (cpumask_empty(nodemask))
7513 continue; 7544 continue;
7514 7545
7515 init_sched_build_groups(nodemask, cpu_map, 7546 init_sched_build_groups(nodemask, cpu_map,
@@ -7520,8 +7551,6 @@ static int __build_sched_domains(const cpumask_t *cpu_map,
7520#ifdef CONFIG_NUMA 7551#ifdef CONFIG_NUMA
7521 /* Set up node groups */ 7552 /* Set up node groups */
7522 if (sd_allnodes) { 7553 if (sd_allnodes) {
7523 SCHED_CPUMASK_VAR(send_covered, allmasks);
7524
7525 init_sched_build_groups(cpu_map, cpu_map, 7554 init_sched_build_groups(cpu_map, cpu_map,
7526 &cpu_to_allnodes_group, 7555 &cpu_to_allnodes_group,
7527 send_covered, tmpmask); 7556 send_covered, tmpmask);
@@ -7530,58 +7559,58 @@ static int __build_sched_domains(const cpumask_t *cpu_map,
7530 for (i = 0; i < nr_node_ids; i++) { 7559 for (i = 0; i < nr_node_ids; i++) {
7531 /* Set up node groups */ 7560 /* Set up node groups */
7532 struct sched_group *sg, *prev; 7561 struct sched_group *sg, *prev;
7533 SCHED_CPUMASK_VAR(nodemask, allmasks);
7534 SCHED_CPUMASK_VAR(domainspan, allmasks);
7535 SCHED_CPUMASK_VAR(covered, allmasks);
7536 int j; 7562 int j;
7537 7563
7564 /* FIXME: Use cpumask_of_node */
7538 *nodemask = node_to_cpumask(i); 7565 *nodemask = node_to_cpumask(i);
7539 cpus_clear(*covered); 7566 cpumask_clear(covered);
7540 7567
7541 cpus_and(*nodemask, *nodemask, *cpu_map); 7568 cpus_and(*nodemask, *nodemask, *cpu_map);
7542 if (cpus_empty(*nodemask)) { 7569 if (cpumask_empty(nodemask)) {
7543 sched_group_nodes[i] = NULL; 7570 sched_group_nodes[i] = NULL;
7544 continue; 7571 continue;
7545 } 7572 }
7546 7573
7547 sched_domain_node_span(i, domainspan); 7574 sched_domain_node_span(i, domainspan);
7548 cpus_and(*domainspan, *domainspan, *cpu_map); 7575 cpumask_and(domainspan, domainspan, cpu_map);
7549 7576
7550 sg = kmalloc_node(sizeof(struct sched_group), GFP_KERNEL, i); 7577 sg = kmalloc_node(sizeof(struct sched_group) + cpumask_size(),
7578 GFP_KERNEL, i);
7551 if (!sg) { 7579 if (!sg) {
7552 printk(KERN_WARNING "Can not alloc domain group for " 7580 printk(KERN_WARNING "Can not alloc domain group for "
7553 "node %d\n", i); 7581 "node %d\n", i);
7554 goto error; 7582 goto error;
7555 } 7583 }
7556 sched_group_nodes[i] = sg; 7584 sched_group_nodes[i] = sg;
7557 for_each_cpu_mask_nr(j, *nodemask) { 7585 for_each_cpu(j, nodemask) {
7558 struct sched_domain *sd; 7586 struct sched_domain *sd;
7559 7587
7560 sd = &per_cpu(node_domains, j); 7588 sd = &per_cpu(node_domains, j);
7561 sd->groups = sg; 7589 sd->groups = sg;
7562 } 7590 }
7563 sg->__cpu_power = 0; 7591 sg->__cpu_power = 0;
7564 sg->cpumask = *nodemask; 7592 cpumask_copy(sched_group_cpus(sg), nodemask);
7565 sg->next = sg; 7593 sg->next = sg;
7566 cpus_or(*covered, *covered, *nodemask); 7594 cpumask_or(covered, covered, nodemask);
7567 prev = sg; 7595 prev = sg;
7568 7596
7569 for (j = 0; j < nr_node_ids; j++) { 7597 for (j = 0; j < nr_node_ids; j++) {
7570 SCHED_CPUMASK_VAR(notcovered, allmasks);
7571 int n = (i + j) % nr_node_ids; 7598 int n = (i + j) % nr_node_ids;
7599 /* FIXME: Use cpumask_of_node */
7572 node_to_cpumask_ptr(pnodemask, n); 7600 node_to_cpumask_ptr(pnodemask, n);
7573 7601
7574 cpus_complement(*notcovered, *covered); 7602 cpumask_complement(notcovered, covered);
7575 cpus_and(*tmpmask, *notcovered, *cpu_map); 7603 cpumask_and(tmpmask, notcovered, cpu_map);
7576 cpus_and(*tmpmask, *tmpmask, *domainspan); 7604 cpumask_and(tmpmask, tmpmask, domainspan);
7577 if (cpus_empty(*tmpmask)) 7605 if (cpumask_empty(tmpmask))
7578 break; 7606 break;
7579 7607
7580 cpus_and(*tmpmask, *tmpmask, *pnodemask); 7608 cpumask_and(tmpmask, tmpmask, pnodemask);
7581 if (cpus_empty(*tmpmask)) 7609 if (cpumask_empty(tmpmask))
7582 continue; 7610 continue;
7583 7611
7584 sg = kmalloc_node(sizeof(struct sched_group), 7612 sg = kmalloc_node(sizeof(struct sched_group) +
7613 cpumask_size(),
7585 GFP_KERNEL, i); 7614 GFP_KERNEL, i);
7586 if (!sg) { 7615 if (!sg) {
7587 printk(KERN_WARNING 7616 printk(KERN_WARNING
@@ -7589,9 +7618,9 @@ static int __build_sched_domains(const cpumask_t *cpu_map,
7589 goto error; 7618 goto error;
7590 } 7619 }
7591 sg->__cpu_power = 0; 7620 sg->__cpu_power = 0;
7592 sg->cpumask = *tmpmask; 7621 cpumask_copy(sched_group_cpus(sg), tmpmask);
7593 sg->next = prev->next; 7622 sg->next = prev->next;
7594 cpus_or(*covered, *covered, *tmpmask); 7623 cpumask_or(covered, covered, tmpmask);
7595 prev->next = sg; 7624 prev->next = sg;
7596 prev = sg; 7625 prev = sg;
7597 } 7626 }
@@ -7600,22 +7629,22 @@ static int __build_sched_domains(const cpumask_t *cpu_map,
7600 7629
7601 /* Calculate CPU power for physical packages and nodes */ 7630 /* Calculate CPU power for physical packages and nodes */
7602#ifdef CONFIG_SCHED_SMT 7631#ifdef CONFIG_SCHED_SMT
7603 for_each_cpu_mask_nr(i, *cpu_map) { 7632 for_each_cpu(i, cpu_map) {
7604 struct sched_domain *sd = &per_cpu(cpu_domains, i); 7633 struct sched_domain *sd = &per_cpu(cpu_domains, i).sd;
7605 7634
7606 init_sched_groups_power(i, sd); 7635 init_sched_groups_power(i, sd);
7607 } 7636 }
7608#endif 7637#endif
7609#ifdef CONFIG_SCHED_MC 7638#ifdef CONFIG_SCHED_MC
7610 for_each_cpu_mask_nr(i, *cpu_map) { 7639 for_each_cpu(i, cpu_map) {
7611 struct sched_domain *sd = &per_cpu(core_domains, i); 7640 struct sched_domain *sd = &per_cpu(core_domains, i).sd;
7612 7641
7613 init_sched_groups_power(i, sd); 7642 init_sched_groups_power(i, sd);
7614 } 7643 }
7615#endif 7644#endif
7616 7645
7617 for_each_cpu_mask_nr(i, *cpu_map) { 7646 for_each_cpu(i, cpu_map) {
7618 struct sched_domain *sd = &per_cpu(phys_domains, i); 7647 struct sched_domain *sd = &per_cpu(phys_domains, i).sd;
7619 7648
7620 init_sched_groups_power(i, sd); 7649 init_sched_groups_power(i, sd);
7621 } 7650 }
@@ -7627,53 +7656,78 @@ static int __build_sched_domains(const cpumask_t *cpu_map,
7627 if (sd_allnodes) { 7656 if (sd_allnodes) {
7628 struct sched_group *sg; 7657 struct sched_group *sg;
7629 7658
7630 cpu_to_allnodes_group(first_cpu(*cpu_map), cpu_map, &sg, 7659 cpu_to_allnodes_group(cpumask_first(cpu_map), cpu_map, &sg,
7631 tmpmask); 7660 tmpmask);
7632 init_numa_sched_groups_power(sg); 7661 init_numa_sched_groups_power(sg);
7633 } 7662 }
7634#endif 7663#endif
7635 7664
7636 /* Attach the domains */ 7665 /* Attach the domains */
7637 for_each_cpu_mask_nr(i, *cpu_map) { 7666 for_each_cpu(i, cpu_map) {
7638 struct sched_domain *sd; 7667 struct sched_domain *sd;
7639#ifdef CONFIG_SCHED_SMT 7668#ifdef CONFIG_SCHED_SMT
7640 sd = &per_cpu(cpu_domains, i); 7669 sd = &per_cpu(cpu_domains, i).sd;
7641#elif defined(CONFIG_SCHED_MC) 7670#elif defined(CONFIG_SCHED_MC)
7642 sd = &per_cpu(core_domains, i); 7671 sd = &per_cpu(core_domains, i).sd;
7643#else 7672#else
7644 sd = &per_cpu(phys_domains, i); 7673 sd = &per_cpu(phys_domains, i).sd;
7645#endif 7674#endif
7646 cpu_attach_domain(sd, rd, i); 7675 cpu_attach_domain(sd, rd, i);
7647 } 7676 }
7648 7677
7649 sched_cpumask_free(allmasks); 7678 err = 0;
7650 return 0; 7679
7680free_tmpmask:
7681 free_cpumask_var(tmpmask);
7682free_send_covered:
7683 free_cpumask_var(send_covered);
7684free_this_core_map:
7685 free_cpumask_var(this_core_map);
7686free_this_sibling_map:
7687 free_cpumask_var(this_sibling_map);
7688free_nodemask:
7689 free_cpumask_var(nodemask);
7690free_notcovered:
7691#ifdef CONFIG_NUMA
7692 free_cpumask_var(notcovered);
7693free_covered:
7694 free_cpumask_var(covered);
7695free_domainspan:
7696 free_cpumask_var(domainspan);
7697out:
7698#endif
7699 return err;
7700
7701free_sched_groups:
7702#ifdef CONFIG_NUMA
7703 kfree(sched_group_nodes);
7704#endif
7705 goto free_tmpmask;
7651 7706
7652#ifdef CONFIG_NUMA 7707#ifdef CONFIG_NUMA
7653error: 7708error:
7654 free_sched_groups(cpu_map, tmpmask); 7709 free_sched_groups(cpu_map, tmpmask);
7655 sched_cpumask_free(allmasks); 7710 free_rootdomain(rd);
7656 kfree(rd); 7711 goto free_tmpmask;
7657 return -ENOMEM;
7658#endif 7712#endif
7659} 7713}
7660 7714
7661static int build_sched_domains(const cpumask_t *cpu_map) 7715static int build_sched_domains(const struct cpumask *cpu_map)
7662{ 7716{
7663 return __build_sched_domains(cpu_map, NULL); 7717 return __build_sched_domains(cpu_map, NULL);
7664} 7718}
7665 7719
7666static cpumask_t *doms_cur; /* current sched domains */ 7720static struct cpumask *doms_cur; /* current sched domains */
7667static int ndoms_cur; /* number of sched domains in 'doms_cur' */ 7721static int ndoms_cur; /* number of sched domains in 'doms_cur' */
7668static struct sched_domain_attr *dattr_cur; 7722static struct sched_domain_attr *dattr_cur;
7669 /* attribues of custom domains in 'doms_cur' */ 7723 /* attribues of custom domains in 'doms_cur' */
7670 7724
7671/* 7725/*
7672 * Special case: If a kmalloc of a doms_cur partition (array of 7726 * Special case: If a kmalloc of a doms_cur partition (array of
7673 * cpumask_t) fails, then fallback to a single sched domain, 7727 * cpumask) fails, then fallback to a single sched domain,
7674 * as determined by the single cpumask_t fallback_doms. 7728 * as determined by the single cpumask fallback_doms.
7675 */ 7729 */
7676static cpumask_t fallback_doms; 7730static cpumask_var_t fallback_doms;
7677 7731
7678/* 7732/*
7679 * arch_update_cpu_topology lets virtualized architectures update the 7733 * arch_update_cpu_topology lets virtualized architectures update the
@@ -7690,16 +7744,16 @@ int __attribute__((weak)) arch_update_cpu_topology(void)
7690 * For now this just excludes isolated cpus, but could be used to 7744 * For now this just excludes isolated cpus, but could be used to
7691 * exclude other special cases in the future. 7745 * exclude other special cases in the future.
7692 */ 7746 */
7693static int arch_init_sched_domains(const cpumask_t *cpu_map) 7747static int arch_init_sched_domains(const struct cpumask *cpu_map)
7694{ 7748{
7695 int err; 7749 int err;
7696 7750
7697 arch_update_cpu_topology(); 7751 arch_update_cpu_topology();
7698 ndoms_cur = 1; 7752 ndoms_cur = 1;
7699 doms_cur = kmalloc(sizeof(cpumask_t), GFP_KERNEL); 7753 doms_cur = kmalloc(cpumask_size(), GFP_KERNEL);
7700 if (!doms_cur) 7754 if (!doms_cur)
7701 doms_cur = &fallback_doms; 7755 doms_cur = fallback_doms;
7702 cpus_andnot(*doms_cur, *cpu_map, cpu_isolated_map); 7756 cpumask_andnot(doms_cur, cpu_map, cpu_isolated_map);
7703 dattr_cur = NULL; 7757 dattr_cur = NULL;
7704 err = build_sched_domains(doms_cur); 7758 err = build_sched_domains(doms_cur);
7705 register_sched_domain_sysctl(); 7759 register_sched_domain_sysctl();
@@ -7707,8 +7761,8 @@ static int arch_init_sched_domains(const cpumask_t *cpu_map)
7707 return err; 7761 return err;
7708} 7762}
7709 7763
7710static void arch_destroy_sched_domains(const cpumask_t *cpu_map, 7764static void arch_destroy_sched_domains(const struct cpumask *cpu_map,
7711 cpumask_t *tmpmask) 7765 struct cpumask *tmpmask)
7712{ 7766{
7713 free_sched_groups(cpu_map, tmpmask); 7767 free_sched_groups(cpu_map, tmpmask);
7714} 7768}
@@ -7717,15 +7771,16 @@ static void arch_destroy_sched_domains(const cpumask_t *cpu_map,
7717 * Detach sched domains from a group of cpus specified in cpu_map 7771 * Detach sched domains from a group of cpus specified in cpu_map
7718 * These cpus will now be attached to the NULL domain 7772 * These cpus will now be attached to the NULL domain
7719 */ 7773 */
7720static void detach_destroy_domains(const cpumask_t *cpu_map) 7774static void detach_destroy_domains(const struct cpumask *cpu_map)
7721{ 7775{
7722 cpumask_t tmpmask; 7776 /* Save because hotplug lock held. */
7777 static DECLARE_BITMAP(tmpmask, CONFIG_NR_CPUS);
7723 int i; 7778 int i;
7724 7779
7725 for_each_cpu_mask_nr(i, *cpu_map) 7780 for_each_cpu(i, cpu_map)
7726 cpu_attach_domain(NULL, &def_root_domain, i); 7781 cpu_attach_domain(NULL, &def_root_domain, i);
7727 synchronize_sched(); 7782 synchronize_sched();
7728 arch_destroy_sched_domains(cpu_map, &tmpmask); 7783 arch_destroy_sched_domains(cpu_map, to_cpumask(tmpmask));
7729} 7784}
7730 7785
7731/* handle null as "default" */ 7786/* handle null as "default" */
@@ -7750,7 +7805,7 @@ static int dattrs_equal(struct sched_domain_attr *cur, int idx_cur,
7750 * doms_new[] to the current sched domain partitioning, doms_cur[]. 7805 * doms_new[] to the current sched domain partitioning, doms_cur[].
7751 * It destroys each deleted domain and builds each new domain. 7806 * It destroys each deleted domain and builds each new domain.
7752 * 7807 *
7753 * 'doms_new' is an array of cpumask_t's of length 'ndoms_new'. 7808 * 'doms_new' is an array of cpumask's of length 'ndoms_new'.
7754 * The masks don't intersect (don't overlap.) We should setup one 7809 * The masks don't intersect (don't overlap.) We should setup one
7755 * sched domain for each mask. CPUs not in any of the cpumasks will 7810 * sched domain for each mask. CPUs not in any of the cpumasks will
7756 * not be load balanced. If the same cpumask appears both in the 7811 * not be load balanced. If the same cpumask appears both in the
@@ -7764,13 +7819,14 @@ static int dattrs_equal(struct sched_domain_attr *cur, int idx_cur,
7764 * the single partition 'fallback_doms', it also forces the domains 7819 * the single partition 'fallback_doms', it also forces the domains
7765 * to be rebuilt. 7820 * to be rebuilt.
7766 * 7821 *
7767 * If doms_new == NULL it will be replaced with cpu_online_map. 7822 * If doms_new == NULL it will be replaced with cpu_online_mask.
7768 * ndoms_new == 0 is a special case for destroying existing domains, 7823 * ndoms_new == 0 is a special case for destroying existing domains,
7769 * and it will not create the default domain. 7824 * and it will not create the default domain.
7770 * 7825 *
7771 * Call with hotplug lock held 7826 * Call with hotplug lock held
7772 */ 7827 */
7773void partition_sched_domains(int ndoms_new, cpumask_t *doms_new, 7828/* FIXME: Change to struct cpumask *doms_new[] */
7829void partition_sched_domains(int ndoms_new, struct cpumask *doms_new,
7774 struct sched_domain_attr *dattr_new) 7830 struct sched_domain_attr *dattr_new)
7775{ 7831{
7776 int i, j, n; 7832 int i, j, n;
@@ -7789,7 +7845,7 @@ void partition_sched_domains(int ndoms_new, cpumask_t *doms_new,
7789 /* Destroy deleted domains */ 7845 /* Destroy deleted domains */
7790 for (i = 0; i < ndoms_cur; i++) { 7846 for (i = 0; i < ndoms_cur; i++) {
7791 for (j = 0; j < n && !new_topology; j++) { 7847 for (j = 0; j < n && !new_topology; j++) {
7792 if (cpus_equal(doms_cur[i], doms_new[j]) 7848 if (cpumask_equal(&doms_cur[i], &doms_new[j])
7793 && dattrs_equal(dattr_cur, i, dattr_new, j)) 7849 && dattrs_equal(dattr_cur, i, dattr_new, j))
7794 goto match1; 7850 goto match1;
7795 } 7851 }
@@ -7801,15 +7857,15 @@ match1:
7801 7857
7802 if (doms_new == NULL) { 7858 if (doms_new == NULL) {
7803 ndoms_cur = 0; 7859 ndoms_cur = 0;
7804 doms_new = &fallback_doms; 7860 doms_new = fallback_doms;
7805 cpus_andnot(doms_new[0], cpu_online_map, cpu_isolated_map); 7861 cpumask_andnot(&doms_new[0], cpu_online_mask, cpu_isolated_map);
7806 WARN_ON_ONCE(dattr_new); 7862 WARN_ON_ONCE(dattr_new);
7807 } 7863 }
7808 7864
7809 /* Build new domains */ 7865 /* Build new domains */
7810 for (i = 0; i < ndoms_new; i++) { 7866 for (i = 0; i < ndoms_new; i++) {
7811 for (j = 0; j < ndoms_cur && !new_topology; j++) { 7867 for (j = 0; j < ndoms_cur && !new_topology; j++) {
7812 if (cpus_equal(doms_new[i], doms_cur[j]) 7868 if (cpumask_equal(&doms_new[i], &doms_cur[j])
7813 && dattrs_equal(dattr_new, i, dattr_cur, j)) 7869 && dattrs_equal(dattr_new, i, dattr_cur, j))
7814 goto match2; 7870 goto match2;
7815 } 7871 }
@@ -7821,7 +7877,7 @@ match2:
7821 } 7877 }
7822 7878
7823 /* Remember the new sched domains */ 7879 /* Remember the new sched domains */
7824 if (doms_cur != &fallback_doms) 7880 if (doms_cur != fallback_doms)
7825 kfree(doms_cur); 7881 kfree(doms_cur);
7826 kfree(dattr_cur); /* kfree(NULL) is safe */ 7882 kfree(dattr_cur); /* kfree(NULL) is safe */
7827 doms_cur = doms_new; 7883 doms_cur = doms_new;
@@ -7961,7 +8017,9 @@ static int update_runtime(struct notifier_block *nfb,
7961 8017
7962void __init sched_init_smp(void) 8018void __init sched_init_smp(void)
7963{ 8019{
7964 cpumask_t non_isolated_cpus; 8020 cpumask_var_t non_isolated_cpus;
8021
8022 alloc_cpumask_var(&non_isolated_cpus, GFP_KERNEL);
7965 8023
7966#if defined(CONFIG_NUMA) 8024#if defined(CONFIG_NUMA)
7967 sched_group_nodes_bycpu = kzalloc(nr_cpu_ids * sizeof(void **), 8025 sched_group_nodes_bycpu = kzalloc(nr_cpu_ids * sizeof(void **),
@@ -7970,10 +8028,10 @@ void __init sched_init_smp(void)
7970#endif 8028#endif
7971 get_online_cpus(); 8029 get_online_cpus();
7972 mutex_lock(&sched_domains_mutex); 8030 mutex_lock(&sched_domains_mutex);
7973 arch_init_sched_domains(&cpu_online_map); 8031 arch_init_sched_domains(cpu_online_mask);
7974 cpus_andnot(non_isolated_cpus, cpu_possible_map, cpu_isolated_map); 8032 cpumask_andnot(non_isolated_cpus, cpu_possible_mask, cpu_isolated_map);
7975 if (cpus_empty(non_isolated_cpus)) 8033 if (cpumask_empty(non_isolated_cpus))
7976 cpu_set(smp_processor_id(), non_isolated_cpus); 8034 cpumask_set_cpu(smp_processor_id(), non_isolated_cpus);
7977 mutex_unlock(&sched_domains_mutex); 8035 mutex_unlock(&sched_domains_mutex);
7978 put_online_cpus(); 8036 put_online_cpus();
7979 8037
@@ -7988,9 +8046,13 @@ void __init sched_init_smp(void)
7988 init_hrtick(); 8046 init_hrtick();
7989 8047
7990 /* Move init over to a non-isolated CPU */ 8048 /* Move init over to a non-isolated CPU */
7991 if (set_cpus_allowed_ptr(current, &non_isolated_cpus) < 0) 8049 if (set_cpus_allowed_ptr(current, non_isolated_cpus) < 0)
7992 BUG(); 8050 BUG();
7993 sched_init_granularity(); 8051 sched_init_granularity();
8052 free_cpumask_var(non_isolated_cpus);
8053
8054 alloc_cpumask_var(&fallback_doms, GFP_KERNEL);
8055 init_sched_rt_class();
7994} 8056}
7995#else 8057#else
7996void __init sched_init_smp(void) 8058void __init sched_init_smp(void)
@@ -8305,6 +8367,15 @@ void __init sched_init(void)
8305 */ 8367 */
8306 current->sched_class = &fair_sched_class; 8368 current->sched_class = &fair_sched_class;
8307 8369
8370 /* Allocate the nohz_cpu_mask if CONFIG_CPUMASK_OFFSTACK */
8371 alloc_bootmem_cpumask_var(&nohz_cpu_mask);
8372#ifdef CONFIG_SMP
8373#ifdef CONFIG_NO_HZ
8374 alloc_bootmem_cpumask_var(&nohz.cpu_mask);
8375#endif
8376 alloc_bootmem_cpumask_var(&cpu_isolated_map);
8377#endif /* SMP */
8378
8308 scheduler_running = 1; 8379 scheduler_running = 1;
8309} 8380}
8310 8381