hrtimer_init_sleeper() calls require prior initialisation of the hrtimer object which is embedded into the hrtimer_sleeper. Combine the initialization and spare a function call. Fixup all call sites. This is also a preparatory change for PREEMPT_RT to do hrtimer sleeper specific initializations of the embedded hrtimer without modifying any of the call sites. No functional change. [ anna-maria: Minor cleanups ] [ tglx: Adopted to the removal of the task argument of hrtimer_init_sleeper() and trivial polishing. Folded a fix from Stephen Rothwell for the vsoc code ]
Unified · Split
| @@ -3415,10 +3415,9 @@ static bool blk_mq_poll_hybrid_sleep(struct request_queue *q, · 3414 unmodified lines | |||
| 3415 | kt = nsecs; | 3415 | kt = nsecs; |
| 3416 | 3416 | ||
| 3417 | mode = HRTIMER_MODE_REL; | 3417 | mode = HRTIMER_MODE_REL; |
| 3418 | hrtimer_init_on_stack(&hs.timer, CLOCK_MONOTONIC, mode); | 3418 | hrtimer_init_sleeper_on_stack(&hs, CLOCK_MONOTONIC, mode); |
| 3419 | hrtimer_set_expires(&hs.timer, kt); | 3419 | hrtimer_set_expires(&hs.timer, kt); |
| 3420 | 3420 | ||
| 3421 | hrtimer_init_sleeper(&hs); | ||
| 3422 | do { | 3421 | do { |
| 3423 | if (blk_mq_rq_state(rq) == MQ_RQ_COMPLETE) | 3422 | if (blk_mq_rq_state(rq) == MQ_RQ_COMPLETE) |
| 3424 | break; | 3423 | break; |
| @@ -437,12 +437,10 @@ static int handle_vsoc_cond_wait(struct file *filp, struct vsoc_cond_wait *arg) · 436 unmodified lines | |||
| 437 | return -EINVAL; | 437 | return -EINVAL; |
| 438 | wake_time = ktime_set(arg->wake_time_sec, arg->wake_time_nsec); | 438 | wake_time = ktime_set(arg->wake_time_sec, arg->wake_time_nsec); |
| 439 | 439 | ||
| 440 | hrtimer_init_on_stack(&to->timer, CLOCK_MONOTONIC, | 440 | hrtimer_init_sleeper_on_stack(to, CLOCK_MONOTONIC, |
| 441 | HRTIMER_MODE_ABS); | 441 | HRTIMER_MODE_ABS); |
| 442 | hrtimer_set_expires_range_ns(&to->timer, wake_time, | 442 | hrtimer_set_expires_range_ns(&to->timer, wake_time, |
| 443 | current->timer_slack_ns); | 443 | current->timer_slack_ns); |
| 444 | |||
| 445 | hrtimer_init_sleeper(to); | ||
| 446 | } | 444 | } |
| 447 | 445 | ||
| 448 | while (1) { | 446 | while (1) { |
| @@ -347,10 +347,15 @@ DECLARE_PER_CPU(struct tick_device, tick_cpu_device); · 346 unmodified lines | |||
| 347 | /* Initialize timers: */ | 347 | /* Initialize timers: */ |
| 348 | extern void hrtimer_init(struct hrtimer *timer, clockid_t which_clock, | 348 | extern void hrtimer_init(struct hrtimer *timer, clockid_t which_clock, |
| 349 | enum hrtimer_mode mode); | 349 | enum hrtimer_mode mode); |
| 350 | extern void hrtimer_init_sleeper(struct hrtimer_sleeper *sl, clockid_t clock_id, | ||
| 351 | enum hrtimer_mode mode); | ||
| 350 | 352 | ||
| 351 | #ifdef CONFIG_DEBUG_OBJECTS_TIMERS | 353 | #ifdef CONFIG_DEBUG_OBJECTS_TIMERS |
| 352 | extern void hrtimer_init_on_stack(struct hrtimer *timer, clockid_t which_clock, | 354 | extern void hrtimer_init_on_stack(struct hrtimer *timer, clockid_t which_clock, |
| 353 | enum hrtimer_mode mode); | 355 | enum hrtimer_mode mode); |
| 356 | extern void hrtimer_init_sleeper_on_stack(struct hrtimer_sleeper *sl, | ||
| 357 | clockid_t clock_id, | ||
| 358 | enum hrtimer_mode mode); | ||
| 354 | 359 | ||
| 355 | extern void destroy_hrtimer_on_stack(struct hrtimer *timer); | 360 | extern void destroy_hrtimer_on_stack(struct hrtimer *timer); |
| 356 | #else | 361 | #else |
| @@ -360,6 +365,14 @@ static inline void hrtimer_init_on_stack(struct hrtimer *timer, · 3 unmodified lines | |||
| 360 | { | 365 | { |
| 361 | hrtimer_init(timer, which_clock, mode); | 366 | hrtimer_init(timer, which_clock, mode); |
| 362 | } | 367 | } |
| 368 | |||
| 369 | static inline void hrtimer_init_sleeper_on_stack(struct hrtimer_sleeper *sl, | ||
| 370 | clockid_t clock_id, | ||
| 371 | enum hrtimer_mode mode) | ||
| 372 | { | ||
| 373 | hrtimer_init_sleeper(sl, clock_id, mode); | ||
| 374 | } | ||
| 375 | |||
| 363 | static inline void destroy_hrtimer_on_stack(struct hrtimer *timer) { } | 376 | static inline void destroy_hrtimer_on_stack(struct hrtimer *timer) { } |
| 364 | #endif | 377 | #endif |
| 365 | 378 | ||
| @@ -463,10 +476,8 @@ extern long hrtimer_nanosleep(const struct timespec64 *rqtp, · 97 unmodified lines | |||
| 463 | const enum hrtimer_mode mode, | 476 | const enum hrtimer_mode mode, |
| 464 | const clockid_t clockid); | 477 | const clockid_t clockid); |
| 465 | 478 | ||
| 466 | extern void hrtimer_init_sleeper(struct hrtimer_sleeper *sl); | ||
| 467 | |||
| 468 | extern int schedule_hrtimeout_range(ktime_t *expires, u64 delta, | 479 | extern int schedule_hrtimeout_range(ktime_t *expires, u64 delta, |
| 469 | const enum hrtimer_mode mode); | 480 | const enum hrtimer_mode mode); |
| 470 | extern int schedule_hrtimeout_range_clock(ktime_t *expires, | 481 | extern int schedule_hrtimeout_range_clock(ktime_t *expires, |
| 471 | u64 delta, | 482 | u64 delta, |
| 472 | const enum hrtimer_mode mode, | 483 | const enum hrtimer_mode mode, |
| @@ -488,8 +488,8 @@ do { \ · 487 unmodified lines | |||
| 488 | int __ret = 0; \ | 488 | int __ret = 0; \ |
| 489 | struct hrtimer_sleeper __t; \ | 489 | struct hrtimer_sleeper __t; \ |
| 490 | \ | 490 | \ |
| 491 | hrtimer_init_on_stack(&__t.timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); \ | 491 | hrtimer_init_sleeper_on_stack(&__t, CLOCK_MONOTONIC, \ |
| 492 | hrtimer_init_sleeper(&__t); \ | 492 | HRTIMER_MODE_REL); \ |
| 493 | if ((timeout) != KTIME_MAX) \ | 493 | if ((timeout) != KTIME_MAX) \ |
| 494 | hrtimer_start_range_ns(&__t.timer, timeout, \ | 494 | hrtimer_start_range_ns(&__t.timer, timeout, \ |
| 495 | current->timer_slack_ns, \ | 495 | current->timer_slack_ns, \ |
| @@ -487,11 +487,9 @@ futex_setup_timer(ktime_t *time, struct hrtimer_sleeper *timeout, · 486 unmodified lines | |||
| 487 | if (!time) | 487 | if (!time) |
| 488 | return NULL; | 488 | return NULL; |
| 489 | 489 | ||
| 490 | hrtimer_init_on_stack(&timeout->timer, (flags & FLAGS_CLOCKRT) ? | 490 | hrtimer_init_sleeper_on_stack(timeout, (flags & FLAGS_CLOCKRT) ? |
| 491 | CLOCK_REALTIME : CLOCK_MONOTONIC, | 491 | CLOCK_REALTIME : CLOCK_MONOTONIC, |
| 492 | HRTIMER_MODE_ABS); | 492 | HRTIMER_MODE_ABS); |
| 493 | hrtimer_init_sleeper(timeout); | ||
| 494 | |||
| 495 | /* | 493 | /* |
| 496 | * If range_ns is 0, calling hrtimer_set_expires_range_ns() is | 494 | * If range_ns is 0, calling hrtimer_set_expires_range_ns() is |
| 497 | * effectively the same as calling hrtimer_set_expires(). | 495 | * effectively the same as calling hrtimer_set_expires(). |
| @@ -427,6 +427,17 @@ void hrtimer_init_on_stack(struct hrtimer *timer, clockid_t clock_id, · 426 unmodified lines | |||
| 427 | } | 427 | } |
| 428 | EXPORT_SYMBOL_GPL(hrtimer_init_on_stack); | 428 | EXPORT_SYMBOL_GPL(hrtimer_init_on_stack); |
| 429 | 429 | ||
| 430 | static void __hrtimer_init_sleeper(struct hrtimer_sleeper *sl, | ||
| 431 | clockid_t clock_id, enum hrtimer_mode mode); | ||
| 432 | |||
| 433 | void hrtimer_init_sleeper_on_stack(struct hrtimer_sleeper *sl, | ||
| 434 | clockid_t clock_id, enum hrtimer_mode mode) | ||
| 435 | { | ||
| 436 | debug_object_init_on_stack(&sl->timer, &hrtimer_debug_descr); | ||
| 437 | __hrtimer_init_sleeper(sl, clock_id, mode); | ||
| 438 | } | ||
| 439 | EXPORT_SYMBOL_GPL(hrtimer_init_sleeper_on_stack); | ||
| 440 | |||
| 430 | void destroy_hrtimer_on_stack(struct hrtimer *timer) | 441 | void destroy_hrtimer_on_stack(struct hrtimer *timer) |
| 431 | { | 442 | { |
| 432 | debug_object_free(timer, &hrtimer_debug_descr); | 443 | debug_object_free(timer, &hrtimer_debug_descr); |
| @@ -1639,11 +1650,27 @@ static enum hrtimer_restart hrtimer_wakeup(struct hrtimer *timer) · 1206 unmodified lines | |||
| 1639 | return HRTIMER_NORESTART; | 1650 | return HRTIMER_NORESTART; |
| 1640 | } | 1651 | } |
| 1641 | 1652 | ||
| 1642 | void hrtimer_init_sleeper(struct hrtimer_sleeper *sl) | 1653 | static void __hrtimer_init_sleeper(struct hrtimer_sleeper *sl, |
| 1654 | clockid_t clock_id, enum hrtimer_mode mode) | ||
| 1643 | { | 1655 | { |
| 1656 | __hrtimer_init(&sl->timer, clock_id, mode); | ||
| 1644 | sl->timer.function = hrtimer_wakeup; | 1657 | sl->timer.function = hrtimer_wakeup; |
| 1645 | sl->task = current; | 1658 | sl->task = current; |
| 1646 | } | 1659 | } |
| 1660 | |||
| 1661 | /** | ||
| 1662 | * hrtimer_init_sleeper - initialize sleeper to the given clock | ||
| 1663 | * @sl: sleeper to be initialized | ||
| 1664 | * @clock_id: the clock to be used | ||
| 1665 | * @mode: timer mode abs/rel | ||
| 1666 | */ | ||
| 1667 | void hrtimer_init_sleeper(struct hrtimer_sleeper *sl, clockid_t clock_id, | ||
| 1668 | enum hrtimer_mode mode) | ||
| 1669 | { | ||
| 1670 | debug_init(&sl->timer, clock_id, mode); | ||
| 1671 | __hrtimer_init_sleeper(sl, clock_id, mode); | ||
| 1672 | |||
| 1673 | } | ||
| 1647 | EXPORT_SYMBOL_GPL(hrtimer_init_sleeper); | 1674 | EXPORT_SYMBOL_GPL(hrtimer_init_sleeper); |
| 1648 | 1675 | ||
| 1649 | int nanosleep_copyout(struct restart_block *restart, struct timespec64 *ts) | 1676 | int nanosleep_copyout(struct restart_block *restart, struct timespec64 *ts) |
| @@ -1669,8 +1696,6 @@ static int __sched do_nanosleep(struct hrtimer_sleeper *t, enum hrtimer_mode mod · 19 unmodified lines | |||
| 1669 | { | 1696 | { |
| 1670 | struct restart_block *restart; | 1697 | struct restart_block *restart; |
| 1671 | 1698 | ||
| 1672 | hrtimer_init_sleeper(t); | ||
| 1673 | |||
| 1674 | do { | 1699 | do { |
| 1675 | set_current_state(TASK_INTERRUPTIBLE); | 1700 | set_current_state(TASK_INTERRUPTIBLE); |
| 1676 | hrtimer_start_expires(&t->timer, mode); | 1701 | hrtimer_start_expires(&t->timer, mode); |
| @@ -1707,10 +1732,9 @@ static long __sched hrtimer_nanosleep_restart(struct restart_block *restart) · 30 unmodified lines | |||
| 1707 | struct hrtimer_sleeper t; | 1732 | struct hrtimer_sleeper t; |
| 1708 | int ret; | 1733 | int ret; |
| 1709 | 1734 | ||
| 1710 | hrtimer_init_on_stack(&t.timer, restart->nanosleep.clockid, | 1735 | hrtimer_init_sleeper_on_stack(&t, restart->nanosleep.clockid, |
| 1711 | HRTIMER_MODE_ABS); | 1736 | HRTIMER_MODE_ABS); |
| 1712 | hrtimer_set_expires_tv64(&t.timer, restart->nanosleep.expires); | 1737 | hrtimer_set_expires_tv64(&t.timer, restart->nanosleep.expires); |
| 1713 | |||
| 1714 | ret = do_nanosleep(&t, HRTIMER_MODE_ABS); | 1738 | ret = do_nanosleep(&t, HRTIMER_MODE_ABS); |
| 1715 | destroy_hrtimer_on_stack(&t.timer); | 1739 | destroy_hrtimer_on_stack(&t.timer); |
| 1716 | return ret; | 1740 | return ret; |
| @@ -1728,7 +1752,7 @@ long hrtimer_nanosleep(const struct timespec64 *rqtp, · 11 unmodified lines | |||
| 1728 | if (dl_task(current) || rt_task(current)) | 1752 | if (dl_task(current) || rt_task(current)) |
| 1729 | slack = 0; | 1753 | slack = 0; |
| 1730 | 1754 | ||
| 1731 | hrtimer_init_on_stack(&t.timer, clockid, mode); | 1755 | hrtimer_init_sleeper_on_stack(&t, clockid, mode); |
| 1732 | hrtimer_set_expires_range_ns(&t.timer, timespec64_to_ktime(*rqtp), slack); | 1756 | hrtimer_set_expires_range_ns(&t.timer, timespec64_to_ktime(*rqtp), slack); |
| 1733 | ret = do_nanosleep(&t, mode); | 1757 | ret = do_nanosleep(&t, mode); |
| 1734 | if (ret != -ERESTART_RESTARTBLOCK) | 1758 | if (ret != -ERESTART_RESTARTBLOCK) |
| @@ -1927,11 +1951,8 @@ schedule_hrtimeout_range_clock(ktime_t *expires, u64 delta, · 192 unmodified lines | |||
| 1927 | return -EINTR; | 1951 | return -EINTR; |
| 1928 | } | 1952 | } |
| 1929 | 1953 | ||
| 1930 | hrtimer_init_on_stack(&t.timer, clock_id, mode); | 1954 | hrtimer_init_sleeper_on_stack(&t, clock_id, mode); |
| 1931 | hrtimer_set_expires_range_ns(&t.timer, *expires, delta); | 1955 | hrtimer_set_expires_range_ns(&t.timer, *expires, delta); |
| 1932 | |||
| 1933 | hrtimer_init_sleeper(&t); | ||
| 1934 | |||
| 1935 | hrtimer_start_expires(&t.timer, mode); | 1956 | hrtimer_start_expires(&t.timer, mode); |
| 1936 | 1957 | ||
| 1937 | if (likely(t.task)) | 1958 | if (likely(t.task)) |
| @@ -2156,7 +2156,7 @@ static void spin(struct pktgen_dev *pkt_dev, ktime_t spin_until) · 2155 unmodified lines | |||
| 2156 | s64 remaining; | 2156 | s64 remaining; |
| 2157 | struct hrtimer_sleeper t; | 2157 | struct hrtimer_sleeper t; |
| 2158 | 2158 | ||
| 2159 | hrtimer_init_on_stack(&t.timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); | 2159 | hrtimer_init_sleeper_on_stack(&t, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); |
| 2160 | hrtimer_set_expires(&t.timer, spin_until); | 2160 | hrtimer_set_expires(&t.timer, spin_until); |
| 2161 | 2161 | ||
| 2162 | remaining = ktime_to_ns(hrtimer_expires_remaining(&t.timer)); | 2162 | remaining = ktime_to_ns(hrtimer_expires_remaining(&t.timer)); |
| @@ -2170,8 +2170,6 @@ static void spin(struct pktgen_dev *pkt_dev, ktime_t spin_until) · 7 unmodified lines | |||
| 2170 | end_time = ktime_get(); | 2170 | end_time = ktime_get(); |
| 2171 | } while (ktime_compare(end_time, spin_until) < 0); | 2171 | } while (ktime_compare(end_time, spin_until) < 0); |
| 2172 | } else { | 2172 | } else { |
| 2173 | /* see do_nanosleep */ | ||
| 2174 | hrtimer_init_sleeper(&t); | ||
| 2175 | do { | 2173 | do { |
| 2176 | set_current_state(TASK_INTERRUPTIBLE); | 2174 | set_current_state(TASK_INTERRUPTIBLE); |
| 2177 | hrtimer_start_expires(&t.timer, HRTIMER_MODE_ABS); | 2175 | hrtimer_start_expires(&t.timer, HRTIMER_MODE_ABS); |