Skip to content

Commit d6c23bb

Browse files
author
Peter Zijlstra
committed
sched: Add get_current_state()
Remove yet another few p->state accesses. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Will Deacon <will@kernel.org> Link: https://lore.kernel.org/r/20210611082838.347475156@infradead.org
1 parent 3ba9f93 commit d6c23bb

4 files changed

Lines changed: 7 additions & 5 deletions

File tree

block/blk-mq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3910,7 +3910,7 @@ int blk_poll(struct request_queue *q, blk_qc_t cookie, bool spin)
39103910

39113911
hctx->poll_considered++;
39123912

3913-
state = current->state;
3913+
state = get_current_state();
39143914
do {
39153915
int ret;
39163916

include/linux/sched.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ struct task_group;
213213

214214
#endif
215215

216+
#define get_current_state() READ_ONCE(current->state)
217+
216218
/* Task command name length: */
217219
#define TASK_COMM_LEN 16
218220

kernel/freezer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ bool __refrigerator(bool check_kthr_stop)
5858
/* Hmm, should we be allowed to suspend when there are realtime
5959
processes around? */
6060
bool was_frozen = false;
61-
long save = current->state;
61+
unsigned int save = get_current_state();
6262

6363
pr_debug("%s entered refrigerator\n", current->comm);
6464

kernel/sched/core.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9098,15 +9098,15 @@ static inline int preempt_count_equals(int preempt_offset)
90989098

90999099
void __might_sleep(const char *file, int line, int preempt_offset)
91009100
{
9101+
unsigned int state = get_current_state();
91019102
/*
91029103
* Blocking primitives will set (and therefore destroy) current->state,
91039104
* since we will exit with TASK_RUNNING make sure we enter with it,
91049105
* otherwise we will destroy state.
91059106
*/
9106-
WARN_ONCE(current->state != TASK_RUNNING && current->task_state_change,
9107+
WARN_ONCE(state != TASK_RUNNING && current->task_state_change,
91079108
"do not call blocking ops when !TASK_RUNNING; "
9108-
"state=%lx set at [<%p>] %pS\n",
9109-
current->state,
9109+
"state=%x set at [<%p>] %pS\n", state,
91109110
(void *)current->task_state_change,
91119111
(void *)current->task_state_change);
91129112

0 commit comments

Comments
 (0)