Linux Perf Users
 help / color / mirror / Atom feed
* [PATCH v2 0/7] perf: Support thread maps larger than one record
@ 2026-12-04 11:23 Leo Yan
  2026-12-04 11:23 ` [PATCH v2 1/7] perf stat: Release aggregation maps on report exit Leo Yan
                   ` (7 more replies)
  0 siblings, 8 replies; 13+ messages in thread
From: Leo Yan @ 2026-12-04 11:23 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, James Clark, Suyash Mahar, Amir Ayupov
  Cc: linux-perf-users, linux-kernel, Leo Yan

PERF_RECORD_THREAD_MAP has a 16-bit size field and can hold at most
2,729 entries. Larger maps overflow the size field, producing records
that readers reject.

This series splits large maps into records with a continuation flag and
updates perf script and perf stat report to assemble the complete map
before allocating per-thread counters. It also adds boundary tests and
documents the format.

Maps that fit in one record keep their existing encoding. Split maps
require updated readers.

Signed-off-by: Leo Yan <leo.yan@arm.com>
---
Changes in v2:
- Fixed leak issues (Sashiko).
- Published maps until the last map record is handled (Sashiko).
- Link to v1: https://lore.kernel.org/r/20261115-perf_fix_large_threads-v1-0-69c9b86b9ae5@arm.com

---
Leo Yan (7):
      perf stat: Release aggregation maps on report exit
      perf stat: Drop CPU and thread map references on report exit
      perf stat: Release the initial evlist before opening the session
      perf synthetic-events: Split oversized thread maps into records
      perf: Assemble split thread maps in script and stat report
      perf test: Cover multi-record thread map synthesis
      perf docs: Describe multi-record thread maps

 tools/lib/perf/include/perf/event.h                |   8 ++
 tools/perf/Documentation/perf.data-file-format.txt |  24 +++++
 tools/perf/builtin-script.c                        |  46 +++++++--
 tools/perf/builtin-stat.c                          |  67 +++++++++++--
 tools/perf/tests/thread-map.c                      | 111 +++++++++++++++++++++
 tools/perf/util/synthetic-events.c                 |  46 +++++++--
 tools/perf/util/thread_map.c                       |  51 ++++++++--
 tools/perf/util/thread_map.h                       |   2 +
 8 files changed, 318 insertions(+), 37 deletions(-)
---
base-commit: 316fdb2d4ed172316923794f91dc9cd2b44bebfd
change-id: 20261019-perf_fix_large_threads-f81558a92988

Best regards,
-- 
Leo Yan <leo.yan@arm.com>


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v2 1/7] perf stat: Release aggregation maps on report exit
  2026-12-04 11:23 [PATCH v2 0/7] perf: Support thread maps larger than one record Leo Yan
@ 2026-12-04 11:23 ` Leo Yan
  2026-12-04 11:23 ` [PATCH v2 2/7] perf stat: Drop CPU and thread map references " Leo Yan
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Leo Yan @ 2026-12-04 11:23 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, James Clark, Suyash Mahar, Amir Ayupov
  Cc: linux-perf-users, linux-kernel, Leo Yan

Report mode bypasses the aggregation cleanup in cmd_stat(). An event
processing error also returns from __cmd_report() before session
deletion.

Run perf_stat__exit_aggr_mode() and perf_session__delete() on both
success and error, and return the event processing status.

Fixes: 68d702f7a120 ("perf stat report: Add support to initialize aggr_map from file")
Link: https://sashiko.dev/#/bug/linux-b77574e3-cc57-4338-8810-73a0cfa6fff7
Signed-off-by: Leo Yan <leo.yan@arm.com>
---
 tools/perf/builtin-stat.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 2647878b8711427e33d21bdf66c37ffa854e2b9d..1d440d66cc3eb76c3a461445042fed3d65d8d570 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -2418,11 +2418,10 @@ static int __cmd_report(int argc, const char **argv)
 	evsel_list         = session->evlist;
 
 	ret = perf_session__process_events(session);
-	if (ret)
-		return ret;
 
+	perf_stat__exit_aggr_mode();
 	perf_session__delete(session);
