Skip to content

Commit ac01fa7

Browse files
committed
tracepoint: Have tracepoints created with DECLARE_TRACE() have _tp suffix
Most tracepoints in the kernel are created with TRACE_EVENT(). The TRACE_EVENT() macro (and DECLARE_EVENT_CLASS() and DEFINE_EVENT() where in reality, TRACE_EVENT() is just a helper macro that calls those other two macros), will create not only a tracepoint (the function trace_<event>() used in the kernel), it also exposes the tracepoint to user space along with defining what fields will be saved by that tracepoint. There are a few places that tracepoints are created in the kernel that are not exposed to userspace via tracefs. They can only be accessed from code within the kernel. These tracepoints are created with DEFINE_TRACE() Most of these tracepoints end with "_tp". This is useful as when the developer sees that, they know that the tracepoint is for in-kernel only (meaning it can only be accessed inside the kernel, either directly by the kernel or indirectly via modules and BPF programs) and is not exposed to user space. Instead of making this only a process to add "_tp", enforce it by making the DECLARE_TRACE() append the "_tp" suffix to the tracepoint. This requires adding DECLARE_TRACE_EVENT() macros for the TRACE_EVENT() macro to use that keeps the original name. Link: https://lore.kernel.org/all/[email protected]/ Cc: netdev <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: David Ahern <[email protected]> Cc: Juri Lelli <[email protected]> Cc: Breno Leitao <[email protected]> Cc: Alexei Starovoitov <[email protected]> Cc: Andrii Nakryiko <[email protected]> Cc: Gabriele Monaco <[email protected]> Cc: Masami Hiramatsu <[email protected]> Link: https://lore.kernel.org/[email protected] Acked-by: Mathieu Desnoyers <[email protected]> Acked-by: Andrii Nakryiko <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent 45c28cd commit ac01fa7

File tree

11 files changed

+83
-49
lines changed

11 files changed

+83
-49
lines changed

Documentation/trace/tracepoints.rst

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ In subsys/file.c (where the tracing statement must be added)::
7171
void somefct(void)
7272
{
7373
...
74-
trace_subsys_eventname(arg, task);
74+
trace_subsys_eventname_tp(arg, task);
7575
...
7676
}
7777

@@ -129,12 +129,12 @@ within an if statement with the following::
129129
for (i = 0; i < count; i++)
130130
tot += calculate_nuggets();
131131

132-
trace_foo_bar(tot);
132+
trace_foo_bar_tp(tot);
133133
}
134134

135-
All trace_<tracepoint>() calls have a matching trace_<tracepoint>_enabled()
135+
All trace_<tracepoint>_tp() calls have a matching trace_<tracepoint>_enabled()
136136
function defined that returns true if the tracepoint is enabled and
137-
false otherwise. The trace_<tracepoint>() should always be within the
137+
false otherwise. The trace_<tracepoint>_tp() should always be within the
138138
block of the if (trace_<tracepoint>_enabled()) to prevent races between
139139
the tracepoint being enabled and the check being seen.
140140

@@ -143,7 +143,10 @@ the static_key of the tracepoint to allow the if statement to be implemented
143143
with jump labels and avoid conditional branches.
144144

145145
.. note:: The convenience macro TRACE_EVENT provides an alternative way to
146-
define tracepoints. Check http://lwn.net/Articles/379903,
146+
define tracepoints. Note, DECLARE_TRACE(foo) creates a function
147+
"trace_foo_tp()" whereas TRACE_EVENT(foo) creates a function
148+
"trace_foo()", and also exposes the tracepoint as a trace event in
149+
/sys/kernel/tracing/events directory. Check http://lwn.net/Articles/379903,
147150
http://lwn.net/Articles/381064 and http://lwn.net/Articles/383362
148151
for a series of articles with more details.
149152

@@ -159,7 +162,9 @@ In a C file::
159162

160163
void do_trace_foo_bar_wrapper(args)
161164
{
162-
trace_foo_bar(args);
165+
trace_foo_bar_tp(args); // for tracepoints created via DECLARE_TRACE
166+
// or
167+
trace_foo_bar(args); // for tracepoints created via TRACE_EVENT
163168
}
164169

