[PATCH] hrtimer: consolidate hrtimer_init() + hrtimer_init_sleeper() calls

2018-07-02 Thread Anna-Maria Gleixner
From: Sebastian Andrzej Siewior 

hrtimer_init_sleeper() calls require a prior initialisation of the
hrtimer object with hrtimer_init(). Lets make the initialisation of
the hrtimer object part of hrtimer_init_sleeper(). To remain
consistent consider init_on_stack as well.

Beside adapting the hrtimer_init_sleeper[_on_stack]() functions, call
sites need to be updated as well.

Link: http://lkml.kernel.org/r/20170905135719.qsj4h5twhjkmk...@linutronix.de
Signed-off-by: Sebastian Andrzej Siewior 
[anna-maria: Updating the commit message]
Signed-off-by: Anna-Maria Gleixner 
---
 block/blk-mq.c  |  3 +--
 include/linux/hrtimer.h | 19 ++---
 include/linux/wait.h|  4 ++--
 kernel/futex.c  | 19 +++--
 kernel/time/hrtimer.c   | 46 -
 net/core/pktgen.c   |  4 ++--
 6 files changed, 65 insertions(+), 30 deletions(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index 95919268564b..f95ad9ede0f6 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -2984,10 +2984,9 @@ static bool blk_mq_poll_hybrid_sleep(struct 
request_queue *q,
kt = nsecs;
 
mode = HRTIMER_MODE_REL;
-   hrtimer_init_on_stack(&hs.timer, CLOCK_MONOTONIC, mode);
+   hrtimer_init_sleeper_on_stack(&hs, CLOCK_MONOTONIC, mode, current);
hrtimer_set_expires(&hs.timer, kt);
 
-   hrtimer_init_sleeper(&hs, current);
do {
if (blk_mq_rq_state(rq) == MQ_RQ_COMPLETE)
break;
diff --git a/include/linux/hrtimer.h b/include/linux/hrtimer.h
index 3892e9c8b2de..b8bbaabd5aff 100644
--- a/include/linux/hrtimer.h
+++ b/include/linux/hrtimer.h
@@ -364,10 +364,17 @@ DECLARE_PER_CPU(struct tick_device, tick_cpu_device);
 /* Initialize timers: */
 extern void hrtimer_init(struct hrtimer *timer, clockid_t which_clock,
 enum hrtimer_mode mode);
+extern void hrtimer_init_sleeper(struct hrtimer_sleeper *sl, clockid_t 
clock_id,
+enum hrtimer_mode mode,
+struct task_struct *task);
 
 #ifdef CONFIG_DEBUG_OBJECTS_TIMERS
 extern void hrtimer_init_on_stack(struct hrtimer *timer, clockid_t which_clock,
  enum hrtimer_mode mode);
+extern void hrtimer_init_sleeper_on_stack(struct hrtimer_sleeper *sl,
+ clockid_t clock_id,
+ enum hrtimer_mode mode,
+ struct task_struct *task);
 
 extern void destroy_hrtimer_on_stack(struct hrtimer *timer);
 #else
@@ -377,6 +384,15 @@ static inline void hrtimer_init_on_stack(struct hrtimer 
*timer,
 {
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,
+   struct task_struct *task)
+{
+   hrtimer_init_sleeper(sl, clock_id, mode, task);
+}
+
 static inline void destroy_hrtimer_on_stack(struct hrtimer *timer) { }
 #endif
 
@@ -480,9 +496,6 @@ extern long hrtimer_nanosleep(const struct timespec64 *rqtp,
  const enum hrtimer_mode mode,
  const clockid_t clockid);
 
-extern void hrtimer_init_sleeper(struct hrtimer_sleeper *sl,
-struct task_struct *tsk);
-
 extern int schedule_hrtimeout_range(ktime_t *expires, u64 delta,
const enum hrtimer_mode mode);
 extern int schedule_hrtimeout_range_clock(ktime_t *expires,
diff --git a/include/linux/wait.h b/include/linux/wait.h
index d9f131ecf708..a0938fc8dcdb 100644
--- a/include/linux/wait.h
+++ b/include/linux/wait.h
@@ -488,8 +488,8 @@ do {
\
int __ret = 0;  
\
struct hrtimer_sleeper __t; 
\

\
-   hrtimer_init_on_stack(&__t.timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);   
\
-   hrtimer_init_sleeper(&__t, current);
\
+   hrtimer_init_sleeper_on_stack(&__t, CLOCK_MONOTONIC, HRTIMER_MODE_REL,  
\
+ current); 
\
if ((timeout) != KTIME_MAX) 
\
hrtimer_start_range_ns(&__t.timer, timeout, 
\
   current->timer_slack_ns, 
\
diff --git a/kernel/futex.c b/kernel/futex.c
index 1f450e092c74..146432d78e06 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -2624,10 +2624,9 @@ static int futex_wait(u32 __user *uaddr, unsigned int 

[RFC / PATCH] hrtimer: consolidate hrtimer_init() + hrtimer_init_sleeper() calls

2017-09-05 Thread Sebastian Andrzej Siewior
hrtimer_init_sleeper() calls require a prior initialisation of the
hrtimer object with hrtimer_init(). Lets make the initialisation of the
hrtimer object part of hrtimer_init_sleeper().
This converts all users in one go. Everyone is using the on-stack
version.

Signed-off-by: Sebastian Andrzej Siewior 
---
 block/blk-mq.c  |  3 +--
 include/linux/hrtimer.h | 19 ---
 include/linux/wait.h|  4 ++--
 kernel/futex.c  | 19 ---
 kernel/time/hrtimer.c   | 46 --
 net/core/pktgen.c   |  4 ++--
 6 files changed, 65 insertions(+), 30 deletions(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index 4603b115e234..4663a2c3e7a8 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -2740,10 +2740,9 @@ static bool blk_mq_poll_hybrid_sleep(struct 
request_queue *q,
kt = nsecs;
 
mode = HRTIMER_MODE_REL;
-   hrtimer_init_on_stack(&hs.timer, CLOCK_MONOTONIC, mode);
+   hrtimer_init_sleeper_on_stack(&hs, CLOCK_MONOTONIC, mode, current);
hrtimer_set_expires(&hs.timer, kt);
 
-   hrtimer_init_sleeper(&hs, current);
do {
if (test_bit(REQ_ATOM_COMPLETE, &rq->atomic_flags))
break;
diff --git a/include/linux/hrtimer.h b/include/linux/hrtimer.h
index 012c37fdb688..a5e462dafd7d 100644
--- a/include/linux/hrtimer.h
+++ b/include/linux/hrtimer.h
@@ -344,10 +344,17 @@ DECLARE_PER_CPU(struct tick_device, tick_cpu_device);
 /* Initialize timers: */
 extern void hrtimer_init(struct hrtimer *timer, clockid_t which_clock,
 enum hrtimer_mode mode);
+extern void hrtimer_init_sleeper(struct hrtimer_sleeper *sl, clockid_t 
clock_id,
+enum hrtimer_mode mode,
+struct task_struct *task);
 
 #ifdef CONFIG_DEBUG_OBJECTS_TIMERS
 extern void hrtimer_init_on_stack(struct hrtimer *timer, clockid_t which_clock,
  enum hrtimer_mode mode);
+extern void hrtimer_init_sleeper_on_stack(struct hrtimer_sleeper *sl,
+ clockid_t clock_id,
+ enum hrtimer_mode mode,
+ struct task_struct *task);
 
 extern void destroy_hrtimer_on_stack(struct hrtimer *timer);
 #else
@@ -357,6 +364,15 @@ static inline void hrtimer_init_on_stack(struct hrtimer 
*timer,
 {
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,
+   struct task_struct *task)
+{
+   hrtimer_init_sleeper(sl, clock_id, mode, task);
+}
+
 static inline void destroy_hrtimer_on_stack(struct hrtimer *timer) { }
 #endif
 
@@ -458,9 +474,6 @@ extern long hrtimer_nanosleep(const struct timespec64 *rqtp,
  const enum hrtimer_mode mode,
  const clockid_t clockid);
 
-extern void hrtimer_init_sleeper(struct hrtimer_sleeper *sl,
-struct task_struct *tsk);
-
 extern int schedule_hrtimeout_range(ktime_t *expires, u64 delta,
const enum hrtimer_mode mode);
 extern int schedule_hrtimeout_range_clock(ktime_t *expires,
diff --git a/include/linux/wait.h b/include/linux/wait.h
index dc19880c02f5..41a586acc739 100644
--- a/include/linux/wait.h
+++ b/include/linux/wait.h
@@ -482,8 +482,8 @@ do {
\
int __ret = 0;  
\
struct hrtimer_sleeper __t; 
\

\
-   hrtimer_init_on_stack(&__t.timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);   
\
-   hrtimer_init_sleeper(&__t, current);
\
+   hrtimer_init_sleeper_on_stack(&__t, CLOCK_MONOTONIC, HRTIMER_MODE_REL,  
\
+ current); 
\
if ((timeout) != KTIME_MAX) 
\
hrtimer_start_range_ns(&__t.timer, timeout, 
\
   current->timer_slack_ns, 
\
diff --git a/kernel/futex.c b/kernel/futex.c
index 3d38eaf05492..2d8719819375 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -2553,10 +2553,9 @@ static int futex_wait(u32 __user *uaddr, unsigned int 
flags, u32 val,
if (abs_time) {
to = &timeout;
 
-   hrtimer_init_on_stack(&to->timer, (flags & FLAGS_CLOCKRT) ?
- CLOCK_REALTIME : CLOCK_MONOTONIC,
-