tracing: Updates for v6.14
Subsystems (4)
Steven Rostedt
maintainercover tracing: Updates for v6.14
git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git
trace/for-next
Head SHA1: 542079b4b12e89f82c8a689b6e9b119ab7d52018
Steven Rostedt (3):
tracing: Add :mod: command to enabled module events
tracing: Cache ":mod:" events for modules not loaded yet selftests/ftrace: Add test that tests event :mod: commands
----
Documentation/admin-guide/kernel-parameters.txt | 8 + Documentation/trace/events.rst | 24 ++ kernel/trace/ftrace.c | 17 -- kernel/trace/trace.c | 28 ++ kernel/trace/trace.h | 12 + kernel/trace/trace_events.c | 300 +++++++++++++++++++-- .../selftests/ftrace/test.d/event/event-mod.tc | 191 +++++++++++++ 7 files changed, 539 insertions(+), 41 deletions(-) create mode 100644 tools/testing/selftests/ftrace/test.d/event/event-mod.tc
Steven Rostedt
maintainerPATCH 1/3 tracing: Add :mod: command to enabled module events
From: Steven Rostedt <[email protected]>
Add a :mod: command to enable only events from a given module from the set_events file.
echo '*:mod:<module>' > set_events
Or
echo ':mod:<module>' > set_events
Will enable all events for that module. Specific events can also be enabled via:
echo '<event>:mod:<module>' > set_events
Or
echo '<system>:<event>:mod:<module>' > set_events
Or
echo '*:<event>:mod:<module>' > set_events
The ":mod:" keyword is consistent with the function tracing filter to enable functions from a given module.
--- Documentation/trace/events.rst | 22 +++++++++++++ kernel/trace/trace.c | 2 ++ kernel/trace/trace_events.c | 59 ++++++++++++++++++++++++++-------- 3 files changed, 70 insertions(+), 13 deletions(-)
Documentation/trace/events.rst +22 -0
@@ -55,6 +55,28 @@ command:: # echo 'irq:*' > /sys/kernel/tracing/set_event +The set_event file may also be used to enable events associated to only +a specific module:: + + # echo ':mod:<module>' > /sys/kernel/tracing/set_event + +Will enable all events in the module ``<module>``. + +The text before ``:mod:`` will be parsed to specify specific events that the +module creates:: + + # echo '<match>:mod:<module>' > /sys/kernel/tracing/set_event + +The above will enable any system or event that ``<match>`` matches. If +``<match>`` is ``"*"`` then it will match all events. + +To enable only a specific event within a system:: + + # echo '<system>:<event>:mod:<module>' > /sys/kernel/tracing/set_event + +If ``<event>`` is ``"*"`` then it will match all events within the system +for a given module. + 2.2 Via the 'enable' toggle ---------------------------
kernel/trace/trace.c +2 -0
@@ -5514,6 +5514,8 @@ static const char readme_msg[] ="\t efield: For event probes ('e' types), the field is on of the fields\n" "\t of the <attached-group>/<attached-event>.\n"#endif +" set_event\t\t- Enables events by name written into it\n" +"\t\t\t Can enable module events via: :mod:<module>\n" " events/\t\t- Directory containing all trace event subsystems:\n" " enable\t\t- Write 0/1 to enable/disable tracing of all events\n" " events/<system>/\t- Directory containing all trace events for <system>:\n"
kernel/trace/trace_events.c +46 -13
151 lines not on this page · raw message
Signature · 1 line
2.45.2
Steven Rostedt
maintainerPATCH 2/3 tracing: Cache ":mod:" events for modules not loaded yet
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
When the :mod: command is written into /sys/kernel/tracing/set_event (or that file within an instance), if the module specified after the ":mod:" is not yet loaded, it will store that string internally. When the module is loaded, it will enable the events as if the module was loaded when the string was written into the set_event file.
This can also be useful to enable events that are in the init section of the module, as the events are enabled before the init section is executed.
This also works on the kernel command line:
trace_event=:mod:<module>
Will enable the events for <module> when it is loaded.
--- .../admin-guide/kernel-parameters.txt | 8 + Documentation/trace/events.rst | 4 +- kernel/trace/ftrace.c | 17 -- kernel/trace/trace.c | 26 ++ kernel/trace/trace.h | 12 + kernel/trace/trace_events.c | 241 +++++++++++++++++- 6 files changed, 279 insertions(+), 29 deletions(-)
Documentation/admin-guide/kernel-parameters.txt +8 -0
@@ -6858,6 +6858,14 @@ comma-separated list of trace events to enable. See also Documentation/trace/events.rst + To enable modules, use :mod: keyword: + + trace_event=:mod:<module> + + The value before :mod: will only enable specific events + that are part of the module. See the above mentioned + document for more information. + trace_instance=[instance-info] [FTRACE] Create a ring buffer instance early in boot up. This will be listed in:
Documentation/trace/events.rst +3 -1
@@ -60,7 +60,9 @@ a specific module:: # echo ':mod:<module>' > /sys/kernel/tracing/set_event -Will enable all events in the module ``<module>``. +Will enable all events in the module ``<module>``. If the module is not yet +loaded, the string will be saved and when a module is that matches ``<module>`` +is loaded, then it will apply the enabling of events then. The text before ``:mod:`` will be parsed to specify specific events that the module creates::
kernel/trace/ftrace.c +0 -17
@@ -4930,23 +4930,6 @@ static int ftrace_hash_move_and_update_ops(struct ftrace_ops *ops,return __ftrace_hash_move_and_update_ops (ops, orig_hash, hash, enable); } -static bool module_exists (const char *module) -{ -/* All modules have the symbol __this_module */ -static const char this_mod[] ="__this_module" ; -char modname[MAX_PARAM_PREFIX_LEN +sizeof (this_mod) +2 ]; -unsigned long val; -int n; - - n =snprintf (modname,sizeof (modname),"%s:%s" , module, this_mod); - -if (n >sizeof (modname) -1 ) -return false; - - val =module_kallsyms_lookup_name (modname); -return val !=0 ; -} -static int cache_mod (struct trace_array *tr,const char *func,char *module,int enable) {
kernel/trace/trace.c +26 -0
@@ -9407,6 +9407,10 @@ trace_array_create_systems(const char *name, const char *systems,INIT_LIST_HEAD (&tr->hist_vars);INIT_LIST_HEAD (&tr->err_log); +#ifdef CONFIG_MODULES +INIT_LIST_HEAD (&tr->mod_events); +#endif +if (allocate_trace_buffers (tr, trace_buf_size) <0 ) goto out_free_tr;
@@ -9823,6 +9827,24 @@ late_initcall_sync(trace_eval_sync);#ifdef CONFIG_MODULES + +bool module_exists (const char *module) +{ +/* All modules have the symbol __this_module */ +static const char this_mod[] ="__this_module" ; +char modname[MAX_PARAM_PREFIX_LEN +sizeof (this_mod) +2 ]; +unsigned long val; +int n; + + n =snprintf (modname,sizeof (modname),"%s:%s" , module, this_mod); + +if (n >sizeof (modname) -1 ) +return false; + + val =module_kallsyms_lookup_name (modname); +return val !=0 ; +} +static void trace_module_add_evals (struct module *mod) {if (!mod->num_trace_evals)
@@ -10535,6 +10557,10 @@ __init static int tracer_alloc_buffers(void)#endif ftrace_init_global_array_ops (&global_trace); +#ifdef CONFIG_MODULES +INIT_LIST_HEAD (&global_trace.mod_events); +#endif +init_trace_flags_index (&global_trace);register_tracer (&nop_trace);
kernel/trace/trace.h +12 -0
@@ -400,6 +400,9 @@ struct trace_array {cpumask_var_t pipe_cpumask;int ref;int trace_ref; +#ifdef CONFIG_MODULES +struct list_head mod_events; +#endif #ifdef CONFIG_FUNCTION_TRACER struct ftrace_ops *ops;struct trace_pid_list __rcu *function_pids;
@@ -434,6 +437,15 @@ enum { TRACE_ARRAY_FL_BOOT = BIT(1), }; +#ifdef CONFIG_MODULES +bool module_exists (const char *module); +#else +static inline bool module_exists (const char *module) +{ +return false; +} +#endif +extern struct list_head ftrace_trace_arrays;extern struct mutex trace_types_lock;
kernel/trace/trace_events.c +230 -11
311 lines not on this page · raw message
Signature · 1 line
2.45.2
Steven Rostedt
maintainerPATCH 3/3 selftests/ftrace: Add test that tests event :mod: commands
In reply to Steven RostedtFrom: Steven Rostedt <[email protected]>
Now that here's a :mod: command that can be sent into set_event, add a test that tests its use. Both setting events for a loaded module, as well as caching what events to set for a module that is not loaded yet.
--- .../ftrace/test.d/event/event-mod.tc | 191 ++++++++++++++++++ 1 file changed, 191 insertions(+) create mode 100644 tools/testing/selftests/ftrace/test.d/event/event-mod.tc
tools/testing/selftests/ftrace/test.d/event/event-mod.tc new file +191 -0
@@ -0,0 +1,191 @@ +#!/bin/sh +# SPDX-License-Identifier: GPL-2.0 +# description: event tracing - enable/disable with module event +# requires: set_event "Can enable module events via: :mod:":README +# flags: instance + +rmmod trace-events-sample ||: +if ! modprobe trace-events-sample ; then + echo "No trace-events sample module - please make CONFIG_SAMPLE_TRACE_EVENTS=m" + exit_unresolved; +fi +trap "rmmod trace-events-sample" EXIT + +# Set events for the module +echo ":mod:trace-events-sample" > set_event + +test_all_enabled() { + + # Check if more than one is enabled + grep -q sample-trace:foo_bar set_event + grep -q sample-trace:foo_bar_with_cond set_event + grep -q sample-trace:foo_bar_with_fn set_event + + # All of them should be enabled. Check via the enable file + val=`cat events/sample-trace/enable` + if [ $val -ne 1 ]; then + exit_fail + fi +} + +clear_events() { + echo > set_event + val=`cat events/enable` + if [ "$val" != "0" ]; then + exit_fail + fi + count=`cat set_event | wc -l` + if [ $count -ne 0 ]; then + exit_fail + fi +} + +test_all_enabled + +echo clear all events +echo 0 > events/enable + +echo Confirm the events are disabled +val=`cat events/sample-trace/enable` +if [ $val -ne 0 ]; then + exit_fail +fi + +echo And the set_event file is empty + +cnt=`wc -l set_event` +if [ $cnt -ne 0 ]; then + exit_fail +fi + +echo now enable all events +echo 1 > events/enable + +echo Confirm the events are enabled again +val=`cat events/sample-trace/enable` +if [ $val -ne 1 ]; then + exit_fail +fi + +echo disable just the module events +echo '!:mod:trace-events-sample' >> set_event + +echo Should have mix of events enabled +val=`cat events/enable` +if [ "$val" != "X" ]; then + exit_fail +fi + +echo Confirm the module events are disabled +val=`cat events/sample-trace/enable` +if [ $val -ne 0 ]; then + exit_fail +fi + +echo 0 > events/enable + +echo now enable the system events +echo 'sample-trace:mod:trace-events-sample' > set_event + +test_all_enabled + +echo clear all events +echo 0 > events/enable + +echo Confirm the events are disabled +val=`cat events/sample-trace/enable` +if [ $val -ne 0 ]; then + exit_fail +fi + +echo Test enabling foo_bar only +echo 'foo_bar:mod:trace-events-sample' > set_event + +grep -q sample-trace:foo_bar set_event + +echo make sure nothing is found besides foo_bar +if grep -q -v sample-trace:foo_bar set_event ; then + exit_fail +fi + +echo Append another using the system and event name +echo 'sample-trace:foo_bar_with_cond:mod:trace-events-sample' >> set_event + +grep -q sample-trace:foo_bar set_event +grep -q sample-trace:foo_bar_with_cond set_event + +count=`cat set_event | wc -l` + +if [ $count -ne 2 ]; then + exit_fail +fi + +clear_events + +rmmod trace-events-sample + +echo ':mod:trace-events-sample' > set_event + +echo make sure that the module shows up, and '-' is converted to '_' +grep -q '\*:\*:mod:trace_events_sample' set_event + +modprobe trace-events-sample + +test_all_enabled + +clear_events + +rmmod trace-events-sample + +echo Enable just the system events +echo 'sample-trace:mod:trace-events-sample' > set_event +grep -q 'sample-trace:mod:trace_events_sample' set_event + +modprobe trace-events-sample + +test_all_enabled + +clear_events + +rmmod trace-events-sample + +echo Enable event with just event name +echo 'foo_bar:mod:trace-events-sample' > set_event +grep -q 'foo_bar:mod:trace_events_sample' set_event + +echo Enable another event with both system and event name +echo 'sample-trace:foo_bar_with_cond:mod:trace-events-sample' >> set_event +grep -q 'sample-trace:foo_bar_with_cond:mod:trace_events_sample' set_event +echo Make sure the other event was still there +grep -q 'foo_bar:mod:trace_events_sample' set_event + +modprobe trace-events-sample + +echo There should be no :mod: cached events +if grep -q ':mod:' set_event; then + exit_fail +fi + +echo two events should be enabled +count=`cat set_event | wc -l` +if [ $count -ne 2 ]; then + exit_fail +fi + +echo only two events should be enabled +val=`cat events/sample-trace/enable` +if [ "$val" != "X" ]; then + exit_fail +fi + +val=`cat events/sample-trace/foo_bar/enable` +if [ "$val" != "1" ]; then + exit_fail +fi + +val=`cat events/sample-trace/foo_bar_with_cond/enable` +if [ "$val" != "1" ]; then + exit_fail +fi + +clear_trace
Signature · 1 line
2.45.2