Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1705246 > unrolled thread

[PATCH 2/2] sched/debug: intruduce task_state_to_char helper function

Started byXie XiuQi <xiexiuqi@huawei.com>
First post2017-08-07 10:50 +0200
Last post2017-08-10 14:20 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH 2/2] sched/debug: intruduce task_state_to_char helper function Xie XiuQi <xiexiuqi@huawei.com> - 2017-08-07 10:50 +0200
    [tip:sched/core] sched/debug: Intruduce task_state_to_char() helper  function tip-bot for Xie XiuQi <tipbot@zytor.com> - 2017-08-10 14:20 +0200

#1705246 — [PATCH 2/2] sched/debug: intruduce task_state_to_char helper function

FromXie XiuQi <xiexiuqi@huawei.com>
Date2017-08-07 10:50 +0200
Subject[PATCH 2/2] sched/debug: intruduce task_state_to_char helper function
Message-ID<ubLTz-5V4-5@gated-at.bofh.it>
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

[toc] | [next] | [standalone]


#1708506 — [tip:sched/core] sched/debug: Intruduce task_state_to_char() helper function

Fromtip-bot for Xie XiuQi <tipbot@zytor.com>
Date2017-08-10 14:20 +0200
Subject[tip:sched/core] sched/debug: Intruduce task_state_to_char() helper function
Message-ID<ucUBs-5tj-3@gated-at.bofh.it>
In reply to#1705246
Commit-ID:  20435d84e5f2041c64c792399ab6f2948a2c2252
Gitweb:     http://git.kernel.org/tip/20435d84e5f2041c64c792399ab6f2948a2c2252
Author:     Xie XiuQi <xiexiuqi@huawei.com>
AuthorDate: Mon, 7 Aug 2017 16:44:23 +0800
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Thu, 10 Aug 2017 12:18:20 +0200

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>
---
 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 8337e2d..c28b182 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.
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 6d91c10..f9f9948 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -5103,24 +5103,17 @@ out_unlock:
 	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 d8d2ea2..cfd84f7 100644
--- a/kernel/sched/debug.c
+++ b/kernel/sched/debug.c
@@ -426,14 +426,10 @@ static const char stat_nam[] = TASK_STATE_TO_CHAR_STR;
 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_state_to_char(p));
 
 	SEQ_printf(m, "%15s %5d %9Ld.%06ld %9Ld %5d ",
 		p->comm, task_pid_nr(p),

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web