Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

+7 -5
+1 -1
block/blk-mq.c
··· 3910 3910 3911 3911 hctx->poll_considered++; 3912 3912 3913 - state = current->state; 3913 + state = get_current_state(); 3914 3914 do { 3915 3915 int ret; 3916 3916
+2
include/linux/sched.h
··· 213 213 214 214 #endif 215 215 216 + #define get_current_state() READ_ONCE(current->state) 217 + 216 218 /* Task command name length: */ 217 219 #define TASK_COMM_LEN 16 218 220
+1 -1
kernel/freezer.c
··· 58 58 /* Hmm, should we be allowed to suspend when there are realtime 59 59 processes around? */ 60 60 bool was_frozen = false; 61 - long save = current->state; 61 + unsigned int save = get_current_state(); 62 62 63 63 pr_debug("%s entered refrigerator\n", current->comm); 64 64
+3 -3
kernel/sched/core.c
··· 9098 9098 9099 9099 void __might_sleep(const char *file, int line, int preempt_offset) 9100 9100 { 9101 + unsigned int state = get_current_state(); 9101 9102 /* 9102 9103 * Blocking primitives will set (and therefore destroy) current->state, 9103 9104 * since we will exit with TASK_RUNNING make sure we enter with it, 9104 9105 * otherwise we will destroy state. 9105 9106 */ 9106 - WARN_ONCE(current->state != TASK_RUNNING && current->task_state_change, 9107 + WARN_ONCE(state != TASK_RUNNING && current->task_state_change, 9107 9108 "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, 9110 9110 (void *)current->task_state_change, 9111 9111 (void *)current->task_state_change); 9112 9112