History

hrtimer: Consolidate hrtimer_init() + hrtimer_init_sleeper() calls

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 ]

Sebastian Andrzej Siewior committed 7 years ago

Commit dbc16251 parent b7449487 files · +55 −30Browse files

Unified · Split

7 files
  1. block/blk-mq.c +1 −2
  2. drivers/staging/android/vsoc.c +2 −4
  3. include/linux/hrtimer.h +14 −3
  4. include/linux/wait.h +2 −2
  5. kernel/futex.c +3 −5
  6. kernel/time/hrtimer.c +32 −11
  7. net/core/pktgen.c +1 −3
block/blk-mq.c+1−2
@@ -3415,10 +3415,9 @@ static bool blk_mq_poll_hybrid_sleep(struct request_queue *q, · 3414 unmodified lines
34153415 kt = nsecs;
34163416
34173417 mode = HRTIMER_MODE_REL;
3418− hrtimer_init_on_stack(&hs.timer, CLOCK_MONOTONIC, mode);
3418+ hrtimer_init_sleeper_on_stack(&hs, CLOCK_MONOTONIC, mode);
34193419 hrtimer_set_expires(&hs.timer, kt);
34203420
3421− hrtimer_init_sleeper(&hs);
34223421 do {
34233422 if (blk_mq_rq_state(rq) == MQ_RQ_COMPLETE)
34243423 break;
drivers/staging/android/vsoc.c+2−4
@@ -437,12 +437,10 @@ static int handle_vsoc_cond_wait(struct file *filp, struct vsoc_cond_wait *arg) · 436 unmodified lines
437437 return -EINVAL;
438438 wake_time = ktime_set(arg->wake_time_sec, arg->wake_time_nsec);
439439
440− hrtimer_init_on_stack(&to->timer, CLOCK_MONOTONIC,
441− HRTIMER_MODE_ABS);
440+ hrtimer_init_sleeper_on_stack(to, CLOCK_MONOTONIC,
441+ HRTIMER_MODE_ABS);
442442 hrtimer_set_expires_range_ns(&to->timer, wake_time,
443443 current->timer_slack_ns);
444−
445− hrtimer_init_sleeper(to);
446444 }
447445
448446 while (1) {
include/linux/hrtimer.h+14−3
@@ -347,10 +347,15 @@ DECLARE_PER_CPU(struct tick_device, tick_cpu_device); · 346 unmodified lines
347347 /* Initialize timers: */
348348 extern void hrtimer_init(struct hrtimer *timer, clockid_t which_clock,
349349 enum hrtimer_mode mode);
350+extern void hrtimer_init_sleeper(struct hrtimer_sleeper *sl, clockid_t clock_id,
351+ enum hrtimer_mode mode);
350352
351353 #ifdef CONFIG_DEBUG_OBJECTS_TIMERS
352354 extern void hrtimer_init_on_stack(struct hrtimer *timer, clockid_t which_clock,
353355 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);
354359
355360 extern void destroy_hrtimer_on_stack(struct hrtimer *timer);
356361 #else
@@ -360,6 +365,14 @@ static inline void hrtimer_init_on_stack(struct hrtimer *timer, · 3 unmodified lines
360365 {
361366 hrtimer_init(timer, which_clock, mode);
362367 }
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+
363376 static inline void destroy_hrtimer_on_stack(struct hrtimer *timer) { }
364377 #endif
365378
@@ -463,10 +476,8 @@ extern long hrtimer_nanosleep(const struct timespec64 *rqtp, · 97 unmodified lines
463476 const enum hrtimer_mode mode,
464477 const clockid_t clockid);
465478
466−extern void hrtimer_init_sleeper(struct hrtimer_sleeper *sl);
467−
468479 extern int schedule_hrtimeout_range(ktime_t *expires, u64 delta,
469− const enum hrtimer_mode mode);
480+ const enum hrtimer_mode mode);
470481 extern int schedule_hrtimeout_range_clock(ktime_t *expires,
471482 u64 delta,
472483 const enum hrtimer_mode mode,
include/linux/wait.h+2−2
@@ -488,8 +488,8 @@ do { \ · 487 unmodified lines
488488 int __ret = 0; \
489489 struct hrtimer_sleeper __t; \
490490 \
491− hrtimer_init_on_stack(&__t.timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); \
492− hrtimer_init_sleeper(&__t); \
491+ hrtimer_init_sleeper_on_stack(&__t, CLOCK_MONOTONIC, \
492+ HRTIMER_MODE_REL); \
493493 if ((timeout) != KTIME_MAX) \
494494 hrtimer_start_range_ns(&__t.timer, timeout, \
495495 current->timer_slack_ns, \
kernel/futex.c+3−5
@@ -487,11 +487,9 @@ futex_setup_timer(ktime_t *time, struct hrtimer_sleeper *timeout, · 486 unmodified lines
487487 if (!time)
488488 return NULL;
489489
490− hrtimer_init_on_stack(&timeout->timer, (flags & FLAGS_CLOCKRT) ?
491− CLOCK_REALTIME : CLOCK_MONOTONIC,
492− HRTIMER_MODE_ABS);
493− hrtimer_init_sleeper(timeout);
494−
490+ hrtimer_init_sleeper_on_stack(timeout, (flags & FLAGS_CLOCKRT) ?
491+ CLOCK_REALTIME : CLOCK_MONOTONIC,
492+ HRTIMER_MODE_ABS);
495493 /*
496494 * If range_ns is 0, calling hrtimer_set_expires_range_ns() is
497495 * effectively the same as calling hrtimer_set_expires().
kernel/time/hrtimer.c+32−11
@@ -427,6 +427,17 @@ void hrtimer_init_on_stack(struct hrtimer *timer, clockid_t clock_id, · 426 unmodified lines
427427 }
428428 EXPORT_SYMBOL_GPL(hrtimer_init_on_stack);
429429
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+
430441 void destroy_hrtimer_on_stack(struct hrtimer *timer)
431442 {
432443 debug_object_free(timer, &hrtimer_debug_descr);
@@ -1639,11 +1650,27 @@ static enum hrtimer_restart hrtimer_wakeup(struct hrtimer *timer) · 1206 unmodified lines
16391650 return HRTIMER_NORESTART;
16401651 }
16411652
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)
16431655 {
1656+ __hrtimer_init(&sl->timer, clock_id, mode);
16441657 sl->timer.function = hrtimer_wakeup;
16451658 sl->task = current;
16461659 }
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+}
16471674 EXPORT_SYMBOL_GPL(hrtimer_init_sleeper);
16481675
16491676 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
16691696 {
16701697 struct restart_block *restart;
16711698
1672− hrtimer_init_sleeper(t);
1673−
16741699 do {
16751700 set_current_state(TASK_INTERRUPTIBLE);
16761701 hrtimer_start_expires(&t->timer, mode);
@@ -1707,10 +1732,9 @@ static long __sched hrtimer_nanosleep_restart(struct restart_block *restart) · 30 unmodified lines
17071732 struct hrtimer_sleeper t;
17081733 int ret;
17091734
1710− hrtimer_init_on_stack(&t.timer, restart->nanosleep.clockid,
1711− HRTIMER_MODE_ABS);
1735+ hrtimer_init_sleeper_on_stack(&t, restart->nanosleep.clockid,
1736+ HRTIMER_MODE_ABS);
17121737 hrtimer_set_expires_tv64(&t.timer, restart->nanosleep.expires);
1713−
17141738 ret = do_nanosleep(&t, HRTIMER_MODE_ABS);
17151739 destroy_hrtimer_on_stack(&t.timer);
17161740 return ret;
@@ -1728,7 +1752,7 @@ long hrtimer_nanosleep(const struct timespec64 *rqtp, · 11 unmodified lines
17281752 if (dl_task(current) || rt_task(current))
17291753 slack = 0;
17301754
1731− hrtimer_init_on_stack(&t.timer, clockid, mode);
1755+ hrtimer_init_sleeper_on_stack(&t, clockid, mode);
17321756 hrtimer_set_expires_range_ns(&t.timer, timespec64_to_ktime(*rqtp), slack);
17331757 ret = do_nanosleep(&t, mode);
17341758 if (ret != -ERESTART_RESTARTBLOCK)
@@ -1927,11 +1951,8 @@ schedule_hrtimeout_range_clock(ktime_t *expires, u64 delta, · 192 unmodified lines
19271951 return -EINTR;
19281952 }
19291953
1930− hrtimer_init_on_stack(&t.timer, clock_id, mode);
1954+ hrtimer_init_sleeper_on_stack(&t, clock_id, mode);
19311955 hrtimer_set_expires_range_ns(&t.timer, *expires, delta);
1932−
1933− hrtimer_init_sleeper(&t);
1934−
19351956 hrtimer_start_expires(&t.timer, mode);
19361957
19371958 if (likely(t.task))
net/core/pktgen.c+1−3
@@ -2156,7 +2156,7 @@ static void spin(struct pktgen_dev *pkt_dev, ktime_t spin_until) · 2155 unmodified lines
21562156 s64 remaining;
21572157 struct hrtimer_sleeper t;
21582158
2159− hrtimer_init_on_stack(&t.timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
2159+ hrtimer_init_sleeper_on_stack(&t, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
21602160 hrtimer_set_expires(&t.timer, spin_until);
21612161
21622162 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
21702170 end_time = ktime_get();
21712171 } while (ktime_compare(end_time, spin_until) < 0);
21722172 } else {
2173− /* see do_nanosleep */
2174− hrtimer_init_sleeper(&t);
21752173 do {
21762174 set_current_state(TASK_INTERRUPTIBLE);
21772175 hrtimer_start_expires(&t.timer, HRTIMER_MODE_ABS);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t