From: Ian Rogers <irogers@google.com>
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
Adrian Hunter <adrian.hunter@intel.com>,
James Clark <james.clark@linaro.org>,
linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v1 3/4] perf cpumap: Add "any" CPU handling to cpu_map__snprint_mask
Date: Mon, 1 Dec 2025 15:09:03 -0800 [thread overview]
Message-ID: <20251201230904.290733-3-irogers@google.com> (raw)
In-Reply-To: <20251201230904.290733-1-irogers@google.com>
If the perf_cpu_map is empty or is just the any CPU value, then early
return. Don't process the "any" CPU when creating the bitmap.
Signed-off-by: Ian Rogers <irogers@google.com>
---
tools/perf/util/cpumap.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c
index 89570397a4b3..a80845038a5e 100644
--- a/tools/perf/util/cpumap.c
+++ b/tools/perf/util/cpumap.c
@@ -684,16 +684,21 @@ size_t cpu_map__snprint_mask(struct perf_cpu_map *map, char *buf, size_t size)
unsigned char *bitmap;
struct perf_cpu c, last_cpu = perf_cpu_map__max(map);
- if (buf == NULL)
+ if (buf == NULL || size == 0)
return 0;
+ if (last_cpu.cpu < 0) {
+ buf[0] = '\0';
+ return 0;
+ }
+
bitmap = zalloc(last_cpu.cpu / 8 + 1);
if (bitmap == NULL) {
buf[0] = '\0';
return 0;
}
- perf_cpu_map__for_each_cpu(c, idx, map)
+ perf_cpu_map__for_each_cpu_skip_any(c, idx, map)
bitmap[c.cpu / 8] |= 1 << (c.cpu % 8);
for (int cpu = last_cpu.cpu / 4 * 4; cpu >= 0; cpu -= 4) {
--
2.52.0.158.g65b55ccf14-goog
next prev parent reply other threads:[~2025-12-01 23:09 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-01 23:09 [PATCH v1 1/4] perf stat: Allow no events to open if this is a "--null" run Ian Rogers
2025-12-01 23:09 ` [PATCH v1 2/4] libperf cpumap: Fix perf_cpu_map__max for an empty/NULL map Ian Rogers
2025-12-01 23:09 ` Ian Rogers [this message]
2025-12-01 23:09 ` [PATCH v1 4/4] perf tests stat: Add "--null" coverage Ian Rogers
2025-12-02 4:38 ` [PATCH v1 1/4] perf stat: Allow no events to open if this is a "--null" run Ingo Molnar
2025-12-02 4:41 ` Ingo Molnar
2025-12-02 4:45 ` Ingo Molnar
2025-12-02 4:52 ` Ingo Molnar
2025-12-03 21:49 ` 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=20251201230904.290733-3-irogers@google.com \
--to=irogers@google.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=james.clark@linaro.org \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.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).