aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/hrtimer.c
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/hrtimer.c')
-rw-r--r--kernel/hrtimer.c350
1 files changed, 286 insertions, 64 deletions
diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
index 0086628b6e97..51168a1e663a 100644
--- a/kernel/hrtimer.c
+++ b/kernel/hrtimer.c
@@ -49,6 +49,7 @@
49#include <asm/uaccess.h> 49#include <asm/uaccess.h>
50 50
51#include <trace/events/timer.h> 51#include <trace/events/timer.h>
52#include <trace/events/hist.h>
52 53
53/* 54/*
54 * The timer bases: 55 * The timer bases:
@@ -88,10 +89,10 @@ static void hrtimer_get_softirq_time(struct hrtimer_cpu_base *base)
88 unsigned long seq; 89 unsigned long seq;
89 90
90 do { 91 do {
91 seq = read_seqbegin(&xtime_lock); 92 seq = read_raw_seqbegin(&xtime_lock);
92 xts = current_kernel_time(); 93 xts = current_kernel_time();
93 tom = wall_to_monotonic; 94 tom = wall_to_monotonic;
94 } while (read_seqretry(&xtime_lock, seq)); 95 } while (read_raw_seqretry(&xtime_lock, seq));
95 96
96 xtim = timespec_to_ktime(xts); 97 xtim = timespec_to_ktime(xts);
97 tomono = timespec_to_ktime(tom); 98 tomono = timespec_to_ktime(tom);
@@ -499,9 +500,9 @@ static inline int hrtimer_is_hres_enabled(void)
499/* 500/*
500 * Is the high resolution mode active ? 501 * Is the high resolution mode active ?
501 */ 502 */
502static inline int hrtimer_hres_active(void) 503static inline int hrtimer_hres_active(struct hrtimer_cpu_base *cpu_base)
503{ 504{
504 return __get_cpu_var(hrtimer_bases).hres_active; 505 return cpu_base->hres_active;
505} 506}
506 507
507/* 508/*
@@ -567,8 +568,7 @@ static int hrtimer_reprogram(struct hrtimer *timer,
567 * When the callback is running, we do not reprogram the clock event 568 * When the callback is running, we do not reprogram the clock event
568 * device. The timer callback is either running on a different CPU or 569 * device. The timer callback is either running on a different CPU or
569 * the callback is executed in the hrtimer_interrupt context. The 570 * the callback is executed in the hrtimer_interrupt context. The
570 * reprogramming is handled either by the softirq, which called the 571 * reprogramming is handled at the end of the hrtimer_interrupt.
571 * callback or at the end of the hrtimer_interrupt.
572 */ 572 */
573 if (hrtimer_callback_running(timer)) 573 if (hrtimer_callback_running(timer))
574 return 0; 574 return 0;
@@ -611,21 +611,19 @@ static int hrtimer_reprogram(struct hrtimer *timer,
611 */ 611 */
612static void retrigger_next_event(void *arg) 612static void retrigger_next_event(void *arg)
613{ 613{
614 struct hrtimer_cpu_base *base; 614 struct hrtimer_cpu_base *base = &__get_cpu_var(hrtimer_bases);
615 struct timespec realtime_offset; 615 struct timespec realtime_offset;
616 unsigned long seq; 616 unsigned long seq;
617 617
618 if (!hrtimer_hres_active()) 618 if (!hrtimer_hres_active(base))
619 return; 619 return;
620 620
621 do { 621 do {
622 seq = read_seqbegin(&xtime_lock); 622 seq = read_raw_seqbegin(&xtime_lock);
623 set_normalized_timespec(&realtime_offset, 623 set_normalized_timespec(&realtime_offset,
624 -wall_to_monotonic.tv_sec, 624 -wall_to_monotonic.tv_sec,
625 -wall_to_monotonic.tv_nsec); 625 -wall_to_monotonic.tv_nsec);
626 } while (read_seqretry(&xtime_lock, seq)); 626 } while (read_raw_seqretry(&xtime_lock, seq));
627
628 base = &__get_cpu_var(hrtimer_bases);
629 627
630 /* Adjust CLOCK_REALTIME offset */ 628 /* Adjust CLOCK_REALTIME offset */
631 raw_spin_lock(&base->lock); 629 raw_spin_lock(&base->lock);
@@ -681,6 +679,8 @@ static inline void hrtimer_init_timer_hres(struct hrtimer *timer)
681{ 679{
682} 680}
683 681
682static void __run_hrtimer(struct hrtimer *timer, ktime_t *now);
683static int hrtimer_rt_defer(struct hrtimer *timer);
684 684
685/* 685/*
686 * When High resolution timers are active, try to reprogram. Note, that in case 686 * When High resolution timers are active, try to reprogram. Note, that in case
@@ -692,7 +692,29 @@ static inline int hrtimer_enqueue_reprogram(struct hrtimer *timer,
692 struct hrtimer_clock_base *base, 692 struct hrtimer_clock_base *base,
693 int wakeup) 693 int wakeup)
694{ 694{
695#ifdef CONFIG_PREEMPT_RT
696again:
697#endif
695 if (base->cpu_base->hres_active && hrtimer_reprogram(timer, base)) { 698 if (base->cpu_base->hres_active && hrtimer_reprogram(timer, base)) {
699#ifdef CONFIG_PREEMPT_RT
700 /*
701 * Move softirq based timers away from the rbtree in
702 * case it expired already. Otherwise we would have a
703 * stale base->first entry until the softirq runs.
704 */
705 if (!hrtimer_rt_defer(timer)) {
706 ktime_t now = ktime_get();
707
708 __run_hrtimer(timer, &now);
709 /*
710 * __run_hrtimer might have requeued timer and
711 * it could be base->first again.
712 */
713 if (base->first == &timer->node)
714 goto again;
715 return 1;
716 }
717#endif
696 if (wakeup) { 718 if (wakeup) {
697 raw_spin_unlock(&base->cpu_base->lock); 719 raw_spin_unlock(&base->cpu_base->lock);
698 raise_softirq_irqoff(HRTIMER_SOFTIRQ); 720 raise_softirq_irqoff(HRTIMER_SOFTIRQ);
@@ -709,10 +731,8 @@ static inline int hrtimer_enqueue_reprogram(struct hrtimer *timer,
709/* 731/*
710 * Switch to high resolution mode 732 * Switch to high resolution mode
711 */ 733 */
712static int hrtimer_switch_to_hres(void) 734static int hrtimer_switch_to_hres(struct hrtimer_cpu_base *base)
713{ 735{
714 int cpu = smp_processor_id();
715 struct hrtimer_cpu_base *base = &per_cpu(hrtimer_bases, cpu);
716 unsigned long flags; 736 unsigned long flags;
717 737
718 if (base->hres_active) 738 if (base->hres_active)
@@ -723,7 +743,7 @@ static int hrtimer_switch_to_hres(void)
723 if (tick_init_highres()) { 743 if (tick_init_highres()) {
724 local_irq_restore(flags); 744 local_irq_restore(flags);
725 printk(KERN_WARNING "Could not switch to high resolution " 745 printk(KERN_WARNING "Could not switch to high resolution "
726 "mode on CPU %d\n", cpu); 746 "mode on CPU %d\n", raw_smp_processor_id());
727 return 0; 747 return 0;
728 } 748 }
729 base->hres_active = 1; 749 base->hres_active = 1;
@@ -740,9 +760,15 @@ static int hrtimer_switch_to_hres(void)
740 760
741#else 761#else
742 762
743static inline int hrtimer_hres_active(void) { return 0; } 763static inline int hrtimer_hres_active(struct hrtimer_cpu_base *base)
764{
765 return 0;
766}
744static inline int hrtimer_is_hres_enabled(void) { return 0; } 767static inline int hrtimer_is_hres_enabled(void) { return 0; }
745static inline int hrtimer_switch_to_hres(void) { return 0; } 768static inline int hrtimer_switch_to_hres(struct hrtimer_cpu_base *base)
769{
770 return 0;
771}
746static inline void 772static inline void
747hrtimer_force_reprogram(struct hrtimer_cpu_base *base, int skip_equal) { } 773hrtimer_force_reprogram(struct hrtimer_cpu_base *base, int skip_equal) { }
748static inline int hrtimer_enqueue_reprogram(struct hrtimer *timer, 774static inline int hrtimer_enqueue_reprogram(struct hrtimer *timer,
@@ -751,6 +777,13 @@ static inline int hrtimer_enqueue_reprogram(struct hrtimer *timer,
751{ 777{
752 return 0; 778 return 0;
753} 779}
780
781static inline int hrtimer_reprogram(struct hrtimer *timer,
782 struct hrtimer_clock_base *base)
783{
784 return 0;
785}
786
754static inline void hrtimer_init_hres(struct hrtimer_cpu_base *base) { } 787static inline void hrtimer_init_hres(struct hrtimer_cpu_base *base) { }
755static inline void hrtimer_init_timer_hres(struct hrtimer *timer) { } 788static inline void hrtimer_init_timer_hres(struct hrtimer *timer) { }
756 789
@@ -889,6 +922,32 @@ static int enqueue_hrtimer(struct hrtimer *timer,
889 return leftmost; 922 return leftmost;
890} 923}
891 924
925#ifdef CONFIG_PREEMPT_SOFTIRQS
926# define wake_up_timer_waiters(b) wake_up(&(b)->wait)
927
928/**
929 * hrtimer_wait_for_timer - Wait for a running timer
930 *
931 * @timer: timer to wait for
932 *
933 * The function waits in case the timers callback function is
934 * currently executed on the waitqueue of the timer base. The
935 * waitqueue is woken up after the timer callback function has
936 * finished execution.
937 */
938void hrtimer_wait_for_timer(const struct hrtimer *timer)
939{
940 struct hrtimer_clock_base *base = timer->base;
941
942 if (base && base->cpu_base && !timer->irqsafe)
943 wait_event(base->cpu_base->wait,
944 !(timer->state & HRTIMER_STATE_CALLBACK));
945}
946
947#else
948# define wake_up_timer_waiters(b) do { } while (0)
949#endif
950
892/* 951/*
893 * __remove_hrtimer - internal function to remove a timer 952 * __remove_hrtimer - internal function to remove a timer
894 * 953 *
@@ -906,6 +965,11 @@ static void __remove_hrtimer(struct hrtimer *timer,
906 if (!(timer->state & HRTIMER_STATE_ENQUEUED)) 965 if (!(timer->state & HRTIMER_STATE_ENQUEUED))
907 goto out; 966 goto out;
908 967
968 if (unlikely(!list_empty(&timer->cb_entry))) {
969 list_del_init(&timer->cb_entry);
970 goto out;
971 }
972
909 /* 973 /*
910 * Remove the timer from the rbtree and replace the first 974 * Remove the timer from the rbtree and replace the first
911 * entry pointer if necessary. 975 * entry pointer if necessary.
@@ -914,7 +978,7 @@ static void __remove_hrtimer(struct hrtimer *timer,
914 base->first = rb_next(&timer->node); 978 base->first = rb_next(&timer->node);
915#ifdef CONFIG_HIGH_RES_TIMERS 979#ifdef CONFIG_HIGH_RES_TIMERS
916 /* Reprogram the clock event device. if enabled */ 980 /* Reprogram the clock event device. if enabled */
917 if (reprogram && hrtimer_hres_active()) { 981 if (reprogram && hrtimer_hres_active(base->cpu_base)) {
918 ktime_t expires; 982 ktime_t expires;
919 983
920 expires = ktime_sub(hrtimer_get_expires(timer), 984 expires = ktime_sub(hrtimer_get_expires(timer),
@@ -1085,7 +1149,7 @@ int hrtimer_cancel(struct hrtimer *timer)
1085 1149
1086 if (ret >= 0) 1150 if (ret >= 0)
1087 return ret; 1151 return ret;
1088 cpu_relax(); 1152 hrtimer_wait_for_timer(timer);
1089 } 1153 }
1090} 1154}
1091EXPORT_SYMBOL_GPL(hrtimer_cancel); 1155EXPORT_SYMBOL_GPL(hrtimer_cancel);
@@ -1125,7 +1189,7 @@ ktime_t hrtimer_get_next_event(void)
1125 1189
1126 raw_spin_lock_irqsave(&cpu_base->lock, flags); 1190 raw_spin_lock_irqsave(&cpu_base->lock, flags);
1127 1191
1128 if (!hrtimer_hres_active()) { 1192 if (!hrtimer_hres_active(cpu_base)) {
1129 for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++, base++) { 1193 for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++, base++) {
1130 struct hrtimer *timer; 1194 struct hrtimer *timer;
1131 1195
@@ -1161,6 +1225,7 @@ static void __hrtimer_init(struct hrtimer *timer, clockid_t clock_id,
1161 clock_id = CLOCK_MONOTONIC; 1225 clock_id = CLOCK_MONOTONIC;
1162 1226
1163 timer->base = &cpu_base->clock_base[clock_id]; 1227 timer->base = &cpu_base->clock_base[clock_id];
1228 INIT_LIST_HEAD(&timer->cb_entry);
1164 hrtimer_init_timer_hres(timer); 1229 hrtimer_init_timer_hres(timer);
1165 1230
1166#ifdef CONFIG_TIMER_STATS 1231#ifdef CONFIG_TIMER_STATS
@@ -1240,8 +1305,120 @@ static void __run_hrtimer(struct hrtimer *timer, ktime_t *now)
1240 timer->state &= ~HRTIMER_STATE_CALLBACK; 1305 timer->state &= ~HRTIMER_STATE_CALLBACK;
1241} 1306}
1242 1307
1308#ifdef CONFIG_PREEMPT_RT
1309
1310static void hrtimer_rt_reprogram(int restart, struct hrtimer *timer,
1311 struct hrtimer_clock_base *base)
1312{
1313 /*
1314 * Note, we clear the callback flag before we requeue the
1315 * timer otherwise we trigger the callback_running() check
1316 * in hrtimer_reprogram().
1317 */
1318 timer->state &= ~HRTIMER_STATE_CALLBACK;
1319
1320 if (restart != HRTIMER_NORESTART) {
1321 BUG_ON(hrtimer_active(timer));
1322 /*
1323 * Enqueue the timer, if it's the leftmost timer then
1324 * we need to reprogram it.
1325 */
1326 if (!enqueue_hrtimer(timer, base))
1327 return;
1328
1329 if (hrtimer_reprogram(timer, base))
1330 goto requeue;
1331
1332 } else if (hrtimer_active(timer)) {
1333 /*
1334 * If the timer was rearmed on another CPU, reprogram
1335 * the event device.
1336 */
1337 if (base->first == &timer->node &&
1338 hrtimer_reprogram(timer, base))
1339 goto requeue;
1340 }
1341 return;
1342
1343requeue:
1344 /*
1345 * Timer is expired. Thus move it from tree to pending list
1346 * again.
1347 */
1348 __remove_hrtimer(timer, base, timer->state, 0);
1349 list_add_tail(&timer->cb_entry, &base->expired);
1350}
1351
1352/*
1353 * The changes in mainline which removed the callback modes from
1354 * hrtimer are not yet working with -rt. The non wakeup_process()
1355 * based callbacks which involve sleeping locks need to be treated
1356 * seperately.
1357 */
1358static void hrtimer_rt_run_pending(void)
1359{
1360 enum hrtimer_restart (*fn)(struct hrtimer *);
1361 struct hrtimer_cpu_base *cpu_base;
1362 struct hrtimer_clock_base *base;
1363 struct hrtimer *timer;
1364 int index, restart;
1365
1366 local_irq_disable();
1367 cpu_base = &per_cpu(hrtimer_bases, smp_processor_id());
1368
1369 raw_spin_lock(&cpu_base->lock);
1370
1371 for (index = 0; index < HRTIMER_MAX_CLOCK_BASES; index++) {
1372 base = &cpu_base->clock_base[index];
1373
1374 while (!list_empty(&base->expired)) {
1375 timer = list_first_entry(&base->expired,
1376 struct hrtimer, cb_entry);
1377
1378 /*
1379 * Same as the above __run_hrtimer function
1380 * just we run with interrupts enabled.
1381 */
1382 debug_hrtimer_deactivate(timer);
1383 __remove_hrtimer(timer, base, HRTIMER_STATE_CALLBACK, 0);
1384 timer_stats_account_hrtimer(timer);
1385 fn = timer->function;
1386
1387 raw_spin_unlock_irq(&cpu_base->lock);
1388 restart = fn(timer);
1389 raw_spin_lock_irq(&cpu_base->lock);
1390
1391 hrtimer_rt_reprogram(restart, timer, base);
1392 }
1393 }
1394
1395 raw_spin_unlock_irq(&cpu_base->lock);
1396
1397 wake_up_timer_waiters(cpu_base);
1398}
1399
1400static int hrtimer_rt_defer(struct hrtimer *timer)
1401{
1402 if (timer->irqsafe)
1403 return 0;
1404
1405 __remove_hrtimer(timer, timer->base, timer->state, 0);
1406 list_add_tail(&timer->cb_entry, &timer->base->expired);
1407 return 1;
1408}
1409
1410#else
1411
1412static inline void hrtimer_rt_run_pending(void) { }
1413static inline int hrtimer_rt_defer(struct hrtimer *timer) { return 0; }
1414
1415#endif
1416
1417
1243#ifdef CONFIG_HIGH_RES_TIMERS 1418#ifdef CONFIG_HIGH_RES_TIMERS
1244 1419
1420static enum hrtimer_restart hrtimer_wakeup(struct hrtimer *timer);
1421
1245/* 1422/*
1246 * High resolution timer interrupt 1423 * High resolution timer interrupt
1247 * Called with interrupts disabled 1424 * Called with interrupts disabled
@@ -1251,7 +1428,7 @@ void hrtimer_interrupt(struct clock_event_device *dev)
1251 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases); 1428 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
1252 struct hrtimer_clock_base *base; 1429 struct hrtimer_clock_base *base;
1253 ktime_t expires_next, now, entry_time, delta; 1430 ktime_t expires_next, now, entry_time, delta;
1254 int i, retries = 0; 1431 int i, retries = 0, raise = 0;
1255 1432
1256 BUG_ON(!cpu_base->hres_active); 1433 BUG_ON(!cpu_base->hres_active);
1257 cpu_base->nr_events++; 1434 cpu_base->nr_events++;
@@ -1284,6 +1461,14 @@ retry:
1284 1461
1285 timer = rb_entry(node, struct hrtimer, node); 1462 timer = rb_entry(node, struct hrtimer, node);
1286 1463
1464 trace_hrtimer_interrupt(raw_smp_processor_id(),
1465 ktime_to_ns(ktime_sub(
1466 hrtimer_get_expires(timer), basenow)),
1467 current,
1468 timer->function == hrtimer_wakeup ?
1469 container_of(timer, struct hrtimer_sleeper,
1470 timer)->task : NULL);
1471
1287 /* 1472 /*
1288 * The immediate goal for using the softexpires is 1473 * The immediate goal for using the softexpires is
1289 * minimizing wakeups, not running timers at the 1474 * minimizing wakeups, not running timers at the
@@ -1307,7 +1492,10 @@ retry:
1307 break; 1492 break;
1308 } 1493 }
1309 1494
1310 __run_hrtimer(timer, &basenow); 1495 if (!hrtimer_rt_defer(timer))
1496 __run_hrtimer(timer, &basenow);
1497 else
1498 raise = 1;
1311 } 1499 }
1312 base++; 1500 base++;
1313 } 1501 }
@@ -1323,6 +1511,10 @@ retry:
1323 if (expires_next.tv64 == KTIME_MAX || 1511 if (expires_next.tv64 == KTIME_MAX ||
1324 !tick_program_event(expires_next, 0)) { 1512 !tick_program_event(expires_next, 0)) {
1325 cpu_base->hang_detected = 0; 1513 cpu_base->hang_detected = 0;
1514
1515 if (raise)
1516 raise_softirq_irqoff(HRTIMER_SOFTIRQ);
1517
1326 return; 1518 return;
1327 } 1519 }
1328 1520
@@ -1370,9 +1562,11 @@ retry:
1370 */ 1562 */
1371static void __hrtimer_peek_ahead_timers(void) 1563static void __hrtimer_peek_ahead_timers(void)
1372{ 1564{
1565 struct hrtimer_cpu_base *cpu_base;
1373 struct tick_device *td; 1566 struct tick_device *td;
1374 1567
1375 if (!hrtimer_hres_active()) 1568 cpu_base = &__get_cpu_var(hrtimer_bases);
1569 if (!hrtimer_hres_active(cpu_base))
1376 return; 1570 return;
1377 1571
1378 td = &__get_cpu_var(tick_cpu_device); 1572 td = &__get_cpu_var(tick_cpu_device);
@@ -1398,17 +1592,17 @@ void hrtimer_peek_ahead_timers(void)
1398 local_irq_restore(flags); 1592 local_irq_restore(flags);
1399} 1593}
1400 1594
1401static void run_hrtimer_softirq(struct softirq_action *h)
1402{
1403 hrtimer_peek_ahead_timers();
1404}
1405
1406#else /* CONFIG_HIGH_RES_TIMERS */ 1595#else /* CONFIG_HIGH_RES_TIMERS */
1407 1596
1408static inline void __hrtimer_peek_ahead_timers(void) { } 1597static inline void __hrtimer_peek_ahead_timers(void) { }
1409 1598
1410#endif /* !CONFIG_HIGH_RES_TIMERS */ 1599#endif /* !CONFIG_HIGH_RES_TIMERS */
1411 1600
1601static void run_hrtimer_softirq(struct softirq_action *h)
1602{
1603 hrtimer_rt_run_pending();
1604}
1605
1412/* 1606/*
1413 * Called from timer softirq every jiffy, expire hrtimers: 1607 * Called from timer softirq every jiffy, expire hrtimers:
1414 * 1608 *
@@ -1418,7 +1612,9 @@ static inline void __hrtimer_peek_ahead_timers(void) { }
1418 */ 1612 */
1419void hrtimer_run_pending(void) 1613void hrtimer_run_pending(void)
1420{ 1614{
1421 if (hrtimer_hres_active()) 1615 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
1616
1617 if (hrtimer_hres_active(cpu_base))
1422 return; 1618 return;
1423 1619
1424 /* 1620 /*
@@ -1430,7 +1626,7 @@ void hrtimer_run_pending(void)
1430 * deadlock vs. xtime_lock. 1626 * deadlock vs. xtime_lock.
1431 */ 1627 */
1432 if (tick_check_oneshot_change(!hrtimer_is_hres_enabled())) 1628 if (tick_check_oneshot_change(!hrtimer_is_hres_enabled()))
1433 hrtimer_switch_to_hres(); 1629 hrtimer_switch_to_hres(cpu_base);
1434} 1630}
1435 1631
1436/* 1632/*
@@ -1439,11 +1635,12 @@ void hrtimer_run_pending(void)
1439void hrtimer_run_queues(void) 1635void hrtimer_run_queues(void)
1440{ 1636{
1441 struct rb_node *node; 1637 struct rb_node *node;
1442 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases); 1638 struct hrtimer_cpu_base *cpu_base;
1443 struct hrtimer_clock_base *base; 1639 struct hrtimer_clock_base *base;
1444 int index, gettime = 1; 1640 int index, gettime = 1, raise = 0;
1445 1641
1446 if (hrtimer_hres_active()) 1642 cpu_base = &per_cpu(hrtimer_bases, raw_smp_processor_id());
1643 if (hrtimer_hres_active(cpu_base))
1447 return; 1644 return;
1448 1645
1449 for (index = 0; index < HRTIMER_MAX_CLOCK_BASES; index++) { 1646 for (index = 0; index < HRTIMER_MAX_CLOCK_BASES; index++) {
@@ -1467,10 +1664,16 @@ void hrtimer_run_queues(void)
1467 hrtimer_get_expires_tv64(timer)) 1664 hrtimer_get_expires_tv64(timer))
1468 break; 1665 break;
1469 1666
1470 __run_hrtimer(timer, &base->softirq_time); 1667 if (!hrtimer_rt_defer(timer))
1668 __run_hrtimer(timer, &base->softirq_time);
1669 else
1670 raise = 1;
1471 } 1671 }
1472 raw_spin_unlock(&cpu_base->lock); 1672 raw_spin_unlock(&cpu_base->lock);
1473 } 1673 }
1674
1675 if (raise)
1676 raise_softirq_irqoff(HRTIMER_SOFTIRQ);
1474} 1677}
1475 1678
1476/* 1679/*
@@ -1492,6 +1695,7 @@ static enum hrtimer_restart hrtimer_wakeup(struct hrtimer *timer)
1492void hrtimer_init_sleeper(struct hrtimer_sleeper *sl, struct task_struct *task) 1695void hrtimer_init_sleeper(struct hrtimer_sleeper *sl, struct task_struct *task)
1493{ 1696{
1494 sl->timer.function = hrtimer_wakeup; 1697 sl->timer.function = hrtimer_wakeup;
1698 sl->timer.irqsafe = 1;
1495 sl->task = task; 1699 sl->task = task;
1496} 1700}
1497EXPORT_SYMBOL_GPL(hrtimer_init_sleeper); 1701EXPORT_SYMBOL_GPL(hrtimer_init_sleeper);
@@ -1627,10 +1831,15 @@ static void __cpuinit init_hrtimers_cpu(int cpu)
1627 1831
1628 raw_spin_lock_init(&cpu_base->lock); 1832 raw_spin_lock_init(&cpu_base->lock);
1629 1833
1630 for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) 1834 for (i = 0; i < HRTIMER_MAX_CLOCK_BASES; i++) {
1631 cpu_base->clock_base[i].cpu_base = cpu_base; 1835 cpu_base->clock_base[i].cpu_base = cpu_base;
1836 INIT_LIST_HEAD(&cpu_base->clock_base[i].expired);
1837 }
1632 1838
1633 hrtimer_init_hres(cpu_base); 1839 hrtimer_init_hres(cpu_base);
1840#ifdef CONFIG_PREEMPT_RT
1841 init_waitqueue_head(&cpu_base->wait);
1842#endif
1634} 1843}
1635 1844
1636#ifdef CONFIG_HOTPLUG_CPU 1845#ifdef CONFIG_HOTPLUG_CPU
@@ -1743,41 +1952,19 @@ void __init hrtimers_init(void)
1743 hrtimer_cpu_notify(&hrtimers_nb, (unsigned long)CPU_UP_PREPARE, 1952 hrtimer_cpu_notify(&hrtimers_nb, (unsigned long)CPU_UP_PREPARE,
1744 (void *)(long)smp_processor_id()); 1953 (void *)(long)smp_processor_id());
1745 register_cpu_notifier(&hrtimers_nb); 1954 register_cpu_notifier(&hrtimers_nb);
1746#ifdef CONFIG_HIGH_RES_TIMERS
1747 open_softirq(HRTIMER_SOFTIRQ, run_hrtimer_softirq); 1955 open_softirq(HRTIMER_SOFTIRQ, run_hrtimer_softirq);
1748#endif
1749} 1956}
1750 1957
1751/** 1958/**
1752 * schedule_hrtimeout_range - sleep until timeout 1959 * schedule_hrtimeout_range_clock - sleep until timeout
1753 * @expires: timeout value (ktime_t) 1960 * @expires: timeout value (ktime_t)
1754 * @delta: slack in expires timeout (ktime_t) 1961 * @delta: slack in expires timeout (ktime_t)
1755 * @mode: timer mode, HRTIMER_MODE_ABS or HRTIMER_MODE_REL 1962 * @mode: timer mode, HRTIMER_MODE_ABS or HRTIMER_MODE_REL
1756 * 1963 * @clock: timer clock, CLOCK_MONOTONIC or CLOCK_REALTIME
1757 * Make the current task sleep until the given expiry time has
1758 * elapsed. The routine will return immediately unless
1759 * the current task state has been set (see set_current_state()).
1760 *
1761 * The @delta argument gives the kernel the freedom to schedule the
1762 * actual wakeup to a time that is both power and performance friendly.
1763 * The kernel give the normal best effort behavior for "@expires+@delta",
1764 * but may decide to fire the timer earlier, but no earlier than @expires.
1765 *
1766 * You can set the task state as follows -
1767 *
1768 * %TASK_UNINTERRUPTIBLE - at least @timeout time is guaranteed to
1769 * pass before the routine returns.
1770 *
1771 * %TASK_INTERRUPTIBLE - the routine may return early if a signal is
1772 * delivered to the current task.
1773 *
1774 * The current task state is guaranteed to be TASK_RUNNING when this
1775 * routine returns.
1776 *
1777 * Returns 0 when the timer has expired otherwise -EINTR
1778 */ 1964 */
1779int __sched schedule_hrtimeout_range(ktime_t *expires, unsigned long delta, 1965int __sched
1780 const enum hrtimer_mode mode) 1966schedule_hrtimeout_range_clock(ktime_t *expires, unsigned long delta,
1967 const enum hrtimer_mode mode, int clock)
1781{ 1968{
1782 struct hrtimer_sleeper t; 1969 struct hrtimer_sleeper t;
1783 1970
@@ -1799,7 +1986,7 @@ int __sched schedule_hrtimeout_range(ktime_t *expires, unsigned long delta,
1799 return -EINTR; 1986 return -EINTR;
1800 } 1987 }
1801 1988
1802 hrtimer_init_on_stack(&t.timer, CLOCK_MONOTONIC, mode); 1989 hrtimer_init_on_stack(&t.timer, clock, mode);
1803 hrtimer_set_expires_range_ns(&t.timer, *expires, delta); 1990 hrtimer_set_expires_range_ns(&t.timer, *expires, delta);
1804 1991
1805 hrtimer_init_sleeper(&t, current); 1992 hrtimer_init_sleeper(&t, current);
@@ -1818,6 +2005,41 @@ int __sched schedule_hrtimeout_range(ktime_t *expires, unsigned long delta,
1818 2005
1819 return !t.task ? 0 : -EINTR; 2006 return !t.task ? 0 : -EINTR;
1820} 2007}
2008
2009/**
2010 * schedule_hrtimeout_range - sleep until timeout
2011 * @expires: timeout value (ktime_t)
2012 * @delta: slack in expires timeout (ktime_t)
2013 * @mode: timer mode, HRTIMER_MODE_ABS or HRTIMER_MODE_REL
2014 *
2015 * Make the current task sleep until the given expiry time has
2016 * elapsed. The routine will return immediately unless
2017 * the current task state has been set (see set_current_state()).
2018 *
2019 * The @delta argument gives the kernel the freedom to schedule the
2020 * actual wakeup to a time that is both power and performance friendly.
2021 * The kernel give the normal best effort behavior for "@expires+@delta",
2022 * but may decide to fire the timer earlier, but no earlier than @expires.
2023 *
2024 * You can set the task state as follows -
2025 *
2026 * %TASK_UNINTERRUPTIBLE - at least @timeout time is guaranteed to
2027 * pass before the routine returns.
2028 *
2029 * %TASK_INTERRUPTIBLE - the routine may return early if a signal is
2030 * delivered to the current task.
2031 *
2032 * The current task state is guaranteed to be TASK_RUNNING when this
2033 * routine returns.
2034 *
2035 * Returns 0 when the timer has expired otherwise -EINTR
2036 */
2037int __sched schedule_hrtimeout_range(ktime_t *expires, unsigned long delta,
2038 const enum hrtimer_mode mode)
2039{
2040 return schedule_hrtimeout_range_clock(expires, delta, mode,
2041 CLOCK_MONOTONIC);
2042}
1821EXPORT_SYMBOL_GPL(schedule_hrtimeout_range); 2043EXPORT_SYMBOL_GPL(schedule_hrtimeout_range);
1822 2044
1823/** 2045/**