Skip to content

Commit 85019c1

Browse files
KAGA-KOKOIngo Molnar
authored andcommitted
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 <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent cd781d0 commit 85019c1

File tree

1 file changed

+23
-25
lines changed

1 file changed

+23
-25
lines changed

include/linux/sched.h

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -123,39 +123,31 @@ struct task_group;
123123

124124
#define task_is_stopped_or_traced(task) ((READ_ONCE(task->__state) & (__TASK_STOPPED | __TASK_TRACED)) != 0)
125125

126-
#ifdef CONFIG_DEBUG_ATOMIC_SLEEP
127-
128126
/*
129127
* Special states are those that do not use the normal wait-loop pattern. See
130128
* the comment with set_special_state().
131129
*/
132130
#define is_special_task_state(state) \
133131
((state) & (__TASK_STOPPED | __TASK_TRACED | TASK_PARKED | TASK_DEAD))
134132

135-
#define __set_current_state(state_value) \
136-
do { \
137-
WARN_ON_ONCE(is_special_task_state(state_value));\
138-
current->task_state_change = _THIS_IP_; \
139-
WRITE_ONCE(current->__state, (state_value)); \
140-
} while (0)
141-
142-
#define set_current_state(state_value) \
143-
do { \
144-
WARN_ON_ONCE(is_special_task_state(state_value));\
145-
current->task_state_change = _THIS_IP_; \
146-
smp_store_mb(current->__state, (state_value)); \
133+
#ifdef CONFIG_DEBUG_ATOMIC_SLEEP
134+
# define debug_normal_state_change(state_value) \
135+
do { \
136+
WARN_ON_ONCE(is_special_task_state(state_value)); \
137+
current->task_state_change = _THIS_IP_; \
147138
} while (0)
148139

149-
#define set_special_state(state_value) \
140+
# define debug_special_state_change(state_value) \
150141
do { \
151-
unsigned long flags; /* may shadow */ \
152142
WARN_ON_ONCE(!is_special_task_state(state_value)); \
153-
raw_spin_lock_irqsave(&current->pi_lock, flags); \
154143
current->task_state_change = _THIS_IP_; \
155-
WRITE_ONCE(current->__state, (state_value)); \
156-
raw_spin_unlock_irqrestore(&current->pi_lock, flags); \
157144
} while (0)
145+
158146
#else
147+
# define debug_normal_state_change(cond) do { } while (0)
148+
# define debug_special_state_change(cond) do { } while (0)
149+
#endif
150+
159151
/*
160152
* set_current_state() includes a barrier so that the write of current->state
161153
* is correctly serialised wrt the caller's subsequent test of whether to
@@ -194,27 +186,33 @@ struct task_group;
194186
* Also see the comments of try_to_wake_up().
195187
*/
196188
#define __set_current_state(state_value) \
197-
WRITE_ONCE(current->__state, (state_value))
189+
do { \
190+
debug_normal_state_change((state_value)); \
191+
WRITE_ONCE(current->__state, (state_value)); \
192+
} while (0)
198193

199194
#define set_current_state(state_value) \
200-
smp_store_mb(current->__state, (state_value))
195+
do { \
196+
debug_normal_state_change((state_value)); \
197+
smp_store_mb(current->__state, (state_value)); \
198+
} while (0)
201199

202200
/*
203201
* set_special_state() should be used for those states when the blocking task
204202
* can not use the regular condition based wait-loop. In that case we must
205-
* serialize against wakeups such that any possible in-flight TASK_RUNNING stores
206-
* will not collide with our state change.
203+
* serialize against wakeups such that any possible in-flight TASK_RUNNING
204+
* stores will not collide with our state change.
207205
*/
208206
#define set_special_state(state_value) \
209207
do { \
210208
unsigned long flags; /* may shadow */ \
209+
\
211210
raw_spin_lock_irqsave(&current->pi_lock, flags); \
211+
debug_special_state_change((state_value)); \
212212
WRITE_ONCE(current->__state, (state_value)); \
213213
raw_spin_unlock_irqrestore(&current->pi_lock, flags); \
214214
} while (0)
215215

216-
#endif
217-
218216
#define get_current_state() READ_ONCE(current->__state)
219217

220218
/* Task command name length: */

0 commit comments

Comments
 (0)