diff options
Diffstat (limited to 'kernel/hrtimer.c')
| -rw-r--r-- | kernel/hrtimer.c | 247 |
1 files changed, 208 insertions, 39 deletions
diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c index cdec83e722fa..47e63349d1b2 100644 --- a/kernel/hrtimer.c +++ b/kernel/hrtimer.c | |||
| @@ -517,7 +517,7 @@ static void hrtimer_force_reprogram(struct hrtimer_cpu_base *cpu_base) | |||
| 517 | if (!base->first) | 517 | if (!base->first) |
| 518 | continue; | 518 | continue; |
| 519 | timer = rb_entry(base->first, struct hrtimer, node); | 519 | timer = rb_entry(base->first, struct hrtimer, node); |
| 520 | expires = ktime_sub(timer->expires, base->offset); | 520 | expires = ktime_sub(hrtimer_get_expires(timer), base->offset); |
| 521 | if (expires.tv64 < cpu_base->expires_next.tv64) | 521 | if (expires.tv64 < cpu_base->expires_next.tv64) |
| 522 | cpu_base->expires_next = expires; | 522 | cpu_base->expires_next = expires; |
| 523 | } | 523 | } |
| @@ -539,10 +539,10 @@ static int hrtimer_reprogram(struct hrtimer *timer, | |||
| 539 | struct hrtimer_clock_base *base) | 539 | struct hrtimer_clock_base *base) |
| 540 | { | 540 | { |
| 541 | ktime_t *expires_next = &__get_cpu_var(hrtimer_bases).expires_next; | 541 | ktime_t *expires_next = &__get_cpu_var(hrtimer_bases).expires_next; |
| 542 | ktime_t expires = ktime_sub(timer->expires, base->offset); | 542 | ktime_t expires = ktime_sub(hrtimer_get_expires(timer), base->offset); |
| 543 | int res; | 543 | int res; |
| 544 | 544 | ||
| 545 | WARN_ON_ONCE(timer->expires.tv64 < 0); | 545 | WARN_ON_ONCE(hrtimer_get_expires_tv64(timer) < 0); |
| 546 | 546 | ||
| 547 | /* | 547 | /* |
| 548 | * When the callback is running, we do not reprogram the clock event | 548 | * When the callback is running, we do not reprogram the clock event |
| @@ -664,14 +664,6 @@ static inline int hrtimer_enqueue_reprogram(struct hrtimer *timer, | |||
| 664 | 664 | ||
| 665 | /* Timer is expired, act upon the callback mode */ | 665 | /* Timer is expired, act upon the callback mode */ |
| 666 | switch(timer->cb_mode) { | 666 | switch(timer->cb_mode) { |
| 667 | case HRTIMER_CB_IRQSAFE_NO_RESTART: | ||
| 668 | debug_hrtimer_deactivate(timer); | ||
| 669 | /* | ||
| 670 | * We can call the callback from here. No restart | ||
| 671 | * happens, so no danger of recursion | ||
| 672 | */ | ||
| 673 | BUG_ON(timer->function(timer) != HRTIMER_NORESTART); | ||
| 674 | return 1; | ||
| 675 | case HRTIMER_CB_IRQSAFE_PERCPU: | 667 | case HRTIMER_CB_IRQSAFE_PERCPU: |
| 676 | case HRTIMER_CB_IRQSAFE_UNLOCKED: | 668 | case HRTIMER_CB_IRQSAFE_UNLOCKED: |
| 677 | /* | 669 | /* |
| @@ -683,7 +675,6 @@ static inline int hrtimer_enqueue_reprogram(struct hrtimer *timer, | |||
| 683 | */ | 675 | */ |
| 684 | debug_hrtimer_deactivate(timer); | 676 | debug_hrtimer_deactivate(timer); |
| 685 | return 1; | 677 | return 1; |
| 686 | case HRTIMER_CB_IRQSAFE: | ||
| 687 | case HRTIMER_CB_SOFTIRQ: | 678 | case HRTIMER_CB_SOFTIRQ: |
| 688 | /* | 679 | /* |
| 689 | * Move everything else into the softirq pending list ! | 680 | * Move everything else into the softirq pending list ! |
| @@ -795,7 +786,7 @@ u64 hrtimer_forward(struct hrtimer *timer, ktime_t now, ktime_t interval) | |||
| 795 | u64 orun = 1; | 786 | u64 orun = 1; |
| 796 | ktime_t delta; | 787 | ktime_t delta; |
| 797 | 788 | ||
| 798 | delta = ktime_sub(now, timer->expires); | 789 | delta = ktime_sub(now, hrtimer_get_expires(timer)); |
| 799 | 790 | ||
| 800 | if (delta.tv64 < 0) | 791 | if (delta.tv64 < 0) |
| 801 | return 0; | 792 | return 0; |
| @@ -807,8 +798,8 @@ u64 hrtimer_forward(struct hrtimer *timer, ktime_t now, ktime_t interval) | |||
| 807 | s64 incr = ktime_to_ns(interval); | 798 | s64 incr = ktime_to_ns(interval); |
| 808 | 799 | ||
| 809 | orun = ktime_divns(delta, incr); | 800 | orun = ktime_divns(delta, incr); |
| 810 | timer->expires = ktime_add_ns(timer->expires, incr * orun); | 801 | hrtimer_add_expires_ns(timer, incr * orun); |
| 811 | if (timer->expires.tv64 > now.tv64) | 802 | if (hrtimer_get_expires_tv64(timer) > now.tv64) |
| 812 | return orun; | 803 | return orun; |
| 813 | /* | 804 | /* |
| 814 | * This (and the ktime_add() below) is the | 805 | * This (and the ktime_add() below) is the |
| @@ -816,7 +807,7 @@ u64 hrtimer_forward(struct hrtimer *timer, ktime_t now, ktime_t interval) | |||
| 816 | */ | 807 | */ |
| 817 | orun++; | 808 | orun++; |
| 818 | } | 809 | } |
| 819 | timer->expires = ktime_add_safe(timer->expires, interval); | 810 | hrtimer_add_expires(timer, interval); |
| 820 | 811 | ||
| 821 | return orun; | 812 | return orun; |
| 822 | } | 813 | } |
| @@ -848,7 +839,8 @@ static void enqueue_hrtimer(struct hrtimer *timer, | |||
| 848 | * We dont care about collisions. Nodes with | 839 | * We dont care about collisions. Nodes with |
| 849 | * the same expiry time stay together. | 840 | * the same expiry time stay together. |
| 850 | */ | 841 | */ |
| 851 | if (timer->expires.tv64 < entry->expires.tv64) { | 842 | if (hrtimer_get_expires_tv64(timer) < |
| 843 | hrtimer_get_expires_tv64(entry)) { | ||
| 852 | link = &(*link)->rb_left; | 844 | link = &(*link)->rb_left; |
| 853 | } else { | 845 | } else { |
| 854 | link = &(*link)->rb_right; | 846 | link = &(*link)->rb_right; |
| @@ -945,9 +937,10 @@ remove_hrtimer(struct hrtimer *timer, struct hrtimer_clock_base *base) | |||
| 945 | } | 937 | } |
| 946 | 938 | ||
| 947 | /** | 939 | /** |
| 948 | * hrtimer_start - (re)start an relative timer on the current CPU | 940 | * hrtimer_start_range_ns - (re)start an hrtimer on the current CPU |
| 949 | * @timer: the timer to be added | 941 | * @timer: the timer to be added |
| 950 | * @tim: expiry time | 942 | * @tim: expiry time |
| 943 | * @delta_ns: "slack" range for the timer | ||
| 951 | * @mode: expiry mode: absolute (HRTIMER_ABS) or relative (HRTIMER_REL) | 944 | * @mode: expiry mode: absolute (HRTIMER_ABS) or relative (HRTIMER_REL) |
| 952 | * | 945 | * |
| 953 | * Returns: | 946 | * Returns: |
| @@ -955,7 +948,8 @@ remove_hrtimer(struct hrtimer *timer, struct hrtimer_clock_base *base) | |||
| 955 | * 1 when the timer was active | 948 | * 1 when the timer was active |
| 956 | */ | 949 | */ |
| 957 | int | 950 | int |
| 958 | hrtimer_start(struct hrtimer *timer, ktime_t tim, const enum hrtimer_mode mode) | 951 | hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim, unsigned long delta_ns, |
| 952 | const enum hrtimer_mode mode) | ||
| 959 | { | 953 | { |
| 960 | struct hrtimer_clock_base *base, *new_base; | 954 | struct hrtimer_clock_base *base, *new_base; |
| 961 | unsigned long flags; | 955 | unsigned long flags; |
| @@ -983,7 +977,7 @@ hrtimer_start(struct hrtimer *timer, ktime_t tim, const enum hrtimer_mode mode) | |||
| 983 | #endif | 977 | #endif |
| 984 | } | 978 | } |
| 985 | 979 | ||
| 986 | timer->expires = tim; | 980 | hrtimer_set_expires_range_ns(timer, tim, delta_ns); |
| 987 | 981 | ||
| 988 | timer_stats_hrtimer_set_start_info(timer); | 982 | timer_stats_hrtimer_set_start_info(timer); |
| 989 | 983 | ||
| @@ -1016,8 +1010,26 @@ hrtimer_start(struct hrtimer *timer, ktime_t tim, const enum hrtimer_mode mode) | |||
| 1016 | 1010 | ||
| 1017 | return ret; | 1011 | return ret; |
| 1018 | } | 1012 | } |
| 1013 | EXPORT_SYMBOL_GPL(hrtimer_start_range_ns); | ||
| 1014 | |||
| 1015 | /** | ||
| 1016 | * hrtimer_start - (re)start an hrtimer on the current CPU | ||
| 1017 | * @timer: the timer to be added | ||
| 1018 | * @tim: expiry time | ||
| 1019 | * @mode: expiry mode: absolute (HRTIMER_ABS) or relative (HRTIMER_REL) | ||
| 1020 | * | ||
| 1021 | * Returns: | ||
| 1022 | * 0 on success | ||
| 1023 | * 1 when the timer was active | ||
| 1024 | */ | ||
| 1025 | int | ||
| 1026 | hrtimer_start(struct hrtimer *timer, ktime_t tim, const enum hrtimer_mode mode) | ||
| 1027 | { | ||
| 1028 | return hrtimer_start_range_ns(timer, tim, 0, mode); | ||
| 1029 | } | ||
| 1019 | EXPORT_SYMBOL_GPL(hrtimer_start); | 1030 | EXPORT_SYMBOL_GPL(hrtimer_start); |
| 1020 | 1031 | ||
| 1032 | |||
| 1021 | /** | 1033 | /** |
| 1022 | * hrtimer_try_to_cancel - try to deactivate a timer | 1034 | * hrtimer_try_to_cancel - try to deactivate a timer |
| 1023 | * @timer: hrtimer to stop | 1035 | * @timer: hrtimer to stop |
| @@ -1077,7 +1089,7 @@ ktime_t hrtimer_get_remaining(const struct hrtimer *timer) | |||
| 1077 | ktime_t rem; | 1089 | ktime_t rem; |
| 1078 | 1090 | ||
| 1079 | base = lock_hrtimer_base(timer, &flags); | 1091 | base = lock_hrtimer_base(timer, &flags); |
| 1080 | rem = ktime_sub(timer->expires, base->get_time()); | 1092 | rem = hrtimer_expires_remaining(timer); |
| 1081 | unlock_hrtimer_base(timer, &flags); | 1093 | unlock_hrtimer_base(timer, &flags); |
| 1082 | 1094 | ||
| 1083 | return rem; | 1095 | return rem; |
| @@ -1109,7 +1121,7 @@ ktime_t hrtimer_get_next_event(void) | |||
| 1109 | continue; | 1121 | continue; |
| 1110 | 1122 | ||
| 1111 | timer = rb_entry(base->first, struct hrtimer, node); | 1123 | timer = rb_entry(base->first, struct hrtimer, node); |
| 1112 | delta.tv64 = timer->expires.tv64; | 1124 | delta.tv64 = hrtimer_get_expires_tv64(timer); |
| 1113 | delta = ktime_sub(delta, base->get_time()); | 1125 | delta = ktime_sub(delta, base->get_time()); |
| 1114 | if (delta.tv64 < mindelta.tv64) | 1126 | if (delta.tv64 < mindelta.tv64) |
| 1115 | mindelta.tv64 = delta.tv64; | 1127 | mindelta.tv64 = delta.tv64; |
| @@ -1188,6 +1200,7 @@ static void run_hrtimer_pending(struct hrtimer_cpu_base *cpu_base) | |||
| 1188 | enum hrtimer_restart (*fn)(struct hrtimer *); | 1200 | enum hrtimer_restart (*fn)(struct hrtimer *); |
| 1189 | struct hrtimer *timer; | 1201 | struct hrtimer *timer; |
| 1190 | int restart; | 1202 | int restart; |
| 1203 | int emulate_hardirq_ctx = 0; | ||
| 1191 | 1204 | ||
| 1192 | timer = list_entry(cpu_base->cb_pending.next, | 1205 | timer = list_entry(cpu_base->cb_pending.next, |
| 1193 | struct hrtimer, cb_entry); | 1206 | struct hrtimer, cb_entry); |
| @@ -1196,10 +1209,24 @@ static void run_hrtimer_pending(struct hrtimer_cpu_base *cpu_base) | |||
| 1196 | timer_stats_account_hrtimer(timer); | 1209 | timer_stats_account_hrtimer(timer); |
| 1197 | 1210 | ||
| 1198 | fn = timer->function; | 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 | |||
| 1199 | __remove_hrtimer(timer, timer->base, HRTIMER_STATE_CALLBACK, 0); | 1221 | __remove_hrtimer(timer, timer->base, HRTIMER_STATE_CALLBACK, 0); |
| 1200 | spin_unlock_irq(&cpu_base->lock); | 1222 | spin_unlock_irq(&cpu_base->lock); |
| 1201 | 1223 | ||
| 1202 | restart = fn(timer); | 1224 | if (unlikely(emulate_hardirq_ctx)) { |
| 1225 | local_irq_disable(); | ||
| 1226 | restart = fn(timer); | ||
| 1227 | local_irq_enable(); | ||
| 1228 | } else | ||
| 1229 | restart = fn(timer); | ||
| 1203 | 1230 | ||
| 1204 | spin_lock_irq(&cpu_base->lock); | 1231 | spin_lock_irq(&cpu_base->lock); |
| 1205 | 1232 | ||
| @@ -1310,10 +1337,23 @@ void hrtimer_interrupt(struct clock_event_device *dev) | |||
| 1310 | 1337 | ||
| 1311 | timer = rb_entry(node, struct hrtimer, node); | 1338 | timer = rb_entry(node, struct hrtimer, node); |
| 1312 | 1339 | ||
| 1313 | if (basenow.tv64 < timer->expires.tv64) { | 1340 | /* |
| 1341 | * The immediate goal for using the softexpires is | ||
| 1342 | * minimizing wakeups, not running timers at the | ||
| 1343 | * earliest interrupt after their soft expiration. | ||
| 1344 | * This allows us to avoid using a Priority Search | ||
| 1345 | * Tree, which can answer a stabbing querry for | ||
| 1346 | * overlapping intervals and instead use the simple | ||
| 1347 | * BST we already have. | ||
| 1348 | * We don't add extra wakeups by delaying timers that | ||
| 1349 | * are right-of a not yet expired timer, because that | ||
| 1350 | * timer will have to trigger a wakeup anyway. | ||
| 1351 | */ | ||
| 1352 | |||
| 1353 | if (basenow.tv64 < hrtimer_get_softexpires_tv64(timer)) { | ||
| 1314 | ktime_t expires; | 1354 | ktime_t expires; |
| 1315 | 1355 | ||
| 1316 | expires = ktime_sub(timer->expires, | 1356 | expires = ktime_sub(hrtimer_get_expires(timer), |
| 1317 | base->offset); | 1357 | base->offset); |
| 1318 | if (expires.tv64 < expires_next.tv64) | 1358 | if (expires.tv64 < expires_next.tv64) |
| 1319 | expires_next = expires; | 1359 | expires_next = expires; |
| @@ -1349,6 +1389,30 @@ void hrtimer_interrupt(struct clock_event_device *dev) | |||
| 1349 | raise_softirq(HRTIMER_SOFTIRQ); | 1389 | raise_softirq(HRTIMER_SOFTIRQ); |
| 1350 | } | 1390 | } |
| 1351 | 1391 | ||
| 1392 | /** | ||
| 1393 | * hrtimer_peek_ahead_timers -- run soft-expired timers now | ||
| 1394 | * | ||
| 1395 | * hrtimer_peek_ahead_timers will peek at the timer queue of | ||
| 1396 | * the current cpu and check if there are any timers for which | ||
| 1397 | * the soft expires time has passed. If any such timers exist, | ||
| 1398 | * they are run immediately and then removed from the timer queue. | ||
| 1399 | * | ||
| 1400 | */ | ||
| 1401 | void hrtimer_peek_ahead_timers(void) | ||
| 1402 | { | ||
| 1403 | struct tick_device *td; | ||
| 1404 | unsigned long flags; | ||
| 1405 | |||
| 1406 | if (!hrtimer_hres_active()) | ||
| 1407 | return; | ||
| 1408 | |||
| 1409 | local_irq_save(flags); | ||
| 1410 | td = &__get_cpu_var(tick_cpu_device); | ||
| 1411 | if (td && td->evtdev) | ||
| 1412 | hrtimer_interrupt(td->evtdev); | ||
| 1413 | local_irq_restore(flags); | ||
| 1414 | } | ||
| 1415 | |||
| 1352 | static void run_hrtimer_softirq(struct softirq_action *h) | 1416 | static void run_hrtimer_softirq(struct softirq_action *h) |
| 1353 | { | 1417 | { |
| 1354 | run_hrtimer_pending(&__get_cpu_var(hrtimer_bases)); | 1418 | run_hrtimer_pending(&__get_cpu_var(hrtimer_bases)); |
| @@ -1403,9 +1467,7 @@ void hrtimer_run_queues(void) | |||
| 1403 | if (!base->first) | 1467 | if (!base->first) |
| 1404 | continue; | 1468 | continue; |
| 1405 | 1469 | ||
| 1406 | if (base->get_softirq_time) | 1470 | if (gettime) { |
| 1407 | base->softirq_time = base->get_softirq_time(); | ||
| 1408 | else if (gettime) { | ||
| 1409 | hrtimer_get_softirq_time(cpu_base); | 1471 | hrtimer_get_softirq_time(cpu_base); |
| 1410 | gettime = 0; | 1472 | gettime = 0; |
| 1411 | } | 1473 | } |
| @@ -1416,7 +1478,8 @@ void hrtimer_run_queues(void) | |||
| 1416 | struct hrtimer *timer; | 1478 | struct hrtimer *timer; |
| 1417 | 1479 | ||
| 1418 | timer = rb_entry(node, struct hrtimer, node); | 1480 | timer = rb_entry(node, struct hrtimer, node); |
| 1419 | if (base->softirq_time.tv64 <= timer->expires.tv64) | 1481 | if (base->softirq_time.tv64 <= |
| 1482 | hrtimer_get_expires_tv64(timer)) | ||
| 1420 | break; | 1483 | break; |
| 1421 | 1484 | ||
| 1422 | if (timer->cb_mode == HRTIMER_CB_SOFTIRQ) { | 1485 | if (timer->cb_mode == HRTIMER_CB_SOFTIRQ) { |
| @@ -1464,7 +1527,7 @@ static int __sched do_nanosleep(struct hrtimer_sleeper *t, enum hrtimer_mode mod | |||
| 1464 | 1527 | ||
| 1465 | do { | 1528 | do { |
| 1466 | set_current_state(TASK_INTERRUPTIBLE); | 1529 | set_current_state(TASK_INTERRUPTIBLE); |
| 1467 | hrtimer_start(&t->timer, t->timer.expires, mode); | 1530 | hrtimer_start_expires(&t->timer, mode); |
| 1468 | if (!hrtimer_active(&t->timer)) | 1531 | if (!hrtimer_active(&t->timer)) |
| 1469 | t->task = NULL; | 1532 | t->task = NULL; |
| 1470 | 1533 | ||
| @@ -1486,7 +1549,7 @@ static int update_rmtp(struct hrtimer *timer, struct timespec __user *rmtp) | |||
| 1486 | struct timespec rmt; | 1549 | struct timespec rmt; |
| 1487 | ktime_t rem; | 1550 | ktime_t rem; |
| 1488 | 1551 | ||
| 1489 | rem = ktime_sub(timer->expires, timer->base->get_time()); | 1552 | rem = hrtimer_expires_remaining(timer); |
| 1490 | if (rem.tv64 <= 0) | 1553 | if (rem.tv64 <= 0) |
| 1491 | return 0; | 1554 | return 0; |
| 1492 | rmt = ktime_to_timespec(rem); | 1555 | rmt = ktime_to_timespec(rem); |
| @@ -1505,7 +1568,7 @@ long __sched hrtimer_nanosleep_restart(struct restart_block *restart) | |||
| 1505 | 1568 | ||
| 1506 | hrtimer_init_on_stack(&t.timer, restart->nanosleep.index, | 1569 | hrtimer_init_on_stack(&t.timer, restart->nanosleep.index, |
| 1507 | HRTIMER_MODE_ABS); | 1570 | HRTIMER_MODE_ABS); |
| 1508 | t.timer.expires.tv64 = restart->nanosleep.expires; | 1571 | hrtimer_set_expires_tv64(&t.timer, restart->nanosleep.expires); |
| 1509 | 1572 | ||
| 1510 | if (do_nanosleep(&t, HRTIMER_MODE_ABS)) | 1573 | if (do_nanosleep(&t, HRTIMER_MODE_ABS)) |
| 1511 | goto out; | 1574 | goto out; |
| @@ -1530,9 +1593,14 @@ long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp, | |||
| 1530 | struct restart_block *restart; | 1593 | struct restart_block *restart; |
| 1531 | struct hrtimer_sleeper t; | 1594 | struct hrtimer_sleeper t; |
| 1532 | int ret = 0; | 1595 | int ret = 0; |
| 1596 | unsigned long slack; | ||
| 1597 | |||
| 1598 | slack = current->timer_slack_ns; | ||
| 1599 | if (rt_task(current)) | ||
| 1600 | slack = 0; | ||
| 1533 | 1601 | ||
| 1534 | hrtimer_init_on_stack(&t.timer, clockid, mode); | 1602 | hrtimer_init_on_stack(&t.timer, clockid, mode); |
| 1535 | t.timer.expires = timespec_to_ktime(*rqtp); | 1603 | hrtimer_set_expires_range_ns(&t.timer, timespec_to_ktime(*rqtp), slack); |
| 1536 | if (do_nanosleep(&t, mode)) | 1604 | if (do_nanosleep(&t, mode)) |
| 1537 | goto out; | 1605 | goto out; |
| 1538 | 1606 | ||
| @@ -1552,7 +1620,7 @@ long hrtimer_nanosleep(struct timespec *rqtp, struct timespec __user *rmtp, | |||
| 1552 | restart->fn = hrtimer_nanosleep_restart; | 1620 | restart->fn = hrtimer_nanosleep_restart; |
| 1553 | restart->nanosleep.index = t.timer.base->index; | 1621 | restart->nanosleep.index = t.timer.base->index; |
| 1554 | restart->nanosleep.rmtp = rmtp; | 1622 | restart->nanosleep.rmtp = rmtp; |
| 1555 | restart->nanosleep.expires = t.timer.expires.tv64; | 1623 | restart->nanosleep.expires = hrtimer_get_expires_tv64(&t.timer); |
| 1556 | 1624 | ||
| 1557 | ret = -ERESTART_RESTARTBLOCK; | 1625 | ret = -ERESTART_RESTARTBLOCK; |
| 1558 | out: | 1626 | out: |
| @@ -1688,9 +1756,11 @@ static void migrate_hrtimers(int cpu) | |||
| 1688 | new_base = &get_cpu_var(hrtimer_bases); | 1756 | new_base = &get_cpu_var(hrtimer_bases); |
| 1689 | 1757 | ||
| 1690 | tick_cancel_sched_timer(cpu); | 1758 | tick_cancel_sched_timer(cpu); |
| 1691 | 1759 | /* | |
| 1692 | local_irq_disable(); | 1760 | * The caller is globally serialized and nobody else |
| 1693 | spin_lock(&new_base->lock); | 1761 | * takes two locks at once, deadlock is not possible. |
| 1762 | */ | ||
| 1763 | spin_lock_irq(&new_base->lock); | ||
| 1694 | spin_lock_nested(&old_base->lock, SINGLE_DEPTH_NESTING); | 1764 | spin_lock_nested(&old_base->lock, SINGLE_DEPTH_NESTING); |
| 1695 | 1765 | ||
| 1696 | for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) { | 1766 | for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) { |
| @@ -1703,8 +1773,7 @@ static void migrate_hrtimers(int cpu) | |||
| 1703 | raise = 1; | 1773 | raise = 1; |
| 1704 | 1774 | ||
| 1705 | spin_unlock(&old_base->lock); | 1775 | spin_unlock(&old_base->lock); |
| 1706 | spin_unlock(&new_base->lock); | 1776 | spin_unlock_irq(&new_base->lock); |
| 1707 | local_irq_enable(); | ||
| 1708 | put_cpu_var(hrtimer_bases); | 1777 | put_cpu_var(hrtimer_bases); |
| 1709 | 1778 | ||
| 1710 | if (raise) | 1779 | if (raise) |
| @@ -1753,3 +1822,103 @@ void __init hrtimers_init(void) | |||
| 1753 | #endif | 1822 | #endif |
| 1754 | } | 1823 | } |
| 1755 | 1824 | ||
| 1825 | /** | ||
| 1826 | * schedule_hrtimeout_range - sleep until timeout | ||
| 1827 | * @expires: timeout value (ktime_t) | ||
| 1828 | * @delta: slack in expires timeout (ktime_t) | ||
| 1829 | * @mode: timer mode, HRTIMER_MODE_ABS or HRTIMER_MODE_REL | ||
| 1830 | * | ||
| 1831 | * Make the current task sleep until the given expiry time has | ||
| 1832 | * elapsed. The routine will return immediately unless | ||
| 1833 | * the current task state has been set (see set_current_state()). | ||
| 1834 | * | ||
| 1835 | * The @delta argument gives the kernel the freedom to schedule the | ||
| 1836 | * actual wakeup to a time that is both power and performance friendly. | ||
| 1837 | * The kernel give the normal best effort behavior for "@expires+@delta", | ||
| 1838 | * but may decide to fire the timer earlier, but no earlier than @expires. | ||
| 1839 | * | ||
| 1840 | * You can set the task state as follows - | ||
| 1841 | * | ||
| 1842 | * %TASK_UNINTERRUPTIBLE - at least @timeout time is guaranteed to | ||
| 1843 | * pass before the routine returns. | ||
| 1844 | * | ||
| 1845 | * %TASK_INTERRUPTIBLE - the routine may return early if a signal is | ||
| 1846 | * delivered to the current task. | ||
| 1847 | * | ||
| 1848 | * The current task state is guaranteed to be TASK_RUNNING when this | ||
| 1849 | * routine returns. | ||
| 1850 | * | ||
| 1851 | * Returns 0 when the timer has expired otherwise -EINTR | ||
| 1852 | */ | ||
| 1853 | int __sched schedule_hrtimeout_range(ktime_t *expires, unsigned long delta, | ||
| 1854 | const enum hrtimer_mode mode) | ||
| 1855 | { | ||
| 1856 | struct hrtimer_sleeper t; | ||
| 1857 | |||
| 1858 | /* | ||
| 1859 | * Optimize when a zero timeout value is given. It does not | ||
| 1860 | * matter whether this is an absolute or a relative time. | ||
| 1861 | */ | ||
| 1862 | if (expires && !expires->tv64) { | ||
| 1863 | __set_current_state(TASK_RUNNING); | ||
| 1864 | return 0; | ||
| 1865 | } | ||
| 1866 | |||
| 1867 | /* | ||
| 1868 | * A NULL parameter means "inifinte" | ||
| 1869 | */ | ||
| 1870 | if (!expires) { | ||
| 1871 | schedule(); | ||
| 1872 | __set_current_state(TASK_RUNNING); | ||
| 1873 | return -EINTR; | ||
| 1874 | } | ||
| 1875 | |||
| 1876 | hrtimer_init_on_stack(&t.timer, CLOCK_MONOTONIC, mode); | ||
| 1877 | hrtimer_set_expires_range_ns(&t.timer, *expires, delta); | ||
| 1878 | |||
| 1879 | hrtimer_init_sleeper(&t, current); | ||
| 1880 | |||
| 1881 | hrtimer_start_expires(&t.timer, mode); | ||
| 1882 | if (!hrtimer_active(&t.timer)) | ||
| 1883 | t.task = NULL; | ||
| 1884 | |||
| 1885 | if (likely(t.task)) | ||
| 1886 | schedule(); | ||
| 1887 | |||
| 1888 | hrtimer_cancel(&t.timer); | ||
| 1889 | destroy_hrtimer_on_stack(&t.timer); | ||
| 1890 | |||
| 1891 | __set_current_state(TASK_RUNNING); | ||
| 1892 | |||
| 1893 | return !t.task ? 0 : -EINTR; | ||
| 1894 | } | ||
| 1895 | EXPORT_SYMBOL_GPL(schedule_hrtimeout_range); | ||
| 1896 | |||
| 1897 | /** | ||
| 1898 | * schedule_hrtimeout - sleep until timeout | ||
| 1899 | * @expires: timeout value (ktime_t) | ||
| 1900 | * @mode: timer mode, HRTIMER_MODE_ABS or HRTIMER_MODE_REL | ||
| 1901 | * | ||
| 1902 | * Make the current task sleep until the given expiry time has | ||
| 1903 | * elapsed. The routine will return immediately unless | ||
| 1904 | * the current task state has been set (see set_current_state()). | ||
| 1905 | * | ||
| 1906 | * You can set the task state as follows - | ||
| 1907 | * | ||
| 1908 | * %TASK_UNINTERRUPTIBLE - at least @timeout time is guaranteed to | ||
| 1909 | * pass before the routine returns. | ||
| 1910 | * | ||
| 1911 | * %TASK_INTERRUPTIBLE - the routine may return early if a signal is | ||
| 1912 | * delivered to the current task. | ||
| 1913 | * | ||
| 1914 | * The current task state is guaranteed to be TASK_RUNNING when this | ||
| 1915 | * routine returns. | ||
| 1916 | * | ||
| 1917 | * Returns 0 when the timer has expired otherwise -EINTR | ||
| 1918 | */ | ||
| 1919 | int __sched schedule_hrtimeout(ktime_t *expires, | ||
| 1920 | const enum hrtimer_mode mode) | ||
| 1921 | { | ||
| 1922 | return schedule_hrtimeout_range(expires, 0, mode); | ||
| 1923 | } | ||
| 1924 | EXPORT_SYMBOL_GPL(schedule_hrtimeout); | ||
