tracing: more updates
Steven Rostedt
maintainerIngo,
Please pull the latest tip/tracing/core3 tree, which can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.git
tip/tracing/core3
Steven Rostedt (3):
tracing: move tgid out of generic entry and into userstack
tracing: add lock depth to entries
tracing: consolidate code between trace_output.c and trace_function_graph.c
[email protected] (3):
tracing: create generic trace parser
tracing: trace parser support for set_event
tracing: trace parser support for function and graph
----
include/linux/ftrace_event.h | 2 +- kernel/trace/ftrace.c | 150 +++++++++------------------------- kernel/trace/trace.c | 117 +++++++++++++++++++++++++- kernel/trace/trace.h | 36 ++++++++ kernel/trace/trace_events.c | 64 ++++----------- kernel/trace/trace_functions_graph.c | 26 ++----- kernel/trace/trace_output.c | 42 ++++++++-- kernel/trace/trace_output.h | 2 + 8 files changed, 246 insertions(+), 193 deletions(-)
Steven Rostedt
maintainerPATCH 1/6 tracing: move tgid out of generic entry and into userstack
From: Steven Rostedt <[email protected]>
The userstack trace required the recording of the tgid entry. Unfortunately, it was added to the generic entry where it wasted 4 bytes of every entry and was only used by one entry.
This patch moves it out of the generic field and moves it into the only user (userstack_entry).
--- include/linux/ftrace_event.h | 1 - kernel/trace/trace.c | 2 +- kernel/trace/trace.h | 1 + kernel/trace/trace_events.c | 5 +---- kernel/trace/trace_output.c | 2 +- 5 files changed, 4 insertions(+), 7 deletions(-)
include/linux/ftrace_event.h +0 -1
@@ -34,7 +34,6 @@ struct trace_entry {unsigned char flags;unsigned char preempt_count;int pid; -int tgid; };#define FTRACE_MAX_EVENT \
kernel/trace/trace.c +1 -1
@@ -886,7 +886,6 @@ tracing_generic_entry_update(struct trace_entry *entry, unsigned long flags, entry->preempt_count = pc &0xff ; entry->pid = (tsk) ? tsk->pid :0 ; - entry->tgid = (tsk) ? tsk->tgid :0 ; entry->flags = #ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT (irqs_disabled_flags(flags) ? TRACE_FLAG_IRQS_OFF : 0) |
@@ -1068,6 +1067,7 @@ ftrace_trace_userstack(struct ring_buffer *buffer, unsigned long flags, int pc)return ; entry =ring_buffer_event_data (event); + entry->tgid = current->tgid;memset (&entry->caller,0 ,sizeof (entry->caller)); trace.nr_entries =0 ;
kernel/trace/trace.h +1 -0
@@ -101,6 +101,7 @@ struct stack_entry {struct userstack_entry {struct trace_entry ent; +unsigned int tgid;unsigned long caller[FTRACE_STACK_ENTRIES ]; };
kernel/trace/trace_events.c +1 -4
@@ -86,7 +86,6 @@ int trace_define_common_fields(struct ftrace_event_call *call) __common_field(unsigned char, flags); __common_field(unsigned char, preempt_count);__common_field (int, pid); -__common_field (int, tgid);return ret; }
@@ -572,13 +571,11 @@ static int trace_write_header(struct trace_seq *s)"\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n" "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n" "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n" -"\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n" "\n" , FIELD(unsigned short, type), FIELD(unsigned char, flags), FIELD(unsigned char, preempt_count), -FIELD (int, pid), - FIELD(int, tgid)); + FIELD(int, pid)); } static ssize_t
kernel/trace/trace_output.c +1 -1
@@ -407,7 +407,7 @@ seq_print_userip_objs(const struct userstack_entry *entry, struct trace_seq *s,* since individual threads might have already quit! */ rcu_read_lock (); - task =find_task_by_vpid (entry->ent.tgid); + task =find_task_by_vpid (entry->tgid);if (task) mm =get_task_mm (task);rcu_read_unlock ();
Signature · 3 lines
1.6.3.3 --
Steven Rostedt
maintainerPATCH 2/6 tracing: add lock depth to entries
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
This patch adds the lock depth of the big kernel lock to the generic entry header. This way we can see the depth of the lock and help in removing the BKL.
Example:
# _------=> CPU#
# / _-----=> irqs-off
# | / _----=> need-resched # || / _---=> hardirq/softirq # ||| / _--=> preempt-depth # |||| /_--=> lock-depth # |||||/ delay # cmd pid |||||| time | caller # \ / |||||| \ | / <idle>-0 2.N..3 5902255250us+: lock_acquire: read rcu_read_lock <idle>-0 2.N..3 5902255253us+: lock_release: rcu_read_lock <idle>-0 2dN..3 5902255257us+: lock_acquire: xtime_lock <idle>-0 2dN..4 5902255259us : lock_acquire: clocksource_lock <idle>-0 2dN..4 5902255261us+: lock_release: clocksource_lock
--- include/linux/ftrace_event.h | 1 + kernel/trace/trace.c | 9 +++++---- kernel/trace/trace_events.c | 5 ++++- kernel/trace/trace_functions_graph.c | 16 ++++++++++++---- kernel/trace/trace_output.c | 10 +++++++++- 5 files changed, 31 insertions(+), 10 deletions(-)
include/linux/ftrace_event.h +1 -0
@@ -34,6 +34,7 @@ struct trace_entry {unsigned char flags;unsigned char preempt_count;int pid; +int lock_depth; };#define FTRACE_MAX_EVENT \
kernel/trace/trace.c +5 -4
@@ -886,6 +886,7 @@ tracing_generic_entry_update(struct trace_entry *entry, unsigned long flags, entry->preempt_count = pc &0xff ; entry->pid = (tsk) ? tsk->pid :0 ; + entry->lock_depth = (tsk) ? tsk->lock_depth :0 ; entry->flags = #ifdef CONFIG_TRACE_IRQFLAGS_SUPPORT (irqs_disabled_flags(flags) ? TRACE_FLAG_IRQS_OFF : 0) |
@@ -1530,10 +1531,10 @@ static void print_lat_help_header(struct seq_file *m)seq_puts (m,"# | / _----=> need-resched \n" );seq_puts (m,"# || / _---=> hardirq/softirq \n" );seq_puts (m,"# ||| / _--=> preempt-depth \n" ); -seq_puts (m,"# |||| / \n" ); -seq_puts (m,"# ||||| delay \n" ); -seq_puts (m,"# cmd pid ||||| time | caller \n" ); -seq_puts (m,"# \\ / ||||| \\ | / \n" ); +seq_puts (m,"# |||| /_--=> lock-depth \n" ); +seq_puts (m,"# |||||/ delay \n" ); +seq_puts (m,"# cmd pid |||||| time | caller \n" ); +seq_puts (m,"# \\ / |||||| \\ | / \n" ); }static void print_func_help_header (struct seq_file *m)
kernel/trace/trace_events.c +4 -1
@@ -86,6 +86,7 @@ int trace_define_common_fields(struct ftrace_event_call *call) __common_field(unsigned char, flags); __common_field(unsigned char, preempt_count);__common_field (int, pid); +__common_field (int, lock_depth);return ret; }
@@ -571,11 +572,13 @@ static int trace_write_header(struct trace_seq *s)"\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n" "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n" "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n" +"\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n" "\n" , FIELD(unsigned short, type), FIELD(unsigned char, flags), FIELD(unsigned char, preempt_count), - FIELD(int, pid)); +FIELD (int, pid), + FIELD(int, lock_depth)); } static ssize_t
kernel/trace/trace_functions_graph.c +12 -4
@@ -368,6 +368,7 @@ static enum print_line_t print_graph_lat_fmt(struct trace_seq *s, struct trace_entry *entry) { int hardirq, softirq; +int ret; hardirq = entry->flags &TRACE_FLAG_HARDIRQ ; softirq = entry->flags &TRACE_FLAG_SOFTIRQ ;
@@ -382,6 +383,13 @@ print_graph_lat_fmt(struct trace_seq *s, struct trace_entry *entry) hardirq ? 'h' : softirq ? 's' : '.'))return 0 ; +if (entry->lock_depth <0 ) + ret =trace_seq_putc (s,'.' ); +else + ret =trace_seq_printf (s,"%d" , entry->lock_depth); +if (!ret) +return 0 ; +if (entry->preempt_count)return trace_seq_printf (s,"%x" , entry->preempt_count);return trace_seq_puts (s,"." );
@@ -1001,8 +1009,8 @@ static void print_lat_header(struct seq_file *s)seq_printf (s,"#%.*s / _----=> need-resched \n" , size, spaces);seq_printf (s,"#%.*s| / _---=> hardirq/softirq \n" , size, spaces);seq_printf (s,"#%.*s|| / _--=> preempt-depth \n" , size, spaces); -seq_printf (s,"#%.*s||| / \n" , size, spaces); -seq_printf (s,"#%.*s|||| \n" , size, spaces); +seq_printf (s,"#%.*s||| / _-=> lock-depth \n" , size, spaces); +seq_printf (s,"#%.*s|||| / \n" , size, spaces); }static void print_graph_headers (struct seq_file *s)
@@ -1021,7 +1029,7 @@ static void print_graph_headers(struct seq_file *s)if (tracer_flags.val &TRACE_GRAPH_PRINT_PROC )seq_printf (s," TASK/PID " );if (lat) -seq_printf (s,"||||" ); +seq_printf (s,"|||||" );if (tracer_flags.val &TRACE_GRAPH_PRINT_DURATION )seq_printf (s," DURATION " );seq_printf (s," FUNCTION CALLS\n" );
@@ -1035,7 +1043,7 @@ static void print_graph_headers(struct seq_file *s)if (tracer_flags.val &TRACE_GRAPH_PRINT_PROC )seq_printf (s," | | " );if (lat) -seq_printf (s,"||||" ); +seq_printf (s,"|||||" );if (tracer_flags.val &TRACE_GRAPH_PRINT_DURATION )seq_printf (s," | | " );seq_printf (s," | | | |\n" );
kernel/trace/trace_output.c +9 -1
@@ -465,6 +465,7 @@ lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu) {int hardirq, softirq;char comm[TASK_COMM_LEN ]; +int ret;trace_find_cmdline (entry->pid, comm); hardirq = entry->flags &TRACE_FLAG_HARDIRQ ;
@@ -481,9 +482,16 @@ lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu) hardirq ? 'h' : softirq ? 's' : '.'))return 0 ; +if (entry->lock_depth <0 ) + ret =trace_seq_putc (s,'.' ); +else + ret =trace_seq_printf (s,"%d" , entry->lock_depth); +if (!ret) +return 0 ; +if (entry->preempt_count)return trace_seq_printf (s,"%x" , entry->preempt_count); -return trace_seq_puts (s,"." ); +return trace_seq_putc (s,'.' ); }static unsigned long preempt_mark_thresh =100 ;
Signature · 3 lines
1.6.3.3 --
Steven Rostedt
maintainerPATCH 3/6 tracing: consolidate code between trace_output.c and trace_function_graph.c
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
Both trace_output.c and trace_function_graph.c do basically the same thing to handle the printing of the latency-format. This patch moves the code into one function that both can use.
--- kernel/trace/trace_functions_graph.c | 26 ++------------------------ kernel/trace/trace_output.c | 30 ++++++++++++++++++++++++------ kernel/trace/trace_output.h | 2 ++ 3 files changed, 28 insertions(+), 30 deletions(-)
kernel/trace/trace_functions_graph.c +2 -24
@@ -367,32 +367,10 @@ print_graph_proc(struct trace_seq *s, pid_t pid)static enum print_line_t print_graph_lat_fmt (struct trace_seq *s,struct trace_entry *entry) { -int hardirq, softirq; -int ret; - - hardirq = entry->flags &TRACE_FLAG_HARDIRQ ; - softirq = entry->flags &TRACE_FLAG_SOFTIRQ ; - -if (!trace_seq_printf (s," %c%c%c" , - (entry->flags &TRACE_FLAG_IRQS_OFF ) ?'d' : - (entry->flags &TRACE_FLAG_IRQS_NOSUPPORT ) ? -'X' :'.' , - (entry->flags &TRACE_FLAG_NEED_RESCHED ) ? -'N' :'.' , - (hardirq && softirq) ?'H' : - hardirq ?'h' : softirq ?'s' :'.' )) -return 0 ; - -if (entry->lock_depth <0 ) - ret =trace_seq_putc (s,'.' ); -else - ret =trace_seq_printf (s,"%d" , entry->lock_depth); -if (!ret) +if (!trace_seq_putc (s,' ' ))return 0 ; -if (entry->preempt_count) -return trace_seq_printf (s,"%x" , entry->preempt_count); -return trace_seq_puts (s,"." ); +return trace_print_lat_fmt (s, entry); }/* If the pid changed since the last trace, output this event */
kernel/trace/trace_output.c +24 -6
@@ -460,19 +460,23 @@ seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)return ret; } -static int -lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu) +/** +* trace_print_lat_fmt - print the irq, preempt and lockdep fields +* @s: trace seq struct to write to +* @entry: The trace entry field from the ring buffer +* +* Prints the generic fields of irqs off, in hard or softirq, preempt +* count and lock depth. +*/ +int trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry) { int hardirq, softirq; - char comm[TASK_COMM_LEN]; int ret; - trace_find_cmdline(entry->pid, comm); hardirq = entry->flags & TRACE_FLAG_HARDIRQ; softirq = entry->flags & TRACE_FLAG_SOFTIRQ; - if (!trace_seq_printf(s, "%8.8s-%-5d %3d%c%c%c", - comm, entry->pid, cpu, + if (!trace_seq_printf(s, "%c%c%c", (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' : (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ? 'X' : '.',
@@ -494,6 +498,20 @@ lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)return trace_seq_putc (s,'.' ); } +static int +lat_print_generic (struct trace_seq *s,struct trace_entry *entry,int cpu) +{ +char comm[TASK_COMM_LEN ]; + +trace_find_cmdline (entry->pid, comm); + +if (!trace_seq_printf (s,"%8.8s-%-5d %3d" , + comm, entry->pid, cpu)) +return 0 ; + +return trace_print_lat_fmt (s, entry); +} +static unsigned long preempt_mark_thresh =100 ; static int
kernel/trace/trace_output.h +2 -0
@@ -26,6 +26,8 @@ extern struct trace_event *ftrace_find_event(int type);extern enum print_line_t trace_nop_print (struct trace_iterator *iter,int flags); +extern int +trace_print_lat_fmt (struct trace_seq *s,struct trace_entry *entry);/* used by module unregistering */ extern int __unregister_ftrace_event (struct trace_event *event);
Signature · 3 lines
1.6.3.3 --
Steven Rostedt
maintainerPATCH 4/6 tracing: create generic trace parser
In reply to Steven RostedtFrom: [email protected] <[email protected]>
Create a "trace_parser" that can parse the user space input for separate words.
struct trace_parser is the descriptor.
Generic "trace_get_user" function that can be a helper to read multiple words passed in by user space.
LKML-Reference: <[email protected]>
--- kernel/trace/trace.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++ kernel/trace/trace.h | 35 ++++++++++++++++ 2 files changed, 141 insertions(+), 0 deletions(-)
kernel/trace/trace.c +106 -0
@@ -339,6 +339,112 @@ static struct {int trace_clock_id; +/* +* trace_parser_get_init - gets the buffer for trace parser +*/ +int trace_parser_get_init (struct trace_parser *parser,int size) +{ +memset (parser,0 ,sizeof (*parser)); + + parser->buffer =kmalloc (size,GFP_KERNEL ); +if (!parser->buffer) +return 1 ; + + parser->size = size; +return 0 ; +} + +/* +* trace_parser_put - frees the buffer for trace parser +*/ +void trace_parser_put (struct trace_parser *parser) +{ +kfree (parser->buffer); +} + +/* +* trace_get_user - reads the user input string separated by space +* (matched by isspace(ch)) +* +* For each string found the 'struct trace_parser' is updated, +* and the function returns. +* +* Returns number of bytes read. +* +* See kernel/trace/trace.h for 'struct trace_parser' details. +*/ +int trace_get_user (struct trace_parser *parser,const char __user *ubuf, +size_t cnt,loff_t *ppos) +{ +char ch; +size_t read =0 ; +ssize_t ret; + +if (!*ppos) +trace_parser_clear (parser); + + ret =get_user (ch, ubuf++); +if (ret) + goto out; + + read++; + cnt--; + +/* +* The parser is not finished with the last write, +* continue reading the user input without skipping spaces. +*/ +if (!parser->cont) { +/* skip white space */ +while (cnt &&isspace (ch)) { + ret =get_user (ch, ubuf++); +if (ret) + goto out; + read++; + cnt--; + } + +/* only spaces were written */ +if (isspace (ch)) { + *ppos += read; + ret = read; + goto out; + } + + parser->idx =0 ; + } + +/* read the non-space input */ +while (cnt && !isspace (ch)) { +if (parser->idx < parser->size) + parser->buffer[parser->idx++] = ch; +else { + ret = -EINVAL ; + goto out; + } + ret =get_user (ch, ubuf++); +if (ret) + goto out; + read++; + cnt--; + } + +/* We either got finished input or we have to wait for another call. */ +if (isspace (ch)) { + parser->buffer[parser->idx] =0 ; + parser->cont = false; + }else { + parser->cont = true; + parser->buffer[parser->idx++] = ch; + } + + *ppos += read; + ret = read; + +out: +return ret; +} +ssize_t trace_seq_to_user (struct trace_seq *s,char __user *ubuf,size_t cnt) {int len;
kernel/trace/trace.h +35 -0
@@ -616,6 +616,41 @@ static inline int ftrace_trace_task(struct task_struct *task)#endif /* +* struct trace_parser - servers for reading the user input separated by spaces +* @cont: set if the input is not complete - no final space char was found +* @buffer: holds the parsed user input +* @idx: user input lenght +* @size: buffer size +*/ +struct trace_parser { +bool cont; +char *buffer; +unsigned idx; +unsigned size; +}; + +static inline bool trace_parser_loaded (struct trace_parser *parser) +{ +return (parser->idx !=0 ); +} + +static inline bool trace_parser_cont (struct trace_parser *parser) +{ +return parser->cont; +} + +static inline void trace_parser_clear (struct trace_parser *parser) +{ + parser->cont = false; + parser->idx =0 ; +} + +extern int trace_parser_get_init (struct trace_parser *parser,int size); +extern void trace_parser_put (struct trace_parser *parser); +extern int trace_get_user (struct trace_parser *parser,const char __user *ubuf, +size_t cnt,loff_t *ppos); + +/* * trace_iterator_flags is an enumeration that defines bit * positions into trace_flags that controls the output. *
Signature · 3 lines
1.6.3.3 --
Steven Rostedt
maintainerRe: [PATCH 4/6] tracing: create generic trace parser
Quoted 3 lines · Steven Rostedt
plain text document attachment
(0004-tracing-create-generic-trace-parser.patch)
From: [email protected] <[email protected]>
Ug! I didn't realize that Jiri's email from line did not contain his name. Thus his email became the author not his real name.
Ingo, do you want me to fix this? His SoB is correct though.
-- Steve
Quoted 183 lines
Create a "
trace_parser" that can parse the user space input for separate words.struct
trace_parseris the descriptor.Generic "
trace_get_user" function that can be a helper to read multiple words passed in by user space.Signed-off-by Jiri Olsa <[email protected]>LKML-Reference: <[email protected]>
Signed-off-by Steven Rostedt <[email protected]>--- kernel/trace/trace.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++ kernel/trace/trace.h | 35 ++++++++++++++++ 2 files changed, 141 insertions(+), 0 deletions(-)kernel/trace/trace.c +106
-0@@ -339,6 +339,112 @@ static struct {int trace_clock_id; +/* +* trace_parser_get_init - gets the buffer for trace parser +*/ +int trace_parser_get_init (struct trace_parser *parser,int size) +{ +memset (parser,0 ,sizeof (*parser)); + + parser->buffer =kmalloc (size,GFP_KERNEL ); +if (!parser->buffer) +return 1 ; + + parser->size = size; +return 0 ; +} + +/* +* trace_parser_put - frees the buffer for trace parser +*/ +void trace_parser_put (struct trace_parser *parser) +{ +kfree (parser->buffer); +} + +/* +* trace_get_user - reads the user input string separated by space +* (matched by isspace(ch)) +* +* For each string found the 'struct trace_parser' is updated, +* and the function returns. +* +* Returns number of bytes read. +* +* See kernel/trace/trace.h for 'struct trace_parser' details. +*/ +int trace_get_user (struct trace_parser *parser,const char __user *ubuf, +size_t cnt,loff_t *ppos) +{ +char ch; +size_t read =0 ; +ssize_t ret; + +if (!*ppos) +trace_parser_clear (parser); + + ret =get_user (ch, ubuf++); +if (ret) + goto out; + + read++; + cnt--; + +/* +* The parser is not finished with the last write, +* continue reading the user input without skipping spaces. +*/ +if (!parser->cont) { +/* skip white space */ +while (cnt &&isspace (ch)) { + ret =get_user (ch, ubuf++); +if (ret) + goto out; + read++; + cnt--; + } + +/* only spaces were written */ +if (isspace (ch)) { + *ppos += read; + ret = read; + goto out; + } + + parser->idx =0 ; + } + +/* read the non-space input */ +while (cnt && !isspace (ch)) { +if (parser->idx < parser->size) + parser->buffer[parser->idx++] = ch; +else { + ret = -EINVAL ; + goto out; + } + ret =get_user (ch, ubuf++); +if (ret) + goto out; + read++; + cnt--; + } + +/* We either got finished input or we have to wait for another call. */ +if (isspace (ch)) { + parser->buffer[parser->idx] =0 ; + parser->cont = false; + }else { + parser->cont = true; + parser->buffer[parser->idx++] = ch; + } + + *ppos += read; + ret = read; + +out: +return ret; +} +ssize_t trace_seq_to_user (struct trace_seq *s,char __user *ubuf,size_t cnt) {int len;kernel/trace/trace.h +35
-0@@ -616,6 +616,41 @@ static inline int ftrace_trace_task(struct task_struct *task)#endif /* +* struct trace_parser - servers for reading the user input separated by spaces +* @cont: set if the input is not complete - no final space char was found +* @buffer: holds the parsed user input +* @idx: user input lenght +* @size: buffer size +*/ +struct trace_parser { +bool cont; +char *buffer; +unsigned idx; +unsigned size; +}; + +static inline bool trace_parser_loaded (struct trace_parser *parser) +{ +return (parser->idx !=0 ); +} + +static inline bool trace_parser_cont (struct trace_parser *parser) +{ +return parser->cont; +} + +static inline void trace_parser_clear (struct trace_parser *parser) +{ + parser->cont = false; + parser->idx =0 ; +} + +extern int trace_parser_get_init (struct trace_parser *parser,int size); +extern void trace_parser_put (struct trace_parser *parser); +extern int trace_get_user (struct trace_parser *parser,const char __user *ubuf, +size_t cnt,loff_t *ppos); + +/* * trace_iterator_flags is an enumeration that defines bit * positions into trace_flags that controls the output. * Signature · 1 line
1.6.3.3
Steven Rostedt
maintainerPATCH 5/6 tracing: trace parser support for set_event
In reply to Steven RostedtFrom: [email protected] <[email protected]>
Convert the parsing of the file 'set_event' to use the generic trace_praser 'trace_get_user' function.
LKML-Reference: <[email protected]>
--- kernel/trace/trace_events.c | 60 +++++++++--------------------------------- 1 files changed, 13 insertions(+), 47 deletions(-)
kernel/trace/trace_events.c +13 -47
@@ -230,11 +230,9 @@ static ssize_t ftrace_event_write(struct file *file, const char __user *ubuf, size_t cnt, loff_t *ppos) { + struct trace_parser parser;size_t read =0 ; -int i, set =1 ;ssize_t ret; -char *buf; -char ch;if (!cnt || cnt <0 )return 0 ;
@@ -243,60 +241,28 @@ ftrace_event_write(struct file *file, const char __user *ubuf,if (ret <0 )return ret; - ret =get_user (ch, ubuf++); -if (ret) -return ret; - read++; - cnt--; - -/* skip white space */ -while (cnt &&isspace (ch)) { - ret =get_user (ch, ubuf++); -if (ret) -return ret; - read++; - cnt--; - } - -/* Only white space found? */ -if (isspace (ch)) { - file->f_pos += read; - ret = read; -return ret; - } - - buf =kmalloc (EVENT_BUF_SIZE +1 ,GFP_KERNEL ); -if (!buf) +if (trace_parser_get_init (&parser,EVENT_BUF_SIZE +1 ))return -ENOMEM ; -if (cnt >EVENT_BUF_SIZE ) - cnt =EVENT_BUF_SIZE ; + read =trace_get_user (&parser, ubuf, cnt, ppos); + +if (trace_parser_loaded ((&parser))) { +int set =1 ; - i =0 ; -while (cnt && !isspace (ch)) { -if (!i && ch =='!' ) +if (*parser.buffer =='!' ) set =0 ; -else - buf[i++] = ch; - ret =get_user (ch, ubuf++); + parser.buffer[parser.idx] =0 ; + + ret =ftrace_set_clr_event (parser.buffer + !set, set);if (ret) - goto out_free; - read++; - cnt--; + goto out_put; } - buf[i] =0 ; - - file->f_pos += read; - - ret =ftrace_set_clr_event (buf, set); -if (ret) - goto out_free; ret = read; - out_free: -kfree (buf); + out_put: +trace_parser_put (&parser);return ret; }
Signature · 3 lines
1.6.3.3 --
Steven Rostedt
maintainerPATCH 6/6 tracing: trace parser support for function and graph
In reply to Steven RostedtFrom: [email protected] <[email protected]>
Convert the writing to 'set_graph_function', 'set_ftrace_filter' and 'set_ftrace_notrace' to use the generic trace_parser 'trace_get_user' function.
Removed FTRACE_ITER_CONT flag, since it's not needed after this change.
Minor fix in set_graph_function display - g_show function.
LKML-Reference: <[email protected]>
--- kernel/trace/ftrace.c | 150 +++++++++++++------------------------------------ 1 files changed, 40 insertions(+), 110 deletions(-)
kernel/trace/ftrace.c +40 -110
@@ -1323,11 +1323,10 @@ static int __init ftrace_dyn_table_alloc(unsigned long num_to_init)enum {FTRACE_ITER_FILTER = (1 <<0 ), -FTRACE_ITER_CONT = (1 <<1 ), -FTRACE_ITER_NOTRACE = (1 <<2 ), -FTRACE_ITER_FAILURES = (1 <<3 ), -FTRACE_ITER_PRINTALL = (1 <<4 ), -FTRACE_ITER_HASH = (1 <<5 ), +FTRACE_ITER_NOTRACE = (1 <<1 ), +FTRACE_ITER_FAILURES = (1 <<2 ), +FTRACE_ITER_PRINTALL = (1 <<3 ), +FTRACE_ITER_HASH = (1 <<4 ), };#define FTRACE_BUFF_MAX (KSYM_SYMBOL_LEN+4)/* room for wildcards */
@@ -1337,8 +1336,7 @@ struct ftrace_iterator {int hidx;int idx;unsigned flags; -unsigned char buffer[FTRACE_BUFF_MAX +1 ]; -unsigned buffer_idx; +struct trace_parser parser; }; static void *
@@ -1604,6 +1602,11 @@ ftrace_regex_open(struct inode *inode, struct file *file, int enable)if (!iter)return -ENOMEM ; +if (trace_parser_get_init (&iter->parser,FTRACE_BUFF_MAX )) { +kfree (iter); +return -ENOMEM ; + } +mutex_lock (&ftrace_regex_lock);if ((file->f_mode &FMODE_WRITE ) && (file->f_flags &O_TRUNC ))
@@ -2196,9 +2199,8 @@ ftrace_regex_write(struct file *file, const char __user *ubuf, size_t cnt, loff_t *ppos, int enable) { struct ftrace_iterator *iter; -char ch; -size_t read =0 ; -ssize_t ret; +struct trace_parser *parser; +ssize_t ret, read;if (!cnt || cnt <0 )return 0 ;
@@ -2211,72 +2213,23 @@ ftrace_regex_write(struct file *file, const char __user *ubuf, }else iter = file->private_data; -if (!*ppos) { - iter->flags &= ~FTRACE_ITER_CONT ; - iter->buffer_idx =0 ; - } - - ret =get_user (ch, ubuf++); -if (ret) - goto out; - read++; - cnt--; - -/* -* If the parser haven't finished with the last write, -* continue reading the user input without skipping spaces. -*/ -if (!(iter->flags &FTRACE_ITER_CONT )) { -/* skip white space */ -while (cnt &&isspace (ch)) { - ret =get_user (ch, ubuf++); -if (ret) - goto out; - read++; - cnt--; - } + parser = &iter->parser; + read =trace_get_user (parser, ubuf, cnt, ppos); -/* only spaces were written */ -if (isspace (ch)) { - *ppos += read; - ret = read; - goto out; - } - - iter->buffer_idx =0 ; - } - -while (cnt && !isspace (ch)) { -if (iter->buffer_idx <FTRACE_BUFF_MAX ) - iter->buffer[iter->buffer_idx++] = ch; -else { - ret = -EINVAL ; - goto out; - } - ret =get_user (ch, ubuf++); +if (trace_parser_loaded (parser) && + !trace_parser_cont (parser)) { + ret =ftrace_process_regex (parser->buffer, + parser->idx, enable);if (ret) goto out; - read++; - cnt--; - } -if (isspace (ch)) { - iter->buffer[iter->buffer_idx] =0 ; - ret =ftrace_process_regex (iter->buffer, - iter->buffer_idx, enable); -if (ret) - goto out; - iter->buffer_idx =0 ; - }else { - iter->flags |=FTRACE_ITER_CONT ; - iter->buffer[iter->buffer_idx++] = ch; +trace_parser_clear (parser); } - *ppos += read; ret = read; - out: -mutex_unlock (&ftrace_regex_lock); +mutex_unlock (&ftrace_regex_lock); +out:return ret; }
@@ -2381,6 +2334,7 @@ ftrace_regex_release(struct inode *inode, struct file *file, int enable) {struct seq_file *m = (struct seq_file *)file->private_data;struct ftrace_iterator *iter; +struct trace_parser *parser;mutex_lock (&ftrace_regex_lock);if (file->f_mode &FMODE_READ ) {
@@ -2390,9 +2344,10 @@ ftrace_regex_release(struct inode *inode, struct file *file, int enable) }else iter = file->private_data; -if (iter->buffer_idx) { - iter->buffer[iter->buffer_idx] =0 ; -ftrace_match_records (iter->buffer, iter->buffer_idx, enable); + parser = &iter->parser; +if (trace_parser_loaded (parser)) { + parser->buffer[parser->idx] =0 ; +ftrace_match_records (parser->buffer, parser->idx, enable); }mutex_lock (&ftrace_lock);
@@ -2400,7 +2355,9 @@ ftrace_regex_release(struct inode *inode, struct file *file, int enable)ftrace_run_update_code (FTRACE_ENABLE_CALLS );mutex_unlock (&ftrace_lock); +trace_parser_put (parser);kfree (iter); +mutex_unlock (&ftrace_regex_lock);return 0 ; }
@@ -2499,7 +2456,7 @@ static int g_show(struct seq_file *m, void *v)return 0 ; } -seq_printf (m,"%pf\n" , v); +seq_printf (m,"%pf\n" , (void *)*ptr);return 0 ; }
@@ -2602,12 +2559,10 @@ static ssize_t ftrace_graph_write(struct file *file, const char __user *ubuf, size_t cnt, loff_t *ppos) { - unsigned char buffer[FTRACE_BUFF_MAX+1]; + struct trace_parser parser;unsigned long *array;size_t read =0 ;ssize_t ret; -int index =0 ; -char ch;if (!cnt || cnt <0 )return 0 ;
@@ -2625,51 +2580,26 @@ ftrace_graph_write(struct file *file, const char __user *ubuf, }else array = file->private_data; - ret =get_user (ch, ubuf++); -if (ret) +if (trace_parser_get_init (&parser,FTRACE_BUFF_MAX )) { + ret = -ENOMEM ; goto out; - read++; - cnt--; - -/* skip white space */ -while (cnt &&isspace (ch)) { - ret =get_user (ch, ubuf++); -if (ret) - goto out; - read++; - cnt--; } -if (isspace (ch)) { - *ppos += read; - ret = read; - goto out; - } + read =trace_get_user (&parser, ubuf, cnt, ppos); -while (cnt && !isspace (ch)) { -if (index <FTRACE_BUFF_MAX ) - buffer[index++] = ch; -else { - ret = -EINVAL ; - goto out; - } - ret =get_user (ch, ubuf++); +if (trace_parser_loaded ((&parser))) { + parser.buffer[parser.idx] =0 ; + +/* we allow only one expression at a time */ + ret =ftrace_set_func (array, &ftrace_graph_count, + parser.buffer);if (ret) goto out; - read++; - cnt--; } - buffer[index] =0 ; - -/* we allow only one expression at a time */ - ret =ftrace_set_func (array, &ftrace_graph_count, buffer); -if (ret) - goto out; - - file->f_pos += read; ret = read; out: +trace_parser_put (&parser);mutex_unlock (&graph_lock);return ret;
Signature · 3 lines
1.6.3.3 --
Quoted 20 lines · Steven Rostedt
Ingo,
Please pull the latest tip/tracing/core3 tree, which can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.git
tip/tracing/core3Steven Rostedt (3):
tracing: move tgid out of generic entry and into userstack
tracing: add lock depth to entries
tracing: consolidate code betweentrace_output.candtrace_function_graph.c[email protected] (3):
tracing: create generic trace parser
tracing: trace parser support forset_event
tracing: trace parser support for function and graph----
Quoted 9 lines
include/linux/ftrace_event.h | 2 +- kernel/trace/ftrace.c | 150 +++++++++------------------------- kernel/trace/trace.c | 117 +++++++++++++++++++++++++- kernel/trace/trace.h | 36 ++++++++ kernel/trace/trace_events.c | 64 ++++----------- kernel/trace/trace_functions_graph.c | 26 ++----- kernel/trace/trace_output.c | 42 ++++++++-- kernel/trace/trace_output.h | 2 + 8 files changed, 246 insertions(+), 193 deletions(-)
Pulled, thanks Steve!
Ingo