Commit 1593baab authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Ingo Molnar

sched/debug: Implement consistent task-state printing

Currently get_task_state() and task_state_to_char() report different
states, create a number of common helpers and unify the reported state
space.
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 770b782f
...@@ -130,19 +130,8 @@ static const char * const task_state_array[] = { ...@@ -130,19 +130,8 @@ static const char * const task_state_array[] = {
static inline const char *get_task_state(struct task_struct *tsk) static inline const char *get_task_state(struct task_struct *tsk)
{ {
unsigned int state = (tsk->state | tsk->exit_state) & TASK_REPORT; BUILD_BUG_ON(1 + ilog2(TASK_REPORT) != ARRAY_SIZE(task_state_array) - 1);
return task_state_array[__get_task_state(tsk)];
/*
* Parked tasks do not run; they sit in __kthread_parkme().
* Without this check, we would report them as running, which is
* clearly wrong, so we report them as sleeping instead.
*/
if (tsk->state == TASK_PARKED)
state = TASK_INTERRUPTIBLE;
BUILD_BUG_ON(1 + ilog2(TASK_REPORT) != ARRAY_SIZE(task_state_array)-1);
return task_state_array[fls(state)];
} }
static inline int get_task_umask(struct task_struct *tsk) static inline int get_task_umask(struct task_struct *tsk)
......
...@@ -1243,17 +1243,29 @@ static inline pid_t task_pgrp_nr(struct task_struct *tsk) ...@@ -1243,17 +1243,29 @@ static inline pid_t task_pgrp_nr(struct task_struct *tsk)
return task_pgrp_nr_ns(tsk, &init_pid_ns); return task_pgrp_nr_ns(tsk, &init_pid_ns);
} }
static inline char task_state_to_char(struct task_struct *task) static inline unsigned int __get_task_state(struct task_struct *tsk)
{ {
const char stat_nam[] = TASK_STATE_TO_CHAR_STR; unsigned int tsk_state = READ_ONCE(tsk->state);
unsigned long state = task->state; unsigned int state = (tsk_state | tsk->exit_state) & TASK_REPORT;
state = state ? __ffs(state) + 1 : 0; if (tsk_state == TASK_PARKED)
state = TASK_INTERRUPTIBLE;
/* Make sure the string lines up properly with the number of task states: */ return fls(state);
BUILD_BUG_ON(sizeof(TASK_STATE_TO_CHAR_STR)-1 != ilog2(TASK_STATE_MAX)+1); }
static inline char __task_state_to_char(unsigned int state)
{
static const char state_char[] = "RSDTtXZ";
BUILD_BUG_ON(1 + ilog2(TASK_REPORT) != sizeof(state_char) - 2);
return state < sizeof(stat_nam) - 1 ? stat_nam[state] : '?'; return state_char[state];
}
static inline char task_state_to_char(struct task_struct *tsk)
{
return __task_state_to_char(__get_task_state(tsk));
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment