mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-10 15:10:38 +00:00
sched/wakeup: Reorganize the current::__state helpers
In order to avoid more duplicate implementations for the debug and non-debug variants of the state change macros, split the debug portion out and make that conditional on CONFIG_DEBUG_ATOMIC_SLEEP=y. Suggested-by: Waiman Long <longman@redhat.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Ingo Molnar <mingo@kernel.org> Link: https://lore.kernel.org/r/20210815211302.200898048@linutronix.de Signed-off-by: Ingo Molnar <mingo@kernel.org>
This commit is contained in:
parent
cd781d0ce8
commit
85019c1674
@ -123,8 +123,6 @@ struct task_group;
|
||||
|
||||
#define task_is_stopped_or_traced(task) ((READ_ONCE(task->__state) & (__TASK_STOPPED | __TASK_TRACED)) != 0)
|
||||
|
||||
#ifdef CONFIG_DEBUG_ATOMIC_SLEEP
|
||||
|
||||
/*
|
||||
* Special states are those that do not use the normal wait-loop pattern. See
|
||||
* the comment with set_special_state().
|
||||
@ -132,30 +130,24 @@ struct task_group;
|
||||
#define is_special_task_state(state) \
|
||||
((state) & (__TASK_STOPPED | __TASK_TRACED | TASK_PARKED | TASK_DEAD))
|
||||
|
||||
#define __set_current_state(state_value) \
|
||||
do { \
|
||||
WARN_ON_ONCE(is_special_task_state(state_value));\
|
||||
current->task_state_change = _THIS_IP_; \
|
||||
WRITE_ONCE(current->__state, (state_value)); \
|
||||
} while (0)
|
||||
|
||||
#define set_current_state(state_value) \
|
||||
do { \
|
||||
WARN_ON_ONCE(is_special_task_state(state_value));\
|
||||
current->task_state_change = _THIS_IP_; \
|
||||
smp_store_mb(current->__state, (state_value)); \
|
||||
} while (0)
|
||||
|
||||
#define set_special_state(state_value) \
|
||||
#ifdef CONFIG_DEBUG_ATOMIC_SLEEP
|
||||
# define debug_normal_state_change(state_value) \
|
||||
do { \
|
||||
unsigned long flags; /* may shadow */ \
|
||||
WARN_ON_ONCE(!is_special_task_state(state_value)); \
|
||||
raw_spin_lock_irqsave(¤t->pi_lock, flags); \
|
||||
WARN_ON_ONCE(is_special_task_state(state_value)); \
|
||||
current->task_state_change = _THIS_IP_; \
|
||||
WRITE_ONCE(current->__state, (state_value)); \
|
||||
raw_spin_unlock_irqrestore(¤t->pi_lock, flags); \
|
||||
} while (0)
|
||||
|
||||
# define debug_special_state_change(state_value) \
|
||||
do { \
|
||||
WARN_ON_ONCE(!is_special_task_state(state_value)); \
|
||||
current->task_state_change = _THIS_IP_; \
|
||||
} while (0)
|
||||
|
||||
#else
|
||||
# define debug_normal_state_change(cond) do { } while (0)
|
||||
# define debug_special_state_change(cond) do { } while (0)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* set_current_state() includes a barrier so that the write of current->state
|
||||
* is correctly serialised wrt the caller's subsequent test of whether to
|
||||
@ -194,27 +186,33 @@ struct task_group;
|
||||
* Also see the comments of try_to_wake_up().
|
||||
*/
|
||||
#define __set_current_state(state_value) \
|
||||
WRITE_ONCE(current->__state, (state_value))
|
||||
do { \
|
||||
debug_normal_state_change((state_value)); \
|
||||
WRITE_ONCE(current->__state, (state_value)); \
|
||||
} while (0)
|
||||
|
||||
#define set_current_state(state_value) \
|
||||
smp_store_mb(current->__state, (state_value))
|
||||
do { \
|
||||
debug_normal_state_change((state_value)); \
|
||||
smp_store_mb(current->__state, (state_value)); \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* set_special_state() should be used for those states when the blocking task
|
||||
* can not use the regular condition based wait-loop. In that case we must
|
||||
* serialize against wakeups such that any possible in-flight TASK_RUNNING stores
|
||||
* will not collide with our state change.
|
||||
* serialize against wakeups such that any possible in-flight TASK_RUNNING
|
||||
* stores will not collide with our state change.
|
||||
*/
|
||||
#define set_special_state(state_value) \
|
||||
do { \
|
||||
unsigned long flags; /* may shadow */ \
|
||||
\
|
||||
raw_spin_lock_irqsave(¤t->pi_lock, flags); \
|
||||
debug_special_state_change((state_value)); \
|
||||
WRITE_ONCE(current->__state, (state_value)); \
|
||||
raw_spin_unlock_irqrestore(¤t->pi_lock, flags); \
|
||||
} while (0)
|
||||
|
||||
#endif
|
||||
|
||||
#define get_current_state() READ_ONCE(current->__state)
|
||||
|
||||
/* Task command name length: */
|
||||
|
Loading…
x
Reference in New Issue
Block a user