mirror of
https://github.com/BobTheBlinker/android_kernel_motorola_sm6375.git
synced 2026-10-28 02:32:09 -04:00
sched/wake_q: Reduce reference counting for special users
Some users, specifically futexes and rwsems, required fixes that allowed the callers to be safe when wakeups occur before they are expected by wake_up_q(). Such scenarios also play games and rely on reference counting, and until now were pivoting on wake_q doing it. With the wake_q_add() call being moved down, this can no longer be the case. As such we end up with a a double task refcounting overhead; and these callers care enough about this (being rather core-ish). This patch introduces a wake_q_add_safe() call that serves for callers that have already done refcounting and therefore the task is 'safe' from wake_q point of view (int that it requires reference throughout the entire queue/>wakeup cycle). In the one case it has internal reference counting, in the other case it consumes the reference counting. Signed-off-by: Davidlohr Bueso <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Paul E. McKenney <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Waiman Long <[email protected]> Cc: Will Deacon <[email protected]> Cc: Xie Yongji <[email protected]> Cc: Yongji Xie <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Link: https://lkml.kernel.org/r/20181218195352.7orq3upiwfdbrdne@linux-r8p5 Signed-off-by: Ingo Molnar <[email protected]>
This commit is contained in:
parent
513e1073d5
commit
07879c6a37
4 changed files with 48 additions and 23 deletions
|
|
@ -396,6 +396,30 @@ static bool set_nr_if_polling(struct task_struct *p)
|
|||
#endif
|
||||
#endif
|
||||
|
||||
static bool __wake_q_add(struct wake_q_head *head, struct task_struct *task)
|
||||
{
|
||||
struct wake_q_node *node = &task->wake_q;
|
||||
|
||||
/*
|
||||
* Atomically grab the task, if ->wake_q is !nil already it means
|
||||
* its already queued (either by us or someone else) and will get the
|
||||
* wakeup due to that.
|
||||
*
|
||||
* In order to ensure that a pending wakeup will observe our pending
|
||||
* state, even in the failed case, an explicit smp_mb() must be used.
|
||||
*/
|
||||
smp_mb__before_atomic();
|
||||
if (unlikely(cmpxchg_relaxed(&node->next, NULL, WAKE_Q_TAIL)))
|
||||
return false;
|
||||
|
||||
/*
|
||||
* The head is context local, there can be no concurrency.
|
||||
*/
|
||||
*head->lastp = node;
|
||||
head->lastp = &node->next;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* wake_q_add() - queue a wakeup for 'later' waking.
|
||||
* @head: the wake_q_head to add @task to
|
||||
|
|
@ -410,27 +434,31 @@ static bool set_nr_if_polling(struct task_struct *p)
|
|||
*/
|
||||
void wake_q_add(struct wake_q_head *head, struct task_struct *task)
|
||||
{
|
||||
struct wake_q_node *node = &task->wake_q;
|
||||
if (__wake_q_add(head, task))
|
||||
get_task_struct(task);
|
||||
}
|
||||
|
||||
/*
|
||||
* Atomically grab the task, if ->wake_q is !nil already it means
|
||||
* its already queued (either by us or someone else) and will get the
|
||||
* wakeup due to that.
|
||||
*
|
||||
* In order to ensure that a pending wakeup will observe our pending
|
||||
* state, even in the failed case, an explicit smp_mb() must be used.
|
||||
*/
|
||||
smp_mb__before_atomic();
|
||||
if (unlikely(cmpxchg_relaxed(&node->next, NULL, WAKE_Q_TAIL)))
|
||||
return;
|
||||
|
||||
get_task_struct(task);
|
||||
|
||||
/*
|
||||
* The head is context local, there can be no concurrency.
|
||||
*/
|
||||
*head->lastp = node;
|
||||
head->lastp = &node->next;
|
||||
/**
|
||||
* wake_q_add_safe() - safely queue a wakeup for 'later' waking.
|
||||
* @head: the wake_q_head to add @task to
|
||||
* @task: the task to queue for 'later' wakeup
|
||||
*
|
||||
* Queue a task for later wakeup, most likely by the wake_up_q() call in the
|
||||
* same context, _HOWEVER_ this is not guaranteed, the wakeup can come
|
||||
* instantly.
|
||||
*
|
||||
* This function must be used as-if it were wake_up_process(); IOW the task
|
||||
* must be ready to be woken at this location.
|
||||
*
|
||||
* This function is essentially a task-safe equivalent to wake_q_add(). Callers
|
||||
* that already hold reference to @task can call the 'safe' version and trust
|
||||
* wake_q to do the right thing depending whether or not the @task is already
|
||||
* queued for wakeup.
|
||||
*/
|
||||
void wake_q_add_safe(struct wake_q_head *head, struct task_struct *task)
|
||||
{
|
||||
if (!__wake_q_add(head, task))
|
||||
put_task_struct(task);
|
||||
}
|
||||
|
||||
void wake_up_q(struct wake_q_head *head)
|
||||
|
|
|
|||
Loading…
Reference in a new issue