Re: [PATCH] tracing/user_events: Run BPF program if attached

From: Steven Rostedt
Date: Tue May 09 2023 - 16:42:54 EST


On Tue, 9 May 2023 16:30:50 -0400
Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:

> >From the user space side, which does:
>
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/samples/user_events/example.c#n60
>
> /* Check if anyone is listening */
> if (enabled) {

Hmm, looking at this deeper, we should update it to prevent the
compiler from optimizing it, and keeping "enabled" in a register. Which
would not work. Should probably add:

if (*(const volatile int *)&enabled) {

-- Steve


> /* Yep, trace out our data */
> writev(data_fd, (const struct iovec *)io, 2);
>
> /* Increase the count */
> count++;
>
> printf("Something was attached, wrote data\n");
> }