aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/proc/array.c15
-rw-r--r--include/linux/sched.h26
2 files changed, 21 insertions, 20 deletions
diff --git a/fs/proc/array.c b/fs/proc/array.c
index 525157ca25cb..01196d3ad452 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -130,19 +130,8 @@ static const char * const task_state_array[] = {
130 130
131static inline const char *get_task_state(struct task_struct *tsk) 131static inline const char *get_task_state(struct task_struct *tsk)
132{ 132{
133 unsigned int state = (tsk->state | tsk->exit_state) & TASK_REPORT; 133 BUILD_BUG_ON(1 + ilog2(TASK_REPORT) != ARRAY_SIZE(task_state_array) - 1);
134 134 return task_state_array[__get_task_state(tsk)];
135 /*
136 * Parked tasks do not run; they sit in __kthread_parkme().
137 * Without this check, we would report them as running, which is
138 * clearly wrong, so we report them as sleeping instead.
139 */
140 if (tsk->state == TASK_PARKED)
141 state = TASK_INTERRUPTIBLE;
142
143 BUILD_BUG_ON(1 + ilog2(TASK_REPORT) != ARRAY_SIZE(task_state_array)-1);
144
145 return task_state_array[fls(state)];
146} 135}
147 136
148static inline int get_task_umask(struct task_struct *tsk) 137static inline int get_task_umask(struct task_struct *tsk)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 92fb8dd5a9e4..163a0b738908 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1243,17 +1243,29 @@ static inline pid_t task_pgrp_nr(struct task_struct *tsk)
1243 return task_pgrp_nr_ns(tsk, &init_pid_ns); 1243 return task_pgrp_nr_ns(tsk, &init_pid_ns);
1244} 1244}
1245 1245
1246static inline char task_state_to_char(struct task_struct *task) 1246static inline unsigned int __get_task_state(struct task_struct *tsk)
1247{ 1247{
1248 const char stat_nam[] = TASK_STATE_TO_CHAR_STR; 1248 unsigned int tsk_state = READ_ONCE(tsk->state);
1249 unsigned long state = task->state; 1249 unsigned int state = (tsk_state | tsk->exit_state) & TASK_REPORT;
1250 1250
1251 state = state ? __ffs(state) + 1 : 0; 1251 if (tsk_state == TASK_PARKED)
1252 state = TASK_INTERRUPTIBLE;
1252 1253
1253 /* Make sure the string lines up properly with the number of task states: */ 1254 return fls(state);
1254 BUILD_BUG_ON(sizeof(TASK_STATE_TO_CHAR_STR)-1 != ilog2(TASK_STATE_MAX)+1); 1255}
1256
1257static inline char __task_state_to_char(unsigned int state)
1258{
1259 static const char state_char[] = "RSDTtXZ";
1260
1261 BUILD_BUG_ON(1 + ilog2(TASK_REPORT) != sizeof(state_char) - 2);
1255 1262
1256 return state < sizeof(stat_nam) - 1 ? stat_nam[state] : '?'; 1263 return state_char[state];
1264}
1265
1266static inline char task_state_to_char(struct task_struct *tsk)
1267{
1268 return __task_state_to_char(__get_task_state(tsk));
1257} 1269}
1258 1270
1259/** 1271/**