From: Leo Yan <leo.yan@arm.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>,
Adrian Hunter <adrian.hunter@intel.com>,
Namhyung Kim <namhyung@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
"Liang, Kan" <kan.liang@linux.intel.com>,
James Clark <james.clark@linaro.org>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Leo Yan <leo.yan@arm.com>
Subject: [PATCH v1 5/5] perf cpumap: Add checking for reference counter
Date: Wed, 25 Sep 2024 20:53:25 +0100 [thread overview]
Message-ID: <20240925195325.426533-6-leo.yan@arm.com> (raw)
In-Reply-To: <20240925195325.426533-1-leo.yan@arm.com>
For the CPU map merging and intersection cases, add an extra check for
the reference counter before releasing the last CPU map.
Signed-off-by: Leo Yan <leo.yan@arm.com>
---
tools/perf/tests/cpumap.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/tools/perf/tests/cpumap.c b/tools/perf/tests/cpumap.c
index d5b6c450f5c9..0bcf603a0ccf 100644
--- a/tools/perf/tests/cpumap.c
+++ b/tools/perf/tests/cpumap.c
@@ -168,6 +168,16 @@ static int __test__cpu_map_merge(const char *lhs, const char *rhs, int nr, const
TEST_ASSERT_VAL("failed to merge map: bad result", !strcmp(buf, expected));
perf_cpu_map__put(a);
perf_cpu_map__put(b);
+
+ /*
+ * If 'b' is a superset of 'a', 'c' points to the same map with the
+ * map 'b'. In this case, the two owners 'b' and 'c' both point to the
+ * same map. The owner 'b' has released the resource above but 'c'
+ * still keeps the ownership, so the reference counter should be 1.
+ */
+ TEST_ASSERT_VAL("unexpected refcnt: bad result",
+ refcount_read(perf_cpu_map__refcnt(c)) == 1);
+
perf_cpu_map__put(c);
return 0;
}
@@ -208,6 +218,16 @@ static int __test__cpu_map_intersect(const char *lhs, const char *rhs, int nr, c
TEST_ASSERT_VAL("failed to intersect map: bad result", !strcmp(buf, expected));
perf_cpu_map__put(a);
perf_cpu_map__put(b);
+
+ /*
+ * If 'b' is a subset of 'a', 'c' points to the same map with the
+ * map 'b'. In this case, the two owners 'b' and 'c' both point to the
+ * same map. The owner 'b' has released the resource above but 'c'
+ * still keeps the ownership, so the reference counter should be 1.
+ */
+ TEST_ASSERT_VAL("unexpected refcnt: bad result",
+ refcount_read(perf_cpu_map__refcnt(c)) == 1);
+
perf_cpu_map__put(c);
return 0;
}
--
2.34.1
next prev parent reply other threads:[~2024-09-25 19:54 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-25 19:53 [PATCH v1 0/5] perf cpumap: Correct for perf_cpu_map__merge() Leo Yan
2024-09-25 19:53 ` [PATCH v1 1/5] libperf cpumap: Correct reference count " Leo Yan
2024-10-10 17:41 ` Adrian Hunter
2024-10-11 9:34 ` Leo Yan
2024-10-11 9:40 ` Leo Yan
2024-10-11 9:46 ` Adrian Hunter
2024-10-11 9:51 ` Leo Yan
2024-09-25 19:53 ` [PATCH v1 2/5] perf: Release old CPU maps after merging Leo Yan
2024-09-25 19:53 ` [PATCH v1 3/5] perf cpumap: Update CPU map merging test Leo Yan
2024-09-25 19:53 ` [PATCH v1 4/5] perf cpumap: Add more tests for CPU map merging Leo Yan
2024-09-25 19:53 ` Leo Yan [this message]
2024-10-10 15:01 ` [PATCH v1 0/5] perf cpumap: Correct for perf_cpu_map__merge() Leo Yan
2024-10-10 16:10 ` Namhyung Kim
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=20240925195325.426533-6-leo.yan@arm.com \
--to=leo.yan@arm.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=irogers@google.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=namhyung@kernel.org \
/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
all inboxes | Powered by JetHome®