-	return 0;
+	return ret;
 }
 
 static void setup_system_wide(int forks)

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 2/7] perf stat: Drop CPU and thread map references on report exit
  2026-12-04 11:23 [PATCH v2 0/7] perf: Support thread maps larger than one record Leo Yan
  2026-12-04 11:23 ` [PATCH v2 1/7] perf stat: Release aggregation maps on report exit Leo Yan
@ 2026-12-04 11:23 ` Leo Yan
  2026-12-04 11:23 ` [PATCH v2 3/7] perf stat: Release the initial evlist before opening the session Leo Yan
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Leo Yan @ 2026-12-04 11:23 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, James Clark, Suyash Mahar, Amir Ayupov
  Cc: linux-perf-users, linux-kernel, Leo Yan

perf_evlist__set_maps() takes references to the CPU and thread maps read
from the recording. Put both the cpu and thread maps after event
processing.

Fixes: a55e56637613 ("perf evlist: Reference count the cpu and thread maps at set_maps()")
Closes: https://sashiko.dev/#/bug/linux-b77574e3-cc57-4338-8810-73a0cfa6fff7
Signed-off-by: Leo Yan <leo.yan@arm.com>
---
 tools/perf/builtin-stat.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 1d440d66cc3eb76c3a461445042fed3d65d8d570..92892581ccdcb28f20737f94b72406432b67e316 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -2419,6 +2419,8 @@ static int __cmd_report(int argc, const char **argv)
 
 	ret = perf_session__process_events(session);
 
+	perf_thread_map__put(perf_stat.threads);
+	perf_cpu_map__put(perf_stat.cpus);
 	perf_stat__exit_aggr_mode();
 	perf_session__delete(session);
 	return ret;

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 3/7] perf stat: Release the initial evlist before opening the session
  2026-12-04 11:23 [PATCH v2 0/7] perf: Support thread maps larger than one record Leo Yan
  2026-12-04 11:23 ` [PATCH v2 1/7] perf stat: Release aggregation maps on report exit Leo Yan
  2026-12-04 11:23 ` [PATCH v2 2/7] perf stat: Drop CPU and thread map references " Leo Yan
@ 2026-12-04 11:23 ` Leo Yan
  2026-12-04 11:23 ` [PATCH v2 4/7] perf synthetic-events: Split oversized thread maps into records Leo Yan
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 13+ messages in thread
From: Leo Yan @ 2026-12-04 11:23 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, James Clark, Suyash Mahar, Amir Ayupov
  Cc: linux-perf-users, linux-kernel, Leo Yan

If perf_session__new() fails, __cmd_report() returns before the put.
cmd_stat() returns the result of __cmd_report() directly, bypassing
cleanup and leaking the initial evlist. Move the put before session
creation to cover this error path.

Fixes: 2b87be183bca ("perf stat: Avoid evlist leak")
Link: https://sashiko.dev/#/bug/linux-b77574e3-cc57-4338-8810-73a0cfa6fff7
Signed-off-by: Leo Yan <leo.yan@arm.com>
---
 tools/perf/builtin-stat.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 92892581ccdcb28f20737f94b72406432b67e316..7b2025c37e87cff4ddcf7da8c643db008bdaed54 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -2408,13 +2408,19 @@ static int __cmd_report(int argc, const char **argv)
 	perf_stat.tool.stat		= perf_event__process_stat_event;
 	perf_stat.tool.stat_round	= process_stat_round_event;
 
+	/*
+	 * The session creates its own evlist. If perf_session__new() fails,
+	 * cmd_stat() returns without releasing the initial evlist, so drop
+	 * it here.
+	 */
+	evlist__put(evsel_list);
+
 	session = perf_session__new(&perf_stat.data, &perf_stat.tool);
 	if (IS_ERR(session))
 		return PTR_ERR(session);
 
 	perf_stat.session  = session;
 	stat_config.output = stderr;
-	evlist__put(evsel_list);
 	evsel_list         = session->evlist;
 
 	ret = perf_session__process_events(session);

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 4/7] perf synthetic-events: Split oversized thread maps into records
  2026-12-04 11:23 [PATCH v2 0/7] perf: Support thread maps larger than one record Leo Yan
                   ` (2 preceding siblings ...)
  2026-12-04 11:23 ` [PATCH v2 3/7] perf stat: Release the initial evlist before opening the session Leo Yan
@ 2026-12-04 11:23 ` Leo Yan
  2026-12-04 12:15   ` sashiko-bot
  2026-12-04 11:23 ` [PATCH v2 5/7] perf: Assemble split thread maps in script and stat report Leo Yan
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 13+ messages in thread
From: Leo Yan @ 2026-12-04 11:23 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, James Clark, Suyash Mahar, Amir Ayupov
  Cc: linux-perf-users, linux-kernel, Leo Yan

PERF_RECORD_THREAD_MAP has a 16-bit header.size field. With 16 bytes of
fixed fields and 24 bytes per entry, a record can hold at most 2,729
threads within the 65,535-byte size limit.

For larger maps, header.size overflows and no longer describes the
entries counted by nr, so readers reject the record.

Split larger maps into records that fit the size field. Set
PERF_RECORD_MISC_THREAD_MAP_MORE in header.misc when another record
follows, and clear it in the final record. Preserve entry order and the
existing encoding for maps that fit in one record, including empty maps.

Stop synthesis if allocation or the event callback fails.

Signed-off-by: Leo Yan <leo.yan@arm.com>
---
 tools/lib/perf/include/perf/event.h |  8 +++++++
 tools/perf/util/synthetic-events.c  | 46 +++++++++++++++++++++++++++++--------
 2 files changed, 44 insertions(+), 10 deletions(-)

diff --git a/tools/lib/perf/include/perf/event.h b/tools/lib/perf/include/perf/event.h
index fdced574c889e503bda3cf2f8457a14026140025..1785fea2873e4c4dca369b9257626302cece11c0 100644
--- a/tools/lib/perf/include/perf/event.h
+++ b/tools/lib/perf/include/perf/event.h
@@ -406,6 +406,14 @@ struct perf_record_thread_map_entry {
 	char			 comm[16];
 };
 
