tracing: Some more last minute updates for 5.6
Subsystems (4)
Steven Rostedt
maintainercover tracing: Some more last minute updates for 5.6
Masami Hiramatsu (2):
tracing/boot: Include required headers and sort it alphabetically tracing/boot: Move external function declarations to kernel/trace/trace.h
Mathieu Desnoyers (1):
tracing: Fix sched switch start/stop refcount racy updates
Steven Rostedt (VMware) (4):
tracing: Move all function tracing configs together
tracing: Move tracing test module configs together
tracing: Move mmio tracer config up with the other tracers
tracing: Move tracing selftests to bottom of menu
Tom Zanussi (11):
tracing: Add trace_array_find/_get() to find instance trace arrays
tracing: Add trace_get/put_event_file()
tracing: Add synth_event_delete()
tracing: Add dynamic event command creation interface
tracing: Add synthetic event command generation functions
tracing: Add synth_event_trace() and related functions
tracing: Add synth event generation test module
tracing: Add kprobe event command generation functions
tracing: Change trace_boot to use kprobe_event interface
tracing: Add kprobe event command generation test module
tracing: Documentation for in-kernel synthetic event API
Vasily Averin (3):
ftrace: fpid_next() should increase position index
tracing: eval_map_next() should always increase position index trigger_next should increase position index
----
Documentation/trace/events.rst | 515 ++++++++++++++++++++ include/linux/trace_events.h | 124 +++++ kernel/trace/Kconfig | 369 +++++++------- kernel/trace/Makefile | 2 + kernel/trace/ftrace.c | 5 +- kernel/trace/kprobe_event_gen_test.c | 225 +++++++++ kernel/trace/synth_event_gen_test.c | 523 ++++++++++++++++++++ kernel/trace/trace.c | 47 +- kernel/trace/trace.h | 19 + kernel/trace/trace_boot.c | 59 +-- kernel/trace/trace_dynevent.c | 240 ++++++++++ kernel/trace/trace_dynevent.h | 33 ++ kernel/trace/trace_events.c | 85 ++++ kernel/trace/trace_events_hist.c | 897 ++++++++++++++++++++++++++++++++++- kernel/trace/trace_events_trigger.c | 5 +- kernel/trace/trace_kprobe.c | 160 ++++++- kernel/trace/trace_sched_switch.c | 4 +- 17 files changed, 3065 insertions(+), 247 deletions(-) create mode 100644 kernel/trace/kprobe_event_gen_test.c create mode 100644 kernel/trace/synth_event_gen_test.c
Steven Rostedt
maintainerPATCH 1/21 tracing/boot: Include required headers and sort it alphabetically
From: Masami Hiramatsu <[email protected]>
Include some required (but currently indirectly included) headers and sort it alphabetically.
--- kernel/trace/trace_boot.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
kernel/trace/trace_boot.c +8 -1
@@ -6,9 +6,16 @@#define pr_fmt (fmt) "trace_boot: " fmt +#include <linux/bootconfig.h> +#include <linux/cpumask.h> #include <linux/ftrace.h> #include <linux/init.h> -#include <linux/bootconfig.h> +#include <linux/kernel.h> +#include <linux/mutex.h> +#include <linux/string.h> +#include <linux/slab.h> +#include <linux/trace.h> +#include <linux/trace_events.h> #include "trace.h"
Signature · 1 line
2.24.1
Steven Rostedt
maintainerPATCH 2/21 tracing/boot: Move external function declarations to kernel/trace/trace.h
In reply to Steven RostedtFrom: Masami Hiramatsu <[email protected]>
Move external function declarations into kernel/trace/trace.h from trace_boot.c for tracing subsystem internal use.
--- kernel/trace/trace.h | 17 +++++++++++++++++ kernel/trace/trace_boot.c | 15 --------------- 2 files changed, 17 insertions(+), 15 deletions(-)
kernel/trace/trace.h +17 -0
@@ -1157,6 +1157,11 @@ int unregister_ftrace_command(struct ftrace_func_command *cmd);void ftrace_create_filter_files (struct ftrace_ops *ops,struct dentry *parent);void ftrace_destroy_filter_files (struct ftrace_ops *ops); + +extern int ftrace_set_filter (struct ftrace_ops *ops,unsigned char *buf, +int len,int reset); +extern int ftrace_set_notrace (struct ftrace_ops *ops,unsigned char *buf, +int len,int reset);#else struct ftrace_func_command ;
@@ -1905,6 +1910,15 @@ void trace_printk_start_comm(void);int trace_keep_overwrite (struct tracer *tracer,u32 mask,int set);int set_tracer_flag (struct trace_array *tr,unsigned int mask,int enabled); +/* Used from boot time tracer */ +extern int trace_set_options (struct trace_array *tr,char *option); +extern int tracing_set_tracer (struct trace_array *tr,const char *buf); +extern ssize_t tracing_resize_ring_buffer (struct trace_array *tr, +unsigned long size,int cpu_id); +extern int tracing_set_cpumask (struct trace_array *tr, +cpumask_var_t tracing_cpumask_new); + +#define MAX_EVENT_NAME_LEN 64extern int trace_run_command (const char *buf,int (*createfn)(int ,char **));
@@ -1964,6 +1978,9 @@ static inline const char *get_syscall_name(int syscall)#ifdef CONFIG_EVENT_TRACING void trace_event_init (void );void trace_event_eval_update (struct trace_eval_map **map,int len); +/* Used from boot time tracer */ +extern int ftrace_set_clr_event (struct trace_array *tr,char *buf,int set); +extern int trigger_process_regex (struct trace_event_file *file,char *buff);#else static inline void __init trace_event_init (void ) { }static inline void trace_event_eval_update (struct trace_eval_map **map,int len) { }
kernel/trace/trace_boot.c +0 -15
@@ -21,13 +21,6 @@#define MAX_BUF_LEN 256 -extern int trace_set_options (struct trace_array *tr,char *option); -extern int tracing_set_tracer (struct trace_array *tr,const char *buf); -extern ssize_t tracing_resize_ring_buffer (struct trace_array *tr, -unsigned long size,int cpu_id); -extern int tracing_set_cpumask (struct trace_array *tr, -cpumask_var_t tracing_cpumask_new); -static void __init trace_boot_set_instance_options (struct trace_array *tr,struct xbc_node *node) {
@@ -76,9 +69,6 @@ trace_boot_set_instance_options(struct trace_array *tr, struct xbc_node *node) }#ifdef CONFIG_EVENT_TRACING -extern int ftrace_set_clr_event (struct trace_array *tr,char *buf,int set); -extern int trigger_process_regex (struct trace_event_file *file,char *buff); -static void __init trace_boot_enable_events (struct trace_array *tr,struct xbc_node *node) {
@@ -252,11 +242,6 @@ trace_boot_init_events(struct trace_array *tr, struct xbc_node *node)#endif #ifdef CONFIG_DYNAMIC_FTRACE -extern bool ftrace_filter_param__initdata ; -extern int ftrace_set_filter (struct ftrace_ops *ops,unsigned char *buf, -int len,int reset); -extern int ftrace_set_notrace (struct ftrace_ops *ops,unsigned char *buf, -int len,int reset);static void __init trace_boot_set_ftrace_filter (struct trace_array *tr,struct xbc_node *node) {
Signature · 1 line
2.24.1
Steven Rostedt
maintainerPATCH 3/21 tracing: Fix sched switch start/stop refcount racy updates
In reply to Steven RostedtFrom: Mathieu Desnoyers <[email protected]>
Reading the sched_cmdline_ref and sched_tgid_ref initial state within tracing_start_sched_switch without holding the sched_register_mutex is racy against concurrent updates, which can lead to tracepoint probes being registered more than once (and thus trigger warnings within tracepoint.c).
--- kernel/trace/trace_sched_switch.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/trace/trace_sched_switch.c +3 -1
@@ -89,8 +89,10 @@ static void tracing_sched_unregister(void)static void tracing_start_sched_switch (int ops) { -bool sched_register = (!sched_cmdline_ref && !sched_tgid_ref); +bool sched_register; +mutex_lock (&sched_register_mutex); + sched_register = (!sched_cmdline_ref && !sched_tgid_ref);switch (ops) {case RECORD_CMDLINE :
Signature · 1 line
2.24.1
Steven Rostedt
maintainerPATCH 4/21 ftrace: fpid_next() should increase position index
In reply to Steven RostedtFrom: Vasily Averin <[email protected]>
if seq_file .next fuction does not change position index, read after some lseek can generate unexpected output.
Without patch:
# dd bs=4 skip=1 if=/sys/kernel/tracing/set_ftrace_pid dd: /sys/kernel/tracing/set_ftrace_pid: cannot skip to specified offset id no pid 2+1 records in 2+1 records out 10 bytes copied, 0.000213285 s, 46.9 kB/s
Notice the "id" followed by "no pid".
With the patch:
# dd bs=4 skip=1 if=/sys/kernel/tracing/set_ftrace_pid dd: /sys/kernel/tracing/set_ftrace_pid: cannot skip to specified offset id 0+1 records in 0+1 records out 3 bytes copied, 0.000202112 s, 14.8 kB/s
Notice that it only prints "id" and not the "no pid" afterward.
https://bugzilla.kernel.org/show_bug.cgi?id=206283
--- kernel/trace/ftrace.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
kernel/trace/ftrace.c +3 -2
@@ -7026,9 +7026,10 @@ static void *fpid_next(struct seq_file *m, void *v, loff_t *pos)struct trace_array *tr = m->private;struct trace_pid_list *pid_list =rcu_dereference_sched (tr->function_pids); -if (v ==FTRACE_NO_PIDS ) +if (v ==FTRACE_NO_PIDS ) { + (*pos)++;return NULL ; - + }return trace_pid_next (pid_list, v, pos); }
Signature · 1 line
2.24.1
Steven Rostedt
maintainerPATCH 5/21 tracing: eval_map_next() should always increase position index
In reply to Steven RostedtFrom: Vasily Averin <[email protected]>
if seq_file .next fuction does not change position index, read after some lseek can generate unexpected output.
[ This is not a bug fix, it just makes it "technically correct"
which is why I applied it. NULL is only returned on an anomaly which triggers a WARN_ON ]
--- kernel/trace/trace.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/trace/trace.c +1 -3
@@ -5399,14 +5399,12 @@ static void *eval_map_next(struct seq_file *m, void *v, loff_t *pos)* Paranoid! If ptr points to end, we don't want to increment past it. * This really should never happen. */ + (*pos)++; ptr =update_eval_map (ptr);if (WARN_ON_ONCE (!ptr))return NULL ; ptr++; - - (*pos)++; - ptr =update_eval_map (ptr);return ptr;
Signature · 1 line
2.24.1
Steven Rostedt
maintainerPATCH 6/21 trigger_next should increase position index
In reply to Steven RostedtFrom: Vasily Averin <[email protected]>
if seq_file .next fuction does not change position index, read after some lseek can generate unexpected output.
Without patch:
# dd bs=30 skip=1 if=/sys/kernel/tracing/events/sched/sched_switch/trigger dd: /sys/kernel/tracing/events/sched/sched_switch/trigger: cannot skip to specified offset n traceoff snapshot stacktrace enable_event disable_event enable_hist disable_hist hist # Available triggers: # traceon traceoff snapshot stacktrace enable_event disable_event enable_hist disable_hist hist 6+1 records in 6+1 records out 206 bytes copied, 0.00027916 s, 738 kB/s
Notice the printing of "# Available triggers:..." after the line.
With the patch:
# dd bs=30 skip=1 if=/sys/kernel/tracing/events/sched/sched_switch/trigger dd: /sys/kernel/tracing/events/sched/sched_switch/trigger: cannot skip to specified offset n traceoff snapshot stacktrace enable_event disable_event enable_hist disable_hist hist 2+1 records in 2+1 records out 88 bytes copied, 0.000526867 s, 167 kB/s
It only prints the end of the file, and does not restart.
https://bugzilla.kernel.org/show_bug.cgi?id=206283
--- kernel/trace/trace_events_trigger.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
kernel/trace/trace_events_trigger.c +3 -2
@@ -116,9 +116,10 @@ static void *trigger_next(struct seq_file *m, void *t, loff_t *pos) {struct trace_event_file *event_file =event_file_data (m->private); -if (t ==SHOW_AVAILABLE_TRIGGERS ) +if (t ==SHOW_AVAILABLE_TRIGGERS ) { + (*pos)++;return NULL ; - + }return seq_list_next (t, &event_file->triggers, pos); }
Signature · 1 line
2.24.1
Steven Rostedt
maintainerPATCH 7/21 tracing: Add trace_array_find/_get() to find instance trace arrays
In reply to Steven RostedtFrom: Tom Zanussi <[email protected]>
Add a new trace_array_find() function that can be used to find a trace array given the instance name, and replace existing code that does the same thing with it. Also add trace_array_find_get() which does the same but returns the trace array after upping its refcount.
Also make both available for use outside of trace.c.
--- kernel/trace/trace.c | 43 +++++++++++++++++++++++++++++++++---------- kernel/trace/trace.h | 2 ++ 2 files changed, 35 insertions(+), 10 deletions(-)
kernel/trace/trace.c +33 -10
@@ -8499,6 +8499,34 @@ static void update_tracer_options(struct trace_array *tr)mutex_unlock (&trace_types_lock); } +/* Must have trace_types_lock held */ +struct trace_array *trace_array_find (const char *instance) +{ +struct trace_array *tr, *found =NULL ; + +list_for_each_entry (tr, &ftrace_trace_arrays, list) { +if (tr->name &&strcmp (tr->name, instance) ==0 ) { + found = tr; +break ; + } + } + +return found; +} + +struct trace_array *trace_array_find_get (const char *instance) +{ +struct trace_array *tr; + +mutex_lock (&trace_types_lock); + tr =trace_array_find (instance); +if (tr) + tr->ref++; +mutex_unlock (&trace_types_lock); + +return tr; +} +static struct trace_array *trace_array_create (const char *name) {struct trace_array *tr;
@@ -8575,10 +8603,8 @@ static int instance_mkdir(const char *name)mutex_lock (&trace_types_lock); ret = -EEXIST ; -list_for_each_entry (tr, &ftrace_trace_arrays, list) { -if (tr->name &&strcmp (tr->name, name) ==0 ) - goto out_unlock; - } +if (trace_array_find (name)) + goto out_unlock; tr =trace_array_create (name);
@@ -8706,12 +8732,9 @@ static int instance_rmdir(const char *name)mutex_lock (&trace_types_lock); ret = -ENODEV ; -list_for_each_entry (tr, &ftrace_trace_arrays, list) { -if (tr->name &&strcmp (tr->name, name) ==0 ) { - ret =__remove_instance (tr); -break ; - } - } + tr =trace_array_find (name); +if (tr) + ret =__remove_instance (tr);mutex_unlock (&trace_types_lock);mutex_unlock (&event_mutex);
kernel/trace/trace.h +2 -0
@@ -358,6 +358,8 @@ extern struct mutex trace_types_lock;extern int trace_array_get (struct trace_array *tr);extern int tracing_check_open_get_tr (struct trace_array *tr); +extern struct trace_array *trace_array_find (const char *instance); +extern struct trace_array *trace_array_find_get (const char *instance);extern int tracing_set_time_stamp_abs (struct trace_array *tr,bool abs);extern int tracing_set_clock (struct trace_array *tr,const char *clockstr);
Signature · 1 line
2.24.1
Steven Rostedt
maintainerPATCH 8/21 tracing: Add trace_get/put_event_file()
In reply to Steven RostedtFrom: Tom Zanussi <[email protected]>
Add a function to get an event file and prevent it from going away on module or instance removal.
trace_get_event_file() will find an event file in a given instance (if instance is NULL, it assumes the top trace array) and return it, pinning the instance's trace array as well as the event's module, if applicable, so they won't go away while in use.
trace_put_event_file() does the matching release.
--- include/linux/trace_events.h | 5 +++ kernel/trace/trace_events.c | 85 ++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+)
include/linux/trace_events.h +5 -0
@@ -349,6 +349,11 @@ enum { EVENT_FILE_FL_WAS_ENABLED_BIT, }; +extern struct trace_event_file *trace_get_event_file (const char *instance, +const char *system, +const char *event); +extern void trace_put_event_file (struct trace_event_file *file); +/* * Event file flags: * ENABLED - The event is enabled
kernel/trace/trace_events.c +85 -0
91 lines not on this page · raw message
Signature · 1 line
2.24.1
Steven Rostedt
maintainerPATCH 9/21 tracing: Add synth_event_delete()
In reply to Steven RostedtFrom: Tom Zanussi <[email protected]>
create_or_delete_synth_event() contains code to delete a synthetic event, which would be useful on its own - specifically, it would be useful to allow event-creating modules to call it separately.
Separate out the delete code from that function and create an exported function named synth_event_delete().
--- include/linux/trace_events.h | 2 ++ kernel/trace/trace_events_hist.c | 57 +++++++++++++++++++++++--------- 2 files changed, 43 insertions(+), 16 deletions(-)
include/linux/trace_events.h +2 -0
@@ -354,6 +354,8 @@ extern struct trace_event_file *trace_get_event_file(const char *instance, const char *event);extern void trace_put_event_file (struct trace_event_file *file); +extern int synth_event_delete (const char *name); +/* * Event file flags: * ENABLED - The event is enabled
kernel/trace/trace_events_hist.c +41 -16
70 lines not on this page · raw message
Signature · 1 line
2.24.1
Steven Rostedt
maintainerPATCH 10/21 tracing: Add dynamic event command creation interface
In reply to Steven RostedtFrom: Tom Zanussi <[email protected]>
Add an interface used to build up dynamic event creation commands, such as synthetic and kprobe events. Interfaces specific to those particular types of events and others can be built on top of this interface.
Command creation is started by first using the dynevent_cmd_init() function to initialize the dynevent_cmd object. Following that, args are appended and optionally checked by the dynevent_arg_add() and dynevent_arg_pair_add() functions, which use objects representing arguments and pairs of arguments, initialized respectively by dynevent_arg_init() and dynevent_arg_pair_init(). Finally, once all args have been successfully added, the command is finalized and actually created using dynevent_create().
The code here for actually printing into the dyn_event->cmd buffer using snprintf() etc was adapted from v4 of Masami's 'tracing/boot:
Add synthetic event support' patch.
--- include/linux/trace_events.h | 23 ++++ kernel/trace/trace_dynevent.c | 240 ++++++++++++++++++++++++++++++++++ kernel/trace/trace_dynevent.h | 33 +++++ 3 files changed, 296 insertions(+)
include/linux/trace_events.h +23 -0
@@ -354,6 +354,29 @@ extern struct trace_event_file *trace_get_event_file(const char *instance, const char *event);extern void trace_put_event_file (struct trace_event_file *file); +#define MAX_DYNEVENT_CMD_LEN (2048) + +enum dynevent_type { +DYNEVENT_TYPE_NONE , +}; + +struct dynevent_cmd ; + +typedef int (*dynevent_create_fn_t )(struct dynevent_cmd *cmd); + +struct dynevent_cmd { +char *buf; +const char *event_name; +int maxlen; +int remaining; +unsigned int n_fields; +enum dynevent_type type; +dynevent_create_fn_t run_command; +void *private_data; +}; + +extern int dynevent_create (struct dynevent_cmd *cmd); +extern int synth_event_delete (const char *name);/*
kernel/trace/trace_dynevent.c +240 -0
243 lines not on this page · raw message
kernel/trace/trace_dynevent.h +33 -0
@@ -117,4 +117,37 @@ int dyn_event_release(int argc, char **argv, struct dyn_event_operations *type);#define for_each_dyn_event_safe (pos, n) \ list_for_each_entry_safe(pos, n, &dyn_event_list, list) +extern void dynevent_cmd_init (struct dynevent_cmd *cmd,char *buf,int maxlen, +enum dynevent_type type, +dynevent_create_fn_t run_command); + +typedef int (*dynevent_check_arg_fn_t )(void *data); + +struct dynevent_arg { +const char *str; +char separator;/* e.g. ';', ',', or nothing */ +dynevent_check_arg_fn_t check_arg; +}; + +extern void dynevent_arg_init (struct dynevent_arg *arg, +dynevent_check_arg_fn_t check_arg, +char separator); +extern int dynevent_arg_add (struct dynevent_cmd *cmd, +struct dynevent_arg *arg); + +struct dynevent_arg_pair { +const char *lhs; +const char *rhs; +char operator;/* e.g. '=' or nothing */ +char separator;/* e.g. ';', ',', or nothing */ +dynevent_check_arg_fn_t check_arg; +}; + +extern void dynevent_arg_pair_init (struct dynevent_arg_pair *arg_pair, +dynevent_check_arg_fn_t check_arg, +char operator,char separator); +extern int dynevent_arg_pair_add (struct dynevent_cmd *cmd, +struct dynevent_arg_pair *arg_pair); +extern int dynevent_str_add (struct dynevent_cmd *cmd,const char *str); +#endif
Signature · 1 line
2.24.1
Steven Rostedt
maintainerPATCH 11/21 tracing: Add synthetic event command generation functions
In reply to Steven RostedtFrom: Tom Zanussi <[email protected]>
Add functions used to generate synthetic event commands, built on top of the dynevent_cmd interface.
synth_event_gen_cmd_start() is used to create a synthetic event command using a variable arg list and synth_event_gen_cmd_array_start() does the same thing but using an array of field descriptors. synth_event_add_field(), synth_event_add_field_str() and synth_event_add_fields() can be used to add single fields one by one or as a group. Once all desired fields are added, synth_event_gen_cmd_end() is used to actually execute the command and create the event.
synth_event_create() does everything, including creating the event, in a single call.
--- include/linux/trace_events.h | 37 +++ kernel/trace/trace_events_hist.c | 379 ++++++++++++++++++++++++++++++- 2 files changed, 412 insertions(+), 4 deletions(-)
include/linux/trace_events.h +37 -0
@@ -357,6 +357,7 @@ extern void trace_put_event_file(struct trace_event_file *file);#define MAX_DYNEVENT_CMD_LEN (2048)enum dynevent_type { +DYNEVENT_TYPE_SYNTH =1 ,DYNEVENT_TYPE_NONE , };
@@ -379,6 +380,42 @@ extern int dynevent_create(struct dynevent_cmd *cmd);extern int synth_event_delete (const char *name); +extern void synth_event_cmd_init (struct dynevent_cmd *cmd, +char *buf,int maxlen); + +extern int __synth_event_gen_cmd_start (struct dynevent_cmd *cmd, +const char *name, +struct module *mod, ...); + +#define synth_event_gen_cmd_start (cmd, name, mod, ...) \ + __synth_event_gen_cmd_start(cmd, name, mod, ## __VA_ARGS__, NULL) + +struct synth_field_desc { +const char *type; +const char *name; +}; + +extern int synth_event_gen_cmd_array_start (struct dynevent_cmd *cmd, +const char *name, +struct module *mod, +struct synth_field_desc *fields, +unsigned int n_fields); +extern int synth_event_create (const char *name, +struct synth_field_desc *fields, +unsigned int n_fields,struct module *mod); + +extern int synth_event_add_field (struct dynevent_cmd *cmd, +const char *type, +const char *name); +extern int synth_event_add_field_str (struct dynevent_cmd *cmd, +const char *type_name); +extern int synth_event_add_fields (struct dynevent_cmd *cmd, +struct synth_field_desc *fields, +unsigned int n_fields); + +#define synth_event_gen_cmd_end (cmd) \ + dynevent_create(cmd) +/* * Event file flags: * ENABLED - The event is enabled
kernel/trace/trace_events_hist.c +375 -4
428 lines not on this page · raw message
Signature · 1 line
2.24.1
Steven Rostedt
maintainerPATCH 12/21 tracing: Add synth_event_trace() and related functions
In reply to Steven RostedtFrom: Tom Zanussi <[email protected]>
Add an exported function named synth_event_trace(), allowing modules or other kernel code to trace synthetic events.
Also added are several functions that allow the same functionality to be broken out in a piecewise fashion, which are useful in situations where tracing an event from a full array of values would be cumbersome. Those functions are synth_event_trace_start/end() and synth_event_add_(next)_val().
--- include/linux/trace_events.h | 26 ++ kernel/trace/trace_events_hist.c | 463 +++++++++++++++++++++++++++++++ 2 files changed, 489 insertions(+)
include/linux/trace_events.h +26 -0
@@ -416,6 +416,32 @@ extern int synth_event_add_fields(struct dynevent_cmd *cmd,#define synth_event_gen_cmd_end (cmd) \ dynevent_create(cmd) +struct synth_event ; + +struct synth_event_trace_state { +struct trace_event_buffer fbuffer; +struct synth_trace_event *entry; +struct trace_buffer *buffer; +struct synth_event *event; +unsigned int cur_field; +unsigned int n_u64; +bool enabled; +bool add_next; +bool add_name; +}; + +extern int synth_event_trace (struct trace_event_file *file, +unsigned int n_vals, ...); +extern int synth_event_trace_array (struct trace_event_file *file,u64 *vals, +unsigned int n_vals); +extern int synth_event_trace_start (struct trace_event_file *file, +struct synth_event_trace_state *trace_state); +extern int synth_event_add_next_val (u64 val, +struct synth_event_trace_state *trace_state); +extern int synth_event_add_val (const char *field_name,u64 val, +struct synth_event_trace_state *trace_state); +extern int synth_event_trace_end (struct synth_event_trace_state *trace_state); +/* * Event file flags: * ENABLED - The event is enabled
kernel/trace/trace_events_hist.c +463 -0
481 lines not on this page · raw message
Signature · 1 line
2.24.1
Steven Rostedt
maintainerPATCH 13/21 tracing: Add synth event generation test module
In reply to Steven RostedtFrom: Tom Zanussi <[email protected]>
Add a test module that checks the basic functionality of the in-kernel synthetic event generation API by generating and tracing synthetic events from a module.
--- kernel/trace/Kconfig | 13 + kernel/trace/Makefile | 1 + kernel/trace/synth_event_gen_test.c | 523 ++++++++++++++++++++++++++++ 3 files changed, 537 insertions(+) create mode 100644 kernel/trace/synth_event_gen_test.c
kernel/trace/Kconfig +13 -0
@@ -774,6 +774,19 @@ config PREEMPTIRQ_DELAY_TEST If unsure, say N +config SYNTH_EVENT_GEN_TEST + tristate "Test module for in-kernel synthetic event generation" + depends on HIST_TRIGGERS + help + This option creates a test module to check the base + functionality of in-kernel synthetic event definition and + generation. + + To test, insert the module, and then check the trace buffer + for the generated sample events. + + If unsure, say N. + config TRACE_EVAL_MAP_FILE bool "Show eval mappings for trace events" depends on TRACING
kernel/trace/Makefile +1 -0
@@ -44,6 +44,7 @@ obj-$(CONFIG_TRACING) += trace_stat.o obj-$(CONFIG_TRACING) += trace_printk.o obj-$(CONFIG_TRACING_MAP) += tracing_map.o obj-$(CONFIG_PREEMPTIRQ_DELAY_TEST) += preemptirq_delay_test.o +obj-$(CONFIG_SYNTH_EVENT_GEN_TEST) += synth_event_gen_test.o obj-$(CONFIG_CONTEXT_SWITCH_TRACER) += trace_sched_switch.o obj-$(CONFIG_FUNCTION_TRACER) += trace_functions.o obj-$(CONFIG_PREEMPTIRQ_TRACEPOINTS) += trace_preemptirq.o
kernel/trace/synth_event_gen_test.c new file +523 -0
523 lines not on this page · raw message
Signature · 1 line
2.24.1
Steven Rostedt
maintainerPATCH 14/21 tracing: Add kprobe event command generation functions
In reply to Steven RostedtFrom: Tom Zanussi <[email protected]>
Add functions used to generate kprobe event commands, built on top of the dynevent_cmd interface.
kprobe_event_gen_cmd_start() is used to create a kprobe event command using a variable arg list, and kretprobe_event_gen_cmd_start() does the same for kretprobe event commands. kprobe_event_add_fields() can be used to add single fields one by one or as a group. Once all desired fields are added, kprobe_event_gen_cmd_end() or kretprobe_event_gen_cmd_end() respectively are used to actually execute the command and create the event.
--- include/linux/trace_events.h | 31 +++++++ kernel/trace/trace_kprobe.c | 161 +++++++++++++++++++++++++++++++++++ 2 files changed, 192 insertions(+)
include/linux/trace_events.h +31 -0
@@ -358,6 +358,7 @@ extern void trace_put_event_file(struct trace_event_file *file);enum dynevent_type {DYNEVENT_TYPE_SYNTH =1 , +DYNEVENT_TYPE_KPROBE ,DYNEVENT_TYPE_NONE , };
@@ -442,6 +443,36 @@ extern int synth_event_add_val(const char *field_name, u64 val, struct synth_event_trace_state *trace_state);extern int synth_event_trace_end (struct synth_event_trace_state *trace_state); +extern int kprobe_event_delete (const char *name); + +extern void kprobe_event_cmd_init (struct dynevent_cmd *cmd, +char *buf,int maxlen); + +#define kprobe_event_gen_cmd_start (cmd, name, loc, ...) \ + __kprobe_event_gen_cmd_start(cmd, false, name, loc, ## __VA_ARGS__, NULL) + +#define kretprobe_event_gen_cmd_start (cmd, name, loc, ...) \ + __kprobe_event_gen_cmd_start(cmd, true, name, loc, ## __VA_ARGS__, NULL) + +extern int __kprobe_event_gen_cmd_start (struct dynevent_cmd *cmd, +bool kretprobe, +const char *name, +const char *loc, ...); + +#define kprobe_event_add_fields (cmd, ...) \ + __kprobe_event_add_fields(cmd, ## __VA_ARGS__, NULL) + +#define kprobe_event_add_field (cmd, field) \ + __kprobe_event_add_fields(cmd, field, NULL) + +extern int __kprobe_event_add_fields (struct dynevent_cmd *cmd, ...); + +#define kprobe_event_gen_cmd_end (cmd) \ + dynevent_create(cmd) + +#define kretprobe_event_gen_cmd_end (cmd) \ + dynevent_create(cmd) +/* * Event file flags: * ENABLED - The event is enabled
kernel/trace/trace_kprobe.c +161 -0
167 lines not on this page · raw message
Signature · 1 line
2.24.1
Steven Rostedt
maintainerPATCH 15/21 tracing: Change trace_boot to use kprobe_event interface
In reply to Steven RostedtFrom: Tom Zanussi <[email protected]>
Have trace_boot_add_kprobe_event() use the kprobe_event interface.
Also, rename kprobe_event_run_cmd() to kprobe_event_run_command() now that trace_boot's version is gone.
--- kernel/trace/trace_boot.c | 35 +++++++++++++++-------------------- kernel/trace/trace_kprobe.c | 9 ++------- 2 files changed, 17 insertions(+), 27 deletions(-)
kernel/trace/trace_boot.c +15 -20
@@ -88,37 +88,32 @@ trace_boot_enable_events(struct trace_array *tr, struct xbc_node *node) }#ifdef CONFIG_KPROBE_EVENTS -extern int trace_kprobe_run_command (const char *command); -static int __init trace_boot_add_kprobe_event (struct xbc_node *node,const char *event) { +struct dynevent_cmd cmd;struct xbc_node *anode;char buf[MAX_BUF_LEN ];const char *val; -char *p; -int len; +int ret; - len =snprintf (buf,ARRAY_SIZE (buf) -1 ,"p:kprobes/%s " , event); -if (len >=ARRAY_SIZE (buf)) { -pr_err ("Event name is too long: %s\n" , event); -return -E2BIG ; - } - p = buf + len; - len =ARRAY_SIZE (buf) - len; +kprobe_event_cmd_init (&cmd, buf,MAX_BUF_LEN ); + + ret =kprobe_event_gen_cmd_start (&cmd, event,NULL ); +if (ret) +return ret;xbc_node_for_each_array_value (node,"probes" , anode, val) { -if (strlcpy (p, val, len) >= len) { -pr_err ("Probe definition is too long: %s\n" , val); -return -E2BIG ; - } -if (trace_kprobe_run_command (buf) <0 ) { -pr_err ("Failed to add probe: %s\n" , buf); -return -EINVAL ; - } + ret =kprobe_event_add_field (&cmd, val); +if (ret) +return ret; } -return 0 ; + ret =kprobe_event_gen_cmd_end (&cmd); +if (ret) +pr_err ("Failed to add probe: %s\n" , buf); + +return ret; }#else static inline int __init
kernel/trace/trace_kprobe.c +2 -7
@@ -901,12 +901,7 @@ static int create_or_delete_trace_kprobe(int argc, char **argv)return ret == -ECANCELED ? -EINVAL : ret; } -int trace_kprobe_run_command (const char *command) -{ -return trace_run_command (command, create_or_delete_trace_kprobe); -} - -static int trace_kprobe_run_cmd (struct dynevent_cmd *cmd) +static int trace_kprobe_run_command (struct dynevent_cmd *cmd) {return trace_run_command (cmd->buf, create_or_delete_trace_kprobe); }
@@ -923,7 +918,7 @@ static int trace_kprobe_run_cmd(struct dynevent_cmd *cmd)void kprobe_event_cmd_init (struct dynevent_cmd *cmd,char *buf,int maxlen) {dynevent_cmd_init (cmd, buf, maxlen,DYNEVENT_TYPE_KPROBE , - trace_kprobe_run_cmd); + trace_kprobe_run_command); }EXPORT_SYMBOL_GPL (kprobe_event_cmd_init);
Signature · 1 line
2.24.1
Steven Rostedt
maintainerPATCH 16/21 tracing: Add kprobe event command generation test module
In reply to Steven RostedtFrom: Tom Zanussi <[email protected]>
Add a test module that checks the basic functionality of the in-kernel kprobe event command generation API by creating kprobe events from a module.
--- kernel/trace/Kconfig | 12 ++ kernel/trace/Makefile | 1 + kernel/trace/kprobe_event_gen_test.c | 225 +++++++++++++++++++++++++++ 3 files changed, 238 insertions(+) create mode 100644 kernel/trace/kprobe_event_gen_test.c
kernel/trace/Kconfig +12 -0
@@ -787,6 +787,18 @@ config SYNTH_EVENT_GEN_TEST If unsure, say N. +config KPROBE_EVENT_GEN_TEST + tristate "Test module for in-kernel kprobe event generation" + depends on KPROBE_EVENTS + help + This option creates a test module to check the base + functionality of in-kernel kprobe event definition. + + To test, insert the module, and then check the trace buffer + for the generated kprobe events. + + If unsure, say N. + config TRACE_EVAL_MAP_FILE bool "Show eval mappings for trace events" depends on TRACING
kernel/trace/Makefile +1 -0
@@ -45,6 +45,7 @@ obj-$(CONFIG_TRACING) += trace_printk.o obj-$(CONFIG_TRACING_MAP) += tracing_map.o obj-$(CONFIG_PREEMPTIRQ_DELAY_TEST) += preemptirq_delay_test.o obj-$(CONFIG_SYNTH_EVENT_GEN_TEST) += synth_event_gen_test.o +obj-$(CONFIG_KPROBE_EVENT_GEN_TEST) += kprobe_event_gen_test.o obj-$(CONFIG_CONTEXT_SWITCH_TRACER) += trace_sched_switch.o obj-$(CONFIG_FUNCTION_TRACER) += trace_functions.o obj-$(CONFIG_PREEMPTIRQ_TRACEPOINTS) += trace_preemptirq.o
kernel/trace/kprobe_event_gen_test.c new file +225 -0
225 lines not on this page · raw message
Signature · 1 line
2.24.1
Steven Rostedt
maintainerPATCH 17/21 tracing: Documentation for in-kernel synthetic event API
In reply to Steven RostedtFrom: Tom Zanussi <[email protected]>
Add Documentation for creating and generating synthetic events from modules.
--- Documentation/trace/events.rst | 515 +++++++++++++++++++++++++++++++++ 1 file changed, 515 insertions(+)
Documentation/trace/events.rst +515 -0
@@ -525,3 +525,518 @@ The following commands are supported: event counts (hitcount). See Documentation/trace/histogram.rst for details and examples. + +6.3 In-kernel trace event API +----------------------------- + +In most cases, the command-line interface to trace events is more than +sufficient. Sometimes, however, applications might find the need for +more complex relationships than can be expressed through a simple +series of linked command-line expressions, or putting together sets of +commands may be simply too cumbersome. An example might be an +application that needs to 'listen' to the trace stream in order to +maintain an in-kernel state machine detecting, for instance, when an +illegal kernel state occurs in the scheduler. + +The trace event subsystem provides an in-kernel API allowing modules +or other kernel code to generate user-defined 'synthetic' events at +will, which can be used to either augment the existing trace stream +and/or signal that a particular important state has occurred. + +A similar in-kernel API is also available for creating kprobe and +kretprobe events. + +Both the synthetic event and k/ret/probe event APIs are built on top +of a lower-level "dynevent_cmd" event command API, which is also +available for more specialized applications, or as the basis of other +higher-level trace event APIs. + +The API provided for these purposes is describe below and allows the +following: + + - dynamically creating synthetic event definitions + - dynamically creating kprobe and kretprobe event definitions + - tracing synthetic events from in-kernel code + - the low-level "dynevent_cmd" API + +6.3.1 Dyamically creating synthetic event definitions +----------------------------------------------------- + +There are a couple ways to create a new synthetic event from a kernel +module or other kernel code. + +The first creates the event in one step, using synth_event_create(). +In this method, the name of the event to create and an array defining +the fields is supplied to synth_event_create(). If successful, a +synthetic event with that name and fields will exist following that +call. For example, to create a new "schedtest" synthetic event: + + ret = synth_event_create("schedtest", sched_fields, + ARRAY_SIZE(sched_fields), THIS_MODULE); + +The sched_fields param in this example points to an array of struct +synth_field_desc, each of which describes an event field by type and +name: + + static struct synth_field_desc sched_fields[] = { + { .type = "pid_t", .name = "next_pid_field" }, + { .type = "char[16]", .name = "next_comm_field" }, + { .type = "u64", .name = "ts_ns" }, + { .type = "u64", .name = "ts_ms" }, + { .type = "unsigned int", .name = "cpu" }, + { .type = "char[64]", .name = "my_string_field" }, + { .type = "int", .name = "my_int_field" }, + }; + +See synth_field_size() for available types. If field_name contains [n] +the field is considered to be an array. + +If the event is created from within a module, a pointer to the module +must be passed to synth_event_create(). This will ensure that the +trace buffer won't contain unreadable events when the module is +removed. + +At this point, the event object is ready to be used for generating new +events. + +In the second method, the event is created in several steps. This +allows events to be created dynamically and without the need to create +and populate an array of fields beforehand. + +To use this method, an empty or partially empty synthetic event should +first be created using synth_event_gen_cmd_start() or +synth_event_gen_cmd_array_start(). For synth_event_gen_cmd_start(), +the name of the event along with one or more pairs of args each pair +representing a 'type field_name;' field specification should be +supplied. For synth_event_gen_cmd_array_start(), the name of the +event along with an array of struct synth_field_desc should be +supplied. Before calling synth_event_gen_cmd_start() or +synth_event_gen_cmd_array_start(), the user should create and +initialize a dynevent_cmd object using synth_event_cmd_init(). + +For example, to create a new "schedtest" synthetic event with two +fields: + + struct dynevent_cmd cmd; + char *buf; + + /* Create a buffer to hold the generated command */ + buf = kzalloc(MAX_DYNEVENT_CMD_LEN, GFP_KERNEL); + + /* Before generating the command, initialize the cmd object */ + synth_event_cmd_init(&cmd, buf, MAX_DYNEVENT_CMD_LEN); + + ret = synth_event_gen_cmd_start(&cmd, "schedtest", THIS_MODULE, + "pid_t", "next_pid_field", + "u64", "ts_ns"); + +Alternatively, using an array of struct synth_field_desc fields +containing the same information: + + ret = synth_event_gen_cmd_array_start(&cmd, "schedtest", THIS_MODULE, + fields, n_fields); + +Once the synthetic event object has been created, it can then be +populated with more fields. Fields are added one by one using +synth_event_add_field(), supplying the dynevent_cmd object, a field +type, and a field name. For example, to add a new int field named +"intfield", the following call should be made: + + ret = synth_event_add_field(&cmd, "int", "intfield"); + +See synth_field_size() for available types. If field_name contains [n] +the field is considered to be an array. + +A group of fields can also be added all at once using an array of +synth_field_desc with add_synth_fields(). For example, this would add +just the first four sched_fields: + + ret = synth_event_add_fields(&cmd, sched_fields, 4); + +If you already have a string of the form 'type field_name', +synth_event_add_field_str() can be used to add it as-is; it will +also automatically append a ';' to the string. + +Once all the fields have been added, the event should be finalized and +registered by calling the synth_event_gen_cmd_end() function: + + ret = synth_event_gen_cmd_end(&cmd); + +At this point, the event object is ready to be used for tracing new +events. + +6.3.3 Tracing synthetic events from in-kernel code +-------------------------------------------------- + +To trace a synthetic event, there are several options. The first +option is to trace the event in one call, using synth_event_trace() +with a variable number of values, or synth_event_trace_array() with an +array of values to be set. A second option can be used to avoid the +need for a pre-formed array of values or list of arguments, via +synth_event_trace_start() and synth_event_trace_end() along with +synth_event_add_next_val() or synth_event_add_val() to add the values +piecewise. + +6.3.3.1 Tracing a synthetic event all at once +--------------------------------------------- + +To trace a synthetic event all at once, the synth_event_trace() or +synth_event_trace_array() functions can be used. + +The synth_event_trace() function is passed the trace_event_file +representing the synthetic event (which can be retrieved using +trace_get_event_file() using the synthetic event name, "synthetic" as +the system name, and the trace instance name (NULL if using the global +trace array)), along with an variable number of u64 args, one for each +synthetic event field, and the number of values being passed. + +So, to trace an event corresponding to the synthetic event definition +above, code like the following could be used: + + ret = synth_event_trace(create_synth_test, 7, /* number of values */ + 444, /* next_pid_field */ + (u64)"clackers", /* next_comm_field */ + 1000000, /* ts_ns */ + 1000, /* ts_ms */ + smp_processor_id(),/* cpu */ + (u64)"Thneed", /* my_string_field */ + 999); /* my_int_field */ + +All vals should be cast to u64, and string vals are just pointers to +strings, cast to u64. Strings will be copied into space reserved in +the event for the string, using these pointers. + +Alternatively, the synth_event_trace_array() function can be used to +accomplish the same thing. It is passed the trace_event_file +representing the synthetic event (which can be retrieved using +trace_get_event_file() using the synthetic event name, "synthetic" as +the system name, and the trace instance name (NULL if using the global +trace array)), along with an array of u64, one for each synthetic +event field. + +To trace an event corresponding to the synthetic event definition +above, code like the following could be used: + + u64 vals[7]; + + vals[0] = 777; /* next_pid_field */ + vals[1] = (u64)"tiddlywinks"; /* next_comm_field */ + vals[2] = 1000000; /* ts_ns */ + vals[3] = 1000; /* ts_ms */ + vals[4] = smp_processor_id(); /* cpu */ + vals[5] = (u64)"thneed"; /* my_string_field */ + vals[6] = 398; /* my_int_field */ + +The 'vals' array is just an array of u64, the number of which must +match the number of field in the synthetic event, and which must be in +the same order as the synthetic event fields. + +All vals should be cast to u64, and string vals are just pointers to +strings, cast to u64. Strings will be copied into space reserved in +the event for the string, using these pointers. + +In order to trace a synthetic event, a pointer to the trace event file +is needed. The trace_get_event_file() function can be used to get +it - it will find the file in the given trace instance (in this case +NULL since the top trace array is being used) while at the same time +preventing the instance containing it from going away: + + schedtest_event_file = trace_get_event_file(NULL, "synthetic", + "schedtest"); + +Before tracing the event, it should be enabled in some way, otherwise +the synthetic event won't actually show up in the trace buffer. + +To enable a synthetic event from the kernel, trace_array_set_clr_event() +can be used (which is not specific to synthetic events, so does need +the "synthetic" system name to be specified explicitly). + +To enable the event, pass 'true' to it: + + trace_array_set_clr_event(schedtest_event_file->tr, + "synthetic", "schedtest", true); + +To disable it pass false: + + trace_array_set_clr_event(schedtest_event_file->tr, + "synthetic", "schedtest", false); + +Finally, synth_event_trace_array() can be used to actually trace the +event, which should be visible in the trace buffer afterwards: + + ret = synth_event_trace_array(schedtest_event_file, vals, + ARRAY_SIZE(vals)); + +To remove the synthetic event, the event should be disabled, and the +trace instance should be 'put' back using trace_put_event_file(): + + trace_array_set_clr_event(schedtest_event_file->tr, + "synthetic", "schedtest", false); + trace_put_event_file(schedtest_event_file); + +If those have been successful, synth_event_delete() can be called to +remove the event: + + ret = synth_event_delete("schedtest"); + +6.3.3.1 Tracing a synthetic event piecewise +------------------------------------------- + +To trace a synthetic using the piecewise method described above, the +synth_event_trace_start() function is used to 'open' the synthetic +event trace: + + struct synth_trace_state trace_state; + + ret = synth_event_trace_start(schedtest_event_file, &trace_state); + +It's passed the trace_event_file representing the synthetic event +using the same methods as described above, along with a pointer to a +struct synth_trace_state object, which will be zeroed before use and +used to maintain state between this and following calls. + +Once the event has been opened, which means space for it has been +reserved in the trace buffer, the individual fields can be set. There +are two ways to do that, either one after another for each field in +the event, which requires no lookups, or by name, which does. The +tradeoff is flexibility in doing the assignments vs the cost of a +lookup per field. + +To assign the values one after the other without lookups, +synth_event_add_next_val() should be used. Each call is passed the +same synth_trace_state object used in the synth_event_trace_start(), +along with the value to set the next field in the event. After each +field is set, the 'cursor' points to the next field, which will be set +by the subsequent call, continuing until all the fields have been set +in order. The same sequence of calls as in the above examples using +this method would be (without error-handling code): + + /* next_pid_field */ + ret = synth_event_add_next_val(777, &trace_state); + + /* next_comm_field */ + ret = synth_event_add_next_val((u64)"slinky", &trace_state); + + /* ts_ns */ + ret = synth_event_add_next_val(1000000, &trace_state); + + /* ts_ms */ + ret = synth_event_add_next_val(1000, &trace_state); + + /* cpu */ + ret = synth_event_add_next_val(smp_processor_id(), &trace_state); + + /* my_string_field */ + ret = synth_event_add_next_val((u64)"thneed_2.01", &trace_state); + + /* my_int_field */ + ret = synth_event_add_next_val(395, &trace_state); + +To assign the values in any order, synth_event_add_val() should be +used. Each call is passed the same synth_trace_state object used in +the synth_event_trace_start(), along with the field name of the field +to set and the value to set it to. The same sequence of calls as in +the above examples using this method would be (without error-handling +code): + + ret = synth_event_add_val("next_pid_field", 777, &trace_state); + ret = synth_event_add_val("next_comm_field", (u64)"silly putty", + &trace_state); + ret = synth_event_add_val("ts_ns", 1000000, &trace_state); + ret = synth_event_add_val("ts_ms", 1000, &trace_state); + ret = synth_event_add_val("cpu", smp_processor_id(), &trace_state); + ret = synth_event_add_val("my_string_field", (u64)"thneed_9", + &trace_state); + ret = synth_event_add_val("my_int_field", 3999, &trace_state); + +Note that synth_event_add_next_val() and synth_event_add_val() are +incompatible if used within the same trace of an event - either one +can be used but not both at the same time. + +Finally, the event won't be actually traced until it's 'closed', +which is done using synth_event_trace_end(), which takes only the +struct synth_trace_state object used in the previous calls: + + ret = synth_event_trace_end(&trace_state); + +Note that synth_event_trace_end() must be called at the end regardless +of whether any of the add calls failed (say due to a bad field name +being passed in). + +6.3.4 Dyamically creating kprobe and kretprobe event definitions +---------------------------------------------------------------- + +To create a kprobe or kretprobe trace event from kernel code, the +kprobe_event_gen_cmd_start() or kretprobe_event_gen_cmd_start() +functions can be used. + +To create a kprobe event, an empty or partially empty kprobe event +should first be created using kprobe_event_gen_cmd_start(). The name +of the event and the probe location should be specfied along with one +or args each representing a probe field should be supplied to this +function. Before calling kprobe_event_gen_cmd_start(), the user +should create and initialize a dynevent_cmd object using +kprobe_event_cmd_init(). + +For example, to create a new "schedtest" kprobe event with two fields: + + struct dynevent_cmd cmd; + char *buf; + + /* Create a buffer to hold the generated command */ + buf = kzalloc(MAX_DYNEVENT_CMD_LEN, GFP_KERNEL); + + /* Before generating the command, initialize the cmd object */ + kprobe_event_cmd_init(&cmd, buf, MAX_DYNEVENT_CMD_LEN); + + /* + * Define the gen_kprobe_test event with the first 2 kprobe + * fields. + */ + ret = kprobe_event_gen_cmd_start(&cmd, "gen_kprobe_test", "do_sys_open", + "dfd=%ax", "filename=%dx"); + +Once the kprobe event object has been created, it can then be +populated with more fields. Fields can be added using +kprobe_event_add_fields(), supplying the dynevent_cmd object along +with a variable arg list of probe fields. For example, to add a +couple additional fields, the following call could be made: + + ret = kprobe_event_add_fields(&cmd, "flags=%cx", "mode=+4($stack)"); + +Once all the fields have been added, the event should be finalized and +registered by calling the kprobe_event_gen_cmd_end() or +kretprobe_event_gen_cmd_end() functions, depending on whether a kprobe +or kretprobe command was started: + + ret = kprobe_event_gen_cmd_end(&cmd); + +or + + ret = kretprobe_event_gen_cmd_end(&cmd); + +At this point, the event object is ready to be used for tracing new +events. + +Similarly, a kretprobe event can be created using +kretprobe_event_gen_cmd_start() with a probe name and location and +additional params such as $retval: + + ret = kretprobe_event_gen_cmd_start(&cmd, "gen_kretprobe_test", + "do_sys_open", "$retval"); + +Similar to the synthetic event case, code like the following can be +used to enable the newly created kprobe event: + + gen_kprobe_test = trace_get_event_file(NULL, "kprobes", "gen_kprobe_test"); + + ret = trace_array_set_clr_event(gen_kprobe_test->tr, + "kprobes", "gen_kprobe_test", true); + +Finally, also similar to synthetic events, the following code can be +used to give the kprobe event file back and delete the event: + + trace_put_event_file(gen_kprobe_test); + + ret = kprobe_event_delete("gen_kprobe_test"); + +6.3.4 The "dynevent_cmd" low-level API +-------------------------------------- + +Both the in-kernel synthetic event and kprobe interfaces are built on +top of a lower-level "dynevent_cmd" interface. This interface is +meant to provide the basis for higher-level interfaces such as the +synthetic and kprobe interfaces, which can be used as examples. + +The basic idea is simple and amounts to providing a general-purpose +layer that can be used to generate trace event commands. The +generated command strings can then be passed to the command-parsing +and event creation code that already exists in the trace event +subystem for creating the corresponding trace events. + +In a nutshell, the way it works is that the higher-level interface +code creates a struct dynevent_cmd object, then uses a couple +functions, dynevent_arg_add() and dynevent_arg_pair_add() to build up +a command string, which finally causes the command to be executed +using the dynevent_create() function. The details of the interface +are described below. + +The first step in building a new command string is to create and +initialize an instance of a dynevent_cmd. Here, for instance, we +create a dynevent_cmd on the stack and initialize it: + + struct dynevent_cmd cmd; + char *buf; + int ret; + + buf = kzalloc(MAX_DYNEVENT_CMD_LEN, GFP_KERNEL); + + dynevent_cmd_init(cmd, buf, maxlen, DYNEVENT_TYPE_FOO, + foo_event_run_command); + +The dynevent_cmd initialization needs to be given a user-specified +buffer and the length of the buffer (MAX_DYNEVENT_CMD_LEN can be used +for this purpose - at 2k it's generally too big to be comfortably put +on the stack, so is dynamically allocated), a dynevent type id, which +is meant to be used to check that further API calls are for the +correct command type, and a pointer to an event-specific run_command() +callback that will be called to actually execute the event-specific +command function. + +Once that's done, the command string can by built up by successive +calls to argument-adding functions. + +To add a single argument, define and initialize a struct dynevent_arg +or struct dynevent_arg_pair object. Here's an example of the simplest +possible arg addition, which is simply to append the given string as +a whitespace-separated argument to the command: + + struct dynevent_arg arg; + + dynevent_arg_init(&arg, NULL, 0); + + arg.str = name; + + ret = dynevent_arg_add(cmd, &arg); + +The arg object is first initialized using dynevent_arg_init() and in +this case the parameters are NULL or 0, which means there's no +optional sanity-checking function or separator appended to the end of +the arg. + +Here's another more complicated example using an 'arg pair', which is +used to create an argument that consists of a couple components added +together as a unit, for example, a 'type field_name;' arg or a simple +expression arg e.g. 'flags=%cx': + + struct dynevent_arg_pair arg_pair; + + dynevent_arg_pair_init(&arg_pair, dynevent_foo_check_arg_fn, 0, ';'); + + arg_pair.lhs = type; + arg_pair.rhs = name; + + ret = dynevent_arg_pair_add(cmd, &arg_pair); + +Again, the arg_pair is first initialized, in this case with a callback +function used to check the sanity of the args (for example, that +neither part of the pair is NULL), along with a character to be used +to add an operator between the pair (here none) and a separator to be +appended onto the end of the arg pair (here ';'). + +There's also a dynevent_str_add() function that can be used to simply +add a string as-is, with no spaces, delimeters, or arg check. + +Any number of dynevent_*_add() calls can be made to build up the string +(until its length surpasses cmd->maxlen). When all the arguments have +been added and the command string is complete, the only thing left to +do is run the command, which happens by simply calling +dynevent_create(): + + ret = dynevent_create(&cmd); + +At that point, if the return value is 0, the dynamic event has been +created and is ready to use. + +See the dynevent_cmd function definitions themselves for the details +of the API.
Signature · 1 line
2.24.1
Steven Rostedt
maintainerPATCH 18/21 tracing: Move all function tracing configs together
In reply to Steven RostedtFrom: "Steven Rostedt (VMware)" <[email protected]>
The features that depend on the function tracer were spread out through the tracing menu, pull them together as it is easier to manage.
--- kernel/trace/Kconfig | 142 +++++++++++++++++++++---------------------- 1 file changed, 71 insertions(+), 71 deletions(-)
kernel/trace/Kconfig +71 -71
@@ -172,6 +172,77 @@ config FUNCTION_GRAPH_TRACER the return value. This is done by setting the current return address on the current task structure into a stack of calls. +config DYNAMIC_FTRACE + bool "enable/disable function tracing dynamically" + depends on FUNCTION_TRACER + depends on HAVE_DYNAMIC_FTRACE + default y + help + This option will modify all the calls to function tracing + dynamically (will patch them out of the binary image and + replace them with a No-Op instruction) on boot up. During + compile time, a table is made of all the locations that ftrace + can function trace, and this table is linked into the kernel + image. When this is enabled, functions can be individually + enabled, and the functions not enabled will not affect + performance of the system. + + See the files in /sys/kernel/debug/tracing: + available_filter_functions + set_ftrace_filter + set_ftrace_notrace + + This way a CONFIG_FUNCTION_TRACER kernel is slightly larger, but + otherwise has native performance as long as no tracing is active. + +config DYNAMIC_FTRACE_WITH_REGS + def_bool y + depends on DYNAMIC_FTRACE + depends on HAVE_DYNAMIC_FTRACE_WITH_REGS + +config DYNAMIC_FTRACE_WITH_DIRECT_CALLS + def_bool y + depends on DYNAMIC_FTRACE + depends on HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS + +config FUNCTION_PROFILER + bool "Kernel function profiler" + depends on FUNCTION_TRACER + default n + help + This option enables the kernel function profiler. A file is created + in debugfs called function_profile_enabled which defaults to zero. + When a 1 is echoed into this file profiling begins, and when a + zero is entered, profiling stops. A "functions" file is created in + the trace_stat directory; this file shows the list of functions that + have been hit and their counters. + + If in doubt, say N. + +config STACK_TRACER + bool "Trace max stack" + depends on HAVE_FUNCTION_TRACER + select FUNCTION_TRACER + select STACKTRACE + select KALLSYMS + help + This special tracer records the maximum stack footprint of the + kernel and displays it in /sys/kernel/debug/tracing/stack_trace. + + This tracer works by hooking into every function call that the + kernel executes, and keeping a maximum stack depth value and + stack-trace saved. If this is configured with DYNAMIC_FTRACE + then it will not have any overhead while the stack tracer + is disabled. + + To enable the stack tracer on bootup, pass in 'stacktrace' + on the kernel command line. + + The stack tracer can also be enabled or disabled via the + sysctl kernel.stack_tracer_enabled + + Say N if unsure. + config TRACE_PREEMPT_TOGGLE bool help
@@ -410,30 +481,6 @@ config BRANCH_TRACER Say N if unsure. -config STACK_TRACER - bool "Trace max stack" - depends on HAVE_FUNCTION_TRACER - select FUNCTION_TRACER - select STACKTRACE - select KALLSYMS - help - This special tracer records the maximum stack footprint of the - kernel and displays it in /sys/kernel/debug/tracing/stack_trace. - - This tracer works by hooking into every function call that the - kernel executes, and keeping a maximum stack depth value and - stack-trace saved. If this is configured with DYNAMIC_FTRACE - then it will not have any overhead while the stack tracer - is disabled. - - To enable the stack tracer on bootup, pass in 'stacktrace' - on the kernel command line. - - The stack tracer can also be enabled or disabled via the - sysctl kernel.stack_tracer_enabled - - Say N if unsure. - config BLK_DEV_IO_TRACE bool "Support for tracing block IO actions" depends on SYSFS
@@ -531,53 +578,6 @@ config DYNAMIC_EVENTS config PROBE_EVENTS def_bool n -config DYNAMIC_FTRACE - bool "enable/disable function tracing dynamically" - depends on FUNCTION_TRACER - depends on HAVE_DYNAMIC_FTRACE - default y - help - This option will modify all the calls to function tracing - dynamically (will patch them out of the binary image and - replace them with a No-Op instruction) on boot up. During - compile time, a table is made of all the locations that ftrace - can function trace, and this table is linked into the kernel - image. When this is enabled, functions can be individually - enabled, and the functions not enabled will not affect - performance of the system. - - See the files in /sys/kernel/debug/tracing: - available_filter_functions - set_ftrace_filter - set_ftrace_notrace - - This way a CONFIG_FUNCTION_TRACER kernel is slightly larger, but - otherwise has native performance as long as no tracing is active. - -config DYNAMIC_FTRACE_WITH_REGS - def_bool y - depends on DYNAMIC_FTRACE - depends on HAVE_DYNAMIC_FTRACE_WITH_REGS - -config DYNAMIC_FTRACE_WITH_DIRECT_CALLS - def_bool y - depends on DYNAMIC_FTRACE - depends on HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS - -config FUNCTION_PROFILER - bool "Kernel function profiler" - depends on FUNCTION_TRACER - default n - help - This option enables the kernel function profiler. A file is created - in debugfs called function_profile_enabled which defaults to zero. - When a 1 is echoed into this file profiling begins, and when a - zero is entered, profiling stops. A "functions" file is created in - the trace_stat directory; this file shows the list of functions that - have been hit and their counters. - - If in doubt, say N. - config BPF_KPROBE_OVERRIDE bool "Enable BPF programs to override a kprobed function" depends on BPF_EVENTS
Signature · 1 line
2.24.1
Steven Rostedt
maintainerPATCH 19/21 tracing: Move tracing test module configs together
In reply to Steven RostedtFrom: "Steven Rostedt (VMware)" <[email protected]>
The MMIO test module was by itself, move it to the other test modules. Also, add the text "Test module" to PREEMPTIRQ_DELAY_TEST as that create a test module as well.
--- kernel/trace/Kconfig | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
kernel/trace/Kconfig +11 -11
@@ -680,16 +680,6 @@ config TRACE_EVENT_INJECT If unsure, say N. -config MMIOTRACE_TEST - tristate "Test module for mmiotrace" - depends on MMIOTRACE && m - help - This is a dumb module for testing mmiotrace. It is very dangerous - as it will write garbage to IO memory starting at a given address. - However, it should be safe to use on e.g. unused portion of VRAM. - - Say N, unless you absolutely know what you are doing. - config TRACEPOINT_BENCHMARK bool "Add tracepoint that benchmarks tracepoints" help
@@ -759,8 +749,18 @@ config RING_BUFFER_STARTUP_TEST If unsure, say N +config MMIOTRACE_TEST + tristate "Test module for mmiotrace" + depends on MMIOTRACE && m + help + This is a dumb module for testing mmiotrace. It is very dangerous + as it will write garbage to IO memory starting at a given address. + However, it should be safe to use on e.g. unused portion of VRAM. + + Say N, unless you absolutely know what you are doing. + config PREEMPTIRQ_DELAY_TEST - tristate "Preempt / IRQ disable delay thread to test latency tracers" + tristate "Test module to create a preempt / IRQ disable delay thread to test latency tracers" depends on m help Select this option to build a test module that can help test latency
Signature · 1 line
2.24.1
Steven Rostedt
maintainerPATCH 20/21 tracing: Move mmio tracer config up with the other tracers
In reply to Steven RostedtFrom: "Steven Rostedt (VMware)" <[email protected]>
Move the config that enables the mmiotracer with the other tracers such that all the tracers are together.
--- kernel/trace/Kconfig | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-)
kernel/trace/Kconfig +13 -13
@@ -353,6 +353,19 @@ config HWLAT_TRACER file. Every time a latency is greater than tracing_thresh, it will be recorded into the ring buffer. +config MMIOTRACE + bool "Memory mapped IO tracing" + depends on HAVE_MMIOTRACE_SUPPORT && PCI + select GENERIC_TRACER + help + Mmiotrace traces Memory Mapped I/O access and is meant for + debugging and reverse engineering. It is called from the ioremap + implementation and works via page faults. Tracing is disabled by + default and can be enabled at run-time. + + See Documentation/trace/mmiotrace.rst. + If you are not helping to develop drivers, say N. + config ENABLE_DEFAULT_TRACERS bool "Trace process context switches and events" depends on !GENERIC_TRACER
@@ -627,19 +640,6 @@ config EVENT_TRACE_TEST_SYSCALLS TBD - enable a way to actually call the syscalls as we test their events -config MMIOTRACE - bool "Memory mapped IO tracing" - depends on HAVE_MMIOTRACE_SUPPORT && PCI - select GENERIC_TRACER - help - Mmiotrace traces Memory Mapped I/O access and is meant for - debugging and reverse engineering. It is called from the ioremap - implementation and works via page faults. Tracing is disabled by - default and can be enabled at run-time. - - See Documentation/trace/mmiotrace.rst. - If you are not helping to develop drivers, say N. - config TRACING_MAP bool depends on ARCH_HAVE_NMI_SAFE_CMPXCHG
Signature · 1 line
2.24.1
Steven Rostedt
maintainerPATCH 21/21 tracing: Move tracing selftests to bottom of menu
In reply to Steven RostedtFrom: "Steven Rostedt (VMware)" <[email protected]>
Move all the tracing selftest configs to the bottom of the tracing menu. There's no reason for them to be interspersed throughout.
Also, move the bootconfig menu to the top.
--- kernel/trace/Kconfig | 168 +++++++++++++++++++++---------------------- 1 file changed, 84 insertions(+), 84 deletions(-)
kernel/trace/Kconfig +84 -84
@@ -141,6 +141,15 @@ menuconfig FTRACE if FTRACE +config BOOTTIME_TRACING + bool "Boot-time Tracing support" + depends on BOOT_CONFIG && TRACING + default y + help + Enable developer to setup ftrace subsystem via supplemental + kernel cmdline at boot time for debugging (tracing) driver + initialization and boot process. + config FUNCTION_TRACER bool "Kernel Function Tracer" depends on HAVE_FUNCTION_TRACER
@@ -605,41 +614,6 @@ config FTRACE_MCOUNT_RECORD depends on DYNAMIC_FTRACE depends on HAVE_FTRACE_MCOUNT_RECORD -config FTRACE_SELFTEST - bool - -config FTRACE_STARTUP_TEST - bool "Perform a startup test on ftrace" - depends on GENERIC_TRACER - select FTRACE_SELFTEST - help - This option performs a series of startup tests on ftrace. On bootup - a series of tests are made to verify that the tracer is - functioning properly. It will do tests on all the configured - tracers of ftrace. - -config EVENT_TRACE_STARTUP_TEST - bool "Run selftest on trace events" - depends on FTRACE_STARTUP_TEST - default y - help - This option performs a test on all trace events in the system. - It basically just enables each event and runs some code that - will trigger events (not necessarily the event it enables) - This may take some time run as there are a lot of events. - -config EVENT_TRACE_TEST_SYSCALLS - bool "Run selftest on syscall events" - depends on EVENT_TRACE_STARTUP_TEST - help - This option will also enable testing every syscall event. - It only enables the event and disables it and runs various loads - with the event enabled. This adds a bit more time for kernel boot - up since it runs this on every system call defined. - - TBD - enable a way to actually call the syscalls as we test their - events - config TRACING_MAP bool depends on ARCH_HAVE_NMI_SAFE_CMPXCHG
@@ -726,6 +700,81 @@ config RING_BUFFER_BENCHMARK If unsure, say N. +config TRACE_EVAL_MAP_FILE + bool "Show eval mappings for trace events" + depends on TRACING + help + The "print fmt" of the trace events will show the enum/sizeof names + instead of their values. This can cause problems for user space tools + that use this string to parse the raw data as user space does not know + how to convert the string to its value. + + To fix this, there's a special macro in the kernel that can be used + to convert an enum/sizeof into its value. If this macro is used, then + the print fmt strings will be converted to their values. + + If something does not get converted properly, this option can be + used to show what enums/sizeof the kernel tried to convert. + + This option is for debugging the conversions. A file is created + in the tracing directory called "eval_map" that will show the + names matched with their values and what trace event system they + belong too. + + Normally, the mapping of the strings to values will be freed after + boot up or module load. With this option, they will not be freed, as + they are needed for the "eval_map" file. Enabling this option will + increase the memory footprint of the running kernel. + + If unsure, say N. + +config GCOV_PROFILE_FTRACE + bool "Enable GCOV profiling on ftrace subsystem" + depends on GCOV_KERNEL + help + Enable GCOV profiling on ftrace subsystem for checking + which functions/lines are tested. + + If unsure, say N. + + Note that on a kernel compiled with this config, ftrace will + run significantly slower. + +config FTRACE_SELFTEST + bool + +config FTRACE_STARTUP_TEST + bool "Perform a startup test on ftrace" + depends on GENERIC_TRACER + select FTRACE_SELFTEST + help + This option performs a series of startup tests on ftrace. On bootup + a series of tests are made to verify that the tracer is + functioning properly. It will do tests on all the configured + tracers of ftrace. + +config EVENT_TRACE_STARTUP_TEST + bool "Run selftest on trace events" + depends on FTRACE_STARTUP_TEST + default y + help + This option performs a test on all trace events in the system. + It basically just enables each event and runs some code that + will trigger events (not necessarily the event it enables) + This may take some time run as there are a lot of events. + +config EVENT_TRACE_TEST_SYSCALLS + bool "Run selftest on syscall events" + depends on EVENT_TRACE_STARTUP_TEST + help + This option will also enable testing every syscall event. + It only enables the event and disables it and runs various loads + with the event enabled. This adds a bit more time for kernel boot + up since it runs this on every system call defined. + + TBD - enable a way to actually call the syscalls as we test their + events + config RING_BUFFER_STARTUP_TEST bool "Ring buffer startup self test" depends on RING_BUFFER
@@ -799,55 +848,6 @@ config KPROBE_EVENT_GEN_TEST If unsure, say N. -config TRACE_EVAL_MAP_FILE - bool "Show eval mappings for trace events" - depends on TRACING - help - The "print fmt" of the trace events will show the enum/sizeof names - instead of their values. This can cause problems for user space tools - that use this string to parse the raw data as user space does not know - how to convert the string to its value. - - To fix this, there's a special macro in the kernel that can be used - to convert an enum/sizeof into its value. If this macro is used, then - the print fmt strings will be converted to their values. - - If something does not get converted properly, this option can be - used to show what enums/sizeof the kernel tried to convert. - - This option is for debugging the conversions. A file is created - in the tracing directory called "eval_map" that will show the - names matched with their values and what trace event system they - belong too. - - Normally, the mapping of the strings to values will be freed after - boot up or module load. With this option, they will not be freed, as - they are needed for the "eval_map" file. Enabling this option will - increase the memory footprint of the running kernel. - - If unsure, say N. - -config GCOV_PROFILE_FTRACE - bool "Enable GCOV profiling on ftrace subsystem" - depends on GCOV_KERNEL - help - Enable GCOV profiling on ftrace subsystem for checking - which functions/lines are tested. - - If unsure, say N. - - Note that on a kernel compiled with this config, ftrace will - run significantly slower. - -config BOOTTIME_TRACING - bool "Boot-time Tracing support" - depends on BOOT_CONFIG && TRACING - default y - help - Enable developer to setup ftrace subsystem via supplemental - kernel cmdline at boot time for debugging (tracing) driver - initialization and boot process. - endif # FTRACE endif # TRACING_SUPPORT
Signature · 1 line
2.24.1