Fix writing to trace/trace_options
PATCH 1/1 Fix writing to trace/trace_options
writing to trace/trace_options use the index of the array to find the value of the flag. With branch tracer flag defined conditionally, this breaks writing to trace_options with branch tracer disabled.
--- kernel/trace/trace.c | 2 -- kernel/trace/trace.h | 2 -- 2 files changed, 0 insertions(+), 4 deletions(-)
kernel/trace/trace.c +0 -2
@@ -259,9 +259,7 @@ static const char *trace_options[] = {"sched-tree" ,"ftrace_printk" ,"ftrace_preempt" , -#ifdef CONFIG_BRANCH_TRACER"branch" , -#endif"annotate" ,"dump" ,NULL
kernel/trace/trace.h +0 -2
@@ -481,9 +481,7 @@ enum trace_iterator_flags {TRACE_ITER_SCHED_TREE =0x200 ,TRACE_ITER_PRINTK =0x400 ,TRACE_ITER_PREEMPTONLY =0x800 , -#ifdef CONFIG_BRANCH_TRACERTRACE_ITER_BRANCH =0x1000 , -#endifTRACE_ITER_ANNOTATE =0x2000 , TRACE_ITER_DUMP = 0x4000, };
Signature · 1 line
tg: (e186e8e..) an/branch-tracer-fix.patch (depends on: an/ext4-ftrace-test.patch)
PATCH 1/1 ftrace: Add new entry type TRACE_BIN_DUMP
The ftrace dump_entry can be used to dump binary data from kernel to userspace.
--- kernel/trace/trace.c | 8 ++++++++ kernel/trace/trace.h | 11 +++++++++++ 2 files changed, 19 insertions(+), 0 deletions(-)
kernel/trace/trace.c +8 -0
@@ -2106,6 +2106,14 @@ static enum print_line_t print_dump_fmt(struct trace_iterator *iter)trace_seq_print_cont (s, iter);break ; } +case TRACE_BIN_DUMP : { +struct dump_entry *field; + +trace_assign_type (field, entry); + +trace_seq_putmem (s, field->buf, field->len); +break ; + } }return TRACE_TYPE_HANDLED ; }
kernel/trace/trace.h +11 -0
@@ -26,6 +26,7 @@ enum trace_type {TRACE_BOOT_CALL ,TRACE_BOOT_RET ,TRACE_FN_RET , +TRACE_BIN_DUMP , __TRACE_LAST_TYPE };
@@ -107,6 +108,15 @@ struct print_entry {char buf[]; }; +/* +* bin dump entry: +*/ +struct dump_entry { +struct trace_entry ent; +int len; +char buf[]; +}; +#define TRACE_OLD_SIZE 88struct trace_field_cont {
@@ -249,6 +259,7 @@ extern void __ftrace_bad_type(void); IF_ASSIGN(var, ent, struct trace_boot_ret, TRACE_BOOT_RET);\ IF_ASSIGN(var, ent, struct trace_branch, TRACE_BRANCH); \ IF_ASSIGN(var, ent, struct ftrace_ret_entry, TRACE_FN_RET);\ + IF_ASSIGN(var, ent, struct dump_entry, TRACE_BIN_DUMP); \__ftrace_bad_type (); \ }while (0 )
Signature · 1 line
tg: (b382bc2..) an/ftrace-bin-dump.patch (depends on: an/ftrace-dp-printk.patch)
PATCH 1/1 ftrace: add proper bin iterator support
In s_show after print_trace_line we call trace_print_seq which does a strlen on the buffer containing binary data. I guess that would give wrong results for bin data even though we are null terminating it. We also don't want header in the output file if we have TRACE_ITER_BIN.
--- kernel/trace/trace.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 41 insertions(+), 0 deletions(-)
kernel/trace/trace.c +41 -0
@@ -2080,10 +2080,51 @@ static enum print_line_t print_trace_line(struct trace_iterator *iter)return print_trace_fmt (iter); } +static int s_bin_show (struct seq_file *m,void *v) +{ +int len; +enum print_line_t ret; +struct trace_iterator *iter = v; + +if (iter->ent ==NULL ) +return 0 ; + +if (iter->trace && iter->trace->print_line) { + ret = iter->trace->print_line (iter); +if (ret !=TRACE_TYPE_UNHANDLED ) + goto trace_handled; + } +/* +* If trace type is unhandled or if we don't have +* a print_line call the standard bin_fmt callback +*/ +print_bin_fmt (iter); + +trace_handled: +/* copy the trace buffer to seq file buffer */ +if (iter->seq.len >=PAGE_SIZE ) + len =PAGE_SIZE -1 ; +else + len = iter->seq.len; + +if (m->count + len < m->size) { +memcpy (m->buf + m->count, iter->seq.buffer, len); + m->count += len; + }else + m->count = m->size; +trace_seq_reset (&iter->seq); + +return 0 ; +} + +static int s_show (struct seq_file *m,void *v) {struct trace_iterator *iter = v; +if (trace_flags &TRACE_ITER_BIN ) +return s_bin_show (m, v); +if (iter->ent ==NULL ) {if (iter->tr) {seq_printf (m,"# tracer: %s\n" , iter->trace->name);
Signature · 1 line
tg: (7195b67..) an/ftrace-bin-iterator.patch (depends on: master)
PATCH 1/1 ftrace: Add debug_dump trace to dump binary data from kernel to userspace
The trace add a new interface debug_dump() which can be used to dump binary data using ftrace framework. Use the dump mode of iterator by 'echo dump > iter_ctrl' to read the value in userspace
--- include/linux/debug_dump.h | 10 ++++ kernel/trace/Kconfig | 6 ++ kernel/trace/Makefile | 1 + kernel/trace/trace_debugdump.c | 103 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 120 insertions(+), 0 deletions(-)
include/linux/debug_dump.h new file +10 -0
@@ -0,0 +1,10 @@ +#ifndef _LINUX_DEBUGDUMP_H +#define _LINUX_DEBUGDUMP_H +#include <linux/marker.h> + +#ifdef CONFIG_DEBUG_DUMP +extern int debug_dump (void *p,int len); +#else +#define debug_dump (p, len) +#endif +#endif /* _LINUX_DEBUGDUMP_H */
kernel/trace/Kconfig +6 -0
@@ -261,4 +261,10 @@ config DEBUG_PRINT help This tracer can be used for printk style debugging. +config DEBUG_DUMP + bool "Trace based dump support" + depends on DEBUG_KERNEL + select TRACING + help + This tracer can be used to dump binary data from kernel endmenu
kernel/trace/Makefile +1 -0
@@ -32,5 +32,6 @@ obj-$(CONFIG_BOOT_TRACER) += trace_boot.o obj-$(CONFIG_FUNCTION_RET_TRACER) += trace_functions_return.o obj-$(CONFIG_TRACE_BRANCH_PROFILING) += trace_branch.o obj-$(CONFIG_DEBUG_PRINT) += trace_debugprint.o +obj-$(CONFIG_DEBUG_DUMP) += trace_debugdump.o libftrace-y := ftrace.o
kernel/trace/trace_debugdump.c new file +103 -0
103 lines not on this page · raw message
Signature · 1 line
tg: (140170e..) an/ftrace-debug-dump.patch (depends on: an/ftrace-bin-dump.patch)
PATCH 1/1 ftrace: Add debug_print trace to print data from kernel to userspace
The trace add a new interface dp_printk() which can be used to dump data from kernel to user space using ftrace framework.
--- include/linux/debug_print.h | 12 +++++ kernel/trace/Kconfig | 7 +++ kernel/trace/Makefile | 1 + kernel/trace/trace_debugprint.c | 90 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 110 insertions(+), 0 deletions(-)
include/linux/debug_print.h new file +12 -0
@@ -0,0 +1,12 @@ +#ifndef _LINUX_DEBUGPRINT_H +#define _LINUX_DEBUGPRINT_H +#include <linux/marker.h> + +#ifdef CONFIG_DEBUG_PRINT +extern int do_dp_printk (const char *fmt, ...); +#define dp_printk(fmt, arg...) \ + do_dp_printk(fmt, ##arg) +#else +#define dp_printk(fmt, arg...) +#endif +#endif /* _LINUX_DEBUGPRINT_H */
kernel/trace/Kconfig +7 -0
@@ -254,4 +254,11 @@ config FTRACE_STARTUP_TEST functioning properly. It will do tests on all the configured tracers of ftrace. +config DEBUG_PRINT + bool "Trace based printk support" + depends on DEBUG_KERNEL + select TRACING + help + This tracer can be used for printk style debugging. + endmenu
kernel/trace/Makefile +1 -0
@@ -31,5 +31,6 @@ obj-$(CONFIG_MMIOTRACE) += trace_mmiotrace.o obj-$(CONFIG_BOOT_TRACER) += trace_boot.o obj-$(CONFIG_FUNCTION_RET_TRACER) += trace_functions_return.o obj-$(CONFIG_TRACE_BRANCH_PROFILING) += trace_branch.o +obj-$(CONFIG_DEBUG_PRINT) += trace_debugprint.o libftrace-y := ftrace.o
kernel/trace/trace_debugprint.c new file +90 -0
90 lines not on this page · raw message
Signature · 1 line
tg: (bfb3409..) an/ftrace-dp-printk.patch (depends on: an/ftrace-dump-iterator.patch)
PATCH 1/1 ftrace: Add dump iteator
This iteator doesn't print headers and tracer information in the ouput trace file. This can be obtained to get a dmesg style trace output file. Also can be used to dump binary data to via trace
--- kernel/trace/trace.c | 92 ++++++++++++++++++++++++++++++++++++++++++-------- kernel/trace/trace.h | 1 + 2 files changed, 79 insertions(+), 14 deletions(-)
kernel/trace/trace.c +78 -14
@@ -263,6 +263,7 @@ static const char *trace_options[] = {"branch" , #endif"annotate" , +"dump" ,NULL };
@@ -2038,6 +2039,77 @@ static enum print_line_t print_bin_fmt(struct trace_iterator *iter)return 1 ; } +static enum print_line_t print_dump_fmt (struct trace_iterator *iter) +{ +struct trace_seq *s = &iter->seq; +struct trace_entry *entry; + + entry = iter->ent; + +if (entry->type ==TRACE_CONT ) +return TRACE_TYPE_HANDLED ; + + +switch (entry->type) { +case TRACE_FN : { +struct ftrace_entry *field; + +trace_assign_type (field, entry); + +SEQ_PUT_FIELD_RET (s, entry->pid); +SEQ_PUT_FIELD_RET (s, iter->cpu); +SEQ_PUT_FIELD_RET (s, iter->ts); + +SEQ_PUT_FIELD_RET (s, field->ip); +SEQ_PUT_FIELD_RET (s, field->parent_ip); +break ; + } +case TRACE_CTX : { +struct ctx_switch_entry *field; + +trace_assign_type (field, entry); + +SEQ_PUT_FIELD_RET (s, entry->pid); +SEQ_PUT_FIELD_RET (s, iter->cpu); +SEQ_PUT_FIELD_RET (s, iter->ts); + +SEQ_PUT_FIELD_RET (s, field->prev_pid); +SEQ_PUT_FIELD_RET (s, field->prev_prio); +SEQ_PUT_FIELD_RET (s, field->prev_state); +SEQ_PUT_FIELD_RET (s, field->next_pid); +SEQ_PUT_FIELD_RET (s, field->next_prio); +SEQ_PUT_FIELD_RET (s, field->next_state); +break ; + } +case TRACE_SPECIAL : +case TRACE_STACK : { +struct special_entry *field; + +trace_assign_type (field, entry); + +SEQ_PUT_FIELD_RET (s, entry->pid); +SEQ_PUT_FIELD_RET (s, iter->cpu); +SEQ_PUT_FIELD_RET (s, iter->ts); + +SEQ_PUT_FIELD_RET (s, field->arg1); +SEQ_PUT_FIELD_RET (s, field->arg2); +SEQ_PUT_FIELD_RET (s, field->arg3); +break ; + } +case TRACE_PRINT : { +struct print_entry *field; + +trace_assign_type (field, entry); + +trace_seq_printf (s,"%s" , field->buf); +if (entry->flags &TRACE_FLAG_CONT ) +trace_seq_print_cont (s, iter); +break ; + } + } +return TRACE_TYPE_HANDLED ; +} +static int trace_empty (struct trace_iterator *iter) {int cpu;
@@ -2074,6 +2146,9 @@ static enum print_line_t print_trace_line(struct trace_iterator *iter)if (trace_flags &TRACE_ITER_RAW )return print_raw_fmt (iter); +if (trace_flags &TRACE_ITER_DUMP ) +return print_dump_fmt (iter); +if (iter->iter_flags &TRACE_FILE_LAT_FMT )return print_lat_fmt (iter, iter->idx, iter->cpu);
@@ -2083,24 +2158,12 @@ static enum print_line_t print_trace_line(struct trace_iterator *iter)static int s_bin_show (struct seq_file *m,void *v) {int len; -enum print_line_t ret;struct trace_iterator *iter = v;if (iter->ent ==NULL )return 0 ; -if (iter->trace && iter->trace->print_line) { - ret = iter->trace->print_line (iter); -if (ret !=TRACE_TYPE_UNHANDLED ) - goto trace_handled; - } -/* -* If trace type is unhandled or if we don't have -* a print_line call the standard bin_fmt callback -*/ -print_bin_fmt (iter); - -trace_handled: +print_trace_line (iter);/* copy the trace buffer to seq file buffer */ if (iter->seq.len >=PAGE_SIZE ) len =PAGE_SIZE -1 ;
@@ -2122,7 +2185,8 @@ static int s_show(struct seq_file *m, void *v) {struct trace_iterator *iter = v; -if (trace_flags &TRACE_ITER_BIN ) +if ((trace_flags &TRACE_ITER_BIN ) || + (trace_flags &TRACE_ITER_DUMP ))return s_bin_show (m, v);if (iter->ent ==NULL ) {
kernel/trace/trace.h +1 -0
@@ -474,6 +474,7 @@ enum trace_iterator_flags {TRACE_ITER_BRANCH =0x1000 , #endifTRACE_ITER_ANNOTATE =0x2000 , + TRACE_ITER_DUMP = 0x4000, };/*
Signature · 1 line
tg: (47b0062..) an/ftrace-dump-iterator.patch (depends on: an/ftrace-bin-iterator.patch)
Quoted 6 lines · Aneesh Kumar K.V
writing to trace/trace_options use the index of the array to find the value of the flag. With branch tracer flag defined conditionally, this breaks writing to
trace_optionswith branch tracer disabled.Signed-off-by Aneesh Kumar K.V <[email protected]>
tg export didn't add numbering to the patch based on dependency. So the series is in the below order
[PATCH] ftrace: add proper bin iterator support
[PATCH] ftrace: Add dump iteator
[PATCH] ftrace: Add debug_print trace to print data from kernel to userspace [PATCH] ftrace: Add new entry type TRACE_BIN_DUMP
[PATCH] ftrace: Add debug_dump trace to dump binary data from kernel to userspace [PATCH] Fix writing to trace/trace_options
The patches are against -tip with HEAD7195b6707adcd00f413ce07e6b9954b4c597495c
-aneesh
Steven Rostedt
maintainerQuoted 18 lines · Aneesh Kumar K.V
Quoted 6 lines · Aneesh Kumar K.V
writing to trace/trace_options use the index of the array to find the value of the flag. With branch tracer flag defined conditionally, this breaks writing to
trace_optionswith branch tracer disabled.Signed-off-by Aneesh Kumar K.V <[email protected]>tg export didn't add numbering to the patch based on dependency. So the series is in the below order
[PATCH] ftrace: add proper bin iterator support
[PATCH] ftrace: Add dump iteator
[PATCH] ftrace: Adddebug_printtrace to print data from kernel to userspace [PATCH] ftrace: Add new entry typeTRACE_BIN_DUMP
[PATCH] ftrace: Adddebug_dumptrace to dump binary data from kernel to userspace [PATCH] Fix writing to trace/trace_options
Quoted 2 lines
The patches are against -tip with HEAD
7195b6707adcd00f413ce07e6b9954b4c597495c
Thanks Aneesh,
I'll look closer at these patches on Monday.
-- Steve
Quoted 18 lines · Aneesh Kumar K.V
Quoted 6 lines · Aneesh Kumar K.V
writing to trace/trace_options use the index of the array to find the value of the flag. With branch tracer flag defined conditionally, this breaks writing to
trace_optionswith branch tracer disabled.Signed-off-by Aneesh Kumar K.V <[email protected]>tg export didn't add numbering to the patch based on dependency. So the series is in the below order
[PATCH] ftrace: add proper bin iterator support
[PATCH] ftrace: Add dump iteator
[PATCH] ftrace: Adddebug_printtrace to print data from kernel to userspace [PATCH] ftrace: Add new entry typeTRACE_BIN_DUMP
[PATCH] ftrace: Adddebug_dumptrace to dump binary data from kernel to userspace [PATCH] Fix writing to trace/trace_options
Quoted 2 lines
The patches are against -tip with HEAD
7195b6707adcd00f413ce07e6b9954b4c597495c
hm, i'm not sure about this. We already do binary dumping, but only for the cases where we actually know the structure of the data (i.e. binary dumping is just an output format, not a tracing type). And that is good so.
In your patchset right now nothing uses debug_dump(ptr, len) so it's hard to see exactly how we should shape it. What specific usages do you have in mind?
Ingo
Quoted 21 lines · Ingo Molnar
Quoted 18 lines · Aneesh Kumar K.V
Quoted 6 lines · Aneesh Kumar K.V
writing to trace/trace_options use the index of the array to find the value of the flag. With branch tracer flag defined conditionally, this breaks writing to
trace_optionswith branch tracer disabled.Signed-off-by Aneesh Kumar K.V <[email protected]>tg export didn't add numbering to the patch based on dependency. So the series is in the below order
[PATCH] ftrace: add proper bin iterator support
[PATCH] ftrace: Add dump iteator
[PATCH] ftrace: Adddebug_printtrace to print data from kernel to userspace [PATCH] ftrace: Add new entry typeTRACE_BIN_DUMP
[PATCH] ftrace: Adddebug_dumptrace to dump binary data from kernel to userspace [PATCH] Fix writing to trace/trace_options
Quoted 7 lines
Quoted 2 lines
The patches are against -tip with HEAD
7195b6707adcd00f413ce07e6b9954b4c597495chm, i'm not sure about this. We already do binary dumping, but only for the cases where we actually know the structure of the data (i.e. binary dumping is just an output format, not a tracing type). And that is good so.
Why do we need to limit to know structures. debug_dump can be looked at as a debugging helper which allows the user to send more data in binary format. Later user space can decide to look at the values. I had the below test case done to check the patches.
int err;
+ struct data {
+ char i;
+ int k;
+ };
+ struct data mydata = {.i = 'c', .k = 10};
/*
* If we have encountered a bitmap-format file, the size limit
* is smaller than s_maxbytes, which is for extent-mapped files. */
+ dp_printk("%s with value %d\n", __func__, pos);
+ debug_dump(&mydata, sizeof(mydata));
Quoted 4 lines
In your patchset right now nothing uses
debug_dump(ptr, len)so it's hard to see exactly how we should shape it. What specific usages do you have in mind?
If you are not convinced about debug_dump you may want to pick the first three patches that include a bug fix and support for dp_printk.
-aneesh
Quoted 51 lines · Aneesh Kumar K.V
Quoted 21 lines · Ingo Molnar
Quoted 18 lines · Aneesh Kumar K.V
Quoted 6 lines · Aneesh Kumar K.V
writing to trace/trace_options use the index of the array to find the value of the flag. With branch tracer flag defined conditionally, this breaks writing to
trace_optionswith branch tracer disabled.Signed-off-by Aneesh Kumar K.V <[email protected]>tg export didn't add numbering to the patch based on dependency. So the series is in the below order
[PATCH] ftrace: add proper bin iterator support
[PATCH] ftrace: Add dump iteator
[PATCH] ftrace: Adddebug_printtrace to print data from kernel to userspace [PATCH] ftrace: Add new entry typeTRACE_BIN_DUMP
[PATCH] ftrace: Adddebug_dumptrace to dump binary data from kernel to userspace [PATCH] Fix writing to trace/trace_optionsQuoted 7 lines
Quoted 2 lines
The patches are against -tip with HEAD
7195b6707adcd00f413ce07e6b9954b4c597495chm, i'm not sure about this. We already do binary dumping, but only for the cases where we actually know the structure of the data (i.e. binary dumping is just an output format, not a tracing type). And that is good so.
Why do we need to limit to know structures.
debug_dumpcan be looked at as a debugging helper which allows the user to send more data in binary format. Later user space can decide to look at the values. I had the below test case done to check the patches.(quoted diff) +7
-0int err; + struct data { + char i; + int k; + }; + struct data mydata = {.i = 'c', .k = 10}; /* * If we have encountered a bitmap-format file, the size limit * is smaller than s_maxbytes, which is for extent-mapped files. */ + dp_printk("%s with value %d\n", __func__, pos); + debug_dump(&mydata, sizeof(mydata));Quoted 3 lines
Quoted 7 lines
Quoted 3 lines
In your patchset right now nothing uses
debug_dump(ptr, len)so it's hard to see exactly how we should shape it. What specific usages do you have in mind?If you are not convinced about
debug_dumpyou may want to pick the first three patches that include a bug fix and support fordp_printk.
i'm still wondering about the specific usecase you have in mind. Where do we want to dump unstructured data to user-space? If you look at all the existing ftrace plugins we know the structure of the logged data very well, and most of the plugins have semantic dependencies on that data content as well.
and having binary log data that _only_ user-space can process meaningfully, while it's opaque to the tracer plugin, sounds like a poor concept to me.
Ingo
Steven Rostedt
maintainerQuoted 4 lines · Aneesh Kumar K.V
writing to trace/trace_options use the index of the array to find the value of the flag. With branch tracer flag defined conditionally, this breaks writing to
trace_optionswith branch tracer disabled.
Ug, you're right!
Quoted 13 lines
Signed-off-by Aneesh Kumar K.V <[email protected]>--- kernel/trace/trace.c | 2 -- kernel/trace/trace.h | 2 -- 2 files changed, 0 insertions(+), 4 deletions(-)kernel/trace/trace.c +0
-0
kernel/trace/trace.c static const char *trace_options[] = { · line 262
Quoted 5 lines
kernel/trace/trace.c +0
-1@@ -259,9 +259,7 @@ static const char *trace_options[] = {"sched-tree" ,"ftrace_printk" ,"ftrace_preempt" , -#ifdef CONFIG_BRANCH_TRACER "branch",
Perhaps what we need is to have this NULL if CONFIG_BRANCH_TRACER is not set, and change the other code to skip NULL pointers.
-- Steve
Quoted 22 lines
kernel/trace/trace.c +0
-1-#endif "annotate" ,"dump" ,NULL kernel/trace/trace.h +0
-2@@ -481,9 +481,7 @@ enum trace_iterator_flags {TRACE_ITER_SCHED_TREE =0x200 ,TRACE_ITER_PRINTK =0x400 ,TRACE_ITER_PREEMPTONLY =0x800 , -#ifdef CONFIG_BRANCH_TRACERTRACE_ITER_BRANCH =0x1000 , -#endifTRACE_ITER_ANNOTATE =0x2000 , TRACE_ITER_DUMP = 0x4000, };Signature · 1 line
tg: (e186e8e..) an/branch-tracer-fix.patch (depends on: an/ext4-ftrace-test.patch)
Ingo Molnar
AppliedQuoted 11 lines · Aneesh Kumar K.V
writing to trace/trace_options use the index of the array to find the value of the flag. With branch tracer flag defined conditionally, this breaks writing to
trace_optionswith branch tracer disabled.Signed-off-by Aneesh Kumar K.V <[email protected]>--- kernel/trace/trace.c | 2 -- kernel/trace/trace.h | 2 -- 2 files changed, 0 insertions(+), 4 deletions(-)
applied to tip/tracing/branch-tracer, thanks Aneesh!
Ingo