Re: [PATCH v2 3/4] perf build: Use libtraceevent from the system

From: Ian Rogers
Date: Fri Dec 02 2022 - 14:45:43 EST


On Fri, Dec 2, 2022 at 10:29 AM Arnaldo Carvalho de Melo
<acme@xxxxxxxxxx> wrote:
>
> Em Fri, Dec 02, 2022 at 10:08:04AM -0800, Namhyung Kim escreveu:
> > On Wed, Nov 30, 2022 at 12:13 PM Ian Rogers <irogers@xxxxxxxxxx> wrote:
> > >
> > > On Wed, Nov 30, 2022 at 11:05 AM Namhyung Kim <namhyung@xxxxxxxxxx> wrote:
> > > >
> > > > On Tue, Nov 29, 2022 at 10:30 PM Ian Rogers <irogers@xxxxxxxxxx> wrote:
> > > > >
> > > > > Remove the LIBTRACEEVENT_DYNAMIC and LIBTRACEFS_DYNAMIC. If
> > > > > libtraceevent isn't installed or NO_LIBTRACEEVENT=1 is passed to the
> > > > > build, don't compile in libtraceevent and libtracefs support. This
> > > > > also disables CONFIG_TRACE that controls "perf
> > > > > trace". CONFIG_TRACEEVENT is used to control enablement in
> > > > > Build/Makefiles, HAVE_LIBTRACEEVENT is used in C code. Without
> > > > > HAVE_LIBTRACEEVENT tracepoints are disabled and as such the commands
> > > > > kmem, kwork, lock, sched and timechart are removed. The majority of
> > > > > commands continue to work including "perf test".
> > > >
> > > > Maybe we can have a different approach. I guess the trace data
> > > > access is isolated then we can make dummy interfaces when there's
> > > > no libtraceevent. This way we don't need to touch every command
> > > > and let it fail when it's asked.
> > >
> > > Sounds like a worthwhile refactor that can land on top of this change.
> > >
> > > > The motivation is that we should be able to run the sub-commands
> > > > as much as possible. In fact, we could run 'record' part only on the
> > > > target machine and pass the data to the host for analysis with a
> > > > full-fledged perf. Also some commands like 'perf lock contention'
> > > > can run with or without libtraceevent (using BPF only).
> > >
> > > The issue here is that perf lock contention will use evsel__new_tp and
> > > internally that uses libtraceevent. As such it is removed without
> > > HAVE_LIBTRACEEVENT. Without the evsel there's not much perf lock
> > > contention can do, so rather than litter the code with
> > > HAVE_LIBTRACEEVENT and for it to be broken, I made the choice just to
> > > remove it from the no libtraceevent build for now.
> >
> > I don't think it needs evsel__new_tp() when BPF is used.
> > The BPF program is attached to the raw tracepoint without
> > perf_event and the result is written to the BPF map.
> >
> > >
> > > I think it is worth pursuing these patches in the shape they are in so
> > > that we can land the removal of tools/lib/traceevent and ensure the
> > > migration away from an out-of-date version of that library.
> >
> > Yeah, I agree that we should remove the stale libtraceevent but
> > I'd like to do it with minimal changes in the perf code base.
> > Let me take a look at this.
>
> Ok, was going to take a look at this patchkit, will wait for you now.
>
> - Arnaldo

So the problematic function is:
https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/tree/tools/perf/util/evsel.c?h=perf/core#n482
struct evsel *evsel__newtp_idx(const char *sys, const char *name, int idx)

on success it will always initialize:
https://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git/tree/tools/perf/util/evsel.c?h=perf/core#n499
evsel->tp_format = trace_event__tp_format(sys, name);

tp_format is a libtraceevent type so this patch makes the variable
conditional on HAVE_LIBTRACEEVENT. I think this will remain true even
with a new evsel__newtp function that isn't dependent on
libtraceevent. I also think adding such things is best kept out of
this patch which is trying to do the minimal (only 312 lines of
addition) to have a build without libtraceevent.

Given we expect builds to use libtraceevent and we should build off of
this patch, I think we should look to land it for 6.2.

Thanks,
Ian