[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <02152f40-1dc5-7f1b-ad88-61ecb146a3da@intel.com>
Date: Wed, 24 Aug 2022 13:14:55 +0300
From: Adrian Hunter <adrian.hunter@...el.com>
To: Ian Rogers <irogers@...gle.com>,
Peter Zijlstra <peterz@...radead.org>,
Ingo Molnar <mingo@...hat.com>,
Arnaldo Carvalho de Melo <acme@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Jiri Olsa <jolsa@...nel.org>,
Namhyung Kim <namhyung@...nel.org>,
Thomas Gleixner <tglx@...utronix.de>,
Darren Hart <dvhart@...radead.org>,
Davidlohr Bueso <dave@...olabs.net>,
André Almeida <andrealmeid@...lia.com>,
Nathan Chancellor <nathan@...nel.org>,
Nick Desaulniers <ndesaulniers@...gle.com>,
Tom Rix <trix@...hat.com>, Weiguo Li <liwg06@...mail.com>,
Athira Rajeev <atrajeev@...ux.vnet.ibm.com>,
Thomas Richter <tmricht@...ux.ibm.com>,
Ravi Bangoria <ravi.bangoria@....com>,
Dario Petrillo <dario.pk1@...il.com>,
Hewenliang <hewenliang4@...wei.com>,
yaowenbin <yaowenbin1@...wei.com>,
Wenyu Liu <liuwenyu7@...wei.com>,
Song Liu <songliubraving@...com>,
Andrii Nakryiko <andrii@...nel.org>,
Dave Marchevsky <davemarchevsky@...com>,
Leo Yan <leo.yan@...aro.org>,
Kim Phillips <kim.phillips@....com>,
Pavithra Gurushankar <gpavithrasha@...il.com>,
Alexandre Truong <alexandre.truong@....com>,
Quentin Monnet <quentin@...valent.com>,
William Cohen <wcohen@...hat.com>,
Andres Freund <andres@...razel.de>,
Adrian Hunter <adrian.hunter@...el.com>,
Martin Liška <mliska@...e.cz>,
Colin Ian King <colin.king@...el.com>,
James Clark <james.clark@....com>,
Fangrui Song <maskray@...gle.com>,
Stephane Eranian <eranian@...gle.com>,
Kajol Jain <kjain@...ux.ibm.com>,
Alexey Bayduraev <alexey.v.bayduraev@...ux.intel.com>,
Riccardo Mancini <rickyman7@...il.com>,
Andi Kleen <ak@...ux.intel.com>,
Masami Hiramatsu <mhiramat@...nel.org>,
Zechuan Chen <chenzechuan1@...wei.com>,
Jason Wang <wangborong@...rlc.com>,
Christophe JAILLET <christophe.jaillet@...adoo.fr>,
Remi Bernon <rbernon@...eweavers.com>,
linux-kernel@...r.kernel.org, linux-perf-users@...r.kernel.org,
bpf@...r.kernel.org, llvm@...ts.linux.dev
Subject: Re: [PATCH v2 07/18] perf record: Update use of pthread mutex
On 24/08/22 01:09, Ian Rogers wrote:
> Switch to the use of mutex wrappers that provide better error checking
> for synth_lock.
It would be better to distinguish patches that make drop-in
replacements from patches like this that change logic.
>
> Signed-off-by: Ian Rogers <irogers@...gle.com>
> ---
> tools/perf/builtin-record.c | 13 +++++++++----
> 1 file changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
> index 4713f0f3a6cf..02eb85677e99 100644
> --- a/tools/perf/builtin-record.c
> +++ b/tools/perf/builtin-record.c
> @@ -21,6 +21,7 @@
> #include "util/evsel.h"
> #include "util/debug.h"
> #include "util/mmap.h"
> +#include "util/mutex.h"
> #include "util/target.h"
> #include "util/session.h"
> #include "util/tool.h"
> @@ -608,17 +609,18 @@ static int process_synthesized_event(struct perf_tool *tool,
> return record__write(rec, NULL, event, event->header.size);
> }
>
> +static struct mutex synth_lock;
> +
> static int process_locked_synthesized_event(struct perf_tool *tool,
> union perf_event *event,
> struct perf_sample *sample __maybe_unused,
> struct machine *machine __maybe_unused)
> {
> - static pthread_mutex_t synth_lock = PTHREAD_MUTEX_INITIALIZER;
> int ret;
>
> - pthread_mutex_lock(&synth_lock);
> + mutex_lock(&synth_lock);
> ret = process_synthesized_event(tool, event, sample, machine);
> - pthread_mutex_unlock(&synth_lock);
> + mutex_unlock(&synth_lock);
> return ret;
> }
>
> @@ -1917,6 +1919,7 @@ static int record__synthesize(struct record *rec, bool tail)
> }
>
> if (rec->opts.nr_threads_synthesize > 1) {
> + mutex_init(&synth_lock, /*pshared=*/false);
It would be better to have mutex_init() and mutex_init_shared()
since /*pshared=*/true is rarely used.
> perf_set_multithreaded();
> f = process_locked_synthesized_event;
> }
> @@ -1930,8 +1933,10 @@ static int record__synthesize(struct record *rec, bool tail)
> rec->opts.nr_threads_synthesize);
> }
>
> - if (rec->opts.nr_threads_synthesize > 1)
> + if (rec->opts.nr_threads_synthesize > 1) {
> perf_set_singlethreaded();
> + mutex_destroy(&synth_lock);
> + }
>
> out:
> return err;
Powered by blists - more mailing lists