diff options
Diffstat (limited to 'kernel/hrtimer.c')
-rw-r--r-- | kernel/hrtimer.c | 390 |
1 files changed, 88 insertions, 302 deletions
diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c index 47e63349d1b2..1455b7651b6b 100644 --- a/kernel/hrtimer.c +++ b/kernel/hrtimer.c | |||
@@ -32,7 +32,6 @@ | |||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #include <linux/cpu.h> | 34 | #include <linux/cpu.h> |
35 | #include <linux/irq.h> | ||
36 | #include <linux/module.h> | 35 | #include <linux/module.h> |
37 | #include <linux/percpu.h> | 36 | #include <linux/percpu.h> |
38 | #include <linux/hrtimer.h> | 37 | #include <linux/hrtimer.h> |
@@ -442,22 +441,6 @@ static inline void debug_hrtimer_activate(struct hrtimer *timer) { } | |||
442 | static inline void debug_hrtimer_deactivate(struct hrtimer *timer) { } | 441 | static inline void debug_hrtimer_deactivate(struct hrtimer *timer) { } |
443 | #endif | 442 | #endif |
444 | 443 | ||
445 | /* | ||
446 | * Check, whether the timer is on the callback pending list | ||
447 | */ | ||
448 | static inline int hrtimer_cb_pending(const struct hrtimer *timer) | ||
449 | { | ||
450 | return timer->state & HRTIMER_STATE_PENDING; | ||
451 | } | ||
452 | |||
453 | /* | ||
454 | * Remove a timer from the callback pending list | ||
455 | */ | ||
456 | static inline void hrtimer_remove_cb_pending(struct hrtimer *timer) | ||
457 | { | ||
458 | list_del_init(&timer->cb_entry); | ||
459 | } | ||
460 | |||
461 | /* High resolution timer related functions */ | 444 | /* High resolution timer related functions */ |
462 | #ifdef CONFIG_HIGH_RES_TIMERS | 445 | #ifdef CONFIG_HIGH_RES_TIMERS |
463 | 446 | ||
@@ -651,6 +634,7 @@ static inline void hrtimer_init_timer_hres(struct hrtimer *timer) | |||
651 | { | 634 | { |
652 | } | 635 | } |
653 | 636 | ||
637 | |||
654 | /* | 638 | /* |
655 | * When High resolution timers are active, try to reprogram. Note, that in case | 639 | * When High resolution timers are active, try to reprogram. Note, that in case |
656 | * the state has HRTIMER_STATE_CALLBACK set, no reprogramming and no expiry | 640 | * the state has HRTIMER_STATE_CALLBACK set, no reprogramming and no expiry |
@@ -661,31 +645,10 @@ static inline int hrtimer_enqueue_reprogram(struct hrtimer *timer, | |||
661 | struct hrtimer_clock_base *base) | 645 | struct hrtimer_clock_base *base) |
662 | { | 646 | { |
663 | if (base->cpu_base->hres_active && hrtimer_reprogram(timer, base)) { | 647 | if (base->cpu_base->hres_active && hrtimer_reprogram(timer, base)) { |
664 | 648 | spin_unlock(&base->cpu_base->lock); | |
665 | /* Timer is expired, act upon the callback mode */ | 649 | raise_softirq_irqoff(HRTIMER_SOFTIRQ); |
666 | switch(timer->cb_mode) { | 650 | spin_lock(&base->cpu_base->lock); |
667 | case HRTIMER_CB_IRQSAFE_PERCPU: | 651 | return 1; |
668 | case HRTIMER_CB_IRQSAFE_UNLOCKED: | ||
669 | /* | ||
670 | * This is solely for the sched tick emulation with | ||
671 | * dynamic tick support to ensure that we do not | ||
672 | * restart the tick right on the edge and end up with | ||
673 | * the tick timer in the softirq ! The calling site | ||
674 | * takes care of this. Also used for hrtimer sleeper ! | ||
675 | */ | ||
676 | debug_hrtimer_deactivate(timer); | ||
677 | return 1; | ||
678 | case HRTIMER_CB_SOFTIRQ: | ||
679 | /* | ||
680 | * Move everything else into the softirq pending list ! | ||
681 | */ | ||
682 | list_add_tail(&timer->cb_entry, | ||
683 | &base->cpu_base->cb_pending); | ||
684 | timer->state = HRTIMER_STATE_PENDING; | ||
685 | return 1; | ||
686 | default: | ||
687 | BUG(); | ||
688 | } | ||
689 | } | 652 | } |
690 | return 0; | 653 | return 0; |
691 | } | 654 | } |
@@ -724,11 +687,6 @@ static int hrtimer_switch_to_hres(void) | |||
724 | return 1; | 687 | return 1; |
725 | } | 688 | } |
726 | 689 | ||
727 | static inline void hrtimer_raise_softirq(void) | ||
728 | { | ||
729 | raise_softirq(HRTIMER_SOFTIRQ); | ||
730 | } | ||
731 | |||
732 | #else | 690 | #else |
733 | 691 | ||
734 | static inline int hrtimer_hres_active(void) { return 0; } | 692 | static inline int hrtimer_hres_active(void) { return 0; } |
@@ -742,12 +700,6 @@ static inline int hrtimer_enqueue_reprogram(struct hrtimer *timer, | |||
742 | } | 700 | } |
743 | static inline void hrtimer_init_hres(struct hrtimer_cpu_base *base) { } | 701 | static inline void hrtimer_init_hres(struct hrtimer_cpu_base *base) { } |
744 | static inline void hrtimer_init_timer_hres(struct hrtimer *timer) { } | 702 | static inline void hrtimer_init_timer_hres(struct hrtimer *timer) { } |
745 | static inline int hrtimer_reprogram(struct hrtimer *timer, | ||
746 | struct hrtimer_clock_base *base) | ||
747 | { | ||
748 | return 0; | ||
749 | } | ||
750 | static inline void hrtimer_raise_softirq(void) { } | ||
751 | 703 | ||
752 | #endif /* CONFIG_HIGH_RES_TIMERS */ | 704 | #endif /* CONFIG_HIGH_RES_TIMERS */ |
753 | 705 | ||
@@ -818,9 +770,11 @@ EXPORT_SYMBOL_GPL(hrtimer_forward); | |||
818 | * | 770 | * |
819 | * The timer is inserted in expiry order. Insertion into the | 771 | * The timer is inserted in expiry order. Insertion into the |
820 | * red black tree is O(log(n)). Must hold the base lock. | 772 | * red black tree is O(log(n)). Must hold the base lock. |
773 | * | ||
774 | * Returns 1 when the new timer is the leftmost timer in the tree. | ||
821 | */ | 775 | */ |
822 | static void enqueue_hrtimer(struct hrtimer *timer, | 776 | static int enqueue_hrtimer(struct hrtimer *timer, |
823 | struct hrtimer_clock_base *base, int reprogram) | 777 | struct hrtimer_clock_base *base) |
824 | { | 778 | { |
825 | struct rb_node **link = &base->active.rb_node; | 779 | struct rb_node **link = &base->active.rb_node; |
826 | struct rb_node *parent = NULL; | 780 | struct rb_node *parent = NULL; |
@@ -852,20 +806,8 @@ static void enqueue_hrtimer(struct hrtimer *timer, | |||
852 | * Insert the timer to the rbtree and check whether it | 806 | * Insert the timer to the rbtree and check whether it |
853 | * replaces the first pending timer | 807 | * replaces the first pending timer |
854 | */ | 808 | */ |
855 | if (leftmost) { | 809 | if (leftmost) |
856 | /* | ||
857 | * Reprogram the clock event device. When the timer is already | ||
858 | * expired hrtimer_enqueue_reprogram has either called the | ||
859 | * callback or added it to the pending list and raised the | ||
860 | * softirq. | ||
861 | * | ||
862 | * This is a NOP for !HIGHRES | ||
863 | */ | ||
864 | if (reprogram && hrtimer_enqueue_reprogram(timer, base)) | ||
865 | return; | ||
866 | |||
867 | base->first = &timer->node; | 810 | base->first = &timer->node; |
868 | } | ||
869 | 811 | ||
870 | rb_link_node(&timer->node, parent, link); | 812 | rb_link_node(&timer->node, parent, link); |
871 | rb_insert_color(&timer->node, &base->active); | 813 | rb_insert_color(&timer->node, &base->active); |
@@ -874,6 +816,8 @@ static void enqueue_hrtimer(struct hrtimer *timer, | |||
874 | * state of a possibly running callback. | 816 | * state of a possibly running callback. |
875 | */ | 817 | */ |
876 | timer->state |= HRTIMER_STATE_ENQUEUED; | 818 | timer->state |= HRTIMER_STATE_ENQUEUED; |
819 | |||
820 | return leftmost; | ||
877 | } | 821 | } |
878 | 822 | ||
879 | /* | 823 | /* |
@@ -890,10 +834,7 @@ static void __remove_hrtimer(struct hrtimer *timer, | |||
890 | struct hrtimer_clock_base *base, | 834 | struct hrtimer_clock_base *base, |
891 | unsigned long newstate, int reprogram) | 835 | unsigned long newstate, int reprogram) |
892 | { | 836 | { |
893 | /* High res. callback list. NOP for !HIGHRES */ | 837 | if (timer->state & HRTIMER_STATE_ENQUEUED) { |
894 | if (hrtimer_cb_pending(timer)) | ||
895 | hrtimer_remove_cb_pending(timer); | ||
896 | else { | ||
897 | /* | 838 | /* |
898 | * Remove the timer from the rbtree and replace the | 839 | * Remove the timer from the rbtree and replace the |
899 | * first entry pointer if necessary. | 840 | * first entry pointer if necessary. |
@@ -953,7 +894,7 @@ hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim, unsigned long delta_n | |||
953 | { | 894 | { |
954 | struct hrtimer_clock_base *base, *new_base; | 895 | struct hrtimer_clock_base *base, *new_base; |
955 | unsigned long flags; | 896 | unsigned long flags; |
956 | int ret, raise; | 897 | int ret, leftmost; |
957 | 898 | ||
958 | base = lock_hrtimer_base(timer, &flags); | 899 | base = lock_hrtimer_base(timer, &flags); |
959 | 900 | ||
@@ -981,33 +922,19 @@ hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim, unsigned long delta_n | |||
981 | 922 | ||
982 | timer_stats_hrtimer_set_start_info(timer); | 923 | timer_stats_hrtimer_set_start_info(timer); |
983 | 924 | ||
925 | leftmost = enqueue_hrtimer(timer, new_base); | ||
926 | |||
984 | /* | 927 | /* |
985 | * Only allow reprogramming if the new base is on this CPU. | 928 | * Only allow reprogramming if the new base is on this CPU. |
986 | * (it might still be on another CPU if the timer was pending) | 929 | * (it might still be on another CPU if the timer was pending) |
930 | * | ||
931 | * XXX send_remote_softirq() ? | ||
987 | */ | 932 | */ |
988 | enqueue_hrtimer(timer, new_base, | 933 | if (leftmost && new_base->cpu_base == &__get_cpu_var(hrtimer_bases)) |
989 | new_base->cpu_base == &__get_cpu_var(hrtimer_bases)); | 934 | hrtimer_enqueue_reprogram(timer, new_base); |
990 | |||
991 | /* | ||
992 | * The timer may be expired and moved to the cb_pending | ||
993 | * list. We can not raise the softirq with base lock held due | ||
994 | * to a possible deadlock with runqueue lock. | ||
995 | */ | ||
996 | raise = timer->state == HRTIMER_STATE_PENDING; | ||
997 | |||
998 | /* | ||
999 | * We use preempt_disable to prevent this task from migrating after | ||
1000 | * setting up the softirq and raising it. Otherwise, if me migrate | ||
1001 | * we will raise the softirq on the wrong CPU. | ||
1002 | */ | ||
1003 | preempt_disable(); | ||
1004 | 935 | ||
1005 | unlock_hrtimer_base(timer, &flags); | 936 | unlock_hrtimer_base(timer, &flags); |
1006 | 937 | ||
1007 | if (raise) | ||
1008 | hrtimer_raise_softirq(); | ||
1009 | preempt_enable(); | ||
1010 | |||
1011 | return ret; | 938 | return ret; |
1012 | } | 939 | } |
1013 | EXPORT_SYMBOL_GPL(hrtimer_start_range_ns); | 940 | EXPORT_SYMBOL_GPL(hrtimer_start_range_ns); |
@@ -1192,75 +1119,6 @@ int hrtimer_get_res(const clockid_t which_clock, struct timespec *tp) | |||
1192 | } | 1119 | } |
1193 | EXPORT_SYMBOL_GPL(hrtimer_get_res); | 1120 | EXPORT_SYMBOL_GPL(hrtimer_get_res); |
1194 | 1121 | ||
1195 | static void run_hrtimer_pending(struct hrtimer_cpu_base *cpu_base) | ||
1196 | { | ||
1197 | spin_lock_irq(&cpu_base->lock); | ||
1198 | |||
1199 | while (!list_empty(&cpu_base->cb_pending)) { | ||
1200 | enum hrtimer_restart (*fn)(struct hrtimer *); | ||
1201 | struct hrtimer *timer; | ||
1202 | int restart; | ||
1203 | int emulate_hardirq_ctx = 0; | ||
1204 | |||
1205 | timer = list_entry(cpu_base->cb_pending.next, | ||
1206 | struct hrtimer, cb_entry); | ||
1207 | |||
1208 | debug_hrtimer_deactivate(timer); | ||
1209 | timer_stats_account_hrtimer(timer); | ||
1210 | |||
1211 | fn = timer->function; | ||
1212 | /* | ||
1213 | * A timer might have been added to the cb_pending list | ||
1214 | * when it was migrated during a cpu-offline operation. | ||
1215 | * Emulate hardirq context for such timers. | ||
1216 | */ | ||
1217 | if (timer->cb_mode == HRTIMER_CB_IRQSAFE_PERCPU || | ||
1218 | timer->cb_mode == HRTIMER_CB_IRQSAFE_UNLOCKED) | ||
1219 | emulate_hardirq_ctx = 1; | ||
1220 | |||
1221 | __remove_hrtimer(timer, timer->base, HRTIMER_STATE_CALLBACK, 0); | ||
1222 | spin_unlock_irq(&cpu_base->lock); | ||
1223 | |||
1224 | if (unlikely(emulate_hardirq_ctx)) { | ||
1225 | local_irq_disable(); | ||
1226 | restart = fn(timer); | ||
1227 | local_irq_enable(); | ||
1228 | } else | ||
1229 | restart = fn(timer); | ||
1230 | |||
1231 | spin_lock_irq(&cpu_base->lock); | ||
1232 | |||
1233 | timer->state &= ~HRTIMER_STATE_CALLBACK; | ||
1234 | if (restart == HRTIMER_RESTART) { | ||
1235 | BUG_ON(hrtimer_active(timer)); | ||
1236 | /* | ||
1237 | * Enqueue the timer, allow reprogramming of the event | ||
1238 | * device | ||
1239 | */ | ||
1240 | enqueue_hrtimer(timer, timer->base, 1); | ||
1241 | } else if (hrtimer_active(timer)) { | ||
1242 | /* | ||
1243 | * If the timer was rearmed on another CPU, reprogram | ||
1244 | * the event device. | ||
1245 | */ | ||
1246 | struct hrtimer_clock_base *base = timer->base; | ||
1247 | |||
1248 | if (base->first == &timer->node && | ||
1249 | hrtimer_reprogram(timer, base)) { | ||
1250 | /* | ||
1251 | * Timer is expired. Thus move it from tree to | ||
1252 | * pending list again. | ||
1253 | */ | ||
1254 | __remove_hrtimer(timer, base, | ||
1255 | HRTIMER_STATE_PENDING, 0); | ||
1256 | list_add_tail(&timer->cb_entry, | ||
1257 | &base->cpu_base->cb_pending); | ||
1258 | } | ||
1259 | } | ||
1260 | } | ||
1261 | spin_unlock_irq(&cpu_base->lock); | ||
1262 | } | ||
1263 | |||
1264 | static void __run_hrtimer(struct hrtimer *timer) | 1122 | static void __run_hrtimer(struct hrtimer *timer) |
1265 | { | 1123 | { |
1266 | struct hrtimer_clock_base *base = timer->base; | 1124 | struct hrtimer_clock_base *base = timer->base; |
@@ -1268,34 +1126,30 @@ static void __run_hrtimer(struct hrtimer *timer) | |||
1268 | enum hrtimer_restart (*fn)(struct hrtimer *); | 1126 | enum hrtimer_restart (*fn)(struct hrtimer *); |
1269 | int restart; | 1127 | int restart; |
1270 | 1128 | ||
1129 | WARN_ON(!irqs_disabled()); | ||
1130 | |||
1271 | debug_hrtimer_deactivate(timer); | 1131 | debug_hrtimer_deactivate(timer); |
1272 | __remove_hrtimer(timer, base, HRTIMER_STATE_CALLBACK, 0); | 1132 | __remove_hrtimer(timer, base, HRTIMER_STATE_CALLBACK, 0); |
1273 | timer_stats_account_hrtimer(timer); | 1133 | timer_stats_account_hrtimer(timer); |
1274 | |||
1275 | fn = timer->function; | 1134 | fn = timer->function; |
1276 | if (timer->cb_mode == HRTIMER_CB_IRQSAFE_PERCPU || | ||
1277 | timer->cb_mode == HRTIMER_CB_IRQSAFE_UNLOCKED) { | ||
1278 | /* | ||
1279 | * Used for scheduler timers, avoid lock inversion with | ||
1280 | * rq->lock and tasklist_lock. | ||
1281 | * | ||
1282 | * These timers are required to deal with enqueue expiry | ||
1283 | * themselves and are not allowed to migrate. | ||
1284 | */ | ||
1285 | spin_unlock(&cpu_base->lock); | ||
1286 | restart = fn(timer); | ||
1287 | spin_lock(&cpu_base->lock); | ||
1288 | } else | ||
1289 | restart = fn(timer); | ||
1290 | 1135 | ||
1291 | /* | 1136 | /* |
1292 | * Note: We clear the CALLBACK bit after enqueue_hrtimer to avoid | 1137 | * Because we run timers from hardirq context, there is no chance |
1293 | * reprogramming of the event hardware. This happens at the end of this | 1138 | * they get migrated to another cpu, therefore its safe to unlock |
1294 | * function anyway. | 1139 | * the timer base. |
1140 | */ | ||
1141 | spin_unlock(&cpu_base->lock); | ||
1142 | restart = fn(timer); | ||
1143 | spin_lock(&cpu_base->lock); | ||
1144 | |||
1145 | /* | ||
1146 | * Note: We clear the CALLBACK bit after enqueue_hrtimer and | ||
1147 | * we do not reprogramm the event hardware. Happens either in | ||
1148 | * hrtimer_start_range_ns() or in hrtimer_interrupt() | ||
1295 | */ | 1149 | */ |
1296 | if (restart != HRTIMER_NORESTART) { | 1150 | if (restart != HRTIMER_NORESTART) { |
1297 | BUG_ON(timer->state != HRTIMER_STATE_CALLBACK); | 1151 | BUG_ON(timer->state != HRTIMER_STATE_CALLBACK); |
1298 | enqueue_hrtimer(timer, base, 0); | 1152 | enqueue_hrtimer(timer, base); |
1299 | } | 1153 | } |
1300 | timer->state &= ~HRTIMER_STATE_CALLBACK; | 1154 | timer->state &= ~HRTIMER_STATE_CALLBACK; |
1301 | } | 1155 | } |
@@ -1311,7 +1165,7 @@ void hrtimer_interrupt(struct clock_event_device *dev) | |||
1311 | struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases); | 1165 | struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases); |
1312 | struct hrtimer_clock_base *base; | 1166 | struct hrtimer_clock_base *base; |
1313 | ktime_t expires_next, now; | 1167 | ktime_t expires_next, now; |
1314 | int i, raise = 0; | 1168 | int i; |
1315 | 1169 | ||
1316 | BUG_ON(!cpu_base->hres_active); | 1170 | BUG_ON(!cpu_base->hres_active); |
1317 | cpu_base->nr_events++; | 1171 | cpu_base->nr_events++; |
@@ -1360,16 +1214,6 @@ void hrtimer_interrupt(struct clock_event_device *dev) | |||
1360 | break; | 1214 | break; |
1361 | } | 1215 | } |
1362 | 1216 | ||
1363 | /* Move softirq callbacks to the pending list */ | ||
1364 | if (timer->cb_mode == HRTIMER_CB_SOFTIRQ) { | ||
1365 | __remove_hrtimer(timer, base, | ||
1366 | HRTIMER_STATE_PENDING, 0); | ||
1367 | list_add_tail(&timer->cb_entry, | ||
1368 | &base->cpu_base->cb_pending); | ||
1369 | raise = 1; | ||
1370 | continue; | ||
1371 | } | ||
1372 | |||
1373 | __run_hrtimer(timer); | 1217 | __run_hrtimer(timer); |
1374 | } | 1218 | } |
1375 | spin_unlock(&cpu_base->lock); | 1219 | spin_unlock(&cpu_base->lock); |
@@ -1383,10 +1227,22 @@ void hrtimer_interrupt(struct clock_event_device *dev) | |||
1383 | if (tick_program_event(expires_next, 0)) | 1227 | if (tick_program_event(expires_next, 0)) |
1384 | goto retry; | 1228 | goto retry; |
1385 | } | 1229 | } |
1230 | } | ||
1231 | |||
1232 | /* | ||
1233 | * local version of hrtimer_peek_ahead_timers() called with interrupts | ||
1234 | * disabled. | ||
1235 | */ | ||
1236 | static void __hrtimer_peek_ahead_timers(void) | ||
1237 | { | ||
1238 | struct tick_device *td; | ||
1239 | |||
1240 | if (!hrtimer_hres_active()) | ||
1241 | return; | ||
1386 | 1242 | ||
1387 | /* Raise softirq ? */ | 1243 | td = &__get_cpu_var(tick_cpu_device); |
1388 | if (raise) | 1244 | if (td && td->evtdev) |
1389 | raise_softirq(HRTIMER_SOFTIRQ); | 1245 | hrtimer_interrupt(td->evtdev); |
1390 | } | 1246 | } |
1391 | 1247 | ||
1392 | /** | 1248 | /** |
@@ -1400,25 +1256,23 @@ void hrtimer_interrupt(struct clock_event_device *dev) | |||
1400 | */ | 1256 | */ |
1401 | void hrtimer_peek_ahead_timers(void) | 1257 | void hrtimer_peek_ahead_timers(void) |
1402 | { | 1258 | { |
1403 | struct tick_device *td; | ||
1404 | unsigned long flags; | 1259 | unsigned long flags; |
1405 | 1260 | ||
1406 | if (!hrtimer_hres_active()) | ||
1407 | return; | ||
1408 | |||
1409 | local_irq_save(flags); | 1261 | local_irq_save(flags); |
1410 | td = &__get_cpu_var(tick_cpu_device); | 1262 | __hrtimer_peek_ahead_timers(); |
1411 | if (td && td->evtdev) | ||
1412 | hrtimer_interrupt(td->evtdev); | ||
1413 | local_irq_restore(flags); | 1263 | local_irq_restore(flags); |
1414 | } | 1264 | } |
1415 | 1265 | ||
1416 | static void run_hrtimer_softirq(struct softirq_action *h) | 1266 | static void run_hrtimer_softirq(struct softirq_action *h) |
1417 | { | 1267 | { |
1418 | run_hrtimer_pending(&__get_cpu_var(hrtimer_bases)); | 1268 | hrtimer_peek_ahead_timers(); |
1419 | } | 1269 | } |
1420 | 1270 | ||
1421 | #endif /* CONFIG_HIGH_RES_TIMERS */ | 1271 | #else /* CONFIG_HIGH_RES_TIMERS */ |
1272 | |||
1273 | static inline void __hrtimer_peek_ahead_timers(void) { } | ||
1274 | |||
1275 | #endif /* !CONFIG_HIGH_RES_TIMERS */ | ||
1422 | 1276 | ||
1423 | /* | 1277 | /* |
1424 | * Called from timer softirq every jiffy, expire hrtimers: | 1278 | * Called from timer softirq every jiffy, expire hrtimers: |
@@ -1429,8 +1283,6 @@ static void run_hrtimer_softirq(struct softirq_action *h) | |||
1429 | */ | 1283 | */ |
1430 | void hrtimer_run_pending(void) | 1284 | void hrtimer_run_pending(void) |
1431 | { | 1285 | { |
1432 | struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases); | ||
1433 | |||
1434 | if (hrtimer_hres_active()) | 1286 | if (hrtimer_hres_active()) |
1435 | return; | 1287 | return; |
1436 | 1288 | ||
@@ -1444,8 +1296,6 @@ void hrtimer_run_pending(void) | |||
1444 | */ | 1296 | */ |
1445 | if (tick_check_oneshot_change(!hrtimer_is_hres_enabled())) | 1297 | if (tick_check_oneshot_change(!hrtimer_is_hres_enabled())) |
1446 | hrtimer_switch_to_hres(); | 1298 | hrtimer_switch_to_hres(); |
1447 | |||
1448 | run_hrtimer_pending(cpu_base); | ||
1449 | } | 1299 | } |
1450 | 1300 | ||
1451 | /* | 1301 | /* |
@@ -1482,14 +1332,6 @@ void hrtimer_run_queues(void) | |||
1482 | hrtimer_get_expires_tv64(timer)) | 1332 | hrtimer_get_expires_tv64(timer)) |
1483 | break; | 1333 | break; |
1484 | 1334 | ||
1485 | if (timer->cb_mode == HRTIMER_CB_SOFTIRQ) { | ||
1486 | __remove_hrtimer(timer, base, | ||
1487 | HRTIMER_STATE_PENDING, 0); | ||
1488 | list_add_tail(&timer->cb_entry, | ||
1489 | &base->cpu_base->cb_pending); | ||
1490 | continue; | ||
1491 | } | ||
1492 | |||
1493 | __run_hrtimer(timer); | 1335 | __run_hrtimer(timer); |
1494 | } | 1336 | } |
1495 | spin_unlock(&cpu_base->lock); | 1337 | spin_unlock(&cpu_base->lock); |
@@ -1516,9 +1358,6 @@ void hrtimer_init_sleeper(struct hrtimer_sleeper *sl, struct task_struct *task) | |||
1516 | { | 1358 | { |
1517 | sl->timer.function = hrtimer_wakeup; | 1359 | sl->timer.function = hrtimer_wakeup; |
1518 | sl->task = task; | 1360 | sl->task = task; |
1519 | #ifdef CONFIG_HIGH_RES_TIMERS | ||
1520 | sl->timer.cb_mode = HRTIMER_CB_IRQSAFE_UNLOCKED; | ||
1521 | #endif | ||
1522 | } | 1361 | } |
1523 | 1362 | ||
1524 | static int __sched do_nanosleep(struct hrtimer_sleeper *t, enum hrtimer_mode mode) | 1363 | static int __sched do_nanosleep(struct hrtimer_sleeper *t, enum hrtimer_mode mode) |
@@ -1655,18 +1494,16 @@ static void __cpuinit init_hrtimers_cpu(int cpu) | |||
1655 | for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) | 1494 | for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) |
1656 | cpu_base->clock_base[i].cpu_base = cpu_base; | 1495 | cpu_base->clock_base[i].cpu_base = cpu_base; |
1657 | 1496 | ||
1658 | INIT_LIST_HEAD(&cpu_base->cb_pending); | ||
1659 | hrtimer_init_hres(cpu_base); | 1497 | hrtimer_init_hres(cpu_base); |
1660 | } | 1498 | } |
1661 | 1499 | ||
1662 | #ifdef CONFIG_HOTPLUG_CPU | 1500 | #ifdef CONFIG_HOTPLUG_CPU |
1663 | 1501 | ||
1664 | static int migrate_hrtimer_list(struct hrtimer_clock_base *old_base, | 1502 | static void migrate_hrtimer_list(struct hrtimer_clock_base *old_base, |
1665 | struct hrtimer_clock_base *new_base, int dcpu) | 1503 | struct hrtimer_clock_base *new_base) |
1666 | { | 1504 | { |
1667 | struct hrtimer *timer; | 1505 | struct hrtimer *timer; |
1668 | struct rb_node *node; | 1506 | struct rb_node *node; |
1669 | int raise = 0; | ||
1670 | 1507 | ||
1671 | while ((node = rb_first(&old_base->active))) { | 1508 | while ((node = rb_first(&old_base->active))) { |
1672 | timer = rb_entry(node, struct hrtimer, node); | 1509 | timer = rb_entry(node, struct hrtimer, node); |
@@ -1674,18 +1511,6 @@ static int migrate_hrtimer_list(struct hrtimer_clock_base *old_base, | |||
1674 | debug_hrtimer_deactivate(timer); | 1511 | debug_hrtimer_deactivate(timer); |
1675 | 1512 | ||
1676 | /* | 1513 | /* |
1677 | * Should not happen. Per CPU timers should be | ||
1678 | * canceled _before_ the migration code is called | ||
1679 | */ | ||
1680 | if (timer->cb_mode == HRTIMER_CB_IRQSAFE_PERCPU) { | ||
1681 | __remove_hrtimer(timer, old_base, | ||
1682 | HRTIMER_STATE_INACTIVE, 0); | ||
1683 | WARN(1, "hrtimer (%p %p)active but cpu %d dead\n", | ||
1684 | timer, timer->function, dcpu); | ||
1685 | continue; | ||
1686 | } | ||
1687 | |||
1688 | /* | ||
1689 | * Mark it as STATE_MIGRATE not INACTIVE otherwise the | 1514 | * Mark it as STATE_MIGRATE not INACTIVE otherwise the |
1690 | * timer could be seen as !active and just vanish away | 1515 | * timer could be seen as !active and just vanish away |
1691 | * under us on another CPU | 1516 | * under us on another CPU |
@@ -1693,112 +1518,73 @@ static int migrate_hrtimer_list(struct hrtimer_clock_base *old_base, | |||
1693 | __remove_hrtimer(timer, old_base, HRTIMER_STATE_MIGRATE, 0); | 1518 | __remove_hrtimer(timer, old_base, HRTIMER_STATE_MIGRATE, 0); |
1694 | timer->base = new_base; | 1519 | timer->base = new_base; |
1695 | /* | 1520 | /* |
1696 | * Enqueue the timer. Allow reprogramming of the event device | 1521 | * Enqueue the timers on the new cpu. This does not |
1522 | * reprogram the event device in case the timer | ||
1523 | * expires before the earliest on this CPU, but we run | ||
1524 | * hrtimer_interrupt after we migrated everything to | ||
1525 | * sort out already expired timers and reprogram the | ||
1526 | * event device. | ||
1697 | */ | 1527 | */ |
1698 | enqueue_hrtimer(timer, new_base, 1); | 1528 | enqueue_hrtimer(timer, new_base); |
1699 | 1529 | ||
1700 | #ifdef CONFIG_HIGH_RES_TIMERS | ||
1701 | /* | ||
1702 | * Happens with high res enabled when the timer was | ||
1703 | * already expired and the callback mode is | ||
1704 | * HRTIMER_CB_IRQSAFE_UNLOCKED (hrtimer_sleeper). The | ||
1705 | * enqueue code does not move them to the soft irq | ||
1706 | * pending list for performance/latency reasons, but | ||
1707 | * in the migration state, we need to do that | ||
1708 | * otherwise we end up with a stale timer. | ||
1709 | */ | ||
1710 | if (timer->state == HRTIMER_STATE_MIGRATE) { | ||
1711 | timer->state = HRTIMER_STATE_PENDING; | ||
1712 | list_add_tail(&timer->cb_entry, | ||
1713 | &new_base->cpu_base->cb_pending); | ||
1714 | raise = 1; | ||
1715 | } | ||
1716 | #endif | ||
1717 | /* Clear the migration state bit */ | 1530 | /* Clear the migration state bit */ |
1718 | timer->state &= ~HRTIMER_STATE_MIGRATE; | 1531 | timer->state &= ~HRTIMER_STATE_MIGRATE; |
1719 | } | 1532 | } |
1720 | return raise; | ||
1721 | } | ||
1722 | |||
1723 | #ifdef CONFIG_HIGH_RES_TIMERS | ||
1724 | static int migrate_hrtimer_pending(struct hrtimer_cpu_base *old_base, | ||
1725 | struct hrtimer_cpu_base *new_base) | ||
1726 | { | ||
1727 | struct hrtimer *timer; | ||
1728 | int raise = 0; | ||
1729 | |||
1730 | while (!list_empty(&old_base->cb_pending)) { | ||
1731 | timer = list_entry(old_base->cb_pending.next, | ||
1732 | struct hrtimer, cb_entry); | ||
1733 | |||
1734 | __remove_hrtimer(timer, timer->base, HRTIMER_STATE_PENDING, 0); | ||
1735 | timer->base = &new_base->clock_base[timer->base->index]; | ||
1736 | list_add_tail(&timer->cb_entry, &new_base->cb_pending); | ||
1737 | raise = 1; | ||
1738 | } | ||
1739 | return raise; | ||
1740 | } | ||
1741 | #else | ||
1742 | static int migrate_hrtimer_pending(struct hrtimer_cpu_base *old_base, | ||
1743 | struct hrtimer_cpu_base *new_base) | ||
1744 | { | ||
1745 | return 0; | ||
1746 | } | 1533 | } |
1747 | #endif | ||
1748 | 1534 | ||
1749 | static void migrate_hrtimers(int cpu) | 1535 | static void migrate_hrtimers(int scpu) |
1750 | { | 1536 | { |
1751 | struct hrtimer_cpu_base *old_base, *new_base; | 1537 | struct hrtimer_cpu_base *old_base, *new_base; |
1752 | int i, raise = 0; | 1538 | int i; |
1753 | 1539 | ||
1754 | BUG_ON(cpu_online(cpu)); | 1540 | BUG_ON(cpu_online(scpu)); |
1755 | old_base = &per_cpu(hrtimer_bases, cpu); | 1541 | tick_cancel_sched_timer(scpu); |
1756 | new_base = &get_cpu_var(hrtimer_bases); | ||
1757 | 1542 | ||
1758 | tick_cancel_sched_timer(cpu); | 1543 | local_irq_disable(); |
1544 | old_base = &per_cpu(hrtimer_bases, scpu); | ||
1545 | new_base = &__get_cpu_var(hrtimer_bases); | ||
1759 | /* | 1546 | /* |
1760 | * The caller is globally serialized and nobody else | 1547 | * The caller is globally serialized and nobody else |
1761 | * takes two locks at once, deadlock is not possible. | 1548 | * takes two locks at once, deadlock is not possible. |
1762 | */ | 1549 | */ |
1763 | spin_lock_irq(&new_base->lock); | 1550 | spin_lock(&new_base->lock); |
1764 | spin_lock_nested(&old_base->lock, SINGLE_DEPTH_NESTING); | 1551 | spin_lock_nested(&old_base->lock, SINGLE_DEPTH_NESTING); |
1765 | 1552 | ||
1766 | for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) { | 1553 | for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) { |
1767 | if (migrate_hrtimer_list(&old_base->clock_base[i], | 1554 | migrate_hrtimer_list(&old_base->clock_base[i], |
1768 | &new_base->clock_base[i], cpu)) | 1555 | &new_base->clock_base[i]); |
1769 | raise = 1; | ||
1770 | } | 1556 | } |
1771 | 1557 | ||
1772 | if (migrate_hrtimer_pending(old_base, new_base)) | ||
1773 | raise = 1; | ||
1774 | |||
1775 | spin_unlock(&old_base->lock); | 1558 | spin_unlock(&old_base->lock); |
1776 | spin_unlock_irq(&new_base->lock); | 1559 | spin_unlock(&new_base->lock); |
1777 | put_cpu_var(hrtimer_bases); | ||
1778 | 1560 | ||
1779 | if (raise) | 1561 | /* Check, if we got expired work to do */ |
1780 | hrtimer_raise_softirq(); | 1562 | __hrtimer_peek_ahead_timers(); |
1563 | local_irq_enable(); | ||
1781 | } | 1564 | } |
1565 | |||
1782 | #endif /* CONFIG_HOTPLUG_CPU */ | 1566 | #endif /* CONFIG_HOTPLUG_CPU */ |
1783 | 1567 | ||
1784 | static int __cpuinit hrtimer_cpu_notify(struct notifier_block *self, | 1568 | static int __cpuinit hrtimer_cpu_notify(struct notifier_block *self, |
1785 | unsigned long action, void *hcpu) | 1569 | unsigned long action, void *hcpu) |
1786 | { | 1570 | { |
1787 | unsigned int cpu = (long)hcpu; | 1571 | int scpu = (long)hcpu; |
1788 | 1572 | ||
1789 | switch (action) { | 1573 | switch (action) { |
1790 | 1574 | ||
1791 | case CPU_UP_PREPARE: | 1575 | case CPU_UP_PREPARE: |
1792 | case CPU_UP_PREPARE_FROZEN: | 1576 | case CPU_UP_PREPARE_FROZEN: |
1793 | init_hrtimers_cpu(cpu); | 1577 | init_hrtimers_cpu(scpu); |
1794 | break; | 1578 | break; |
1795 | 1579 | ||
1796 | #ifdef CONFIG_HOTPLUG_CPU | 1580 | #ifdef CONFIG_HOTPLUG_CPU |
1797 | case CPU_DEAD: | 1581 | case CPU_DEAD: |
1798 | case CPU_DEAD_FROZEN: | 1582 | case CPU_DEAD_FROZEN: |
1799 | clockevents_notify(CLOCK_EVT_NOTIFY_CPU_DEAD, &cpu); | 1583 | { |
1800 | migrate_hrtimers(cpu); | 1584 | clockevents_notify(CLOCK_EVT_NOTIFY_CPU_DEAD, &scpu); |
1585 | migrate_hrtimers(scpu); | ||
1801 | break; | 1586 | break; |
1587 | } | ||
1802 | #endif | 1588 | #endif |
1803 | 1589 | ||
1804 | default: | 1590 | default: |