+/*
+ * PERF_RECORD_MISC_THREAD_MAP_MORE means another THREAD_MAP record follows
+ * for the same map. A clear bit marks the final record.
+ * Each nr counts only that record's entries; concatenate records in order.
+ * A map fitting in one record has the bit clear.
+ */
+#define PERF_RECORD_MISC_THREAD_MAP_MORE (1U << 0)
+
 struct perf_record_thread_map {
 	struct perf_event_header		 header;
 	__u64					 nr;
diff --git a/tools/perf/util/synthetic-events.c b/tools/perf/util/synthetic-events.c
index 3c8d29f27fd91a2cb5ddcf3a20664024edf697c7..938fb63473c479bda167acfe432e7a2d623c6ef0 100644
--- a/tools/perf/util/synthetic-events.c
+++ b/tools/perf/util/synthetic-events.c
@@ -1332,16 +1332,18 @@ int perf_event__synthesize_kernel_mmap(const struct perf_tool *tool,
 	return perf_event__synthesize_extra_kmaps(tool, process, machine);
 }
 
-int perf_event__synthesize_thread_map2(const struct perf_tool *tool,
-				      struct perf_thread_map *threads,
-				      perf_event__handler_t process,
-				      struct machine *machine)
+static int __perf_event__synthesize_thread_map2(const struct perf_tool *tool,
+					       struct perf_thread_map *threads,
+					       perf_event__handler_t process,
+					       struct machine *machine,
+					       int offset, int nr)
 {
 	union perf_event *event;
-	int i, err, size;
+	int i, err;
+	size_t size;
 
 	size  = sizeof(event->thread_map);
-	size +=	threads->nr * sizeof(event->thread_map.entries[0]);
+	size += nr * sizeof(event->thread_map.entries[0]);
 
 	event = zalloc(size);
 	if (!event)
@@ -1349,16 +1351,18 @@ int perf_event__synthesize_thread_map2(const struct perf_tool *tool,
 
 	event->header.type = PERF_RECORD_THREAD_MAP;
 	event->header.size = size;
-	event->thread_map.nr = threads->nr;
+	event->header.misc = offset + nr < threads->nr ?
+			     PERF_RECORD_MISC_THREAD_MAP_MORE : 0;
+	event->thread_map.nr = nr;
 
-	for (i = 0; i < threads->nr; i++) {
+	for (i = 0; i < nr; i++) {
 		struct perf_record_thread_map_entry *entry = &event->thread_map.entries[i];
-		char *comm = perf_thread_map__comm(threads, i);
+		char *comm = perf_thread_map__comm(threads, offset + i);
 
 		if (!comm)
 			comm = (char *) "";
 
-		entry->pid = perf_thread_map__pid(threads, i);
+		entry->pid = perf_thread_map__pid(threads, offset + i);
 		strncpy((char *) &entry->comm, comm, sizeof(entry->comm));
 	}
 
@@ -1368,6 +1372,28 @@ int perf_event__synthesize_thread_map2(const struct perf_tool *tool,
 	return err;
 }
 
+int perf_event__synthesize_thread_map2(const struct perf_tool *tool,
+				      struct perf_thread_map *threads,
+				      perf_event__handler_t process,
+				      struct machine *machine)
+{
+	const int max_nr = (UINT16_MAX - sizeof(struct perf_record_thread_map)) /
+			   sizeof(struct perf_record_thread_map_entry);
+	int offset = 0;
+	int nr, err;
+
+	do {
+		nr = min(threads->nr - offset, max_nr);
+		err = __perf_event__synthesize_thread_map2(tool, threads, process, machine,
+							 offset, nr);
+		if (err)
+			return err;
+		offset += nr;
+	} while (offset < threads->nr);
+
+	return 0;
+}
+
 struct synthesize_cpu_map_data {
 	const struct perf_cpu_map *map;
 	int nr;

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 5/7] perf: Assemble split thread maps in script and stat report
  2026-12-04 11:23 [PATCH v2 0/7] perf: Support thread maps larger than one record Leo Yan
                   ` (3 preceding siblings ...)
  2026-12-04 11:23 ` [PATCH v2 4/7] perf synthetic-events: Split oversized thread maps into records Leo Yan
@ 2026-12-04 11:23 ` Leo Yan
  2026-12-04 12:39   ` sashiko-bot
  2026-12-04 11:23 ` [PATCH v2 6/7] perf test: Cover multi-record thread map synthesis Leo Yan
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 13+ messages in thread
From: Leo Yan @ 2026-12-04 11:23 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, James Clark, Suyash Mahar, Amir Ayupov
  Cc: linux-perf-users, linux-kernel, Leo Yan

Add thread_map__append_event() to assemble records in order, and reuse
it for single-record construction. Free any command names copied by a
failed append.

Keep the map private until the final record arrives. Publish it to the
evlist and allocate counters once both the complete thread map and CPU
map are available. This avoids reallocating a map already shared with
the evlist.

Signed-off-by: Leo Yan <leo.yan@arm.com>
---
 tools/perf/builtin-script.c  | 46 ++++++++++++++++++++++++++++++++++-----
 tools/perf/builtin-stat.c    | 52 +++++++++++++++++++++++++++++++++++++++-----
 tools/perf/util/thread_map.c | 51 +++++++++++++++++++++++++++++++++----------
 tools/perf/util/thread_map.h |  2 ++
 4 files changed, 128 insertions(+), 23 deletions(-)

diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 88aaf9cfd132a7aa80ae240edf8268e59af9cc47..e9fc3c7b1864789b3f99a1f0534c0d6a10e0ed9f 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -162,6 +162,7 @@ struct perf_script {
 	bool			show_cgroup_events;
 	bool			show_text_poke_events;
 	bool			allocated;
+	bool			threads_is_appending;
 	bool			per_event_dump;
 	bool			stitch_lbr;
 	struct evswitch		evswitch;
@@ -3416,6 +3417,10 @@ static int __cmd_script(struct perf_script *script)
 	}
 
 	ret = perf_session__process_events(script->session);
+	if (!ret && !session_done() && script->threads_is_appending) {
+		pr_err("Incomplete thread map: missing final record.\n");
+		ret = -EINVAL;
+	}
 
 	if (script->per_event_dump)
 		perf_script__exit_per_event_dump_stats(script);
@@ -3940,13 +3945,34 @@ static void script__setup_sample_type(struct perf_script *script)
 	}
 }
 
-static int process_stat_round_event(const struct perf_tool *tool __maybe_unused,
+static int process_stat_event(const struct perf_tool *tool, struct perf_session *session,
+			      union perf_event *event)
+{
+	const struct perf_script *script = container_of(tool, struct perf_script, tool);
+
+	if (!script->allocated) {
+		pr_err("Maps are not allocated: threads_is_appending=%d\n",
+		       script->threads_is_appending);
+		return -EINVAL;
+	}
+
+	return perf_event__process_stat_event(tool, session, event);
+}
+
+static int process_stat_round_event(const struct perf_tool *tool,
 				    struct perf_session *session,
 				    union perf_event *event)
 {
+	const struct perf_script *script = container_of(tool, struct perf_script, tool);
 	struct perf_record_stat_round *round = &event->stat_round;
 	struct evsel *counter;
 
+	if (!script->allocated) {
+		pr_err("Maps are not allocated: threads_is_appending=%d\n",
+		       script->threads_is_appending);
+		return -EINVAL;
+	}
+
 	evlist__for_each_entry(session->evlist, counter) {
 		perf_stat_process_counter(&stat_config, counter);
 		process_stat(counter, round->time);
@@ -3975,6 +4001,10 @@ static int set_maps(struct perf_script *script)
 {
 	struct evlist *evlist = script->session->evlist;
 
+	/* Appending can move the map, so share it only after the final record. */
+	if (script->threads_is_appending)
+		return 0;
+
 	if (!script->cpus || !script->threads)
 		return 0;
 
@@ -3996,18 +4026,22 @@ int process_thread_map_event(const struct perf_tool *tool,
 			     union perf_event *event)
 {
 	struct perf_script *script = container_of(tool, struct perf_script, tool);
+	int ret;
 
 	if (dump_trace)
 		perf_event__fprintf_thread_map(event, stdout);
 
-	if (script->threads) {
+	if (script->threads && !script->threads_is_appending) {
 		pr_warning("Extra thread map event, ignoring.\n");
 		return 0;
 	}
 
-	script->threads = thread_map__new_event(&event->thread_map);
-	if (!script->threads)
-		return -ENOMEM;
+	ret = thread_map__append_event(&script->threads, &event->thread_map);
+	if (ret)
+		return ret;
+
+	script->threads_is_appending =
+		event->header.misc & PERF_RECORD_MISC_THREAD_MAP_MORE;
 
 	return set_maps(script);
 }
@@ -4624,7 +4658,7 @@ int cmd_script(int argc, const char **argv)
 	script.tool.auxtrace_info	 = perf_script__process_auxtrace_info;
 	script.tool.auxtrace		 = perf_event__process_auxtrace;
 	script.tool.auxtrace_error	 = perf_event__process_auxtrace_error;
-	script.tool.stat		 = perf_event__process_stat_event;
+	script.tool.stat		 = process_stat_event;
 	script.tool.stat_round		 = process_stat_round_event;
 	script.tool.stat_config		 = process_stat_config_event;
 	script.tool.thread_map		 = process_thread_map_event;
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 7b2025c37e87cff4ddcf7da8c643db008bdaed54..a00594b2210929e1856a744a9c2b00dcc7f9d631 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -147,6 +147,7 @@ struct perf_stat {
 	u64			 bytes_written;
 	struct perf_tool	 tool;
 	bool			 maps_allocated;
+	bool			 threads_is_appending;
 	struct perf_cpu_map	*cpus;
 	struct perf_thread_map *threads;
 	enum aggr_mode		 aggr_mode;
@@ -2234,16 +2235,37 @@ static int __cmd_record(const struct option stat_options[], struct opt_aggr_mode
 	return argc;
 }
 
-static int process_stat_round_event(const struct perf_tool *tool __maybe_unused,
+static int process_stat_event(const struct perf_tool *tool, struct perf_session *session,
+			      union perf_event *event)
+{
+	const struct perf_stat *st = container_of(tool, struct perf_stat, tool);
+
+	if (!st->maps_allocated) {
+		pr_err("Maps are not allocated: threads_is_appending=%d\n",
+		       st->threads_is_appending);
+		return -EINVAL;
+	}
+
+	return perf_event__process_stat_event(tool, session, event);
+}
+
+static int process_stat_round_event(const struct perf_tool *tool,
 				    struct perf_session *session,
 				    union perf_event *event)
 {
+	const struct perf_stat *st = container_of(tool, struct perf_stat, tool);
 	struct perf_record_stat_round *stat_round = &event->stat_round;
 	struct timespec tsh, *ts = NULL;
 	struct perf_env *env = perf_session__env(session);
 	const char **argv = env->cmdline_argv;
 	int argc = env->nr_cmdline;
 
+	if (!st->maps_allocated) {
+		pr_err("Maps are not allocated: threads_is_appending=%d\n",
+		       st->threads_is_appending);
+		return -EINVAL;
+	}
+
 	process_counters();
 
 	if (stat_round->type == PERF_STAT_ROUND_TYPE__FINAL)
@@ -2266,6 +2288,12 @@ int process_stat_config_event(const struct perf_tool *tool,
 {
 	struct perf_stat *st = container_of(tool, struct perf_stat, tool);
 
+	if (!st->maps_allocated) {
+		pr_err("Maps are not allocated: threads_is_appending=%d\n",
+		       st->threads_is_appending);
+		return -EINVAL;
+	}
+
 	perf_event__read_stat_config(&stat_config, &event->stat_config);
 
 	if (perf_cpu_map__is_empty(st->cpus)) {
@@ -2293,6 +2321,10 @@ int process_stat_config_event(const struct perf_tool *tool,
 
 static int set_maps(struct perf_stat *st)
 {
+	/* Appending can move the map, so share it only after the final record. */
+	if (st->threads_is_appending)
+		return 0;
+
 	if (!st->cpus || !st->threads)
 		return 0;
 
@@ -2314,15 +2346,19 @@ int process_thread_map_event(const struct perf_tool *tool,
 			     union perf_event *event)
 {
 	struct perf_stat *st = container_of(tool, struct perf_stat, tool);
+	int ret;
 
-	if (st->threads) {
+	if (st->threads && !st->threads_is_appending) {
 		pr_warning("Extra thread map event, ignoring.\n");
 		return 0;
 	}
 
-	st->threads = thread_map__new_event(&event->thread_map);
-	if (!st->threads)
-		return -ENOMEM;
+	ret = thread_map__append_event(&st->threads, &event->thread_map);
+	if (ret)
+		return ret;
+
+	st->threads_is_appending =
+		event->header.misc & PERF_RECORD_MISC_THREAD_MAP_MORE;
 
 	return set_maps(st);
 }
@@ -2405,7 +2441,7 @@ static int __cmd_report(int argc, const char **argv)
 	perf_stat.tool.thread_map	= process_thread_map_event;
 	perf_stat.tool.cpu_map		= process_cpu_map_event;
 	perf_stat.tool.stat_config	= process_stat_config_event;
-	perf_stat.tool.stat		= perf_event__process_stat_event;
+	perf_stat.tool.stat		= process_stat_event;
 	perf_stat.tool.stat_round	= process_stat_round_event;
 
 	/*
@@ -2424,6 +2460,10 @@ static int __cmd_report(int argc, const char **argv)
 	evsel_list         = session->evlist;
 
 	ret = perf_session__process_events(session);
+	if (!ret && !session_done() && perf_stat.threads_is_appending) {
+		pr_err("Incomplete thread map: missing final record.\n");
+		ret = -EINVAL;
+	}
 
 	perf_thread_map__put(perf_stat.threads);
 	perf_cpu_map__put(perf_stat.cpus);
diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c
index 918ab318023205e48ccc18d9a0dd675c1b77f1ed..4b3e0cd022fb79635b914610f32cb0c9c161568f 100644
--- a/tools/perf/util/thread_map.c
+++ b/tools/perf/util/thread_map.c
@@ -336,28 +336,57 @@ void thread_map__read_comms(struct perf_thread_map *threads)
 		comm_init(threads, i);
 }
 
-static void thread_map__copy_event(struct perf_thread_map *threads,
-				   struct perf_record_thread_map *event)
+int thread_map__append_event(struct perf_thread_map **map,
+			    const struct perf_record_thread_map *event)
 {
-	unsigned i;
+	struct perf_thread_map *threads = *map;
+	bool new_map = !threads;
+	u64 old_nr = threads ? threads->nr : 0, nr, i;
 
-	threads->nr = (int) event->nr;
+	/*
+	 * Trust event->nr to describe chunks of a valid thread map, whose total
+	 * count and allocation size are representable without overflow.
+	 */
+	nr = old_nr + event->nr;
+
+	threads = perf_thread_map__realloc(threads, nr);
+	if (!threads)
+		return -ENOMEM;
+
+	if (new_map) {
+		threads->nr = 0;
+		refcount_set(&threads->refcnt, 1);
+	}
+	*map = threads;
 
 	for (i = 0; i < event->nr; i++) {
-		perf_thread_map__set_pid(threads, i, (pid_t) event->entries[i].pid);
-		threads->map[i].comm = strndup(event->entries[i].comm, 16);
+		u64 idx = old_nr + i;
+
+		perf_thread_map__set_pid(threads, idx,
+					 (pid_t) event->entries[i].pid);
+		threads->map[idx].comm = strndup(event->entries[i].comm,
+						 sizeof(event->entries[i].comm));
+		if (!threads->map[idx].comm)
+			goto out_free;
 	}
+	threads->nr = nr;
 
-	refcount_set(&threads->refcnt, 1);
+	return 0;
+
+out_free:
+	while (i--)
+		zfree(&threads->map[old_nr + i].comm);
+	return -ENOMEM;
 }
 
 struct perf_thread_map *thread_map__new_event(struct perf_record_thread_map *event)
 {
-	struct perf_thread_map *threads;
+	struct perf_thread_map *threads = NULL;
 
-	threads = thread_map__alloc(event->nr);
-	if (threads)
-		thread_map__copy_event(threads, event);
+	if (thread_map__append_event(&threads, event)) {
+		perf_thread_map__put(threads);
+		return NULL;
+	}
 
 	return threads;
 }
diff --git a/tools/perf/util/thread_map.h b/tools/perf/util/thread_map.h
index d700a22b7ae4663aca843baf80f7e5f522d6e607..7ddb9dd3fe9f2525cc7ba358bd6294a293cac910 100644
--- a/tools/perf/util/thread_map.h
+++ b/tools/perf/util/thread_map.h
@@ -13,6 +13,8 @@ struct perf_thread_map *thread_map__new_by_pid(pid_t pid);
 struct perf_thread_map *thread_map__new_by_tid(pid_t tid);
 struct perf_thread_map *thread_map__new(pid_t pid, pid_t tid);
 struct perf_thread_map *thread_map__new_event(struct perf_record_thread_map *event);
+int thread_map__append_event(struct perf_thread_map **map,
+			     const struct perf_record_thread_map *event);
 
 struct perf_thread_map *thread_map__new_str(const char *pid,
 		const char *tid, bool all_threads);

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 6/7] perf test: Cover multi-record thread map synthesis
  2026-12-04 11:23 [PATCH v2 0/7] perf: Support thread maps larger than one record Leo Yan
                   ` (4 preceding siblings ...)
  2026-12-04 11:23 ` [PATCH v2 5/7] perf: Assemble split thread maps in script and stat report Leo Yan
@ 2026-12-04 11:23 ` Leo Yan
  2026-12-04 13:22   ` sashiko-bot
  2026-12-04 11:23 ` [PATCH v2 7/7] perf docs: Describe multi-record thread maps Leo Yan
  2026-12-04 13:22 ` [PATCH v2 0/7] perf: Support thread maps larger than one record sashiko-bot
  7 siblings, 1 reply; 13+ messages in thread
From: Leo Yan @ 2026-12-04 11:23 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, James Clark, Suyash Mahar, Amir Ayupov
  Cc: linux-perf-users, linux-kernel, Leo Yan

Extend the thread-map synthesis test with empty maps and sizes around
the one-record and two-record limits.

Check record sizes, entry counts, continuation flags and entry order.
Reassemble each map and verify PIDs and command names, including missing
names and full-width names without a terminating NUL.

Signed-off-by: Leo Yan <leo.yan@arm.com>
---
 tools/perf/tests/thread-map.c | 111 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 111 insertions(+)

diff --git a/tools/perf/tests/thread-map.c b/tools/perf/tests/thread-map.c
index 877868107455e87e526e2b336ca1ca3c7314033e..ced1a357233d68f5b81d6f2136e8cc0d0a95fc15 100644
--- a/tools/perf/tests/thread-map.c
+++ b/tools/perf/tests/thread-map.c
@@ -1,6 +1,9 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <stdlib.h>
 #include <string.h>
+#include <errno.h>
+#include <stdint.h>
+#include <linux/kernel.h>
 #include <sys/types.h>
 #include <unistd.h>
 #include <sys/prctl.h>
@@ -8,6 +11,7 @@
 #include "thread_map.h"
 #include "debug.h"
 #include "event.h"
+#include "tool.h"
 #include "util/synthetic-events.h"
 #include <perf/event.h>
 #include <internal/threadmap.h>
@@ -86,9 +90,110 @@ static int process_event(const struct perf_tool *tool __maybe_unused,
 	return 0;
 }
 
+struct thread_map_synthesize {
+	struct perf_tool tool;
+	struct perf_thread_map *source;
+	struct perf_thread_map *threads;
+	int offset;
+	int calls;
+};
+
+static int process_thread_map_chunk(const struct perf_tool *tool,
+				    union perf_event *event,
+				    struct perf_sample *sample __maybe_unused,
+				    struct machine *machine __maybe_unused)
+{
+	struct thread_map_synthesize *data = container_of(tool, struct thread_map_synthesize, tool);
+	struct perf_record_thread_map *map = &event->thread_map;
+	const int max_nr = (UINT16_MAX - sizeof(*map)) / sizeof(map->entries[0]);
+	int nr = min(data->source->nr - data->offset, max_nr);
+	bool more = data->offset + nr < data->source->nr;
+	int ret;
+
+	data->calls++;
+	TEST_ASSERT_VAL("wrong chunk type", event->header.type == PERF_RECORD_THREAD_MAP);
+	TEST_ASSERT_VAL("wrong chunk nr", map->nr == (u64)nr);
+	TEST_ASSERT_VAL("wrong chunk size",
+			event->header.size == sizeof(*map) + nr * sizeof(map->entries[0]));
+	TEST_ASSERT_VAL("wrong continuation marker",
+			event->header.misc == (more ? PERF_RECORD_MISC_THREAD_MAP_MORE : 0));
+
+	ret = thread_map__append_event(&data->threads, map);
+	if (ret)
+		return ret;
+	data->offset += nr;
+	return 0;
+}
+
+static int check_thread_map_chunks(struct thread_map_synthesize *data)
+{
+	const int max_nr = (UINT16_MAX - sizeof(struct perf_record_thread_map)) /
+			   sizeof(struct perf_record_thread_map_entry);
+	int ret;
+
+	ret = perf_event__synthesize_thread_map2(&data->tool, data->source,
+					       process_thread_map_chunk, NULL);
+	TEST_ASSERT_VAL("failed to synthesize chunks", !ret);
+	TEST_ASSERT_VAL("wrong chunk count",
+			data->calls == max(1, (data->source->nr + max_nr - 1) / max_nr));
+	TEST_ASSERT_VAL("incomplete thread map", data->offset == data->source->nr);
+	TEST_ASSERT_VAL("failed to assemble thread map", data->threads);
+	TEST_ASSERT_VAL("wrong assembled nr", data->threads->nr == data->source->nr);
+	TEST_ASSERT_VAL("wrong assembled refcnt", refcount_read(&data->threads->refcnt) == 1);
+
+	for (int i = 0; i < data->source->nr; i++) {
+		const char *expected = perf_thread_map__comm(data->source, i);
+		const char *comm = perf_thread_map__comm(data->threads, i);
+
+		if (!expected)
+			expected = "";
+		TEST_ASSERT_VAL("wrong assembled pid",
+				perf_thread_map__pid(data->threads, i) ==
+				perf_thread_map__pid(data->source, i));
+		TEST_ASSERT_VAL("wrong assembled comm", comm && !strncmp(comm, expected, 16));
+		TEST_ASSERT_VAL("assembled comm not terminated",
+				strlen(comm) == strnlen(expected, 16));
+	}
+	return 0;
+}
+
+static int test_thread_map_chunks(int nr)
+{
+	struct thread_map_synthesize data = { 0 };
+	int ret = -ENOMEM;
+
+	data.source = perf_thread_map__new_array(nr, NULL);
+	if (!data.source)
+		return ret;
+
+	for (int i = 0; i < nr; i++) {
+		char comm[32];
+
+		/* Include missing comms and full-width, non-NUL-terminated wire comms. */
+		perf_thread_map__set_pid(data.source, i, nr - i);
+		if (i % 3 == 0)
+			continue;
+		if (i % 3 == 1)
+			snprintf(comm, sizeof(comm), "thread-%d", i);
+		else
+			strcpy(comm, "1234567890123456");
+		data.source->map[i].comm = strdup(comm);
+		if (!data.source->map[i].comm)
+			goto out;
+	}
+
+	ret = check_thread_map_chunks(&data);
+out:
+	perf_thread_map__put(data.threads);
+	perf_thread_map__put(data.source);
+	return ret;
+}
+
 static int test__thread_map_synthesize(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
 {
 	struct perf_thread_map *threads;
+	static const int sizes[] = { 0, 1, 2729, 2730, 3000, 5458, 5459 };
+	int ret;
 
 	TEST_ASSERT_VAL("failed to set process name",
 			!prctl(PR_SET_NAME, NAMEUL, 0, 0, 0));
@@ -103,6 +208,12 @@ static int test__thread_map_synthesize(struct test_suite *test __maybe_unused, i
 		!perf_event__synthesize_thread_map2(NULL, threads, process_event, NULL));
 
 	perf_thread_map__put(threads);
+	for (unsigned int i = 0; i < ARRAY_SIZE(sizes); i++) {
+		ret = test_thread_map_chunks(sizes[i]);
+		if (ret)
+			return ret;
+	}
+
 	return 0;
 }
 

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 7/7] perf docs: Describe multi-record thread maps
  2026-12-04 11:23 [PATCH v2 0/7] perf: Support thread maps larger than one record Leo Yan
                   ` (5 preceding siblings ...)
  2026-12-04 11:23 ` [PATCH v2 6/7] perf test: Cover multi-record thread map synthesis Leo Yan
@ 2026-12-04 11:23 ` Leo Yan
  2026-12-04 13:22 ` [PATCH v2 0/7] perf: Support thread maps larger than one record sashiko-bot
  7 siblings, 0 replies; 13+ messages in thread
From: Leo Yan @ 2026-12-04 11:23 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo, Namhyung Kim, Jiri Olsa, Ian Rogers,
	Adrian Hunter, James Clark, Suyash Mahar, Amir Ayupov
  Cc: linux-perf-users, linux-kernel, Leo Yan

Document the PERF_RECORD_THREAD_MAP layout using the structure names
and flexible array declaration from the code.

Describe the continuation flag and ordered assembly of split maps.
Explain that readers must collect the complete map before allocating
per-thread counters or processing statistics, and that split maps
require updated readers.

Signed-off-by: Leo Yan <leo.yan@arm.com>
---
 tools/perf/Documentation/perf.data-file-format.txt | 24 ++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/tools/perf/Documentation/perf.data-file-format.txt b/tools/perf/Documentation/perf.data-file-format.txt
index 359d6ef0c80aac26a02b81ff590c3545daebf40b..4d6e81e65b59587b867b747d821ca2f1f03baf03 100644
--- a/tools/perf/Documentation/perf.data-file-format.txt
+++ b/tools/perf/Documentation/perf.data-file-format.txt
@@ -656,6 +656,30 @@ struct auxtrace_error_event {
 	char msg[MAX_AUXTRACE_ERROR_MSG];
 };
 
+	PERF_RECORD_THREAD_MAP			= 73,
+
+Lists thread IDs and command names.
+
+struct perf_record_thread_map_entry {
+	uint64_t pid;
+	char comm[16];
+};
+
+struct perf_record_thread_map {
+	struct perf_event_header header;
+	uint64_t nr;
+	struct perf_record_thread_map_entry entries[];
+};
+
+Large maps are split into records that fit in the 16-bit header.size field.
+PERF_RECORD_MISC_THREAD_MAP_MORE (1 << 0) in header.misc is set when another
+record follows and clear for the final record. Each record's nr counts only
+its own entries. Concatenate entries in record order, preserving their
+positions, until a record with MORE clear completes the map. Consumers must
+assemble the complete map before allocating per-thread counters or processing
+statistics. Split maps require readers that support this convention; maps
+that fit in one record are unchanged.
+
 	PERF_RECORD_HEADER_FEATURE		= 80,
 
 Describes a header feature. These are records used in pipe-mode that

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 4/7] perf synthetic-events: Split oversized thread maps into records
  2026-12-04 11:23 ` [PATCH v2 4/7] perf synthetic-events: Split oversized thread maps into records Leo Yan
@ 2026-12-04 12:15   ` sashiko-bot
  2026-12-04 12:31     ` Leo Yan
  0 siblings, 1 reply; 13+ messages in thread
From: sashiko-bot @ 2026-12-04 12:15 UTC (permalink / raw)
  To: Leo Yan; +Cc: linux-perf-users

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] perf: PERF_RECORD_MISC_THREAD_MAP_MORE collides with
  CPUMODE_MASK
--

commit ae292c402320802a8fd8c7199764b2c5af7b2533
Author: Leo Yan <leo.yan@arm.com>

perf synthetic-events: Split oversized thread maps into records

This commit splits oversized thread maps into multiple
PERF_RECORD_THREAD_MAP records that fit within the 16-bit header.size
limit, using a new PERF_RECORD_MISC_THREAD_MAP_MORE flag in header.misc
to mark continuation records.

> diff --git a/tools/lib/perf/include/perf/event.h b/tools/lib/perf/include/perf/event.h
> index fdced574c889e..1785fea2873e4 100644
> --- a/tools/lib/perf/include/perf/event.h
> +++ b/tools/lib/perf/include/perf/event.h
> @@ -406,6 +406,14 @@ struct perf_record_thread_map_entry {
>  	char			 comm[16];
>  };
>  
> +/*
> + * PERF_RECORD_MISC_THREAD_MAP_MORE means another THREAD_MAP record follows
> + * for the same map. A clear bit marks the final record.
> + * Each nr counts only that record's entries; concatenate records in order.
> + * A map fitting in one record has the bit clear.
> + */
> +#define PERF_RECORD_MISC_THREAD_MAP_MORE (1U << 0)

[Severity: Low]
Does defining PERF_RECORD_MISC_THREAD_MAP_MORE as (1U << 0) collide with
PERF_RECORD_MISC_CPUMODE_MASK?

tools/include/uapi/linux/perf_event.h reserves bits 0-2 of header.misc
for PERF_RECORD_MISC_CPUMODE_MASK, with (1 << 0) being
PERF_RECORD_MISC_KERNEL.  Generic perf.data parsers decoding cpumode
will misclassify continuation thread-map records as kernel-mode events.

Other flags in this header (PERF_RECORD_MISC_LOST_SAMPLES_BPF and
PERF_RECORD_MISC_BUILD_ID_SIZE) use (1 << 15) to stay outside the cpumode
mask; moving this flag before it becomes on-disk ABI would avoid that.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-perf_fix_large_threads-v2-0-a6c077f3037d@arm.com?part=4

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 4/7] perf synthetic-events: Split oversized thread maps into records
  2026-12-04 12:15   ` sashiko-bot
@ 2026-12-04 12:31     ` Leo Yan
  0 siblings, 0 replies; 13+ messages in thread
From: Leo Yan @ 2026-12-04 12:31 UTC (permalink / raw)
  To: sashiko-reviews; +Cc: linux-perf-users

On Fri, Dec 04, 2026 at 12:15:08PM +0000, sashiko-bot@kernel.org wrote:

[...]

> > +/*
> > + * PERF_RECORD_MISC_THREAD_MAP_MORE means another THREAD_MAP record follows
> > + * for the same map. A clear bit marks the final record.
> > + * Each nr counts only that record's entries; concatenate records in order.
> > + * A map fitting in one record has the bit clear.
> > + */
> > +#define PERF_RECORD_MISC_THREAD_MAP_MORE (1U << 0)
> 
> [Severity: Low]
> Does defining PERF_RECORD_MISC_THREAD_MAP_MORE as (1U << 0) collide with
> PERF_RECORD_MISC_CPUMODE_MASK?

Makes sense. Will respin.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 5/7] perf: Assemble split thread maps in script and stat report
  2026-12-04 11:23 ` [PATCH v2 5/7] perf: Assemble split thread maps in script and stat report Leo Yan
@ 2026-12-04 12:39   ` sashiko-bot
  0 siblings, 0 replies; 13+ messages in thread
From: sashiko-bot @ 2026-12-04 12:39 UTC (permalink / raw)
  To: Leo Yan; +Cc: linux-perf-users

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] perf: integer overflow in xyarray__new() with split thread
  maps
