public inbox for llvm@lists.linux.dev
 help / color / mirror / Atom feed
From: Ian Rogers <irogers@google.com>
To: "Peter Zijlstra" <peterz@infradead.org>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Arnaldo Carvalho de Melo" <acme@kernel.org>,
	"Mark Rutland" <mark.rutland@arm.com>,
	"Alexander Shishkin" <alexander.shishkin@linux.intel.com>,
	"Jiri Olsa" <jolsa@kernel.org>,
	"Namhyung Kim" <namhyung@kernel.org>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Darren Hart" <dvhart@infradead.org>,
	"Davidlohr Bueso" <dave@stgolabs.net>,
	"André Almeida" <andrealmeid@igalia.com>,
	"Nathan Chancellor" <nathan@kernel.org>,
	"Nick Desaulniers" <ndesaulniers@google.com>,
	"Tom Rix" <trix@redhat.com>,
	"Athira Rajeev" <atrajeev@linux.vnet.ibm.com>,
	"Weiguo Li" <liwg06@foxmail.com>,
	"Pavithra Gurushankar" <gpavithrasha@gmail.com>,
	"Thomas Richter" <tmricht@linux.ibm.com>,
	"Ravi Bangoria" <ravi.bangoria@amd.com>,
	"Dario Petrillo" <dario.pk1@gmail.com>,
	"Wenyu Liu" <liuwenyu7@huawei.com>,
	Hewenliang <hewenliang4@huawei.com>,
	yaowenbin <yaowenbin1@huawei.com>,
	"Dave Marchevsky" <davemarchevsky@fb.com>,
	"Andrii Nakryiko" <andrii@kernel.org>,
	"Alexandre Truong" <alexandre.truong@arm.com>,
	"Kim Phillips" <kim.phillips@amd.com>,
	"Leo Yan" <leo.yan@linaro.org>,
	"Quentin Monnet" <quentin@isovalent.com>,
	"William Cohen" <wcohen@redhat.com>,
	"Andres Freund" <andres@anarazel.de>,
	"Song Liu" <songliubraving@fb.com>,
	"Adrian Hunter" <adrian.hunter@intel.com>,
	"Martin Liška" <mliska@suse.cz>,
	"Colin Ian King" <colin.king@intel.com>,
	"James Clark" <james.clark@arm.com>,
	"Fangrui Song" <maskray@google.com>,
	"Stephane Eranian" <eranian@google.com>,
	"Kajol Jain" <kjain@linux.ibm.com>,
	"Andi Kleen" <ak@linux.intel.com>,
	"Alexey Bayduraev" <alexey.v.bayduraev@linux.intel.com>,
	"Riccardo Mancini" <rickyman7@gmail.com>,
	"Masami Hiramatsu" <mhiramat@kernel.org>,
	"Christophe JAILLET" <christophe.jaillet@wanadoo.fr>,
	"Zechuan Chen" <chenzechuan1@huawei.com>,
	"Jason Wang" <wangborong@cdjrlc.com>,
	"Lexi Shao" <shaolexi@huawei.com>,
	"Remi Bernon" <rbernon@codeweavers.com>,
	linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org,
	llvm@lists.linux.dev
Cc: Ian Rogers <irogers@google.com>
Subject: [PATCH v1 5/6] perf mutex: Fix thread safety analysis
Date: Tue, 16 Aug 2022 22:39:29 -0700	[thread overview]
Message-ID: <20220817053930.769840-6-irogers@google.com> (raw)
In-Reply-To: <20220817053930.769840-1-irogers@google.com>

Add annotations to describe lock behavior. Add missing unlocks to
perf_sched__replay. Alter hist_iter__top_callback as the thread-safety
analysis cannot follow pointers through local variables.

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/builtin-sched.c | 8 ++++++++
 tools/perf/builtin-top.c   | 5 +++--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 0f52f73be896..a8a765ed28ce 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -658,6 +658,8 @@ static void *thread_func(void *ctx)
 }
 
 static void create_tasks(struct perf_sched *sched)
+	EXCLUSIVE_LOCK_FUNCTION(sched->start_work_mutex)
+	EXCLUSIVE_LOCK_FUNCTION(sched->work_done_wait_mutex)
 {
 	struct task_desc *task;
 	pthread_attr_t attr;
@@ -687,6 +689,8 @@ static void create_tasks(struct perf_sched *sched)
 }
 
 static void wait_for_tasks(struct perf_sched *sched)
+	EXCLUSIVE_LOCKS_REQUIRED(sched->work_done_wait_mutex)
+	EXCLUSIVE_LOCKS_REQUIRED(sched->start_work_mutex)
 {
 	u64 cpu_usage_0, cpu_usage_1;
 	struct task_desc *task;
@@ -738,6 +742,8 @@ static void wait_for_tasks(struct perf_sched *sched)
 }
 
 static void run_one_test(struct perf_sched *sched)
