All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf header: Fix HEADER_CPU_DOMAIN_INFO feature
@ 2026-09-11  9:41 Thomas Richter
  2026-09-11  9:52 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Thomas Richter @ 2026-09-11  9:41 UTC (permalink / raw)
  To: linux-s390, sumanthk, japo; +Cc: agordeev, iii, hca, Thomas Richter

commit d40c68a49f69 ("perf header: Support CPU DOMAIN relation info")
introduced the HEADER_CPU_DOMAIN_INFO feature and the necessary data
into the perf.data file.

The documentation differs from the data actually written by
write_cpu_domain_info(). The first two values written to the header
section are schedstat_version and max_sched_domains. They are missing
in the documentation. Add them to the documentation.

Also structure cpu_domain_info actually contains an array of
struct domain_info. It is very important for the reader to know
how many array elements have been written to that file section,
especially when the member domain_info::dname is optional and
only present when schedstat_version >= 17.
Add the number of CPUs which have been saved into that file section
so the reader knows in advance how many array elements to read.
This is also in sync with other perf.data file sections which always
have the number of elements before the array data.

Fixes: d40c68a49f69 ("perf header: Support CPU DOMAIN relation info")
Signed-off-by: Thomas Richter <tmricht@linux.ibm.com>
 # Cc: Swapnil Sapkal <swapnil.sapkal@amd.com>
---
 tools/perf/Documentation/perf.data-file-format.txt | 11 +++++++++--
 tools/perf/util/header.c                           | 11 ++++++++++-
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/tools/perf/Documentation/perf.data-file-format.txt b/tools/perf/Documentation/perf.data-file-format.txt
index b90cba9168f8..e37f7484487b 100644
--- a/tools/perf/Documentation/perf.data-file-format.txt
+++ b/tools/perf/Documentation/perf.data-file-format.txt
@@ -453,7 +453,7 @@ List of cpu-domain relation info. The format of the data is as below.
 
 struct domain_info {
 	int domain;
-	char dname[];
+	char dname[];	if schedstat_version >= 17
 	char cpumask[];
 	char cpulist[];
 };
@@ -461,7 +461,14 @@ struct domain_info {
 struct cpu_domain_info {
 	int cpu;
 	int nr_domains;
-	struct domain_info domains[];
++	int schedstat_version;
++	int max_sched_domains;
++	int nr_cpus;
++	struct {
++	       int cpu;
++	       int nr_domains;
++	       struct domain_info domains[nr_domains];
++	} [nr_cpus]
 };
 
 	HEADER_E_MACHINE = 33,
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 7db7da090a1e..770fd21eb1a5 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1836,7 +1836,7 @@ struct cpu_domain_map **build_cpu_domain_map(u32 *schedstat_version, u32 *max_sc
 static int write_cpu_domain_info(struct feat_fd *ff,
 				 struct evlist *evlist __maybe_unused)
 {
-	u32 max_sched_domains = 0, schedstat_version = 0;
+	u32 max_sched_domains = 0, schedstat_version = 0, nr_cpus = 0;
 	struct cpu_domain_map **cd_map;
 	u32 i, j, nr, ret;
 
@@ -1855,6 +1855,15 @@ static int write_cpu_domain_info(struct feat_fd *ff,
 	if (ret < 0)
 		goto out;
 
+	for (i = 0; i < nr; i++) {
+		if (!cd_map[i])
+			continue;
+		++nr_cpus;
+	}
+	ret = do_write(ff, &nr_cpus, sizeof(u32));
+	if (ret < 0)
+		goto out;
+
 	for (i = 0; i < nr; i++) {
 		if (!cd_map[i])
 			continue;
-- 
2.55.0


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

end of thread, other threads:[~2026-09-11  9:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-11  9:41 [PATCH] perf header: Fix HEADER_CPU_DOMAIN_INFO feature Thomas Richter
2026-09-11  9:52 ` sashiko-bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.