[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <ZLk7hOvDsliOboEH@kernel.org>
Date: Thu, 20 Jul 2023 10:49:56 -0300
From: Arnaldo Carvalho de Melo <acme@...nel.org>
To: Ian Rogers <irogers@...gle.com>
Cc: Namhyung Kim <namhyung@...nel.org>, Ingo Molnar <mingo@...nel.org>,
Thomas Gleixner <tglx@...utronix.de>,
Jiri Olsa <jolsa@...nel.org>,
Adrian Hunter <adrian.hunter@...el.com>,
Clark Williams <williams@...hat.com>,
Kate Carcia <kcarcia@...hat.com>, linux-kernel@...r.kernel.org,
linux-perf-users@...r.kernel.org,
Arnaldo Carvalho de Melo <acme@...hat.com>
Subject: Re: [PATCH 2/6] perf thread: Allow tools to register a thread->priv
destructor
Em Wed, Jul 19, 2023 at 03:31:41PM -0700, Ian Rogers escreveu:
> On Wed, Jul 19, 2023 at 1:30 PM Arnaldo Carvalho de Melo
> <acme@...nel.org> wrote:
> >
> > From: Arnaldo Carvalho de Melo <acme@...hat.com>
> >
> > So that when thread__delete() runs it can be called and free stuff tools
> > stashed into thread->priv, like 'perf trace' does and will use this
> > new facility to plug some leaks.
> >
> > Cc: Adrian Hunter <adrian.hunter@...el.com>
> > Cc: Ian Rogers <irogers@...gle.com>
> > Cc: Jiri Olsa <jolsa@...nel.org>
> > Cc: Namhyung Kim <namhyung@...nel.org>
> > Signed-off-by: Arnaldo Carvalho de Melo <acme@...hat.com>
> > ---
> > tools/perf/util/thread.c | 11 +++++++++++
> > tools/perf/util/thread.h | 2 ++
> > 2 files changed, 13 insertions(+)
> >
> > diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c
> > index 0b166404c5c365cf..35dd4e716e411da9 100644
> > --- a/tools/perf/util/thread.c
> > +++ b/tools/perf/util/thread.c
> > @@ -80,6 +80,13 @@ struct thread *thread__new(pid_t pid, pid_t tid)
> > return NULL;
> > }
> >
> > +static void (*thread__priv_destructor)(void *priv);
> > +
> > +void thread__set_priv_destructor(void (*destructor)(void *priv))
> > +{
>
> Perhaps:
> assert(thread__priv_destructor == NULL);
I'll add that.
> To make it clear that there should never be >1 currently.
>
> > + thread__priv_destructor = destructor;
> > +}
> > +
> > void thread__delete(struct thread *thread)
> > {
> > struct namespaces *namespaces, *tmp_namespaces;
> > @@ -112,6 +119,10 @@ void thread__delete(struct thread *thread)
> > exit_rwsem(thread__namespaces_lock(thread));
> > exit_rwsem(thread__comm_lock(thread));
> > thread__free_stitch_list(thread);
> > +
> > + if (thread__priv_destructor)
> > + thread__priv_destructor(thread__priv(thread));
> > +
> > RC_CHK_FREE(thread);
> > }
> >
> > diff --git a/tools/perf/util/thread.h b/tools/perf/util/thread.h
> > index 9068a21ce0fa1b0f..e79225a0ea46b789 100644
> > --- a/tools/perf/util/thread.h
> > +++ b/tools/perf/util/thread.h
> > @@ -71,6 +71,8 @@ struct thread *thread__new(pid_t pid, pid_t tid);
> > int thread__init_maps(struct thread *thread, struct machine *machine);
> > void thread__delete(struct thread *thread);
> >
> > +void thread__set_priv_destructor(void (*destructor)(void *priv));
> > +
> > struct thread *thread__get(struct thread *thread);
> > void thread__put(struct thread *thread);
> >
> > --
> > 2.41.0
> >
--
- Arnaldo
Powered by blists - more mailing lists