Skip to content

Commit bdafb4d

Browse files
committed
tracing: Remove get_trigger_ops() and add count_func() from trigger ops
The struct event_command has a callback function called get_trigger_ops(). This callback returns the "trigger_ops" to use for the trigger. These ops define the trigger function, how to init the trigger, how to print the trigger and how to free it. The only reason there's a callback function to get these ops is because some triggers have two types of operations. One is an "always on" operation, and the other is a "count down" operation. If a user passes in a parameter to say how many times the trigger should execute. For example: echo stacktrace:5 > events/kmem/kmem_cache_alloc/trigger It will trigger the stacktrace for the first 5 times the kmem_cache_alloc event is hit. Instead of having two different trigger_ops since the only difference between them is the tigger itself (the print, init and free functions are all the same), just use a single ops that the event_command points to and add a function field to the trigger_ops to have a count_func. When a trigger is added to an event, if there's a count attached to it and the trigger ops has the count_func field, the data allocated to represent this trigger will have a new flag set called COUNT. Then when the trigger executes, it will check if the COUNT data flag is set, and if so, it will call the ops count_func(). If that returns false, it returns without executing the trigger. This removes the need for duplicate event_trigger_ops structures. Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Cc: Andrew Morton <akpm@linux-foundation.org> Link: https://patch.msgid.link/20251125200932.274566147@kernel.org Reviewed-by: Tom Zanussi <zanussi@kernel.org> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 23c0e9c commit bdafb4d

4 files changed

Lines changed: 116 additions & 235 deletions

File tree

kernel/trace/trace.h

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,6 +1791,7 @@ extern void clear_event_triggers(struct trace_array *tr);
17911791

17921792
enum {
17931793
EVENT_TRIGGER_FL_PROBE = BIT(0),
1794+
EVENT_TRIGGER_FL_COUNT = BIT(1),
17941795
};
17951796

