aboutsummaryrefslogtreecommitdiffstats
path: root/fs/proc
diff options
context:
space:
mode:
authorOleg Nesterov <oleg@redhat.com>2014-01-23 18:55:35 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2014-01-23 19:37:01 -0500
commit74e37200de8e9c4e09b70c21c3f13c2071e77457 (patch)
treede7db4aa1113562665ba7f72d92ef33be788f7b7 /fs/proc
parent942be3875a1931c379bbc37053829dd6847e0f3f (diff)
proc: cleanup/simplify get_task_state/task_state_array
get_task_state() and task_state_array[] look confusing and suboptimal, it is not clear what it can actually report to user-space and task_state_array[] blows .data for no reason. 1. state = (tsk->state & TASK_REPORT) | tsk->exit_state is not clear. TASK_REPORT is self-documenting but it is not clear what ->exit_state can add. Move the potential exit_state's (EXIT_ZOMBIE and EXIT_DEAD) into TASK_REPORT and use it to calculate the final result. 2. With the change above it is obvious that task_state_array[] has the unused entries just to make BUILD_BUG_ON() happy. Change this BUILD_BUG_ON() to use TASK_REPORT rather than TASK_STATE_MAX and shrink task_state_array[]. 3. Turn the "while (state)" loop into fls(state). Signed-off-by: Oleg Nesterov <oleg@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: David Laight <David.Laight@ACULAB.COM> Cc: Geert Uytterhoeven <geert@linux-m68k.org> Cc: Ingo Molnar <mingo@kernel.org> Cc: Tejun Heo <tj@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/proc')
-rw-r--r--fs/proc/array.c15
1 files changed, 3 insertions, 12 deletions
diff --git a/fs/proc/array.c b/fs/proc/array.c
index 1bd2077187fd..554a0b229ac2 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -140,24 +140,15 @@ static const char * const task_state_array[] = {
140 "t (tracing stop)", /* 8 */ 140 "t (tracing stop)", /* 8 */
141 "Z (zombie)", /* 16 */ 141 "Z (zombie)", /* 16 */
142 "X (dead)", /* 32 */ 142 "X (dead)", /* 32 */
143 "x (dead)", /* 64 */
144 "K (wakekill)", /* 128 */
145 "W (waking)", /* 256 */
146 "P (parked)", /* 512 */
147}; 143};
148 144
149static inline const char *get_task_state(struct task_struct *tsk) 145static inline const char *get_task_state(struct task_struct *tsk)
150{ 146{
151 unsigned int state = (tsk->state & TASK_REPORT) | tsk->exit_state; 147 unsigned int state = (tsk->state | tsk->exit_state) & TASK_REPORT;
152 const char * const *p = &task_state_array[0];
153 148
154 BUILD_BUG_ON(1 + ilog2(TASK_STATE_MAX) != ARRAY_SIZE(task_state_array)); 149 BUILD_BUG_ON(1 + ilog2(TASK_REPORT) != ARRAY_SIZE(task_state_array)-1);
155 150
156 while (state) { 151 return task_state_array[fls(state)];
157 p++;
158 state >>= 1;
159 }
160 return *p;
161} 152}
162 153
163static inline void task_state(struct seq_file *m, struct pid_namespace *ns, 154static inline void task_state(struct seq_file *m, struct pid_namespace *ns,