165170
In the header file::

include/linux/tracepoint.h

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -464,16 +464,30 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
464464
#endif
465465

466466
#define DECLARE_TRACE(name, proto, args) \
467-
__DECLARE_TRACE(name, PARAMS(proto), PARAMS(args), \
467+
__DECLARE_TRACE(name##_tp, PARAMS(proto), PARAMS(args), \
468468
cpu_online(raw_smp_processor_id()), \
469469
PARAMS(void *__data, proto))
470470

471471
#define DECLARE_TRACE_CONDITION(name, proto, args, cond) \
472-
__DECLARE_TRACE(name, PARAMS(proto), PARAMS(args), \
472+
__DECLARE_TRACE(name##_tp, PARAMS(proto), PARAMS(args), \
473473
cpu_online(raw_smp_processor_id()) && (PARAMS(cond)), \
474474
PARAMS(void *__data, proto))
475475

476476
#define DECLARE_TRACE_SYSCALL(name, proto, args) \
477+
__DECLARE_TRACE_SYSCALL(name##_tp, PARAMS(proto), PARAMS(args), \
478+
PARAMS(void *__data, proto))
479+
480+
#define DECLARE_TRACE_EVENT(name, proto, args) \
481+
__DECLARE_TRACE(name, PARAMS(proto), PARAMS(args), \
482+
cpu_online(raw_smp_processor_id()), \
483+
PARAMS(void *__data, proto))
484+
485+
#define DECLARE_TRACE_EVENT_CONDITION(name, proto, args, cond) \
486+
__DECLARE_TRACE(name, PARAMS(proto), PARAMS(args), \
487+
cpu_online(raw_smp_processor_id()) && (PARAMS(cond)), \
488+
PARAMS(void *__data, proto))
489+
490+
#define DECLARE_TRACE_EVENT_SYSCALL(name, proto, args) \
477491
__DECLARE_TRACE_SYSCALL(name, PARAMS(proto), PARAMS(args), \
478492
PARAMS(void *__data, proto))
479493

@@ -591,32 +605,32 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
591605

592606
#define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print)
593607
#define DEFINE_EVENT(template, name, proto, args) \
594-
DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
608+
DECLARE_TRACE_EVENT(name, PARAMS(proto), PARAMS(args))
595609
#define DEFINE_EVENT_FN(template, name, proto, args, reg, unreg)\
596-
DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
610+
DECLARE_TRACE_EVENT(name, PARAMS(proto), PARAMS(args))
597611
#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
598-
DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
612+
DECLARE_TRACE_EVENT(name, PARAMS(proto), PARAMS(args))
599613
#define DEFINE_EVENT_CONDITION(template, name, proto, \
600614
args, cond) \
601-
DECLARE_TRACE_CONDITION(name, PARAMS(proto), \
615+
DECLARE_TRACE_EVENT_CONDITION(name, PARAMS(proto), \
602616
PARAMS(args), PARAMS(cond))
603617

604618
#define TRACE_EVENT(name, proto, args, struct, assign, print) \
605-
DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
619+
DECLARE_TRACE_EVENT(name, PARAMS(proto), PARAMS(args))
606620
#define TRACE_EVENT_FN(name, proto, args, struct, \
607621
assign, print, reg, unreg) \
608-
DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
609-
#define TRACE_EVENT_FN_COND(name, proto, args, cond, struct, \
622+
DECLARE_TRACE_EVENT(name, PARAMS(proto), PARAMS(args))
623+
#define TRACE_EVENT_FN_COND(name, proto, args, cond, struct, \
610624
assign, print, reg, unreg) \
611-
DECLARE_TRACE_CONDITION(name, PARAMS(proto), \
625+
DECLARE_TRACE_EVENT_CONDITION(name, PARAMS(proto), \
612626
PARAMS(args), PARAMS(cond))
613627
#define TRACE_EVENT_CONDITION(name, proto, args, cond, \
614628
struct, assign, print) \
615-
DECLARE_TRACE_CONDITION(name, PARAMS(proto), \
629+
DECLARE_TRACE_EVENT_CONDITION(name, PARAMS(proto), \
616630
PARAMS(args), PARAMS(cond))
617631
#define TRACE_EVENT_SYSCALL(name, proto, args, struct, assign, \
618632
print, reg, unreg) \
619-
DECLARE_TRACE_SYSCALL(name, PARAMS(proto), PARAMS(args))
633+
DECLARE_TRACE_EVENT_SYSCALL(name, PARAMS(proto), PARAMS(args))
620634

