Re: [PATCH v12 16/20] perf intel-tpebs: Use DEFINE_MUTEX for tpebs_mtx

From: Ian Rogers

Date: Fri Nov 13 2026 - 12:44:36 EST


On Wed, Nov 11, 2026 at 11:08 PM Namhyung Kim <namhyung@xxxxxxxxxx> wrote:
>
> On Wed, Nov 11, 2026 at 09:42:08AM -0800, Ian Rogers wrote:
> > Replace tpebs_mtx_get() and its pthread_once() initialization helper
> > tpebs_init() with DEFINE_MUTEX(tpebs_mtx) and static initializers for
> > control_fd and ack_fd.
> >
> > Signed-off-by: Ian Rogers <irogers@xxxxxxxxxx>
> > ---
> > tools/perf/util/intel-tpebs.c | 91 +++++++++++++++--------------------
> > 1 file changed, 38 insertions(+), 53 deletions(-)
> >
> > diff --git a/tools/perf/util/intel-tpebs.c b/tools/perf/util/intel-tpebs.c
> > index 5cb090b27fbd..2edd8297fa1b 100644
> > --- a/tools/perf/util/intel-tpebs.c
> > +++ b/tools/perf/util/intel-tpebs.c
> > @@ -38,12 +38,12 @@
> >
> > bool tpebs_recording;
> > enum tpebs_mode tpebs_mode;
> > +static DEFINE_MUTEX(tpebs_mtx);
> > static LIST_HEAD(tpebs_results);
> > static pthread_t tpebs_reader_thread;
> > static struct child_process tpebs_cmd;
> > -static int control_fd[2], ack_fd[2];
> > -static struct mutex tpebs_mtx;
> > static struct cond tpebs_cmd_cond = { .cond = PTHREAD_COND_INITIALIZER };
> > +static int control_fd[2] = { -1, -1 }, ack_fd[2] = { -1, -1 };
>
> Nit: I think it's better to split the line when they have initializers.

Done in v13 (along with folding in the __guarded_by(&tpebs_mtx)
annotations from the next patch).

Thanks,
Ian

> Thanks,
> Namhyung
>
>
> > static bool tpebs_stopping;
> > static bool tpebs_enabled;
> > static bool tpebs_cmd_in_flight;