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


Groups > linux.kernel > #1742066 > unrolled thread

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

Started byPeter Zijlstra <peterz@infradead.org>
First post2017-09-29 14:00 +0200
Last post2017-09-29 15: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

  Re: [PATCH 1/8] sched: Consistent task-state printing Peter Zijlstra <peterz@infradead.org> - 2017-09-29 14:00 +0200
    Re: [PATCH 1/8] sched: Consistent task-state printing Steven Rostedt <rostedt@goodmis.org> - 2017-09-29 15:10 +0200

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

FromPeter Zijlstra <peterz@infradead.org>
Date2017-09-29 14:00 +0200
SubjectRe: [PATCH 1/8] sched: Consistent task-state printing
Message-ID<uv27w-5HZ-3@gated-at.bofh.it>
On Mon, Sep 25, 2017 at 04:01:09PM -0400, Steven Rostedt wrote:
> 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);
> 
> ?

Hurmph.. naming.

How about something like so?


--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -137,7 +137,7 @@ static const char * const task_state_arr
 static inline const char *get_task_state(struct task_struct *tsk)
 {
 	BUILD_BUG_ON(1 + ilog2(TASK_REPORT_MAX) != ARRAY_SIZE(task_state_array));
-	return task_state_array[__get_task_state(tsk)];
+	return task_state_array[task_state_index(tsk)];
 }
 
 static inline int get_task_umask(struct task_struct *tsk)
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1245,7 +1245,7 @@ static inline pid_t task_pgrp_nr(struct
 #define TASK_REPORT_IDLE	(TASK_REPORT + 1)
 #define TASK_REPORT_MAX		(TASK_REPORT_IDLE << 1)
 
-static inline unsigned int __get_task_state(struct task_struct *tsk)
+static inline unsigned int task_state_index(struct task_struct *tsk)
 {
 	unsigned int tsk_state = READ_ONCE(tsk->state);
 	unsigned int state = (tsk_state | tsk->exit_state) & TASK_REPORT;
@@ -1258,7 +1258,7 @@ static inline unsigned int __get_task_st
 	return fls(state);
 }
 
-static inline char __task_state_to_char(unsigned int state)
+static inline char task_index_to_char(unsigned int state)
 {
 	static const char state_char[] = "RSDTtXZPI";
 
@@ -1269,7 +1269,7 @@ static inline char __task_state_to_char(
 
 static inline char task_state_to_char(struct task_struct *tsk)
 {
-	return __task_state_to_char(__get_task_state(tsk));
+	return task_index_to_char(task_state_index(tsk));
 }
 
 /**
--- a/include/trace/events/sched.h
+++ b/include/trace/events/sched.h
@@ -117,7 +117,7 @@ static inline long __trace_sched_switch_
 	if (preempt)
 		return TASK_STATE_MAX;
 
-	return __get_task_state(p);
+	return task_state_index(p);
 }
 #endif /* CREATE_TRACE_POINTS */
 
--- a/kernel/trace/trace_output.c
+++ b/kernel/trace/trace_output.c
@@ -921,8 +921,8 @@ static enum print_line_t trace_ctxwake_p
 
 	trace_assign_type(field, iter->ent);
 
-	T = __task_state_to_char(field->next_state);
-	S = __task_state_to_char(field->prev_state);
+	T = task_index_to_char(field->next_state);
+	S = task_index_to_char(field->prev_state);
 	trace_find_cmdline(field->next_pid, comm);
 	trace_seq_printf(&iter->seq,
 			 " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
@@ -957,8 +957,8 @@ static int trace_ctxwake_raw(struct trac
 	trace_assign_type(field, iter->ent);
 
 	if (!S)
-		S = __task_state_to_char(field->prev_state);
-	T = __task_state_to_char(field->next_state);
+		S = task_index_to_char(field->prev_state);
+	T = task_index_to_char(field->next_state);
 	trace_seq_printf(&iter->seq, "%d %d %c %d %d %d %c\n",
 			 field->prev_pid,
 			 field->prev_prio,
@@ -993,8 +993,8 @@ static int trace_ctxwake_hex(struct trac
 	trace_assign_type(field, iter->ent);
 
 	if (!S)
-		S = __task_state_to_char(field->prev_state);
-	T = __task_state_to_char(field->next_state);
+		S = task_index_to_char(field->prev_state);
+	T = task_index_to_char(field->next_state);
 
 	SEQ_PUT_HEX_FIELD(s, field->prev_pid);
 	SEQ_PUT_HEX_FIELD(s, field->prev_prio);
--- a/kernel/trace/trace_sched_wakeup.c
+++ b/kernel/trace/trace_sched_wakeup.c
@@ -397,10 +397,10 @@ tracing_sched_switch_trace(struct trace_
 	entry	= ring_buffer_event_data(event);
 	entry->prev_pid			= prev->pid;
 	entry->prev_prio		= prev->prio;
-	entry->prev_state		= __get_task_state(prev);
+	entry->prev_state		= task_state_index(prev);
 	entry->next_pid			= next->pid;
 	entry->next_prio		= next->prio;
-	entry->next_state		= __get_task_state(next);
+	entry->next_state		= task_state_index(next);
 	entry->next_cpu	= task_cpu(next);
 
 	if (!call_filter_check_discard(call, entry, buffer, event))
@@ -425,10 +425,10 @@ tracing_sched_wakeup_trace(struct trace_
 	entry	= ring_buffer_event_data(event);
 	entry->prev_pid			= curr->pid;
 	entry->prev_prio		= curr->prio;
-	entry->prev_state		= __get_task_state(curr);
+	entry->prev_state		= task_state_index(curr);
 	entry->next_pid			= wakee->pid;
 	entry->next_prio		= wakee->prio;
-	entry->next_state		= __get_task_state(wakee);
+	entry->next_state		= task_state_index(wakee);
 	entry->next_cpu			= task_cpu(wakee);
 
 	if (!call_filter_check_discard(call, entry, buffer, event))

[toc] | [next] | [standalone]


#1742093

FromSteven Rostedt <rostedt@goodmis.org>
Date2017-09-29 15:10 +0200
Message-ID<uv3df-6Af-19@gated-at.bofh.it>
In reply to#1742066
On Fri, 29 Sep 2017 13:50:16 +0200
Peter Zijlstra <peterz@infradead.org> wrote:

> On Mon, Sep 25, 2017 at 04:01:09PM -0400, Steven Rostedt wrote:
> > 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);
> > 
> > ?  
> 
> Hurmph.. naming.
> 
> How about something like so?
> 

I'm not picky, I just hate beginning underscores, and wish we can start
removing all functions that use them.

Acked-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

-- Steve

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web