diff options
Diffstat (limited to 'kernel/sched.c')
-rw-r--r-- | kernel/sched.c | 818 |
1 files changed, 297 insertions, 521 deletions
diff --git a/kernel/sched.c b/kernel/sched.c index 6a212c97f523..1d93cd0ae4d3 100644 --- a/kernel/sched.c +++ b/kernel/sched.c | |||
@@ -55,9 +55,9 @@ | |||
55 | #include <linux/cpu.h> | 55 | #include <linux/cpu.h> |
56 | #include <linux/cpuset.h> | 56 | #include <linux/cpuset.h> |
57 | #include <linux/percpu.h> | 57 | #include <linux/percpu.h> |
58 | #include <linux/kthread.h> | ||
59 | #include <linux/proc_fs.h> | 58 | #include <linux/proc_fs.h> |
60 | #include <linux/seq_file.h> | 59 | #include <linux/seq_file.h> |
60 | #include <linux/stop_machine.h> | ||
61 | #include <linux/sysctl.h> | 61 | #include <linux/sysctl.h> |
62 | #include <linux/syscalls.h> | 62 | #include <linux/syscalls.h> |
63 | #include <linux/times.h> | 63 | #include <linux/times.h> |
@@ -71,6 +71,7 @@ | |||
71 | #include <linux/debugfs.h> | 71 | #include <linux/debugfs.h> |
72 | #include <linux/ctype.h> | 72 | #include <linux/ctype.h> |
73 | #include <linux/ftrace.h> | 73 | #include <linux/ftrace.h> |
74 | #include <linux/slab.h> | ||
74 | 75 | ||
75 | #include <asm/tlb.h> | 76 | #include <asm/tlb.h> |
76 | #include <asm/irq_regs.h> | 77 | #include <asm/irq_regs.h> |
@@ -322,6 +323,15 @@ static inline struct task_group *task_group(struct task_struct *p) | |||
322 | /* Change a task's cfs_rq and parent entity if it moves across CPUs/groups */ | 323 | /* Change a task's cfs_rq and parent entity if it moves across CPUs/groups */ |
323 | static inline void set_task_rq(struct task_struct *p, unsigned int cpu) | 324 | static inline void set_task_rq(struct task_struct *p, unsigned int cpu) |
324 | { | 325 | { |
326 | /* | ||
327 | * Strictly speaking this rcu_read_lock() is not needed since the | ||
328 | * task_group is tied to the cgroup, which in turn can never go away | ||
329 | * as long as there are tasks attached to it. | ||
330 | * | ||
331 | * However since task_group() uses task_subsys_state() which is an | ||
332 | * rcu_dereference() user, this quiets CONFIG_PROVE_RCU. | ||
333 | */ | ||
334 | rcu_read_lock(); | ||
325 | #ifdef CONFIG_FAIR_GROUP_SCHED | 335 | #ifdef CONFIG_FAIR_GROUP_SCHED |
326 | p->se.cfs_rq = task_group(p)->cfs_rq[cpu]; | 336 | p->se.cfs_rq = task_group(p)->cfs_rq[cpu]; |
327 | p->se.parent = task_group(p)->se[cpu]; | 337 | p->se.parent = task_group(p)->se[cpu]; |
@@ -331,6 +341,7 @@ static inline void set_task_rq(struct task_struct *p, unsigned int cpu) | |||
331 | p->rt.rt_rq = task_group(p)->rt_rq[cpu]; | 341 | p->rt.rt_rq = task_group(p)->rt_rq[cpu]; |
332 | p->rt.parent = task_group(p)->rt_se[cpu]; | 342 | p->rt.parent = task_group(p)->rt_se[cpu]; |
333 | #endif | 343 | #endif |
344 | rcu_read_unlock(); | ||
334 | } | 345 | } |
335 | 346 | ||
336 | #else | 347 | #else |
@@ -492,8 +503,11 @@ struct rq { | |||
492 | #define CPU_LOAD_IDX_MAX 5 | 503 | #define CPU_LOAD_IDX_MAX 5 |
493 | unsigned long cpu_load[CPU_LOAD_IDX_MAX]; | 504 | unsigned long cpu_load[CPU_LOAD_IDX_MAX]; |
494 | #ifdef CONFIG_NO_HZ | 505 | #ifdef CONFIG_NO_HZ |
506 | u64 nohz_stamp; | ||
495 | unsigned char in_nohz_recently; | 507 | unsigned char in_nohz_recently; |
496 | #endif | 508 | #endif |
509 | unsigned int skip_clock_update; | ||
510 | |||
497 | /* capture load from *all* tasks on this cpu: */ | 511 | /* capture load from *all* tasks on this cpu: */ |
498 | struct load_weight load; | 512 | struct load_weight load; |
499 | unsigned long nr_load_updates; | 513 | unsigned long nr_load_updates; |
@@ -535,15 +549,13 @@ struct rq { | |||
535 | int post_schedule; | 549 | int post_schedule; |
536 | int active_balance; | 550 | int active_balance; |
537 | int push_cpu; | 551 | int push_cpu; |
552 | struct cpu_stop_work active_balance_work; | ||
538 | /* cpu of this runqueue: */ | 553 | /* cpu of this runqueue: */ |
539 | int cpu; | 554 | int cpu; |
540 | int online; | 555 | int online; |
541 | 556 | ||
542 | unsigned long avg_load_per_task; | 557 | unsigned long avg_load_per_task; |
543 | 558 | ||
544 | struct task_struct *migration_thread; | ||
545 | struct list_head migration_queue; | ||
546 | |||
547 | u64 rt_avg; | 559 | u64 rt_avg; |
548 | u64 age_stamp; | 560 | u64 age_stamp; |
549 | u64 idle_stamp; | 561 | u64 idle_stamp; |
@@ -591,6 +603,13 @@ static inline | |||
591 | void check_preempt_curr(struct rq *rq, struct task_struct *p, int flags) | 603 | void check_preempt_curr(struct rq *rq, struct task_struct *p, int flags) |
592 | { | 604 | { |
593 | rq->curr->sched_class->check_preempt_curr(rq, p, flags); | 605 | rq->curr->sched_class->check_preempt_curr(rq, p, flags); |
606 | |||
607 | /* | ||
608 | * A queue event has occurred, and we're going to schedule. In | ||
609 | * this case, we can save a useless back to back clock update. | ||
610 | */ | ||
611 | if (test_tsk_need_resched(p)) | ||
612 | rq->skip_clock_update = 1; | ||
594 | } | 613 | } |
595 | 614 | ||
596 | static inline int cpu_of(struct rq *rq) | 615 | static inline int cpu_of(struct rq *rq) |
@@ -625,7 +644,8 @@ static inline int cpu_of(struct rq *rq) | |||
625 | 644 | ||
626 | inline void update_rq_clock(struct rq *rq) | 645 | inline void update_rq_clock(struct rq *rq) |
627 | { | 646 | { |
628 | rq->clock = sched_clock_cpu(cpu_of(rq)); | 647 | if (!rq->skip_clock_update) |
648 | rq->clock = sched_clock_cpu(cpu_of(rq)); | ||
629 | } | 649 | } |
630 | 650 | ||
631 | /* | 651 | /* |
@@ -903,16 +923,12 @@ static inline void finish_lock_switch(struct rq *rq, struct task_struct *prev) | |||
903 | #endif /* __ARCH_WANT_UNLOCKED_CTXSW */ | 923 | #endif /* __ARCH_WANT_UNLOCKED_CTXSW */ |
904 | 924 | ||
905 | /* | 925 | /* |
906 | * Check whether the task is waking, we use this to synchronize against | 926 | * Check whether the task is waking, we use this to synchronize ->cpus_allowed |
907 | * ttwu() so that task_cpu() reports a stable number. | 927 | * against ttwu(). |
908 | * | ||
909 | * We need to make an exception for PF_STARTING tasks because the fork | ||
910 | * path might require task_rq_lock() to work, eg. it can call | ||
911 | * set_cpus_allowed_ptr() from the cpuset clone_ns code. | ||
912 | */ | 928 | */ |
913 | static inline int task_is_waking(struct task_struct *p) | 929 | static inline int task_is_waking(struct task_struct *p) |
914 | { | 930 | { |
915 | return unlikely((p->state == TASK_WAKING) && !(p->flags & PF_STARTING)); | 931 | return unlikely(p->state == TASK_WAKING); |
916 | } | 932 | } |
917 | 933 | ||
918 | /* | 934 | /* |
@@ -925,11 +941,9 @@ static inline struct rq *__task_rq_lock(struct task_struct *p) | |||
925 | struct rq *rq; | 941 | struct rq *rq; |
926 | 942 | ||
927 | for (;;) { | 943 | for (;;) { |
928 | while (task_is_waking(p)) | ||
929 | cpu_relax(); | ||
930 | rq = task_rq(p); | 944 | rq = task_rq(p); |
931 | raw_spin_lock(&rq->lock); | 945 | raw_spin_lock(&rq->lock); |
932 | if (likely(rq == task_rq(p) && !task_is_waking(p))) | 946 | if (likely(rq == task_rq(p))) |
933 | return rq; | 947 | return rq; |
934 | raw_spin_unlock(&rq->lock); | 948 | raw_spin_unlock(&rq->lock); |
935 | } | 949 | } |
@@ -946,12 +960,10 @@ static struct rq *task_rq_lock(struct task_struct *p, unsigned long *flags) | |||
946 | struct rq *rq; | 960 | struct rq *rq; |
947 | 961 | ||
948 | for (;;) { | 962 | for (;;) { |
949 | while (task_is_waking(p)) | ||
950 | cpu_relax(); | ||
951 | local_irq_save(*flags); | 963 | local_irq_save(*flags); |
952 | rq = task_rq(p); | 964 | rq = task_rq(p); |
953 | raw_spin_lock(&rq->lock); | 965 | raw_spin_lock(&rq->lock); |
954 | if (likely(rq == task_rq(p) && !task_is_waking(p))) | 966 | if (likely(rq == task_rq(p))) |
955 | return rq; | 967 | return rq; |
956 | raw_spin_unlock_irqrestore(&rq->lock, *flags); | 968 | raw_spin_unlock_irqrestore(&rq->lock, *flags); |
957 | } | 969 | } |
@@ -1228,6 +1240,17 @@ void wake_up_idle_cpu(int cpu) | |||
1228 | if (!tsk_is_polling(rq->idle)) | 1240 | if (!tsk_is_polling(rq->idle)) |
1229 | smp_send_reschedule(cpu); | 1241 | smp_send_reschedule(cpu); |
1230 | } | 1242 | } |
1243 | |||
1244 | int nohz_ratelimit(int cpu) | ||
1245 | { | ||
1246 | struct rq *rq = cpu_rq(cpu); | ||
1247 | u64 diff = rq->clock - rq->nohz_stamp; | ||
1248 | |||
1249 | rq->nohz_stamp = rq->clock; | ||
1250 | |||
1251 | return diff < (NSEC_PER_SEC / HZ) >> 1; | ||
1252 | } | ||
1253 | |||
1231 | #endif /* CONFIG_NO_HZ */ | 1254 | #endif /* CONFIG_NO_HZ */ |
1232 | 1255 | ||
1233 | static u64 sched_avg_period(void) | 1256 | static u64 sched_avg_period(void) |
@@ -1521,7 +1544,7 @@ static unsigned long cpu_avg_load_per_task(int cpu) | |||
1521 | 1544 | ||
1522 | #ifdef CONFIG_FAIR_GROUP_SCHED | 1545 | #ifdef CONFIG_FAIR_GROUP_SCHED |
1523 | 1546 | ||
1524 | static __read_mostly unsigned long *update_shares_data; | 1547 | static __read_mostly unsigned long __percpu *update_shares_data; |
1525 | 1548 | ||
1526 | static void __set_se_shares(struct sched_entity *se, unsigned long shares); | 1549 | static void __set_se_shares(struct sched_entity *se, unsigned long shares); |
1527 | 1550 | ||
@@ -1770,8 +1793,6 @@ static void double_rq_lock(struct rq *rq1, struct rq *rq2) | |||
1770 | raw_spin_lock_nested(&rq1->lock, SINGLE_DEPTH_NESTING); | 1793 | raw_spin_lock_nested(&rq1->lock, SINGLE_DEPTH_NESTING); |
1771 | } | 1794 | } |
1772 | } | 1795 | } |
1773 | update_rq_clock(rq1); | ||
1774 | update_rq_clock(rq2); | ||
1775 | } | 1796 | } |
1776 | 1797 | ||
1777 | /* | 1798 | /* |
@@ -1802,7 +1823,7 @@ static void cfs_rq_set_shares(struct cfs_rq *cfs_rq, unsigned long shares) | |||
1802 | } | 1823 | } |
1803 | #endif | 1824 | #endif |
1804 | 1825 | ||
1805 | static void calc_load_account_active(struct rq *this_rq); | 1826 | static void calc_load_account_idle(struct rq *this_rq); |
1806 | static void update_sysctl(void); | 1827 | static void update_sysctl(void); |
1807 | static int get_update_sysctl_factor(void); | 1828 | static int get_update_sysctl_factor(void); |
1808 | 1829 | ||
@@ -1859,62 +1880,43 @@ static void set_load_weight(struct task_struct *p) | |||
1859 | p->se.load.inv_weight = prio_to_wmult[p->static_prio - MAX_RT_PRIO]; | 1880 | p->se.load.inv_weight = prio_to_wmult[p->static_prio - MAX_RT_PRIO]; |
1860 | } | 1881 | } |
1861 | 1882 | ||
1862 | static void update_avg(u64 *avg, u64 sample) | 1883 | static void enqueue_task(struct rq *rq, struct task_struct *p, int flags) |
1863 | { | ||
1864 | s64 diff = sample - *avg; | ||
1865 | *avg += diff >> 3; | ||
1866 | } | ||
1867 | |||
1868 | static void | ||
1869 | enqueue_task(struct rq *rq, struct task_struct *p, int wakeup, bool head) | ||
1870 | { | 1884 | { |
1871 | if (wakeup) | 1885 | update_rq_clock(rq); |
1872 | p->se.start_runtime = p->se.sum_exec_runtime; | ||
1873 | |||
1874 | sched_info_queued(p); | 1886 | sched_info_queued(p); |
1875 | p->sched_class->enqueue_task(rq, p, wakeup, head); | 1887 | p->sched_class->enqueue_task(rq, p, flags); |
1876 | p->se.on_rq = 1; | 1888 | p->se.on_rq = 1; |
1877 | } | 1889 | } |
1878 | 1890 | ||
1879 | static void dequeue_task(struct rq *rq, struct task_struct *p, int sleep) | 1891 | static void dequeue_task(struct rq *rq, struct task_struct *p, int flags) |
1880 | { | 1892 | { |
1881 | if (sleep) { | 1893 | update_rq_clock(rq); |
1882 | if (p->se.last_wakeup) { | ||
1883 | update_avg(&p->se.avg_overlap, | ||
1884 | p->se.sum_exec_runtime - p->se.last_wakeup); | ||
1885 | p->se.last_wakeup = 0; | ||
1886 | } else { | ||
1887 | update_avg(&p->se.avg_wakeup, | ||
1888 | sysctl_sched_wakeup_granularity); | ||
1889 | } | ||
1890 | } | ||
1891 | |||
1892 | sched_info_dequeued(p); | 1894 | sched_info_dequeued(p); |
1893 | p->sched_class->dequeue_task(rq, p, sleep); | 1895 | p->sched_class->dequeue_task(rq, p, flags); |
1894 | p->se.on_rq = 0; | 1896 | p->se.on_rq = 0; |
1895 | } | 1897 | } |
1896 | 1898 | ||
1897 | /* | 1899 | /* |
1898 | * activate_task - move a task to the runqueue. | 1900 | * activate_task - move a task to the runqueue. |
1899 | */ | 1901 | */ |
1900 | static void activate_task(struct rq *rq, struct task_struct *p, int wakeup) | 1902 | static void activate_task(struct rq *rq, struct task_struct *p, int flags) |
1901 | { | 1903 | { |
1902 | if (task_contributes_to_load(p)) | 1904 | if (task_contributes_to_load(p)) |
1903 | rq->nr_uninterruptible--; | 1905 | rq->nr_uninterruptible--; |
1904 | 1906 | ||
1905 | enqueue_task(rq, p, wakeup, false); | 1907 | enqueue_task(rq, p, flags); |
1906 | inc_nr_running(rq); | 1908 | inc_nr_running(rq); |
1907 | } | 1909 | } |
1908 | 1910 | ||
1909 | /* | 1911 | /* |
1910 | * deactivate_task - remove a task from the runqueue. | 1912 | * deactivate_task - remove a task from the runqueue. |
1911 | */ | 1913 | */ |
1912 | static void deactivate_task(struct rq *rq, struct task_struct *p, int sleep) | 1914 | static void deactivate_task(struct rq *rq, struct task_struct *p, int flags) |
1913 | { | 1915 | { |
1914 | if (task_contributes_to_load(p)) | 1916 | if (task_contributes_to_load(p)) |
1915 | rq->nr_uninterruptible++; | 1917 | rq->nr_uninterruptible++; |
1916 | 1918 | ||
1917 | dequeue_task(rq, p, sleep); | 1919 | dequeue_task(rq, p, flags); |
1918 | dec_nr_running(rq); | 1920 | dec_nr_running(rq); |
1919 | } | 1921 | } |
1920 | 1922 | ||
@@ -2043,21 +2045,18 @@ void set_task_cpu(struct task_struct *p, unsigned int new_cpu) | |||
2043 | __set_task_cpu(p, new_cpu); | 2045 | __set_task_cpu(p, new_cpu); |
2044 | } | 2046 | } |
2045 | 2047 | ||
2046 | struct migration_req { | 2048 | struct migration_arg { |
2047 | struct list_head list; | ||
2048 | |||
2049 | struct task_struct *task; | 2049 | struct task_struct *task; |
2050 | int dest_cpu; | 2050 | int dest_cpu; |
2051 | |||
2052 | struct completion done; | ||
2053 | }; | 2051 | }; |
2054 | 2052 | ||
2053 | static int migration_cpu_stop(void *data); | ||
2054 | |||
2055 | /* | 2055 | /* |
2056 | * The task's runqueue lock must be held. | 2056 | * The task's runqueue lock must be held. |
2057 | * Returns true if you have to wait for migration thread. | 2057 | * Returns true if you have to wait for migration thread. |
2058 | */ | 2058 | */ |
2059 | static int | 2059 | static bool migrate_task(struct task_struct *p, int dest_cpu) |
2060 | migrate_task(struct task_struct *p, int dest_cpu, struct migration_req *req) | ||
2061 | { | 2060 | { |
2062 | struct rq *rq = task_rq(p); | 2061 | struct rq *rq = task_rq(p); |
2063 | 2062 | ||
@@ -2065,58 +2064,7 @@ migrate_task(struct task_struct *p, int dest_cpu, struct migration_req *req) | |||
2065 | * If the task is not on a runqueue (and not running), then | 2064 | * If the task is not on a runqueue (and not running), then |
2066 | * the next wake-up will properly place the task. | 2065 | * the next wake-up will properly place the task. |
2067 | */ | 2066 | */ |
2068 | if (!p->se.on_rq && !task_running(rq, p)) | 2067 | return p->se.on_rq || task_running(rq, p); |
2069 | return 0; | ||
2070 | |||
2071 | init_completion(&req->done); | ||
2072 | req->task = p; | ||
2073 | req->dest_cpu = dest_cpu; | ||
2074 | list_add(&req->list, &rq->migration_queue); | ||
2075 | |||
2076 | return 1; | ||
2077 | } | ||
2078 | |||
2079 | /* | ||
2080 | * wait_task_context_switch - wait for a thread to complete at least one | ||
2081 | * context switch. | ||
2082 | * | ||
2083 | * @p must not be current. | ||
2084 | */ | ||
2085 | void wait_task_context_switch(struct task_struct *p) | ||
2086 | { | ||
2087 | unsigned long nvcsw, nivcsw, flags; | ||
2088 | int running; | ||
2089 | struct rq *rq; | ||
2090 | |||
2091 | nvcsw = p->nvcsw; | ||
2092 | nivcsw = p->nivcsw; | ||
2093 | for (;;) { | ||
2094 | /* | ||
2095 | * The runqueue is assigned before the actual context | ||
2096 | * switch. We need to take the runqueue lock. | ||
2097 | * | ||
2098 | * We could check initially without the lock but it is | ||
2099 | * very likely that we need to take the lock in every | ||
2100 | * iteration. | ||
2101 | */ | ||
2102 | rq = task_rq_lock(p, &flags); | ||
2103 | running = task_running(rq, p); | ||
2104 | task_rq_unlock(rq, &flags); | ||
2105 | |||
2106 | if (likely(!running)) | ||
2107 | break; | ||
2108 | /* | ||
2109 | * The switch count is incremented before the actual | ||
2110 | * context switch. We thus wait for two switches to be | ||
2111 | * sure at least one completed. | ||
2112 | */ | ||
2113 | if ((p->nvcsw - nvcsw) > 1) | ||
2114 | break; | ||
2115 | if ((p->nivcsw - nivcsw) > 1) | ||
2116 | break; | ||
2117 | |||
2118 | cpu_relax(); | ||
2119 | } | ||
2120 | } | 2068 | } |
2121 | 2069 | ||
2122 | /* | 2070 | /* |
@@ -2174,7 +2122,7 @@ unsigned long wait_task_inactive(struct task_struct *p, long match_state) | |||
2174 | * just go back and repeat. | 2122 | * just go back and repeat. |
2175 | */ | 2123 | */ |
2176 | rq = task_rq_lock(p, &flags); | 2124 | rq = task_rq_lock(p, &flags); |
2177 | trace_sched_wait_task(rq, p); | 2125 | trace_sched_wait_task(p); |
2178 | running = task_running(rq, p); | 2126 | running = task_running(rq, p); |
2179 | on_rq = p->se.on_rq; | 2127 | on_rq = p->se.on_rq; |
2180 | ncsw = 0; | 2128 | ncsw = 0; |
@@ -2272,6 +2220,9 @@ void task_oncpu_function_call(struct task_struct *p, | |||
2272 | } | 2220 | } |
2273 | 2221 | ||
2274 | #ifdef CONFIG_SMP | 2222 | #ifdef CONFIG_SMP |
2223 | /* | ||
2224 | * ->cpus_allowed is protected by either TASK_WAKING or rq->lock held. | ||
2225 | */ | ||
2275 | static int select_fallback_rq(int cpu, struct task_struct *p) | 2226 | static int select_fallback_rq(int cpu, struct task_struct *p) |
2276 | { | 2227 | { |
2277 | int dest_cpu; | 2228 | int dest_cpu; |
@@ -2288,12 +2239,8 @@ static int select_fallback_rq(int cpu, struct task_struct *p) | |||
2288 | return dest_cpu; | 2239 | return dest_cpu; |
2289 | 2240 | ||
2290 | /* No more Mr. Nice Guy. */ | 2241 | /* No more Mr. Nice Guy. */ |
2291 | if (dest_cpu >= nr_cpu_ids) { | 2242 | if (unlikely(dest_cpu >= nr_cpu_ids)) { |
2292 | rcu_read_lock(); | 2243 | dest_cpu = cpuset_cpus_allowed_fallback(p); |
2293 | cpuset_cpus_allowed_locked(p, &p->cpus_allowed); | ||
2294 | rcu_read_unlock(); | ||
2295 | dest_cpu = cpumask_any_and(cpu_active_mask, &p->cpus_allowed); | ||
2296 | |||
2297 | /* | 2244 | /* |
2298 | * Don't tell them about moving exiting tasks or | 2245 | * Don't tell them about moving exiting tasks or |
2299 | * kernel threads (both mm NULL), since they never | 2246 | * kernel threads (both mm NULL), since they never |
@@ -2310,17 +2257,12 @@ static int select_fallback_rq(int cpu, struct task_struct *p) | |||
2310 | } | 2257 | } |
2311 | 2258 | ||
2312 | /* | 2259 | /* |
2313 | * Gets called from 3 sites (exec, fork, wakeup), since it is called without | 2260 | * The caller (fork, wakeup) owns TASK_WAKING, ->cpus_allowed is stable. |
2314 | * holding rq->lock we need to ensure ->cpus_allowed is stable, this is done | ||
2315 | * by: | ||
2316 | * | ||
2317 | * exec: is unstable, retry loop | ||
2318 | * fork & wake-up: serialize ->cpus_allowed against TASK_WAKING | ||
2319 | */ | 2261 | */ |
2320 | static inline | 2262 | static inline |
2321 | int select_task_rq(struct task_struct *p, int sd_flags, int wake_flags) | 2263 | int select_task_rq(struct rq *rq, struct task_struct *p, int sd_flags, int wake_flags) |
2322 | { | 2264 | { |
2323 | int cpu = p->sched_class->select_task_rq(p, sd_flags, wake_flags); | 2265 | int cpu = p->sched_class->select_task_rq(rq, p, sd_flags, wake_flags); |
2324 | 2266 | ||
2325 | /* | 2267 | /* |
2326 | * In order not to call set_task_cpu() on a blocking task we need | 2268 | * In order not to call set_task_cpu() on a blocking task we need |
@@ -2338,6 +2280,12 @@ int select_task_rq(struct task_struct *p, int sd_flags, int wake_flags) | |||
2338 | 2280 | ||
2339 | return cpu; | 2281 | return cpu; |
2340 | } | 2282 | } |
2283 | |||
2284 | static void update_avg(u64 *avg, u64 sample) | ||
2285 | { | ||
2286 | s64 diff = sample - *avg; | ||
2287 | *avg += diff >> 3; | ||
2288 | } | ||
2341 | #endif | 2289 | #endif |
2342 | 2290 | ||
2343 | /*** | 2291 | /*** |
@@ -2359,16 +2307,13 @@ static int try_to_wake_up(struct task_struct *p, unsigned int state, | |||
2359 | { | 2307 | { |
2360 | int cpu, orig_cpu, this_cpu, success = 0; | 2308 | int cpu, orig_cpu, this_cpu, success = 0; |
2361 | unsigned long flags; | 2309 | unsigned long flags; |
2362 | struct rq *rq, *orig_rq; | 2310 | unsigned long en_flags = ENQUEUE_WAKEUP; |
2363 | 2311 | struct rq *rq; | |
2364 | if (!sched_feat(SYNC_WAKEUPS)) | ||
2365 | wake_flags &= ~WF_SYNC; | ||
2366 | 2312 | ||
2367 | this_cpu = get_cpu(); | 2313 | this_cpu = get_cpu(); |
2368 | 2314 | ||
2369 | smp_wmb(); | 2315 | smp_wmb(); |
2370 | rq = orig_rq = task_rq_lock(p, &flags); | 2316 | rq = task_rq_lock(p, &flags); |
2371 | update_rq_clock(rq); | ||
2372 | if (!(p->state & state)) | 2317 | if (!(p->state & state)) |
2373 | goto out; | 2318 | goto out; |
2374 | 2319 | ||
@@ -2388,28 +2333,26 @@ static int try_to_wake_up(struct task_struct *p, unsigned int state, | |||
2388 | * | 2333 | * |
2389 | * First fix up the nr_uninterruptible count: | 2334 | * First fix up the nr_uninterruptible count: |
2390 | */ | 2335 | */ |
2391 | if (task_contributes_to_load(p)) | 2336 | if (task_contributes_to_load(p)) { |
2392 | rq->nr_uninterruptible--; | 2337 | if (likely(cpu_online(orig_cpu))) |
2338 | rq->nr_uninterruptible--; | ||
2339 | else | ||
2340 | this_rq()->nr_uninterruptible--; | ||
2341 | } | ||
2393 | p->state = TASK_WAKING; | 2342 | p->state = TASK_WAKING; |
2394 | 2343 | ||
2395 | if (p->sched_class->task_waking) | 2344 | if (p->sched_class->task_waking) { |
2396 | p->sched_class->task_waking(rq, p); | 2345 | p->sched_class->task_waking(rq, p); |
2346 | en_flags |= ENQUEUE_WAKING; | ||
2347 | } | ||
2397 | 2348 | ||
2398 | __task_rq_unlock(rq); | 2349 | cpu = select_task_rq(rq, p, SD_BALANCE_WAKE, wake_flags); |
2399 | 2350 | if (cpu != orig_cpu) | |
2400 | cpu = select_task_rq(p, SD_BALANCE_WAKE, wake_flags); | ||
2401 | if (cpu != orig_cpu) { | ||
2402 | /* | ||
2403 | * Since we migrate the task without holding any rq->lock, | ||
2404 | * we need to be careful with task_rq_lock(), since that | ||
2405 | * might end up locking an invalid rq. | ||
2406 | */ | ||
2407 | set_task_cpu(p, cpu); | 2351 | set_task_cpu(p, cpu); |
2408 | } | 2352 | __task_rq_unlock(rq); |
2409 | 2353 | ||
2410 | rq = cpu_rq(cpu); | 2354 | rq = cpu_rq(cpu); |
2411 | raw_spin_lock(&rq->lock); | 2355 | raw_spin_lock(&rq->lock); |
2412 | update_rq_clock(rq); | ||
2413 | 2356 | ||
2414 | /* | 2357 | /* |
2415 | * We migrated the task without holding either rq->lock, however | 2358 | * We migrated the task without holding either rq->lock, however |
@@ -2437,36 +2380,20 @@ static int try_to_wake_up(struct task_struct *p, unsigned int state, | |||
2437 | 2380 | ||
2438 | out_activate: | 2381 | out_activate: |
2439 | #endif /* CONFIG_SMP */ | 2382 | #endif /* CONFIG_SMP */ |
2440 | schedstat_inc(p, se.nr_wakeups); | 2383 | schedstat_inc(p, se.statistics.nr_wakeups); |
2441 | if (wake_flags & WF_SYNC) | 2384 | if (wake_flags & WF_SYNC) |
2442 | schedstat_inc(p, se.nr_wakeups_sync); | 2385 | schedstat_inc(p, se.statistics.nr_wakeups_sync); |
2443 | if (orig_cpu != cpu) | 2386 | if (orig_cpu != cpu) |
2444 | schedstat_inc(p, se.nr_wakeups_migrate); | 2387 | schedstat_inc(p, se.statistics.nr_wakeups_migrate); |
2445 | if (cpu == this_cpu) | 2388 | if (cpu == this_cpu) |
2446 | schedstat_inc(p, se.nr_wakeups_local); | 2389 | schedstat_inc(p, se.statistics.nr_wakeups_local); |
2447 | else | 2390 | else |
2448 | schedstat_inc(p, se.nr_wakeups_remote); | 2391 | schedstat_inc(p, se.statistics.nr_wakeups_remote); |
2449 | activate_task(rq, p, 1); | 2392 | activate_task(rq, p, en_flags); |
2450 | success = 1; | 2393 | success = 1; |
2451 | 2394 | ||
2452 | /* | ||
2453 | * Only attribute actual wakeups done by this task. | ||
2454 | */ | ||
2455 | if (!in_interrupt()) { | ||
2456 | struct sched_entity *se = ¤t->se; | ||
2457 | u64 sample = se->sum_exec_runtime; | ||
2458 | |||
2459 | if (se->last_wakeup) | ||
2460 | sample -= se->last_wakeup; | ||
2461 | else | ||
2462 | sample -= se->start_runtime; | ||
2463 | update_avg(&se->avg_wakeup, sample); | ||
2464 | |||
2465 | se->last_wakeup = se->sum_exec_runtime; | ||
2466 | } | ||
2467 | |||
2468 | out_running: | 2395 | out_running: |
2469 | trace_sched_wakeup(rq, p, success); | 2396 | trace_sched_wakeup(p, success); |
2470 | check_preempt_curr(rq, p, wake_flags); | 2397 | check_preempt_curr(rq, p, wake_flags); |
2471 | 2398 | ||
2472 | p->state = TASK_RUNNING; | 2399 | p->state = TASK_RUNNING; |
@@ -2526,42 +2453,9 @@ static void __sched_fork(struct task_struct *p) | |||
2526 | p->se.sum_exec_runtime = 0; | 2453 | p->se.sum_exec_runtime = 0; |
2527 | p->se.prev_sum_exec_runtime = 0; | 2454 | p->se.prev_sum_exec_runtime = 0; |
2528 | p->se.nr_migrations = 0; | 2455 | p->se.nr_migrations = 0; |
2529 | p->se.last_wakeup = 0; | ||
2530 | p->se.avg_overlap = 0; | ||
2531 | p->se.start_runtime = 0; | ||
2532 | p->se.avg_wakeup = sysctl_sched_wakeup_granularity; | ||
2533 | 2456 | ||
2534 | #ifdef CONFIG_SCHEDSTATS | 2457 | #ifdef CONFIG_SCHEDSTATS |
2535 | p->se.wait_start = 0; | 2458 | memset(&p->se.statistics, 0, sizeof(p->se.statistics)); |
2536 | p->se.wait_max = 0; | ||
2537 | p->se.wait_count = 0; | ||
2538 | p->se.wait_sum = 0; | ||
2539 | |||
2540 | p->se.sleep_start = 0; | ||
2541 | p->se.sleep_max = 0; | ||
2542 | p->se.sum_sleep_runtime = 0; | ||
2543 | |||
2544 | p->se.block_start = 0; | ||
2545 | p->se.block_max = 0; | ||
2546 | p->se.exec_max = 0; | ||
2547 | p->se.slice_max = 0; | ||
2548 | |||
2549 | p->se.nr_migrations_cold = 0; | ||
2550 | p->se.nr_failed_migrations_affine = 0; | ||
2551 | p->se.nr_failed_migrations_running = 0; | ||
2552 | p->se.nr_failed_migrations_hot = 0; | ||
2553 | p->se.nr_forced_migrations = 0; | ||
2554 | |||
2555 | p->se.nr_wakeups = 0; | ||
2556 | p->se.nr_wakeups_sync = 0; | ||
2557 | p->se.nr_wakeups_migrate = 0; | ||
2558 | p->se.nr_wakeups_local = 0; | ||
2559 | p->se.nr_wakeups_remote = 0; | ||
2560 | p->se.nr_wakeups_affine = 0; | ||
2561 | p->se.nr_wakeups_affine_attempts = 0; | ||
2562 | p->se.nr_wakeups_passive = 0; | ||
2563 | p->se.nr_wakeups_idle = 0; | ||
2564 | |||
2565 | #endif | 2459 | #endif |
2566 | 2460 | ||
2567 | INIT_LIST_HEAD(&p->rt.run_list); | 2461 | INIT_LIST_HEAD(&p->rt.run_list); |
@@ -2582,11 +2476,11 @@ void sched_fork(struct task_struct *p, int clone_flags) | |||
2582 | 2476 | ||
2583 | __sched_fork(p); | 2477 | __sched_fork(p); |
2584 | /* | 2478 | /* |
2585 | * We mark the process as waking here. This guarantees that | 2479 | * We mark the process as running here. This guarantees that |
2586 | * nobody will actually run it, and a signal or other external | 2480 | * nobody will actually run it, and a signal or other external |
2587 | * event cannot wake it up and insert it on the runqueue either. | 2481 | * event cannot wake it up and insert it on the runqueue either. |
2588 | */ | 2482 | */ |
2589 | p->state = TASK_WAKING; | 2483 | p->state = TASK_RUNNING; |
2590 | 2484 | ||
2591 | /* | 2485 | /* |
2592 | * Revert to default priority/policy on fork if requested. | 2486 | * Revert to default priority/policy on fork if requested. |
@@ -2650,34 +2544,30 @@ void wake_up_new_task(struct task_struct *p, unsigned long clone_flags) | |||
2650 | { | 2544 | { |
2651 | unsigned long flags; | 2545 | unsigned long flags; |
2652 | struct rq *rq; | 2546 | struct rq *rq; |
2653 | int cpu = get_cpu(); | 2547 | int cpu __maybe_unused = get_cpu(); |
2654 | 2548 | ||
2655 | #ifdef CONFIG_SMP | 2549 | #ifdef CONFIG_SMP |
2550 | rq = task_rq_lock(p, &flags); | ||
2551 | p->state = TASK_WAKING; | ||
2552 | |||
2656 | /* | 2553 | /* |
2657 | * Fork balancing, do it here and not earlier because: | 2554 | * Fork balancing, do it here and not earlier because: |
2658 | * - cpus_allowed can change in the fork path | 2555 | * - cpus_allowed can change in the fork path |
2659 | * - any previously selected cpu might disappear through hotplug | 2556 | * - any previously selected cpu might disappear through hotplug |
2660 | * | 2557 | * |
2661 | * We still have TASK_WAKING but PF_STARTING is gone now, meaning | 2558 | * We set TASK_WAKING so that select_task_rq() can drop rq->lock |
2662 | * ->cpus_allowed is stable, we have preemption disabled, meaning | 2559 | * without people poking at ->cpus_allowed. |
2663 | * cpu_online_mask is stable. | ||
2664 | */ | 2560 | */ |
2665 | cpu = select_task_rq(p, SD_BALANCE_FORK, 0); | 2561 | cpu = select_task_rq(rq, p, SD_BALANCE_FORK, 0); |
2666 | set_task_cpu(p, cpu); | 2562 | set_task_cpu(p, cpu); |
2667 | #endif | ||
2668 | |||
2669 | /* | ||
2670 | * Since the task is not on the rq and we still have TASK_WAKING set | ||
2671 | * nobody else will migrate this task. | ||
2672 | */ | ||
2673 | rq = cpu_rq(cpu); | ||
2674 | raw_spin_lock_irqsave(&rq->lock, flags); | ||
2675 | 2563 | ||
2676 | BUG_ON(p->state != TASK_WAKING); | ||
2677 | p->state = TASK_RUNNING; | 2564 | p->state = TASK_RUNNING; |
2678 | update_rq_clock(rq); | 2565 | task_rq_unlock(rq, &flags); |
2566 | #endif | ||
2567 | |||
2568 | rq = task_rq_lock(p, &flags); | ||
2679 | activate_task(rq, p, 0); | 2569 | activate_task(rq, p, 0); |
2680 | trace_sched_wakeup_new(rq, p, 1); | 2570 | trace_sched_wakeup_new(p, 1); |
2681 | check_preempt_curr(rq, p, WF_FORK); | 2571 | check_preempt_curr(rq, p, WF_FORK); |
2682 | #ifdef CONFIG_SMP | 2572 | #ifdef CONFIG_SMP |
2683 | if (p->sched_class->task_woken) | 2573 | if (p->sched_class->task_woken) |
@@ -2897,7 +2787,7 @@ context_switch(struct rq *rq, struct task_struct *prev, | |||
2897 | struct mm_struct *mm, *oldmm; | 2787 | struct mm_struct *mm, *oldmm; |
2898 | 2788 | ||
2899 | prepare_task_switch(rq, prev, next); | 2789 | prepare_task_switch(rq, prev, next); |
2900 | trace_sched_switch(rq, prev, next); | 2790 | trace_sched_switch(prev, next); |
2901 | mm = next->mm; | 2791 | mm = next->mm; |
2902 | oldmm = prev->active_mm; | 2792 | oldmm = prev->active_mm; |
2903 | /* | 2793 | /* |
@@ -3014,6 +2904,61 @@ static unsigned long calc_load_update; | |||
3014 | unsigned long avenrun[3]; | 2904 | unsigned long avenrun[3]; |
3015 | EXPORT_SYMBOL(avenrun); | 2905 | EXPORT_SYMBOL(avenrun); |
3016 | 2906 | ||
2907 | static long calc_load_fold_active(struct rq *this_rq) | ||
2908 | { | ||
2909 | long nr_active, delta = 0; | ||
2910 | |||
2911 | nr_active = this_rq->nr_running; | ||
2912 | nr_active += (long) this_rq->nr_uninterruptible; | ||
2913 | |||
2914 | if (nr_active != this_rq->calc_load_active) { | ||
2915 | delta = nr_active - this_rq->calc_load_active; | ||
2916 | this_rq->calc_load_active = nr_active; | ||
2917 | } | ||
2918 | |||
2919 | return delta; | ||
2920 | } | ||
2921 | |||
2922 | #ifdef CONFIG_NO_HZ | ||
2923 | /* | ||
2924 | * For NO_HZ we delay the active fold to the next LOAD_FREQ update. | ||
2925 | * | ||
2926 | * When making the ILB scale, we should try to pull this in as well. | ||
2927 | */ | ||
2928 | static atomic_long_t calc_load_tasks_idle; | ||
2929 | |||
2930 | static void calc_load_account_idle(struct rq *this_rq) | ||
2931 | { | ||
2932 | long delta; | ||
2933 | |||
2934 | delta = calc_load_fold_active(this_rq); | ||
2935 | if (delta) | ||
2936 | atomic_long_add(delta, &calc_load_tasks_idle); | ||
2937 | } | ||
2938 | |||
2939 | static long calc_load_fold_idle(void) | ||
2940 | { | ||
2941 | long delta = 0; | ||
2942 | |||
2943 | /* | ||
2944 | * Its got a race, we don't care... | ||
2945 | */ | ||
2946 | if (atomic_long_read(&calc_load_tasks_idle)) | ||
2947 | delta = atomic_long_xchg(&calc_load_tasks_idle, 0); | ||
2948 | |||
2949 | return delta; | ||
2950 | } | ||
2951 | #else | ||
2952 | static void calc_load_account_idle(struct rq *this_rq) | ||
2953 | { | ||
2954 | } | ||
2955 | |||
2956 | static inline long calc_load_fold_idle(void) | ||
2957 | { | ||
2958 | return 0; | ||
2959 | } | ||
2960 | #endif | ||
2961 | |||
3017 | /** | 2962 | /** |
3018 | * get_avenrun - get the load average array | 2963 | * get_avenrun - get the load average array |
3019 | * @loads: pointer to dest load array | 2964 | * @loads: pointer to dest load array |
@@ -3060,20 +3005,22 @@ void calc_global_load(void) | |||
3060 | } | 3005 | } |
3061 | 3006 | ||
3062 | /* | 3007 | /* |
3063 | * Either called from update_cpu_load() or from a cpu going idle | 3008 | * Called from update_cpu_load() to periodically update this CPU's |
3009 | * active count. | ||
3064 | */ | 3010 | */ |
3065 | static void calc_load_account_active(struct rq *this_rq) | 3011 | static void calc_load_account_active(struct rq *this_rq) |
3066 | { | 3012 | { |
3067 | long nr_active, delta; | 3013 | long delta; |
3068 | 3014 | ||
3069 | nr_active = this_rq->nr_running; | 3015 | if (time_before(jiffies, this_rq->calc_load_update)) |
3070 | nr_active += (long) this_rq->nr_uninterruptible; | 3016 | return; |
3071 | 3017 | ||
3072 | if (nr_active != this_rq->calc_load_active) { | 3018 | delta = calc_load_fold_active(this_rq); |
3073 | delta = nr_active - this_rq->calc_load_active; | 3019 | delta += calc_load_fold_idle(); |
3074 | this_rq->calc_load_active = nr_active; | 3020 | if (delta) |
3075 | atomic_long_add(delta, &calc_load_tasks); | 3021 | atomic_long_add(delta, &calc_load_tasks); |
3076 | } | 3022 | |
3023 | this_rq->calc_load_update += LOAD_FREQ; | ||
3077 | } | 3024 | } |
3078 | 3025 | ||
3079 | /* | 3026 | /* |
@@ -3105,10 +3052,7 @@ static void update_cpu_load(struct rq *this_rq) | |||
3105 | this_rq->cpu_load[i] = (old_load*(scale-1) + new_load) >> i; | 3052 | this_rq->cpu_load[i] = (old_load*(scale-1) + new_load) >> i; |
3106 | } | 3053 | } |
3107 | 3054 | ||
3108 | if (time_after_eq(jiffies, this_rq->calc_load_update)) { | 3055 | calc_load_account_active(this_rq); |
3109 | this_rq->calc_load_update += LOAD_FREQ; | ||
3110 | calc_load_account_active(this_rq); | ||
3111 | } | ||
3112 | } | 3056 | } |
3113 | 3057 | ||
3114 | #ifdef CONFIG_SMP | 3058 | #ifdef CONFIG_SMP |
@@ -3120,44 +3064,27 @@ static void update_cpu_load(struct rq *this_rq) | |||
3120 | void sched_exec(void) | 3064 | void sched_exec(void) |
3121 | { | 3065 | { |
3122 | struct task_struct *p = current; | 3066 | struct task_struct *p = current; |
3123 | struct migration_req req; | ||
3124 | int dest_cpu, this_cpu; | ||
3125 | unsigned long flags; | 3067 | unsigned long flags; |
3126 | struct rq *rq; | 3068 | struct rq *rq; |
3127 | 3069 | int dest_cpu; | |
3128 | again: | ||
3129 | this_cpu = get_cpu(); | ||
3130 | dest_cpu = select_task_rq(p, SD_BALANCE_EXEC, 0); | ||
3131 | if (dest_cpu == this_cpu) { | ||
3132 | put_cpu(); | ||
3133 | return; | ||
3134 | } | ||
3135 | 3070 | ||
3136 | rq = task_rq_lock(p, &flags); | 3071 | rq = task_rq_lock(p, &flags); |
3137 | put_cpu(); | 3072 | dest_cpu = p->sched_class->select_task_rq(rq, p, SD_BALANCE_EXEC, 0); |
3073 | if (dest_cpu == smp_processor_id()) | ||
3074 | goto unlock; | ||
3138 | 3075 | ||
3139 | /* | 3076 | /* |
3140 | * select_task_rq() can race against ->cpus_allowed | 3077 | * select_task_rq() can race against ->cpus_allowed |
3141 | */ | 3078 | */ |
3142 | if (!cpumask_test_cpu(dest_cpu, &p->cpus_allowed) | 3079 | if (cpumask_test_cpu(dest_cpu, &p->cpus_allowed) && |
3143 | || unlikely(!cpu_active(dest_cpu))) { | 3080 | likely(cpu_active(dest_cpu)) && migrate_task(p, dest_cpu)) { |
3144 | task_rq_unlock(rq, &flags); | 3081 | struct migration_arg arg = { p, dest_cpu }; |
3145 | goto again; | ||
3146 | } | ||
3147 | 3082 | ||
3148 | /* force the process onto the specified CPU */ | ||
3149 | if (migrate_task(p, dest_cpu, &req)) { | ||
3150 | /* Need to wait for migration thread (might exit: take ref). */ | ||
3151 | struct task_struct *mt = rq->migration_thread; | ||
3152 | |||
3153 | get_task_struct(mt); | ||
3154 | task_rq_unlock(rq, &flags); | 3083 | task_rq_unlock(rq, &flags); |
3155 | wake_up_process(mt); | 3084 | stop_one_cpu(cpu_of(rq), migration_cpu_stop, &arg); |
3156 | put_task_struct(mt); | ||
3157 | wait_for_completion(&req.done); | ||
3158 | |||
3159 | return; | 3085 | return; |
3160 | } | 3086 | } |
3087 | unlock: | ||
3161 | task_rq_unlock(rq, &flags); | 3088 | task_rq_unlock(rq, &flags); |
3162 | } | 3089 | } |
3163 | 3090 | ||
@@ -3629,23 +3556,9 @@ static inline void schedule_debug(struct task_struct *prev) | |||
3629 | 3556 | ||
3630 | static void put_prev_task(struct rq *rq, struct task_struct *prev) | 3557 | static void put_prev_task(struct rq *rq, struct task_struct *prev) |
3631 | { | 3558 | { |
3632 | if (prev->state == TASK_RUNNING) { | 3559 | if (prev->se.on_rq) |
3633 | u64 runtime = prev->se.sum_exec_runtime; | 3560 | update_rq_clock(rq); |
3634 | 3561 | rq->skip_clock_update = 0; | |
3635 | runtime -= prev->se.prev_sum_exec_runtime; | ||
3636 | runtime = min_t(u64, runtime, 2*sysctl_sched_migration_cost); | ||
3637 | |||
3638 | /* | ||
3639 | * In order to avoid avg_overlap growing stale when we are | ||
3640 | * indeed overlapping and hence not getting put to sleep, grow | ||
3641 | * the avg_overlap on preemption. | ||
3642 | * | ||
3643 | * We use the average preemption runtime because that | ||
3644 | * correlates to the amount of cache footprint a task can | ||
3645 | * build up. | ||
3646 | */ | ||
3647 | update_avg(&prev->se.avg_overlap, runtime); | ||
3648 | } | ||
3649 | prev->sched_class->put_prev_task(rq, prev); | 3562 | prev->sched_class->put_prev_task(rq, prev); |
3650 | } | 3563 | } |
3651 | 3564 | ||
@@ -3695,7 +3608,7 @@ need_resched: | |||
3695 | preempt_disable(); | 3608 | preempt_disable(); |
3696 | cpu = smp_processor_id(); | 3609 | cpu = smp_processor_id(); |
3697 | rq = cpu_rq(cpu); | 3610 | rq = cpu_rq(cpu); |
3698 | rcu_sched_qs(cpu); | 3611 | rcu_note_context_switch(cpu); |
3699 | prev = rq->curr; | 3612 | prev = rq->curr; |
3700 | switch_count = &prev->nivcsw; | 3613 | switch_count = &prev->nivcsw; |
3701 | 3614 | ||
@@ -3708,14 +3621,13 @@ need_resched_nonpreemptible: | |||
3708 | hrtick_clear(rq); | 3621 | hrtick_clear(rq); |
3709 | 3622 | ||
3710 | raw_spin_lock_irq(&rq->lock); | 3623 | raw_spin_lock_irq(&rq->lock); |
3711 | update_rq_clock(rq); | ||
3712 | clear_tsk_need_resched(prev); | 3624 | clear_tsk_need_resched(prev); |
3713 | 3625 | ||
3714 | if (prev->state && !(preempt_count() & PREEMPT_ACTIVE)) { | 3626 | if (prev->state && !(preempt_count() & PREEMPT_ACTIVE)) { |
3715 | if (unlikely(signal_pending_state(prev->state, prev))) | 3627 | if (unlikely(signal_pending_state(prev->state, prev))) |
3716 | prev->state = TASK_RUNNING; | 3628 | prev->state = TASK_RUNNING; |
3717 | else | 3629 | else |
3718 | deactivate_task(rq, prev, 1); | 3630 | deactivate_task(rq, prev, DEQUEUE_SLEEP); |
3719 | switch_count = &prev->nvcsw; | 3631 | switch_count = &prev->nvcsw; |
3720 | } | 3632 | } |
3721 | 3633 | ||
@@ -3779,7 +3691,7 @@ int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner) | |||
3779 | * the mutex owner just released it and exited. | 3691 | * the mutex owner just released it and exited. |
3780 | */ | 3692 | */ |
3781 | if (probe_kernel_address(&owner->cpu, cpu)) | 3693 | if (probe_kernel_address(&owner->cpu, cpu)) |
3782 | goto out; | 3694 | return 0; |
3783 | #else | 3695 | #else |
3784 | cpu = owner->cpu; | 3696 | cpu = owner->cpu; |
3785 | #endif | 3697 | #endif |
@@ -3789,14 +3701,14 @@ int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner) | |||
3789 | * the cpu field may no longer be valid. | 3701 | * the cpu field may no longer be valid. |
3790 | */ | 3702 | */ |
3791 | if (cpu >= nr_cpumask_bits) | 3703 | if (cpu >= nr_cpumask_bits) |
3792 | goto out; | 3704 | return 0; |
3793 | 3705 | ||
3794 | /* | 3706 | /* |
3795 | * We need to validate that we can do a | 3707 | * We need to validate that we can do a |
3796 | * get_cpu() and that we have the percpu area. | 3708 | * get_cpu() and that we have the percpu area. |
3797 | */ | 3709 | */ |
3798 | if (!cpu_online(cpu)) | 3710 | if (!cpu_online(cpu)) |
3799 | goto out; | 3711 | return 0; |
3800 | 3712 | ||
3801 | rq = cpu_rq(cpu); | 3713 | rq = cpu_rq(cpu); |
3802 | 3714 | ||
@@ -3815,7 +3727,7 @@ int mutex_spin_on_owner(struct mutex *lock, struct thread_info *owner) | |||
3815 | 3727 | ||
3816 | cpu_relax(); | 3728 | cpu_relax(); |
3817 | } | 3729 | } |
3818 | out: | 3730 | |
3819 | return 1; | 3731 | return 1; |
3820 | } | 3732 | } |
3821 | #endif | 3733 | #endif |
@@ -4038,8 +3950,7 @@ do_wait_for_common(struct completion *x, long timeout, int state) | |||
4038 | if (!x->done) { | 3950 | if (!x->done) { |
4039 | DECLARE_WAITQUEUE(wait, current); | 3951 | DECLARE_WAITQUEUE(wait, current); |
4040 | 3952 | ||
4041 | wait.flags |= WQ_FLAG_EXCLUSIVE; | 3953 | __add_wait_queue_tail_exclusive(&x->wait, &wait); |
4042 | __add_wait_queue_tail(&x->wait, &wait); | ||
4043 | do { | 3954 | do { |
4044 | if (signal_pending_state(state, current)) { | 3955 | if (signal_pending_state(state, current)) { |
4045 | timeout = -ERESTARTSYS; | 3956 | timeout = -ERESTARTSYS; |
@@ -4265,7 +4176,6 @@ void rt_mutex_setprio(struct task_struct *p, int prio) | |||
4265 | BUG_ON(prio < 0 || prio > MAX_PRIO); | 4176 | BUG_ON(prio < 0 || prio > MAX_PRIO); |
4266 | 4177 | ||
4267 | rq = task_rq_lock(p, &flags); | 4178 | rq = task_rq_lock(p, &flags); |
4268 | update_rq_clock(rq); | ||
4269 | 4179 | ||
4270 | oldprio = p->prio; | 4180 | oldprio = p->prio; |
4271 | prev_class = p->sched_class; | 4181 | prev_class = p->sched_class; |
@@ -4286,7 +4196,7 @@ void rt_mutex_setprio(struct task_struct *p, int prio) | |||
4286 | if (running) | 4196 | if (running) |
4287 | p->sched_class->set_curr_task(rq); | 4197 | p->sched_class->set_curr_task(rq); |
4288 | if (on_rq) { | 4198 | if (on_rq) { |
4289 | enqueue_task(rq, p, 0, oldprio < prio); | 4199 | enqueue_task(rq, p, oldprio < prio ? ENQUEUE_HEAD : 0); |
4290 | 4200 | ||
4291 | check_class_changed(rq, p, prev_class, oldprio, running); | 4201 | check_class_changed(rq, p, prev_class, oldprio, running); |
4292 | } | 4202 | } |
@@ -4308,7 +4218,6 @@ void set_user_nice(struct task_struct *p, long nice) | |||
4308 | * the task might be in the middle of scheduling on another CPU. | 4218 | * the task might be in the middle of scheduling on another CPU. |
4309 | */ | 4219 | */ |
4310 | rq = task_rq_lock(p, &flags); | 4220 | rq = task_rq_lock(p, &flags); |
4311 | update_rq_clock(rq); | ||
4312 | /* | 4221 | /* |
4313 | * The RT priorities are set via sched_setscheduler(), but we still | 4222 | * The RT priorities are set via sched_setscheduler(), but we still |
4314 | * allow the 'normal' nice value to be set - but as expected | 4223 | * allow the 'normal' nice value to be set - but as expected |
@@ -4330,7 +4239,7 @@ void set_user_nice(struct task_struct *p, long nice) | |||
4330 | delta = p->prio - old_prio; | 4239 | delta = p->prio - old_prio; |
4331 | 4240 | ||
4332 | if (on_rq) { | 4241 | if (on_rq) { |
4333 | enqueue_task(rq, p, 0, false); | 4242 | enqueue_task(rq, p, 0); |
4334 | /* | 4243 | /* |
4335 | * If the task increased its priority or is running and | 4244 | * If the task increased its priority or is running and |
4336 | * lowered its priority, then reschedule its CPU: | 4245 | * lowered its priority, then reschedule its CPU: |
@@ -4353,7 +4262,7 @@ int can_nice(const struct task_struct *p, const int nice) | |||
4353 | /* convert nice value [19,-20] to rlimit style value [1,40] */ | 4262 | /* convert nice value [19,-20] to rlimit style value [1,40] */ |
4354 | int nice_rlim = 20 - nice; | 4263 | int nice_rlim = 20 - nice; |
4355 | 4264 | ||
4356 | return (nice_rlim <= p->signal->rlim[RLIMIT_NICE].rlim_cur || | 4265 | return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) || |
4357 | capable(CAP_SYS_NICE)); | 4266 | capable(CAP_SYS_NICE)); |
4358 | } | 4267 | } |
4359 | 4268 | ||
@@ -4530,7 +4439,7 @@ recheck: | |||
4530 | 4439 | ||
4531 | if (!lock_task_sighand(p, &flags)) | 4440 | if (!lock_task_sighand(p, &flags)) |
4532 | return -ESRCH; | 4441 | return -ESRCH; |
4533 | rlim_rtprio = p->signal->rlim[RLIMIT_RTPRIO].rlim_cur; | 4442 | rlim_rtprio = task_rlimit(p, RLIMIT_RTPRIO); |
4534 | unlock_task_sighand(p, &flags); | 4443 | unlock_task_sighand(p, &flags); |
4535 | 4444 | ||
4536 | /* can't set/change the rt policy */ | 4445 | /* can't set/change the rt policy */ |
@@ -4591,7 +4500,6 @@ recheck: | |||
4591 | raw_spin_unlock_irqrestore(&p->pi_lock, flags); | 4500 | raw_spin_unlock_irqrestore(&p->pi_lock, flags); |
4592 | goto recheck; | 4501 | goto recheck; |
4593 | } | 4502 | } |
4594 | update_rq_clock(rq); | ||
4595 | on_rq = p->se.on_rq; | 4503 | on_rq = p->se.on_rq; |
4596 | running = task_current(rq, p); | 4504 | running = task_current(rq, p); |
4597 | if (on_rq) | 4505 | if (on_rq) |
@@ -4902,7 +4810,9 @@ SYSCALL_DEFINE3(sched_getaffinity, pid_t, pid, unsigned int, len, | |||
4902 | int ret; | 4810 | int ret; |
4903 | cpumask_var_t mask; | 4811 | cpumask_var_t mask; |
4904 | 4812 | ||
4905 | if (len < cpumask_size()) | 4813 | if ((len * BITS_PER_BYTE) < nr_cpu_ids) |
4814 | return -EINVAL; | ||
4815 | if (len & (sizeof(unsigned long)-1)) | ||
4906 | return -EINVAL; | 4816 | return -EINVAL; |
4907 | 4817 | ||
4908 | if (!alloc_cpumask_var(&mask, GFP_KERNEL)) | 4818 | if (!alloc_cpumask_var(&mask, GFP_KERNEL)) |
@@ -4910,10 +4820,12 @@ SYSCALL_DEFINE3(sched_getaffinity, pid_t, pid, unsigned int, len, | |||
4910 | 4820 | ||
4911 | ret = sched_getaffinity(pid, mask); | 4821 | ret = sched_getaffinity(pid, mask); |
4912 | if (ret == 0) { | 4822 | if (ret == 0) { |
4913 | if (copy_to_user(user_mask_ptr, mask, cpumask_size())) | 4823 | size_t retlen = min_t(size_t, len, cpumask_size()); |
4824 | |||
4825 | if (copy_to_user(user_mask_ptr, mask, retlen)) | ||
4914 | ret = -EFAULT; | 4826 | ret = -EFAULT; |
4915 | else | 4827 | else |
4916 | ret = cpumask_size(); | 4828 | ret = retlen; |
4917 | } | 4829 | } |
4918 | free_cpumask_var(mask); | 4830 | free_cpumask_var(mask); |
4919 | 4831 | ||
@@ -5324,17 +5236,15 @@ static inline void sched_init_granularity(void) | |||
5324 | /* | 5236 | /* |
5325 | * This is how migration works: | 5237 | * This is how migration works: |
5326 | * | 5238 | * |
5327 | * 1) we queue a struct migration_req structure in the source CPU's | 5239 | * 1) we invoke migration_cpu_stop() on the target CPU using |
5328 | * runqueue and wake up that CPU's migration thread. | 5240 | * stop_one_cpu(). |
5329 | * 2) we down() the locked semaphore => thread blocks. | 5241 | * 2) stopper starts to run (implicitly forcing the migrated thread |
5330 | * 3) migration thread wakes up (implicitly it forces the migrated | 5242 | * off the CPU) |
5331 | * thread off the CPU) | 5243 | * 3) it checks whether the migrated task is still in the wrong runqueue. |
5332 | * 4) it gets the migration request and checks whether the migrated | 5244 | * 4) if it's in the wrong runqueue then the migration thread removes |
5333 | * task is still in the wrong runqueue. | ||
5334 | * 5) if it's in the wrong runqueue then the migration thread removes | ||
5335 | * it and puts it into the right queue. | 5245 | * it and puts it into the right queue. |
5336 | * 6) migration thread up()s the semaphore. | 5246 | * 5) stopper completes and stop_one_cpu() returns and the migration |
5337 | * 7) we wake up and the migration is done. | 5247 | * is done. |
5338 | */ | 5248 | */ |
5339 | 5249 | ||
5340 | /* | 5250 | /* |
@@ -5348,12 +5258,23 @@ static inline void sched_init_granularity(void) | |||
5348 | */ | 5258 | */ |
5349 | int set_cpus_allowed_ptr(struct task_struct *p, const struct cpumask *new_mask) | 5259 | int set_cpus_allowed_ptr(struct task_struct *p, const struct cpumask *new_mask) |
5350 | { | 5260 | { |
5351 | struct migration_req req; | ||
5352 | unsigned long flags; | 5261 | unsigned long flags; |
5353 | struct rq *rq; | 5262 | struct rq *rq; |
5263 | unsigned int dest_cpu; | ||
5354 | int ret = 0; | 5264 | int ret = 0; |
5355 | 5265 | ||
5266 | /* | ||
5267 | * Serialize against TASK_WAKING so that ttwu() and wunt() can | ||
5268 | * drop the rq->lock and still rely on ->cpus_allowed. | ||
5269 | */ | ||
5270 | again: | ||
5271 | while (task_is_waking(p)) | ||
5272 | cpu_relax(); | ||
5356 | rq = task_rq_lock(p, &flags); | 5273 | rq = task_rq_lock(p, &flags); |
5274 | if (task_is_waking(p)) { | ||
5275 | task_rq_unlock(rq, &flags); | ||
5276 | goto again; | ||
5277 | } | ||
5357 | 5278 | ||
5358 | if (!cpumask_intersects(new_mask, cpu_active_mask)) { | 5279 | if (!cpumask_intersects(new_mask, cpu_active_mask)) { |
5359 | ret = -EINVAL; | 5280 | ret = -EINVAL; |
@@ -5377,15 +5298,12 @@ int set_cpus_allowed_ptr(struct task_struct *p, const struct cpumask *new_mask) | |||
5377 | if (cpumask_test_cpu(task_cpu(p), new_mask)) | 5298 | if (cpumask_test_cpu(task_cpu(p), new_mask)) |
5378 | goto out; | 5299 | goto out; |
5379 | 5300 | ||
5380 | if (migrate_task(p, cpumask_any_and(cpu_active_mask, new_mask), &req)) { | 5301 | dest_cpu = cpumask_any_and(cpu_active_mask, new_mask); |
5302 | if (migrate_task(p, dest_cpu)) { | ||
5303 | struct migration_arg arg = { p, dest_cpu }; | ||
5381 | /* Need help from migration thread: drop lock and wait. */ | 5304 | /* Need help from migration thread: drop lock and wait. */ |
5382 | struct task_struct *mt = rq->migration_thread; | ||
5383 | |||
5384 | get_task_struct(mt); | ||
5385 | task_rq_unlock(rq, &flags); | 5305 | task_rq_unlock(rq, &flags); |
5386 | wake_up_process(rq->migration_thread); | 5306 | stop_one_cpu(cpu_of(rq), migration_cpu_stop, &arg); |
5387 | put_task_struct(mt); | ||
5388 | wait_for_completion(&req.done); | ||
5389 | tlb_migrate_finish(p->mm); | 5307 | tlb_migrate_finish(p->mm); |
5390 | return 0; | 5308 | return 0; |
5391 | } | 5309 | } |
@@ -5443,98 +5361,49 @@ fail: | |||
5443 | return ret; | 5361 | return ret; |
5444 | } | 5362 | } |
5445 | 5363 | ||
5446 | #define RCU_MIGRATION_IDLE 0 | ||
5447 | #define RCU_MIGRATION_NEED_QS 1 | ||
5448 | #define RCU_MIGRATION_GOT_QS 2 | ||
5449 | #define RCU_MIGRATION_MUST_SYNC 3 | ||
5450 | |||
5451 | /* | 5364 | /* |
5452 | * migration_thread - this is a highprio system thread that performs | 5365 | * migration_cpu_stop - this will be executed by a highprio stopper thread |
5453 | * thread migration by bumping thread off CPU then 'pushing' onto | 5366 | * and performs thread migration by bumping thread off CPU then |
5454 | * another runqueue. | 5367 | * 'pushing' onto another runqueue. |
5455 | */ | 5368 | */ |
5456 | static int migration_thread(void *data) | 5369 | static int migration_cpu_stop(void *data) |
5457 | { | 5370 | { |
5458 | int badcpu; | 5371 | struct migration_arg *arg = data; |
5459 | int cpu = (long)data; | ||
5460 | struct rq *rq; | ||
5461 | |||
5462 | rq = cpu_rq(cpu); | ||
5463 | BUG_ON(rq->migration_thread != current); | ||
5464 | |||
5465 | set_current_state(TASK_INTERRUPTIBLE); | ||
5466 | while (!kthread_should_stop()) { | ||
5467 | struct migration_req *req; | ||
5468 | struct list_head *head; | ||
5469 | |||
5470 | raw_spin_lock_irq(&rq->lock); | ||
5471 | |||
5472 | if (cpu_is_offline(cpu)) { | ||
5473 | raw_spin_unlock_irq(&rq->lock); | ||
5474 | break; | ||
5475 | } | ||
5476 | |||
5477 | if (rq->active_balance) { | ||
5478 | active_load_balance(rq, cpu); | ||
5479 | rq->active_balance = 0; | ||
5480 | } | ||
5481 | |||
5482 | head = &rq->migration_queue; | ||
5483 | |||
5484 | if (list_empty(head)) { | ||
5485 | raw_spin_unlock_irq(&rq->lock); | ||
5486 | schedule(); | ||
5487 | set_current_state(TASK_INTERRUPTIBLE); | ||
5488 | continue; | ||
5489 | } | ||
5490 | req = list_entry(head->next, struct migration_req, list); | ||
5491 | list_del_init(head->next); | ||
5492 | |||
5493 | if (req->task != NULL) { | ||
5494 | raw_spin_unlock(&rq->lock); | ||
5495 | __migrate_task(req->task, cpu, req->dest_cpu); | ||
5496 | } else if (likely(cpu == (badcpu = smp_processor_id()))) { | ||
5497 | req->dest_cpu = RCU_MIGRATION_GOT_QS; | ||
5498 | raw_spin_unlock(&rq->lock); | ||
5499 | } else { | ||
5500 | req->dest_cpu = RCU_MIGRATION_MUST_SYNC; | ||
5501 | raw_spin_unlock(&rq->lock); | ||
5502 | WARN_ONCE(1, "migration_thread() on CPU %d, expected %d\n", badcpu, cpu); | ||
5503 | } | ||
5504 | local_irq_enable(); | ||
5505 | |||
5506 | complete(&req->done); | ||
5507 | } | ||
5508 | __set_current_state(TASK_RUNNING); | ||
5509 | |||
5510 | return 0; | ||
5511 | } | ||
5512 | |||
5513 | #ifdef CONFIG_HOTPLUG_CPU | ||
5514 | |||
5515 | static int __migrate_task_irq(struct task_struct *p, int src_cpu, int dest_cpu) | ||
5516 | { | ||
5517 | int ret; | ||
5518 | 5372 | ||
5373 | /* | ||
5374 | * The original target cpu might have gone down and we might | ||
5375 | * be on another cpu but it doesn't matter. | ||
5376 | */ | ||
5519 | local_irq_disable(); | 5377 | local_irq_disable(); |
5520 | ret = __migrate_task(p, src_cpu, dest_cpu); | 5378 | __migrate_task(arg->task, raw_smp_processor_id(), arg->dest_cpu); |
5521 | local_irq_enable(); | 5379 | local_irq_enable(); |
5522 | return ret; | 5380 | return 0; |
5523 | } | 5381 | } |
5524 | 5382 | ||
5383 | #ifdef CONFIG_HOTPLUG_CPU | ||
5525 | /* | 5384 | /* |
5526 | * Figure out where task on dead CPU should go, use force if necessary. | 5385 | * Figure out where task on dead CPU should go, use force if necessary. |
5527 | */ | 5386 | */ |
5528 | static void move_task_off_dead_cpu(int dead_cpu, struct task_struct *p) | 5387 | void move_task_off_dead_cpu(int dead_cpu, struct task_struct *p) |
5529 | { | 5388 | { |
5530 | int dest_cpu; | 5389 | struct rq *rq = cpu_rq(dead_cpu); |
5390 | int needs_cpu, uninitialized_var(dest_cpu); | ||
5391 | unsigned long flags; | ||
5531 | 5392 | ||
5532 | again: | 5393 | local_irq_save(flags); |
5533 | dest_cpu = select_fallback_rq(dead_cpu, p); | ||
5534 | 5394 | ||
5535 | /* It can have affinity changed while we were choosing. */ | 5395 | raw_spin_lock(&rq->lock); |
5536 | if (unlikely(!__migrate_task_irq(p, dead_cpu, dest_cpu))) | 5396 | needs_cpu = (task_cpu(p) == dead_cpu) && (p->state != TASK_WAKING); |
5537 | goto again; | 5397 | if (needs_cpu) |
5398 | dest_cpu = select_fallback_rq(dead_cpu, p); | ||
5399 | raw_spin_unlock(&rq->lock); | ||
5400 | /* | ||
5401 | * It can only fail if we race with set_cpus_allowed(), | ||
5402 | * in the racer should migrate the task anyway. | ||
5403 | */ | ||
5404 | if (needs_cpu) | ||
5405 | __migrate_task(p, dead_cpu, dest_cpu); | ||
5406 | local_irq_restore(flags); | ||
5538 | } | 5407 | } |
5539 | 5408 | ||
5540 | /* | 5409 | /* |
@@ -5598,7 +5467,6 @@ void sched_idle_next(void) | |||
5598 | 5467 | ||
5599 | __setscheduler(rq, p, SCHED_FIFO, MAX_RT_PRIO-1); | 5468 | __setscheduler(rq, p, SCHED_FIFO, MAX_RT_PRIO-1); |
5600 | 5469 | ||
5601 | update_rq_clock(rq); | ||
5602 | activate_task(rq, p, 0); | 5470 | activate_task(rq, p, 0); |
5603 | 5471 | ||
5604 | raw_spin_unlock_irqrestore(&rq->lock, flags); | 5472 | raw_spin_unlock_irqrestore(&rq->lock, flags); |
@@ -5653,7 +5521,6 @@ static void migrate_dead_tasks(unsigned int dead_cpu) | |||
5653 | for ( ; ; ) { | 5521 | for ( ; ; ) { |
5654 | if (!rq->nr_running) | 5522 | if (!rq->nr_running) |
5655 | break; | 5523 | break; |
5656 | update_rq_clock(rq); | ||
5657 | next = pick_next_task(rq); | 5524 | next = pick_next_task(rq); |
5658 | if (!next) | 5525 | if (!next) |
5659 | break; | 5526 | break; |
@@ -5876,35 +5743,20 @@ static void set_rq_offline(struct rq *rq) | |||
5876 | static int __cpuinit | 5743 | static int __cpuinit |
5877 | migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu) | 5744 | migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu) |
5878 | { | 5745 | { |
5879 | struct task_struct *p; | ||
5880 | int cpu = (long)hcpu; | 5746 | int cpu = (long)hcpu; |
5881 | unsigned long flags; | 5747 | unsigned long flags; |
5882 | struct rq *rq; | 5748 | struct rq *rq = cpu_rq(cpu); |
5883 | 5749 | ||
5884 | switch (action) { | 5750 | switch (action) { |
5885 | 5751 | ||
5886 | case CPU_UP_PREPARE: | 5752 | case CPU_UP_PREPARE: |
5887 | case CPU_UP_PREPARE_FROZEN: | 5753 | case CPU_UP_PREPARE_FROZEN: |
5888 | p = kthread_create(migration_thread, hcpu, "migration/%d", cpu); | ||
5889 | if (IS_ERR(p)) | ||
5890 | return NOTIFY_BAD; | ||
5891 | kthread_bind(p, cpu); | ||
5892 | /* Must be high prio: stop_machine expects to yield to it. */ | ||
5893 | rq = task_rq_lock(p, &flags); | ||
5894 | __setscheduler(rq, p, SCHED_FIFO, MAX_RT_PRIO-1); | ||
5895 | task_rq_unlock(rq, &flags); | ||
5896 | get_task_struct(p); | ||
5897 | cpu_rq(cpu)->migration_thread = p; | ||
5898 | rq->calc_load_update = calc_load_update; | 5754 | rq->calc_load_update = calc_load_update; |
5899 | break; | 5755 | break; |
5900 | 5756 | ||
5901 | case CPU_ONLINE: | 5757 | case CPU_ONLINE: |
5902 | case CPU_ONLINE_FROZEN: | 5758 | case CPU_ONLINE_FROZEN: |
5903 | /* Strictly unnecessary, as first user will wake it. */ | ||
5904 | wake_up_process(cpu_rq(cpu)->migration_thread); | ||
5905 | |||
5906 | /* Update our root-domain */ | 5759 | /* Update our root-domain */ |
5907 | rq = cpu_rq(cpu); | ||
5908 | raw_spin_lock_irqsave(&rq->lock, flags); | 5760 | raw_spin_lock_irqsave(&rq->lock, flags); |
5909 | if (rq->rd) { | 5761 | if (rq->rd) { |
5910 | BUG_ON(!cpumask_test_cpu(cpu, rq->rd->span)); | 5762 | BUG_ON(!cpumask_test_cpu(cpu, rq->rd->span)); |
@@ -5915,61 +5767,24 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu) | |||
5915 | break; | 5767 | break; |
5916 | 5768 | ||
5917 | #ifdef CONFIG_HOTPLUG_CPU | 5769 | #ifdef CONFIG_HOTPLUG_CPU |
5918 | case CPU_UP_CANCELED: | ||
5919 | case CPU_UP_CANCELED_FROZEN: | ||
5920 | if (!cpu_rq(cpu)->migration_thread) | ||
5921 | break; | ||
5922 | /* Unbind it from offline cpu so it can run. Fall thru. */ | ||
5923 | kthread_bind(cpu_rq(cpu)->migration_thread, | ||
5924 | cpumask_any(cpu_online_mask)); | ||
5925 | kthread_stop(cpu_rq(cpu)->migration_thread); | ||
5926 | put_task_struct(cpu_rq(cpu)->migration_thread); | ||
5927 | cpu_rq(cpu)->migration_thread = NULL; | ||
5928 | break; | ||
5929 | |||
5930 | case CPU_DEAD: | 5770 | case CPU_DEAD: |
5931 | case CPU_DEAD_FROZEN: | 5771 | case CPU_DEAD_FROZEN: |
5932 | cpuset_lock(); /* around calls to cpuset_cpus_allowed_lock() */ | ||
5933 | migrate_live_tasks(cpu); | 5772 | migrate_live_tasks(cpu); |
5934 | rq = cpu_rq(cpu); | ||
5935 | kthread_stop(rq->migration_thread); | ||
5936 | put_task_struct(rq->migration_thread); | ||
5937 | rq->migration_thread = NULL; | ||
5938 | /* Idle task back to normal (off runqueue, low prio) */ | 5773 | /* Idle task back to normal (off runqueue, low prio) */ |
5939 | raw_spin_lock_irq(&rq->lock); | 5774 | raw_spin_lock_irq(&rq->lock); |
5940 | update_rq_clock(rq); | ||
5941 | deactivate_task(rq, rq->idle, 0); | 5775 | deactivate_task(rq, rq->idle, 0); |
5942 | __setscheduler(rq, rq->idle, SCHED_NORMAL, 0); | 5776 | __setscheduler(rq, rq->idle, SCHED_NORMAL, 0); |
5943 | rq->idle->sched_class = &idle_sched_class; | 5777 | rq->idle->sched_class = &idle_sched_class; |
5944 | migrate_dead_tasks(cpu); | 5778 | migrate_dead_tasks(cpu); |
5945 | raw_spin_unlock_irq(&rq->lock); | 5779 | raw_spin_unlock_irq(&rq->lock); |
5946 | cpuset_unlock(); | ||
5947 | migrate_nr_uninterruptible(rq); | 5780 | migrate_nr_uninterruptible(rq); |
5948 | BUG_ON(rq->nr_running != 0); | 5781 | BUG_ON(rq->nr_running != 0); |
5949 | calc_global_load_remove(rq); | 5782 | calc_global_load_remove(rq); |
5950 | /* | ||
5951 | * No need to migrate the tasks: it was best-effort if | ||
5952 | * they didn't take sched_hotcpu_mutex. Just wake up | ||
5953 | * the requestors. | ||
5954 | */ | ||
5955 | raw_spin_lock_irq(&rq->lock); | ||
5956 | while (!list_empty(&rq->migration_queue)) { | ||
5957 | struct migration_req *req; | ||
5958 | |||
5959 | req = list_entry(rq->migration_queue.next, | ||
5960 | struct migration_req, list); | ||
5961 | list_del_init(&req->list); | ||
5962 | raw_spin_unlock_irq(&rq->lock); | ||
5963 | complete(&req->done); | ||
5964 | raw_spin_lock_irq(&rq->lock); | ||
5965 | } | ||
5966 | raw_spin_unlock_irq(&rq->lock); | ||
5967 | break; | 5783 | break; |
5968 | 5784 | ||
5969 | case CPU_DYING: | 5785 | case CPU_DYING: |
5970 | case CPU_DYING_FROZEN: | 5786 | case CPU_DYING_FROZEN: |
5971 | /* Update our root-domain */ | 5787 | /* Update our root-domain */ |
5972 | rq = cpu_rq(cpu); | ||
5973 | raw_spin_lock_irqsave(&rq->lock, flags); | 5788 | raw_spin_lock_irqsave(&rq->lock, flags); |
5974 | if (rq->rd) { | 5789 | if (rq->rd) { |
5975 | BUG_ON(!cpumask_test_cpu(cpu, rq->rd->span)); | 5790 | BUG_ON(!cpumask_test_cpu(cpu, rq->rd->span)); |
@@ -6300,6 +6115,9 @@ cpu_attach_domain(struct sched_domain *sd, struct root_domain *rd, int cpu) | |||
6300 | struct rq *rq = cpu_rq(cpu); | 6115 | struct rq *rq = cpu_rq(cpu); |
6301 | struct sched_domain *tmp; | 6116 | struct sched_domain *tmp; |
6302 | 6117 | ||
6118 | for (tmp = sd; tmp; tmp = tmp->parent) | ||
6119 | tmp->span_weight = cpumask_weight(sched_domain_span(tmp)); | ||
6120 | |||
6303 | /* Remove the sched domains which do not contribute to scheduling. */ | 6121 | /* Remove the sched domains which do not contribute to scheduling. */ |
6304 | for (tmp = sd; tmp; ) { | 6122 | for (tmp = sd; tmp; ) { |
6305 | struct sched_domain *parent = tmp->parent; | 6123 | struct sched_domain *parent = tmp->parent; |
@@ -7406,11 +7224,13 @@ static ssize_t sched_power_savings_store(const char *buf, size_t count, int smt) | |||
7406 | 7224 | ||
7407 | #ifdef CONFIG_SCHED_MC | 7225 | #ifdef CONFIG_SCHED_MC |
7408 | static ssize_t sched_mc_power_savings_show(struct sysdev_class *class, | 7226 | static ssize_t sched_mc_power_savings_show(struct sysdev_class *class, |
7227 | struct sysdev_class_attribute *attr, | ||
7409 | char *page) | 7228 | char *page) |
7410 | { | 7229 | { |
7411 | return sprintf(page, "%u\n", sched_mc_power_savings); | 7230 | return sprintf(page, "%u\n", sched_mc_power_savings); |
7412 | } | 7231 | } |
7413 | static ssize_t sched_mc_power_savings_store(struct sysdev_class *class, | 7232 | static ssize_t sched_mc_power_savings_store(struct sysdev_class *class, |
7233 | struct sysdev_class_attribute *attr, | ||
7414 | const char *buf, size_t count) | 7234 | const char *buf, size_t count) |
7415 | { | 7235 | { |
7416 | return sched_power_savings_store(buf, count, 0); | 7236 | return sched_power_savings_store(buf, count, 0); |
@@ -7422,11 +7242,13 @@ static SYSDEV_CLASS_ATTR(sched_mc_power_savings, 0644, | |||
7422 | 7242 | ||
7423 | #ifdef CONFIG_SCHED_SMT | 7243 | #ifdef CONFIG_SCHED_SMT |
7424 | static ssize_t sched_smt_power_savings_show(struct sysdev_class *dev, | 7244 | static ssize_t sched_smt_power_savings_show(struct sysdev_class *dev, |
7245 | struct sysdev_class_attribute *attr, | ||
7425 | char *page) | 7246 | char *page) |
7426 | { | 7247 | { |
7427 | return sprintf(page, "%u\n", sched_smt_power_savings); | 7248 | return sprintf(page, "%u\n", sched_smt_power_savings); |
7428 | } | 7249 | } |
7429 | static ssize_t sched_smt_power_savings_store(struct sysdev_class *dev, | 7250 | static ssize_t sched_smt_power_savings_store(struct sysdev_class *dev, |
7251 | struct sysdev_class_attribute *attr, | ||
7430 | const char *buf, size_t count) | 7252 | const char *buf, size_t count) |
7431 | { | 7253 | { |
7432 | return sched_power_savings_store(buf, count, 1); | 7254 | return sched_power_savings_store(buf, count, 1); |
@@ -7779,10 +7601,8 @@ void __init sched_init(void) | |||
7779 | rq->push_cpu = 0; | 7601 | rq->push_cpu = 0; |
7780 | rq->cpu = i; | 7602 | rq->cpu = i; |
7781 | rq->online = 0; | 7603 | rq->online = 0; |
7782 | rq->migration_thread = NULL; | ||
7783 | rq->idle_stamp = 0; | 7604 | rq->idle_stamp = 0; |
7784 | rq->avg_idle = 2*sysctl_sched_migration_cost; | 7605 | rq->avg_idle = 2*sysctl_sched_migration_cost; |
7785 | INIT_LIST_HEAD(&rq->migration_queue); | ||
7786 | rq_attach_root(rq, &def_root_domain); | 7606 | rq_attach_root(rq, &def_root_domain); |
7787 | #endif | 7607 | #endif |
7788 | init_rq_hrtick(rq); | 7608 | init_rq_hrtick(rq); |
@@ -7883,7 +7703,6 @@ static void normalize_task(struct rq *rq, struct task_struct *p) | |||
7883 | { | 7703 | { |
7884 | int on_rq; | 7704 | int on_rq; |
7885 | 7705 | ||
7886 | update_rq_clock(rq); | ||
7887 | on_rq = p->se.on_rq; | 7706 | on_rq = p->se.on_rq; |
7888 | if (on_rq) | 7707 | if (on_rq) |
7889 | deactivate_task(rq, p, 0); | 7708 | deactivate_task(rq, p, 0); |
@@ -7910,9 +7729,9 @@ void normalize_rt_tasks(void) | |||
7910 | 7729 | ||
7911 | p->se.exec_start = 0; | 7730 | p->se.exec_start = 0; |
7912 | #ifdef CONFIG_SCHEDSTATS | 7731 | #ifdef CONFIG_SCHEDSTATS |
7913 | p->se.wait_start = 0; | 7732 | p->se.statistics.wait_start = 0; |
7914 | p->se.sleep_start = 0; | 7733 | p->se.statistics.sleep_start = 0; |
7915 | p->se.block_start = 0; | 7734 | p->se.statistics.block_start = 0; |
7916 | #endif | 7735 | #endif |
7917 | 7736 | ||
7918 | if (!rt_task(p)) { | 7737 | if (!rt_task(p)) { |
@@ -8245,8 +8064,6 @@ void sched_move_task(struct task_struct *tsk) | |||
8245 | 8064 | ||
8246 | rq = task_rq_lock(tsk, &flags); | 8065 | rq = task_rq_lock(tsk, &flags); |
8247 | 8066 | ||
8248 | update_rq_clock(rq); | ||
8249 | |||
8250 | running = task_current(rq, tsk); | 8067 | running = task_current(rq, tsk); |
8251 | on_rq = tsk->se.on_rq; | 8068 | on_rq = tsk->se.on_rq; |
8252 | 8069 | ||
@@ -8265,7 +8082,7 @@ void sched_move_task(struct task_struct *tsk) | |||
8265 | if (unlikely(running)) | 8082 | if (unlikely(running)) |
8266 | tsk->sched_class->set_curr_task(rq); | 8083 | tsk->sched_class->set_curr_task(rq); |
8267 | if (on_rq) | 8084 | if (on_rq) |
8268 | enqueue_task(rq, tsk, 0, false); | 8085 | enqueue_task(rq, tsk, 0); |
8269 | 8086 | ||
8270 | task_rq_unlock(rq, &flags); | 8087 | task_rq_unlock(rq, &flags); |
8271 | } | 8088 | } |
@@ -8813,7 +8630,7 @@ struct cgroup_subsys cpu_cgroup_subsys = { | |||
8813 | struct cpuacct { | 8630 | struct cpuacct { |
8814 | struct cgroup_subsys_state css; | 8631 | struct cgroup_subsys_state css; |
8815 | /* cpuusage holds pointer to a u64-type object on every cpu */ | 8632 | /* cpuusage holds pointer to a u64-type object on every cpu */ |
8816 | u64 *cpuusage; | 8633 | u64 __percpu *cpuusage; |
8817 | struct percpu_counter cpustat[CPUACCT_STAT_NSTATS]; | 8634 | struct percpu_counter cpustat[CPUACCT_STAT_NSTATS]; |
8818 | struct cpuacct *parent; | 8635 | struct cpuacct *parent; |
8819 | }; | 8636 | }; |
@@ -9079,43 +8896,32 @@ struct cgroup_subsys cpuacct_subsys = { | |||
9079 | 8896 | ||
9080 | #ifndef CONFIG_SMP | 8897 | #ifndef CONFIG_SMP |
9081 | 8898 | ||
9082 | int rcu_expedited_torture_stats(char *page) | ||
9083 | { | ||
9084 | return 0; | ||
9085 | } | ||
9086 | EXPORT_SYMBOL_GPL(rcu_expedited_torture_stats); | ||
9087 | |||
9088 | void synchronize_sched_expedited(void) | 8899 | void synchronize_sched_expedited(void) |
9089 | { | 8900 | { |
8901 | barrier(); | ||
9090 | } | 8902 | } |
9091 | EXPORT_SYMBOL_GPL(synchronize_sched_expedited); | 8903 | EXPORT_SYMBOL_GPL(synchronize_sched_expedited); |
9092 | 8904 | ||
9093 | #else /* #ifndef CONFIG_SMP */ | 8905 | #else /* #ifndef CONFIG_SMP */ |
9094 | 8906 | ||
9095 | static DEFINE_PER_CPU(struct migration_req, rcu_migration_req); | 8907 | static atomic_t synchronize_sched_expedited_count = ATOMIC_INIT(0); |
9096 | static DEFINE_MUTEX(rcu_sched_expedited_mutex); | ||
9097 | |||
9098 | #define RCU_EXPEDITED_STATE_POST -2 | ||
9099 | #define RCU_EXPEDITED_STATE_IDLE -1 | ||
9100 | 8908 | ||
9101 | static int rcu_expedited_state = RCU_EXPEDITED_STATE_IDLE; | 8909 | static int synchronize_sched_expedited_cpu_stop(void *data) |
9102 | |||
9103 | int rcu_expedited_torture_stats(char *page) | ||
9104 | { | 8910 | { |
9105 | int cnt = 0; | 8911 | /* |
9106 | int cpu; | 8912 | * There must be a full memory barrier on each affected CPU |
9107 | 8913 | * between the time that try_stop_cpus() is called and the | |
9108 | cnt += sprintf(&page[cnt], "state: %d /", rcu_expedited_state); | 8914 | * time that it returns. |
9109 | for_each_online_cpu(cpu) { | 8915 | * |
9110 | cnt += sprintf(&page[cnt], " %d:%d", | 8916 | * In the current initial implementation of cpu_stop, the |
9111 | cpu, per_cpu(rcu_migration_req, cpu).dest_cpu); | 8917 | * above condition is already met when the control reaches |
9112 | } | 8918 | * this point and the following smp_mb() is not strictly |
9113 | cnt += sprintf(&page[cnt], "\n"); | 8919 | * necessary. Do smp_mb() anyway for documentation and |
9114 | return cnt; | 8920 | * robustness against future implementation changes. |
8921 | */ | ||
8922 | smp_mb(); /* See above comment block. */ | ||
8923 | return 0; | ||
9115 | } | 8924 | } |
9116 | EXPORT_SYMBOL_GPL(rcu_expedited_torture_stats); | ||
9117 | |||
9118 | static long synchronize_sched_expedited_count; | ||
9119 | 8925 | ||
9120 | /* | 8926 | /* |
9121 | * Wait for an rcu-sched grace period to elapse, but use "big hammer" | 8927 | * Wait for an rcu-sched grace period to elapse, but use "big hammer" |
@@ -9129,18 +8935,14 @@ static long synchronize_sched_expedited_count; | |||
9129 | */ | 8935 | */ |
9130 | void synchronize_sched_expedited(void) | 8936 | void synchronize_sched_expedited(void) |
9131 | { | 8937 | { |
9132 | int cpu; | 8938 | int snap, trycount = 0; |
9133 | unsigned long flags; | ||
9134 | bool need_full_sync = 0; | ||
9135 | struct rq *rq; | ||
9136 | struct migration_req *req; | ||
9137 | long snap; | ||
9138 | int trycount = 0; | ||
9139 | 8939 | ||
9140 | smp_mb(); /* ensure prior mod happens before capturing snap. */ | 8940 | smp_mb(); /* ensure prior mod happens before capturing snap. */ |
9141 | snap = ACCESS_ONCE(synchronize_sched_expedited_count) + 1; | 8941 | snap = atomic_read(&synchronize_sched_expedited_count) + 1; |
9142 | get_online_cpus(); | 8942 | get_online_cpus(); |
9143 | while (!mutex_trylock(&rcu_sched_expedited_mutex)) { | 8943 | while (try_stop_cpus(cpu_online_mask, |
8944 | synchronize_sched_expedited_cpu_stop, | ||
8945 | NULL) == -EAGAIN) { | ||
9144 | put_online_cpus(); | 8946 | put_online_cpus(); |
9145 | if (trycount++ < 10) | 8947 | if (trycount++ < 10) |
9146 | udelay(trycount * num_online_cpus()); | 8948 | udelay(trycount * num_online_cpus()); |
@@ -9148,41 +8950,15 @@ void synchronize_sched_expedited(void) | |||
9148 | synchronize_sched(); | 8950 | synchronize_sched(); |
9149 | return; | 8951 | return; |
9150 | } | 8952 | } |
9151 | if (ACCESS_ONCE(synchronize_sched_expedited_count) - snap > 0) { | 8953 | if (atomic_read(&synchronize_sched_expedited_count) - snap > 0) { |
9152 | smp_mb(); /* ensure test happens before caller kfree */ | 8954 | smp_mb(); /* ensure test happens before caller kfree */ |
9153 | return; | 8955 | return; |
9154 | } | 8956 | } |
9155 | get_online_cpus(); | 8957 | get_online_cpus(); |
9156 | } | 8958 | } |
9157 | rcu_expedited_state = RCU_EXPEDITED_STATE_POST; | 8959 | atomic_inc(&synchronize_sched_expedited_count); |
9158 | for_each_online_cpu(cpu) { | 8960 | smp_mb__after_atomic_inc(); /* ensure post-GP actions seen after GP. */ |
9159 | rq = cpu_rq(cpu); | ||
9160 | req = &per_cpu(rcu_migration_req, cpu); | ||
9161 | init_completion(&req->done); | ||
9162 | req->task = NULL; | ||
9163 | req->dest_cpu = RCU_MIGRATION_NEED_QS; | ||
9164 | raw_spin_lock_irqsave(&rq->lock, flags); | ||
9165 | list_add(&req->list, &rq->migration_queue); | ||
9166 | raw_spin_unlock_irqrestore(&rq->lock, flags); | ||
9167 | wake_up_process(rq->migration_thread); | ||
9168 | } | ||
9169 | for_each_online_cpu(cpu) { | ||
9170 | rcu_expedited_state = cpu; | ||
9171 | req = &per_cpu(rcu_migration_req, cpu); | ||
9172 | rq = cpu_rq(cpu); | ||
9173 | wait_for_completion(&req->done); | ||
9174 | raw_spin_lock_irqsave(&rq->lock, flags); | ||
9175 | if (unlikely(req->dest_cpu == RCU_MIGRATION_MUST_SYNC)) | ||
9176 | need_full_sync = 1; | ||
9177 | req->dest_cpu = RCU_MIGRATION_IDLE; | ||
9178 | raw_spin_unlock_irqrestore(&rq->lock, flags); | ||
9179 | } | ||
9180 | rcu_expedited_state = RCU_EXPEDITED_STATE_IDLE; | ||
9181 | synchronize_sched_expedited_count++; | ||
9182 | mutex_unlock(&rcu_sched_expedited_mutex); | ||
9183 | put_online_cpus(); | 8961 | put_online_cpus(); |
9184 | if (need_full_sync) | ||
9185 | synchronize_sched(); | ||
9186 | } | 8962 | } |
9187 | EXPORT_SYMBOL_GPL(synchronize_sched_expedited); | 8963 | EXPORT_SYMBOL_GPL(synchronize_sched_expedited); |
9188 | 8964 | ||