aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/sched.h
diff options
context:
space:
mode:
authorPeter Zijlstra <peterz@infradead.org>2017-09-22 18:09:26 +0200
committerIngo Molnar <mingo@kernel.org>2017-09-29 10:09:08 +0200
commit1593baab910da72480d651ea7bf2ce6e3a25a484 (patch)
treef25d6f915062f9c322233c987d30a66260f474bb /include/linux/sched.h
parentMerge tag 'acpi-4.14-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm (diff)
downloadlinux-dev-1593baab910da72480d651ea7bf2ce6e3a25a484.tar.xz
linux-dev-1593baab910da72480d651ea7bf2ce6e3a25a484.zip
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: Peter 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: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to '')
-rw-r--r--include/linux/sched.h26
1 files changed, 19 insertions, 7 deletions
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)
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 long state = task->state;
+ unsigned int tsk_state = READ_ONCE(tsk->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: */
- BUILD_BUG_ON(sizeof(TASK_STATE_TO_CHAR_STR)-1 != ilog2(TASK_STATE_MAX)+1);
+ return fls(state);
+}
+
+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));
}
/**