blob: 766e5ccad60ae6937066d58d5d71da2002fd6300 [file] [log] [blame]
Tom Zanussi7ef224d2016-03-03 12:54:42 -06001/*
2 * trace_events_hist - trace event hist 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 * Copyright (C) 2015 Tom Zanussi <tom.zanussi@linux.intel.com>
15 */
16
17#include <linux/module.h>
18#include <linux/kallsyms.h>
19#include <linux/mutex.h>
20#include <linux/slab.h>
21#include <linux/stacktrace.h>
22
23#include "tracing_map.h"
24#include "trace.h"
25
26struct hist_field;
27
28typedef u64 (*hist_field_fn_t) (struct hist_field *field, void *event);
29
30struct hist_field {
31 struct ftrace_event_field *field;
32 unsigned long flags;
33 hist_field_fn_t fn;
34 unsigned int size;
Tom Zanussi76a3b0c2016-03-03 12:54:44 -060035 unsigned int offset;
Tom Zanussi7ef224d2016-03-03 12:54:42 -060036};
37
Tom Zanussi69a02002016-03-03 12:54:52 -060038static u64 hist_field_none(struct hist_field *field, void *event)
39{
40 return 0;
41}
42
Tom Zanussi7ef224d2016-03-03 12:54:42 -060043static u64 hist_field_counter(struct hist_field *field, void *event)
44{
45 return 1;
46}
47
48static u64 hist_field_string(struct hist_field *hist_field, void *event)
49{
50 char *addr = (char *)(event + hist_field->field->offset);
51
52 return (u64)(unsigned long)addr;
53}
54
Namhyung Kim79e577c2016-03-03 12:54:53 -060055static u64 hist_field_dynstring(struct hist_field *hist_field, void *event)
56{
57 u32 str_item = *(u32 *)(event + hist_field->field->offset);
58 int str_loc = str_item & 0xffff;
59 char *addr = (char *)(event + str_loc);
60
61 return (u64)(unsigned long)addr;
62}
63
64static u64 hist_field_pstring(struct hist_field *hist_field, void *event)
65{
66 char **addr = (char **)(event + hist_field->field->offset);
67
68 return (u64)(unsigned long)*addr;
69}
70
Namhyung Kim4b94f5b2016-03-03 12:55:02 -060071static u64 hist_field_log2(struct hist_field *hist_field, void *event)
72{
73 u64 val = *(u64 *)(event + hist_field->field->offset);
74
75 return (u64) ilog2(roundup_pow_of_two(val));
76}
77
Tom Zanussi7ef224d2016-03-03 12:54:42 -060078#define DEFINE_HIST_FIELD_FN(type) \
79static u64 hist_field_##type(struct hist_field *hist_field, void *event)\
80{ \
81 type *addr = (type *)(event + hist_field->field->offset); \
82 \
Namhyung Kim79e577c2016-03-03 12:54:53 -060083 return (u64)(unsigned long)*addr; \
Tom Zanussi7ef224d2016-03-03 12:54:42 -060084}
85
86DEFINE_HIST_FIELD_FN(s64);
87DEFINE_HIST_FIELD_FN(u64);
88DEFINE_HIST_FIELD_FN(s32);
89DEFINE_HIST_FIELD_FN(u32);
90DEFINE_HIST_FIELD_FN(s16);
91DEFINE_HIST_FIELD_FN(u16);
92DEFINE_HIST_FIELD_FN(s8);
93DEFINE_HIST_FIELD_FN(u8);
94
95#define for_each_hist_field(i, hist_data) \
96 for ((i) = 0; (i) < (hist_data)->n_fields; (i)++)
97
98#define for_each_hist_val_field(i, hist_data) \
99 for ((i) = 0; (i) < (hist_data)->n_vals; (i)++)
100
101#define for_each_hist_key_field(i, hist_data) \
102 for ((i) = (hist_data)->n_vals; (i) < (hist_data)->n_fields; (i)++)
103
Tom Zanussi69a02002016-03-03 12:54:52 -0600104#define HIST_STACKTRACE_DEPTH 16
105#define HIST_STACKTRACE_SIZE (HIST_STACKTRACE_DEPTH * sizeof(unsigned long))
106#define HIST_STACKTRACE_SKIP 5
107
Tom Zanussi7ef224d2016-03-03 12:54:42 -0600108#define HITCOUNT_IDX 0
Tom Zanussi69a02002016-03-03 12:54:52 -0600109#define HIST_KEY_SIZE_MAX (MAX_FILTER_STR_VAL + HIST_STACKTRACE_SIZE)
Tom Zanussi7ef224d2016-03-03 12:54:42 -0600110
111enum hist_field_flags {
Tom Zanussic6afad42016-03-03 12:54:49 -0600112 HIST_FIELD_FL_HITCOUNT = 1,
113 HIST_FIELD_FL_KEY = 2,
114 HIST_FIELD_FL_STRING = 4,
115 HIST_FIELD_FL_HEX = 8,
116 HIST_FIELD_FL_SYM = 16,
117 HIST_FIELD_FL_SYM_OFFSET = 32,
Tom Zanussi6b4827a2016-03-03 12:54:50 -0600118 HIST_FIELD_FL_EXECNAME = 64,
Tom Zanussi31696192016-03-03 12:54:51 -0600119 HIST_FIELD_FL_SYSCALL = 128,
Tom Zanussi69a02002016-03-03 12:54:52 -0600120 HIST_FIELD_FL_STACKTRACE = 256,
Namhyung Kim4b94f5b2016-03-03 12:55:02 -0600121 HIST_FIELD_FL_LOG2 = 512,
Tom Zanussi7ef224d2016-03-03 12:54:42 -0600122};
123
124struct hist_trigger_attrs {
125 char *keys_str;
Tom Zanussif2606832016-03-03 12:54:43 -0600126 char *vals_str;
Tom Zanussie62347d2016-03-03 12:54:45 -0600127 char *sort_key_str;
Tom Zanussi5463bfd2016-03-03 12:54:59 -0600128 char *name;
Tom Zanussi83e99912016-03-03 12:54:46 -0600129 bool pause;
130 bool cont;
Tom Zanussie86ae9b2016-03-03 12:54:47 -0600131 bool clear;
Tom Zanussi7ef224d2016-03-03 12:54:42 -0600132 unsigned int map_bits;
133};
134
135struct hist_trigger_data {
136 struct hist_field *fields[TRACING_MAP_FIELDS_MAX];
137 unsigned int n_vals;
138 unsigned int n_keys;
139 unsigned int n_fields;
140 unsigned int key_size;
141 struct tracing_map_sort_key sort_keys[TRACING_MAP_SORT_KEYS_MAX];
142 unsigned int n_sort_keys;
143 struct trace_event_file *event_file;
144 struct hist_trigger_attrs *attrs;
145 struct tracing_map *map;
146};
147
148static hist_field_fn_t select_value_fn(int field_size, int field_is_signed)
149{
150 hist_field_fn_t fn = NULL;
151
152 switch (field_size) {
153 case 8:
154 if (field_is_signed)
155 fn = hist_field_s64;
156 else
157 fn = hist_field_u64;
158 break;
159 case 4:
160 if (field_is_signed)
161 fn = hist_field_s32;
162 else
163 fn = hist_field_u32;
164 break;
165 case 2:
166 if (field_is_signed)
167 fn = hist_field_s16;
168 else
169 fn = hist_field_u16;
170 break;
171 case 1:
172 if (field_is_signed)
173 fn = hist_field_s8;
174 else
175 fn = hist_field_u8;
176 break;
177 }
178
179 return fn;
180}
181
182static int parse_map_size(char *str)
183{
184 unsigned long size, map_bits;
185 int ret;
186
187 strsep(&str, "=");
188 if (!str) {
189 ret = -EINVAL;
190 goto out;
191 }
192
193 ret = kstrtoul(str, 0, &size);
194 if (ret)
195 goto out;
196
197 map_bits = ilog2(roundup_pow_of_two(size));
198 if (map_bits < TRACING_MAP_BITS_MIN ||
199 map_bits > TRACING_MAP_BITS_MAX)
200 ret = -EINVAL;
201 else
202 ret = map_bits;
203 out:
204 return ret;
205}
206
207static void destroy_hist_trigger_attrs(struct hist_trigger_attrs *attrs)
208{
209 if (!attrs)
210 return;
211
Tom Zanussi5463bfd2016-03-03 12:54:59 -0600212 kfree(attrs->name);
Tom Zanussie62347d2016-03-03 12:54:45 -0600213 kfree(attrs->sort_key_str);
Tom Zanussi7ef224d2016-03-03 12:54:42 -0600214 kfree(attrs->keys_str);
Tom Zanussif2606832016-03-03 12:54:43 -0600215 kfree(attrs->vals_str);
Tom Zanussi7ef224d2016-03-03 12:54:42 -0600216 kfree(attrs);
217}
218
219static struct hist_trigger_attrs *parse_hist_trigger_attrs(char *trigger_str)
220{
221 struct hist_trigger_attrs *attrs;
222 int ret = 0;
223
224 attrs = kzalloc(sizeof(*attrs), GFP_KERNEL);
225 if (!attrs)
226 return ERR_PTR(-ENOMEM);
227
228 while (trigger_str) {
229 char *str = strsep(&trigger_str, ":");
230
231 if ((strncmp(str, "key=", strlen("key=")) == 0) ||
232 (strncmp(str, "keys=", strlen("keys=")) == 0))
233 attrs->keys_str = kstrdup(str, GFP_KERNEL);
Tom Zanussif2606832016-03-03 12:54:43 -0600234 else if ((strncmp(str, "val=", strlen("val=")) == 0) ||
235 (strncmp(str, "vals=", strlen("vals=")) == 0) ||
236 (strncmp(str, "values=", strlen("values=")) == 0))
237 attrs->vals_str = kstrdup(str, GFP_KERNEL);
Tom Zanussie62347d2016-03-03 12:54:45 -0600238 else if (strncmp(str, "sort=", strlen("sort=")) == 0)
239 attrs->sort_key_str = kstrdup(str, GFP_KERNEL);
Tom Zanussi5463bfd2016-03-03 12:54:59 -0600240 else if (strncmp(str, "name=", strlen("name=")) == 0)
241 attrs->name = kstrdup(str, GFP_KERNEL);
Tom Zanussi83e99912016-03-03 12:54:46 -0600242 else if (strcmp(str, "pause") == 0)
243 attrs->pause = true;
244 else if ((strcmp(str, "cont") == 0) ||
245 (strcmp(str, "continue") == 0))
246 attrs->cont = true;
Tom Zanussie86ae9b2016-03-03 12:54:47 -0600247 else if (strcmp(str, "clear") == 0)
248 attrs->clear = true;
Tom Zanussi7ef224d2016-03-03 12:54:42 -0600249 else if (strncmp(str, "size=", strlen("size=")) == 0) {
250 int map_bits = parse_map_size(str);
251
252 if (map_bits < 0) {
253 ret = map_bits;
254 goto free;
255 }
256 attrs->map_bits = map_bits;
257 } else {
258 ret = -EINVAL;
259 goto free;
260 }
261 }
262
263 if (!attrs->keys_str) {
264 ret = -EINVAL;
265 goto free;
266 }
267
268 return attrs;
269 free:
270 destroy_hist_trigger_attrs(attrs);
271
272 return ERR_PTR(ret);
273}
274
Tom Zanussi6b4827a2016-03-03 12:54:50 -0600275static inline void save_comm(char *comm, struct task_struct *task)
276{
277 if (!task->pid) {
278 strcpy(comm, "<idle>");
279 return;
280 }
281
282 if (WARN_ON_ONCE(task->pid < 0)) {
283 strcpy(comm, "<XXX>");
284 return;
285 }
286
287 memcpy(comm, task->comm, TASK_COMM_LEN);
288}
289
290static void hist_trigger_elt_comm_free(struct tracing_map_elt *elt)
291{
292 kfree((char *)elt->private_data);
293}
294
295static int hist_trigger_elt_comm_alloc(struct tracing_map_elt *elt)
296{
297 struct hist_trigger_data *hist_data = elt->map->private_data;
298 struct hist_field *key_field;
299 unsigned int i;
300
301 for_each_hist_key_field(i, hist_data) {
302 key_field = hist_data->fields[i];
303
304 if (key_field->flags & HIST_FIELD_FL_EXECNAME) {
305 unsigned int size = TASK_COMM_LEN + 1;
306
307 elt->private_data = kzalloc(size, GFP_KERNEL);
308 if (!elt->private_data)
309 return -ENOMEM;
310 break;
311 }
312 }
313
314 return 0;
315}
316
317static void hist_trigger_elt_comm_copy(struct tracing_map_elt *to,
318 struct tracing_map_elt *from)
319{
320 char *comm_from = from->private_data;
321 char *comm_to = to->private_data;
322
323 if (comm_from)
324 memcpy(comm_to, comm_from, TASK_COMM_LEN + 1);
325}
326
327static void hist_trigger_elt_comm_init(struct tracing_map_elt *elt)
328{
329 char *comm = elt->private_data;
330
331 if (comm)
332 save_comm(comm, current);
333}
334
335static const struct tracing_map_ops hist_trigger_elt_comm_ops = {
336 .elt_alloc = hist_trigger_elt_comm_alloc,
337 .elt_copy = hist_trigger_elt_comm_copy,
338 .elt_free = hist_trigger_elt_comm_free,
339 .elt_init = hist_trigger_elt_comm_init,
340};
341
Tom Zanussi7ef224d2016-03-03 12:54:42 -0600342static void destroy_hist_field(struct hist_field *hist_field)
343{
344 kfree(hist_field);
345}
346
347static struct hist_field *create_hist_field(struct ftrace_event_field *field,
348 unsigned long flags)
349{
350 struct hist_field *hist_field;
351
352 if (field && is_function_field(field))
353 return NULL;
354
355 hist_field = kzalloc(sizeof(struct hist_field), GFP_KERNEL);
356 if (!hist_field)
357 return NULL;
358
359 if (flags & HIST_FIELD_FL_HITCOUNT) {
360 hist_field->fn = hist_field_counter;
361 goto out;
362 }
363
Tom Zanussi69a02002016-03-03 12:54:52 -0600364 if (flags & HIST_FIELD_FL_STACKTRACE) {
365 hist_field->fn = hist_field_none;
366 goto out;
367 }
368
Namhyung Kim4b94f5b2016-03-03 12:55:02 -0600369 if (flags & HIST_FIELD_FL_LOG2) {
370 hist_field->fn = hist_field_log2;
371 goto out;
372 }
373
Tom Zanussi432480c2016-04-25 14:01:27 -0500374 if (WARN_ON_ONCE(!field))
375 goto out;
376
Tom Zanussi7ef224d2016-03-03 12:54:42 -0600377 if (is_string_field(field)) {
378 flags |= HIST_FIELD_FL_STRING;
Namhyung Kim79e577c2016-03-03 12:54:53 -0600379
380 if (field->filter_type == FILTER_STATIC_STRING)
381 hist_field->fn = hist_field_string;
382 else if (field->filter_type == FILTER_DYN_STRING)
383 hist_field->fn = hist_field_dynstring;
384 else
385 hist_field->fn = hist_field_pstring;
Tom Zanussi7ef224d2016-03-03 12:54:42 -0600386 } else {
387 hist_field->fn = select_value_fn(field->size,
388 field->is_signed);
389 if (!hist_field->fn) {
390 destroy_hist_field(hist_field);
391 return NULL;
392 }
393 }
394 out:
395 hist_field->field = field;
396 hist_field->flags = flags;
397
398 return hist_field;
399}
400
401static void destroy_hist_fields(struct hist_trigger_data *hist_data)
402{
403 unsigned int i;
404
405 for (i = 0; i < TRACING_MAP_FIELDS_MAX; i++) {
406 if (hist_data->fields[i]) {
407 destroy_hist_field(hist_data->fields[i]);
408 hist_data->fields[i] = NULL;
409 }
410 }
411}
412
413static int create_hitcount_val(struct hist_trigger_data *hist_data)
414{
415 hist_data->fields[HITCOUNT_IDX] =
416 create_hist_field(NULL, HIST_FIELD_FL_HITCOUNT);
417 if (!hist_data->fields[HITCOUNT_IDX])
418 return -ENOMEM;
419
420 hist_data->n_vals++;
421
422 if (WARN_ON(hist_data->n_vals > TRACING_MAP_VALS_MAX))
423 return -EINVAL;
424
425 return 0;
426}
427
Tom Zanussif2606832016-03-03 12:54:43 -0600428static int create_val_field(struct hist_trigger_data *hist_data,
429 unsigned int val_idx,
430 struct trace_event_file *file,
431 char *field_str)
432{
433 struct ftrace_event_field *field = NULL;
434 unsigned long flags = 0;
Tom Zanussi0c4a6b42016-03-03 12:54:48 -0600435 char *field_name;
Tom Zanussif2606832016-03-03 12:54:43 -0600436 int ret = 0;
437
438 if (WARN_ON(val_idx >= TRACING_MAP_VALS_MAX))
439 return -EINVAL;
Tom Zanussi0c4a6b42016-03-03 12:54:48 -0600440
441 field_name = strsep(&field_str, ".");
442 if (field_str) {
443 if (strcmp(field_str, "hex") == 0)
444 flags |= HIST_FIELD_FL_HEX;
445 else {
446 ret = -EINVAL;
447 goto out;
448 }
449 }
450
451 field = trace_find_event_field(file->event_call, field_name);
Tom Zanussi6af9b182017-09-22 14:58:17 -0500452 if (!field || !field->size) {
Tom Zanussif2606832016-03-03 12:54:43 -0600453 ret = -EINVAL;
454 goto out;
455 }
456
457 hist_data->fields[val_idx] = create_hist_field(field, flags);
458 if (!hist_data->fields[val_idx]) {
459 ret = -ENOMEM;
460 goto out;
461 }
462
463 ++hist_data->n_vals;
464
465 if (WARN_ON(hist_data->n_vals > TRACING_MAP_VALS_MAX))
466 ret = -EINVAL;
467 out:
468 return ret;
469}
470
Tom Zanussi7ef224d2016-03-03 12:54:42 -0600471static int create_val_fields(struct hist_trigger_data *hist_data,
472 struct trace_event_file *file)
473{
Tom Zanussif2606832016-03-03 12:54:43 -0600474 char *fields_str, *field_str;
475 unsigned int i, j;
Tom Zanussi7ef224d2016-03-03 12:54:42 -0600476 int ret;
477
478 ret = create_hitcount_val(hist_data);
Tom Zanussif2606832016-03-03 12:54:43 -0600479 if (ret)
480 goto out;
Tom Zanussi7ef224d2016-03-03 12:54:42 -0600481
Tom Zanussif2606832016-03-03 12:54:43 -0600482 fields_str = hist_data->attrs->vals_str;
483 if (!fields_str)
484 goto out;
485
486 strsep(&fields_str, "=");
487 if (!fields_str)
488 goto out;
489
490 for (i = 0, j = 1; i < TRACING_MAP_VALS_MAX &&
491 j < TRACING_MAP_VALS_MAX; i++) {
492 field_str = strsep(&fields_str, ",");
493 if (!field_str)
494 break;
495 if (strcmp(field_str, "hitcount") == 0)
496 continue;
497 ret = create_val_field(hist_data, j++, file, field_str);
498 if (ret)
499 goto out;
500 }
501 if (fields_str && (strcmp(fields_str, "hitcount") != 0))
502 ret = -EINVAL;
503 out:
Tom Zanussi7ef224d2016-03-03 12:54:42 -0600504 return ret;
505}
506
507static int create_key_field(struct hist_trigger_data *hist_data,
508 unsigned int key_idx,
Tom Zanussi76a3b0c2016-03-03 12:54:44 -0600509 unsigned int key_offset,
Tom Zanussi7ef224d2016-03-03 12:54:42 -0600510 struct trace_event_file *file,
511 char *field_str)
512{
513 struct ftrace_event_field *field = NULL;
514 unsigned long flags = 0;
515 unsigned int key_size;
516 int ret = 0;
517
518 if (WARN_ON(key_idx >= TRACING_MAP_FIELDS_MAX))
519 return -EINVAL;
520
521 flags |= HIST_FIELD_FL_KEY;
522
Tom Zanussi69a02002016-03-03 12:54:52 -0600523 if (strcmp(field_str, "stacktrace") == 0) {
524 flags |= HIST_FIELD_FL_STACKTRACE;
525 key_size = sizeof(unsigned long) * HIST_STACKTRACE_DEPTH;
526 } else {
527 char *field_name = strsep(&field_str, ".");
528
529 if (field_str) {
530 if (strcmp(field_str, "hex") == 0)
531 flags |= HIST_FIELD_FL_HEX;
532 else if (strcmp(field_str, "sym") == 0)
533 flags |= HIST_FIELD_FL_SYM;
534 else if (strcmp(field_str, "sym-offset") == 0)
535 flags |= HIST_FIELD_FL_SYM_OFFSET;
536 else if ((strcmp(field_str, "execname") == 0) &&
537 (strcmp(field_name, "common_pid") == 0))
538 flags |= HIST_FIELD_FL_EXECNAME;
539 else if (strcmp(field_str, "syscall") == 0)
540 flags |= HIST_FIELD_FL_SYSCALL;
Namhyung Kim4b94f5b2016-03-03 12:55:02 -0600541 else if (strcmp(field_str, "log2") == 0)
542 flags |= HIST_FIELD_FL_LOG2;
Tom Zanussi69a02002016-03-03 12:54:52 -0600543 else {
544 ret = -EINVAL;
545 goto out;
546 }
547 }
548
549 field = trace_find_event_field(file->event_call, field_name);
Tom Zanussi6af9b182017-09-22 14:58:17 -0500550 if (!field || !field->size) {
Tom Zanussi0c4a6b42016-03-03 12:54:48 -0600551 ret = -EINVAL;
552 goto out;
553 }
Tom Zanussi0c4a6b42016-03-03 12:54:48 -0600554
Tom Zanussi6a475cb2016-03-03 12:54:54 -0600555 if (is_string_field(field))
556 key_size = MAX_FILTER_STR_VAL;
Namhyung Kim79e577c2016-03-03 12:54:53 -0600557 else
558 key_size = field->size;
Tom Zanussi7ef224d2016-03-03 12:54:42 -0600559 }
560
Tom Zanussi7ef224d2016-03-03 12:54:42 -0600561 hist_data->fields[key_idx] = create_hist_field(field, flags);
562 if (!hist_data->fields[key_idx]) {
563 ret = -ENOMEM;
564 goto out;
565 }
566
567 key_size = ALIGN(key_size, sizeof(u64));
568 hist_data->fields[key_idx]->size = key_size;
Tom Zanussi76a3b0c2016-03-03 12:54:44 -0600569 hist_data->fields[key_idx]->offset = key_offset;
570 hist_data->key_size += key_size;
Tom Zanussi7ef224d2016-03-03 12:54:42 -0600571 if (hist_data->key_size > HIST_KEY_SIZE_MAX) {
572 ret = -EINVAL;
573 goto out;
574 }
575
576 hist_data->n_keys++;
577
578 if (WARN_ON(hist_data->n_keys > TRACING_MAP_KEYS_MAX))
579 return -EINVAL;
580
581 ret = key_size;
582 out:
583 return ret;
584}
585
586static int create_key_fields(struct hist_trigger_data *hist_data,
587 struct trace_event_file *file)
588{
Tom Zanussi76a3b0c2016-03-03 12:54:44 -0600589 unsigned int i, key_offset = 0, n_vals = hist_data->n_vals;
Tom Zanussi7ef224d2016-03-03 12:54:42 -0600590 char *fields_str, *field_str;
591 int ret = -EINVAL;
592
593 fields_str = hist_data->attrs->keys_str;
594 if (!fields_str)
595 goto out;
596
597 strsep(&fields_str, "=");
598 if (!fields_str)
599 goto out;
600
Tom Zanussi76a3b0c2016-03-03 12:54:44 -0600601 for (i = n_vals; i < n_vals + TRACING_MAP_KEYS_MAX; i++) {
Tom Zanussi7ef224d2016-03-03 12:54:42 -0600602 field_str = strsep(&fields_str, ",");
603 if (!field_str)
604 break;
Tom Zanussi76a3b0c2016-03-03 12:54:44 -0600605 ret = create_key_field(hist_data, i, key_offset,
606 file, field_str);
Tom Zanussi7ef224d2016-03-03 12:54:42 -0600607 if (ret < 0)
608 goto out;
Tom Zanussi76a3b0c2016-03-03 12:54:44 -0600609 key_offset += ret;
Tom Zanussi7ef224d2016-03-03 12:54:42 -0600610 }
611 if (fields_str) {
612 ret = -EINVAL;
613 goto out;
614 }
615 ret = 0;
616 out:
617 return ret;
618}
619
620static int create_hist_fields(struct hist_trigger_data *hist_data,
621 struct trace_event_file *file)
622{
623 int ret;
624
625 ret = create_val_fields(hist_data, file);
626 if (ret)
627 goto out;
628
629 ret = create_key_fields(hist_data, file);
630 if (ret)
631 goto out;
632
633 hist_data->n_fields = hist_data->n_vals + hist_data->n_keys;
634 out:
635 return ret;
636}
637
Tom Zanussie62347d2016-03-03 12:54:45 -0600638static int is_descending(const char *str)
639{
640 if (!str)
641 return 0;
642
643 if (strcmp(str, "descending") == 0)
644 return 1;
645
646 if (strcmp(str, "ascending") == 0)
647 return 0;
648
649 return -EINVAL;
650}
651
Tom Zanussi7ef224d2016-03-03 12:54:42 -0600652static int create_sort_keys(struct hist_trigger_data *hist_data)
653{
Tom Zanussie62347d2016-03-03 12:54:45 -0600654 char *fields_str = hist_data->attrs->sort_key_str;
655 struct ftrace_event_field *field = NULL;
656 struct tracing_map_sort_key *sort_key;
657 int descending, ret = 0;
658 unsigned int i, j;
Tom Zanussi7ef224d2016-03-03 12:54:42 -0600659
Tom Zanussie62347d2016-03-03 12:54:45 -0600660 hist_data->n_sort_keys = 1; /* we always have at least one, hitcount */
Tom Zanussi7ef224d2016-03-03 12:54:42 -0600661
Tom Zanussie62347d2016-03-03 12:54:45 -0600662 if (!fields_str)
663 goto out;
664
665 strsep(&fields_str, "=");
666 if (!fields_str) {
667 ret = -EINVAL;
668 goto out;
669 }
670
671 for (i = 0; i < TRACING_MAP_SORT_KEYS_MAX; i++) {
672 char *field_str, *field_name;
673
674 sort_key = &hist_data->sort_keys[i];
675
676 field_str = strsep(&fields_str, ",");
677 if (!field_str) {
678 if (i == 0)
679 ret = -EINVAL;
680 break;
681 }
682
683 if ((i == TRACING_MAP_SORT_KEYS_MAX - 1) && fields_str) {
684 ret = -EINVAL;
685 break;
686 }
687
688 field_name = strsep(&field_str, ".");
689 if (!field_name) {
690 ret = -EINVAL;
691 break;
692 }
693
694 if (strcmp(field_name, "hitcount") == 0) {
695 descending = is_descending(field_str);
696 if (descending < 0) {
697 ret = descending;
698 break;
699 }
700 sort_key->descending = descending;
701 continue;
702 }
703
704 for (j = 1; j < hist_data->n_fields; j++) {
705 field = hist_data->fields[j]->field;
706 if (field && (strcmp(field_name, field->name) == 0)) {
707 sort_key->field_idx = j;
708 descending = is_descending(field_str);
709 if (descending < 0) {
710 ret = descending;
711 goto out;
712 }
713 sort_key->descending = descending;
714 break;
715 }
716 }
717 if (j == hist_data->n_fields) {
718 ret = -EINVAL;
719 break;
720 }
721 }
722 hist_data->n_sort_keys = i;
723 out:
Tom Zanussi7ef224d2016-03-03 12:54:42 -0600724 return ret;
725}
726
727static void destroy_hist_data(struct hist_trigger_data *hist_data)
728{
729 destroy_hist_trigger_attrs(hist_data->attrs);
730 destroy_hist_fields(hist_data);
731 tracing_map_destroy(hist_data->map);
732 kfree(hist_data);
733}
734
735static int create_tracing_map_fields(struct hist_trigger_data *hist_data)
736{
737 struct tracing_map *map = hist_data->map;
738 struct ftrace_event_field *field;
739 struct hist_field *hist_field;
Steven Rostedt (Red Hat)d50c7442016-03-08 17:17:15 -0500740 int i, idx;
Tom Zanussi7ef224d2016-03-03 12:54:42 -0600741
742 for_each_hist_field(i, hist_data) {
743 hist_field = hist_data->fields[i];
744 if (hist_field->flags & HIST_FIELD_FL_KEY) {
745 tracing_map_cmp_fn_t cmp_fn;
746
747 field = hist_field->field;
748
Tom Zanussi69a02002016-03-03 12:54:52 -0600749 if (hist_field->flags & HIST_FIELD_FL_STACKTRACE)
750 cmp_fn = tracing_map_cmp_none;
751 else if (is_string_field(field))
Tom Zanussi7ef224d2016-03-03 12:54:42 -0600752 cmp_fn = tracing_map_cmp_string;
753 else
754 cmp_fn = tracing_map_cmp_num(field->size,
755 field->is_signed);
Tom Zanussi76a3b0c2016-03-03 12:54:44 -0600756 idx = tracing_map_add_key_field(map,
757 hist_field->offset,
758 cmp_fn);
759
Tom Zanussi7ef224d2016-03-03 12:54:42 -0600760 } else
761 idx = tracing_map_add_sum_field(map);
762
763 if (idx < 0)
764 return idx;
765 }
766
767 return 0;
768}
769
Tom Zanussi6b4827a2016-03-03 12:54:50 -0600770static bool need_tracing_map_ops(struct hist_trigger_data *hist_data)
771{
772 struct hist_field *key_field;
773 unsigned int i;
774
775 for_each_hist_key_field(i, hist_data) {
776 key_field = hist_data->fields[i];
777
778 if (key_field->flags & HIST_FIELD_FL_EXECNAME)
779 return true;
780 }
781
782 return false;
783}
784
Tom Zanussi7ef224d2016-03-03 12:54:42 -0600785static struct hist_trigger_data *
786create_hist_data(unsigned int map_bits,
787 struct hist_trigger_attrs *attrs,
788 struct trace_event_file *file)
789{
Tom Zanussi6b4827a2016-03-03 12:54:50 -0600790 const struct tracing_map_ops *map_ops = NULL;
Tom Zanussi7ef224d2016-03-03 12:54:42 -0600791 struct hist_trigger_data *hist_data;
792 int ret = 0;
793
794 hist_data = kzalloc(sizeof(*hist_data), GFP_KERNEL);
795 if (!hist_data)
796 return ERR_PTR(-ENOMEM);
797
798 hist_data->attrs = attrs;
799
800 ret = create_hist_fields(hist_data, file);
801 if (ret)
802 goto free;
803
804 ret = create_sort_keys(hist_data);
805 if (ret)
806 goto free;
807
Tom Zanussi6b4827a2016-03-03 12:54:50 -0600808 if (need_tracing_map_ops(hist_data))
809 map_ops = &hist_trigger_elt_comm_ops;
810
Tom Zanussi7ef224d2016-03-03 12:54:42 -0600811 hist_data->map = tracing_map_create(map_bits, hist_data->key_size,
Tom Zanussi6b4827a2016-03-03 12:54:50 -0600812 map_ops, hist_data);
Tom Zanussi7ef224d2016-03-03 12:54:42 -0600813 if (IS_ERR(hist_data->map)) {
814 ret = PTR_ERR(hist_data->map);
815 hist_data->map = NULL;
816 goto free;
817 }
818
819 ret = create_tracing_map_fields(hist_data);
820 if (ret)
821 goto free;
822
823 ret = tracing_map_init(hist_data->map);
824 if (ret)
825 goto free;
826
827 hist_data->event_file = file;
828 out:
829 return hist_data;
830 free:
831 hist_data->attrs = NULL;
832
833 destroy_hist_data(hist_data);
834
835 hist_data = ERR_PTR(ret);
836
837 goto out;
838}
839
840static void hist_trigger_elt_update(struct hist_trigger_data *hist_data,
841 struct tracing_map_elt *elt,
842 void *rec)
843{
844 struct hist_field *hist_field;
845 unsigned int i;
846 u64 hist_val;
847
848 for_each_hist_val_field(i, hist_data) {
849 hist_field = hist_data->fields[i];
850 hist_val = hist_field->fn(hist_field, rec);
851 tracing_map_update_sum(elt, i, hist_val);
852 }
853}
854
Tom Zanussi6a475cb2016-03-03 12:54:54 -0600855static inline void add_to_key(char *compound_key, void *key,
856 struct hist_field *key_field, void *rec)
857{
858 size_t size = key_field->size;
859
860 if (key_field->flags & HIST_FIELD_FL_STRING) {
861 struct ftrace_event_field *field;
862
863 field = key_field->field;
864 if (field->filter_type == FILTER_DYN_STRING)
865 size = *(u32 *)(rec + field->offset) >> 16;
866 else if (field->filter_type == FILTER_PTR_STRING)
867 size = strlen(key);
868 else if (field->filter_type == FILTER_STATIC_STRING)
869 size = field->size;
870
871 /* ensure NULL-termination */
872 if (size > key_field->size - 1)
873 size = key_field->size - 1;
Tom Zanussi6a475cb2016-03-03 12:54:54 -0600874
Tom Zanussi286ffaa2019-02-04 15:07:24 -0600875 strncpy(compound_key + key_field->offset, (char *)key, size);
876 } else
877 memcpy(compound_key + key_field->offset, key, size);
Tom Zanussi6a475cb2016-03-03 12:54:54 -0600878}
879
Tom Zanussi7ef224d2016-03-03 12:54:42 -0600880static void event_hist_trigger(struct event_trigger_data *data, void *rec)
881{
882 struct hist_trigger_data *hist_data = data->private_data;
Tom Zanussi6a475cb2016-03-03 12:54:54 -0600883 bool use_compound_key = (hist_data->n_keys > 1);
Tom Zanussi69a02002016-03-03 12:54:52 -0600884 unsigned long entries[HIST_STACKTRACE_DEPTH];
Tom Zanussi76a3b0c2016-03-03 12:54:44 -0600885 char compound_key[HIST_KEY_SIZE_MAX];
Tom Zanussi69a02002016-03-03 12:54:52 -0600886 struct stack_trace stacktrace;
Tom Zanussi7ef224d2016-03-03 12:54:42 -0600887 struct hist_field *key_field;
888 struct tracing_map_elt *elt;
889 u64 field_contents;
890 void *key = NULL;
891 unsigned int i;
892
Tom Zanussi6a475cb2016-03-03 12:54:54 -0600893 memset(compound_key, 0, hist_data->key_size);
Tom Zanussi76a3b0c2016-03-03 12:54:44 -0600894
Tom Zanussi7ef224d2016-03-03 12:54:42 -0600895 for_each_hist_key_field(i, hist_data) {
896 key_field = hist_data->fields[i];
897
Tom Zanussi69a02002016-03-03 12:54:52 -0600898 if (key_field->flags & HIST_FIELD_FL_STACKTRACE) {
899 stacktrace.max_entries = HIST_STACKTRACE_DEPTH;
900 stacktrace.entries = entries;
901 stacktrace.nr_entries = 0;
902 stacktrace.skip = HIST_STACKTRACE_SKIP;
Tom Zanussi76a3b0c2016-03-03 12:54:44 -0600903
Tom Zanussi69a02002016-03-03 12:54:52 -0600904 memset(stacktrace.entries, 0, HIST_STACKTRACE_SIZE);
905 save_stack_trace(&stacktrace);
906
907 key = entries;
908 } else {
909 field_contents = key_field->fn(key_field, rec);
Tom Zanussi6a475cb2016-03-03 12:54:54 -0600910 if (key_field->flags & HIST_FIELD_FL_STRING) {
Tom Zanussi69a02002016-03-03 12:54:52 -0600911 key = (void *)(unsigned long)field_contents;
Tom Zanussi6a475cb2016-03-03 12:54:54 -0600912 use_compound_key = true;
913 } else
Tom Zanussi69a02002016-03-03 12:54:52 -0600914 key = (void *)&field_contents;
Tom Zanussi76a3b0c2016-03-03 12:54:44 -0600915 }
Tom Zanussi6a475cb2016-03-03 12:54:54 -0600916
917 if (use_compound_key)
918 add_to_key(compound_key, key, key_field, rec);
Tom Zanussi7ef224d2016-03-03 12:54:42 -0600919 }
920
Tom Zanussi6a475cb2016-03-03 12:54:54 -0600921 if (use_compound_key)
Tom Zanussi76a3b0c2016-03-03 12:54:44 -0600922 key = compound_key;
923
Tom Zanussi7ef224d2016-03-03 12:54:42 -0600924 elt = tracing_map_insert(hist_data->map, key);
925 if (elt)
926 hist_trigger_elt_update(hist_data, elt, rec);
927}
928
Tom Zanussi69a02002016-03-03 12:54:52 -0600929static void hist_trigger_stacktrace_print(struct seq_file *m,
930 unsigned long *stacktrace_entries,
931 unsigned int max_entries)
932{
933 char str[KSYM_SYMBOL_LEN];
934 unsigned int spaces = 8;
935 unsigned int i;
936
937 for (i = 0; i < max_entries; i++) {
938 if (stacktrace_entries[i] == ULONG_MAX)
939 return;
940
941 seq_printf(m, "%*c", 1 + spaces, ' ');
942 sprint_symbol(str, stacktrace_entries[i]);
943 seq_printf(m, "%s\n", str);
944 }
945}
946
Tom Zanussi7ef224d2016-03-03 12:54:42 -0600947static void
948hist_trigger_entry_print(struct seq_file *m,
949 struct hist_trigger_data *hist_data, void *key,
950 struct tracing_map_elt *elt)
951{
952 struct hist_field *key_field;
Tom Zanussic6afad42016-03-03 12:54:49 -0600953 char str[KSYM_SYMBOL_LEN];
Tom Zanussi69a02002016-03-03 12:54:52 -0600954 bool multiline = false;
Tom Zanussi7ef224d2016-03-03 12:54:42 -0600955 unsigned int i;
956 u64 uval;
957
958 seq_puts(m, "{ ");
959
960 for_each_hist_key_field(i, hist_data) {
961 key_field = hist_data->fields[i];
962
963 if (i > hist_data->n_vals)
964 seq_puts(m, ", ");
965
Tom Zanussi0c4a6b42016-03-03 12:54:48 -0600966 if (key_field->flags & HIST_FIELD_FL_HEX) {
967 uval = *(u64 *)(key + key_field->offset);
968 seq_printf(m, "%s: %llx",
969 key_field->field->name, uval);
Tom Zanussic6afad42016-03-03 12:54:49 -0600970 } else if (key_field->flags & HIST_FIELD_FL_SYM) {
971 uval = *(u64 *)(key + key_field->offset);
972 sprint_symbol_no_offset(str, uval);
973 seq_printf(m, "%s: [%llx] %-45s",
974 key_field->field->name, uval, str);
975 } else if (key_field->flags & HIST_FIELD_FL_SYM_OFFSET) {
976 uval = *(u64 *)(key + key_field->offset);
977 sprint_symbol(str, uval);
978 seq_printf(m, "%s: [%llx] %-55s",
979 key_field->field->name, uval, str);
Tom Zanussi6b4827a2016-03-03 12:54:50 -0600980 } else if (key_field->flags & HIST_FIELD_FL_EXECNAME) {
981 char *comm = elt->private_data;
982
983 uval = *(u64 *)(key + key_field->offset);
984 seq_printf(m, "%s: %-16s[%10llu]",
985 key_field->field->name, comm, uval);
Tom Zanussi31696192016-03-03 12:54:51 -0600986 } else if (key_field->flags & HIST_FIELD_FL_SYSCALL) {
987 const char *syscall_name;
988
989 uval = *(u64 *)(key + key_field->offset);
990 syscall_name = get_syscall_name(uval);
991 if (!syscall_name)
992 syscall_name = "unknown_syscall";
993
994 seq_printf(m, "%s: %-30s[%3llu]",
995 key_field->field->name, syscall_name, uval);
Tom Zanussi69a02002016-03-03 12:54:52 -0600996 } else if (key_field->flags & HIST_FIELD_FL_STACKTRACE) {
997 seq_puts(m, "stacktrace:\n");
998 hist_trigger_stacktrace_print(m,
999 key + key_field->offset,
1000 HIST_STACKTRACE_DEPTH);
1001 multiline = true;
Namhyung Kim4b94f5b2016-03-03 12:55:02 -06001002 } else if (key_field->flags & HIST_FIELD_FL_LOG2) {
1003 seq_printf(m, "%s: ~ 2^%-2llu", key_field->field->name,
1004 *(u64 *)(key + key_field->offset));
Tom Zanussi0c4a6b42016-03-03 12:54:48 -06001005 } else if (key_field->flags & HIST_FIELD_FL_STRING) {
Tom Zanussi7ef224d2016-03-03 12:54:42 -06001006 seq_printf(m, "%s: %-50s", key_field->field->name,
Tom Zanussi76a3b0c2016-03-03 12:54:44 -06001007 (char *)(key + key_field->offset));
Tom Zanussi7ef224d2016-03-03 12:54:42 -06001008 } else {
Tom Zanussi76a3b0c2016-03-03 12:54:44 -06001009 uval = *(u64 *)(key + key_field->offset);
1010 seq_printf(m, "%s: %10llu", key_field->field->name,
1011 uval);
Tom Zanussi7ef224d2016-03-03 12:54:42 -06001012 }
1013 }
1014
Tom Zanussi69a02002016-03-03 12:54:52 -06001015 if (!multiline)
1016 seq_puts(m, " ");
1017
1018 seq_puts(m, "}");
Tom Zanussi7ef224d2016-03-03 12:54:42 -06001019
1020 seq_printf(m, " hitcount: %10llu",
1021 tracing_map_read_sum(elt, HITCOUNT_IDX));
1022
Tom Zanussif2606832016-03-03 12:54:43 -06001023 for (i = 1; i < hist_data->n_vals; i++) {
Tom Zanussi0c4a6b42016-03-03 12:54:48 -06001024 if (hist_data->fields[i]->flags & HIST_FIELD_FL_HEX) {
1025 seq_printf(m, " %s: %10llx",
1026 hist_data->fields[i]->field->name,
1027 tracing_map_read_sum(elt, i));
1028 } else {
1029 seq_printf(m, " %s: %10llu",
1030 hist_data->fields[i]->field->name,
1031 tracing_map_read_sum(elt, i));
1032 }
Tom Zanussif2606832016-03-03 12:54:43 -06001033 }
1034
Tom Zanussi7ef224d2016-03-03 12:54:42 -06001035 seq_puts(m, "\n");
1036}
1037
1038static int print_entries(struct seq_file *m,
1039 struct hist_trigger_data *hist_data)
1040{
1041 struct tracing_map_sort_entry **sort_entries = NULL;
1042 struct tracing_map *map = hist_data->map;
Steven Rostedt (Red Hat)d50c7442016-03-08 17:17:15 -05001043 int i, n_entries;
Tom Zanussi7ef224d2016-03-03 12:54:42 -06001044
1045 n_entries = tracing_map_sort_entries(map, hist_data->sort_keys,
1046 hist_data->n_sort_keys,
1047 &sort_entries);
1048 if (n_entries < 0)
1049 return n_entries;
1050
1051 for (i = 0; i < n_entries; i++)
1052 hist_trigger_entry_print(m, hist_data,
1053 sort_entries[i]->key,
1054 sort_entries[i]->elt);
1055
1056 tracing_map_destroy_sort_entries(sort_entries, n_entries);
1057
1058 return n_entries;
1059}
1060
Tom Zanussi52a7f162016-03-03 12:54:57 -06001061static void hist_trigger_show(struct seq_file *m,
1062 struct event_trigger_data *data, int n)
Tom Zanussi7ef224d2016-03-03 12:54:42 -06001063{
Tom Zanussi7ef224d2016-03-03 12:54:42 -06001064 struct hist_trigger_data *hist_data;
1065 int n_entries, ret = 0;
1066
Tom Zanussi52a7f162016-03-03 12:54:57 -06001067 if (n > 0)
1068 seq_puts(m, "\n\n");
Tom Zanussi7ef224d2016-03-03 12:54:42 -06001069
1070 seq_puts(m, "# event histogram\n#\n# trigger info: ");
1071 data->ops->print(m, data->ops, data);
Tom Zanussi52a7f162016-03-03 12:54:57 -06001072 seq_puts(m, "#\n\n");
Tom Zanussi7ef224d2016-03-03 12:54:42 -06001073
1074 hist_data = data->private_data;
1075 n_entries = print_entries(m, hist_data);
1076 if (n_entries < 0) {
1077 ret = n_entries;
1078 n_entries = 0;
1079 }
1080
1081 seq_printf(m, "\nTotals:\n Hits: %llu\n Entries: %u\n Dropped: %llu\n",
1082 (u64)atomic64_read(&hist_data->map->hits),
1083 n_entries, (u64)atomic64_read(&hist_data->map->drops));
Tom Zanussi52a7f162016-03-03 12:54:57 -06001084}
1085
1086static int hist_show(struct seq_file *m, void *v)
1087{
1088 struct event_trigger_data *data;
1089 struct trace_event_file *event_file;
1090 int n = 0, ret = 0;
1091
1092 mutex_lock(&event_mutex);
1093
1094 event_file = event_file_data(m->private);
1095 if (unlikely(!event_file)) {
1096 ret = -ENODEV;
1097 goto out_unlock;
1098 }
1099
1100 list_for_each_entry_rcu(data, &event_file->triggers, list) {
1101 if (data->cmd_ops->trigger_type == ETT_EVENT_HIST)
1102 hist_trigger_show(m, data, n++);
1103 }
1104
Tom Zanussi7ef224d2016-03-03 12:54:42 -06001105 out_unlock:
1106 mutex_unlock(&event_mutex);
1107
1108 return ret;
1109}
1110
1111static int event_hist_open(struct inode *inode, struct file *file)
1112{
1113 return single_open(file, hist_show, file);
1114}
1115
1116const struct file_operations event_hist_fops = {
1117 .open = event_hist_open,
1118 .read = seq_read,
1119 .llseek = seq_lseek,
1120 .release = single_release,
1121};
1122
Tom Zanussi0c4a6b42016-03-03 12:54:48 -06001123static const char *get_hist_field_flags(struct hist_field *hist_field)
1124{
1125 const char *flags_str = NULL;
1126
1127 if (hist_field->flags & HIST_FIELD_FL_HEX)
1128 flags_str = "hex";
Tom Zanussic6afad42016-03-03 12:54:49 -06001129 else if (hist_field->flags & HIST_FIELD_FL_SYM)
1130 flags_str = "sym";
1131 else if (hist_field->flags & HIST_FIELD_FL_SYM_OFFSET)
1132 flags_str = "sym-offset";
Tom Zanussi6b4827a2016-03-03 12:54:50 -06001133 else if (hist_field->flags & HIST_FIELD_FL_EXECNAME)
1134 flags_str = "execname";
Tom Zanussi31696192016-03-03 12:54:51 -06001135 else if (hist_field->flags & HIST_FIELD_FL_SYSCALL)
1136 flags_str = "syscall";
Namhyung Kim4b94f5b2016-03-03 12:55:02 -06001137 else if (hist_field->flags & HIST_FIELD_FL_LOG2)
1138 flags_str = "log2";
Tom Zanussi0c4a6b42016-03-03 12:54:48 -06001139
1140 return flags_str;
1141}
1142
Tom Zanussi7ef224d2016-03-03 12:54:42 -06001143static void hist_field_print(struct seq_file *m, struct hist_field *hist_field)
1144{
1145 seq_printf(m, "%s", hist_field->field->name);
Tom Zanussi0c4a6b42016-03-03 12:54:48 -06001146 if (hist_field->flags) {
1147 const char *flags_str = get_hist_field_flags(hist_field);
1148
1149 if (flags_str)
1150 seq_printf(m, ".%s", flags_str);
1151 }
Tom Zanussi7ef224d2016-03-03 12:54:42 -06001152}
1153
1154static int event_hist_trigger_print(struct seq_file *m,
1155 struct event_trigger_ops *ops,
1156 struct event_trigger_data *data)
1157{
1158 struct hist_trigger_data *hist_data = data->private_data;
1159 struct hist_field *key_field;
1160 unsigned int i;
1161
Tom Zanussi5463bfd2016-03-03 12:54:59 -06001162 seq_puts(m, "hist:");
1163
1164 if (data->name)
1165 seq_printf(m, "%s:", data->name);
1166
1167 seq_puts(m, "keys=");
Tom Zanussi7ef224d2016-03-03 12:54:42 -06001168
1169 for_each_hist_key_field(i, hist_data) {
1170 key_field = hist_data->fields[i];
1171
1172 if (i > hist_data->n_vals)
1173 seq_puts(m, ",");
1174
Tom Zanussi69a02002016-03-03 12:54:52 -06001175 if (key_field->flags & HIST_FIELD_FL_STACKTRACE)
1176 seq_puts(m, "stacktrace");
1177 else
1178 hist_field_print(m, key_field);
Tom Zanussi7ef224d2016-03-03 12:54:42 -06001179 }
1180
1181 seq_puts(m, ":vals=");
Tom Zanussif2606832016-03-03 12:54:43 -06001182
1183 for_each_hist_val_field(i, hist_data) {
1184 if (i == HITCOUNT_IDX)
1185 seq_puts(m, "hitcount");
1186 else {
1187 seq_puts(m, ",");
1188 hist_field_print(m, hist_data->fields[i]);
1189 }
1190 }
Tom Zanussi7ef224d2016-03-03 12:54:42 -06001191
1192 seq_puts(m, ":sort=");
Tom Zanussie62347d2016-03-03 12:54:45 -06001193
1194 for (i = 0; i < hist_data->n_sort_keys; i++) {
1195 struct tracing_map_sort_key *sort_key;
1196
1197 sort_key = &hist_data->sort_keys[i];
1198
1199 if (i > 0)
1200 seq_puts(m, ",");
1201
1202 if (sort_key->field_idx == HITCOUNT_IDX)
1203 seq_puts(m, "hitcount");
1204 else {
1205 unsigned int idx = sort_key->field_idx;
1206
1207 if (WARN_ON(idx >= TRACING_MAP_FIELDS_MAX))
1208 return -EINVAL;
1209
1210 hist_field_print(m, hist_data->fields[idx]);
1211 }
1212
1213 if (sort_key->descending)
1214 seq_puts(m, ".descending");
1215 }
Tom Zanussi7ef224d2016-03-03 12:54:42 -06001216
1217 seq_printf(m, ":size=%u", (1 << hist_data->map->map_bits));
1218
1219 if (data->filter_str)
1220 seq_printf(m, " if %s", data->filter_str);
1221
Tom Zanussi83e99912016-03-03 12:54:46 -06001222 if (data->paused)
1223 seq_puts(m, " [paused]");
1224 else
1225 seq_puts(m, " [active]");
Tom Zanussi7ef224d2016-03-03 12:54:42 -06001226
1227 seq_putc(m, '\n');
1228
1229 return 0;
1230}
1231
Tom Zanussi5463bfd2016-03-03 12:54:59 -06001232static int event_hist_trigger_init(struct event_trigger_ops *ops,
1233 struct event_trigger_data *data)
1234{
1235 struct hist_trigger_data *hist_data = data->private_data;
1236
1237 if (!data->ref && hist_data->attrs->name)
1238 save_named_trigger(hist_data->attrs->name, data);
1239
1240 data->ref++;
1241
1242 return 0;
1243}
1244
Tom Zanussi7ef224d2016-03-03 12:54:42 -06001245static void event_hist_trigger_free(struct event_trigger_ops *ops,
1246 struct event_trigger_data *data)
1247{
1248 struct hist_trigger_data *hist_data = data->private_data;
1249
1250 if (WARN_ON_ONCE(data->ref <= 0))
1251 return;
1252
1253 data->ref--;
1254 if (!data->ref) {
Tom Zanussi5463bfd2016-03-03 12:54:59 -06001255 if (data->name)
1256 del_named_trigger(data);
Tom Zanussi7ef224d2016-03-03 12:54:42 -06001257 trigger_data_free(data);
1258 destroy_hist_data(hist_data);
1259 }
1260}
1261
1262static struct event_trigger_ops event_hist_trigger_ops = {
1263 .func = event_hist_trigger,
1264 .print = event_hist_trigger_print,
Tom Zanussi5463bfd2016-03-03 12:54:59 -06001265 .init = event_hist_trigger_init,
Tom Zanussi7ef224d2016-03-03 12:54:42 -06001266 .free = event_hist_trigger_free,
1267};
1268
Tom Zanussi5463bfd2016-03-03 12:54:59 -06001269static int event_hist_trigger_named_init(struct event_trigger_ops *ops,
1270 struct event_trigger_data *data)
1271{
1272 data->ref++;
1273
1274 save_named_trigger(data->named_data->name, data);
1275
1276 event_hist_trigger_init(ops, data->named_data);
1277
1278 return 0;
1279}
1280
1281static void event_hist_trigger_named_free(struct event_trigger_ops *ops,
1282 struct event_trigger_data *data)
1283{
1284 if (WARN_ON_ONCE(data->ref <= 0))
1285 return;
1286
1287 event_hist_trigger_free(ops, data->named_data);
1288
1289 data->ref--;
1290 if (!data->ref) {
1291 del_named_trigger(data);
1292 trigger_data_free(data);
1293 }
1294}
1295
1296static struct event_trigger_ops event_hist_trigger_named_ops = {
1297 .func = event_hist_trigger,
1298 .print = event_hist_trigger_print,
1299 .init = event_hist_trigger_named_init,
1300 .free = event_hist_trigger_named_free,
1301};
1302
Tom Zanussi7ef224d2016-03-03 12:54:42 -06001303static struct event_trigger_ops *event_hist_get_trigger_ops(char *cmd,
1304 char *param)
1305{
1306 return &event_hist_trigger_ops;
1307}
1308
Tom Zanussie86ae9b2016-03-03 12:54:47 -06001309static void hist_clear(struct event_trigger_data *data)
1310{
1311 struct hist_trigger_data *hist_data = data->private_data;
Tom Zanussie86ae9b2016-03-03 12:54:47 -06001312
Tom Zanussi5463bfd2016-03-03 12:54:59 -06001313 if (data->name)
1314 pause_named_trigger(data);
Tom Zanussie86ae9b2016-03-03 12:54:47 -06001315
1316 synchronize_sched();
1317
1318 tracing_map_clear(hist_data->map);
1319
Tom Zanussi5463bfd2016-03-03 12:54:59 -06001320 if (data->name)
1321 unpause_named_trigger(data);
1322}
1323
1324static bool compatible_field(struct ftrace_event_field *field,
1325 struct ftrace_event_field *test_field)
1326{
1327 if (field == test_field)
1328 return true;
1329 if (field == NULL || test_field == NULL)
1330 return false;
1331 if (strcmp(field->name, test_field->name) != 0)
1332 return false;
1333 if (strcmp(field->type, test_field->type) != 0)
1334 return false;
1335 if (field->size != test_field->size)
1336 return false;
1337 if (field->is_signed != test_field->is_signed)
1338 return false;
1339
1340 return true;
Tom Zanussie86ae9b2016-03-03 12:54:47 -06001341}
1342
Tom Zanussi52a7f162016-03-03 12:54:57 -06001343static bool hist_trigger_match(struct event_trigger_data *data,
Tom Zanussi5463bfd2016-03-03 12:54:59 -06001344 struct event_trigger_data *data_test,
1345 struct event_trigger_data *named_data,
1346 bool ignore_filter)
Tom Zanussi52a7f162016-03-03 12:54:57 -06001347{
1348 struct tracing_map_sort_key *sort_key, *sort_key_test;
1349 struct hist_trigger_data *hist_data, *hist_data_test;
1350 struct hist_field *key_field, *key_field_test;
1351 unsigned int i;
1352
Tom Zanussi5463bfd2016-03-03 12:54:59 -06001353 if (named_data && (named_data != data_test) &&
1354 (named_data != data_test->named_data))
1355 return false;
1356
1357 if (!named_data && is_named_trigger(data_test))
1358 return false;
1359
Tom Zanussi52a7f162016-03-03 12:54:57 -06001360 hist_data = data->private_data;
1361 hist_data_test = data_test->private_data;
1362
1363 if (hist_data->n_vals != hist_data_test->n_vals ||
1364 hist_data->n_fields != hist_data_test->n_fields ||
1365 hist_data->n_sort_keys != hist_data_test->n_sort_keys)
1366 return false;
1367
Tom Zanussi5463bfd2016-03-03 12:54:59 -06001368 if (!ignore_filter) {
1369 if ((data->filter_str && !data_test->filter_str) ||
1370 (!data->filter_str && data_test->filter_str))
1371 return false;
1372 }
Tom Zanussi52a7f162016-03-03 12:54:57 -06001373
1374 for_each_hist_field(i, hist_data) {
1375 key_field = hist_data->fields[i];
1376 key_field_test = hist_data_test->fields[i];
1377
1378 if (key_field->flags != key_field_test->flags)
1379 return false;
Tom Zanussi5463bfd2016-03-03 12:54:59 -06001380 if (!compatible_field(key_field->field, key_field_test->field))
Tom Zanussi52a7f162016-03-03 12:54:57 -06001381 return false;
1382 if (key_field->offset != key_field_test->offset)
1383 return false;
1384 }
1385
1386 for (i = 0; i < hist_data->n_sort_keys; i++) {
1387 sort_key = &hist_data->sort_keys[i];
1388 sort_key_test = &hist_data_test->sort_keys[i];
1389
1390 if (sort_key->field_idx != sort_key_test->field_idx ||
1391 sort_key->descending != sort_key_test->descending)
1392 return false;
1393 }
1394
Tom Zanussi5463bfd2016-03-03 12:54:59 -06001395 if (!ignore_filter && data->filter_str &&
Tom Zanussi52a7f162016-03-03 12:54:57 -06001396 (strcmp(data->filter_str, data_test->filter_str) != 0))
1397 return false;
1398
1399 return true;
1400}
1401
Tom Zanussi7ef224d2016-03-03 12:54:42 -06001402static int hist_register_trigger(char *glob, struct event_trigger_ops *ops,
1403 struct event_trigger_data *data,
1404 struct trace_event_file *file)
1405{
Tom Zanussi83e99912016-03-03 12:54:46 -06001406 struct hist_trigger_data *hist_data = data->private_data;
Tom Zanussi5463bfd2016-03-03 12:54:59 -06001407 struct event_trigger_data *test, *named_data = NULL;
Tom Zanussi7ef224d2016-03-03 12:54:42 -06001408 int ret = 0;
1409
Tom Zanussi5463bfd2016-03-03 12:54:59 -06001410 if (hist_data->attrs->name) {
1411 named_data = find_named_trigger(hist_data->attrs->name);
1412 if (named_data) {
1413 if (!hist_trigger_match(data, named_data, named_data,
1414 true)) {
1415 ret = -EINVAL;
1416 goto out;
1417 }
1418 }
1419 }
1420
1421 if (hist_data->attrs->name && !named_data)
1422 goto new;
1423
Tom Zanussi7ef224d2016-03-03 12:54:42 -06001424 list_for_each_entry_rcu(test, &file->triggers, list) {
1425 if (test->cmd_ops->trigger_type == ETT_EVENT_HIST) {
Tom Zanussi5463bfd2016-03-03 12:54:59 -06001426 if (!hist_trigger_match(data, test, named_data, false))
Tom Zanussi52a7f162016-03-03 12:54:57 -06001427 continue;
Tom Zanussi83e99912016-03-03 12:54:46 -06001428 if (hist_data->attrs->pause)
1429 test->paused = true;
1430 else if (hist_data->attrs->cont)
1431 test->paused = false;
Tom Zanussie86ae9b2016-03-03 12:54:47 -06001432 else if (hist_data->attrs->clear)
1433 hist_clear(test);
Tom Zanussi83e99912016-03-03 12:54:46 -06001434 else
1435 ret = -EEXIST;
Tom Zanussi7ef224d2016-03-03 12:54:42 -06001436 goto out;
1437 }
1438 }
Tom Zanussi5463bfd2016-03-03 12:54:59 -06001439 new:
Tom Zanussie86ae9b2016-03-03 12:54:47 -06001440 if (hist_data->attrs->cont || hist_data->attrs->clear) {
Tom Zanussi83e99912016-03-03 12:54:46 -06001441 ret = -ENOENT;
1442 goto out;
1443 }
1444
Tom Zanussi7522c032016-06-29 19:56:00 -05001445 if (hist_data->attrs->pause)
1446 data->paused = true;
1447
Tom Zanussi5463bfd2016-03-03 12:54:59 -06001448 if (named_data) {
1449 destroy_hist_data(data->private_data);
1450 data->private_data = named_data->private_data;
1451 set_named_trigger_data(data, named_data);
1452 data->ops = &event_hist_trigger_named_ops;
1453 }
1454
Tom Zanussi7ef224d2016-03-03 12:54:42 -06001455 if (data->ops->init) {
1456 ret = data->ops->init(data->ops, data);
1457 if (ret < 0)
1458 goto out;
1459 }
1460
1461 list_add_rcu(&data->list, &file->triggers);
1462 ret++;
1463
1464 update_cond_flag(file);
Tom Zanussi5463bfd2016-03-03 12:54:59 -06001465
Tom Zanussi7ef224d2016-03-03 12:54:42 -06001466 if (trace_event_trigger_enable_disable(file, 1) < 0) {
1467 list_del_rcu(&data->list);
1468 update_cond_flag(file);
1469 ret--;
1470 }
1471 out:
1472 return ret;
1473}
1474
Tom Zanussi52a7f162016-03-03 12:54:57 -06001475static void hist_unregister_trigger(char *glob, struct event_trigger_ops *ops,
1476 struct event_trigger_data *data,
1477 struct trace_event_file *file)
1478{
Tom Zanussi5463bfd2016-03-03 12:54:59 -06001479 struct hist_trigger_data *hist_data = data->private_data;
1480 struct event_trigger_data *test, *named_data = NULL;
Tom Zanussi52a7f162016-03-03 12:54:57 -06001481 bool unregistered = false;
1482
Tom Zanussi5463bfd2016-03-03 12:54:59 -06001483 if (hist_data->attrs->name)
1484 named_data = find_named_trigger(hist_data->attrs->name);
1485
Tom Zanussi52a7f162016-03-03 12:54:57 -06001486 list_for_each_entry_rcu(test, &file->triggers, list) {
1487 if (test->cmd_ops->trigger_type == ETT_EVENT_HIST) {
Tom Zanussi5463bfd2016-03-03 12:54:59 -06001488 if (!hist_trigger_match(data, test, named_data, false))
Tom Zanussi52a7f162016-03-03 12:54:57 -06001489 continue;
1490 unregistered = true;
1491 list_del_rcu(&test->list);
1492 trace_event_trigger_enable_disable(file, 0);
1493 update_cond_flag(file);
1494 break;
1495 }
1496 }
1497
1498 if (unregistered && test->ops->free)
1499 test->ops->free(test->ops, test);
1500}
1501
1502static void hist_unreg_all(struct trace_event_file *file)
1503{
Steven Rostedt47c18562016-06-29 19:55:59 -05001504 struct event_trigger_data *test, *n;
Tom Zanussi52a7f162016-03-03 12:54:57 -06001505
Steven Rostedt47c18562016-06-29 19:55:59 -05001506 list_for_each_entry_safe(test, n, &file->triggers, list) {
Tom Zanussi52a7f162016-03-03 12:54:57 -06001507 if (test->cmd_ops->trigger_type == ETT_EVENT_HIST) {
1508 list_del_rcu(&test->list);
1509 trace_event_trigger_enable_disable(file, 0);
1510 update_cond_flag(file);
1511 if (test->ops->free)
1512 test->ops->free(test->ops, test);
1513 }
1514 }
1515}
1516
Tom Zanussi7ef224d2016-03-03 12:54:42 -06001517static int event_hist_trigger_func(struct event_command *cmd_ops,
1518 struct trace_event_file *file,
1519 char *glob, char *cmd, char *param)
1520{
1521 unsigned int hist_trigger_bits = TRACING_MAP_BITS_DEFAULT;
1522 struct event_trigger_data *trigger_data;
1523 struct hist_trigger_attrs *attrs;
1524 struct event_trigger_ops *trigger_ops;
1525 struct hist_trigger_data *hist_data;
1526 char *trigger;
1527 int ret = 0;
1528
1529 if (!param)
1530 return -EINVAL;
1531
1532 /* separate the trigger from the filter (k:v [if filter]) */
1533 trigger = strsep(&param, " \t");
1534 if (!trigger)
1535 return -EINVAL;
1536
1537 attrs = parse_hist_trigger_attrs(trigger);
1538 if (IS_ERR(attrs))
1539 return PTR_ERR(attrs);
1540
1541 if (attrs->map_bits)
1542 hist_trigger_bits = attrs->map_bits;
1543
1544 hist_data = create_hist_data(hist_trigger_bits, attrs, file);
1545 if (IS_ERR(hist_data)) {
1546 destroy_hist_trigger_attrs(attrs);
1547 return PTR_ERR(hist_data);
1548 }
1549
1550 trigger_ops = cmd_ops->get_trigger_ops(cmd, trigger);
1551
1552 ret = -ENOMEM;
1553 trigger_data = kzalloc(sizeof(*trigger_data), GFP_KERNEL);
1554 if (!trigger_data)
1555 goto out_free;
1556
1557 trigger_data->count = -1;
1558 trigger_data->ops = trigger_ops;
1559 trigger_data->cmd_ops = cmd_ops;
1560
1561 INIT_LIST_HEAD(&trigger_data->list);
1562 RCU_INIT_POINTER(trigger_data->filter, NULL);
1563
1564 trigger_data->private_data = hist_data;
1565
Tom Zanussi52a7f162016-03-03 12:54:57 -06001566 /* if param is non-empty, it's supposed to be a filter */
1567 if (param && cmd_ops->set_filter) {
1568 ret = cmd_ops->set_filter(param, trigger_data, file);
1569 if (ret < 0)
1570 goto out_free;
1571 }
1572
Tom Zanussi7ef224d2016-03-03 12:54:42 -06001573 if (glob[0] == '!') {
1574 cmd_ops->unreg(glob+1, trigger_ops, trigger_data, file);
1575 ret = 0;
1576 goto out_free;
1577 }
1578
Tom Zanussi7ef224d2016-03-03 12:54:42 -06001579 ret = cmd_ops->reg(glob, trigger_ops, trigger_data, file);
1580 /*
1581 * The above returns on success the # of triggers registered,
1582 * but if it didn't register any it returns zero. Consider no
1583 * triggers registered a failure too.
1584 */
1585 if (!ret) {
Tom Zanussie86ae9b2016-03-03 12:54:47 -06001586 if (!(attrs->pause || attrs->cont || attrs->clear))
Tom Zanussi83e99912016-03-03 12:54:46 -06001587 ret = -ENOENT;
Tom Zanussi7ef224d2016-03-03 12:54:42 -06001588 goto out_free;
1589 } else if (ret < 0)
1590 goto out_free;
1591 /* Just return zero, not the number of registered triggers */
1592 ret = 0;
1593 out:
1594 return ret;
1595 out_free:
1596 if (cmd_ops->set_filter)
1597 cmd_ops->set_filter(NULL, trigger_data, NULL);
1598
1599 kfree(trigger_data);
1600
1601 destroy_hist_data(hist_data);
1602 goto out;
1603}
1604
1605static struct event_command trigger_hist_cmd = {
1606 .name = "hist",
1607 .trigger_type = ETT_EVENT_HIST,
1608 .flags = EVENT_CMD_FL_NEEDS_REC,
1609 .func = event_hist_trigger_func,
1610 .reg = hist_register_trigger,
Tom Zanussi52a7f162016-03-03 12:54:57 -06001611 .unreg = hist_unregister_trigger,
1612 .unreg_all = hist_unreg_all,
Tom Zanussi7ef224d2016-03-03 12:54:42 -06001613 .get_trigger_ops = event_hist_get_trigger_ops,
1614 .set_filter = set_trigger_filter,
1615};
1616
1617__init int register_trigger_hist_cmd(void)
1618{
1619 int ret;
1620
1621 ret = register_event_command(&trigger_hist_cmd);
1622 WARN_ON(ret < 0);
1623
1624 return ret;
1625}
Tom Zanussid0bad492016-03-03 12:54:55 -06001626
1627static void
1628hist_enable_trigger(struct event_trigger_data *data, void *rec)
1629{
1630 struct enable_trigger_data *enable_data = data->private_data;
1631 struct event_trigger_data *test;
1632
1633 list_for_each_entry_rcu(test, &enable_data->file->triggers, list) {
1634 if (test->cmd_ops->trigger_type == ETT_EVENT_HIST) {
1635 if (enable_data->enable)
1636 test->paused = false;
1637 else
1638 test->paused = true;
Tom Zanussid0bad492016-03-03 12:54:55 -06001639 }
1640 }
1641}
1642
1643static void
1644hist_enable_count_trigger(struct event_trigger_data *data, void *rec)
1645{
1646 if (!data->count)
1647 return;
1648
1649 if (data->count != -1)
1650 (data->count)--;
1651
1652 hist_enable_trigger(data, rec);
1653}
1654
1655static struct event_trigger_ops hist_enable_trigger_ops = {
1656 .func = hist_enable_trigger,
1657 .print = event_enable_trigger_print,
1658 .init = event_trigger_init,
1659 .free = event_enable_trigger_free,
1660};
1661
1662static struct event_trigger_ops hist_enable_count_trigger_ops = {
1663 .func = hist_enable_count_trigger,
1664 .print = event_enable_trigger_print,
1665 .init = event_trigger_init,
1666 .free = event_enable_trigger_free,
1667};
1668
1669static struct event_trigger_ops hist_disable_trigger_ops = {
1670 .func = hist_enable_trigger,
1671 .print = event_enable_trigger_print,
1672 .init = event_trigger_init,
1673 .free = event_enable_trigger_free,
1674};
1675
1676static struct event_trigger_ops hist_disable_count_trigger_ops = {
1677 .func = hist_enable_count_trigger,
1678 .print = event_enable_trigger_print,
1679 .init = event_trigger_init,
1680 .free = event_enable_trigger_free,
1681};
1682
1683static struct event_trigger_ops *
1684hist_enable_get_trigger_ops(char *cmd, char *param)
1685{
1686 struct event_trigger_ops *ops;
1687 bool enable;
1688
1689 enable = (strcmp(cmd, ENABLE_HIST_STR) == 0);
1690
1691 if (enable)
1692 ops = param ? &hist_enable_count_trigger_ops :
1693 &hist_enable_trigger_ops;
1694 else
1695 ops = param ? &hist_disable_count_trigger_ops :
1696 &hist_disable_trigger_ops;
1697
1698 return ops;
1699}
1700
Tom Zanussi52a7f162016-03-03 12:54:57 -06001701static void hist_enable_unreg_all(struct trace_event_file *file)
1702{
Steven Rostedt47c18562016-06-29 19:55:59 -05001703 struct event_trigger_data *test, *n;
Tom Zanussi52a7f162016-03-03 12:54:57 -06001704
Steven Rostedt47c18562016-06-29 19:55:59 -05001705 list_for_each_entry_safe(test, n, &file->triggers, list) {
Tom Zanussi52a7f162016-03-03 12:54:57 -06001706 if (test->cmd_ops->trigger_type == ETT_HIST_ENABLE) {
1707 list_del_rcu(&test->list);
1708 update_cond_flag(file);
1709 trace_event_trigger_enable_disable(file, 0);
1710 if (test->ops->free)
1711 test->ops->free(test->ops, test);
1712 }
1713 }
1714}
1715
Tom Zanussid0bad492016-03-03 12:54:55 -06001716static struct event_command trigger_hist_enable_cmd = {
1717 .name = ENABLE_HIST_STR,
1718 .trigger_type = ETT_HIST_ENABLE,
1719 .func = event_enable_trigger_func,
1720 .reg = event_enable_register_trigger,
1721 .unreg = event_enable_unregister_trigger,
Tom Zanussi52a7f162016-03-03 12:54:57 -06001722 .unreg_all = hist_enable_unreg_all,
Tom Zanussid0bad492016-03-03 12:54:55 -06001723 .get_trigger_ops = hist_enable_get_trigger_ops,
1724 .set_filter = set_trigger_filter,
1725};
1726
1727static struct event_command trigger_hist_disable_cmd = {
1728 .name = DISABLE_HIST_STR,
1729 .trigger_type = ETT_HIST_ENABLE,
1730 .func = event_enable_trigger_func,
1731 .reg = event_enable_register_trigger,
1732 .unreg = event_enable_unregister_trigger,
Tom Zanussi52a7f162016-03-03 12:54:57 -06001733 .unreg_all = hist_enable_unreg_all,
Tom Zanussid0bad492016-03-03 12:54:55 -06001734 .get_trigger_ops = hist_enable_get_trigger_ops,
1735 .set_filter = set_trigger_filter,
1736};
1737
1738static __init void unregister_trigger_hist_enable_disable_cmds(void)
1739{
1740 unregister_event_command(&trigger_hist_enable_cmd);
1741 unregister_event_command(&trigger_hist_disable_cmd);
1742}
1743
1744__init int register_trigger_hist_enable_disable_cmds(void)
1745{
1746 int ret;
1747
1748 ret = register_event_command(&trigger_hist_enable_cmd);
1749 if (WARN_ON(ret < 0))
1750 return ret;
1751 ret = register_event_command(&trigger_hist_disable_cmd);
1752 if (WARN_ON(ret < 0))
1753 unregister_trigger_hist_enable_disable_cmds();
1754
1755 return ret;
1756}