--

commit 5da116763d7a7d4ff839c7c950a57030bfbeb322
Author: Leo Yan <leo.yan@arm.com>

perf: Assemble split thread maps in script and stat report

This commit adds thread_map__append_event() to assemble split thread map
records in perf script and perf stat report, keeping the thread map
private until the final record arrives before publishing it to the evlist
and allocating counter stats.

> diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c
> index 918ab31802320..4b3e0cd022fb7 100644
> --- a/tools/perf/util/thread_map.c
> +++ b/tools/perf/util/thread_map.c
> @@ -336,28 +336,57 @@ void thread_map__read_comms(struct perf_thread_map *threads)
>  		comm_init(threads, i);
>  }
>  
> -static void thread_map__copy_event(struct perf_thread_map *threads,
> -				   struct perf_record_thread_map *event)
> +int thread_map__append_event(struct perf_thread_map **map,
> +			    const struct perf_record_thread_map *event)
>  {
> -	unsigned i;
> +	struct perf_thread_map *threads = *map;
> +	bool new_map = !threads;
> +	u64 old_nr = threads ? threads->nr : 0, nr, i;
>  
> -	threads->nr = (int) event->nr;
> +	/*
> +	 * Trust event->nr to describe chunks of a valid thread map, whose total
> +	 * count and allocation size are representable without overflow.
> +	 */
> +	nr = old_nr + event->nr;

[Severity: Medium]
Can unbounded thread counts across split PERF_RECORD_THREAD_MAP records
overflow the allocation size in xyarray__new()?

Before this patch, a single PERF_RECORD_THREAD_MAP record held at most
2,729 threads, keeping xyarray__new() below 2^32 bytes even at 32,768
CPUs.  Split records remove that ceiling, so set_maps() ->
evlist__alloc_stats() -> perf_counts__new() -> xyarray__new() can overflow:

tools/lib/perf/xyarray.c:xyarray__new() {
	size_t row_size = ylen * entry_size;
	struct xyarray *xy = zalloc(sizeof(*xy) + xlen * row_size);

	if (xy != NULL) {
		xy->entry_size = entry_size;
		xy->row_size   = row_size;
		xy->entries    = xlen * ylen;
		xy->max_x      = xlen;
		xy->max_y      = ylen;
	}
}

On 32-bit builds, xlen * row_size wraps size_t at 3,277 threads across
two records (with 32,768 CPUs and 40-byte struct perf_counts_values),
producing an undersized buffer while max_x and max_y stay large.

Subsequent PERF_RECORD_STAT events then pass xyarray__entry() bounds
checks in perf_event__process_stat_event() and write out of bounds on
the heap.

On 64-bit builds, xlen * ylen overflows signed 32-bit int at 65,536
threads (with 32,768 CPUs), sign-extending xy->entries to a huge size_t
in xyarray__reset().

Adding overflow checks in xyarray__new() would protect both paths.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-perf_fix_large_threads-v2-0-a6c077f3037d@arm.com?part=5

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 6/7] perf test: Cover multi-record thread map synthesis
  2026-12-04 11:23 ` [PATCH v2 6/7] perf test: Cover multi-record thread map synthesis Leo Yan
@ 2026-12-04 13:22   ` sashiko-bot
  0 siblings, 0 replies; 13+ messages in thread
