Re: [PATCH v6 15/26] perf trace: Filter the target's tasks in BPF
From: Ian Rogers
Date: Thu Oct 01 2026 - 12:56:15 EST
On Thu, Oct 1, 2026 at 8:43 AM Arnaldo Carvalho de Melo <acme@xxxxxxxxxx> wrote:
>
> On Mon, Sep 28, 2026 at 11:25:54AM -0700, Ian Rogers wrote:
> > +static bool task_traced(void)
> > +{
> > + u64 pid_tgid = bpf_get_current_pid_tgid();
> > + pid_t pid = uses_tgid ? pid_tgid >> 32 : (pid_t)pid_tgid;
> > + bool *traced;
> > +
> > + if (!has_pids_to_trace)
> > + return true;
> > +
>
> I didn't look at the generated code, some optimization may well make the
> bpf_get_current_pif_tgid() to be executed only if has_pids_to_trace is
> !NULL, otherwise it would be better to move that to after the test.
>
> I'm applying it anyway, just caught my attention while applying.
Agreed, that's an inefficiency and the compiler likely won't optimize
it. I'll send a fix.
Thanks,
Ian
> - Arnaldo
>
> > + traced = bpf_map_lookup_elem(&pids_to_trace, &pid);
> > + return traced && *traced;
> > +}