Skip to content

Commit 0e6caab

Browse files
compudjrostedt
authored andcommitted
tracing: Declare system call tracepoints with TRACE_EVENT_SYSCALL
In preparation for allowing system call tracepoints to handle page faults, introduce TRACE_EVENT_SYSCALL to declare the sys_enter/sys_exit tracepoints. Move the common code between __DECLARE_TRACE and __DECLARE_TRACE_SYSCALL into __DECLARE_TRACE_COMMON. This change is not meant to alter the generated code, and only prepares the following modifications. Cc: Michael Jeanson <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Alexei Starovoitov <[email protected]> Cc: Yonghong Song <[email protected]> Cc: Paul E. McKenney <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Arnaldo Carvalho de Melo <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Andrii Nakryiko <[email protected]> Cc: [email protected] Cc: Joel Fernandes <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Mathieu Desnoyers <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent e53244e commit 0e6caab

File tree

6 files changed

+81
-15
lines changed

6 files changed

+81
-15
lines changed

include/linux/tracepoint.h

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
197197
* it_func[0] is never NULL because there is at least one element in the array
198198
* when the array itself is non NULL.
199199
*/
200-
#define __DO_TRACE(name, args, cond) \
200+
#define __DO_TRACE(name, args, cond, syscall) \
201201
do { \
202202
int __maybe_unused __idx = 0; \
203203
\
@@ -222,21 +222,10 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
222222
* site if it is not watching, as it will need to be active when the
223223
* tracepoint is enabled.
224224
*/
225-
#define __DECLARE_TRACE(name, proto, args, cond, data_proto) \
225+
#define __DECLARE_TRACE_COMMON(name, proto, args, cond, data_proto) \
226226
extern int __traceiter_##name(data_proto); \
227227
DECLARE_STATIC_CALL(tp_func_##name, __traceiter_##name); \
228228
extern struct tracepoint __tracepoint_##name; \
229-
static inline void trace_##name(proto) \
230-
{ \
231-
if (static_branch_unlikely(&__tracepoint_##name.key)) \
232-
__DO_TRACE(name, \
233-
TP_ARGS(args), \
234-
TP_CONDITION(cond)); \
235-
if (IS_ENABLED(CONFIG_LOCKDEP) && (cond)) { \
236-
WARN_ONCE(!rcu_is_watching(), \
237-
"RCU not watching for tracepoint"); \
238-
} \
239-
} \
240229
static inline int \
241230
register_trace_##name(void (*probe)(data_proto), void *data) \
242231
{ \
@@ -266,6 +255,34 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
266255
return static_branch_unlikely(&__tracepoint_##name.key);\
267256
}
268257

258+
#define __DECLARE_TRACE(name, proto, args, cond, data_proto) \
259+
__DECLARE_TRACE_COMMON(name, PARAMS(proto), PARAMS(args), cond, PARAMS(data_proto)) \
260+
static inline void trace_##name(proto) \
261+
{ \
262+
if (static_branch_unlikely(&__tracepoint_##name.key)) \
263+
__DO_TRACE(name, \
264+
TP_ARGS(args), \
265+
TP_CONDITION(cond), 0); \
266+
if (IS_ENABLED(CONFIG_LOCKDEP) && (cond)) { \
267+
WARN_ONCE(!rcu_is_watching(), \
268+
"RCU not watching for tracepoint"); \
269+
} \
270+
}
271+
272+
#define __DECLARE_TRACE_SYSCALL(name, proto, args, cond, data_proto) \
273+
__DECLARE_TRACE_COMMON(name, PARAMS(proto), PARAMS(args), cond, PARAMS(data_proto)) \
274+
static inline void trace_##name(proto) \
275+
{ \
276+
if (static_branch_unlikely(&__tracepoint_##name.key)) \
277+
__DO_TRACE(name, \
278+
TP_ARGS(args), \
279+
TP_CONDITION(cond), 1); \
280+
if (IS_ENABLED(CONFIG_LOCKDEP) && (cond)) { \
281+
WARN_ONCE(!rcu_is_watching(), \
282+
"RCU not watching for tracepoint"); \
283+
} \
284+
}
285+
269286
/*
270287
* We have no guarantee that gcc and the linker won't up-align the tracepoint
271288
* structures, so we create an array of pointers that will be used for iteration
@@ -348,6 +365,8 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
348365
return false; \
349366
}
350367

368+
#define __DECLARE_TRACE_SYSCALL __DECLARE_TRACE
369+
351370
#define DEFINE_TRACE_FN(name, reg, unreg, proto, args)
352371
#define DEFINE_TRACE(name, proto, args)
353372
#define EXPORT_TRACEPOINT_SYMBOL_GPL(name)
@@ -409,6 +428,11 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
409428
cpu_online(raw_smp_processor_id()) && (PARAMS(cond)), \
410429
PARAMS(void *__data, proto))
411430

431+
#define DECLARE_TRACE_SYSCALL(name, proto, args) \
432+
__DECLARE_TRACE_SYSCALL(name, PARAMS(proto), PARAMS(args), \
433+
cpu_online(raw_smp_processor_id()), \
434+
PARAMS(void *__data, proto))
435+
412436
#define TRACE_EVENT_FLAGS(event, flag)
413437

414438
#define TRACE_EVENT_PERF_PERM(event, expr...)
@@ -546,6 +570,9 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
546570
struct, assign, print) \
547571
DECLARE_TRACE_CONDITION(name, PARAMS(proto), \
548572
PARAMS(args), PARAMS(cond))
573+
#define TRACE_EVENT_SYSCALL(name, proto, args, struct, assign, \
574+
print, reg, unreg) \
575+
DECLARE_TRACE_SYSCALL(name, PARAMS(proto), PARAMS(args))
549576

550577
#define TRACE_EVENT_FLAGS(event, flag)
551578

include/trace/bpf_probe.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ __bpf_trace_##call(void *__data, proto) \
5353
#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
5454
__BPF_DECLARE_TRACE(call, PARAMS(proto), PARAMS(args))
5555

56+
#undef DECLARE_EVENT_SYSCALL_CLASS
57+
#define DECLARE_EVENT_SYSCALL_CLASS DECLARE_EVENT_CLASS
58+
5659
/*
5760
* This part is compiled out, it is only here as a build time check
5861
* to make sure that if the tracepoint handling changes, the

include/trace/define_trace.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646
assign, print, reg, unreg) \
4747
DEFINE_TRACE_FN(name, reg, unreg, PARAMS(proto), PARAMS(args))
4848

49+
#undef TRACE_EVENT_SYSCALL
50+
#define TRACE_EVENT_SYSCALL(name, proto, args, struct, assign, print, reg, unreg) \
51+
DEFINE_TRACE_FN(name, reg, unreg, PARAMS(proto), PARAMS(args))
52+
4953
#undef TRACE_EVENT_NOP
5054
#define TRACE_EVENT_NOP(name, proto, args, struct, assign, print)
5155

@@ -107,6 +111,7 @@
107111
#undef TRACE_EVENT
108112
#undef TRACE_EVENT_FN
109113
#undef TRACE_EVENT_FN_COND
114+
#undef TRACE_EVENT_SYSCALL
110115
#undef TRACE_EVENT_CONDITION
111116
#undef TRACE_EVENT_NOP
112117
#undef DEFINE_EVENT_NOP

include/trace/events/syscalls.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
#ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS
1717

18-
TRACE_EVENT_FN(sys_enter,
18+
TRACE_EVENT_SYSCALL(sys_enter,
1919

2020
TP_PROTO(struct pt_regs *regs, long id),
2121

@@ -41,7 +41,7 @@ TRACE_EVENT_FN(sys_enter,
4141

4242
TRACE_EVENT_FLAGS(sys_enter, TRACE_EVENT_FL_CAP_ANY)
4343

44-
TRACE_EVENT_FN(sys_exit,
44+
TRACE_EVENT_SYSCALL(sys_exit,
4545

4646
TP_PROTO(struct pt_regs *regs, long ret),
4747

include/trace/perf.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ perf_trace_##call(void *__data, proto) \
5555
head, __task); \
5656
}
5757

58+
#undef DECLARE_EVENT_SYSCALL_CLASS
59+
#define DECLARE_EVENT_SYSCALL_CLASS DECLARE_EVENT_CLASS
60+
5861
/*
5962
* This part is compiled out, it is only here as a build time check
6063
* to make sure that if the tracepoint handling changes, the

include/trace/trace_events.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@
4545
PARAMS(print)); \
4646
DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args));
4747

48+
#undef TRACE_EVENT_SYSCALL
49+
#define TRACE_EVENT_SYSCALL(name, proto, args, tstruct, assign, print, reg, unreg) \
50+
DECLARE_EVENT_SYSCALL_CLASS(name, \
51+
PARAMS(proto), \
52+
PARAMS(args), \
53+
PARAMS(tstruct), \
54+
PARAMS(assign), \
55+
PARAMS(print)); \
56+
DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args));
57+
4858
#include "stages/stage1_struct_define.h"
4959

5060
#undef DECLARE_EVENT_CLASS
@@ -57,6 +67,9 @@
5767
\
5868
static struct trace_event_class event_class_##name;
5969

70+
#undef DECLARE_EVENT_SYSCALL_CLASS
71+
#define DECLARE_EVENT_SYSCALL_CLASS DECLARE_EVENT_CLASS
72+
6073
#undef DEFINE_EVENT
6174
#define DEFINE_EVENT(template, name, proto, args) \
6275
static struct trace_event_call __used \
@@ -117,6 +130,9 @@
117130
tstruct; \
118131
};
119132

133+
#undef DECLARE_EVENT_SYSCALL_CLASS
134+
#define DECLARE_EVENT_SYSCALL_CLASS DECLARE_EVENT_CLASS
135+
120136
#undef DEFINE_EVENT
121137
#define DEFINE_EVENT(template, name, proto, args)
122138

@@ -208,6 +224,9 @@ static struct trace_event_functions trace_event_type_funcs_##call = { \
208224
.trace = trace_raw_output_##call, \
209225
};
210226

227+
#undef DECLARE_EVENT_SYSCALL_CLASS
228+
#define DECLARE_EVENT_SYSCALL_CLASS DECLARE_EVENT_CLASS
229+
211230
#undef DEFINE_EVENT_PRINT
212231
#define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
213232
static notrace enum print_line_t \
@@ -265,6 +284,9 @@ static inline notrace int trace_event_get_offsets_##call( \
265284
return __data_size; \
266285
}
267286

287+
#undef DECLARE_EVENT_SYSCALL_CLASS
288+
#define DECLARE_EVENT_SYSCALL_CLASS DECLARE_EVENT_CLASS
289+
268290
#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
269291

270292
/*
@@ -409,6 +431,9 @@ trace_event_raw_event_##call(void *__data, proto) \
409431
* fail to compile unless it too is updated.
410432
*/
411433

434+
#undef DECLARE_EVENT_SYSCALL_CLASS
435+
#define DECLARE_EVENT_SYSCALL_CLASS DECLARE_EVENT_CLASS
436+
412437
#undef DEFINE_EVENT
413438
#define DEFINE_EVENT(template, call, proto, args) \
414439
static inline void ftrace_test_probe_##call(void) \
@@ -434,6 +459,9 @@ static struct trace_event_class __used __refdata event_class_##call = { \
434459
_TRACE_PERF_INIT(call) \
435460
};
436461

462+
#undef DECLARE_EVENT_SYSCALL_CLASS
463+
#define DECLARE_EVENT_SYSCALL_CLASS DECLARE_EVENT_CLASS
464+
437465
#undef DEFINE_EVENT
438466
#define DEFINE_EVENT(template, call, proto, args) \
439467
\

0 commit comments

Comments
 (0)