From: sashiko-bot @ 2026-12-04 13:22 UTC (permalink / raw)
  To: Leo Yan; +Cc: linux-perf-users

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Low] perf test: missing explicit stdio.h and stdbool.h includes in
  thread-map.c
- [Low] perf test: duplicated max_nr calculation and hardcoded limits in
  thread-map.c
--

commit e2b0a1a73dca6e5c1f8eb5380921925d2faf9ba2
Author: Leo Yan <leo.yan@arm.com>

perf test: Cover multi-record thread map synthesis

This commit extends the thread-map synthesis test with empty maps and
sizes around the one-record and two-record limits, reassembling each map
to verify record headers, process IDs, and command names.

> diff --git a/tools/perf/tests/thread-map.c b/tools/perf/tests/thread-map.c
> index 877868107455e..ced1a357233d6 100644
> --- a/tools/perf/tests/thread-map.c
> +++ b/tools/perf/tests/thread-map.c
> @@ -1,6 +1,9 @@
>  // SPDX-License-Identifier: GPL-2.0
>  #include <stdlib.h>
>  #include <string.h>
> +#include <errno.h>
> +#include <stdint.h>
> +#include <linux/kernel.h>
>  #include <sys/types.h>
>  #include <unistd.h>
>  #include <sys/prctl.h>