621635
#define TRACE_EVENT_FLAGS(event, flag)
622636

include/trace/bpf_probe.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,14 @@ static inline void bpf_test_buffer_##call(void) \
119119

120120
#undef DECLARE_TRACE
121121
#define DECLARE_TRACE(call, proto, args) \
122-
__BPF_DECLARE_TRACE(call, PARAMS(proto), PARAMS(args)) \
123-
__DEFINE_EVENT(call, call, PARAMS(proto), PARAMS(args), 0)
122+
__BPF_DECLARE_TRACE(call##_tp, PARAMS(proto), PARAMS(args)) \
123+
__DEFINE_EVENT(call##_tp, call##_tp, PARAMS(proto), PARAMS(args), 0)
124124

125125
#undef DECLARE_TRACE_WRITABLE
126126
#define DECLARE_TRACE_WRITABLE(call, proto, args, size) \
127127
__CHECK_WRITABLE_BUF_SIZE(call, PARAMS(proto), PARAMS(args), size) \
128-
__BPF_DECLARE_TRACE(call, PARAMS(proto), PARAMS(args)) \
129-
__DEFINE_EVENT(call, call, PARAMS(proto), PARAMS(args), size)
128+
__BPF_DECLARE_TRACE(call##_tp, PARAMS(proto), PARAMS(args)) \
129+
__DEFINE_EVENT(call##_tp, call##_tp, PARAMS(proto), PARAMS(args), size)
130130

131131
#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
132132

include/trace/define_trace.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,18 @@
7474

7575
#undef DECLARE_TRACE
7676
#define DECLARE_TRACE(name, proto, args) \
77-
DEFINE_TRACE(name, PARAMS(proto), PARAMS(args))
77+
DEFINE_TRACE(name##_tp, PARAMS(proto), PARAMS(args))
7878

7979
#undef DECLARE_TRACE_CONDITION
8080
#define DECLARE_TRACE_CONDITION(name, proto, args, cond) \
81+
DEFINE_TRACE(name##_tp, PARAMS(proto), PARAMS(args))
82+
83+
#undef DECLARE_TRACE_EVENT
84+
#define DECLARE_TRACE_EVENT(name, proto, args) \
85+
DEFINE_TRACE(name, PARAMS(proto), PARAMS(args))
86+
87+
#undef DECLARE_TRACE_EVENT_CONDITION
88+
#define DECLARE_TRACE_EVENT_CONDITION(name, proto, args, cond) \
8189
DEFINE_TRACE(name, PARAMS(proto), PARAMS(args))
8290

8391
/* If requested, create helpers for calling these tracepoints from Rust. */
@@ -115,6 +123,11 @@
115123
#undef DECLARE_TRACE_CONDITION
116124
#define DECLARE_TRACE_CONDITION(name, proto, args, cond)
117125

126+
#undef DECLARE_TRACE_EVENT
127+
#define DECLARE_TRACE_EVENT(name, proto, args)
128+
#undef DECLARE_TRACE_EVENT_CONDITION
129+
#define DECLARE_TRACE_EVENT_CONDITION(name, proto, args, cond)
130+
118131
#ifdef TRACEPOINTS_ENABLED
119132
#include <trace/trace_events.h>
120133
#include <trace/perf.h>
@@ -136,6 +149,8 @@
136149
#undef TRACE_HEADER_MULTI_READ
137150
#undef DECLARE_TRACE
138151
#undef DECLARE_TRACE_CONDITION
152+
#undef DECLARE_TRACE_EVENT
153+
#undef DECLARE_TRACE_EVENT_CONDITION
139154

140155
/* Only undef what we defined in this file */
141156
#ifdef UNDEF_TRACE_INCLUDE_FILE

include/trace/events/sched.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -773,64 +773,64 @@ TRACE_EVENT(sched_wake_idle_without_ipi,
773773
*
774774
* Postfixed with _tp to make them easily identifiable in the code.
775775
*/
776-
DECLARE_TRACE(pelt_cfs_tp,
776+
DECLARE_TRACE(pelt_cfs,
777777
TP_PROTO(struct cfs_rq *cfs_rq),
778778
TP_ARGS(cfs_rq));
779779

780-
DECLARE_TRACE(pelt_rt_tp,
780+
DECLARE_TRACE(pelt_rt,
781781
TP_PROTO(struct rq *rq),
782782
TP_ARGS(rq));
783783

784-
DECLARE_TRACE(pelt_dl_tp,
784+
DECLARE_TRACE(pelt_dl,
785785
TP_PROTO(struct rq *rq),
786786
TP_ARGS(rq));
787787

788-
DECLARE_TRACE(pelt_hw_tp,
788+
DECLARE_TRACE(pelt_hw,
789789
TP_PROTO(struct rq *rq),
790790
TP_ARGS(rq));
791791

792-
DECLARE_TRACE(pelt_irq_tp,
792+
DECLARE_TRACE(pelt_irq,
793793
TP_PROTO(struct rq *rq),
794794
TP_ARGS(rq));
795795

796-
DECLARE_TRACE(pelt_se_tp,
796+
DECLARE_TRACE(pelt_se,
797797
TP_PROTO(struct sched_entity *se),
798798
TP_ARGS(se));
799799

800-
DECLARE_TRACE(sched_cpu_capacity_tp,
800+
DECLARE_TRACE(sched_cpu_capacity,
801801
TP_PROTO(struct rq *rq),
802802
TP_ARGS(rq));
803803

804-
DECLARE_TRACE(sched_overutilized_tp,
804+
DECLARE_TRACE(sched_overutilized,
805805
TP_PROTO(struct root_domain *rd, bool overutilized),
806806
TP_ARGS(rd, overutilized));
807807

808-
DECLARE_TRACE(sched_util_est_cfs_tp,
808+
DECLARE_TRACE(sched_util_est_cfs,
809809
TP_PROTO(struct cfs_rq *cfs_rq),
810810
TP_ARGS(cfs_rq));
811811

812-
DECLARE_TRACE(sched_util_est_se_tp,
812+
DECLARE_TRACE(sched_util_est_se,
813813
TP_PROTO(struct sched_entity *se),
814814
TP_ARGS(se));
815815

816-
DECLARE_TRACE(sched_update_nr_running_tp,
816+
DECLARE_TRACE(sched_update_nr_running,
817817
TP_PROTO(struct rq *rq, int change),
818818
TP_ARGS(rq, change));
819819

820-
DECLARE_TRACE(sched_compute_energy_tp,
820+
DECLARE_TRACE(sched_compute_energy,
821821
TP_PROTO(struct task_struct *p, int dst_cpu, unsigned long energy,
822822
unsigned long max_util, unsigned long busy_time),
823823
TP_ARGS(p, dst_cpu, energy, max_util, busy_time));
824824

825-
DECLARE_TRACE(sched_entry_tp,
825+
DECLARE_TRACE(sched_entry,
826826
TP_PROTO(bool preempt, unsigned long ip),
827827
TP_ARGS(preempt, ip));
828828

829-
DECLARE_TRACE(sched_exit_tp,
829+
DECLARE_TRACE(sched_exit,
830830
TP_PROTO(bool is_switch, unsigned long ip),
831831
TP_ARGS(is_switch, ip));
832832

833-
DECLARE_TRACE_CONDITION(sched_set_state_tp,
833+
DECLARE_TRACE_CONDITION(sched_set_state,
834834
TP_PROTO(struct task_struct *tsk, int state),
835835
TP_ARGS(tsk, state),
836836
TP_CONDITION(!!(tsk->__state) != !!state));

include/trace/events/tcp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ TRACE_EVENT(tcp_retransmit_synack,
259259
__entry->saddr_v6, __entry->daddr_v6)
260260
);
261261

262-
DECLARE_TRACE(tcp_cwnd_reduction_tp,
262+
DECLARE_TRACE(tcp_cwnd_reduction,
263263
TP_PROTO(const struct sock *sk, int newly_acked_sacked,
264264
int newly_lost, int flag),
265265
TP_ARGS(sk, newly_acked_sacked, newly_lost, flag)

tools/testing/selftests/bpf/progs/raw_tp_null.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ char _license[] SEC("license") = "GPL";
1010
int tid;
1111
int i;
1212

13-
SEC("tp_btf/bpf_testmod_test_raw_tp_null")
13+
SEC("tp_btf/bpf_testmod_test_raw_tp_null_tp")
1414
int BPF_PROG(test_raw_tp_null, struct sk_buff *skb)
1515
{
1616
struct task_struct *task = bpf_get_current_task_btf();

tools/testing/selftests/bpf/progs/raw_tp_null_fail.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
char _license[] SEC("license") = "GPL";
99

1010
/* Ensure module parameter has PTR_MAYBE_NULL */
11-
SEC("tp_btf/bpf_testmod_test_raw_tp_null")
11+
SEC("tp_btf/bpf_testmod_test_raw_tp_null_tp")
1212
__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
1313
int test_raw_tp_null_bpf_testmod_test_raw_tp_null_arg_1(void *ctx) {
1414
asm volatile("r1 = *(u64 *)(r1 +0); r1 = *(u64 *)(r1 +0);" ::: __clobber_all);

tools/testing/selftests/bpf/progs/test_module_attach.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ int BPF_PROG(handle_raw_tp,
1919

2020
__u32 raw_tp_bare_write_sz = 0;
2121

22-
SEC("raw_tp/bpf_testmod_test_write_bare")
22+
SEC("raw_tp/bpf_testmod_test_write_bare_tp")
2323
int BPF_PROG(handle_raw_tp_bare,
2424
struct task_struct *task, struct bpf_testmod_test_write_ctx *write_ctx)
2525
{
@@ -31,7 +31,7 @@ int raw_tp_writable_bare_in_val = 0;
3131
int raw_tp_writable_bare_early_ret = 0;
3232
int raw_tp_writable_bare_out_val = 0;
3333

34-
SEC("raw_tp.w/bpf_testmod_test_writable_bare")
34+
SEC("raw_tp.w/bpf_testmod_test_writable_bare_tp")
3535
int BPF_PROG(handle_raw_tp_writable_bare,
3636
struct bpf_testmod_test_writable_ctx *writable)
3737
{

tools/testing/selftests/bpf/progs/test_tp_btf_nullable.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
#include "../test_kmods/bpf_testmod.h"
77
#include "bpf_misc.h"
88

9-
SEC("tp_btf/bpf_testmod_test_nullable_bare")
9+
SEC("tp_btf/bpf_testmod_test_nullable_bare_tp")
1010
__failure __msg("R1 invalid mem access 'trusted_ptr_or_null_'")
1111
int BPF_PROG(handle_tp_btf_nullable_bare1, struct bpf_testmod_test_read_ctx *nullable_ctx)
1212
{
1313
return nullable_ctx->len;
1414
}
1515

16-
SEC("tp_btf/bpf_testmod_test_nullable_bare")
16+
SEC("tp_btf/bpf_testmod_test_nullable_bare_tp")
1717
int BPF_PROG(handle_tp_btf_nullable_bare2, struct bpf_testmod_test_read_ctx *nullable_ctx)
1818
{
1919
if (nullable_ctx)

0 commit comments

Comments
 (0)