Skip to content

Commit e8744fb

Browse files
committed
Merge tag 'trace-v6.14-3' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace
Pull tracing updates from Steven Rostedt: - Cleanup with guard() and free() helpers There were several places in the code that had a lot of "goto out" in the error paths to either unlock a lock or free some memory that was allocated. But this is error prone. Convert the code over to use the guard() and free() helpers that let the compiler unlock locks or free memory when the function exits. - Update the Rust tracepoint code to use the C code too There was some duplication of the tracepoint code for Rust that did the same logic as the C code. Add a helper that makes it possible for both algorithms to use the same logic in one place. - Add poll to trace event hist files It is useful to know when an event is triggered, or even with some filtering. Since hist files of events get updated when active and the event is triggered, allow applications to poll the hist file and wake up when an event is triggered. This will let the application know that the event it is waiting for happened. - Add :mod: command to enable events for current or future modules The function tracer already has a way to enable functions to be traced in modules by writing ":mod:<module>" into set_ftrace_filter. That will enable either all the functions for the module if it is loaded, or if it is not, it will cache that command, and when the module is loaded that matches <module>, its functions will be enabled. This also allows init functions to be traced. But currently events do not have that feature. Add the command where if ':mod:<module>' is written into set_event, then either all the modules events are enabled if it is loaded, or cache it so that the module's events are enabled when it is loaded. This also works from the kernel command line, where "trace_event=:mod:<module>", when the module is loaded at boot up, its events will be enabled then. * tag 'trace-v6.14-3' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace: (26 commits) tracing: Fix output of set_event for some cached module events tracing: Fix allocation of printing set_event file content tracing: Rename update_cache() to update_mod_cache() tracing: Fix #if CONFIG_MODULES to #ifdef CONFIG_MODULES selftests/ftrace: Add test that tests event :mod: commands tracing: Cache ":mod:" events for modules not loaded yet tracing: Add :mod: command to enabled module events selftests/tracing: Add hist poll() support test tracing/hist: Support POLLPRI event for poll on histogram tracing/hist: Add poll(POLLIN) support on hist file tracing: Fix using ret variable in tracing_set_tracer() tracepoint: Reduce duplication of __DO_TRACE_CALL tracing/string: Create and use __free(argv_free) in trace_dynevent.c tracing: Switch trace_stat.c code over to use guard() tracing: Switch trace_stack.c code over to use guard() tracing: Switch trace_osnoise.c code over to use guard() and __free() tracing: Switch trace_events_synth.c code over to use guard() tracing: Switch trace_events_filter.c code over to use guard() tracing: Switch trace_events_trigger.c code over to use guard() tracing: Switch trace_events_hist.c code over to use guard() ...
2 parents 7f71554 + 8f21943 commit e8744fb

File tree

21 files changed

+1047
-475
lines changed

21 files changed

+1047
-475
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7161,6 +7161,14 @@
71617161
comma-separated list of trace events to enable. See
71627162
also Documentation/trace/events.rst
71637163

7164+
To enable modules, use :mod: keyword:
7165+
7166+
trace_event=:mod:<module>
7167+
7168+
The value before :mod: will only enable specific events
7169+
that are part of the module. See the above mentioned
7170+
document for more information.
7171+
71647172
trace_instance=[instance-info]
71657173
[FTRACE] Create a ring buffer instance early in boot up.
71667174
This will be listed in:

Documentation/trace/events.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,30 @@ command::
5555

5656
# echo 'irq:*' > /sys/kernel/tracing/set_event
5757

58+
The set_event file may also be used to enable events associated to only
59+
a specific module::
60+
61+
# echo ':mod:<module>' > /sys/kernel/tracing/set_event
62+
63+
Will enable all events in the module ``<module>``. If the module is not yet
64+
loaded, the string will be saved and when a module is that matches ``<module>``
65+
is loaded, then it will apply the enabling of events then.
66+
67+
The text before ``:mod:`` will be parsed to specify specific events that the
68+
module creates::
69+
70+
# echo '<match>:mod:<module>' > /sys/kernel/tracing/set_event
71+
72+
The above will enable any system or event that ``<match>`` matches. If
73+
``<match>`` is ``"*"`` then it will match all events.
74+
75+
To enable only a specific event within a system::
76+
77+
# echo '<system>:<event>:mod:<module>' > /sys/kernel/tracing/set_event
78+
79+
If ``<event>`` is ``"*"`` then it will match all events within the system
80+
for a given module.
81+
5882
2.2 Via the 'enable' toggle
5983
---------------------------
6084

