for tip/tracing/ftrace
Steven Rostedt
maintainerIngo,
Please pull the latest tip/tracing/ftrace tree, which can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.git
tip/tracing/ftrace
Steven Rostedt (7):
ring-buffer: fix timestamp in partial ring_buffer_page_read
tracing: do not return EFAULT if read copied anything
tracing: fix seq read from trace files
tracing: add latency output format option
tracing: remove extra latency_trace method from trace structure
tracing: consolidate print_lat_fmt and print_trace_fmt
tracing: have latency tracers set the latency format
----
kernel/trace/blktrace.c | 1 - kernel/trace/ring_buffer.c | 6 ++- kernel/trace/trace.c | 81 ++++++++++-------------------------- kernel/trace/trace.h | 3 +- kernel/trace/trace_branch.c | 1 - kernel/trace/trace_irqsoff.c | 8 ++++ kernel/trace/trace_output.c | 32 -------------- kernel/trace/trace_output.h | 1 - kernel/trace/trace_sched_wakeup.c | 8 ++++ 9 files changed, 46 insertions(+), 95 deletions(-)
Steven Rostedt
maintainerPATCH 1/7 ring-buffer: fix timestamp in partial ring_buffer_page_read
From: Steven Rostedt <[email protected]>
If a partial ring_buffer_page_read happens, then some of the incremental timestamps may be lost. This patch writes the recent timestamp into the page that is passed back to the caller.
A partial ring_buffer_page_read is where the full page would not be written back to the user, and instead, just part of the page is copied to the user. A full page would be a page swap with the ring buffer and the timestamps would be correct.
--- kernel/trace/ring_buffer.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
kernel/trace/ring_buffer.c +5 -1
@@ -2461,6 +2461,7 @@ int ring_buffer_read_page(struct ring_buffer *buffer,unsigned long flags;unsigned int commit;unsigned int read; +u64 save_timestamp;int ret =-1 ;/*
@@ -2515,6 +2516,9 @@ int ring_buffer_read_page(struct ring_buffer *buffer,if (len < size) goto out; +/* save the current timestamp, since the user will need it */ + save_timestamp = cpu_buffer->read_stamp; +/* Need to copy one event at a time */ do { memcpy(bpage->data + pos, rpage->data + rpos, size);
@@ -2531,7 +2535,7 @@ int ring_buffer_read_page(struct ring_buffer *buffer,/* update bpage */ local_set (&bpage->commit, pos); - bpage->time_stamp = rpage->time_stamp; + bpage->time_stamp = save_timestamp;/* we copied everything to the beginning */ read =0 ;
Signature · 3 lines
1.6.1.3 --
Steven Rostedt
maintainerPATCH 2/7 tracing: do not return EFAULT if read copied anything
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
Impact: fix trace read to conform to standards
Andrew Morton, Theodore Tso and H. Peter Anvin brought to my attention that a userspace read should not return -EFAULT if it succeeded in copying anything. It should only return -EFAULT if it failed to copy at all.
This patch modifies the check of copy_from_user and updates the return code appropriately.
I also used H. Peter Anvin's short cut rule to just test ret == count.
--- kernel/trace/trace.c | 14 ++++++++++++-- 1 files changed, 12 insertions(+), 2 deletions(-)
kernel/trace/trace.c +12 -2
@@ -346,6 +346,9 @@ ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, size_t cnt)int len;int ret; +if (!cnt) +return 0 ; +if (s->len <= s->readpos)return -EBUSY ;
@@ -353,9 +356,11 @@ ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, size_t cnt)if (cnt > len) cnt = len; ret =copy_to_user (ubuf, s->buffer + s->readpos, cnt); -if (ret) +if (ret == cnt)return -EFAULT ; + cnt -= ret; + s->readpos += len;return cnt; }
@@ -3049,6 +3054,9 @@ tracing_buffers_read(struct file *filp, char __user *ubuf,ssize_t ret;size_t size; +if (!count) +return 0 ; +/* Do we have previous read data to read? */ if (info->read <PAGE_SIZE ) goto read;
@@ -3073,8 +3081,10 @@ read: size = count; ret =copy_to_user (ubuf, info->spare + info->read, size); -if (ret) +if (ret == size)return -EFAULT ; + size -= ret; + *ppos += size; info->read += size;
Signature · 3 lines
1.6.1.3 --
Steven Rostedt
maintainerPATCH 3/7 tracing: fix seq read from trace files
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
The buffer used by trace_seq was updated incorrectly. Instead of consuming what was actually read, it consumed the rest of the buffer on reads.
--- kernel/trace/trace.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
kernel/trace/trace.c +2 -2
@@ -361,7 +361,7 @@ ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, size_t cnt) cnt -= ret; - s->readpos += len; + s->readpos += cnt;return cnt; }
@@ -380,7 +380,7 @@ ssize_t trace_seq_to_buffer(struct trace_seq *s, void *buf, size_t cnt)if (!ret)return -EFAULT ; - s->readpos += len; + s->readpos += cnt;return cnt; }
Signature · 3 lines
1.6.1.3 --
Steven Rostedt
maintainerPATCH 4/7 tracing: add latency output format option
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
With the removal of the latency_trace file, we lost the ability to see some of the finer details in a trace. Like the state of interrupts enabled, the preempt count, need resched, and if we are in an interrupt handler, softirq handler or not.
This patch simply creates an option to bring back the old format. This also removes the warning about an unused variable that held the latency_trace file operations.
--- kernel/trace/trace.c | 24 ++---------------------- kernel/trace/trace.h | 3 ++- 2 files changed, 4 insertions(+), 23 deletions(-)
kernel/trace/trace.c +2 -22
@@ -299,6 +299,7 @@ static const char *trace_options[] = {"sym-userobj" ,"printk-msg-only" ,"context-info" , +"latency-format" , NULL };
@@ -1829,26 +1830,12 @@ static int tracing_open(struct inode *inode, struct file *file) iter =__tracing_open (inode, file);if (IS_ERR (iter)) ret =PTR_ERR (iter); - -return ret; -} - -static int tracing_lt_open (struct inode *inode,struct file *file) -{ -struct trace_iterator *iter; -int ret =0 ; - - iter =__tracing_open (inode, file); - -if (IS_ERR (iter)) - ret =PTR_ERR (iter); -else +else if (trace_flags &TRACE_ITER_LATENCY_FMT ) iter->iter_flags |=TRACE_FILE_LAT_FMT ;return ret; } -static void *t_next (struct seq_file *m,void *v,loff_t *pos) {
@@ -1927,13 +1914,6 @@ static struct file_operations tracing_fops = { .release = tracing_release, }; -static struct file_operations tracing_lt_fops = { - .open = tracing_lt_open, - .read = seq_read, - .llseek = seq_lseek, - .release = tracing_release, -}; -static struct file_operations show_traces_fops = { .open = show_traces_open, .read = seq_read,
kernel/trace/trace.h +2 -1
@@ -651,7 +651,8 @@ enum trace_iterator_flags {TRACE_ITER_USERSTACKTRACE =0x4000 ,TRACE_ITER_SYM_USEROBJ =0x8000 ,TRACE_ITER_PRINTK_MSGONLY =0x10000 , - TRACE_ITER_CONTEXT_INFO = 0x20000 /* Print pid/cpu/time */ +TRACE_ITER_CONTEXT_INFO =0x20000 ,/* Print pid/cpu/time */ + TRACE_ITER_LATENCY_FMT = 0x40000, };/*
Signature · 3 lines
1.6.1.3 --
Steven Rostedt
maintainerPATCH 5/7 tracing: remove extra latency_trace method from trace structure
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
Impact: clean up
The trace and latency_trace function pointers are identical for every tracer but the function tracer. The differences in the function tracer are trivial (latency output puts paranthesis around parent).
This patch removes the latency_trace pointer and all prints will now just use the trace output function pointer.
--- kernel/trace/blktrace.c | 1 - kernel/trace/trace.c | 2 +- kernel/trace/trace_branch.c | 1 - kernel/trace/trace_output.c | 32 -------------------------------- kernel/trace/trace_output.h | 1 - 5 files changed, 1 insertions(+), 36 deletions(-)
kernel/trace/blktrace.c +0 -1
@@ -1231,7 +1231,6 @@ static struct tracer blk_tracer __read_mostly = {static struct trace_event trace_blk_event = { .type =TRACE_BLK , .trace = blk_trace_event_print, - .latency_trace = blk_trace_event_print, .binary = blk_trace_event_print_binary, };
kernel/trace/trace.c +1 -1
@@ -1485,7 +1485,7 @@ static enum print_line_t print_lat_fmt(struct trace_iterator *iter) }if (event) -return event->latency_trace (iter, sym_flags); +return event->trace (iter, sym_flags);if (!trace_seq_printf (s,"Unknown type %d\n" , entry->type)) goto partial;
kernel/trace/trace_branch.c +0 -1
@@ -159,7 +159,6 @@ static enum print_line_t trace_branch_print(struct trace_iterator *iter,static struct trace_event trace_branch_event = { .type =TRACE_BRANCH , .trace = trace_branch_print, - .latency_trace = trace_branch_print, }; static struct tracer branch_trace __read_mostly =
kernel/trace/trace_output.c +0 -32
@@ -437,8 +437,6 @@ int register_ftrace_event(struct trace_event *event)if (event->trace ==NULL ) event->trace = trace_nop_print; -if (event->latency_trace ==NULL ) - event->latency_trace = trace_nop_print;if (event->raw ==NULL ) event->raw = trace_nop_print;if (event->hex ==NULL )
@@ -480,29 +478,6 @@ enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags) }/* TRACE_FN */ -static enum print_line_t trace_fn_latency (struct trace_iterator *iter, -int flags) -{ -struct ftrace_entry *field; -struct trace_seq *s = &iter->seq; - -trace_assign_type (field, iter->ent); - -if (!seq_print_ip_sym (s, field->ip, flags)) - goto partial; -if (!trace_seq_puts (s," (" )) - goto partial; -if (!seq_print_ip_sym (s, field->parent_ip, flags)) - goto partial; -if (!trace_seq_puts (s,")\n" )) - goto partial; - -return TRACE_TYPE_HANDLED ; - - partial: -return TRACE_TYPE_PARTIAL_LINE ; -} -static enum print_line_t trace_fn_trace (struct trace_iterator *iter,int flags) {struct ftrace_entry *field;
@@ -573,7 +548,6 @@ static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags)static struct trace_event trace_fn_event = { .type =TRACE_FN , .trace = trace_fn_trace, - .latency_trace = trace_fn_latency, .raw = trace_fn_raw, .hex = trace_fn_hex, .binary = trace_fn_bin,
@@ -705,7 +679,6 @@ static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter,static struct trace_event trace_ctx_event = { .type =TRACE_CTX , .trace = trace_ctx_print, - .latency_trace = trace_ctx_print, .raw = trace_ctx_raw, .hex = trace_ctx_hex, .binary = trace_ctxwake_bin,
@@ -714,7 +687,6 @@ static struct trace_event trace_ctx_event = {static struct trace_event trace_wake_event = { .type =TRACE_WAKE , .trace = trace_wake_print, - .latency_trace = trace_wake_print, .raw = trace_wake_raw, .hex = trace_wake_hex, .binary = trace_ctxwake_bin,
@@ -770,7 +742,6 @@ static enum print_line_t trace_special_bin(struct trace_iterator *iter,static struct trace_event trace_special_event = { .type =TRACE_SPECIAL , .trace = trace_special_print, - .latency_trace = trace_special_print, .raw = trace_special_print, .hex = trace_special_hex, .binary = trace_special_bin,
@@ -808,7 +779,6 @@ static enum print_line_t trace_stack_print(struct trace_iterator *iter,static struct trace_event trace_stack_event = { .type =TRACE_STACK , .trace = trace_stack_print, - .latency_trace = trace_stack_print, .raw = trace_special_print, .hex = trace_special_hex, .binary = trace_special_bin,
@@ -838,7 +808,6 @@ static enum print_line_t trace_user_stack_print(struct trace_iterator *iter,static struct trace_event trace_user_stack_event = { .type =TRACE_USER_STACK , .trace = trace_user_stack_print, - .latency_trace = trace_user_stack_print, .raw = trace_special_print, .hex = trace_special_hex, .binary = trace_special_bin,
@@ -883,7 +852,6 @@ static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags)static struct trace_event trace_print_event = { .type =TRACE_PRINT , .trace = trace_print_print, - .latency_trace = trace_print_print, .raw = trace_print_raw, };
kernel/trace/trace_output.h +0 -1
@@ -10,7 +10,6 @@ struct trace_event {struct hlist_node node;int type;trace_print_func trace; -trace_print_func latency_trace;trace_print_func raw;trace_print_func hex;trace_print_func binary;
Signature · 3 lines
1.6.1.3 --
Steven Rostedt
maintainerPATCH 6/7 tracing: consolidate print_lat_fmt and print_trace_fmt
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
Impact: clean up
Both print_lat_fmt and print_trace_fmt do pretty much the same thing except for one different function call. This patch consolidates the two functions and adds an if statement to perform the difference.
--- kernel/trace/trace.c | 39 +++++++-------------------------------- 1 files changed, 7 insertions(+), 32 deletions(-)
kernel/trace/trace.c +7 -32
@@ -1468,33 +1468,6 @@ static void test_cpu_buff_start(struct trace_iterator *iter)trace_seq_printf (s,"##### CPU %u buffer started ####\n" , iter->cpu); } -static enum print_line_t print_lat_fmt (struct trace_iterator *iter) -{ -struct trace_seq *s = &iter->seq; -unsigned long sym_flags = (trace_flags &TRACE_ITER_SYM_MASK ); -struct trace_event *event; -struct trace_entry *entry = iter->ent; - -test_cpu_buff_start (iter); - - event =ftrace_find_event (entry->type); - -if (trace_flags &TRACE_ITER_CONTEXT_INFO ) { -if (!trace_print_lat_context (iter)) - goto partial; - } - -if (event) -return event->trace (iter, sym_flags); - -if (!trace_seq_printf (s,"Unknown type %d\n" , entry->type)) - goto partial; - -return TRACE_TYPE_HANDLED ; -partial: -return TRACE_TYPE_PARTIAL_LINE ; -} -static enum print_line_t print_trace_fmt (struct trace_iterator *iter) {struct trace_seq *s = &iter->seq;
@@ -1509,8 +1482,13 @@ static enum print_line_t print_trace_fmt(struct trace_iterator *iter) event =ftrace_find_event (entry->type);if (trace_flags &TRACE_ITER_CONTEXT_INFO ) { -if (!trace_print_context (iter)) - goto partial; +if (iter->iter_flags &TRACE_FILE_LAT_FMT ) { +if (!trace_print_lat_context (iter)) + goto partial; + }else { +if (!trace_print_context (iter)) + goto partial; + } }if (event)
@@ -1652,9 +1630,6 @@ static enum print_line_t print_trace_line(struct trace_iterator *iter)if (trace_flags &TRACE_ITER_RAW )return print_raw_fmt (iter); -if (iter->iter_flags &TRACE_FILE_LAT_FMT ) -return print_lat_fmt (iter); -return print_trace_fmt (iter); }
Signature · 3 lines
1.6.1.3 --
Steven Rostedt
maintainerPATCH 7/7 tracing: have latency tracers set the latency format
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
The latency tracers (irqsoff, preemptoff, preemptirqsoff, and wakeup) are pretty useless with the default output format. This patch makes them automatically enable the latency format when they are selected. They also record the state of the latency option, and if it was not enabled when selected, they disable it on reset.
--- kernel/trace/trace_irqsoff.c | 8 ++++++++ kernel/trace/trace_sched_wakeup.c | 8 ++++++++ 2 files changed, 16 insertions(+), 0 deletions(-)
kernel/trace/trace_irqsoff.c +8 -0
@@ -32,6 +32,8 @@ enum {static int trace_type__read_mostly ; +static int save_lat_flag; +#ifdef CONFIG_PREEMPT_TRACER static inline int preempt_trace (void )
@@ -370,6 +372,9 @@ static void stop_irqsoff_tracer(struct trace_array *tr)static void __irqsoff_tracer_init (struct trace_array *tr) { + save_lat_flag = trace_flags &TRACE_ITER_LATENCY_FMT ; + trace_flags |=TRACE_ITER_LATENCY_FMT ; + tracing_max_latency =0 ; irqsoff_trace = tr;/* make sure that the tracer is visible */
@@ -380,6 +385,9 @@ static void __irqsoff_tracer_init(struct trace_array *tr)static void irqsoff_tracer_reset (struct trace_array *tr) {stop_irqsoff_tracer (tr); + +if (!save_lat_flag) + trace_flags &= ~TRACE_ITER_LATENCY_FMT ; }static void irqsoff_tracer_start (struct trace_array *tr)
kernel/trace/trace_sched_wakeup.c +8 -0
@@ -32,6 +32,8 @@ static raw_spinlock_t wakeup_lock =static void __wakeup_reset (struct trace_array *tr); +static int save_lat_flag; +#ifdef CONFIG_FUNCTION_TRACER /* * irqsoff uses its own tracer function to keep the overhead down:
@@ -324,6 +326,9 @@ static void stop_wakeup_tracer(struct trace_array *tr)static int __wakeup_tracer_init (struct trace_array *tr) { + save_lat_flag = trace_flags &TRACE_ITER_LATENCY_FMT ; + trace_flags |=TRACE_ITER_LATENCY_FMT ; + tracing_max_latency =0 ; wakeup_trace = tr;start_wakeup_tracer (tr);
@@ -347,6 +352,9 @@ static void wakeup_tracer_reset(struct trace_array *tr)stop_wakeup_tracer (tr);/* make sure we put back any tasks we are tracing */ wakeup_reset (tr); + +if (!save_lat_flag) + trace_flags &= ~TRACE_ITER_LATENCY_FMT ; }static void wakeup_tracer_start (struct trace_array *tr)
Signature · 3 lines
1.6.1.3 --
Quoted 19 lines · Steven Rostedt
Ingo,
Please pull the latest tip/tracing/ftrace tree, which can be found at:
git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.git
tip/tracing/ftraceSteven Rostedt (7):
ring-buffer: fix timestamp in partialring_buffer_page_read
tracing: do not return EFAULT if read copied anything
tracing: fix seq read from trace files
tracing: add latency output format option
tracing: remove extralatency_tracemethod from trace structure
tracing: consolidateprint_lat_fmtandprint_trace_fmt
tracing: have latency tracers set the latency format----
Quoted 10 lines
kernel/trace/blktrace.c | 1 - kernel/trace/ring_buffer.c | 6 ++- kernel/trace/trace.c | 81 ++++++++++-------------------------- kernel/trace/trace.h | 3 +- kernel/trace/trace_branch.c | 1 - kernel/trace/trace_irqsoff.c | 8 ++++ kernel/trace/trace_output.c | 32 -------------- kernel/trace/trace_output.h | 1 - kernel/trace/trace_sched_wakeup.c | 8 ++++ 9 files changed, 46 insertions(+), 95 deletions(-)
Pulled, thanks Steve!
Ingo