mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ian Rogers <irogers@google.com>
Cc: Namhyung Kim <namhyung@kernel.org>,
	Ingo Molnar <mingo@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Jiri Olsa <jolsa@kernel.org>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Clark Williams <williams@redhat.com>,
	Kate Carcia <kcarcia@redhat.com>,
	linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: Re: [PATCH 2/6] perf thread: Allow tools to register a thread->priv destructor
Date: Thu, 20 Jul 2023 10:49:56 -0300	[thread overview]
Message-ID: <ZLk7hOvDsliOboEH@kernel.org> (raw)
In-Reply-To: <CAP-5=fV3Er=Ek8=iE=bSGbEBmM56_PJffMWot1g_5Bh8B5hO7A@mail.gmail.com>

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@kernel.org> wrote:
> >
> > From: Arnaldo Carvalho de Melo <acme@redhat.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@intel.com>
> > Cc: Ian Rogers <irogers@google.com>
> > Cc: Jiri Olsa <jolsa@kernel.org>
> > Cc: Namhyung Kim <namhyung@kernel.org>
> > Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.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

  reply	other threads:[~2023-07-20 13:50 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-19 20:29 [PATCHES 0/6] Fix some 'perf trace' leaks found with -fsanitize=address Arnaldo Carvalho de Melo
2023-07-19 20:29 ` [PATCH 1/6] perf evsel: Free evsel->filter on the destructor Arnaldo Carvalho de Melo
2023-07-19 20:29 ` [PATCH 2/6] perf thread: Allow tools to register a thread->priv destructor Arnaldo Carvalho de Melo
2023-07-19 22:31   ` Ian Rogers
2023-07-20 13:49     ` Arnaldo Carvalho de Melo [this message]
2023-07-19 20:29 ` [PATCH 3/6] perf trace: Register a thread priv destructor Arnaldo Carvalho de Melo
2023-07-19 20:29 ` [PATCH 4/6] perf trace: Really free the evsel->priv area Arnaldo Carvalho de Melo
2023-07-19 20:29 ` [PATCH 5/6] perf trace: Free thread_trace->files table Arnaldo Carvalho de Melo
2023-07-19 20:29 ` [PATCH 6/6] MAINTAINERS: Add git information for perf-tools and perf-tools-next trees/branches Arnaldo Carvalho de Melo
2023-07-19 22:34 ` [PATCHES 0/6] Fix some 'perf trace' leaks found with -fsanitize=address Ian Rogers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZLk7hOvDsliOboEH@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=kcarcia@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=williams@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome