summaryrefslogtreecommitdiffstats
path: root/include/linux/sched.h
diff options
context:
space:
mode:
authorXie XiuQi2017-08-07 10:44:23 +0200
committerIngo Molnar2017-08-10 12:18:20 +0200
commit20435d84e5f2041c64c792399ab6f2948a2c2252 (patch)
tree7576b55eef9f3291f3488635e1ab60cdf23ea19e /include/linux/sched.h
parentsched/debug: Show task state in /proc/sched_debug (diff)
downloadkernel-qcow2-linux-20435d84e5f2041c64c792399ab6f2948a2c2252.tar.gz
kernel-qcow2-linux-20435d84e5f2041c64c792399ab6f2948a2c2252.tar.xz
kernel-qcow2-linux-20435d84e5f2041c64c792399ab6f2948a2c2252.zip
sched/debug: Intruduce task_state_to_char() helper function
Now that we have more than one place to get the task state, intruduce the task_state_to_char() helper function to save some code. No functionality changed. Signed-off-by: Xie XiuQi <xiexiuqi@huawei.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: <cj.chengjian@huawei.com> Cc: <huawei.libin@huawei.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/1502095463-160172-3-git-send-email-xiexiuqi@huawei.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'include/linux/sched.h')
-rw-r--r--include/linux/sched.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 8337e2db0bb2..c28b182c9833 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1229,6 +1229,19 @@ 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)
+{
+ const char stat_nam[] = TASK_STATE_TO_CHAR_STR;
+ unsigned long state = task->state;
+
+ state = state ? __ffs(state) + 1 : 0;
+
+ /* 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 state < sizeof(stat_nam) - 1 ? stat_nam[state] : '?';
+}
+
/**
* is_global_init - check if a task structure is init. Since init
* is free to have sub-threads we need to check tgid.