mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-19 00:26:42 +07:00
07879c6a37
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 <dbueso@suse.de> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Waiman Long <longman@redhat.com> Cc: Will Deacon <will.deacon@arm.com> Cc: Xie Yongji <xieyongji@baidu.com> Cc: Yongji Xie <elohimes@gmail.com> Cc: andrea.parri@amarulasolutions.com Cc: lilin24@baidu.com Cc: liuqi16@baidu.com Cc: nixun@baidu.com Cc: yuanlinsi01@baidu.com Cc: zhangyu31@baidu.com Link: https://lkml.kernel.org/r/20181218195352.7orq3upiwfdbrdne@linux-r8p5 Signed-off-by: Ingo Molnar <mingo@kernel.org>
59 lines
2.0 KiB
C
59 lines
2.0 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef _LINUX_SCHED_WAKE_Q_H
|
|
#define _LINUX_SCHED_WAKE_Q_H
|
|
|
|
/*
|
|
* Wake-queues are lists of tasks with a pending wakeup, whose
|
|
* callers have already marked the task as woken internally,
|
|
* and can thus carry on. A common use case is being able to
|
|
* do the wakeups once the corresponding user lock as been
|
|
* released.
|
|
*
|
|
* We hold reference to each task in the list across the wakeup,
|
|
* thus guaranteeing that the memory is still valid by the time
|
|
* the actual wakeups are performed in wake_up_q().
|
|
*
|
|
* One per task suffices, because there's never a need for a task to be
|
|
* in two wake queues simultaneously; it is forbidden to abandon a task
|
|
* in a wake queue (a call to wake_up_q() _must_ follow), so if a task is
|
|
* already in a wake queue, the wakeup will happen soon and the second
|
|
* waker can just skip it.
|
|
*
|
|
* The DEFINE_WAKE_Q macro declares and initializes the list head.
|
|
* wake_up_q() does NOT reinitialize the list; it's expected to be
|
|
* called near the end of a function. Otherwise, the list can be
|
|
* re-initialized for later re-use by wake_q_init().
|
|
*
|
|
* NOTE that this can cause spurious wakeups. schedule() callers
|
|
* must ensure the call is done inside a loop, confirming that the
|
|
* wakeup condition has in fact occurred.
|
|
*
|
|
* NOTE that there is no guarantee the wakeup will happen any later than the
|
|
* wake_q_add() location. Therefore task must be ready to be woken at the
|
|
* location of the wake_q_add().
|
|
*/
|
|
|
|
#include <linux/sched.h>
|
|
|
|
struct wake_q_head {
|
|
struct wake_q_node *first;
|
|
struct wake_q_node **lastp;
|
|
};
|
|
|
|
#define WAKE_Q_TAIL ((struct wake_q_node *) 0x01)
|
|
|
|
#define DEFINE_WAKE_Q(name) \
|
|
struct wake_q_head name = { WAKE_Q_TAIL, &name.first }
|
|
|
|
static inline void wake_q_init(struct wake_q_head *head)
|
|
{
|
|
head->first = WAKE_Q_TAIL;
|
|
head->lastp = &head->first;
|
|
}
|
|
|
|
extern void wake_q_add(struct wake_q_head *head, struct task_struct *task);
|
|
extern void wake_q_add_safe(struct wake_q_head *head, struct task_struct *task);
|
|
extern void wake_up_q(struct wake_q_head *head);
|
|
|
|
#endif /* _LINUX_SCHED_WAKE_Q_H */
|