From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: rostedt <rostedt@goodmis.org>
Cc: Alexei Starovoitov <ast@fb.com>,
"David S. Miller" <davem@davemloft.net>,
Daniel Borkmann <daniel@iogearbox.net>,
Linus Torvalds <torvalds@linux-foundation.org>,
Peter Zijlstra <peterz@infradead.org>,
netdev@vger.kernel.org, kernel-team@fb.com,
linux-api <linux-api@vger.kernel.org>
Subject: Re: [PATCH v5 bpf-next 06/10] tracepoint: compute num_args at build time
Date: Mon, 26 Mar 2018 11:14:04 -0400 (EDT) [thread overview]
Message-ID: <1787605856.4574.1522077244597.JavaMail.zimbra@efficios.com> (raw)
In-Reply-To: <20180326110204.042801dd@gandalf.local.home>
----- On Mar 26, 2018, at 11:02 AM, rostedt rostedt@goodmis.org wrote:
> On Fri, 23 Mar 2018 19:30:34 -0700
> Alexei Starovoitov <ast@fb.com> wrote:
>
>> From: Alexei Starovoitov <ast@kernel.org>
>>
>> add fancy macro to compute number of arguments passed into tracepoint
>> at compile time and store it as part of 'struct tracepoint'.
>> The number is necessary to check safety of bpf program access that
>> is coming in subsequent patch.
>>
>> for_each_tracepoint_range() api has no users inside the kernel.
>> Make it more useful with ability to stop for_each() loop depending
>> via callback return value.
>> In such form it's used in subsequent patch.
>
> I believe this is used by LTTng.
Indeed, and by SystemTAP as well.
What justifies the need to stop mid-iteration ? A less intrusive alternative
would be to use the "priv" data pointer to keep state telling further calls
to return immediately. Does performance of iteration over tracepoints really
matter here so much that stopping iteration immediately is worth it ?
Thanks,
Mathieu
>
> -- Steve
>
>>
>> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
>> ---
>> include/linux/tracepoint-defs.h | 1 +
>> include/linux/tracepoint.h | 28 +++++++++++++++++++---------
>> include/trace/define_trace.h | 14 +++++++-------
>> kernel/tracepoint.c | 27 ++++++++++++++++-----------
>> 4 files changed, 43 insertions(+), 27 deletions(-)
>>
>> diff --git a/include/linux/tracepoint-defs.h b/include/linux/tracepoint-defs.h
>> index 64ed7064f1fa..39a283c61c51 100644
>> --- a/include/linux/tracepoint-defs.h
>> +++ b/include/linux/tracepoint-defs.h
>> @@ -33,6 +33,7 @@ struct tracepoint {
>> int (*regfunc)(void);
>> void (*unregfunc)(void);
>> struct tracepoint_func __rcu *funcs;
>> + u32 num_args;
>> };
>>
>> #endif
>> diff --git a/include/linux/tracepoint.h b/include/linux/tracepoint.h
>> index c94f466d57ef..2194e7c31484 100644
>> --- a/include/linux/tracepoint.h
>> +++ b/include/linux/tracepoint.h
>> @@ -40,9 +40,19 @@ tracepoint_probe_register_prio(struct tracepoint *tp, void
>> *probe, void *data,
>> int prio);
>> extern int
>> tracepoint_probe_unregister(struct tracepoint *tp, void *probe, void *data);
>> -extern void
>> -for_each_kernel_tracepoint(void (*fct)(struct tracepoint *tp, void *priv),
>> - void *priv);
>> +
>> +#ifdef CONFIG_TRACEPOINTS
>> +void *
>> +for_each_kernel_tracepoint(void *(*fct)(struct tracepoint *tp, void *priv),
>> + void *priv);
>> +#else
>> +static inline void *
>> +for_each_kernel_tracepoint(void *(*fct)(struct tracepoint *tp, void *priv),
>> + void *priv)
>> +{
>> + return NULL;
>> +}
>> +#endif
>>
>> #ifdef CONFIG_MODULES
>> struct tp_module {
>> @@ -230,18 +240,18 @@ extern void syscall_unregfunc(void);
>> * structures, so we create an array of pointers that will be used for iteration
>> * on the tracepoints.
>> */
>> -#define DEFINE_TRACE_FN(name, reg, unreg) \
>> +#define DEFINE_TRACE_FN(name, reg, unreg, num_args) \
>> static const char __tpstrtab_##name[] \
>> __attribute__((section("__tracepoints_strings"))) = #name; \
>> struct tracepoint __tracepoint_##name \
>> __attribute__((section("__tracepoints"))) = \
>> - { __tpstrtab_##name, STATIC_KEY_INIT_FALSE, reg, unreg, NULL };\
>> + { __tpstrtab_##name, STATIC_KEY_INIT_FALSE, reg, unreg, NULL, num_args };\
>> static struct tracepoint * const __tracepoint_ptr_##name __used \
>> __attribute__((section("__tracepoints_ptrs"))) = \
>> &__tracepoint_##name;
>>
>> -#define DEFINE_TRACE(name) \
>> - DEFINE_TRACE_FN(name, NULL, NULL);
>> +#define DEFINE_TRACE(name, num_args) \
>> + DEFINE_TRACE_FN(name, NULL, NULL, num_args);
>>
>> #define EXPORT_TRACEPOINT_SYMBOL_GPL(name) \
>> EXPORT_SYMBOL_GPL(__tracepoint_##name)
>> @@ -275,8 +285,8 @@ extern void syscall_unregfunc(void);
>> return false; \
>> }
>>
>> -#define DEFINE_TRACE_FN(name, reg, unreg)
>> -#define DEFINE_TRACE(name)
>> +#define DEFINE_TRACE_FN(name, reg, unreg, num_args)
>> +#define DEFINE_TRACE(name, num_args)
>> #define EXPORT_TRACEPOINT_SYMBOL_GPL(name)
>> #define EXPORT_TRACEPOINT_SYMBOL(name)
>>
>> diff --git a/include/trace/define_trace.h b/include/trace/define_trace.h
>> index d9e3d4aa3f6e..96b22ace9ae7 100644
>> --- a/include/trace/define_trace.h
>> +++ b/include/trace/define_trace.h
>> @@ -25,7 +25,7 @@
>>
>> #undef TRACE_EVENT
>> #define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
>> - DEFINE_TRACE(name)
>> + DEFINE_TRACE(name, COUNT_ARGS(args))
>>
>> #undef TRACE_EVENT_CONDITION
>> #define TRACE_EVENT_CONDITION(name, proto, args, cond, tstruct, assign, print) \
>> @@ -39,24 +39,24 @@
>> #undef TRACE_EVENT_FN
>> #define TRACE_EVENT_FN(name, proto, args, tstruct, \
>> assign, print, reg, unreg) \
>> - DEFINE_TRACE_FN(name, reg, unreg)
>> + DEFINE_TRACE_FN(name, reg, unreg, COUNT_ARGS(args))
>>
>> #undef TRACE_EVENT_FN_COND
>> #define TRACE_EVENT_FN_COND(name, proto, args, cond, tstruct, \
>> assign, print, reg, unreg) \
>> - DEFINE_TRACE_FN(name, reg, unreg)
>> + DEFINE_TRACE_FN(name, reg, unreg, COUNT_ARGS(args))
>>
>> #undef DEFINE_EVENT
>> #define DEFINE_EVENT(template, name, proto, args) \
>> - DEFINE_TRACE(name)
>> + DEFINE_TRACE(name, COUNT_ARGS(args))
>>
>> #undef DEFINE_EVENT_FN
>> #define DEFINE_EVENT_FN(template, name, proto, args, reg, unreg) \
>> - DEFINE_TRACE_FN(name, reg, unreg)
>> + DEFINE_TRACE_FN(name, reg, unreg, COUNT_ARGS(args))
>>
>> #undef DEFINE_EVENT_PRINT
>> #define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
>> - DEFINE_TRACE(name)
>> + DEFINE_TRACE(name, COUNT_ARGS(args))
>>
>> #undef DEFINE_EVENT_CONDITION
>> #define DEFINE_EVENT_CONDITION(template, name, proto, args, cond) \
>> @@ -64,7 +64,7 @@
>>
>> #undef DECLARE_TRACE
>> #define DECLARE_TRACE(name, proto, args) \
>> - DEFINE_TRACE(name)
>> + DEFINE_TRACE(name, COUNT_ARGS(args))
>>
>> #undef TRACE_INCLUDE
>> #undef __TRACE_INCLUDE
>> diff --git a/kernel/tracepoint.c b/kernel/tracepoint.c
>> index 671b13457387..3f2dc5738c2b 100644
>> --- a/kernel/tracepoint.c
>> +++ b/kernel/tracepoint.c
>> @@ -502,17 +502,22 @@ static __init int init_tracepoints(void)
>> __initcall(init_tracepoints);
>> #endif /* CONFIG_MODULES */
>>
>> -static void for_each_tracepoint_range(struct tracepoint * const *begin,
>> - struct tracepoint * const *end,
>> - void (*fct)(struct tracepoint *tp, void *priv),
>> - void *priv)
>> +static void *for_each_tracepoint_range(struct tracepoint * const *begin,
>> + struct tracepoint * const *end,
>> + void *(*fct)(struct tracepoint *tp, void *priv),
>> + void *priv)
>> {
>> struct tracepoint * const *iter;
>> + void *ret;
>>
>> if (!begin)
>> - return;
>> - for (iter = begin; iter < end; iter++)
>> - fct(*iter, priv);
>> + return NULL;
>> + for (iter = begin; iter < end; iter++) {
>> + ret = fct(*iter, priv);
>> + if (ret)
>> + return ret;
>> + }
>> + return NULL;
>> }
>>
>> /**
>> @@ -520,11 +525,11 @@ static void for_each_tracepoint_range(struct tracepoint *
>> const *begin,
>> * @fct: callback
>> * @priv: private data
>> */
>> -void for_each_kernel_tracepoint(void (*fct)(struct tracepoint *tp, void *priv),
>> - void *priv)
>> +void *for_each_kernel_tracepoint(void *(*fct)(struct tracepoint *tp, void
>> *priv),
>> + void *priv)
>> {
>> - for_each_tracepoint_range(__start___tracepoints_ptrs,
>> - __stop___tracepoints_ptrs, fct, priv);
>> + return for_each_tracepoint_range(__start___tracepoints_ptrs,
>> + __stop___tracepoints_ptrs, fct, priv);
>> }
>> EXPORT_SYMBOL_GPL(for_each_kernel_tracepoint);
--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
next prev parent reply other threads:[~2018-03-26 15:21 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-24 2:30 [PATCH v5 bpf-next 00/10] bpf, tracing: introduce bpf raw tracepoints Alexei Starovoitov
2018-03-24 2:30 ` [PATCH v5 bpf-next 01/10] treewide: remove large struct-pass-by-value from tracepoint arguments Alexei Starovoitov
2018-03-24 2:30 ` [PATCH v5 bpf-next 02/10] net/mediatek: disambiguate mt76 vs mt7601u trace events Alexei Starovoitov
2018-03-24 2:30 ` [PATCH v5 bpf-next 03/10] net/mac802154: disambiguate mac80215 vs mac802154 " Alexei Starovoitov
2018-03-24 2:30 ` [PATCH v5 bpf-next 04/10] net/wireless/iwlwifi: fix iwlwifi_dev_ucode_error tracepoint Alexei Starovoitov
2018-03-24 2:30 ` [PATCH v5 bpf-next 05/10] macro: introduce COUNT_ARGS() macro Alexei Starovoitov
2018-03-24 2:30 ` [PATCH v5 bpf-next 06/10] tracepoint: compute num_args at build time Alexei Starovoitov
2018-03-26 15:02 ` Steven Rostedt
2018-03-26 15:14 ` Mathieu Desnoyers [this message]
2018-03-26 15:42 ` Alexei Starovoitov
2018-03-26 15:55 ` Mathieu Desnoyers
2018-03-26 16:08 ` Alexei Starovoitov
2018-03-26 16:17 ` Mathieu Desnoyers
2018-03-26 16:25 ` Alexei Starovoitov
2018-03-26 16:35 ` Steven Rostedt
2018-03-26 16:47 ` Alexei Starovoitov
2018-03-26 17:04 ` Steven Rostedt
2018-03-26 16:57 ` Mathieu Desnoyers
2018-03-26 17:55 ` Alexei Starovoitov
2018-03-26 18:11 ` Steven Rostedt
2018-03-26 18:39 ` Alexei Starovoitov
2018-03-26 18:48 ` Steven Rostedt
2018-03-26 21:27 ` Mathieu Desnoyers
2018-03-26 15:56 ` Steven Rostedt
2018-03-26 16:31 ` Steven Rostedt
2018-03-24 2:30 ` [PATCH v5 bpf-next 07/10] bpf: introduce BPF_RAW_TRACEPOINT Alexei Starovoitov
2018-03-24 2:30 ` [PATCH v5 bpf-next 08/10] libbpf: add bpf_raw_tracepoint_open helper Alexei Starovoitov
2018-03-24 2:30 ` [PATCH v5 bpf-next 09/10] samples/bpf: raw tracepoint test Alexei Starovoitov
2018-03-24 2:30 ` [PATCH v5 bpf-next 10/10] selftests/bpf: test for bpf_get_stackid() from raw tracepoints Alexei Starovoitov
2018-03-24 2:35 ` [PATCH v5 bpf-next 00/10] bpf, tracing: introduce bpf " Alexei Starovoitov
2018-03-26 8:28 ` Daniel Borkmann
2018-03-26 15:04 ` Steven Rostedt
2018-03-26 15:32 ` Daniel Borkmann
2018-03-26 15:47 ` Steven Rostedt
2018-03-26 16:00 ` Alexei Starovoitov
2018-03-26 16:16 ` Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1787605856.4574.1522077244597.JavaMail.zimbra@efficios.com \
--to=mathieu.desnoyers@efficios.com \
--cc=ast@fb.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=kernel-team@fb.com \
--cc=linux-api@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).