Skip to content

Commit a9cfb87

Browse files
compudjrostedt
authored andcommitted
tracing: Introduce tracepoint extended structure
Shrink the struct tracepoint size from 80 bytes to 72 bytes on x86-64 by moving the (typically NULL) regfunc/unregfunc pointers to an extended structure. Tested-by: Jordan Rife <[email protected]> Cc: Michael Jeanson <[email protected]> Cc: Thomas Gleixner <[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]> Cc: Jordan Rife <[email protected]> Cc: [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 e9f0a36 commit a9cfb87

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

include/linux/tracepoint-defs.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,20 @@ struct tracepoint_func {
2929
int prio;
3030
};
3131

32+
struct tracepoint_ext {
33+
int (*regfunc)(void);
34+
void (*unregfunc)(void);
35+
};
36+
3237
struct tracepoint {
3338
const char *name; /* Tracepoint name */
3439
struct static_key_false key;
3540
struct static_call_key *static_call_key;
3641
void *static_call_tramp;
3742
void *iterator;
3843
void *probestub;
39-
int (*regfunc)(void);
40-
void (*unregfunc)(void);
4144
struct tracepoint_func __rcu *funcs;
45+
struct tracepoint_ext *ext;
4246
};
4347

4448
#ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS

include/linux/tracepoint.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
302302
* structures, so we create an array of pointers that will be used for iteration
303303
* on the tracepoints.
304304
*/
305-
#define DEFINE_TRACE_FN(_name, _reg, _unreg, proto, args) \
305+
#define __DEFINE_TRACE_EXT(_name, _ext, proto, args) \
306306
static const char __tpstrtab_##_name[] \
307307
__section("__tracepoints_strings") = #_name; \
308308
extern struct static_call_key STATIC_CALL_KEY(tp_func_##_name); \
@@ -316,9 +316,9 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
316316
.static_call_tramp = STATIC_CALL_TRAMP_ADDR(tp_func_##_name), \
317317
.iterator = &__traceiter_##_name, \
318318
.probestub = &__probestub_##_name, \
319-
.regfunc = _reg, \
320-
.unregfunc = _unreg, \
321-
.funcs = NULL }; \
319+
.funcs = NULL, \
320+
.ext = _ext, \
321+
}; \
322322
__TRACEPOINT_ENTRY(_name); \
323323
int __traceiter_##_name(void *__data, proto) \
324324
{ \
@@ -341,8 +341,15 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
341341
} \
342342
DEFINE_STATIC_CALL(tp_func_##_name, __traceiter_##_name);
343343

344-
#define DEFINE_TRACE(name, proto, args) \
345-
DEFINE_TRACE_FN(name, NULL, NULL, PARAMS(proto), PARAMS(args));
344+
#define DEFINE_TRACE_FN(_name, _reg, _unreg, _proto, _args) \
345+
static struct tracepoint_ext __tracepoint_ext_##_name = { \
346+
.regfunc = _reg, \
347+
.unregfunc = _unreg, \
348+
}; \
349+
__DEFINE_TRACE_EXT(_name, &__tracepoint_ext_##_name, PARAMS(_proto), PARAMS(_args));
350+
351+
#define DEFINE_TRACE(_name, _proto, _args) \
352+
__DEFINE_TRACE_EXT(_name, NULL, PARAMS(_proto), PARAMS(_args));
346353

347354
#define EXPORT_TRACEPOINT_SYMBOL_GPL(name) \
348355
EXPORT_SYMBOL_GPL(__tracepoint_##name); \

kernel/tracepoint.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,8 @@ static int tracepoint_add_func(struct tracepoint *tp,
278278
struct tracepoint_func *old, *tp_funcs;
279279
int ret;
280280

281-
if (tp->regfunc && !static_key_enabled(&tp->key)) {
282-
ret = tp->regfunc();
281+
if (tp->ext && tp->ext->regfunc && !static_key_enabled(&tp->key)) {
282+
ret = tp->ext->regfunc();
283283
if (ret < 0)
284284
return ret;
285285
}
@@ -362,9 +362,8 @@ static int tracepoint_remove_func(struct tracepoint *tp,
362362
switch (nr_func_state(tp_funcs)) {
363363
case TP_FUNC_0: /* 1->0 */
364364
/* Removed last function */
365-
if (tp->unregfunc && static_key_enabled(&tp->key))
366-
tp->unregfunc();
367-
365+
if (tp->ext && tp->ext->unregfunc && static_key_enabled(&tp->key))
366+
tp->ext->unregfunc();
368367
static_branch_disable(&tp->key);
369368
/* Set iterator static call */
370369
tracepoint_update_call(tp, tp_funcs);

0 commit comments

Comments
 (0)