From: yskelg@gmail.com
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
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>,
Adrian Hunter <adrian.hunter@intel.com>,
"Liang, Kan" <kan.liang@linux.intel.com>
Cc: Gautham Shenoy <gautham.shenoy@amd.com>,
K Prateek Nayak <kprateek.nayak@amd.com>,
skhan@linuxfoundation.org, Austin Kim <austindh.kim@gmail.com>,
shjy180909@gmail.com, linux-perf-users@vger.kernel.org,
linux-kernel@vger.kernel.org,
linux-kernel-mentees@lists.linuxfoundation.org,
Yunseong Kim <yskelg@gmail.com>
Subject: [PATCH] perf stat: allocation check when calculating cache instance ID
Date: Mon, 27 May 2024 18:03:02 +0900 [thread overview]
Message-ID: <20240527090300.17864-1-yskelg@gmail.com> (raw)
From: Yunseong Kim <yskelg@gmail.com>
Adds an allocation check for cpu_map before perf_cpu_map__min() accessing
Signed-off-by: Yunseong Kim <yskelg@gmail.com>
---
tools/perf/builtin-stat.c | 24 +++++++++++++-----------
1 file changed, 13 insertions(+), 11 deletions(-)
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 35f79b48e8dc..1f238824abb2 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -1291,20 +1291,22 @@ static struct option stat_options[] = {
*/
static int cpu__get_cache_id_from_map(struct perf_cpu cpu, char *map)
{
- int id;
+ int id = cpu.cpu;
struct perf_cpu_map *cpu_map = perf_cpu_map__new(map);
- /*
- * If the map contains no CPU, consider the current CPU to
- * be the first online CPU in the cache domain else use the
- * first online CPU of the cache domain as the ID.
- */
- id = perf_cpu_map__min(cpu_map).cpu;
- if (id == -1)
- id = cpu.cpu;
+ if (cpu_map) {
+ /*
+ * If the map contains no CPU, consider the current CPU to
+ * be the first online CPU in the cache domain else use the
+ * first online CPU of the cache domain as the ID.
+ */
+ id = perf_cpu_map__min(cpu_map).cpu;
+ if (id == -1)
+ id = cpu.cpu;
- /* Free the perf_cpu_map used to find the cache ID */
- perf_cpu_map__put(cpu_map);
+ /* Free the perf_cpu_map used to find the cache ID */
+ perf_cpu_map__put(cpu_map);
+ }
return id;
}
--
2.34.1
next reply other threads:[~2024-05-27 9:06 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-27 9:03 yskelg [this message]
2024-05-28 18:56 ` [PATCH] perf stat: allocation check when calculating cache instance ID Namhyung Kim
2024-05-30 11:43 ` Yunseong 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=20240527090300.17864-1-yskelg@gmail.com \
--to=yskelg@gmail.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=austindh.kim@gmail.com \
--cc=gautham.shenoy@amd.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-kernel-mentees@lists.linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=shjy180909@gmail.com \
--cc=skhan@linuxfoundation.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;
as well as URLs for NNTP newsgroup(s).