tracing: Add and use event_command parsing func helpers
PATCH v8 1/4 tracing: Remove logic for registering multiple event triggers at a time
In reply to Tom ZanussiCode for registering triggers assumes it's possible to register more than one trigger at a time. In fact, it's unimplemented and there doesn't seem to be a reason to do that.
Remove the n_registered param from event_trigger_register() and fix up callers.
Doing so simplifies the logic in event_trigger_register to the point that it just becomes a wrapper calling event_command.reg().
It also removes the problematic call to event_command.unreg() in case of failure. A new function, event_trigger_unregister() is also added for callers to call themselves.
The changes to trace_events_hist.c simply allow compilation; a separate patch follows which updates the hist triggers to work correctly with the new changes.
--- kernel/trace/trace.h | 9 +-- kernel/trace/trace_events_hist.c | 17 ++--- kernel/trace/trace_events_trigger.c | 96 ++++++++++------------------- 3 files changed, 45 insertions(+), 77 deletions(-)
kernel/trace/trace.h +5 -4
@@ -1630,10 +1630,11 @@ extern void event_trigger_reset_filter(struct event_command *cmd_ops,extern int event_trigger_register (struct event_command *cmd_ops,struct trace_event_file *file,char *glob, -char *cmd, -char *trigger, -struct event_trigger_data *trigger_data, -int *n_registered); +struct event_trigger_data *trigger_data); +extern void event_trigger_unregister (struct event_command *cmd_ops, +struct trace_event_file *file, +char *glob, +struct event_trigger_data *trigger_data);/** * struct event_trigger_ops - callbacks for trace event triggers
kernel/trace/trace_events_hist.c +6 -11
@@ -6284,7 +6284,7 @@ static int event_hist_trigger_parse(struct event_command *cmd_ops, goto out_free; } - cmd_ops->unreg (glob+1 , trigger_data, file); +event_trigger_unregister (cmd_ops, file, glob+1 , trigger_data); se_name =trace_event_name (file->event_call); se =find_synth_event (se_name);if (se)
@@ -6293,13 +6293,10 @@ static int event_hist_trigger_parse(struct event_command *cmd_ops, goto out_free; } - ret = cmd_ops->reg (glob, trigger_data, file); -/* -* The above returns on success the # of triggers registered, -* but if it didn't register any it returns zero. Consider no -* triggers registered a failure too. -*/ -if (!ret) { + ret =event_trigger_register (cmd_ops, file, glob, trigger_data); +if (ret) + goto out_free; +if (ret ==0 ) {if (!(attrs->pause || attrs->cont || attrs->clear)) ret = -ENOENT ; goto out_free;
@@ -6328,15 +6325,13 @@ static int event_hist_trigger_parse(struct event_command *cmd_ops, se =find_synth_event (se_name);if (se) se->ref++; -/* Just return zero, not the number of registered triggers */ - ret =0 ; out:if (ret ==0 )hist_err_clear ();return ret; out_unreg: - cmd_ops->unreg (glob+1 , trigger_data, file); +event_trigger_unregister (cmd_ops, file, glob+1 , trigger_data); out_free:if (cmd_ops->set_filter) cmd_ops->set_filter (NULL , trigger_data,NULL );
kernel/trace/trace_events_trigger.c +34 -62
158 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v8 3/4 tracing: Have existing event_command.parse() implementations use helpers
In reply to Tom ZanussiSimplify the existing event_command.parse() implementations by having them make use of the helper functions previously introduced.
--- kernel/trace/trace.h | 3 +- kernel/trace/trace_eprobe.c | 3 +- kernel/trace/trace_events_hist.c | 64 +++++------- kernel/trace/trace_events_trigger.c | 150 ++++++++-------------------- 4 files changed, 69 insertions(+), 151 deletions(-)
kernel/trace/trace.h +2 -1
@@ -1578,7 +1578,8 @@ extern int event_enable_trigger_print(struct seq_file *m,extern void event_enable_trigger_free (struct event_trigger_data *data);extern int event_enable_trigger_parse (struct event_command *cmd_ops,struct trace_event_file *file, -char *glob,char *cmd,char *param); +char *glob,char *cmd, +char *param_and_filter);extern int event_enable_register_trigger (char *glob,struct event_trigger_data *data,struct trace_event_file *file);
kernel/trace/trace_eprobe.c +2 -1
@@ -548,7 +548,8 @@ static struct event_trigger_ops eprobe_trigger_ops = {static int eprobe_trigger_cmd_parse (struct event_command *cmd_ops,struct trace_event_file *file, -char *glob,char *cmd,char *param) +char *glob,char *cmd, +char *param_and_filter) {return -1 ; }
kernel/trace/trace_events_hist.c +24 -40
148 lines not on this page · raw message
kernel/trace/trace_events_trigger.c +41 -109
247 lines not on this page · raw message
Signature · 1 line
2.17.1
v8 cover tracing: Add and use event_command parsing func helpers
With more event commands being implemented, it's been pointed out that it would make sense to clean up the existing ones and make it easier to implement new ones without copying a lot of boilerplate. The main culprit here is the event_command.func() callback - the rest of the event_command infrastructure has default implementations that work for most implementations. The func() callback is a little different in that every new command needs to customize parsing to some extent.
This patchset attempts to help clean that up and make it easier for new users to deal with.
v8: Patches 1-4 of v7 were merged and so don't appear here.
Added new patch 'tracing: Remove logic for registering multiple event triggers at a time' because the code doesn't ever register multiple triggers and it just complicates the code. Doing this also removes the unreg() call along with just about everything else from event_trigger_register() so is no longer a policy violation. Also added a new function event_trigger_unregister() to match event_trigger_register() and clean up the code even more.
Moved 'tracing: Remove redundant trigger_ops params' so it doesn't depend on the following patches.
Added 'tracing: Separate hist state updates from hist registration' to remove the confusing logic concerning pause/cont/clear and which caused problems in v7.
v7: Missed a fixup in patch 6/6 to a data->ops->print() in the debug
code since I forgot to build with CONFIG_HIST_TRIGGERS_DEBUG.
Patches 1-5 remain the same.
v6: Fixed warning for an uninitialized trigger_ops local in
event_trigger_parse() pointed out by Steve and the kernel test robot. This was done by removing the need for the local by removing the redundant trigger_ops params in [PATCH v6 3/6]
tracing: Remove ops param from event_command reg()/unreg() callbacks.
Also added a follow-on patch to remove all the other instances of redundant trigger_ops in [PATCH v6 6/6] tracing: Remove redundant trigger_ops params
v5: Changed the parsing helper function example components param and
filter to reflect only the param and filter components, and added param_and_filter which now appears in the functions.
Removed the check for a NULL *param following the strsep separating the param from the filter in event_trigger_separate_filter() because it will never be true due to the previous check for NULL param_and_filter previously.
Changed the param name from trigger to param and updated the function documentation in event_trigger_parse_num().
v4: Added two patches changing the names of event_command.func() and
event_trigger_ops.func() to make them reflect their functions.
Added back missing kfree(trigger_data) in event_trigger_callback().
Changed char *param to const char *param in event_trigger_check_remove() and event_trigger_empty_param().
Changed event_trigger_separate_filter() to use separate param and filter outparams, and changed the name of the param inparam to param_and_filter to better reflect its contents and avoid the clash with new param outparam. Changed all parse() implementations to use this new scheme.
Fixed some typos and added more extensive comments with examples explaining various things that were mentioned as causing confusion and just in general tried to clarify things with respect to the callbacks and parameters.
v3: broke up event_trigger_check() into smaller functions instead of
parameterizing it, and added function documentation.
v2: removed unused event_trigger_remove(). No change in functionality.
The following changes since commit f125ef075cd648a7794aa0cc61a188b1c40c8f94:
tracing: Remove size restriction on synthetic event cmd error logging (2022-01-27 19:15:51 -0500)
are available in the Git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/zanussi/linux-trace.git ftrace/cleanup-hist-func-v8
Tom Zanussi (4):
tracing: Remove logic for registering multiple event triggers at a
time
tracing: Remove redundant trigger_ops params
tracing: Have existing event_command.parse() implementations use
helpers
tracing: Separate hist state updates from hist registration
kernel/trace/trace.h | 26 ++- kernel/trace/trace_eprobe.c | 10 +- kernel/trace/trace_events_hist.c | 166 ++++++++-------- kernel/trace/trace_events_trigger.c | 292 +++++++++------------------- 4 files changed, 193 insertions(+), 301 deletions(-)
Signature · 1 line
2.17.1
PATCH v8 2/4 tracing: Remove redundant trigger_ops params
Since event_trigger_data contains the .ops trigger_ops field, there's no reason to pass the trigger_ops separately. Remove it as a param from functions whenever event_trigger_data is passed.
--- kernel/trace/trace.h | 14 +++------ kernel/trace/trace_eprobe.c | 7 ++--- kernel/trace/trace_events_hist.c | 29 ++++++++---------- kernel/trace/trace_events_trigger.c | 46 +++++++++++------------------ 4 files changed, 36 insertions(+), 60 deletions(-)
kernel/trace/trace.h +4 -10
@@ -1574,10 +1574,8 @@ struct enable_trigger_data { };extern int event_enable_trigger_print (struct seq_file *m, -struct event_trigger_ops *ops, -struct event_trigger_data *data); -extern void event_enable_trigger_free (struct event_trigger_ops *ops,struct event_trigger_data *data); +extern void event_enable_trigger_free (struct event_trigger_data *data);extern int event_enable_trigger_parse (struct event_command *cmd_ops,struct trace_event_file *file,char *glob,char *cmd,char *param);
@@ -1588,8 +1586,7 @@ extern void event_enable_unregister_trigger(char *glob,struct event_trigger_data *test, struct trace_event_file *file);extern void trigger_data_free (struct event_trigger_data *data); -extern int event_trigger_init (struct event_trigger_ops *ops, -struct event_trigger_data *data); +extern int event_trigger_init (struct event_trigger_data *data);extern int trace_event_trigger_enable_disable (struct trace_event_file *file,int trigger_enable);extern void update_cond_flag (struct trace_event_file *file);
@@ -1688,12 +1685,9 @@ struct event_trigger_ops {struct trace_buffer *buffer, void *rec, struct ring_buffer_event *rbe); -int (*init)(struct event_trigger_ops *ops, -struct event_trigger_data *data); -void (*free)(struct event_trigger_ops *ops, -struct event_trigger_data *data); +int (*init)(struct event_trigger_data *data); +void (*free)(struct event_trigger_data *data);int (*print)(struct seq_file *m, -struct event_trigger_ops *ops,struct event_trigger_data *data); };
kernel/trace/trace_eprobe.c +2 -5
@@ -513,20 +513,17 @@ __eprobe_trace_func(struct eprobe_data *edata, void *rec)* functions are just stubs to fulfill what is needed to use the trigger * infrastructure. */ -static int eprobe_trigger_init (struct event_trigger_ops *ops, -struct event_trigger_data *data) +static int eprobe_trigger_init (struct event_trigger_data *data) {return 0 ; } -static void eprobe_trigger_free (struct event_trigger_ops *ops, -struct event_trigger_data *data) +static void eprobe_trigger_free (struct event_trigger_data *data) { }static int eprobe_trigger_print (struct seq_file *m, -struct event_trigger_ops *ops,struct event_trigger_data *data) {/* Do not print eprobe event triggers */
kernel/trace/trace_events_hist.c +12 -17
@@ -5249,7 +5249,7 @@ static void hist_trigger_show(struct seq_file *m,seq_puts (m,"\n\n" );seq_puts (m,"# event histogram\n#\n# trigger info: " ); - data->ops->seq_puts (m,"#\n\n" ); hist_data = data->private_data;
@@ -5481,7 +5481,7 @@ static void hist_trigger_debug_show(struct seq_file *m,seq_puts (m,"\n\n" );seq_puts (m,"# event histogram\n#\n# trigger info: " ); - data->ops->seq_puts (m,"#\n\n" ); hist_data = data->private_data;
@@ -5618,7 +5618,6 @@ static void hist_field_print(struct seq_file *m, struct hist_field *hist_field) }static int event_hist_trigger_print (struct seq_file *m, -struct event_trigger_ops *ops,struct event_trigger_data *data) {struct hist_trigger_data *hist_data = data->private_data;
@@ -5726,8 +5725,7 @@ static int event_hist_trigger_print(struct seq_file *m,return 0 ; } -static int event_hist_trigger_init (struct event_trigger_ops *ops, -struct event_trigger_data *data) +static int event_hist_trigger_init (struct event_trigger_data *data) {struct hist_trigger_data *hist_data = data->private_data;
@@ -5755,8 +5753,7 @@ static void unregister_field_var_hists(struct hist_trigger_data *hist_data) } } -static void event_hist_trigger_free (struct event_trigger_ops *ops, -struct event_trigger_data *data) +static void event_hist_trigger_free (struct event_trigger_data *data) {struct hist_trigger_data *hist_data = data->private_data;
@@ -5785,25 +5782,23 @@ static struct event_trigger_ops event_hist_trigger_ops = { .free = event_hist_trigger_free, }; -static int event_hist_trigger_named_init (struct event_trigger_ops *ops, -struct event_trigger_data *data) +static int event_hist_trigger_named_init (struct event_trigger_data *data) { data->ref++;save_named_trigger (data->named_data->name, data); -event_hist_trigger_init (ops, data->named_data); +event_hist_trigger_init (data->named_data);return 0 ; } -static void event_hist_trigger_named_free (struct event_trigger_ops *ops, -struct event_trigger_data *data) +static void event_hist_trigger_named_free (struct event_trigger_data *data) {if (WARN_ON_ONCE (data->ref <=0 ))return ; -event_hist_trigger_free (ops, data->named_data); +event_hist_trigger_free (data->named_data); data->ref--;if (!data->ref) {
@@ -5990,7 +5985,7 @@ static int hist_register_trigger(char *glob, }if (data->ops->init) { - ret = data->ops->init (data->ops, data); + ret = data->ops->init (data);if (ret <0 ) goto out; }
@@ -6108,7 +6103,7 @@ static void hist_unregister_trigger(char *glob, }if (unregistered && test->ops->free) - test->ops->free (test->ops, test); + test->ops->free (test);if (hist_data->enable_timestamps) {if (!hist_data->remove || unregistered)
@@ -6161,7 +6156,7 @@ static void hist_unreg_all(struct trace_event_file *file)if (hist_data->enable_timestamps)tracing_set_filter_buffering (file->tr, false);if (test->ops->free) - test->ops->free (test->ops, test); + test->ops->free (test); } } }
@@ -6455,7 +6450,7 @@ static void hist_enable_unreg_all(struct trace_event_file *file)update_cond_flag (file);trace_event_trigger_enable_disable (file,0 );if (test->ops->free) - test->ops->free (test->ops, test); + test->ops->free (test); } } }
kernel/trace/trace_events_trigger.c +18 -28
172 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v8 4/4 tracing: Separate hist state updates from hist registration
In reply to Tom Zanussihist_register_trigger() handles both new hist registration as well as existing hist registration through event_command.reg().
Adding a new function, existing_hist_update_only(), that checks and updates existing histograms and exits after doing so allows the confusing logic in event_hist_trigger_parse() to be simplified.
--- kernel/trace/trace_events_hist.c | 66 +++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 18 deletions(-)
kernel/trace/trace_events_hist.c +48 -18
@@ -5926,6 +5926,48 @@ static bool hist_trigger_match(struct event_trigger_data *data,return true; } +static bool existing_hist_update_only (char *glob, +struct event_trigger_data *data, +struct trace_event_file *file) +{ +struct hist_trigger_data *hist_data = data->private_data; +struct event_trigger_data *test, *named_data =NULL ; +bool updated = false; + +if (!hist_data->attrs->pause && !hist_data->attrs->cont && + !hist_data->attrs->clear) + goto out; + +if (hist_data->attrs->name) { + named_data =find_named_trigger (hist_data->attrs->name); +if (named_data) { +if (!hist_trigger_match (data, named_data, named_data, + true)) + goto out; + } + } + +if (hist_data->attrs->name && !named_data) + goto out; + +list_for_each_entry (test, &file->triggers, list) { +if (test->cmd_ops->trigger_type ==ETT_EVENT_HIST ) { +if (!hist_trigger_match (data, test, named_data, false)) +continue ; +if (hist_data->attrs->pause) + test->paused = true; +else if (hist_data->attrs->cont) + test->paused = false; +else if (hist_data->attrs->clear) +hist_clear (test); + updated = true; + goto out; + } + } + out: +return updated; +} +static int hist_register_trigger (char *glob,struct event_trigger_data *data,struct trace_event_file *file)
@@ -5954,19 +5996,11 @@ static int hist_register_trigger(char *glob,list_for_each_entry (test, &file->triggers, list) {if (test->cmd_ops->trigger_type ==ETT_EVENT_HIST ) { -if (!hist_trigger_match (data, test, named_data, false)) -continue ; -if (hist_data->attrs->pause) - test->paused = true; -else if (hist_data->attrs->cont) - test->paused = false; -else if (hist_data->attrs->clear) -hist_clear (test); -else { +if (hist_trigger_match (data, test, named_data, false)) {hist_err (tr,HIST_ERR_TRIGGER_EEXIST ,0 ); ret = -EEXIST ; + goto out; } - goto out; } } new:
@@ -6005,8 +6039,6 @@ static int hist_register_trigger(char *glob,if (named_data)destroy_hist_data (hist_data); - - ret++; out:return ret; }
@@ -6274,14 +6306,12 @@ static int event_hist_trigger_parse(struct event_command *cmd_ops, goto out_free; } - ret =event_trigger_register (cmd_ops, file, glob, trigger_data); -if (ret) +if (existing_hist_update_only (glob, trigger_data, file)) goto out_free; -if (ret ==0 ) { -if (!(attrs->pause || attrs->cont || attrs->clear)) - ret = -ENOENT ; + + ret =event_trigger_register (cmd_ops, file, glob, trigger_data); +if (ret <0 ) goto out_free; - }if (get_named_trigger_data (trigger_data)) goto enable;
Signature · 1 line
2.17.1