17961797
struct event_trigger_data {
@@ -1822,6 +1823,10 @@ struct enable_trigger_data {
18221823
bool hist;
18231824
};
18241825

1826+
bool event_trigger_count(struct event_trigger_data *data,
1827+
struct trace_buffer *buffer, void *rec,
1828+
struct ring_buffer_event *event);
1829+
18251830
extern int event_enable_trigger_print(struct seq_file *m,
18261831
struct event_trigger_data *data);
18271832
extern void event_enable_trigger_free(struct event_trigger_data *data);
@@ -1909,6 +1914,11 @@ extern void event_file_put(struct trace_event_file *file);
19091914
* registered the trigger (see struct event_command) along with
19101915
* the trace record, rec.
19111916
*
1917+
* @count_func: If defined and a numeric parameter is passed to the
1918+
* trigger, then this function will be called before @trigger
1919+
* is called. If this function returns false, then @trigger is not
1920+
* executed.
1921+
*
19121922
* @init: An optional initialization function called for the trigger
19131923
* when the trigger is registered (via the event_command reg()
19141924
* function). This can be used to perform per-trigger
@@ -1936,6 +1946,10 @@ struct event_trigger_ops {
19361946
struct trace_buffer *buffer,
19371947
void *rec,
19381948
struct ring_buffer_event *rbe);
1949+
bool (*count_func)(struct event_trigger_data *data,
1950+
struct trace_buffer *buffer,
1951+
void *rec,
1952+
struct ring_buffer_event *rbe);
19391953
int (*init)(struct event_trigger_data *data);
19401954
void (*free)(struct event_trigger_data *data);
19411955
int (*print)(struct seq_file *m,
@@ -1962,6 +1976,9 @@ struct event_trigger_ops {
19621976
* @name: The unique name that identifies the event command. This is
19631977
* the name used when setting triggers via trigger files.
19641978
*
1979+
* @trigger_ops: The event_trigger_ops implementation associated with
1980+
* the command.
1981+
*
19651982
* @trigger_type: A unique id that identifies the event command
19661983
* 'type'. This value has two purposes, the first to ensure that
19671984
* only one trigger of the same type can be set at a given time
@@ -2013,17 +2030,11 @@ struct event_trigger_ops {
20132030
* event command, filters set by the user for the command will be
20142031
* ignored. This is usually implemented by the generic utility
20152032
* function @set_trigger_filter() (see trace_event_triggers.c).
2016-
*
2017-
* @get_trigger_ops: The callback function invoked to retrieve the
2018-
* event_trigger_ops implementation associated with the command.
2019-
* This callback function allows a single event_command to
2020-
* support multiple trigger implementations via different sets of
2021-
* event_trigger_ops, depending on the value of the @param
2022-
* string.
20232033
*/
20242034
struct event_command {
20252035
struct list_head list;
20262036
char *name;
2037+
const struct event_trigger_ops *trigger_ops;
20272038
enum event_trigger_type trigger_type;
20282039
int flags;
20292040
int (*parse)(struct event_command *cmd_ops,
@@ -2040,7 +2051,6 @@ struct event_command {
20402051
int (*set_filter)(char *filter_str,
20412052
struct event_trigger_data *data,
20422053
struct trace_event_file *file);
2043-
const struct event_trigger_ops *(*get_trigger_ops)(char *cmd, char *param);
20442054
};
20452055

20462056
/**

kernel/trace/trace_eprobe.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -513,21 +513,15 @@ static void eprobe_trigger_unreg_func(char *glob,
513513

514514
}
515515

516-
static const struct event_trigger_ops *eprobe_trigger_get_ops(char *cmd,
517-
char *param)
518-
{
519-
return &eprobe_trigger_ops;
520-
}
521-
522516
static struct event_command event_trigger_cmd = {
523517
.name = "eprobe",
524518
.trigger_type = ETT_EVENT_EPROBE,
525519
.flags = EVENT_CMD_FL_NEEDS_REC,
520+
.trigger_ops = &eprobe_trigger_ops,
526521
.parse = eprobe_trigger_cmd_parse,
527522
.reg = eprobe_trigger_reg_func,
528523
.unreg = eprobe_trigger_unreg_func,
529524
.unreg_all = NULL,
530-
.get_trigger_ops = eprobe_trigger_get_ops,
531525
.set_filter = NULL,
532526
};
533527

kernel/trace/trace_events_hist.c

Lines changed: 5 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -6363,12 +6363,6 @@ static const struct event_trigger_ops event_hist_trigger_named_ops = {
63636363
.free = event_hist_trigger_named_free,
63646364
};
63656365

6366-
static const struct event_trigger_ops *event_hist_get_trigger_ops(char *cmd,
6367-
char *param)
6368-
{
6369-
return &event_hist_trigger_ops;
6370-
}
6371-
63726366
static void hist_clear(struct event_trigger_data *data)
63736367
{
63746368
struct hist_trigger_data *hist_data = data->private_data;
@@ -6908,11 +6902,11 @@ static struct event_command trigger_hist_cmd = {
69086902
.name = "hist",
69096903
.trigger_type = ETT_EVENT_HIST,
69106904
.flags = EVENT_CMD_FL_NEEDS_REC,
6905+
.trigger_ops = &event_hist_trigger_ops,
69116906
.parse = event_hist_trigger_parse,
69126907
.reg = hist_register_trigger,
69136908
.unreg = hist_unregister_trigger,
69146909
.unreg_all = hist_unreg_all,
6915-
.get_trigger_ops = event_hist_get_trigger_ops,
69166910
.set_filter = set_trigger_filter,
69176911
};
69186912

@@ -6945,66 +6939,22 @@ hist_enable_trigger(struct event_trigger_data *data,
69456939
}
69466940
}
69476941

6948-
static void
6949-
hist_enable_count_trigger(struct event_trigger_data *data,
6950-
struct trace_buffer *buffer, void *rec,
6951-
struct ring_buffer_event *event)
6952-
{
6953-
if (!data->count)
6954-
return;
6955-
6956-
if (data->count != -1)
6957-
(data->count)--;
6958-
6959-
hist_enable_trigger(data, buffer, rec, event);
6960-
}
6961-
69626942
static const struct event_trigger_ops hist_enable_trigger_ops = {
69636943
.trigger = hist_enable_trigger,
6964-
.print = event_enable_trigger_print,
6965-
.init = event_trigger_init,
6966-
.free = event_enable_trigger_free,
6967-
};
6968-
6969-
static const struct event_trigger_ops hist_enable_count_trigger_ops = {
6970-
.trigger = hist_enable_count_trigger,
6944+
.count_func = event_trigger_count,
69716945
.print = event_enable_trigger_print,
69726946
.init = event_trigger_init,
69736947
.free = event_enable_trigger_free,
69746948
};
69756949

69766950
static const struct event_trigger_ops hist_disable_trigger_ops = {
69776951
.trigger = hist_enable_trigger,
6952+
.count_func = event_trigger_count,
69786953
.print = event_enable_trigger_print,
69796954
.init = event_trigger_init,
69806955
.free = event_enable_trigger_free,
69816956
};
69826957

6983-
static const struct event_trigger_ops hist_disable_count_trigger_ops = {
6984-
.trigger = hist_enable_count_trigger,
6985-
.print = event_enable_trigger_print,
6986-
.init = event_trigger_init,
6987-
.free = event_enable_trigger_free,
6988-
};
6989-
6990-
static const struct event_trigger_ops *
6991-
hist_enable_get_trigger_ops(char *cmd, char *param)
6992-
{
6993-
const struct event_trigger_ops *ops;
6994-
bool enable;
6995-
6996-
enable = (strcmp(cmd, ENABLE_HIST_STR) == 0);
6997-
6998-
if (enable)
6999-
ops = param ? &hist_enable_count_trigger_ops :
7000-
&hist_enable_trigger_ops;
7001-
else
7002-
ops = param ? &hist_disable_count_trigger_ops :
7003-
&hist_disable_trigger_ops;
7004-
7005-
return ops;
7006-
}
7007-
70086958
static void hist_enable_unreg_all(struct trace_event_file *file)
70096959
{
70106960
struct event_trigger_data *test, *n;
@@ -7023,22 +6973,22 @@ static void hist_enable_unreg_all(struct trace_event_file *file)
70236973
static struct event_command trigger_hist_enable_cmd = {
70246974
.name = ENABLE_HIST_STR,
70256975
.trigger_type = ETT_HIST_ENABLE,
6976+
.trigger_ops = &hist_enable_trigger_ops,
70266977
.parse = event_enable_trigger_parse,
70276978
.reg = event_enable_register_trigger,
70286979
.unreg = event_enable_unregister_trigger,
70296980
.unreg_all = hist_enable_unreg_all,
7030-
.get_trigger_ops = hist_enable_get_trigger_ops,
70316981
.set_filter = set_trigger_filter,
70326982
};
70336983

70346984
static struct event_command trigger_hist_disable_cmd = {
70356985
.name = DISABLE_HIST_STR,
70366986
.trigger_type = ETT_HIST_ENABLE,
6987+
.trigger_ops = &hist_disable_trigger_ops,
70376988
.parse = event_enable_trigger_parse,
70386989
.reg = event_enable_register_trigger,
70396990
.unreg = event_enable_unregister_trigger,
70406991
.unreg_all = hist_enable_unreg_all,
7041-
.get_trigger_ops = hist_enable_get_trigger_ops,
70426992
.set_filter = set_trigger_filter,
70436993
};
70446994

0 commit comments

Comments
 (0)