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


Groups > linux.kernel > #1738976 > unrolled thread

[PATCH 1/8] sched: Consistent task-state printing

Started byPeter Zijlstra <peterz@infradead.org>
First post2017-09-25 14:20 +0200
Last post2017-09-25 22:10 +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 1/8] sched: Consistent task-state printing Peter Zijlstra <peterz@infradead.org> - 2017-09-25 14:20 +0200
    Re: [PATCH 1/8] sched: Consistent task-state printing Steven Rostedt <rostedt@goodmis.org> - 2017-09-25 22:10 +0200

#1738976 — [PATCH 1/8] sched: Consistent task-state printing

FromPeter Zijlstra <peterz@infradead.org>
Date2017-09-25 14:20 +0200
Subject[PATCH 1/8] sched: Consistent task-state printing
Message-ID<utAwG-6f6-13@gated-at.bofh.it>
Currently get_task_state() and task_state_to_char() report different
states, create a number of common helpers and unify the reported state
space.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
 fs/proc/array.c       |   15 ++-------------
 include/linux/sched.h |   26 +++++++++++++++++++-------
 2 files changed, 21 insertions(+), 20 deletions(-)

--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -129,19 +129,8 @@ static const char * const task_state_arr
 
 static inline const char *get_task_state(struct task_struct *tsk)
 {
-	unsigned int state = (tsk->state | tsk->exit_state) & TASK_REPORT;
-
-	/*
-	 * Parked tasks do not run; they sit in __kthread_parkme().
-	 * Without this check, we would report them as running, which is
-	 * clearly wrong, so we report them as sleeping instead.
-	 */
-	if (tsk->state == TASK_PARKED)
-		state = TASK_INTERRUPTIBLE;
-
-	BUILD_BUG_ON(1 + ilog2(TASK_REPORT) != ARRAY_SIZE(task_state_array)-1);
-
-	return task_state_array[fls(state)];
+	BUILD_BUG_ON(1 + ilog2(TASK_REPORT) != ARRAY_SIZE(task_state_array) - 1);
+	return task_state_array[__get_task_state(tsk)];
 }
 
 static inline int get_task_umask(struct task_struct *tsk)
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1244,17 +1244,29 @@ static inline pid_t task_pgrp_nr(struct
 	return task_pgrp_nr_ns(tsk, &init_pid_ns);
 }
 
-static inline char task_state_to_char(struct task_struct *task)
+static inline unsigned int __get_task_state(struct task_struct *tsk)
 {
-	const char stat_nam[] = TASK_STATE_TO_CHAR_STR;
-	unsigned long state = task->state;
+	unsigned int tsk_state = READ_ONCE(tsk->state);
+	unsigned int state = (tsk_state | tsk->exit_state) & TASK_REPORT;
 
-	state = state ? __ffs(state) + 1 : 0;
+	if (tsk_state == TASK_PARKED)
+		state = TASK_INTERRUPTIBLE;
 
-	/* 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 fls(state);
+}
+
+static inline char __task_state_to_char(unsigned int state)
+{
+	static const char state_char[] = "RSDTtXZ";
+
+	BUILD_BUG_ON(1 + ilog2(TASK_REPORT) != sizeof(state_char) - 2);
 
-	return state < sizeof(stat_nam) - 1 ? stat_nam[state] : '?';
+	return state_char[state];
+}
+
+static inline char task_state_to_char(struct task_struct *tsk)
+{
+	return __task_state_to_char(__get_task_state(tsk));
 }
 
 /**

[toc] | [next] | [standalone]


#1739256

FromSteven Rostedt <rostedt@goodmis.org>
Date2017-09-25 22:10 +0200
Message-ID<utHRw-2MV-9@gated-at.bofh.it>
In reply to#1738976
On Mon, 25 Sep 2017 14:07:48 +0200
Peter Zijlstra <peterz@infradead.org> wrote:

> +static inline char __task_state_to_char(unsigned int state)
> +{
> +	static const char state_char[] = "RSDTtXZ";
> +
> +	BUILD_BUG_ON(1 + ilog2(TASK_REPORT) != sizeof(state_char) - 2);
>  
> -	return state < sizeof(stat_nam) - 1 ? stat_nam[state] : '?';
> +	return state_char[state];
> +}
> +
> +static inline char task_state_to_char(struct task_struct *tsk)
> +{
> +	return __task_state_to_char(__get_task_state(tsk));
>  }
>  

So far I'm fine with the patch set, but I hate the non descriptive "__"
prefix of __task_state_to_char(). Can we make this a bit more
descriptive, because every time I see it in other patches, I go back to
this patch to see if we are using the right function.

What about something like:

task_state_to_state_char(unsigned int state);

task_to_state_char(struct task_struct *tsk);

?

This way, the "__" wont keep making me think we used the wrong
function.

-- Steve

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web