linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Xie XiuQi <xiexiuqi@huawei.com>
To: <mingo@redhat.com>, <peterz@infradead.org>
Cc: <linux-kernel@vger.kernel.org>, <huawei.libin@huawei.com>,
	<cj.chengjian@huawei.com>, <xiexiuqi@huawei.com>
Subject: [PATCH 2/2] sched/debug: intruduce task_state_to_char helper function
Date: Mon, 7 Aug 2017 16:44:23 +0800	[thread overview]
Message-ID: <1502095463-160172-3-git-send-email-xiexiuqi@huawei.com> (raw)
In-Reply-To: <1502095463-160172-1-git-send-email-xiexiuqi@huawei.com>

Now we have more than one place to get the task state,
so intruduce task_state_to_char helper to save some code.

No function changed.

Signed-off-by: Xie XiuQi <xiexiuqi@huawei.com>
---
 include/linux/sched.h | 13 +++++++++++++
 kernel/sched/core.c   | 15 ++++-----------
 kernel/sched/debug.c  | 10 +++-------
 3 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index 2b69fc6..d20edc0 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1189,6 +1189,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.
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 326d4f8..aa9cf40 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -5316,24 +5316,17 @@ void io_schedule(void)
 	return retval;
 }
 
-static const char stat_nam[] = TASK_STATE_TO_CHAR_STR;
-
 void sched_show_task(struct task_struct *p)
 {
 	unsigned long free = 0;
 	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))
 		return;
-	if (state)
-		state = __ffs(state) + 1;
-	printk(KERN_INFO "%-15.15s %c", p->comm,
-		state < sizeof(stat_nam) - 1 ? stat_nam[state] : '?');
-	if (state == TASK_RUNNING)
+
+	printk(KERN_INFO "%-15.15s %c", p->comm, task_state_to_char(p);
+
+	if (p->state == TASK_RUNNING)
 		printk(KERN_CONT "  running task    ");
 #ifdef CONFIG_DEBUG_STACK_USAGE
 	free = stack_not_used(p);
diff --git a/kernel/sched/debug.c b/kernel/sched/debug.c
index 60f7e20..1447266 100644
--- a/kernel/sched/debug.c
+++ b/kernel/sched/debug.c
@@ -426,14 +426,10 @@ static char *task_group_path(struct task_group *tg)
 static void
 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");
-	} else {
-		state = p->state ? __ffs(p->state) + 1 : 0;
-		SEQ_printf(m, " %c", state < sizeof(stat_nam) - 1 ? stat_nam[state] : '?');
-	}
+	else
+		SEQ_printf(m, " %c", task_sate_to_char(p));
 
 	SEQ_printf(m, "%15s %5d %9Ld.%06ld %9Ld %5d ",
 		p->comm, task_pid_nr(p),
-- 
1.8.3.1

  parent reply	other threads:[~2017-08-07  8:41 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-07  8:44 [PATCH 0/2] sched/debug: show task state on /proc/sched_debug Xie XiuQi
2017-08-07  8:44 ` [PATCH 1/2] " Xie XiuQi
2017-08-10 12:09   ` [tip:sched/core] sched/debug: Show task state in /proc/sched_debug tip-bot for Xie XiuQi
2017-08-07  8:44 ` Xie XiuQi [this message]
2017-08-08  6:42   ` [PATCH 2/2] sched/debug: intruduce task_state_to_char helper function kbuild test robot
2017-08-08  8:43     ` Xie XiuQi
2017-08-09  1:16     ` Xie XiuQi
2017-08-08 17:27   ` kbuild test robot
2017-08-10 12:10   ` [tip:sched/core] sched/debug: Intruduce task_state_to_char() " tip-bot for Xie XiuQi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1502095463-160172-3-git-send-email-xiexiuqi@huawei.com \
    --to=xiexiuqi@huawei.com \
    --cc=cj.chengjian@huawei.com \
    --cc=huawei.libin@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).