1bcea3f96SSteven Rostedt (VMware) // SPDX-License-Identifier: GPL-2.0
285f2b082STom Zanussi /*
385f2b082STom Zanussi * trace_events_trigger - trace event triggers
485f2b082STom Zanussi *
585f2b082STom Zanussi * Copyright (C) 2013 Tom Zanussi <tom.zanussi@linux.intel.com>
685f2b082STom Zanussi */
785f2b082STom Zanussi
817911ff3SSteven Rostedt (VMware) #include <linux/security.h>
985f2b082STom Zanussi #include <linux/module.h>
1085f2b082STom Zanussi #include <linux/ctype.h>
1185f2b082STom Zanussi #include <linux/mutex.h>
1285f2b082STom Zanussi #include <linux/slab.h>
13b2d09103SIngo Molnar #include <linux/rculist.h>
1485f2b082STom Zanussi
1585f2b082STom Zanussi #include "trace.h"
1685f2b082STom Zanussi
1785f2b082STom Zanussi static LIST_HEAD(trigger_commands);
1885f2b082STom Zanussi static DEFINE_MUTEX(trigger_cmd_mutex);
1985f2b082STom Zanussi
trigger_data_free(struct event_trigger_data * data)20ab4bf008STom Zanussi void trigger_data_free(struct event_trigger_data *data)
212a2df321STom Zanussi {
22bac5fb97STom Zanussi if (data->cmd_ops->set_filter)
23bac5fb97STom Zanussi data->cmd_ops->set_filter(NULL, data, NULL);
24bac5fb97STom Zanussi
25e0a568dcSSteven Rostedt (VMware) /* make sure current triggers exit before free */
26e0a568dcSSteven Rostedt (VMware) tracepoint_synchronize_unregister();
27e0a568dcSSteven Rostedt (VMware)
282a2df321STom Zanussi kfree(data);
292a2df321STom Zanussi }
302a2df321STom Zanussi
3185f2b082STom Zanussi /**
3285f2b082STom Zanussi * event_triggers_call - Call triggers associated with a trace event
337f1d2f82SSteven Rostedt (Red Hat) * @file: The trace_event_file associated with the event
34bd7217f3SGaosheng Cui * @buffer: The ring buffer that the event is being written to
35bac5fb97STom Zanussi * @rec: The trace entry for the event, NULL for unconditional invocation
36bd7217f3SGaosheng Cui * @event: The event meta data in the ring buffer
3785f2b082STom Zanussi *
3885f2b082STom Zanussi * For each trigger associated with an event, invoke the trigger
39bac5fb97STom Zanussi * function registered with the associated trigger command. If rec is
40bac5fb97STom Zanussi * non-NULL, it means that the trigger requires further processing and
41bac5fb97STom Zanussi * shouldn't be unconditionally invoked. If rec is non-NULL and the
42bac5fb97STom Zanussi * trigger has a filter associated with it, rec will checked against
43bac5fb97STom Zanussi * the filter and if the record matches the trigger will be invoked.
44bac5fb97STom Zanussi * If the trigger is a 'post_trigger', meaning it shouldn't be invoked
45bac5fb97STom Zanussi * in any case until the current event is written, the trigger
46bac5fb97STom Zanussi * function isn't invoked but the bit associated with the deferred
47bac5fb97STom Zanussi * trigger is set in the return value.
48bac5fb97STom Zanussi *
49bac5fb97STom Zanussi * Returns an enum event_trigger_type value containing a set bit for
50bac5fb97STom Zanussi * any trigger that should be deferred, ETT_NONE if nothing to defer.
5185f2b082STom Zanussi *
5285f2b082STom Zanussi * Called from tracepoint handlers (with rcu_read_lock_sched() held).
5385f2b082STom Zanussi *
5485f2b082STom Zanussi * Return: an enum event_trigger_type value containing a set bit for
5585f2b082STom Zanussi * any trigger that should be deferred, ETT_NONE if nothing to defer.
5685f2b082STom Zanussi */
57bac5fb97STom Zanussi enum event_trigger_type
event_triggers_call(struct trace_event_file * file,struct trace_buffer * buffer,void * rec,struct ring_buffer_event * event)58b47e3302SSteven Rostedt (VMware) event_triggers_call(struct trace_event_file *file,
59b47e3302SSteven Rostedt (VMware) struct trace_buffer *buffer, void *rec,
601ac4f51cSTom Zanussi struct ring_buffer_event *event)
61bac5fb97STom Zanussi {
62bac5fb97STom Zanussi struct event_trigger_data *data;
63bac5fb97STom Zanussi enum event_trigger_type tt = ETT_NONE;
64d8a30f20SSteven Rostedt (Red Hat) struct event_filter *filter;
65bac5fb97STom Zanussi
66bac5fb97STom Zanussi if (list_empty(&file->triggers))
67bac5fb97STom Zanussi return tt;
68bac5fb97STom Zanussi
69bac5fb97STom Zanussi list_for_each_entry_rcu(data, &file->triggers, list) {
70104f2810STom Zanussi if (data->paused)
71104f2810STom Zanussi continue;
72bac5fb97STom Zanussi if (!rec) {
73fb339e53STom Zanussi data->ops->trigger(data, buffer, rec, event);
74bac5fb97STom Zanussi continue;
75bac5fb97STom Zanussi }
76561a4fe8SSteven Rostedt (Red Hat) filter = rcu_dereference_sched(data->filter);
77d8a30f20SSteven Rostedt (Red Hat) if (filter && !filter_match_preds(filter, rec))
78bac5fb97STom Zanussi continue;
79353206f5SSteven Rostedt (Red Hat) if (event_command_post_trigger(data->cmd_ops)) {
80bac5fb97STom Zanussi tt |= data->cmd_ops->trigger_type;
81bac5fb97STom Zanussi continue;
82bac5fb97STom Zanussi }
83fb339e53STom Zanussi data->ops->trigger(data, buffer, rec, event);
84bac5fb97STom Zanussi }
85bac5fb97STom Zanussi return tt;
86bac5fb97STom Zanussi }
87bac5fb97STom Zanussi EXPORT_SYMBOL_GPL(event_triggers_call);
88bac5fb97STom Zanussi
__trace_trigger_soft_disabled(struct trace_event_file * file)89bc82c38aSChristophe Leroy bool __trace_trigger_soft_disabled(struct trace_event_file *file)
90bc82c38aSChristophe Leroy {
91bc82c38aSChristophe Leroy unsigned long eflags = file->flags;
92bc82c38aSChristophe Leroy
93bc82c38aSChristophe Leroy if (eflags & EVENT_FILE_FL_TRIGGER_MODE)
94bc82c38aSChristophe Leroy event_triggers_call(file, NULL, NULL, NULL);
95bc82c38aSChristophe Leroy if (eflags & EVENT_FILE_FL_SOFT_DISABLED)
96bc82c38aSChristophe Leroy return true;
97bc82c38aSChristophe Leroy if (eflags & EVENT_FILE_FL_PID_FILTER)
98bc82c38aSChristophe Leroy return trace_event_ignore_this_pid(file);
99bc82c38aSChristophe Leroy return false;
100bc82c38aSChristophe Leroy }
101bc82c38aSChristophe Leroy EXPORT_SYMBOL_GPL(__trace_trigger_soft_disabled);
102bc82c38aSChristophe Leroy
103bac5fb97STom Zanussi /**
104bac5fb97STom Zanussi * event_triggers_post_call - Call 'post_triggers' for a trace event
1057f1d2f82SSteven Rostedt (Red Hat) * @file: The trace_event_file associated with the event
106bac5fb97STom Zanussi * @tt: enum event_trigger_type containing a set bit for each trigger to invoke
107bac5fb97STom Zanussi *
108bac5fb97STom Zanussi * For each trigger associated with an event, invoke the trigger
109bac5fb97STom Zanussi * function registered with the associated trigger command, if the
110bac5fb97STom Zanussi * corresponding bit is set in the tt enum passed into this function.
111bac5fb97STom Zanussi * See @event_triggers_call for details on how those bits are set.
112bac5fb97STom Zanussi *
113bac5fb97STom Zanussi * Called from tracepoint handlers (with rcu_read_lock_sched() held).
114bac5fb97STom Zanussi */
115bac5fb97STom Zanussi void
event_triggers_post_call(struct trace_event_file * file,enum event_trigger_type tt)1167f1d2f82SSteven Rostedt (Red Hat) event_triggers_post_call(struct trace_event_file *file,
117c94e45bcSSteven Rostedt (VMware) enum event_trigger_type tt)
11885f2b082STom Zanussi {
11985f2b082STom Zanussi struct event_trigger_data *data;
12085f2b082STom Zanussi
121bac5fb97STom Zanussi list_for_each_entry_rcu(data, &file->triggers, list) {
122104f2810STom Zanussi if (data->paused)
123104f2810STom Zanussi continue;
124bac5fb97STom Zanussi if (data->cmd_ops->trigger_type & tt)
125fb339e53STom Zanussi data->ops->trigger(data, NULL, NULL, NULL);
12685f2b082STom Zanussi }
127bac5fb97STom Zanussi }
128bac5fb97STom Zanussi EXPORT_SYMBOL_GPL(event_triggers_post_call);
12985f2b082STom Zanussi
130dd97b954SSteven Rostedt (Red Hat) #define SHOW_AVAILABLE_TRIGGERS (void *)(1UL)
131dd97b954SSteven Rostedt (Red Hat)
trigger_next(struct seq_file * m,void * t,loff_t * pos)13285f2b082STom Zanussi static void *trigger_next(struct seq_file *m, void *t, loff_t *pos)
13385f2b082STom Zanussi {
1347f1d2f82SSteven Rostedt (Red Hat) struct trace_event_file *event_file = event_file_data(m->private);
13585f2b082STom Zanussi
1366722b23eSVasily Averin if (t == SHOW_AVAILABLE_TRIGGERS) {
1376722b23eSVasily Averin (*pos)++;
138dd97b954SSteven Rostedt (Red Hat) return NULL;
1396722b23eSVasily Averin }
14085f2b082STom Zanussi return seq_list_next(t, &event_file->triggers, pos);
14185f2b082STom Zanussi }
14285f2b082STom Zanussi
check_user_trigger(struct trace_event_file * file)1437491e2c4STzvetomir Stoyanov (VMware) static bool check_user_trigger(struct trace_event_file *file)
1447491e2c4STzvetomir Stoyanov (VMware) {
1457491e2c4STzvetomir Stoyanov (VMware) struct event_trigger_data *data;
1467491e2c4STzvetomir Stoyanov (VMware)
147cecf8e12SMasami Hiramatsu (Google) list_for_each_entry_rcu(data, &file->triggers, list,
148cecf8e12SMasami Hiramatsu (Google) lockdep_is_held(&event_mutex)) {
1497491e2c4STzvetomir Stoyanov (VMware) if (data->flags & EVENT_TRIGGER_FL_PROBE)
1507491e2c4STzvetomir Stoyanov (VMware) continue;
1517491e2c4STzvetomir Stoyanov (VMware) return true;
1527491e2c4STzvetomir Stoyanov (VMware) }
1537491e2c4STzvetomir Stoyanov (VMware) return false;
1547491e2c4STzvetomir Stoyanov (VMware) }
1557491e2c4STzvetomir Stoyanov (VMware)
trigger_start(struct seq_file * m,loff_t * pos)15685f2b082STom Zanussi static void *trigger_start(struct seq_file *m, loff_t *pos)
15785f2b082STom Zanussi {
1587f1d2f82SSteven Rostedt (Red Hat) struct trace_event_file *event_file;
15985f2b082STom Zanussi
16085f2b082STom Zanussi /* ->stop() is called even if ->start() fails */
16185f2b082STom Zanussi mutex_lock(&event_mutex);
16285f2b082STom Zanussi event_file = event_file_data(m->private);
16385f2b082STom Zanussi if (unlikely(!event_file))
16485f2b082STom Zanussi return ERR_PTR(-ENODEV);
16585f2b082STom Zanussi
1667491e2c4STzvetomir Stoyanov (VMware) if (list_empty(&event_file->triggers) || !check_user_trigger(event_file))
167dd97b954SSteven Rostedt (Red Hat) return *pos == 0 ? SHOW_AVAILABLE_TRIGGERS : NULL;
168dd97b954SSteven Rostedt (Red Hat)
16985f2b082STom Zanussi return seq_list_start(&event_file->triggers, *pos);
17085f2b082STom Zanussi }
17185f2b082STom Zanussi
trigger_stop(struct seq_file * m,void * t)17285f2b082STom Zanussi static void trigger_stop(struct seq_file *m, void *t)
17385f2b082STom Zanussi {
17485f2b082STom Zanussi mutex_unlock(&event_mutex);
17585f2b082STom Zanussi }
17685f2b082STom Zanussi
trigger_show(struct seq_file * m,void * v)17785f2b082STom Zanussi static int trigger_show(struct seq_file *m, void *v)
17885f2b082STom Zanussi {
17985f2b082STom Zanussi struct event_trigger_data *data;
180dd97b954SSteven Rostedt (Red Hat) struct event_command *p;
181dd97b954SSteven Rostedt (Red Hat)
182dd97b954SSteven Rostedt (Red Hat) if (v == SHOW_AVAILABLE_TRIGGERS) {
183dd97b954SSteven Rostedt (Red Hat) seq_puts(m, "# Available triggers:\n");
184dd97b954SSteven Rostedt (Red Hat) seq_putc(m, '#');
185dd97b954SSteven Rostedt (Red Hat) mutex_lock(&trigger_cmd_mutex);
186dd97b954SSteven Rostedt (Red Hat) list_for_each_entry_reverse(p, &trigger_commands, list)
187dd97b954SSteven Rostedt (Red Hat) seq_printf(m, " %s", p->name);
188dd97b954SSteven Rostedt (Red Hat) seq_putc(m, '\n');
189dd97b954SSteven Rostedt (Red Hat) mutex_unlock(&trigger_cmd_mutex);
190dd97b954SSteven Rostedt (Red Hat) return 0;
191dd97b954SSteven Rostedt (Red Hat) }
19285f2b082STom Zanussi
19385f2b082STom Zanussi data = list_entry(v, struct event_trigger_data, list);
19447670541STom Zanussi data->ops->print(m, data);
19585f2b082STom Zanussi
19685f2b082STom Zanussi return 0;
19785f2b082STom Zanussi }
19885f2b082STom Zanussi
19985f2b082STom Zanussi static const struct seq_operations event_triggers_seq_ops = {
20085f2b082STom Zanussi .start = trigger_start,
20185f2b082STom Zanussi .next = trigger_next,
20285f2b082STom Zanussi .stop = trigger_stop,
20385f2b082STom Zanussi .show = trigger_show,
20485f2b082STom Zanussi };
20585f2b082STom Zanussi
event_trigger_regex_open(struct inode * inode,struct file * file)20685f2b082STom Zanussi static int event_trigger_regex_open(struct inode *inode, struct file *file)
20785f2b082STom Zanussi {
20817911ff3SSteven Rostedt (VMware) int ret;
20917911ff3SSteven Rostedt (VMware)
21017911ff3SSteven Rostedt (VMware) ret = security_locked_down(LOCKDOWN_TRACEFS);
21117911ff3SSteven Rostedt (VMware) if (ret)
21217911ff3SSteven Rostedt (VMware) return ret;
21385f2b082STom Zanussi
21485f2b082STom Zanussi mutex_lock(&event_mutex);
21585f2b082STom Zanussi
21685f2b082STom Zanussi if (unlikely(!event_file_data(file))) {
21785f2b082STom Zanussi mutex_unlock(&event_mutex);
21885f2b082STom Zanussi return -ENODEV;
21985f2b082STom Zanussi }
22085f2b082STom Zanussi
221a88e1cfbSTom Zanussi if ((file->f_mode & FMODE_WRITE) &&
222a88e1cfbSTom Zanussi (file->f_flags & O_TRUNC)) {
223a88e1cfbSTom Zanussi struct trace_event_file *event_file;
224a88e1cfbSTom Zanussi struct event_command *p;
225a88e1cfbSTom Zanussi
226a88e1cfbSTom Zanussi event_file = event_file_data(file);
227a88e1cfbSTom Zanussi
228a88e1cfbSTom Zanussi list_for_each_entry(p, &trigger_commands, list) {
229a88e1cfbSTom Zanussi if (p->unreg_all)
230a88e1cfbSTom Zanussi p->unreg_all(event_file);
231a88e1cfbSTom Zanussi }
232a88e1cfbSTom Zanussi }
233a88e1cfbSTom Zanussi
23485f2b082STom Zanussi if (file->f_mode & FMODE_READ) {
23585f2b082STom Zanussi ret = seq_open(file, &event_triggers_seq_ops);
23685f2b082STom Zanussi if (!ret) {
23785f2b082STom Zanussi struct seq_file *m = file->private_data;
23885f2b082STom Zanussi m->private = file;
23985f2b082STom Zanussi }
24085f2b082STom Zanussi }
24185f2b082STom Zanussi
24285f2b082STom Zanussi mutex_unlock(&event_mutex);
24385f2b082STom Zanussi
24485f2b082STom Zanussi return ret;
24585f2b082STom Zanussi }
24685f2b082STom Zanussi
trigger_process_regex(struct trace_event_file * file,char * buff)24781a59555SMasami Hiramatsu int trigger_process_regex(struct trace_event_file *file, char *buff)
24885f2b082STom Zanussi {
2496784beadSMasami Hiramatsu char *command, *next;
25085f2b082STom Zanussi struct event_command *p;
25185f2b082STom Zanussi int ret = -EINVAL;
25285f2b082STom Zanussi
2536784beadSMasami Hiramatsu next = buff = skip_spaces(buff);
25485f2b082STom Zanussi command = strsep(&next, ": \t");
2556784beadSMasami Hiramatsu if (next) {
2566784beadSMasami Hiramatsu next = skip_spaces(next);
2576784beadSMasami Hiramatsu if (!*next)
2586784beadSMasami Hiramatsu next = NULL;
2596784beadSMasami Hiramatsu }
26085f2b082STom Zanussi command = (command[0] != '!') ? command : command + 1;
26185f2b082STom Zanussi
26285f2b082STom Zanussi mutex_lock(&trigger_cmd_mutex);
26385f2b082STom Zanussi list_for_each_entry(p, &trigger_commands, list) {
26485f2b082STom Zanussi if (strcmp(p->name, command) == 0) {
2659ec5a7d1STom Zanussi ret = p->parse(p, file, buff, command, next);
26685f2b082STom Zanussi goto out_unlock;
26785f2b082STom Zanussi }
26885f2b082STom Zanussi }
26985f2b082STom Zanussi out_unlock:
27085f2b082STom Zanussi mutex_unlock(&trigger_cmd_mutex);
27185f2b082STom Zanussi
27285f2b082STom Zanussi return ret;
27385f2b082STom Zanussi }
27485f2b082STom Zanussi
event_trigger_regex_write(struct file * file,const char __user * ubuf,size_t cnt,loff_t * ppos)27585f2b082STom Zanussi static ssize_t event_trigger_regex_write(struct file *file,
27685f2b082STom Zanussi const char __user *ubuf,
27785f2b082STom Zanussi size_t cnt, loff_t *ppos)
27885f2b082STom Zanussi {
2797f1d2f82SSteven Rostedt (Red Hat) struct trace_event_file *event_file;
28085f2b082STom Zanussi ssize_t ret;
28185f2b082STom Zanussi char *buf;
28285f2b082STom Zanussi
28385f2b082STom Zanussi if (!cnt)
28485f2b082STom Zanussi return 0;
28585f2b082STom Zanussi
28685f2b082STom Zanussi if (cnt >= PAGE_SIZE)
28785f2b082STom Zanussi return -EINVAL;
28885f2b082STom Zanussi
28970f6cbb6SAl Viro buf = memdup_user_nul(ubuf, cnt);
29070f6cbb6SAl Viro if (IS_ERR(buf))
29170f6cbb6SAl Viro return PTR_ERR(buf);
29285f2b082STom Zanussi
29385f2b082STom Zanussi strim(buf);
29485f2b082STom Zanussi
29585f2b082STom Zanussi mutex_lock(&event_mutex);
29685f2b082STom Zanussi event_file = event_file_data(file);
29785f2b082STom Zanussi if (unlikely(!event_file)) {
29885f2b082STom Zanussi mutex_unlock(&event_mutex);
29970f6cbb6SAl Viro kfree(buf);
30085f2b082STom Zanussi return -ENODEV;
30185f2b082STom Zanussi }
30285f2b082STom Zanussi ret = trigger_process_regex(event_file, buf);
30385f2b082STom Zanussi mutex_unlock(&event_mutex);
30485f2b082STom Zanussi
30570f6cbb6SAl Viro kfree(buf);
30685f2b082STom Zanussi if (ret < 0)
30785f2b082STom Zanussi goto out;
30885f2b082STom Zanussi
30985f2b082STom Zanussi *ppos += cnt;
31085f2b082STom Zanussi ret = cnt;
31185f2b082STom Zanussi out:
31285f2b082STom Zanussi return ret;
31385f2b082STom Zanussi }
31485f2b082STom Zanussi
event_trigger_regex_release(struct inode * inode,struct file * file)31585f2b082STom Zanussi static int event_trigger_regex_release(struct inode *inode, struct file *file)
31685f2b082STom Zanussi {
31785f2b082STom Zanussi mutex_lock(&event_mutex);
31885f2b082STom Zanussi
31985f2b082STom Zanussi if (file->f_mode & FMODE_READ)
32085f2b082STom Zanussi seq_release(inode, file);
32185f2b082STom Zanussi
32285f2b082STom Zanussi mutex_unlock(&event_mutex);
32385f2b082STom Zanussi
32485f2b082STom Zanussi return 0;
32585f2b082STom Zanussi }
32685f2b082STom Zanussi
32785f2b082STom Zanussi static ssize_t
event_trigger_write(struct file * filp,const char __user * ubuf,size_t cnt,loff_t * ppos)32885f2b082STom Zanussi event_trigger_write(struct file *filp, const char __user *ubuf,
32985f2b082STom Zanussi size_t cnt, loff_t *ppos)
33085f2b082STom Zanussi {
33185f2b082STom Zanussi return event_trigger_regex_write(filp, ubuf, cnt, ppos);
33285f2b082STom Zanussi }
33385f2b082STom Zanussi
33485f2b082STom Zanussi static int
event_trigger_open(struct inode * inode,struct file * filp)33585f2b082STom Zanussi event_trigger_open(struct inode *inode, struct file *filp)
33685f2b082STom Zanussi {
33717911ff3SSteven Rostedt (VMware) /* Checks for tracefs lockdown */
33885f2b082STom Zanussi return event_trigger_regex_open(inode, filp);
33985f2b082STom Zanussi }
34085f2b082STom Zanussi
34185f2b082STom Zanussi static int
event_trigger_release(struct inode * inode,struct file * file)34285f2b082STom Zanussi event_trigger_release(struct inode *inode, struct file *file)
34385f2b082STom Zanussi {
34485f2b082STom Zanussi return event_trigger_regex_release(inode, file);
34585f2b082STom Zanussi }
34685f2b082STom Zanussi
34785f2b082STom Zanussi const struct file_operations event_trigger_fops = {
34885f2b082STom Zanussi .open = event_trigger_open,
34985f2b082STom Zanussi .read = seq_read,
35085f2b082STom Zanussi .write = event_trigger_write,
351098c879eSSteven Rostedt (Red Hat) .llseek = tracing_lseek,
35285f2b082STom Zanussi .release = event_trigger_release,
35385f2b082STom Zanussi };
35485f2b082STom Zanussi
3552a2df321STom Zanussi /*
3562a2df321STom Zanussi * Currently we only register event commands from __init, so mark this
3572a2df321STom Zanussi * __init too.
3582a2df321STom Zanussi */
register_event_command(struct event_command * cmd)359ab4bf008STom Zanussi __init int register_event_command(struct event_command *cmd)
3602a2df321STom Zanussi {
3612a2df321STom Zanussi struct event_command *p;
3622a2df321STom Zanussi int ret = 0;
3632a2df321STom Zanussi
3642a2df321STom Zanussi mutex_lock(&trigger_cmd_mutex);
3652a2df321STom Zanussi list_for_each_entry(p, &trigger_commands, list) {
3662a2df321STom Zanussi if (strcmp(cmd->name, p->name) == 0) {
3672a2df321STom Zanussi ret = -EBUSY;
3682a2df321STom Zanussi goto out_unlock;
3692a2df321STom Zanussi }
3702a2df321STom Zanussi }
3712a2df321STom Zanussi list_add(&cmd->list, &trigger_commands);
3722a2df321STom Zanussi out_unlock:
3732a2df321STom Zanussi mutex_unlock(&trigger_cmd_mutex);
3742a2df321STom Zanussi
3752a2df321STom Zanussi return ret;
3762a2df321STom Zanussi }
3772a2df321STom Zanussi
3782a2df321STom Zanussi /*
3792a2df321STom Zanussi * Currently we only unregister event commands from __init, so mark
3802a2df321STom Zanussi * this __init too.
3812a2df321STom Zanussi */
unregister_event_command(struct event_command * cmd)382d0bad49bSTom Zanussi __init int unregister_event_command(struct event_command *cmd)
3832a2df321STom Zanussi {
3842a2df321STom Zanussi struct event_command *p, *n;
3852a2df321STom Zanussi int ret = -ENODEV;
3862a2df321STom Zanussi
3872a2df321STom Zanussi mutex_lock(&trigger_cmd_mutex);
3882a2df321STom Zanussi list_for_each_entry_safe(p, n, &trigger_commands, list) {
3892a2df321STom Zanussi if (strcmp(cmd->name, p->name) == 0) {
3902a2df321STom Zanussi ret = 0;
3912a2df321STom Zanussi list_del_init(&p->list);
3922a2df321STom Zanussi goto out_unlock;
3932a2df321STom Zanussi }
3942a2df321STom Zanussi }
3952a2df321STom Zanussi out_unlock:
3962a2df321STom Zanussi mutex_unlock(&trigger_cmd_mutex);
3972a2df321STom Zanussi
3982a2df321STom Zanussi return ret;
3992a2df321STom Zanussi }
4002a2df321STom Zanussi
4012a2df321STom Zanussi /**
4022a2df321STom Zanussi * event_trigger_print - Generic event_trigger_ops @print implementation
4032a2df321STom Zanussi * @name: The name of the event trigger
4042a2df321STom Zanussi * @m: The seq_file being printed to
4052a2df321STom Zanussi * @data: Trigger-specific data
4062a2df321STom Zanussi * @filter_str: filter_str to print, if present
4072a2df321STom Zanussi *
4082a2df321STom Zanussi * Common implementation for event triggers to print themselves.
4092a2df321STom Zanussi *
4102a2df321STom Zanussi * Usually wrapped by a function that simply sets the @name of the
4112a2df321STom Zanussi * trigger command and then invokes this.
4122a2df321STom Zanussi *
4132a2df321STom Zanussi * Return: 0 on success, errno otherwise
4142a2df321STom Zanussi */
4152a2df321STom Zanussi static int
event_trigger_print(const char * name,struct seq_file * m,void * data,char * filter_str)4162a2df321STom Zanussi event_trigger_print(const char *name, struct seq_file *m,
4172a2df321STom Zanussi void *data, char *filter_str)
4182a2df321STom Zanussi {
4192a2df321STom Zanussi long count = (long)data;
4202a2df321STom Zanussi
421fa6f0cc7SRasmus Villemoes seq_puts(m, name);
4222a2df321STom Zanussi
4232a2df321STom Zanussi if (count == -1)
4242a2df321STom Zanussi seq_puts(m, ":unlimited");
4252a2df321STom Zanussi else
4262a2df321STom Zanussi seq_printf(m, ":count=%ld", count);
4272a2df321STom Zanussi
4282a2df321STom Zanussi if (filter_str)
4292a2df321STom Zanussi seq_printf(m, " if %s\n", filter_str);
4302a2df321STom Zanussi else
4311177e436SRasmus Villemoes seq_putc(m, '\n');
4322a2df321STom Zanussi
4332a2df321STom Zanussi return 0;
4342a2df321STom Zanussi }
4352a2df321STom Zanussi
4362a2df321STom Zanussi /**
4372a2df321STom Zanussi * event_trigger_init - Generic event_trigger_ops @init implementation
4382a2df321STom Zanussi * @data: Trigger-specific data
4392a2df321STom Zanussi *
4402a2df321STom Zanussi * Common implementation of event trigger initialization.
4412a2df321STom Zanussi *
4422a2df321STom Zanussi * Usually used directly as the @init method in event trigger
4432a2df321STom Zanussi * implementations.
4442a2df321STom Zanussi *
4452a2df321STom Zanussi * Return: 0 on success, errno otherwise
4462a2df321STom Zanussi */
event_trigger_init(struct event_trigger_data * data)44747670541STom Zanussi int event_trigger_init(struct event_trigger_data *data)
4482a2df321STom Zanussi {
4492a2df321STom Zanussi data->ref++;
4502a2df321STom Zanussi return 0;
4512a2df321STom Zanussi }
4522a2df321STom Zanussi
4532a2df321STom Zanussi /**
4542a2df321STom Zanussi * event_trigger_free - Generic event_trigger_ops @free implementation
4552a2df321STom Zanussi * @data: Trigger-specific data
4562a2df321STom Zanussi *
4572a2df321STom Zanussi * Common implementation of event trigger de-initialization.
4582a2df321STom Zanussi *
4592a2df321STom Zanussi * Usually used directly as the @free method in event trigger
4602a2df321STom Zanussi * implementations.
4612a2df321STom Zanussi */
4622a2df321STom Zanussi static void
event_trigger_free(struct event_trigger_data * data)46347670541STom Zanussi event_trigger_free(struct event_trigger_data *data)
4642a2df321STom Zanussi {
4652a2df321STom Zanussi if (WARN_ON_ONCE(data->ref <= 0))
4662a2df321STom Zanussi return;
4672a2df321STom Zanussi
4682a2df321STom Zanussi data->ref--;
4692a2df321STom Zanussi if (!data->ref)
4702a2df321STom Zanussi trigger_data_free(data);
4712a2df321STom Zanussi }
4722a2df321STom Zanussi
trace_event_trigger_enable_disable(struct trace_event_file * file,int trigger_enable)473ab4bf008STom Zanussi int trace_event_trigger_enable_disable(struct trace_event_file *file,
47485f2b082STom Zanussi int trigger_enable)
47585f2b082STom Zanussi {
47685f2b082STom Zanussi int ret = 0;
47785f2b082STom Zanussi
47885f2b082STom Zanussi if (trigger_enable) {
47985f2b082STom Zanussi if (atomic_inc_return(&file->tm_ref) > 1)
48085f2b082STom Zanussi return ret;
4815d6ad960SSteven Rostedt (Red Hat) set_bit(EVENT_FILE_FL_TRIGGER_MODE_BIT, &file->flags);
48285f2b082STom Zanussi ret = trace_event_enable_disable(file, 1, 1);
48385f2b082STom Zanussi } else {
48485f2b082STom Zanussi if (atomic_dec_return(&file->tm_ref) > 0)
48585f2b082STom Zanussi return ret;
4865d6ad960SSteven Rostedt (Red Hat) clear_bit(EVENT_FILE_FL_TRIGGER_MODE_BIT, &file->flags);
48785f2b082STom Zanussi ret = trace_event_enable_disable(file, 0, 1);
48885f2b082STom Zanussi }
48985f2b082STom Zanussi
49085f2b082STom Zanussi return ret;
49185f2b082STom Zanussi }
49285f2b082STom Zanussi
49385f2b082STom Zanussi /**
49485f2b082STom Zanussi * clear_event_triggers - Clear all triggers associated with a trace array
49585f2b082STom Zanussi * @tr: The trace array to clear
49685f2b082STom Zanussi *
49785f2b082STom Zanussi * For each trigger, the triggering event has its tm_ref decremented
49885f2b082STom Zanussi * via trace_event_trigger_enable_disable(), and any associated event
49985f2b082STom Zanussi * (in the case of enable/disable_event triggers) will have its sm_ref
50085f2b082STom Zanussi * decremented via free()->trace_event_enable_disable(). That
50185f2b082STom Zanussi * combination effectively reverses the soft-mode/trigger state added
50285f2b082STom Zanussi * by trigger registration.
50385f2b082STom Zanussi *
50485f2b082STom Zanussi * Must be called with event_mutex held.
50585f2b082STom Zanussi */
50685f2b082STom Zanussi void
clear_event_triggers(struct trace_array * tr)50785f2b082STom Zanussi clear_event_triggers(struct trace_array *tr)
50885f2b082STom Zanussi {
5097f1d2f82SSteven Rostedt (Red Hat) struct trace_event_file *file;
51085f2b082STom Zanussi
51185f2b082STom Zanussi list_for_each_entry(file, &tr->events, list) {
51286b389ffSSteven Rostedt (VMware) struct event_trigger_data *data, *n;
51386b389ffSSteven Rostedt (VMware) list_for_each_entry_safe(data, n, &file->triggers, list) {
51485f2b082STom Zanussi trace_event_trigger_enable_disable(file, 0);
51586b389ffSSteven Rostedt (VMware) list_del_rcu(&data->list);
51685f2b082STom Zanussi if (data->ops->free)
51747670541STom Zanussi data->ops->free(data);
51885f2b082STom Zanussi }
51985f2b082STom Zanussi }
52085f2b082STom Zanussi }
52185f2b082STom Zanussi
5222a2df321STom Zanussi /**
523bac5fb97STom Zanussi * update_cond_flag - Set or reset the TRIGGER_COND bit
5247f1d2f82SSteven Rostedt (Red Hat) * @file: The trace_event_file associated with the event
525bac5fb97STom Zanussi *
526bac5fb97STom Zanussi * If an event has triggers and any of those triggers has a filter or
527bac5fb97STom Zanussi * a post_trigger, trigger invocation needs to be deferred until after
528bac5fb97STom Zanussi * the current event has logged its data, and the event should have
529bac5fb97STom Zanussi * its TRIGGER_COND bit set, otherwise the TRIGGER_COND bit should be
530bac5fb97STom Zanussi * cleared.
531bac5fb97STom Zanussi */
update_cond_flag(struct trace_event_file * file)532ab4bf008STom Zanussi void update_cond_flag(struct trace_event_file *file)
533bac5fb97STom Zanussi {
534bac5fb97STom Zanussi struct event_trigger_data *data;
535bac5fb97STom Zanussi bool set_cond = false;
536bac5fb97STom Zanussi
5373b42a4c8SMasami Hiramatsu lockdep_assert_held(&event_mutex);
5383b42a4c8SMasami Hiramatsu
5393b42a4c8SMasami Hiramatsu list_for_each_entry(data, &file->triggers, list) {
540353206f5SSteven Rostedt (Red Hat) if (data->filter || event_command_post_trigger(data->cmd_ops) ||
541353206f5SSteven Rostedt (Red Hat) event_command_needs_rec(data->cmd_ops)) {
542bac5fb97STom Zanussi set_cond = true;
543bac5fb97STom Zanussi break;
544bac5fb97STom Zanussi }
545bac5fb97STom Zanussi }
546bac5fb97STom Zanussi
547bac5fb97STom Zanussi if (set_cond)
5485d6ad960SSteven Rostedt (Red Hat) set_bit(EVENT_FILE_FL_TRIGGER_COND_BIT, &file->flags);
549bac5fb97STom Zanussi else
5505d6ad960SSteven Rostedt (Red Hat) clear_bit(EVENT_FILE_FL_TRIGGER_COND_BIT, &file->flags);
551bac5fb97STom Zanussi }
552bac5fb97STom Zanussi
553bac5fb97STom Zanussi /**
5542a2df321STom Zanussi * register_trigger - Generic event_command @reg implementation
5552a2df321STom Zanussi * @glob: The raw string used to register the trigger
5562a2df321STom Zanussi * @data: Trigger-specific data to associate with the trigger
5577f1d2f82SSteven Rostedt (Red Hat) * @file: The trace_event_file associated with the event
5582a2df321STom Zanussi *
5592a2df321STom Zanussi * Common implementation for event trigger registration.
5602a2df321STom Zanussi *
5612a2df321STom Zanussi * Usually used directly as the @reg method in event command
5622a2df321STom Zanussi * implementations.
5632a2df321STom Zanussi *
5642a2df321STom Zanussi * Return: 0 on success, errno otherwise
5652a2df321STom Zanussi */
register_trigger(char * glob,struct event_trigger_data * data,struct trace_event_file * file)5662378a2d6STom Zanussi static int register_trigger(char *glob,
5672a2df321STom Zanussi struct event_trigger_data *data,
5687f1d2f82SSteven Rostedt (Red Hat) struct trace_event_file *file)
5692a2df321STom Zanussi {
5702a2df321STom Zanussi struct event_trigger_data *test;
5712a2df321STom Zanussi int ret = 0;
5722a2df321STom Zanussi
5733b42a4c8SMasami Hiramatsu lockdep_assert_held(&event_mutex);
5743b42a4c8SMasami Hiramatsu
5753b42a4c8SMasami Hiramatsu list_for_each_entry(test, &file->triggers, list) {
5762a2df321STom Zanussi if (test->cmd_ops->trigger_type == data->cmd_ops->trigger_type) {
5772a2df321STom Zanussi ret = -EEXIST;
5782a2df321STom Zanussi goto out;
5792a2df321STom Zanussi }
5802a2df321STom Zanussi }
5812a2df321STom Zanussi
5822a2df321STom Zanussi if (data->ops->init) {
58347670541STom Zanussi ret = data->ops->init(data);
5842a2df321STom Zanussi if (ret < 0)
5852a2df321STom Zanussi goto out;
5862a2df321STom Zanussi }
5872a2df321STom Zanussi
5882a2df321STom Zanussi list_add_rcu(&data->list, &file->triggers);
5892a2df321STom Zanussi
5904e4a4d75STom Zanussi update_cond_flag(file);
591b8cc44a4STom Zanussi ret = trace_event_trigger_enable_disable(file, 1);
592b8cc44a4STom Zanussi if (ret < 0) {
5932a2df321STom Zanussi list_del_rcu(&data->list);
5944e4a4d75STom Zanussi update_cond_flag(file);
5952a2df321STom Zanussi }
5962a2df321STom Zanussi out:
5972a2df321STom Zanussi return ret;
5982a2df321STom Zanussi }
5992a2df321STom Zanussi
6002a2df321STom Zanussi /**
6012a2df321STom Zanussi * unregister_trigger - Generic event_command @unreg implementation
6022a2df321STom Zanussi * @glob: The raw string used to register the trigger
6032a2df321STom Zanussi * @test: Trigger-specific data used to find the trigger to remove
6047f1d2f82SSteven Rostedt (Red Hat) * @file: The trace_event_file associated with the event
6052a2df321STom Zanussi *
6062a2df321STom Zanussi * Common implementation for event trigger unregistration.
6072a2df321STom Zanussi *
6082a2df321STom Zanussi * Usually used directly as the @unreg method in event command
6092a2df321STom Zanussi * implementations.
6102a2df321STom Zanussi */
unregister_trigger(char * glob,struct event_trigger_data * test,struct trace_event_file * file)6112378a2d6STom Zanussi static void unregister_trigger(char *glob,
6122a2df321STom Zanussi struct event_trigger_data *test,
6137f1d2f82SSteven Rostedt (Red Hat) struct trace_event_file *file)
6142a2df321STom Zanussi {
61545e333ceSJakob Koschel struct event_trigger_data *data = NULL, *iter;
6162a2df321STom Zanussi
6173b42a4c8SMasami Hiramatsu lockdep_assert_held(&event_mutex);
6183b42a4c8SMasami Hiramatsu
61945e333ceSJakob Koschel list_for_each_entry(iter, &file->triggers, list) {
62045e333ceSJakob Koschel if (iter->cmd_ops->trigger_type == test->cmd_ops->trigger_type) {
62145e333ceSJakob Koschel data = iter;
6222a2df321STom Zanussi list_del_rcu(&data->list);
6232a2df321STom Zanussi trace_event_trigger_enable_disable(file, 0);
6244e4a4d75STom Zanussi update_cond_flag(file);
6252a2df321STom Zanussi break;
6262a2df321STom Zanussi }
6272a2df321STom Zanussi }
6282a2df321STom Zanussi
62945e333ceSJakob Koschel if (data && data->ops->free)
63047670541STom Zanussi data->ops->free(data);
6312a2df321STom Zanussi }
6322a2df321STom Zanussi
63386599dbeSTom Zanussi /*
63486599dbeSTom Zanussi * Event trigger parsing helper functions.
63586599dbeSTom Zanussi *
63686599dbeSTom Zanussi * These functions help make it easier to write an event trigger
63786599dbeSTom Zanussi * parsing function i.e. the struct event_command.parse() callback
63886599dbeSTom Zanussi * function responsible for parsing and registering a trigger command
63986599dbeSTom Zanussi * written to the 'trigger' file.
64086599dbeSTom Zanussi *
64186599dbeSTom Zanussi * A trigger command (or just 'trigger' for short) takes the form:
64286599dbeSTom Zanussi * [trigger] [if filter]
64386599dbeSTom Zanussi *
64486599dbeSTom Zanussi * The struct event_command.parse() callback (and other struct
64586599dbeSTom Zanussi * event_command functions) refer to several components of a trigger
64686599dbeSTom Zanussi * command. Those same components are referenced by the event trigger
64786599dbeSTom Zanussi * parsing helper functions defined below. These components are:
64886599dbeSTom Zanussi *
64986599dbeSTom Zanussi * cmd - the trigger command name
65086599dbeSTom Zanussi * glob - the trigger command name optionally prefaced with '!'
65186599dbeSTom Zanussi * param_and_filter - text following cmd and ':'
65286599dbeSTom Zanussi * param - text following cmd and ':' and stripped of filter
65386599dbeSTom Zanussi * filter - the optional filter text following (and including) 'if'
65486599dbeSTom Zanussi *
65586599dbeSTom Zanussi * To illustrate the use of these componenents, here are some concrete
65686599dbeSTom Zanussi * examples. For the following triggers:
65786599dbeSTom Zanussi *
65886599dbeSTom Zanussi * echo 'traceon:5 if pid == 0' > trigger
65986599dbeSTom Zanussi * - 'traceon' is both cmd and glob
66086599dbeSTom Zanussi * - '5 if pid == 0' is the param_and_filter
66186599dbeSTom Zanussi * - '5' is the param
66286599dbeSTom Zanussi * - 'if pid == 0' is the filter
66386599dbeSTom Zanussi *
66486599dbeSTom Zanussi * echo 'enable_event:sys:event:n' > trigger
66586599dbeSTom Zanussi * - 'enable_event' is both cmd and glob
66686599dbeSTom Zanussi * - 'sys:event:n' is the param_and_filter
66786599dbeSTom Zanussi * - 'sys:event:n' is the param
66886599dbeSTom Zanussi * - there is no filter
66986599dbeSTom Zanussi *
67086599dbeSTom Zanussi * echo 'hist:keys=pid if prio > 50' > trigger
67186599dbeSTom Zanussi * - 'hist' is both cmd and glob
67286599dbeSTom Zanussi * - 'keys=pid if prio > 50' is the param_and_filter
67386599dbeSTom Zanussi * - 'keys=pid' is the param
67486599dbeSTom Zanussi * - 'if prio > 50' is the filter
67586599dbeSTom Zanussi *
67686599dbeSTom Zanussi * echo '!enable_event:sys:event:n' > trigger
67786599dbeSTom Zanussi * - 'enable_event' the cmd
67886599dbeSTom Zanussi * - '!enable_event' is the glob
67986599dbeSTom Zanussi * - 'sys:event:n' is the param_and_filter
68086599dbeSTom Zanussi * - 'sys:event:n' is the param
68186599dbeSTom Zanussi * - there is no filter
68286599dbeSTom Zanussi *
68386599dbeSTom Zanussi * echo 'traceoff' > trigger
68486599dbeSTom Zanussi * - 'traceoff' is both cmd and glob
68586599dbeSTom Zanussi * - there is no param_and_filter
68686599dbeSTom Zanussi * - there is no param
68786599dbeSTom Zanussi * - there is no filter
68886599dbeSTom Zanussi *
68986599dbeSTom Zanussi * There are a few different categories of event trigger covered by
69086599dbeSTom Zanussi * these helpers:
69186599dbeSTom Zanussi *
69286599dbeSTom Zanussi * - triggers that don't require a parameter e.g. traceon
69386599dbeSTom Zanussi * - triggers that do require a parameter e.g. enable_event and hist
69486599dbeSTom Zanussi * - triggers that though they may not require a param may support an
69586599dbeSTom Zanussi * optional 'n' param (n = number of times the trigger should fire)
69686599dbeSTom Zanussi * e.g.: traceon:5 or enable_event:sys:event:n
69786599dbeSTom Zanussi * - triggers that do not support an 'n' param e.g. hist
69886599dbeSTom Zanussi *
69986599dbeSTom Zanussi * These functions can be used or ignored as necessary - it all
70086599dbeSTom Zanussi * depends on the complexity of the trigger, and the granularity of
70186599dbeSTom Zanussi * the functions supported reflects the fact that some implementations
70286599dbeSTom Zanussi * may need to customize certain aspects of their implementations and
70386599dbeSTom Zanussi * won't need certain functions. For instance, the hist trigger
70486599dbeSTom Zanussi * implementation doesn't use event_trigger_separate_filter() because
70586599dbeSTom Zanussi * it has special requirements for handling the filter.
70686599dbeSTom Zanussi */
70786599dbeSTom Zanussi
70886599dbeSTom Zanussi /**
70986599dbeSTom Zanussi * event_trigger_check_remove - check whether an event trigger specifies remove
71086599dbeSTom Zanussi * @glob: The trigger command string, with optional remove(!) operator
71186599dbeSTom Zanussi *
71286599dbeSTom Zanussi * The event trigger callback implementations pass in 'glob' as a
71386599dbeSTom Zanussi * parameter. This is the command name either with or without a
71486599dbeSTom Zanussi * remove(!) operator. This function simply parses the glob and
71586599dbeSTom Zanussi * determines whether the command corresponds to a trigger removal or
71686599dbeSTom Zanussi * a trigger addition.
71786599dbeSTom Zanussi *
71886599dbeSTom Zanussi * Return: true if this is a remove command, false otherwise
71986599dbeSTom Zanussi */
event_trigger_check_remove(const char * glob)72086599dbeSTom Zanussi bool event_trigger_check_remove(const char *glob)
72186599dbeSTom Zanussi {
72286599dbeSTom Zanussi return (glob && glob[0] == '!') ? true : false;
72386599dbeSTom Zanussi }
72486599dbeSTom Zanussi
72586599dbeSTom Zanussi /**
72686599dbeSTom Zanussi * event_trigger_empty_param - check whether the param is empty
72786599dbeSTom Zanussi * @param: The trigger param string
72886599dbeSTom Zanussi *
72986599dbeSTom Zanussi * The event trigger callback implementations pass in 'param' as a
73086599dbeSTom Zanussi * parameter. This corresponds to the string following the command
73186599dbeSTom Zanussi * name minus the command name. This function can be called by a
73286599dbeSTom Zanussi * callback implementation for any command that requires a param; a
73386599dbeSTom Zanussi * callback that doesn't require a param can ignore it.
73486599dbeSTom Zanussi *
73586599dbeSTom Zanussi * Return: true if this is an empty param, false otherwise
73686599dbeSTom Zanussi */
event_trigger_empty_param(const char * param)73786599dbeSTom Zanussi bool event_trigger_empty_param(const char *param)
73886599dbeSTom Zanussi {
73986599dbeSTom Zanussi return !param;
74086599dbeSTom Zanussi }
74186599dbeSTom Zanussi
74286599dbeSTom Zanussi /**
74386599dbeSTom Zanussi * event_trigger_separate_filter - separate an event trigger from a filter
7448d4a21b5Ssunliming * @param_and_filter: String containing trigger and possibly filter
7458d4a21b5Ssunliming * @param: outparam, will be filled with a pointer to the trigger
74686599dbeSTom Zanussi * @filter: outparam, will be filled with a pointer to the filter
74786599dbeSTom Zanussi * @param_required: Specifies whether or not the param string is required
74886599dbeSTom Zanussi *
74986599dbeSTom Zanussi * Given a param string of the form '[trigger] [if filter]', this
75086599dbeSTom Zanussi * function separates the filter from the trigger and returns the
7518d4a21b5Ssunliming * trigger in @param and the filter in @filter. Either the @param
7528d4a21b5Ssunliming * or the @filter may be set to NULL by this function - if not set to
75386599dbeSTom Zanussi * NULL, they will contain strings corresponding to the trigger and
75486599dbeSTom Zanussi * filter.
75586599dbeSTom Zanussi *
75686599dbeSTom Zanussi * There are two cases that need to be handled with respect to the
75786599dbeSTom Zanussi * passed-in param: either the param is required, or it is not
75886599dbeSTom Zanussi * required. If @param_required is set, and there's no param, it will
75986599dbeSTom Zanussi * return -EINVAL. If @param_required is not set and there's a param
76086599dbeSTom Zanussi * that starts with a number, that corresponds to the case of a
76186599dbeSTom Zanussi * trigger with :n (n = number of times the trigger should fire) and
76286599dbeSTom Zanussi * the parsing continues normally; otherwise the function just returns
76386599dbeSTom Zanussi * and assumes param just contains a filter and there's nothing else
76486599dbeSTom Zanussi * to do.
76586599dbeSTom Zanussi *
76686599dbeSTom Zanussi * Return: 0 on success, errno otherwise
76786599dbeSTom Zanussi */
event_trigger_separate_filter(char * param_and_filter,char ** param,char ** filter,bool param_required)76886599dbeSTom Zanussi int event_trigger_separate_filter(char *param_and_filter, char **param,
76986599dbeSTom Zanussi char **filter, bool param_required)
77086599dbeSTom Zanussi {
77186599dbeSTom Zanussi int ret = 0;
77286599dbeSTom Zanussi
77386599dbeSTom Zanussi *param = *filter = NULL;
77486599dbeSTom Zanussi
77586599dbeSTom Zanussi if (!param_and_filter) {
77686599dbeSTom Zanussi if (param_required)
77786599dbeSTom Zanussi ret = -EINVAL;
77886599dbeSTom Zanussi goto out;
77986599dbeSTom Zanussi }
78086599dbeSTom Zanussi
78186599dbeSTom Zanussi /*
78286599dbeSTom Zanussi * Here we check for an optional param. The only legal
78386599dbeSTom Zanussi * optional param is :n, and if that's the case, continue
78486599dbeSTom Zanussi * below. Otherwise we assume what's left is a filter and
78586599dbeSTom Zanussi * return it as the filter string for the caller to deal with.
78686599dbeSTom Zanussi */
78786599dbeSTom Zanussi if (!param_required && param_and_filter && !isdigit(param_and_filter[0])) {
78886599dbeSTom Zanussi *filter = param_and_filter;
78986599dbeSTom Zanussi goto out;
79086599dbeSTom Zanussi }
79186599dbeSTom Zanussi
79286599dbeSTom Zanussi /*
79386599dbeSTom Zanussi * Separate the param from the filter (param [if filter]).
79486599dbeSTom Zanussi * Here we have either an optional :n param or a required
79586599dbeSTom Zanussi * param and an optional filter.
79686599dbeSTom Zanussi */
79786599dbeSTom Zanussi *param = strsep(¶m_and_filter, " \t");
79886599dbeSTom Zanussi
79986599dbeSTom Zanussi /*
80086599dbeSTom Zanussi * Here we have a filter, though it may be empty.
80186599dbeSTom Zanussi */
80286599dbeSTom Zanussi if (param_and_filter) {
80386599dbeSTom Zanussi *filter = skip_spaces(param_and_filter);
80486599dbeSTom Zanussi if (!**filter)
80586599dbeSTom Zanussi *filter = NULL;
80686599dbeSTom Zanussi }
80786599dbeSTom Zanussi out:
80886599dbeSTom Zanussi return ret;
80986599dbeSTom Zanussi }
81086599dbeSTom Zanussi
81186599dbeSTom Zanussi /**
81286599dbeSTom Zanussi * event_trigger_alloc - allocate and init event_trigger_data for a trigger
81386599dbeSTom Zanussi * @cmd_ops: The event_command operations for the trigger
81486599dbeSTom Zanussi * @cmd: The cmd string
81586599dbeSTom Zanussi * @param: The param string
81686599dbeSTom Zanussi * @private_data: User data to associate with the event trigger
81786599dbeSTom Zanussi *
81886599dbeSTom Zanussi * Allocate an event_trigger_data instance and initialize it. The
81986599dbeSTom Zanussi * @cmd_ops are used along with the @cmd and @param to get the
82086599dbeSTom Zanussi * trigger_ops to assign to the event_trigger_data. @private_data can
82186599dbeSTom Zanussi * also be passed in and associated with the event_trigger_data.
82286599dbeSTom Zanussi *
82386599dbeSTom Zanussi * Use event_trigger_free() to free an event_trigger_data object.
82486599dbeSTom Zanussi *
82586599dbeSTom Zanussi * Return: The trigger_data object success, NULL otherwise
82686599dbeSTom Zanussi */
event_trigger_alloc(struct event_command * cmd_ops,char * cmd,char * param,void * private_data)82786599dbeSTom Zanussi struct event_trigger_data *event_trigger_alloc(struct event_command *cmd_ops,
82886599dbeSTom Zanussi char *cmd,
82986599dbeSTom Zanussi char *param,
83086599dbeSTom Zanussi void *private_data)
83186599dbeSTom Zanussi {
83286599dbeSTom Zanussi struct event_trigger_data *trigger_data;
83386599dbeSTom Zanussi struct event_trigger_ops *trigger_ops;
83486599dbeSTom Zanussi
83586599dbeSTom Zanussi trigger_ops = cmd_ops->get_trigger_ops(cmd, param);
83686599dbeSTom Zanussi
83786599dbeSTom Zanussi trigger_data = kzalloc(sizeof(*trigger_data), GFP_KERNEL);
83886599dbeSTom Zanussi if (!trigger_data)
83986599dbeSTom Zanussi return NULL;
84086599dbeSTom Zanussi
84186599dbeSTom Zanussi trigger_data->count = -1;
84286599dbeSTom Zanussi trigger_data->ops = trigger_ops;
84386599dbeSTom Zanussi trigger_data->cmd_ops = cmd_ops;
84486599dbeSTom Zanussi trigger_data->private_data = private_data;
84586599dbeSTom Zanussi
84686599dbeSTom Zanussi INIT_LIST_HEAD(&trigger_data->list);
84786599dbeSTom Zanussi INIT_LIST_HEAD(&trigger_data->named_list);
84886599dbeSTom Zanussi RCU_INIT_POINTER(trigger_data->filter, NULL);
84986599dbeSTom Zanussi
85086599dbeSTom Zanussi return trigger_data;
85186599dbeSTom Zanussi }
85286599dbeSTom Zanussi
85386599dbeSTom Zanussi /**
85486599dbeSTom Zanussi * event_trigger_parse_num - parse and return the number param for a trigger
85586599dbeSTom Zanussi * @param: The param string
85686599dbeSTom Zanussi * @trigger_data: The trigger_data for the trigger
85786599dbeSTom Zanussi *
85886599dbeSTom Zanussi * Parse the :n (n = number of times the trigger should fire) param
85986599dbeSTom Zanussi * and set the count variable in the trigger_data to the parsed count.
86086599dbeSTom Zanussi *
86186599dbeSTom Zanussi * Return: 0 on success, errno otherwise
86286599dbeSTom Zanussi */
event_trigger_parse_num(char * param,struct event_trigger_data * trigger_data)86386599dbeSTom Zanussi int event_trigger_parse_num(char *param,
86486599dbeSTom Zanussi struct event_trigger_data *trigger_data)
86586599dbeSTom Zanussi {
86686599dbeSTom Zanussi char *number;
86786599dbeSTom Zanussi int ret = 0;
86886599dbeSTom Zanussi
86986599dbeSTom Zanussi if (param) {
87086599dbeSTom Zanussi number = strsep(¶m, ":");
87186599dbeSTom Zanussi
87286599dbeSTom Zanussi if (!strlen(number))
87386599dbeSTom Zanussi return -EINVAL;
87486599dbeSTom Zanussi
87586599dbeSTom Zanussi /*
87686599dbeSTom Zanussi * We use the callback data field (which is a pointer)
87786599dbeSTom Zanussi * as our counter.
87886599dbeSTom Zanussi */
87986599dbeSTom Zanussi ret = kstrtoul(number, 0, &trigger_data->count);
88086599dbeSTom Zanussi }
88186599dbeSTom Zanussi
88286599dbeSTom Zanussi return ret;
88386599dbeSTom Zanussi }
88486599dbeSTom Zanussi
88586599dbeSTom Zanussi /**
88686599dbeSTom Zanussi * event_trigger_set_filter - set an event trigger's filter
88786599dbeSTom Zanussi * @cmd_ops: The event_command operations for the trigger
88886599dbeSTom Zanussi * @file: The event file for the trigger's event
88986599dbeSTom Zanussi * @param: The string containing the filter
89086599dbeSTom Zanussi * @trigger_data: The trigger_data for the trigger
89186599dbeSTom Zanussi *
89286599dbeSTom Zanussi * Set the filter for the trigger. If the filter is NULL, just return
89386599dbeSTom Zanussi * without error.
89486599dbeSTom Zanussi *
89586599dbeSTom Zanussi * Return: 0 on success, errno otherwise
89686599dbeSTom Zanussi */
event_trigger_set_filter(struct event_command * cmd_ops,struct trace_event_file * file,char * param,struct event_trigger_data * trigger_data)89786599dbeSTom Zanussi int event_trigger_set_filter(struct event_command *cmd_ops,
89886599dbeSTom Zanussi struct trace_event_file *file,
89986599dbeSTom Zanussi char *param,
90086599dbeSTom Zanussi struct event_trigger_data *trigger_data)
90186599dbeSTom Zanussi {
90286599dbeSTom Zanussi if (param && cmd_ops->set_filter)
90386599dbeSTom Zanussi return cmd_ops->set_filter(param, trigger_data, file);
90486599dbeSTom Zanussi
90586599dbeSTom Zanussi return 0;
90686599dbeSTom Zanussi }
90786599dbeSTom Zanussi
90886599dbeSTom Zanussi /**
90986599dbeSTom Zanussi * event_trigger_reset_filter - reset an event trigger's filter
91086599dbeSTom Zanussi * @cmd_ops: The event_command operations for the trigger
91186599dbeSTom Zanussi * @trigger_data: The trigger_data for the trigger
91286599dbeSTom Zanussi *
91386599dbeSTom Zanussi * Reset the filter for the trigger to no filter.
91486599dbeSTom Zanussi */
event_trigger_reset_filter(struct event_command * cmd_ops,struct event_trigger_data * trigger_data)91586599dbeSTom Zanussi void event_trigger_reset_filter(struct event_command *cmd_ops,
91686599dbeSTom Zanussi struct event_trigger_data *trigger_data)
91786599dbeSTom Zanussi {
91886599dbeSTom Zanussi if (cmd_ops->set_filter)
91986599dbeSTom Zanussi cmd_ops->set_filter(NULL, trigger_data, NULL);
92086599dbeSTom Zanussi }
92186599dbeSTom Zanussi
92286599dbeSTom Zanussi /**
92386599dbeSTom Zanussi * event_trigger_register - register an event trigger
92486599dbeSTom Zanussi * @cmd_ops: The event_command operations for the trigger
92586599dbeSTom Zanussi * @file: The event file for the trigger's event
92686599dbeSTom Zanussi * @glob: The trigger command string, with optional remove(!) operator
92786599dbeSTom Zanussi * @trigger_data: The trigger_data for the trigger
92886599dbeSTom Zanussi *
92986599dbeSTom Zanussi * Register an event trigger. The @cmd_ops are used to call the
930b8cc44a4STom Zanussi * cmd_ops->reg() function which actually does the registration.
93186599dbeSTom Zanussi *
93286599dbeSTom Zanussi * Return: 0 on success, errno otherwise
93386599dbeSTom Zanussi */
event_trigger_register(struct event_command * cmd_ops,struct trace_event_file * file,char * glob,struct event_trigger_data * trigger_data)93486599dbeSTom Zanussi int event_trigger_register(struct event_command *cmd_ops,
93586599dbeSTom Zanussi struct trace_event_file *file,
93686599dbeSTom Zanussi char *glob,
937b8cc44a4STom Zanussi struct event_trigger_data *trigger_data)
93886599dbeSTom Zanussi {
939b8cc44a4STom Zanussi return cmd_ops->reg(glob, trigger_data, file);
94086599dbeSTom Zanussi }
94186599dbeSTom Zanussi
942b8cc44a4STom Zanussi /**
943b8cc44a4STom Zanussi * event_trigger_unregister - unregister an event trigger
944b8cc44a4STom Zanussi * @cmd_ops: The event_command operations for the trigger
945b8cc44a4STom Zanussi * @file: The event file for the trigger's event
946b8cc44a4STom Zanussi * @glob: The trigger command string, with optional remove(!) operator
947b8cc44a4STom Zanussi * @trigger_data: The trigger_data for the trigger
948b8cc44a4STom Zanussi *
949b8cc44a4STom Zanussi * Unregister an event trigger. The @cmd_ops are used to call the
950b8cc44a4STom Zanussi * cmd_ops->unreg() function which actually does the unregistration.
951b8cc44a4STom Zanussi */
event_trigger_unregister(struct event_command * cmd_ops,struct trace_event_file * file,char * glob,struct event_trigger_data * trigger_data)952b8cc44a4STom Zanussi void event_trigger_unregister(struct event_command *cmd_ops,
953b8cc44a4STom Zanussi struct trace_event_file *file,
954b8cc44a4STom Zanussi char *glob,
955b8cc44a4STom Zanussi struct event_trigger_data *trigger_data)
956b8cc44a4STom Zanussi {
957b8cc44a4STom Zanussi cmd_ops->unreg(glob, trigger_data, file);
95886599dbeSTom Zanussi }
95986599dbeSTom Zanussi
96086599dbeSTom Zanussi /*
96186599dbeSTom Zanussi * End event trigger parsing helper functions.
96286599dbeSTom Zanussi */
96386599dbeSTom Zanussi
9642a2df321STom Zanussi /**
9659ec5a7d1STom Zanussi * event_trigger_parse - Generic event_command @parse implementation
9662a2df321STom Zanussi * @cmd_ops: The command ops, used for trigger registration
9677f1d2f82SSteven Rostedt (Red Hat) * @file: The trace_event_file associated with the event
9682a2df321STom Zanussi * @glob: The raw string used to register the trigger
9692a2df321STom Zanussi * @cmd: The cmd portion of the string used to register the trigger
970e1f187d0STom Zanussi * @param_and_filter: The param and filter portion of the string used to register the trigger
9712a2df321STom Zanussi *
9722a2df321STom Zanussi * Common implementation for event command parsing and trigger
9732a2df321STom Zanussi * instantiation.
9742a2df321STom Zanussi *
9759ec5a7d1STom Zanussi * Usually used directly as the @parse method in event command
9762a2df321STom Zanussi * implementations.
9772a2df321STom Zanussi *
9782a2df321STom Zanussi * Return: 0 on success, errno otherwise
9792a2df321STom Zanussi */
9802a2df321STom Zanussi static int
event_trigger_parse(struct event_command * cmd_ops,struct trace_event_file * file,char * glob,char * cmd,char * param_and_filter)9819ec5a7d1STom Zanussi event_trigger_parse(struct event_command *cmd_ops,
9827f1d2f82SSteven Rostedt (Red Hat) struct trace_event_file *file,
983e1f187d0STom Zanussi char *glob, char *cmd, char *param_and_filter)
9842a2df321STom Zanussi {
9852a2df321STom Zanussi struct event_trigger_data *trigger_data;
986e1f187d0STom Zanussi char *param, *filter;
987e1f187d0STom Zanussi bool remove;
9882a2df321STom Zanussi int ret;
9892a2df321STom Zanussi
990e1f187d0STom Zanussi remove = event_trigger_check_remove(glob);
9912a2df321STom Zanussi
992e1f187d0STom Zanussi ret = event_trigger_separate_filter(param_and_filter, ¶m, &filter, false);
993e1f187d0STom Zanussi if (ret)
994e1f187d0STom Zanussi return ret;
9952a2df321STom Zanussi
9962a2df321STom Zanussi ret = -ENOMEM;
997e1f187d0STom Zanussi trigger_data = event_trigger_alloc(cmd_ops, cmd, param, file);
9982a2df321STom Zanussi if (!trigger_data)
9992a2df321STom Zanussi goto out;
10002a2df321STom Zanussi
1001e1f187d0STom Zanussi if (remove) {
1002b8cc44a4STom Zanussi event_trigger_unregister(cmd_ops, file, glob+1, trigger_data);
10032a2df321STom Zanussi kfree(trigger_data);
10042a2df321STom Zanussi ret = 0;
10052a2df321STom Zanussi goto out;
10062a2df321STom Zanussi }
10072a2df321STom Zanussi
1008e1f187d0STom Zanussi ret = event_trigger_parse_num(param, trigger_data);
10092a2df321STom Zanussi if (ret)
10102a2df321STom Zanussi goto out_free;
10112a2df321STom Zanussi
1012e1f187d0STom Zanussi ret = event_trigger_set_filter(cmd_ops, file, filter, trigger_data);
10132a2df321STom Zanussi if (ret < 0)
10142a2df321STom Zanussi goto out_free;
10152a2df321STom Zanussi
10161863c387SSteven Rostedt (VMware) /* Up the trigger_data count to make sure reg doesn't free it on failure */
101747670541STom Zanussi event_trigger_init(trigger_data);
1018b8cc44a4STom Zanussi
1019b8cc44a4STom Zanussi ret = event_trigger_register(cmd_ops, file, glob, trigger_data);
1020b8cc44a4STom Zanussi if (ret)
1021b8cc44a4STom Zanussi goto out_free;
10221863c387SSteven Rostedt (VMware)
10231863c387SSteven Rostedt (VMware) /* Down the counter of trigger_data or free it if not used anymore */
102447670541STom Zanussi event_trigger_free(trigger_data);
10252a2df321STom Zanussi out:
10262a2df321STom Zanussi return ret;
10272a2df321STom Zanussi
10282a2df321STom Zanussi out_free:
1029e1f187d0STom Zanussi event_trigger_reset_filter(cmd_ops, trigger_data);
10302a2df321STom Zanussi kfree(trigger_data);
10312a2df321STom Zanussi goto out;
10322a2df321STom Zanussi }
10332a2df321STom Zanussi
1034bac5fb97STom Zanussi /**
1035bac5fb97STom Zanussi * set_trigger_filter - Generic event_command @set_filter implementation
1036bac5fb97STom Zanussi * @filter_str: The filter string for the trigger, NULL to remove filter
1037bac5fb97STom Zanussi * @trigger_data: Trigger-specific data
10387f1d2f82SSteven Rostedt (Red Hat) * @file: The trace_event_file associated with the event
1039bac5fb97STom Zanussi *
1040bac5fb97STom Zanussi * Common implementation for event command filter parsing and filter
1041bac5fb97STom Zanussi * instantiation.
1042bac5fb97STom Zanussi *
1043bac5fb97STom Zanussi * Usually used directly as the @set_filter method in event command
1044bac5fb97STom Zanussi * implementations.
1045bac5fb97STom Zanussi *
1046bac5fb97STom Zanussi * Also used to remove a filter (if filter_str = NULL).
1047bac5fb97STom Zanussi *
1048bac5fb97STom Zanussi * Return: 0 on success, errno otherwise
1049bac5fb97STom Zanussi */
set_trigger_filter(char * filter_str,struct event_trigger_data * trigger_data,struct trace_event_file * file)1050ab4bf008STom Zanussi int set_trigger_filter(char *filter_str,
1051bac5fb97STom Zanussi struct event_trigger_data *trigger_data,
10527f1d2f82SSteven Rostedt (Red Hat) struct trace_event_file *file)
1053bac5fb97STom Zanussi {
1054bac5fb97STom Zanussi struct event_trigger_data *data = trigger_data;
1055bac5fb97STom Zanussi struct event_filter *filter = NULL, *tmp;
1056bac5fb97STom Zanussi int ret = -EINVAL;
1057bac5fb97STom Zanussi char *s;
1058bac5fb97STom Zanussi
1059bac5fb97STom Zanussi if (!filter_str) /* clear the current filter */
1060bac5fb97STom Zanussi goto assign;
1061bac5fb97STom Zanussi
1062bac5fb97STom Zanussi s = strsep(&filter_str, " \t");
1063bac5fb97STom Zanussi
1064bac5fb97STom Zanussi if (!strlen(s) || strcmp(s, "if") != 0)
1065bac5fb97STom Zanussi goto out;
1066bac5fb97STom Zanussi
1067bac5fb97STom Zanussi if (!filter_str)
1068bac5fb97STom Zanussi goto out;
1069bac5fb97STom Zanussi
1070bac5fb97STom Zanussi /* The filter is for the 'trigger' event, not the triggered event */
10711e144d73SSteven Rostedt (VMware) ret = create_event_filter(file->tr, file->event_call,
1072a785736dSSteven Rostedt (Google) filter_str, true, &filter);
1073a785736dSSteven Rostedt (Google)
1074a785736dSSteven Rostedt (Google) /* Only enabled set_str for error handling */
1075a785736dSSteven Rostedt (Google) if (filter) {
1076a785736dSSteven Rostedt (Google) kfree(filter->filter_string);
1077a785736dSSteven Rostedt (Google) filter->filter_string = NULL;
1078a785736dSSteven Rostedt (Google) }
1079a785736dSSteven Rostedt (Google)
10803cec638bSSteven Rostedt (VMware) /*
10813cec638bSSteven Rostedt (VMware) * If create_event_filter() fails, filter still needs to be freed.
10823cec638bSSteven Rostedt (VMware) * Which the calling code will do with data->filter.
10833cec638bSSteven Rostedt (VMware) */
1084bac5fb97STom Zanussi assign:
1085d8a30f20SSteven Rostedt (Red Hat) tmp = rcu_access_pointer(data->filter);
1086bac5fb97STom Zanussi
1087bac5fb97STom Zanussi rcu_assign_pointer(data->filter, filter);
1088bac5fb97STom Zanussi
1089bac5fb97STom Zanussi if (tmp) {
1090fb9f5ee9SSteven Rostedt (Google) /*
1091fb9f5ee9SSteven Rostedt (Google) * Make sure the call is done with the filter.
1092fb9f5ee9SSteven Rostedt (Google) * It is possible that a filter could fail at boot up,
1093fb9f5ee9SSteven Rostedt (Google) * and then this path will be called. Avoid the synchronization
1094fb9f5ee9SSteven Rostedt (Google) * in that case.
1095fb9f5ee9SSteven Rostedt (Google) */
1096fb9f5ee9SSteven Rostedt (Google) if (system_state != SYSTEM_BOOTING)
1097e0a568dcSSteven Rostedt (VMware) tracepoint_synchronize_unregister();
1098bac5fb97STom Zanussi free_event_filter(tmp);
1099bac5fb97STom Zanussi }
1100bac5fb97STom Zanussi
1101bac5fb97STom Zanussi kfree(data->filter_str);
1102bac5fb97STom Zanussi data->filter_str = NULL;
1103bac5fb97STom Zanussi
1104bac5fb97STom Zanussi if (filter_str) {
1105bac5fb97STom Zanussi data->filter_str = kstrdup(filter_str, GFP_KERNEL);
1106bac5fb97STom Zanussi if (!data->filter_str) {
1107d8a30f20SSteven Rostedt (Red Hat) free_event_filter(rcu_access_pointer(data->filter));
1108bac5fb97STom Zanussi data->filter = NULL;
1109bac5fb97STom Zanussi ret = -ENOMEM;
1110bac5fb97STom Zanussi }
1111bac5fb97STom Zanussi }
1112bac5fb97STom Zanussi out:
1113bac5fb97STom Zanussi return ret;
1114bac5fb97STom Zanussi }
1115bac5fb97STom Zanussi
1116db1388b4STom Zanussi static LIST_HEAD(named_triggers);
1117db1388b4STom Zanussi
1118db1388b4STom Zanussi /**
1119db1388b4STom Zanussi * find_named_trigger - Find the common named trigger associated with @name
1120db1388b4STom Zanussi * @name: The name of the set of named triggers to find the common data for
1121db1388b4STom Zanussi *
1122db1388b4STom Zanussi * Named triggers are sets of triggers that share a common set of
1123db1388b4STom Zanussi * trigger data. The first named trigger registered with a given name
1124db1388b4STom Zanussi * owns the common trigger data that the others subsequently
1125db1388b4STom Zanussi * registered with the same name will reference. This function
1126db1388b4STom Zanussi * returns the common trigger data associated with that first
1127db1388b4STom Zanussi * registered instance.
1128db1388b4STom Zanussi *
1129db1388b4STom Zanussi * Return: the common trigger data for the given named trigger on
1130db1388b4STom Zanussi * success, NULL otherwise.
1131db1388b4STom Zanussi */
find_named_trigger(const char * name)1132db1388b4STom Zanussi struct event_trigger_data *find_named_trigger(const char *name)
1133db1388b4STom Zanussi {
1134db1388b4STom Zanussi struct event_trigger_data *data;
1135db1388b4STom Zanussi
1136db1388b4STom Zanussi if (!name)
1137db1388b4STom Zanussi return NULL;
1138db1388b4STom Zanussi
1139db1388b4STom Zanussi list_for_each_entry(data, &named_triggers, named_list) {
1140db1388b4STom Zanussi if (data->named_data)
1141db1388b4STom Zanussi continue;
1142db1388b4STom Zanussi if (strcmp(data->name, name) == 0)
1143db1388b4STom Zanussi return data;
1144db1388b4STom Zanussi }
1145db1388b4STom Zanussi
1146db1388b4STom Zanussi return NULL;
1147db1388b4STom Zanussi }
1148db1388b4STom Zanussi
1149db1388b4STom Zanussi /**
1150db1388b4STom Zanussi * is_named_trigger - determine if a given trigger is a named trigger
1151db1388b4STom Zanussi * @test: The trigger data to test
1152db1388b4STom Zanussi *
1153db1388b4STom Zanussi * Return: true if 'test' is a named trigger, false otherwise.
1154db1388b4STom Zanussi */
is_named_trigger(struct event_trigger_data * test)1155db1388b4STom Zanussi bool is_named_trigger(struct event_trigger_data *test)
1156db1388b4STom Zanussi {
1157db1388b4STom Zanussi struct event_trigger_data *data;
1158db1388b4STom Zanussi
1159db1388b4STom Zanussi list_for_each_entry(data, &named_triggers, named_list) {
1160db1388b4STom Zanussi if (test == data)
1161db1388b4STom Zanussi return true;
1162db1388b4STom Zanussi }
1163db1388b4STom Zanussi
1164db1388b4STom Zanussi return false;
1165db1388b4STom Zanussi }
1166db1388b4STom Zanussi
1167db1388b4STom Zanussi /**
1168db1388b4STom Zanussi * save_named_trigger - save the trigger in the named trigger list
1169db1388b4STom Zanussi * @name: The name of the named trigger set
1170db1388b4STom Zanussi * @data: The trigger data to save
1171db1388b4STom Zanussi *
1172db1388b4STom Zanussi * Return: 0 if successful, negative error otherwise.
1173db1388b4STom Zanussi */
save_named_trigger(const char * name,struct event_trigger_data * data)1174db1388b4STom Zanussi int save_named_trigger(const char *name, struct event_trigger_data *data)
1175db1388b4STom Zanussi {
1176db1388b4STom Zanussi data->name = kstrdup(name, GFP_KERNEL);
1177db1388b4STom Zanussi if (!data->name)
1178db1388b4STom Zanussi return -ENOMEM;
1179db1388b4STom Zanussi
1180db1388b4STom Zanussi list_add(&data->named_list, &named_triggers);
1181db1388b4STom Zanussi
1182db1388b4STom Zanussi return 0;
1183db1388b4STom Zanussi }
1184db1388b4STom Zanussi
1185db1388b4STom Zanussi /**
1186db1388b4STom Zanussi * del_named_trigger - delete a trigger from the named trigger list
1187db1388b4STom Zanussi * @data: The trigger data to delete
1188db1388b4STom Zanussi */
del_named_trigger(struct event_trigger_data * data)1189db1388b4STom Zanussi void del_named_trigger(struct event_trigger_data *data)
1190db1388b4STom Zanussi {
1191db1388b4STom Zanussi kfree(data->name);
1192db1388b4STom Zanussi data->name = NULL;
1193db1388b4STom Zanussi
1194db1388b4STom Zanussi list_del(&data->named_list);
1195db1388b4STom Zanussi }
1196db1388b4STom Zanussi
__pause_named_trigger(struct event_trigger_data * data,bool pause)1197db1388b4STom Zanussi static void __pause_named_trigger(struct event_trigger_data *data, bool pause)
1198db1388b4STom Zanussi {
1199db1388b4STom Zanussi struct event_trigger_data *test;
1200db1388b4STom Zanussi
1201db1388b4STom Zanussi list_for_each_entry(test, &named_triggers, named_list) {
1202db1388b4STom Zanussi if (strcmp(test->name, data->name) == 0) {
1203db1388b4STom Zanussi if (pause) {
1204db1388b4STom Zanussi test->paused_tmp = test->paused;
1205db1388b4STom Zanussi test->paused = true;
1206db1388b4STom Zanussi } else {
1207db1388b4STom Zanussi test->paused = test->paused_tmp;
1208db1388b4STom Zanussi }
1209db1388b4STom Zanussi }
1210db1388b4STom Zanussi }
1211db1388b4STom Zanussi }
1212db1388b4STom Zanussi
1213db1388b4STom Zanussi /**
1214db1388b4STom Zanussi * pause_named_trigger - Pause all named triggers with the same name
1215db1388b4STom Zanussi * @data: The trigger data of a named trigger to pause
1216db1388b4STom Zanussi *
1217db1388b4STom Zanussi * Pauses a named trigger along with all other triggers having the
1218db1388b4STom Zanussi * same name. Because named triggers share a common set of data,
1219db1388b4STom Zanussi * pausing only one is meaningless, so pausing one named trigger needs
1220db1388b4STom Zanussi * to pause all triggers with the same name.
1221db1388b4STom Zanussi */
pause_named_trigger(struct event_trigger_data * data)1222db1388b4STom Zanussi void pause_named_trigger(struct event_trigger_data *data)
1223db1388b4STom Zanussi {
1224db1388b4STom Zanussi __pause_named_trigger(data, true);
1225db1388b4STom Zanussi }
1226db1388b4STom Zanussi
1227db1388b4STom Zanussi /**
1228db1388b4STom Zanussi * unpause_named_trigger - Un-pause all named triggers with the same name
1229db1388b4STom Zanussi * @data: The trigger data of a named trigger to unpause
1230db1388b4STom Zanussi *
1231db1388b4STom Zanussi * Un-pauses a named trigger along with all other triggers having the
1232db1388b4STom Zanussi * same name. Because named triggers share a common set of data,
1233db1388b4STom Zanussi * unpausing only one is meaningless, so unpausing one named trigger
1234db1388b4STom Zanussi * needs to unpause all triggers with the same name.
1235db1388b4STom Zanussi */
unpause_named_trigger(struct event_trigger_data * data)1236db1388b4STom Zanussi void unpause_named_trigger(struct event_trigger_data *data)
1237db1388b4STom Zanussi {
1238db1388b4STom Zanussi __pause_named_trigger(data, false);
1239db1388b4STom Zanussi }
1240db1388b4STom Zanussi
1241db1388b4STom Zanussi /**
1242db1388b4STom Zanussi * set_named_trigger_data - Associate common named trigger data
1243099dcc18SQiujun Huang * @data: The trigger data to associate
1244099dcc18SQiujun Huang * @named_data: The common named trigger to be associated
1245db1388b4STom Zanussi *
1246db1388b4STom Zanussi * Named triggers are sets of triggers that share a common set of
1247db1388b4STom Zanussi * trigger data. The first named trigger registered with a given name
1248db1388b4STom Zanussi * owns the common trigger data that the others subsequently
1249db1388b4STom Zanussi * registered with the same name will reference. This function
1250db1388b4STom Zanussi * associates the common trigger data from the first trigger with the
1251db1388b4STom Zanussi * given trigger.
1252db1388b4STom Zanussi */
set_named_trigger_data(struct event_trigger_data * data,struct event_trigger_data * named_data)1253db1388b4STom Zanussi void set_named_trigger_data(struct event_trigger_data *data,
1254db1388b4STom Zanussi struct event_trigger_data *named_data)
1255db1388b4STom Zanussi {
1256db1388b4STom Zanussi data->named_data = named_data;
1257db1388b4STom Zanussi }
1258db1388b4STom Zanussi
1259067fe038STom Zanussi struct event_trigger_data *
get_named_trigger_data(struct event_trigger_data * data)1260067fe038STom Zanussi get_named_trigger_data(struct event_trigger_data *data)
1261067fe038STom Zanussi {
1262067fe038STom Zanussi return data->named_data;
1263067fe038STom Zanussi }
1264067fe038STom Zanussi
12652a2df321STom Zanussi static void
traceon_trigger(struct event_trigger_data * data,struct trace_buffer * buffer,void * rec,struct ring_buffer_event * event)1266b47e3302SSteven Rostedt (VMware) traceon_trigger(struct event_trigger_data *data,
1267b47e3302SSteven Rostedt (VMware) struct trace_buffer *buffer, void *rec,
12681ac4f51cSTom Zanussi struct ring_buffer_event *event)
12692a2df321STom Zanussi {
1270302e9eddSSteven Rostedt (Google) struct trace_event_file *file = data->private_data;
1271302e9eddSSteven Rostedt (Google)
1272302e9eddSSteven Rostedt (Google) if (file) {
1273302e9eddSSteven Rostedt (Google) if (tracer_tracing_is_on(file->tr))
1274302e9eddSSteven Rostedt (Google) return;
1275302e9eddSSteven Rostedt (Google)
1276302e9eddSSteven Rostedt (Google) tracer_tracing_on(file->tr);
1277302e9eddSSteven Rostedt (Google) return;
1278302e9eddSSteven Rostedt (Google) }
1279302e9eddSSteven Rostedt (Google)
12802a2df321STom Zanussi if (tracing_is_on())
12812a2df321STom Zanussi return;
12822a2df321STom Zanussi
12832a2df321STom Zanussi tracing_on();
12842a2df321STom Zanussi }
12852a2df321STom Zanussi
12862a2df321STom Zanussi static void
traceon_count_trigger(struct event_trigger_data * data,struct trace_buffer * buffer,void * rec,struct ring_buffer_event * event)1287b47e3302SSteven Rostedt (VMware) traceon_count_trigger(struct event_trigger_data *data,
1288b47e3302SSteven Rostedt (VMware) struct trace_buffer *buffer, void *rec,
12891ac4f51cSTom Zanussi struct ring_buffer_event *event)
12902a2df321STom Zanussi {
1291302e9eddSSteven Rostedt (Google) struct trace_event_file *file = data->private_data;
1292302e9eddSSteven Rostedt (Google)
1293302e9eddSSteven Rostedt (Google) if (file) {
1294302e9eddSSteven Rostedt (Google) if (tracer_tracing_is_on(file->tr))
1295302e9eddSSteven Rostedt (Google) return;
1296302e9eddSSteven Rostedt (Google) } else {
1297e8dc6371SSteven Rostedt (Red Hat) if (tracing_is_on())
1298e8dc6371SSteven Rostedt (Red Hat) return;
1299302e9eddSSteven Rostedt (Google) }
1300e8dc6371SSteven Rostedt (Red Hat)
13012a2df321STom Zanussi if (!data->count)
13022a2df321STom Zanussi return;
13032a2df321STom Zanussi
13042a2df321STom Zanussi if (data->count != -1)
13052a2df321STom Zanussi (data->count)--;
13062a2df321STom Zanussi
1307302e9eddSSteven Rostedt (Google) if (file)
1308302e9eddSSteven Rostedt (Google) tracer_tracing_on(file->tr);
1309302e9eddSSteven Rostedt (Google) else
1310e8dc6371SSteven Rostedt (Red Hat) tracing_on();
13112a2df321STom Zanussi }
13122a2df321STom Zanussi
13132a2df321STom Zanussi static void
traceoff_trigger(struct event_trigger_data * data,struct trace_buffer * buffer,void * rec,struct ring_buffer_event * event)1314b47e3302SSteven Rostedt (VMware) traceoff_trigger(struct event_trigger_data *data,
1315b47e3302SSteven Rostedt (VMware) struct trace_buffer *buffer, void *rec,
13161ac4f51cSTom Zanussi struct ring_buffer_event *event)
13172a2df321STom Zanussi {
1318302e9eddSSteven Rostedt (Google) struct trace_event_file *file = data->private_data;
1319302e9eddSSteven Rostedt (Google)
1320302e9eddSSteven Rostedt (Google) if (file) {
1321302e9eddSSteven Rostedt (Google) if (!tracer_tracing_is_on(file->tr))
1322302e9eddSSteven Rostedt (Google) return;
1323302e9eddSSteven Rostedt (Google)
1324302e9eddSSteven Rostedt (Google) tracer_tracing_off(file->tr);
1325302e9eddSSteven Rostedt (Google) return;
1326302e9eddSSteven Rostedt (Google) }
1327302e9eddSSteven Rostedt (Google)
13282a2df321STom Zanussi if (!tracing_is_on())
13292a2df321STom Zanussi return;
13302a2df321STom Zanussi
13312a2df321STom Zanussi tracing_off();
13322a2df321STom Zanussi }
13332a2df321STom Zanussi
13342a2df321STom Zanussi static void
traceoff_count_trigger(struct event_trigger_data * data,struct trace_buffer * buffer,void * rec,struct ring_buffer_event * event)1335b47e3302SSteven Rostedt (VMware) traceoff_count_trigger(struct event_trigger_data *data,
1336b47e3302SSteven Rostedt (VMware) struct trace_buffer *buffer, void *rec,
13371ac4f51cSTom Zanussi struct ring_buffer_event *event)
13382a2df321STom Zanussi {
1339302e9eddSSteven Rostedt (Google) struct trace_event_file *file = data->private_data;
1340302e9eddSSteven Rostedt (Google)
1341302e9eddSSteven Rostedt (Google) if (file) {
1342302e9eddSSteven Rostedt (Google) if (!tracer_tracing_is_on(file->tr))
1343302e9eddSSteven Rostedt (Google) return;
1344302e9eddSSteven Rostedt (Google) } else {
1345e8dc6371SSteven Rostedt (Red Hat) if (!tracing_is_on())
1346e8dc6371SSteven Rostedt (Red Hat) return;
1347302e9eddSSteven Rostedt (Google) }
1348e8dc6371SSteven Rostedt (Red Hat)
13492a2df321STom Zanussi if (!data->count)
13502a2df321STom Zanussi return;
13512a2df321STom Zanussi
13522a2df321STom Zanussi if (data->count != -1)
13532a2df321STom Zanussi (data->count)--;
13542a2df321STom Zanussi
1355302e9eddSSteven Rostedt (Google) if (file)
1356302e9eddSSteven Rostedt (Google) tracer_tracing_off(file->tr);
1357302e9eddSSteven Rostedt (Google) else
1358e8dc6371SSteven Rostedt (Red Hat) tracing_off();
13592a2df321STom Zanussi }
13602a2df321STom Zanussi
13612a2df321STom Zanussi static int
traceon_trigger_print(struct seq_file * m,struct event_trigger_data * data)136247670541STom Zanussi traceon_trigger_print(struct seq_file *m, struct event_trigger_data *data)
13632a2df321STom Zanussi {
13642a2df321STom Zanussi return event_trigger_print("traceon", m, (void *)data->count,
13652a2df321STom Zanussi data->filter_str);
13662a2df321STom Zanussi }
13672a2df321STom Zanussi
13682a2df321STom Zanussi static int
traceoff_trigger_print(struct seq_file * m,struct event_trigger_data * data)136947670541STom Zanussi traceoff_trigger_print(struct seq_file *m, struct event_trigger_data *data)
13702a2df321STom Zanussi {
13712a2df321STom Zanussi return event_trigger_print("traceoff", m, (void *)data->count,
13722a2df321STom Zanussi data->filter_str);
13732a2df321STom Zanussi }
13742a2df321STom Zanussi
13752a2df321STom Zanussi static struct event_trigger_ops traceon_trigger_ops = {
1376fb339e53STom Zanussi .trigger = traceon_trigger,
13772a2df321STom Zanussi .print = traceon_trigger_print,
13782a2df321STom Zanussi .init = event_trigger_init,
13792a2df321STom Zanussi .free = event_trigger_free,
13802a2df321STom Zanussi };
13812a2df321STom Zanussi
13822a2df321STom Zanussi static struct event_trigger_ops traceon_count_trigger_ops = {
1383fb339e53STom Zanussi .trigger = traceon_count_trigger,
13842a2df321STom Zanussi .print = traceon_trigger_print,
13852a2df321STom Zanussi .init = event_trigger_init,
13862a2df321STom Zanussi .free = event_trigger_free,
13872a2df321STom Zanussi };
13882a2df321STom Zanussi
13892a2df321STom Zanussi static struct event_trigger_ops traceoff_trigger_ops = {
1390fb339e53STom Zanussi .trigger = traceoff_trigger,
13912a2df321STom Zanussi .print = traceoff_trigger_print,
13922a2df321STom Zanussi .init = event_trigger_init,
13932a2df321STom Zanussi .free = event_trigger_free,
13942a2df321STom Zanussi };
13952a2df321STom Zanussi
13962a2df321STom Zanussi static struct event_trigger_ops traceoff_count_trigger_ops = {
1397fb339e53STom Zanussi .trigger = traceoff_count_trigger,
13982a2df321STom Zanussi .print = traceoff_trigger_print,
13992a2df321STom Zanussi .init = event_trigger_init,
14002a2df321STom Zanussi .free = event_trigger_free,
14012a2df321STom Zanussi };
14022a2df321STom Zanussi
14032a2df321STom Zanussi static struct event_trigger_ops *
onoff_get_trigger_ops(char * cmd,char * param)14042a2df321STom Zanussi onoff_get_trigger_ops(char *cmd, char *param)
14052a2df321STom Zanussi {
14062a2df321STom Zanussi struct event_trigger_ops *ops;
14072a2df321STom Zanussi
14082a2df321STom Zanussi /* we register both traceon and traceoff to this callback */
14092a2df321STom Zanussi if (strcmp(cmd, "traceon") == 0)
14102a2df321STom Zanussi ops = param ? &traceon_count_trigger_ops :
14112a2df321STom Zanussi &traceon_trigger_ops;
14122a2df321STom Zanussi else
14132a2df321STom Zanussi ops = param ? &traceoff_count_trigger_ops :
14142a2df321STom Zanussi &traceoff_trigger_ops;
14152a2df321STom Zanussi
14162a2df321STom Zanussi return ops;
14172a2df321STom Zanussi }
14182a2df321STom Zanussi
14192a2df321STom Zanussi static struct event_command trigger_traceon_cmd = {
14202a2df321STom Zanussi .name = "traceon",
14212a2df321STom Zanussi .trigger_type = ETT_TRACE_ONOFF,
14229ec5a7d1STom Zanussi .parse = event_trigger_parse,
14232a2df321STom Zanussi .reg = register_trigger,
14242a2df321STom Zanussi .unreg = unregister_trigger,
14252a2df321STom Zanussi .get_trigger_ops = onoff_get_trigger_ops,
1426bac5fb97STom Zanussi .set_filter = set_trigger_filter,
14272a2df321STom Zanussi };
14282a2df321STom Zanussi
14292a2df321STom Zanussi static struct event_command trigger_traceoff_cmd = {
14302a2df321STom Zanussi .name = "traceoff",
14312a2df321STom Zanussi .trigger_type = ETT_TRACE_ONOFF,
1432a0d0c621SMasami Hiramatsu .flags = EVENT_CMD_FL_POST_TRIGGER,
14339ec5a7d1STom Zanussi .parse = event_trigger_parse,
14342a2df321STom Zanussi .reg = register_trigger,
14352a2df321STom Zanussi .unreg = unregister_trigger,
14362a2df321STom Zanussi .get_trigger_ops = onoff_get_trigger_ops,
1437bac5fb97STom Zanussi .set_filter = set_trigger_filter,
14382a2df321STom Zanussi };
14392a2df321STom Zanussi
144093e31ffbSTom Zanussi #ifdef CONFIG_TRACER_SNAPSHOT
144193e31ffbSTom Zanussi static void
snapshot_trigger(struct event_trigger_data * data,struct trace_buffer * buffer,void * rec,struct ring_buffer_event * event)1442b47e3302SSteven Rostedt (VMware) snapshot_trigger(struct event_trigger_data *data,
1443b47e3302SSteven Rostedt (VMware) struct trace_buffer *buffer, void *rec,
14441ac4f51cSTom Zanussi struct ring_buffer_event *event)
144593e31ffbSTom Zanussi {
14462824f503SSteven Rostedt (VMware) struct trace_event_file *file = data->private_data;
14472824f503SSteven Rostedt (VMware)
14482824f503SSteven Rostedt (VMware) if (file)
14492824f503SSteven Rostedt (VMware) tracing_snapshot_instance(file->tr);
14502824f503SSteven Rostedt (VMware) else
145193e31ffbSTom Zanussi tracing_snapshot();
145293e31ffbSTom Zanussi }
145393e31ffbSTom Zanussi
145493e31ffbSTom Zanussi static void
snapshot_count_trigger(struct event_trigger_data * data,struct trace_buffer * buffer,void * rec,struct ring_buffer_event * event)1455b47e3302SSteven Rostedt (VMware) snapshot_count_trigger(struct event_trigger_data *data,
1456b47e3302SSteven Rostedt (VMware) struct trace_buffer *buffer, void *rec,
14571ac4f51cSTom Zanussi struct ring_buffer_event *event)
145893e31ffbSTom Zanussi {
145993e31ffbSTom Zanussi if (!data->count)
146093e31ffbSTom Zanussi return;
146193e31ffbSTom Zanussi
146293e31ffbSTom Zanussi if (data->count != -1)
146393e31ffbSTom Zanussi (data->count)--;
146493e31ffbSTom Zanussi
1465b47e3302SSteven Rostedt (VMware) snapshot_trigger(data, buffer, rec, event);
146693e31ffbSTom Zanussi }
146793e31ffbSTom Zanussi
146893e31ffbSTom Zanussi static int
register_snapshot_trigger(char * glob,struct event_trigger_data * data,struct trace_event_file * file)14692378a2d6STom Zanussi register_snapshot_trigger(char *glob,
147093e31ffbSTom Zanussi struct event_trigger_data *data,
14717f1d2f82SSteven Rostedt (Red Hat) struct trace_event_file *file)
147293e31ffbSTom Zanussi {
1473*6022c065SMasami Hiramatsu (Google) int ret = tracing_alloc_snapshot_instance(file->tr);
1474*6022c065SMasami Hiramatsu (Google)
1475*6022c065SMasami Hiramatsu (Google) if (ret < 0)
1476*6022c065SMasami Hiramatsu (Google) return ret;
147793e31ffbSTom Zanussi
14782378a2d6STom Zanussi return register_trigger(glob, data, file);
147993e31ffbSTom Zanussi }
148093e31ffbSTom Zanussi
148193e31ffbSTom Zanussi static int
snapshot_trigger_print(struct seq_file * m,struct event_trigger_data * data)148247670541STom Zanussi snapshot_trigger_print(struct seq_file *m, struct event_trigger_data *data)
148393e31ffbSTom Zanussi {
148493e31ffbSTom Zanussi return event_trigger_print("snapshot", m, (void *)data->count,
148593e31ffbSTom Zanussi data->filter_str);
148693e31ffbSTom Zanussi }
148793e31ffbSTom Zanussi
148893e31ffbSTom Zanussi static struct event_trigger_ops snapshot_trigger_ops = {
1489fb339e53STom Zanussi .trigger = snapshot_trigger,
149093e31ffbSTom Zanussi .print = snapshot_trigger_print,
149193e31ffbSTom Zanussi .init = event_trigger_init,
149293e31ffbSTom Zanussi .free = event_trigger_free,
149393e31ffbSTom Zanussi };
149493e31ffbSTom Zanussi
149593e31ffbSTom Zanussi static struct event_trigger_ops snapshot_count_trigger_ops = {
1496fb339e53STom Zanussi .trigger = snapshot_count_trigger,
149793e31ffbSTom Zanussi .print = snapshot_trigger_print,
149893e31ffbSTom Zanussi .init = event_trigger_init,
149993e31ffbSTom Zanussi .free = event_trigger_free,
150093e31ffbSTom Zanussi };
150193e31ffbSTom Zanussi
150293e31ffbSTom Zanussi static struct event_trigger_ops *
snapshot_get_trigger_ops(char * cmd,char * param)150393e31ffbSTom Zanussi snapshot_get_trigger_ops(char *cmd, char *param)
150493e31ffbSTom Zanussi {
150593e31ffbSTom Zanussi return param ? &snapshot_count_trigger_ops : &snapshot_trigger_ops;
150693e31ffbSTom Zanussi }
150793e31ffbSTom Zanussi
150893e31ffbSTom Zanussi static struct event_command trigger_snapshot_cmd = {
150993e31ffbSTom Zanussi .name = "snapshot",
151093e31ffbSTom Zanussi .trigger_type = ETT_SNAPSHOT,
15119ec5a7d1STom Zanussi .parse = event_trigger_parse,
151293e31ffbSTom Zanussi .reg = register_snapshot_trigger,
151393e31ffbSTom Zanussi .unreg = unregister_trigger,
151493e31ffbSTom Zanussi .get_trigger_ops = snapshot_get_trigger_ops,
1515bac5fb97STom Zanussi .set_filter = set_trigger_filter,
151693e31ffbSTom Zanussi };
151793e31ffbSTom Zanussi
register_trigger_snapshot_cmd(void)151893e31ffbSTom Zanussi static __init int register_trigger_snapshot_cmd(void)
151993e31ffbSTom Zanussi {
152093e31ffbSTom Zanussi int ret;
152193e31ffbSTom Zanussi
152293e31ffbSTom Zanussi ret = register_event_command(&trigger_snapshot_cmd);
152393e31ffbSTom Zanussi WARN_ON(ret < 0);
152493e31ffbSTom Zanussi
152593e31ffbSTom Zanussi return ret;
152693e31ffbSTom Zanussi }
152793e31ffbSTom Zanussi #else
register_trigger_snapshot_cmd(void)152893e31ffbSTom Zanussi static __init int register_trigger_snapshot_cmd(void) { return 0; }
152993e31ffbSTom Zanussi #endif /* CONFIG_TRACER_SNAPSHOT */
153093e31ffbSTom Zanussi
1531f21ecbb3STom Zanussi #ifdef CONFIG_STACKTRACE
15322ee5b92aSSteven Rostedt (VMware) #ifdef CONFIG_UNWINDER_ORC
15332ee5b92aSSteven Rostedt (VMware) /* Skip 2:
1534f21ecbb3STom Zanussi * event_triggers_post_call()
1535a7237765SSteven Rostedt (Red Hat) * trace_event_raw_event_xxx()
1536f21ecbb3STom Zanussi */
15372ee5b92aSSteven Rostedt (VMware) # define STACK_SKIP 2
15382ee5b92aSSteven Rostedt (VMware) #else
15392ee5b92aSSteven Rostedt (VMware) /*
15402ee5b92aSSteven Rostedt (VMware) * Skip 4:
15412ee5b92aSSteven Rostedt (VMware) * stacktrace_trigger()
15422ee5b92aSSteven Rostedt (VMware) * event_triggers_post_call()
15432ee5b92aSSteven Rostedt (VMware) * trace_event_buffer_commit()
15442ee5b92aSSteven Rostedt (VMware) * trace_event_raw_event_xxx()
15452ee5b92aSSteven Rostedt (VMware) */
15462ee5b92aSSteven Rostedt (VMware) #define STACK_SKIP 4
15472ee5b92aSSteven Rostedt (VMware) #endif
1548f21ecbb3STom Zanussi
1549f21ecbb3STom Zanussi static void
stacktrace_trigger(struct event_trigger_data * data,struct trace_buffer * buffer,void * rec,struct ring_buffer_event * event)1550b47e3302SSteven Rostedt (VMware) stacktrace_trigger(struct event_trigger_data *data,
1551b47e3302SSteven Rostedt (VMware) struct trace_buffer *buffer, void *rec,
15521ac4f51cSTom Zanussi struct ring_buffer_event *event)
1553f21ecbb3STom Zanussi {
1554ce33c845SDaniel Bristot de Oliveira struct trace_event_file *file = data->private_data;
1555ce33c845SDaniel Bristot de Oliveira
1556ce33c845SDaniel Bristot de Oliveira if (file)
1557ce33c845SDaniel Bristot de Oliveira __trace_stack(file->tr, tracing_gen_ctx(), STACK_SKIP);
1558ce33c845SDaniel Bristot de Oliveira else
1559f21ecbb3STom Zanussi trace_dump_stack(STACK_SKIP);
1560f21ecbb3STom Zanussi }
1561f21ecbb3STom Zanussi
1562f21ecbb3STom Zanussi static void
stacktrace_count_trigger(struct event_trigger_data * data,struct trace_buffer * buffer,void * rec,struct ring_buffer_event * event)1563b47e3302SSteven Rostedt (VMware) stacktrace_count_trigger(struct event_trigger_data *data,
1564b47e3302SSteven Rostedt (VMware) struct trace_buffer *buffer, void *rec,
15651ac4f51cSTom Zanussi struct ring_buffer_event *event)
1566f21ecbb3STom Zanussi {
1567f21ecbb3STom Zanussi if (!data->count)
1568f21ecbb3STom Zanussi return;
1569f21ecbb3STom Zanussi
1570f21ecbb3STom Zanussi if (data->count != -1)
1571f21ecbb3STom Zanussi (data->count)--;
1572f21ecbb3STom Zanussi
1573b47e3302SSteven Rostedt (VMware) stacktrace_trigger(data, buffer, rec, event);
1574f21ecbb3STom Zanussi }
1575f21ecbb3STom Zanussi
1576f21ecbb3STom Zanussi static int
stacktrace_trigger_print(struct seq_file * m,struct event_trigger_data * data)157747670541STom Zanussi stacktrace_trigger_print(struct seq_file *m, struct event_trigger_data *data)
1578f21ecbb3STom Zanussi {
1579f21ecbb3STom Zanussi return event_trigger_print("stacktrace", m, (void *)data->count,
1580f21ecbb3STom Zanussi data->filter_str);
1581f21ecbb3STom Zanussi }
1582f21ecbb3STom Zanussi
1583f21ecbb3STom Zanussi static struct event_trigger_ops stacktrace_trigger_ops = {
1584fb339e53STom Zanussi .trigger = stacktrace_trigger,
1585f21ecbb3STom Zanussi .print = stacktrace_trigger_print,
1586f21ecbb3STom Zanussi .init = event_trigger_init,
1587f21ecbb3STom Zanussi .free = event_trigger_free,
1588f21ecbb3STom Zanussi };
1589f21ecbb3STom Zanussi
1590f21ecbb3STom Zanussi static struct event_trigger_ops stacktrace_count_trigger_ops = {
1591fb339e53STom Zanussi .trigger = stacktrace_count_trigger,
1592f21ecbb3STom Zanussi .print = stacktrace_trigger_print,
1593f21ecbb3STom Zanussi .init = event_trigger_init,
1594f21ecbb3STom Zanussi .free = event_trigger_free,
1595f21ecbb3STom Zanussi };
1596f21ecbb3STom Zanussi
1597f21ecbb3STom Zanussi static struct event_trigger_ops *
stacktrace_get_trigger_ops(char * cmd,char * param)1598f21ecbb3STom Zanussi stacktrace_get_trigger_ops(char *cmd, char *param)
1599f21ecbb3STom Zanussi {
1600f21ecbb3STom Zanussi return param ? &stacktrace_count_trigger_ops : &stacktrace_trigger_ops;
1601f21ecbb3STom Zanussi }
1602f21ecbb3STom Zanussi
1603f21ecbb3STom Zanussi static struct event_command trigger_stacktrace_cmd = {
1604f21ecbb3STom Zanussi .name = "stacktrace",
1605f21ecbb3STom Zanussi .trigger_type = ETT_STACKTRACE,
1606353206f5SSteven Rostedt (Red Hat) .flags = EVENT_CMD_FL_POST_TRIGGER,
16079ec5a7d1STom Zanussi .parse = event_trigger_parse,
1608f21ecbb3STom Zanussi .reg = register_trigger,
1609f21ecbb3STom Zanussi .unreg = unregister_trigger,
1610f21ecbb3STom Zanussi .get_trigger_ops = stacktrace_get_trigger_ops,
1611bac5fb97STom Zanussi .set_filter = set_trigger_filter,
1612f21ecbb3STom Zanussi };
1613f21ecbb3STom Zanussi
register_trigger_stacktrace_cmd(void)1614f21ecbb3STom Zanussi static __init int register_trigger_stacktrace_cmd(void)
1615f21ecbb3STom Zanussi {
1616f21ecbb3STom Zanussi int ret;
1617f21ecbb3STom Zanussi
1618f21ecbb3STom Zanussi ret = register_event_command(&trigger_stacktrace_cmd);
1619f21ecbb3STom Zanussi WARN_ON(ret < 0);
1620f21ecbb3STom Zanussi
1621f21ecbb3STom Zanussi return ret;
1622f21ecbb3STom Zanussi }
1623f21ecbb3STom Zanussi #else
register_trigger_stacktrace_cmd(void)1624f21ecbb3STom Zanussi static __init int register_trigger_stacktrace_cmd(void) { return 0; }
1625f21ecbb3STom Zanussi #endif /* CONFIG_STACKTRACE */
1626f21ecbb3STom Zanussi
unregister_trigger_traceon_traceoff_cmds(void)16272a2df321STom Zanussi static __init void unregister_trigger_traceon_traceoff_cmds(void)
16282a2df321STom Zanussi {
16292a2df321STom Zanussi unregister_event_command(&trigger_traceon_cmd);
16302a2df321STom Zanussi unregister_event_command(&trigger_traceoff_cmd);
16312a2df321STom Zanussi }
16322a2df321STom Zanussi
16337862ad18STom Zanussi static void
event_enable_trigger(struct event_trigger_data * data,struct trace_buffer * buffer,void * rec,struct ring_buffer_event * event)1634b47e3302SSteven Rostedt (VMware) event_enable_trigger(struct event_trigger_data *data,
1635b47e3302SSteven Rostedt (VMware) struct trace_buffer *buffer, void *rec,
16361ac4f51cSTom Zanussi struct ring_buffer_event *event)
16377862ad18STom Zanussi {
16387862ad18STom Zanussi struct enable_trigger_data *enable_data = data->private_data;
16397862ad18STom Zanussi
16407862ad18STom Zanussi if (enable_data->enable)
16415d6ad960SSteven Rostedt (Red Hat) clear_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &enable_data->file->flags);
16427862ad18STom Zanussi else
16435d6ad960SSteven Rostedt (Red Hat) set_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &enable_data->file->flags);
16447862ad18STom Zanussi }
16457862ad18STom Zanussi
16467862ad18STom Zanussi static void
event_enable_count_trigger(struct event_trigger_data * data,struct trace_buffer * buffer,void * rec,struct ring_buffer_event * event)1647b47e3302SSteven Rostedt (VMware) event_enable_count_trigger(struct event_trigger_data *data,
1648b47e3302SSteven Rostedt (VMware) struct trace_buffer *buffer, void *rec,
16491ac4f51cSTom Zanussi struct ring_buffer_event *event)
16507862ad18STom Zanussi {
16517862ad18STom Zanussi struct enable_trigger_data *enable_data = data->private_data;
16527862ad18STom Zanussi
16537862ad18STom Zanussi if (!data->count)
16547862ad18STom Zanussi return;
16557862ad18STom Zanussi
16567862ad18STom Zanussi /* Skip if the event is in a state we want to switch to */
16575d6ad960SSteven Rostedt (Red Hat) if (enable_data->enable == !(enable_data->file->flags & EVENT_FILE_FL_SOFT_DISABLED))
16587862ad18STom Zanussi return;
16597862ad18STom Zanussi
16607862ad18STom Zanussi if (data->count != -1)
16617862ad18STom Zanussi (data->count)--;
16627862ad18STom Zanussi
1663b47e3302SSteven Rostedt (VMware) event_enable_trigger(data, buffer, rec, event);
16647862ad18STom Zanussi }
16657862ad18STom Zanussi
event_enable_trigger_print(struct seq_file * m,struct event_trigger_data * data)1666d0bad49bSTom Zanussi int event_enable_trigger_print(struct seq_file *m,
16677862ad18STom Zanussi struct event_trigger_data *data)
16687862ad18STom Zanussi {
16697862ad18STom Zanussi struct enable_trigger_data *enable_data = data->private_data;
16707862ad18STom Zanussi
16717862ad18STom Zanussi seq_printf(m, "%s:%s:%s",
1672d0bad49bSTom Zanussi enable_data->hist ?
1673d0bad49bSTom Zanussi (enable_data->enable ? ENABLE_HIST_STR : DISABLE_HIST_STR) :
1674d0bad49bSTom Zanussi (enable_data->enable ? ENABLE_EVENT_STR : DISABLE_EVENT_STR),
16757862ad18STom Zanussi enable_data->file->event_call->class->system,
1676687fcc4aSSteven Rostedt (Red Hat) trace_event_name(enable_data->file->event_call));
16777862ad18STom Zanussi
16787862ad18STom Zanussi if (data->count == -1)
16797862ad18STom Zanussi seq_puts(m, ":unlimited");
16807862ad18STom Zanussi else
16817862ad18STom Zanussi seq_printf(m, ":count=%ld", data->count);
16827862ad18STom Zanussi
16837862ad18STom Zanussi if (data->filter_str)
16847862ad18STom Zanussi seq_printf(m, " if %s\n", data->filter_str);
16857862ad18STom Zanussi else
16861177e436SRasmus Villemoes seq_putc(m, '\n');
16877862ad18STom Zanussi
16887862ad18STom Zanussi return 0;
16897862ad18STom Zanussi }
16907862ad18STom Zanussi
event_enable_trigger_free(struct event_trigger_data * data)169147670541STom Zanussi void event_enable_trigger_free(struct event_trigger_data *data)
16927862ad18STom Zanussi {
16937862ad18STom Zanussi struct enable_trigger_data *enable_data = data->private_data;
16947862ad18STom Zanussi
16957862ad18STom Zanussi if (WARN_ON_ONCE(data->ref <= 0))
16967862ad18STom Zanussi return;
16977862ad18STom Zanussi
16987862ad18STom Zanussi data->ref--;
16997862ad18STom Zanussi if (!data->ref) {
17007862ad18STom Zanussi /* Remove the SOFT_MODE flag */
17017862ad18STom Zanussi trace_event_enable_disable(enable_data->file, 0, 1);
17021d18538eSSteven Rostedt (VMware) trace_event_put_ref(enable_data->file->event_call);
17037862ad18STom Zanussi trigger_data_free(data);
17047862ad18STom Zanussi kfree(enable_data);
17057862ad18STom Zanussi }
17067862ad18STom Zanussi }
17077862ad18STom Zanussi
17087862ad18STom Zanussi static struct event_trigger_ops event_enable_trigger_ops = {
1709fb339e53STom Zanussi .trigger = event_enable_trigger,
17107862ad18STom Zanussi .print = event_enable_trigger_print,
17117862ad18STom Zanussi .init = event_trigger_init,
17127862ad18STom Zanussi .free = event_enable_trigger_free,
17137862ad18STom Zanussi };
17147862ad18STom Zanussi
17157862ad18STom Zanussi static struct event_trigger_ops event_enable_count_trigger_ops = {
1716fb339e53STom Zanussi .trigger = event_enable_count_trigger,
17177862ad18STom Zanussi .print = event_enable_trigger_print,
17187862ad18STom Zanussi .init = event_trigger_init,
17197862ad18STom Zanussi .free = event_enable_trigger_free,
17207862ad18STom Zanussi };
17217862ad18STom Zanussi
17227862ad18STom Zanussi static struct event_trigger_ops event_disable_trigger_ops = {
1723fb339e53STom Zanussi .trigger = event_enable_trigger,
17247862ad18STom Zanussi .print = event_enable_trigger_print,
17257862ad18STom Zanussi .init = event_trigger_init,
17267862ad18STom Zanussi .free = event_enable_trigger_free,
17277862ad18STom Zanussi };
17287862ad18STom Zanussi
17297862ad18STom Zanussi static struct event_trigger_ops event_disable_count_trigger_ops = {
1730fb339e53STom Zanussi .trigger = event_enable_count_trigger,
17317862ad18STom Zanussi .print = event_enable_trigger_print,
17327862ad18STom Zanussi .init = event_trigger_init,
17337862ad18STom Zanussi .free = event_enable_trigger_free,
17347862ad18STom Zanussi };
17357862ad18STom Zanussi
event_enable_trigger_parse(struct event_command * cmd_ops,struct trace_event_file * file,char * glob,char * cmd,char * param_and_filter)17369ec5a7d1STom Zanussi int event_enable_trigger_parse(struct event_command *cmd_ops,
17377f1d2f82SSteven Rostedt (Red Hat) struct trace_event_file *file,
1738e1f187d0STom Zanussi char *glob, char *cmd, char *param_and_filter)
17397862ad18STom Zanussi {
17407f1d2f82SSteven Rostedt (Red Hat) struct trace_event_file *event_enable_file;
17417862ad18STom Zanussi struct enable_trigger_data *enable_data;
17427862ad18STom Zanussi struct event_trigger_data *trigger_data;
17437862ad18STom Zanussi struct trace_array *tr = file->tr;
1744e1f187d0STom Zanussi char *param, *filter;
1745e1f187d0STom Zanussi bool enable, remove;
17467862ad18STom Zanussi const char *system;
17477862ad18STom Zanussi const char *event;
1748d0bad49bSTom Zanussi bool hist = false;
17497862ad18STom Zanussi int ret;
17507862ad18STom Zanussi
1751e1f187d0STom Zanussi remove = event_trigger_check_remove(glob);
1752e1f187d0STom Zanussi
1753e1f187d0STom Zanussi if (event_trigger_empty_param(param_and_filter))
1754e1f187d0STom Zanussi return -EINVAL;
1755e1f187d0STom Zanussi
1756e1f187d0STom Zanussi ret = event_trigger_separate_filter(param_and_filter, ¶m, &filter, true);
1757e1f187d0STom Zanussi if (ret)
1758e1f187d0STom Zanussi return ret;
1759e1f187d0STom Zanussi
1760e1f187d0STom Zanussi system = strsep(¶m, ":");
17617862ad18STom Zanussi if (!param)
17627862ad18STom Zanussi return -EINVAL;
17637862ad18STom Zanussi
1764e1f187d0STom Zanussi event = strsep(¶m, ":");
17657862ad18STom Zanussi
17667862ad18STom Zanussi ret = -EINVAL;
17677862ad18STom Zanussi event_enable_file = find_event_file(tr, system, event);
17687862ad18STom Zanussi if (!event_enable_file)
17697862ad18STom Zanussi goto out;
17707862ad18STom Zanussi
1771d0bad49bSTom Zanussi #ifdef CONFIG_HIST_TRIGGERS
1772d0bad49bSTom Zanussi hist = ((strcmp(cmd, ENABLE_HIST_STR) == 0) ||
1773d0bad49bSTom Zanussi (strcmp(cmd, DISABLE_HIST_STR) == 0));
17747862ad18STom Zanussi
1775d0bad49bSTom Zanussi enable = ((strcmp(cmd, ENABLE_EVENT_STR) == 0) ||
1776d0bad49bSTom Zanussi (strcmp(cmd, ENABLE_HIST_STR) == 0));
1777d0bad49bSTom Zanussi #else
1778d0bad49bSTom Zanussi enable = strcmp(cmd, ENABLE_EVENT_STR) == 0;
1779d0bad49bSTom Zanussi #endif
17807862ad18STom Zanussi ret = -ENOMEM;
17817862ad18STom Zanussi
17827862ad18STom Zanussi enable_data = kzalloc(sizeof(*enable_data), GFP_KERNEL);
1783e1f187d0STom Zanussi if (!enable_data)
17847862ad18STom Zanussi goto out;
17857862ad18STom Zanussi
1786d0bad49bSTom Zanussi enable_data->hist = hist;
17877862ad18STom Zanussi enable_data->enable = enable;
17887862ad18STom Zanussi enable_data->file = event_enable_file;
17897862ad18STom Zanussi
1790e1f187d0STom Zanussi trigger_data = event_trigger_alloc(cmd_ops, cmd, param, enable_data);
1791e1f187d0STom Zanussi if (!trigger_data) {
1792e1f187d0STom Zanussi kfree(enable_data);
1793e1f187d0STom Zanussi goto out;
1794e1f187d0STom Zanussi }
1795e1f187d0STom Zanussi
1796e1f187d0STom Zanussi if (remove) {
1797b8cc44a4STom Zanussi event_trigger_unregister(cmd_ops, file, glob+1, trigger_data);
17987862ad18STom Zanussi kfree(trigger_data);
17997862ad18STom Zanussi kfree(enable_data);
18007862ad18STom Zanussi ret = 0;
18017862ad18STom Zanussi goto out;
18027862ad18STom Zanussi }
18037862ad18STom Zanussi
180415cc7864SSteven Rostedt (VMware) /* Up the trigger_data count to make sure nothing frees it on failure */
180547670541STom Zanussi event_trigger_init(trigger_data);
180615cc7864SSteven Rostedt (VMware)
1807e1f187d0STom Zanussi ret = event_trigger_parse_num(param, trigger_data);
18087862ad18STom Zanussi if (ret)
18097862ad18STom Zanussi goto out_free;
18107862ad18STom Zanussi
1811e1f187d0STom Zanussi ret = event_trigger_set_filter(cmd_ops, file, filter, trigger_data);
18127862ad18STom Zanussi if (ret < 0)
18137862ad18STom Zanussi goto out_free;
18147862ad18STom Zanussi
18157862ad18STom Zanussi /* Don't let event modules unload while probe registered */
18161d18538eSSteven Rostedt (VMware) ret = trace_event_try_get_ref(event_enable_file->event_call);
18177862ad18STom Zanussi if (!ret) {
18187862ad18STom Zanussi ret = -EBUSY;
18197862ad18STom Zanussi goto out_free;
18207862ad18STom Zanussi }
18217862ad18STom Zanussi
18227862ad18STom Zanussi ret = trace_event_enable_disable(event_enable_file, 1, 1);
18237862ad18STom Zanussi if (ret < 0)
18247862ad18STom Zanussi goto out_put;
1825b8cc44a4STom Zanussi
1826b8cc44a4STom Zanussi ret = event_trigger_register(cmd_ops, file, glob, trigger_data);
1827b8cc44a4STom Zanussi if (ret)
18287862ad18STom Zanussi goto out_disable;
1829b8cc44a4STom Zanussi
183047670541STom Zanussi event_trigger_free(trigger_data);
18317862ad18STom Zanussi out:
18327862ad18STom Zanussi return ret;
18337862ad18STom Zanussi out_disable:
18347862ad18STom Zanussi trace_event_enable_disable(event_enable_file, 0, 1);
18357862ad18STom Zanussi out_put:
18361d18538eSSteven Rostedt (VMware) trace_event_put_ref(event_enable_file->event_call);
18377862ad18STom Zanussi out_free:
1838e1f187d0STom Zanussi event_trigger_reset_filter(cmd_ops, trigger_data);
183947670541STom Zanussi event_trigger_free(trigger_data);
18407862ad18STom Zanussi kfree(enable_data);
1841e1f187d0STom Zanussi
18427862ad18STom Zanussi goto out;
18437862ad18STom Zanussi }
18447862ad18STom Zanussi
event_enable_register_trigger(char * glob,struct event_trigger_data * data,struct trace_event_file * file)1845d0bad49bSTom Zanussi int event_enable_register_trigger(char *glob,
18467862ad18STom Zanussi struct event_trigger_data *data,
18477f1d2f82SSteven Rostedt (Red Hat) struct trace_event_file *file)
18487862ad18STom Zanussi {
18497862ad18STom Zanussi struct enable_trigger_data *enable_data = data->private_data;
18507862ad18STom Zanussi struct enable_trigger_data *test_enable_data;
18517862ad18STom Zanussi struct event_trigger_data *test;
18527862ad18STom Zanussi int ret = 0;
18537862ad18STom Zanussi
18543b42a4c8SMasami Hiramatsu lockdep_assert_held(&event_mutex);
18553b42a4c8SMasami Hiramatsu
18563b42a4c8SMasami Hiramatsu list_for_each_entry(test, &file->triggers, list) {
18577862ad18STom Zanussi test_enable_data = test->private_data;
18587862ad18STom Zanussi if (test_enable_data &&
1859d0bad49bSTom Zanussi (test->cmd_ops->trigger_type ==
1860d0bad49bSTom Zanussi data->cmd_ops->trigger_type) &&
18617862ad18STom Zanussi (test_enable_data->file == enable_data->file)) {
18627862ad18STom Zanussi ret = -EEXIST;
18637862ad18STom Zanussi goto out;
18647862ad18STom Zanussi }
18657862ad18STom Zanussi }
18667862ad18STom Zanussi
18677862ad18STom Zanussi if (data->ops->init) {
186847670541STom Zanussi ret = data->ops->init(data);
18697862ad18STom Zanussi if (ret < 0)
18707862ad18STom Zanussi goto out;
18717862ad18STom Zanussi }
18727862ad18STom Zanussi
18737862ad18STom Zanussi list_add_rcu(&data->list, &file->triggers);
18747862ad18STom Zanussi
18754e4a4d75STom Zanussi update_cond_flag(file);
1876b8cc44a4STom Zanussi ret = trace_event_trigger_enable_disable(file, 1);
1877b8cc44a4STom Zanussi if (ret < 0) {
18787862ad18STom Zanussi list_del_rcu(&data->list);
18794e4a4d75STom Zanussi update_cond_flag(file);
18807862ad18STom Zanussi }
18817862ad18STom Zanussi out:
18827862ad18STom Zanussi return ret;
18837862ad18STom Zanussi }
18847862ad18STom Zanussi
event_enable_unregister_trigger(char * glob,struct event_trigger_data * test,struct trace_event_file * file)1885d0bad49bSTom Zanussi void event_enable_unregister_trigger(char *glob,
18867862ad18STom Zanussi struct event_trigger_data *test,
18877f1d2f82SSteven Rostedt (Red Hat) struct trace_event_file *file)
18887862ad18STom Zanussi {
18897862ad18STom Zanussi struct enable_trigger_data *test_enable_data = test->private_data;
189045e333ceSJakob Koschel struct event_trigger_data *data = NULL, *iter;
18917862ad18STom Zanussi struct enable_trigger_data *enable_data;
18927862ad18STom Zanussi
18933b42a4c8SMasami Hiramatsu lockdep_assert_held(&event_mutex);
18943b42a4c8SMasami Hiramatsu
189545e333ceSJakob Koschel list_for_each_entry(iter, &file->triggers, list) {
189645e333ceSJakob Koschel enable_data = iter->private_data;
18977862ad18STom Zanussi if (enable_data &&
189845e333ceSJakob Koschel (iter->cmd_ops->trigger_type ==
1899d0bad49bSTom Zanussi test->cmd_ops->trigger_type) &&
19007862ad18STom Zanussi (enable_data->file == test_enable_data->file)) {
190145e333ceSJakob Koschel data = iter;
19027862ad18STom Zanussi list_del_rcu(&data->list);
19037862ad18STom Zanussi trace_event_trigger_enable_disable(file, 0);
19044e4a4d75STom Zanussi update_cond_flag(file);
19057862ad18STom Zanussi break;
19067862ad18STom Zanussi }
19077862ad18STom Zanussi }
19087862ad18STom Zanussi
190945e333ceSJakob Koschel if (data && data->ops->free)
191047670541STom Zanussi data->ops->free(data);
19117862ad18STom Zanussi }
19127862ad18STom Zanussi
19137862ad18STom Zanussi static struct event_trigger_ops *
event_enable_get_trigger_ops(char * cmd,char * param)19147862ad18STom Zanussi event_enable_get_trigger_ops(char *cmd, char *param)
19157862ad18STom Zanussi {
19167862ad18STom Zanussi struct event_trigger_ops *ops;
19177862ad18STom Zanussi bool enable;
19187862ad18STom Zanussi
1919d0bad49bSTom Zanussi #ifdef CONFIG_HIST_TRIGGERS
1920d0bad49bSTom Zanussi enable = ((strcmp(cmd, ENABLE_EVENT_STR) == 0) ||
1921d0bad49bSTom Zanussi (strcmp(cmd, ENABLE_HIST_STR) == 0));
1922d0bad49bSTom Zanussi #else
19237862ad18STom Zanussi enable = strcmp(cmd, ENABLE_EVENT_STR) == 0;
1924d0bad49bSTom Zanussi #endif
19257862ad18STom Zanussi if (enable)
19267862ad18STom Zanussi ops = param ? &event_enable_count_trigger_ops :
19277862ad18STom Zanussi &event_enable_trigger_ops;
19287862ad18STom Zanussi else
19297862ad18STom Zanussi ops = param ? &event_disable_count_trigger_ops :
19307862ad18STom Zanussi &event_disable_trigger_ops;
19317862ad18STom Zanussi
19327862ad18STom Zanussi return ops;
19337862ad18STom Zanussi }
19347862ad18STom Zanussi
19357862ad18STom Zanussi static struct event_command trigger_enable_cmd = {
19367862ad18STom Zanussi .name = ENABLE_EVENT_STR,
19377862ad18STom Zanussi .trigger_type = ETT_EVENT_ENABLE,
19389ec5a7d1STom Zanussi .parse = event_enable_trigger_parse,
19397862ad18STom Zanussi .reg = event_enable_register_trigger,
19407862ad18STom Zanussi .unreg = event_enable_unregister_trigger,
19417862ad18STom Zanussi .get_trigger_ops = event_enable_get_trigger_ops,
1942bac5fb97STom Zanussi .set_filter = set_trigger_filter,
19437862ad18STom Zanussi };
19447862ad18STom Zanussi
19457862ad18STom Zanussi static struct event_command trigger_disable_cmd = {
19467862ad18STom Zanussi .name = DISABLE_EVENT_STR,
19477862ad18STom Zanussi .trigger_type = ETT_EVENT_ENABLE,
19489ec5a7d1STom Zanussi .parse = event_enable_trigger_parse,
19497862ad18STom Zanussi .reg = event_enable_register_trigger,
19507862ad18STom Zanussi .unreg = event_enable_unregister_trigger,
19517862ad18STom Zanussi .get_trigger_ops = event_enable_get_trigger_ops,
1952bac5fb97STom Zanussi .set_filter = set_trigger_filter,
19537862ad18STom Zanussi };
19547862ad18STom Zanussi
unregister_trigger_enable_disable_cmds(void)19557862ad18STom Zanussi static __init void unregister_trigger_enable_disable_cmds(void)
19567862ad18STom Zanussi {
19577862ad18STom Zanussi unregister_event_command(&trigger_enable_cmd);
19587862ad18STom Zanussi unregister_event_command(&trigger_disable_cmd);
19597862ad18STom Zanussi }
19607862ad18STom Zanussi
register_trigger_enable_disable_cmds(void)19617862ad18STom Zanussi static __init int register_trigger_enable_disable_cmds(void)
19627862ad18STom Zanussi {
19637862ad18STom Zanussi int ret;
19647862ad18STom Zanussi
19657862ad18STom Zanussi ret = register_event_command(&trigger_enable_cmd);
19667862ad18STom Zanussi if (WARN_ON(ret < 0))
19677862ad18STom Zanussi return ret;
19687862ad18STom Zanussi ret = register_event_command(&trigger_disable_cmd);
19697862ad18STom Zanussi if (WARN_ON(ret < 0))
19707862ad18STom Zanussi unregister_trigger_enable_disable_cmds();
19717862ad18STom Zanussi
19727862ad18STom Zanussi return ret;
19737862ad18STom Zanussi }
19747862ad18STom Zanussi
register_trigger_traceon_traceoff_cmds(void)19752a2df321STom Zanussi static __init int register_trigger_traceon_traceoff_cmds(void)
19762a2df321STom Zanussi {
19772a2df321STom Zanussi int ret;
19782a2df321STom Zanussi
19792a2df321STom Zanussi ret = register_event_command(&trigger_traceon_cmd);
19802a2df321STom Zanussi if (WARN_ON(ret < 0))
19812a2df321STom Zanussi return ret;
19822a2df321STom Zanussi ret = register_event_command(&trigger_traceoff_cmd);
19832a2df321STom Zanussi if (WARN_ON(ret < 0))
19842a2df321STom Zanussi unregister_trigger_traceon_traceoff_cmds();
19852a2df321STom Zanussi
19862a2df321STom Zanussi return ret;
19872a2df321STom Zanussi }
19882a2df321STom Zanussi
register_trigger_cmds(void)198985f2b082STom Zanussi __init int register_trigger_cmds(void)
199085f2b082STom Zanussi {
19912a2df321STom Zanussi register_trigger_traceon_traceoff_cmds();
199293e31ffbSTom Zanussi register_trigger_snapshot_cmd();
1993f21ecbb3STom Zanussi register_trigger_stacktrace_cmd();
19947862ad18STom Zanussi register_trigger_enable_disable_cmds();
1995d0bad49bSTom Zanussi register_trigger_hist_enable_disable_cmds();
19967ef224d1STom Zanussi register_trigger_hist_cmd();
19972a2df321STom Zanussi
199885f2b082STom Zanussi return 0;
199985f2b082STom Zanussi }
2000