include/linux/string.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <linux/args.h>
66
#include <linux/array_size.h>
7+
#include <linux/cleanup.h> /* for DEFINE_FREE() */
78
#include <linux/compiler.h> /* for inline */
89
#include <linux/types.h> /* for size_t */
910
#include <linux/stddef.h> /* for NULL */
@@ -312,6 +313,8 @@ extern void *kmemdup_array(const void *src, size_t count, size_t element_size, g
312313
extern char **argv_split(gfp_t gfp, const char *str, int *argcp);
313314
extern void argv_free(char **argv);
314315

316+
DEFINE_FREE(argv_free, char **, if (!IS_ERR_OR_NULL(_T)) argv_free(_T))
317+
315318
/* lib/cmdline.c */
316319
extern int get_option(char **str, int *pint);
317320
extern char *get_options(const char *str, int nints, int *ints);

include/linux/trace_events.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,20 @@ struct trace_event_file {
673673
atomic_t tm_ref; /* trigger-mode reference counter */
674674
};
675675

676+
#ifdef CONFIG_HIST_TRIGGERS
677+
extern struct irq_work hist_poll_work;
678+
extern wait_queue_head_t hist_poll_wq;
679+
680+
static inline void hist_poll_wakeup(void)
681+
{
682+
if (wq_has_sleeper(&hist_poll_wq))
683+
irq_work_queue(&hist_poll_work);
684+
}
685+
686+
#define hist_poll_wait(file, wait) \
687+
poll_wait(file, &hist_poll_wq, wait)
688+
#endif
689+
676690
#define __TRACE_EVENT_FLAGS(name, value) \
677691
static int __init trace_init_flags_##name(void) \
678692
{ \

include/linux/tracepoint.h

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
218218
#define __DEFINE_RUST_DO_TRACE(name, proto, args) \
219219
notrace void rust_do_trace_##name(proto) \
220220
{ \
221-
__rust_do_trace_##name(args); \
221+
__do_trace_##name(args); \
222222
}
223223

224224
/*
@@ -268,7 +268,7 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
268268

269269
#define __DECLARE_TRACE(name, proto, args, cond, data_proto) \
270270
__DECLARE_TRACE_COMMON(name, PARAMS(proto), PARAMS(args), PARAMS(data_proto)) \
271-
static inline void __rust_do_trace_##name(proto) \
271+
static inline void __do_trace_##name(proto) \
272272
{ \
273273
if (cond) { \
274274
guard(preempt_notrace)(); \
@@ -277,12 +277,8 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
277277
} \
278278
static inline void trace_##name(proto) \
279279
{ \
280-
if (static_branch_unlikely(&__tracepoint_##name.key)) { \
281-
if (cond) { \
282-
guard(preempt_notrace)(); \
283-
__DO_TRACE_CALL(name, TP_ARGS(args)); \
284-
} \
285-
} \
280+
if (static_branch_unlikely(&__tracepoint_##name.key)) \
281+
__do_trace_##name(args); \
286282
if (IS_ENABLED(CONFIG_LOCKDEP) && (cond)) { \
287283
WARN_ONCE(!rcu_is_watching(), \
288284
"RCU not watching for tracepoint"); \
@@ -291,18 +287,16 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
291287

292288
#define __DECLARE_TRACE_SYSCALL(name, proto, args, data_proto) \
293289
__DECLARE_TRACE_COMMON(name, PARAMS(proto), PARAMS(args), PARAMS(data_proto)) \
294-
static inline void __rust_do_trace_##name(proto) \
290+
static inline void __do_trace_##name(proto) \
295291
{ \
296292
guard(rcu_tasks_trace)(); \
297293
__DO_TRACE_CALL(name, TP_ARGS(args)); \
298294
} \
299295
static inline void trace_##name(proto) \
300296
{ \
301297
might_fault(); \
302-
if (static_branch_unlikely(&__tracepoint_##name.key)) { \
303-
guard(rcu_tasks_trace)(); \
304-
__DO_TRACE_CALL(name, TP_ARGS(args)); \
305-
} \
298+
if (static_branch_unlikely(&__tracepoint_##name.key)) \
299+
__do_trace_##name(args); \
306300
if (IS_ENABLED(CONFIG_LOCKDEP)) { \
307301
WARN_ONCE(!rcu_is_watching(), \
308302
"RCU not watching for tracepoint"); \

kernel/trace/ftrace.c

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4908,23 +4908,6 @@ static int ftrace_hash_move_and_update_ops(struct ftrace_ops *ops,
49084908
return __ftrace_hash_move_and_update_ops(ops, orig_hash, hash, enable);
49094909
}
49104910

4911-
static bool module_exists(const char *module)
4912-
{
4913-
/* All modules have the symbol __this_module */
4914-
static const char this_mod[] = "__this_module";
4915-
char modname[MAX_PARAM_PREFIX_LEN + sizeof(this_mod) + 2];
4916-
unsigned long val;
4917-
int n;
4918-
4919-
n = snprintf(modname, sizeof(modname), "%s:%s", module, this_mod);
4920-
4921-
if (n > sizeof(modname) - 1)
4922-
return false;
4923-
4924-
val = module_kallsyms_lookup_name(modname);
4925-
return val != 0;
4926-
}
4927-
49284911
static int cache_mod(struct trace_array *tr,
49294912
const char *func, char *module, int enable)
49304913
{

0 commit comments

Comments
 (0)