diff options
Diffstat (limited to 'kernel/sched.c')
-rw-r--r-- | kernel/sched.c | 974 |
1 files changed, 558 insertions, 416 deletions
diff --git a/kernel/sched.c b/kernel/sched.c index f2095660efec..27ba1d642f0f 100644 --- a/kernel/sched.c +++ b/kernel/sched.c | |||
@@ -498,18 +498,26 @@ struct rt_rq { | |||
498 | */ | 498 | */ |
499 | struct root_domain { | 499 | struct root_domain { |
500 | atomic_t refcount; | 500 | atomic_t refcount; |
501 | cpumask_t span; | 501 | cpumask_var_t span; |
502 | cpumask_t online; | 502 | cpumask_var_t online; |
503 | 503 | ||
504 | /* | 504 | /* |
505 | * The "RT overload" flag: it gets set if a CPU has more than | 505 | * The "RT overload" flag: it gets set if a CPU has more than |
506 | * one runnable RT task. | 506 | * one runnable RT task. |
507 | */ | 507 | */ |
508 | cpumask_t rto_mask; | 508 | cpumask_var_t rto_mask; |
509 | atomic_t rto_count; | 509 | atomic_t rto_count; |
510 | #ifdef CONFIG_SMP | 510 | #ifdef CONFIG_SMP |
511 | struct cpupri cpupri; | 511 | struct cpupri cpupri; |
512 | #endif | 512 | #endif |
513 | #if defined(CONFIG_SCHED_MC) || defined(CONFIG_SCHED_SMT) | ||
514 | /* | ||
515 | * Preferred wake up cpu nominated by sched_mc balance that will be | ||
516 | * used when most cpus are idle in the system indicating overall very | ||
517 | * low system utilisation. Triggered at POWERSAVINGS_BALANCE_WAKEUP(2) | ||
518 | */ | ||
519 | unsigned int sched_mc_preferred_wakeup_cpu; | ||
520 | #endif | ||
513 | }; | 521 | }; |
514 | 522 | ||
515 | /* | 523 | /* |
@@ -1514,7 +1522,7 @@ static int tg_shares_up(struct task_group *tg, void *data) | |||
1514 | struct sched_domain *sd = data; | 1522 | struct sched_domain *sd = data; |
1515 | int i; | 1523 | int i; |
1516 | 1524 | ||
1517 | for_each_cpu_mask(i, sd->span) { | 1525 | for_each_cpu(i, sched_domain_span(sd)) { |
1518 | /* | 1526 | /* |
1519 | * If there are currently no tasks on the cpu pretend there | 1527 | * If there are currently no tasks on the cpu pretend there |
1520 | * is one of average load so that when a new task gets to | 1528 | * is one of average load so that when a new task gets to |
@@ -1535,7 +1543,7 @@ static int tg_shares_up(struct task_group *tg, void *data) | |||
1535 | if (!sd->parent || !(sd->parent->flags & SD_LOAD_BALANCE)) | 1543 | if (!sd->parent || !(sd->parent->flags & SD_LOAD_BALANCE)) |
1536 | shares = tg->shares; | 1544 | shares = tg->shares; |
1537 | 1545 | ||
1538 | for_each_cpu_mask(i, sd->span) | 1546 | for_each_cpu(i, sched_domain_span(sd)) |
1539 | update_group_shares_cpu(tg, i, shares, rq_weight); | 1547 | update_group_shares_cpu(tg, i, shares, rq_weight); |
1540 | 1548 | ||
1541 | return 0; | 1549 | return 0; |
@@ -2101,15 +2109,17 @@ find_idlest_group(struct sched_domain *sd, struct task_struct *p, int this_cpu) | |||
2101 | int i; | 2109 | int i; |
2102 | 2110 | ||
2103 | /* Skip over this group if it has no CPUs allowed */ | 2111 | /* Skip over this group if it has no CPUs allowed */ |
2104 | if (!cpus_intersects(group->cpumask, p->cpus_allowed)) | 2112 | if (!cpumask_intersects(sched_group_cpus(group), |
2113 | &p->cpus_allowed)) | ||
2105 | continue; | 2114 | continue; |
2106 | 2115 | ||
2107 | local_group = cpu_isset(this_cpu, group->cpumask); | 2116 | local_group = cpumask_test_cpu(this_cpu, |
2117 | sched_group_cpus(group)); | ||
2108 | 2118 | ||
2109 | /* Tally up the load of all CPUs in the group */ | 2119 | /* Tally up the load of all CPUs in the group */ |
2110 | avg_load = 0; | 2120 | avg_load = 0; |
2111 | 2121 | ||
2112 | for_each_cpu_mask_nr(i, group->cpumask) { | 2122 | for_each_cpu(i, sched_group_cpus(group)) { |
2113 | /* Bias balancing toward cpus of our domain */ | 2123 | /* Bias balancing toward cpus of our domain */ |
2114 | if (local_group) | 2124 | if (local_group) |
2115 | load = source_load(i, load_idx); | 2125 | load = source_load(i, load_idx); |
@@ -2141,17 +2151,14 @@ find_idlest_group(struct sched_domain *sd, struct task_struct *p, int this_cpu) | |||
2141 | * find_idlest_cpu - find the idlest cpu among the cpus in group. | 2151 | * find_idlest_cpu - find the idlest cpu among the cpus in group. |
2142 | */ | 2152 | */ |
2143 | static int | 2153 | static int |
2144 | find_idlest_cpu(struct sched_group *group, struct task_struct *p, int this_cpu, | 2154 | find_idlest_cpu(struct sched_group *group, struct task_struct *p, int this_cpu) |
2145 | cpumask_t *tmp) | ||
2146 | { | 2155 | { |
2147 | unsigned long load, min_load = ULONG_MAX; | 2156 | unsigned long load, min_load = ULONG_MAX; |
2148 | int idlest = -1; | 2157 | int idlest = -1; |
2149 | int i; | 2158 | int i; |
2150 | 2159 | ||
2151 | /* Traverse only the allowed CPUs */ | 2160 | /* Traverse only the allowed CPUs */ |
2152 | cpus_and(*tmp, group->cpumask, p->cpus_allowed); | 2161 | for_each_cpu_and(i, sched_group_cpus(group), &p->cpus_allowed) { |
2153 | |||
2154 | for_each_cpu_mask_nr(i, *tmp) { | ||
2155 | load = weighted_cpuload(i); | 2162 | load = weighted_cpuload(i); |
2156 | 2163 | ||
2157 | if (load < min_load || (load == min_load && i == this_cpu)) { | 2164 | if (load < min_load || (load == min_load && i == this_cpu)) { |
@@ -2193,7 +2200,6 @@ static int sched_balance_self(int cpu, int flag) | |||
2193 | update_shares(sd); | 2200 | update_shares(sd); |
2194 | 2201 | ||
2195 | while (sd) { | 2202 | while (sd) { |
2196 | cpumask_t span, tmpmask; | ||
2197 | struct sched_group *group; | 2203 | struct sched_group *group; |
2198 | int new_cpu, weight; | 2204 | int new_cpu, weight; |
2199 | 2205 | ||
@@ -2202,14 +2208,13 @@ static int sched_balance_self(int cpu, int flag) | |||
2202 | continue; | 2208 | continue; |
2203 | } | 2209 | } |
2204 | 2210 | ||
2205 | span = sd->span; | ||
2206 | group = find_idlest_group(sd, t, cpu); | 2211 | group = find_idlest_group(sd, t, cpu); |
2207 | if (!group) { | 2212 | if (!group) { |
2208 | sd = sd->child; | 2213 | sd = sd->child; |
2209 | continue; | 2214 | continue; |
2210 | } | 2215 | } |
2211 | 2216 | ||
2212 | new_cpu = find_idlest_cpu(group, t, cpu, &tmpmask); | 2217 | new_cpu = find_idlest_cpu(group, t, cpu); |
2213 | if (new_cpu == -1 || new_cpu == cpu) { | 2218 | if (new_cpu == -1 || new_cpu == cpu) { |
2214 | /* Now try balancing at a lower domain level of cpu */ | 2219 | /* Now try balancing at a lower domain level of cpu */ |
2215 | sd = sd->child; | 2220 | sd = sd->child; |
@@ -2218,10 +2223,10 @@ static int sched_balance_self(int cpu, int flag) | |||
2218 | 2223 | ||
2219 | /* Now try balancing at a lower domain level of new_cpu */ | 2224 | /* Now try balancing at a lower domain level of new_cpu */ |
2220 | cpu = new_cpu; | 2225 | cpu = new_cpu; |
2226 | weight = cpumask_weight(sched_domain_span(sd)); | ||
2221 | sd = NULL; | 2227 | sd = NULL; |
2222 | weight = cpus_weight(span); | ||
2223 | for_each_domain(cpu, tmp) { | 2228 | for_each_domain(cpu, tmp) { |
2224 | if (weight <= cpus_weight(tmp->span)) | 2229 | if (weight <= cpumask_weight(sched_domain_span(tmp))) |
2225 | break; | 2230 | break; |
2226 | if (tmp->flags & flag) | 2231 | if (tmp->flags & flag) |
2227 | sd = tmp; | 2232 | sd = tmp; |
@@ -2266,7 +2271,7 @@ static int try_to_wake_up(struct task_struct *p, unsigned int state, int sync) | |||
2266 | cpu = task_cpu(p); | 2271 | cpu = task_cpu(p); |
2267 | 2272 | ||
2268 | for_each_domain(this_cpu, sd) { | 2273 | for_each_domain(this_cpu, sd) { |
2269 | if (cpu_isset(cpu, sd->span)) { | 2274 | if (cpumask_test_cpu(cpu, sched_domain_span(sd))) { |
2270 | update_shares(sd); | 2275 | update_shares(sd); |
2271 | break; | 2276 | break; |
2272 | } | 2277 | } |
@@ -2315,7 +2320,7 @@ static int try_to_wake_up(struct task_struct *p, unsigned int state, int sync) | |||
2315 | else { | 2320 | else { |
2316 | struct sched_domain *sd; | 2321 | struct sched_domain *sd; |
2317 | for_each_domain(this_cpu, sd) { | 2322 | for_each_domain(this_cpu, sd) { |
2318 | if (cpu_isset(cpu, sd->span)) { | 2323 | if (cpumask_test_cpu(cpu, sched_domain_span(sd))) { |
2319 | schedstat_inc(sd, ttwu_wake_remote); | 2324 | schedstat_inc(sd, ttwu_wake_remote); |
2320 | break; | 2325 | break; |
2321 | } | 2326 | } |
@@ -2846,7 +2851,7 @@ static void sched_migrate_task(struct task_struct *p, int dest_cpu) | |||
2846 | struct rq *rq; | 2851 | struct rq *rq; |
2847 | 2852 | ||
2848 | rq = task_rq_lock(p, &flags); | 2853 | rq = task_rq_lock(p, &flags); |
2849 | if (!cpu_isset(dest_cpu, p->cpus_allowed) | 2854 | if (!cpumask_test_cpu(dest_cpu, &p->cpus_allowed) |
2850 | || unlikely(!cpu_active(dest_cpu))) | 2855 | || unlikely(!cpu_active(dest_cpu))) |
2851 | goto out; | 2856 | goto out; |
2852 | 2857 | ||
@@ -2911,7 +2916,7 @@ int can_migrate_task(struct task_struct *p, struct rq *rq, int this_cpu, | |||
2911 | * 2) cannot be migrated to this CPU due to cpus_allowed, or | 2916 | * 2) cannot be migrated to this CPU due to cpus_allowed, or |
2912 | * 3) are cache-hot on their current CPU. | 2917 | * 3) are cache-hot on their current CPU. |
2913 | */ | 2918 | */ |
2914 | if (!cpu_isset(this_cpu, p->cpus_allowed)) { | 2919 | if (!cpumask_test_cpu(this_cpu, &p->cpus_allowed)) { |
2915 | schedstat_inc(p, se.nr_failed_migrations_affine); | 2920 | schedstat_inc(p, se.nr_failed_migrations_affine); |
2916 | return 0; | 2921 | return 0; |
2917 | } | 2922 | } |
@@ -3086,7 +3091,7 @@ static int move_one_task(struct rq *this_rq, int this_cpu, struct rq *busiest, | |||
3086 | static struct sched_group * | 3091 | static struct sched_group * |
3087 | find_busiest_group(struct sched_domain *sd, int this_cpu, | 3092 | find_busiest_group(struct sched_domain *sd, int this_cpu, |
3088 | unsigned long *imbalance, enum cpu_idle_type idle, | 3093 | unsigned long *imbalance, enum cpu_idle_type idle, |
3089 | int *sd_idle, const cpumask_t *cpus, int *balance) | 3094 | int *sd_idle, const struct cpumask *cpus, int *balance) |
3090 | { | 3095 | { |
3091 | struct sched_group *busiest = NULL, *this = NULL, *group = sd->groups; | 3096 | struct sched_group *busiest = NULL, *this = NULL, *group = sd->groups; |
3092 | unsigned long max_load, avg_load, total_load, this_load, total_pwr; | 3097 | unsigned long max_load, avg_load, total_load, this_load, total_pwr; |
@@ -3122,10 +3127,11 @@ find_busiest_group(struct sched_domain *sd, int this_cpu, | |||
3122 | unsigned long sum_avg_load_per_task; | 3127 | unsigned long sum_avg_load_per_task; |
3123 | unsigned long avg_load_per_task; | 3128 | unsigned long avg_load_per_task; |
3124 | 3129 | ||
3125 | local_group = cpu_isset(this_cpu, group->cpumask); | 3130 | local_group = cpumask_test_cpu(this_cpu, |
3131 | sched_group_cpus(group)); | ||
3126 | 3132 | ||
3127 | if (local_group) | 3133 | if (local_group) |
3128 | balance_cpu = first_cpu(group->cpumask); | 3134 | balance_cpu = cpumask_first(sched_group_cpus(group)); |
3129 | 3135 | ||
3130 | /* Tally up the load of all CPUs in the group */ | 3136 | /* Tally up the load of all CPUs in the group */ |
3131 | sum_weighted_load = sum_nr_running = avg_load = 0; | 3137 | sum_weighted_load = sum_nr_running = avg_load = 0; |
@@ -3134,13 +3140,8 @@ find_busiest_group(struct sched_domain *sd, int this_cpu, | |||
3134 | max_cpu_load = 0; | 3140 | max_cpu_load = 0; |
3135 | min_cpu_load = ~0UL; | 3141 | min_cpu_load = ~0UL; |
3136 | 3142 | ||
3137 | for_each_cpu_mask_nr(i, group->cpumask) { | 3143 | for_each_cpu_and(i, sched_group_cpus(group), cpus) { |
3138 | struct rq *rq; | 3144 | struct rq *rq = cpu_rq(i); |
3139 | |||
3140 | if (!cpu_isset(i, *cpus)) | ||
3141 | continue; | ||
3142 | |||
3143 | rq = cpu_rq(i); | ||
3144 | 3145 | ||
3145 | if (*sd_idle && rq->nr_running) | 3146 | if (*sd_idle && rq->nr_running) |
3146 | *sd_idle = 0; | 3147 | *sd_idle = 0; |
@@ -3251,8 +3252,8 @@ find_busiest_group(struct sched_domain *sd, int this_cpu, | |||
3251 | */ | 3252 | */ |
3252 | if ((sum_nr_running < min_nr_running) || | 3253 | if ((sum_nr_running < min_nr_running) || |
3253 | (sum_nr_running == min_nr_running && | 3254 | (sum_nr_running == min_nr_running && |
3254 | first_cpu(group->cpumask) < | 3255 | cpumask_first(sched_group_cpus(group)) > |
3255 | first_cpu(group_min->cpumask))) { | 3256 | cpumask_first(sched_group_cpus(group_min)))) { |
3256 | group_min = group; | 3257 | group_min = group; |
3257 | min_nr_running = sum_nr_running; | 3258 | min_nr_running = sum_nr_running; |
3258 | min_load_per_task = sum_weighted_load / | 3259 | min_load_per_task = sum_weighted_load / |
@@ -3267,8 +3268,8 @@ find_busiest_group(struct sched_domain *sd, int this_cpu, | |||
3267 | if (sum_nr_running <= group_capacity - 1) { | 3268 | if (sum_nr_running <= group_capacity - 1) { |
3268 | if (sum_nr_running > leader_nr_running || | 3269 | if (sum_nr_running > leader_nr_running || |
3269 | (sum_nr_running == leader_nr_running && | 3270 | (sum_nr_running == leader_nr_running && |
3270 | first_cpu(group->cpumask) > | 3271 | cpumask_first(sched_group_cpus(group)) < |
3271 | first_cpu(group_leader->cpumask))) { | 3272 | cpumask_first(sched_group_cpus(group_leader)))) { |
3272 | group_leader = group; | 3273 | group_leader = group; |
3273 | leader_nr_running = sum_nr_running; | 3274 | leader_nr_running = sum_nr_running; |
3274 | } | 3275 | } |
@@ -3394,6 +3395,10 @@ out_balanced: | |||
3394 | 3395 | ||
3395 | if (this == group_leader && group_leader != group_min) { | 3396 | if (this == group_leader && group_leader != group_min) { |
3396 | *imbalance = min_load_per_task; | 3397 | *imbalance = min_load_per_task; |
3398 | if (sched_mc_power_savings >= POWERSAVINGS_BALANCE_WAKEUP) { | ||
3399 | cpu_rq(this_cpu)->rd->sched_mc_preferred_wakeup_cpu = | ||
3400 | cpumask_first(sched_group_cpus(group_leader)); | ||
3401 | } | ||
3397 | return group_min; | 3402 | return group_min; |
3398 | } | 3403 | } |
3399 | #endif | 3404 | #endif |
@@ -3407,16 +3412,16 @@ ret: | |||
3407 | */ | 3412 | */ |
3408 | static struct rq * | 3413 | static struct rq * |
3409 | find_busiest_queue(struct sched_group *group, enum cpu_idle_type idle, | 3414 | find_busiest_queue(struct sched_group *group, enum cpu_idle_type idle, |
3410 | unsigned long imbalance, const cpumask_t *cpus) | 3415 | unsigned long imbalance, const struct cpumask *cpus) |
3411 | { | 3416 | { |
3412 | struct rq *busiest = NULL, *rq; | 3417 | struct rq *busiest = NULL, *rq; |
3413 | unsigned long max_load = 0; | 3418 | unsigned long max_load = 0; |
3414 | int i; | 3419 | int i; |
3415 | 3420 | ||
3416 | for_each_cpu_mask_nr(i, group->cpumask) { | 3421 | for_each_cpu(i, sched_group_cpus(group)) { |
3417 | unsigned long wl; | 3422 | unsigned long wl; |
3418 | 3423 | ||
3419 | if (!cpu_isset(i, *cpus)) | 3424 | if (!cpumask_test_cpu(i, cpus)) |
3420 | continue; | 3425 | continue; |
3421 | 3426 | ||
3422 | rq = cpu_rq(i); | 3427 | rq = cpu_rq(i); |
@@ -3446,7 +3451,7 @@ find_busiest_queue(struct sched_group *group, enum cpu_idle_type idle, | |||
3446 | */ | 3451 | */ |
3447 | static int load_balance(int this_cpu, struct rq *this_rq, | 3452 | static int load_balance(int this_cpu, struct rq *this_rq, |
3448 | struct sched_domain *sd, enum cpu_idle_type idle, | 3453 | struct sched_domain *sd, enum cpu_idle_type idle, |
3449 | int *balance, cpumask_t *cpus) | 3454 | int *balance, struct cpumask *cpus) |
3450 | { | 3455 | { |
3451 | int ld_moved, all_pinned = 0, active_balance = 0, sd_idle = 0; | 3456 | int ld_moved, all_pinned = 0, active_balance = 0, sd_idle = 0; |
3452 | struct sched_group *group; | 3457 | struct sched_group *group; |
@@ -3454,7 +3459,7 @@ static int load_balance(int this_cpu, struct rq *this_rq, | |||
3454 | struct rq *busiest; | 3459 | struct rq *busiest; |
3455 | unsigned long flags; | 3460 | unsigned long flags; |
3456 | 3461 | ||
3457 | cpus_setall(*cpus); | 3462 | cpumask_setall(cpus); |
3458 | 3463 | ||
3459 | /* | 3464 | /* |
3460 | * When power savings policy is enabled for the parent domain, idle | 3465 | * When power savings policy is enabled for the parent domain, idle |
@@ -3514,8 +3519,8 @@ redo: | |||
3514 | 3519 | ||
3515 | /* All tasks on this runqueue were pinned by CPU affinity */ | 3520 | /* All tasks on this runqueue were pinned by CPU affinity */ |
3516 | if (unlikely(all_pinned)) { | 3521 | if (unlikely(all_pinned)) { |
3517 | cpu_clear(cpu_of(busiest), *cpus); | 3522 | cpumask_clear_cpu(cpu_of(busiest), cpus); |
3518 | if (!cpus_empty(*cpus)) | 3523 | if (!cpumask_empty(cpus)) |
3519 | goto redo; | 3524 | goto redo; |
3520 | goto out_balanced; | 3525 | goto out_balanced; |
3521 | } | 3526 | } |
@@ -3532,7 +3537,8 @@ redo: | |||
3532 | /* don't kick the migration_thread, if the curr | 3537 | /* don't kick the migration_thread, if the curr |
3533 | * task on busiest cpu can't be moved to this_cpu | 3538 | * task on busiest cpu can't be moved to this_cpu |
3534 | */ | 3539 | */ |
3535 | if (!cpu_isset(this_cpu, busiest->curr->cpus_allowed)) { | 3540 | if (!cpumask_test_cpu(this_cpu, |
3541 | &busiest->curr->cpus_allowed)) { | ||
3536 | spin_unlock_irqrestore(&busiest->lock, flags); | 3542 | spin_unlock_irqrestore(&busiest->lock, flags); |
3537 | all_pinned = 1; | 3543 | all_pinned = 1; |
3538 | goto out_one_pinned; | 3544 | goto out_one_pinned; |
@@ -3607,7 +3613,7 @@ out: | |||
3607 | */ | 3613 | */ |
3608 | static int | 3614 | static int |
3609 | load_balance_newidle(int this_cpu, struct rq *this_rq, struct sched_domain *sd, | 3615 | load_balance_newidle(int this_cpu, struct rq *this_rq, struct sched_domain *sd, |
3610 | cpumask_t *cpus) | 3616 | struct cpumask *cpus) |
3611 | { | 3617 | { |
3612 | struct sched_group *group; | 3618 | struct sched_group *group; |
3613 | struct rq *busiest = NULL; | 3619 | struct rq *busiest = NULL; |
@@ -3616,7 +3622,7 @@ load_balance_newidle(int this_cpu, struct rq *this_rq, struct sched_domain *sd, | |||
3616 | int sd_idle = 0; | 3622 | int sd_idle = 0; |
3617 | int all_pinned = 0; | 3623 | int all_pinned = 0; |
3618 | 3624 | ||
3619 | cpus_setall(*cpus); | 3625 | cpumask_setall(cpus); |
3620 | 3626 | ||
3621 | /* | 3627 | /* |
3622 | * When power savings policy is enabled for the parent domain, idle | 3628 | * When power savings policy is enabled for the parent domain, idle |
@@ -3660,17 +3666,71 @@ redo: | |||
3660 | double_unlock_balance(this_rq, busiest); | 3666 | double_unlock_balance(this_rq, busiest); |
3661 | 3667 | ||
3662 | if (unlikely(all_pinned)) { | 3668 | if (unlikely(all_pinned)) { |
3663 | cpu_clear(cpu_of(busiest), *cpus); | 3669 | cpumask_clear_cpu(cpu_of(busiest), cpus); |
3664 | if (!cpus_empty(*cpus)) | 3670 | if (!cpumask_empty(cpus)) |
3665 | goto redo; | 3671 | goto redo; |
3666 | } | 3672 | } |
3667 | } | 3673 | } |
3668 | 3674 | ||
3669 | if (!ld_moved) { | 3675 | if (!ld_moved) { |
3676 | int active_balance = 0; | ||
3677 | |||
3670 | schedstat_inc(sd, lb_failed[CPU_NEWLY_IDLE]); | 3678 | schedstat_inc(sd, lb_failed[CPU_NEWLY_IDLE]); |
3671 | if (!sd_idle && sd->flags & SD_SHARE_CPUPOWER && | 3679 | if (!sd_idle && sd->flags & SD_SHARE_CPUPOWER && |
3672 | !test_sd_parent(sd, SD_POWERSAVINGS_BALANCE)) | 3680 | !test_sd_parent(sd, SD_POWERSAVINGS_BALANCE)) |
3673 | return -1; | 3681 | return -1; |
3682 | |||
3683 | if (sched_mc_power_savings < POWERSAVINGS_BALANCE_WAKEUP) | ||
3684 | return -1; | ||
3685 | |||
3686 | if (sd->nr_balance_failed++ < 2) | ||
3687 | return -1; | ||
3688 | |||
3689 | /* | ||
3690 | * The only task running in a non-idle cpu can be moved to this | ||
3691 | * cpu in an attempt to completely freeup the other CPU | ||
3692 | * package. The same method used to move task in load_balance() | ||
3693 | * have been extended for load_balance_newidle() to speedup | ||
3694 | * consolidation at sched_mc=POWERSAVINGS_BALANCE_WAKEUP (2) | ||
3695 | * | ||
3696 | * The package power saving logic comes from | ||
3697 | * find_busiest_group(). If there are no imbalance, then | ||
3698 | * f_b_g() will return NULL. However when sched_mc={1,2} then | ||
3699 | * f_b_g() will select a group from which a running task may be | ||
3700 | * pulled to this cpu in order to make the other package idle. | ||
3701 | * If there is no opportunity to make a package idle and if | ||
3702 | * there are no imbalance, then f_b_g() will return NULL and no | ||
3703 | * action will be taken in load_balance_newidle(). | ||
3704 | * | ||
3705 | * Under normal task pull operation due to imbalance, there | ||
3706 | * will be more than one task in the source run queue and | ||
3707 | * move_tasks() will succeed. ld_moved will be true and this | ||
3708 | * active balance code will not be triggered. | ||
3709 | */ | ||
3710 | |||
3711 | /* Lock busiest in correct order while this_rq is held */ | ||
3712 | double_lock_balance(this_rq, busiest); | ||
3713 | |||
3714 | /* | ||
3715 | * don't kick the migration_thread, if the curr | ||
3716 | * task on busiest cpu can't be moved to this_cpu | ||
3717 | */ | ||
3718 | if (!cpu_isset(this_cpu, busiest->curr->cpus_allowed)) { | ||
3719 | double_unlock_balance(this_rq, busiest); | ||
3720 | all_pinned = 1; | ||
3721 | return ld_moved; | ||
3722 | } | ||
3723 | |||
3724 | if (!busiest->active_balance) { | ||
3725 | busiest->active_balance = 1; | ||
3726 | busiest->push_cpu = this_cpu; | ||
3727 | active_balance = 1; | ||
3728 | } | ||
3729 | |||
3730 | double_unlock_balance(this_rq, busiest); | ||
3731 | if (active_balance) | ||
3732 | wake_up_process(busiest->migration_thread); | ||
3733 | |||
3674 | } else | 3734 | } else |
3675 | sd->nr_balance_failed = 0; | 3735 | sd->nr_balance_failed = 0; |
3676 | 3736 | ||
@@ -3696,7 +3756,10 @@ static void idle_balance(int this_cpu, struct rq *this_rq) | |||
3696 | struct sched_domain *sd; | 3756 | struct sched_domain *sd; |
3697 | int pulled_task = 0; | 3757 | int pulled_task = 0; |
3698 | unsigned long next_balance = jiffies + HZ; | 3758 | unsigned long next_balance = jiffies + HZ; |
3699 | cpumask_t tmpmask; | 3759 | cpumask_var_t tmpmask; |
3760 | |||
3761 | if (!alloc_cpumask_var(&tmpmask, GFP_ATOMIC)) | ||
3762 | return; | ||
3700 | 3763 | ||
3701 | for_each_domain(this_cpu, sd) { | 3764 | for_each_domain(this_cpu, sd) { |
3702 | unsigned long interval; | 3765 | unsigned long interval; |
@@ -3707,7 +3770,7 @@ static void idle_balance(int this_cpu, struct rq *this_rq) | |||
3707 | if (sd->flags & SD_BALANCE_NEWIDLE) | 3770 | if (sd->flags & SD_BALANCE_NEWIDLE) |
3708 | /* If we've pulled tasks over stop searching: */ | 3771 | /* If we've pulled tasks over stop searching: */ |
3709 | pulled_task = load_balance_newidle(this_cpu, this_rq, | 3772 | pulled_task = load_balance_newidle(this_cpu, this_rq, |
3710 | sd, &tmpmask); | 3773 | sd, tmpmask); |
3711 | 3774 | ||
3712 | interval = msecs_to_jiffies(sd->balance_interval); | 3775 | interval = msecs_to_jiffies(sd->balance_interval); |
3713 | if (time_after(next_balance, sd->last_balance + interval)) | 3776 | if (time_after(next_balance, sd->last_balance + interval)) |
@@ -3722,6 +3785,7 @@ static void idle_balance(int this_cpu, struct rq *this_rq) | |||
3722 | */ | 3785 | */ |
3723 | this_rq->next_balance = next_balance; | 3786 | this_rq->next_balance = next_balance; |
3724 | } | 3787 | } |
3788 | free_cpumask_var(tmpmask); | ||
3725 | } | 3789 | } |
3726 | 3790 | ||
3727 | /* | 3791 | /* |
@@ -3759,7 +3823,7 @@ static void active_load_balance(struct rq *busiest_rq, int busiest_cpu) | |||
3759 | /* Search for an sd spanning us and the target CPU. */ | 3823 | /* Search for an sd spanning us and the target CPU. */ |
3760 | for_each_domain(target_cpu, sd) { | 3824 | for_each_domain(target_cpu, sd) { |
3761 | if ((sd->flags & SD_LOAD_BALANCE) && | 3825 | if ((sd->flags & SD_LOAD_BALANCE) && |
3762 | cpu_isset(busiest_cpu, sd->span)) | 3826 | cpumask_test_cpu(busiest_cpu, sched_domain_span(sd))) |
3763 | break; | 3827 | break; |
3764 | } | 3828 | } |
3765 | 3829 | ||
@@ -3778,10 +3842,9 @@ static void active_load_balance(struct rq *busiest_rq, int busiest_cpu) | |||
3778 | #ifdef CONFIG_NO_HZ | 3842 | #ifdef CONFIG_NO_HZ |
3779 | static struct { | 3843 | static struct { |
3780 | atomic_t load_balancer; | 3844 | atomic_t load_balancer; |
3781 | cpumask_t cpu_mask; | 3845 | cpumask_var_t cpu_mask; |
3782 | } nohz ____cacheline_aligned = { | 3846 | } nohz ____cacheline_aligned = { |
3783 | .load_balancer = ATOMIC_INIT(-1), | 3847 | .load_balancer = ATOMIC_INIT(-1), |
3784 | .cpu_mask = CPU_MASK_NONE, | ||
3785 | }; | 3848 | }; |
3786 | 3849 | ||
3787 | /* | 3850 | /* |
@@ -3809,7 +3872,7 @@ int select_nohz_load_balancer(int stop_tick) | |||
3809 | int cpu = smp_processor_id(); | 3872 | int cpu = smp_processor_id(); |
3810 | 3873 | ||
3811 | if (stop_tick) { | 3874 | if (stop_tick) { |
3812 | cpu_set(cpu, nohz.cpu_mask); | 3875 | cpumask_set_cpu(cpu, nohz.cpu_mask); |
3813 | cpu_rq(cpu)->in_nohz_recently = 1; | 3876 | cpu_rq(cpu)->in_nohz_recently = 1; |
3814 | 3877 | ||
3815 | /* | 3878 | /* |
@@ -3823,7 +3886,7 @@ int select_nohz_load_balancer(int stop_tick) | |||
3823 | } | 3886 | } |
3824 | 3887 | ||
3825 | /* time for ilb owner also to sleep */ | 3888 | /* time for ilb owner also to sleep */ |
3826 | if (cpus_weight(nohz.cpu_mask) == num_online_cpus()) { | 3889 | if (cpumask_weight(nohz.cpu_mask) == num_online_cpus()) { |
3827 | if (atomic_read(&nohz.load_balancer) == cpu) | 3890 | if (atomic_read(&nohz.load_balancer) == cpu) |
3828 | atomic_set(&nohz.load_balancer, -1); | 3891 | atomic_set(&nohz.load_balancer, -1); |
3829 | return 0; | 3892 | return 0; |
@@ -3836,10 +3899,10 @@ int select_nohz_load_balancer(int stop_tick) | |||
3836 | } else if (atomic_read(&nohz.load_balancer) == cpu) | 3899 | } else if (atomic_read(&nohz.load_balancer) == cpu) |
3837 | return 1; | 3900 | return 1; |
3838 | } else { | 3901 | } else { |
3839 | if (!cpu_isset(cpu, nohz.cpu_mask)) | 3902 | if (!cpumask_test_cpu(cpu, nohz.cpu_mask)) |
3840 | return 0; | 3903 | return 0; |
3841 | 3904 | ||
3842 | cpu_clear(cpu, nohz.cpu_mask); | 3905 | cpumask_clear_cpu(cpu, nohz.cpu_mask); |
3843 | 3906 | ||
3844 | if (atomic_read(&nohz.load_balancer) == cpu) | 3907 | if (atomic_read(&nohz.load_balancer) == cpu) |
3845 | if (atomic_cmpxchg(&nohz.load_balancer, cpu, -1) != cpu) | 3908 | if (atomic_cmpxchg(&nohz.load_balancer, cpu, -1) != cpu) |
@@ -3867,7 +3930,11 @@ static void rebalance_domains(int cpu, enum cpu_idle_type idle) | |||
3867 | unsigned long next_balance = jiffies + 60*HZ; | 3930 | unsigned long next_balance = jiffies + 60*HZ; |
3868 | int update_next_balance = 0; | 3931 | int update_next_balance = 0; |
3869 | int need_serialize; | 3932 | int need_serialize; |
3870 | cpumask_t tmp; | 3933 | cpumask_var_t tmp; |
3934 | |||
3935 | /* Fails alloc? Rebalancing probably not a priority right now. */ | ||
3936 | if (!alloc_cpumask_var(&tmp, GFP_ATOMIC)) | ||
3937 | return; | ||
3871 | 3938 | ||
3872 | for_each_domain(cpu, sd) { | 3939 | for_each_domain(cpu, sd) { |
3873 | if (!(sd->flags & SD_LOAD_BALANCE)) | 3940 | if (!(sd->flags & SD_LOAD_BALANCE)) |
@@ -3892,7 +3959,7 @@ static void rebalance_domains(int cpu, enum cpu_idle_type idle) | |||
3892 | } | 3959 | } |
3893 | 3960 | ||
3894 | if (time_after_eq(jiffies, sd->last_balance + interval)) { | 3961 | if (time_after_eq(jiffies, sd->last_balance + interval)) { |
3895 | if (load_balance(cpu, rq, sd, idle, &balance, &tmp)) { | 3962 | if (load_balance(cpu, rq, sd, idle, &balance, tmp)) { |
3896 | /* | 3963 | /* |
3897 | * We've pulled tasks over so either we're no | 3964 | * We've pulled tasks over so either we're no |
3898 | * longer idle, or one of our SMT siblings is | 3965 | * longer idle, or one of our SMT siblings is |
@@ -3926,6 +3993,8 @@ out: | |||
3926 | */ | 3993 | */ |
3927 | if (likely(update_next_balance)) | 3994 | if (likely(update_next_balance)) |
3928 | rq->next_balance = next_balance; | 3995 | rq->next_balance = next_balance; |
3996 | |||
3997 | free_cpumask_var(tmp); | ||
3929 | } | 3998 | } |
3930 | 3999 | ||
3931 | /* | 4000 | /* |
@@ -3950,12 +4019,13 @@ static void run_rebalance_domains(struct softirq_action *h) | |||
3950 | */ | 4019 | */ |
3951 | if (this_rq->idle_at_tick && | 4020 | if (this_rq->idle_at_tick && |
3952 | atomic_read(&nohz.load_balancer) == this_cpu) { | 4021 | atomic_read(&nohz.load_balancer) == this_cpu) { |
3953 | cpumask_t cpus = nohz.cpu_mask; | ||
3954 | struct rq *rq; | 4022 | struct rq *rq; |
3955 | int balance_cpu; | 4023 | int balance_cpu; |
3956 | 4024 | ||
3957 | cpu_clear(this_cpu, cpus); | 4025 | for_each_cpu(balance_cpu, nohz.cpu_mask) { |
3958 | for_each_cpu_mask_nr(balance_cpu, cpus) { | 4026 | if (balance_cpu == this_cpu) |
4027 | continue; | ||
4028 | |||
3959 | /* | 4029 | /* |
3960 | * If this cpu gets work to do, stop the load balancing | 4030 | * If this cpu gets work to do, stop the load balancing |
3961 | * work being done for other cpus. Next load | 4031 | * work being done for other cpus. Next load |
@@ -3993,7 +4063,7 @@ static inline void trigger_load_balance(struct rq *rq, int cpu) | |||
3993 | rq->in_nohz_recently = 0; | 4063 | rq->in_nohz_recently = 0; |
3994 | 4064 | ||
3995 | if (atomic_read(&nohz.load_balancer) == cpu) { | 4065 | if (atomic_read(&nohz.load_balancer) == cpu) { |
3996 | cpu_clear(cpu, nohz.cpu_mask); | 4066 | cpumask_clear_cpu(cpu, nohz.cpu_mask); |
3997 | atomic_set(&nohz.load_balancer, -1); | 4067 | atomic_set(&nohz.load_balancer, -1); |
3998 | } | 4068 | } |
3999 | 4069 | ||
@@ -4006,7 +4076,7 @@ static inline void trigger_load_balance(struct rq *rq, int cpu) | |||
4006 | * TBD: Traverse the sched domains and nominate | 4076 | * TBD: Traverse the sched domains and nominate |
4007 | * the nearest cpu in the nohz.cpu_mask. | 4077 | * the nearest cpu in the nohz.cpu_mask. |
4008 | */ | 4078 | */ |
4009 | int ilb = first_cpu(nohz.cpu_mask); | 4079 | int ilb = cpumask_first(nohz.cpu_mask); |
4010 | 4080 | ||
4011 | if (ilb < nr_cpu_ids) | 4081 | if (ilb < nr_cpu_ids) |
4012 | resched_cpu(ilb); | 4082 | resched_cpu(ilb); |
@@ -4018,7 +4088,7 @@ static inline void trigger_load_balance(struct rq *rq, int cpu) | |||
4018 | * cpus with ticks stopped, is it time for that to stop? | 4088 | * cpus with ticks stopped, is it time for that to stop? |
4019 | */ | 4089 | */ |
4020 | if (rq->idle_at_tick && atomic_read(&nohz.load_balancer) == cpu && | 4090 | if (rq->idle_at_tick && atomic_read(&nohz.load_balancer) == cpu && |
4021 | cpus_weight(nohz.cpu_mask) == num_online_cpus()) { | 4091 | cpumask_weight(nohz.cpu_mask) == num_online_cpus()) { |
4022 | resched_cpu(cpu); | 4092 | resched_cpu(cpu); |
4023 | return; | 4093 | return; |
4024 | } | 4094 | } |
@@ -4028,7 +4098,7 @@ static inline void trigger_load_balance(struct rq *rq, int cpu) | |||
4028 | * someone else, then no need raise the SCHED_SOFTIRQ | 4098 | * someone else, then no need raise the SCHED_SOFTIRQ |
4029 | */ | 4099 | */ |
4030 | if (rq->idle_at_tick && atomic_read(&nohz.load_balancer) != cpu && | 4100 | if (rq->idle_at_tick && atomic_read(&nohz.load_balancer) != cpu && |
4031 | cpu_isset(cpu, nohz.cpu_mask)) | 4101 | cpumask_test_cpu(cpu, nohz.cpu_mask)) |
4032 | return; | 4102 | return; |
4033 | #endif | 4103 | #endif |
4034 | if (time_after_eq(jiffies, rq->next_balance)) | 4104 | if (time_after_eq(jiffies, rq->next_balance)) |
@@ -5401,10 +5471,9 @@ out_unlock: | |||
5401 | return retval; | 5471 | return retval; |
5402 | } | 5472 | } |
5403 | 5473 | ||
5404 | long sched_setaffinity(pid_t pid, const cpumask_t *in_mask) | 5474 | long sched_setaffinity(pid_t pid, const struct cpumask *in_mask) |
5405 | { | 5475 | { |
5406 | cpumask_t cpus_allowed; | 5476 | cpumask_var_t cpus_allowed, new_mask; |
5407 | cpumask_t new_mask = *in_mask; | ||
5408 | struct task_struct *p; | 5477 | struct task_struct *p; |
5409 | int retval; | 5478 | int retval; |
5410 | 5479 | ||
@@ -5426,6 +5495,14 @@ long sched_setaffinity(pid_t pid, const cpumask_t *in_mask) | |||
5426 | get_task_struct(p); | 5495 | get_task_struct(p); |
5427 | read_unlock(&tasklist_lock); | 5496 | read_unlock(&tasklist_lock); |
5428 | 5497 | ||
5498 | if (!alloc_cpumask_var(&cpus_allowed, GFP_KERNEL)) { | ||
5499 | retval = -ENOMEM; | ||
5500 | goto out_put_task; | ||
5501 | } | ||
5502 | if (!alloc_cpumask_var(&new_mask, GFP_KERNEL)) { | ||
5503 | retval = -ENOMEM; | ||
5504 | goto out_free_cpus_allowed; | ||
5505 | } | ||
5429 | retval = -EPERM; | 5506 | retval = -EPERM; |
5430 | if (!check_same_owner(p) && !capable(CAP_SYS_NICE)) | 5507 | if (!check_same_owner(p) && !capable(CAP_SYS_NICE)) |
5431 | goto out_unlock; | 5508 | goto out_unlock; |
@@ -5434,37 +5511,41 @@ long sched_setaffinity(pid_t pid, const cpumask_t *in_mask) | |||
5434 | if (retval) | 5511 | if (retval) |
5435 | goto out_unlock; | 5512 | goto out_unlock; |
5436 | 5513 | ||
5437 | cpuset_cpus_allowed(p, &cpus_allowed); | 5514 | cpuset_cpus_allowed(p, cpus_allowed); |
5438 | cpus_and(new_mask, new_mask, cpus_allowed); | 5515 | cpumask_and(new_mask, in_mask, cpus_allowed); |
5439 | again: | 5516 | again: |
5440 | retval = set_cpus_allowed_ptr(p, &new_mask); | 5517 | retval = set_cpus_allowed_ptr(p, new_mask); |
5441 | 5518 | ||
5442 | if (!retval) { | 5519 | if (!retval) { |
5443 | cpuset_cpus_allowed(p, &cpus_allowed); | 5520 | cpuset_cpus_allowed(p, cpus_allowed); |
5444 | if (!cpus_subset(new_mask, cpus_allowed)) { | 5521 | if (!cpumask_subset(new_mask, cpus_allowed)) { |
5445 | /* | 5522 | /* |
5446 | * We must have raced with a concurrent cpuset | 5523 | * We must have raced with a concurrent cpuset |
5447 | * update. Just reset the cpus_allowed to the | 5524 | * update. Just reset the cpus_allowed to the |
5448 | * cpuset's cpus_allowed | 5525 | * cpuset's cpus_allowed |
5449 | */ | 5526 | */ |
5450 | new_mask = cpus_allowed; | 5527 | cpumask_copy(new_mask, cpus_allowed); |
5451 | goto again; | 5528 | goto again; |
5452 | } | 5529 | } |
5453 | } | 5530 | } |
5454 | out_unlock: | 5531 | out_unlock: |
5532 | free_cpumask_var(new_mask); | ||
5533 | out_free_cpus_allowed: | ||
5534 | free_cpumask_var(cpus_allowed); | ||
5535 | out_put_task: | ||
5455 | put_task_struct(p); | 5536 | put_task_struct(p); |
5456 | put_online_cpus(); | 5537 | put_online_cpus(); |
5457 | return retval; | 5538 | return retval; |
5458 | } | 5539 | } |
5459 | 5540 | ||
5460 | static int get_user_cpu_mask(unsigned long __user *user_mask_ptr, unsigned len, | 5541 | static int get_user_cpu_mask(unsigned long __user *user_mask_ptr, unsigned len, |
5461 | cpumask_t *new_mask) | 5542 | struct cpumask *new_mask) |
5462 | { | 5543 | { |
5463 | if (len < sizeof(cpumask_t)) { | 5544 | if (len < cpumask_size()) |
5464 | memset(new_mask, 0, sizeof(cpumask_t)); | 5545 | cpumask_clear(new_mask); |
5465 | } else if (len > sizeof(cpumask_t)) { | 5546 | else if (len > cpumask_size()) |
5466 | len = sizeof(cpumask_t); | 5547 | len = cpumask_size(); |
5467 | } | 5548 | |
5468 | return copy_from_user(new_mask, user_mask_ptr, len) ? -EFAULT : 0; | 5549 | return copy_from_user(new_mask, user_mask_ptr, len) ? -EFAULT : 0; |
5469 | } | 5550 | } |
5470 | 5551 | ||
@@ -5477,17 +5558,20 @@ static int get_user_cpu_mask(unsigned long __user *user_mask_ptr, unsigned len, | |||
5477 | asmlinkage long sys_sched_setaffinity(pid_t pid, unsigned int len, | 5558 | asmlinkage long sys_sched_setaffinity(pid_t pid, unsigned int len, |
5478 | unsigned long __user *user_mask_ptr) | 5559 | unsigned long __user *user_mask_ptr) |
5479 | { | 5560 | { |
5480 | cpumask_t new_mask; | 5561 | cpumask_var_t new_mask; |
5481 | int retval; | 5562 | int retval; |
5482 | 5563 | ||
5483 | retval = get_user_cpu_mask(user_mask_ptr, len, &new_mask); | 5564 | if (!alloc_cpumask_var(&new_mask, GFP_KERNEL)) |
5484 | if (retval) | 5565 | return -ENOMEM; |
5485 | return retval; | ||
5486 | 5566 | ||
5487 | return sched_setaffinity(pid, &new_mask); | 5567 | retval = get_user_cpu_mask(user_mask_ptr, len, new_mask); |
5568 | if (retval == 0) | ||
5569 | retval = sched_setaffinity(pid, new_mask); | ||
5570 | free_cpumask_var(new_mask); | ||
5571 | return retval; | ||
5488 | } | 5572 | } |
5489 | 5573 | ||
5490 | long sched_getaffinity(pid_t pid, cpumask_t *mask) | 5574 | long sched_getaffinity(pid_t pid, struct cpumask *mask) |
5491 | { | 5575 | { |
5492 | struct task_struct *p; | 5576 | struct task_struct *p; |
5493 | int retval; | 5577 | int retval; |
@@ -5504,7 +5588,7 @@ long sched_getaffinity(pid_t pid, cpumask_t *mask) | |||
5504 | if (retval) | 5588 | if (retval) |
5505 | goto out_unlock; | 5589 | goto out_unlock; |
5506 | 5590 | ||
5507 | cpus_and(*mask, p->cpus_allowed, cpu_online_map); | 5591 | cpumask_and(mask, &p->cpus_allowed, cpu_online_mask); |
5508 | 5592 | ||
5509 | out_unlock: | 5593 | out_unlock: |
5510 | read_unlock(&tasklist_lock); | 5594 | read_unlock(&tasklist_lock); |
@@ -5523,19 +5607,24 @@ asmlinkage long sys_sched_getaffinity(pid_t pid, unsigned int len, | |||
5523 | unsigned long __user *user_mask_ptr) | 5607 | unsigned long __user *user_mask_ptr) |
5524 | { | 5608 | { |
5525 | int ret; | 5609 | int ret; |
5526 | cpumask_t mask; | 5610 | cpumask_var_t mask; |
5527 | 5611 | ||
5528 | if (len < sizeof(cpumask_t)) | 5612 | if (len < cpumask_size()) |
5529 | return -EINVAL; | 5613 | return -EINVAL; |
5530 | 5614 | ||
5531 | ret = sched_getaffinity(pid, &mask); | 5615 | if (!alloc_cpumask_var(&mask, GFP_KERNEL)) |
5532 | if (ret < 0) | 5616 | return -ENOMEM; |
5533 | return ret; | ||
5534 | 5617 | ||
5535 | if (copy_to_user(user_mask_ptr, &mask, sizeof(cpumask_t))) | 5618 | ret = sched_getaffinity(pid, mask); |
5536 | return -EFAULT; | 5619 | if (ret == 0) { |
5620 | if (copy_to_user(user_mask_ptr, mask, cpumask_size())) | ||
5621 | ret = -EFAULT; | ||
5622 | else | ||
5623 | ret = cpumask_size(); | ||
5624 | } | ||
5625 | free_cpumask_var(mask); | ||
5537 | 5626 | ||
5538 | return sizeof(cpumask_t); | 5627 | return ret; |
5539 | } | 5628 | } |
5540 | 5629 | ||
5541 | /** | 5630 | /** |
@@ -5877,7 +5966,7 @@ void __cpuinit init_idle(struct task_struct *idle, int cpu) | |||
5877 | idle->se.exec_start = sched_clock(); | 5966 | idle->se.exec_start = sched_clock(); |
5878 | 5967 | ||
5879 | idle->prio = idle->normal_prio = MAX_PRIO; | 5968 | idle->prio = idle->normal_prio = MAX_PRIO; |
5880 | idle->cpus_allowed = cpumask_of_cpu(cpu); | 5969 | cpumask_copy(&idle->cpus_allowed, cpumask_of(cpu)); |
5881 | __set_task_cpu(idle, cpu); | 5970 | __set_task_cpu(idle, cpu); |
5882 | 5971 | ||
5883 | rq->curr = rq->idle = idle; | 5972 | rq->curr = rq->idle = idle; |
@@ -5904,9 +5993,9 @@ void __cpuinit init_idle(struct task_struct *idle, int cpu) | |||
5904 | * indicates which cpus entered this state. This is used | 5993 | * indicates which cpus entered this state. This is used |
5905 | * in the rcu update to wait only for active cpus. For system | 5994 | * in the rcu update to wait only for active cpus. For system |
5906 | * which do not switch off the HZ timer nohz_cpu_mask should | 5995 | * which do not switch off the HZ timer nohz_cpu_mask should |
5907 | * always be CPU_MASK_NONE. | 5996 | * always be CPU_BITS_NONE. |
5908 | */ | 5997 | */ |
5909 | cpumask_t nohz_cpu_mask = CPU_MASK_NONE; | 5998 | cpumask_var_t nohz_cpu_mask; |
5910 | 5999 | ||
5911 | /* | 6000 | /* |
5912 | * Increase the granularity value when there are more CPUs, | 6001 | * Increase the granularity value when there are more CPUs, |
@@ -5961,7 +6050,7 @@ static inline void sched_init_granularity(void) | |||
5961 | * task must not exit() & deallocate itself prematurely. The | 6050 | * task must not exit() & deallocate itself prematurely. The |
5962 | * call is not atomic; no spinlocks may be held. | 6051 | * call is not atomic; no spinlocks may be held. |
5963 | */ | 6052 | */ |
5964 | int set_cpus_allowed_ptr(struct task_struct *p, const cpumask_t *new_mask) | 6053 | int set_cpus_allowed_ptr(struct task_struct *p, const struct cpumask *new_mask) |
5965 | { | 6054 | { |
5966 | struct migration_req req; | 6055 | struct migration_req req; |
5967 | unsigned long flags; | 6056 | unsigned long flags; |
@@ -5969,13 +6058,13 @@ int set_cpus_allowed_ptr(struct task_struct *p, const cpumask_t *new_mask) | |||
5969 | int ret = 0; | 6058 | int ret = 0; |
5970 | 6059 | ||
5971 | rq = task_rq_lock(p, &flags); | 6060 | rq = task_rq_lock(p, &flags); |
5972 | if (!cpus_intersects(*new_mask, cpu_online_map)) { | 6061 | if (!cpumask_intersects(new_mask, cpu_online_mask)) { |
5973 | ret = -EINVAL; | 6062 | ret = -EINVAL; |
5974 | goto out; | 6063 | goto out; |
5975 | } | 6064 | } |
5976 | 6065 | ||
5977 | if (unlikely((p->flags & PF_THREAD_BOUND) && p != current && | 6066 | if (unlikely((p->flags & PF_THREAD_BOUND) && p != current && |
5978 | !cpus_equal(p->cpus_allowed, *new_mask))) { | 6067 | !cpumask_equal(&p->cpus_allowed, new_mask))) { |
5979 | ret = -EINVAL; | 6068 | ret = -EINVAL; |
5980 | goto out; | 6069 | goto out; |
5981 | } | 6070 | } |
@@ -5983,15 +6072,15 @@ int set_cpus_allowed_ptr(struct task_struct *p, const cpumask_t *new_mask) | |||
5983 | if (p->sched_class->set_cpus_allowed) | 6072 | if (p->sched_class->set_cpus_allowed) |
5984 | p->sched_class->set_cpus_allowed(p, new_mask); | 6073 | p->sched_class->set_cpus_allowed(p, new_mask); |
5985 | else { | 6074 | else { |
5986 | p->cpus_allowed = *new_mask; | 6075 | cpumask_copy(&p->cpus_allowed, new_mask); |
5987 | p->rt.nr_cpus_allowed = cpus_weight(*new_mask); | 6076 | p->rt.nr_cpus_allowed = cpumask_weight(new_mask); |
5988 | } | 6077 | } |
5989 | 6078 | ||
5990 | /* Can the task run on the task's current CPU? If so, we're done */ | 6079 | /* Can the task run on the task's current CPU? If so, we're done */ |
5991 | if (cpu_isset(task_cpu(p), *new_mask)) | 6080 | if (cpumask_test_cpu(task_cpu(p), new_mask)) |
5992 | goto out; | 6081 | goto out; |
5993 | 6082 | ||
5994 | if (migrate_task(p, any_online_cpu(*new_mask), &req)) { | 6083 | if (migrate_task(p, cpumask_any_and(cpu_online_mask, new_mask), &req)) { |
5995 | /* Need help from migration thread: drop lock and wait. */ | 6084 | /* Need help from migration thread: drop lock and wait. */ |
5996 | task_rq_unlock(rq, &flags); | 6085 | task_rq_unlock(rq, &flags); |
5997 | wake_up_process(rq->migration_thread); | 6086 | wake_up_process(rq->migration_thread); |
@@ -6033,7 +6122,7 @@ static int __migrate_task(struct task_struct *p, int src_cpu, int dest_cpu) | |||
6033 | if (task_cpu(p) != src_cpu) | 6122 | if (task_cpu(p) != src_cpu) |
6034 | goto done; | 6123 | goto done; |
6035 | /* Affinity changed (again). */ | 6124 | /* Affinity changed (again). */ |
6036 | if (!cpu_isset(dest_cpu, p->cpus_allowed)) | 6125 | if (!cpumask_test_cpu(dest_cpu, &p->cpus_allowed)) |
6037 | goto fail; | 6126 | goto fail; |
6038 | 6127 | ||
6039 | on_rq = p->se.on_rq; | 6128 | on_rq = p->se.on_rq; |
@@ -6130,50 +6219,43 @@ static int __migrate_task_irq(struct task_struct *p, int src_cpu, int dest_cpu) | |||
6130 | */ | 6219 | */ |
6131 | static void move_task_off_dead_cpu(int dead_cpu, struct task_struct *p) | 6220 | static void move_task_off_dead_cpu(int dead_cpu, struct task_struct *p) |
6132 | { | 6221 | { |
6133 | unsigned long flags; | ||
6134 | cpumask_t mask; | ||
6135 | struct rq *rq; | ||
6136 | int dest_cpu; | 6222 | int dest_cpu; |
6223 | /* FIXME: Use cpumask_of_node here. */ | ||
6224 | cpumask_t _nodemask = node_to_cpumask(cpu_to_node(dead_cpu)); | ||
6225 | const struct cpumask *nodemask = &_nodemask; | ||
6226 | |||
6227 | again: | ||
6228 | /* Look for allowed, online CPU in same node. */ | ||
6229 | for_each_cpu_and(dest_cpu, nodemask, cpu_online_mask) | ||
6230 | if (cpumask_test_cpu(dest_cpu, &p->cpus_allowed)) | ||
6231 | goto move; | ||
6232 | |||
6233 | /* Any allowed, online CPU? */ | ||
6234 | dest_cpu = cpumask_any_and(&p->cpus_allowed, cpu_online_mask); | ||
6235 | if (dest_cpu < nr_cpu_ids) | ||
6236 | goto move; | ||
6237 | |||
6238 | /* No more Mr. Nice Guy. */ | ||
6239 | if (dest_cpu >= nr_cpu_ids) { | ||
6240 | cpuset_cpus_allowed_locked(p, &p->cpus_allowed); | ||
6241 | dest_cpu = cpumask_any_and(cpu_online_mask, &p->cpus_allowed); | ||
6137 | 6242 | ||
6138 | do { | 6243 | /* |
6139 | /* On same node? */ | 6244 | * Don't tell them about moving exiting tasks or |
6140 | mask = node_to_cpumask(cpu_to_node(dead_cpu)); | 6245 | * kernel threads (both mm NULL), since they never |
6141 | cpus_and(mask, mask, p->cpus_allowed); | 6246 | * leave kernel. |
6142 | dest_cpu = any_online_cpu(mask); | 6247 | */ |
6143 | 6248 | if (p->mm && printk_ratelimit()) { | |
6144 | /* On any allowed CPU? */ | 6249 | printk(KERN_INFO "process %d (%s) no " |
6145 | if (dest_cpu >= nr_cpu_ids) | 6250 | "longer affine to cpu%d\n", |
6146 | dest_cpu = any_online_cpu(p->cpus_allowed); | 6251 | task_pid_nr(p), p->comm, dead_cpu); |
6147 | |||
6148 | /* No more Mr. Nice Guy. */ | ||
6149 | if (dest_cpu >= nr_cpu_ids) { | ||
6150 | cpumask_t cpus_allowed; | ||
6151 | |||
6152 | cpuset_cpus_allowed_locked(p, &cpus_allowed); | ||
6153 | /* | ||
6154 | * Try to stay on the same cpuset, where the | ||
6155 | * current cpuset may be a subset of all cpus. | ||
6156 | * The cpuset_cpus_allowed_locked() variant of | ||
6157 | * cpuset_cpus_allowed() will not block. It must be | ||
6158 | * called within calls to cpuset_lock/cpuset_unlock. | ||
6159 | */ | ||
6160 | rq = task_rq_lock(p, &flags); | ||
6161 | p->cpus_allowed = cpus_allowed; | ||
6162 | dest_cpu = any_online_cpu(p->cpus_allowed); | ||
6163 | task_rq_unlock(rq, &flags); | ||
6164 | |||
6165 | /* | ||
6166 | * Don't tell them about moving exiting tasks or | ||
6167 | * kernel threads (both mm NULL), since they never | ||
6168 | * leave kernel. | ||
6169 | */ | ||
6170 | if (p->mm && printk_ratelimit()) { | ||
6171 | printk(KERN_INFO "process %d (%s) no " | ||
6172 | "longer affine to cpu%d\n", | ||
6173 | task_pid_nr(p), p->comm, dead_cpu); | ||
6174 | } | ||
6175 | } | 6252 | } |
6176 | } while (!__migrate_task_irq(p, dead_cpu, dest_cpu)); | 6253 | } |
6254 | |||
6255 | move: | ||
6256 | /* It can have affinity changed while we were choosing. */ | ||
6257 | if (unlikely(!__migrate_task_irq(p, dead_cpu, dest_cpu))) | ||
6258 | goto again; | ||
6177 | } | 6259 | } |
6178 | 6260 | ||
6179 | /* | 6261 | /* |
@@ -6185,7 +6267,7 @@ static void move_task_off_dead_cpu(int dead_cpu, struct task_struct *p) | |||
6185 | */ | 6267 | */ |
6186 | static void migrate_nr_uninterruptible(struct rq *rq_src) | 6268 | static void migrate_nr_uninterruptible(struct rq *rq_src) |
6187 | { | 6269 | { |
6188 | struct rq *rq_dest = cpu_rq(any_online_cpu(*CPU_MASK_ALL_PTR)); | 6270 | struct rq *rq_dest = cpu_rq(cpumask_any(cpu_online_mask)); |
6189 | unsigned long flags; | 6271 | unsigned long flags; |
6190 | 6272 | ||
6191 | local_irq_save(flags); | 6273 | local_irq_save(flags); |
@@ -6475,7 +6557,7 @@ static void set_rq_online(struct rq *rq) | |||
6475 | if (!rq->online) { | 6557 | if (!rq->online) { |
6476 | const struct sched_class *class; | 6558 | const struct sched_class *class; |
6477 | 6559 | ||
6478 | cpu_set(rq->cpu, rq->rd->online); | 6560 | cpumask_set_cpu(rq->cpu, rq->rd->online); |
6479 | rq->online = 1; | 6561 | rq->online = 1; |
6480 | 6562 | ||
6481 | for_each_class(class) { | 6563 | for_each_class(class) { |
@@ -6495,7 +6577,7 @@ static void set_rq_offline(struct rq *rq) | |||
6495 | class->rq_offline(rq); | 6577 | class->rq_offline(rq); |
6496 | } | 6578 | } |
6497 | 6579 | ||
6498 | cpu_clear(rq->cpu, rq->rd->online); | 6580 | cpumask_clear_cpu(rq->cpu, rq->rd->online); |
6499 | rq->online = 0; | 6581 | rq->online = 0; |
6500 | } | 6582 | } |
6501 | } | 6583 | } |
@@ -6536,7 +6618,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu) | |||
6536 | rq = cpu_rq(cpu); | 6618 | rq = cpu_rq(cpu); |
6537 | spin_lock_irqsave(&rq->lock, flags); | 6619 | spin_lock_irqsave(&rq->lock, flags); |
6538 | if (rq->rd) { | 6620 | if (rq->rd) { |
6539 | BUG_ON(!cpu_isset(cpu, rq->rd->span)); | 6621 | BUG_ON(!cpumask_test_cpu(cpu, rq->rd->span)); |
6540 | 6622 | ||
6541 | set_rq_online(rq); | 6623 | set_rq_online(rq); |
6542 | } | 6624 | } |
@@ -6550,7 +6632,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu) | |||
6550 | break; | 6632 | break; |
6551 | /* Unbind it from offline cpu so it can run. Fall thru. */ | 6633 | /* Unbind it from offline cpu so it can run. Fall thru. */ |
6552 | kthread_bind(cpu_rq(cpu)->migration_thread, | 6634 | kthread_bind(cpu_rq(cpu)->migration_thread, |
6553 | any_online_cpu(cpu_online_map)); | 6635 | cpumask_any(cpu_online_mask)); |
6554 | kthread_stop(cpu_rq(cpu)->migration_thread); | 6636 | kthread_stop(cpu_rq(cpu)->migration_thread); |
6555 | cpu_rq(cpu)->migration_thread = NULL; | 6637 | cpu_rq(cpu)->migration_thread = NULL; |
6556 | break; | 6638 | break; |
@@ -6600,7 +6682,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu) | |||
6600 | rq = cpu_rq(cpu); | 6682 | rq = cpu_rq(cpu); |
6601 | spin_lock_irqsave(&rq->lock, flags); | 6683 | spin_lock_irqsave(&rq->lock, flags); |
6602 | if (rq->rd) { | 6684 | if (rq->rd) { |
6603 | BUG_ON(!cpu_isset(cpu, rq->rd->span)); | 6685 | BUG_ON(!cpumask_test_cpu(cpu, rq->rd->span)); |
6604 | set_rq_offline(rq); | 6686 | set_rq_offline(rq); |
6605 | } | 6687 | } |
6606 | spin_unlock_irqrestore(&rq->lock, flags); | 6688 | spin_unlock_irqrestore(&rq->lock, flags); |
@@ -6639,13 +6721,13 @@ early_initcall(migration_init); | |||
6639 | #ifdef CONFIG_SCHED_DEBUG | 6721 | #ifdef CONFIG_SCHED_DEBUG |
6640 | 6722 | ||
6641 | static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level, | 6723 | static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level, |
6642 | cpumask_t *groupmask) | 6724 | struct cpumask *groupmask) |
6643 | { | 6725 | { |
6644 | struct sched_group *group = sd->groups; | 6726 | struct sched_group *group = sd->groups; |
6645 | char str[256]; | 6727 | char str[256]; |
6646 | 6728 | ||
6647 | cpulist_scnprintf(str, sizeof(str), &sd->span); | 6729 | cpulist_scnprintf(str, sizeof(str), sched_domain_span(sd)); |
6648 | cpus_clear(*groupmask); | 6730 | cpumask_clear(groupmask); |
6649 | 6731 | ||
6650 | printk(KERN_DEBUG "%*s domain %d: ", level, "", level); | 6732 | printk(KERN_DEBUG "%*s domain %d: ", level, "", level); |
6651 | 6733 | ||
@@ -6659,11 +6741,11 @@ static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level, | |||
6659 | 6741 | ||
6660 | printk(KERN_CONT "span %s level %s\n", str, sd->name); | 6742 | printk(KERN_CONT "span %s level %s\n", str, sd->name); |
6661 | 6743 | ||
6662 | if (!cpu_isset(cpu, sd->span)) { | 6744 | if (!cpumask_test_cpu(cpu, sched_domain_span(sd))) { |
6663 | printk(KERN_ERR "ERROR: domain->span does not contain " | 6745 | printk(KERN_ERR "ERROR: domain->span does not contain " |
6664 | "CPU%d\n", cpu); | 6746 | "CPU%d\n", cpu); |
6665 | } | 6747 | } |
6666 | if (!cpu_isset(cpu, group->cpumask)) { | 6748 | if (!cpumask_test_cpu(cpu, sched_group_cpus(group))) { |
6667 | printk(KERN_ERR "ERROR: domain->groups does not contain" | 6749 | printk(KERN_ERR "ERROR: domain->groups does not contain" |
6668 | " CPU%d\n", cpu); | 6750 | " CPU%d\n", cpu); |
6669 | } | 6751 | } |
@@ -6683,31 +6765,32 @@ static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level, | |||
6683 | break; | 6765 | break; |
6684 | } | 6766 | } |
6685 | 6767 | ||
6686 | if (!cpus_weight(group->cpumask)) { | 6768 | if (!cpumask_weight(sched_group_cpus(group))) { |
6687 | printk(KERN_CONT "\n"); | 6769 | printk(KERN_CONT "\n"); |
6688 | printk(KERN_ERR "ERROR: empty group\n"); | 6770 | printk(KERN_ERR "ERROR: empty group\n"); |
6689 | break; | 6771 | break; |
6690 | } | 6772 | } |
6691 | 6773 | ||
6692 | if (cpus_intersects(*groupmask, group->cpumask)) { | 6774 | if (cpumask_intersects(groupmask, sched_group_cpus(group))) { |
6693 | printk(KERN_CONT "\n"); | 6775 | printk(KERN_CONT "\n"); |
6694 | printk(KERN_ERR "ERROR: repeated CPUs\n"); | 6776 | printk(KERN_ERR "ERROR: repeated CPUs\n"); |
6695 | break; | 6777 | break; |
6696 | } | 6778 | } |
6697 | 6779 | ||
6698 | cpus_or(*groupmask, *groupmask, group->cpumask); | 6780 | cpumask_or(groupmask, groupmask, sched_group_cpus(group)); |
6699 | 6781 | ||
6700 | cpulist_scnprintf(str, sizeof(str), &group->cpumask); | 6782 | cpulist_scnprintf(str, sizeof(str), sched_group_cpus(group)); |
6701 | printk(KERN_CONT " %s", str); | 6783 | printk(KERN_CONT " %s", str); |
6702 | 6784 | ||
6703 | group = group->next; | 6785 | group = group->next; |
6704 | } while (group != sd->groups); | 6786 | } while (group != sd->groups); |
6705 | printk(KERN_CONT "\n"); | 6787 | printk(KERN_CONT "\n"); |
6706 | 6788 | ||
6707 | if (!cpus_equal(sd->span, *groupmask)) | 6789 | if (!cpumask_equal(sched_domain_span(sd), groupmask)) |
6708 | printk(KERN_ERR "ERROR: groups don't span domain->span\n"); | 6790 | printk(KERN_ERR "ERROR: groups don't span domain->span\n"); |
6709 | 6791 | ||
6710 | if (sd->parent && !cpus_subset(*groupmask, sd->parent->span)) | 6792 | if (sd->parent && |
6793 | !cpumask_subset(groupmask, sched_domain_span(sd->parent))) | ||
6711 | printk(KERN_ERR "ERROR: parent span is not a superset " | 6794 | printk(KERN_ERR "ERROR: parent span is not a superset " |
6712 | "of domain->span\n"); | 6795 | "of domain->span\n"); |
6713 | return 0; | 6796 | return 0; |
@@ -6715,7 +6798,7 @@ static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level, | |||
6715 | 6798 | ||
6716 | static void sched_domain_debug(struct sched_domain *sd, int cpu) | 6799 | static void sched_domain_debug(struct sched_domain *sd, int cpu) |
6717 | { | 6800 | { |
6718 | cpumask_t *groupmask; | 6801 | cpumask_var_t groupmask; |
6719 | int level = 0; | 6802 | int level = 0; |
6720 | 6803 | ||
6721 | if (!sd) { | 6804 | if (!sd) { |
@@ -6725,8 +6808,7 @@ static void sched_domain_debug(struct sched_domain *sd, int cpu) | |||
6725 | 6808 | ||
6726 | printk(KERN_DEBUG "CPU%d attaching sched-domain:\n", cpu); | 6809 | printk(KERN_DEBUG "CPU%d attaching sched-domain:\n", cpu); |
6727 | 6810 | ||
6728 | groupmask = kmalloc(sizeof(cpumask_t), GFP_KERNEL); | 6811 | if (!alloc_cpumask_var(&groupmask, GFP_KERNEL)) { |
6729 | if (!groupmask) { | ||
6730 | printk(KERN_DEBUG "Cannot load-balance (out of memory)\n"); | 6812 | printk(KERN_DEBUG "Cannot load-balance (out of memory)\n"); |
6731 | return; | 6813 | return; |
6732 | } | 6814 | } |
@@ -6739,7 +6821,7 @@ static void sched_domain_debug(struct sched_domain *sd, int cpu) | |||
6739 | if (!sd) | 6821 | if (!sd) |
6740 | break; | 6822 | break; |
6741 | } | 6823 | } |
6742 | kfree(groupmask); | 6824 | free_cpumask_var(groupmask); |
6743 | } | 6825 | } |
6744 | #else /* !CONFIG_SCHED_DEBUG */ | 6826 | #else /* !CONFIG_SCHED_DEBUG */ |
6745 | # define sched_domain_debug(sd, cpu) do { } while (0) | 6827 | # define sched_domain_debug(sd, cpu) do { } while (0) |
@@ -6747,7 +6829,7 @@ static void sched_domain_debug(struct sched_domain *sd, int cpu) | |||
6747 | 6829 | ||
6748 | static int sd_degenerate(struct sched_domain *sd) | 6830 | static int sd_degenerate(struct sched_domain *sd) |
6749 | { | 6831 | { |
6750 | if (cpus_weight(sd->span) == 1) | 6832 | if (cpumask_weight(sched_domain_span(sd)) == 1) |
6751 | return 1; | 6833 | return 1; |
6752 | 6834 | ||
6753 | /* Following flags need at least 2 groups */ | 6835 | /* Following flags need at least 2 groups */ |
@@ -6778,7 +6860,7 @@ sd_parent_degenerate(struct sched_domain *sd, struct sched_domain *parent) | |||
6778 | if (sd_degenerate(parent)) | 6860 | if (sd_degenerate(parent)) |
6779 | return 1; | 6861 | return 1; |
6780 | 6862 | ||
6781 | if (!cpus_equal(sd->span, parent->span)) | 6863 | if (!cpumask_equal(sched_domain_span(sd), sched_domain_span(parent))) |
6782 | return 0; | 6864 | return 0; |
6783 | 6865 | ||
6784 | /* Does parent contain flags not in child? */ | 6866 | /* Does parent contain flags not in child? */ |
@@ -6802,6 +6884,16 @@ sd_parent_degenerate(struct sched_domain *sd, struct sched_domain *parent) | |||
6802 | return 1; | 6884 | return 1; |
6803 | } | 6885 | } |
6804 | 6886 | ||
6887 | static void free_rootdomain(struct root_domain *rd) | ||
6888 | { | ||
6889 | cpupri_cleanup(&rd->cpupri); | ||
6890 | |||
6891 | free_cpumask_var(rd->rto_mask); | ||
6892 | free_cpumask_var(rd->online); | ||
6893 | free_cpumask_var(rd->span); | ||
6894 | kfree(rd); | ||
6895 | } | ||
6896 | |||
6805 | static void rq_attach_root(struct rq *rq, struct root_domain *rd) | 6897 | static void rq_attach_root(struct rq *rq, struct root_domain *rd) |
6806 | { | 6898 | { |
6807 | unsigned long flags; | 6899 | unsigned long flags; |
@@ -6811,38 +6903,63 @@ static void rq_attach_root(struct rq *rq, struct root_domain *rd) | |||
6811 | if (rq->rd) { | 6903 | if (rq->rd) { |
6812 | struct root_domain *old_rd = rq->rd; | 6904 | struct root_domain *old_rd = rq->rd; |
6813 | 6905 | ||
6814 | if (cpu_isset(rq->cpu, old_rd->online)) | 6906 | if (cpumask_test_cpu(rq->cpu, old_rd->online)) |
6815 | set_rq_offline(rq); | 6907 | set_rq_offline(rq); |
6816 | 6908 | ||
6817 | cpu_clear(rq->cpu, old_rd->span); | 6909 | cpumask_clear_cpu(rq->cpu, old_rd->span); |
6818 | 6910 | ||
6819 | if (atomic_dec_and_test(&old_rd->refcount)) | 6911 | if (atomic_dec_and_test(&old_rd->refcount)) |
6820 | kfree(old_rd); | 6912 | free_rootdomain(old_rd); |
6821 | } | 6913 | } |
6822 | 6914 | ||
6823 | atomic_inc(&rd->refcount); | 6915 | atomic_inc(&rd->refcount); |
6824 | rq->rd = rd; | 6916 | rq->rd = rd; |
6825 | 6917 | ||
6826 | cpu_set(rq->cpu, rd->span); | 6918 | cpumask_set_cpu(rq->cpu, rd->span); |
6827 | if (cpu_isset(rq->cpu, cpu_online_map)) | 6919 | if (cpumask_test_cpu(rq->cpu, cpu_online_mask)) |
6828 | set_rq_online(rq); | 6920 | set_rq_online(rq); |
6829 | 6921 | ||
6830 | spin_unlock_irqrestore(&rq->lock, flags); | 6922 | spin_unlock_irqrestore(&rq->lock, flags); |
6831 | } | 6923 | } |
6832 | 6924 | ||
6833 | static void init_rootdomain(struct root_domain *rd) | 6925 | static int init_rootdomain(struct root_domain *rd, bool bootmem) |
6834 | { | 6926 | { |
6835 | memset(rd, 0, sizeof(*rd)); | 6927 | memset(rd, 0, sizeof(*rd)); |
6836 | 6928 | ||
6837 | cpus_clear(rd->span); | 6929 | if (bootmem) { |
6838 | cpus_clear(rd->online); | 6930 | alloc_bootmem_cpumask_var(&def_root_domain.span); |
6931 | alloc_bootmem_cpumask_var(&def_root_domain.online); | ||
6932 | alloc_bootmem_cpumask_var(&def_root_domain.rto_mask); | ||
6933 | cpupri_init(&rd->cpupri, true); | ||
6934 | return 0; | ||
6935 | } | ||
6936 | |||
6937 | if (!alloc_cpumask_var(&rd->span, GFP_KERNEL)) | ||
6938 | goto free_rd; | ||
6939 | if (!alloc_cpumask_var(&rd->online, GFP_KERNEL)) | ||
6940 | goto free_span; | ||
6941 | if (!alloc_cpumask_var(&rd->rto_mask, GFP_KERNEL)) | ||
6942 | goto free_online; | ||
6943 | |||
6944 | if (cpupri_init(&rd->cpupri, false) != 0) | ||
6945 | goto free_rto_mask; | ||
6946 | return 0; | ||
6839 | 6947 | ||
6840 | cpupri_init(&rd->cpupri); | 6948 | free_rto_mask: |
6949 | free_cpumask_var(rd->rto_mask); | ||
6950 | free_online: | ||
6951 | free_cpumask_var(rd->online); | ||
6952 | free_span: | ||
6953 | free_cpumask_var(rd->span); | ||
6954 | free_rd: | ||
6955 | kfree(rd); | ||
6956 | return -ENOMEM; | ||
6841 | } | 6957 | } |
6842 | 6958 | ||
6843 | static void init_defrootdomain(void) | 6959 | static void init_defrootdomain(void) |
6844 | { | 6960 | { |
6845 | init_rootdomain(&def_root_domain); | 6961 | init_rootdomain(&def_root_domain, true); |
6962 | |||
6846 | atomic_set(&def_root_domain.refcount, 1); | 6963 | atomic_set(&def_root_domain.refcount, 1); |
6847 | } | 6964 | } |
6848 | 6965 | ||
@@ -6854,7 +6971,10 @@ static struct root_domain *alloc_rootdomain(void) | |||
6854 | if (!rd) | 6971 | if (!rd) |
6855 | return NULL; | 6972 | return NULL; |
6856 | 6973 | ||
6857 | init_rootdomain(rd); | 6974 | if (init_rootdomain(rd, false) != 0) { |
6975 | kfree(rd); | ||
6976 | return NULL; | ||
6977 | } | ||
6858 | 6978 | ||
6859 | return rd; | 6979 | return rd; |
6860 | } | 6980 | } |
@@ -6896,19 +7016,12 @@ cpu_attach_domain(struct sched_domain *sd, struct root_domain *rd, int cpu) | |||
6896 | } | 7016 | } |
6897 | 7017 | ||
6898 | /* cpus with isolated domains */ | 7018 | /* cpus with isolated domains */ |
6899 | static cpumask_t cpu_isolated_map = CPU_MASK_NONE; | 7019 | static cpumask_var_t cpu_isolated_map; |
6900 | 7020 | ||
6901 | /* Setup the mask of cpus configured for isolated domains */ | 7021 | /* Setup the mask of cpus configured for isolated domains */ |
6902 | static int __init isolated_cpu_setup(char *str) | 7022 | static int __init isolated_cpu_setup(char *str) |
6903 | { | 7023 | { |
6904 | static int __initdata ints[NR_CPUS]; | 7024 | cpulist_parse(str, cpu_isolated_map); |
6905 | int i; | ||
6906 | |||
6907 | str = get_options(str, ARRAY_SIZE(ints), ints); | ||
6908 | cpus_clear(cpu_isolated_map); | ||
6909 | for (i = 1; i <= ints[0]; i++) | ||
6910 | if (ints[i] < NR_CPUS) | ||
6911 | cpu_set(ints[i], cpu_isolated_map); | ||
6912 | return 1; | 7025 | return 1; |
6913 | } | 7026 | } |
6914 | 7027 | ||
@@ -6917,42 +7030,43 @@ __setup("isolcpus=", isolated_cpu_setup); | |||
6917 | /* | 7030 | /* |
6918 | * init_sched_build_groups takes the cpumask we wish to span, and a pointer | 7031 | * init_sched_build_groups takes the cpumask we wish to span, and a pointer |
6919 | * to a function which identifies what group(along with sched group) a CPU | 7032 | * to a function which identifies what group(along with sched group) a CPU |
6920 | * belongs to. The return value of group_fn must be a >= 0 and < NR_CPUS | 7033 | * belongs to. The return value of group_fn must be a >= 0 and < nr_cpu_ids |
6921 | * (due to the fact that we keep track of groups covered with a cpumask_t). | 7034 | * (due to the fact that we keep track of groups covered with a struct cpumask). |
6922 | * | 7035 | * |
6923 | * init_sched_build_groups will build a circular linked list of the groups | 7036 | * init_sched_build_groups will build a circular linked list of the groups |
6924 | * covered by the given span, and will set each group's ->cpumask correctly, | 7037 | * covered by the given span, and will set each group's ->cpumask correctly, |
6925 | * and ->cpu_power to 0. | 7038 | * and ->cpu_power to 0. |
6926 | */ | 7039 | */ |
6927 | static void | 7040 | static void |
6928 | init_sched_build_groups(const cpumask_t *span, const cpumask_t *cpu_map, | 7041 | init_sched_build_groups(const struct cpumask *span, |
6929 | int (*group_fn)(int cpu, const cpumask_t *cpu_map, | 7042 | const struct cpumask *cpu_map, |
7043 | int (*group_fn)(int cpu, const struct cpumask *cpu_map, | ||
6930 | struct sched_group **sg, | 7044 | struct sched_group **sg, |
6931 | cpumask_t *tmpmask), | 7045 | struct cpumask *tmpmask), |
6932 | cpumask_t *covered, cpumask_t *tmpmask) | 7046 | struct cpumask *covered, struct cpumask *tmpmask) |
6933 | { | 7047 | { |
6934 | struct sched_group *first = NULL, *last = NULL; | 7048 | struct sched_group *first = NULL, *last = NULL; |
6935 | int i; | 7049 | int i; |
6936 | 7050 | ||
6937 | cpus_clear(*covered); | 7051 | cpumask_clear(covered); |
6938 | 7052 | ||
6939 | for_each_cpu_mask_nr(i, *span) { | 7053 | for_each_cpu(i, span) { |
6940 | struct sched_group *sg; | 7054 | struct sched_group *sg; |
6941 | int group = group_fn(i, cpu_map, &sg, tmpmask); | 7055 | int group = group_fn(i, cpu_map, &sg, tmpmask); |
6942 | int j; | 7056 | int j; |
6943 | 7057 | ||
6944 | if (cpu_isset(i, *covered)) | 7058 | if (cpumask_test_cpu(i, covered)) |
6945 | continue; | 7059 | continue; |
6946 | 7060 | ||
6947 | cpus_clear(sg->cpumask); | 7061 | cpumask_clear(sched_group_cpus(sg)); |
6948 | sg->__cpu_power = 0; | 7062 | sg->__cpu_power = 0; |
6949 | 7063 | ||
6950 | for_each_cpu_mask_nr(j, *span) { | 7064 | for_each_cpu(j, span) { |
6951 | if (group_fn(j, cpu_map, NULL, tmpmask) != group) | 7065 | if (group_fn(j, cpu_map, NULL, tmpmask) != group) |
6952 | continue; | 7066 | continue; |
6953 | 7067 | ||
6954 | cpu_set(j, *covered); | 7068 | cpumask_set_cpu(j, covered); |
6955 | cpu_set(j, sg->cpumask); | 7069 | cpumask_set_cpu(j, sched_group_cpus(sg)); |
6956 | } | 7070 | } |
6957 | if (!first) | 7071 | if (!first) |
6958 | first = sg; | 7072 | first = sg; |
@@ -7016,9 +7130,10 @@ static int find_next_best_node(int node, nodemask_t *used_nodes) | |||
7016 | * should be one that prevents unnecessary balancing, but also spreads tasks | 7130 | * should be one that prevents unnecessary balancing, but also spreads tasks |
7017 | * out optimally. | 7131 | * out optimally. |
7018 | */ | 7132 | */ |
7019 | static void sched_domain_node_span(int node, cpumask_t *span) | 7133 | static void sched_domain_node_span(int node, struct cpumask *span) |
7020 | { | 7134 | { |
7021 | nodemask_t used_nodes; | 7135 | nodemask_t used_nodes; |
7136 | /* FIXME: use cpumask_of_node() */ | ||
7022 | node_to_cpumask_ptr(nodemask, node); | 7137 | node_to_cpumask_ptr(nodemask, node); |
7023 | int i; | 7138 | int i; |
7024 | 7139 | ||
@@ -7040,18 +7155,33 @@ static void sched_domain_node_span(int node, cpumask_t *span) | |||
7040 | int sched_smt_power_savings = 0, sched_mc_power_savings = 0; | 7155 | int sched_smt_power_savings = 0, sched_mc_power_savings = 0; |
7041 | 7156 | ||
7042 | /* | 7157 | /* |
7158 | * The cpus mask in sched_group and sched_domain hangs off the end. | ||
7159 | * FIXME: use cpumask_var_t or dynamic percpu alloc to avoid wasting space | ||
7160 | * for nr_cpu_ids < CONFIG_NR_CPUS. | ||
7161 | */ | ||
7162 | struct static_sched_group { | ||
7163 | struct sched_group sg; | ||
7164 | DECLARE_BITMAP(cpus, CONFIG_NR_CPUS); | ||
7165 | }; | ||
7166 | |||
7167 | struct static_sched_domain { | ||
7168 | struct sched_domain sd; | ||
7169 | DECLARE_BITMAP(span, CONFIG_NR_CPUS); | ||
7170 | }; | ||
7171 | |||
7172 | /* | ||
7043 | * SMT sched-domains: | 7173 | * SMT sched-domains: |
7044 | */ | 7174 | */ |
7045 | #ifdef CONFIG_SCHED_SMT | 7175 | #ifdef CONFIG_SCHED_SMT |
7046 | static DEFINE_PER_CPU(struct sched_domain, cpu_domains); | 7176 | static DEFINE_PER_CPU(struct static_sched_domain, cpu_domains); |
7047 | static DEFINE_PER_CPU(struct sched_group, sched_group_cpus); | 7177 | static DEFINE_PER_CPU(struct static_sched_group, sched_group_cpus); |
7048 | 7178 | ||
7049 | static int | 7179 | static int |
7050 | cpu_to_cpu_group(int cpu, const cpumask_t *cpu_map, struct sched_group **sg, | 7180 | cpu_to_cpu_group(int cpu, const struct cpumask *cpu_map, |
7051 | cpumask_t *unused) | 7181 | struct sched_group **sg, struct cpumask *unused) |
7052 | { | 7182 | { |
7053 | if (sg) | 7183 | if (sg) |
7054 | *sg = &per_cpu(sched_group_cpus, cpu); | 7184 | *sg = &per_cpu(sched_group_cpus, cpu).sg; |
7055 | return cpu; | 7185 | return cpu; |
7056 | } | 7186 | } |
7057 | #endif /* CONFIG_SCHED_SMT */ | 7187 | #endif /* CONFIG_SCHED_SMT */ |
@@ -7060,56 +7190,55 @@ cpu_to_cpu_group(int cpu, const cpumask_t *cpu_map, struct sched_group **sg, | |||
7060 | * multi-core sched-domains: | 7190 | * multi-core sched-domains: |
7061 | */ | 7191 | */ |
7062 | #ifdef CONFIG_SCHED_MC | 7192 | #ifdef CONFIG_SCHED_MC |
7063 | static DEFINE_PER_CPU(struct sched_domain, core_domains); | 7193 | static DEFINE_PER_CPU(struct static_sched_domain, core_domains); |
7064 | static DEFINE_PER_CPU(struct sched_group, sched_group_core); | 7194 | static DEFINE_PER_CPU(struct static_sched_group, sched_group_core); |
7065 | #endif /* CONFIG_SCHED_MC */ | 7195 | #endif /* CONFIG_SCHED_MC */ |
7066 | 7196 | ||
7067 | #if defined(CONFIG_SCHED_MC) && defined(CONFIG_SCHED_SMT) | 7197 | #if defined(CONFIG_SCHED_MC) && defined(CONFIG_SCHED_SMT) |
7068 | static int | 7198 | static int |
7069 | cpu_to_core_group(int cpu, const cpumask_t *cpu_map, struct sched_group **sg, | 7199 | cpu_to_core_group(int cpu, const struct cpumask *cpu_map, |
7070 | cpumask_t *mask) | 7200 | struct sched_group **sg, struct cpumask *mask) |
7071 | { | 7201 | { |
7072 | int group; | 7202 | int group; |
7073 | 7203 | ||
7074 | *mask = per_cpu(cpu_sibling_map, cpu); | 7204 | cpumask_and(mask, &per_cpu(cpu_sibling_map, cpu), cpu_map); |
7075 | cpus_and(*mask, *mask, *cpu_map); | 7205 | group = cpumask_first(mask); |
7076 | group = first_cpu(*mask); | ||
7077 | if (sg) | 7206 | if (sg) |
7078 | *sg = &per_cpu(sched_group_core, group); | 7207 | *sg = &per_cpu(sched_group_core, group).sg; |
7079 | return group; | 7208 | return group; |
7080 | } | 7209 | } |
7081 | #elif defined(CONFIG_SCHED_MC) | 7210 | #elif defined(CONFIG_SCHED_MC) |
7082 | static int | 7211 | static int |
7083 | cpu_to_core_group(int cpu, const cpumask_t *cpu_map, struct sched_group **sg, | 7212 | cpu_to_core_group(int cpu, const struct cpumask *cpu_map, |
7084 | cpumask_t *unused) | 7213 | struct sched_group **sg, struct cpumask *unused) |
7085 | { | 7214 | { |
7086 | if (sg) | 7215 | if (sg) |
7087 | *sg = &per_cpu(sched_group_core, cpu); | 7216 | *sg = &per_cpu(sched_group_core, cpu).sg; |
7088 | return cpu; | 7217 | return cpu; |
7089 | } | 7218 | } |
7090 | #endif | 7219 | #endif |
7091 | 7220 | ||
7092 | static DEFINE_PER_CPU(struct sched_domain, phys_domains); | 7221 | static DEFINE_PER_CPU(struct static_sched_domain, phys_domains); |
7093 | static DEFINE_PER_CPU(struct sched_group, sched_group_phys); | 7222 | static DEFINE_PER_CPU(struct static_sched_group, sched_group_phys); |
7094 | 7223 | ||
7095 | static int | 7224 | static int |
7096 | cpu_to_phys_group(int cpu, const cpumask_t *cpu_map, struct sched_group **sg, | 7225 | cpu_to_phys_group(int cpu, const struct cpumask *cpu_map, |
7097 | cpumask_t *mask) | 7226 | struct sched_group **sg, struct cpumask *mask) |
7098 | { | 7227 | { |
7099 | int group; | 7228 | int group; |
7100 | #ifdef CONFIG_SCHED_MC | 7229 | #ifdef CONFIG_SCHED_MC |
7101 | *mask = *cpu_coregroup_mask(cpu); | 7230 | /* FIXME: Use cpu_coregroup_mask. */ |
7231 | *mask = cpu_coregroup_map(cpu); | ||
7102 | cpus_and(*mask, *mask, *cpu_map); | 7232 | cpus_and(*mask, *mask, *cpu_map); |
7103 | group = first_cpu(*mask); | 7233 | group = cpumask_first(mask); |
7104 | #elif defined(CONFIG_SCHED_SMT) | 7234 | #elif defined(CONFIG_SCHED_SMT) |
7105 | *mask = per_cpu(cpu_sibling_map, cpu); | 7235 | cpumask_and(mask, &per_cpu(cpu_sibling_map, cpu), cpu_map); |
7106 | cpus_and(*mask, *mask, *cpu_map); | 7236 | group = cpumask_first(mask); |
7107 | group = first_cpu(*mask); | ||
7108 | #else | 7237 | #else |
7109 | group = cpu; | 7238 | group = cpu; |
7110 | #endif | 7239 | #endif |
7111 | if (sg) | 7240 | if (sg) |
7112 | *sg = &per_cpu(sched_group_phys, group); | 7241 | *sg = &per_cpu(sched_group_phys, group).sg; |
7113 | return group; | 7242 | return group; |
7114 | } | 7243 | } |
7115 | 7244 | ||
@@ -7123,19 +7252,21 @@ static DEFINE_PER_CPU(struct sched_domain, node_domains); | |||
7123 | static struct sched_group ***sched_group_nodes_bycpu; | 7252 | static struct sched_group ***sched_group_nodes_bycpu; |
7124 | 7253 | ||
7125 | static DEFINE_PER_CPU(struct sched_domain, allnodes_domains); | 7254 | static DEFINE_PER_CPU(struct sched_domain, allnodes_domains); |
7126 | static DEFINE_PER_CPU(struct sched_group, sched_group_allnodes); | 7255 | static DEFINE_PER_CPU(struct static_sched_group, sched_group_allnodes); |
7127 | 7256 | ||
7128 | static int cpu_to_allnodes_group(int cpu, const cpumask_t *cpu_map, | 7257 | static int cpu_to_allnodes_group(int cpu, const struct cpumask *cpu_map, |
7129 | struct sched_group **sg, cpumask_t *nodemask) | 7258 | struct sched_group **sg, |
7259 | struct cpumask *nodemask) | ||
7130 | { | 7260 | { |
7131 | int group; | 7261 | int group; |
7262 | /* FIXME: use cpumask_of_node */ | ||
7263 | node_to_cpumask_ptr(pnodemask, cpu_to_node(cpu)); | ||
7132 | 7264 | ||
7133 | *nodemask = node_to_cpumask(cpu_to_node(cpu)); | 7265 | cpumask_and(nodemask, pnodemask, cpu_map); |
7134 | cpus_and(*nodemask, *nodemask, *cpu_map); | 7266 | group = cpumask_first(nodemask); |
7135 | group = first_cpu(*nodemask); | ||
7136 | 7267 | ||
7137 | if (sg) | 7268 | if (sg) |
7138 | *sg = &per_cpu(sched_group_allnodes, group); | 7269 | *sg = &per_cpu(sched_group_allnodes, group).sg; |
7139 | return group; | 7270 | return group; |
7140 | } | 7271 | } |
7141 | 7272 | ||
@@ -7147,11 +7278,11 @@ static void init_numa_sched_groups_power(struct sched_group *group_head) | |||
7147 | if (!sg) | 7278 | if (!sg) |
7148 | return; | 7279 | return; |
7149 | do { | 7280 | do { |
7150 | for_each_cpu_mask_nr(j, sg->cpumask) { | 7281 | for_each_cpu(j, sched_group_cpus(sg)) { |
7151 | struct sched_domain *sd; | 7282 | struct sched_domain *sd; |
7152 | 7283 | ||
7153 | sd = &per_cpu(phys_domains, j); | 7284 | sd = &per_cpu(phys_domains, j).sd; |
7154 | if (j != first_cpu(sd->groups->cpumask)) { | 7285 | if (j != cpumask_first(sched_group_cpus(sd->groups))) { |
7155 | /* | 7286 | /* |
7156 | * Only add "power" once for each | 7287 | * Only add "power" once for each |
7157 | * physical package. | 7288 | * physical package. |
@@ -7168,11 +7299,12 @@ static void init_numa_sched_groups_power(struct sched_group *group_head) | |||
7168 | 7299 | ||
7169 | #ifdef CONFIG_NUMA | 7300 | #ifdef CONFIG_NUMA |
7170 | /* Free memory allocated for various sched_group structures */ | 7301 | /* Free memory allocated for various sched_group structures */ |
7171 | static void free_sched_groups(const cpumask_t *cpu_map, cpumask_t *nodemask) | 7302 | static void free_sched_groups(const struct cpumask *cpu_map, |
7303 | struct cpumask *nodemask) | ||
7172 | { | 7304 | { |
7173 | int cpu, i; | 7305 | int cpu, i; |
7174 | 7306 | ||
7175 | for_each_cpu_mask_nr(cpu, *cpu_map) { | 7307 | for_each_cpu(cpu, cpu_map) { |
7176 | struct sched_group **sched_group_nodes | 7308 | struct sched_group **sched_group_nodes |
7177 | = sched_group_nodes_bycpu[cpu]; | 7309 | = sched_group_nodes_bycpu[cpu]; |
7178 | 7310 | ||
@@ -7181,10 +7313,11 @@ static void free_sched_groups(const cpumask_t *cpu_map, cpumask_t *nodemask) | |||
7181 | 7313 | ||
7182 | for (i = 0; i < nr_node_ids; i++) { | 7314 | for (i = 0; i < nr_node_ids; i++) { |
7183 | struct sched_group *oldsg, *sg = sched_group_nodes[i]; | 7315 | struct sched_group *oldsg, *sg = sched_group_nodes[i]; |
7316 | /* FIXME: Use cpumask_of_node */ | ||
7317 | node_to_cpumask_ptr(pnodemask, i); | ||
7184 | 7318 | ||
7185 | *nodemask = node_to_cpumask(i); | 7319 | cpus_and(*nodemask, *pnodemask, *cpu_map); |
7186 | cpus_and(*nodemask, *nodemask, *cpu_map); | 7320 | if (cpumask_empty(nodemask)) |
7187 | if (cpus_empty(*nodemask)) | ||
7188 | continue; | 7321 | continue; |
7189 | 7322 | ||
7190 | if (sg == NULL) | 7323 | if (sg == NULL) |
@@ -7202,7 +7335,8 @@ next_sg: | |||
7202 | } | 7335 | } |
7203 | } | 7336 | } |
7204 | #else /* !CONFIG_NUMA */ | 7337 | #else /* !CONFIG_NUMA */ |
7205 | static void free_sched_groups(const cpumask_t *cpu_map, cpumask_t *nodemask) | 7338 | static void free_sched_groups(const struct cpumask *cpu_map, |
7339 | struct cpumask *nodemask) | ||
7206 | { | 7340 | { |
7207 | } | 7341 | } |
7208 | #endif /* CONFIG_NUMA */ | 7342 | #endif /* CONFIG_NUMA */ |
@@ -7228,7 +7362,7 @@ static void init_sched_groups_power(int cpu, struct sched_domain *sd) | |||
7228 | 7362 | ||
7229 | WARN_ON(!sd || !sd->groups); | 7363 | WARN_ON(!sd || !sd->groups); |
7230 | 7364 | ||
7231 | if (cpu != first_cpu(sd->groups->cpumask)) | 7365 | if (cpu != cpumask_first(sched_group_cpus(sd->groups))) |
7232 | return; | 7366 | return; |
7233 | 7367 | ||
7234 | child = sd->child; | 7368 | child = sd->child; |
@@ -7293,48 +7427,6 @@ SD_INIT_FUNC(CPU) | |||
7293 | SD_INIT_FUNC(MC) | 7427 | SD_INIT_FUNC(MC) |
7294 | #endif | 7428 | #endif |
7295 | 7429 | ||
7296 | /* | ||
7297 | * To minimize stack usage kmalloc room for cpumasks and share the | ||
7298 | * space as the usage in build_sched_domains() dictates. Used only | ||
7299 | * if the amount of space is significant. | ||
7300 | */ | ||
7301 | struct allmasks { | ||
7302 | cpumask_t tmpmask; /* make this one first */ | ||
7303 | union { | ||
7304 | cpumask_t nodemask; | ||
7305 | cpumask_t this_sibling_map; | ||
7306 | cpumask_t this_core_map; | ||
7307 | }; | ||
7308 | cpumask_t send_covered; | ||
7309 | |||
7310 | #ifdef CONFIG_NUMA | ||
7311 | cpumask_t domainspan; | ||
7312 | cpumask_t covered; | ||
7313 | cpumask_t notcovered; | ||
7314 | #endif | ||
7315 | }; | ||
7316 | |||
7317 | #if NR_CPUS > 128 | ||
7318 | #define SCHED_CPUMASK_DECLARE(v) struct allmasks *v | ||
7319 | static inline void sched_cpumask_alloc(struct allmasks **masks) | ||
7320 | { | ||
7321 | *masks = kmalloc(sizeof(**masks), GFP_KERNEL); | ||
7322 | } | ||
7323 | static inline void sched_cpumask_free(struct allmasks *masks) | ||
7324 | { | ||
7325 | kfree(masks); | ||
7326 | } | ||
7327 | #else | ||
7328 | #define SCHED_CPUMASK_DECLARE(v) struct allmasks _v, *v = &_v | ||
7329 | static inline void sched_cpumask_alloc(struct allmasks **masks) | ||
7330 | { } | ||
7331 | static inline void sched_cpumask_free(struct allmasks *masks) | ||
7332 | { } | ||
7333 | #endif | ||
7334 | |||
7335 | #define SCHED_CPUMASK_VAR(v, a) cpumask_t *v = (cpumask_t *) \ | ||
7336 | ((unsigned long)(a) + offsetof(struct allmasks, v)) | ||
7337 | |||
7338 | static int default_relax_domain_level = -1; | 7430 | static int default_relax_domain_level = -1; |
7339 | 7431 | ||
7340 | static int __init setup_relax_domain_level(char *str) | 7432 | static int __init setup_relax_domain_level(char *str) |
@@ -7374,17 +7466,38 @@ static void set_domain_attribute(struct sched_domain *sd, | |||
7374 | * Build sched domains for a given set of cpus and attach the sched domains | 7466 | * Build sched domains for a given set of cpus and attach the sched domains |
7375 | * to the individual cpus | 7467 | * to the individual cpus |
7376 | */ | 7468 | */ |
7377 | static int __build_sched_domains(const cpumask_t *cpu_map, | 7469 | static int __build_sched_domains(const struct cpumask *cpu_map, |
7378 | struct sched_domain_attr *attr) | 7470 | struct sched_domain_attr *attr) |
7379 | { | 7471 | { |
7380 | int i; | 7472 | int i, err = -ENOMEM; |
7381 | struct root_domain *rd; | 7473 | struct root_domain *rd; |
7382 | SCHED_CPUMASK_DECLARE(allmasks); | 7474 | cpumask_var_t nodemask, this_sibling_map, this_core_map, send_covered, |
7383 | cpumask_t *tmpmask; | 7475 | tmpmask; |
7384 | #ifdef CONFIG_NUMA | 7476 | #ifdef CONFIG_NUMA |
7477 | cpumask_var_t domainspan, covered, notcovered; | ||
7385 | struct sched_group **sched_group_nodes = NULL; | 7478 | struct sched_group **sched_group_nodes = NULL; |
7386 | int sd_allnodes = 0; | 7479 | int sd_allnodes = 0; |
7387 | 7480 | ||
7481 | if (!alloc_cpumask_var(&domainspan, GFP_KERNEL)) | ||
7482 | goto out; | ||
7483 | if (!alloc_cpumask_var(&covered, GFP_KERNEL)) | ||
7484 | goto free_domainspan; | ||
7485 | if (!alloc_cpumask_var(¬covered, GFP_KERNEL)) | ||
7486 | goto free_covered; | ||
7487 | #endif | ||
7488 | |||
7489 | if (!alloc_cpumask_var(&nodemask, GFP_KERNEL)) | ||
7490 | goto free_notcovered; | ||
7491 | if (!alloc_cpumask_var(&this_sibling_map, GFP_KERNEL)) | ||
7492 | goto free_nodemask; | ||
7493 | if (!alloc_cpumask_var(&this_core_map, GFP_KERNEL)) | ||
7494 | goto free_this_sibling_map; | ||
7495 | if (!alloc_cpumask_var(&send_covered, GFP_KERNEL)) | ||
7496 | goto free_this_core_map; | ||
7497 | if (!alloc_cpumask_var(&tmpmask, GFP_KERNEL)) | ||
7498 | goto free_send_covered; | ||
7499 | |||
7500 | #ifdef CONFIG_NUMA | ||
7388 | /* | 7501 | /* |
7389 | * Allocate the per-node list of sched groups | 7502 | * Allocate the per-node list of sched groups |
7390 | */ | 7503 | */ |
@@ -7392,54 +7505,37 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7392 | GFP_KERNEL); | 7505 | GFP_KERNEL); |
7393 | if (!sched_group_nodes) { | 7506 | if (!sched_group_nodes) { |
7394 | printk(KERN_WARNING "Can not alloc sched group node list\n"); | 7507 | printk(KERN_WARNING "Can not alloc sched group node list\n"); |
7395 | return -ENOMEM; | 7508 | goto free_tmpmask; |
7396 | } | 7509 | } |
7397 | #endif | 7510 | #endif |
7398 | 7511 | ||
7399 | rd = alloc_rootdomain(); | 7512 | rd = alloc_rootdomain(); |
7400 | if (!rd) { | 7513 | if (!rd) { |
7401 | printk(KERN_WARNING "Cannot alloc root domain\n"); | 7514 | printk(KERN_WARNING "Cannot alloc root domain\n"); |
7402 | #ifdef CONFIG_NUMA | 7515 | goto free_sched_groups; |
7403 | kfree(sched_group_nodes); | ||
7404 | #endif | ||
7405 | return -ENOMEM; | ||
7406 | } | 7516 | } |
7407 | 7517 | ||
7408 | /* get space for all scratch cpumask variables */ | ||
7409 | sched_cpumask_alloc(&allmasks); | ||
7410 | if (!allmasks) { | ||
7411 | printk(KERN_WARNING "Cannot alloc cpumask array\n"); | ||
7412 | kfree(rd); | ||
7413 | #ifdef CONFIG_NUMA | 7518 | #ifdef CONFIG_NUMA |
7414 | kfree(sched_group_nodes); | 7519 | sched_group_nodes_bycpu[cpumask_first(cpu_map)] = sched_group_nodes; |
7415 | #endif | ||
7416 | return -ENOMEM; | ||
7417 | } | ||
7418 | |||
7419 | tmpmask = (cpumask_t *)allmasks; | ||
7420 | |||
7421 | |||
7422 | #ifdef CONFIG_NUMA | ||
7423 | sched_group_nodes_bycpu[first_cpu(*cpu_map)] = sched_group_nodes; | ||
7424 | #endif | 7520 | #endif |
7425 | 7521 | ||
7426 | /* | 7522 | /* |
7427 | * Set up domains for cpus specified by the cpu_map. | 7523 | * Set up domains for cpus specified by the cpu_map. |
7428 | */ | 7524 | */ |
7429 | for_each_cpu_mask_nr(i, *cpu_map) { | 7525 | for_each_cpu(i, cpu_map) { |
7430 | struct sched_domain *sd = NULL, *p; | 7526 | struct sched_domain *sd = NULL, *p; |
7431 | SCHED_CPUMASK_VAR(nodemask, allmasks); | ||
7432 | 7527 | ||
7528 | /* FIXME: use cpumask_of_node */ | ||
7433 | *nodemask = node_to_cpumask(cpu_to_node(i)); | 7529 | *nodemask = node_to_cpumask(cpu_to_node(i)); |
7434 | cpus_and(*nodemask, *nodemask, *cpu_map); | 7530 | cpus_and(*nodemask, *nodemask, *cpu_map); |
7435 | 7531 | ||
7436 | #ifdef CONFIG_NUMA | 7532 | #ifdef CONFIG_NUMA |
7437 | if (cpus_weight(*cpu_map) > | 7533 | if (cpumask_weight(cpu_map) > |
7438 | SD_NODES_PER_DOMAIN*cpus_weight(*nodemask)) { | 7534 | SD_NODES_PER_DOMAIN*cpumask_weight(nodemask)) { |
7439 | sd = &per_cpu(allnodes_domains, i); | 7535 | sd = &per_cpu(allnodes_domains, i); |
7440 | SD_INIT(sd, ALLNODES); | 7536 | SD_INIT(sd, ALLNODES); |
7441 | set_domain_attribute(sd, attr); | 7537 | set_domain_attribute(sd, attr); |
7442 | sd->span = *cpu_map; | 7538 | cpumask_copy(sched_domain_span(sd), cpu_map); |
7443 | cpu_to_allnodes_group(i, cpu_map, &sd->groups, tmpmask); | 7539 | cpu_to_allnodes_group(i, cpu_map, &sd->groups, tmpmask); |
7444 | p = sd; | 7540 | p = sd; |
7445 | sd_allnodes = 1; | 7541 | sd_allnodes = 1; |
@@ -7449,18 +7545,19 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7449 | sd = &per_cpu(node_domains, i); | 7545 | sd = &per_cpu(node_domains, i); |
7450 | SD_INIT(sd, NODE); | 7546 | SD_INIT(sd, NODE); |
7451 | set_domain_attribute(sd, attr); | 7547 | set_domain_attribute(sd, attr); |
7452 | sched_domain_node_span(cpu_to_node(i), &sd->span); | 7548 | sched_domain_node_span(cpu_to_node(i), sched_domain_span(sd)); |
7453 | sd->parent = p; | 7549 | sd->parent = p; |
7454 | if (p) | 7550 | if (p) |
7455 | p->child = sd; | 7551 | p->child = sd; |
7456 | cpus_and(sd->span, sd->span, *cpu_map); | 7552 | cpumask_and(sched_domain_span(sd), |
7553 | sched_domain_span(sd), cpu_map); | ||
7457 | #endif | 7554 | #endif |
7458 | 7555 | ||
7459 | p = sd; | 7556 | p = sd; |
7460 | sd = &per_cpu(phys_domains, i); | 7557 | sd = &per_cpu(phys_domains, i).sd; |
7461 | SD_INIT(sd, CPU); | 7558 | SD_INIT(sd, CPU); |
7462 | set_domain_attribute(sd, attr); | 7559 | set_domain_attribute(sd, attr); |
7463 | sd->span = *nodemask; | 7560 | cpumask_copy(sched_domain_span(sd), nodemask); |
7464 | sd->parent = p; | 7561 | sd->parent = p; |
7465 | if (p) | 7562 | if (p) |
7466 | p->child = sd; | 7563 | p->child = sd; |
@@ -7468,11 +7565,12 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7468 | 7565 | ||
7469 | #ifdef CONFIG_SCHED_MC | 7566 | #ifdef CONFIG_SCHED_MC |
7470 | p = sd; | 7567 | p = sd; |
7471 | sd = &per_cpu(core_domains, i); | 7568 | sd = &per_cpu(core_domains, i).sd; |
7472 | SD_INIT(sd, MC); | 7569 | SD_INIT(sd, MC); |
7473 | set_domain_attribute(sd, attr); | 7570 | set_domain_attribute(sd, attr); |
7474 | sd->span = *cpu_coregroup_mask(i); | 7571 | *sched_domain_span(sd) = cpu_coregroup_map(i); |
7475 | cpus_and(sd->span, sd->span, *cpu_map); | 7572 | cpumask_and(sched_domain_span(sd), |
7573 | sched_domain_span(sd), cpu_map); | ||
7476 | sd->parent = p; | 7574 | sd->parent = p; |
7477 | p->child = sd; | 7575 | p->child = sd; |
7478 | cpu_to_core_group(i, cpu_map, &sd->groups, tmpmask); | 7576 | cpu_to_core_group(i, cpu_map, &sd->groups, tmpmask); |
@@ -7480,11 +7578,11 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7480 | 7578 | ||
7481 | #ifdef CONFIG_SCHED_SMT | 7579 | #ifdef CONFIG_SCHED_SMT |
7482 | p = sd; | 7580 | p = sd; |
7483 | sd = &per_cpu(cpu_domains, i); | 7581 | sd = &per_cpu(cpu_domains, i).sd; |
7484 | SD_INIT(sd, SIBLING); | 7582 | SD_INIT(sd, SIBLING); |
7485 | set_domain_attribute(sd, attr); | 7583 | set_domain_attribute(sd, attr); |
7486 | sd->span = per_cpu(cpu_sibling_map, i); | 7584 | cpumask_and(sched_domain_span(sd), |
7487 | cpus_and(sd->span, sd->span, *cpu_map); | 7585 | &per_cpu(cpu_sibling_map, i), cpu_map); |
7488 | sd->parent = p; | 7586 | sd->parent = p; |
7489 | p->child = sd; | 7587 | p->child = sd; |
7490 | cpu_to_cpu_group(i, cpu_map, &sd->groups, tmpmask); | 7588 | cpu_to_cpu_group(i, cpu_map, &sd->groups, tmpmask); |
@@ -7493,13 +7591,10 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7493 | 7591 | ||
7494 | #ifdef CONFIG_SCHED_SMT | 7592 | #ifdef CONFIG_SCHED_SMT |
7495 | /* Set up CPU (sibling) groups */ | 7593 | /* Set up CPU (sibling) groups */ |
7496 | for_each_cpu_mask_nr(i, *cpu_map) { | 7594 | for_each_cpu(i, cpu_map) { |
7497 | SCHED_CPUMASK_VAR(this_sibling_map, allmasks); | 7595 | cpumask_and(this_sibling_map, |
7498 | SCHED_CPUMASK_VAR(send_covered, allmasks); | 7596 | &per_cpu(cpu_sibling_map, i), cpu_map); |
7499 | 7597 | if (i != cpumask_first(this_sibling_map)) | |
7500 | *this_sibling_map = per_cpu(cpu_sibling_map, i); | ||
7501 | cpus_and(*this_sibling_map, *this_sibling_map, *cpu_map); | ||
7502 | if (i != first_cpu(*this_sibling_map)) | ||
7503 | continue; | 7598 | continue; |
7504 | 7599 | ||
7505 | init_sched_build_groups(this_sibling_map, cpu_map, | 7600 | init_sched_build_groups(this_sibling_map, cpu_map, |
@@ -7510,13 +7605,11 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7510 | 7605 | ||
7511 | #ifdef CONFIG_SCHED_MC | 7606 | #ifdef CONFIG_SCHED_MC |
7512 | /* Set up multi-core groups */ | 7607 | /* Set up multi-core groups */ |
7513 | for_each_cpu_mask_nr(i, *cpu_map) { | 7608 | for_each_cpu(i, cpu_map) { |
7514 | SCHED_CPUMASK_VAR(this_core_map, allmasks); | 7609 | /* FIXME: Use cpu_coregroup_mask */ |
7515 | SCHED_CPUMASK_VAR(send_covered, allmasks); | 7610 | *this_core_map = cpu_coregroup_map(i); |
7516 | |||
7517 | *this_core_map = *cpu_coregroup_mask(i); | ||
7518 | cpus_and(*this_core_map, *this_core_map, *cpu_map); | 7611 | cpus_and(*this_core_map, *this_core_map, *cpu_map); |
7519 | if (i != first_cpu(*this_core_map)) | 7612 | if (i != cpumask_first(this_core_map)) |
7520 | continue; | 7613 | continue; |
7521 | 7614 | ||
7522 | init_sched_build_groups(this_core_map, cpu_map, | 7615 | init_sched_build_groups(this_core_map, cpu_map, |
@@ -7527,12 +7620,10 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7527 | 7620 | ||
7528 | /* Set up physical groups */ | 7621 | /* Set up physical groups */ |
7529 | for (i = 0; i < nr_node_ids; i++) { | 7622 | for (i = 0; i < nr_node_ids; i++) { |
7530 | SCHED_CPUMASK_VAR(nodemask, allmasks); | 7623 | /* FIXME: Use cpumask_of_node */ |
7531 | SCHED_CPUMASK_VAR(send_covered, allmasks); | ||
7532 | |||
7533 | *nodemask = node_to_cpumask(i); | 7624 | *nodemask = node_to_cpumask(i); |
7534 | cpus_and(*nodemask, *nodemask, *cpu_map); | 7625 | cpus_and(*nodemask, *nodemask, *cpu_map); |
7535 | if (cpus_empty(*nodemask)) | 7626 | if (cpumask_empty(nodemask)) |
7536 | continue; | 7627 | continue; |
7537 | 7628 | ||
7538 | init_sched_build_groups(nodemask, cpu_map, | 7629 | init_sched_build_groups(nodemask, cpu_map, |
@@ -7543,8 +7634,6 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7543 | #ifdef CONFIG_NUMA | 7634 | #ifdef CONFIG_NUMA |
7544 | /* Set up node groups */ | 7635 | /* Set up node groups */ |
7545 | if (sd_allnodes) { | 7636 | if (sd_allnodes) { |
7546 | SCHED_CPUMASK_VAR(send_covered, allmasks); | ||
7547 | |||
7548 | init_sched_build_groups(cpu_map, cpu_map, | 7637 | init_sched_build_groups(cpu_map, cpu_map, |
7549 | &cpu_to_allnodes_group, | 7638 | &cpu_to_allnodes_group, |
7550 | send_covered, tmpmask); | 7639 | send_covered, tmpmask); |
@@ -7553,58 +7642,58 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7553 | for (i = 0; i < nr_node_ids; i++) { | 7642 | for (i = 0; i < nr_node_ids; i++) { |
7554 | /* Set up node groups */ | 7643 | /* Set up node groups */ |
7555 | struct sched_group *sg, *prev; | 7644 | struct sched_group *sg, *prev; |
7556 | SCHED_CPUMASK_VAR(nodemask, allmasks); | ||
7557 | SCHED_CPUMASK_VAR(domainspan, allmasks); | ||
7558 | SCHED_CPUMASK_VAR(covered, allmasks); | ||
7559 | int j; | 7645 | int j; |
7560 | 7646 | ||
7647 | /* FIXME: Use cpumask_of_node */ | ||
7561 | *nodemask = node_to_cpumask(i); | 7648 | *nodemask = node_to_cpumask(i); |
7562 | cpus_clear(*covered); | 7649 | cpumask_clear(covered); |
7563 | 7650 | ||
7564 | cpus_and(*nodemask, *nodemask, *cpu_map); | 7651 | cpus_and(*nodemask, *nodemask, *cpu_map); |
7565 | if (cpus_empty(*nodemask)) { | 7652 | if (cpumask_empty(nodemask)) { |
7566 | sched_group_nodes[i] = NULL; | 7653 | sched_group_nodes[i] = NULL; |
7567 | continue; | 7654 | continue; |
7568 | } | 7655 | } |
7569 | 7656 | ||
7570 | sched_domain_node_span(i, domainspan); | 7657 | sched_domain_node_span(i, domainspan); |
7571 | cpus_and(*domainspan, *domainspan, *cpu_map); | 7658 | cpumask_and(domainspan, domainspan, cpu_map); |
7572 | 7659 | ||
7573 | sg = kmalloc_node(sizeof(struct sched_group), GFP_KERNEL, i); | 7660 | sg = kmalloc_node(sizeof(struct sched_group) + cpumask_size(), |
7661 | GFP_KERNEL, i); | ||
7574 | if (!sg) { | 7662 | if (!sg) { |
7575 | printk(KERN_WARNING "Can not alloc domain group for " | 7663 | printk(KERN_WARNING "Can not alloc domain group for " |
7576 | "node %d\n", i); | 7664 | "node %d\n", i); |
7577 | goto error; | 7665 | goto error; |
7578 | } | 7666 | } |
7579 | sched_group_nodes[i] = sg; | 7667 | sched_group_nodes[i] = sg; |
7580 | for_each_cpu_mask_nr(j, *nodemask) { | 7668 | for_each_cpu(j, nodemask) { |
7581 | struct sched_domain *sd; | 7669 | struct sched_domain *sd; |
7582 | 7670 | ||
7583 | sd = &per_cpu(node_domains, j); | 7671 | sd = &per_cpu(node_domains, j); |
7584 | sd->groups = sg; | 7672 | sd->groups = sg; |
7585 | } | 7673 | } |
7586 | sg->__cpu_power = 0; | 7674 | sg->__cpu_power = 0; |
7587 | sg->cpumask = *nodemask; | 7675 | cpumask_copy(sched_group_cpus(sg), nodemask); |
7588 | sg->next = sg; | 7676 | sg->next = sg; |
7589 | cpus_or(*covered, *covered, *nodemask); | 7677 | cpumask_or(covered, covered, nodemask); |
7590 | prev = sg; | 7678 | prev = sg; |
7591 | 7679 | ||
7592 | for (j = 0; j < nr_node_ids; j++) { | 7680 | for (j = 0; j < nr_node_ids; j++) { |
7593 | SCHED_CPUMASK_VAR(notcovered, allmasks); | ||
7594 | int n = (i + j) % nr_node_ids; | 7681 | int n = (i + j) % nr_node_ids; |
7682 | /* FIXME: Use cpumask_of_node */ | ||
7595 | node_to_cpumask_ptr(pnodemask, n); | 7683 | node_to_cpumask_ptr(pnodemask, n); |
7596 | 7684 | ||
7597 | cpus_complement(*notcovered, *covered); | 7685 | cpumask_complement(notcovered, covered); |
7598 | cpus_and(*tmpmask, *notcovered, *cpu_map); | 7686 | cpumask_and(tmpmask, notcovered, cpu_map); |
7599 | cpus_and(*tmpmask, *tmpmask, *domainspan); | 7687 | cpumask_and(tmpmask, tmpmask, domainspan); |
7600 | if (cpus_empty(*tmpmask)) | 7688 | if (cpumask_empty(tmpmask)) |
7601 | break; | 7689 | break; |
7602 | 7690 | ||
7603 | cpus_and(*tmpmask, *tmpmask, *pnodemask); | 7691 | cpumask_and(tmpmask, tmpmask, pnodemask); |
7604 | if (cpus_empty(*tmpmask)) | 7692 | if (cpumask_empty(tmpmask)) |
7605 | continue; | 7693 | continue; |
7606 | 7694 | ||
7607 | sg = kmalloc_node(sizeof(struct sched_group), | 7695 | sg = kmalloc_node(sizeof(struct sched_group) + |
7696 | cpumask_size(), | ||
7608 | GFP_KERNEL, i); | 7697 | GFP_KERNEL, i); |
7609 | if (!sg) { | 7698 | if (!sg) { |
7610 | printk(KERN_WARNING | 7699 | printk(KERN_WARNING |
@@ -7612,9 +7701,9 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7612 | goto error; | 7701 | goto error; |
7613 | } | 7702 | } |
7614 | sg->__cpu_power = 0; | 7703 | sg->__cpu_power = 0; |
7615 | sg->cpumask = *tmpmask; | 7704 | cpumask_copy(sched_group_cpus(sg), tmpmask); |
7616 | sg->next = prev->next; | 7705 | sg->next = prev->next; |
7617 | cpus_or(*covered, *covered, *tmpmask); | 7706 | cpumask_or(covered, covered, tmpmask); |
7618 | prev->next = sg; | 7707 | prev->next = sg; |
7619 | prev = sg; | 7708 | prev = sg; |
7620 | } | 7709 | } |
@@ -7623,22 +7712,22 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7623 | 7712 | ||
7624 | /* Calculate CPU power for physical packages and nodes */ | 7713 | /* Calculate CPU power for physical packages and nodes */ |
7625 | #ifdef CONFIG_SCHED_SMT | 7714 | #ifdef CONFIG_SCHED_SMT |
7626 | for_each_cpu_mask_nr(i, *cpu_map) { | 7715 | for_each_cpu(i, cpu_map) { |
7627 | struct sched_domain *sd = &per_cpu(cpu_domains, i); | 7716 | struct sched_domain *sd = &per_cpu(cpu_domains, i).sd; |
7628 | 7717 | ||
7629 | init_sched_groups_power(i, sd); | 7718 | init_sched_groups_power(i, sd); |
7630 | } | 7719 | } |
7631 | #endif | 7720 | #endif |
7632 | #ifdef CONFIG_SCHED_MC | 7721 | #ifdef CONFIG_SCHED_MC |
7633 | for_each_cpu_mask_nr(i, *cpu_map) { | 7722 | for_each_cpu(i, cpu_map) { |
7634 | struct sched_domain *sd = &per_cpu(core_domains, i); | 7723 | struct sched_domain *sd = &per_cpu(core_domains, i).sd; |
7635 | 7724 | ||
7636 | init_sched_groups_power(i, sd); | 7725 | init_sched_groups_power(i, sd); |
7637 | } | 7726 | } |
7638 | #endif | 7727 | #endif |
7639 | 7728 | ||
7640 | for_each_cpu_mask_nr(i, *cpu_map) { | 7729 | for_each_cpu(i, cpu_map) { |
7641 | struct sched_domain *sd = &per_cpu(phys_domains, i); | 7730 | struct sched_domain *sd = &per_cpu(phys_domains, i).sd; |
7642 | 7731 | ||
7643 | init_sched_groups_power(i, sd); | 7732 | init_sched_groups_power(i, sd); |
7644 | } | 7733 | } |
@@ -7650,53 +7739,78 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7650 | if (sd_allnodes) { | 7739 | if (sd_allnodes) { |
7651 | struct sched_group *sg; | 7740 | struct sched_group *sg; |
7652 | 7741 | ||
7653 | cpu_to_allnodes_group(first_cpu(*cpu_map), cpu_map, &sg, | 7742 | cpu_to_allnodes_group(cpumask_first(cpu_map), cpu_map, &sg, |
7654 | tmpmask); | 7743 | tmpmask); |
7655 | init_numa_sched_groups_power(sg); | 7744 | init_numa_sched_groups_power(sg); |
7656 | } | 7745 | } |
7657 | #endif | 7746 | #endif |
7658 | 7747 | ||
7659 | /* Attach the domains */ | 7748 | /* Attach the domains */ |
7660 | for_each_cpu_mask_nr(i, *cpu_map) { | 7749 | for_each_cpu(i, cpu_map) { |
7661 | struct sched_domain *sd; | 7750 | struct sched_domain *sd; |
7662 | #ifdef CONFIG_SCHED_SMT | 7751 | #ifdef CONFIG_SCHED_SMT |
7663 | sd = &per_cpu(cpu_domains, i); | 7752 | sd = &per_cpu(cpu_domains, i).sd; |
7664 | #elif defined(CONFIG_SCHED_MC) | 7753 | #elif defined(CONFIG_SCHED_MC) |
7665 | sd = &per_cpu(core_domains, i); | 7754 | sd = &per_cpu(core_domains, i).sd; |
7666 | #else | 7755 | #else |
7667 | sd = &per_cpu(phys_domains, i); | 7756 | sd = &per_cpu(phys_domains, i).sd; |
7668 | #endif | 7757 | #endif |
7669 | cpu_attach_domain(sd, rd, i); | 7758 | cpu_attach_domain(sd, rd, i); |
7670 | } | 7759 | } |
7671 | 7760 | ||
7672 | sched_cpumask_free(allmasks); | 7761 | err = 0; |
7673 | return 0; | 7762 | |
7763 | free_tmpmask: | ||
7764 | free_cpumask_var(tmpmask); | ||
7765 | free_send_covered: | ||
7766 | free_cpumask_var(send_covered); | ||
7767 | free_this_core_map: | ||
7768 | free_cpumask_var(this_core_map); | ||
7769 | free_this_sibling_map: | ||
7770 | free_cpumask_var(this_sibling_map); | ||
7771 | free_nodemask: | ||
7772 | free_cpumask_var(nodemask); | ||
7773 | free_notcovered: | ||
7774 | #ifdef CONFIG_NUMA | ||
7775 | free_cpumask_var(notcovered); | ||
7776 | free_covered: | ||
7777 | free_cpumask_var(covered); | ||
7778 | free_domainspan: | ||
7779 | free_cpumask_var(domainspan); | ||
7780 | out: | ||
7781 | #endif | ||
7782 | return err; | ||
7783 | |||
7784 | free_sched_groups: | ||
7785 | #ifdef CONFIG_NUMA | ||
7786 | kfree(sched_group_nodes); | ||
7787 | #endif | ||
7788 | goto free_tmpmask; | ||
7674 | 7789 | ||
7675 | #ifdef CONFIG_NUMA | 7790 | #ifdef CONFIG_NUMA |
7676 | error: | 7791 | error: |
7677 | free_sched_groups(cpu_map, tmpmask); | 7792 | free_sched_groups(cpu_map, tmpmask); |
7678 | sched_cpumask_free(allmasks); | 7793 | free_rootdomain(rd); |
7679 | kfree(rd); | 7794 | goto free_tmpmask; |
7680 | return -ENOMEM; | ||
7681 | #endif | 7795 | #endif |
7682 | } | 7796 | } |
7683 | 7797 | ||
7684 | static int build_sched_domains(const cpumask_t *cpu_map) | 7798 | static int build_sched_domains(const struct cpumask *cpu_map) |
7685 | { | 7799 | { |
7686 | return __build_sched_domains(cpu_map, NULL); | 7800 | return __build_sched_domains(cpu_map, NULL); |
7687 | } | 7801 | } |
7688 | 7802 | ||
7689 | static cpumask_t *doms_cur; /* current sched domains */ | 7803 | static struct cpumask *doms_cur; /* current sched domains */ |
7690 | static int ndoms_cur; /* number of sched domains in 'doms_cur' */ | 7804 | static int ndoms_cur; /* number of sched domains in 'doms_cur' */ |
7691 | static struct sched_domain_attr *dattr_cur; | 7805 | static struct sched_domain_attr *dattr_cur; |
7692 | /* attribues of custom domains in 'doms_cur' */ | 7806 | /* attribues of custom domains in 'doms_cur' */ |
7693 | 7807 | ||
7694 | /* | 7808 | /* |
7695 | * Special case: If a kmalloc of a doms_cur partition (array of | 7809 | * Special case: If a kmalloc of a doms_cur partition (array of |
7696 | * cpumask_t) fails, then fallback to a single sched domain, | 7810 | * cpumask) fails, then fallback to a single sched domain, |
7697 | * as determined by the single cpumask_t fallback_doms. | 7811 | * as determined by the single cpumask fallback_doms. |
7698 | */ | 7812 | */ |
7699 | static cpumask_t fallback_doms; | 7813 | static cpumask_var_t fallback_doms; |
7700 | 7814 | ||
7701 | /* | 7815 | /* |
7702 | * arch_update_cpu_topology lets virtualized architectures update the | 7816 | * arch_update_cpu_topology lets virtualized architectures update the |
@@ -7713,16 +7827,16 @@ int __attribute__((weak)) arch_update_cpu_topology(void) | |||
7713 | * For now this just excludes isolated cpus, but could be used to | 7827 | * For now this just excludes isolated cpus, but could be used to |
7714 | * exclude other special cases in the future. | 7828 | * exclude other special cases in the future. |
7715 | */ | 7829 | */ |
7716 | static int arch_init_sched_domains(const cpumask_t *cpu_map) | 7830 | static int arch_init_sched_domains(const struct cpumask *cpu_map) |
7717 | { | 7831 | { |
7718 | int err; | 7832 | int err; |
7719 | 7833 | ||
7720 | arch_update_cpu_topology(); | 7834 | arch_update_cpu_topology(); |
7721 | ndoms_cur = 1; | 7835 | ndoms_cur = 1; |
7722 | doms_cur = kmalloc(sizeof(cpumask_t), GFP_KERNEL); | 7836 | doms_cur = kmalloc(cpumask_size(), GFP_KERNEL); |
7723 | if (!doms_cur) | 7837 | if (!doms_cur) |
7724 | doms_cur = &fallback_doms; | 7838 | doms_cur = fallback_doms; |
7725 | cpus_andnot(*doms_cur, *cpu_map, cpu_isolated_map); | 7839 | cpumask_andnot(doms_cur, cpu_map, cpu_isolated_map); |
7726 | dattr_cur = NULL; | 7840 | dattr_cur = NULL; |
7727 | err = build_sched_domains(doms_cur); | 7841 | err = build_sched_domains(doms_cur); |
7728 | register_sched_domain_sysctl(); | 7842 | register_sched_domain_sysctl(); |
@@ -7730,8 +7844,8 @@ static int arch_init_sched_domains(const cpumask_t *cpu_map) | |||
7730 | return err; | 7844 | return err; |
7731 | } | 7845 | } |
7732 | 7846 | ||
7733 | static void arch_destroy_sched_domains(const cpumask_t *cpu_map, | 7847 | static void arch_destroy_sched_domains(const struct cpumask *cpu_map, |
7734 | cpumask_t *tmpmask) | 7848 | struct cpumask *tmpmask) |
7735 | { | 7849 | { |
7736 | free_sched_groups(cpu_map, tmpmask); | 7850 | free_sched_groups(cpu_map, tmpmask); |
7737 | } | 7851 | } |
@@ -7740,15 +7854,16 @@ static void arch_destroy_sched_domains(const cpumask_t *cpu_map, | |||
7740 | * Detach sched domains from a group of cpus specified in cpu_map | 7854 | * Detach sched domains from a group of cpus specified in cpu_map |
7741 | * These cpus will now be attached to the NULL domain | 7855 | * These cpus will now be attached to the NULL domain |
7742 | */ | 7856 | */ |
7743 | static void detach_destroy_domains(const cpumask_t *cpu_map) | 7857 | static void detach_destroy_domains(const struct cpumask *cpu_map) |
7744 | { | 7858 | { |
7745 | cpumask_t tmpmask; | 7859 | /* Save because hotplug lock held. */ |
7860 | static DECLARE_BITMAP(tmpmask, CONFIG_NR_CPUS); | ||
7746 | int i; | 7861 | int i; |
7747 | 7862 | ||
7748 | for_each_cpu_mask_nr(i, *cpu_map) | 7863 | for_each_cpu(i, cpu_map) |
7749 | cpu_attach_domain(NULL, &def_root_domain, i); | 7864 | cpu_attach_domain(NULL, &def_root_domain, i); |
7750 | synchronize_sched(); | 7865 | synchronize_sched(); |
7751 | arch_destroy_sched_domains(cpu_map, &tmpmask); | 7866 | arch_destroy_sched_domains(cpu_map, to_cpumask(tmpmask)); |
7752 | } | 7867 | } |
7753 | 7868 | ||
7754 | /* handle null as "default" */ | 7869 | /* handle null as "default" */ |
@@ -7773,7 +7888,7 @@ static int dattrs_equal(struct sched_domain_attr *cur, int idx_cur, | |||
7773 | * doms_new[] to the current sched domain partitioning, doms_cur[]. | 7888 | * doms_new[] to the current sched domain partitioning, doms_cur[]. |
7774 | * It destroys each deleted domain and builds each new domain. | 7889 | * It destroys each deleted domain and builds each new domain. |
7775 | * | 7890 | * |
7776 | * 'doms_new' is an array of cpumask_t's of length 'ndoms_new'. | 7891 | * 'doms_new' is an array of cpumask's of length 'ndoms_new'. |
7777 | * The masks don't intersect (don't overlap.) We should setup one | 7892 | * The masks don't intersect (don't overlap.) We should setup one |
7778 | * sched domain for each mask. CPUs not in any of the cpumasks will | 7893 | * sched domain for each mask. CPUs not in any of the cpumasks will |
7779 | * not be load balanced. If the same cpumask appears both in the | 7894 | * not be load balanced. If the same cpumask appears both in the |
@@ -7787,13 +7902,14 @@ static int dattrs_equal(struct sched_domain_attr *cur, int idx_cur, | |||
7787 | * the single partition 'fallback_doms', it also forces the domains | 7902 | * the single partition 'fallback_doms', it also forces the domains |
7788 | * to be rebuilt. | 7903 | * to be rebuilt. |
7789 | * | 7904 | * |
7790 | * If doms_new == NULL it will be replaced with cpu_online_map. | 7905 | * If doms_new == NULL it will be replaced with cpu_online_mask. |
7791 | * ndoms_new == 0 is a special case for destroying existing domains, | 7906 | * ndoms_new == 0 is a special case for destroying existing domains, |
7792 | * and it will not create the default domain. | 7907 | * and it will not create the default domain. |
7793 | * | 7908 | * |
7794 | * Call with hotplug lock held | 7909 | * Call with hotplug lock held |
7795 | */ | 7910 | */ |
7796 | void partition_sched_domains(int ndoms_new, cpumask_t *doms_new, | 7911 | /* FIXME: Change to struct cpumask *doms_new[] */ |
7912 | void partition_sched_domains(int ndoms_new, struct cpumask *doms_new, | ||
7797 | struct sched_domain_attr *dattr_new) | 7913 | struct sched_domain_attr *dattr_new) |
7798 | { | 7914 | { |
7799 | int i, j, n; | 7915 | int i, j, n; |
@@ -7812,7 +7928,7 @@ void partition_sched_domains(int ndoms_new, cpumask_t *doms_new, | |||
7812 | /* Destroy deleted domains */ | 7928 | /* Destroy deleted domains */ |
7813 | for (i = 0; i < ndoms_cur; i++) { | 7929 | for (i = 0; i < ndoms_cur; i++) { |
7814 | for (j = 0; j < n && !new_topology; j++) { | 7930 | for (j = 0; j < n && !new_topology; j++) { |
7815 | if (cpus_equal(doms_cur[i], doms_new[j]) | 7931 | if (cpumask_equal(&doms_cur[i], &doms_new[j]) |
7816 | && dattrs_equal(dattr_cur, i, dattr_new, j)) | 7932 | && dattrs_equal(dattr_cur, i, dattr_new, j)) |
7817 | goto match1; | 7933 | goto match1; |
7818 | } | 7934 | } |
@@ -7824,15 +7940,15 @@ match1: | |||
7824 | 7940 | ||
7825 | if (doms_new == NULL) { | 7941 | if (doms_new == NULL) { |
7826 | ndoms_cur = 0; | 7942 | ndoms_cur = 0; |
7827 | doms_new = &fallback_doms; | 7943 | doms_new = fallback_doms; |
7828 | cpus_andnot(doms_new[0], cpu_online_map, cpu_isolated_map); | 7944 | cpumask_andnot(&doms_new[0], cpu_online_mask, cpu_isolated_map); |
7829 | WARN_ON_ONCE(dattr_new); | 7945 | WARN_ON_ONCE(dattr_new); |
7830 | } | 7946 | } |
7831 | 7947 | ||
7832 | /* Build new domains */ | 7948 | /* Build new domains */ |
7833 | for (i = 0; i < ndoms_new; i++) { | 7949 | for (i = 0; i < ndoms_new; i++) { |
7834 | for (j = 0; j < ndoms_cur && !new_topology; j++) { | 7950 | for (j = 0; j < ndoms_cur && !new_topology; j++) { |
7835 | if (cpus_equal(doms_new[i], doms_cur[j]) | 7951 | if (cpumask_equal(&doms_new[i], &doms_cur[j]) |
7836 | && dattrs_equal(dattr_new, i, dattr_cur, j)) | 7952 | && dattrs_equal(dattr_new, i, dattr_cur, j)) |
7837 | goto match2; | 7953 | goto match2; |
7838 | } | 7954 | } |
@@ -7844,7 +7960,7 @@ match2: | |||
7844 | } | 7960 | } |
7845 | 7961 | ||
7846 | /* Remember the new sched domains */ | 7962 | /* Remember the new sched domains */ |
7847 | if (doms_cur != &fallback_doms) | 7963 | if (doms_cur != fallback_doms) |
7848 | kfree(doms_cur); | 7964 | kfree(doms_cur); |
7849 | kfree(dattr_cur); /* kfree(NULL) is safe */ | 7965 | kfree(dattr_cur); /* kfree(NULL) is safe */ |
7850 | doms_cur = doms_new; | 7966 | doms_cur = doms_new; |
@@ -7873,14 +7989,25 @@ int arch_reinit_sched_domains(void) | |||
7873 | static ssize_t sched_power_savings_store(const char *buf, size_t count, int smt) | 7989 | static ssize_t sched_power_savings_store(const char *buf, size_t count, int smt) |
7874 | { | 7990 | { |
7875 | int ret; | 7991 | int ret; |
7992 | unsigned int level = 0; | ||
7876 | 7993 | ||
7877 | if (buf[0] != '0' && buf[0] != '1') | 7994 | if (sscanf(buf, "%u", &level) != 1) |
7995 | return -EINVAL; | ||
7996 | |||
7997 | /* | ||
7998 | * level is always be positive so don't check for | ||
7999 | * level < POWERSAVINGS_BALANCE_NONE which is 0 | ||
8000 | * What happens on 0 or 1 byte write, | ||
8001 | * need to check for count as well? | ||
8002 | */ | ||
8003 | |||
8004 | if (level >= MAX_POWERSAVINGS_BALANCE_LEVELS) | ||
7878 | return -EINVAL; | 8005 | return -EINVAL; |
7879 | 8006 | ||
7880 | if (smt) | 8007 | if (smt) |
7881 | sched_smt_power_savings = (buf[0] == '1'); | 8008 | sched_smt_power_savings = level; |
7882 | else | 8009 | else |
7883 | sched_mc_power_savings = (buf[0] == '1'); | 8010 | sched_mc_power_savings = level; |
7884 | 8011 | ||
7885 | ret = arch_reinit_sched_domains(); | 8012 | ret = arch_reinit_sched_domains(); |
7886 | 8013 | ||
@@ -7984,7 +8111,9 @@ static int update_runtime(struct notifier_block *nfb, | |||
7984 | 8111 | ||
7985 | void __init sched_init_smp(void) | 8112 | void __init sched_init_smp(void) |
7986 | { | 8113 | { |
7987 | cpumask_t non_isolated_cpus; | 8114 | cpumask_var_t non_isolated_cpus; |
8115 | |||
8116 | alloc_cpumask_var(&non_isolated_cpus, GFP_KERNEL); | ||
7988 | 8117 | ||
7989 | #if defined(CONFIG_NUMA) | 8118 | #if defined(CONFIG_NUMA) |
7990 | sched_group_nodes_bycpu = kzalloc(nr_cpu_ids * sizeof(void **), | 8119 | sched_group_nodes_bycpu = kzalloc(nr_cpu_ids * sizeof(void **), |
@@ -7993,10 +8122,10 @@ void __init sched_init_smp(void) | |||
7993 | #endif | 8122 | #endif |
7994 | get_online_cpus(); | 8123 | get_online_cpus(); |
7995 | mutex_lock(&sched_domains_mutex); | 8124 | mutex_lock(&sched_domains_mutex); |
7996 | arch_init_sched_domains(&cpu_online_map); | 8125 | arch_init_sched_domains(cpu_online_mask); |
7997 | cpus_andnot(non_isolated_cpus, cpu_possible_map, cpu_isolated_map); | 8126 | cpumask_andnot(non_isolated_cpus, cpu_possible_mask, cpu_isolated_map); |
7998 | if (cpus_empty(non_isolated_cpus)) | 8127 | if (cpumask_empty(non_isolated_cpus)) |
7999 | cpu_set(smp_processor_id(), non_isolated_cpus); | 8128 | cpumask_set_cpu(smp_processor_id(), non_isolated_cpus); |
8000 | mutex_unlock(&sched_domains_mutex); | 8129 | mutex_unlock(&sched_domains_mutex); |
8001 | put_online_cpus(); | 8130 | put_online_cpus(); |
8002 | 8131 | ||
@@ -8011,9 +8140,13 @@ void __init sched_init_smp(void) | |||
8011 | init_hrtick(); | 8140 | init_hrtick(); |
8012 | 8141 | ||
8013 | /* Move init over to a non-isolated CPU */ | 8142 | /* Move init over to a non-isolated CPU */ |
8014 | if (set_cpus_allowed_ptr(current, &non_isolated_cpus) < 0) | 8143 | if (set_cpus_allowed_ptr(current, non_isolated_cpus) < 0) |
8015 | BUG(); | 8144 | BUG(); |
8016 | sched_init_granularity(); | 8145 | sched_init_granularity(); |
8146 | free_cpumask_var(non_isolated_cpus); | ||
8147 | |||
8148 | alloc_cpumask_var(&fallback_doms, GFP_KERNEL); | ||
8149 | init_sched_rt_class(); | ||
8017 | } | 8150 | } |
8018 | #else | 8151 | #else |
8019 | void __init sched_init_smp(void) | 8152 | void __init sched_init_smp(void) |
@@ -8328,6 +8461,15 @@ void __init sched_init(void) | |||
8328 | */ | 8461 | */ |
8329 | current->sched_class = &fair_sched_class; | 8462 | current->sched_class = &fair_sched_class; |
8330 | 8463 | ||
8464 | /* Allocate the nohz_cpu_mask if CONFIG_CPUMASK_OFFSTACK */ | ||
8465 | alloc_bootmem_cpumask_var(&nohz_cpu_mask); | ||
8466 | #ifdef CONFIG_SMP | ||
8467 | #ifdef CONFIG_NO_HZ | ||
8468 | alloc_bootmem_cpumask_var(&nohz.cpu_mask); | ||
8469 | #endif | ||
8470 | alloc_bootmem_cpumask_var(&cpu_isolated_map); | ||
8471 | #endif /* SMP */ | ||
8472 | |||
8331 | scheduler_running = 1; | 8473 | scheduler_running = 1; |
8332 | } | 8474 | } |
8333 | 8475 | ||