History

sched: Add get_current_state()

Remove yet another few p->state accesses.

Peter Zijlstra committed 5 years ago

Commit d6c23bb1 parent 3ba9f934 files · +7 −5Browse files

Unified · Split

4 files
  1. block/blk-mq.c +1 −1
  2. include/linux/sched.h +2 −0
  3. kernel/freezer.c +1 −1
  4. kernel/sched/core.c +3 −3
block/blk-mq.c+1−1
@@ -3910,7 +3910,7 @@ int blk_poll(struct request_queue *q, blk_qc_t cookie, bool spin) · 3909 unmodified lines
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+2−0
@@ -213,6 +213,8 @@ struct task_group; · 212 unmodified lines
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+1−1
@@ -58,7 +58,7 @@ bool __refrigerator(bool check_kthr_stop) · 57 unmodified lines
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+3−3
@@ -9098,15 +9098,15 @@ static inline int preempt_count_equals(int preempt_offset) · 9097 unmodified lines
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

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t