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

Commit 20435d84 authored by Xie XiuQi's avatar Xie XiuQi Committed by Ingo Molnar
Browse files

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: default avatarXie XiuQi <xiexiuqi@huawei.com>
Signed-off-by: default avatarPeter 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: default avatarIngo Molnar <mingo@kernel.org>
parent e8c16495
Loading
Loading
Loading
Loading
+13 −0
Original line number Original line Diff line number Diff line
@@ -1229,6 +1229,19 @@ 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)
{
	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_global_init - check if a task structure is init. Since init
 * is free to have sub-threads we need to check tgid.
 * is free to have sub-threads we need to check tgid.
+4 −11
Original line number Original line Diff line number Diff line
@@ -5103,24 +5103,17 @@ SYSCALL_DEFINE2(sched_rr_get_interval, pid_t, pid,
	return retval;
	return retval;
}
}


static const char stat_nam[] = TASK_STATE_TO_CHAR_STR;

void sched_show_task(struct task_struct *p)
void sched_show_task(struct task_struct *p)
{
{
	unsigned long free = 0;
	unsigned long free = 0;
	int ppid;
	int ppid;
	unsigned long state = p->state;

	/* 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);


	if (!try_get_task_stack(p))
	if (!try_get_task_stack(p))
		return;
		return;
	if (state)

		state = __ffs(state) + 1;
	printk(KERN_INFO "%-15.15s %c", p->comm, task_state_to_char(p));
	printk(KERN_INFO "%-15.15s %c", p->comm,

		state < sizeof(stat_nam) - 1 ? stat_nam[state] : '?');
	if (p->state == TASK_RUNNING)
	if (state == TASK_RUNNING)
		printk(KERN_CONT "  running task    ");
		printk(KERN_CONT "  running task    ");
#ifdef CONFIG_DEBUG_STACK_USAGE
#ifdef CONFIG_DEBUG_STACK_USAGE
	free = stack_not_used(p);
	free = stack_not_used(p);
+3 −7
Original line number Original line Diff line number Diff line
@@ -426,14 +426,10 @@ static const char stat_nam[] = TASK_STATE_TO_CHAR_STR;
static void
static void
print_task(struct seq_file *m, struct rq *rq, struct task_struct *p)
print_task(struct seq_file *m, struct rq *rq, struct task_struct *p)
{
{
	unsigned long state;
	if (rq->curr == p)

	if (rq->curr == p) {
		SEQ_printf(m, ">R");
		SEQ_printf(m, ">R");
	} else {
	else
		state = p->state ? __ffs(p->state) + 1 : 0;
		SEQ_printf(m, " %c", task_state_to_char(p));
		SEQ_printf(m, " %c", state < sizeof(stat_nam) - 1 ? stat_nam[state] : '?');
	}


	SEQ_printf(m, "%15s %5d %9Ld.%06ld %9Ld %5d ",
	SEQ_printf(m, "%15s %5d %9Ld.%06ld %9Ld %5d ",
		p->comm, task_pid_nr(p),
		p->comm, task_pid_nr(p),