diff options
author | Ingo Molnar <mingo@elte.hu> | 2009-01-05 07:53:39 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-01-05 07:53:39 -0500 |
commit | 5359c32eb7402124abc9964d5d53639fe0739cea (patch) | |
tree | d77b6967fe8420678bb9d1d936855ac0699c196a /kernel/sched.c | |
parent | 8916edef5888c5d8fe283714416a9ca95b4c3431 (diff) | |
parent | fe0bdec68b77020281dc814805edfe594ae89e0f (diff) |
Merge branch 'linus' into sched/urgent
Diffstat (limited to 'kernel/sched.c')
-rw-r--r-- | kernel/sched.c | 1090 |
1 files changed, 623 insertions, 467 deletions
diff --git a/kernel/sched.c b/kernel/sched.c index fff1c4a20b65..545c6fccd1dc 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 (!cpumask_test_cpu(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)) |
@@ -4080,13 +4150,17 @@ unsigned long long task_delta_exec(struct task_struct *p) | |||
4080 | * Account user cpu time to a process. | 4150 | * Account user cpu time to a process. |
4081 | * @p: the process that the cpu time gets accounted to | 4151 | * @p: the process that the cpu time gets accounted to |
4082 | * @cputime: the cpu time spent in user space since the last update | 4152 | * @cputime: the cpu time spent in user space since the last update |
4153 | * @cputime_scaled: cputime scaled by cpu frequency | ||
4083 | */ | 4154 | */ |
4084 | void account_user_time(struct task_struct *p, cputime_t cputime) | 4155 | void account_user_time(struct task_struct *p, cputime_t cputime, |
4156 | cputime_t cputime_scaled) | ||
4085 | { | 4157 | { |
4086 | struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat; | 4158 | struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat; |
4087 | cputime64_t tmp; | 4159 | cputime64_t tmp; |
4088 | 4160 | ||
4161 | /* Add user time to process. */ | ||
4089 | p->utime = cputime_add(p->utime, cputime); | 4162 | p->utime = cputime_add(p->utime, cputime); |
4163 | p->utimescaled = cputime_add(p->utimescaled, cputime_scaled); | ||
4090 | account_group_user_time(p, cputime); | 4164 | account_group_user_time(p, cputime); |
4091 | 4165 | ||
4092 | /* Add user time to cpustat. */ | 4166 | /* Add user time to cpustat. */ |
@@ -4103,51 +4177,48 @@ void account_user_time(struct task_struct *p, cputime_t cputime) | |||
4103 | * Account guest cpu time to a process. | 4177 | * Account guest cpu time to a process. |
4104 | * @p: the process that the cpu time gets accounted to | 4178 | * @p: the process that the cpu time gets accounted to |
4105 | * @cputime: the cpu time spent in virtual machine since the last update | 4179 | * @cputime: the cpu time spent in virtual machine since the last update |
4180 | * @cputime_scaled: cputime scaled by cpu frequency | ||
4106 | */ | 4181 | */ |
4107 | static void account_guest_time(struct task_struct *p, cputime_t cputime) | 4182 | static void account_guest_time(struct task_struct *p, cputime_t cputime, |
4183 | cputime_t cputime_scaled) | ||
4108 | { | 4184 | { |
4109 | cputime64_t tmp; | 4185 | cputime64_t tmp; |
4110 | struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat; | 4186 | struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat; |
4111 | 4187 | ||
4112 | tmp = cputime_to_cputime64(cputime); | 4188 | tmp = cputime_to_cputime64(cputime); |
4113 | 4189 | ||
4190 | /* Add guest time to process. */ | ||
4114 | p->utime = cputime_add(p->utime, cputime); | 4191 | p->utime = cputime_add(p->utime, cputime); |
4192 | p->utimescaled = cputime_add(p->utimescaled, cputime_scaled); | ||
4115 | account_group_user_time(p, cputime); | 4193 | account_group_user_time(p, cputime); |
4116 | p->gtime = cputime_add(p->gtime, cputime); | 4194 | p->gtime = cputime_add(p->gtime, cputime); |
4117 | 4195 | ||
4196 | /* Add guest time to cpustat. */ | ||
4118 | cpustat->user = cputime64_add(cpustat->user, tmp); | 4197 | cpustat->user = cputime64_add(cpustat->user, tmp); |
4119 | cpustat->guest = cputime64_add(cpustat->guest, tmp); | 4198 | cpustat->guest = cputime64_add(cpustat->guest, tmp); |
4120 | } | 4199 | } |
4121 | 4200 | ||
4122 | /* | 4201 | /* |
4123 | * Account scaled user cpu time to a process. | ||
4124 | * @p: the process that the cpu time gets accounted to | ||
4125 | * @cputime: the cpu time spent in user space since the last update | ||
4126 | */ | ||
4127 | void account_user_time_scaled(struct task_struct *p, cputime_t cputime) | ||
4128 | { | ||
4129 | p->utimescaled = cputime_add(p->utimescaled, cputime); | ||
4130 | } | ||
4131 | |||
4132 | /* | ||
4133 | * Account system cpu time to a process. | 4202 | * Account system cpu time to a process. |
4134 | * @p: the process that the cpu time gets accounted to | 4203 | * @p: the process that the cpu time gets accounted to |
4135 | * @hardirq_offset: the offset to subtract from hardirq_count() | 4204 | * @hardirq_offset: the offset to subtract from hardirq_count() |
4136 | * @cputime: the cpu time spent in kernel space since the last update | 4205 | * @cputime: the cpu time spent in kernel space since the last update |
4206 | * @cputime_scaled: cputime scaled by cpu frequency | ||
4137 | */ | 4207 | */ |
4138 | void account_system_time(struct task_struct *p, int hardirq_offset, | 4208 | void account_system_time(struct task_struct *p, int hardirq_offset, |
4139 | cputime_t cputime) | 4209 | cputime_t cputime, cputime_t cputime_scaled) |
4140 | { | 4210 | { |
4141 | struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat; | 4211 | struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat; |
4142 | struct rq *rq = this_rq(); | ||
4143 | cputime64_t tmp; | 4212 | cputime64_t tmp; |
4144 | 4213 | ||
4145 | if ((p->flags & PF_VCPU) && (irq_count() - hardirq_offset == 0)) { | 4214 | if ((p->flags & PF_VCPU) && (irq_count() - hardirq_offset == 0)) { |
4146 | account_guest_time(p, cputime); | 4215 | account_guest_time(p, cputime, cputime_scaled); |
4147 | return; | 4216 | return; |
4148 | } | 4217 | } |
4149 | 4218 | ||
4219 | /* Add system time to process. */ | ||
4150 | p->stime = cputime_add(p->stime, cputime); | 4220 | p->stime = cputime_add(p->stime, cputime); |
4221 | p->stimescaled = cputime_add(p->stimescaled, cputime_scaled); | ||
4151 | account_group_system_time(p, cputime); | 4222 | account_group_system_time(p, cputime); |
4152 | 4223 | ||
4153 | /* Add system time to cpustat. */ | 4224 | /* Add system time to cpustat. */ |
@@ -4156,48 +4227,84 @@ void account_system_time(struct task_struct *p, int hardirq_offset, | |||
4156 | cpustat->irq = cputime64_add(cpustat->irq, tmp); | 4227 | cpustat->irq = cputime64_add(cpustat->irq, tmp); |
4157 | else if (softirq_count()) | 4228 | else if (softirq_count()) |
4158 | cpustat->softirq = cputime64_add(cpustat->softirq, tmp); | 4229 | cpustat->softirq = cputime64_add(cpustat->softirq, tmp); |
4159 | else if (p != rq->idle) | ||
4160 | cpustat->system = cputime64_add(cpustat->system, tmp); | ||
4161 | else if (atomic_read(&rq->nr_iowait) > 0) | ||
4162 | cpustat->iowait = cputime64_add(cpustat->iowait, tmp); | ||
4163 | else | 4230 | else |
4164 | cpustat->idle = cputime64_add(cpustat->idle, tmp); | 4231 | cpustat->system = cputime64_add(cpustat->system, tmp); |
4232 | |||
4165 | /* Account for system time used */ | 4233 | /* Account for system time used */ |
4166 | acct_update_integrals(p); | 4234 | acct_update_integrals(p); |
4167 | } | 4235 | } |
4168 | 4236 | ||
4169 | /* | 4237 | /* |
4170 | * Account scaled system cpu time to a process. | 4238 | * Account for involuntary wait time. |
4171 | * @p: the process that the cpu time gets accounted to | 4239 | * @steal: the cpu time spent in involuntary wait |
4172 | * @hardirq_offset: the offset to subtract from hardirq_count() | ||
4173 | * @cputime: the cpu time spent in kernel space since the last update | ||
4174 | */ | 4240 | */ |
4175 | void account_system_time_scaled(struct task_struct *p, cputime_t cputime) | 4241 | void account_steal_time(cputime_t cputime) |
4176 | { | 4242 | { |
4177 | p->stimescaled = cputime_add(p->stimescaled, cputime); | 4243 | struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat; |
4244 | cputime64_t cputime64 = cputime_to_cputime64(cputime); | ||
4245 | |||
4246 | cpustat->steal = cputime64_add(cpustat->steal, cputime64); | ||
4178 | } | 4247 | } |
4179 | 4248 | ||
4180 | /* | 4249 | /* |
4181 | * Account for involuntary wait time. | 4250 | * Account for idle time. |
4182 | * @p: the process from which the cpu time has been stolen | 4251 | * @cputime: the cpu time spent in idle wait |
4183 | * @steal: the cpu time spent in involuntary wait | ||
4184 | */ | 4252 | */ |
4185 | void account_steal_time(struct task_struct *p, cputime_t steal) | 4253 | void account_idle_time(cputime_t cputime) |
4186 | { | 4254 | { |
4187 | struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat; | 4255 | struct cpu_usage_stat *cpustat = &kstat_this_cpu.cpustat; |
4188 | cputime64_t tmp = cputime_to_cputime64(steal); | 4256 | cputime64_t cputime64 = cputime_to_cputime64(cputime); |
4189 | struct rq *rq = this_rq(); | 4257 | struct rq *rq = this_rq(); |
4190 | 4258 | ||
4191 | if (p == rq->idle) { | 4259 | if (atomic_read(&rq->nr_iowait) > 0) |
4192 | p->stime = cputime_add(p->stime, steal); | 4260 | cpustat->iowait = cputime64_add(cpustat->iowait, cputime64); |
4193 | if (atomic_read(&rq->nr_iowait) > 0) | 4261 | else |
4194 | cpustat->iowait = cputime64_add(cpustat->iowait, tmp); | 4262 | cpustat->idle = cputime64_add(cpustat->idle, cputime64); |
4195 | else | ||
4196 | cpustat->idle = cputime64_add(cpustat->idle, tmp); | ||
4197 | } else | ||
4198 | cpustat->steal = cputime64_add(cpustat->steal, tmp); | ||
4199 | } | 4263 | } |
4200 | 4264 | ||
4265 | #ifndef CONFIG_VIRT_CPU_ACCOUNTING | ||
4266 | |||
4267 | /* | ||
4268 | * Account a single tick of cpu time. | ||
4269 | * @p: the process that the cpu time gets accounted to | ||
4270 | * @user_tick: indicates if the tick is a user or a system tick | ||
4271 | */ | ||
4272 | void account_process_tick(struct task_struct *p, int user_tick) | ||
4273 | { | ||
4274 | cputime_t one_jiffy = jiffies_to_cputime(1); | ||
4275 | cputime_t one_jiffy_scaled = cputime_to_scaled(one_jiffy); | ||
4276 | struct rq *rq = this_rq(); | ||
4277 | |||
4278 | if (user_tick) | ||
4279 | account_user_time(p, one_jiffy, one_jiffy_scaled); | ||
4280 | else if (p != rq->idle) | ||
4281 | account_system_time(p, HARDIRQ_OFFSET, one_jiffy, | ||
4282 | one_jiffy_scaled); | ||
4283 | else | ||
4284 | account_idle_time(one_jiffy); | ||
4285 | } | ||
4286 | |||
4287 | /* | ||
4288 | * Account multiple ticks of steal time. | ||
4289 | * @p: the process from which the cpu time has been stolen | ||
4290 | * @ticks: number of stolen ticks | ||
4291 | */ | ||
4292 | void account_steal_ticks(unsigned long ticks) | ||
4293 | { | ||
4294 | account_steal_time(jiffies_to_cputime(ticks)); | ||
4295 | } | ||
4296 | |||
4297 | /* | ||
4298 | * Account multiple ticks of idle time. | ||
4299 | * @ticks: number of stolen ticks | ||
4300 | */ | ||
4301 | void account_idle_ticks(unsigned long ticks) | ||
4302 | { | ||
4303 | account_idle_time(jiffies_to_cputime(ticks)); | ||
4304 | } | ||
4305 | |||
4306 | #endif | ||
4307 | |||
4201 | /* | 4308 | /* |
4202 | * Use precise platform statistics if available: | 4309 | * Use precise platform statistics if available: |
4203 | */ | 4310 | */ |
@@ -5401,10 +5508,9 @@ out_unlock: | |||
5401 | return retval; | 5508 | return retval; |
5402 | } | 5509 | } |
5403 | 5510 | ||
5404 | long sched_setaffinity(pid_t pid, const cpumask_t *in_mask) | 5511 | long sched_setaffinity(pid_t pid, const struct cpumask *in_mask) |
5405 | { | 5512 | { |
5406 | cpumask_t cpus_allowed; | 5513 | cpumask_var_t cpus_allowed, new_mask; |
5407 | cpumask_t new_mask = *in_mask; | ||
5408 | struct task_struct *p; | 5514 | struct task_struct *p; |
5409 | int retval; | 5515 | int retval; |
5410 | 5516 | ||
@@ -5426,6 +5532,14 @@ long sched_setaffinity(pid_t pid, const cpumask_t *in_mask) | |||
5426 | get_task_struct(p); | 5532 | get_task_struct(p); |
5427 | read_unlock(&tasklist_lock); | 5533 | read_unlock(&tasklist_lock); |
5428 | 5534 | ||
5535 | if (!alloc_cpumask_var(&cpus_allowed, GFP_KERNEL)) { | ||
5536 | retval = -ENOMEM; | ||
5537 | goto out_put_task; | ||
5538 | } | ||
5539 | if (!alloc_cpumask_var(&new_mask, GFP_KERNEL)) { | ||
5540 | retval = -ENOMEM; | ||
5541 | goto out_free_cpus_allowed; | ||
5542 | } | ||
5429 | retval = -EPERM; | 5543 | retval = -EPERM; |
5430 | if (!check_same_owner(p) && !capable(CAP_SYS_NICE)) | 5544 | if (!check_same_owner(p) && !capable(CAP_SYS_NICE)) |
5431 | goto out_unlock; | 5545 | goto out_unlock; |
@@ -5434,37 +5548,41 @@ long sched_setaffinity(pid_t pid, const cpumask_t *in_mask) | |||
5434 | if (retval) | 5548 | if (retval) |
5435 | goto out_unlock; | 5549 | goto out_unlock; |
5436 | 5550 | ||
5437 | cpuset_cpus_allowed(p, &cpus_allowed); | 5551 | cpuset_cpus_allowed(p, cpus_allowed); |
5438 | cpus_and(new_mask, new_mask, cpus_allowed); | 5552 | cpumask_and(new_mask, in_mask, cpus_allowed); |
5439 | again: | 5553 | again: |
5440 | retval = set_cpus_allowed_ptr(p, &new_mask); | 5554 | retval = set_cpus_allowed_ptr(p, new_mask); |
5441 | 5555 | ||
5442 | if (!retval) { | 5556 | if (!retval) { |
5443 | cpuset_cpus_allowed(p, &cpus_allowed); | 5557 | cpuset_cpus_allowed(p, cpus_allowed); |
5444 | if (!cpus_subset(new_mask, cpus_allowed)) { | 5558 | if (!cpumask_subset(new_mask, cpus_allowed)) { |
5445 | /* | 5559 | /* |
5446 | * We must have raced with a concurrent cpuset | 5560 | * We must have raced with a concurrent cpuset |
5447 | * update. Just reset the cpus_allowed to the | 5561 | * update. Just reset the cpus_allowed to the |
5448 | * cpuset's cpus_allowed | 5562 | * cpuset's cpus_allowed |
5449 | */ | 5563 | */ |
5450 | new_mask = cpus_allowed; | 5564 | cpumask_copy(new_mask, cpus_allowed); |
5451 | goto again; | 5565 | goto again; |
5452 | } | 5566 | } |
5453 | } | 5567 | } |
5454 | out_unlock: | 5568 | out_unlock: |
5569 | free_cpumask_var(new_mask); | ||
5570 | out_free_cpus_allowed: | ||
5571 | free_cpumask_var(cpus_allowed); | ||
5572 | out_put_task: | ||
5455 | put_task_struct(p); | 5573 | put_task_struct(p); |
5456 | put_online_cpus(); | 5574 | put_online_cpus(); |
5457 | return retval; | 5575 | return retval; |
5458 | } | 5576 | } |
5459 | 5577 | ||
5460 | static int get_user_cpu_mask(unsigned long __user *user_mask_ptr, unsigned len, | 5578 | static int get_user_cpu_mask(unsigned long __user *user_mask_ptr, unsigned len, |
5461 | cpumask_t *new_mask) | 5579 | struct cpumask *new_mask) |
5462 | { | 5580 | { |
5463 | if (len < sizeof(cpumask_t)) { | 5581 | if (len < cpumask_size()) |
5464 | memset(new_mask, 0, sizeof(cpumask_t)); | 5582 | cpumask_clear(new_mask); |
5465 | } else if (len > sizeof(cpumask_t)) { | 5583 | else if (len > cpumask_size()) |
5466 | len = sizeof(cpumask_t); | 5584 | len = cpumask_size(); |
5467 | } | 5585 | |
5468 | return copy_from_user(new_mask, user_mask_ptr, len) ? -EFAULT : 0; | 5586 | return copy_from_user(new_mask, user_mask_ptr, len) ? -EFAULT : 0; |
5469 | } | 5587 | } |
5470 | 5588 | ||
@@ -5477,17 +5595,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, | 5595 | asmlinkage long sys_sched_setaffinity(pid_t pid, unsigned int len, |
5478 | unsigned long __user *user_mask_ptr) | 5596 | unsigned long __user *user_mask_ptr) |
5479 | { | 5597 | { |
5480 | cpumask_t new_mask; | 5598 | cpumask_var_t new_mask; |
5481 | int retval; | 5599 | int retval; |
5482 | 5600 | ||
5483 | retval = get_user_cpu_mask(user_mask_ptr, len, &new_mask); | 5601 | if (!alloc_cpumask_var(&new_mask, GFP_KERNEL)) |
5484 | if (retval) | 5602 | return -ENOMEM; |
5485 | return retval; | ||
5486 | 5603 | ||
5487 | return sched_setaffinity(pid, &new_mask); | 5604 | retval = get_user_cpu_mask(user_mask_ptr, len, new_mask); |
5605 | if (retval == 0) | ||
5606 | retval = sched_setaffinity(pid, new_mask); | ||
5607 | free_cpumask_var(new_mask); | ||
5608 | return retval; | ||
5488 | } | 5609 | } |
5489 | 5610 | ||
5490 | long sched_getaffinity(pid_t pid, cpumask_t *mask) | 5611 | long sched_getaffinity(pid_t pid, struct cpumask *mask) |
5491 | { | 5612 | { |
5492 | struct task_struct *p; | 5613 | struct task_struct *p; |
5493 | int retval; | 5614 | int retval; |
@@ -5504,7 +5625,7 @@ long sched_getaffinity(pid_t pid, cpumask_t *mask) | |||
5504 | if (retval) | 5625 | if (retval) |
5505 | goto out_unlock; | 5626 | goto out_unlock; |
5506 | 5627 | ||
5507 | cpus_and(*mask, p->cpus_allowed, cpu_online_map); | 5628 | cpumask_and(mask, &p->cpus_allowed, cpu_online_mask); |
5508 | 5629 | ||
5509 | out_unlock: | 5630 | out_unlock: |
5510 | read_unlock(&tasklist_lock); | 5631 | read_unlock(&tasklist_lock); |
@@ -5523,19 +5644,24 @@ asmlinkage long sys_sched_getaffinity(pid_t pid, unsigned int len, | |||
5523 | unsigned long __user *user_mask_ptr) | 5644 | unsigned long __user *user_mask_ptr) |
5524 | { | 5645 | { |
5525 | int ret; | 5646 | int ret; |
5526 | cpumask_t mask; | 5647 | cpumask_var_t mask; |
5527 | 5648 | ||
5528 | if (len < sizeof(cpumask_t)) | 5649 | if (len < cpumask_size()) |
5529 | return -EINVAL; | 5650 | return -EINVAL; |
5530 | 5651 | ||
5531 | ret = sched_getaffinity(pid, &mask); | 5652 | if (!alloc_cpumask_var(&mask, GFP_KERNEL)) |
5532 | if (ret < 0) | 5653 | return -ENOMEM; |
5533 | return ret; | ||
5534 | 5654 | ||
5535 | if (copy_to_user(user_mask_ptr, &mask, sizeof(cpumask_t))) | 5655 | ret = sched_getaffinity(pid, mask); |
5536 | return -EFAULT; | 5656 | if (ret == 0) { |
5657 | if (copy_to_user(user_mask_ptr, mask, cpumask_size())) | ||
5658 | ret = -EFAULT; | ||
5659 | else | ||
5660 | ret = cpumask_size(); | ||
5661 | } | ||
5662 | free_cpumask_var(mask); | ||
5537 | 5663 | ||
5538 | return sizeof(cpumask_t); | 5664 | return ret; |
5539 | } | 5665 | } |
5540 | 5666 | ||
5541 | /** | 5667 | /** |
@@ -5877,7 +6003,7 @@ void __cpuinit init_idle(struct task_struct *idle, int cpu) | |||
5877 | idle->se.exec_start = sched_clock(); | 6003 | idle->se.exec_start = sched_clock(); |
5878 | 6004 | ||
5879 | idle->prio = idle->normal_prio = MAX_PRIO; | 6005 | idle->prio = idle->normal_prio = MAX_PRIO; |
5880 | idle->cpus_allowed = cpumask_of_cpu(cpu); | 6006 | cpumask_copy(&idle->cpus_allowed, cpumask_of(cpu)); |
5881 | __set_task_cpu(idle, cpu); | 6007 | __set_task_cpu(idle, cpu); |
5882 | 6008 | ||
5883 | rq->curr = rq->idle = idle; | 6009 | rq->curr = rq->idle = idle; |
@@ -5904,9 +6030,9 @@ void __cpuinit init_idle(struct task_struct *idle, int cpu) | |||
5904 | * indicates which cpus entered this state. This is used | 6030 | * indicates which cpus entered this state. This is used |
5905 | * in the rcu update to wait only for active cpus. For system | 6031 | * 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 | 6032 | * which do not switch off the HZ timer nohz_cpu_mask should |
5907 | * always be CPU_MASK_NONE. | 6033 | * always be CPU_BITS_NONE. |
5908 | */ | 6034 | */ |
5909 | cpumask_t nohz_cpu_mask = CPU_MASK_NONE; | 6035 | cpumask_var_t nohz_cpu_mask; |
5910 | 6036 | ||
5911 | /* | 6037 | /* |
5912 | * Increase the granularity value when there are more CPUs, | 6038 | * Increase the granularity value when there are more CPUs, |
@@ -5961,7 +6087,7 @@ static inline void sched_init_granularity(void) | |||
5961 | * task must not exit() & deallocate itself prematurely. The | 6087 | * task must not exit() & deallocate itself prematurely. The |
5962 | * call is not atomic; no spinlocks may be held. | 6088 | * call is not atomic; no spinlocks may be held. |
5963 | */ | 6089 | */ |
5964 | int set_cpus_allowed_ptr(struct task_struct *p, const cpumask_t *new_mask) | 6090 | int set_cpus_allowed_ptr(struct task_struct *p, const struct cpumask *new_mask) |
5965 | { | 6091 | { |
5966 | struct migration_req req; | 6092 | struct migration_req req; |
5967 | unsigned long flags; | 6093 | unsigned long flags; |
@@ -5969,13 +6095,13 @@ int set_cpus_allowed_ptr(struct task_struct *p, const cpumask_t *new_mask) | |||
5969 | int ret = 0; | 6095 | int ret = 0; |
5970 | 6096 | ||
5971 | rq = task_rq_lock(p, &flags); | 6097 | rq = task_rq_lock(p, &flags); |
5972 | if (!cpus_intersects(*new_mask, cpu_online_map)) { | 6098 | if (!cpumask_intersects(new_mask, cpu_online_mask)) { |
5973 | ret = -EINVAL; | 6099 | ret = -EINVAL; |
5974 | goto out; | 6100 | goto out; |
5975 | } | 6101 | } |
5976 | 6102 | ||
5977 | if (unlikely((p->flags & PF_THREAD_BOUND) && p != current && | 6103 | if (unlikely((p->flags & PF_THREAD_BOUND) && p != current && |
5978 | !cpus_equal(p->cpus_allowed, *new_mask))) { | 6104 | !cpumask_equal(&p->cpus_allowed, new_mask))) { |
5979 | ret = -EINVAL; | 6105 | ret = -EINVAL; |
5980 | goto out; | 6106 | goto out; |
5981 | } | 6107 | } |
@@ -5983,15 +6109,15 @@ int set_cpus_allowed_ptr(struct task_struct *p, const cpumask_t *new_mask) | |||
5983 | if (p->sched_class->set_cpus_allowed) | 6109 | if (p->sched_class->set_cpus_allowed) |
5984 | p->sched_class->set_cpus_allowed(p, new_mask); | 6110 | p->sched_class->set_cpus_allowed(p, new_mask); |
5985 | else { | 6111 | else { |
5986 | p->cpus_allowed = *new_mask; | 6112 | cpumask_copy(&p->cpus_allowed, new_mask); |
5987 | p->rt.nr_cpus_allowed = cpus_weight(*new_mask); | 6113 | p->rt.nr_cpus_allowed = cpumask_weight(new_mask); |
5988 | } | 6114 | } |
5989 | 6115 | ||
5990 | /* Can the task run on the task's current CPU? If so, we're done */ | 6116 | /* Can the task run on the task's current CPU? If so, we're done */ |
5991 | if (cpu_isset(task_cpu(p), *new_mask)) | 6117 | if (cpumask_test_cpu(task_cpu(p), new_mask)) |
5992 | goto out; | 6118 | goto out; |
5993 | 6119 | ||
5994 | if (migrate_task(p, any_online_cpu(*new_mask), &req)) { | 6120 | if (migrate_task(p, cpumask_any_and(cpu_online_mask, new_mask), &req)) { |
5995 | /* Need help from migration thread: drop lock and wait. */ | 6121 | /* Need help from migration thread: drop lock and wait. */ |
5996 | task_rq_unlock(rq, &flags); | 6122 | task_rq_unlock(rq, &flags); |
5997 | wake_up_process(rq->migration_thread); | 6123 | wake_up_process(rq->migration_thread); |
@@ -6033,7 +6159,7 @@ static int __migrate_task(struct task_struct *p, int src_cpu, int dest_cpu) | |||
6033 | if (task_cpu(p) != src_cpu) | 6159 | if (task_cpu(p) != src_cpu) |
6034 | goto done; | 6160 | goto done; |
6035 | /* Affinity changed (again). */ | 6161 | /* Affinity changed (again). */ |
6036 | if (!cpu_isset(dest_cpu, p->cpus_allowed)) | 6162 | if (!cpumask_test_cpu(dest_cpu, &p->cpus_allowed)) |
6037 | goto fail; | 6163 | goto fail; |
6038 | 6164 | ||
6039 | on_rq = p->se.on_rq; | 6165 | on_rq = p->se.on_rq; |
@@ -6130,50 +6256,41 @@ static int __migrate_task_irq(struct task_struct *p, int src_cpu, int dest_cpu) | |||
6130 | */ | 6256 | */ |
6131 | static void move_task_off_dead_cpu(int dead_cpu, struct task_struct *p) | 6257 | static void move_task_off_dead_cpu(int dead_cpu, struct task_struct *p) |
6132 | { | 6258 | { |
6133 | unsigned long flags; | ||
6134 | cpumask_t mask; | ||
6135 | struct rq *rq; | ||
6136 | int dest_cpu; | 6259 | int dest_cpu; |
6260 | const struct cpumask *nodemask = cpumask_of_node(cpu_to_node(dead_cpu)); | ||
6137 | 6261 | ||
6138 | do { | 6262 | again: |
6139 | /* On same node? */ | 6263 | /* Look for allowed, online CPU in same node. */ |
6140 | mask = node_to_cpumask(cpu_to_node(dead_cpu)); | 6264 | for_each_cpu_and(dest_cpu, nodemask, cpu_online_mask) |
6141 | cpus_and(mask, mask, p->cpus_allowed); | 6265 | if (cpumask_test_cpu(dest_cpu, &p->cpus_allowed)) |
6142 | dest_cpu = any_online_cpu(mask); | 6266 | goto move; |
6143 | 6267 | ||
6144 | /* On any allowed CPU? */ | 6268 | /* Any allowed, online CPU? */ |
6145 | if (dest_cpu >= nr_cpu_ids) | 6269 | dest_cpu = cpumask_any_and(&p->cpus_allowed, cpu_online_mask); |
6146 | dest_cpu = any_online_cpu(p->cpus_allowed); | 6270 | if (dest_cpu < nr_cpu_ids) |
6271 | goto move; | ||
6147 | 6272 | ||
6148 | /* No more Mr. Nice Guy. */ | 6273 | /* No more Mr. Nice Guy. */ |
6149 | if (dest_cpu >= nr_cpu_ids) { | 6274 | if (dest_cpu >= nr_cpu_ids) { |
6150 | cpumask_t cpus_allowed; | 6275 | cpuset_cpus_allowed_locked(p, &p->cpus_allowed); |
6151 | 6276 | dest_cpu = cpumask_any_and(cpu_online_mask, &p->cpus_allowed); | |
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 | 6277 | ||
6165 | /* | 6278 | /* |
6166 | * Don't tell them about moving exiting tasks or | 6279 | * Don't tell them about moving exiting tasks or |
6167 | * kernel threads (both mm NULL), since they never | 6280 | * kernel threads (both mm NULL), since they never |
6168 | * leave kernel. | 6281 | * leave kernel. |
6169 | */ | 6282 | */ |
6170 | if (p->mm && printk_ratelimit()) { | 6283 | if (p->mm && printk_ratelimit()) { |
6171 | printk(KERN_INFO "process %d (%s) no " | 6284 | printk(KERN_INFO "process %d (%s) no " |
6172 | "longer affine to cpu%d\n", | 6285 | "longer affine to cpu%d\n", |
6173 | task_pid_nr(p), p->comm, dead_cpu); | 6286 | task_pid_nr(p), p->comm, dead_cpu); |
6174 | } | ||
6175 | } | 6287 | } |
6176 | } while (!__migrate_task_irq(p, dead_cpu, dest_cpu)); | 6288 | } |
6289 | |||
6290 | move: | ||
6291 | /* It can have affinity changed while we were choosing. */ | ||
6292 | if (unlikely(!__migrate_task_irq(p, dead_cpu, dest_cpu))) | ||
6293 | goto again; | ||
6177 | } | 6294 | } |
6178 | 6295 | ||
6179 | /* | 6296 | /* |
@@ -6185,7 +6302,7 @@ static void move_task_off_dead_cpu(int dead_cpu, struct task_struct *p) | |||
6185 | */ | 6302 | */ |
6186 | static void migrate_nr_uninterruptible(struct rq *rq_src) | 6303 | static void migrate_nr_uninterruptible(struct rq *rq_src) |
6187 | { | 6304 | { |
6188 | struct rq *rq_dest = cpu_rq(any_online_cpu(*CPU_MASK_ALL_PTR)); | 6305 | struct rq *rq_dest = cpu_rq(cpumask_any(cpu_online_mask)); |
6189 | unsigned long flags; | 6306 | unsigned long flags; |
6190 | 6307 | ||
6191 | local_irq_save(flags); | 6308 | local_irq_save(flags); |
@@ -6475,7 +6592,7 @@ static void set_rq_online(struct rq *rq) | |||
6475 | if (!rq->online) { | 6592 | if (!rq->online) { |
6476 | const struct sched_class *class; | 6593 | const struct sched_class *class; |
6477 | 6594 | ||
6478 | cpu_set(rq->cpu, rq->rd->online); | 6595 | cpumask_set_cpu(rq->cpu, rq->rd->online); |
6479 | rq->online = 1; | 6596 | rq->online = 1; |
6480 | 6597 | ||
6481 | for_each_class(class) { | 6598 | for_each_class(class) { |
@@ -6495,7 +6612,7 @@ static void set_rq_offline(struct rq *rq) | |||
6495 | class->rq_offline(rq); | 6612 | class->rq_offline(rq); |
6496 | } | 6613 | } |
6497 | 6614 | ||
6498 | cpu_clear(rq->cpu, rq->rd->online); | 6615 | cpumask_clear_cpu(rq->cpu, rq->rd->online); |
6499 | rq->online = 0; | 6616 | rq->online = 0; |
6500 | } | 6617 | } |
6501 | } | 6618 | } |
@@ -6536,7 +6653,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu) | |||
6536 | rq = cpu_rq(cpu); | 6653 | rq = cpu_rq(cpu); |
6537 | spin_lock_irqsave(&rq->lock, flags); | 6654 | spin_lock_irqsave(&rq->lock, flags); |
6538 | if (rq->rd) { | 6655 | if (rq->rd) { |
6539 | BUG_ON(!cpu_isset(cpu, rq->rd->span)); | 6656 | BUG_ON(!cpumask_test_cpu(cpu, rq->rd->span)); |
6540 | 6657 | ||
6541 | set_rq_online(rq); | 6658 | set_rq_online(rq); |
6542 | } | 6659 | } |
@@ -6550,7 +6667,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu) | |||
6550 | break; | 6667 | break; |
6551 | /* Unbind it from offline cpu so it can run. Fall thru. */ | 6668 | /* Unbind it from offline cpu so it can run. Fall thru. */ |
6552 | kthread_bind(cpu_rq(cpu)->migration_thread, | 6669 | kthread_bind(cpu_rq(cpu)->migration_thread, |
6553 | any_online_cpu(cpu_online_map)); | 6670 | cpumask_any(cpu_online_mask)); |
6554 | kthread_stop(cpu_rq(cpu)->migration_thread); | 6671 | kthread_stop(cpu_rq(cpu)->migration_thread); |
6555 | cpu_rq(cpu)->migration_thread = NULL; | 6672 | cpu_rq(cpu)->migration_thread = NULL; |
6556 | break; | 6673 | break; |
@@ -6600,7 +6717,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu) | |||
6600 | rq = cpu_rq(cpu); | 6717 | rq = cpu_rq(cpu); |
6601 | spin_lock_irqsave(&rq->lock, flags); | 6718 | spin_lock_irqsave(&rq->lock, flags); |
6602 | if (rq->rd) { | 6719 | if (rq->rd) { |
6603 | BUG_ON(!cpu_isset(cpu, rq->rd->span)); | 6720 | BUG_ON(!cpumask_test_cpu(cpu, rq->rd->span)); |
6604 | set_rq_offline(rq); | 6721 | set_rq_offline(rq); |
6605 | } | 6722 | } |
6606 | spin_unlock_irqrestore(&rq->lock, flags); | 6723 | spin_unlock_irqrestore(&rq->lock, flags); |
@@ -6639,13 +6756,13 @@ early_initcall(migration_init); | |||
6639 | #ifdef CONFIG_SCHED_DEBUG | 6756 | #ifdef CONFIG_SCHED_DEBUG |
6640 | 6757 | ||
6641 | static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level, | 6758 | static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level, |
6642 | cpumask_t *groupmask) | 6759 | struct cpumask *groupmask) |
6643 | { | 6760 | { |
6644 | struct sched_group *group = sd->groups; | 6761 | struct sched_group *group = sd->groups; |
6645 | char str[256]; | 6762 | char str[256]; |
6646 | 6763 | ||
6647 | cpulist_scnprintf(str, sizeof(str), sd->span); | 6764 | cpulist_scnprintf(str, sizeof(str), sched_domain_span(sd)); |
6648 | cpus_clear(*groupmask); | 6765 | cpumask_clear(groupmask); |
6649 | 6766 | ||
6650 | printk(KERN_DEBUG "%*s domain %d: ", level, "", level); | 6767 | printk(KERN_DEBUG "%*s domain %d: ", level, "", level); |
6651 | 6768 | ||
@@ -6659,11 +6776,11 @@ static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level, | |||
6659 | 6776 | ||
6660 | printk(KERN_CONT "span %s level %s\n", str, sd->name); | 6777 | printk(KERN_CONT "span %s level %s\n", str, sd->name); |
6661 | 6778 | ||
6662 | if (!cpu_isset(cpu, sd->span)) { | 6779 | if (!cpumask_test_cpu(cpu, sched_domain_span(sd))) { |
6663 | printk(KERN_ERR "ERROR: domain->span does not contain " | 6780 | printk(KERN_ERR "ERROR: domain->span does not contain " |
6664 | "CPU%d\n", cpu); | 6781 | "CPU%d\n", cpu); |
6665 | } | 6782 | } |
6666 | if (!cpu_isset(cpu, group->cpumask)) { | 6783 | if (!cpumask_test_cpu(cpu, sched_group_cpus(group))) { |
6667 | printk(KERN_ERR "ERROR: domain->groups does not contain" | 6784 | printk(KERN_ERR "ERROR: domain->groups does not contain" |
6668 | " CPU%d\n", cpu); | 6785 | " CPU%d\n", cpu); |
6669 | } | 6786 | } |
@@ -6683,31 +6800,32 @@ static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level, | |||
6683 | break; | 6800 | break; |
6684 | } | 6801 | } |
6685 | 6802 | ||
6686 | if (!cpus_weight(group->cpumask)) { | 6803 | if (!cpumask_weight(sched_group_cpus(group))) { |
6687 | printk(KERN_CONT "\n"); | 6804 | printk(KERN_CONT "\n"); |
6688 | printk(KERN_ERR "ERROR: empty group\n"); | 6805 | printk(KERN_ERR "ERROR: empty group\n"); |
6689 | break; | 6806 | break; |
6690 | } | 6807 | } |
6691 | 6808 | ||
6692 | if (cpus_intersects(*groupmask, group->cpumask)) { | 6809 | if (cpumask_intersects(groupmask, sched_group_cpus(group))) { |
6693 | printk(KERN_CONT "\n"); | 6810 | printk(KERN_CONT "\n"); |
6694 | printk(KERN_ERR "ERROR: repeated CPUs\n"); | 6811 | printk(KERN_ERR "ERROR: repeated CPUs\n"); |
6695 | break; | 6812 | break; |
6696 | } | 6813 | } |
6697 | 6814 | ||
6698 | cpus_or(*groupmask, *groupmask, group->cpumask); | 6815 | cpumask_or(groupmask, groupmask, sched_group_cpus(group)); |
6699 | 6816 | ||
6700 | cpulist_scnprintf(str, sizeof(str), group->cpumask); | 6817 | cpulist_scnprintf(str, sizeof(str), sched_group_cpus(group)); |
6701 | printk(KERN_CONT " %s", str); | 6818 | printk(KERN_CONT " %s", str); |
6702 | 6819 | ||
6703 | group = group->next; | 6820 | group = group->next; |
6704 | } while (group != sd->groups); | 6821 | } while (group != sd->groups); |
6705 | printk(KERN_CONT "\n"); | 6822 | printk(KERN_CONT "\n"); |
6706 | 6823 | ||
6707 | if (!cpus_equal(sd->span, *groupmask)) | 6824 | if (!cpumask_equal(sched_domain_span(sd), groupmask)) |
6708 | printk(KERN_ERR "ERROR: groups don't span domain->span\n"); | 6825 | printk(KERN_ERR "ERROR: groups don't span domain->span\n"); |
6709 | 6826 | ||
6710 | if (sd->parent && !cpus_subset(*groupmask, sd->parent->span)) | 6827 | if (sd->parent && |
6828 | !cpumask_subset(groupmask, sched_domain_span(sd->parent))) | ||
6711 | printk(KERN_ERR "ERROR: parent span is not a superset " | 6829 | printk(KERN_ERR "ERROR: parent span is not a superset " |
6712 | "of domain->span\n"); | 6830 | "of domain->span\n"); |
6713 | return 0; | 6831 | return 0; |
@@ -6715,7 +6833,7 @@ static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level, | |||
6715 | 6833 | ||
6716 | static void sched_domain_debug(struct sched_domain *sd, int cpu) | 6834 | static void sched_domain_debug(struct sched_domain *sd, int cpu) |
6717 | { | 6835 | { |
6718 | cpumask_t *groupmask; | 6836 | cpumask_var_t groupmask; |
6719 | int level = 0; | 6837 | int level = 0; |
6720 | 6838 | ||
6721 | if (!sd) { | 6839 | if (!sd) { |
@@ -6725,8 +6843,7 @@ static void sched_domain_debug(struct sched_domain *sd, int cpu) | |||
6725 | 6843 | ||
6726 | printk(KERN_DEBUG "CPU%d attaching sched-domain:\n", cpu); | 6844 | printk(KERN_DEBUG "CPU%d attaching sched-domain:\n", cpu); |
6727 | 6845 | ||
6728 | groupmask = kmalloc(sizeof(cpumask_t), GFP_KERNEL); | 6846 | if (!alloc_cpumask_var(&groupmask, GFP_KERNEL)) { |
6729 | if (!groupmask) { | ||
6730 | printk(KERN_DEBUG "Cannot load-balance (out of memory)\n"); | 6847 | printk(KERN_DEBUG "Cannot load-balance (out of memory)\n"); |
6731 | return; | 6848 | return; |
6732 | } | 6849 | } |
@@ -6739,7 +6856,7 @@ static void sched_domain_debug(struct sched_domain *sd, int cpu) | |||
6739 | if (!sd) | 6856 | if (!sd) |
6740 | break; | 6857 | break; |
6741 | } | 6858 | } |
6742 | kfree(groupmask); | 6859 | free_cpumask_var(groupmask); |
6743 | } | 6860 | } |
6744 | #else /* !CONFIG_SCHED_DEBUG */ | 6861 | #else /* !CONFIG_SCHED_DEBUG */ |
6745 | # define sched_domain_debug(sd, cpu) do { } while (0) | 6862 | # define sched_domain_debug(sd, cpu) do { } while (0) |
@@ -6747,7 +6864,7 @@ static void sched_domain_debug(struct sched_domain *sd, int cpu) | |||
6747 | 6864 | ||
6748 | static int sd_degenerate(struct sched_domain *sd) | 6865 | static int sd_degenerate(struct sched_domain *sd) |
6749 | { | 6866 | { |
6750 | if (cpus_weight(sd->span) == 1) | 6867 | if (cpumask_weight(sched_domain_span(sd)) == 1) |
6751 | return 1; | 6868 | return 1; |
6752 | 6869 | ||
6753 | /* Following flags need at least 2 groups */ | 6870 | /* Following flags need at least 2 groups */ |
@@ -6778,7 +6895,7 @@ sd_parent_degenerate(struct sched_domain *sd, struct sched_domain *parent) | |||
6778 | if (sd_degenerate(parent)) | 6895 | if (sd_degenerate(parent)) |
6779 | return 1; | 6896 | return 1; |
6780 | 6897 | ||
6781 | if (!cpus_equal(sd->span, parent->span)) | 6898 | if (!cpumask_equal(sched_domain_span(sd), sched_domain_span(parent))) |
6782 | return 0; | 6899 | return 0; |
6783 | 6900 | ||
6784 | /* Does parent contain flags not in child? */ | 6901 | /* Does parent contain flags not in child? */ |
@@ -6802,6 +6919,16 @@ sd_parent_degenerate(struct sched_domain *sd, struct sched_domain *parent) | |||
6802 | return 1; | 6919 | return 1; |
6803 | } | 6920 | } |
6804 | 6921 | ||
6922 | static void free_rootdomain(struct root_domain *rd) | ||
6923 | { | ||
6924 | cpupri_cleanup(&rd->cpupri); | ||
6925 | |||
6926 | free_cpumask_var(rd->rto_mask); | ||
6927 | free_cpumask_var(rd->online); | ||
6928 | free_cpumask_var(rd->span); | ||
6929 | kfree(rd); | ||
6930 | } | ||
6931 | |||
6805 | static void rq_attach_root(struct rq *rq, struct root_domain *rd) | 6932 | static void rq_attach_root(struct rq *rq, struct root_domain *rd) |
6806 | { | 6933 | { |
6807 | unsigned long flags; | 6934 | unsigned long flags; |
@@ -6811,38 +6938,63 @@ static void rq_attach_root(struct rq *rq, struct root_domain *rd) | |||
6811 | if (rq->rd) { | 6938 | if (rq->rd) { |
6812 | struct root_domain *old_rd = rq->rd; | 6939 | struct root_domain *old_rd = rq->rd; |
6813 | 6940 | ||
6814 | if (cpu_isset(rq->cpu, old_rd->online)) | 6941 | if (cpumask_test_cpu(rq->cpu, old_rd->online)) |
6815 | set_rq_offline(rq); | 6942 | set_rq_offline(rq); |
6816 | 6943 | ||
6817 | cpu_clear(rq->cpu, old_rd->span); | 6944 | cpumask_clear_cpu(rq->cpu, old_rd->span); |
6818 | 6945 | ||
6819 | if (atomic_dec_and_test(&old_rd->refcount)) | 6946 | if (atomic_dec_and_test(&old_rd->refcount)) |
6820 | kfree(old_rd); | 6947 | free_rootdomain(old_rd); |
6821 | } | 6948 | } |
6822 | 6949 | ||
6823 | atomic_inc(&rd->refcount); | 6950 | atomic_inc(&rd->refcount); |
6824 | rq->rd = rd; | 6951 | rq->rd = rd; |
6825 | 6952 | ||
6826 | cpu_set(rq->cpu, rd->span); | 6953 | cpumask_set_cpu(rq->cpu, rd->span); |
6827 | if (cpu_isset(rq->cpu, cpu_online_map)) | 6954 | if (cpumask_test_cpu(rq->cpu, cpu_online_mask)) |
6828 | set_rq_online(rq); | 6955 | set_rq_online(rq); |
6829 | 6956 | ||
6830 | spin_unlock_irqrestore(&rq->lock, flags); | 6957 | spin_unlock_irqrestore(&rq->lock, flags); |
6831 | } | 6958 | } |
6832 | 6959 | ||
6833 | static void init_rootdomain(struct root_domain *rd) | 6960 | static int init_rootdomain(struct root_domain *rd, bool bootmem) |
6834 | { | 6961 | { |
6835 | memset(rd, 0, sizeof(*rd)); | 6962 | memset(rd, 0, sizeof(*rd)); |
6836 | 6963 | ||
6837 | cpus_clear(rd->span); | 6964 | if (bootmem) { |
6838 | cpus_clear(rd->online); | 6965 | alloc_bootmem_cpumask_var(&def_root_domain.span); |
6966 | alloc_bootmem_cpumask_var(&def_root_domain.online); | ||
6967 | alloc_bootmem_cpumask_var(&def_root_domain.rto_mask); | ||
6968 | cpupri_init(&rd->cpupri, true); | ||
6969 | return 0; | ||
6970 | } | ||
6971 | |||
6972 | if (!alloc_cpumask_var(&rd->span, GFP_KERNEL)) | ||
6973 | goto free_rd; | ||
6974 | if (!alloc_cpumask_var(&rd->online, GFP_KERNEL)) | ||
6975 | goto free_span; | ||
6976 | if (!alloc_cpumask_var(&rd->rto_mask, GFP_KERNEL)) | ||
6977 | goto free_online; | ||
6839 | 6978 | ||
6840 | cpupri_init(&rd->cpupri); | 6979 | if (cpupri_init(&rd->cpupri, false) != 0) |
6980 | goto free_rto_mask; | ||
6981 | return 0; | ||
6982 | |||
6983 | free_rto_mask: | ||
6984 | free_cpumask_var(rd->rto_mask); | ||
6985 | free_online: | ||
6986 | free_cpumask_var(rd->online); | ||
6987 | free_span: | ||
6988 | free_cpumask_var(rd->span); | ||
6989 | free_rd: | ||
6990 | kfree(rd); | ||
6991 | return -ENOMEM; | ||
6841 | } | 6992 | } |
6842 | 6993 | ||
6843 | static void init_defrootdomain(void) | 6994 | static void init_defrootdomain(void) |
6844 | { | 6995 | { |
6845 | init_rootdomain(&def_root_domain); | 6996 | init_rootdomain(&def_root_domain, true); |
6997 | |||
6846 | atomic_set(&def_root_domain.refcount, 1); | 6998 | atomic_set(&def_root_domain.refcount, 1); |
6847 | } | 6999 | } |
6848 | 7000 | ||
@@ -6854,7 +7006,10 @@ static struct root_domain *alloc_rootdomain(void) | |||
6854 | if (!rd) | 7006 | if (!rd) |
6855 | return NULL; | 7007 | return NULL; |
6856 | 7008 | ||
6857 | init_rootdomain(rd); | 7009 | if (init_rootdomain(rd, false) != 0) { |
7010 | kfree(rd); | ||
7011 | return NULL; | ||
7012 | } | ||
6858 | 7013 | ||
6859 | return rd; | 7014 | return rd; |
6860 | } | 7015 | } |
@@ -6896,19 +7051,12 @@ cpu_attach_domain(struct sched_domain *sd, struct root_domain *rd, int cpu) | |||
6896 | } | 7051 | } |
6897 | 7052 | ||
6898 | /* cpus with isolated domains */ | 7053 | /* cpus with isolated domains */ |
6899 | static cpumask_t cpu_isolated_map = CPU_MASK_NONE; | 7054 | static cpumask_var_t cpu_isolated_map; |
6900 | 7055 | ||
6901 | /* Setup the mask of cpus configured for isolated domains */ | 7056 | /* Setup the mask of cpus configured for isolated domains */ |
6902 | static int __init isolated_cpu_setup(char *str) | 7057 | static int __init isolated_cpu_setup(char *str) |
6903 | { | 7058 | { |
6904 | static int __initdata ints[NR_CPUS]; | 7059 | 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; | 7060 | return 1; |
6913 | } | 7061 | } |
6914 | 7062 | ||
@@ -6917,42 +7065,43 @@ __setup("isolcpus=", isolated_cpu_setup); | |||
6917 | /* | 7065 | /* |
6918 | * init_sched_build_groups takes the cpumask we wish to span, and a pointer | 7066 | * 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 | 7067 | * 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 | 7068 | * 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). | 7069 | * (due to the fact that we keep track of groups covered with a struct cpumask). |
6922 | * | 7070 | * |
6923 | * init_sched_build_groups will build a circular linked list of the groups | 7071 | * 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, | 7072 | * covered by the given span, and will set each group's ->cpumask correctly, |
6925 | * and ->cpu_power to 0. | 7073 | * and ->cpu_power to 0. |
6926 | */ | 7074 | */ |
6927 | static void | 7075 | static void |
6928 | init_sched_build_groups(const cpumask_t *span, const cpumask_t *cpu_map, | 7076 | init_sched_build_groups(const struct cpumask *span, |
6929 | int (*group_fn)(int cpu, const cpumask_t *cpu_map, | 7077 | const struct cpumask *cpu_map, |
7078 | int (*group_fn)(int cpu, const struct cpumask *cpu_map, | ||
6930 | struct sched_group **sg, | 7079 | struct sched_group **sg, |
6931 | cpumask_t *tmpmask), | 7080 | struct cpumask *tmpmask), |
6932 | cpumask_t *covered, cpumask_t *tmpmask) | 7081 | struct cpumask *covered, struct cpumask *tmpmask) |
6933 | { | 7082 | { |
6934 | struct sched_group *first = NULL, *last = NULL; | 7083 | struct sched_group *first = NULL, *last = NULL; |
6935 | int i; | 7084 | int i; |
6936 | 7085 | ||
6937 | cpus_clear(*covered); | 7086 | cpumask_clear(covered); |
6938 | 7087 | ||
6939 | for_each_cpu_mask_nr(i, *span) { | 7088 | for_each_cpu(i, span) { |
6940 | struct sched_group *sg; | 7089 | struct sched_group *sg; |
6941 | int group = group_fn(i, cpu_map, &sg, tmpmask); | 7090 | int group = group_fn(i, cpu_map, &sg, tmpmask); |
6942 | int j; | 7091 | int j; |
6943 | 7092 | ||
6944 | if (cpu_isset(i, *covered)) | 7093 | if (cpumask_test_cpu(i, covered)) |
6945 | continue; | 7094 | continue; |
6946 | 7095 | ||
6947 | cpus_clear(sg->cpumask); | 7096 | cpumask_clear(sched_group_cpus(sg)); |
6948 | sg->__cpu_power = 0; | 7097 | sg->__cpu_power = 0; |
6949 | 7098 | ||
6950 | for_each_cpu_mask_nr(j, *span) { | 7099 | for_each_cpu(j, span) { |
6951 | if (group_fn(j, cpu_map, NULL, tmpmask) != group) | 7100 | if (group_fn(j, cpu_map, NULL, tmpmask) != group) |
6952 | continue; | 7101 | continue; |
6953 | 7102 | ||
6954 | cpu_set(j, *covered); | 7103 | cpumask_set_cpu(j, covered); |
6955 | cpu_set(j, sg->cpumask); | 7104 | cpumask_set_cpu(j, sched_group_cpus(sg)); |
6956 | } | 7105 | } |
6957 | if (!first) | 7106 | if (!first) |
6958 | first = sg; | 7107 | first = sg; |
@@ -7016,23 +7165,21 @@ static int find_next_best_node(int node, nodemask_t *used_nodes) | |||
7016 | * should be one that prevents unnecessary balancing, but also spreads tasks | 7165 | * should be one that prevents unnecessary balancing, but also spreads tasks |
7017 | * out optimally. | 7166 | * out optimally. |
7018 | */ | 7167 | */ |
7019 | static void sched_domain_node_span(int node, cpumask_t *span) | 7168 | static void sched_domain_node_span(int node, struct cpumask *span) |
7020 | { | 7169 | { |
7021 | nodemask_t used_nodes; | 7170 | nodemask_t used_nodes; |
7022 | node_to_cpumask_ptr(nodemask, node); | ||
7023 | int i; | 7171 | int i; |
7024 | 7172 | ||
7025 | cpus_clear(*span); | 7173 | cpumask_clear(span); |
7026 | nodes_clear(used_nodes); | 7174 | nodes_clear(used_nodes); |
7027 | 7175 | ||
7028 | cpus_or(*span, *span, *nodemask); | 7176 | cpumask_or(span, span, cpumask_of_node(node)); |
7029 | node_set(node, used_nodes); | 7177 | node_set(node, used_nodes); |
7030 | 7178 | ||
7031 | for (i = 1; i < SD_NODES_PER_DOMAIN; i++) { | 7179 | for (i = 1; i < SD_NODES_PER_DOMAIN; i++) { |
7032 | int next_node = find_next_best_node(node, &used_nodes); | 7180 | int next_node = find_next_best_node(node, &used_nodes); |
7033 | 7181 | ||
7034 | node_to_cpumask_ptr_next(nodemask, next_node); | 7182 | cpumask_or(span, span, cpumask_of_node(next_node)); |
7035 | cpus_or(*span, *span, *nodemask); | ||
7036 | } | 7183 | } |
7037 | } | 7184 | } |
7038 | #endif /* CONFIG_NUMA */ | 7185 | #endif /* CONFIG_NUMA */ |
@@ -7040,18 +7187,33 @@ static void sched_domain_node_span(int node, cpumask_t *span) | |||
7040 | int sched_smt_power_savings = 0, sched_mc_power_savings = 0; | 7187 | int sched_smt_power_savings = 0, sched_mc_power_savings = 0; |
7041 | 7188 | ||
7042 | /* | 7189 | /* |
7190 | * The cpus mask in sched_group and sched_domain hangs off the end. | ||
7191 | * FIXME: use cpumask_var_t or dynamic percpu alloc to avoid wasting space | ||
7192 | * for nr_cpu_ids < CONFIG_NR_CPUS. | ||
7193 | */ | ||
7194 | struct static_sched_group { | ||
7195 | struct sched_group sg; | ||
7196 | DECLARE_BITMAP(cpus, CONFIG_NR_CPUS); | ||
7197 | }; | ||
7198 | |||
7199 | struct static_sched_domain { | ||
7200 | struct sched_domain sd; | ||
7201 | DECLARE_BITMAP(span, CONFIG_NR_CPUS); | ||
7202 | }; | ||
7203 | |||
7204 | /* | ||
7043 | * SMT sched-domains: | 7205 | * SMT sched-domains: |
7044 | */ | 7206 | */ |
7045 | #ifdef CONFIG_SCHED_SMT | 7207 | #ifdef CONFIG_SCHED_SMT |
7046 | static DEFINE_PER_CPU(struct sched_domain, cpu_domains); | 7208 | static DEFINE_PER_CPU(struct static_sched_domain, cpu_domains); |
7047 | static DEFINE_PER_CPU(struct sched_group, sched_group_cpus); | 7209 | static DEFINE_PER_CPU(struct static_sched_group, sched_group_cpus); |
7048 | 7210 | ||
7049 | static int | 7211 | static int |
7050 | cpu_to_cpu_group(int cpu, const cpumask_t *cpu_map, struct sched_group **sg, | 7212 | cpu_to_cpu_group(int cpu, const struct cpumask *cpu_map, |
7051 | cpumask_t *unused) | 7213 | struct sched_group **sg, struct cpumask *unused) |
7052 | { | 7214 | { |
7053 | if (sg) | 7215 | if (sg) |
7054 | *sg = &per_cpu(sched_group_cpus, cpu); | 7216 | *sg = &per_cpu(sched_group_cpus, cpu).sg; |
7055 | return cpu; | 7217 | return cpu; |
7056 | } | 7218 | } |
7057 | #endif /* CONFIG_SCHED_SMT */ | 7219 | #endif /* CONFIG_SCHED_SMT */ |
@@ -7060,56 +7222,53 @@ cpu_to_cpu_group(int cpu, const cpumask_t *cpu_map, struct sched_group **sg, | |||
7060 | * multi-core sched-domains: | 7222 | * multi-core sched-domains: |
7061 | */ | 7223 | */ |
7062 | #ifdef CONFIG_SCHED_MC | 7224 | #ifdef CONFIG_SCHED_MC |
7063 | static DEFINE_PER_CPU(struct sched_domain, core_domains); | 7225 | static DEFINE_PER_CPU(struct static_sched_domain, core_domains); |
7064 | static DEFINE_PER_CPU(struct sched_group, sched_group_core); | 7226 | static DEFINE_PER_CPU(struct static_sched_group, sched_group_core); |
7065 | #endif /* CONFIG_SCHED_MC */ | 7227 | #endif /* CONFIG_SCHED_MC */ |
7066 | 7228 | ||
7067 | #if defined(CONFIG_SCHED_MC) && defined(CONFIG_SCHED_SMT) | 7229 | #if defined(CONFIG_SCHED_MC) && defined(CONFIG_SCHED_SMT) |
7068 | static int | 7230 | static int |
7069 | cpu_to_core_group(int cpu, const cpumask_t *cpu_map, struct sched_group **sg, | 7231 | cpu_to_core_group(int cpu, const struct cpumask *cpu_map, |
7070 | cpumask_t *mask) | 7232 | struct sched_group **sg, struct cpumask *mask) |
7071 | { | 7233 | { |
7072 | int group; | 7234 | int group; |
7073 | 7235 | ||
7074 | *mask = per_cpu(cpu_sibling_map, cpu); | 7236 | cpumask_and(mask, &per_cpu(cpu_sibling_map, cpu), cpu_map); |
7075 | cpus_and(*mask, *mask, *cpu_map); | 7237 | group = cpumask_first(mask); |
7076 | group = first_cpu(*mask); | ||
7077 | if (sg) | 7238 | if (sg) |
7078 | *sg = &per_cpu(sched_group_core, group); | 7239 | *sg = &per_cpu(sched_group_core, group).sg; |
7079 | return group; | 7240 | return group; |
7080 | } | 7241 | } |
7081 | #elif defined(CONFIG_SCHED_MC) | 7242 | #elif defined(CONFIG_SCHED_MC) |
7082 | static int | 7243 | static int |
7083 | cpu_to_core_group(int cpu, const cpumask_t *cpu_map, struct sched_group **sg, | 7244 | cpu_to_core_group(int cpu, const struct cpumask *cpu_map, |
7084 | cpumask_t *unused) | 7245 | struct sched_group **sg, struct cpumask *unused) |
7085 | { | 7246 | { |
7086 | if (sg) | 7247 | if (sg) |
7087 | *sg = &per_cpu(sched_group_core, cpu); | 7248 | *sg = &per_cpu(sched_group_core, cpu).sg; |
7088 | return cpu; | 7249 | return cpu; |
7089 | } | 7250 | } |
7090 | #endif | 7251 | #endif |
7091 | 7252 | ||
7092 | static DEFINE_PER_CPU(struct sched_domain, phys_domains); | 7253 | static DEFINE_PER_CPU(struct static_sched_domain, phys_domains); |
7093 | static DEFINE_PER_CPU(struct sched_group, sched_group_phys); | 7254 | static DEFINE_PER_CPU(struct static_sched_group, sched_group_phys); |
7094 | 7255 | ||
7095 | static int | 7256 | static int |
7096 | cpu_to_phys_group(int cpu, const cpumask_t *cpu_map, struct sched_group **sg, | 7257 | cpu_to_phys_group(int cpu, const struct cpumask *cpu_map, |
7097 | cpumask_t *mask) | 7258 | struct sched_group **sg, struct cpumask *mask) |
7098 | { | 7259 | { |
7099 | int group; | 7260 | int group; |
7100 | #ifdef CONFIG_SCHED_MC | 7261 | #ifdef CONFIG_SCHED_MC |
7101 | *mask = cpu_coregroup_map(cpu); | 7262 | cpumask_and(mask, cpu_coregroup_mask(cpu), cpu_map); |
7102 | cpus_and(*mask, *mask, *cpu_map); | 7263 | group = cpumask_first(mask); |
7103 | group = first_cpu(*mask); | ||
7104 | #elif defined(CONFIG_SCHED_SMT) | 7264 | #elif defined(CONFIG_SCHED_SMT) |
7105 | *mask = per_cpu(cpu_sibling_map, cpu); | 7265 | cpumask_and(mask, &per_cpu(cpu_sibling_map, cpu), cpu_map); |
7106 | cpus_and(*mask, *mask, *cpu_map); | 7266 | group = cpumask_first(mask); |
7107 | group = first_cpu(*mask); | ||
7108 | #else | 7267 | #else |
7109 | group = cpu; | 7268 | group = cpu; |
7110 | #endif | 7269 | #endif |
7111 | if (sg) | 7270 | if (sg) |
7112 | *sg = &per_cpu(sched_group_phys, group); | 7271 | *sg = &per_cpu(sched_group_phys, group).sg; |
7113 | return group; | 7272 | return group; |
7114 | } | 7273 | } |
7115 | 7274 | ||
@@ -7123,19 +7282,19 @@ static DEFINE_PER_CPU(struct sched_domain, node_domains); | |||
7123 | static struct sched_group ***sched_group_nodes_bycpu; | 7282 | static struct sched_group ***sched_group_nodes_bycpu; |
7124 | 7283 | ||
7125 | static DEFINE_PER_CPU(struct sched_domain, allnodes_domains); | 7284 | static DEFINE_PER_CPU(struct sched_domain, allnodes_domains); |
7126 | static DEFINE_PER_CPU(struct sched_group, sched_group_allnodes); | 7285 | static DEFINE_PER_CPU(struct static_sched_group, sched_group_allnodes); |
7127 | 7286 | ||
7128 | static int cpu_to_allnodes_group(int cpu, const cpumask_t *cpu_map, | 7287 | static int cpu_to_allnodes_group(int cpu, const struct cpumask *cpu_map, |
7129 | struct sched_group **sg, cpumask_t *nodemask) | 7288 | struct sched_group **sg, |
7289 | struct cpumask *nodemask) | ||
7130 | { | 7290 | { |
7131 | int group; | 7291 | int group; |
7132 | 7292 | ||
7133 | *nodemask = node_to_cpumask(cpu_to_node(cpu)); | 7293 | cpumask_and(nodemask, cpumask_of_node(cpu_to_node(cpu)), cpu_map); |
7134 | cpus_and(*nodemask, *nodemask, *cpu_map); | 7294 | group = cpumask_first(nodemask); |
7135 | group = first_cpu(*nodemask); | ||
7136 | 7295 | ||
7137 | if (sg) | 7296 | if (sg) |
7138 | *sg = &per_cpu(sched_group_allnodes, group); | 7297 | *sg = &per_cpu(sched_group_allnodes, group).sg; |
7139 | return group; | 7298 | return group; |
7140 | } | 7299 | } |
7141 | 7300 | ||
@@ -7147,11 +7306,11 @@ static void init_numa_sched_groups_power(struct sched_group *group_head) | |||
7147 | if (!sg) | 7306 | if (!sg) |
7148 | return; | 7307 | return; |
7149 | do { | 7308 | do { |
7150 | for_each_cpu_mask_nr(j, sg->cpumask) { | 7309 | for_each_cpu(j, sched_group_cpus(sg)) { |
7151 | struct sched_domain *sd; | 7310 | struct sched_domain *sd; |
7152 | 7311 | ||
7153 | sd = &per_cpu(phys_domains, j); | 7312 | sd = &per_cpu(phys_domains, j).sd; |
7154 | if (j != first_cpu(sd->groups->cpumask)) { | 7313 | if (j != cpumask_first(sched_group_cpus(sd->groups))) { |
7155 | /* | 7314 | /* |
7156 | * Only add "power" once for each | 7315 | * Only add "power" once for each |
7157 | * physical package. | 7316 | * physical package. |
@@ -7168,11 +7327,12 @@ static void init_numa_sched_groups_power(struct sched_group *group_head) | |||
7168 | 7327 | ||
7169 | #ifdef CONFIG_NUMA | 7328 | #ifdef CONFIG_NUMA |
7170 | /* Free memory allocated for various sched_group structures */ | 7329 | /* Free memory allocated for various sched_group structures */ |
7171 | static void free_sched_groups(const cpumask_t *cpu_map, cpumask_t *nodemask) | 7330 | static void free_sched_groups(const struct cpumask *cpu_map, |
7331 | struct cpumask *nodemask) | ||
7172 | { | 7332 | { |
7173 | int cpu, i; | 7333 | int cpu, i; |
7174 | 7334 | ||
7175 | for_each_cpu_mask_nr(cpu, *cpu_map) { | 7335 | for_each_cpu(cpu, cpu_map) { |
7176 | struct sched_group **sched_group_nodes | 7336 | struct sched_group **sched_group_nodes |
7177 | = sched_group_nodes_bycpu[cpu]; | 7337 | = sched_group_nodes_bycpu[cpu]; |
7178 | 7338 | ||
@@ -7182,9 +7342,8 @@ static void free_sched_groups(const cpumask_t *cpu_map, cpumask_t *nodemask) | |||
7182 | for (i = 0; i < nr_node_ids; i++) { | 7342 | for (i = 0; i < nr_node_ids; i++) { |
7183 | struct sched_group *oldsg, *sg = sched_group_nodes[i]; | 7343 | struct sched_group *oldsg, *sg = sched_group_nodes[i]; |
7184 | 7344 | ||
7185 | *nodemask = node_to_cpumask(i); | 7345 | cpumask_and(nodemask, cpumask_of_node(i), cpu_map); |
7186 | cpus_and(*nodemask, *nodemask, *cpu_map); | 7346 | if (cpumask_empty(nodemask)) |
7187 | if (cpus_empty(*nodemask)) | ||
7188 | continue; | 7347 | continue; |
7189 | 7348 | ||
7190 | if (sg == NULL) | 7349 | if (sg == NULL) |
@@ -7202,7 +7361,8 @@ next_sg: | |||
7202 | } | 7361 | } |
7203 | } | 7362 | } |
7204 | #else /* !CONFIG_NUMA */ | 7363 | #else /* !CONFIG_NUMA */ |
7205 | static void free_sched_groups(const cpumask_t *cpu_map, cpumask_t *nodemask) | 7364 | static void free_sched_groups(const struct cpumask *cpu_map, |
7365 | struct cpumask *nodemask) | ||
7206 | { | 7366 | { |
7207 | } | 7367 | } |
7208 | #endif /* CONFIG_NUMA */ | 7368 | #endif /* CONFIG_NUMA */ |
@@ -7228,7 +7388,7 @@ static void init_sched_groups_power(int cpu, struct sched_domain *sd) | |||
7228 | 7388 | ||
7229 | WARN_ON(!sd || !sd->groups); | 7389 | WARN_ON(!sd || !sd->groups); |
7230 | 7390 | ||
7231 | if (cpu != first_cpu(sd->groups->cpumask)) | 7391 | if (cpu != cpumask_first(sched_group_cpus(sd->groups))) |
7232 | return; | 7392 | return; |
7233 | 7393 | ||
7234 | child = sd->child; | 7394 | child = sd->child; |
@@ -7293,48 +7453,6 @@ SD_INIT_FUNC(CPU) | |||
7293 | SD_INIT_FUNC(MC) | 7453 | SD_INIT_FUNC(MC) |
7294 | #endif | 7454 | #endif |
7295 | 7455 | ||
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; | 7456 | static int default_relax_domain_level = -1; |
7339 | 7457 | ||
7340 | static int __init setup_relax_domain_level(char *str) | 7458 | static int __init setup_relax_domain_level(char *str) |
@@ -7374,17 +7492,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 | 7492 | * Build sched domains for a given set of cpus and attach the sched domains |
7375 | * to the individual cpus | 7493 | * to the individual cpus |
7376 | */ | 7494 | */ |
7377 | static int __build_sched_domains(const cpumask_t *cpu_map, | 7495 | static int __build_sched_domains(const struct cpumask *cpu_map, |
7378 | struct sched_domain_attr *attr) | 7496 | struct sched_domain_attr *attr) |
7379 | { | 7497 | { |
7380 | int i; | 7498 | int i, err = -ENOMEM; |
7381 | struct root_domain *rd; | 7499 | struct root_domain *rd; |
7382 | SCHED_CPUMASK_DECLARE(allmasks); | 7500 | cpumask_var_t nodemask, this_sibling_map, this_core_map, send_covered, |
7383 | cpumask_t *tmpmask; | 7501 | tmpmask; |
7384 | #ifdef CONFIG_NUMA | 7502 | #ifdef CONFIG_NUMA |
7503 | cpumask_var_t domainspan, covered, notcovered; | ||
7385 | struct sched_group **sched_group_nodes = NULL; | 7504 | struct sched_group **sched_group_nodes = NULL; |
7386 | int sd_allnodes = 0; | 7505 | int sd_allnodes = 0; |
7387 | 7506 | ||
7507 | if (!alloc_cpumask_var(&domainspan, GFP_KERNEL)) | ||
7508 | goto out; | ||
7509 | if (!alloc_cpumask_var(&covered, GFP_KERNEL)) | ||
7510 | goto free_domainspan; | ||
7511 | if (!alloc_cpumask_var(¬covered, GFP_KERNEL)) | ||
7512 | goto free_covered; | ||
7513 | #endif | ||
7514 | |||
7515 | if (!alloc_cpumask_var(&nodemask, GFP_KERNEL)) | ||
7516 | goto free_notcovered; | ||
7517 | if (!alloc_cpumask_var(&this_sibling_map, GFP_KERNEL)) | ||
7518 | goto free_nodemask; | ||
7519 | if (!alloc_cpumask_var(&this_core_map, GFP_KERNEL)) | ||
7520 | goto free_this_sibling_map; | ||
7521 | if (!alloc_cpumask_var(&send_covered, GFP_KERNEL)) | ||
7522 | goto free_this_core_map; | ||
7523 | if (!alloc_cpumask_var(&tmpmask, GFP_KERNEL)) | ||
7524 | goto free_send_covered; | ||
7525 | |||
7526 | #ifdef CONFIG_NUMA | ||
7388 | /* | 7527 | /* |
7389 | * Allocate the per-node list of sched groups | 7528 | * Allocate the per-node list of sched groups |
7390 | */ | 7529 | */ |
@@ -7392,54 +7531,35 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7392 | GFP_KERNEL); | 7531 | GFP_KERNEL); |
7393 | if (!sched_group_nodes) { | 7532 | if (!sched_group_nodes) { |
7394 | printk(KERN_WARNING "Can not alloc sched group node list\n"); | 7533 | printk(KERN_WARNING "Can not alloc sched group node list\n"); |
7395 | return -ENOMEM; | 7534 | goto free_tmpmask; |
7396 | } | 7535 | } |
7397 | #endif | 7536 | #endif |
7398 | 7537 | ||
7399 | rd = alloc_rootdomain(); | 7538 | rd = alloc_rootdomain(); |
7400 | if (!rd) { | 7539 | if (!rd) { |
7401 | printk(KERN_WARNING "Cannot alloc root domain\n"); | 7540 | printk(KERN_WARNING "Cannot alloc root domain\n"); |
7402 | #ifdef CONFIG_NUMA | 7541 | goto free_sched_groups; |
7403 | kfree(sched_group_nodes); | ||
7404 | #endif | ||
7405 | return -ENOMEM; | ||
7406 | } | 7542 | } |
7407 | 7543 | ||
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 | ||
7414 | kfree(sched_group_nodes); | ||
7415 | #endif | ||
7416 | return -ENOMEM; | ||
7417 | } | ||
7418 | |||
7419 | tmpmask = (cpumask_t *)allmasks; | ||
7420 | |||
7421 | |||
7422 | #ifdef CONFIG_NUMA | 7544 | #ifdef CONFIG_NUMA |
7423 | sched_group_nodes_bycpu[first_cpu(*cpu_map)] = sched_group_nodes; | 7545 | sched_group_nodes_bycpu[cpumask_first(cpu_map)] = sched_group_nodes; |
7424 | #endif | 7546 | #endif |
7425 | 7547 | ||
7426 | /* | 7548 | /* |
7427 | * Set up domains for cpus specified by the cpu_map. | 7549 | * Set up domains for cpus specified by the cpu_map. |
7428 | */ | 7550 | */ |
7429 | for_each_cpu_mask_nr(i, *cpu_map) { | 7551 | for_each_cpu(i, cpu_map) { |
7430 | struct sched_domain *sd = NULL, *p; | 7552 | struct sched_domain *sd = NULL, *p; |
7431 | SCHED_CPUMASK_VAR(nodemask, allmasks); | ||
7432 | 7553 | ||
7433 | *nodemask = node_to_cpumask(cpu_to_node(i)); | 7554 | cpumask_and(nodemask, cpumask_of_node(cpu_to_node(i)), cpu_map); |
7434 | cpus_and(*nodemask, *nodemask, *cpu_map); | ||
7435 | 7555 | ||
7436 | #ifdef CONFIG_NUMA | 7556 | #ifdef CONFIG_NUMA |
7437 | if (cpus_weight(*cpu_map) > | 7557 | if (cpumask_weight(cpu_map) > |
7438 | SD_NODES_PER_DOMAIN*cpus_weight(*nodemask)) { | 7558 | SD_NODES_PER_DOMAIN*cpumask_weight(nodemask)) { |
7439 | sd = &per_cpu(allnodes_domains, i); | 7559 | sd = &per_cpu(allnodes_domains, i); |
7440 | SD_INIT(sd, ALLNODES); | 7560 | SD_INIT(sd, ALLNODES); |
7441 | set_domain_attribute(sd, attr); | 7561 | set_domain_attribute(sd, attr); |
7442 | sd->span = *cpu_map; | 7562 | cpumask_copy(sched_domain_span(sd), cpu_map); |
7443 | cpu_to_allnodes_group(i, cpu_map, &sd->groups, tmpmask); | 7563 | cpu_to_allnodes_group(i, cpu_map, &sd->groups, tmpmask); |
7444 | p = sd; | 7564 | p = sd; |
7445 | sd_allnodes = 1; | 7565 | sd_allnodes = 1; |
@@ -7449,18 +7569,19 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7449 | sd = &per_cpu(node_domains, i); | 7569 | sd = &per_cpu(node_domains, i); |
7450 | SD_INIT(sd, NODE); | 7570 | SD_INIT(sd, NODE); |
7451 | set_domain_attribute(sd, attr); | 7571 | set_domain_attribute(sd, attr); |
7452 | sched_domain_node_span(cpu_to_node(i), &sd->span); | 7572 | sched_domain_node_span(cpu_to_node(i), sched_domain_span(sd)); |
7453 | sd->parent = p; | 7573 | sd->parent = p; |
7454 | if (p) | 7574 | if (p) |
7455 | p->child = sd; | 7575 | p->child = sd; |
7456 | cpus_and(sd->span, sd->span, *cpu_map); | 7576 | cpumask_and(sched_domain_span(sd), |
7577 | sched_domain_span(sd), cpu_map); | ||
7457 | #endif | 7578 | #endif |
7458 | 7579 | ||
7459 | p = sd; | 7580 | p = sd; |
7460 | sd = &per_cpu(phys_domains, i); | 7581 | sd = &per_cpu(phys_domains, i).sd; |
7461 | SD_INIT(sd, CPU); | 7582 | SD_INIT(sd, CPU); |
7462 | set_domain_attribute(sd, attr); | 7583 | set_domain_attribute(sd, attr); |
7463 | sd->span = *nodemask; | 7584 | cpumask_copy(sched_domain_span(sd), nodemask); |
7464 | sd->parent = p; | 7585 | sd->parent = p; |
7465 | if (p) | 7586 | if (p) |
7466 | p->child = sd; | 7587 | p->child = sd; |
@@ -7468,11 +7589,11 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7468 | 7589 | ||
7469 | #ifdef CONFIG_SCHED_MC | 7590 | #ifdef CONFIG_SCHED_MC |
7470 | p = sd; | 7591 | p = sd; |
7471 | sd = &per_cpu(core_domains, i); | 7592 | sd = &per_cpu(core_domains, i).sd; |
7472 | SD_INIT(sd, MC); | 7593 | SD_INIT(sd, MC); |
7473 | set_domain_attribute(sd, attr); | 7594 | set_domain_attribute(sd, attr); |
7474 | sd->span = cpu_coregroup_map(i); | 7595 | cpumask_and(sched_domain_span(sd), cpu_map, |
7475 | cpus_and(sd->span, sd->span, *cpu_map); | 7596 | cpu_coregroup_mask(i)); |
7476 | sd->parent = p; | 7597 | sd->parent = p; |
7477 | p->child = sd; | 7598 | p->child = sd; |
7478 | cpu_to_core_group(i, cpu_map, &sd->groups, tmpmask); | 7599 | cpu_to_core_group(i, cpu_map, &sd->groups, tmpmask); |
@@ -7480,11 +7601,11 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7480 | 7601 | ||
7481 | #ifdef CONFIG_SCHED_SMT | 7602 | #ifdef CONFIG_SCHED_SMT |
7482 | p = sd; | 7603 | p = sd; |
7483 | sd = &per_cpu(cpu_domains, i); | 7604 | sd = &per_cpu(cpu_domains, i).sd; |
7484 | SD_INIT(sd, SIBLING); | 7605 | SD_INIT(sd, SIBLING); |
7485 | set_domain_attribute(sd, attr); | 7606 | set_domain_attribute(sd, attr); |
7486 | sd->span = per_cpu(cpu_sibling_map, i); | 7607 | cpumask_and(sched_domain_span(sd), |
7487 | cpus_and(sd->span, sd->span, *cpu_map); | 7608 | &per_cpu(cpu_sibling_map, i), cpu_map); |
7488 | sd->parent = p; | 7609 | sd->parent = p; |
7489 | p->child = sd; | 7610 | p->child = sd; |
7490 | cpu_to_cpu_group(i, cpu_map, &sd->groups, tmpmask); | 7611 | cpu_to_cpu_group(i, cpu_map, &sd->groups, tmpmask); |
@@ -7493,13 +7614,10 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7493 | 7614 | ||
7494 | #ifdef CONFIG_SCHED_SMT | 7615 | #ifdef CONFIG_SCHED_SMT |
7495 | /* Set up CPU (sibling) groups */ | 7616 | /* Set up CPU (sibling) groups */ |
7496 | for_each_cpu_mask_nr(i, *cpu_map) { | 7617 | for_each_cpu(i, cpu_map) { |
7497 | SCHED_CPUMASK_VAR(this_sibling_map, allmasks); | 7618 | cpumask_and(this_sibling_map, |
7498 | SCHED_CPUMASK_VAR(send_covered, allmasks); | 7619 | &per_cpu(cpu_sibling_map, i), cpu_map); |
7499 | 7620 | 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; | 7621 | continue; |
7504 | 7622 | ||
7505 | init_sched_build_groups(this_sibling_map, cpu_map, | 7623 | init_sched_build_groups(this_sibling_map, cpu_map, |
@@ -7510,13 +7628,9 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7510 | 7628 | ||
7511 | #ifdef CONFIG_SCHED_MC | 7629 | #ifdef CONFIG_SCHED_MC |
7512 | /* Set up multi-core groups */ | 7630 | /* Set up multi-core groups */ |
7513 | for_each_cpu_mask_nr(i, *cpu_map) { | 7631 | for_each_cpu(i, cpu_map) { |
7514 | SCHED_CPUMASK_VAR(this_core_map, allmasks); | 7632 | cpumask_and(this_core_map, cpu_coregroup_mask(i), cpu_map); |
7515 | SCHED_CPUMASK_VAR(send_covered, allmasks); | 7633 | if (i != cpumask_first(this_core_map)) |
7516 | |||
7517 | *this_core_map = cpu_coregroup_map(i); | ||
7518 | cpus_and(*this_core_map, *this_core_map, *cpu_map); | ||
7519 | if (i != first_cpu(*this_core_map)) | ||
7520 | continue; | 7634 | continue; |
7521 | 7635 | ||
7522 | init_sched_build_groups(this_core_map, cpu_map, | 7636 | init_sched_build_groups(this_core_map, cpu_map, |
@@ -7527,12 +7641,8 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7527 | 7641 | ||
7528 | /* Set up physical groups */ | 7642 | /* Set up physical groups */ |
7529 | for (i = 0; i < nr_node_ids; i++) { | 7643 | for (i = 0; i < nr_node_ids; i++) { |
7530 | SCHED_CPUMASK_VAR(nodemask, allmasks); | 7644 | cpumask_and(nodemask, cpumask_of_node(i), cpu_map); |
7531 | SCHED_CPUMASK_VAR(send_covered, allmasks); | 7645 | if (cpumask_empty(nodemask)) |
7532 | |||
7533 | *nodemask = node_to_cpumask(i); | ||
7534 | cpus_and(*nodemask, *nodemask, *cpu_map); | ||
7535 | if (cpus_empty(*nodemask)) | ||
7536 | continue; | 7646 | continue; |
7537 | 7647 | ||
7538 | init_sched_build_groups(nodemask, cpu_map, | 7648 | init_sched_build_groups(nodemask, cpu_map, |
@@ -7543,8 +7653,6 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7543 | #ifdef CONFIG_NUMA | 7653 | #ifdef CONFIG_NUMA |
7544 | /* Set up node groups */ | 7654 | /* Set up node groups */ |
7545 | if (sd_allnodes) { | 7655 | if (sd_allnodes) { |
7546 | SCHED_CPUMASK_VAR(send_covered, allmasks); | ||
7547 | |||
7548 | init_sched_build_groups(cpu_map, cpu_map, | 7656 | init_sched_build_groups(cpu_map, cpu_map, |
7549 | &cpu_to_allnodes_group, | 7657 | &cpu_to_allnodes_group, |
7550 | send_covered, tmpmask); | 7658 | send_covered, tmpmask); |
@@ -7553,58 +7661,53 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7553 | for (i = 0; i < nr_node_ids; i++) { | 7661 | for (i = 0; i < nr_node_ids; i++) { |
7554 | /* Set up node groups */ | 7662 | /* Set up node groups */ |
7555 | struct sched_group *sg, *prev; | 7663 | 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; | 7664 | int j; |
7560 | 7665 | ||
7561 | *nodemask = node_to_cpumask(i); | 7666 | cpumask_clear(covered); |
7562 | cpus_clear(*covered); | 7667 | cpumask_and(nodemask, cpumask_of_node(i), cpu_map); |
7563 | 7668 | if (cpumask_empty(nodemask)) { | |
7564 | cpus_and(*nodemask, *nodemask, *cpu_map); | ||
7565 | if (cpus_empty(*nodemask)) { | ||
7566 | sched_group_nodes[i] = NULL; | 7669 | sched_group_nodes[i] = NULL; |
7567 | continue; | 7670 | continue; |
7568 | } | 7671 | } |
7569 | 7672 | ||
7570 | sched_domain_node_span(i, domainspan); | 7673 | sched_domain_node_span(i, domainspan); |
7571 | cpus_and(*domainspan, *domainspan, *cpu_map); | 7674 | cpumask_and(domainspan, domainspan, cpu_map); |
7572 | 7675 | ||
7573 | sg = kmalloc_node(sizeof(struct sched_group), GFP_KERNEL, i); | 7676 | sg = kmalloc_node(sizeof(struct sched_group) + cpumask_size(), |
7677 | GFP_KERNEL, i); | ||
7574 | if (!sg) { | 7678 | if (!sg) { |
7575 | printk(KERN_WARNING "Can not alloc domain group for " | 7679 | printk(KERN_WARNING "Can not alloc domain group for " |
7576 | "node %d\n", i); | 7680 | "node %d\n", i); |
7577 | goto error; | 7681 | goto error; |
7578 | } | 7682 | } |
7579 | sched_group_nodes[i] = sg; | 7683 | sched_group_nodes[i] = sg; |
7580 | for_each_cpu_mask_nr(j, *nodemask) { | 7684 | for_each_cpu(j, nodemask) { |
7581 | struct sched_domain *sd; | 7685 | struct sched_domain *sd; |
7582 | 7686 | ||
7583 | sd = &per_cpu(node_domains, j); | 7687 | sd = &per_cpu(node_domains, j); |
7584 | sd->groups = sg; | 7688 | sd->groups = sg; |
7585 | } | 7689 | } |
7586 | sg->__cpu_power = 0; | 7690 | sg->__cpu_power = 0; |
7587 | sg->cpumask = *nodemask; | 7691 | cpumask_copy(sched_group_cpus(sg), nodemask); |
7588 | sg->next = sg; | 7692 | sg->next = sg; |
7589 | cpus_or(*covered, *covered, *nodemask); | 7693 | cpumask_or(covered, covered, nodemask); |
7590 | prev = sg; | 7694 | prev = sg; |
7591 | 7695 | ||
7592 | for (j = 0; j < nr_node_ids; j++) { | 7696 | for (j = 0; j < nr_node_ids; j++) { |
7593 | SCHED_CPUMASK_VAR(notcovered, allmasks); | ||
7594 | int n = (i + j) % nr_node_ids; | 7697 | int n = (i + j) % nr_node_ids; |
7595 | node_to_cpumask_ptr(pnodemask, n); | ||
7596 | 7698 | ||
7597 | cpus_complement(*notcovered, *covered); | 7699 | cpumask_complement(notcovered, covered); |
7598 | cpus_and(*tmpmask, *notcovered, *cpu_map); | 7700 | cpumask_and(tmpmask, notcovered, cpu_map); |
7599 | cpus_and(*tmpmask, *tmpmask, *domainspan); | 7701 | cpumask_and(tmpmask, tmpmask, domainspan); |
7600 | if (cpus_empty(*tmpmask)) | 7702 | if (cpumask_empty(tmpmask)) |
7601 | break; | 7703 | break; |
7602 | 7704 | ||
7603 | cpus_and(*tmpmask, *tmpmask, *pnodemask); | 7705 | cpumask_and(tmpmask, tmpmask, cpumask_of_node(n)); |
7604 | if (cpus_empty(*tmpmask)) | 7706 | if (cpumask_empty(tmpmask)) |
7605 | continue; | 7707 | continue; |
7606 | 7708 | ||
7607 | sg = kmalloc_node(sizeof(struct sched_group), | 7709 | sg = kmalloc_node(sizeof(struct sched_group) + |
7710 | cpumask_size(), | ||
7608 | GFP_KERNEL, i); | 7711 | GFP_KERNEL, i); |
7609 | if (!sg) { | 7712 | if (!sg) { |
7610 | printk(KERN_WARNING | 7713 | printk(KERN_WARNING |
@@ -7612,9 +7715,9 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7612 | goto error; | 7715 | goto error; |
7613 | } | 7716 | } |
7614 | sg->__cpu_power = 0; | 7717 | sg->__cpu_power = 0; |
7615 | sg->cpumask = *tmpmask; | 7718 | cpumask_copy(sched_group_cpus(sg), tmpmask); |
7616 | sg->next = prev->next; | 7719 | sg->next = prev->next; |
7617 | cpus_or(*covered, *covered, *tmpmask); | 7720 | cpumask_or(covered, covered, tmpmask); |
7618 | prev->next = sg; | 7721 | prev->next = sg; |
7619 | prev = sg; | 7722 | prev = sg; |
7620 | } | 7723 | } |
@@ -7623,22 +7726,22 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7623 | 7726 | ||
7624 | /* Calculate CPU power for physical packages and nodes */ | 7727 | /* Calculate CPU power for physical packages and nodes */ |
7625 | #ifdef CONFIG_SCHED_SMT | 7728 | #ifdef CONFIG_SCHED_SMT |
7626 | for_each_cpu_mask_nr(i, *cpu_map) { | 7729 | for_each_cpu(i, cpu_map) { |
7627 | struct sched_domain *sd = &per_cpu(cpu_domains, i); | 7730 | struct sched_domain *sd = &per_cpu(cpu_domains, i).sd; |
7628 | 7731 | ||
7629 | init_sched_groups_power(i, sd); | 7732 | init_sched_groups_power(i, sd); |
7630 | } | 7733 | } |
7631 | #endif | 7734 | #endif |
7632 | #ifdef CONFIG_SCHED_MC | 7735 | #ifdef CONFIG_SCHED_MC |
7633 | for_each_cpu_mask_nr(i, *cpu_map) { | 7736 | for_each_cpu(i, cpu_map) { |
7634 | struct sched_domain *sd = &per_cpu(core_domains, i); | 7737 | struct sched_domain *sd = &per_cpu(core_domains, i).sd; |
7635 | 7738 | ||
7636 | init_sched_groups_power(i, sd); | 7739 | init_sched_groups_power(i, sd); |
7637 | } | 7740 | } |
7638 | #endif | 7741 | #endif |
7639 | 7742 | ||
7640 | for_each_cpu_mask_nr(i, *cpu_map) { | 7743 | for_each_cpu(i, cpu_map) { |
7641 | struct sched_domain *sd = &per_cpu(phys_domains, i); | 7744 | struct sched_domain *sd = &per_cpu(phys_domains, i).sd; |
7642 | 7745 | ||
7643 | init_sched_groups_power(i, sd); | 7746 | init_sched_groups_power(i, sd); |
7644 | } | 7747 | } |
@@ -7650,53 +7753,78 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7650 | if (sd_allnodes) { | 7753 | if (sd_allnodes) { |
7651 | struct sched_group *sg; | 7754 | struct sched_group *sg; |
7652 | 7755 | ||
7653 | cpu_to_allnodes_group(first_cpu(*cpu_map), cpu_map, &sg, | 7756 | cpu_to_allnodes_group(cpumask_first(cpu_map), cpu_map, &sg, |
7654 | tmpmask); | 7757 | tmpmask); |
7655 | init_numa_sched_groups_power(sg); | 7758 | init_numa_sched_groups_power(sg); |
7656 | } | 7759 | } |
7657 | #endif | 7760 | #endif |
7658 | 7761 | ||
7659 | /* Attach the domains */ | 7762 | /* Attach the domains */ |
7660 | for_each_cpu_mask_nr(i, *cpu_map) { | 7763 | for_each_cpu(i, cpu_map) { |
7661 | struct sched_domain *sd; | 7764 | struct sched_domain *sd; |
7662 | #ifdef CONFIG_SCHED_SMT | 7765 | #ifdef CONFIG_SCHED_SMT |
7663 | sd = &per_cpu(cpu_domains, i); | 7766 | sd = &per_cpu(cpu_domains, i).sd; |
7664 | #elif defined(CONFIG_SCHED_MC) | 7767 | #elif defined(CONFIG_SCHED_MC) |
7665 | sd = &per_cpu(core_domains, i); | 7768 | sd = &per_cpu(core_domains, i).sd; |
7666 | #else | 7769 | #else |
7667 | sd = &per_cpu(phys_domains, i); | 7770 | sd = &per_cpu(phys_domains, i).sd; |
7668 | #endif | 7771 | #endif |
7669 | cpu_attach_domain(sd, rd, i); | 7772 | cpu_attach_domain(sd, rd, i); |
7670 | } | 7773 | } |
7671 | 7774 | ||
7672 | sched_cpumask_free(allmasks); | 7775 | err = 0; |
7673 | return 0; | 7776 | |
7777 | free_tmpmask: | ||
7778 | free_cpumask_var(tmpmask); | ||
7779 | free_send_covered: | ||
7780 | free_cpumask_var(send_covered); | ||
7781 | free_this_core_map: | ||
7782 | free_cpumask_var(this_core_map); | ||
7783 | free_this_sibling_map: | ||
7784 | free_cpumask_var(this_sibling_map); | ||
7785 | free_nodemask: | ||
7786 | free_cpumask_var(nodemask); | ||
7787 | free_notcovered: | ||
7788 | #ifdef CONFIG_NUMA | ||
7789 | free_cpumask_var(notcovered); | ||
7790 | free_covered: | ||
7791 | free_cpumask_var(covered); | ||
7792 | free_domainspan: | ||
7793 | free_cpumask_var(domainspan); | ||
7794 | out: | ||
7795 | #endif | ||
7796 | return err; | ||
7797 | |||
7798 | free_sched_groups: | ||
7799 | #ifdef CONFIG_NUMA | ||
7800 | kfree(sched_group_nodes); | ||
7801 | #endif | ||
7802 | goto free_tmpmask; | ||
7674 | 7803 | ||
7675 | #ifdef CONFIG_NUMA | 7804 | #ifdef CONFIG_NUMA |
7676 | error: | 7805 | error: |
7677 | free_sched_groups(cpu_map, tmpmask); | 7806 | free_sched_groups(cpu_map, tmpmask); |
7678 | sched_cpumask_free(allmasks); | 7807 | free_rootdomain(rd); |
7679 | kfree(rd); | 7808 | goto free_tmpmask; |
7680 | return -ENOMEM; | ||
7681 | #endif | 7809 | #endif |
7682 | } | 7810 | } |
7683 | 7811 | ||
7684 | static int build_sched_domains(const cpumask_t *cpu_map) | 7812 | static int build_sched_domains(const struct cpumask *cpu_map) |
7685 | { | 7813 | { |
7686 | return __build_sched_domains(cpu_map, NULL); | 7814 | return __build_sched_domains(cpu_map, NULL); |
7687 | } | 7815 | } |
7688 | 7816 | ||
7689 | static cpumask_t *doms_cur; /* current sched domains */ | 7817 | static struct cpumask *doms_cur; /* current sched domains */ |
7690 | static int ndoms_cur; /* number of sched domains in 'doms_cur' */ | 7818 | static int ndoms_cur; /* number of sched domains in 'doms_cur' */ |
7691 | static struct sched_domain_attr *dattr_cur; | 7819 | static struct sched_domain_attr *dattr_cur; |
7692 | /* attribues of custom domains in 'doms_cur' */ | 7820 | /* attribues of custom domains in 'doms_cur' */ |
7693 | 7821 | ||
7694 | /* | 7822 | /* |
7695 | * Special case: If a kmalloc of a doms_cur partition (array of | 7823 | * Special case: If a kmalloc of a doms_cur partition (array of |
7696 | * cpumask_t) fails, then fallback to a single sched domain, | 7824 | * cpumask) fails, then fallback to a single sched domain, |
7697 | * as determined by the single cpumask_t fallback_doms. | 7825 | * as determined by the single cpumask fallback_doms. |
7698 | */ | 7826 | */ |
7699 | static cpumask_t fallback_doms; | 7827 | static cpumask_var_t fallback_doms; |
7700 | 7828 | ||
7701 | /* | 7829 | /* |
7702 | * arch_update_cpu_topology lets virtualized architectures update the | 7830 | * arch_update_cpu_topology lets virtualized architectures update the |
@@ -7713,16 +7841,16 @@ int __attribute__((weak)) arch_update_cpu_topology(void) | |||
7713 | * For now this just excludes isolated cpus, but could be used to | 7841 | * For now this just excludes isolated cpus, but could be used to |
7714 | * exclude other special cases in the future. | 7842 | * exclude other special cases in the future. |
7715 | */ | 7843 | */ |
7716 | static int arch_init_sched_domains(const cpumask_t *cpu_map) | 7844 | static int arch_init_sched_domains(const struct cpumask *cpu_map) |
7717 | { | 7845 | { |
7718 | int err; | 7846 | int err; |
7719 | 7847 | ||
7720 | arch_update_cpu_topology(); | 7848 | arch_update_cpu_topology(); |
7721 | ndoms_cur = 1; | 7849 | ndoms_cur = 1; |
7722 | doms_cur = kmalloc(sizeof(cpumask_t), GFP_KERNEL); | 7850 | doms_cur = kmalloc(cpumask_size(), GFP_KERNEL); |
7723 | if (!doms_cur) | 7851 | if (!doms_cur) |
7724 | doms_cur = &fallback_doms; | 7852 | doms_cur = fallback_doms; |
7725 | cpus_andnot(*doms_cur, *cpu_map, cpu_isolated_map); | 7853 | cpumask_andnot(doms_cur, cpu_map, cpu_isolated_map); |
7726 | dattr_cur = NULL; | 7854 | dattr_cur = NULL; |
7727 | err = build_sched_domains(doms_cur); | 7855 | err = build_sched_domains(doms_cur); |
7728 | register_sched_domain_sysctl(); | 7856 | register_sched_domain_sysctl(); |
@@ -7730,8 +7858,8 @@ static int arch_init_sched_domains(const cpumask_t *cpu_map) | |||
7730 | return err; | 7858 | return err; |
7731 | } | 7859 | } |
7732 | 7860 | ||
7733 | static void arch_destroy_sched_domains(const cpumask_t *cpu_map, | 7861 | static void arch_destroy_sched_domains(const struct cpumask *cpu_map, |
7734 | cpumask_t *tmpmask) | 7862 | struct cpumask *tmpmask) |
7735 | { | 7863 | { |
7736 | free_sched_groups(cpu_map, tmpmask); | 7864 | free_sched_groups(cpu_map, tmpmask); |
7737 | } | 7865 | } |
@@ -7740,15 +7868,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 | 7868 | * Detach sched domains from a group of cpus specified in cpu_map |
7741 | * These cpus will now be attached to the NULL domain | 7869 | * These cpus will now be attached to the NULL domain |
7742 | */ | 7870 | */ |
7743 | static void detach_destroy_domains(const cpumask_t *cpu_map) | 7871 | static void detach_destroy_domains(const struct cpumask *cpu_map) |
7744 | { | 7872 | { |
7745 | cpumask_t tmpmask; | 7873 | /* Save because hotplug lock held. */ |
7874 | static DECLARE_BITMAP(tmpmask, CONFIG_NR_CPUS); | ||
7746 | int i; | 7875 | int i; |
7747 | 7876 | ||
7748 | for_each_cpu_mask_nr(i, *cpu_map) | 7877 | for_each_cpu(i, cpu_map) |
7749 | cpu_attach_domain(NULL, &def_root_domain, i); | 7878 | cpu_attach_domain(NULL, &def_root_domain, i); |
7750 | synchronize_sched(); | 7879 | synchronize_sched(); |
7751 | arch_destroy_sched_domains(cpu_map, &tmpmask); | 7880 | arch_destroy_sched_domains(cpu_map, to_cpumask(tmpmask)); |
7752 | } | 7881 | } |
7753 | 7882 | ||
7754 | /* handle null as "default" */ | 7883 | /* handle null as "default" */ |
@@ -7773,7 +7902,7 @@ static int dattrs_equal(struct sched_domain_attr *cur, int idx_cur, | |||
7773 | * doms_new[] to the current sched domain partitioning, doms_cur[]. | 7902 | * doms_new[] to the current sched domain partitioning, doms_cur[]. |
7774 | * It destroys each deleted domain and builds each new domain. | 7903 | * It destroys each deleted domain and builds each new domain. |
7775 | * | 7904 | * |
7776 | * 'doms_new' is an array of cpumask_t's of length 'ndoms_new'. | 7905 | * '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 | 7906 | * 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 | 7907 | * 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 | 7908 | * not be load balanced. If the same cpumask appears both in the |
@@ -7787,13 +7916,14 @@ static int dattrs_equal(struct sched_domain_attr *cur, int idx_cur, | |||
7787 | * the single partition 'fallback_doms', it also forces the domains | 7916 | * the single partition 'fallback_doms', it also forces the domains |
7788 | * to be rebuilt. | 7917 | * to be rebuilt. |
7789 | * | 7918 | * |
7790 | * If doms_new == NULL it will be replaced with cpu_online_map. | 7919 | * If doms_new == NULL it will be replaced with cpu_online_mask. |
7791 | * ndoms_new == 0 is a special case for destroying existing domains, | 7920 | * ndoms_new == 0 is a special case for destroying existing domains, |
7792 | * and it will not create the default domain. | 7921 | * and it will not create the default domain. |
7793 | * | 7922 | * |
7794 | * Call with hotplug lock held | 7923 | * Call with hotplug lock held |
7795 | */ | 7924 | */ |
7796 | void partition_sched_domains(int ndoms_new, cpumask_t *doms_new, | 7925 | /* FIXME: Change to struct cpumask *doms_new[] */ |
7926 | void partition_sched_domains(int ndoms_new, struct cpumask *doms_new, | ||
7797 | struct sched_domain_attr *dattr_new) | 7927 | struct sched_domain_attr *dattr_new) |
7798 | { | 7928 | { |
7799 | int i, j, n; | 7929 | int i, j, n; |
@@ -7812,7 +7942,7 @@ void partition_sched_domains(int ndoms_new, cpumask_t *doms_new, | |||
7812 | /* Destroy deleted domains */ | 7942 | /* Destroy deleted domains */ |
7813 | for (i = 0; i < ndoms_cur; i++) { | 7943 | for (i = 0; i < ndoms_cur; i++) { |
7814 | for (j = 0; j < n && !new_topology; j++) { | 7944 | for (j = 0; j < n && !new_topology; j++) { |
7815 | if (cpus_equal(doms_cur[i], doms_new[j]) | 7945 | if (cpumask_equal(&doms_cur[i], &doms_new[j]) |
7816 | && dattrs_equal(dattr_cur, i, dattr_new, j)) | 7946 | && dattrs_equal(dattr_cur, i, dattr_new, j)) |
7817 | goto match1; | 7947 | goto match1; |
7818 | } | 7948 | } |
@@ -7824,15 +7954,15 @@ match1: | |||
7824 | 7954 | ||
7825 | if (doms_new == NULL) { | 7955 | if (doms_new == NULL) { |
7826 | ndoms_cur = 0; | 7956 | ndoms_cur = 0; |
7827 | doms_new = &fallback_doms; | 7957 | doms_new = fallback_doms; |
7828 | cpus_andnot(doms_new[0], cpu_online_map, cpu_isolated_map); | 7958 | cpumask_andnot(&doms_new[0], cpu_online_mask, cpu_isolated_map); |
7829 | WARN_ON_ONCE(dattr_new); | 7959 | WARN_ON_ONCE(dattr_new); |
7830 | } | 7960 | } |
7831 | 7961 | ||
7832 | /* Build new domains */ | 7962 | /* Build new domains */ |
7833 | for (i = 0; i < ndoms_new; i++) { | 7963 | for (i = 0; i < ndoms_new; i++) { |
7834 | for (j = 0; j < ndoms_cur && !new_topology; j++) { | 7964 | for (j = 0; j < ndoms_cur && !new_topology; j++) { |
7835 | if (cpus_equal(doms_new[i], doms_cur[j]) | 7965 | if (cpumask_equal(&doms_new[i], &doms_cur[j]) |
7836 | && dattrs_equal(dattr_new, i, dattr_cur, j)) | 7966 | && dattrs_equal(dattr_new, i, dattr_cur, j)) |
7837 | goto match2; | 7967 | goto match2; |
7838 | } | 7968 | } |
@@ -7844,7 +7974,7 @@ match2: | |||
7844 | } | 7974 | } |
7845 | 7975 | ||
7846 | /* Remember the new sched domains */ | 7976 | /* Remember the new sched domains */ |
7847 | if (doms_cur != &fallback_doms) | 7977 | if (doms_cur != fallback_doms) |
7848 | kfree(doms_cur); | 7978 | kfree(doms_cur); |
7849 | kfree(dattr_cur); /* kfree(NULL) is safe */ | 7979 | kfree(dattr_cur); /* kfree(NULL) is safe */ |
7850 | doms_cur = doms_new; | 7980 | doms_cur = doms_new; |
@@ -7873,14 +8003,25 @@ int arch_reinit_sched_domains(void) | |||
7873 | static ssize_t sched_power_savings_store(const char *buf, size_t count, int smt) | 8003 | static ssize_t sched_power_savings_store(const char *buf, size_t count, int smt) |
7874 | { | 8004 | { |
7875 | int ret; | 8005 | int ret; |
8006 | unsigned int level = 0; | ||
8007 | |||
8008 | if (sscanf(buf, "%u", &level) != 1) | ||
8009 | return -EINVAL; | ||
8010 | |||
8011 | /* | ||
8012 | * level is always be positive so don't check for | ||
8013 | * level < POWERSAVINGS_BALANCE_NONE which is 0 | ||
8014 | * What happens on 0 or 1 byte write, | ||
8015 | * need to check for count as well? | ||
8016 | */ | ||
7876 | 8017 | ||
7877 | if (buf[0] != '0' && buf[0] != '1') | 8018 | if (level >= MAX_POWERSAVINGS_BALANCE_LEVELS) |
7878 | return -EINVAL; | 8019 | return -EINVAL; |
7879 | 8020 | ||
7880 | if (smt) | 8021 | if (smt) |
7881 | sched_smt_power_savings = (buf[0] == '1'); | 8022 | sched_smt_power_savings = level; |
7882 | else | 8023 | else |
7883 | sched_mc_power_savings = (buf[0] == '1'); | 8024 | sched_mc_power_savings = level; |
7884 | 8025 | ||
7885 | ret = arch_reinit_sched_domains(); | 8026 | ret = arch_reinit_sched_domains(); |
7886 | 8027 | ||
@@ -7984,7 +8125,9 @@ static int update_runtime(struct notifier_block *nfb, | |||
7984 | 8125 | ||
7985 | void __init sched_init_smp(void) | 8126 | void __init sched_init_smp(void) |
7986 | { | 8127 | { |
7987 | cpumask_t non_isolated_cpus; | 8128 | cpumask_var_t non_isolated_cpus; |
8129 | |||
8130 | alloc_cpumask_var(&non_isolated_cpus, GFP_KERNEL); | ||
7988 | 8131 | ||
7989 | #if defined(CONFIG_NUMA) | 8132 | #if defined(CONFIG_NUMA) |
7990 | sched_group_nodes_bycpu = kzalloc(nr_cpu_ids * sizeof(void **), | 8133 | sched_group_nodes_bycpu = kzalloc(nr_cpu_ids * sizeof(void **), |
@@ -7993,10 +8136,10 @@ void __init sched_init_smp(void) | |||
7993 | #endif | 8136 | #endif |
7994 | get_online_cpus(); | 8137 | get_online_cpus(); |
7995 | mutex_lock(&sched_domains_mutex); | 8138 | mutex_lock(&sched_domains_mutex); |
7996 | arch_init_sched_domains(&cpu_online_map); | 8139 | arch_init_sched_domains(cpu_online_mask); |
7997 | cpus_andnot(non_isolated_cpus, cpu_possible_map, cpu_isolated_map); | 8140 | cpumask_andnot(non_isolated_cpus, cpu_possible_mask, cpu_isolated_map); |
7998 | if (cpus_empty(non_isolated_cpus)) | 8141 | if (cpumask_empty(non_isolated_cpus)) |
7999 | cpu_set(smp_processor_id(), non_isolated_cpus); | 8142 | cpumask_set_cpu(smp_processor_id(), non_isolated_cpus); |
8000 | mutex_unlock(&sched_domains_mutex); | 8143 | mutex_unlock(&sched_domains_mutex); |
8001 | put_online_cpus(); | 8144 | put_online_cpus(); |
8002 | 8145 | ||
@@ -8011,9 +8154,13 @@ void __init sched_init_smp(void) | |||
8011 | init_hrtick(); | 8154 | init_hrtick(); |
8012 | 8155 | ||
8013 | /* Move init over to a non-isolated CPU */ | 8156 | /* Move init over to a non-isolated CPU */ |
8014 | if (set_cpus_allowed_ptr(current, &non_isolated_cpus) < 0) | 8157 | if (set_cpus_allowed_ptr(current, non_isolated_cpus) < 0) |
8015 | BUG(); | 8158 | BUG(); |
8016 | sched_init_granularity(); | 8159 | sched_init_granularity(); |
8160 | free_cpumask_var(non_isolated_cpus); | ||
8161 | |||
8162 | alloc_cpumask_var(&fallback_doms, GFP_KERNEL); | ||
8163 | init_sched_rt_class(); | ||
8017 | } | 8164 | } |
8018 | #else | 8165 | #else |
8019 | void __init sched_init_smp(void) | 8166 | void __init sched_init_smp(void) |
@@ -8328,6 +8475,15 @@ void __init sched_init(void) | |||
8328 | */ | 8475 | */ |
8329 | current->sched_class = &fair_sched_class; | 8476 | current->sched_class = &fair_sched_class; |
8330 | 8477 | ||
8478 | /* Allocate the nohz_cpu_mask if CONFIG_CPUMASK_OFFSTACK */ | ||
8479 | alloc_bootmem_cpumask_var(&nohz_cpu_mask); | ||
8480 | #ifdef CONFIG_SMP | ||
8481 | #ifdef CONFIG_NO_HZ | ||
8482 | alloc_bootmem_cpumask_var(&nohz.cpu_mask); | ||
8483 | #endif | ||
8484 | alloc_bootmem_cpumask_var(&cpu_isolated_map); | ||
8485 | #endif /* SMP */ | ||
8486 | |||
8331 | scheduler_running = 1; | 8487 | scheduler_running = 1; |
8332 | } | 8488 | } |
8333 | 8489 | ||