tracing: Unifying dynamic event interface
Subsystems (2)
Masami Hiramatsu
maintainercover tracing: Unifying dynamic event interface
Hi,
This is an RFC series of unifying dynamic event interface on ftrace. Currently ftrace has 3 dynamic event interfaces, kprobes, uprobes and synthetic. This series unifies kprobes and uprobes event interface on "dynamic_events". This enables us to add new dynamic events easily on same interface, e.g. function events. The older interfaces are left on the tracefs for backward compatibility at this moment.
dynamic_events syntax has no different from kprobe_events and uprobe_events. You can use same syntax for dynamic_events interface.
I think we can integrate synthetic events to this dynamic_events interface but it will requires new syntax. e.g.
echo "s:<event-name> <args>" >> dynamic_events
If it is OK, I'll add it in next version.
BTW, since this dynamic_events interface derived from *probe_events, it inherits "all clear when truncate file open" behavior. But if you think this is too aggressive, I can drop it. (even in that case, kprobe_events/uprobe_events behavior is not changed)
I also introduced a widely used way to erase entries in other interfaces of ftrace, that is '!'. So you can now use '!event-name' or '!group/event' to erase an entry in dynamic_events. (Wait... it has to be '!p:event' as others do??)
Any thought?
Thank you,
---
Masami Hiramatsu (5):
tracing/uprobes: Add busy check when cleanup all uprobes
tracing: Add a unified dynamic event framework tracing/kprobes: Use dyn_event framework for kprobe events tracing/uprobes: Use dyn_event framework for uprobe events
tracing: Add generic event-name based remove event method
Documentation/trace/kprobetrace.rst | 3 + Documentation/trace/uprobetracer.rst | 4 + kernel/trace/Kconfig | 4 + kernel/trace/Makefile | 1 kernel/trace/trace.c | 4 + kernel/trace/trace_dynevent.c | 183 +++++++++++++++++++++++++++++++++ kernel/trace/trace_dynevent.h | 89 ++++++++++++++++ kernel/trace/trace_kprobe.c | 191 +++++++++++++++++++++++----------- kernel/trace/trace_uprobe.c | 175 +++++++++++++++++++++++-------- 9 files changed, 547 insertions(+), 107 deletions(-) create mode 100644 kernel/trace/trace_dynevent.c create mode 100644 kernel/trace/trace_dynevent.h
--
Masami Hiramatsu (Linaro) <[email protected]>
Masami Hiramatsu
maintainerRFC PATCH 1/5 tracing/uprobes: Add busy check when cleanup all uprobes
Add a busy check loop in cleanup_all_probes() before trying to remove all events in uprobe_events as same as kprobe_events does.
Without this change, writing null to uprobe_events will try to remove events but if one of them is enabled, it stopped there but some of events are already cleared.
With this change, writing null to uprobe_events make sure all events are not enabled before removing events. So, it clears all events, or return an error (-EBUSY) with keeping all events.
--- kernel/trace/trace_uprobe.c | 7 +++++++ 1 file changed, 7 insertions(+)
kernel/trace/trace_uprobe.c +7 -0
@@ -609,12 +609,19 @@ static int cleanup_all_probes(void)int ret =0 ;mutex_lock (&uprobe_lock); +/* Ensure no probe is in use. */ +list_for_each_entry (tu, &uprobe_list, list) +if (trace_probe_is_enabled (&tu->tp)) { + ret = -EBUSY ; + goto end; + }while (!list_empty (&uprobe_list)) { tu = list_entry(uprobe_list.next, struct trace_uprobe, list); ret =unregister_trace_uprobe (tu);if (ret)break ; } +end:mutex_unlock (&uprobe_lock);return ret; }
Masami Hiramatsu
maintainerRFC PATCH 2/5 tracing: Add a unified dynamic event framework
In reply to Masami HiramatsuAdd an unified dynamic event framework for kprobes and uprobes. Those dynamic events can be co-exist on same file because those syntax doesn't over-wrapped.
This introduces a framework part which provides a
unified tracefs interface and operations.
--- kernel/trace/Kconfig | 3 + kernel/trace/Makefile | 1 kernel/trace/trace.c | 4 + kernel/trace/trace_dynevent.c | 149 +++++++++++++++++++++++++++++++++++++++++ kernel/trace/trace_dynevent.h | 87 ++++++++++++++++++++++++ 5 files changed, 244 insertions(+) create mode 100644 kernel/trace/trace_dynevent.c create mode 100644 kernel/trace/trace_dynevent.h
kernel/trace/Kconfig +3 -0
@@ -518,6 +518,9 @@ config BPF_EVENTS help This allows the user to attach BPF programs to kprobe events. +config DYNAMIC_EVENTS + def_bool n + config PROBE_EVENTS def_bool n
kernel/trace/Makefile +1 -0
@@ -78,6 +78,7 @@ endif ifeq ($(CONFIG_TRACING),y) obj-$(CONFIG_KGDB_KDB) += trace_kdb.o endif +obj-$(CONFIG_DYNAMIC_EVENTS) += trace_dynevent.o obj-$(CONFIG_PROBE_EVENTS) += trace_probe.o obj-$(CONFIG_UPROBE_EVENTS) += trace_uprobe.o
kernel/trace/trace.c +4 -0
@@ -4603,6 +4603,10 @@ static const char readme_msg[] = "\t\t\t traces\n"#endif #endif /* CONFIG_STACK_TRACER */ +#ifdef CONFIG_DYNAMIC_EVENTS +" dynamic_events\t\t- Add/remove/show the generic dynamic events\n" + "\t\t\t Write into this file to define/undefine new trace events.\n" +#endif #ifdef CONFIG_KPROBE_EVENTS " kprobe_events\t\t- Add/remove/show the kernel dynamic events\n" "\t\t\t Write into this file to define/undefine new trace events.\n"
kernel/trace/trace_dynevent.c new file +149 -0
149 lines not on this page · raw message
kernel/trace/trace_dynevent.h new file +87 -0
87 lines not on this page · raw message
Masami Hiramatsu
maintainerRFC PATCH 3/5 tracing/kprobes: Use dyn_event framework for kprobe events
In reply to Masami HiramatsuUse dyn_event framework for kprobe events. This shows kprobe events on "tracing/dynamic_events" file.
User can also define new events via tracing/dynamic_events.
--- Documentation/trace/kprobetrace.rst | 3 + kernel/trace/Kconfig | 1 kernel/trace/trace_kprobe.c | 179 +++++++++++++++++++++++------------ 3 files changed, 124 insertions(+), 59 deletions(-)
Documentation/trace/kprobetrace.rst +3 -0
@@ -20,6 +20,9 @@ current_tracer. Instead of that, add probe points via /sys/kernel/debug/tracing/kprobe_events, and enable it via /sys/kernel/debug/tracing/events/kprobes/<EVENT>/enable. +You can also use /sys/kernel/debug/tracing/dynamic_events instead of +kprobe_events. That interface will provide unified access to other +dynamic events too. Synopsis of kprobe_events -------------------------
kernel/trace/Kconfig +1 -0
@@ -461,6 +461,7 @@ config KPROBE_EVENTS bool "Enable kprobes-based dynamic events" select TRACING select PROBE_EVENTS + select DYNAMIC_EVENTS default y help This allows the user to add tracing events (similar to tracepoints)
kernel/trace/trace_kprobe.c +120 -59
384 lines not on this page · raw message
Masami Hiramatsu
maintainerRFC PATCH 4/5 tracing/uprobes: Use dyn_event framework for uprobe events
In reply to Masami HiramatsuUse dyn_event framework for uprobe events. This shows uprobe events on "dynamic_events" file.
User can also define new uprobe events via dynamic_events.
--- Documentation/trace/uprobetracer.rst | 4 + kernel/trace/trace_uprobe.c | 158 +++++++++++++++++++++++----------- 2 files changed, 113 insertions(+), 49 deletions(-)
Documentation/trace/uprobetracer.rst +4 -0
@@ -18,6 +18,10 @@ current_tracer. Instead of that, add probe points via However unlike kprobe-event tracer, the uprobe event interface expects the user to calculate the offset of the probepoint in the object. +You can also use /sys/kernel/debug/tracing/dynamic_events instead of +uprobe_events. That interface will provide unified access to other +dynamic events too. + Synopsis of uprobe_tracer ------------------------- ::
kernel/trace/trace_uprobe.c +109 -49
328 lines not on this page · raw message
Masami Hiramatsu
maintainerRFC PATCH 5/5 tracing: Add generic event-name based remove event method
In reply to Masami HiramatsuAdd a generic method to remove event from dynamic event list. This is same as other system under ftrace. You just need to pass the event name with '!' prefix, e.g.
# echo p:new_grp/new_event _do_fork > dynamic_events
This creates an event, and
# echo '!new_grp/new_event' > dynamic_events
Or,
# echo '!new_event' > dynamic_events
will remove new_grp/new_event event.
--- kernel/trace/trace_dynevent.c | 36 +++++++++++++++++++++++++++++++++++- kernel/trace/trace_dynevent.h | 2 ++ kernel/trace/trace_kprobe.c | 12 ++++++++++++ kernel/trace/trace_uprobe.c | 12 ++++++++++++ 4 files changed, 61 insertions(+), 1 deletion(-)
kernel/trace/trace_dynevent.c +35 -1
@@ -19,7 +19,8 @@ static LIST_HEAD(dyn_event_ops_list);int dyn_event_register (struct dyn_event_operations *ops) { -if (!ops || !ops->create || !ops->show || !ops->is_busy || !ops->free) +if (!ops || !ops->create || !ops->show || !ops->is_busy || + !ops->free || !ops->match)return -EINVAL ;INIT_LIST_HEAD (&ops->list);
@@ -29,11 +30,19 @@ int dyn_event_register(struct dyn_event_operations *ops)return 0 ; } +static int delete_dyn_event (int argc,char **argv); +static int create_dyn_event (int argc,char **argv) {struct dyn_event_operations *ops;int ret; +if (argc ==0 ) +return 0 ; + +if (argv[0 ][0 ] =='!' ) +return delete_dyn_event (argc, argv); +mutex_lock (&dyn_event_ops_mutex);list_for_each_entry (ops, &dyn_event_ops_list, list) { ret = ops->create (argc, argv);
@@ -80,6 +89,31 @@ static const struct seq_operations dyn_event_seq_op = { .show = dyn_event_seq_show }; +static int delete_dyn_event (int argc,char **argv) +{ +struct dyn_event *pos, *n; +char *system =NULL , *event, *p; +int ret = -ENOENT ; + + event = &argv[0 ][1 ]; + p =strchr (event,'/' ); +if (p) { + system = event; + event = p +1 ; + *p ='\0' ; + } +mutex_lock (&dyn_event_mutex); +for_each_dyn_event_safe (pos, n) { +if (pos->ops->match (system, event, pos)) { + ret = pos->ops->free (pos); +break ; + } + } +mutex_unlock (&dyn_event_mutex); + +return ret; +} +static int release_all_dyn_events (void ) {struct dyn_event *ev, *tmp;
kernel/trace/trace_dynevent.h +2 -0
@@ -20,6 +20,8 @@ struct dyn_event_operations {int (*show)(struct seq_file *m,struct dyn_event *ev);bool (*is_busy)(struct dyn_event *ev);int (*free)(struct dyn_event *ev); +bool (*match)(const char *system,const char *event, +struct dyn_event *ev); };/* Register new dyn_event type -- must be called at first */
kernel/trace/trace_kprobe.c +12 -0
@@ -23,12 +23,15 @@ static int trace_kprobe_create(int argc, char **argv);static int trace_kprobe_show (struct seq_file *m,struct dyn_event *ev);static int trace_kprobe_release (struct dyn_event *ev);static bool trace_kprobe_is_busy (struct dyn_event *ev); +static bool trace_kprobe_match (const char *system,const char *event, +struct dyn_event *ev);static struct dyn_event_operations trace_kprobe_ops = { .create = trace_kprobe_create, .show = trace_kprobe_show, .is_busy = trace_kprobe_is_busy, .free = trace_kprobe_release, + .match = trace_kprobe_match, };/**
@@ -115,6 +118,15 @@ static bool trace_kprobe_is_busy(struct dyn_event *ev)return trace_probe_is_enabled (&tk->tp); } +static bool trace_kprobe_match (const char *system,const char *event, +struct dyn_event *ev) +{ +struct trace_kprobe *tk =to_trace_kprobe (ev); + +return strcmp (trace_event_name (&tk->tp.call), event) ==0 && + (!system ||strcmp (tk->tp.call.class->system, system) ==0 ); +} +static nokprobe_inline unsigned long trace_kprobe_nhit (struct trace_kprobe *tk) {unsigned long nhit =0 ;
kernel/trace/trace_uprobe.c +12 -0
@@ -41,12 +41,15 @@ static int trace_uprobe_create(int argc, char **argv);static int trace_uprobe_show (struct seq_file *m,struct dyn_event *ev);static int trace_uprobe_release (struct dyn_event *ev);static bool trace_uprobe_is_busy (struct dyn_event *ev); +static bool trace_uprobe_match (const char *system,const char *event, +struct dyn_event *ev);static struct dyn_event_operations trace_uprobe_ops = { .create = trace_uprobe_create, .show = trace_uprobe_show, .is_busy = trace_uprobe_is_busy, .free = trace_uprobe_release, + .match = trace_uprobe_match, };/*
@@ -276,6 +279,15 @@ static bool trace_uprobe_is_busy(struct dyn_event *ev)return trace_probe_is_enabled (&tu->tp); } +static bool trace_uprobe_match (const char *system,const char *event, +struct dyn_event *ev) +{ +struct trace_uprobe *tu =to_trace_uprobe (ev); + +return strcmp (trace_event_name (&tu->tp.call), event) ==0 && + (!system ||strcmp (tu->tp.call.class->system, system) ==0 ); +} +/* * Allocate new trace_uprobe and initialize it (including uprobes). */
Hi Masami,
Quoted 7 lines · Masami Hiramatsu
Hi,
This is an RFC series of unifying dynamic event interface on ftrace. Currently ftrace has 3 dynamic event interfaces, kprobes, uprobes and synthetic. This series unifies kprobes and uprobes event interface on "
dynamic_events". This enables us to add new dynamic events easily on same interface, e.g. function events.
This seems like a nice idea to me and I don't see any problems with the patches themselves, so consider it
Quoted 11 lines
The older interfaces are left on the tracefs for backward compatibility at this moment.
dynamic_eventssyntax has no different fromkprobe_eventsanduprobe_events. You can use same syntax fordynamic_eventsinterface.I think we can integrate synthetic events to this
dynamic_eventsinterface but it will requires new syntax. e.g.echo "s:<event-name> <args>" >>
dynamic_events
So that's just the existing syntax, prefaced by s: , right?
Quoted 2 lines
If it is OK, I'll add it in next version.
Makes sense to me.
Quoted 10 lines
BTW, since this
dynamic_eventsinterface derived from*probe_events, it inherits "all clear when truncate file open" behavior. But if you think this is too aggressive, I can drop it. (even in that case, kprobe_events/uprobe_events behavior is not changed)I also introduced a widely used way to erase entries in other interfaces of ftrace, that is '!'. So you can now use '!event-name' or '!group/event' to erase an entry in
dynamic_events. (Wait... it has to be '!p:event' as others do??)
I'd think the full form should always be accepted, but would only be necessary in cases requiring disambiguation.
Thanks,
Tom
Quoted 32 lines
Any thought?
Thank you,
---
Masami Hiramatsu (5):
tracing/uprobes: Add busy check when cleanup all uprobes
tracing: Add a unified dynamic event framework tracing/kprobes: Usedyn_eventframework for kprobe events tracing/uprobes: Usedyn_eventframework for uprobe events
tracing: Add generic event-name based remove event methodDocumentation/trace/kprobetrace.rst | 3 + Documentation/trace/uprobetracer.rst | 4 + kernel/trace/Kconfig | 4 + kernel/trace/Makefile | 1 kernel/trace/trace.c | 4 + kernel/trace/trace_dynevent.c | 183 +++++++++++++++++++++++++++++++++ kernel/trace/trace_dynevent.h | 89 ++++++++++++++++ kernel/trace/trace_kprobe.c | 191 +++++++++++++++++++++++- ---------- kernel/trace/trace_uprobe.c | 175 +++++++++++++++++++++++- ------- 9 files changed, 547 insertions(+), 107 deletions(-) create mode 100644 kernel/trace/trace_dynevent.c create mode 100644 kernel/trace/trace_dynevent.h--
Masami Hiramatsu (Linaro) <[email protected]>
Masami Hiramatsu
maintainerHi Tom,
Quoted 11 lines · On Mon, 01 Oct 2018 08:49:24 -0500 Tom Zanussi <[email protected]>…
Hi Masami,
Quoted 7 lines · Masami Hiramatsu
Hi,
This is an RFC series of unifying dynamic event interface on ftrace. Currently ftrace has 3 dynamic event interfaces, kprobes, uprobes and synthetic. This series unifies kprobes and uprobes event interface on "
dynamic_events". This enables us to add new dynamic events easily on same interface, e.g. function events.
Quoted 4 lines
This seems like a nice idea to me and I don't see any problems with the patches themselves, so consider it
Acked-by Tom Zanussi <[email protected]>
Thanks!
Quoted 7 lines
Quoted 7 lines
The older interfaces are left on the tracefs for backward compatibility at this moment.
dynamic_eventssyntax has no different fromkprobe_eventsanduprobe_events. You can use same syntax fordynamic_eventsinterface.
Quoted 7 lines
Quoted 5 lines
I think we can integrate synthetic events to this
dynamic_eventsinterface but it will requires new syntax. e.g.echo "s:<event-name> <args>" >>
dynamic_eventsSo that's just the existing syntax, prefaced by s: , right?
Yes, just for identifying.
Quoted 4 lines
Quoted 2 lines
If it is OK, I'll add it in next version.
Makes sense to me.
OK, I'll try :)
Quoted 6 lines
Quoted 6 lines
BTW, since this
dynamic_eventsinterface derived from*probe_events, it inherits "all clear when truncate file open" behavior. But if you think this is too aggressive, I can drop it. (even in that case, kprobe_events/uprobe_events behavior is not changed)
Quoted 8 lines
Quoted 5 lines
I also introduced a widely used way to erase entries in other interfaces of ftrace, that is '!'. So you can now use '!event-name' or '!group/event' to erase an entry in
dynamic_events. (Wait... it has to be '!p:event' as others do??)I'd think the full form should always be accepted, but would only be necessary in cases requiring disambiguation.
OK, I'll add full form support.
Thank you,
Signature · 1 line
Masami Hiramatsu <[email protected]>