1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Common header file for generic dynamic events.
6 #ifndef _TRACE_DYNEVENT_H
7 #define _TRACE_DYNEVENT_H
9 #include <linux/kernel.h>
10 #include <linux/list.h>
11 #include <linux/mutex.h>
12 #include <linux/seq_file.h>
19 * struct dyn_event_operations - Methods for each type of dynamic events
21 * These methods must be set for each type, since there is no default method.
22 * Before using this for dyn_event_init(), it must be registered by
23 * dyn_event_register().
25 * @create: Parse and create event method. This is invoked when user passes
26 * a event definition to dynamic_events interface. This must not destruct
27 * the arguments and return -ECANCELED if given arguments doesn't match its
29 * @show: Showing method. This is invoked when user reads the event definitions
30 * via dynamic_events interface.
31 * @is_busy: Check whether given event is busy so that it can not be deleted.
32 * Return true if it is busy, otherwides false.
33 * @free: Delete the given event. Return 0 if success, otherwides error.
34 * @match: Check whether given event and system name match this event.
35 * Return true if it matches, otherwides false.
37 * Except for @create, these methods are called under holding event_mutex.
39 struct dyn_event_operations
{
40 struct list_head list
;
41 int (*create
)(int argc
, const char *argv
[]);
42 int (*show
)(struct seq_file
*m
, struct dyn_event
*ev
);
43 bool (*is_busy
)(struct dyn_event
*ev
);
44 int (*free
)(struct dyn_event
*ev
);
45 bool (*match
)(const char *system
, const char *event
,
46 struct dyn_event
*ev
);
49 /* Register new dyn_event type -- must be called at first */
50 int dyn_event_register(struct dyn_event_operations
*ops
);
53 * struct dyn_event - Dynamic event list header
55 * The dyn_event structure encapsulates a list and a pointer to the operators
56 * for making a global list of dynamic events.
57 * User must includes this in each event structure, so that those events can
58 * be added/removed via dynamic_events interface.
61 struct list_head list
;
62 struct dyn_event_operations
*ops
;
65 extern struct list_head dyn_event_list
;
68 int dyn_event_init(struct dyn_event
*ev
, struct dyn_event_operations
*ops
)
73 INIT_LIST_HEAD(&ev
->list
);
78 static inline int dyn_event_add(struct dyn_event
*ev
)
80 lockdep_assert_held(&event_mutex
);
85 list_add_tail(&ev
->list
, &dyn_event_list
);
89 static inline void dyn_event_remove(struct dyn_event
*ev
)
91 lockdep_assert_held(&event_mutex
);
92 list_del_init(&ev
->list
);
95 void *dyn_event_seq_start(struct seq_file
*m
, loff_t
*pos
);
96 void *dyn_event_seq_next(struct seq_file
*m
, void *v
, loff_t
*pos
);
97 void dyn_event_seq_stop(struct seq_file
*m
, void *v
);
98 int dyn_events_release_all(struct dyn_event_operations
*type
);
99 int dyn_event_release(int argc
, char **argv
, struct dyn_event_operations
*type
);
102 * for_each_dyn_event - iterate over the dyn_event list
103 * @pos: the struct dyn_event * to use as a loop cursor
105 * This is just a basement of for_each macro. Wrap this for
106 * each actual event structure with ops filtering.
108 #define for_each_dyn_event(pos) \
109 list_for_each_entry(pos, &dyn_event_list, list)
112 * for_each_dyn_event - iterate over the dyn_event list safely
113 * @pos: the struct dyn_event * to use as a loop cursor
114 * @n: the struct dyn_event * to use as temporary storage
116 #define for_each_dyn_event_safe(pos, n) \
117 list_for_each_entry_safe(pos, n, &dyn_event_list, list)