Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 74e37200 authored by Oleg Nesterov's avatar Oleg Nesterov Committed by Linus Torvalds
Browse files

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: default avatarOleg 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: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 942be387
Loading
Loading
Loading
Loading
+3 −12
Original line number Original line Diff line number Diff line
@@ -140,24 +140,15 @@ static const char * const task_state_array[] = {
	"t (tracing stop)",	/*   8 */
	"t (tracing stop)",	/*   8 */
	"Z (zombie)",		/*  16 */
	"Z (zombie)",		/*  16 */
	"X (dead)",		/*  32 */
	"X (dead)",		/*  32 */
	"x (dead)",		/*  64 */
	"K (wakekill)",		/* 128 */
	"W (waking)",		/* 256 */
	"P (parked)",		/* 512 */
};
};


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 & TASK_REPORT) | tsk->exit_state;
	unsigned int state = (tsk->state | tsk->exit_state) & TASK_REPORT;
	const char * const *p = &task_state_array[0];


	BUILD_BUG_ON(1 + ilog2(TASK_STATE_MAX) != ARRAY_SIZE(task_state_array));
	BUILD_BUG_ON(1 + ilog2(TASK_REPORT) != ARRAY_SIZE(task_state_array)-1);


	while (state) {
	return task_state_array[fls(state)];
		p++;
		state >>= 1;
	}
	return *p;
}
}


static inline void task_state(struct seq_file *m, struct pid_namespace *ns,
static inline void task_state(struct seq_file *m, struct pid_namespace *ns,
+1 −1
Original line number Original line Diff line number Diff line
@@ -229,7 +229,7 @@ extern char ___assert_task_state[1 - 2*!!(
/* get_task_state() */
/* get_task_state() */
#define TASK_REPORT		(TASK_RUNNING | TASK_INTERRUPTIBLE | \
#define TASK_REPORT		(TASK_RUNNING | TASK_INTERRUPTIBLE | \
				 TASK_UNINTERRUPTIBLE | __TASK_STOPPED | \
				 TASK_UNINTERRUPTIBLE | __TASK_STOPPED | \
				 __TASK_TRACED)
				 __TASK_TRACED | EXIT_ZOMBIE | EXIT_DEAD)


#define task_is_traced(task)	((task->state & __TASK_TRACED) != 0)
#define task_is_traced(task)	((task->state & __TASK_TRACED) != 0)
#define task_is_stopped(task)	((task->state & __TASK_STOPPED) != 0)
#define task_is_stopped(task)	((task->state & __TASK_STOPPED) != 0)