+	EXCLUSIVE_LOCKS_REQUIRED(sched->work_done_wait_mutex)
+	EXCLUSIVE_LOCKS_REQUIRED(sched->start_work_mutex)
 {
 	u64 T0, T1, delta, avg_delta, fluct;
 
@@ -3314,6 +3320,8 @@ static int perf_sched__replay(struct perf_sched *sched)
 	for (i = 0; i < sched->replay_repeat; i++)
 		run_one_test(sched);
 
+	mutex_unlock(&sched->start_work_mutex);
+	mutex_unlock(&sched->work_done_wait_mutex);
 	return 0;
 }
 
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 3757292bfe86..e832f04e3076 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -196,6 +196,7 @@ static void perf_top__record_precise_ip(struct perf_top *top,
 					struct hist_entry *he,
 					struct perf_sample *sample,
 					struct evsel *evsel, u64 ip)
+	EXCLUSIVE_LOCKS_REQUIRED(he->hists->lock)
 {
 	struct annotation *notes;
 	struct symbol *sym = he->ms.sym;
@@ -724,13 +725,13 @@ static void *display_thread(void *arg)
 static int hist_iter__top_callback(struct hist_entry_iter *iter,
 				   struct addr_location *al, bool single,
 				   void *arg)
+	EXCLUSIVE_LOCKS_REQUIRED(iter->he->hists->lock)
 {
 	struct perf_top *top = arg;
-	struct hist_entry *he = iter->he;
 	struct evsel *evsel = iter->evsel;
 
 	if (perf_hpp_list.sym && single)
-		perf_top__record_precise_ip(top, he, iter->sample, evsel, al->addr);
+		perf_top__record_precise_ip(top, iter->he, iter->sample, evsel, al->addr);
 
 	hist__account_cycles(iter->sample->branch_stack, al, iter->sample,
 		     !(top->record_opts.branch_stack & PERF_SAMPLE_BRANCH_ANY),
-- 
2.37.1.595.g718a3a8f04-goog


  parent reply	other threads:[~2022-08-17  5:39 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-17  5:39 [PATCH v1 0/6] Mutex wrapper, locking and memory leak fixes Ian Rogers
2022-08-17  5:39 ` [PATCH v1 1/6] perf mutex: Wrapped usage of mutex and cond Ian Rogers
2022-08-17  5:39 ` [PATCH v1 2/6] perf mutex: Update use of pthread mutex/cond Ian Rogers
2022-08-17 11:54   ` Arnaldo Carvalho de Melo
2022-08-17 13:16     ` Ian Rogers
2022-08-17 13:50       ` Arnaldo Carvalho de Melo
2022-08-17 18:49       ` Arnaldo Carvalho de Melo
2022-08-17 20:42         ` Ian Rogers
2022-08-17  5:39 ` [PATCH v1 3/6] perf dso: Hold lock when accessing nsinfo Ian Rogers
2022-08-17  5:39 ` [PATCH v1 4/6] perf mutex: Add thread safety annotations Ian Rogers
2022-08-17  5:39 ` Ian Rogers [this message]
2022-08-18 16:41   ` [PATCH v1 5/6] perf mutex: Fix thread safety analysis Namhyung Kim
2022-08-18 18:17     ` Ian Rogers
2022-08-19  6:42       ` Namhyung Kim
2022-08-17  5:39 ` [PATCH v1 6/6] perf build: Enable -Wthread-safety with clang Ian Rogers
2022-08-18  6:11   ` Namhyung Kim
2022-08-18 13:17     ` Ian Rogers
2022-08-18 15:59       ` Namhyung Kim
2022-08-18 16:20         ` 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=20220817053930.769840-6-irogers@google.com \
    --to=irogers@google.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=ak@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=alexandre.truong@arm.com \
    --cc=alexey.v.bayduraev@linux.intel.com \
    --cc=andrealmeid@igalia.com \
    --cc=andres@anarazel.de \
    --cc=andrii@kernel.org \
    --cc=atrajeev@linux.vnet.ibm.com \
    --cc=chenzechuan1@huawei.com \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=colin.king@intel.com \
    --cc=dario.pk1@gmail.com \
    --cc=dave@stgolabs.net \
    --cc=davemarchevsky@fb.com \
    --cc=dvhart@infradead.org \
    --cc=eranian@google.com \
    --cc=gpavithrasha@gmail.com \
    --cc=hewenliang4@huawei.com \
    --cc=james.clark@arm.com \
    --cc=jolsa@kernel.org \
    --cc=kim.phillips@amd.com \
    --cc=kjain@linux.ibm.com \
    --cc=leo.yan@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=liuwenyu7@huawei.com \
    --cc=liwg06@foxmail.com \
    --cc=llvm@lists.linux.dev \
    --cc=mark.rutland@arm.com \
    --cc=maskray@google.com \
    --cc=mhiramat@kernel.org \
    --cc=mingo@redhat.com \
    --cc=mliska@suse.cz \
    --cc=namhyung@kernel.org \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=peterz@infradead.org \
    --cc=quentin@isovalent.com \
    --cc=ravi.bangoria@amd.com \
    --cc=rbernon@codeweavers.com \
    --cc=rickyman7@gmail.com \
    --cc=shaolexi@huawei.com \
    --cc=songliubraving@fb.com \
    --cc=tglx@linutronix.de \
    --cc=tmricht@linux.ibm.com \
    --cc=trix@redhat.com \
    --cc=wangborong@cdjrlc.com \
    --cc=wcohen@redhat.com \
    --cc=yaowenbin1@huawei.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