Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 1 | /* |
| 2 | * trace_events_trigger - trace event triggers |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; either version 2 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 | * |
| 18 | * Copyright (C) 2013 Tom Zanussi <tom.zanussi@linux.intel.com> |
| 19 | */ |
| 20 | |
| 21 | #include <linux/module.h> |
| 22 | #include <linux/ctype.h> |
| 23 | #include <linux/mutex.h> |
| 24 | #include <linux/slab.h> |
| 25 | |
| 26 | #include "trace.h" |
| 27 | |
| 28 | static LIST_HEAD(trigger_commands); |
| 29 | static DEFINE_MUTEX(trigger_cmd_mutex); |
| 30 | |
Tom Zanussi | ab4bf00 | 2015-12-10 12:50:44 -0600 | [diff] [blame^] | 31 | void trigger_data_free(struct event_trigger_data *data) |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 32 | { |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 33 | if (data->cmd_ops->set_filter) |
| 34 | data->cmd_ops->set_filter(NULL, data, NULL); |
| 35 | |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 36 | synchronize_sched(); /* make sure current triggers exit before free */ |
| 37 | kfree(data); |
| 38 | } |
| 39 | |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 40 | /** |
| 41 | * event_triggers_call - Call triggers associated with a trace event |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 42 | * @file: The trace_event_file associated with the event |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 43 | * @rec: The trace entry for the event, NULL for unconditional invocation |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 44 | * |
| 45 | * For each trigger associated with an event, invoke the trigger |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 46 | * function registered with the associated trigger command. If rec is |
| 47 | * non-NULL, it means that the trigger requires further processing and |
| 48 | * shouldn't be unconditionally invoked. If rec is non-NULL and the |
| 49 | * trigger has a filter associated with it, rec will checked against |
| 50 | * the filter and if the record matches the trigger will be invoked. |
| 51 | * If the trigger is a 'post_trigger', meaning it shouldn't be invoked |
| 52 | * in any case until the current event is written, the trigger |
| 53 | * function isn't invoked but the bit associated with the deferred |
| 54 | * trigger is set in the return value. |
| 55 | * |
| 56 | * Returns an enum event_trigger_type value containing a set bit for |
| 57 | * any trigger that should be deferred, ETT_NONE if nothing to defer. |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 58 | * |
| 59 | * Called from tracepoint handlers (with rcu_read_lock_sched() held). |
| 60 | * |
| 61 | * Return: an enum event_trigger_type value containing a set bit for |
| 62 | * any trigger that should be deferred, ETT_NONE if nothing to defer. |
| 63 | */ |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 64 | enum event_trigger_type |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 65 | event_triggers_call(struct trace_event_file *file, void *rec) |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 66 | { |
| 67 | struct event_trigger_data *data; |
| 68 | enum event_trigger_type tt = ETT_NONE; |
Steven Rostedt (Red Hat) | d8a30f2 | 2013-12-21 21:55:17 -0500 | [diff] [blame] | 69 | struct event_filter *filter; |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 70 | |
| 71 | if (list_empty(&file->triggers)) |
| 72 | return tt; |
| 73 | |
| 74 | list_for_each_entry_rcu(data, &file->triggers, list) { |
| 75 | if (!rec) { |
| 76 | data->ops->func(data); |
| 77 | continue; |
| 78 | } |
Steven Rostedt (Red Hat) | 561a4fe | 2014-05-02 13:30:04 -0400 | [diff] [blame] | 79 | filter = rcu_dereference_sched(data->filter); |
Steven Rostedt (Red Hat) | d8a30f2 | 2013-12-21 21:55:17 -0500 | [diff] [blame] | 80 | if (filter && !filter_match_preds(filter, rec)) |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 81 | continue; |
| 82 | if (data->cmd_ops->post_trigger) { |
| 83 | tt |= data->cmd_ops->trigger_type; |
| 84 | continue; |
| 85 | } |
| 86 | data->ops->func(data); |
| 87 | } |
| 88 | return tt; |
| 89 | } |
| 90 | EXPORT_SYMBOL_GPL(event_triggers_call); |
| 91 | |
| 92 | /** |
| 93 | * event_triggers_post_call - Call 'post_triggers' for a trace event |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 94 | * @file: The trace_event_file associated with the event |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 95 | * @tt: enum event_trigger_type containing a set bit for each trigger to invoke |
| 96 | * |
| 97 | * For each trigger associated with an event, invoke the trigger |
| 98 | * function registered with the associated trigger command, if the |
| 99 | * corresponding bit is set in the tt enum passed into this function. |
| 100 | * See @event_triggers_call for details on how those bits are set. |
| 101 | * |
| 102 | * Called from tracepoint handlers (with rcu_read_lock_sched() held). |
| 103 | */ |
| 104 | void |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 105 | event_triggers_post_call(struct trace_event_file *file, |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 106 | enum event_trigger_type tt) |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 107 | { |
| 108 | struct event_trigger_data *data; |
| 109 | |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 110 | list_for_each_entry_rcu(data, &file->triggers, list) { |
| 111 | if (data->cmd_ops->trigger_type & tt) |
| 112 | data->ops->func(data); |
| 113 | } |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 114 | } |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 115 | EXPORT_SYMBOL_GPL(event_triggers_post_call); |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 116 | |
Steven Rostedt (Red Hat) | dd97b95 | 2014-01-07 10:31:04 -0500 | [diff] [blame] | 117 | #define SHOW_AVAILABLE_TRIGGERS (void *)(1UL) |
| 118 | |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 119 | static void *trigger_next(struct seq_file *m, void *t, loff_t *pos) |
| 120 | { |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 121 | struct trace_event_file *event_file = event_file_data(m->private); |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 122 | |
Steven Rostedt (Red Hat) | dd97b95 | 2014-01-07 10:31:04 -0500 | [diff] [blame] | 123 | if (t == SHOW_AVAILABLE_TRIGGERS) |
| 124 | return NULL; |
| 125 | |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 126 | return seq_list_next(t, &event_file->triggers, pos); |
| 127 | } |
| 128 | |
| 129 | static void *trigger_start(struct seq_file *m, loff_t *pos) |
| 130 | { |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 131 | struct trace_event_file *event_file; |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 132 | |
| 133 | /* ->stop() is called even if ->start() fails */ |
| 134 | mutex_lock(&event_mutex); |
| 135 | event_file = event_file_data(m->private); |
| 136 | if (unlikely(!event_file)) |
| 137 | return ERR_PTR(-ENODEV); |
| 138 | |
Steven Rostedt (Red Hat) | dd97b95 | 2014-01-07 10:31:04 -0500 | [diff] [blame] | 139 | if (list_empty(&event_file->triggers)) |
| 140 | return *pos == 0 ? SHOW_AVAILABLE_TRIGGERS : NULL; |
| 141 | |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 142 | return seq_list_start(&event_file->triggers, *pos); |
| 143 | } |
| 144 | |
| 145 | static void trigger_stop(struct seq_file *m, void *t) |
| 146 | { |
| 147 | mutex_unlock(&event_mutex); |
| 148 | } |
| 149 | |
| 150 | static int trigger_show(struct seq_file *m, void *v) |
| 151 | { |
| 152 | struct event_trigger_data *data; |
Steven Rostedt (Red Hat) | dd97b95 | 2014-01-07 10:31:04 -0500 | [diff] [blame] | 153 | struct event_command *p; |
| 154 | |
| 155 | if (v == SHOW_AVAILABLE_TRIGGERS) { |
| 156 | seq_puts(m, "# Available triggers:\n"); |
| 157 | seq_putc(m, '#'); |
| 158 | mutex_lock(&trigger_cmd_mutex); |
| 159 | list_for_each_entry_reverse(p, &trigger_commands, list) |
| 160 | seq_printf(m, " %s", p->name); |
| 161 | seq_putc(m, '\n'); |
| 162 | mutex_unlock(&trigger_cmd_mutex); |
| 163 | return 0; |
| 164 | } |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 165 | |
| 166 | data = list_entry(v, struct event_trigger_data, list); |
| 167 | data->ops->print(m, data->ops, data); |
| 168 | |
| 169 | return 0; |
| 170 | } |
| 171 | |
| 172 | static const struct seq_operations event_triggers_seq_ops = { |
| 173 | .start = trigger_start, |
| 174 | .next = trigger_next, |
| 175 | .stop = trigger_stop, |
| 176 | .show = trigger_show, |
| 177 | }; |
| 178 | |
| 179 | static int event_trigger_regex_open(struct inode *inode, struct file *file) |
| 180 | { |
| 181 | int ret = 0; |
| 182 | |
| 183 | mutex_lock(&event_mutex); |
| 184 | |
| 185 | if (unlikely(!event_file_data(file))) { |
| 186 | mutex_unlock(&event_mutex); |
| 187 | return -ENODEV; |
| 188 | } |
| 189 | |
| 190 | if (file->f_mode & FMODE_READ) { |
| 191 | ret = seq_open(file, &event_triggers_seq_ops); |
| 192 | if (!ret) { |
| 193 | struct seq_file *m = file->private_data; |
| 194 | m->private = file; |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | mutex_unlock(&event_mutex); |
| 199 | |
| 200 | return ret; |
| 201 | } |
| 202 | |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 203 | static int trigger_process_regex(struct trace_event_file *file, char *buff) |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 204 | { |
| 205 | char *command, *next = buff; |
| 206 | struct event_command *p; |
| 207 | int ret = -EINVAL; |
| 208 | |
| 209 | command = strsep(&next, ": \t"); |
| 210 | command = (command[0] != '!') ? command : command + 1; |
| 211 | |
| 212 | mutex_lock(&trigger_cmd_mutex); |
| 213 | list_for_each_entry(p, &trigger_commands, list) { |
| 214 | if (strcmp(p->name, command) == 0) { |
| 215 | ret = p->func(p, file, buff, command, next); |
| 216 | goto out_unlock; |
| 217 | } |
| 218 | } |
| 219 | out_unlock: |
| 220 | mutex_unlock(&trigger_cmd_mutex); |
| 221 | |
| 222 | return ret; |
| 223 | } |
| 224 | |
| 225 | static ssize_t event_trigger_regex_write(struct file *file, |
| 226 | const char __user *ubuf, |
| 227 | size_t cnt, loff_t *ppos) |
| 228 | { |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 229 | struct trace_event_file *event_file; |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 230 | ssize_t ret; |
| 231 | char *buf; |
| 232 | |
| 233 | if (!cnt) |
| 234 | return 0; |
| 235 | |
| 236 | if (cnt >= PAGE_SIZE) |
| 237 | return -EINVAL; |
| 238 | |
Al Viro | 70f6cbb | 2015-12-24 00:13:10 -0500 | [diff] [blame] | 239 | buf = memdup_user_nul(ubuf, cnt); |
| 240 | if (IS_ERR(buf)) |
| 241 | return PTR_ERR(buf); |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 242 | |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 243 | strim(buf); |
| 244 | |
| 245 | mutex_lock(&event_mutex); |
| 246 | event_file = event_file_data(file); |
| 247 | if (unlikely(!event_file)) { |
| 248 | mutex_unlock(&event_mutex); |
Al Viro | 70f6cbb | 2015-12-24 00:13:10 -0500 | [diff] [blame] | 249 | kfree(buf); |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 250 | return -ENODEV; |
| 251 | } |
| 252 | ret = trigger_process_regex(event_file, buf); |
| 253 | mutex_unlock(&event_mutex); |
| 254 | |
Al Viro | 70f6cbb | 2015-12-24 00:13:10 -0500 | [diff] [blame] | 255 | kfree(buf); |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 256 | if (ret < 0) |
| 257 | goto out; |
| 258 | |
| 259 | *ppos += cnt; |
| 260 | ret = cnt; |
| 261 | out: |
| 262 | return ret; |
| 263 | } |
| 264 | |
| 265 | static int event_trigger_regex_release(struct inode *inode, struct file *file) |
| 266 | { |
| 267 | mutex_lock(&event_mutex); |
| 268 | |
| 269 | if (file->f_mode & FMODE_READ) |
| 270 | seq_release(inode, file); |
| 271 | |
| 272 | mutex_unlock(&event_mutex); |
| 273 | |
| 274 | return 0; |
| 275 | } |
| 276 | |
| 277 | static ssize_t |
| 278 | event_trigger_write(struct file *filp, const char __user *ubuf, |
| 279 | size_t cnt, loff_t *ppos) |
| 280 | { |
| 281 | return event_trigger_regex_write(filp, ubuf, cnt, ppos); |
| 282 | } |
| 283 | |
| 284 | static int |
| 285 | event_trigger_open(struct inode *inode, struct file *filp) |
| 286 | { |
| 287 | return event_trigger_regex_open(inode, filp); |
| 288 | } |
| 289 | |
| 290 | static int |
| 291 | event_trigger_release(struct inode *inode, struct file *file) |
| 292 | { |
| 293 | return event_trigger_regex_release(inode, file); |
| 294 | } |
| 295 | |
| 296 | const struct file_operations event_trigger_fops = { |
| 297 | .open = event_trigger_open, |
| 298 | .read = seq_read, |
| 299 | .write = event_trigger_write, |
Steven Rostedt (Red Hat) | 098c879 | 2013-12-21 17:39:40 -0500 | [diff] [blame] | 300 | .llseek = tracing_lseek, |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 301 | .release = event_trigger_release, |
| 302 | }; |
| 303 | |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 304 | /* |
| 305 | * Currently we only register event commands from __init, so mark this |
| 306 | * __init too. |
| 307 | */ |
Tom Zanussi | ab4bf00 | 2015-12-10 12:50:44 -0600 | [diff] [blame^] | 308 | __init int register_event_command(struct event_command *cmd) |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 309 | { |
| 310 | struct event_command *p; |
| 311 | int ret = 0; |
| 312 | |
| 313 | mutex_lock(&trigger_cmd_mutex); |
| 314 | list_for_each_entry(p, &trigger_commands, list) { |
| 315 | if (strcmp(cmd->name, p->name) == 0) { |
| 316 | ret = -EBUSY; |
| 317 | goto out_unlock; |
| 318 | } |
| 319 | } |
| 320 | list_add(&cmd->list, &trigger_commands); |
| 321 | out_unlock: |
| 322 | mutex_unlock(&trigger_cmd_mutex); |
| 323 | |
| 324 | return ret; |
| 325 | } |
| 326 | |
| 327 | /* |
| 328 | * Currently we only unregister event commands from __init, so mark |
| 329 | * this __init too. |
| 330 | */ |
| 331 | static __init int unregister_event_command(struct event_command *cmd) |
| 332 | { |
| 333 | struct event_command *p, *n; |
| 334 | int ret = -ENODEV; |
| 335 | |
| 336 | mutex_lock(&trigger_cmd_mutex); |
| 337 | list_for_each_entry_safe(p, n, &trigger_commands, list) { |
| 338 | if (strcmp(cmd->name, p->name) == 0) { |
| 339 | ret = 0; |
| 340 | list_del_init(&p->list); |
| 341 | goto out_unlock; |
| 342 | } |
| 343 | } |
| 344 | out_unlock: |
| 345 | mutex_unlock(&trigger_cmd_mutex); |
| 346 | |
| 347 | return ret; |
| 348 | } |
| 349 | |
| 350 | /** |
| 351 | * event_trigger_print - Generic event_trigger_ops @print implementation |
| 352 | * @name: The name of the event trigger |
| 353 | * @m: The seq_file being printed to |
| 354 | * @data: Trigger-specific data |
| 355 | * @filter_str: filter_str to print, if present |
| 356 | * |
| 357 | * Common implementation for event triggers to print themselves. |
| 358 | * |
| 359 | * Usually wrapped by a function that simply sets the @name of the |
| 360 | * trigger command and then invokes this. |
| 361 | * |
| 362 | * Return: 0 on success, errno otherwise |
| 363 | */ |
| 364 | static int |
| 365 | event_trigger_print(const char *name, struct seq_file *m, |
| 366 | void *data, char *filter_str) |
| 367 | { |
| 368 | long count = (long)data; |
| 369 | |
Rasmus Villemoes | fa6f0cc | 2014-11-08 21:42:10 +0100 | [diff] [blame] | 370 | seq_puts(m, name); |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 371 | |
| 372 | if (count == -1) |
| 373 | seq_puts(m, ":unlimited"); |
| 374 | else |
| 375 | seq_printf(m, ":count=%ld", count); |
| 376 | |
| 377 | if (filter_str) |
| 378 | seq_printf(m, " if %s\n", filter_str); |
| 379 | else |
Rasmus Villemoes | 1177e43 | 2014-11-08 21:42:12 +0100 | [diff] [blame] | 380 | seq_putc(m, '\n'); |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 381 | |
| 382 | return 0; |
| 383 | } |
| 384 | |
| 385 | /** |
| 386 | * event_trigger_init - Generic event_trigger_ops @init implementation |
| 387 | * @ops: The trigger ops associated with the trigger |
| 388 | * @data: Trigger-specific data |
| 389 | * |
| 390 | * Common implementation of event trigger initialization. |
| 391 | * |
| 392 | * Usually used directly as the @init method in event trigger |
| 393 | * implementations. |
| 394 | * |
| 395 | * Return: 0 on success, errno otherwise |
| 396 | */ |
Tom Zanussi | ab4bf00 | 2015-12-10 12:50:44 -0600 | [diff] [blame^] | 397 | int event_trigger_init(struct event_trigger_ops *ops, |
| 398 | struct event_trigger_data *data) |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 399 | { |
| 400 | data->ref++; |
| 401 | return 0; |
| 402 | } |
| 403 | |
| 404 | /** |
| 405 | * event_trigger_free - Generic event_trigger_ops @free implementation |
| 406 | * @ops: The trigger ops associated with the trigger |
| 407 | * @data: Trigger-specific data |
| 408 | * |
| 409 | * Common implementation of event trigger de-initialization. |
| 410 | * |
| 411 | * Usually used directly as the @free method in event trigger |
| 412 | * implementations. |
| 413 | */ |
| 414 | static void |
| 415 | event_trigger_free(struct event_trigger_ops *ops, |
| 416 | struct event_trigger_data *data) |
| 417 | { |
| 418 | if (WARN_ON_ONCE(data->ref <= 0)) |
| 419 | return; |
| 420 | |
| 421 | data->ref--; |
| 422 | if (!data->ref) |
| 423 | trigger_data_free(data); |
| 424 | } |
| 425 | |
Tom Zanussi | ab4bf00 | 2015-12-10 12:50:44 -0600 | [diff] [blame^] | 426 | int trace_event_trigger_enable_disable(struct trace_event_file *file, |
| 427 | int trigger_enable) |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 428 | { |
| 429 | int ret = 0; |
| 430 | |
| 431 | if (trigger_enable) { |
| 432 | if (atomic_inc_return(&file->tm_ref) > 1) |
| 433 | return ret; |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 434 | set_bit(EVENT_FILE_FL_TRIGGER_MODE_BIT, &file->flags); |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 435 | ret = trace_event_enable_disable(file, 1, 1); |
| 436 | } else { |
| 437 | if (atomic_dec_return(&file->tm_ref) > 0) |
| 438 | return ret; |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 439 | clear_bit(EVENT_FILE_FL_TRIGGER_MODE_BIT, &file->flags); |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 440 | ret = trace_event_enable_disable(file, 0, 1); |
| 441 | } |
| 442 | |
| 443 | return ret; |
| 444 | } |
| 445 | |
| 446 | /** |
| 447 | * clear_event_triggers - Clear all triggers associated with a trace array |
| 448 | * @tr: The trace array to clear |
| 449 | * |
| 450 | * For each trigger, the triggering event has its tm_ref decremented |
| 451 | * via trace_event_trigger_enable_disable(), and any associated event |
| 452 | * (in the case of enable/disable_event triggers) will have its sm_ref |
| 453 | * decremented via free()->trace_event_enable_disable(). That |
| 454 | * combination effectively reverses the soft-mode/trigger state added |
| 455 | * by trigger registration. |
| 456 | * |
| 457 | * Must be called with event_mutex held. |
| 458 | */ |
| 459 | void |
| 460 | clear_event_triggers(struct trace_array *tr) |
| 461 | { |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 462 | struct trace_event_file *file; |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 463 | |
| 464 | list_for_each_entry(file, &tr->events, list) { |
| 465 | struct event_trigger_data *data; |
| 466 | list_for_each_entry_rcu(data, &file->triggers, list) { |
| 467 | trace_event_trigger_enable_disable(file, 0); |
| 468 | if (data->ops->free) |
| 469 | data->ops->free(data->ops, data); |
| 470 | } |
| 471 | } |
| 472 | } |
| 473 | |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 474 | /** |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 475 | * update_cond_flag - Set or reset the TRIGGER_COND bit |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 476 | * @file: The trace_event_file associated with the event |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 477 | * |
| 478 | * If an event has triggers and any of those triggers has a filter or |
| 479 | * a post_trigger, trigger invocation needs to be deferred until after |
| 480 | * the current event has logged its data, and the event should have |
| 481 | * its TRIGGER_COND bit set, otherwise the TRIGGER_COND bit should be |
| 482 | * cleared. |
| 483 | */ |
Tom Zanussi | ab4bf00 | 2015-12-10 12:50:44 -0600 | [diff] [blame^] | 484 | void update_cond_flag(struct trace_event_file *file) |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 485 | { |
| 486 | struct event_trigger_data *data; |
| 487 | bool set_cond = false; |
| 488 | |
| 489 | list_for_each_entry_rcu(data, &file->triggers, list) { |
| 490 | if (data->filter || data->cmd_ops->post_trigger) { |
| 491 | set_cond = true; |
| 492 | break; |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | if (set_cond) |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 497 | set_bit(EVENT_FILE_FL_TRIGGER_COND_BIT, &file->flags); |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 498 | else |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 499 | clear_bit(EVENT_FILE_FL_TRIGGER_COND_BIT, &file->flags); |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | /** |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 503 | * register_trigger - Generic event_command @reg implementation |
| 504 | * @glob: The raw string used to register the trigger |
| 505 | * @ops: The trigger ops associated with the trigger |
| 506 | * @data: Trigger-specific data to associate with the trigger |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 507 | * @file: The trace_event_file associated with the event |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 508 | * |
| 509 | * Common implementation for event trigger registration. |
| 510 | * |
| 511 | * Usually used directly as the @reg method in event command |
| 512 | * implementations. |
| 513 | * |
| 514 | * Return: 0 on success, errno otherwise |
| 515 | */ |
| 516 | static int register_trigger(char *glob, struct event_trigger_ops *ops, |
| 517 | struct event_trigger_data *data, |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 518 | struct trace_event_file *file) |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 519 | { |
| 520 | struct event_trigger_data *test; |
| 521 | int ret = 0; |
| 522 | |
| 523 | list_for_each_entry_rcu(test, &file->triggers, list) { |
| 524 | if (test->cmd_ops->trigger_type == data->cmd_ops->trigger_type) { |
| 525 | ret = -EEXIST; |
| 526 | goto out; |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | if (data->ops->init) { |
| 531 | ret = data->ops->init(data->ops, data); |
| 532 | if (ret < 0) |
| 533 | goto out; |
| 534 | } |
| 535 | |
| 536 | list_add_rcu(&data->list, &file->triggers); |
| 537 | ret++; |
| 538 | |
Tom Zanussi | 4e4a4d7 | 2015-11-23 13:51:16 -0600 | [diff] [blame] | 539 | update_cond_flag(file); |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 540 | if (trace_event_trigger_enable_disable(file, 1) < 0) { |
| 541 | list_del_rcu(&data->list); |
Tom Zanussi | 4e4a4d7 | 2015-11-23 13:51:16 -0600 | [diff] [blame] | 542 | update_cond_flag(file); |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 543 | ret--; |
| 544 | } |
| 545 | out: |
| 546 | return ret; |
| 547 | } |
| 548 | |
| 549 | /** |
| 550 | * unregister_trigger - Generic event_command @unreg implementation |
| 551 | * @glob: The raw string used to register the trigger |
| 552 | * @ops: The trigger ops associated with the trigger |
| 553 | * @test: Trigger-specific data used to find the trigger to remove |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 554 | * @file: The trace_event_file associated with the event |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 555 | * |
| 556 | * Common implementation for event trigger unregistration. |
| 557 | * |
| 558 | * Usually used directly as the @unreg method in event command |
| 559 | * implementations. |
| 560 | */ |
Tom Zanussi | ab4bf00 | 2015-12-10 12:50:44 -0600 | [diff] [blame^] | 561 | void unregister_trigger(char *glob, struct event_trigger_ops *ops, |
| 562 | struct event_trigger_data *test, |
| 563 | struct trace_event_file *file) |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 564 | { |
| 565 | struct event_trigger_data *data; |
| 566 | bool unregistered = false; |
| 567 | |
| 568 | list_for_each_entry_rcu(data, &file->triggers, list) { |
| 569 | if (data->cmd_ops->trigger_type == test->cmd_ops->trigger_type) { |
| 570 | unregistered = true; |
| 571 | list_del_rcu(&data->list); |
| 572 | trace_event_trigger_enable_disable(file, 0); |
Tom Zanussi | 4e4a4d7 | 2015-11-23 13:51:16 -0600 | [diff] [blame] | 573 | update_cond_flag(file); |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 574 | break; |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | if (unregistered && data->ops->free) |
| 579 | data->ops->free(data->ops, data); |
| 580 | } |
| 581 | |
| 582 | /** |
| 583 | * event_trigger_callback - Generic event_command @func implementation |
| 584 | * @cmd_ops: The command ops, used for trigger registration |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 585 | * @file: The trace_event_file associated with the event |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 586 | * @glob: The raw string used to register the trigger |
| 587 | * @cmd: The cmd portion of the string used to register the trigger |
| 588 | * @param: The params portion of the string used to register the trigger |
| 589 | * |
| 590 | * Common implementation for event command parsing and trigger |
| 591 | * instantiation. |
| 592 | * |
| 593 | * Usually used directly as the @func method in event command |
| 594 | * implementations. |
| 595 | * |
| 596 | * Return: 0 on success, errno otherwise |
| 597 | */ |
| 598 | static int |
| 599 | event_trigger_callback(struct event_command *cmd_ops, |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 600 | struct trace_event_file *file, |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 601 | char *glob, char *cmd, char *param) |
| 602 | { |
| 603 | struct event_trigger_data *trigger_data; |
| 604 | struct event_trigger_ops *trigger_ops; |
| 605 | char *trigger = NULL; |
| 606 | char *number; |
| 607 | int ret; |
| 608 | |
| 609 | /* separate the trigger from the filter (t:n [if filter]) */ |
| 610 | if (param && isdigit(param[0])) |
| 611 | trigger = strsep(¶m, " \t"); |
| 612 | |
| 613 | trigger_ops = cmd_ops->get_trigger_ops(cmd, trigger); |
| 614 | |
| 615 | ret = -ENOMEM; |
| 616 | trigger_data = kzalloc(sizeof(*trigger_data), GFP_KERNEL); |
| 617 | if (!trigger_data) |
| 618 | goto out; |
| 619 | |
| 620 | trigger_data->count = -1; |
| 621 | trigger_data->ops = trigger_ops; |
| 622 | trigger_data->cmd_ops = cmd_ops; |
| 623 | INIT_LIST_HEAD(&trigger_data->list); |
| 624 | |
| 625 | if (glob[0] == '!') { |
| 626 | cmd_ops->unreg(glob+1, trigger_ops, trigger_data, file); |
| 627 | kfree(trigger_data); |
| 628 | ret = 0; |
| 629 | goto out; |
| 630 | } |
| 631 | |
| 632 | if (trigger) { |
| 633 | number = strsep(&trigger, ":"); |
| 634 | |
| 635 | ret = -EINVAL; |
| 636 | if (!strlen(number)) |
| 637 | goto out_free; |
| 638 | |
| 639 | /* |
| 640 | * We use the callback data field (which is a pointer) |
| 641 | * as our counter. |
| 642 | */ |
| 643 | ret = kstrtoul(number, 0, &trigger_data->count); |
| 644 | if (ret) |
| 645 | goto out_free; |
| 646 | } |
| 647 | |
| 648 | if (!param) /* if param is non-empty, it's supposed to be a filter */ |
| 649 | goto out_reg; |
| 650 | |
| 651 | if (!cmd_ops->set_filter) |
| 652 | goto out_reg; |
| 653 | |
| 654 | ret = cmd_ops->set_filter(param, trigger_data, file); |
| 655 | if (ret < 0) |
| 656 | goto out_free; |
| 657 | |
| 658 | out_reg: |
| 659 | ret = cmd_ops->reg(glob, trigger_ops, trigger_data, file); |
| 660 | /* |
| 661 | * The above returns on success the # of functions enabled, |
| 662 | * but if it didn't find any functions it returns zero. |
| 663 | * Consider no functions a failure too. |
| 664 | */ |
| 665 | if (!ret) { |
| 666 | ret = -ENOENT; |
| 667 | goto out_free; |
| 668 | } else if (ret < 0) |
| 669 | goto out_free; |
| 670 | ret = 0; |
| 671 | out: |
| 672 | return ret; |
| 673 | |
| 674 | out_free: |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 675 | if (cmd_ops->set_filter) |
| 676 | cmd_ops->set_filter(NULL, trigger_data, NULL); |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 677 | kfree(trigger_data); |
| 678 | goto out; |
| 679 | } |
| 680 | |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 681 | /** |
| 682 | * set_trigger_filter - Generic event_command @set_filter implementation |
| 683 | * @filter_str: The filter string for the trigger, NULL to remove filter |
| 684 | * @trigger_data: Trigger-specific data |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 685 | * @file: The trace_event_file associated with the event |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 686 | * |
| 687 | * Common implementation for event command filter parsing and filter |
| 688 | * instantiation. |
| 689 | * |
| 690 | * Usually used directly as the @set_filter method in event command |
| 691 | * implementations. |
| 692 | * |
| 693 | * Also used to remove a filter (if filter_str = NULL). |
| 694 | * |
| 695 | * Return: 0 on success, errno otherwise |
| 696 | */ |
Tom Zanussi | ab4bf00 | 2015-12-10 12:50:44 -0600 | [diff] [blame^] | 697 | int set_trigger_filter(char *filter_str, |
| 698 | struct event_trigger_data *trigger_data, |
| 699 | struct trace_event_file *file) |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 700 | { |
| 701 | struct event_trigger_data *data = trigger_data; |
| 702 | struct event_filter *filter = NULL, *tmp; |
| 703 | int ret = -EINVAL; |
| 704 | char *s; |
| 705 | |
| 706 | if (!filter_str) /* clear the current filter */ |
| 707 | goto assign; |
| 708 | |
| 709 | s = strsep(&filter_str, " \t"); |
| 710 | |
| 711 | if (!strlen(s) || strcmp(s, "if") != 0) |
| 712 | goto out; |
| 713 | |
| 714 | if (!filter_str) |
| 715 | goto out; |
| 716 | |
| 717 | /* The filter is for the 'trigger' event, not the triggered event */ |
| 718 | ret = create_event_filter(file->event_call, filter_str, false, &filter); |
| 719 | if (ret) |
| 720 | goto out; |
| 721 | assign: |
Steven Rostedt (Red Hat) | d8a30f2 | 2013-12-21 21:55:17 -0500 | [diff] [blame] | 722 | tmp = rcu_access_pointer(data->filter); |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 723 | |
| 724 | rcu_assign_pointer(data->filter, filter); |
| 725 | |
| 726 | if (tmp) { |
| 727 | /* Make sure the call is done with the filter */ |
| 728 | synchronize_sched(); |
| 729 | free_event_filter(tmp); |
| 730 | } |
| 731 | |
| 732 | kfree(data->filter_str); |
| 733 | data->filter_str = NULL; |
| 734 | |
| 735 | if (filter_str) { |
| 736 | data->filter_str = kstrdup(filter_str, GFP_KERNEL); |
| 737 | if (!data->filter_str) { |
Steven Rostedt (Red Hat) | d8a30f2 | 2013-12-21 21:55:17 -0500 | [diff] [blame] | 738 | free_event_filter(rcu_access_pointer(data->filter)); |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 739 | data->filter = NULL; |
| 740 | ret = -ENOMEM; |
| 741 | } |
| 742 | } |
| 743 | out: |
| 744 | return ret; |
| 745 | } |
| 746 | |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 747 | static void |
| 748 | traceon_trigger(struct event_trigger_data *data) |
| 749 | { |
| 750 | if (tracing_is_on()) |
| 751 | return; |
| 752 | |
| 753 | tracing_on(); |
| 754 | } |
| 755 | |
| 756 | static void |
| 757 | traceon_count_trigger(struct event_trigger_data *data) |
| 758 | { |
Steven Rostedt (Red Hat) | e8dc637 | 2014-01-06 22:25:50 -0500 | [diff] [blame] | 759 | if (tracing_is_on()) |
| 760 | return; |
| 761 | |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 762 | if (!data->count) |
| 763 | return; |
| 764 | |
| 765 | if (data->count != -1) |
| 766 | (data->count)--; |
| 767 | |
Steven Rostedt (Red Hat) | e8dc637 | 2014-01-06 22:25:50 -0500 | [diff] [blame] | 768 | tracing_on(); |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | static void |
| 772 | traceoff_trigger(struct event_trigger_data *data) |
| 773 | { |
| 774 | if (!tracing_is_on()) |
| 775 | return; |
| 776 | |
| 777 | tracing_off(); |
| 778 | } |
| 779 | |
| 780 | static void |
| 781 | traceoff_count_trigger(struct event_trigger_data *data) |
| 782 | { |
Steven Rostedt (Red Hat) | e8dc637 | 2014-01-06 22:25:50 -0500 | [diff] [blame] | 783 | if (!tracing_is_on()) |
| 784 | return; |
| 785 | |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 786 | if (!data->count) |
| 787 | return; |
| 788 | |
| 789 | if (data->count != -1) |
| 790 | (data->count)--; |
| 791 | |
Steven Rostedt (Red Hat) | e8dc637 | 2014-01-06 22:25:50 -0500 | [diff] [blame] | 792 | tracing_off(); |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | static int |
| 796 | traceon_trigger_print(struct seq_file *m, struct event_trigger_ops *ops, |
| 797 | struct event_trigger_data *data) |
| 798 | { |
| 799 | return event_trigger_print("traceon", m, (void *)data->count, |
| 800 | data->filter_str); |
| 801 | } |
| 802 | |
| 803 | static int |
| 804 | traceoff_trigger_print(struct seq_file *m, struct event_trigger_ops *ops, |
| 805 | struct event_trigger_data *data) |
| 806 | { |
| 807 | return event_trigger_print("traceoff", m, (void *)data->count, |
| 808 | data->filter_str); |
| 809 | } |
| 810 | |
| 811 | static struct event_trigger_ops traceon_trigger_ops = { |
| 812 | .func = traceon_trigger, |
| 813 | .print = traceon_trigger_print, |
| 814 | .init = event_trigger_init, |
| 815 | .free = event_trigger_free, |
| 816 | }; |
| 817 | |
| 818 | static struct event_trigger_ops traceon_count_trigger_ops = { |
| 819 | .func = traceon_count_trigger, |
| 820 | .print = traceon_trigger_print, |
| 821 | .init = event_trigger_init, |
| 822 | .free = event_trigger_free, |
| 823 | }; |
| 824 | |
| 825 | static struct event_trigger_ops traceoff_trigger_ops = { |
| 826 | .func = traceoff_trigger, |
| 827 | .print = traceoff_trigger_print, |
| 828 | .init = event_trigger_init, |
| 829 | .free = event_trigger_free, |
| 830 | }; |
| 831 | |
| 832 | static struct event_trigger_ops traceoff_count_trigger_ops = { |
| 833 | .func = traceoff_count_trigger, |
| 834 | .print = traceoff_trigger_print, |
| 835 | .init = event_trigger_init, |
| 836 | .free = event_trigger_free, |
| 837 | }; |
| 838 | |
| 839 | static struct event_trigger_ops * |
| 840 | onoff_get_trigger_ops(char *cmd, char *param) |
| 841 | { |
| 842 | struct event_trigger_ops *ops; |
| 843 | |
| 844 | /* we register both traceon and traceoff to this callback */ |
| 845 | if (strcmp(cmd, "traceon") == 0) |
| 846 | ops = param ? &traceon_count_trigger_ops : |
| 847 | &traceon_trigger_ops; |
| 848 | else |
| 849 | ops = param ? &traceoff_count_trigger_ops : |
| 850 | &traceoff_trigger_ops; |
| 851 | |
| 852 | return ops; |
| 853 | } |
| 854 | |
| 855 | static struct event_command trigger_traceon_cmd = { |
| 856 | .name = "traceon", |
| 857 | .trigger_type = ETT_TRACE_ONOFF, |
| 858 | .func = event_trigger_callback, |
| 859 | .reg = register_trigger, |
| 860 | .unreg = unregister_trigger, |
| 861 | .get_trigger_ops = onoff_get_trigger_ops, |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 862 | .set_filter = set_trigger_filter, |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 863 | }; |
| 864 | |
| 865 | static struct event_command trigger_traceoff_cmd = { |
| 866 | .name = "traceoff", |
| 867 | .trigger_type = ETT_TRACE_ONOFF, |
| 868 | .func = event_trigger_callback, |
| 869 | .reg = register_trigger, |
| 870 | .unreg = unregister_trigger, |
| 871 | .get_trigger_ops = onoff_get_trigger_ops, |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 872 | .set_filter = set_trigger_filter, |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 873 | }; |
| 874 | |
Tom Zanussi | 93e31ff | 2013-10-24 08:59:26 -0500 | [diff] [blame] | 875 | #ifdef CONFIG_TRACER_SNAPSHOT |
| 876 | static void |
| 877 | snapshot_trigger(struct event_trigger_data *data) |
| 878 | { |
| 879 | tracing_snapshot(); |
| 880 | } |
| 881 | |
| 882 | static void |
| 883 | snapshot_count_trigger(struct event_trigger_data *data) |
| 884 | { |
| 885 | if (!data->count) |
| 886 | return; |
| 887 | |
| 888 | if (data->count != -1) |
| 889 | (data->count)--; |
| 890 | |
| 891 | snapshot_trigger(data); |
| 892 | } |
| 893 | |
| 894 | static int |
| 895 | register_snapshot_trigger(char *glob, struct event_trigger_ops *ops, |
| 896 | struct event_trigger_data *data, |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 897 | struct trace_event_file *file) |
Tom Zanussi | 93e31ff | 2013-10-24 08:59:26 -0500 | [diff] [blame] | 898 | { |
| 899 | int ret = register_trigger(glob, ops, data, file); |
| 900 | |
| 901 | if (ret > 0 && tracing_alloc_snapshot() != 0) { |
| 902 | unregister_trigger(glob, ops, data, file); |
| 903 | ret = 0; |
| 904 | } |
| 905 | |
| 906 | return ret; |
| 907 | } |
| 908 | |
| 909 | static int |
| 910 | snapshot_trigger_print(struct seq_file *m, struct event_trigger_ops *ops, |
| 911 | struct event_trigger_data *data) |
| 912 | { |
| 913 | return event_trigger_print("snapshot", m, (void *)data->count, |
| 914 | data->filter_str); |
| 915 | } |
| 916 | |
| 917 | static struct event_trigger_ops snapshot_trigger_ops = { |
| 918 | .func = snapshot_trigger, |
| 919 | .print = snapshot_trigger_print, |
| 920 | .init = event_trigger_init, |
| 921 | .free = event_trigger_free, |
| 922 | }; |
| 923 | |
| 924 | static struct event_trigger_ops snapshot_count_trigger_ops = { |
| 925 | .func = snapshot_count_trigger, |
| 926 | .print = snapshot_trigger_print, |
| 927 | .init = event_trigger_init, |
| 928 | .free = event_trigger_free, |
| 929 | }; |
| 930 | |
| 931 | static struct event_trigger_ops * |
| 932 | snapshot_get_trigger_ops(char *cmd, char *param) |
| 933 | { |
| 934 | return param ? &snapshot_count_trigger_ops : &snapshot_trigger_ops; |
| 935 | } |
| 936 | |
| 937 | static struct event_command trigger_snapshot_cmd = { |
| 938 | .name = "snapshot", |
| 939 | .trigger_type = ETT_SNAPSHOT, |
| 940 | .func = event_trigger_callback, |
| 941 | .reg = register_snapshot_trigger, |
| 942 | .unreg = unregister_trigger, |
| 943 | .get_trigger_ops = snapshot_get_trigger_ops, |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 944 | .set_filter = set_trigger_filter, |
Tom Zanussi | 93e31ff | 2013-10-24 08:59:26 -0500 | [diff] [blame] | 945 | }; |
| 946 | |
| 947 | static __init int register_trigger_snapshot_cmd(void) |
| 948 | { |
| 949 | int ret; |
| 950 | |
| 951 | ret = register_event_command(&trigger_snapshot_cmd); |
| 952 | WARN_ON(ret < 0); |
| 953 | |
| 954 | return ret; |
| 955 | } |
| 956 | #else |
| 957 | static __init int register_trigger_snapshot_cmd(void) { return 0; } |
| 958 | #endif /* CONFIG_TRACER_SNAPSHOT */ |
| 959 | |
Tom Zanussi | f21ecbb | 2013-10-24 08:59:27 -0500 | [diff] [blame] | 960 | #ifdef CONFIG_STACKTRACE |
| 961 | /* |
| 962 | * Skip 3: |
| 963 | * stacktrace_trigger() |
| 964 | * event_triggers_post_call() |
Steven Rostedt (Red Hat) | a723776 | 2015-05-13 15:27:47 -0400 | [diff] [blame] | 965 | * trace_event_raw_event_xxx() |
Tom Zanussi | f21ecbb | 2013-10-24 08:59:27 -0500 | [diff] [blame] | 966 | */ |
| 967 | #define STACK_SKIP 3 |
| 968 | |
| 969 | static void |
| 970 | stacktrace_trigger(struct event_trigger_data *data) |
| 971 | { |
| 972 | trace_dump_stack(STACK_SKIP); |
| 973 | } |
| 974 | |
| 975 | static void |
| 976 | stacktrace_count_trigger(struct event_trigger_data *data) |
| 977 | { |
| 978 | if (!data->count) |
| 979 | return; |
| 980 | |
| 981 | if (data->count != -1) |
| 982 | (data->count)--; |
| 983 | |
| 984 | stacktrace_trigger(data); |
| 985 | } |
| 986 | |
| 987 | static int |
| 988 | stacktrace_trigger_print(struct seq_file *m, struct event_trigger_ops *ops, |
| 989 | struct event_trigger_data *data) |
| 990 | { |
| 991 | return event_trigger_print("stacktrace", m, (void *)data->count, |
| 992 | data->filter_str); |
| 993 | } |
| 994 | |
| 995 | static struct event_trigger_ops stacktrace_trigger_ops = { |
| 996 | .func = stacktrace_trigger, |
| 997 | .print = stacktrace_trigger_print, |
| 998 | .init = event_trigger_init, |
| 999 | .free = event_trigger_free, |
| 1000 | }; |
| 1001 | |
| 1002 | static struct event_trigger_ops stacktrace_count_trigger_ops = { |
| 1003 | .func = stacktrace_count_trigger, |
| 1004 | .print = stacktrace_trigger_print, |
| 1005 | .init = event_trigger_init, |
| 1006 | .free = event_trigger_free, |
| 1007 | }; |
| 1008 | |
| 1009 | static struct event_trigger_ops * |
| 1010 | stacktrace_get_trigger_ops(char *cmd, char *param) |
| 1011 | { |
| 1012 | return param ? &stacktrace_count_trigger_ops : &stacktrace_trigger_ops; |
| 1013 | } |
| 1014 | |
| 1015 | static struct event_command trigger_stacktrace_cmd = { |
| 1016 | .name = "stacktrace", |
| 1017 | .trigger_type = ETT_STACKTRACE, |
| 1018 | .post_trigger = true, |
| 1019 | .func = event_trigger_callback, |
| 1020 | .reg = register_trigger, |
| 1021 | .unreg = unregister_trigger, |
| 1022 | .get_trigger_ops = stacktrace_get_trigger_ops, |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 1023 | .set_filter = set_trigger_filter, |
Tom Zanussi | f21ecbb | 2013-10-24 08:59:27 -0500 | [diff] [blame] | 1024 | }; |
| 1025 | |
| 1026 | static __init int register_trigger_stacktrace_cmd(void) |
| 1027 | { |
| 1028 | int ret; |
| 1029 | |
| 1030 | ret = register_event_command(&trigger_stacktrace_cmd); |
| 1031 | WARN_ON(ret < 0); |
| 1032 | |
| 1033 | return ret; |
| 1034 | } |
| 1035 | #else |
| 1036 | static __init int register_trigger_stacktrace_cmd(void) { return 0; } |
| 1037 | #endif /* CONFIG_STACKTRACE */ |
| 1038 | |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 1039 | static __init void unregister_trigger_traceon_traceoff_cmds(void) |
| 1040 | { |
| 1041 | unregister_event_command(&trigger_traceon_cmd); |
| 1042 | unregister_event_command(&trigger_traceoff_cmd); |
| 1043 | } |
| 1044 | |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1045 | /* Avoid typos */ |
| 1046 | #define ENABLE_EVENT_STR "enable_event" |
| 1047 | #define DISABLE_EVENT_STR "disable_event" |
| 1048 | |
| 1049 | struct enable_trigger_data { |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 1050 | struct trace_event_file *file; |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1051 | bool enable; |
| 1052 | }; |
| 1053 | |
| 1054 | static void |
| 1055 | event_enable_trigger(struct event_trigger_data *data) |
| 1056 | { |
| 1057 | struct enable_trigger_data *enable_data = data->private_data; |
| 1058 | |
| 1059 | if (enable_data->enable) |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 1060 | clear_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &enable_data->file->flags); |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1061 | else |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 1062 | set_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &enable_data->file->flags); |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | static void |
| 1066 | event_enable_count_trigger(struct event_trigger_data *data) |
| 1067 | { |
| 1068 | struct enable_trigger_data *enable_data = data->private_data; |
| 1069 | |
| 1070 | if (!data->count) |
| 1071 | return; |
| 1072 | |
| 1073 | /* Skip if the event is in a state we want to switch to */ |
Steven Rostedt (Red Hat) | 5d6ad96 | 2015-05-13 15:12:33 -0400 | [diff] [blame] | 1074 | if (enable_data->enable == !(enable_data->file->flags & EVENT_FILE_FL_SOFT_DISABLED)) |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1075 | return; |
| 1076 | |
| 1077 | if (data->count != -1) |
| 1078 | (data->count)--; |
| 1079 | |
| 1080 | event_enable_trigger(data); |
| 1081 | } |
| 1082 | |
| 1083 | static int |
| 1084 | event_enable_trigger_print(struct seq_file *m, struct event_trigger_ops *ops, |
| 1085 | struct event_trigger_data *data) |
| 1086 | { |
| 1087 | struct enable_trigger_data *enable_data = data->private_data; |
| 1088 | |
| 1089 | seq_printf(m, "%s:%s:%s", |
| 1090 | enable_data->enable ? ENABLE_EVENT_STR : DISABLE_EVENT_STR, |
| 1091 | enable_data->file->event_call->class->system, |
Steven Rostedt (Red Hat) | 687fcc4 | 2015-05-13 14:20:14 -0400 | [diff] [blame] | 1092 | trace_event_name(enable_data->file->event_call)); |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1093 | |
| 1094 | if (data->count == -1) |
| 1095 | seq_puts(m, ":unlimited"); |
| 1096 | else |
| 1097 | seq_printf(m, ":count=%ld", data->count); |
| 1098 | |
| 1099 | if (data->filter_str) |
| 1100 | seq_printf(m, " if %s\n", data->filter_str); |
| 1101 | else |
Rasmus Villemoes | 1177e43 | 2014-11-08 21:42:12 +0100 | [diff] [blame] | 1102 | seq_putc(m, '\n'); |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1103 | |
| 1104 | return 0; |
| 1105 | } |
| 1106 | |
| 1107 | static void |
| 1108 | event_enable_trigger_free(struct event_trigger_ops *ops, |
| 1109 | struct event_trigger_data *data) |
| 1110 | { |
| 1111 | struct enable_trigger_data *enable_data = data->private_data; |
| 1112 | |
| 1113 | if (WARN_ON_ONCE(data->ref <= 0)) |
| 1114 | return; |
| 1115 | |
| 1116 | data->ref--; |
| 1117 | if (!data->ref) { |
| 1118 | /* Remove the SOFT_MODE flag */ |
| 1119 | trace_event_enable_disable(enable_data->file, 0, 1); |
| 1120 | module_put(enable_data->file->event_call->mod); |
| 1121 | trigger_data_free(data); |
| 1122 | kfree(enable_data); |
| 1123 | } |
| 1124 | } |
| 1125 | |
| 1126 | static struct event_trigger_ops event_enable_trigger_ops = { |
| 1127 | .func = event_enable_trigger, |
| 1128 | .print = event_enable_trigger_print, |
| 1129 | .init = event_trigger_init, |
| 1130 | .free = event_enable_trigger_free, |
| 1131 | }; |
| 1132 | |
| 1133 | static struct event_trigger_ops event_enable_count_trigger_ops = { |
| 1134 | .func = event_enable_count_trigger, |
| 1135 | .print = event_enable_trigger_print, |
| 1136 | .init = event_trigger_init, |
| 1137 | .free = event_enable_trigger_free, |
| 1138 | }; |
| 1139 | |
| 1140 | static struct event_trigger_ops event_disable_trigger_ops = { |
| 1141 | .func = event_enable_trigger, |
| 1142 | .print = event_enable_trigger_print, |
| 1143 | .init = event_trigger_init, |
| 1144 | .free = event_enable_trigger_free, |
| 1145 | }; |
| 1146 | |
| 1147 | static struct event_trigger_ops event_disable_count_trigger_ops = { |
| 1148 | .func = event_enable_count_trigger, |
| 1149 | .print = event_enable_trigger_print, |
| 1150 | .init = event_trigger_init, |
| 1151 | .free = event_enable_trigger_free, |
| 1152 | }; |
| 1153 | |
| 1154 | static int |
| 1155 | event_enable_trigger_func(struct event_command *cmd_ops, |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 1156 | struct trace_event_file *file, |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1157 | char *glob, char *cmd, char *param) |
| 1158 | { |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 1159 | struct trace_event_file *event_enable_file; |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1160 | struct enable_trigger_data *enable_data; |
| 1161 | struct event_trigger_data *trigger_data; |
| 1162 | struct event_trigger_ops *trigger_ops; |
| 1163 | struct trace_array *tr = file->tr; |
| 1164 | const char *system; |
| 1165 | const char *event; |
| 1166 | char *trigger; |
| 1167 | char *number; |
| 1168 | bool enable; |
| 1169 | int ret; |
| 1170 | |
| 1171 | if (!param) |
| 1172 | return -EINVAL; |
| 1173 | |
| 1174 | /* separate the trigger from the filter (s:e:n [if filter]) */ |
| 1175 | trigger = strsep(¶m, " \t"); |
| 1176 | if (!trigger) |
| 1177 | return -EINVAL; |
| 1178 | |
| 1179 | system = strsep(&trigger, ":"); |
| 1180 | if (!trigger) |
| 1181 | return -EINVAL; |
| 1182 | |
| 1183 | event = strsep(&trigger, ":"); |
| 1184 | |
| 1185 | ret = -EINVAL; |
| 1186 | event_enable_file = find_event_file(tr, system, event); |
| 1187 | if (!event_enable_file) |
| 1188 | goto out; |
| 1189 | |
| 1190 | enable = strcmp(cmd, ENABLE_EVENT_STR) == 0; |
| 1191 | |
| 1192 | trigger_ops = cmd_ops->get_trigger_ops(cmd, trigger); |
| 1193 | |
| 1194 | ret = -ENOMEM; |
| 1195 | trigger_data = kzalloc(sizeof(*trigger_data), GFP_KERNEL); |
| 1196 | if (!trigger_data) |
| 1197 | goto out; |
| 1198 | |
| 1199 | enable_data = kzalloc(sizeof(*enable_data), GFP_KERNEL); |
| 1200 | if (!enable_data) { |
| 1201 | kfree(trigger_data); |
| 1202 | goto out; |
| 1203 | } |
| 1204 | |
| 1205 | trigger_data->count = -1; |
| 1206 | trigger_data->ops = trigger_ops; |
| 1207 | trigger_data->cmd_ops = cmd_ops; |
| 1208 | INIT_LIST_HEAD(&trigger_data->list); |
| 1209 | RCU_INIT_POINTER(trigger_data->filter, NULL); |
| 1210 | |
| 1211 | enable_data->enable = enable; |
| 1212 | enable_data->file = event_enable_file; |
| 1213 | trigger_data->private_data = enable_data; |
| 1214 | |
| 1215 | if (glob[0] == '!') { |
| 1216 | cmd_ops->unreg(glob+1, trigger_ops, trigger_data, file); |
| 1217 | kfree(trigger_data); |
| 1218 | kfree(enable_data); |
| 1219 | ret = 0; |
| 1220 | goto out; |
| 1221 | } |
| 1222 | |
| 1223 | if (trigger) { |
| 1224 | number = strsep(&trigger, ":"); |
| 1225 | |
| 1226 | ret = -EINVAL; |
| 1227 | if (!strlen(number)) |
| 1228 | goto out_free; |
| 1229 | |
| 1230 | /* |
| 1231 | * We use the callback data field (which is a pointer) |
| 1232 | * as our counter. |
| 1233 | */ |
| 1234 | ret = kstrtoul(number, 0, &trigger_data->count); |
| 1235 | if (ret) |
| 1236 | goto out_free; |
| 1237 | } |
| 1238 | |
| 1239 | if (!param) /* if param is non-empty, it's supposed to be a filter */ |
| 1240 | goto out_reg; |
| 1241 | |
| 1242 | if (!cmd_ops->set_filter) |
| 1243 | goto out_reg; |
| 1244 | |
| 1245 | ret = cmd_ops->set_filter(param, trigger_data, file); |
| 1246 | if (ret < 0) |
| 1247 | goto out_free; |
| 1248 | |
| 1249 | out_reg: |
| 1250 | /* Don't let event modules unload while probe registered */ |
| 1251 | ret = try_module_get(event_enable_file->event_call->mod); |
| 1252 | if (!ret) { |
| 1253 | ret = -EBUSY; |
| 1254 | goto out_free; |
| 1255 | } |
| 1256 | |
| 1257 | ret = trace_event_enable_disable(event_enable_file, 1, 1); |
| 1258 | if (ret < 0) |
| 1259 | goto out_put; |
| 1260 | ret = cmd_ops->reg(glob, trigger_ops, trigger_data, file); |
| 1261 | /* |
| 1262 | * The above returns on success the # of functions enabled, |
| 1263 | * but if it didn't find any functions it returns zero. |
| 1264 | * Consider no functions a failure too. |
| 1265 | */ |
| 1266 | if (!ret) { |
| 1267 | ret = -ENOENT; |
| 1268 | goto out_disable; |
| 1269 | } else if (ret < 0) |
| 1270 | goto out_disable; |
| 1271 | /* Just return zero, not the number of enabled functions */ |
| 1272 | ret = 0; |
| 1273 | out: |
| 1274 | return ret; |
| 1275 | |
| 1276 | out_disable: |
| 1277 | trace_event_enable_disable(event_enable_file, 0, 1); |
| 1278 | out_put: |
| 1279 | module_put(event_enable_file->event_call->mod); |
| 1280 | out_free: |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 1281 | if (cmd_ops->set_filter) |
| 1282 | cmd_ops->set_filter(NULL, trigger_data, NULL); |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1283 | kfree(trigger_data); |
| 1284 | kfree(enable_data); |
| 1285 | goto out; |
| 1286 | } |
| 1287 | |
| 1288 | static int event_enable_register_trigger(char *glob, |
| 1289 | struct event_trigger_ops *ops, |
| 1290 | struct event_trigger_data *data, |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 1291 | struct trace_event_file *file) |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1292 | { |
| 1293 | struct enable_trigger_data *enable_data = data->private_data; |
| 1294 | struct enable_trigger_data *test_enable_data; |
| 1295 | struct event_trigger_data *test; |
| 1296 | int ret = 0; |
| 1297 | |
| 1298 | list_for_each_entry_rcu(test, &file->triggers, list) { |
| 1299 | test_enable_data = test->private_data; |
| 1300 | if (test_enable_data && |
| 1301 | (test_enable_data->file == enable_data->file)) { |
| 1302 | ret = -EEXIST; |
| 1303 | goto out; |
| 1304 | } |
| 1305 | } |
| 1306 | |
| 1307 | if (data->ops->init) { |
| 1308 | ret = data->ops->init(data->ops, data); |
| 1309 | if (ret < 0) |
| 1310 | goto out; |
| 1311 | } |
| 1312 | |
| 1313 | list_add_rcu(&data->list, &file->triggers); |
| 1314 | ret++; |
| 1315 | |
Tom Zanussi | 4e4a4d7 | 2015-11-23 13:51:16 -0600 | [diff] [blame] | 1316 | update_cond_flag(file); |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1317 | if (trace_event_trigger_enable_disable(file, 1) < 0) { |
| 1318 | list_del_rcu(&data->list); |
Tom Zanussi | 4e4a4d7 | 2015-11-23 13:51:16 -0600 | [diff] [blame] | 1319 | update_cond_flag(file); |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1320 | ret--; |
| 1321 | } |
| 1322 | out: |
| 1323 | return ret; |
| 1324 | } |
| 1325 | |
| 1326 | static void event_enable_unregister_trigger(char *glob, |
| 1327 | struct event_trigger_ops *ops, |
| 1328 | struct event_trigger_data *test, |
Steven Rostedt (Red Hat) | 7f1d2f8 | 2015-05-05 10:09:53 -0400 | [diff] [blame] | 1329 | struct trace_event_file *file) |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1330 | { |
| 1331 | struct enable_trigger_data *test_enable_data = test->private_data; |
| 1332 | struct enable_trigger_data *enable_data; |
| 1333 | struct event_trigger_data *data; |
| 1334 | bool unregistered = false; |
| 1335 | |
| 1336 | list_for_each_entry_rcu(data, &file->triggers, list) { |
| 1337 | enable_data = data->private_data; |
| 1338 | if (enable_data && |
| 1339 | (enable_data->file == test_enable_data->file)) { |
| 1340 | unregistered = true; |
| 1341 | list_del_rcu(&data->list); |
| 1342 | trace_event_trigger_enable_disable(file, 0); |
Tom Zanussi | 4e4a4d7 | 2015-11-23 13:51:16 -0600 | [diff] [blame] | 1343 | update_cond_flag(file); |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1344 | break; |
| 1345 | } |
| 1346 | } |
| 1347 | |
| 1348 | if (unregistered && data->ops->free) |
| 1349 | data->ops->free(data->ops, data); |
| 1350 | } |
| 1351 | |
| 1352 | static struct event_trigger_ops * |
| 1353 | event_enable_get_trigger_ops(char *cmd, char *param) |
| 1354 | { |
| 1355 | struct event_trigger_ops *ops; |
| 1356 | bool enable; |
| 1357 | |
| 1358 | enable = strcmp(cmd, ENABLE_EVENT_STR) == 0; |
| 1359 | |
| 1360 | if (enable) |
| 1361 | ops = param ? &event_enable_count_trigger_ops : |
| 1362 | &event_enable_trigger_ops; |
| 1363 | else |
| 1364 | ops = param ? &event_disable_count_trigger_ops : |
| 1365 | &event_disable_trigger_ops; |
| 1366 | |
| 1367 | return ops; |
| 1368 | } |
| 1369 | |
| 1370 | static struct event_command trigger_enable_cmd = { |
| 1371 | .name = ENABLE_EVENT_STR, |
| 1372 | .trigger_type = ETT_EVENT_ENABLE, |
| 1373 | .func = event_enable_trigger_func, |
| 1374 | .reg = event_enable_register_trigger, |
| 1375 | .unreg = event_enable_unregister_trigger, |
| 1376 | .get_trigger_ops = event_enable_get_trigger_ops, |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 1377 | .set_filter = set_trigger_filter, |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1378 | }; |
| 1379 | |
| 1380 | static struct event_command trigger_disable_cmd = { |
| 1381 | .name = DISABLE_EVENT_STR, |
| 1382 | .trigger_type = ETT_EVENT_ENABLE, |
| 1383 | .func = event_enable_trigger_func, |
| 1384 | .reg = event_enable_register_trigger, |
| 1385 | .unreg = event_enable_unregister_trigger, |
| 1386 | .get_trigger_ops = event_enable_get_trigger_ops, |
Tom Zanussi | bac5fb9 | 2013-10-24 08:59:29 -0500 | [diff] [blame] | 1387 | .set_filter = set_trigger_filter, |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1388 | }; |
| 1389 | |
| 1390 | static __init void unregister_trigger_enable_disable_cmds(void) |
| 1391 | { |
| 1392 | unregister_event_command(&trigger_enable_cmd); |
| 1393 | unregister_event_command(&trigger_disable_cmd); |
| 1394 | } |
| 1395 | |
| 1396 | static __init int register_trigger_enable_disable_cmds(void) |
| 1397 | { |
| 1398 | int ret; |
| 1399 | |
| 1400 | ret = register_event_command(&trigger_enable_cmd); |
| 1401 | if (WARN_ON(ret < 0)) |
| 1402 | return ret; |
| 1403 | ret = register_event_command(&trigger_disable_cmd); |
| 1404 | if (WARN_ON(ret < 0)) |
| 1405 | unregister_trigger_enable_disable_cmds(); |
| 1406 | |
| 1407 | return ret; |
| 1408 | } |
| 1409 | |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 1410 | static __init int register_trigger_traceon_traceoff_cmds(void) |
| 1411 | { |
| 1412 | int ret; |
| 1413 | |
| 1414 | ret = register_event_command(&trigger_traceon_cmd); |
| 1415 | if (WARN_ON(ret < 0)) |
| 1416 | return ret; |
| 1417 | ret = register_event_command(&trigger_traceoff_cmd); |
| 1418 | if (WARN_ON(ret < 0)) |
| 1419 | unregister_trigger_traceon_traceoff_cmds(); |
| 1420 | |
| 1421 | return ret; |
| 1422 | } |
| 1423 | |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 1424 | __init int register_trigger_cmds(void) |
| 1425 | { |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 1426 | register_trigger_traceon_traceoff_cmds(); |
Tom Zanussi | 93e31ff | 2013-10-24 08:59:26 -0500 | [diff] [blame] | 1427 | register_trigger_snapshot_cmd(); |
Tom Zanussi | f21ecbb | 2013-10-24 08:59:27 -0500 | [diff] [blame] | 1428 | register_trigger_stacktrace_cmd(); |
Tom Zanussi | 7862ad1 | 2013-10-24 08:59:28 -0500 | [diff] [blame] | 1429 | register_trigger_enable_disable_cmds(); |
Tom Zanussi | 2a2df32 | 2013-10-24 08:59:25 -0500 | [diff] [blame] | 1430 | |
Tom Zanussi | 85f2b08 | 2013-10-24 08:59:24 -0500 | [diff] [blame] | 1431 | return 0; |
| 1432 | } |