From: Thomas Gleixner <tglx@linutronix.de>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Ingo Molnar <mingo@elte.hu>, Steven Rostedt <rostedt@goodmis.org>,
Peter Zijlstra <peterz@infradead.org>,
Clark Williams <clark.williams@gmail.com>,
Gregory Haskins <ghaskins@novell.com>,
Linux-rt <linux-rt-users@vger.kernel.org>
Subject: [patch 1/7] ftrace: fix task state printout
Date: Fri, 19 Dec 2008 16:02:37 -0000 [thread overview]
Message-ID: <20081219155555.919550408@linutronix.de> (raw)
In-Reply-To: <20081219155504.735865178@linutronix.de>
[-- Attachment #1: ftrace-fix-task-state-printout.patch --]
[-- Type: text/plain, Size: 3801 bytes --]
Impact: tracer task state decoding is wrong, size check is buggy
The tracing code has interesting varieties of printing out task state.
Unfortunalely only one of the instances is correct as it copies the
code from sched.c:sched_show_task(). The others are plain wrong as
they treatthe bitfield as an integer offset into the character
array. Also the size check of the character array is wrong as it
includes the trailing \0.
Use a common state decoder inline which does the Right Thing.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
kernel/trace/trace.c | 40 ++++++++++++++++++----------------------
1 file changed, 18 insertions(+), 22 deletions(-)
Index: linux-2.6.24/kernel/trace/trace.c
===================================================================
--- linux-2.6.24.orig/kernel/trace/trace.c
+++ linux-2.6.24/kernel/trace/trace.c
@@ -1626,6 +1626,13 @@ lat_print_timestamp(struct trace_seq *s,
static const char state_to_char[] = TASK_STATE_TO_CHAR_STR;
+static int task_state_char(unsigned long state)
+{
+ int bit = state ? __ffs(state) + 1 : 0;
+
+ return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?';
+}
+
extern unsigned long sys_call_table[NR_syscalls];
#if defined(CONFIG_COMPAT) && defined(CONFIG_X86)
@@ -1654,7 +1661,6 @@ print_lat_fmt(struct trace_iterator *ite
char *comm;
int S, T;
int i;
- unsigned state;
if (!next_entry)
next_entry = entry;
@@ -1685,11 +1691,8 @@ print_lat_fmt(struct trace_iterator *ite
break;
case TRACE_CTX:
case TRACE_WAKE:
- T = entry->ctx.next_state < sizeof(state_to_char) ?
- state_to_char[entry->ctx.next_state] : 'X';
-
- state = entry->ctx.prev_state ? __ffs(entry->ctx.prev_state) + 1 : 0;
- S = state < sizeof(state_to_char) - 1 ? state_to_char[state] : 'X';
+ T = task_state_char(entry->ctx.next_state);
+ S = task_state_char(entry->ctx.prev_state);
comm = trace_find_cmdline(entry->ctx.next_pid);
trace_seq_printf(s, " %5d:%3d:%c %s %5d:%3d:%c %s\n",
entry->ctx.prev_pid,
@@ -1862,10 +1865,8 @@ static int print_trace_fmt(struct trace_
break;
case TRACE_CTX:
case TRACE_WAKE:
- S = entry->ctx.prev_state < sizeof(state_to_char) ?
- state_to_char[entry->ctx.prev_state] : 'X';
- T = entry->ctx.next_state < sizeof(state_to_char) ?
- state_to_char[entry->ctx.next_state] : 'X';
+ T = task_state_char(entry->ctx.next_state);
+ S = task_state_char(entry->ctx.prev_state);
ret = trace_seq_printf(s, " %5d:%3d:%c %s %5d:%3d:%c\n",
entry->ctx.prev_pid,
entry->ctx.prev_prio,
@@ -2012,12 +2013,10 @@ static int print_raw_fmt(struct trace_it
break;
case TRACE_CTX:
case TRACE_WAKE:
- S = entry->ctx.prev_state < sizeof(state_to_char) ?
- state_to_char[entry->ctx.prev_state] : 'X';
- T = entry->ctx.next_state < sizeof(state_to_char) ?
- state_to_char[entry->ctx.next_state] : 'X';
- if (entry->type == TRACE_WAKE)
- S = '+';
+ T = task_state_char(entry->ctx.next_state);
+ S = entry->type == TRACE_WAKE ? '+' :
+ task_state_char(entry->ctx.prev_state);
+
ret = trace_seq_printf(s, "%d %d %c %d %d %c\n",
entry->ctx.prev_pid,
entry->ctx.prev_prio,
@@ -2073,12 +2072,9 @@ static int print_hex_fmt(struct trace_it
break;
case TRACE_CTX:
case TRACE_WAKE:
- S = entry->ctx.prev_state < sizeof(state_to_char) ?
- state_to_char[entry->ctx.prev_state] : 'X';
- T = entry->ctx.next_state < sizeof(state_to_char) ?
- state_to_char[entry->ctx.next_state] : 'X';
- if (entry->type == TRACE_WAKE)
- S = '+';
+ T = task_state_char(entry->ctx.next_state);
+ S = entry->type == TRACE_WAKE ? '+' :
+ task_state_char(entry->ctx.prev_state);
SEQ_PUT_HEX_FIELD_RET(s, entry->ctx.prev_pid);
SEQ_PUT_HEX_FIELD_RET(s, entry->ctx.prev_prio);
SEQ_PUT_HEX_FIELD_RET(s, S);
--
next prev parent reply other threads:[~2008-12-19 16:19 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-19 16:02 [patch 0/7] 2.6.24.7-rt24 bugfixes Thomas Gleixner
2008-12-19 16:02 ` Thomas Gleixner [this message]
2008-12-19 16:25 ` [patch 1/7] ftrace: fix task state printout Frédéric Weisbecker
2008-12-19 21:36 ` Ingo Molnar
2008-12-19 21:40 ` Thomas Gleixner
2008-12-20 13:08 ` Frédéric Weisbecker
2008-12-19 16:02 ` [patch 2/7] sched: remove useless nointeractive state Thomas Gleixner
2008-12-19 16:02 ` [patch 3/7] rtmutex: remove unused variable Thomas Gleixner
2008-12-19 16:03 ` [patch 4/7] rtmutex: unify state manipulation Thomas Gleixner
2008-12-19 18:36 ` Steven Rostedt
2008-12-19 19:40 ` Thomas Gleixner
2008-12-19 16:03 ` [patch 5/7] rtmutex: remove uber optimization Thomas Gleixner
2008-12-19 16:03 ` [patch 6/7] rtmutex: remove useless schedule enforcement Thomas Gleixner
2008-12-19 16:03 ` [patch 7/7] rtmutex: prevent missed wakeups Thomas Gleixner
2008-12-19 21:22 [patch 0/7] 2.6.24.7-rt24 bugfixes V2 Thomas Gleixner
2008-12-19 21:22 ` [patch 1/7] ftrace: fix task state printout Thomas Gleixner
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=20081219155555.919550408@linutronix.de \
--to=tglx@linutronix.de \
--cc=clark.williams@gmail.com \
--cc=ghaskins@novell.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-users@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.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
all inboxes | Powered by JetHome®