diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2008-12-13 06:25:51 -0500 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2008-12-13 06:25:51 -0500 |
commit | 968ea6d80e395cf11a51143cfa1b9a14ada676df (patch) | |
tree | dc2acec8c9bdced33afe1e273ee5e0b0b93d2703 /kernel/sched.c | |
parent | 7be7585393d311866653564fbcd10a3232773c0b (diff) | |
parent | 8299608f140ae321e4eb5d1306184265d2b9511e (diff) |
Merge ../linux-2.6-x86
Conflicts:
arch/x86/kernel/io_apic.c
kernel/sched.c
kernel/sched_stats.h
Diffstat (limited to 'kernel/sched.c')
-rw-r--r-- | kernel/sched.c | 1148 |
1 files changed, 597 insertions, 551 deletions
diff --git a/kernel/sched.c b/kernel/sched.c index d2d16d1273b1..b309027bf9e8 100644 --- a/kernel/sched.c +++ b/kernel/sched.c | |||
@@ -118,6 +118,12 @@ | |||
118 | */ | 118 | */ |
119 | #define RUNTIME_INF ((u64)~0ULL) | 119 | #define RUNTIME_INF ((u64)~0ULL) |
120 | 120 | ||
121 | DEFINE_TRACE(sched_wait_task); | ||
122 | DEFINE_TRACE(sched_wakeup); | ||
123 | DEFINE_TRACE(sched_wakeup_new); | ||
124 | DEFINE_TRACE(sched_switch); | ||
125 | DEFINE_TRACE(sched_migrate_task); | ||
126 | |||
121 | #ifdef CONFIG_SMP | 127 | #ifdef CONFIG_SMP |
122 | /* | 128 | /* |
123 | * Divide a load by a sched group cpu_power : (load / sg->__cpu_power) | 129 | * Divide a load by a sched group cpu_power : (load / sg->__cpu_power) |
@@ -261,6 +267,10 @@ struct task_group { | |||
261 | struct cgroup_subsys_state css; | 267 | struct cgroup_subsys_state css; |
262 | #endif | 268 | #endif |
263 | 269 | ||
270 | #ifdef CONFIG_USER_SCHED | ||
271 | uid_t uid; | ||
272 | #endif | ||
273 | |||
264 | #ifdef CONFIG_FAIR_GROUP_SCHED | 274 | #ifdef CONFIG_FAIR_GROUP_SCHED |
265 | /* schedulable entities of this group on each cpu */ | 275 | /* schedulable entities of this group on each cpu */ |
266 | struct sched_entity **se; | 276 | struct sched_entity **se; |
@@ -286,6 +296,12 @@ struct task_group { | |||
286 | 296 | ||
287 | #ifdef CONFIG_USER_SCHED | 297 | #ifdef CONFIG_USER_SCHED |
288 | 298 | ||
299 | /* Helper function to pass uid information to create_sched_user() */ | ||
300 | void set_tg_uid(struct user_struct *user) | ||
301 | { | ||
302 | user->tg->uid = user->uid; | ||
303 | } | ||
304 | |||
289 | /* | 305 | /* |
290 | * Root task group. | 306 | * Root task group. |
291 | * Every UID task group (including init_task_group aka UID-0) will | 307 | * Every UID task group (including init_task_group aka UID-0) will |
@@ -481,14 +497,14 @@ struct rt_rq { | |||
481 | */ | 497 | */ |
482 | struct root_domain { | 498 | struct root_domain { |
483 | atomic_t refcount; | 499 | atomic_t refcount; |
484 | cpumask_t span; | 500 | cpumask_var_t span; |
485 | cpumask_t online; | 501 | cpumask_var_t online; |
486 | 502 | ||
487 | /* | 503 | /* |
488 | * The "RT overload" flag: it gets set if a CPU has more than | 504 | * The "RT overload" flag: it gets set if a CPU has more than |
489 | * one runnable RT task. | 505 | * one runnable RT task. |
490 | */ | 506 | */ |
491 | cpumask_t rto_mask; | 507 | cpumask_var_t rto_mask; |
492 | atomic_t rto_count; | 508 | atomic_t rto_count; |
493 | #ifdef CONFIG_SMP | 509 | #ifdef CONFIG_SMP |
494 | struct cpupri cpupri; | 510 | struct cpupri cpupri; |
@@ -703,45 +719,18 @@ static __read_mostly char *sched_feat_names[] = { | |||
703 | 719 | ||
704 | #undef SCHED_FEAT | 720 | #undef SCHED_FEAT |
705 | 721 | ||
706 | static int sched_feat_open(struct inode *inode, struct file *filp) | 722 | static int sched_feat_show(struct seq_file *m, void *v) |
707 | { | 723 | { |
708 | filp->private_data = inode->i_private; | ||
709 | return 0; | ||
710 | } | ||
711 | |||
712 | static ssize_t | ||
713 | sched_feat_read(struct file *filp, char __user *ubuf, | ||
714 | size_t cnt, loff_t *ppos) | ||
715 | { | ||
716 | char *buf; | ||
717 | int r = 0; | ||
718 | int len = 0; | ||
719 | int i; | 724 | int i; |
720 | 725 | ||
721 | for (i = 0; sched_feat_names[i]; i++) { | 726 | for (i = 0; sched_feat_names[i]; i++) { |
722 | len += strlen(sched_feat_names[i]); | 727 | if (!(sysctl_sched_features & (1UL << i))) |
723 | len += 4; | 728 | seq_puts(m, "NO_"); |
724 | } | 729 | seq_printf(m, "%s ", sched_feat_names[i]); |
725 | |||
726 | buf = kmalloc(len + 2, GFP_KERNEL); | ||
727 | if (!buf) | ||
728 | return -ENOMEM; | ||
729 | |||
730 | for (i = 0; sched_feat_names[i]; i++) { | ||
731 | if (sysctl_sched_features & (1UL << i)) | ||
732 | r += sprintf(buf + r, "%s ", sched_feat_names[i]); | ||
733 | else | ||
734 | r += sprintf(buf + r, "NO_%s ", sched_feat_names[i]); | ||
735 | } | 730 | } |
731 | seq_puts(m, "\n"); | ||
736 | 732 | ||
737 | r += sprintf(buf + r, "\n"); | 733 | return 0; |
738 | WARN_ON(r >= len + 2); | ||
739 | |||
740 | r = simple_read_from_buffer(ubuf, cnt, ppos, buf, r); | ||
741 | |||
742 | kfree(buf); | ||
743 | |||
744 | return r; | ||
745 | } | 734 | } |
746 | 735 | ||
747 | static ssize_t | 736 | static ssize_t |
@@ -786,10 +775,17 @@ sched_feat_write(struct file *filp, const char __user *ubuf, | |||
786 | return cnt; | 775 | return cnt; |
787 | } | 776 | } |
788 | 777 | ||
778 | static int sched_feat_open(struct inode *inode, struct file *filp) | ||
779 | { | ||
780 | return single_open(filp, sched_feat_show, NULL); | ||
781 | } | ||
782 | |||
789 | static struct file_operations sched_feat_fops = { | 783 | static struct file_operations sched_feat_fops = { |
790 | .open = sched_feat_open, | 784 | .open = sched_feat_open, |
791 | .read = sched_feat_read, | 785 | .write = sched_feat_write, |
792 | .write = sched_feat_write, | 786 | .read = seq_read, |
787 | .llseek = seq_lseek, | ||
788 | .release = single_release, | ||
793 | }; | 789 | }; |
794 | 790 | ||
795 | static __init int sched_init_debug(void) | 791 | static __init int sched_init_debug(void) |
@@ -1474,27 +1470,13 @@ static void | |||
1474 | update_group_shares_cpu(struct task_group *tg, int cpu, | 1470 | update_group_shares_cpu(struct task_group *tg, int cpu, |
1475 | unsigned long sd_shares, unsigned long sd_rq_weight) | 1471 | unsigned long sd_shares, unsigned long sd_rq_weight) |
1476 | { | 1472 | { |
1477 | int boost = 0; | ||
1478 | unsigned long shares; | 1473 | unsigned long shares; |
1479 | unsigned long rq_weight; | 1474 | unsigned long rq_weight; |
1480 | 1475 | ||
1481 | if (!tg->se[cpu]) | 1476 | if (!tg->se[cpu]) |
1482 | return; | 1477 | return; |
1483 | 1478 | ||
1484 | rq_weight = tg->cfs_rq[cpu]->load.weight; | 1479 | rq_weight = tg->cfs_rq[cpu]->rq_weight; |
1485 | |||
1486 | /* | ||
1487 | * If there are currently no tasks on the cpu pretend there is one of | ||
1488 | * average load so that when a new task gets to run here it will not | ||
1489 | * get delayed by group starvation. | ||
1490 | */ | ||
1491 | if (!rq_weight) { | ||
1492 | boost = 1; | ||
1493 | rq_weight = NICE_0_LOAD; | ||
1494 | } | ||
1495 | |||
1496 | if (unlikely(rq_weight > sd_rq_weight)) | ||
1497 | rq_weight = sd_rq_weight; | ||
1498 | 1480 | ||
1499 | /* | 1481 | /* |
1500 | * \Sum shares * rq_weight | 1482 | * \Sum shares * rq_weight |
@@ -1502,7 +1484,7 @@ update_group_shares_cpu(struct task_group *tg, int cpu, | |||
1502 | * \Sum rq_weight | 1484 | * \Sum rq_weight |
1503 | * | 1485 | * |
1504 | */ | 1486 | */ |
1505 | shares = (sd_shares * rq_weight) / (sd_rq_weight + 1); | 1487 | shares = (sd_shares * rq_weight) / sd_rq_weight; |
1506 | shares = clamp_t(unsigned long, shares, MIN_SHARES, MAX_SHARES); | 1488 | shares = clamp_t(unsigned long, shares, MIN_SHARES, MAX_SHARES); |
1507 | 1489 | ||
1508 | if (abs(shares - tg->se[cpu]->load.weight) > | 1490 | if (abs(shares - tg->se[cpu]->load.weight) > |
@@ -1511,11 +1493,7 @@ update_group_shares_cpu(struct task_group *tg, int cpu, | |||
1511 | unsigned long flags; | 1493 | unsigned long flags; |
1512 | 1494 | ||
1513 | spin_lock_irqsave(&rq->lock, flags); | 1495 | spin_lock_irqsave(&rq->lock, flags); |
1514 | /* | 1496 | tg->cfs_rq[cpu]->shares = shares; |
1515 | * record the actual number of shares, not the boosted amount. | ||
1516 | */ | ||
1517 | tg->cfs_rq[cpu]->shares = boost ? 0 : shares; | ||
1518 | tg->cfs_rq[cpu]->rq_weight = rq_weight; | ||
1519 | 1497 | ||
1520 | __set_se_shares(tg->se[cpu], shares); | 1498 | __set_se_shares(tg->se[cpu], shares); |
1521 | spin_unlock_irqrestore(&rq->lock, flags); | 1499 | spin_unlock_irqrestore(&rq->lock, flags); |
@@ -1529,13 +1507,23 @@ update_group_shares_cpu(struct task_group *tg, int cpu, | |||
1529 | */ | 1507 | */ |
1530 | static int tg_shares_up(struct task_group *tg, void *data) | 1508 | static int tg_shares_up(struct task_group *tg, void *data) |
1531 | { | 1509 | { |
1532 | unsigned long rq_weight = 0; | 1510 | unsigned long weight, rq_weight = 0; |
1533 | unsigned long shares = 0; | 1511 | unsigned long shares = 0; |
1534 | struct sched_domain *sd = data; | 1512 | struct sched_domain *sd = data; |
1535 | int i; | 1513 | int i; |
1536 | 1514 | ||
1537 | for_each_cpu_mask(i, sd->span) { | 1515 | for_each_cpu(i, sched_domain_span(sd)) { |
1538 | rq_weight += tg->cfs_rq[i]->load.weight; | 1516 | /* |
1517 | * If there are currently no tasks on the cpu pretend there | ||
1518 | * is one of average load so that when a new task gets to | ||
1519 | * run here it will not get delayed by group starvation. | ||
1520 | */ | ||
1521 | weight = tg->cfs_rq[i]->load.weight; | ||
1522 | if (!weight) | ||
1523 | weight = NICE_0_LOAD; | ||
1524 | |||
1525 | tg->cfs_rq[i]->rq_weight = weight; | ||
1526 | rq_weight += weight; | ||
1539 | shares += tg->cfs_rq[i]->shares; | 1527 | shares += tg->cfs_rq[i]->shares; |
1540 | } | 1528 | } |
1541 | 1529 | ||
@@ -1545,10 +1533,7 @@ static int tg_shares_up(struct task_group *tg, void *data) | |||
1545 | if (!sd->parent || !(sd->parent->flags & SD_LOAD_BALANCE)) | 1533 | if (!sd->parent || !(sd->parent->flags & SD_LOAD_BALANCE)) |
1546 | shares = tg->shares; | 1534 | shares = tg->shares; |
1547 | 1535 | ||
1548 | if (!rq_weight) | 1536 | for_each_cpu(i, sched_domain_span(sd)) |
1549 | rq_weight = cpus_weight(sd->span) * NICE_0_LOAD; | ||
1550 | |||
1551 | for_each_cpu_mask(i, sd->span) | ||
1552 | update_group_shares_cpu(tg, i, shares, rq_weight); | 1537 | update_group_shares_cpu(tg, i, shares, rq_weight); |
1553 | 1538 | ||
1554 | return 0; | 1539 | return 0; |
@@ -1612,6 +1597,39 @@ static inline void update_shares_locked(struct rq *rq, struct sched_domain *sd) | |||
1612 | 1597 | ||
1613 | #endif | 1598 | #endif |
1614 | 1599 | ||
1600 | /* | ||
1601 | * double_lock_balance - lock the busiest runqueue, this_rq is locked already. | ||
1602 | */ | ||
1603 | static int double_lock_balance(struct rq *this_rq, struct rq *busiest) | ||
1604 | __releases(this_rq->lock) | ||
1605 | __acquires(busiest->lock) | ||
1606 | __acquires(this_rq->lock) | ||
1607 | { | ||
1608 | int ret = 0; | ||
1609 | |||
1610 | if (unlikely(!irqs_disabled())) { | ||
1611 | /* printk() doesn't work good under rq->lock */ | ||
1612 | spin_unlock(&this_rq->lock); | ||
1613 | BUG_ON(1); | ||
1614 | } | ||
1615 | if (unlikely(!spin_trylock(&busiest->lock))) { | ||
1616 | if (busiest < this_rq) { | ||
1617 | spin_unlock(&this_rq->lock); | ||
1618 | spin_lock(&busiest->lock); | ||
1619 | spin_lock_nested(&this_rq->lock, SINGLE_DEPTH_NESTING); | ||
1620 | ret = 1; | ||
1621 | } else | ||
1622 | spin_lock_nested(&busiest->lock, SINGLE_DEPTH_NESTING); | ||
1623 | } | ||
1624 | return ret; | ||
1625 | } | ||
1626 | |||
1627 | static inline void double_unlock_balance(struct rq *this_rq, struct rq *busiest) | ||
1628 | __releases(busiest->lock) | ||
1629 | { | ||
1630 | spin_unlock(&busiest->lock); | ||
1631 | lock_set_subclass(&this_rq->lock.dep_map, 0, _RET_IP_); | ||
1632 | } | ||
1615 | #endif | 1633 | #endif |
1616 | 1634 | ||
1617 | #ifdef CONFIG_FAIR_GROUP_SCHED | 1635 | #ifdef CONFIG_FAIR_GROUP_SCHED |
@@ -2079,15 +2097,17 @@ find_idlest_group(struct sched_domain *sd, struct task_struct *p, int this_cpu) | |||
2079 | int i; | 2097 | int i; |
2080 | 2098 | ||
2081 | /* Skip over this group if it has no CPUs allowed */ | 2099 | /* Skip over this group if it has no CPUs allowed */ |
2082 | if (!cpus_intersects(group->cpumask, p->cpus_allowed)) | 2100 | if (!cpumask_intersects(sched_group_cpus(group), |
2101 | &p->cpus_allowed)) | ||
2083 | continue; | 2102 | continue; |
2084 | 2103 | ||
2085 | local_group = cpu_isset(this_cpu, group->cpumask); | 2104 | local_group = cpumask_test_cpu(this_cpu, |
2105 | sched_group_cpus(group)); | ||
2086 | 2106 | ||
2087 | /* Tally up the load of all CPUs in the group */ | 2107 | /* Tally up the load of all CPUs in the group */ |
2088 | avg_load = 0; | 2108 | avg_load = 0; |
2089 | 2109 | ||
2090 | for_each_cpu_mask_nr(i, group->cpumask) { | 2110 | for_each_cpu(i, sched_group_cpus(group)) { |
2091 | /* Bias balancing toward cpus of our domain */ | 2111 | /* Bias balancing toward cpus of our domain */ |
2092 | if (local_group) | 2112 | if (local_group) |
2093 | load = source_load(i, load_idx); | 2113 | load = source_load(i, load_idx); |
@@ -2119,17 +2139,14 @@ find_idlest_group(struct sched_domain *sd, struct task_struct *p, int this_cpu) | |||
2119 | * find_idlest_cpu - find the idlest cpu among the cpus in group. | 2139 | * find_idlest_cpu - find the idlest cpu among the cpus in group. |
2120 | */ | 2140 | */ |
2121 | static int | 2141 | static int |
2122 | find_idlest_cpu(struct sched_group *group, struct task_struct *p, int this_cpu, | 2142 | find_idlest_cpu(struct sched_group *group, struct task_struct *p, int this_cpu) |
2123 | cpumask_t *tmp) | ||
2124 | { | 2143 | { |
2125 | unsigned long load, min_load = ULONG_MAX; | 2144 | unsigned long load, min_load = ULONG_MAX; |
2126 | int idlest = -1; | 2145 | int idlest = -1; |
2127 | int i; | 2146 | int i; |
2128 | 2147 | ||
2129 | /* Traverse only the allowed CPUs */ | 2148 | /* Traverse only the allowed CPUs */ |
2130 | cpus_and(*tmp, group->cpumask, p->cpus_allowed); | 2149 | for_each_cpu_and(i, sched_group_cpus(group), &p->cpus_allowed) { |
2131 | |||
2132 | for_each_cpu_mask_nr(i, *tmp) { | ||
2133 | load = weighted_cpuload(i); | 2150 | load = weighted_cpuload(i); |
2134 | 2151 | ||
2135 | if (load < min_load || (load == min_load && i == this_cpu)) { | 2152 | if (load < min_load || (load == min_load && i == this_cpu)) { |
@@ -2171,7 +2188,6 @@ static int sched_balance_self(int cpu, int flag) | |||
2171 | update_shares(sd); | 2188 | update_shares(sd); |
2172 | 2189 | ||
2173 | while (sd) { | 2190 | while (sd) { |
2174 | cpumask_t span, tmpmask; | ||
2175 | struct sched_group *group; | 2191 | struct sched_group *group; |
2176 | int new_cpu, weight; | 2192 | int new_cpu, weight; |
2177 | 2193 | ||
@@ -2180,14 +2196,13 @@ static int sched_balance_self(int cpu, int flag) | |||
2180 | continue; | 2196 | continue; |
2181 | } | 2197 | } |
2182 | 2198 | ||
2183 | span = sd->span; | ||
2184 | group = find_idlest_group(sd, t, cpu); | 2199 | group = find_idlest_group(sd, t, cpu); |
2185 | if (!group) { | 2200 | if (!group) { |
2186 | sd = sd->child; | 2201 | sd = sd->child; |
2187 | continue; | 2202 | continue; |
2188 | } | 2203 | } |
2189 | 2204 | ||
2190 | new_cpu = find_idlest_cpu(group, t, cpu, &tmpmask); | 2205 | new_cpu = find_idlest_cpu(group, t, cpu); |
2191 | if (new_cpu == -1 || new_cpu == cpu) { | 2206 | if (new_cpu == -1 || new_cpu == cpu) { |
2192 | /* Now try balancing at a lower domain level of cpu */ | 2207 | /* Now try balancing at a lower domain level of cpu */ |
2193 | sd = sd->child; | 2208 | sd = sd->child; |
@@ -2196,10 +2211,10 @@ static int sched_balance_self(int cpu, int flag) | |||
2196 | 2211 | ||
2197 | /* Now try balancing at a lower domain level of new_cpu */ | 2212 | /* Now try balancing at a lower domain level of new_cpu */ |
2198 | cpu = new_cpu; | 2213 | cpu = new_cpu; |
2214 | weight = cpumask_weight(sched_domain_span(sd)); | ||
2199 | sd = NULL; | 2215 | sd = NULL; |
2200 | weight = cpus_weight(span); | ||
2201 | for_each_domain(cpu, tmp) { | 2216 | for_each_domain(cpu, tmp) { |
2202 | if (weight <= cpus_weight(tmp->span)) | 2217 | if (weight <= cpumask_weight(sched_domain_span(tmp))) |
2203 | break; | 2218 | break; |
2204 | if (tmp->flags & flag) | 2219 | if (tmp->flags & flag) |
2205 | sd = tmp; | 2220 | sd = tmp; |
@@ -2244,7 +2259,7 @@ static int try_to_wake_up(struct task_struct *p, unsigned int state, int sync) | |||
2244 | cpu = task_cpu(p); | 2259 | cpu = task_cpu(p); |
2245 | 2260 | ||
2246 | for_each_domain(this_cpu, sd) { | 2261 | for_each_domain(this_cpu, sd) { |
2247 | if (cpu_isset(cpu, sd->span)) { | 2262 | if (cpumask_test_cpu(cpu, sched_domain_span(sd))) { |
2248 | update_shares(sd); | 2263 | update_shares(sd); |
2249 | break; | 2264 | break; |
2250 | } | 2265 | } |
@@ -2292,7 +2307,7 @@ static int try_to_wake_up(struct task_struct *p, unsigned int state, int sync) | |||
2292 | else { | 2307 | else { |
2293 | struct sched_domain *sd; | 2308 | struct sched_domain *sd; |
2294 | for_each_domain(this_cpu, sd) { | 2309 | for_each_domain(this_cpu, sd) { |
2295 | if (cpu_isset(cpu, sd->span)) { | 2310 | if (cpumask_test_cpu(cpu, sched_domain_span(sd))) { |
2296 | schedstat_inc(sd, ttwu_wake_remote); | 2311 | schedstat_inc(sd, ttwu_wake_remote); |
2297 | break; | 2312 | break; |
2298 | } | 2313 | } |
@@ -2812,40 +2827,6 @@ static void double_rq_unlock(struct rq *rq1, struct rq *rq2) | |||
2812 | } | 2827 | } |
2813 | 2828 | ||
2814 | /* | 2829 | /* |
2815 | * double_lock_balance - lock the busiest runqueue, this_rq is locked already. | ||
2816 | */ | ||
2817 | static int double_lock_balance(struct rq *this_rq, struct rq *busiest) | ||
2818 | __releases(this_rq->lock) | ||
2819 | __acquires(busiest->lock) | ||
2820 | __acquires(this_rq->lock) | ||
2821 | { | ||
2822 | int ret = 0; | ||
2823 | |||
2824 | if (unlikely(!irqs_disabled())) { | ||
2825 | /* printk() doesn't work good under rq->lock */ | ||
2826 | spin_unlock(&this_rq->lock); | ||
2827 | BUG_ON(1); | ||
2828 | } | ||
2829 | if (unlikely(!spin_trylock(&busiest->lock))) { | ||
2830 | if (busiest < this_rq) { | ||
2831 | spin_unlock(&this_rq->lock); | ||
2832 | spin_lock(&busiest->lock); | ||
2833 | spin_lock_nested(&this_rq->lock, SINGLE_DEPTH_NESTING); | ||
2834 | ret = 1; | ||
2835 | } else | ||
2836 | spin_lock_nested(&busiest->lock, SINGLE_DEPTH_NESTING); | ||
2837 | } | ||
2838 | return ret; | ||
2839 | } | ||
2840 | |||
2841 | static void double_unlock_balance(struct rq *this_rq, struct rq *busiest) | ||
2842 | __releases(busiest->lock) | ||
2843 | { | ||
2844 | spin_unlock(&busiest->lock); | ||
2845 | lock_set_subclass(&this_rq->lock.dep_map, 0, _RET_IP_); | ||
2846 | } | ||
2847 | |||
2848 | /* | ||
2849 | * If dest_cpu is allowed for this process, migrate the task to it. | 2830 | * If dest_cpu is allowed for this process, migrate the task to it. |
2850 | * This is accomplished by forcing the cpu_allowed mask to only | 2831 | * This is accomplished by forcing the cpu_allowed mask to only |
2851 | * allow dest_cpu, which will force the cpu onto dest_cpu. Then | 2832 | * allow dest_cpu, which will force the cpu onto dest_cpu. Then |
@@ -2858,7 +2839,7 @@ static void sched_migrate_task(struct task_struct *p, int dest_cpu) | |||
2858 | struct rq *rq; | 2839 | struct rq *rq; |
2859 | 2840 | ||
2860 | rq = task_rq_lock(p, &flags); | 2841 | rq = task_rq_lock(p, &flags); |
2861 | if (!cpu_isset(dest_cpu, p->cpus_allowed) | 2842 | if (!cpumask_test_cpu(dest_cpu, &p->cpus_allowed) |
2862 | || unlikely(!cpu_active(dest_cpu))) | 2843 | || unlikely(!cpu_active(dest_cpu))) |
2863 | goto out; | 2844 | goto out; |
2864 | 2845 | ||
@@ -2924,7 +2905,7 @@ int can_migrate_task(struct task_struct *p, struct rq *rq, int this_cpu, | |||
2924 | * 2) cannot be migrated to this CPU due to cpus_allowed, or | 2905 | * 2) cannot be migrated to this CPU due to cpus_allowed, or |
2925 | * 3) are cache-hot on their current CPU. | 2906 | * 3) are cache-hot on their current CPU. |
2926 | */ | 2907 | */ |
2927 | if (!cpu_isset(this_cpu, p->cpus_allowed)) { | 2908 | if (!cpumask_test_cpu(this_cpu, &p->cpus_allowed)) { |
2928 | schedstat_inc(p, se.nr_failed_migrations_affine); | 2909 | schedstat_inc(p, se.nr_failed_migrations_affine); |
2929 | return 0; | 2910 | return 0; |
2930 | } | 2911 | } |
@@ -3099,7 +3080,7 @@ static int move_one_task(struct rq *this_rq, int this_cpu, struct rq *busiest, | |||
3099 | static struct sched_group * | 3080 | static struct sched_group * |
3100 | find_busiest_group(struct sched_domain *sd, int this_cpu, | 3081 | find_busiest_group(struct sched_domain *sd, int this_cpu, |
3101 | unsigned long *imbalance, enum cpu_idle_type idle, | 3082 | unsigned long *imbalance, enum cpu_idle_type idle, |
3102 | int *sd_idle, const cpumask_t *cpus, int *balance) | 3083 | int *sd_idle, const struct cpumask *cpus, int *balance) |
3103 | { | 3084 | { |
3104 | struct sched_group *busiest = NULL, *this = NULL, *group = sd->groups; | 3085 | struct sched_group *busiest = NULL, *this = NULL, *group = sd->groups; |
3105 | unsigned long max_load, avg_load, total_load, this_load, total_pwr; | 3086 | unsigned long max_load, avg_load, total_load, this_load, total_pwr; |
@@ -3135,10 +3116,11 @@ find_busiest_group(struct sched_domain *sd, int this_cpu, | |||
3135 | unsigned long sum_avg_load_per_task; | 3116 | unsigned long sum_avg_load_per_task; |
3136 | unsigned long avg_load_per_task; | 3117 | unsigned long avg_load_per_task; |
3137 | 3118 | ||
3138 | local_group = cpu_isset(this_cpu, group->cpumask); | 3119 | local_group = cpumask_test_cpu(this_cpu, |
3120 | sched_group_cpus(group)); | ||
3139 | 3121 | ||
3140 | if (local_group) | 3122 | if (local_group) |
3141 | balance_cpu = first_cpu(group->cpumask); | 3123 | balance_cpu = cpumask_first(sched_group_cpus(group)); |
3142 | 3124 | ||
3143 | /* Tally up the load of all CPUs in the group */ | 3125 | /* Tally up the load of all CPUs in the group */ |
3144 | sum_weighted_load = sum_nr_running = avg_load = 0; | 3126 | sum_weighted_load = sum_nr_running = avg_load = 0; |
@@ -3147,13 +3129,8 @@ find_busiest_group(struct sched_domain *sd, int this_cpu, | |||
3147 | max_cpu_load = 0; | 3129 | max_cpu_load = 0; |
3148 | min_cpu_load = ~0UL; | 3130 | min_cpu_load = ~0UL; |
3149 | 3131 | ||
3150 | for_each_cpu_mask_nr(i, group->cpumask) { | 3132 | for_each_cpu_and(i, sched_group_cpus(group), cpus) { |
3151 | struct rq *rq; | 3133 | struct rq *rq = cpu_rq(i); |
3152 | |||
3153 | if (!cpu_isset(i, *cpus)) | ||
3154 | continue; | ||
3155 | |||
3156 | rq = cpu_rq(i); | ||
3157 | 3134 | ||
3158 | if (*sd_idle && rq->nr_running) | 3135 | if (*sd_idle && rq->nr_running) |
3159 | *sd_idle = 0; | 3136 | *sd_idle = 0; |
@@ -3264,8 +3241,8 @@ find_busiest_group(struct sched_domain *sd, int this_cpu, | |||
3264 | */ | 3241 | */ |
3265 | if ((sum_nr_running < min_nr_running) || | 3242 | if ((sum_nr_running < min_nr_running) || |
3266 | (sum_nr_running == min_nr_running && | 3243 | (sum_nr_running == min_nr_running && |
3267 | first_cpu(group->cpumask) < | 3244 | cpumask_first(sched_group_cpus(group)) < |
3268 | first_cpu(group_min->cpumask))) { | 3245 | cpumask_first(sched_group_cpus(group_min)))) { |
3269 | group_min = group; | 3246 | group_min = group; |
3270 | min_nr_running = sum_nr_running; | 3247 | min_nr_running = sum_nr_running; |
3271 | min_load_per_task = sum_weighted_load / | 3248 | min_load_per_task = sum_weighted_load / |
@@ -3280,8 +3257,8 @@ find_busiest_group(struct sched_domain *sd, int this_cpu, | |||
3280 | if (sum_nr_running <= group_capacity - 1) { | 3257 | if (sum_nr_running <= group_capacity - 1) { |
3281 | if (sum_nr_running > leader_nr_running || | 3258 | if (sum_nr_running > leader_nr_running || |
3282 | (sum_nr_running == leader_nr_running && | 3259 | (sum_nr_running == leader_nr_running && |
3283 | first_cpu(group->cpumask) > | 3260 | cpumask_first(sched_group_cpus(group)) > |
3284 | first_cpu(group_leader->cpumask))) { | 3261 | cpumask_first(sched_group_cpus(group_leader)))) { |
3285 | group_leader = group; | 3262 | group_leader = group; |
3286 | leader_nr_running = sum_nr_running; | 3263 | leader_nr_running = sum_nr_running; |
3287 | } | 3264 | } |
@@ -3420,16 +3397,16 @@ ret: | |||
3420 | */ | 3397 | */ |
3421 | static struct rq * | 3398 | static struct rq * |
3422 | find_busiest_queue(struct sched_group *group, enum cpu_idle_type idle, | 3399 | find_busiest_queue(struct sched_group *group, enum cpu_idle_type idle, |
3423 | unsigned long imbalance, const cpumask_t *cpus) | 3400 | unsigned long imbalance, const struct cpumask *cpus) |
3424 | { | 3401 | { |
3425 | struct rq *busiest = NULL, *rq; | 3402 | struct rq *busiest = NULL, *rq; |
3426 | unsigned long max_load = 0; | 3403 | unsigned long max_load = 0; |
3427 | int i; | 3404 | int i; |
3428 | 3405 | ||
3429 | for_each_cpu_mask_nr(i, group->cpumask) { | 3406 | for_each_cpu(i, sched_group_cpus(group)) { |
3430 | unsigned long wl; | 3407 | unsigned long wl; |
3431 | 3408 | ||
3432 | if (!cpu_isset(i, *cpus)) | 3409 | if (!cpumask_test_cpu(i, cpus)) |
3433 | continue; | 3410 | continue; |
3434 | 3411 | ||
3435 | rq = cpu_rq(i); | 3412 | rq = cpu_rq(i); |
@@ -3459,7 +3436,7 @@ find_busiest_queue(struct sched_group *group, enum cpu_idle_type idle, | |||
3459 | */ | 3436 | */ |
3460 | static int load_balance(int this_cpu, struct rq *this_rq, | 3437 | static int load_balance(int this_cpu, struct rq *this_rq, |
3461 | struct sched_domain *sd, enum cpu_idle_type idle, | 3438 | struct sched_domain *sd, enum cpu_idle_type idle, |
3462 | int *balance, cpumask_t *cpus) | 3439 | int *balance, struct cpumask *cpus) |
3463 | { | 3440 | { |
3464 | int ld_moved, all_pinned = 0, active_balance = 0, sd_idle = 0; | 3441 | int ld_moved, all_pinned = 0, active_balance = 0, sd_idle = 0; |
3465 | struct sched_group *group; | 3442 | struct sched_group *group; |
@@ -3467,7 +3444,7 @@ static int load_balance(int this_cpu, struct rq *this_rq, | |||
3467 | struct rq *busiest; | 3444 | struct rq *busiest; |
3468 | unsigned long flags; | 3445 | unsigned long flags; |
3469 | 3446 | ||
3470 | cpus_setall(*cpus); | 3447 | cpumask_setall(cpus); |
3471 | 3448 | ||
3472 | /* | 3449 | /* |
3473 | * When power savings policy is enabled for the parent domain, idle | 3450 | * When power savings policy is enabled for the parent domain, idle |
@@ -3527,8 +3504,8 @@ redo: | |||
3527 | 3504 | ||
3528 | /* All tasks on this runqueue were pinned by CPU affinity */ | 3505 | /* All tasks on this runqueue were pinned by CPU affinity */ |
3529 | if (unlikely(all_pinned)) { | 3506 | if (unlikely(all_pinned)) { |
3530 | cpu_clear(cpu_of(busiest), *cpus); | 3507 | cpumask_clear_cpu(cpu_of(busiest), cpus); |
3531 | if (!cpus_empty(*cpus)) | 3508 | if (!cpumask_empty(cpus)) |
3532 | goto redo; | 3509 | goto redo; |
3533 | goto out_balanced; | 3510 | goto out_balanced; |
3534 | } | 3511 | } |
@@ -3545,7 +3522,8 @@ redo: | |||
3545 | /* don't kick the migration_thread, if the curr | 3522 | /* don't kick the migration_thread, if the curr |
3546 | * task on busiest cpu can't be moved to this_cpu | 3523 | * task on busiest cpu can't be moved to this_cpu |
3547 | */ | 3524 | */ |
3548 | if (!cpu_isset(this_cpu, busiest->curr->cpus_allowed)) { | 3525 | if (!cpumask_test_cpu(this_cpu, |
3526 | &busiest->curr->cpus_allowed)) { | ||
3549 | spin_unlock_irqrestore(&busiest->lock, flags); | 3527 | spin_unlock_irqrestore(&busiest->lock, flags); |
3550 | all_pinned = 1; | 3528 | all_pinned = 1; |
3551 | goto out_one_pinned; | 3529 | goto out_one_pinned; |
@@ -3620,7 +3598,7 @@ out: | |||
3620 | */ | 3598 | */ |
3621 | static int | 3599 | static int |
3622 | load_balance_newidle(int this_cpu, struct rq *this_rq, struct sched_domain *sd, | 3600 | load_balance_newidle(int this_cpu, struct rq *this_rq, struct sched_domain *sd, |
3623 | cpumask_t *cpus) | 3601 | struct cpumask *cpus) |
3624 | { | 3602 | { |
3625 | struct sched_group *group; | 3603 | struct sched_group *group; |
3626 | struct rq *busiest = NULL; | 3604 | struct rq *busiest = NULL; |
@@ -3629,7 +3607,7 @@ load_balance_newidle(int this_cpu, struct rq *this_rq, struct sched_domain *sd, | |||
3629 | int sd_idle = 0; | 3607 | int sd_idle = 0; |
3630 | int all_pinned = 0; | 3608 | int all_pinned = 0; |
3631 | 3609 | ||
3632 | cpus_setall(*cpus); | 3610 | cpumask_setall(cpus); |
3633 | 3611 | ||
3634 | /* | 3612 | /* |
3635 | * When power savings policy is enabled for the parent domain, idle | 3613 | * When power savings policy is enabled for the parent domain, idle |
@@ -3673,8 +3651,8 @@ redo: | |||
3673 | double_unlock_balance(this_rq, busiest); | 3651 | double_unlock_balance(this_rq, busiest); |
3674 | 3652 | ||
3675 | if (unlikely(all_pinned)) { | 3653 | if (unlikely(all_pinned)) { |
3676 | cpu_clear(cpu_of(busiest), *cpus); | 3654 | cpumask_clear_cpu(cpu_of(busiest), cpus); |
3677 | if (!cpus_empty(*cpus)) | 3655 | if (!cpumask_empty(cpus)) |
3678 | goto redo; | 3656 | goto redo; |
3679 | } | 3657 | } |
3680 | } | 3658 | } |
@@ -3707,9 +3685,12 @@ out_balanced: | |||
3707 | static void idle_balance(int this_cpu, struct rq *this_rq) | 3685 | static void idle_balance(int this_cpu, struct rq *this_rq) |
3708 | { | 3686 | { |
3709 | struct sched_domain *sd; | 3687 | struct sched_domain *sd; |
3710 | int pulled_task = -1; | 3688 | int pulled_task = 0; |
3711 | unsigned long next_balance = jiffies + HZ; | 3689 | unsigned long next_balance = jiffies + HZ; |
3712 | cpumask_t tmpmask; | 3690 | cpumask_var_t tmpmask; |
3691 | |||
3692 | if (!alloc_cpumask_var(&tmpmask, GFP_ATOMIC)) | ||
3693 | return; | ||
3713 | 3694 | ||
3714 | for_each_domain(this_cpu, sd) { | 3695 | for_each_domain(this_cpu, sd) { |
3715 | unsigned long interval; | 3696 | unsigned long interval; |
@@ -3720,7 +3701,7 @@ static void idle_balance(int this_cpu, struct rq *this_rq) | |||
3720 | if (sd->flags & SD_BALANCE_NEWIDLE) | 3701 | if (sd->flags & SD_BALANCE_NEWIDLE) |
3721 | /* If we've pulled tasks over stop searching: */ | 3702 | /* If we've pulled tasks over stop searching: */ |
3722 | pulled_task = load_balance_newidle(this_cpu, this_rq, | 3703 | pulled_task = load_balance_newidle(this_cpu, this_rq, |
3723 | sd, &tmpmask); | 3704 | sd, tmpmask); |
3724 | 3705 | ||
3725 | interval = msecs_to_jiffies(sd->balance_interval); | 3706 | interval = msecs_to_jiffies(sd->balance_interval); |
3726 | if (time_after(next_balance, sd->last_balance + interval)) | 3707 | if (time_after(next_balance, sd->last_balance + interval)) |
@@ -3735,6 +3716,7 @@ static void idle_balance(int this_cpu, struct rq *this_rq) | |||
3735 | */ | 3716 | */ |
3736 | this_rq->next_balance = next_balance; | 3717 | this_rq->next_balance = next_balance; |
3737 | } | 3718 | } |
3719 | free_cpumask_var(tmpmask); | ||
3738 | } | 3720 | } |
3739 | 3721 | ||
3740 | /* | 3722 | /* |
@@ -3772,7 +3754,7 @@ static void active_load_balance(struct rq *busiest_rq, int busiest_cpu) | |||
3772 | /* Search for an sd spanning us and the target CPU. */ | 3754 | /* Search for an sd spanning us and the target CPU. */ |
3773 | for_each_domain(target_cpu, sd) { | 3755 | for_each_domain(target_cpu, sd) { |
3774 | if ((sd->flags & SD_LOAD_BALANCE) && | 3756 | if ((sd->flags & SD_LOAD_BALANCE) && |
3775 | cpu_isset(busiest_cpu, sd->span)) | 3757 | cpumask_test_cpu(busiest_cpu, sched_domain_span(sd))) |
3776 | break; | 3758 | break; |
3777 | } | 3759 | } |
3778 | 3760 | ||
@@ -3791,10 +3773,9 @@ static void active_load_balance(struct rq *busiest_rq, int busiest_cpu) | |||
3791 | #ifdef CONFIG_NO_HZ | 3773 | #ifdef CONFIG_NO_HZ |
3792 | static struct { | 3774 | static struct { |
3793 | atomic_t load_balancer; | 3775 | atomic_t load_balancer; |
3794 | cpumask_t cpu_mask; | 3776 | cpumask_var_t cpu_mask; |
3795 | } nohz ____cacheline_aligned = { | 3777 | } nohz ____cacheline_aligned = { |
3796 | .load_balancer = ATOMIC_INIT(-1), | 3778 | .load_balancer = ATOMIC_INIT(-1), |
3797 | .cpu_mask = CPU_MASK_NONE, | ||
3798 | }; | 3779 | }; |
3799 | 3780 | ||
3800 | /* | 3781 | /* |
@@ -3822,7 +3803,7 @@ int select_nohz_load_balancer(int stop_tick) | |||
3822 | int cpu = smp_processor_id(); | 3803 | int cpu = smp_processor_id(); |
3823 | 3804 | ||
3824 | if (stop_tick) { | 3805 | if (stop_tick) { |
3825 | cpu_set(cpu, nohz.cpu_mask); | 3806 | cpumask_set_cpu(cpu, nohz.cpu_mask); |
3826 | cpu_rq(cpu)->in_nohz_recently = 1; | 3807 | cpu_rq(cpu)->in_nohz_recently = 1; |
3827 | 3808 | ||
3828 | /* | 3809 | /* |
@@ -3836,7 +3817,7 @@ int select_nohz_load_balancer(int stop_tick) | |||
3836 | } | 3817 | } |
3837 | 3818 | ||
3838 | /* time for ilb owner also to sleep */ | 3819 | /* time for ilb owner also to sleep */ |
3839 | if (cpus_weight(nohz.cpu_mask) == num_online_cpus()) { | 3820 | if (cpumask_weight(nohz.cpu_mask) == num_online_cpus()) { |
3840 | if (atomic_read(&nohz.load_balancer) == cpu) | 3821 | if (atomic_read(&nohz.load_balancer) == cpu) |
3841 | atomic_set(&nohz.load_balancer, -1); | 3822 | atomic_set(&nohz.load_balancer, -1); |
3842 | return 0; | 3823 | return 0; |
@@ -3849,10 +3830,10 @@ int select_nohz_load_balancer(int stop_tick) | |||
3849 | } else if (atomic_read(&nohz.load_balancer) == cpu) | 3830 | } else if (atomic_read(&nohz.load_balancer) == cpu) |
3850 | return 1; | 3831 | return 1; |
3851 | } else { | 3832 | } else { |
3852 | if (!cpu_isset(cpu, nohz.cpu_mask)) | 3833 | if (!cpumask_test_cpu(cpu, nohz.cpu_mask)) |
3853 | return 0; | 3834 | return 0; |
3854 | 3835 | ||
3855 | cpu_clear(cpu, nohz.cpu_mask); | 3836 | cpumask_clear_cpu(cpu, nohz.cpu_mask); |
3856 | 3837 | ||
3857 | if (atomic_read(&nohz.load_balancer) == cpu) | 3838 | if (atomic_read(&nohz.load_balancer) == cpu) |
3858 | if (atomic_cmpxchg(&nohz.load_balancer, cpu, -1) != cpu) | 3839 | if (atomic_cmpxchg(&nohz.load_balancer, cpu, -1) != cpu) |
@@ -3880,7 +3861,11 @@ static void rebalance_domains(int cpu, enum cpu_idle_type idle) | |||
3880 | unsigned long next_balance = jiffies + 60*HZ; | 3861 | unsigned long next_balance = jiffies + 60*HZ; |
3881 | int update_next_balance = 0; | 3862 | int update_next_balance = 0; |
3882 | int need_serialize; | 3863 | int need_serialize; |
3883 | cpumask_t tmp; | 3864 | cpumask_var_t tmp; |
3865 | |||
3866 | /* Fails alloc? Rebalancing probably not a priority right now. */ | ||
3867 | if (!alloc_cpumask_var(&tmp, GFP_ATOMIC)) | ||
3868 | return; | ||
3884 | 3869 | ||
3885 | for_each_domain(cpu, sd) { | 3870 | for_each_domain(cpu, sd) { |
3886 | if (!(sd->flags & SD_LOAD_BALANCE)) | 3871 | if (!(sd->flags & SD_LOAD_BALANCE)) |
@@ -3905,7 +3890,7 @@ static void rebalance_domains(int cpu, enum cpu_idle_type idle) | |||
3905 | } | 3890 | } |
3906 | 3891 | ||
3907 | if (time_after_eq(jiffies, sd->last_balance + interval)) { | 3892 | if (time_after_eq(jiffies, sd->last_balance + interval)) { |
3908 | if (load_balance(cpu, rq, sd, idle, &balance, &tmp)) { | 3893 | if (load_balance(cpu, rq, sd, idle, &balance, tmp)) { |
3909 | /* | 3894 | /* |
3910 | * We've pulled tasks over so either we're no | 3895 | * We've pulled tasks over so either we're no |
3911 | * longer idle, or one of our SMT siblings is | 3896 | * longer idle, or one of our SMT siblings is |
@@ -3939,6 +3924,8 @@ out: | |||
3939 | */ | 3924 | */ |
3940 | if (likely(update_next_balance)) | 3925 | if (likely(update_next_balance)) |
3941 | rq->next_balance = next_balance; | 3926 | rq->next_balance = next_balance; |
3927 | |||
3928 | free_cpumask_var(tmp); | ||
3942 | } | 3929 | } |
3943 | 3930 | ||
3944 | /* | 3931 | /* |
@@ -3963,12 +3950,13 @@ static void run_rebalance_domains(struct softirq_action *h) | |||
3963 | */ | 3950 | */ |
3964 | if (this_rq->idle_at_tick && | 3951 | if (this_rq->idle_at_tick && |
3965 | atomic_read(&nohz.load_balancer) == this_cpu) { | 3952 | atomic_read(&nohz.load_balancer) == this_cpu) { |
3966 | cpumask_t cpus = nohz.cpu_mask; | ||
3967 | struct rq *rq; | 3953 | struct rq *rq; |
3968 | int balance_cpu; | 3954 | int balance_cpu; |
3969 | 3955 | ||
3970 | cpu_clear(this_cpu, cpus); | 3956 | for_each_cpu(balance_cpu, nohz.cpu_mask) { |
3971 | for_each_cpu_mask_nr(balance_cpu, cpus) { | 3957 | if (balance_cpu == this_cpu) |
3958 | continue; | ||
3959 | |||
3972 | /* | 3960 | /* |
3973 | * If this cpu gets work to do, stop the load balancing | 3961 | * If this cpu gets work to do, stop the load balancing |
3974 | * work being done for other cpus. Next load | 3962 | * work being done for other cpus. Next load |
@@ -4006,7 +3994,7 @@ static inline void trigger_load_balance(struct rq *rq, int cpu) | |||
4006 | rq->in_nohz_recently = 0; | 3994 | rq->in_nohz_recently = 0; |
4007 | 3995 | ||
4008 | if (atomic_read(&nohz.load_balancer) == cpu) { | 3996 | if (atomic_read(&nohz.load_balancer) == cpu) { |
4009 | cpu_clear(cpu, nohz.cpu_mask); | 3997 | cpumask_clear_cpu(cpu, nohz.cpu_mask); |
4010 | atomic_set(&nohz.load_balancer, -1); | 3998 | atomic_set(&nohz.load_balancer, -1); |
4011 | } | 3999 | } |
4012 | 4000 | ||
@@ -4019,7 +4007,7 @@ static inline void trigger_load_balance(struct rq *rq, int cpu) | |||
4019 | * TBD: Traverse the sched domains and nominate | 4007 | * TBD: Traverse the sched domains and nominate |
4020 | * the nearest cpu in the nohz.cpu_mask. | 4008 | * the nearest cpu in the nohz.cpu_mask. |
4021 | */ | 4009 | */ |
4022 | int ilb = first_cpu(nohz.cpu_mask); | 4010 | int ilb = cpumask_first(nohz.cpu_mask); |
4023 | 4011 | ||
4024 | if (ilb < nr_cpu_ids) | 4012 | if (ilb < nr_cpu_ids) |
4025 | resched_cpu(ilb); | 4013 | resched_cpu(ilb); |
@@ -4031,7 +4019,7 @@ static inline void trigger_load_balance(struct rq *rq, int cpu) | |||
4031 | * cpus with ticks stopped, is it time for that to stop? | 4019 | * cpus with ticks stopped, is it time for that to stop? |
4032 | */ | 4020 | */ |
4033 | if (rq->idle_at_tick && atomic_read(&nohz.load_balancer) == cpu && | 4021 | if (rq->idle_at_tick && atomic_read(&nohz.load_balancer) == cpu && |
4034 | cpus_weight(nohz.cpu_mask) == num_online_cpus()) { | 4022 | cpumask_weight(nohz.cpu_mask) == num_online_cpus()) { |
4035 | resched_cpu(cpu); | 4023 | resched_cpu(cpu); |
4036 | return; | 4024 | return; |
4037 | } | 4025 | } |
@@ -4041,7 +4029,7 @@ static inline void trigger_load_balance(struct rq *rq, int cpu) | |||
4041 | * someone else, then no need raise the SCHED_SOFTIRQ | 4029 | * someone else, then no need raise the SCHED_SOFTIRQ |
4042 | */ | 4030 | */ |
4043 | if (rq->idle_at_tick && atomic_read(&nohz.load_balancer) != cpu && | 4031 | if (rq->idle_at_tick && atomic_read(&nohz.load_balancer) != cpu && |
4044 | cpu_isset(cpu, nohz.cpu_mask)) | 4032 | cpumask_test_cpu(cpu, nohz.cpu_mask)) |
4045 | return; | 4033 | return; |
4046 | #endif | 4034 | #endif |
4047 | if (time_after_eq(jiffies, rq->next_balance)) | 4035 | if (time_after_eq(jiffies, rq->next_balance)) |
@@ -4203,7 +4191,6 @@ void account_steal_time(struct task_struct *p, cputime_t steal) | |||
4203 | 4191 | ||
4204 | if (p == rq->idle) { | 4192 | if (p == rq->idle) { |
4205 | p->stime = cputime_add(p->stime, steal); | 4193 | p->stime = cputime_add(p->stime, steal); |
4206 | account_group_system_time(p, steal); | ||
4207 | if (atomic_read(&rq->nr_iowait) > 0) | 4194 | if (atomic_read(&rq->nr_iowait) > 0) |
4208 | cpustat->iowait = cputime64_add(cpustat->iowait, tmp); | 4195 | cpustat->iowait = cputime64_add(cpustat->iowait, tmp); |
4209 | else | 4196 | else |
@@ -4339,7 +4326,7 @@ void __kprobes sub_preempt_count(int val) | |||
4339 | /* | 4326 | /* |
4340 | * Underflow? | 4327 | * Underflow? |
4341 | */ | 4328 | */ |
4342 | if (DEBUG_LOCKS_WARN_ON(val > preempt_count())) | 4329 | if (DEBUG_LOCKS_WARN_ON(val > preempt_count() - (!!kernel_locked()))) |
4343 | return; | 4330 | return; |
4344 | /* | 4331 | /* |
4345 | * Is the spinlock portion underflowing? | 4332 | * Is the spinlock portion underflowing? |
@@ -5400,10 +5387,9 @@ out_unlock: | |||
5400 | return retval; | 5387 | return retval; |
5401 | } | 5388 | } |
5402 | 5389 | ||
5403 | long sched_setaffinity(pid_t pid, const cpumask_t *in_mask) | 5390 | long sched_setaffinity(pid_t pid, const struct cpumask *in_mask) |
5404 | { | 5391 | { |
5405 | cpumask_t cpus_allowed; | 5392 | cpumask_var_t cpus_allowed, new_mask; |
5406 | cpumask_t new_mask = *in_mask; | ||
5407 | struct task_struct *p; | 5393 | struct task_struct *p; |
5408 | int retval; | 5394 | int retval; |
5409 | 5395 | ||
@@ -5425,6 +5411,14 @@ long sched_setaffinity(pid_t pid, const cpumask_t *in_mask) | |||
5425 | get_task_struct(p); | 5411 | get_task_struct(p); |
5426 | read_unlock(&tasklist_lock); | 5412 | read_unlock(&tasklist_lock); |
5427 | 5413 | ||
5414 | if (!alloc_cpumask_var(&cpus_allowed, GFP_KERNEL)) { | ||
5415 | retval = -ENOMEM; | ||
5416 | goto out_put_task; | ||
5417 | } | ||
5418 | if (!alloc_cpumask_var(&new_mask, GFP_KERNEL)) { | ||
5419 | retval = -ENOMEM; | ||
5420 | goto out_free_cpus_allowed; | ||
5421 | } | ||
5428 | retval = -EPERM; | 5422 | retval = -EPERM; |
5429 | if ((current->euid != p->euid) && (current->euid != p->uid) && | 5423 | if ((current->euid != p->euid) && (current->euid != p->uid) && |
5430 | !capable(CAP_SYS_NICE)) | 5424 | !capable(CAP_SYS_NICE)) |
@@ -5434,37 +5428,41 @@ long sched_setaffinity(pid_t pid, const cpumask_t *in_mask) | |||
5434 | if (retval) | 5428 | if (retval) |
5435 | goto out_unlock; | 5429 | goto out_unlock; |
5436 | 5430 | ||
5437 | cpuset_cpus_allowed(p, &cpus_allowed); | 5431 | cpuset_cpus_allowed(p, cpus_allowed); |
5438 | cpus_and(new_mask, new_mask, cpus_allowed); | 5432 | cpumask_and(new_mask, in_mask, cpus_allowed); |
5439 | again: | 5433 | again: |
5440 | retval = set_cpus_allowed_ptr(p, &new_mask); | 5434 | retval = set_cpus_allowed_ptr(p, new_mask); |
5441 | 5435 | ||
5442 | if (!retval) { | 5436 | if (!retval) { |
5443 | cpuset_cpus_allowed(p, &cpus_allowed); | 5437 | cpuset_cpus_allowed(p, cpus_allowed); |
5444 | if (!cpus_subset(new_mask, cpus_allowed)) { | 5438 | if (!cpumask_subset(new_mask, cpus_allowed)) { |
5445 | /* | 5439 | /* |
5446 | * We must have raced with a concurrent cpuset | 5440 | * We must have raced with a concurrent cpuset |
5447 | * update. Just reset the cpus_allowed to the | 5441 | * update. Just reset the cpus_allowed to the |
5448 | * cpuset's cpus_allowed | 5442 | * cpuset's cpus_allowed |
5449 | */ | 5443 | */ |
5450 | new_mask = cpus_allowed; | 5444 | cpumask_copy(new_mask, cpus_allowed); |
5451 | goto again; | 5445 | goto again; |
5452 | } | 5446 | } |
5453 | } | 5447 | } |
5454 | out_unlock: | 5448 | out_unlock: |
5449 | free_cpumask_var(new_mask); | ||
5450 | out_free_cpus_allowed: | ||
5451 | free_cpumask_var(cpus_allowed); | ||
5452 | out_put_task: | ||
5455 | put_task_struct(p); | 5453 | put_task_struct(p); |
5456 | put_online_cpus(); | 5454 | put_online_cpus(); |
5457 | return retval; | 5455 | return retval; |
5458 | } | 5456 | } |
5459 | 5457 | ||
5460 | static int get_user_cpu_mask(unsigned long __user *user_mask_ptr, unsigned len, | 5458 | static int get_user_cpu_mask(unsigned long __user *user_mask_ptr, unsigned len, |
5461 | cpumask_t *new_mask) | 5459 | struct cpumask *new_mask) |
5462 | { | 5460 | { |
5463 | if (len < sizeof(cpumask_t)) { | 5461 | if (len < cpumask_size()) |
5464 | memset(new_mask, 0, sizeof(cpumask_t)); | 5462 | cpumask_clear(new_mask); |
5465 | } else if (len > sizeof(cpumask_t)) { | 5463 | else if (len > cpumask_size()) |
5466 | len = sizeof(cpumask_t); | 5464 | len = cpumask_size(); |
5467 | } | 5465 | |
5468 | return copy_from_user(new_mask, user_mask_ptr, len) ? -EFAULT : 0; | 5466 | return copy_from_user(new_mask, user_mask_ptr, len) ? -EFAULT : 0; |
5469 | } | 5467 | } |
5470 | 5468 | ||
@@ -5477,17 +5475,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, | 5475 | asmlinkage long sys_sched_setaffinity(pid_t pid, unsigned int len, |
5478 | unsigned long __user *user_mask_ptr) | 5476 | unsigned long __user *user_mask_ptr) |
5479 | { | 5477 | { |
5480 | cpumask_t new_mask; | 5478 | cpumask_var_t new_mask; |
5481 | int retval; | 5479 | int retval; |
5482 | 5480 | ||
5483 | retval = get_user_cpu_mask(user_mask_ptr, len, &new_mask); | 5481 | if (!alloc_cpumask_var(&new_mask, GFP_KERNEL)) |
5484 | if (retval) | 5482 | return -ENOMEM; |
5485 | return retval; | ||
5486 | 5483 | ||
5487 | return sched_setaffinity(pid, &new_mask); | 5484 | retval = get_user_cpu_mask(user_mask_ptr, len, new_mask); |
5485 | if (retval == 0) | ||
5486 | retval = sched_setaffinity(pid, new_mask); | ||
5487 | free_cpumask_var(new_mask); | ||
5488 | return retval; | ||
5488 | } | 5489 | } |
5489 | 5490 | ||
5490 | long sched_getaffinity(pid_t pid, cpumask_t *mask) | 5491 | long sched_getaffinity(pid_t pid, struct cpumask *mask) |
5491 | { | 5492 | { |
5492 | struct task_struct *p; | 5493 | struct task_struct *p; |
5493 | int retval; | 5494 | int retval; |
@@ -5504,7 +5505,7 @@ long sched_getaffinity(pid_t pid, cpumask_t *mask) | |||
5504 | if (retval) | 5505 | if (retval) |
5505 | goto out_unlock; | 5506 | goto out_unlock; |
5506 | 5507 | ||
5507 | cpus_and(*mask, p->cpus_allowed, cpu_online_map); | 5508 | cpumask_and(mask, &p->cpus_allowed, cpu_online_mask); |
5508 | 5509 | ||
5509 | out_unlock: | 5510 | out_unlock: |
5510 | read_unlock(&tasklist_lock); | 5511 | read_unlock(&tasklist_lock); |
@@ -5523,19 +5524,24 @@ asmlinkage long sys_sched_getaffinity(pid_t pid, unsigned int len, | |||
5523 | unsigned long __user *user_mask_ptr) | 5524 | unsigned long __user *user_mask_ptr) |
5524 | { | 5525 | { |
5525 | int ret; | 5526 | int ret; |
5526 | cpumask_t mask; | 5527 | cpumask_var_t mask; |
5527 | 5528 | ||
5528 | if (len < sizeof(cpumask_t)) | 5529 | if (len < cpumask_size()) |
5529 | return -EINVAL; | 5530 | return -EINVAL; |
5530 | 5531 | ||
5531 | ret = sched_getaffinity(pid, &mask); | 5532 | if (!alloc_cpumask_var(&mask, GFP_KERNEL)) |
5532 | if (ret < 0) | 5533 | return -ENOMEM; |
5533 | return ret; | ||
5534 | 5534 | ||
5535 | if (copy_to_user(user_mask_ptr, &mask, sizeof(cpumask_t))) | 5535 | ret = sched_getaffinity(pid, mask); |
5536 | return -EFAULT; | 5536 | if (ret == 0) { |
5537 | if (copy_to_user(user_mask_ptr, mask, cpumask_size())) | ||
5538 | ret = -EFAULT; | ||
5539 | else | ||
5540 | ret = cpumask_size(); | ||
5541 | } | ||
5542 | free_cpumask_var(mask); | ||
5537 | 5543 | ||
5538 | return sizeof(cpumask_t); | 5544 | return ret; |
5539 | } | 5545 | } |
5540 | 5546 | ||
5541 | /** | 5547 | /** |
@@ -5877,7 +5883,7 @@ void __cpuinit init_idle(struct task_struct *idle, int cpu) | |||
5877 | idle->se.exec_start = sched_clock(); | 5883 | idle->se.exec_start = sched_clock(); |
5878 | 5884 | ||
5879 | idle->prio = idle->normal_prio = MAX_PRIO; | 5885 | idle->prio = idle->normal_prio = MAX_PRIO; |
5880 | idle->cpus_allowed = cpumask_of_cpu(cpu); | 5886 | cpumask_copy(&idle->cpus_allowed, cpumask_of(cpu)); |
5881 | __set_task_cpu(idle, cpu); | 5887 | __set_task_cpu(idle, cpu); |
5882 | 5888 | ||
5883 | rq->curr = rq->idle = idle; | 5889 | rq->curr = rq->idle = idle; |
@@ -5896,6 +5902,7 @@ void __cpuinit init_idle(struct task_struct *idle, int cpu) | |||
5896 | * The idle tasks have their own, simple scheduling class: | 5902 | * The idle tasks have their own, simple scheduling class: |
5897 | */ | 5903 | */ |
5898 | idle->sched_class = &idle_sched_class; | 5904 | idle->sched_class = &idle_sched_class; |
5905 | ftrace_graph_init_task(idle); | ||
5899 | } | 5906 | } |
5900 | 5907 | ||
5901 | /* | 5908 | /* |
@@ -5903,9 +5910,9 @@ void __cpuinit init_idle(struct task_struct *idle, int cpu) | |||
5903 | * indicates which cpus entered this state. This is used | 5910 | * indicates which cpus entered this state. This is used |
5904 | * in the rcu update to wait only for active cpus. For system | 5911 | * in the rcu update to wait only for active cpus. For system |
5905 | * which do not switch off the HZ timer nohz_cpu_mask should | 5912 | * which do not switch off the HZ timer nohz_cpu_mask should |
5906 | * always be CPU_MASK_NONE. | 5913 | * always be CPU_BITS_NONE. |
5907 | */ | 5914 | */ |
5908 | cpumask_t nohz_cpu_mask = CPU_MASK_NONE; | 5915 | cpumask_var_t nohz_cpu_mask; |
5909 | 5916 | ||
5910 | /* | 5917 | /* |
5911 | * Increase the granularity value when there are more CPUs, | 5918 | * Increase the granularity value when there are more CPUs, |
@@ -5960,7 +5967,7 @@ static inline void sched_init_granularity(void) | |||
5960 | * task must not exit() & deallocate itself prematurely. The | 5967 | * task must not exit() & deallocate itself prematurely. The |
5961 | * call is not atomic; no spinlocks may be held. | 5968 | * call is not atomic; no spinlocks may be held. |
5962 | */ | 5969 | */ |
5963 | int set_cpus_allowed_ptr(struct task_struct *p, const cpumask_t *new_mask) | 5970 | int set_cpus_allowed_ptr(struct task_struct *p, const struct cpumask *new_mask) |
5964 | { | 5971 | { |
5965 | struct migration_req req; | 5972 | struct migration_req req; |
5966 | unsigned long flags; | 5973 | unsigned long flags; |
@@ -5968,13 +5975,13 @@ int set_cpus_allowed_ptr(struct task_struct *p, const cpumask_t *new_mask) | |||
5968 | int ret = 0; | 5975 | int ret = 0; |
5969 | 5976 | ||
5970 | rq = task_rq_lock(p, &flags); | 5977 | rq = task_rq_lock(p, &flags); |
5971 | if (!cpus_intersects(*new_mask, cpu_online_map)) { | 5978 | if (!cpumask_intersects(new_mask, cpu_online_mask)) { |
5972 | ret = -EINVAL; | 5979 | ret = -EINVAL; |
5973 | goto out; | 5980 | goto out; |
5974 | } | 5981 | } |
5975 | 5982 | ||
5976 | if (unlikely((p->flags & PF_THREAD_BOUND) && p != current && | 5983 | if (unlikely((p->flags & PF_THREAD_BOUND) && p != current && |
5977 | !cpus_equal(p->cpus_allowed, *new_mask))) { | 5984 | !cpumask_equal(&p->cpus_allowed, new_mask))) { |
5978 | ret = -EINVAL; | 5985 | ret = -EINVAL; |
5979 | goto out; | 5986 | goto out; |
5980 | } | 5987 | } |
@@ -5982,15 +5989,15 @@ int set_cpus_allowed_ptr(struct task_struct *p, const cpumask_t *new_mask) | |||
5982 | if (p->sched_class->set_cpus_allowed) | 5989 | if (p->sched_class->set_cpus_allowed) |
5983 | p->sched_class->set_cpus_allowed(p, new_mask); | 5990 | p->sched_class->set_cpus_allowed(p, new_mask); |
5984 | else { | 5991 | else { |
5985 | p->cpus_allowed = *new_mask; | 5992 | cpumask_copy(&p->cpus_allowed, new_mask); |
5986 | p->rt.nr_cpus_allowed = cpus_weight(*new_mask); | 5993 | p->rt.nr_cpus_allowed = cpumask_weight(new_mask); |
5987 | } | 5994 | } |
5988 | 5995 | ||
5989 | /* Can the task run on the task's current CPU? If so, we're done */ | 5996 | /* Can the task run on the task's current CPU? If so, we're done */ |
5990 | if (cpu_isset(task_cpu(p), *new_mask)) | 5997 | if (cpumask_test_cpu(task_cpu(p), new_mask)) |
5991 | goto out; | 5998 | goto out; |
5992 | 5999 | ||
5993 | if (migrate_task(p, any_online_cpu(*new_mask), &req)) { | 6000 | if (migrate_task(p, cpumask_any_and(cpu_online_mask, new_mask), &req)) { |
5994 | /* Need help from migration thread: drop lock and wait. */ | 6001 | /* Need help from migration thread: drop lock and wait. */ |
5995 | task_rq_unlock(rq, &flags); | 6002 | task_rq_unlock(rq, &flags); |
5996 | wake_up_process(rq->migration_thread); | 6003 | wake_up_process(rq->migration_thread); |
@@ -6032,7 +6039,7 @@ static int __migrate_task(struct task_struct *p, int src_cpu, int dest_cpu) | |||
6032 | if (task_cpu(p) != src_cpu) | 6039 | if (task_cpu(p) != src_cpu) |
6033 | goto done; | 6040 | goto done; |
6034 | /* Affinity changed (again). */ | 6041 | /* Affinity changed (again). */ |
6035 | if (!cpu_isset(dest_cpu, p->cpus_allowed)) | 6042 | if (!cpumask_test_cpu(dest_cpu, &p->cpus_allowed)) |
6036 | goto fail; | 6043 | goto fail; |
6037 | 6044 | ||
6038 | on_rq = p->se.on_rq; | 6045 | on_rq = p->se.on_rq; |
@@ -6126,54 +6133,46 @@ static int __migrate_task_irq(struct task_struct *p, int src_cpu, int dest_cpu) | |||
6126 | 6133 | ||
6127 | /* | 6134 | /* |
6128 | * Figure out where task on dead CPU should go, use force if necessary. | 6135 | * Figure out where task on dead CPU should go, use force if necessary. |
6129 | * NOTE: interrupts should be disabled by the caller | ||
6130 | */ | 6136 | */ |
6131 | static void move_task_off_dead_cpu(int dead_cpu, struct task_struct *p) | 6137 | static void move_task_off_dead_cpu(int dead_cpu, struct task_struct *p) |
6132 | { | 6138 | { |
6133 | unsigned long flags; | ||
6134 | cpumask_t mask; | ||
6135 | struct rq *rq; | ||
6136 | int dest_cpu; | 6139 | int dest_cpu; |
6140 | /* FIXME: Use cpumask_of_node here. */ | ||
6141 | cpumask_t _nodemask = node_to_cpumask(cpu_to_node(dead_cpu)); | ||
6142 | const struct cpumask *nodemask = &_nodemask; | ||
6143 | |||
6144 | again: | ||
6145 | /* Look for allowed, online CPU in same node. */ | ||
6146 | for_each_cpu_and(dest_cpu, nodemask, cpu_online_mask) | ||
6147 | if (cpumask_test_cpu(dest_cpu, &p->cpus_allowed)) | ||
6148 | goto move; | ||
6149 | |||
6150 | /* Any allowed, online CPU? */ | ||
6151 | dest_cpu = cpumask_any_and(&p->cpus_allowed, cpu_online_mask); | ||
6152 | if (dest_cpu < nr_cpu_ids) | ||
6153 | goto move; | ||
6154 | |||
6155 | /* No more Mr. Nice Guy. */ | ||
6156 | if (dest_cpu >= nr_cpu_ids) { | ||
6157 | cpuset_cpus_allowed_locked(p, &p->cpus_allowed); | ||
6158 | dest_cpu = cpumask_any_and(cpu_online_mask, &p->cpus_allowed); | ||
6137 | 6159 | ||
6138 | do { | 6160 | /* |
6139 | /* On same node? */ | 6161 | * Don't tell them about moving exiting tasks or |
6140 | mask = node_to_cpumask(cpu_to_node(dead_cpu)); | 6162 | * kernel threads (both mm NULL), since they never |
6141 | cpus_and(mask, mask, p->cpus_allowed); | 6163 | * leave kernel. |
6142 | dest_cpu = any_online_cpu(mask); | 6164 | */ |
6143 | 6165 | if (p->mm && printk_ratelimit()) { | |
6144 | /* On any allowed CPU? */ | 6166 | printk(KERN_INFO "process %d (%s) no " |
6145 | if (dest_cpu >= nr_cpu_ids) | 6167 | "longer affine to cpu%d\n", |
6146 | dest_cpu = any_online_cpu(p->cpus_allowed); | 6168 | task_pid_nr(p), p->comm, dead_cpu); |
6147 | |||
6148 | /* No more Mr. Nice Guy. */ | ||
6149 | if (dest_cpu >= nr_cpu_ids) { | ||
6150 | cpumask_t cpus_allowed; | ||
6151 | |||
6152 | cpuset_cpus_allowed_locked(p, &cpus_allowed); | ||
6153 | /* | ||
6154 | * Try to stay on the same cpuset, where the | ||
6155 | * current cpuset may be a subset of all cpus. | ||
6156 | * The cpuset_cpus_allowed_locked() variant of | ||
6157 | * cpuset_cpus_allowed() will not block. It must be | ||
6158 | * called within calls to cpuset_lock/cpuset_unlock. | ||
6159 | */ | ||
6160 | rq = task_rq_lock(p, &flags); | ||
6161 | p->cpus_allowed = cpus_allowed; | ||
6162 | dest_cpu = any_online_cpu(p->cpus_allowed); | ||
6163 | task_rq_unlock(rq, &flags); | ||
6164 | |||
6165 | /* | ||
6166 | * Don't tell them about moving exiting tasks or | ||
6167 | * kernel threads (both mm NULL), since they never | ||
6168 | * leave kernel. | ||
6169 | */ | ||
6170 | if (p->mm && printk_ratelimit()) { | ||
6171 | printk(KERN_INFO "process %d (%s) no " | ||
6172 | "longer affine to cpu%d\n", | ||
6173 | task_pid_nr(p), p->comm, dead_cpu); | ||
6174 | } | ||
6175 | } | 6169 | } |
6176 | } while (!__migrate_task_irq(p, dead_cpu, dest_cpu)); | 6170 | } |
6171 | |||
6172 | move: | ||
6173 | /* It can have affinity changed while we were choosing. */ | ||
6174 | if (unlikely(!__migrate_task_irq(p, dead_cpu, dest_cpu))) | ||
6175 | goto again; | ||
6177 | } | 6176 | } |
6178 | 6177 | ||
6179 | /* | 6178 | /* |
@@ -6185,7 +6184,7 @@ static void move_task_off_dead_cpu(int dead_cpu, struct task_struct *p) | |||
6185 | */ | 6184 | */ |
6186 | static void migrate_nr_uninterruptible(struct rq *rq_src) | 6185 | static void migrate_nr_uninterruptible(struct rq *rq_src) |
6187 | { | 6186 | { |
6188 | struct rq *rq_dest = cpu_rq(any_online_cpu(*CPU_MASK_ALL_PTR)); | 6187 | struct rq *rq_dest = cpu_rq(cpumask_any(cpu_online_mask)); |
6189 | unsigned long flags; | 6188 | unsigned long flags; |
6190 | 6189 | ||
6191 | local_irq_save(flags); | 6190 | local_irq_save(flags); |
@@ -6475,7 +6474,7 @@ static void set_rq_online(struct rq *rq) | |||
6475 | if (!rq->online) { | 6474 | if (!rq->online) { |
6476 | const struct sched_class *class; | 6475 | const struct sched_class *class; |
6477 | 6476 | ||
6478 | cpu_set(rq->cpu, rq->rd->online); | 6477 | cpumask_set_cpu(rq->cpu, rq->rd->online); |
6479 | rq->online = 1; | 6478 | rq->online = 1; |
6480 | 6479 | ||
6481 | for_each_class(class) { | 6480 | for_each_class(class) { |
@@ -6495,7 +6494,7 @@ static void set_rq_offline(struct rq *rq) | |||
6495 | class->rq_offline(rq); | 6494 | class->rq_offline(rq); |
6496 | } | 6495 | } |
6497 | 6496 | ||
6498 | cpu_clear(rq->cpu, rq->rd->online); | 6497 | cpumask_clear_cpu(rq->cpu, rq->rd->online); |
6499 | rq->online = 0; | 6498 | rq->online = 0; |
6500 | } | 6499 | } |
6501 | } | 6500 | } |
@@ -6536,7 +6535,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu) | |||
6536 | rq = cpu_rq(cpu); | 6535 | rq = cpu_rq(cpu); |
6537 | spin_lock_irqsave(&rq->lock, flags); | 6536 | spin_lock_irqsave(&rq->lock, flags); |
6538 | if (rq->rd) { | 6537 | if (rq->rd) { |
6539 | BUG_ON(!cpu_isset(cpu, rq->rd->span)); | 6538 | BUG_ON(!cpumask_test_cpu(cpu, rq->rd->span)); |
6540 | 6539 | ||
6541 | set_rq_online(rq); | 6540 | set_rq_online(rq); |
6542 | } | 6541 | } |
@@ -6550,7 +6549,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu) | |||
6550 | break; | 6549 | break; |
6551 | /* Unbind it from offline cpu so it can run. Fall thru. */ | 6550 | /* Unbind it from offline cpu so it can run. Fall thru. */ |
6552 | kthread_bind(cpu_rq(cpu)->migration_thread, | 6551 | kthread_bind(cpu_rq(cpu)->migration_thread, |
6553 | any_online_cpu(cpu_online_map)); | 6552 | cpumask_any(cpu_online_mask)); |
6554 | kthread_stop(cpu_rq(cpu)->migration_thread); | 6553 | kthread_stop(cpu_rq(cpu)->migration_thread); |
6555 | cpu_rq(cpu)->migration_thread = NULL; | 6554 | cpu_rq(cpu)->migration_thread = NULL; |
6556 | break; | 6555 | break; |
@@ -6600,7 +6599,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu) | |||
6600 | rq = cpu_rq(cpu); | 6599 | rq = cpu_rq(cpu); |
6601 | spin_lock_irqsave(&rq->lock, flags); | 6600 | spin_lock_irqsave(&rq->lock, flags); |
6602 | if (rq->rd) { | 6601 | if (rq->rd) { |
6603 | BUG_ON(!cpu_isset(cpu, rq->rd->span)); | 6602 | BUG_ON(!cpumask_test_cpu(cpu, rq->rd->span)); |
6604 | set_rq_offline(rq); | 6603 | set_rq_offline(rq); |
6605 | } | 6604 | } |
6606 | spin_unlock_irqrestore(&rq->lock, flags); | 6605 | spin_unlock_irqrestore(&rq->lock, flags); |
@@ -6638,36 +6637,14 @@ early_initcall(migration_init); | |||
6638 | 6637 | ||
6639 | #ifdef CONFIG_SCHED_DEBUG | 6638 | #ifdef CONFIG_SCHED_DEBUG |
6640 | 6639 | ||
6641 | static inline const char *sd_level_to_string(enum sched_domain_level lvl) | ||
6642 | { | ||
6643 | switch (lvl) { | ||
6644 | case SD_LV_NONE: | ||
6645 | return "NONE"; | ||
6646 | case SD_LV_SIBLING: | ||
6647 | return "SIBLING"; | ||
6648 | case SD_LV_MC: | ||
6649 | return "MC"; | ||
6650 | case SD_LV_CPU: | ||
6651 | return "CPU"; | ||
6652 | case SD_LV_NODE: | ||
6653 | return "NODE"; | ||
6654 | case SD_LV_ALLNODES: | ||
6655 | return "ALLNODES"; | ||
6656 | case SD_LV_MAX: | ||
6657 | return "MAX"; | ||
6658 | |||
6659 | } | ||
6660 | return "MAX"; | ||
6661 | } | ||
6662 | |||
6663 | static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level, | 6640 | static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level, |
6664 | cpumask_t *groupmask) | 6641 | struct cpumask *groupmask) |
6665 | { | 6642 | { |
6666 | struct sched_group *group = sd->groups; | 6643 | struct sched_group *group = sd->groups; |
6667 | char str[256]; | 6644 | char str[256]; |
6668 | 6645 | ||
6669 | cpulist_scnprintf(str, sizeof(str), &sd->span); | 6646 | cpulist_scnprintf(str, sizeof(str), sched_domain_span(sd)); |
6670 | cpus_clear(*groupmask); | 6647 | cpumask_clear(groupmask); |
6671 | 6648 | ||
6672 | printk(KERN_DEBUG "%*s domain %d: ", level, "", level); | 6649 | printk(KERN_DEBUG "%*s domain %d: ", level, "", level); |
6673 | 6650 | ||
@@ -6679,14 +6656,13 @@ static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level, | |||
6679 | return -1; | 6656 | return -1; |
6680 | } | 6657 | } |
6681 | 6658 | ||
6682 | printk(KERN_CONT "span %s level %s\n", | 6659 | printk(KERN_CONT "span %s level %s\n", str, sd->name); |
6683 | str, sd_level_to_string(sd->level)); | ||
6684 | 6660 | ||
6685 | if (!cpu_isset(cpu, sd->span)) { | 6661 | if (!cpumask_test_cpu(cpu, sched_domain_span(sd))) { |
6686 | printk(KERN_ERR "ERROR: domain->span does not contain " | 6662 | printk(KERN_ERR "ERROR: domain->span does not contain " |
6687 | "CPU%d\n", cpu); | 6663 | "CPU%d\n", cpu); |
6688 | } | 6664 | } |
6689 | if (!cpu_isset(cpu, group->cpumask)) { | 6665 | if (!cpumask_test_cpu(cpu, sched_group_cpus(group))) { |
6690 | printk(KERN_ERR "ERROR: domain->groups does not contain" | 6666 | printk(KERN_ERR "ERROR: domain->groups does not contain" |
6691 | " CPU%d\n", cpu); | 6667 | " CPU%d\n", cpu); |
6692 | } | 6668 | } |
@@ -6706,31 +6682,32 @@ static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level, | |||
6706 | break; | 6682 | break; |
6707 | } | 6683 | } |
6708 | 6684 | ||
6709 | if (!cpus_weight(group->cpumask)) { | 6685 | if (!cpumask_weight(sched_group_cpus(group))) { |
6710 | printk(KERN_CONT "\n"); | 6686 | printk(KERN_CONT "\n"); |
6711 | printk(KERN_ERR "ERROR: empty group\n"); | 6687 | printk(KERN_ERR "ERROR: empty group\n"); |
6712 | break; | 6688 | break; |
6713 | } | 6689 | } |
6714 | 6690 | ||
6715 | if (cpus_intersects(*groupmask, group->cpumask)) { | 6691 | if (cpumask_intersects(groupmask, sched_group_cpus(group))) { |
6716 | printk(KERN_CONT "\n"); | 6692 | printk(KERN_CONT "\n"); |
6717 | printk(KERN_ERR "ERROR: repeated CPUs\n"); | 6693 | printk(KERN_ERR "ERROR: repeated CPUs\n"); |
6718 | break; | 6694 | break; |
6719 | } | 6695 | } |
6720 | 6696 | ||
6721 | cpus_or(*groupmask, *groupmask, group->cpumask); | 6697 | cpumask_or(groupmask, groupmask, sched_group_cpus(group)); |
6722 | 6698 | ||
6723 | cpulist_scnprintf(str, sizeof(str), &group->cpumask); | 6699 | cpulist_scnprintf(str, sizeof(str), sched_group_cpus(group)); |
6724 | printk(KERN_CONT " %s", str); | 6700 | printk(KERN_CONT " %s", str); |
6725 | 6701 | ||
6726 | group = group->next; | 6702 | group = group->next; |
6727 | } while (group != sd->groups); | 6703 | } while (group != sd->groups); |
6728 | printk(KERN_CONT "\n"); | 6704 | printk(KERN_CONT "\n"); |
6729 | 6705 | ||
6730 | if (!cpus_equal(sd->span, *groupmask)) | 6706 | if (!cpumask_equal(sched_domain_span(sd), groupmask)) |
6731 | printk(KERN_ERR "ERROR: groups don't span domain->span\n"); | 6707 | printk(KERN_ERR "ERROR: groups don't span domain->span\n"); |
6732 | 6708 | ||
6733 | if (sd->parent && !cpus_subset(*groupmask, sd->parent->span)) | 6709 | if (sd->parent && |
6710 | !cpumask_subset(groupmask, sched_domain_span(sd->parent))) | ||
6734 | printk(KERN_ERR "ERROR: parent span is not a superset " | 6711 | printk(KERN_ERR "ERROR: parent span is not a superset " |
6735 | "of domain->span\n"); | 6712 | "of domain->span\n"); |
6736 | return 0; | 6713 | return 0; |
@@ -6738,7 +6715,7 @@ static int sched_domain_debug_one(struct sched_domain *sd, int cpu, int level, | |||
6738 | 6715 | ||
6739 | static void sched_domain_debug(struct sched_domain *sd, int cpu) | 6716 | static void sched_domain_debug(struct sched_domain *sd, int cpu) |
6740 | { | 6717 | { |
6741 | cpumask_t *groupmask; | 6718 | cpumask_var_t groupmask; |
6742 | int level = 0; | 6719 | int level = 0; |
6743 | 6720 | ||
6744 | if (!sd) { | 6721 | if (!sd) { |
@@ -6748,8 +6725,7 @@ static void sched_domain_debug(struct sched_domain *sd, int cpu) | |||
6748 | 6725 | ||
6749 | printk(KERN_DEBUG "CPU%d attaching sched-domain:\n", cpu); | 6726 | printk(KERN_DEBUG "CPU%d attaching sched-domain:\n", cpu); |
6750 | 6727 | ||
6751 | groupmask = kmalloc(sizeof(cpumask_t), GFP_KERNEL); | 6728 | if (!alloc_cpumask_var(&groupmask, GFP_KERNEL)) { |
6752 | if (!groupmask) { | ||
6753 | printk(KERN_DEBUG "Cannot load-balance (out of memory)\n"); | 6729 | printk(KERN_DEBUG "Cannot load-balance (out of memory)\n"); |
6754 | return; | 6730 | return; |
6755 | } | 6731 | } |
@@ -6762,7 +6738,7 @@ static void sched_domain_debug(struct sched_domain *sd, int cpu) | |||
6762 | if (!sd) | 6738 | if (!sd) |
6763 | break; | 6739 | break; |
6764 | } | 6740 | } |
6765 | kfree(groupmask); | 6741 | free_cpumask_var(groupmask); |
6766 | } | 6742 | } |
6767 | #else /* !CONFIG_SCHED_DEBUG */ | 6743 | #else /* !CONFIG_SCHED_DEBUG */ |
6768 | # define sched_domain_debug(sd, cpu) do { } while (0) | 6744 | # define sched_domain_debug(sd, cpu) do { } while (0) |
@@ -6770,7 +6746,7 @@ static void sched_domain_debug(struct sched_domain *sd, int cpu) | |||
6770 | 6746 | ||
6771 | static int sd_degenerate(struct sched_domain *sd) | 6747 | static int sd_degenerate(struct sched_domain *sd) |
6772 | { | 6748 | { |
6773 | if (cpus_weight(sd->span) == 1) | 6749 | if (cpumask_weight(sched_domain_span(sd)) == 1) |
6774 | return 1; | 6750 | return 1; |
6775 | 6751 | ||
6776 | /* Following flags need at least 2 groups */ | 6752 | /* Following flags need at least 2 groups */ |
@@ -6801,7 +6777,7 @@ sd_parent_degenerate(struct sched_domain *sd, struct sched_domain *parent) | |||
6801 | if (sd_degenerate(parent)) | 6777 | if (sd_degenerate(parent)) |
6802 | return 1; | 6778 | return 1; |
6803 | 6779 | ||
6804 | if (!cpus_equal(sd->span, parent->span)) | 6780 | if (!cpumask_equal(sched_domain_span(sd), sched_domain_span(parent))) |
6805 | return 0; | 6781 | return 0; |
6806 | 6782 | ||
6807 | /* Does parent contain flags not in child? */ | 6783 | /* Does parent contain flags not in child? */ |
@@ -6816,6 +6792,8 @@ sd_parent_degenerate(struct sched_domain *sd, struct sched_domain *parent) | |||
6816 | SD_BALANCE_EXEC | | 6792 | SD_BALANCE_EXEC | |
6817 | SD_SHARE_CPUPOWER | | 6793 | SD_SHARE_CPUPOWER | |
6818 | SD_SHARE_PKG_RESOURCES); | 6794 | SD_SHARE_PKG_RESOURCES); |
6795 | if (nr_node_ids == 1) | ||
6796 | pflags &= ~SD_SERIALIZE; | ||
6819 | } | 6797 | } |
6820 | if (~cflags & pflags) | 6798 | if (~cflags & pflags) |
6821 | return 0; | 6799 | return 0; |
@@ -6823,6 +6801,16 @@ sd_parent_degenerate(struct sched_domain *sd, struct sched_domain *parent) | |||
6823 | return 1; | 6801 | return 1; |
6824 | } | 6802 | } |
6825 | 6803 | ||
6804 | static void free_rootdomain(struct root_domain *rd) | ||
6805 | { | ||
6806 | cpupri_cleanup(&rd->cpupri); | ||
6807 | |||
6808 | free_cpumask_var(rd->rto_mask); | ||
6809 | free_cpumask_var(rd->online); | ||
6810 | free_cpumask_var(rd->span); | ||
6811 | kfree(rd); | ||
6812 | } | ||
6813 | |||
6826 | static void rq_attach_root(struct rq *rq, struct root_domain *rd) | 6814 | static void rq_attach_root(struct rq *rq, struct root_domain *rd) |
6827 | { | 6815 | { |
6828 | unsigned long flags; | 6816 | unsigned long flags; |
@@ -6832,38 +6820,63 @@ static void rq_attach_root(struct rq *rq, struct root_domain *rd) | |||
6832 | if (rq->rd) { | 6820 | if (rq->rd) { |
6833 | struct root_domain *old_rd = rq->rd; | 6821 | struct root_domain *old_rd = rq->rd; |
6834 | 6822 | ||
6835 | if (cpu_isset(rq->cpu, old_rd->online)) | 6823 | if (cpumask_test_cpu(rq->cpu, old_rd->online)) |
6836 | set_rq_offline(rq); | 6824 | set_rq_offline(rq); |
6837 | 6825 | ||
6838 | cpu_clear(rq->cpu, old_rd->span); | 6826 | cpumask_clear_cpu(rq->cpu, old_rd->span); |
6839 | 6827 | ||
6840 | if (atomic_dec_and_test(&old_rd->refcount)) | 6828 | if (atomic_dec_and_test(&old_rd->refcount)) |
6841 | kfree(old_rd); | 6829 | free_rootdomain(old_rd); |
6842 | } | 6830 | } |
6843 | 6831 | ||
6844 | atomic_inc(&rd->refcount); | 6832 | atomic_inc(&rd->refcount); |
6845 | rq->rd = rd; | 6833 | rq->rd = rd; |
6846 | 6834 | ||
6847 | cpu_set(rq->cpu, rd->span); | 6835 | cpumask_set_cpu(rq->cpu, rd->span); |
6848 | if (cpu_isset(rq->cpu, cpu_online_map)) | 6836 | if (cpumask_test_cpu(rq->cpu, cpu_online_mask)) |
6849 | set_rq_online(rq); | 6837 | set_rq_online(rq); |
6850 | 6838 | ||
6851 | spin_unlock_irqrestore(&rq->lock, flags); | 6839 | spin_unlock_irqrestore(&rq->lock, flags); |
6852 | } | 6840 | } |
6853 | 6841 | ||
6854 | static void init_rootdomain(struct root_domain *rd) | 6842 | static int init_rootdomain(struct root_domain *rd, bool bootmem) |
6855 | { | 6843 | { |
6856 | memset(rd, 0, sizeof(*rd)); | 6844 | memset(rd, 0, sizeof(*rd)); |
6857 | 6845 | ||
6858 | cpus_clear(rd->span); | 6846 | if (bootmem) { |
6859 | cpus_clear(rd->online); | 6847 | alloc_bootmem_cpumask_var(&def_root_domain.span); |
6848 | alloc_bootmem_cpumask_var(&def_root_domain.online); | ||
6849 | alloc_bootmem_cpumask_var(&def_root_domain.rto_mask); | ||
6850 | cpupri_init(&rd->cpupri, true); | ||
6851 | return 0; | ||
6852 | } | ||
6853 | |||
6854 | if (!alloc_cpumask_var(&rd->span, GFP_KERNEL)) | ||
6855 | goto free_rd; | ||
6856 | if (!alloc_cpumask_var(&rd->online, GFP_KERNEL)) | ||
6857 | goto free_span; | ||
6858 | if (!alloc_cpumask_var(&rd->rto_mask, GFP_KERNEL)) | ||
6859 | goto free_online; | ||
6860 | |||
6861 | if (cpupri_init(&rd->cpupri, false) != 0) | ||
6862 | goto free_rto_mask; | ||
6863 | return 0; | ||
6860 | 6864 | ||
6861 | cpupri_init(&rd->cpupri); | 6865 | free_rto_mask: |
6866 | free_cpumask_var(rd->rto_mask); | ||
6867 | free_online: | ||
6868 | free_cpumask_var(rd->online); | ||
6869 | free_span: | ||
6870 | free_cpumask_var(rd->span); | ||
6871 | free_rd: | ||
6872 | kfree(rd); | ||
6873 | return -ENOMEM; | ||
6862 | } | 6874 | } |
6863 | 6875 | ||
6864 | static void init_defrootdomain(void) | 6876 | static void init_defrootdomain(void) |
6865 | { | 6877 | { |
6866 | init_rootdomain(&def_root_domain); | 6878 | init_rootdomain(&def_root_domain, true); |
6879 | |||
6867 | atomic_set(&def_root_domain.refcount, 1); | 6880 | atomic_set(&def_root_domain.refcount, 1); |
6868 | } | 6881 | } |
6869 | 6882 | ||
@@ -6875,7 +6888,10 @@ static struct root_domain *alloc_rootdomain(void) | |||
6875 | if (!rd) | 6888 | if (!rd) |
6876 | return NULL; | 6889 | return NULL; |
6877 | 6890 | ||
6878 | init_rootdomain(rd); | 6891 | if (init_rootdomain(rd, false) != 0) { |
6892 | kfree(rd); | ||
6893 | return NULL; | ||
6894 | } | ||
6879 | 6895 | ||
6880 | return rd; | 6896 | return rd; |
6881 | } | 6897 | } |
@@ -6917,19 +6933,12 @@ cpu_attach_domain(struct sched_domain *sd, struct root_domain *rd, int cpu) | |||
6917 | } | 6933 | } |
6918 | 6934 | ||
6919 | /* cpus with isolated domains */ | 6935 | /* cpus with isolated domains */ |
6920 | static cpumask_t cpu_isolated_map = CPU_MASK_NONE; | 6936 | static cpumask_var_t cpu_isolated_map; |
6921 | 6937 | ||
6922 | /* Setup the mask of cpus configured for isolated domains */ | 6938 | /* Setup the mask of cpus configured for isolated domains */ |
6923 | static int __init isolated_cpu_setup(char *str) | 6939 | static int __init isolated_cpu_setup(char *str) |
6924 | { | 6940 | { |
6925 | static int __initdata ints[NR_CPUS]; | 6941 | cpulist_parse(str, cpu_isolated_map); |
6926 | int i; | ||
6927 | |||
6928 | str = get_options(str, ARRAY_SIZE(ints), ints); | ||
6929 | cpus_clear(cpu_isolated_map); | ||
6930 | for (i = 1; i <= ints[0]; i++) | ||
6931 | if (ints[i] < NR_CPUS) | ||
6932 | cpu_set(ints[i], cpu_isolated_map); | ||
6933 | return 1; | 6942 | return 1; |
6934 | } | 6943 | } |
6935 | 6944 | ||
@@ -6938,42 +6947,43 @@ __setup("isolcpus=", isolated_cpu_setup); | |||
6938 | /* | 6947 | /* |
6939 | * init_sched_build_groups takes the cpumask we wish to span, and a pointer | 6948 | * init_sched_build_groups takes the cpumask we wish to span, and a pointer |
6940 | * to a function which identifies what group(along with sched group) a CPU | 6949 | * to a function which identifies what group(along with sched group) a CPU |
6941 | * belongs to. The return value of group_fn must be a >= 0 and < NR_CPUS | 6950 | * belongs to. The return value of group_fn must be a >= 0 and < nr_cpu_ids |
6942 | * (due to the fact that we keep track of groups covered with a cpumask_t). | 6951 | * (due to the fact that we keep track of groups covered with a struct cpumask). |
6943 | * | 6952 | * |
6944 | * init_sched_build_groups will build a circular linked list of the groups | 6953 | * init_sched_build_groups will build a circular linked list of the groups |
6945 | * covered by the given span, and will set each group's ->cpumask correctly, | 6954 | * covered by the given span, and will set each group's ->cpumask correctly, |
6946 | * and ->cpu_power to 0. | 6955 | * and ->cpu_power to 0. |
6947 | */ | 6956 | */ |
6948 | static void | 6957 | static void |
6949 | init_sched_build_groups(const cpumask_t *span, const cpumask_t *cpu_map, | 6958 | init_sched_build_groups(const struct cpumask *span, |
6950 | int (*group_fn)(int cpu, const cpumask_t *cpu_map, | 6959 | const struct cpumask *cpu_map, |
6960 | int (*group_fn)(int cpu, const struct cpumask *cpu_map, | ||
6951 | struct sched_group **sg, | 6961 | struct sched_group **sg, |
6952 | cpumask_t *tmpmask), | 6962 | struct cpumask *tmpmask), |
6953 | cpumask_t *covered, cpumask_t *tmpmask) | 6963 | struct cpumask *covered, struct cpumask *tmpmask) |
6954 | { | 6964 | { |
6955 | struct sched_group *first = NULL, *last = NULL; | 6965 | struct sched_group *first = NULL, *last = NULL; |
6956 | int i; | 6966 | int i; |
6957 | 6967 | ||
6958 | cpus_clear(*covered); | 6968 | cpumask_clear(covered); |
6959 | 6969 | ||
6960 | for_each_cpu_mask_nr(i, *span) { | 6970 | for_each_cpu(i, span) { |
6961 | struct sched_group *sg; | 6971 | struct sched_group *sg; |
6962 | int group = group_fn(i, cpu_map, &sg, tmpmask); | 6972 | int group = group_fn(i, cpu_map, &sg, tmpmask); |
6963 | int j; | 6973 | int j; |
6964 | 6974 | ||
6965 | if (cpu_isset(i, *covered)) | 6975 | if (cpumask_test_cpu(i, covered)) |
6966 | continue; | 6976 | continue; |
6967 | 6977 | ||
6968 | cpus_clear(sg->cpumask); | 6978 | cpumask_clear(sched_group_cpus(sg)); |
6969 | sg->__cpu_power = 0; | 6979 | sg->__cpu_power = 0; |
6970 | 6980 | ||
6971 | for_each_cpu_mask_nr(j, *span) { | 6981 | for_each_cpu(j, span) { |
6972 | if (group_fn(j, cpu_map, NULL, tmpmask) != group) | 6982 | if (group_fn(j, cpu_map, NULL, tmpmask) != group) |
6973 | continue; | 6983 | continue; |
6974 | 6984 | ||
6975 | cpu_set(j, *covered); | 6985 | cpumask_set_cpu(j, covered); |
6976 | cpu_set(j, sg->cpumask); | 6986 | cpumask_set_cpu(j, sched_group_cpus(sg)); |
6977 | } | 6987 | } |
6978 | if (!first) | 6988 | if (!first) |
6979 | first = sg; | 6989 | first = sg; |
@@ -7037,9 +7047,10 @@ static int find_next_best_node(int node, nodemask_t *used_nodes) | |||
7037 | * should be one that prevents unnecessary balancing, but also spreads tasks | 7047 | * should be one that prevents unnecessary balancing, but also spreads tasks |
7038 | * out optimally. | 7048 | * out optimally. |
7039 | */ | 7049 | */ |
7040 | static void sched_domain_node_span(int node, cpumask_t *span) | 7050 | static void sched_domain_node_span(int node, struct cpumask *span) |
7041 | { | 7051 | { |
7042 | nodemask_t used_nodes; | 7052 | nodemask_t used_nodes; |
7053 | /* FIXME: use cpumask_of_node() */ | ||
7043 | node_to_cpumask_ptr(nodemask, node); | 7054 | node_to_cpumask_ptr(nodemask, node); |
7044 | int i; | 7055 | int i; |
7045 | 7056 | ||
@@ -7061,18 +7072,33 @@ static void sched_domain_node_span(int node, cpumask_t *span) | |||
7061 | int sched_smt_power_savings = 0, sched_mc_power_savings = 0; | 7072 | int sched_smt_power_savings = 0, sched_mc_power_savings = 0; |
7062 | 7073 | ||
7063 | /* | 7074 | /* |
7075 | * The cpus mask in sched_group and sched_domain hangs off the end. | ||
7076 | * FIXME: use cpumask_var_t or dynamic percpu alloc to avoid wasting space | ||
7077 | * for nr_cpu_ids < CONFIG_NR_CPUS. | ||
7078 | */ | ||
7079 | struct static_sched_group { | ||
7080 | struct sched_group sg; | ||
7081 | DECLARE_BITMAP(cpus, CONFIG_NR_CPUS); | ||
7082 | }; | ||
7083 | |||
7084 | struct static_sched_domain { | ||
7085 | struct sched_domain sd; | ||
7086 | DECLARE_BITMAP(span, CONFIG_NR_CPUS); | ||
7087 | }; | ||
7088 | |||
7089 | /* | ||
7064 | * SMT sched-domains: | 7090 | * SMT sched-domains: |
7065 | */ | 7091 | */ |
7066 | #ifdef CONFIG_SCHED_SMT | 7092 | #ifdef CONFIG_SCHED_SMT |
7067 | static DEFINE_PER_CPU(struct sched_domain, cpu_domains); | 7093 | static DEFINE_PER_CPU(struct static_sched_domain, cpu_domains); |
7068 | static DEFINE_PER_CPU(struct sched_group, sched_group_cpus); | 7094 | static DEFINE_PER_CPU(struct static_sched_group, sched_group_cpus); |
7069 | 7095 | ||
7070 | static int | 7096 | static int |
7071 | cpu_to_cpu_group(int cpu, const cpumask_t *cpu_map, struct sched_group **sg, | 7097 | cpu_to_cpu_group(int cpu, const struct cpumask *cpu_map, |
7072 | cpumask_t *unused) | 7098 | struct sched_group **sg, struct cpumask *unused) |
7073 | { | 7099 | { |
7074 | if (sg) | 7100 | if (sg) |
7075 | *sg = &per_cpu(sched_group_cpus, cpu); | 7101 | *sg = &per_cpu(sched_group_cpus, cpu).sg; |
7076 | return cpu; | 7102 | return cpu; |
7077 | } | 7103 | } |
7078 | #endif /* CONFIG_SCHED_SMT */ | 7104 | #endif /* CONFIG_SCHED_SMT */ |
@@ -7081,56 +7107,55 @@ cpu_to_cpu_group(int cpu, const cpumask_t *cpu_map, struct sched_group **sg, | |||
7081 | * multi-core sched-domains: | 7107 | * multi-core sched-domains: |
7082 | */ | 7108 | */ |
7083 | #ifdef CONFIG_SCHED_MC | 7109 | #ifdef CONFIG_SCHED_MC |
7084 | static DEFINE_PER_CPU(struct sched_domain, core_domains); | 7110 | static DEFINE_PER_CPU(struct static_sched_domain, core_domains); |
7085 | static DEFINE_PER_CPU(struct sched_group, sched_group_core); | 7111 | static DEFINE_PER_CPU(struct static_sched_group, sched_group_core); |
7086 | #endif /* CONFIG_SCHED_MC */ | 7112 | #endif /* CONFIG_SCHED_MC */ |
7087 | 7113 | ||
7088 | #if defined(CONFIG_SCHED_MC) && defined(CONFIG_SCHED_SMT) | 7114 | #if defined(CONFIG_SCHED_MC) && defined(CONFIG_SCHED_SMT) |
7089 | static int | 7115 | static int |
7090 | cpu_to_core_group(int cpu, const cpumask_t *cpu_map, struct sched_group **sg, | 7116 | cpu_to_core_group(int cpu, const struct cpumask *cpu_map, |
7091 | cpumask_t *mask) | 7117 | struct sched_group **sg, struct cpumask *mask) |
7092 | { | 7118 | { |
7093 | int group; | 7119 | int group; |
7094 | 7120 | ||
7095 | *mask = per_cpu(cpu_sibling_map, cpu); | 7121 | cpumask_and(mask, &per_cpu(cpu_sibling_map, cpu), cpu_map); |
7096 | cpus_and(*mask, *mask, *cpu_map); | 7122 | group = cpumask_first(mask); |
7097 | group = first_cpu(*mask); | ||
7098 | if (sg) | 7123 | if (sg) |
7099 | *sg = &per_cpu(sched_group_core, group); | 7124 | *sg = &per_cpu(sched_group_core, group).sg; |
7100 | return group; | 7125 | return group; |
7101 | } | 7126 | } |
7102 | #elif defined(CONFIG_SCHED_MC) | 7127 | #elif defined(CONFIG_SCHED_MC) |
7103 | static int | 7128 | static int |
7104 | cpu_to_core_group(int cpu, const cpumask_t *cpu_map, struct sched_group **sg, | 7129 | cpu_to_core_group(int cpu, const struct cpumask *cpu_map, |
7105 | cpumask_t *unused) | 7130 | struct sched_group **sg, struct cpumask *unused) |
7106 | { | 7131 | { |
7107 | if (sg) | 7132 | if (sg) |
7108 | *sg = &per_cpu(sched_group_core, cpu); | 7133 | *sg = &per_cpu(sched_group_core, cpu).sg; |
7109 | return cpu; | 7134 | return cpu; |
7110 | } | 7135 | } |
7111 | #endif | 7136 | #endif |
7112 | 7137 | ||
7113 | static DEFINE_PER_CPU(struct sched_domain, phys_domains); | 7138 | static DEFINE_PER_CPU(struct static_sched_domain, phys_domains); |
7114 | static DEFINE_PER_CPU(struct sched_group, sched_group_phys); | 7139 | static DEFINE_PER_CPU(struct static_sched_group, sched_group_phys); |
7115 | 7140 | ||
7116 | static int | 7141 | static int |
7117 | cpu_to_phys_group(int cpu, const cpumask_t *cpu_map, struct sched_group **sg, | 7142 | cpu_to_phys_group(int cpu, const struct cpumask *cpu_map, |
7118 | cpumask_t *mask) | 7143 | struct sched_group **sg, struct cpumask *mask) |
7119 | { | 7144 | { |
7120 | int group; | 7145 | int group; |
7121 | #ifdef CONFIG_SCHED_MC | 7146 | #ifdef CONFIG_SCHED_MC |
7147 | /* FIXME: Use cpu_coregroup_mask. */ | ||
7122 | *mask = cpu_coregroup_map(cpu); | 7148 | *mask = cpu_coregroup_map(cpu); |
7123 | cpus_and(*mask, *mask, *cpu_map); | 7149 | cpus_and(*mask, *mask, *cpu_map); |
7124 | group = first_cpu(*mask); | 7150 | group = cpumask_first(mask); |
7125 | #elif defined(CONFIG_SCHED_SMT) | 7151 | #elif defined(CONFIG_SCHED_SMT) |
7126 | *mask = per_cpu(cpu_sibling_map, cpu); | 7152 | cpumask_and(mask, &per_cpu(cpu_sibling_map, cpu), cpu_map); |
7127 | cpus_and(*mask, *mask, *cpu_map); | 7153 | group = cpumask_first(mask); |
7128 | group = first_cpu(*mask); | ||
7129 | #else | 7154 | #else |
7130 | group = cpu; | 7155 | group = cpu; |
7131 | #endif | 7156 | #endif |
7132 | if (sg) | 7157 | if (sg) |
7133 | *sg = &per_cpu(sched_group_phys, group); | 7158 | *sg = &per_cpu(sched_group_phys, group).sg; |
7134 | return group; | 7159 | return group; |
7135 | } | 7160 | } |
7136 | 7161 | ||
@@ -7144,19 +7169,21 @@ static DEFINE_PER_CPU(struct sched_domain, node_domains); | |||
7144 | static struct sched_group ***sched_group_nodes_bycpu; | 7169 | static struct sched_group ***sched_group_nodes_bycpu; |
7145 | 7170 | ||
7146 | static DEFINE_PER_CPU(struct sched_domain, allnodes_domains); | 7171 | static DEFINE_PER_CPU(struct sched_domain, allnodes_domains); |
7147 | static DEFINE_PER_CPU(struct sched_group, sched_group_allnodes); | 7172 | static DEFINE_PER_CPU(struct static_sched_group, sched_group_allnodes); |
7148 | 7173 | ||
7149 | static int cpu_to_allnodes_group(int cpu, const cpumask_t *cpu_map, | 7174 | static int cpu_to_allnodes_group(int cpu, const struct cpumask *cpu_map, |
7150 | struct sched_group **sg, cpumask_t *nodemask) | 7175 | struct sched_group **sg, |
7176 | struct cpumask *nodemask) | ||
7151 | { | 7177 | { |
7152 | int group; | 7178 | int group; |
7179 | /* FIXME: use cpumask_of_node */ | ||
7180 | node_to_cpumask_ptr(pnodemask, cpu_to_node(cpu)); | ||
7153 | 7181 | ||
7154 | *nodemask = node_to_cpumask(cpu_to_node(cpu)); | 7182 | cpumask_and(nodemask, pnodemask, cpu_map); |
7155 | cpus_and(*nodemask, *nodemask, *cpu_map); | 7183 | group = cpumask_first(nodemask); |
7156 | group = first_cpu(*nodemask); | ||
7157 | 7184 | ||
7158 | if (sg) | 7185 | if (sg) |
7159 | *sg = &per_cpu(sched_group_allnodes, group); | 7186 | *sg = &per_cpu(sched_group_allnodes, group).sg; |
7160 | return group; | 7187 | return group; |
7161 | } | 7188 | } |
7162 | 7189 | ||
@@ -7168,11 +7195,11 @@ static void init_numa_sched_groups_power(struct sched_group *group_head) | |||
7168 | if (!sg) | 7195 | if (!sg) |
7169 | return; | 7196 | return; |
7170 | do { | 7197 | do { |
7171 | for_each_cpu_mask_nr(j, sg->cpumask) { | 7198 | for_each_cpu(j, sched_group_cpus(sg)) { |
7172 | struct sched_domain *sd; | 7199 | struct sched_domain *sd; |
7173 | 7200 | ||
7174 | sd = &per_cpu(phys_domains, j); | 7201 | sd = &per_cpu(phys_domains, j).sd; |
7175 | if (j != first_cpu(sd->groups->cpumask)) { | 7202 | if (j != cpumask_first(sched_group_cpus(sd->groups))) { |
7176 | /* | 7203 | /* |
7177 | * Only add "power" once for each | 7204 | * Only add "power" once for each |
7178 | * physical package. | 7205 | * physical package. |
@@ -7189,11 +7216,12 @@ static void init_numa_sched_groups_power(struct sched_group *group_head) | |||
7189 | 7216 | ||
7190 | #ifdef CONFIG_NUMA | 7217 | #ifdef CONFIG_NUMA |
7191 | /* Free memory allocated for various sched_group structures */ | 7218 | /* Free memory allocated for various sched_group structures */ |
7192 | static void free_sched_groups(const cpumask_t *cpu_map, cpumask_t *nodemask) | 7219 | static void free_sched_groups(const struct cpumask *cpu_map, |
7220 | struct cpumask *nodemask) | ||
7193 | { | 7221 | { |
7194 | int cpu, i; | 7222 | int cpu, i; |
7195 | 7223 | ||
7196 | for_each_cpu_mask_nr(cpu, *cpu_map) { | 7224 | for_each_cpu(cpu, cpu_map) { |
7197 | struct sched_group **sched_group_nodes | 7225 | struct sched_group **sched_group_nodes |
7198 | = sched_group_nodes_bycpu[cpu]; | 7226 | = sched_group_nodes_bycpu[cpu]; |
7199 | 7227 | ||
@@ -7202,10 +7230,11 @@ static void free_sched_groups(const cpumask_t *cpu_map, cpumask_t *nodemask) | |||
7202 | 7230 | ||
7203 | for (i = 0; i < nr_node_ids; i++) { | 7231 | for (i = 0; i < nr_node_ids; i++) { |
7204 | struct sched_group *oldsg, *sg = sched_group_nodes[i]; | 7232 | struct sched_group *oldsg, *sg = sched_group_nodes[i]; |
7233 | /* FIXME: Use cpumask_of_node */ | ||
7234 | node_to_cpumask_ptr(pnodemask, i); | ||
7205 | 7235 | ||
7206 | *nodemask = node_to_cpumask(i); | 7236 | cpus_and(*nodemask, *pnodemask, *cpu_map); |
7207 | cpus_and(*nodemask, *nodemask, *cpu_map); | 7237 | if (cpumask_empty(nodemask)) |
7208 | if (cpus_empty(*nodemask)) | ||
7209 | continue; | 7238 | continue; |
7210 | 7239 | ||
7211 | if (sg == NULL) | 7240 | if (sg == NULL) |
@@ -7223,7 +7252,8 @@ next_sg: | |||
7223 | } | 7252 | } |
7224 | } | 7253 | } |
7225 | #else /* !CONFIG_NUMA */ | 7254 | #else /* !CONFIG_NUMA */ |
7226 | static void free_sched_groups(const cpumask_t *cpu_map, cpumask_t *nodemask) | 7255 | static void free_sched_groups(const struct cpumask *cpu_map, |
7256 | struct cpumask *nodemask) | ||
7227 | { | 7257 | { |
7228 | } | 7258 | } |
7229 | #endif /* CONFIG_NUMA */ | 7259 | #endif /* CONFIG_NUMA */ |
@@ -7249,7 +7279,7 @@ static void init_sched_groups_power(int cpu, struct sched_domain *sd) | |||
7249 | 7279 | ||
7250 | WARN_ON(!sd || !sd->groups); | 7280 | WARN_ON(!sd || !sd->groups); |
7251 | 7281 | ||
7252 | if (cpu != first_cpu(sd->groups->cpumask)) | 7282 | if (cpu != cpumask_first(sched_group_cpus(sd->groups))) |
7253 | return; | 7283 | return; |
7254 | 7284 | ||
7255 | child = sd->child; | 7285 | child = sd->child; |
@@ -7314,40 +7344,6 @@ SD_INIT_FUNC(CPU) | |||
7314 | SD_INIT_FUNC(MC) | 7344 | SD_INIT_FUNC(MC) |
7315 | #endif | 7345 | #endif |
7316 | 7346 | ||
7317 | /* | ||
7318 | * To minimize stack usage kmalloc room for cpumasks and share the | ||
7319 | * space as the usage in build_sched_domains() dictates. Used only | ||
7320 | * if the amount of space is significant. | ||
7321 | */ | ||
7322 | struct allmasks { | ||
7323 | cpumask_t tmpmask; /* make this one first */ | ||
7324 | union { | ||
7325 | cpumask_t nodemask; | ||
7326 | cpumask_t this_sibling_map; | ||
7327 | cpumask_t this_core_map; | ||
7328 | }; | ||
7329 | cpumask_t send_covered; | ||
7330 | |||
7331 | #ifdef CONFIG_NUMA | ||
7332 | cpumask_t domainspan; | ||
7333 | cpumask_t covered; | ||
7334 | cpumask_t notcovered; | ||
7335 | #endif | ||
7336 | }; | ||
7337 | |||
7338 | #if NR_CPUS > 128 | ||
7339 | #define SCHED_CPUMASK_ALLOC 1 | ||
7340 | #define SCHED_CPUMASK_FREE(v) kfree(v) | ||
7341 | #define SCHED_CPUMASK_DECLARE(v) struct allmasks *v | ||
7342 | #else | ||
7343 | #define SCHED_CPUMASK_ALLOC 0 | ||
7344 | #define SCHED_CPUMASK_FREE(v) | ||
7345 | #define SCHED_CPUMASK_DECLARE(v) struct allmasks _v, *v = &_v | ||
7346 | #endif | ||
7347 | |||
7348 | #define SCHED_CPUMASK_VAR(v, a) cpumask_t *v = (cpumask_t *) \ | ||
7349 | ((unsigned long)(a) + offsetof(struct allmasks, v)) | ||
7350 | |||
7351 | static int default_relax_domain_level = -1; | 7347 | static int default_relax_domain_level = -1; |
7352 | 7348 | ||
7353 | static int __init setup_relax_domain_level(char *str) | 7349 | static int __init setup_relax_domain_level(char *str) |
@@ -7387,17 +7383,38 @@ static void set_domain_attribute(struct sched_domain *sd, | |||
7387 | * Build sched domains for a given set of cpus and attach the sched domains | 7383 | * Build sched domains for a given set of cpus and attach the sched domains |
7388 | * to the individual cpus | 7384 | * to the individual cpus |
7389 | */ | 7385 | */ |
7390 | static int __build_sched_domains(const cpumask_t *cpu_map, | 7386 | static int __build_sched_domains(const struct cpumask *cpu_map, |
7391 | struct sched_domain_attr *attr) | 7387 | struct sched_domain_attr *attr) |
7392 | { | 7388 | { |
7393 | int i; | 7389 | int i, err = -ENOMEM; |
7394 | struct root_domain *rd; | 7390 | struct root_domain *rd; |
7395 | SCHED_CPUMASK_DECLARE(allmasks); | 7391 | cpumask_var_t nodemask, this_sibling_map, this_core_map, send_covered, |
7396 | cpumask_t *tmpmask; | 7392 | tmpmask; |
7397 | #ifdef CONFIG_NUMA | 7393 | #ifdef CONFIG_NUMA |
7394 | cpumask_var_t domainspan, covered, notcovered; | ||
7398 | struct sched_group **sched_group_nodes = NULL; | 7395 | struct sched_group **sched_group_nodes = NULL; |
7399 | int sd_allnodes = 0; | 7396 | int sd_allnodes = 0; |
7400 | 7397 | ||
7398 | if (!alloc_cpumask_var(&domainspan, GFP_KERNEL)) | ||
7399 | goto out; | ||
7400 | if (!alloc_cpumask_var(&covered, GFP_KERNEL)) | ||
7401 | goto free_domainspan; | ||
7402 | if (!alloc_cpumask_var(¬covered, GFP_KERNEL)) | ||
7403 | goto free_covered; | ||
7404 | #endif | ||
7405 | |||
7406 | if (!alloc_cpumask_var(&nodemask, GFP_KERNEL)) | ||
7407 | goto free_notcovered; | ||
7408 | if (!alloc_cpumask_var(&this_sibling_map, GFP_KERNEL)) | ||
7409 | goto free_nodemask; | ||
7410 | if (!alloc_cpumask_var(&this_core_map, GFP_KERNEL)) | ||
7411 | goto free_this_sibling_map; | ||
7412 | if (!alloc_cpumask_var(&send_covered, GFP_KERNEL)) | ||
7413 | goto free_this_core_map; | ||
7414 | if (!alloc_cpumask_var(&tmpmask, GFP_KERNEL)) | ||
7415 | goto free_send_covered; | ||
7416 | |||
7417 | #ifdef CONFIG_NUMA | ||
7401 | /* | 7418 | /* |
7402 | * Allocate the per-node list of sched groups | 7419 | * Allocate the per-node list of sched groups |
7403 | */ | 7420 | */ |
@@ -7405,55 +7422,37 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7405 | GFP_KERNEL); | 7422 | GFP_KERNEL); |
7406 | if (!sched_group_nodes) { | 7423 | if (!sched_group_nodes) { |
7407 | printk(KERN_WARNING "Can not alloc sched group node list\n"); | 7424 | printk(KERN_WARNING "Can not alloc sched group node list\n"); |
7408 | return -ENOMEM; | 7425 | goto free_tmpmask; |
7409 | } | 7426 | } |
7410 | #endif | 7427 | #endif |
7411 | 7428 | ||
7412 | rd = alloc_rootdomain(); | 7429 | rd = alloc_rootdomain(); |
7413 | if (!rd) { | 7430 | if (!rd) { |
7414 | printk(KERN_WARNING "Cannot alloc root domain\n"); | 7431 | printk(KERN_WARNING "Cannot alloc root domain\n"); |
7415 | #ifdef CONFIG_NUMA | 7432 | goto free_sched_groups; |
7416 | kfree(sched_group_nodes); | ||
7417 | #endif | ||
7418 | return -ENOMEM; | ||
7419 | } | 7433 | } |
7420 | 7434 | ||
7421 | #if SCHED_CPUMASK_ALLOC | ||
7422 | /* get space for all scratch cpumask variables */ | ||
7423 | allmasks = kmalloc(sizeof(*allmasks), GFP_KERNEL); | ||
7424 | if (!allmasks) { | ||
7425 | printk(KERN_WARNING "Cannot alloc cpumask array\n"); | ||
7426 | kfree(rd); | ||
7427 | #ifdef CONFIG_NUMA | 7435 | #ifdef CONFIG_NUMA |
7428 | kfree(sched_group_nodes); | 7436 | sched_group_nodes_bycpu[cpumask_first(cpu_map)] = sched_group_nodes; |
7429 | #endif | ||
7430 | return -ENOMEM; | ||
7431 | } | ||
7432 | #endif | ||
7433 | tmpmask = (cpumask_t *)allmasks; | ||
7434 | |||
7435 | |||
7436 | #ifdef CONFIG_NUMA | ||
7437 | sched_group_nodes_bycpu[first_cpu(*cpu_map)] = sched_group_nodes; | ||
7438 | #endif | 7437 | #endif |
7439 | 7438 | ||
7440 | /* | 7439 | /* |
7441 | * Set up domains for cpus specified by the cpu_map. | 7440 | * Set up domains for cpus specified by the cpu_map. |
7442 | */ | 7441 | */ |
7443 | for_each_cpu_mask_nr(i, *cpu_map) { | 7442 | for_each_cpu(i, cpu_map) { |
7444 | struct sched_domain *sd = NULL, *p; | 7443 | struct sched_domain *sd = NULL, *p; |
7445 | SCHED_CPUMASK_VAR(nodemask, allmasks); | ||
7446 | 7444 | ||
7445 | /* FIXME: use cpumask_of_node */ | ||
7447 | *nodemask = node_to_cpumask(cpu_to_node(i)); | 7446 | *nodemask = node_to_cpumask(cpu_to_node(i)); |
7448 | cpus_and(*nodemask, *nodemask, *cpu_map); | 7447 | cpus_and(*nodemask, *nodemask, *cpu_map); |
7449 | 7448 | ||
7450 | #ifdef CONFIG_NUMA | 7449 | #ifdef CONFIG_NUMA |
7451 | if (cpus_weight(*cpu_map) > | 7450 | if (cpumask_weight(cpu_map) > |
7452 | SD_NODES_PER_DOMAIN*cpus_weight(*nodemask)) { | 7451 | SD_NODES_PER_DOMAIN*cpumask_weight(nodemask)) { |
7453 | sd = &per_cpu(allnodes_domains, i); | 7452 | sd = &per_cpu(allnodes_domains, i); |
7454 | SD_INIT(sd, ALLNODES); | 7453 | SD_INIT(sd, ALLNODES); |
7455 | set_domain_attribute(sd, attr); | 7454 | set_domain_attribute(sd, attr); |
7456 | sd->span = *cpu_map; | 7455 | cpumask_copy(sched_domain_span(sd), cpu_map); |
7457 | cpu_to_allnodes_group(i, cpu_map, &sd->groups, tmpmask); | 7456 | cpu_to_allnodes_group(i, cpu_map, &sd->groups, tmpmask); |
7458 | p = sd; | 7457 | p = sd; |
7459 | sd_allnodes = 1; | 7458 | sd_allnodes = 1; |
@@ -7463,18 +7462,19 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7463 | sd = &per_cpu(node_domains, i); | 7462 | sd = &per_cpu(node_domains, i); |
7464 | SD_INIT(sd, NODE); | 7463 | SD_INIT(sd, NODE); |
7465 | set_domain_attribute(sd, attr); | 7464 | set_domain_attribute(sd, attr); |
7466 | sched_domain_node_span(cpu_to_node(i), &sd->span); | 7465 | sched_domain_node_span(cpu_to_node(i), sched_domain_span(sd)); |
7467 | sd->parent = p; | 7466 | sd->parent = p; |
7468 | if (p) | 7467 | if (p) |
7469 | p->child = sd; | 7468 | p->child = sd; |
7470 | cpus_and(sd->span, sd->span, *cpu_map); | 7469 | cpumask_and(sched_domain_span(sd), |
7470 | sched_domain_span(sd), cpu_map); | ||
7471 | #endif | 7471 | #endif |
7472 | 7472 | ||
7473 | p = sd; | 7473 | p = sd; |
7474 | sd = &per_cpu(phys_domains, i); | 7474 | sd = &per_cpu(phys_domains, i).sd; |
7475 | SD_INIT(sd, CPU); | 7475 | SD_INIT(sd, CPU); |
7476 | set_domain_attribute(sd, attr); | 7476 | set_domain_attribute(sd, attr); |
7477 | sd->span = *nodemask; | 7477 | cpumask_copy(sched_domain_span(sd), nodemask); |
7478 | sd->parent = p; | 7478 | sd->parent = p; |
7479 | if (p) | 7479 | if (p) |
7480 | p->child = sd; | 7480 | p->child = sd; |
@@ -7482,11 +7482,12 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7482 | 7482 | ||
7483 | #ifdef CONFIG_SCHED_MC | 7483 | #ifdef CONFIG_SCHED_MC |
7484 | p = sd; | 7484 | p = sd; |
7485 | sd = &per_cpu(core_domains, i); | 7485 | sd = &per_cpu(core_domains, i).sd; |
7486 | SD_INIT(sd, MC); | 7486 | SD_INIT(sd, MC); |
7487 | set_domain_attribute(sd, attr); | 7487 | set_domain_attribute(sd, attr); |
7488 | sd->span = cpu_coregroup_map(i); | 7488 | *sched_domain_span(sd) = cpu_coregroup_map(i); |
7489 | cpus_and(sd->span, sd->span, *cpu_map); | 7489 | cpumask_and(sched_domain_span(sd), |
7490 | sched_domain_span(sd), cpu_map); | ||
7490 | sd->parent = p; | 7491 | sd->parent = p; |
7491 | p->child = sd; | 7492 | p->child = sd; |
7492 | cpu_to_core_group(i, cpu_map, &sd->groups, tmpmask); | 7493 | cpu_to_core_group(i, cpu_map, &sd->groups, tmpmask); |
@@ -7494,11 +7495,11 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7494 | 7495 | ||
7495 | #ifdef CONFIG_SCHED_SMT | 7496 | #ifdef CONFIG_SCHED_SMT |
7496 | p = sd; | 7497 | p = sd; |
7497 | sd = &per_cpu(cpu_domains, i); | 7498 | sd = &per_cpu(cpu_domains, i).sd; |
7498 | SD_INIT(sd, SIBLING); | 7499 | SD_INIT(sd, SIBLING); |
7499 | set_domain_attribute(sd, attr); | 7500 | set_domain_attribute(sd, attr); |
7500 | sd->span = per_cpu(cpu_sibling_map, i); | 7501 | cpumask_and(sched_domain_span(sd), |
7501 | cpus_and(sd->span, sd->span, *cpu_map); | 7502 | &per_cpu(cpu_sibling_map, i), cpu_map); |
7502 | sd->parent = p; | 7503 | sd->parent = p; |
7503 | p->child = sd; | 7504 | p->child = sd; |
7504 | cpu_to_cpu_group(i, cpu_map, &sd->groups, tmpmask); | 7505 | cpu_to_cpu_group(i, cpu_map, &sd->groups, tmpmask); |
@@ -7507,13 +7508,10 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7507 | 7508 | ||
7508 | #ifdef CONFIG_SCHED_SMT | 7509 | #ifdef CONFIG_SCHED_SMT |
7509 | /* Set up CPU (sibling) groups */ | 7510 | /* Set up CPU (sibling) groups */ |
7510 | for_each_cpu_mask_nr(i, *cpu_map) { | 7511 | for_each_cpu(i, cpu_map) { |
7511 | SCHED_CPUMASK_VAR(this_sibling_map, allmasks); | 7512 | cpumask_and(this_sibling_map, |
7512 | SCHED_CPUMASK_VAR(send_covered, allmasks); | 7513 | &per_cpu(cpu_sibling_map, i), cpu_map); |
7513 | 7514 | if (i != cpumask_first(this_sibling_map)) | |
7514 | *this_sibling_map = per_cpu(cpu_sibling_map, i); | ||
7515 | cpus_and(*this_sibling_map, *this_sibling_map, *cpu_map); | ||
7516 | if (i != first_cpu(*this_sibling_map)) | ||
7517 | continue; | 7515 | continue; |
7518 | 7516 | ||
7519 | init_sched_build_groups(this_sibling_map, cpu_map, | 7517 | init_sched_build_groups(this_sibling_map, cpu_map, |
@@ -7524,13 +7522,11 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7524 | 7522 | ||
7525 | #ifdef CONFIG_SCHED_MC | 7523 | #ifdef CONFIG_SCHED_MC |
7526 | /* Set up multi-core groups */ | 7524 | /* Set up multi-core groups */ |
7527 | for_each_cpu_mask_nr(i, *cpu_map) { | 7525 | for_each_cpu(i, cpu_map) { |
7528 | SCHED_CPUMASK_VAR(this_core_map, allmasks); | 7526 | /* FIXME: Use cpu_coregroup_mask */ |
7529 | SCHED_CPUMASK_VAR(send_covered, allmasks); | ||
7530 | |||
7531 | *this_core_map = cpu_coregroup_map(i); | 7527 | *this_core_map = cpu_coregroup_map(i); |
7532 | cpus_and(*this_core_map, *this_core_map, *cpu_map); | 7528 | cpus_and(*this_core_map, *this_core_map, *cpu_map); |
7533 | if (i != first_cpu(*this_core_map)) | 7529 | if (i != cpumask_first(this_core_map)) |
7534 | continue; | 7530 | continue; |
7535 | 7531 | ||
7536 | init_sched_build_groups(this_core_map, cpu_map, | 7532 | init_sched_build_groups(this_core_map, cpu_map, |
@@ -7541,12 +7537,10 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7541 | 7537 | ||
7542 | /* Set up physical groups */ | 7538 | /* Set up physical groups */ |
7543 | for (i = 0; i < nr_node_ids; i++) { | 7539 | for (i = 0; i < nr_node_ids; i++) { |
7544 | SCHED_CPUMASK_VAR(nodemask, allmasks); | 7540 | /* FIXME: Use cpumask_of_node */ |
7545 | SCHED_CPUMASK_VAR(send_covered, allmasks); | ||
7546 | |||
7547 | *nodemask = node_to_cpumask(i); | 7541 | *nodemask = node_to_cpumask(i); |
7548 | cpus_and(*nodemask, *nodemask, *cpu_map); | 7542 | cpus_and(*nodemask, *nodemask, *cpu_map); |
7549 | if (cpus_empty(*nodemask)) | 7543 | if (cpumask_empty(nodemask)) |
7550 | continue; | 7544 | continue; |
7551 | 7545 | ||
7552 | init_sched_build_groups(nodemask, cpu_map, | 7546 | init_sched_build_groups(nodemask, cpu_map, |
@@ -7557,8 +7551,6 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7557 | #ifdef CONFIG_NUMA | 7551 | #ifdef CONFIG_NUMA |
7558 | /* Set up node groups */ | 7552 | /* Set up node groups */ |
7559 | if (sd_allnodes) { | 7553 | if (sd_allnodes) { |
7560 | SCHED_CPUMASK_VAR(send_covered, allmasks); | ||
7561 | |||
7562 | init_sched_build_groups(cpu_map, cpu_map, | 7554 | init_sched_build_groups(cpu_map, cpu_map, |
7563 | &cpu_to_allnodes_group, | 7555 | &cpu_to_allnodes_group, |
7564 | send_covered, tmpmask); | 7556 | send_covered, tmpmask); |
@@ -7567,58 +7559,58 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7567 | for (i = 0; i < nr_node_ids; i++) { | 7559 | for (i = 0; i < nr_node_ids; i++) { |
7568 | /* Set up node groups */ | 7560 | /* Set up node groups */ |
7569 | struct sched_group *sg, *prev; | 7561 | struct sched_group *sg, *prev; |
7570 | SCHED_CPUMASK_VAR(nodemask, allmasks); | ||
7571 | SCHED_CPUMASK_VAR(domainspan, allmasks); | ||
7572 | SCHED_CPUMASK_VAR(covered, allmasks); | ||
7573 | int j; | 7562 | int j; |
7574 | 7563 | ||
7564 | /* FIXME: Use cpumask_of_node */ | ||
7575 | *nodemask = node_to_cpumask(i); | 7565 | *nodemask = node_to_cpumask(i); |
7576 | cpus_clear(*covered); | 7566 | cpumask_clear(covered); |
7577 | 7567 | ||
7578 | cpus_and(*nodemask, *nodemask, *cpu_map); | 7568 | cpus_and(*nodemask, *nodemask, *cpu_map); |
7579 | if (cpus_empty(*nodemask)) { | 7569 | if (cpumask_empty(nodemask)) { |
7580 | sched_group_nodes[i] = NULL; | 7570 | sched_group_nodes[i] = NULL; |
7581 | continue; | 7571 | continue; |
7582 | } | 7572 | } |
7583 | 7573 | ||
7584 | sched_domain_node_span(i, domainspan); | 7574 | sched_domain_node_span(i, domainspan); |
7585 | cpus_and(*domainspan, *domainspan, *cpu_map); | 7575 | cpumask_and(domainspan, domainspan, cpu_map); |
7586 | 7576 | ||
7587 | sg = kmalloc_node(sizeof(struct sched_group), GFP_KERNEL, i); | 7577 | sg = kmalloc_node(sizeof(struct sched_group) + cpumask_size(), |
7578 | GFP_KERNEL, i); | ||
7588 | if (!sg) { | 7579 | if (!sg) { |
7589 | printk(KERN_WARNING "Can not alloc domain group for " | 7580 | printk(KERN_WARNING "Can not alloc domain group for " |
7590 | "node %d\n", i); | 7581 | "node %d\n", i); |
7591 | goto error; | 7582 | goto error; |
7592 | } | 7583 | } |
7593 | sched_group_nodes[i] = sg; | 7584 | sched_group_nodes[i] = sg; |
7594 | for_each_cpu_mask_nr(j, *nodemask) { | 7585 | for_each_cpu(j, nodemask) { |
7595 | struct sched_domain *sd; | 7586 | struct sched_domain *sd; |
7596 | 7587 | ||
7597 | sd = &per_cpu(node_domains, j); | 7588 | sd = &per_cpu(node_domains, j); |
7598 | sd->groups = sg; | 7589 | sd->groups = sg; |
7599 | } | 7590 | } |
7600 | sg->__cpu_power = 0; | 7591 | sg->__cpu_power = 0; |
7601 | sg->cpumask = *nodemask; | 7592 | cpumask_copy(sched_group_cpus(sg), nodemask); |
7602 | sg->next = sg; | 7593 | sg->next = sg; |
7603 | cpus_or(*covered, *covered, *nodemask); | 7594 | cpumask_or(covered, covered, nodemask); |
7604 | prev = sg; | 7595 | prev = sg; |
7605 | 7596 | ||
7606 | for (j = 0; j < nr_node_ids; j++) { | 7597 | for (j = 0; j < nr_node_ids; j++) { |
7607 | SCHED_CPUMASK_VAR(notcovered, allmasks); | ||
7608 | int n = (i + j) % nr_node_ids; | 7598 | int n = (i + j) % nr_node_ids; |
7599 | /* FIXME: Use cpumask_of_node */ | ||
7609 | node_to_cpumask_ptr(pnodemask, n); | 7600 | node_to_cpumask_ptr(pnodemask, n); |
7610 | 7601 | ||
7611 | cpus_complement(*notcovered, *covered); | 7602 | cpumask_complement(notcovered, covered); |
7612 | cpus_and(*tmpmask, *notcovered, *cpu_map); | 7603 | cpumask_and(tmpmask, notcovered, cpu_map); |
7613 | cpus_and(*tmpmask, *tmpmask, *domainspan); | 7604 | cpumask_and(tmpmask, tmpmask, domainspan); |
7614 | if (cpus_empty(*tmpmask)) | 7605 | if (cpumask_empty(tmpmask)) |
7615 | break; | 7606 | break; |
7616 | 7607 | ||
7617 | cpus_and(*tmpmask, *tmpmask, *pnodemask); | 7608 | cpumask_and(tmpmask, tmpmask, pnodemask); |
7618 | if (cpus_empty(*tmpmask)) | 7609 | if (cpumask_empty(tmpmask)) |
7619 | continue; | 7610 | continue; |
7620 | 7611 | ||
7621 | sg = kmalloc_node(sizeof(struct sched_group), | 7612 | sg = kmalloc_node(sizeof(struct sched_group) + |
7613 | cpumask_size(), | ||
7622 | GFP_KERNEL, i); | 7614 | GFP_KERNEL, i); |
7623 | if (!sg) { | 7615 | if (!sg) { |
7624 | printk(KERN_WARNING | 7616 | printk(KERN_WARNING |
@@ -7626,9 +7618,9 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7626 | goto error; | 7618 | goto error; |
7627 | } | 7619 | } |
7628 | sg->__cpu_power = 0; | 7620 | sg->__cpu_power = 0; |
7629 | sg->cpumask = *tmpmask; | 7621 | cpumask_copy(sched_group_cpus(sg), tmpmask); |
7630 | sg->next = prev->next; | 7622 | sg->next = prev->next; |
7631 | cpus_or(*covered, *covered, *tmpmask); | 7623 | cpumask_or(covered, covered, tmpmask); |
7632 | prev->next = sg; | 7624 | prev->next = sg; |
7633 | prev = sg; | 7625 | prev = sg; |
7634 | } | 7626 | } |
@@ -7637,22 +7629,22 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7637 | 7629 | ||
7638 | /* Calculate CPU power for physical packages and nodes */ | 7630 | /* Calculate CPU power for physical packages and nodes */ |
7639 | #ifdef CONFIG_SCHED_SMT | 7631 | #ifdef CONFIG_SCHED_SMT |
7640 | for_each_cpu_mask_nr(i, *cpu_map) { | 7632 | for_each_cpu(i, cpu_map) { |
7641 | struct sched_domain *sd = &per_cpu(cpu_domains, i); | 7633 | struct sched_domain *sd = &per_cpu(cpu_domains, i).sd; |
7642 | 7634 | ||
7643 | init_sched_groups_power(i, sd); | 7635 | init_sched_groups_power(i, sd); |
7644 | } | 7636 | } |
7645 | #endif | 7637 | #endif |
7646 | #ifdef CONFIG_SCHED_MC | 7638 | #ifdef CONFIG_SCHED_MC |
7647 | for_each_cpu_mask_nr(i, *cpu_map) { | 7639 | for_each_cpu(i, cpu_map) { |
7648 | struct sched_domain *sd = &per_cpu(core_domains, i); | 7640 | struct sched_domain *sd = &per_cpu(core_domains, i).sd; |
7649 | 7641 | ||
7650 | init_sched_groups_power(i, sd); | 7642 | init_sched_groups_power(i, sd); |
7651 | } | 7643 | } |
7652 | #endif | 7644 | #endif |
7653 | 7645 | ||
7654 | for_each_cpu_mask_nr(i, *cpu_map) { | 7646 | for_each_cpu(i, cpu_map) { |
7655 | struct sched_domain *sd = &per_cpu(phys_domains, i); | 7647 | struct sched_domain *sd = &per_cpu(phys_domains, i).sd; |
7656 | 7648 | ||
7657 | init_sched_groups_power(i, sd); | 7649 | init_sched_groups_power(i, sd); |
7658 | } | 7650 | } |
@@ -7664,56 +7656,87 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7664 | if (sd_allnodes) { | 7656 | if (sd_allnodes) { |
7665 | struct sched_group *sg; | 7657 | struct sched_group *sg; |
7666 | 7658 | ||
7667 | cpu_to_allnodes_group(first_cpu(*cpu_map), cpu_map, &sg, | 7659 | cpu_to_allnodes_group(cpumask_first(cpu_map), cpu_map, &sg, |
7668 | tmpmask); | 7660 | tmpmask); |
7669 | init_numa_sched_groups_power(sg); | 7661 | init_numa_sched_groups_power(sg); |
7670 | } | 7662 | } |
7671 | #endif | 7663 | #endif |
7672 | 7664 | ||
7673 | /* Attach the domains */ | 7665 | /* Attach the domains */ |
7674 | for_each_cpu_mask_nr(i, *cpu_map) { | 7666 | for_each_cpu(i, cpu_map) { |
7675 | struct sched_domain *sd; | 7667 | struct sched_domain *sd; |
7676 | #ifdef CONFIG_SCHED_SMT | 7668 | #ifdef CONFIG_SCHED_SMT |
7677 | sd = &per_cpu(cpu_domains, i); | 7669 | sd = &per_cpu(cpu_domains, i).sd; |
7678 | #elif defined(CONFIG_SCHED_MC) | 7670 | #elif defined(CONFIG_SCHED_MC) |
7679 | sd = &per_cpu(core_domains, i); | 7671 | sd = &per_cpu(core_domains, i).sd; |
7680 | #else | 7672 | #else |
7681 | sd = &per_cpu(phys_domains, i); | 7673 | sd = &per_cpu(phys_domains, i).sd; |
7682 | #endif | 7674 | #endif |
7683 | cpu_attach_domain(sd, rd, i); | 7675 | cpu_attach_domain(sd, rd, i); |
7684 | } | 7676 | } |
7685 | 7677 | ||
7686 | SCHED_CPUMASK_FREE((void *)allmasks); | 7678 | err = 0; |
7687 | return 0; | 7679 | |
7680 | free_tmpmask: | ||
7681 | free_cpumask_var(tmpmask); | ||
7682 | free_send_covered: | ||
7683 | free_cpumask_var(send_covered); | ||
7684 | free_this_core_map: | ||
7685 | free_cpumask_var(this_core_map); | ||
7686 | free_this_sibling_map: | ||
7687 | free_cpumask_var(this_sibling_map); | ||
7688 | free_nodemask: | ||
7689 | free_cpumask_var(nodemask); | ||
7690 | free_notcovered: | ||
7691 | #ifdef CONFIG_NUMA | ||
7692 | free_cpumask_var(notcovered); | ||
7693 | free_covered: | ||
7694 | free_cpumask_var(covered); | ||
7695 | free_domainspan: | ||
7696 | free_cpumask_var(domainspan); | ||
7697 | out: | ||
7698 | #endif | ||
7699 | return err; | ||
7700 | |||
7701 | free_sched_groups: | ||
7702 | #ifdef CONFIG_NUMA | ||
7703 | kfree(sched_group_nodes); | ||
7704 | #endif | ||
7705 | goto free_tmpmask; | ||
7688 | 7706 | ||
7689 | #ifdef CONFIG_NUMA | 7707 | #ifdef CONFIG_NUMA |
7690 | error: | 7708 | error: |
7691 | free_sched_groups(cpu_map, tmpmask); | 7709 | free_sched_groups(cpu_map, tmpmask); |
7692 | SCHED_CPUMASK_FREE((void *)allmasks); | 7710 | free_rootdomain(rd); |
7693 | kfree(rd); | 7711 | goto free_tmpmask; |
7694 | return -ENOMEM; | ||
7695 | #endif | 7712 | #endif |
7696 | } | 7713 | } |
7697 | 7714 | ||
7698 | static int build_sched_domains(const cpumask_t *cpu_map) | 7715 | static int build_sched_domains(const struct cpumask *cpu_map) |
7699 | { | 7716 | { |
7700 | return __build_sched_domains(cpu_map, NULL); | 7717 | return __build_sched_domains(cpu_map, NULL); |
7701 | } | 7718 | } |
7702 | 7719 | ||
7703 | static cpumask_t *doms_cur; /* current sched domains */ | 7720 | static struct cpumask *doms_cur; /* current sched domains */ |
7704 | static int ndoms_cur; /* number of sched domains in 'doms_cur' */ | 7721 | static int ndoms_cur; /* number of sched domains in 'doms_cur' */ |
7705 | static struct sched_domain_attr *dattr_cur; | 7722 | static struct sched_domain_attr *dattr_cur; |
7706 | /* attribues of custom domains in 'doms_cur' */ | 7723 | /* attribues of custom domains in 'doms_cur' */ |
7707 | 7724 | ||
7708 | /* | 7725 | /* |
7709 | * Special case: If a kmalloc of a doms_cur partition (array of | 7726 | * Special case: If a kmalloc of a doms_cur partition (array of |
7710 | * cpumask_t) fails, then fallback to a single sched domain, | 7727 | * cpumask) fails, then fallback to a single sched domain, |
7711 | * as determined by the single cpumask_t fallback_doms. | 7728 | * as determined by the single cpumask fallback_doms. |
7712 | */ | 7729 | */ |
7713 | static cpumask_t fallback_doms; | 7730 | static cpumask_var_t fallback_doms; |
7714 | 7731 | ||
7715 | void __attribute__((weak)) arch_update_cpu_topology(void) | 7732 | /* |
7733 | * arch_update_cpu_topology lets virtualized architectures update the | ||
7734 | * cpu core maps. It is supposed to return 1 if the topology changed | ||
7735 | * or 0 if it stayed the same. | ||
7736 | */ | ||
7737 | int __attribute__((weak)) arch_update_cpu_topology(void) | ||
7716 | { | 7738 | { |
7739 | return 0; | ||
7717 | } | 7740 | } |
7718 | 7741 | ||
7719 | /* | 7742 | /* |
@@ -7721,16 +7744,16 @@ void __attribute__((weak)) arch_update_cpu_topology(void) | |||
7721 | * For now this just excludes isolated cpus, but could be used to | 7744 | * For now this just excludes isolated cpus, but could be used to |
7722 | * exclude other special cases in the future. | 7745 | * exclude other special cases in the future. |
7723 | */ | 7746 | */ |
7724 | static int arch_init_sched_domains(const cpumask_t *cpu_map) | 7747 | static int arch_init_sched_domains(const struct cpumask *cpu_map) |
7725 | { | 7748 | { |
7726 | int err; | 7749 | int err; |
7727 | 7750 | ||
7728 | arch_update_cpu_topology(); | 7751 | arch_update_cpu_topology(); |
7729 | ndoms_cur = 1; | 7752 | ndoms_cur = 1; |
7730 | doms_cur = kmalloc(sizeof(cpumask_t), GFP_KERNEL); | 7753 | doms_cur = kmalloc(cpumask_size(), GFP_KERNEL); |
7731 | if (!doms_cur) | 7754 | if (!doms_cur) |
7732 | doms_cur = &fallback_doms; | 7755 | doms_cur = fallback_doms; |
7733 | cpus_andnot(*doms_cur, *cpu_map, cpu_isolated_map); | 7756 | cpumask_andnot(doms_cur, cpu_map, cpu_isolated_map); |
7734 | dattr_cur = NULL; | 7757 | dattr_cur = NULL; |
7735 | err = build_sched_domains(doms_cur); | 7758 | err = build_sched_domains(doms_cur); |
7736 | register_sched_domain_sysctl(); | 7759 | register_sched_domain_sysctl(); |
@@ -7738,8 +7761,8 @@ static int arch_init_sched_domains(const cpumask_t *cpu_map) | |||
7738 | return err; | 7761 | return err; |
7739 | } | 7762 | } |
7740 | 7763 | ||
7741 | static void arch_destroy_sched_domains(const cpumask_t *cpu_map, | 7764 | static void arch_destroy_sched_domains(const struct cpumask *cpu_map, |
7742 | cpumask_t *tmpmask) | 7765 | struct cpumask *tmpmask) |
7743 | { | 7766 | { |
7744 | free_sched_groups(cpu_map, tmpmask); | 7767 | free_sched_groups(cpu_map, tmpmask); |
7745 | } | 7768 | } |
@@ -7748,17 +7771,16 @@ static void arch_destroy_sched_domains(const cpumask_t *cpu_map, | |||
7748 | * Detach sched domains from a group of cpus specified in cpu_map | 7771 | * Detach sched domains from a group of cpus specified in cpu_map |
7749 | * These cpus will now be attached to the NULL domain | 7772 | * These cpus will now be attached to the NULL domain |
7750 | */ | 7773 | */ |
7751 | static void detach_destroy_domains(const cpumask_t *cpu_map) | 7774 | static void detach_destroy_domains(const struct cpumask *cpu_map) |
7752 | { | 7775 | { |
7753 | cpumask_t tmpmask; | 7776 | /* Save because hotplug lock held. */ |
7777 | static DECLARE_BITMAP(tmpmask, CONFIG_NR_CPUS); | ||
7754 | int i; | 7778 | int i; |
7755 | 7779 | ||
7756 | unregister_sched_domain_sysctl(); | 7780 | for_each_cpu(i, cpu_map) |
7757 | |||
7758 | for_each_cpu_mask_nr(i, *cpu_map) | ||
7759 | cpu_attach_domain(NULL, &def_root_domain, i); | 7781 | cpu_attach_domain(NULL, &def_root_domain, i); |
7760 | synchronize_sched(); | 7782 | synchronize_sched(); |
7761 | arch_destroy_sched_domains(cpu_map, &tmpmask); | 7783 | arch_destroy_sched_domains(cpu_map, to_cpumask(tmpmask)); |
7762 | } | 7784 | } |
7763 | 7785 | ||
7764 | /* handle null as "default" */ | 7786 | /* handle null as "default" */ |
@@ -7783,7 +7805,7 @@ static int dattrs_equal(struct sched_domain_attr *cur, int idx_cur, | |||
7783 | * doms_new[] to the current sched domain partitioning, doms_cur[]. | 7805 | * doms_new[] to the current sched domain partitioning, doms_cur[]. |
7784 | * It destroys each deleted domain and builds each new domain. | 7806 | * It destroys each deleted domain and builds each new domain. |
7785 | * | 7807 | * |
7786 | * 'doms_new' is an array of cpumask_t's of length 'ndoms_new'. | 7808 | * 'doms_new' is an array of cpumask's of length 'ndoms_new'. |
7787 | * The masks don't intersect (don't overlap.) We should setup one | 7809 | * The masks don't intersect (don't overlap.) We should setup one |
7788 | * sched domain for each mask. CPUs not in any of the cpumasks will | 7810 | * sched domain for each mask. CPUs not in any of the cpumasks will |
7789 | * not be load balanced. If the same cpumask appears both in the | 7811 | * not be load balanced. If the same cpumask appears both in the |
@@ -7797,28 +7819,33 @@ static int dattrs_equal(struct sched_domain_attr *cur, int idx_cur, | |||
7797 | * the single partition 'fallback_doms', it also forces the domains | 7819 | * the single partition 'fallback_doms', it also forces the domains |
7798 | * to be rebuilt. | 7820 | * to be rebuilt. |
7799 | * | 7821 | * |
7800 | * If doms_new == NULL it will be replaced with cpu_online_map. | 7822 | * If doms_new == NULL it will be replaced with cpu_online_mask. |
7801 | * ndoms_new == 0 is a special case for destroying existing domains, | 7823 | * ndoms_new == 0 is a special case for destroying existing domains, |
7802 | * and it will not create the default domain. | 7824 | * and it will not create the default domain. |
7803 | * | 7825 | * |
7804 | * Call with hotplug lock held | 7826 | * Call with hotplug lock held |
7805 | */ | 7827 | */ |
7806 | void partition_sched_domains(int ndoms_new, cpumask_t *doms_new, | 7828 | /* FIXME: Change to struct cpumask *doms_new[] */ |
7829 | void partition_sched_domains(int ndoms_new, struct cpumask *doms_new, | ||
7807 | struct sched_domain_attr *dattr_new) | 7830 | struct sched_domain_attr *dattr_new) |
7808 | { | 7831 | { |
7809 | int i, j, n; | 7832 | int i, j, n; |
7833 | int new_topology; | ||
7810 | 7834 | ||
7811 | mutex_lock(&sched_domains_mutex); | 7835 | mutex_lock(&sched_domains_mutex); |
7812 | 7836 | ||
7813 | /* always unregister in case we don't destroy any domains */ | 7837 | /* always unregister in case we don't destroy any domains */ |
7814 | unregister_sched_domain_sysctl(); | 7838 | unregister_sched_domain_sysctl(); |
7815 | 7839 | ||
7840 | /* Let architecture update cpu core mappings. */ | ||
7841 | new_topology = arch_update_cpu_topology(); | ||
7842 | |||
7816 | n = doms_new ? ndoms_new : 0; | 7843 | n = doms_new ? ndoms_new : 0; |
7817 | 7844 | ||
7818 | /* Destroy deleted domains */ | 7845 | /* Destroy deleted domains */ |
7819 | for (i = 0; i < ndoms_cur; i++) { | 7846 | for (i = 0; i < ndoms_cur; i++) { |
7820 | for (j = 0; j < n; j++) { | 7847 | for (j = 0; j < n && !new_topology; j++) { |
7821 | if (cpus_equal(doms_cur[i], doms_new[j]) | 7848 | if (cpumask_equal(&doms_cur[i], &doms_new[j]) |
7822 | && dattrs_equal(dattr_cur, i, dattr_new, j)) | 7849 | && dattrs_equal(dattr_cur, i, dattr_new, j)) |
7823 | goto match1; | 7850 | goto match1; |
7824 | } | 7851 | } |
@@ -7830,15 +7857,15 @@ match1: | |||
7830 | 7857 | ||
7831 | if (doms_new == NULL) { | 7858 | if (doms_new == NULL) { |
7832 | ndoms_cur = 0; | 7859 | ndoms_cur = 0; |
7833 | doms_new = &fallback_doms; | 7860 | doms_new = fallback_doms; |
7834 | cpus_andnot(doms_new[0], cpu_online_map, cpu_isolated_map); | 7861 | cpumask_andnot(&doms_new[0], cpu_online_mask, cpu_isolated_map); |
7835 | dattr_new = NULL; | 7862 | WARN_ON_ONCE(dattr_new); |
7836 | } | 7863 | } |
7837 | 7864 | ||
7838 | /* Build new domains */ | 7865 | /* Build new domains */ |
7839 | for (i = 0; i < ndoms_new; i++) { | 7866 | for (i = 0; i < ndoms_new; i++) { |
7840 | for (j = 0; j < ndoms_cur; j++) { | 7867 | for (j = 0; j < ndoms_cur && !new_topology; j++) { |
7841 | if (cpus_equal(doms_new[i], doms_cur[j]) | 7868 | if (cpumask_equal(&doms_new[i], &doms_cur[j]) |
7842 | && dattrs_equal(dattr_new, i, dattr_cur, j)) | 7869 | && dattrs_equal(dattr_new, i, dattr_cur, j)) |
7843 | goto match2; | 7870 | goto match2; |
7844 | } | 7871 | } |
@@ -7850,7 +7877,7 @@ match2: | |||
7850 | } | 7877 | } |
7851 | 7878 | ||
7852 | /* Remember the new sched domains */ | 7879 | /* Remember the new sched domains */ |
7853 | if (doms_cur != &fallback_doms) | 7880 | if (doms_cur != fallback_doms) |
7854 | kfree(doms_cur); | 7881 | kfree(doms_cur); |
7855 | kfree(dattr_cur); /* kfree(NULL) is safe */ | 7882 | kfree(dattr_cur); /* kfree(NULL) is safe */ |
7856 | doms_cur = doms_new; | 7883 | doms_cur = doms_new; |
@@ -7990,7 +8017,9 @@ static int update_runtime(struct notifier_block *nfb, | |||
7990 | 8017 | ||
7991 | void __init sched_init_smp(void) | 8018 | void __init sched_init_smp(void) |
7992 | { | 8019 | { |
7993 | cpumask_t non_isolated_cpus; | 8020 | cpumask_var_t non_isolated_cpus; |
8021 | |||
8022 | alloc_cpumask_var(&non_isolated_cpus, GFP_KERNEL); | ||
7994 | 8023 | ||
7995 | #if defined(CONFIG_NUMA) | 8024 | #if defined(CONFIG_NUMA) |
7996 | sched_group_nodes_bycpu = kzalloc(nr_cpu_ids * sizeof(void **), | 8025 | sched_group_nodes_bycpu = kzalloc(nr_cpu_ids * sizeof(void **), |
@@ -7999,10 +8028,10 @@ void __init sched_init_smp(void) | |||
7999 | #endif | 8028 | #endif |
8000 | get_online_cpus(); | 8029 | get_online_cpus(); |
8001 | mutex_lock(&sched_domains_mutex); | 8030 | mutex_lock(&sched_domains_mutex); |
8002 | arch_init_sched_domains(&cpu_online_map); | 8031 | arch_init_sched_domains(cpu_online_mask); |
8003 | cpus_andnot(non_isolated_cpus, cpu_possible_map, cpu_isolated_map); | 8032 | cpumask_andnot(non_isolated_cpus, cpu_possible_mask, cpu_isolated_map); |
8004 | if (cpus_empty(non_isolated_cpus)) | 8033 | if (cpumask_empty(non_isolated_cpus)) |
8005 | cpu_set(smp_processor_id(), non_isolated_cpus); | 8034 | cpumask_set_cpu(smp_processor_id(), non_isolated_cpus); |
8006 | mutex_unlock(&sched_domains_mutex); | 8035 | mutex_unlock(&sched_domains_mutex); |
8007 | put_online_cpus(); | 8036 | put_online_cpus(); |
8008 | 8037 | ||
@@ -8017,9 +8046,13 @@ void __init sched_init_smp(void) | |||
8017 | init_hrtick(); | 8046 | init_hrtick(); |
8018 | 8047 | ||
8019 | /* Move init over to a non-isolated CPU */ | 8048 | /* Move init over to a non-isolated CPU */ |
8020 | if (set_cpus_allowed_ptr(current, &non_isolated_cpus) < 0) | 8049 | if (set_cpus_allowed_ptr(current, non_isolated_cpus) < 0) |
8021 | BUG(); | 8050 | BUG(); |
8022 | sched_init_granularity(); | 8051 | sched_init_granularity(); |
8052 | free_cpumask_var(non_isolated_cpus); | ||
8053 | |||
8054 | alloc_cpumask_var(&fallback_doms, GFP_KERNEL); | ||
8055 | init_sched_rt_class(); | ||
8023 | } | 8056 | } |
8024 | #else | 8057 | #else |
8025 | void __init sched_init_smp(void) | 8058 | void __init sched_init_smp(void) |
@@ -8334,6 +8367,15 @@ void __init sched_init(void) | |||
8334 | */ | 8367 | */ |
8335 | current->sched_class = &fair_sched_class; | 8368 | current->sched_class = &fair_sched_class; |
8336 | 8369 | ||
8370 | /* Allocate the nohz_cpu_mask if CONFIG_CPUMASK_OFFSTACK */ | ||
8371 | alloc_bootmem_cpumask_var(&nohz_cpu_mask); | ||
8372 | #ifdef CONFIG_SMP | ||
8373 | #ifdef CONFIG_NO_HZ | ||
8374 | alloc_bootmem_cpumask_var(&nohz.cpu_mask); | ||
8375 | #endif | ||
8376 | alloc_bootmem_cpumask_var(&cpu_isolated_map); | ||
8377 | #endif /* SMP */ | ||
8378 | |||
8337 | scheduler_running = 1; | 8379 | scheduler_running = 1; |
8338 | } | 8380 | } |
8339 | 8381 | ||
@@ -8492,7 +8534,7 @@ static | |||
8492 | int alloc_fair_sched_group(struct task_group *tg, struct task_group *parent) | 8534 | int alloc_fair_sched_group(struct task_group *tg, struct task_group *parent) |
8493 | { | 8535 | { |
8494 | struct cfs_rq *cfs_rq; | 8536 | struct cfs_rq *cfs_rq; |
8495 | struct sched_entity *se, *parent_se; | 8537 | struct sched_entity *se; |
8496 | struct rq *rq; | 8538 | struct rq *rq; |
8497 | int i; | 8539 | int i; |
8498 | 8540 | ||
@@ -8508,18 +8550,17 @@ int alloc_fair_sched_group(struct task_group *tg, struct task_group *parent) | |||
8508 | for_each_possible_cpu(i) { | 8550 | for_each_possible_cpu(i) { |
8509 | rq = cpu_rq(i); | 8551 | rq = cpu_rq(i); |
8510 | 8552 | ||
8511 | cfs_rq = kmalloc_node(sizeof(struct cfs_rq), | 8553 | cfs_rq = kzalloc_node(sizeof(struct cfs_rq), |
8512 | GFP_KERNEL|__GFP_ZERO, cpu_to_node(i)); | 8554 | GFP_KERNEL, cpu_to_node(i)); |
8513 | if (!cfs_rq) | 8555 | if (!cfs_rq) |
8514 | goto err; | 8556 | goto err; |
8515 | 8557 | ||
8516 | se = kmalloc_node(sizeof(struct sched_entity), | 8558 | se = kzalloc_node(sizeof(struct sched_entity), |
8517 | GFP_KERNEL|__GFP_ZERO, cpu_to_node(i)); | 8559 | GFP_KERNEL, cpu_to_node(i)); |
8518 | if (!se) | 8560 | if (!se) |
8519 | goto err; | 8561 | goto err; |
8520 | 8562 | ||
8521 | parent_se = parent ? parent->se[i] : NULL; | 8563 | init_tg_cfs_entry(tg, cfs_rq, se, i, 0, parent->se[i]); |
8522 | init_tg_cfs_entry(tg, cfs_rq, se, i, 0, parent_se); | ||
8523 | } | 8564 | } |
8524 | 8565 | ||
8525 | return 1; | 8566 | return 1; |
@@ -8580,7 +8621,7 @@ static | |||
8580 | int alloc_rt_sched_group(struct task_group *tg, struct task_group *parent) | 8621 | int alloc_rt_sched_group(struct task_group *tg, struct task_group *parent) |
8581 | { | 8622 | { |
8582 | struct rt_rq *rt_rq; | 8623 | struct rt_rq *rt_rq; |
8583 | struct sched_rt_entity *rt_se, *parent_se; | 8624 | struct sched_rt_entity *rt_se; |
8584 | struct rq *rq; | 8625 | struct rq *rq; |
8585 | int i; | 8626 | int i; |
8586 | 8627 | ||
@@ -8597,18 +8638,17 @@ int alloc_rt_sched_group(struct task_group *tg, struct task_group *parent) | |||
8597 | for_each_possible_cpu(i) { | 8638 | for_each_possible_cpu(i) { |
8598 | rq = cpu_rq(i); | 8639 | rq = cpu_rq(i); |
8599 | 8640 | ||
8600 | rt_rq = kmalloc_node(sizeof(struct rt_rq), | 8641 | rt_rq = kzalloc_node(sizeof(struct rt_rq), |
8601 | GFP_KERNEL|__GFP_ZERO, cpu_to_node(i)); | 8642 | GFP_KERNEL, cpu_to_node(i)); |
8602 | if (!rt_rq) | 8643 | if (!rt_rq) |
8603 | goto err; | 8644 | goto err; |
8604 | 8645 | ||
8605 | rt_se = kmalloc_node(sizeof(struct sched_rt_entity), | 8646 | rt_se = kzalloc_node(sizeof(struct sched_rt_entity), |
8606 | GFP_KERNEL|__GFP_ZERO, cpu_to_node(i)); | 8647 | GFP_KERNEL, cpu_to_node(i)); |
8607 | if (!rt_se) | 8648 | if (!rt_se) |
8608 | goto err; | 8649 | goto err; |
8609 | 8650 | ||
8610 | parent_se = parent ? parent->rt_se[i] : NULL; | 8651 | init_tg_rt_entry(tg, rt_rq, rt_se, i, 0, parent->rt_se[i]); |
8611 | init_tg_rt_entry(tg, rt_rq, rt_se, i, 0, parent_se); | ||
8612 | } | 8652 | } |
8613 | 8653 | ||
8614 | return 1; | 8654 | return 1; |
@@ -9251,11 +9291,12 @@ struct cgroup_subsys cpu_cgroup_subsys = { | |||
9251 | * (balbir@in.ibm.com). | 9291 | * (balbir@in.ibm.com). |
9252 | */ | 9292 | */ |
9253 | 9293 | ||
9254 | /* track cpu usage of a group of tasks */ | 9294 | /* track cpu usage of a group of tasks and its child groups */ |
9255 | struct cpuacct { | 9295 | struct cpuacct { |
9256 | struct cgroup_subsys_state css; | 9296 | struct cgroup_subsys_state css; |
9257 | /* cpuusage holds pointer to a u64-type object on every cpu */ | 9297 | /* cpuusage holds pointer to a u64-type object on every cpu */ |
9258 | u64 *cpuusage; | 9298 | u64 *cpuusage; |
9299 | struct cpuacct *parent; | ||
9259 | }; | 9300 | }; |
9260 | 9301 | ||
9261 | struct cgroup_subsys cpuacct_subsys; | 9302 | struct cgroup_subsys cpuacct_subsys; |
@@ -9289,6 +9330,9 @@ static struct cgroup_subsys_state *cpuacct_create( | |||
9289 | return ERR_PTR(-ENOMEM); | 9330 | return ERR_PTR(-ENOMEM); |
9290 | } | 9331 | } |
9291 | 9332 | ||
9333 | if (cgrp->parent) | ||
9334 | ca->parent = cgroup_ca(cgrp->parent); | ||
9335 | |||
9292 | return &ca->css; | 9336 | return &ca->css; |
9293 | } | 9337 | } |
9294 | 9338 | ||
@@ -9368,14 +9412,16 @@ static int cpuacct_populate(struct cgroup_subsys *ss, struct cgroup *cgrp) | |||
9368 | static void cpuacct_charge(struct task_struct *tsk, u64 cputime) | 9412 | static void cpuacct_charge(struct task_struct *tsk, u64 cputime) |
9369 | { | 9413 | { |
9370 | struct cpuacct *ca; | 9414 | struct cpuacct *ca; |
9415 | int cpu; | ||
9371 | 9416 | ||
9372 | if (!cpuacct_subsys.active) | 9417 | if (!cpuacct_subsys.active) |
9373 | return; | 9418 | return; |
9374 | 9419 | ||
9420 | cpu = task_cpu(tsk); | ||
9375 | ca = task_ca(tsk); | 9421 | ca = task_ca(tsk); |
9376 | if (ca) { | ||
9377 | u64 *cpuusage = percpu_ptr(ca->cpuusage, task_cpu(tsk)); | ||
9378 | 9422 | ||
9423 | for (; ca; ca = ca->parent) { | ||
9424 | u64 *cpuusage = percpu_ptr(ca->cpuusage, cpu); | ||
9379 | *cpuusage += cputime; | 9425 | *cpuusage += cputime; |
9380 | } | 9426 | } |
9381 | } | 9427 | } |