[Severity: Low]
Should <stdbool.h> and <stdio.h> also be included explicitly here?

process_thread_map_chunk() uses bool and test_thread_map_chunks() calls
snprintf(), so relying on transitive includes risks build failures if
internal perf headers change or when building against musl.

[ ... ]

> +static int process_thread_map_chunk(const struct perf_tool *tool,
> +				    union perf_event *event,
> +				    struct perf_sample *sample __maybe_unused,
> +				    struct machine *machine __maybe_unused)
> +{
> +	struct thread_map_synthesize *data = container_of(tool, struct thread_map_synthesize, tool);
> +	struct perf_record_thread_map *map = &event->thread_map;
> +	const int max_nr = (UINT16_MAX - sizeof(*map)) / sizeof(map->entries[0]);

[ ... ]

> +static int check_thread_map_chunks(struct thread_map_synthesize *data)
> +{
> +	const int max_nr = (UINT16_MAX - sizeof(struct perf_record_thread_map)) /
> +			   sizeof(struct perf_record_thread_map_entry);

[ ... ]

>  static int test__thread_map_synthesize(struct test_suite *test __maybe_unused, int subtest __maybe_unused)
>  {
>  	struct perf_thread_map *threads;
> +	static const int sizes[] = { 0, 1, 2729, 2730, 3000, 5458, 5459 };

[Severity: Low]
Could max_nr be consolidated into a single file-scope constant or macro?

process_thread_map_chunk() and check_thread_map_chunks() duplicate the
per-record entry limit calculation, and sizes[] hardcodes 2729, 2730,
5458, and 5459 instead of expressing them in terms of max_nr.  A shared
constant would remove the duplication and make the one-record and
two-record boundary sizes self-documenting.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-perf_fix_large_threads-v2-0-a6c077f3037d@arm.com?part=6

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 0/7] perf: Support thread maps larger than one record
  2026-12-04 11:23 [PATCH v2 0/7] perf: Support thread maps larger than one record Leo Yan
                   ` (6 preceding siblings ...)
  2026-12-04 11:23 ` [PATCH v2 7/7] perf docs: Describe multi-record thread maps Leo Yan
@ 2026-12-04 13:22 ` sashiko-bot
  7 siblings, 0 replies; 13+ messages in thread
From: sashiko-bot @ 2026-12-04 13:22 UTC (permalink / raw)
  To: Leo Yan; +Cc: linux-perf-users

Sashiko has finished reviewing this 7-patch series:

- Patches 1-3 and 7: no issues found.
- Patch 4 ("perf synthetic-events: Split oversized thread maps i..."): 1
  potential issue (1 Low)
- Patch 5 ("perf: Assemble split thread maps in script and stat..."): 1
  potential issue (1 Medium)
- Patch 6 ("perf test: Cover multi-record thread map synthesis"): 2
  potential issues (2 Low)

Detailed reviews have been sent as separate replies to patches 4-6.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204-perf_fix_large_threads-v2-0-a6c077f3037d@arm.com

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2026-12-04 13:22 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 11:23 [PATCH v2 0/7] perf: Support thread maps larger than one record Leo Yan
2026-12-04 11:23 ` [PATCH v2 1/7] perf stat: Release aggregation maps on report exit Leo Yan
2026-12-04 11:23 ` [PATCH v2 2/7] perf stat: Drop CPU and thread map references " Leo Yan
2026-12-04 11:23 ` [PATCH v2 3/7] perf stat: Release the initial evlist before opening the session Leo Yan
2026-12-04 11:23 ` [PATCH v2 4/7] perf synthetic-events: Split oversized thread maps into records Leo Yan
2026-12-04 12:15   ` sashiko-bot
2026-12-04 12:31     ` Leo Yan
2026-12-04 11:23 ` [PATCH v2 5/7] perf: Assemble split thread maps in script and stat report Leo Yan
2026-12-04 12:39   ` sashiko-bot
2026-12-04 11:23 ` [PATCH v2 6/7] perf test: Cover multi-record thread map synthesis Leo Yan
2026-12-04 13:22   ` sashiko-bot
2026-12-04 11:23 ` [PATCH v2 7/7] perf docs: Describe multi-record thread maps Leo Yan
2026-12-04 13:22 ` [PATCH v2 0/7] perf: Support thread maps larger than one record sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox