mirror of
https://github.com/rd-stuffs/msm-4.14.git
synced 2025-02-20 11:45:48 +08:00
futex: Consolidate duplicated timer setup code
Add a new futex_setup_timer() helper function to consolidate all the hrtimer_sleeper setup code. Signed-off-by: Waiman Long <longman@redhat.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Darren Hart <dvhart@infradead.org> Cc: Davidlohr Bueso <dave@stgolabs.net> Link: https://lkml.kernel.org/r/20190528160345.24017-1-longman@redhat.com Signed-off-by: Adam W. Willis <return.of.octobot@gmail.com> Signed-off-by: Nauval Rizky <enuma.alrizky@gmail.com> Signed-off-by: azrim <mirzaspc@gmail.com>
This commit is contained in:
parent
e7bdf61b2c
commit
ab4915af82
@ -523,6 +523,37 @@ static u64 get_inode_sequence_number(struct inode *inode)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* futex_setup_timer - set up the sleeping hrtimer.
|
||||
* @time: ptr to the given timeout value
|
||||
* @timeout: the hrtimer_sleeper structure to be set up
|
||||
* @flags: futex flags
|
||||
* @range_ns: optional range in ns
|
||||
*
|
||||
* Return: Initialized hrtimer_sleeper structure or NULL if no timeout
|
||||
* value given
|
||||
*/
|
||||
static inline struct hrtimer_sleeper *
|
||||
futex_setup_timer(ktime_t *time, struct hrtimer_sleeper *timeout,
|
||||
int flags, u64 range_ns)
|
||||
{
|
||||
if (!time)
|
||||
return NULL;
|
||||
|
||||
hrtimer_init_on_stack(&timeout->timer, (flags & FLAGS_CLOCKRT) ?
|
||||
CLOCK_REALTIME : CLOCK_MONOTONIC,
|
||||
HRTIMER_MODE_ABS);
|
||||
hrtimer_init_sleeper(timeout, current);
|
||||
|
||||
/*
|
||||
* If range_ns is 0, calling hrtimer_set_expires_range_ns() is
|
||||
* effectively the same as calling hrtimer_set_expires().
|
||||
*/
|
||||
hrtimer_set_expires_range_ns(&timeout->timer, *time, range_ns);
|
||||
|
||||
return timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* get_futex_key() - Get parameters which are the keys for a futex
|
||||
* @uaddr: virtual address of the futex
|
||||
@ -2818,7 +2849,7 @@ out:
|
||||
static int futex_wait(u32 __user *uaddr, unsigned int flags, u32 val,
|
||||
ktime_t *abs_time, u32 bitset)
|
||||
{
|
||||
struct hrtimer_sleeper timeout, *to = NULL;
|
||||
struct hrtimer_sleeper timeout, *to;
|
||||
struct restart_block *restart;
|
||||
struct futex_hash_bucket *hb;
|
||||
struct futex_q q = futex_q_init;
|
||||
@ -2828,17 +2859,8 @@ static int futex_wait(u32 __user *uaddr, unsigned int flags, u32 val,
|
||||
return -EINVAL;
|
||||
q.bitset = bitset;
|
||||
|
||||
if (abs_time) {
|
||||
to = &timeout;
|
||||
|
||||
hrtimer_init_on_stack(&to->timer, (flags & FLAGS_CLOCKRT) ?
|
||||
CLOCK_REALTIME : CLOCK_MONOTONIC,
|
||||
HRTIMER_MODE_ABS);
|
||||
hrtimer_init_sleeper(to, current);
|
||||
hrtimer_set_expires_range_ns(&to->timer, *abs_time,
|
||||
to = futex_setup_timer(abs_time, &timeout, flags,
|
||||
current->timer_slack_ns);
|
||||
}
|
||||
|
||||
retry:
|
||||
/*
|
||||
* Prepare to wait on uaddr. On success, holds hb lock and increments
|
||||
@ -2917,7 +2939,7 @@ static long futex_wait_restart(struct restart_block *restart)
|
||||
static int futex_lock_pi(u32 __user *uaddr, unsigned int flags,
|
||||
ktime_t *time, int trylock)
|
||||
{
|
||||
struct hrtimer_sleeper timeout, *to = NULL;
|
||||
struct hrtimer_sleeper timeout, *to;
|
||||
struct task_struct *exiting = NULL;
|
||||
struct rt_mutex_waiter rt_waiter;
|
||||
struct futex_hash_bucket *hb;
|
||||
@ -2930,13 +2952,7 @@ static int futex_lock_pi(u32 __user *uaddr, unsigned int flags,
|
||||
if (refill_pi_state_cache())
|
||||
return -ENOMEM;
|
||||
|
||||
if (time) {
|
||||
to = &timeout;
|
||||
hrtimer_init_on_stack(&to->timer, CLOCK_REALTIME,
|
||||
HRTIMER_MODE_ABS);
|
||||
hrtimer_init_sleeper(to, current);
|
||||
hrtimer_set_expires(&to->timer, *time);
|
||||
}
|
||||
to = futex_setup_timer(time, &timeout, FLAGS_CLOCKRT, 0);
|
||||
|
||||
retry:
|
||||
ret = get_futex_key(uaddr, flags & FLAGS_SHARED, &q.key, VERIFY_WRITE);
|
||||
@ -3327,7 +3343,7 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
|
||||
u32 val, ktime_t *abs_time, u32 bitset,
|
||||
u32 __user *uaddr2)
|
||||
{
|
||||
struct hrtimer_sleeper timeout, *to = NULL;
|
||||
struct hrtimer_sleeper timeout, *to;
|
||||
struct rt_mutex_waiter rt_waiter;
|
||||
struct futex_hash_bucket *hb;
|
||||
union futex_key key2 = FUTEX_KEY_INIT;
|
||||
@ -3343,15 +3359,8 @@ static int futex_wait_requeue_pi(u32 __user *uaddr, unsigned int flags,
|
||||
if (!bitset)
|
||||
return -EINVAL;
|
||||
|
||||
if (abs_time) {
|
||||
to = &timeout;
|
||||
hrtimer_init_on_stack(&to->timer, (flags & FLAGS_CLOCKRT) ?
|
||||
CLOCK_REALTIME : CLOCK_MONOTONIC,
|
||||
HRTIMER_MODE_ABS);
|
||||
hrtimer_init_sleeper(to, current);
|
||||
hrtimer_set_expires_range_ns(&to->timer, *abs_time,
|
||||
to = futex_setup_timer(abs_time, &timeout, flags,
|
||||
current->timer_slack_ns);
|
||||
}
|
||||
|
||||
/*
|
||||
* The waiter is allocated on our stack, manipulated by the requeue
|
||||
|
Loading…
x
Reference in New Issue
Block a user