Commit dbc1625f authored by Sebastian Andrzej Siewior's avatar Sebastian Andrzej Siewior Committed by Thomas Gleixner

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 ]
Signed-off-by: default avatarSebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: default avatarAnna-Maria Gleixner <anna-maria@linutronix.de>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Acked-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20190726185752.887468908@linutronix.de
parent b7449487
...@@ -3415,10 +3415,9 @@ static bool blk_mq_poll_hybrid_sleep(struct request_queue *q, ...@@ -3415,10 +3415,9 @@ static bool blk_mq_poll_hybrid_sleep(struct request_queue *q,
kt = nsecs; kt = nsecs;
mode = HRTIMER_MODE_REL; mode = HRTIMER_MODE_REL;
hrtimer_init_on_stack(&hs.timer, CLOCK_MONOTONIC, mode); hrtimer_init_sleeper_on_stack(&hs, CLOCK_MONOTONIC, mode);
hrtimer_set_expires(&hs.timer, kt); hrtimer_set_expires(&hs.timer, kt);
hrtimer_init_sleeper(&hs);
do { do {
if (blk_mq_rq_state(rq) == MQ_RQ_COMPLETE) if (blk_mq_rq_state(rq) == MQ_RQ_COMPLETE)
break; break;
......
...@@ -437,12 +437,10 @@ static int handle_vsoc_cond_wait(struct file *filp, struct vsoc_cond_wait *arg) ...@@ -437,12 +437,10 @@ static int handle_vsoc_cond_wait(struct file *filp, struct vsoc_cond_wait *arg)
return -EINVAL; return -EINVAL;
wake_time = ktime_set(arg->wake_time_sec, arg->wake_time_nsec); wake_time = ktime_set(arg->wake_time_sec, arg->wake_time_nsec);
hrtimer_init_on_stack(&to->timer, CLOCK_MONOTONIC, hrtimer_init_sleeper_on_stack(to, CLOCK_MONOTONIC,
HRTIMER_MODE_ABS); HRTIMER_MODE_ABS);
hrtimer_set_expires_range_ns(&to->timer, wake_time, hrtimer_set_expires_range_ns(&to->timer, wake_time,
current->timer_slack_ns); current->timer_slack_ns);
hrtimer_init_sleeper(to);
} }
while (1) { while (1) {
......
...@@ -347,10 +347,15 @@ DECLARE_PER_CPU(struct tick_device, tick_cpu_device); ...@@ -347,10 +347,15 @@ DECLARE_PER_CPU(struct tick_device, tick_cpu_device);
/* Initialize timers: */ /* Initialize timers: */
extern void hrtimer_init(struct hrtimer *timer, clockid_t which_clock, extern void hrtimer_init(struct hrtimer *timer, clockid_t which_clock,
enum hrtimer_mode mode); enum hrtimer_mode mode);
extern void hrtimer_init_sleeper(struct hrtimer_sleeper *sl, clockid_t clock_id,
enum hrtimer_mode mode);
#ifdef CONFIG_DEBUG_OBJECTS_TIMERS #ifdef CONFIG_DEBUG_OBJECTS_TIMERS
extern void hrtimer_init_on_stack(struct hrtimer *timer, clockid_t which_clock, extern void hrtimer_init_on_stack(struct hrtimer *timer, clockid_t which_clock,
enum hrtimer_mode mode); enum hrtimer_mode mode);
extern void hrtimer_init_sleeper_on_stack(struct hrtimer_sleeper *sl,
clockid_t clock_id,
enum hrtimer_mode mode);
extern void destroy_hrtimer_on_stack(struct hrtimer *timer); extern void destroy_hrtimer_on_stack(struct hrtimer *timer);
#else #else
...@@ -360,6 +365,14 @@ static inline void hrtimer_init_on_stack(struct hrtimer *timer, ...@@ -360,6 +365,14 @@ static inline void hrtimer_init_on_stack(struct hrtimer *timer,
{ {
hrtimer_init(timer, which_clock, mode); hrtimer_init(timer, which_clock, mode);
} }
static inline void hrtimer_init_sleeper_on_stack(struct hrtimer_sleeper *sl,
clockid_t clock_id,
enum hrtimer_mode mode)
{
hrtimer_init_sleeper(sl, clock_id, mode);
}
static inline void destroy_hrtimer_on_stack(struct hrtimer *timer) { } static inline void destroy_hrtimer_on_stack(struct hrtimer *timer) { }
#endif #endif
...@@ -463,10 +476,8 @@ extern long hrtimer_nanosleep(const struct timespec64 *rqtp, ...@@ -463,10 +476,8 @@ extern long hrtimer_nanosleep(const struct timespec64 *rqtp,
const enum hrtimer_mode mode, const enum hrtimer_mode mode,
const clockid_t clockid); const clockid_t clockid);
extern void hrtimer_init_sleeper(struct hrtimer_sleeper *sl);
extern int schedule_hrtimeout_range(ktime_t *expires, u64 delta, extern int schedule_hrtimeout_range(ktime_t *expires, u64 delta,
const enum hrtimer_mode mode); const enum hrtimer_mode mode);
extern int schedule_hrtimeout_range_clock(ktime_t *expires, extern int schedule_hrtimeout_range_clock(ktime_t *expires,
u64 delta, u64 delta,
const enum hrtimer_mode mode, const enum hrtimer_mode mode,
......
...@@ -488,8 +488,8 @@ do { \ ...@@ -488,8 +488,8 @@ do { \
int __ret = 0; \ int __ret = 0; \
struct hrtimer_sleeper __t; \ struct hrtimer_sleeper __t; \
\ \
hrtimer_init_on_stack(&__t.timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); \ hrtimer_init_sleeper_on_stack(&__t, CLOCK_MONOTONIC, \
hrtimer_init_sleeper(&__t); \ HRTIMER_MODE_REL); \
if ((timeout) != KTIME_MAX) \ if ((timeout) != KTIME_MAX) \
hrtimer_start_range_ns(&__t.timer, timeout, \ hrtimer_start_range_ns(&__t.timer, timeout, \
current->timer_slack_ns, \ current->timer_slack_ns, \
......
...@@ -487,11 +487,9 @@ futex_setup_timer(ktime_t *time, struct hrtimer_sleeper *timeout, ...@@ -487,11 +487,9 @@ futex_setup_timer(ktime_t *time, struct hrtimer_sleeper *timeout,
if (!time) if (!time)
return NULL; return NULL;
hrtimer_init_on_stack(&timeout->timer, (flags & FLAGS_CLOCKRT) ? hrtimer_init_sleeper_on_stack(timeout, (flags & FLAGS_CLOCKRT) ?
CLOCK_REALTIME : CLOCK_MONOTONIC, CLOCK_REALTIME : CLOCK_MONOTONIC,
HRTIMER_MODE_ABS); HRTIMER_MODE_ABS);
hrtimer_init_sleeper(timeout);
/* /*
* If range_ns is 0, calling hrtimer_set_expires_range_ns() is * If range_ns is 0, calling hrtimer_set_expires_range_ns() is
* effectively the same as calling hrtimer_set_expires(). * effectively the same as calling hrtimer_set_expires().
......
...@@ -427,6 +427,17 @@ void hrtimer_init_on_stack(struct hrtimer *timer, clockid_t clock_id, ...@@ -427,6 +427,17 @@ void hrtimer_init_on_stack(struct hrtimer *timer, clockid_t clock_id,
} }
EXPORT_SYMBOL_GPL(hrtimer_init_on_stack); EXPORT_SYMBOL_GPL(hrtimer_init_on_stack);
static void __hrtimer_init_sleeper(struct hrtimer_sleeper *sl,
clockid_t clock_id, enum hrtimer_mode mode);
void hrtimer_init_sleeper_on_stack(struct hrtimer_sleeper *sl,
clockid_t clock_id, enum hrtimer_mode mode)
{
debug_object_init_on_stack(&sl->timer, &hrtimer_debug_descr);
__hrtimer_init_sleeper(sl, clock_id, mode);
}
EXPORT_SYMBOL_GPL(hrtimer_init_sleeper_on_stack);
void destroy_hrtimer_on_stack(struct hrtimer *timer) void destroy_hrtimer_on_stack(struct hrtimer *timer)
{ {
debug_object_free(timer, &hrtimer_debug_descr); debug_object_free(timer, &hrtimer_debug_descr);
...@@ -1639,11 +1650,27 @@ static enum hrtimer_restart hrtimer_wakeup(struct hrtimer *timer) ...@@ -1639,11 +1650,27 @@ static enum hrtimer_restart hrtimer_wakeup(struct hrtimer *timer)
return HRTIMER_NORESTART; return HRTIMER_NORESTART;
} }
void hrtimer_init_sleeper(struct hrtimer_sleeper *sl) static void __hrtimer_init_sleeper(struct hrtimer_sleeper *sl,
clockid_t clock_id, enum hrtimer_mode mode)
{ {
__hrtimer_init(&sl->timer, clock_id, mode);
sl->timer.function = hrtimer_wakeup; sl->timer.function = hrtimer_wakeup;
sl->task = current; sl->task = current;
} }
/**
* hrtimer_init_sleeper - initialize sleeper to the given clock
* @sl: sleeper to be initialized
* @clock_id: the clock to be used
* @mode: timer mode abs/rel
*/
void hrtimer_init_sleeper(struct hrtimer_sleeper *sl, clockid_t clock_id,
enum hrtimer_mode mode)
{
debug_init(&sl->timer, clock_id, mode);
__hrtimer_init_sleeper(sl, clock_id, mode);
}
EXPORT_SYMBOL_GPL(hrtimer_init_sleeper); EXPORT_SYMBOL_GPL(hrtimer_init_sleeper);
int nanosleep_copyout(struct restart_block *restart, struct timespec64 *ts) 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 ...@@ -1669,8 +1696,6 @@ static int __sched do_nanosleep(struct hrtimer_sleeper *t, enum hrtimer_mode mod
{ {
struct restart_block *restart; struct restart_block *restart;
hrtimer_init_sleeper(t);
do { do {
set_current_state(TASK_INTERRUPTIBLE); set_current_state(TASK_INTERRUPTIBLE);
hrtimer_start_expires(&t->timer, mode); hrtimer_start_expires(&t->timer, mode);
...@@ -1707,10 +1732,9 @@ static long __sched hrtimer_nanosleep_restart(struct restart_block *restart) ...@@ -1707,10 +1732,9 @@ static long __sched hrtimer_nanosleep_restart(struct restart_block *restart)
struct hrtimer_sleeper t; struct hrtimer_sleeper t;
int ret; int ret;
hrtimer_init_on_stack(&t.timer, restart->nanosleep.clockid, hrtimer_init_sleeper_on_stack(&t, restart->nanosleep.clockid,
HRTIMER_MODE_ABS); HRTIMER_MODE_ABS);
hrtimer_set_expires_tv64(&t.timer, restart->nanosleep.expires); hrtimer_set_expires_tv64(&t.timer, restart->nanosleep.expires);
ret = do_nanosleep(&t, HRTIMER_MODE_ABS); ret = do_nanosleep(&t, HRTIMER_MODE_ABS);
destroy_hrtimer_on_stack(&t.timer); destroy_hrtimer_on_stack(&t.timer);
return ret; return ret;
...@@ -1728,7 +1752,7 @@ long hrtimer_nanosleep(const struct timespec64 *rqtp, ...@@ -1728,7 +1752,7 @@ long hrtimer_nanosleep(const struct timespec64 *rqtp,
if (dl_task(current) || rt_task(current)) if (dl_task(current) || rt_task(current))
slack = 0; slack = 0;
hrtimer_init_on_stack(&t.timer, clockid, mode); hrtimer_init_sleeper_on_stack(&t, clockid, mode);
hrtimer_set_expires_range_ns(&t.timer, timespec64_to_ktime(*rqtp), slack); hrtimer_set_expires_range_ns(&t.timer, timespec64_to_ktime(*rqtp), slack);
ret = do_nanosleep(&t, mode); ret = do_nanosleep(&t, mode);
if (ret != -ERESTART_RESTARTBLOCK) if (ret != -ERESTART_RESTARTBLOCK)
...@@ -1927,11 +1951,8 @@ schedule_hrtimeout_range_clock(ktime_t *expires, u64 delta, ...@@ -1927,11 +1951,8 @@ schedule_hrtimeout_range_clock(ktime_t *expires, u64 delta,
return -EINTR; return -EINTR;
} }
hrtimer_init_on_stack(&t.timer, clock_id, mode); hrtimer_init_sleeper_on_stack(&t, clock_id, mode);
hrtimer_set_expires_range_ns(&t.timer, *expires, delta); hrtimer_set_expires_range_ns(&t.timer, *expires, delta);
hrtimer_init_sleeper(&t);
hrtimer_start_expires(&t.timer, mode); hrtimer_start_expires(&t.timer, mode);
if (likely(t.task)) if (likely(t.task))
......
...@@ -2156,7 +2156,7 @@ static void spin(struct pktgen_dev *pkt_dev, ktime_t spin_until) ...@@ -2156,7 +2156,7 @@ static void spin(struct pktgen_dev *pkt_dev, ktime_t spin_until)
s64 remaining; s64 remaining;
struct hrtimer_sleeper t; struct hrtimer_sleeper t;
hrtimer_init_on_stack(&t.timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); hrtimer_init_sleeper_on_stack(&t, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
hrtimer_set_expires(&t.timer, spin_until); hrtimer_set_expires(&t.timer, spin_until);
remaining = ktime_to_ns(hrtimer_expires_remaining(&t.timer)); 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) ...@@ -2170,8 +2170,6 @@ static void spin(struct pktgen_dev *pkt_dev, ktime_t spin_until)
end_time = ktime_get(); end_time = ktime_get();
} while (ktime_compare(end_time, spin_until) < 0); } while (ktime_compare(end_time, spin_until) < 0);
} else { } else {
/* see do_nanosleep */
hrtimer_init_sleeper(&t);
do { do {
set_current_state(TASK_INTERRUPTIBLE); set_current_state(TASK_INTERRUPTIBLE);
hrtimer_start_expires(&t.timer, HRTIMER_MODE_ABS); hrtimer_start_expires(&t.timer, HRTIMER_MODE_ABS);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment