diff options
author | Ingo Molnar <mingo@elte.hu> | 2008-08-15 12:15:17 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2008-08-15 12:15:17 -0400 |
commit | f3efbe582b5396d134024c03a5fa253f2a85d9a6 (patch) | |
tree | e4e15b7567b82d24cb1e7327398286a2b88df04c /kernel/sched.c | |
parent | 05d3ed0a1fe3ea05ab9f3b8d32576a0bc2e19660 (diff) | |
parent | b635acec48bcaa9183fcbf4e3955616b0d4119b5 (diff) |
Merge branch 'linus' into x86/gart
Diffstat (limited to 'kernel/sched.c')
-rw-r--r-- | kernel/sched.c | 452 |
1 files changed, 195 insertions, 257 deletions
diff --git a/kernel/sched.c b/kernel/sched.c index b1104ea5d255..d601fb0406ca 100644 --- a/kernel/sched.c +++ b/kernel/sched.c | |||
@@ -571,8 +571,10 @@ struct rq { | |||
571 | #endif | 571 | #endif |
572 | 572 | ||
573 | #ifdef CONFIG_SCHED_HRTICK | 573 | #ifdef CONFIG_SCHED_HRTICK |
574 | unsigned long hrtick_flags; | 574 | #ifdef CONFIG_SMP |
575 | ktime_t hrtick_expire; | 575 | int hrtick_csd_pending; |
576 | struct call_single_data hrtick_csd; | ||
577 | #endif | ||
576 | struct hrtimer hrtick_timer; | 578 | struct hrtimer hrtick_timer; |
577 | #endif | 579 | #endif |
578 | 580 | ||
@@ -598,7 +600,6 @@ struct rq { | |||
598 | /* BKL stats */ | 600 | /* BKL stats */ |
599 | unsigned int bkl_count; | 601 | unsigned int bkl_count; |
600 | #endif | 602 | #endif |
601 | struct lock_class_key rq_lock_key; | ||
602 | }; | 603 | }; |
603 | 604 | ||
604 | static DEFINE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues); | 605 | static DEFINE_PER_CPU_SHARED_ALIGNED(struct rq, runqueues); |
@@ -832,7 +833,7 @@ static inline u64 global_rt_period(void) | |||
832 | 833 | ||
833 | static inline u64 global_rt_runtime(void) | 834 | static inline u64 global_rt_runtime(void) |
834 | { | 835 | { |
835 | if (sysctl_sched_rt_period < 0) | 836 | if (sysctl_sched_rt_runtime < 0) |
836 | return RUNTIME_INF; | 837 | return RUNTIME_INF; |
837 | 838 | ||
838 | return (u64)sysctl_sched_rt_runtime * NSEC_PER_USEC; | 839 | return (u64)sysctl_sched_rt_runtime * NSEC_PER_USEC; |
@@ -983,13 +984,6 @@ static struct rq *this_rq_lock(void) | |||
983 | return rq; | 984 | return rq; |
984 | } | 985 | } |
985 | 986 | ||
986 | static void __resched_task(struct task_struct *p, int tif_bit); | ||
987 | |||
988 | static inline void resched_task(struct task_struct *p) | ||
989 | { | ||
990 | __resched_task(p, TIF_NEED_RESCHED); | ||
991 | } | ||
992 | |||
993 | #ifdef CONFIG_SCHED_HRTICK | 987 | #ifdef CONFIG_SCHED_HRTICK |
994 | /* | 988 | /* |
995 | * Use HR-timers to deliver accurate preemption points. | 989 | * Use HR-timers to deliver accurate preemption points. |
@@ -1001,25 +995,6 @@ static inline void resched_task(struct task_struct *p) | |||
1001 | * When we get rescheduled we reprogram the hrtick_timer outside of the | 995 | * When we get rescheduled we reprogram the hrtick_timer outside of the |
1002 | * rq->lock. | 996 | * rq->lock. |
1003 | */ | 997 | */ |
1004 | static inline void resched_hrt(struct task_struct *p) | ||
1005 | { | ||
1006 | __resched_task(p, TIF_HRTICK_RESCHED); | ||
1007 | } | ||
1008 | |||
1009 | static inline void resched_rq(struct rq *rq) | ||
1010 | { | ||
1011 | unsigned long flags; | ||
1012 | |||
1013 | spin_lock_irqsave(&rq->lock, flags); | ||
1014 | resched_task(rq->curr); | ||
1015 | spin_unlock_irqrestore(&rq->lock, flags); | ||
1016 | } | ||
1017 | |||
1018 | enum { | ||
1019 | HRTICK_SET, /* re-programm hrtick_timer */ | ||
1020 | HRTICK_RESET, /* not a new slice */ | ||
1021 | HRTICK_BLOCK, /* stop hrtick operations */ | ||
1022 | }; | ||
1023 | 998 | ||
1024 | /* | 999 | /* |
1025 | * Use hrtick when: | 1000 | * Use hrtick when: |
@@ -1030,40 +1005,11 @@ static inline int hrtick_enabled(struct rq *rq) | |||
1030 | { | 1005 | { |
1031 | if (!sched_feat(HRTICK)) | 1006 | if (!sched_feat(HRTICK)) |
1032 | return 0; | 1007 | return 0; |
1033 | if (unlikely(test_bit(HRTICK_BLOCK, &rq->hrtick_flags))) | 1008 | if (!cpu_active(cpu_of(rq))) |
1034 | return 0; | 1009 | return 0; |
1035 | return hrtimer_is_hres_active(&rq->hrtick_timer); | 1010 | return hrtimer_is_hres_active(&rq->hrtick_timer); |
1036 | } | 1011 | } |
1037 | 1012 | ||
1038 | /* | ||
1039 | * Called to set the hrtick timer state. | ||
1040 | * | ||
1041 | * called with rq->lock held and irqs disabled | ||
1042 | */ | ||
1043 | static void hrtick_start(struct rq *rq, u64 delay, int reset) | ||
1044 | { | ||
1045 | assert_spin_locked(&rq->lock); | ||
1046 | |||
1047 | /* | ||
1048 | * preempt at: now + delay | ||
1049 | */ | ||
1050 | rq->hrtick_expire = | ||
1051 | ktime_add_ns(rq->hrtick_timer.base->get_time(), delay); | ||
1052 | /* | ||
1053 | * indicate we need to program the timer | ||
1054 | */ | ||
1055 | __set_bit(HRTICK_SET, &rq->hrtick_flags); | ||
1056 | if (reset) | ||
1057 | __set_bit(HRTICK_RESET, &rq->hrtick_flags); | ||
1058 | |||
1059 | /* | ||
1060 | * New slices are called from the schedule path and don't need a | ||
1061 | * forced reschedule. | ||
1062 | */ | ||
1063 | if (reset) | ||
1064 | resched_hrt(rq->curr); | ||
1065 | } | ||
1066 | |||
1067 | static void hrtick_clear(struct rq *rq) | 1013 | static void hrtick_clear(struct rq *rq) |
1068 | { | 1014 | { |
1069 | if (hrtimer_active(&rq->hrtick_timer)) | 1015 | if (hrtimer_active(&rq->hrtick_timer)) |
@@ -1071,32 +1017,6 @@ static void hrtick_clear(struct rq *rq) | |||
1071 | } | 1017 | } |
1072 | 1018 | ||
1073 | /* | 1019 | /* |
1074 | * Update the timer from the possible pending state. | ||
1075 | */ | ||
1076 | static void hrtick_set(struct rq *rq) | ||
1077 | { | ||
1078 | ktime_t time; | ||
1079 | int set, reset; | ||
1080 | unsigned long flags; | ||
1081 | |||
1082 | WARN_ON_ONCE(cpu_of(rq) != smp_processor_id()); | ||
1083 | |||
1084 | spin_lock_irqsave(&rq->lock, flags); | ||
1085 | set = __test_and_clear_bit(HRTICK_SET, &rq->hrtick_flags); | ||
1086 | reset = __test_and_clear_bit(HRTICK_RESET, &rq->hrtick_flags); | ||
1087 | time = rq->hrtick_expire; | ||
1088 | clear_thread_flag(TIF_HRTICK_RESCHED); | ||
1089 | spin_unlock_irqrestore(&rq->lock, flags); | ||
1090 | |||
1091 | if (set) { | ||
1092 | hrtimer_start(&rq->hrtick_timer, time, HRTIMER_MODE_ABS); | ||
1093 | if (reset && !hrtimer_active(&rq->hrtick_timer)) | ||
1094 | resched_rq(rq); | ||
1095 | } else | ||
1096 | hrtick_clear(rq); | ||
1097 | } | ||
1098 | |||
1099 | /* | ||
1100 | * High-resolution timer tick. | 1020 | * High-resolution timer tick. |
1101 | * Runs from hardirq context with interrupts disabled. | 1021 | * Runs from hardirq context with interrupts disabled. |
1102 | */ | 1022 | */ |
@@ -1115,27 +1035,37 @@ static enum hrtimer_restart hrtick(struct hrtimer *timer) | |||
1115 | } | 1035 | } |
1116 | 1036 | ||
1117 | #ifdef CONFIG_SMP | 1037 | #ifdef CONFIG_SMP |
1118 | static void hotplug_hrtick_disable(int cpu) | 1038 | /* |
1039 | * called from hardirq (IPI) context | ||
1040 | */ | ||
1041 | static void __hrtick_start(void *arg) | ||
1119 | { | 1042 | { |
1120 | struct rq *rq = cpu_rq(cpu); | 1043 | struct rq *rq = arg; |
1121 | unsigned long flags; | ||
1122 | 1044 | ||
1123 | spin_lock_irqsave(&rq->lock, flags); | 1045 | spin_lock(&rq->lock); |
1124 | rq->hrtick_flags = 0; | 1046 | hrtimer_restart(&rq->hrtick_timer); |
1125 | __set_bit(HRTICK_BLOCK, &rq->hrtick_flags); | 1047 | rq->hrtick_csd_pending = 0; |
1126 | spin_unlock_irqrestore(&rq->lock, flags); | 1048 | spin_unlock(&rq->lock); |
1127 | |||
1128 | hrtick_clear(rq); | ||
1129 | } | 1049 | } |
1130 | 1050 | ||
1131 | static void hotplug_hrtick_enable(int cpu) | 1051 | /* |
1052 | * Called to set the hrtick timer state. | ||
1053 | * | ||
1054 | * called with rq->lock held and irqs disabled | ||
1055 | */ | ||
1056 | static void hrtick_start(struct rq *rq, u64 delay) | ||
1132 | { | 1057 | { |
1133 | struct rq *rq = cpu_rq(cpu); | 1058 | struct hrtimer *timer = &rq->hrtick_timer; |
1134 | unsigned long flags; | 1059 | ktime_t time = ktime_add_ns(timer->base->get_time(), delay); |
1135 | 1060 | ||
1136 | spin_lock_irqsave(&rq->lock, flags); | 1061 | timer->expires = time; |
1137 | __clear_bit(HRTICK_BLOCK, &rq->hrtick_flags); | 1062 | |
1138 | spin_unlock_irqrestore(&rq->lock, flags); | 1063 | if (rq == this_rq()) { |
1064 | hrtimer_restart(timer); | ||
1065 | } else if (!rq->hrtick_csd_pending) { | ||
1066 | __smp_call_function_single(cpu_of(rq), &rq->hrtick_csd); | ||
1067 | rq->hrtick_csd_pending = 1; | ||
1068 | } | ||
1139 | } | 1069 | } |
1140 | 1070 | ||
1141 | static int | 1071 | static int |
@@ -1150,16 +1080,7 @@ hotplug_hrtick(struct notifier_block *nfb, unsigned long action, void *hcpu) | |||
1150 | case CPU_DOWN_PREPARE_FROZEN: | 1080 | case CPU_DOWN_PREPARE_FROZEN: |
1151 | case CPU_DEAD: | 1081 | case CPU_DEAD: |
1152 | case CPU_DEAD_FROZEN: | 1082 | case CPU_DEAD_FROZEN: |
1153 | hotplug_hrtick_disable(cpu); | 1083 | hrtick_clear(cpu_rq(cpu)); |
1154 | return NOTIFY_OK; | ||
1155 | |||
1156 | case CPU_UP_PREPARE: | ||
1157 | case CPU_UP_PREPARE_FROZEN: | ||
1158 | case CPU_DOWN_FAILED: | ||
1159 | case CPU_DOWN_FAILED_FROZEN: | ||
1160 | case CPU_ONLINE: | ||
1161 | case CPU_ONLINE_FROZEN: | ||
1162 | hotplug_hrtick_enable(cpu); | ||
1163 | return NOTIFY_OK; | 1084 | return NOTIFY_OK; |
1164 | } | 1085 | } |
1165 | 1086 | ||
@@ -1170,46 +1091,45 @@ static void init_hrtick(void) | |||
1170 | { | 1091 | { |
1171 | hotcpu_notifier(hotplug_hrtick, 0); | 1092 | hotcpu_notifier(hotplug_hrtick, 0); |
1172 | } | 1093 | } |
1173 | #endif /* CONFIG_SMP */ | 1094 | #else |
1095 | /* | ||
1096 | * Called to set the hrtick timer state. | ||
1097 | * | ||
1098 | * called with rq->lock held and irqs disabled | ||
1099 | */ | ||
1100 | static void hrtick_start(struct rq *rq, u64 delay) | ||
1101 | { | ||
1102 | hrtimer_start(&rq->hrtick_timer, ns_to_ktime(delay), HRTIMER_MODE_REL); | ||
1103 | } | ||
1174 | 1104 | ||
1175 | static void init_rq_hrtick(struct rq *rq) | 1105 | static void init_hrtick(void) |
1176 | { | 1106 | { |
1177 | rq->hrtick_flags = 0; | ||
1178 | hrtimer_init(&rq->hrtick_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); | ||
1179 | rq->hrtick_timer.function = hrtick; | ||
1180 | rq->hrtick_timer.cb_mode = HRTIMER_CB_IRQSAFE_NO_SOFTIRQ; | ||
1181 | } | 1107 | } |
1108 | #endif /* CONFIG_SMP */ | ||
1182 | 1109 | ||
1183 | void hrtick_resched(void) | 1110 | static void init_rq_hrtick(struct rq *rq) |
1184 | { | 1111 | { |
1185 | struct rq *rq; | 1112 | #ifdef CONFIG_SMP |
1186 | unsigned long flags; | 1113 | rq->hrtick_csd_pending = 0; |
1187 | 1114 | ||
1188 | if (!test_thread_flag(TIF_HRTICK_RESCHED)) | 1115 | rq->hrtick_csd.flags = 0; |
1189 | return; | 1116 | rq->hrtick_csd.func = __hrtick_start; |
1117 | rq->hrtick_csd.info = rq; | ||
1118 | #endif | ||
1190 | 1119 | ||
1191 | local_irq_save(flags); | 1120 | hrtimer_init(&rq->hrtick_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); |
1192 | rq = cpu_rq(smp_processor_id()); | 1121 | rq->hrtick_timer.function = hrtick; |
1193 | hrtick_set(rq); | 1122 | rq->hrtick_timer.cb_mode = HRTIMER_CB_IRQSAFE_NO_SOFTIRQ; |
1194 | local_irq_restore(flags); | ||
1195 | } | 1123 | } |
1196 | #else | 1124 | #else |
1197 | static inline void hrtick_clear(struct rq *rq) | 1125 | static inline void hrtick_clear(struct rq *rq) |
1198 | { | 1126 | { |
1199 | } | 1127 | } |
1200 | 1128 | ||
1201 | static inline void hrtick_set(struct rq *rq) | ||
1202 | { | ||
1203 | } | ||
1204 | |||
1205 | static inline void init_rq_hrtick(struct rq *rq) | 1129 | static inline void init_rq_hrtick(struct rq *rq) |
1206 | { | 1130 | { |
1207 | } | 1131 | } |
1208 | 1132 | ||
1209 | void hrtick_resched(void) | ||
1210 | { | ||
1211 | } | ||
1212 | |||
1213 | static inline void init_hrtick(void) | 1133 | static inline void init_hrtick(void) |
1214 | { | 1134 | { |
1215 | } | 1135 | } |
@@ -1228,16 +1148,16 @@ static inline void init_hrtick(void) | |||
1228 | #define tsk_is_polling(t) test_tsk_thread_flag(t, TIF_POLLING_NRFLAG) | 1148 | #define tsk_is_polling(t) test_tsk_thread_flag(t, TIF_POLLING_NRFLAG) |
1229 | #endif | 1149 | #endif |
1230 | 1150 | ||
1231 | static void __resched_task(struct task_struct *p, int tif_bit) | 1151 | static void resched_task(struct task_struct *p) |
1232 | { | 1152 | { |
1233 | int cpu; | 1153 | int cpu; |
1234 | 1154 | ||
1235 | assert_spin_locked(&task_rq(p)->lock); | 1155 | assert_spin_locked(&task_rq(p)->lock); |
1236 | 1156 | ||
1237 | if (unlikely(test_tsk_thread_flag(p, tif_bit))) | 1157 | if (unlikely(test_tsk_thread_flag(p, TIF_NEED_RESCHED))) |
1238 | return; | 1158 | return; |
1239 | 1159 | ||
1240 | set_tsk_thread_flag(p, tif_bit); | 1160 | set_tsk_thread_flag(p, TIF_NEED_RESCHED); |
1241 | 1161 | ||
1242 | cpu = task_cpu(p); | 1162 | cpu = task_cpu(p); |
1243 | if (cpu == smp_processor_id()) | 1163 | if (cpu == smp_processor_id()) |
@@ -1303,10 +1223,10 @@ void wake_up_idle_cpu(int cpu) | |||
1303 | #endif /* CONFIG_NO_HZ */ | 1223 | #endif /* CONFIG_NO_HZ */ |
1304 | 1224 | ||
1305 | #else /* !CONFIG_SMP */ | 1225 | #else /* !CONFIG_SMP */ |
1306 | static void __resched_task(struct task_struct *p, int tif_bit) | 1226 | static void resched_task(struct task_struct *p) |
1307 | { | 1227 | { |
1308 | assert_spin_locked(&task_rq(p)->lock); | 1228 | assert_spin_locked(&task_rq(p)->lock); |
1309 | set_tsk_thread_flag(p, tif_bit); | 1229 | set_tsk_need_resched(p); |
1310 | } | 1230 | } |
1311 | #endif /* CONFIG_SMP */ | 1231 | #endif /* CONFIG_SMP */ |
1312 | 1232 | ||
@@ -1946,16 +1866,24 @@ migrate_task(struct task_struct *p, int dest_cpu, struct migration_req *req) | |||
1946 | /* | 1866 | /* |
1947 | * wait_task_inactive - wait for a thread to unschedule. | 1867 | * wait_task_inactive - wait for a thread to unschedule. |
1948 | * | 1868 | * |
1869 | * If @match_state is nonzero, it's the @p->state value just checked and | ||
1870 | * not expected to change. If it changes, i.e. @p might have woken up, | ||
1871 | * then return zero. When we succeed in waiting for @p to be off its CPU, | ||
1872 | * we return a positive number (its total switch count). If a second call | ||
1873 | * a short while later returns the same number, the caller can be sure that | ||
1874 | * @p has remained unscheduled the whole time. | ||
1875 | * | ||
1949 | * The caller must ensure that the task *will* unschedule sometime soon, | 1876 | * The caller must ensure that the task *will* unschedule sometime soon, |
1950 | * else this function might spin for a *long* time. This function can't | 1877 | * else this function might spin for a *long* time. This function can't |
1951 | * be called with interrupts off, or it may introduce deadlock with | 1878 | * be called with interrupts off, or it may introduce deadlock with |
1952 | * smp_call_function() if an IPI is sent by the same process we are | 1879 | * smp_call_function() if an IPI is sent by the same process we are |
1953 | * waiting to become inactive. | 1880 | * waiting to become inactive. |
1954 | */ | 1881 | */ |
1955 | void wait_task_inactive(struct task_struct *p) | 1882 | unsigned long wait_task_inactive(struct task_struct *p, long match_state) |
1956 | { | 1883 | { |
1957 | unsigned long flags; | 1884 | unsigned long flags; |
1958 | int running, on_rq; | 1885 | int running, on_rq; |
1886 | unsigned long ncsw; | ||
1959 | struct rq *rq; | 1887 | struct rq *rq; |
1960 | 1888 | ||
1961 | for (;;) { | 1889 | for (;;) { |
@@ -1978,8 +1906,11 @@ void wait_task_inactive(struct task_struct *p) | |||
1978 | * return false if the runqueue has changed and p | 1906 | * return false if the runqueue has changed and p |
1979 | * is actually now running somewhere else! | 1907 | * is actually now running somewhere else! |
1980 | */ | 1908 | */ |
1981 | while (task_running(rq, p)) | 1909 | while (task_running(rq, p)) { |
1910 | if (match_state && unlikely(p->state != match_state)) | ||
1911 | return 0; | ||
1982 | cpu_relax(); | 1912 | cpu_relax(); |
1913 | } | ||
1983 | 1914 | ||
1984 | /* | 1915 | /* |
1985 | * Ok, time to look more closely! We need the rq | 1916 | * Ok, time to look more closely! We need the rq |
@@ -1989,9 +1920,21 @@ void wait_task_inactive(struct task_struct *p) | |||
1989 | rq = task_rq_lock(p, &flags); | 1920 | rq = task_rq_lock(p, &flags); |
1990 | running = task_running(rq, p); | 1921 | running = task_running(rq, p); |
1991 | on_rq = p->se.on_rq; | 1922 | on_rq = p->se.on_rq; |
1923 | ncsw = 0; | ||
1924 | if (!match_state || p->state == match_state) { | ||
1925 | ncsw = p->nivcsw + p->nvcsw; | ||
1926 | if (unlikely(!ncsw)) | ||
1927 | ncsw = 1; | ||
1928 | } | ||
1992 | task_rq_unlock(rq, &flags); | 1929 | task_rq_unlock(rq, &flags); |
1993 | 1930 | ||
1994 | /* | 1931 | /* |
1932 | * If it changed from the expected state, bail out now. | ||
1933 | */ | ||
1934 | if (unlikely(!ncsw)) | ||
1935 | break; | ||
1936 | |||
1937 | /* | ||
1995 | * Was it really running after all now that we | 1938 | * Was it really running after all now that we |
1996 | * checked with the proper locks actually held? | 1939 | * checked with the proper locks actually held? |
1997 | * | 1940 | * |
@@ -2023,6 +1966,8 @@ void wait_task_inactive(struct task_struct *p) | |||
2023 | */ | 1966 | */ |
2024 | break; | 1967 | break; |
2025 | } | 1968 | } |
1969 | |||
1970 | return ncsw; | ||
2026 | } | 1971 | } |
2027 | 1972 | ||
2028 | /*** | 1973 | /*** |
@@ -2108,7 +2053,7 @@ find_idlest_group(struct sched_domain *sd, struct task_struct *p, int this_cpu) | |||
2108 | /* Tally up the load of all CPUs in the group */ | 2053 | /* Tally up the load of all CPUs in the group */ |
2109 | avg_load = 0; | 2054 | avg_load = 0; |
2110 | 2055 | ||
2111 | for_each_cpu_mask(i, group->cpumask) { | 2056 | for_each_cpu_mask_nr(i, group->cpumask) { |
2112 | /* Bias balancing toward cpus of our domain */ | 2057 | /* Bias balancing toward cpus of our domain */ |
2113 | if (local_group) | 2058 | if (local_group) |
2114 | load = source_load(i, load_idx); | 2059 | load = source_load(i, load_idx); |
@@ -2150,7 +2095,7 @@ find_idlest_cpu(struct sched_group *group, struct task_struct *p, int this_cpu, | |||
2150 | /* Traverse only the allowed CPUs */ | 2095 | /* Traverse only the allowed CPUs */ |
2151 | cpus_and(*tmp, group->cpumask, p->cpus_allowed); | 2096 | cpus_and(*tmp, group->cpumask, p->cpus_allowed); |
2152 | 2097 | ||
2153 | for_each_cpu_mask(i, *tmp) { | 2098 | for_each_cpu_mask_nr(i, *tmp) { |
2154 | load = weighted_cpuload(i); | 2099 | load = weighted_cpuload(i); |
2155 | 2100 | ||
2156 | if (load < min_load || (load == min_load && i == this_cpu)) { | 2101 | if (load < min_load || (load == min_load && i == this_cpu)) { |
@@ -2813,10 +2758,10 @@ static void double_rq_lock(struct rq *rq1, struct rq *rq2) | |||
2813 | } else { | 2758 | } else { |
2814 | if (rq1 < rq2) { | 2759 | if (rq1 < rq2) { |
2815 | spin_lock(&rq1->lock); | 2760 | spin_lock(&rq1->lock); |
2816 | spin_lock(&rq2->lock); | 2761 | spin_lock_nested(&rq2->lock, SINGLE_DEPTH_NESTING); |
2817 | } else { | 2762 | } else { |
2818 | spin_lock(&rq2->lock); | 2763 | spin_lock(&rq2->lock); |
2819 | spin_lock(&rq1->lock); | 2764 | spin_lock_nested(&rq1->lock, SINGLE_DEPTH_NESTING); |
2820 | } | 2765 | } |
2821 | } | 2766 | } |
2822 | update_rq_clock(rq1); | 2767 | update_rq_clock(rq1); |
@@ -2859,14 +2804,21 @@ static int double_lock_balance(struct rq *this_rq, struct rq *busiest) | |||
2859 | if (busiest < this_rq) { | 2804 | if (busiest < this_rq) { |
2860 | spin_unlock(&this_rq->lock); | 2805 | spin_unlock(&this_rq->lock); |
2861 | spin_lock(&busiest->lock); | 2806 | spin_lock(&busiest->lock); |
2862 | spin_lock(&this_rq->lock); | 2807 | spin_lock_nested(&this_rq->lock, SINGLE_DEPTH_NESTING); |
2863 | ret = 1; | 2808 | ret = 1; |
2864 | } else | 2809 | } else |
2865 | spin_lock(&busiest->lock); | 2810 | spin_lock_nested(&busiest->lock, SINGLE_DEPTH_NESTING); |
2866 | } | 2811 | } |
2867 | return ret; | 2812 | return ret; |
2868 | } | 2813 | } |
2869 | 2814 | ||
2815 | static void double_unlock_balance(struct rq *this_rq, struct rq *busiest) | ||
2816 | __releases(busiest->lock) | ||
2817 | { | ||
2818 | spin_unlock(&busiest->lock); | ||
2819 | lock_set_subclass(&this_rq->lock.dep_map, 0, _RET_IP_); | ||
2820 | } | ||
2821 | |||
2870 | /* | 2822 | /* |
2871 | * If dest_cpu is allowed for this process, migrate the task to it. | 2823 | * If dest_cpu is allowed for this process, migrate the task to it. |
2872 | * This is accomplished by forcing the cpu_allowed mask to only | 2824 | * This is accomplished by forcing the cpu_allowed mask to only |
@@ -2881,7 +2833,7 @@ static void sched_migrate_task(struct task_struct *p, int dest_cpu) | |||
2881 | 2833 | ||
2882 | rq = task_rq_lock(p, &flags); | 2834 | rq = task_rq_lock(p, &flags); |
2883 | if (!cpu_isset(dest_cpu, p->cpus_allowed) | 2835 | if (!cpu_isset(dest_cpu, p->cpus_allowed) |
2884 | || unlikely(cpu_is_offline(dest_cpu))) | 2836 | || unlikely(!cpu_active(dest_cpu))) |
2885 | goto out; | 2837 | goto out; |
2886 | 2838 | ||
2887 | /* force the process onto the specified CPU */ | 2839 | /* force the process onto the specified CPU */ |
@@ -3168,7 +3120,7 @@ find_busiest_group(struct sched_domain *sd, int this_cpu, | |||
3168 | max_cpu_load = 0; | 3120 | max_cpu_load = 0; |
3169 | min_cpu_load = ~0UL; | 3121 | min_cpu_load = ~0UL; |
3170 | 3122 | ||
3171 | for_each_cpu_mask(i, group->cpumask) { | 3123 | for_each_cpu_mask_nr(i, group->cpumask) { |
3172 | struct rq *rq; | 3124 | struct rq *rq; |
3173 | 3125 | ||
3174 | if (!cpu_isset(i, *cpus)) | 3126 | if (!cpu_isset(i, *cpus)) |
@@ -3447,7 +3399,7 @@ find_busiest_queue(struct sched_group *group, enum cpu_idle_type idle, | |||
3447 | unsigned long max_load = 0; | 3399 | unsigned long max_load = 0; |
3448 | int i; | 3400 | int i; |
3449 | 3401 | ||
3450 | for_each_cpu_mask(i, group->cpumask) { | 3402 | for_each_cpu_mask_nr(i, group->cpumask) { |
3451 | unsigned long wl; | 3403 | unsigned long wl; |
3452 | 3404 | ||
3453 | if (!cpu_isset(i, *cpus)) | 3405 | if (!cpu_isset(i, *cpus)) |
@@ -3691,7 +3643,7 @@ redo: | |||
3691 | ld_moved = move_tasks(this_rq, this_cpu, busiest, | 3643 | ld_moved = move_tasks(this_rq, this_cpu, busiest, |
3692 | imbalance, sd, CPU_NEWLY_IDLE, | 3644 | imbalance, sd, CPU_NEWLY_IDLE, |
3693 | &all_pinned); | 3645 | &all_pinned); |
3694 | spin_unlock(&busiest->lock); | 3646 | double_unlock_balance(this_rq, busiest); |
3695 | 3647 | ||
3696 | if (unlikely(all_pinned)) { | 3648 | if (unlikely(all_pinned)) { |
3697 | cpu_clear(cpu_of(busiest), *cpus); | 3649 | cpu_clear(cpu_of(busiest), *cpus); |
@@ -3806,7 +3758,7 @@ static void active_load_balance(struct rq *busiest_rq, int busiest_cpu) | |||
3806 | else | 3758 | else |
3807 | schedstat_inc(sd, alb_failed); | 3759 | schedstat_inc(sd, alb_failed); |
3808 | } | 3760 | } |
3809 | spin_unlock(&target_rq->lock); | 3761 | double_unlock_balance(busiest_rq, target_rq); |
3810 | } | 3762 | } |
3811 | 3763 | ||
3812 | #ifdef CONFIG_NO_HZ | 3764 | #ifdef CONFIG_NO_HZ |
@@ -3849,7 +3801,7 @@ int select_nohz_load_balancer(int stop_tick) | |||
3849 | /* | 3801 | /* |
3850 | * If we are going offline and still the leader, give up! | 3802 | * If we are going offline and still the leader, give up! |
3851 | */ | 3803 | */ |
3852 | if (cpu_is_offline(cpu) && | 3804 | if (!cpu_active(cpu) && |
3853 | atomic_read(&nohz.load_balancer) == cpu) { | 3805 | atomic_read(&nohz.load_balancer) == cpu) { |
3854 | if (atomic_cmpxchg(&nohz.load_balancer, cpu, -1) != cpu) | 3806 | if (atomic_cmpxchg(&nohz.load_balancer, cpu, -1) != cpu) |
3855 | BUG(); | 3807 | BUG(); |
@@ -3989,7 +3941,7 @@ static void run_rebalance_domains(struct softirq_action *h) | |||
3989 | int balance_cpu; | 3941 | int balance_cpu; |
3990 | 3942 | ||
3991 | cpu_clear(this_cpu, cpus); | 3943 | cpu_clear(this_cpu, cpus); |
3992 | for_each_cpu_mask(balance_cpu, cpus) { | 3944 | for_each_cpu_mask_nr(balance_cpu, cpus) { |
3993 | /* | 3945 | /* |
3994 | * If this cpu gets work to do, stop the load balancing | 3946 | * If this cpu gets work to do, stop the load balancing |
3995 | * work being done for other cpus. Next load | 3947 | * work being done for other cpus. Next load |
@@ -4125,6 +4077,8 @@ void account_user_time(struct task_struct *p, cputime_t cputime) | |||
4125 | cpustat->nice = cputime64_add(cpustat->nice, tmp); | 4077 | cpustat->nice = cputime64_add(cpustat->nice, tmp); |
4126 | else | 4078 | else |
4127 | cpustat->user = cputime64_add(cpustat->user, tmp); | 4079 | cpustat->user = cputime64_add(cpustat->user, tmp); |
4080 | /* Account for user time used */ | ||
4081 | acct_update_integrals(p); | ||
4128 | } | 4082 | } |
4129 | 4083 | ||
4130 | /* | 4084 | /* |
@@ -4395,7 +4349,7 @@ asmlinkage void __sched schedule(void) | |||
4395 | struct task_struct *prev, *next; | 4349 | struct task_struct *prev, *next; |
4396 | unsigned long *switch_count; | 4350 | unsigned long *switch_count; |
4397 | struct rq *rq; | 4351 | struct rq *rq; |
4398 | int cpu, hrtick = sched_feat(HRTICK); | 4352 | int cpu; |
4399 | 4353 | ||
4400 | need_resched: | 4354 | need_resched: |
4401 | preempt_disable(); | 4355 | preempt_disable(); |
@@ -4410,7 +4364,7 @@ need_resched_nonpreemptible: | |||
4410 | 4364 | ||
4411 | schedule_debug(prev); | 4365 | schedule_debug(prev); |
4412 | 4366 | ||
4413 | if (hrtick) | 4367 | if (sched_feat(HRTICK)) |
4414 | hrtick_clear(rq); | 4368 | hrtick_clear(rq); |
4415 | 4369 | ||
4416 | /* | 4370 | /* |
@@ -4457,9 +4411,6 @@ need_resched_nonpreemptible: | |||
4457 | } else | 4411 | } else |
4458 | spin_unlock_irq(&rq->lock); | 4412 | spin_unlock_irq(&rq->lock); |
4459 | 4413 | ||
4460 | if (hrtick) | ||
4461 | hrtick_set(rq); | ||
4462 | |||
4463 | if (unlikely(reacquire_kernel_lock(current) < 0)) | 4414 | if (unlikely(reacquire_kernel_lock(current) < 0)) |
4464 | goto need_resched_nonpreemptible; | 4415 | goto need_resched_nonpreemptible; |
4465 | 4416 | ||
@@ -5059,19 +5010,21 @@ recheck: | |||
5059 | return -EPERM; | 5010 | return -EPERM; |
5060 | } | 5011 | } |
5061 | 5012 | ||
5013 | if (user) { | ||
5062 | #ifdef CONFIG_RT_GROUP_SCHED | 5014 | #ifdef CONFIG_RT_GROUP_SCHED |
5063 | /* | 5015 | /* |
5064 | * Do not allow realtime tasks into groups that have no runtime | 5016 | * Do not allow realtime tasks into groups that have no runtime |
5065 | * assigned. | 5017 | * assigned. |
5066 | */ | 5018 | */ |
5067 | if (user | 5019 | if (rt_policy(policy) && task_group(p)->rt_bandwidth.rt_runtime == 0) |
5068 | && rt_policy(policy) && task_group(p)->rt_bandwidth.rt_runtime == 0) | 5020 | return -EPERM; |
5069 | return -EPERM; | ||
5070 | #endif | 5021 | #endif |
5071 | 5022 | ||
5072 | retval = security_task_setscheduler(p, policy, param); | 5023 | retval = security_task_setscheduler(p, policy, param); |
5073 | if (retval) | 5024 | if (retval) |
5074 | return retval; | 5025 | return retval; |
5026 | } | ||
5027 | |||
5075 | /* | 5028 | /* |
5076 | * make sure no PI-waiters arrive (or leave) while we are | 5029 | * make sure no PI-waiters arrive (or leave) while we are |
5077 | * changing the priority of the task: | 5030 | * changing the priority of the task: |
@@ -5876,7 +5829,7 @@ static int __migrate_task(struct task_struct *p, int src_cpu, int dest_cpu) | |||
5876 | struct rq *rq_dest, *rq_src; | 5829 | struct rq *rq_dest, *rq_src; |
5877 | int ret = 0, on_rq; | 5830 | int ret = 0, on_rq; |
5878 | 5831 | ||
5879 | if (unlikely(cpu_is_offline(dest_cpu))) | 5832 | if (unlikely(!cpu_active(dest_cpu))) |
5880 | return ret; | 5833 | return ret; |
5881 | 5834 | ||
5882 | rq_src = cpu_rq(src_cpu); | 5835 | rq_src = cpu_rq(src_cpu); |
@@ -6469,7 +6422,7 @@ static struct notifier_block __cpuinitdata migration_notifier = { | |||
6469 | .priority = 10 | 6422 | .priority = 10 |
6470 | }; | 6423 | }; |
6471 | 6424 | ||
6472 | void __init migration_init(void) | 6425 | static int __init migration_init(void) |
6473 | { | 6426 | { |
6474 | void *cpu = (void *)(long)smp_processor_id(); | 6427 | void *cpu = (void *)(long)smp_processor_id(); |
6475 | int err; | 6428 | int err; |
@@ -6479,7 +6432,10 @@ void __init migration_init(void) | |||
6479 | BUG_ON(err == NOTIFY_BAD); | 6432 | BUG_ON(err == NOTIFY_BAD); |
6480 | migration_call(&migration_notifier, CPU_ONLINE, cpu); | 6433 | migration_call(&migration_notifier, CPU_ONLINE, cpu); |
6481 | register_cpu_notifier(&migration_notifier); | 6434 | register_cpu_notifier(&migration_notifier); |
6435 | |||
6436 | return err; | ||
6482 | } | 6437 | } |
6438 | early_initcall(migration_init); | ||
6483 | #endif | 6439 | #endif |
6484 | 6440 | ||
6485 | #ifdef CONFIG_SMP | 6441 | #ifdef CONFIG_SMP |
@@ -6768,7 +6724,8 @@ static cpumask_t cpu_isolated_map = CPU_MASK_NONE; | |||
6768 | /* Setup the mask of cpus configured for isolated domains */ | 6724 | /* Setup the mask of cpus configured for isolated domains */ |
6769 | static int __init isolated_cpu_setup(char *str) | 6725 | static int __init isolated_cpu_setup(char *str) |
6770 | { | 6726 | { |
6771 | int ints[NR_CPUS], i; | 6727 | static int __initdata ints[NR_CPUS]; |
6728 | int i; | ||
6772 | 6729 | ||
6773 | str = get_options(str, ARRAY_SIZE(ints), ints); | 6730 | str = get_options(str, ARRAY_SIZE(ints), ints); |
6774 | cpus_clear(cpu_isolated_map); | 6731 | cpus_clear(cpu_isolated_map); |
@@ -6802,7 +6759,7 @@ init_sched_build_groups(const cpumask_t *span, const cpumask_t *cpu_map, | |||
6802 | 6759 | ||
6803 | cpus_clear(*covered); | 6760 | cpus_clear(*covered); |
6804 | 6761 | ||
6805 | for_each_cpu_mask(i, *span) { | 6762 | for_each_cpu_mask_nr(i, *span) { |
6806 | struct sched_group *sg; | 6763 | struct sched_group *sg; |
6807 | int group = group_fn(i, cpu_map, &sg, tmpmask); | 6764 | int group = group_fn(i, cpu_map, &sg, tmpmask); |
6808 | int j; | 6765 | int j; |
@@ -6813,7 +6770,7 @@ init_sched_build_groups(const cpumask_t *span, const cpumask_t *cpu_map, | |||
6813 | cpus_clear(sg->cpumask); | 6770 | cpus_clear(sg->cpumask); |
6814 | sg->__cpu_power = 0; | 6771 | sg->__cpu_power = 0; |
6815 | 6772 | ||
6816 | for_each_cpu_mask(j, *span) { | 6773 | for_each_cpu_mask_nr(j, *span) { |
6817 | if (group_fn(j, cpu_map, NULL, tmpmask) != group) | 6774 | if (group_fn(j, cpu_map, NULL, tmpmask) != group) |
6818 | continue; | 6775 | continue; |
6819 | 6776 | ||
@@ -7013,7 +6970,7 @@ static void init_numa_sched_groups_power(struct sched_group *group_head) | |||
7013 | if (!sg) | 6970 | if (!sg) |
7014 | return; | 6971 | return; |
7015 | do { | 6972 | do { |
7016 | for_each_cpu_mask(j, sg->cpumask) { | 6973 | for_each_cpu_mask_nr(j, sg->cpumask) { |
7017 | struct sched_domain *sd; | 6974 | struct sched_domain *sd; |
7018 | 6975 | ||
7019 | sd = &per_cpu(phys_domains, j); | 6976 | sd = &per_cpu(phys_domains, j); |
@@ -7038,7 +6995,7 @@ static void free_sched_groups(const cpumask_t *cpu_map, cpumask_t *nodemask) | |||
7038 | { | 6995 | { |
7039 | int cpu, i; | 6996 | int cpu, i; |
7040 | 6997 | ||
7041 | for_each_cpu_mask(cpu, *cpu_map) { | 6998 | for_each_cpu_mask_nr(cpu, *cpu_map) { |
7042 | struct sched_group **sched_group_nodes | 6999 | struct sched_group **sched_group_nodes |
7043 | = sched_group_nodes_bycpu[cpu]; | 7000 | = sched_group_nodes_bycpu[cpu]; |
7044 | 7001 | ||
@@ -7277,7 +7234,7 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7277 | /* | 7234 | /* |
7278 | * Set up domains for cpus specified by the cpu_map. | 7235 | * Set up domains for cpus specified by the cpu_map. |
7279 | */ | 7236 | */ |
7280 | for_each_cpu_mask(i, *cpu_map) { | 7237 | for_each_cpu_mask_nr(i, *cpu_map) { |
7281 | struct sched_domain *sd = NULL, *p; | 7238 | struct sched_domain *sd = NULL, *p; |
7282 | SCHED_CPUMASK_VAR(nodemask, allmasks); | 7239 | SCHED_CPUMASK_VAR(nodemask, allmasks); |
7283 | 7240 | ||
@@ -7344,7 +7301,7 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7344 | 7301 | ||
7345 | #ifdef CONFIG_SCHED_SMT | 7302 | #ifdef CONFIG_SCHED_SMT |
7346 | /* Set up CPU (sibling) groups */ | 7303 | /* Set up CPU (sibling) groups */ |
7347 | for_each_cpu_mask(i, *cpu_map) { | 7304 | for_each_cpu_mask_nr(i, *cpu_map) { |
7348 | SCHED_CPUMASK_VAR(this_sibling_map, allmasks); | 7305 | SCHED_CPUMASK_VAR(this_sibling_map, allmasks); |
7349 | SCHED_CPUMASK_VAR(send_covered, allmasks); | 7306 | SCHED_CPUMASK_VAR(send_covered, allmasks); |
7350 | 7307 | ||
@@ -7361,7 +7318,7 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7361 | 7318 | ||
7362 | #ifdef CONFIG_SCHED_MC | 7319 | #ifdef CONFIG_SCHED_MC |
7363 | /* Set up multi-core groups */ | 7320 | /* Set up multi-core groups */ |
7364 | for_each_cpu_mask(i, *cpu_map) { | 7321 | for_each_cpu_mask_nr(i, *cpu_map) { |
7365 | SCHED_CPUMASK_VAR(this_core_map, allmasks); | 7322 | SCHED_CPUMASK_VAR(this_core_map, allmasks); |
7366 | SCHED_CPUMASK_VAR(send_covered, allmasks); | 7323 | SCHED_CPUMASK_VAR(send_covered, allmasks); |
7367 | 7324 | ||
@@ -7428,7 +7385,7 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7428 | goto error; | 7385 | goto error; |
7429 | } | 7386 | } |
7430 | sched_group_nodes[i] = sg; | 7387 | sched_group_nodes[i] = sg; |
7431 | for_each_cpu_mask(j, *nodemask) { | 7388 | for_each_cpu_mask_nr(j, *nodemask) { |
7432 | struct sched_domain *sd; | 7389 | struct sched_domain *sd; |
7433 | 7390 | ||
7434 | sd = &per_cpu(node_domains, j); | 7391 | sd = &per_cpu(node_domains, j); |
@@ -7474,21 +7431,21 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7474 | 7431 | ||
7475 | /* Calculate CPU power for physical packages and nodes */ | 7432 | /* Calculate CPU power for physical packages and nodes */ |
7476 | #ifdef CONFIG_SCHED_SMT | 7433 | #ifdef CONFIG_SCHED_SMT |
7477 | for_each_cpu_mask(i, *cpu_map) { | 7434 | for_each_cpu_mask_nr(i, *cpu_map) { |
7478 | struct sched_domain *sd = &per_cpu(cpu_domains, i); | 7435 | struct sched_domain *sd = &per_cpu(cpu_domains, i); |
7479 | 7436 | ||
7480 | init_sched_groups_power(i, sd); | 7437 | init_sched_groups_power(i, sd); |
7481 | } | 7438 | } |
7482 | #endif | 7439 | #endif |
7483 | #ifdef CONFIG_SCHED_MC | 7440 | #ifdef CONFIG_SCHED_MC |
7484 | for_each_cpu_mask(i, *cpu_map) { | 7441 | for_each_cpu_mask_nr(i, *cpu_map) { |
7485 | struct sched_domain *sd = &per_cpu(core_domains, i); | 7442 | struct sched_domain *sd = &per_cpu(core_domains, i); |
7486 | 7443 | ||
7487 | init_sched_groups_power(i, sd); | 7444 | init_sched_groups_power(i, sd); |
7488 | } | 7445 | } |
7489 | #endif | 7446 | #endif |
7490 | 7447 | ||
7491 | for_each_cpu_mask(i, *cpu_map) { | 7448 | for_each_cpu_mask_nr(i, *cpu_map) { |
7492 | struct sched_domain *sd = &per_cpu(phys_domains, i); | 7449 | struct sched_domain *sd = &per_cpu(phys_domains, i); |
7493 | 7450 | ||
7494 | init_sched_groups_power(i, sd); | 7451 | init_sched_groups_power(i, sd); |
@@ -7508,7 +7465,7 @@ static int __build_sched_domains(const cpumask_t *cpu_map, | |||
7508 | #endif | 7465 | #endif |
7509 | 7466 | ||
7510 | /* Attach the domains */ | 7467 | /* Attach the domains */ |
7511 | for_each_cpu_mask(i, *cpu_map) { | 7468 | for_each_cpu_mask_nr(i, *cpu_map) { |
7512 | struct sched_domain *sd; | 7469 | struct sched_domain *sd; |
7513 | #ifdef CONFIG_SCHED_SMT | 7470 | #ifdef CONFIG_SCHED_SMT |
7514 | sd = &per_cpu(cpu_domains, i); | 7471 | sd = &per_cpu(cpu_domains, i); |
@@ -7553,18 +7510,6 @@ void __attribute__((weak)) arch_update_cpu_topology(void) | |||
7553 | } | 7510 | } |
7554 | 7511 | ||
7555 | /* | 7512 | /* |
7556 | * Free current domain masks. | ||
7557 | * Called after all cpus are attached to NULL domain. | ||
7558 | */ | ||
7559 | static void free_sched_domains(void) | ||
7560 | { | ||
7561 | ndoms_cur = 0; | ||
7562 | if (doms_cur != &fallback_doms) | ||
7563 | kfree(doms_cur); | ||
7564 | doms_cur = &fallback_doms; | ||
7565 | } | ||
7566 | |||
7567 | /* | ||
7568 | * Set up scheduler domains and groups. Callers must hold the hotplug lock. | 7513 | * Set up scheduler domains and groups. Callers must hold the hotplug lock. |
7569 | * For now this just excludes isolated cpus, but could be used to | 7514 | * For now this just excludes isolated cpus, but could be used to |
7570 | * exclude other special cases in the future. | 7515 | * exclude other special cases in the future. |
@@ -7603,7 +7548,7 @@ static void detach_destroy_domains(const cpumask_t *cpu_map) | |||
7603 | 7548 | ||
7604 | unregister_sched_domain_sysctl(); | 7549 | unregister_sched_domain_sysctl(); |
7605 | 7550 | ||
7606 | for_each_cpu_mask(i, *cpu_map) | 7551 | for_each_cpu_mask_nr(i, *cpu_map) |
7607 | cpu_attach_domain(NULL, &def_root_domain, i); | 7552 | cpu_attach_domain(NULL, &def_root_domain, i); |
7608 | synchronize_sched(); | 7553 | synchronize_sched(); |
7609 | arch_destroy_sched_domains(cpu_map, &tmpmask); | 7554 | arch_destroy_sched_domains(cpu_map, &tmpmask); |
@@ -7642,7 +7587,7 @@ static int dattrs_equal(struct sched_domain_attr *cur, int idx_cur, | |||
7642 | * ownership of it and will kfree it when done with it. If the caller | 7587 | * ownership of it and will kfree it when done with it. If the caller |
7643 | * failed the kmalloc call, then it can pass in doms_new == NULL, | 7588 | * failed the kmalloc call, then it can pass in doms_new == NULL, |
7644 | * and partition_sched_domains() will fallback to the single partition | 7589 | * and partition_sched_domains() will fallback to the single partition |
7645 | * 'fallback_doms'. | 7590 | * 'fallback_doms', it also forces the domains to be rebuilt. |
7646 | * | 7591 | * |
7647 | * Call with hotplug lock held | 7592 | * Call with hotplug lock held |
7648 | */ | 7593 | */ |
@@ -7656,12 +7601,8 @@ void partition_sched_domains(int ndoms_new, cpumask_t *doms_new, | |||
7656 | /* always unregister in case we don't destroy any domains */ | 7601 | /* always unregister in case we don't destroy any domains */ |
7657 | unregister_sched_domain_sysctl(); | 7602 | unregister_sched_domain_sysctl(); |
7658 | 7603 | ||
7659 | if (doms_new == NULL) { | 7604 | if (doms_new == NULL) |
7660 | ndoms_new = 1; | 7605 | ndoms_new = 0; |
7661 | doms_new = &fallback_doms; | ||
7662 | cpus_andnot(doms_new[0], cpu_online_map, cpu_isolated_map); | ||
7663 | dattr_new = NULL; | ||
7664 | } | ||
7665 | 7606 | ||
7666 | /* Destroy deleted domains */ | 7607 | /* Destroy deleted domains */ |
7667 | for (i = 0; i < ndoms_cur; i++) { | 7608 | for (i = 0; i < ndoms_cur; i++) { |
@@ -7676,6 +7617,14 @@ match1: | |||
7676 | ; | 7617 | ; |
7677 | } | 7618 | } |
7678 | 7619 | ||
7620 | if (doms_new == NULL) { | ||
7621 | ndoms_cur = 0; | ||
7622 | ndoms_new = 1; | ||
7623 | doms_new = &fallback_doms; | ||
7624 | cpus_andnot(doms_new[0], cpu_online_map, cpu_isolated_map); | ||
7625 | dattr_new = NULL; | ||
7626 | } | ||
7627 | |||
7679 | /* Build new domains */ | 7628 | /* Build new domains */ |
7680 | for (i = 0; i < ndoms_new; i++) { | 7629 | for (i = 0; i < ndoms_new; i++) { |
7681 | for (j = 0; j < ndoms_cur; j++) { | 7630 | for (j = 0; j < ndoms_cur; j++) { |
@@ -7706,17 +7655,10 @@ match2: | |||
7706 | #if defined(CONFIG_SCHED_MC) || defined(CONFIG_SCHED_SMT) | 7655 | #if defined(CONFIG_SCHED_MC) || defined(CONFIG_SCHED_SMT) |
7707 | int arch_reinit_sched_domains(void) | 7656 | int arch_reinit_sched_domains(void) |
7708 | { | 7657 | { |
7709 | int err; | ||
7710 | |||
7711 | get_online_cpus(); | 7658 | get_online_cpus(); |
7712 | mutex_lock(&sched_domains_mutex); | 7659 | rebuild_sched_domains(); |
7713 | detach_destroy_domains(&cpu_online_map); | ||
7714 | free_sched_domains(); | ||
7715 | err = arch_init_sched_domains(&cpu_online_map); | ||
7716 | mutex_unlock(&sched_domains_mutex); | ||
7717 | put_online_cpus(); | 7660 | put_online_cpus(); |
7718 | 7661 | return 0; | |
7719 | return err; | ||
7720 | } | 7662 | } |
7721 | 7663 | ||
7722 | static ssize_t sched_power_savings_store(const char *buf, size_t count, int smt) | 7664 | static ssize_t sched_power_savings_store(const char *buf, size_t count, int smt) |
@@ -7737,34 +7679,34 @@ static ssize_t sched_power_savings_store(const char *buf, size_t count, int smt) | |||
7737 | } | 7679 | } |
7738 | 7680 | ||
7739 | #ifdef CONFIG_SCHED_MC | 7681 | #ifdef CONFIG_SCHED_MC |
7740 | static ssize_t sched_mc_power_savings_show(struct sys_device *dev, | 7682 | static ssize_t sched_mc_power_savings_show(struct sysdev_class *class, |
7741 | struct sysdev_attribute *attr, char *page) | 7683 | char *page) |
7742 | { | 7684 | { |
7743 | return sprintf(page, "%u\n", sched_mc_power_savings); | 7685 | return sprintf(page, "%u\n", sched_mc_power_savings); |
7744 | } | 7686 | } |
7745 | static ssize_t sched_mc_power_savings_store(struct sys_device *dev, | 7687 | static ssize_t sched_mc_power_savings_store(struct sysdev_class *class, |
7746 | struct sysdev_attribute *attr, | ||
7747 | const char *buf, size_t count) | 7688 | const char *buf, size_t count) |
7748 | { | 7689 | { |
7749 | return sched_power_savings_store(buf, count, 0); | 7690 | return sched_power_savings_store(buf, count, 0); |
7750 | } | 7691 | } |
7751 | static SYSDEV_ATTR(sched_mc_power_savings, 0644, sched_mc_power_savings_show, | 7692 | static SYSDEV_CLASS_ATTR(sched_mc_power_savings, 0644, |
7752 | sched_mc_power_savings_store); | 7693 | sched_mc_power_savings_show, |
7694 | sched_mc_power_savings_store); | ||
7753 | #endif | 7695 | #endif |
7754 | 7696 | ||
7755 | #ifdef CONFIG_SCHED_SMT | 7697 | #ifdef CONFIG_SCHED_SMT |
7756 | static ssize_t sched_smt_power_savings_show(struct sys_device *dev, | 7698 | static ssize_t sched_smt_power_savings_show(struct sysdev_class *dev, |
7757 | struct sysdev_attribute *attr, char *page) | 7699 | char *page) |
7758 | { | 7700 | { |
7759 | return sprintf(page, "%u\n", sched_smt_power_savings); | 7701 | return sprintf(page, "%u\n", sched_smt_power_savings); |
7760 | } | 7702 | } |
7761 | static ssize_t sched_smt_power_savings_store(struct sys_device *dev, | 7703 | static ssize_t sched_smt_power_savings_store(struct sysdev_class *dev, |
7762 | struct sysdev_attribute *attr, | ||
7763 | const char *buf, size_t count) | 7704 | const char *buf, size_t count) |
7764 | { | 7705 | { |
7765 | return sched_power_savings_store(buf, count, 1); | 7706 | return sched_power_savings_store(buf, count, 1); |
7766 | } | 7707 | } |
7767 | static SYSDEV_ATTR(sched_smt_power_savings, 0644, sched_smt_power_savings_show, | 7708 | static SYSDEV_CLASS_ATTR(sched_smt_power_savings, 0644, |
7709 | sched_smt_power_savings_show, | ||
7768 | sched_smt_power_savings_store); | 7710 | sched_smt_power_savings_store); |
7769 | #endif | 7711 | #endif |
7770 | 7712 | ||
@@ -7786,59 +7728,49 @@ int sched_create_sysfs_power_savings_entries(struct sysdev_class *cls) | |||
7786 | } | 7728 | } |
7787 | #endif /* CONFIG_SCHED_MC || CONFIG_SCHED_SMT */ | 7729 | #endif /* CONFIG_SCHED_MC || CONFIG_SCHED_SMT */ |
7788 | 7730 | ||
7731 | #ifndef CONFIG_CPUSETS | ||
7789 | /* | 7732 | /* |
7790 | * Force a reinitialization of the sched domains hierarchy. The domains | 7733 | * Add online and remove offline CPUs from the scheduler domains. |
7791 | * and groups cannot be updated in place without racing with the balancing | 7734 | * When cpusets are enabled they take over this function. |
7792 | * code, so we temporarily attach all running cpus to the NULL domain | ||
7793 | * which will prevent rebalancing while the sched domains are recalculated. | ||
7794 | */ | 7735 | */ |
7795 | static int update_sched_domains(struct notifier_block *nfb, | 7736 | static int update_sched_domains(struct notifier_block *nfb, |
7796 | unsigned long action, void *hcpu) | 7737 | unsigned long action, void *hcpu) |
7797 | { | 7738 | { |
7739 | switch (action) { | ||
7740 | case CPU_ONLINE: | ||
7741 | case CPU_ONLINE_FROZEN: | ||
7742 | case CPU_DEAD: | ||
7743 | case CPU_DEAD_FROZEN: | ||
7744 | partition_sched_domains(0, NULL, NULL); | ||
7745 | return NOTIFY_OK; | ||
7746 | |||
7747 | default: | ||
7748 | return NOTIFY_DONE; | ||
7749 | } | ||
7750 | } | ||
7751 | #endif | ||
7752 | |||
7753 | static int update_runtime(struct notifier_block *nfb, | ||
7754 | unsigned long action, void *hcpu) | ||
7755 | { | ||
7798 | int cpu = (int)(long)hcpu; | 7756 | int cpu = (int)(long)hcpu; |
7799 | 7757 | ||
7800 | switch (action) { | 7758 | switch (action) { |
7801 | case CPU_DOWN_PREPARE: | 7759 | case CPU_DOWN_PREPARE: |
7802 | case CPU_DOWN_PREPARE_FROZEN: | 7760 | case CPU_DOWN_PREPARE_FROZEN: |
7803 | disable_runtime(cpu_rq(cpu)); | 7761 | disable_runtime(cpu_rq(cpu)); |
7804 | /* fall-through */ | ||
7805 | case CPU_UP_PREPARE: | ||
7806 | case CPU_UP_PREPARE_FROZEN: | ||
7807 | detach_destroy_domains(&cpu_online_map); | ||
7808 | free_sched_domains(); | ||
7809 | return NOTIFY_OK; | 7762 | return NOTIFY_OK; |
7810 | 7763 | ||
7811 | |||
7812 | case CPU_DOWN_FAILED: | 7764 | case CPU_DOWN_FAILED: |
7813 | case CPU_DOWN_FAILED_FROZEN: | 7765 | case CPU_DOWN_FAILED_FROZEN: |
7814 | case CPU_ONLINE: | 7766 | case CPU_ONLINE: |
7815 | case CPU_ONLINE_FROZEN: | 7767 | case CPU_ONLINE_FROZEN: |
7816 | enable_runtime(cpu_rq(cpu)); | 7768 | enable_runtime(cpu_rq(cpu)); |
7817 | /* fall-through */ | 7769 | return NOTIFY_OK; |
7818 | case CPU_UP_CANCELED: | 7770 | |
7819 | case CPU_UP_CANCELED_FROZEN: | ||
7820 | case CPU_DEAD: | ||
7821 | case CPU_DEAD_FROZEN: | ||
7822 | /* | ||
7823 | * Fall through and re-initialise the domains. | ||
7824 | */ | ||
7825 | break; | ||
7826 | default: | 7771 | default: |
7827 | return NOTIFY_DONE; | 7772 | return NOTIFY_DONE; |
7828 | } | 7773 | } |
7829 | |||
7830 | #ifndef CONFIG_CPUSETS | ||
7831 | /* | ||
7832 | * Create default domain partitioning if cpusets are disabled. | ||
7833 | * Otherwise we let cpusets rebuild the domains based on the | ||
7834 | * current setup. | ||
7835 | */ | ||
7836 | |||
7837 | /* The hotplug lock is already held by cpu_up/cpu_down */ | ||
7838 | arch_init_sched_domains(&cpu_online_map); | ||
7839 | #endif | ||
7840 | |||
7841 | return NOTIFY_OK; | ||
7842 | } | 7774 | } |
7843 | 7775 | ||
7844 | void __init sched_init_smp(void) | 7776 | void __init sched_init_smp(void) |
@@ -7858,8 +7790,15 @@ void __init sched_init_smp(void) | |||
7858 | cpu_set(smp_processor_id(), non_isolated_cpus); | 7790 | cpu_set(smp_processor_id(), non_isolated_cpus); |
7859 | mutex_unlock(&sched_domains_mutex); | 7791 | mutex_unlock(&sched_domains_mutex); |
7860 | put_online_cpus(); | 7792 | put_online_cpus(); |
7793 | |||
7794 | #ifndef CONFIG_CPUSETS | ||
7861 | /* XXX: Theoretical race here - CPU may be hotplugged now */ | 7795 | /* XXX: Theoretical race here - CPU may be hotplugged now */ |
7862 | hotcpu_notifier(update_sched_domains, 0); | 7796 | hotcpu_notifier(update_sched_domains, 0); |
7797 | #endif | ||
7798 | |||
7799 | /* RT runtime code needs to handle some hotplug events */ | ||
7800 | hotcpu_notifier(update_runtime, 0); | ||
7801 | |||
7863 | init_hrtick(); | 7802 | init_hrtick(); |
7864 | 7803 | ||
7865 | /* Move init over to a non-isolated CPU */ | 7804 | /* Move init over to a non-isolated CPU */ |
@@ -8067,7 +8006,6 @@ void __init sched_init(void) | |||
8067 | 8006 | ||
8068 | rq = cpu_rq(i); | 8007 | rq = cpu_rq(i); |
8069 | spin_lock_init(&rq->lock); | 8008 | spin_lock_init(&rq->lock); |
8070 | lockdep_set_class(&rq->lock, &rq->rq_lock_key); | ||
8071 | rq->nr_running = 0; | 8009 | rq->nr_running = 0; |
8072 | init_cfs_rq(&rq->cfs, rq); | 8010 | init_cfs_rq(&rq->cfs, rq); |
8073 | init_rt_rq(&rq->rt, rq); | 8011 | init_rt_rq(&rq->rt, rq); |