perf: Add support for memory region/range reporting
v11 cover perf: Add support for memory region/range reporting
Add support for two memory-related reporting features in the perf tool:
1. Memory region reporting in perf-c2c and perf-script subcommands.
2. Memory range data in perf.data file header and perf-c2c subcommand.
Memory region reporting was introduced as part of support for the Off-module Response facility (OMR) [1], which provides a new data source encoding supporting "up to 8 fine-grained memory regions in addition to the cache region, offering more detailed insights into memory access regions."
Memory Range support was introduced with the addition of the ACPI Memory Range and Region Mapping (MRRM) [2] table. It provides a base address plus a length value for each memory range, as well as NUMA node and local and remote "region ID's" so that "platform firmware can indicate the type of memory for each range."[3]
Include a change allowing PERF_MEM_LVLNUM_L0 to be printed in perf-mem output as well.
[1]: https://lore.kernel.org/all/[email protected]/
[2]: https://lore.kernel.org/lkml/[email protected]/
[3]: MRRM definition allow for future expansion for the OS to assign these region IDs.
v11:
-- perf-c2c: revert to only recording a real memory region for a
cacheline (Dapeng Mi)
v10:
-- perf-c2c: only update a cacheline's mem_region for real cache/memory
regions, so region-less samples (N/A) no longer overwrite a valid region recorded by an earlier sample on the same cacheline (Sashiko)
-- perf-script: replace #include "session.h" in mem-events.h with a
forward declaration of struct perf_session, and add direct session.h includes to the .c files that use it (Sashiko)
-- perf header: add missing #include <fcntl.h> for open()/openat()/
O_DIRECTORY to avoid build failures under strict libc such as musl (Sashiko)
-- perf-c2c: add missing #include <stdio.h> for asprintf() (Sashiko) -- Fix some whitespace and comment formatting issues
v9:
-- Fixed incorrect developer tags and updated perf-c2c to include cache
region reporting (Dapeng Mi)
v8:
-- Updated developer tags and commit messages with real example output
from perf script and perf c2c (Dapeng Mi)
v7:
-- perf-c2c: fix output_str allocation error handling that introduces a
memory leak (Sashiko)
v6:
-- Rebase on 7.3-rc1
v5:
-- perf-c2c: make the cacheline header span and ui_quirks() width
fixup depend on memory-region availability (Namhyung Kim)
v4:
-- perf-script: gate the Region field on the HEADER_MEMORY_RANGES feature
bit via perf_session instead of a global flag, with a pipe-mode fallback
-- perf-c2c: fix output_str allocation error handling
-- perf header: Fix typo in region id bounds checking which made region 255
invalid
v3:
-- included missing ff-size check in process_memory_ranges
-- make memory region reporting in perf c2c-and perf-script conditional
on feature bit, requiring some patch reordering (Namhyung Kim)
-- used open/openat to read memory range sysfs files in memory_range__read()
(Namhyung Kim)
-- Removed path name and file name buffers in memory_range__read(),
instead pass path name from as a parameter from memory_range__parse() (Namhyung Kim)
-- use calloc instead of zalloc in memory_range__parse() and
process_memory_ranges() (Namhyung Kim)
-- Removed redundant check for existence of memory range directory in
memory_range__read() (Namhyung Kim)
-- Included output examples of memory ranges in perf header and perf-c2c
in commit message (Namhyung Kim)
v2:
-- Added missing newline in WARN_ONCE message in c2c_he__set_mem_region() -- increased buffers passed to perf_script__meminfo_scnprintf() from 150
to 200 bytes to avoid silent truncation
-- Added check for NULL return of sysfs__mountpoint() when parsing
memory ranges in sysfs
-- increased MAX_MEMORY_RANGES sanity check from 64 to 256 based on
ACPI MRRM table implementation in Linux kernel
-- added comment for MAX_MEMORY_RANGES to clarify that it is a sanity check
for malformed perf.data files
-- cleaned up some removed code that was added back by this patch series
due to a bad rebase
Dapeng Mi (3):
perf mem: Add support for printing PERF_MEM_LVLNUM_L0 perf tools: Show memory region in perf-c2c subcommand perf tools: Show memory region in perf-script subcommand
Thomas Falcon (3):
perf mem: Fix size tracking for mem_lvl's in
perf_script__meminfo_scnprintf()
perf header: Support memory ranges
perf c2c: print memory region data with stdio output
tools/perf/Documentation/perf-record.txt | 2 +- .../Documentation/perf.data-file-format.txt | 13 ++ tools/perf/builtin-c2c.c | 143 +++++++++++- tools/perf/builtin-inject.c | 1 + tools/perf/builtin-script.c | 13 +- tools/perf/util/bpf-filter.l | 1 + tools/perf/util/c2c.h | 1 + tools/perf/util/env.c | 1 + tools/perf/util/env.h | 10 + tools/perf/util/header.c | 205 ++++++++++++++++++ tools/perf/util/header.h | 1 + tools/perf/util/mem-events.c | 94 +++++++- tools/perf/util/mem-events.h | 5 +- .../scripting-engines/trace-event-python.c | 6 +- 14 files changed, 473 insertions(+), 23 deletions(-)
Signature · 1 line
2.43.0
PATCH v11 1/6 perf mem: Fix size tracking for mem_lvl's in perf_script__meminfo_scnprintf()
When printing memory info in perf script, the entire size of the buffer is passed to perf_mem__lvl_scnprintf() instead of the remaining size. Pass the remaining buffer size instead.
This issue was detected by sashiko during an internal code review.
--- tools/perf/util/mem-events.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/mem-events.c +1 -1
@@ -610,7 +610,7 @@ int perf_script__meminfo_scnprintf(char *out, size_t sz, const struct mem_info * i +=scnprintf (out, sz,"|OP " ); i +=perf_mem__op_scnprintf (out + i, sz - i, mem_info); i +=scnprintf (out + i, sz - i,"|LVL " ); - i +=perf_mem__lvl_scnprintf (out + i, sz, mem_info); + i +=perf_mem__lvl_scnprintf (out + i, sz - i, mem_info); i +=scnprintf (out + i, sz - i,"|SNP " ); i +=perf_mem__snp_scnprintf (out + i, sz - i, mem_info); i +=scnprintf (out + i, sz - i,"|TLB " );
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v11 1/6] perf mem: Fix size tracking for mem_lvl's in perf_script__meminfo_scnprintf()
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 4 lines
When printing memory info in perf script, the entire size of the buffer is passed to
perf_mem__lvl_scnprintf()instead of the remaining size. Pass the remaining buffer size instead.
Quoted 8 lines
This issue was detected by sashiko during an internal code review.
Assisted-by Sashiko:gemini-3.1-pro-previewFixes fdefc3750e847 ("perf mem: Print memory operation type")Reviewed-by Dapeng Mi <[email protected]>Reviewed-by Ian Rogers <[email protected]>Reviewed-by Namhyung Kim <[email protected]>Signed-off-by Thomas Falcon <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH v11 2/6 perf mem: Add support for printing PERF_MEM_LVLNUM_L0
In reply to Thomas FalconFrom: Dapeng Mi <[email protected]>
Add support for printing PERF_MEM_LVLNUM_L0 in perf mem report.
The L0 cache is newly added a small piece of cache which is the closest, lowest-latency memory cache tied directly to the execution pipeline.
The table "Table 9-4. Data Source Field Encodings for Panther Cove and Coyote Cove Microarchitectures" in the ISE doc chapter "9.2.1 Panther Cove and Coyote Cove Microarchitectures Memory Auxiliary Field Layout"[1] indicates the code "01H" means the "L0 Hit - Minimal latency core cache hit. This request was satisfied by the L0 data cache."
---
v8: Updated developer tags
v3: Included more information about the L0 cache in the commit message.
--- tools/perf/Documentation/perf-record.txt | 2 +- tools/perf/util/bpf-filter.l | 1 + tools/perf/util/mem-events.c | 5 +++++ tools/perf/util/mem-events.h | 1 + 4 files changed, 8 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-record.txt +1 -1
@@ -212,7 +212,7 @@ OPTIONS The <value> can be one of: <number> (for any term) na, load, store, pfetch, exec (for mem_op) - l1, l2, l3, l4, cxl, io, any_cache, lfb, ram, pmem (for mem_lvl) + l0, l1, l2, l3, l4, cxl, io, any_cache, lfb, ram, pmem (for mem_lvl) na, none, hit, miss, hitm, fwd, peer (for mem_snoop) remote (for mem_remote) na, locked (for mem_locked)
tools/perf/util/bpf-filter.l +1 -0
@@ -131,6 +131,7 @@ store { return constant(PERF_MEM_OP_STORE); } pfetch { return constant(PERF_MEM_OP_PFETCH); } exec { return constant(PERF_MEM_OP_EXEC); } +l0 { return constant(PERF_MEM_LVLNUM_L0); } l1 { return constant(PERF_MEM_LVLNUM_L1); } l2 { return constant(PERF_MEM_LVLNUM_L2); } l3 { return constant(PERF_MEM_LVLNUM_L3); }
tools/perf/util/mem-events.c +5 -0
@@ -391,6 +391,7 @@ static const char * const mem_lvlnum[] = { [PERF_MEM_LVLNUM_L4] = "L4", [PERF_MEM_LVLNUM_L2_MHB] = "L2 MHB", [PERF_MEM_LVLNUM_MSC] = "Memory-side Cache", + [PERF_MEM_LVLNUM_L0] = "L0", [PERF_MEM_LVLNUM_UNC] = "Uncached", [PERF_MEM_LVLNUM_CXL] = "CXL", [PERF_MEM_LVLNUM_IO] = "I/O",
@@ -831,6 +832,8 @@ int mem_stat_index(const enum mem_stat_type mst, const u64 val) }case PERF_MEM_STAT_CACHE :switch (src.mem_lvl_num) { +case PERF_MEM_LVLNUM_L0 : +return MEM_STAT_CACHE_L0 ;case PERF_MEM_LVLNUM_L1 :return MEM_STAT_CACHE_L1 ;case PERF_MEM_LVLNUM_L2 :
@@ -915,6 +918,8 @@ const char *mem_stat_name(const enum mem_stat_type mst, const int idx) }case PERF_MEM_STAT_CACHE :switch (idx) { +case MEM_STAT_CACHE_L0 : +return "L0" ;case MEM_STAT_CACHE_L1 :return "L1" ;case MEM_STAT_CACHE_L2 :
tools/perf/util/mem-events.h +1 -0
@@ -109,6 +109,7 @@ enum mem_stat_op { };enum mem_stat_cache { +MEM_STAT_CACHE_L0 ,MEM_STAT_CACHE_L1 ,MEM_STAT_CACHE_L2 ,MEM_STAT_CACHE_L3 ,
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v11 2/6] perf mem: Add support for printing PERF_MEM_LVLNUM_L0
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] perf: L0 cache hits are silently dropped in perf c2c statistics --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] perf: L0 cache hits are silently dropped in perf c2c statistics --
commit f3eb05aaf438922225a25a217c33e99b8e7d269e
Author: Dapeng Mi <[email protected]>
perf mem: Add support for printing PERF_MEM_LVLNUM_L0
Add support for printing PERF_MEM_LVLNUM_L0 in perf mem report.
The L0 cache is newly added a small piece of cache which is the closest, lowest-latency memory cache tied directly to the execution pipeline.
The table "Table 9-4. Data Source Field Encodings for Panther Cove and Coyote Cove Microarchitectures" in the ISE doc chapter "9.2.1 Panther Cove and Coyote Cove Microarchitectures Memory Auxiliary Field Layout"[1] indicates the code "01H" means the "L0 Hit - Minimal latency core cache hit. This request was satisfied by the L0 data cache."
tools/perf/util/mem-events.c static const char * const mem_lvlnum[] = { · line 394
Quoted 9 lines
tools/perf/util/mem-events.c +1
-0@@ -391,6 +391,7 @@ static const char * const mem_lvlnum[] = { [PERF_MEM_LVLNUM_L4] = "L4", [PERF_MEM_LVLNUM_L2_MHB] = "L2 MHB", [PERF_MEM_LVLNUM_MSC] = "Memory-side Cache", + [PERF_MEM_LVLNUM_L0] = "L0",
[Severity: Medium]
This is a pre-existing issue, but does sort__lvl_cmp() in tools/perf/util/sort.c incorrectly merge histogram entries for L0 cache hits with other unmatched cache hierarchies?
Because sort__lvl_cmp() exclusively compares the deprecated mem_lvl bitmask when determining the sort order:
return (int64_t)(data_src_r.mem_lvl - data_src_l.mem_lvl);
Since PERF_MEM_LVLNUM_L0 and other new levels are only defined in mem_lvl_num, their mem_lvl evaluates to 0. This causes them to be incorrectly grouped together with other unrecognized hierarchies like CXL or PMEM in perf report.
[Severity: Medium]
Will L0 cache hits be silently dropped in perf c2c statistics since they are not accounted for in c2c_decode_stats() in tools/perf/util/mem-events.c?
c2c_decode_stats() populates c2c_stats by checking the deprecated mem_lvl bitmask:
if (lvl & P(LVL, L1 )) stats->ld_l1hit++;
if (lvl & P(LVL, L2)) {Since PERF_MEM_LVLNUM_L0 is encoded in the new mem_lvl_num field, L0 cache hits will bypass these cache depth checks entirely. In addition, the c2c_stats structure lacks an ld_l0hit counter to track them.
Quoted 3 lines
tools/perf/util/mem-events.c +0
-0[PERF_MEM_LVLNUM_UNC] = "Uncached", [PERF_MEM_LVLNUM_CXL] = "CXL", [PERF_MEM_LVLNUM_IO] = "I/O",
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
PATCH v11 3/6 perf header: Support memory ranges
In reply to Thomas FalconMemory ranges were created to track different types of memory, such as persistent, high bandwidth, or CXL-attached, that may be present on a system for performance monitoring and resource control purposes.
Memory range data are parsed from the ACPI MRRM table and exposed to userspace tools via sysfs [1]. Memory range data is read from:
/sys/firmware/acpi/memory_ranges/rangeX
With the following attributes:
u64 base; u64 length; int node; u8 local_region_id; u8 remote_region_id;
Read memory range data from sysfs if present and save it in the header of the perf data file under a new feature bit, HEADER_MEMORY_RANGES (35). Memory range data can be viewed with the --header or --header-only options of perf-report and perf-script.
Example output:
# memory ranges (nr 5): # range0: [0x0000000000000000-0x00000000bfffffff], node = 0, local_region_id = 0, remote_region_id = 255 # range1: [0x0000000100000000-0x000000203fffffff], node = 0, local_region_id = 0, remote_region_id = 255 # range2: [0x0000008000000000-0x0000027fffffffff], node = -2, local_region_id = 1, remote_region_id = 255 # range3: [0x0000028000000000-0x0000047fffffffff], node = -2, local_region_id = 1, remote_region_id = 255 # range4: [0x0000048000000000-0x000004ffffffffff], node = -2, local_region_id = 1, remote_region_id = 255
[1]: https://lore.kernel.org/lkml/[email protected]/
---
v10:
-- Add missing #include <fcntl.h> for open/openat/O_DIRECTORY (Sashiko) -- Fix up incorrectly formatted comment in process_memory_ranges() v4:
-- Fixed bounds checking for local and remote region IDs in
memory_range__read(), which made region "255" invalid
v3:
-- Added missing ff->size check in process_memory_ranges()
-- used open/openat to read memory range sysfs files in memory_range__read() -- Removed path name and file name buffers in memory_range__read(),
instead pass path name from as a parameter from memory_range__parse()
-- use calloc instead of zalloc in memory_range__parse() and
process_memory_ranges()
-- Removed redundant check for existance of memory range directory in
memory_range__read()
-- Included examples of memory range output in commit message v2:
-- Added check for NULL return of sysfs__mountpoint() when parsing
memory ranges in sysfs
-- increased MAX_MEMORY_RANGES sanity check from 64 to 256 based on
ACPI MRRM table implementation in Linux kernel
-- added comment for MAX_MEMORY_RANGES to clarify that it is a sanity check
for malformed perf.data files
-- removed a line of code was removed from util/env.h but was added back in
v1 due to bad rebase
--- .../Documentation/perf.data-file-format.txt | 13 ++ tools/perf/builtin-inject.c | 1 + tools/perf/util/env.c | 1 + tools/perf/util/env.h | 10 + tools/perf/util/header.c | 205 ++++++++++++++++++ tools/perf/util/header.h | 1 + 6 files changed, 231 insertions(+)
tools/perf/Documentation/perf.data-file-format.txt +13 -0
@@ -478,6 +478,19 @@ The size of the cacheline in bytes. Format: unsigned int cln_size; + HEADER_MEMORY_RANGES = 35, + +List of memory ranges. The format of the data is as below. + +u32 nr_memory_ranges; +struct memory_range { + u64 base; + u64 length; + int node; + u8 local_region_id; + u8 remote_region_id; +}; [nr_memory_ranges] + other bits are reserved and should be ignored for now HEADER_FEAT_BITS = 256,
tools/perf/builtin-inject.c +1 -0
@@ -2306,6 +2306,7 @@ static bool keep_feat(struct perf_inject *inject, int feat)case HEADER_PMU_CAPS :case HEADER_CPU_DOMAIN_INFO :case HEADER_CLN_SIZE : +case HEADER_MEMORY_RANGES :return true;/* Information that can be updated */ case HEADER_BUILD_ID :
tools/perf/util/env.c +1 -0
@@ -297,6 +297,7 @@ void perf_env__exit(struct perf_env *env)zfree (&env->pmu_caps[i].pmu_name); }zfree (&env->pmu_caps); +zfree (&env->memory_ranges);free_cpu_domain_info (env->cpu_domain, env->schedstat_version, env->nr_cpus_avail); }
tools/perf/util/env.h +10 -0
@@ -68,6 +68,14 @@ struct cpu_domain_map {struct domain_info **domains; }; +struct memory_range { +u64 base; +u64 length; +int node; +u8 local_region_id; +u8 remote_region_id; +}; +struct perf_env {char *hostname;char *os_release;
@@ -100,6 +108,7 @@ struct perf_env {int nr_cpu_pmu_caps;int nr_hybrid_nodes;int nr_pmus_with_caps; +int nr_memory_ranges;char *cmdline;const char **cmdline_argv;char *sibling_cores;
@@ -122,6 +131,7 @@ struct perf_env {unsigned long long memory_bsize;struct hybrid_node *hybrid_nodes;struct pmu_caps *pmu_caps; +struct memory_range *memory_ranges;#ifdef HAVE_LIBBPF_SUPPORT /* * bpf_info_lock protects bpf rbtrees. This is needed because the
tools/perf/util/header.c +205 -0
241 lines not on this page · raw message
tools/perf/util/header.h +1 -0
@@ -56,6 +56,7 @@ enum {HEADER_CPU_DOMAIN_INFO ,HEADER_E_MACHINE ,HEADER_CLN_SIZE , +HEADER_MEMORY_RANGES ,HEADER_LAST_FEATURE , HEADER_FEAT_BITS = 256, };
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v11 3/6] perf header: Support memory ranges
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] perf header: contradictory error message for MAX_MEMORY_RANGES bounds check --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] perf header: contradictory error message for MAX_MEMORY_RANGES bounds check --
commit 85df312c747d8e803c10425e475af0b3a2dc6e55
Author: Thomas Falcon <[email protected]>
perf header: Support memory ranges
This commit adds support for tracking and storing memory range data from ACPI MRRM tables into the perf data file header. It reads the data from sysfs and exposes it to userspace tools via a new feature bit.
Quoted 4 lines
tools/perf/util/header.c +0
-0
[ ... ]
Quoted 5 lines
tools/perf/util/header.c +5
-0+static int process_memory_ranges (struct feat_fd *ff,void *data__maybe_unused ) +{ +struct perf_env *env = &ff->ph->env; +struct memory_range *ranges, *r; +u32 nr_memory_ranges, i;
[ ... ]
tools/perf/util/header.c static int process_cpu_domain_info(struct feat_fd *ff, void *data __maybe_unused · line 4396
Quoted 8 lines
tools/perf/util/header.c +8
-0+/* +* According to version 1.1 of the ACPI MRRM table, the maximum +* number of memory regions can be at most 255. Do a sanity check +* here to guard against a malformed perf.data file. +*/ +if (nr_memory_ranges >=MAX_MEMORY_RANGES ) { +pr_err ("Invalid memory_ranges: nr_memory_ranges (%u) > %u\n" , + nr_memory_ranges,MAX_MEMORY_RANGES );
[Severity: Low]
Does this error message accurately reflect the bounds check? If a malformed perf.data file contains exactly MAX_MEMORY_RANGES (256) memory ranges, the check will reject the file but the log will confusingly print that 256 > 256.
Quoted 2 lines
tools/perf/util/header.c +2
-0+return -1 ; + }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
v12 cover perf: Add support for memory region/range reporting
Add support for two memory-related reporting features in the perf tool:
1. Memory region reporting in perf-c2c and perf-script subcommands.
2. Memory range data in perf.data file header and perf-c2c subcommand.
Memory region reporting was introduced as part of support for the Off-module Response facility (OMR) [1], which provides a new data source encoding supporting "up to 8 fine-grained memory regions in addition to the cache region, offering more detailed insights into memory access regions."
Memory Range support was introduced with the addition of the ACPI Memory Range and Region Mapping (MRRM) [2] table. It provides a base address plus a length value for each memory range, as well as NUMA node and local and remote "region ID's" so that "platform firmware can indicate the type of memory for each range."[3]
Include a change allowing PERF_MEM_LVLNUM_L0 to be printed in perf-mem output as well.
[1]: https://lore.kernel.org/all/[email protected]/
[2]: https://lore.kernel.org/lkml/[email protected]/
[3]: MRRM definition allow for future expansion for the OS to assign these region IDs.
v12:
-- Fixed typo in bounds checking for max supported memory ranges when
reading header data
v11:
-- perf-c2c: revert to only recording a real memory region for a
cacheline (Dapeng Mi)
v10:
-- perf-c2c: only update a cacheline's mem_region for real cache/memory
regions, so region-less samples (N/A) no longer overwrite a valid region recorded by an earlier sample on the same cacheline (Sashiko)
-- perf-script: replace #include "session.h" in mem-events.h with a
forward declaration of struct perf_session, and add direct session.h includes to the .c files that use it (Sashiko)
-- perf header: add missing #include <fcntl.h> for open()/openat()/
O_DIRECTORY to avoid build failures under strict libc such as musl (Sashiko)
-- perf-c2c: add missing #include <stdio.h> for asprintf() (Sashiko) -- Fix some whitespace and comment formatting issues
v9:
-- Fixed incorrect developer tags and updated perf-c2c to include cache
region reporting (Dapeng Mi)
v8:
-- Updated developer tags and commit messages with real example output
from perf script and perf c2c (Dapeng Mi)
v7:
-- perf-c2c: fix output_str allocation error handling that introduces a
memory leak (Sashiko)
v6:
-- Rebase on 7.3-rc1
v5:
-- perf-c2c: make the cacheline header span and ui_quirks() width
fixup depend on memory-region availability (Namhyung Kim)
v4:
-- perf-script: gate the Region field on the HEADER_MEMORY_RANGES feature
bit via perf_session instead of a global flag, with a pipe-mode fallback
-- perf-c2c: fix output_str allocation error handling
-- perf header: Fix typo in region id bounds checking which made region 255
invalid
v3:
-- included missing ff-size check in process_memory_ranges
-- make memory region reporting in perf c2c-and perf-script conditional
on feature bit, requiring some patch reordering (Namhyung Kim)
-- used open/openat to read memory range sysfs files in memory_range__read()
(Namhyung Kim)
-- Removed path name and file name buffers in memory_range__read(),
instead pass path name from as a parameter from memory_range__parse() (Namhyung Kim)
-- use calloc instead of zalloc in memory_range__parse() and
process_memory_ranges() (Namhyung Kim)
-- Removed redundant check for existence of memory range directory in
memory_range__read() (Namhyung Kim)
-- Included output examples of memory ranges in perf header and perf-c2c
in commit message (Namhyung Kim)
v2:
-- Added missing newline in WARN_ONCE message in c2c_he__set_mem_region() -- increased buffers passed to perf_script__meminfo_scnprintf() from 150
to 200 bytes to avoid silent truncation
-- Added check for NULL return of sysfs__mountpoint() when parsing
memory ranges in sysfs
-- increased MAX_MEMORY_RANGES sanity check from 64 to 256 based on
ACPI MRRM table implementation in Linux kernel
-- added comment for MAX_MEMORY_RANGES to clarify that it is a sanity check
for malformed perf.data files
-- cleaned up some removed code that was added back by this patch series
due to a bad rebase
Dapeng Mi (3):
perf mem: Add support for printing PERF_MEM_LVLNUM_L0 perf tools: Show memory region in perf-c2c subcommand perf tools: Show memory region in perf-script subcommand
Thomas Falcon (3):
perf mem: Fix size tracking for mem_lvl's in
perf_script__meminfo_scnprintf()
perf header: Support memory ranges
perf c2c: print memory region data with stdio output
tools/perf/Documentation/perf-record.txt | 2 +- .../Documentation/perf.data-file-format.txt | 13 ++ tools/perf/builtin-c2c.c | 143 +++++++++++- tools/perf/builtin-inject.c | 1 + tools/perf/builtin-script.c | 13 +- tools/perf/util/bpf-filter.l | 1 + tools/perf/util/c2c.h | 1 + tools/perf/util/env.c | 1 + tools/perf/util/env.h | 10 + tools/perf/util/header.c | 205 ++++++++++++++++++ tools/perf/util/header.h | 1 + tools/perf/util/mem-events.c | 94 +++++++- tools/perf/util/mem-events.h | 5 +- .../scripting-engines/trace-event-python.c | 6 +- 14 files changed, 473 insertions(+), 23 deletions(-)
Signature · 1 line
2.43.0
PATCH v12 1/6 perf mem: Fix size tracking for mem_lvl's in perf_script__meminfo_scnprintf()
When printing memory info in perf script, the entire size of the buffer is passed to perf_mem__lvl_scnprintf() instead of the remaining size. Pass the remaining buffer size instead.
This issue was detected by sashiko during an internal code review.
--- tools/perf/util/mem-events.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/mem-events.c +1 -1
@@ -610,7 +610,7 @@ int perf_script__meminfo_scnprintf(char *out, size_t sz, const struct mem_info * i +=scnprintf (out, sz,"|OP " ); i +=perf_mem__op_scnprintf (out + i, sz - i, mem_info); i +=scnprintf (out + i, sz - i,"|LVL " ); - i +=perf_mem__lvl_scnprintf (out + i, sz, mem_info); + i +=perf_mem__lvl_scnprintf (out + i, sz - i, mem_info); i +=scnprintf (out + i, sz - i,"|SNP " ); i +=perf_mem__snp_scnprintf (out + i, sz - i, mem_info); i +=scnprintf (out + i, sz - i,"|TLB " );
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v12 1/6] perf mem: Fix size tracking for mem_lvl's in perf_script__meminfo_scnprintf()
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 4 lines
When printing memory info in perf script, the entire size of the buffer is passed to
perf_mem__lvl_scnprintf()instead of the remaining size. Pass the remaining buffer size instead.
Quoted 8 lines
This issue was detected by sashiko during an internal code review.
Assisted-by Sashiko:gemini-3.1-pro-previewFixes fdefc3750e847 ("perf mem: Print memory operation type")Reviewed-by Dapeng Mi <[email protected]>Reviewed-by Ian Rogers <[email protected]>Reviewed-by Namhyung Kim <[email protected]>Signed-off-by Thomas Falcon <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
PATCH v12 2/6 perf mem: Add support for printing PERF_MEM_LVLNUM_L0
In reply to Thomas FalconFrom: Dapeng Mi <[email protected]>
Add support for printing PERF_MEM_LVLNUM_L0 in perf mem report.
The L0 cache is newly added a small piece of cache which is the closest, lowest-latency memory cache tied directly to the execution pipeline.
The table "Table 9-4. Data Source Field Encodings for Panther Cove and Coyote Cove Microarchitectures" in the ISE doc chapter "9.2.1 Panther Cove and Coyote Cove Microarchitectures Memory Auxiliary Field Layout"[1] indicates the code "01H" means the "L0 Hit - Minimal latency core cache hit. This request was satisfied by the L0 data cache."
---
v8: Updated developer tags
v3: Included more information about the L0 cache in the commit message.
--- tools/perf/Documentation/perf-record.txt | 2 +- tools/perf/util/bpf-filter.l | 1 + tools/perf/util/mem-events.c | 5 +++++ tools/perf/util/mem-events.h | 1 + 4 files changed, 8 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-record.txt +1 -1
@@ -212,7 +212,7 @@ OPTIONS The <value> can be one of: <number> (for any term) na, load, store, pfetch, exec (for mem_op) - l1, l2, l3, l4, cxl, io, any_cache, lfb, ram, pmem (for mem_lvl) + l0, l1, l2, l3, l4, cxl, io, any_cache, lfb, ram, pmem (for mem_lvl) na, none, hit, miss, hitm, fwd, peer (for mem_snoop) remote (for mem_remote) na, locked (for mem_locked)
tools/perf/util/bpf-filter.l +1 -0
@@ -131,6 +131,7 @@ store { return constant(PERF_MEM_OP_STORE); } pfetch { return constant(PERF_MEM_OP_PFETCH); } exec { return constant(PERF_MEM_OP_EXEC); } +l0 { return constant(PERF_MEM_LVLNUM_L0); } l1 { return constant(PERF_MEM_LVLNUM_L1); } l2 { return constant(PERF_MEM_LVLNUM_L2); } l3 { return constant(PERF_MEM_LVLNUM_L3); }
tools/perf/util/mem-events.c +5 -0
@@ -391,6 +391,7 @@ static const char * const mem_lvlnum[] = { [PERF_MEM_LVLNUM_L4] = "L4", [PERF_MEM_LVLNUM_L2_MHB] = "L2 MHB", [PERF_MEM_LVLNUM_MSC] = "Memory-side Cache", + [PERF_MEM_LVLNUM_L0] = "L0", [PERF_MEM_LVLNUM_UNC] = "Uncached", [PERF_MEM_LVLNUM_CXL] = "CXL", [PERF_MEM_LVLNUM_IO] = "I/O",
@@ -831,6 +832,8 @@ int mem_stat_index(const enum mem_stat_type mst, const u64 val) }case PERF_MEM_STAT_CACHE :switch (src.mem_lvl_num) { +case PERF_MEM_LVLNUM_L0 : +return MEM_STAT_CACHE_L0 ;case PERF_MEM_LVLNUM_L1 :return MEM_STAT_CACHE_L1 ;case PERF_MEM_LVLNUM_L2 :
@@ -915,6 +918,8 @@ const char *mem_stat_name(const enum mem_stat_type mst, const int idx) }case PERF_MEM_STAT_CACHE :switch (idx) { +case MEM_STAT_CACHE_L0 : +return "L0" ;case MEM_STAT_CACHE_L1 :return "L1" ;case MEM_STAT_CACHE_L2 :
tools/perf/util/mem-events.h +1 -0
@@ -109,6 +109,7 @@ enum mem_stat_op { };enum mem_stat_cache { +MEM_STAT_CACHE_L0 ,MEM_STAT_CACHE_L1 ,MEM_STAT_CACHE_L2 ,MEM_STAT_CACHE_L3 ,
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v12 2/6] perf mem: Add support for printing PERF_MEM_LVLNUM_L0
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 17 lines
From: Dapeng Mi <[email protected]>
Add support for printing
PERF_MEM_LVLNUM_L0in perf mem report.The L0 cache is newly added a small piece of cache which is the closest, lowest-latency memory cache tied directly to the execution pipeline.
The table "Table 9-4. Data Source Field Encodings for Panther Cove and Coyote Cove Microarchitectures" in the ISE doc chapter "9.2.1 Panther Cove and Coyote Cove Microarchitectures Memory Auxiliary Field Layout"[1] indicates the code "01H" means the "L0 Hit - Minimal latency core cache hit. This request was satisfied by the L0 data cache."
Quoted 7 lines
Assisted-by Sashiko:gemini-3.1-pro-previewReviewed-by Dapeng Mi <[email protected]>Reviewed-by Ian Rogers <[email protected]>Reviewed-by Namhyung Kim <[email protected]>Signed-off-by Dapeng Mi <[email protected]>Co-developed-by Thomas Falcon <[email protected]>Signed-off-by Thomas Falcon <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
PATCH v12 3/6 perf header: Support memory ranges
In reply to Thomas FalconMemory ranges were created to track different types of memory, such as persistent, high bandwidth, or CXL-attached, that may be present on a system for performance monitoring and resource control purposes.
Memory range data are parsed from the ACPI MRRM table and exposed to userspace tools via sysfs [1]. Memory range data is read from:
/sys/firmware/acpi/memory_ranges/rangeX
With the following attributes:
u64 base; u64 length; int node; u8 local_region_id; u8 remote_region_id;
Read memory range data from sysfs if present and save it in the header of the perf data file under a new feature bit, HEADER_MEMORY_RANGES (35). Memory range data can be viewed with the --header or --header-only options of perf-report and perf-script.
Example output:
# memory ranges (nr 5): # range0: [0x0000000000000000-0x00000000bfffffff], node = 0, local_region_id = 0, remote_region_id = 255 # range1: [0x0000000100000000-0x000000203fffffff], node = 0, local_region_id = 0, remote_region_id = 255 # range2: [0x0000008000000000-0x0000027fffffffff], node = -2, local_region_id = 1, remote_region_id = 255 # range3: [0x0000028000000000-0x0000047fffffffff], node = -2, local_region_id = 1, remote_region_id = 255 # range4: [0x0000048000000000-0x000004ffffffffff], node = -2, local_region_id = 1, remote_region_id = 255
[1]: https://lore.kernel.org/lkml/[email protected]/
---
v12:
-- Fixed typo in bounds checking for max supported memory ranges when
reading header data
v10:
-- Add missing #include <fcntl.h> for open/openat/O_DIRECTORY (Sashiko) -- Fix up incorrectly formatted comment in process_memory_ranges() v4:
-- Fixed bounds checking for local and remote region IDs in
memory_range__read(), which made region "255" invalid
v3:
-- Added missing ff->size check in process_memory_ranges()
-- used open/openat to read memory range sysfs files in memory_range__read() -- Removed path name and file name buffers in memory_range__read(),
instead pass path name from as a parameter from memory_range__parse()
-- use calloc instead of zalloc in memory_range__parse() and
process_memory_ranges()
-- Removed redundant check for existance of memory range directory in
memory_range__read()
-- Included examples of memory range output in commit message v2:
-- Added check for NULL return of sysfs__mountpoint() when parsing
memory ranges in sysfs
-- increased MAX_MEMORY_RANGES sanity check from 64 to 256 based on
ACPI MRRM table implementation in Linux kernel
-- added comment for MAX_MEMORY_RANGES to clarify that it is a sanity check
for malformed perf.data files
-- removed a line of code was removed from util/env.h but was added back in
v1 due to bad rebase
--- .../Documentation/perf.data-file-format.txt | 13 ++ tools/perf/builtin-inject.c | 1 + tools/perf/util/env.c | 1 + tools/perf/util/env.h | 10 + tools/perf/util/header.c | 205 ++++++++++++++++++ tools/perf/util/header.h | 1 + 6 files changed, 231 insertions(+)
tools/perf/Documentation/perf.data-file-format.txt +13 -0
@@ -478,6 +478,19 @@ The size of the cacheline in bytes. Format: unsigned int cln_size; + HEADER_MEMORY_RANGES = 35, + +List of memory ranges. The format of the data is as below. + +u32 nr_memory_ranges; +struct memory_range { + u64 base; + u64 length; + int node; + u8 local_region_id; + u8 remote_region_id; +}; [nr_memory_ranges] + other bits are reserved and should be ignored for now HEADER_FEAT_BITS = 256,
tools/perf/builtin-inject.c +1 -0
@@ -2306,6 +2306,7 @@ static bool keep_feat(struct perf_inject *inject, int feat)case HEADER_PMU_CAPS :case HEADER_CPU_DOMAIN_INFO :case HEADER_CLN_SIZE : +case HEADER_MEMORY_RANGES :return true;/* Information that can be updated */ case HEADER_BUILD_ID :
tools/perf/util/env.c +1 -0
@@ -297,6 +297,7 @@ void perf_env__exit(struct perf_env *env)zfree (&env->pmu_caps[i].pmu_name); }zfree (&env->pmu_caps); +zfree (&env->memory_ranges);free_cpu_domain_info (env->cpu_domain, env->schedstat_version, env->nr_cpus_avail); }
tools/perf/util/env.h +10 -0
@@ -68,6 +68,14 @@ struct cpu_domain_map {struct domain_info **domains; }; +struct memory_range { +u64 base; +u64 length; +int node; +u8 local_region_id; +u8 remote_region_id; +}; +struct perf_env {char *hostname;char *os_release;
@@ -100,6 +108,7 @@ struct perf_env {int nr_cpu_pmu_caps;int nr_hybrid_nodes;int nr_pmus_with_caps; +int nr_memory_ranges;char *cmdline;const char **cmdline_argv;char *sibling_cores;
@@ -122,6 +131,7 @@ struct perf_env {unsigned long long memory_bsize;struct hybrid_node *hybrid_nodes;struct pmu_caps *pmu_caps; +struct memory_range *memory_ranges;#ifdef HAVE_LIBBPF_SUPPORT /* * bpf_info_lock protects bpf rbtrees. This is needed because the
tools/perf/util/header.c +205 -0
241 lines not on this page · raw message
tools/perf/util/header.h +1 -0
@@ -56,6 +56,7 @@ enum {HEADER_CPU_DOMAIN_INFO ,HEADER_E_MACHINE ,HEADER_CLN_SIZE , +HEADER_MEMORY_RANGES ,HEADER_LAST_FEATURE , HEADER_FEAT_BITS = 256, };
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v12 3/6] perf header: Support memory ranges
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 15 lines
Memory ranges were created to track different types of memory, such as persistent, high bandwidth, or CXL-attached, that may be present on a system for performance monitoring and resource control purposes.
Memory range data are parsed from the ACPI MRRM table and exposed to userspace tools via sysfs [1]. Memory range data is read from:
/sys/firmware/acpi/memory_ranges/rangeXWith the following attributes:
u64 base; u64 length; int node;
Quoted 6 lines
[ ... ]Assisted-by Sashiko:gemini-3.1-pro-previewAssisted-by GitHub-Copilot:claude-opus-4-8Reviewed-by Ian Rogers <[email protected]>Reviewed-by Namhyung Kim <[email protected]>Signed-off-by Thomas Falcon <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
PATCH v12 4/6 perf tools: Show memory region in perf-c2c subcommand
In reply to Thomas FalconFrom: Dapeng Mi <[email protected]>
Add memory region field to the cacheline list view to help users identify the memory region to which the cacheline belongs. The memory region field was included with the introduction of support for the Off-module Response facility (OMR) [1] in Intel's Diamond Rapids and Nova Lake architectures.
An example of the new perf c2c output including the memory region field is shown below:
# Index Address Region Node PA cnt Hitm Total LclHitm RmtHitm records Loads
# ..... .................. ...... .... ...... ....... ....... ....... ....... ....... .......
#
0 0xffffffff84eb0040 N/A 0 1205 23.25% 544 544 0 1677 1677
1 0xffffffff84f03a80 N/A 0 1 18.12% 424 424 0 585 585
[...]
19 0xffffffff845bc840 Mem-0 0 13 0.30% 7 7 0 31 31
20 0xff3bbba284520a00 N/A 0 10 0.26% 6 6 0 11 11
21 0xff3bbbe0bc833500 N/A 0 24 0.26% 6 6 0 30 30[1]: https://lore.kernel.org/all/[email protected]/
---
v11: perf-c2c: revert to only recording a real memory region for a
cacheline
v10: only update mem_region for real cache/memory regions so N/A samples
don't overwrite a valid region; add #include <stdio.h> for asprintf (Sashiko)
v9: Update perf-c2c to include cache region reporting (Dapeng Mi)
v8: Update developer tags and commit message with real example
output (Dapeng Mi)
v7: fix output_str allocation error handling which introduced
a memory leak (Sashiko)
v6: rebased onto 7.3-rc1
v5: make the cacheline header span and ui_quirks() width
fixup depend on memory-region availability (Namhyung Kim)
v4: correctly handle output_str memory allocation failure
v3: make memory region reporting conditional on feature bit
--- tools/perf/builtin-c2c.c | 114 +++++++++++++++++++++++++++++++++++---- tools/perf/util/c2c.h | 1 + 2 files changed, 104 insertions(+), 11 deletions(-)
tools/perf/builtin-c2c.c +103 -11
@@ -14,6 +14,7 @@#include <inttypes.h> #include <stdlib.h> #include <string.h> +#include <stdio.h> #include <asm/bug.h> #include <linux/compiler.h>
@@ -72,6 +73,7 @@ struct perf_c2c {bool show_src;bool show_all; +bool show_mem_region;bool use_stdio;bool stats_only;bool symbol_full;
@@ -248,6 +250,18 @@ static void c2c_he__set_node(struct c2c_hist_entry *c2c_he, } } +static void c2c_he__set_mem_region (struct c2c_hist_entry *c2c_he, +unsigned int mem_region) +{ +if (WARN_ONCE (mem_region >PERF_MEM_REGION_MEM7 , +"WARNING: invalid memory region ID\n" )) +return ; + +/* Update mem_region only if it really accesses memory */ +if (mem_region >=PERF_MEM_REGION_MMIO ) + c2c_he->mem_region = mem_region; +} +static void compute_stats (struct c2c_hist_entry *c2c_he,struct c2c_stats *stats,u64 weight)
@@ -306,6 +320,7 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused,struct addr_location al;struct mem_info *mi =NULL ;struct callchain_cursor *cursor; +unsigned int mem_region;int ret;addr_location__init (&al);
@@ -333,6 +348,7 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused, }c2c_decode_stats (&stats, mi); + mem_region =mem_info__data_src (mi)->mem_region; he = hists__add_entry_ops(&c2c_hists->hists, &c2c_entry_ops, &al, NULL, NULL, mi, NULL,
@@ -349,6 +365,7 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused,c2c_he__set_cpu (c2c_he, sample);c2c_he__set_node (c2c_he, sample);c2c_he__set_evsel (c2c_he, evsel); +c2c_he__set_mem_region (c2c_he, mem_region);hists__inc_nr_samples (&c2c_hists->hists, he->filtered);
@@ -402,6 +419,7 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused,c2c_he__set_cpu (c2c_he, sample);c2c_he__set_node (c2c_he, sample);c2c_he__set_evsel (c2c_he, evsel); +c2c_he__set_mem_region (c2c_he, mem_region);hists__inc_nr_samples (&c2c_hists->hists, he->filtered); ret =hist_entry__append_callchain (he, sample);
@@ -540,6 +558,45 @@ dcacheline_node_count(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,return scnprintf (hpp->buf, hpp->size,"%*lu" , width, c2c_he->paddr_cnt); } +static int +dcacheline_node_mem_region (struct perf_hpp_fmt *fmt,struct perf_hpp *hpp, +struct hist_entry *he) +{ +int width =c2c_width (fmt, hpp, he->hists); +struct c2c_hist_entry *c2c_he; +unsigned int mem_region; +char buf[20 ]; + + c2c_he = container_of(he, struct c2c_hist_entry, he); + mem_region = c2c_he->mem_region; + +switch (mem_region) { +case PERF_MEM_REGION_NA : +case PERF_MEM_REGION_RSVD : +scnprintf (buf,sizeof (buf),"N/A" ); +break ; +case PERF_MEM_REGION_MMIO : +scnprintf (buf,sizeof (buf),"MMIO" ); +break ; +case PERF_MEM_REGION_MEM0 : +case PERF_MEM_REGION_MEM1 : +case PERF_MEM_REGION_MEM2 : +case PERF_MEM_REGION_MEM3 : +case PERF_MEM_REGION_MEM4 : +case PERF_MEM_REGION_MEM5 : +case PERF_MEM_REGION_MEM6 : +case PERF_MEM_REGION_MEM7 : +scnprintf (buf,sizeof (buf),"Mem-%d" , + mem_region -PERF_MEM_REGION_MEM0 ); +break ; +default : +scnprintf (buf,sizeof (buf),"N/A" ); +break ; + } + +return scnprintf (hpp->buf, hpp->size,"%*s" , width, buf); +} +static int offset_entry (struct perf_hpp_fmt *fmt,struct perf_hpp *hpp,struct hist_entry *he) {
@@ -1360,6 +1417,14 @@ static struct c2c_dimension dim_dcacheline_node = { .width = 4, }; +static struct c2c_dimension dim_dcacheline_mem_region = { + .header =HEADER_LOW ("Region" ), + .name ="dcacheline_mem_region" , + .cmp = empty_cmp, + .entry = dcacheline_node_mem_region, + .width =6 , +}; +static struct c2c_dimension dim_dcacheline_count = { .header =HEADER_LOW ("PA cnt" ), .name ="dcacheline_count" ,
@@ -1791,6 +1856,7 @@ static struct c2c_dimension dim_dcacheline_num_empty = {static struct c2c_dimension *dimensions[] = { &dim_dcacheline, + &dim_dcacheline_mem_region, &dim_dcacheline_node, &dim_dcacheline_count, &dim_offset,
@@ -2854,8 +2920,11 @@ static int ui_quirks(void)/* Fix the zero line for dcacheline column. */ buf =fill_line (chk_double_cl ?"Double-Cacheline" :"Cacheline" , dim_dcacheline.width + + (c2c.show_mem_region ? + dim_dcacheline_mem_region.width :0 ) + dim_dcacheline_node.width + - dim_dcacheline_count.width +4 ); + dim_dcacheline_count.width + + (c2c.show_mem_region ?6 :4 ));if (!buf)return -ENOMEM ;
@@ -3107,7 +3176,8 @@ static int perf_c2c__report(int argc, const char **argv) OPT_END() };int err =0 ; -const char *output_str, *sort_str =NULL ; +const char *sort_str =NULL ; +char *output_str =NULL ;struct perf_env *env;annotation_options__init ();
@@ -3272,9 +3342,16 @@ static int perf_c2c__report(int argc, const char **argv) goto out_mem2node; } -if (c2c.display !=DISPLAY_SNP_PEER ) - output_str ="cl_idx," + c2c.show_mem_region =perf_header__has_feat (&session->header, +HEADER_MEMORY_RANGES ); +if (c2c.show_mem_region) + dim_dcacheline.header.line[0 ].span =3 ; + +if (c2c.display !=DISPLAY_SNP_PEER ) { + if (asprintf(&output_str, + "cl_idx," "dcacheline," + "%s" "dcacheline_node," "dcacheline_count," "percent_costly_snoop,"
@@ -3286,10 +3363,17 @@ static int perf_c2c__report(int argc, const char **argv) "ld_fbhit,ld_l1hit,ld_l2hit," "ld_lclhit,lcl_hitm," "ld_rmthit,rmt_hitm," -"dram_lcl,dram_rmt" ; - else - output_str ="cl_idx," + "dram_lcl,dram_rmt", + c2c.show_mem_region ? + "dcacheline_mem_region," : "") < 0) { + err = -ENOMEM ; + goto out_mem2node; + } + }else { + if (asprintf(&output_str, + "cl_idx," "dcacheline," + "%s" "dcacheline_node," "dcacheline_count," "percent_costly_snoop,"
@@ -3301,7 +3385,13 @@ static int perf_c2c__report(int argc, const char **argv) "ld_fbhit,ld_l1hit,ld_l2hit," "ld_lclhit,lcl_hitm," "ld_rmthit,rmt_hitm," -"dram_lcl,dram_rmt" ; + "dram_lcl,dram_rmt", + c2c.show_mem_region ? + "dcacheline_mem_region," : "") < 0) { + err = -ENOMEM ; + goto out_mem2node; + } + }if (c2c.display ==DISPLAY_TOT_HITM ) sort_str ="tot_hitm" ;
@@ -3315,7 +3405,7 @@ static int perf_c2c__report(int argc, const char **argv) err =c2c_hists__reinit (&c2c.hists, output_str, sort_str,perf_session__env (session));if (err) {pr_err ("Failed to reinitialize hists\n" ); - goto out_mem2node; + goto out_str; }ui_progress__init (&prog, c2c.hists.hists.nr_entries,"Sorting..." );
@@ -3324,17 +3414,19 @@ static int perf_c2c__report(int argc, const char **argv)hists__output_resort_cb (&c2c.hists.hists, &prog, resort_shared_cl_cb); err =hists__iterate_cb (&c2c.hists.hists, resort_cl_cb,perf_session__env (session));if (err) - goto out_mem2node; + goto out_str;ui_progress__finish ();if (ui_quirks ()) {pr_err ("failed to setup UI\n" ); - goto out_mem2node; + goto out_str; }perf_c2c_display (session); +out_str: +free (output_str); out_mem2node:mem2node__exit (&c2c.mem2node); out_session:
tools/perf/util/c2c.h +1 -0
@@ -33,6 +33,7 @@ struct c2c_hist_entry {unsigned long *nodeset;struct c2c_stats *node_stats;unsigned int cacheline_idx; +unsigned int mem_region;struct compute_stats cstats;
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v12 4/6] perf tools: Show memory region in perf-c2c subcommand
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 23 lines
From: Dapeng Mi <[email protected]>
Add memory region field to the cacheline list view to help users identify the memory region to which the cacheline belongs. The memory region field was included with the introduction of support for the Off-module Response facility (OMR) [1] in Intel's Diamond Rapids and Nova Lake architectures.
An example of the new perf c2c output including the memory region field is shown below:
# Index Address Region Node PA cnt Hitm Total LclHitm RmtHitm records Loads # ..... .................. ...... .... ...... ....... ....... ....... ....... ....... ....... # 0 0xffffffff84eb0040 N/A 0 1205 23.25% 544 544 0 1677 1677 1 0xffffffff84f03a80 N/A 0 1 18.12% 424 424 0 585 585 [...] 19 0xffffffff845bc840 Mem-0 0 13 0.30% 7 7 0 31 31 20 0xff3bbba284520a00 N/A 0 10 0.26% 6 6 0 11 11 21 0xff3bbbe0bc833500 N/A 0 24 0.26% 6 6 0 30 30
Quoted 7 lines
Assisted-by Sashiko:gemini-3.1-pro-previewAssisted-by GitHub-Copilot:claude-opus-4-8Reviewed-by Ian Rogers <[email protected]>Reviewed-by Namhyung Kim <[email protected]>Signed-off-by Dapeng Mi <[email protected]>Co-developed-by Thomas Falcon <[email protected]>Signed-off-by Thomas Falcon <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Re: [PATCH v12 4/6] perf tools: Show memory region in perf-c2c subcommand
In reply to Thomas FalconThanks.
Quoted 312 lines · Thomas Falcon
From: Dapeng Mi <[email protected]>
Add memory region field to the cacheline list view to help users identify the memory region to which the cacheline belongs. The memory region field was included with the introduction of support for the Off-module Response facility (OMR) [1] in Intel's Diamond Rapids and Nova Lake architectures.
An example of the new perf c2c output including the memory region field is shown below:
# Index Address Region Node PA cnt Hitm Total LclHitm RmtHitm records Loads # ..... .................. ...... .... ...... ....... ....... ....... ....... ....... ....... # 0 0xffffffff84eb0040 N/A 0 1205 23.25% 544 544 0 1677 1677 1 0xffffffff84f03a80 N/A 0 1 18.12% 424 424 0 585 585 [...] 19 0xffffffff845bc840 Mem-0 0 13 0.30% 7 7 0 31 31 20 0xff3bbba284520a00 N/A 0 10 0.26% 6 6 0 11 11 21 0xff3bbbe0bc833500 N/A 0 24 0.26% 6 6 0 30 30[1]: https://lore.kernel.org/all/[email protected]/
Assisted-by Sashiko:gemini-3.1-pro-previewAssisted-by GitHub-Copilot:claude-opus-4-8Reviewed-by Ian Rogers <[email protected]>Reviewed-by Namhyung Kim <[email protected]>Signed-off-by Dapeng Mi <[email protected]>Co-developed-by Thomas Falcon <[email protected]>Signed-off-by Thomas Falcon <[email protected]>---
v11: perf-c2c: revert to only recording a real memory region for a
cacheline
v10: only updatemem_regionfor real cache/memory regions so N/A samples
don't overwrite a valid region; add #include <stdio.h> for asprintf (Sashiko)
v9: Update perf-c2c to include cache region reporting (Dapeng Mi)
v8: Update developer tags and commit message with real example
output (Dapeng Mi)
v7: fixoutput_strallocation error handling which introduced
a memory leak (Sashiko)
v6: rebased onto 7.3-rc1
v5: make the cacheline header span andui_quirks()width
fixup depend on memory-region availability (Namhyung Kim)
v4: correctly handleoutput_strmemory allocation failure
v3: make memory region reporting conditional on feature bit--- tools/perf/builtin-c2c.c | 114 +++++++++++++++++++++++++++++++++++---- tools/perf/util/c2c.h | 1 + 2 files changed, 104 insertions(+), 11 deletions(-)tools/perf/builtin-c2c.c +103
-11@@ -14,6 +14,7 @@#include <inttypes.h> #include <stdlib.h> #include <string.h> +#include <stdio.h> #include <asm/bug.h> #include <linux/compiler.h> @@ -72,6 +73,7 @@ struct perf_c2c {bool show_src;bool show_all; +bool show_mem_region;bool use_stdio;bool stats_only;bool symbol_full;@@ -248,6 +250,18 @@ static void c2c_he__set_node(struct c2c_hist_entry *c2c_he, } } +static void c2c_he__set_mem_region (struct c2c_hist_entry *c2c_he, +unsigned int mem_region) +{ +if (WARN_ONCE (mem_region >PERF_MEM_REGION_MEM7 , +"WARNING: invalid memory region ID\n" )) +return ; + +/* Update mem_region only if it really accesses memory */ +if (mem_region >=PERF_MEM_REGION_MMIO ) + c2c_he->mem_region = mem_region; +} +static void compute_stats (struct c2c_hist_entry *c2c_he,struct c2c_stats *stats,u64 weight)@@ -306,6 +320,7 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused,struct addr_location al;struct mem_info *mi =NULL ;struct callchain_cursor *cursor; +unsigned int mem_region;int ret;addr_location__init (&al);@@ -333,6 +348,7 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused, }c2c_decode_stats (&stats, mi); + mem_region =mem_info__data_src (mi)->mem_region; he = hists__add_entry_ops(&c2c_hists->hists, &c2c_entry_ops, &al, NULL, NULL, mi, NULL,@@ -349,6 +365,7 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused,c2c_he__set_cpu (c2c_he, sample);c2c_he__set_node (c2c_he, sample);c2c_he__set_evsel (c2c_he, evsel); +c2c_he__set_mem_region (c2c_he, mem_region);hists__inc_nr_samples (&c2c_hists->hists, he->filtered);@@ -402,6 +419,7 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused,c2c_he__set_cpu (c2c_he, sample);c2c_he__set_node (c2c_he, sample);c2c_he__set_evsel (c2c_he, evsel); +c2c_he__set_mem_region (c2c_he, mem_region);hists__inc_nr_samples (&c2c_hists->hists, he->filtered); ret =hist_entry__append_callchain (he, sample);@@ -540,6 +558,45 @@ dcacheline_node_count(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,return scnprintf (hpp->buf, hpp->size,"%*lu" , width, c2c_he->paddr_cnt); } +static int +dcacheline_node_mem_region (struct perf_hpp_fmt *fmt,struct perf_hpp *hpp, +struct hist_entry *he) +{ +int width =c2c_width (fmt, hpp, he->hists); +struct c2c_hist_entry *c2c_he; +unsigned int mem_region; +char buf[20 ]; + + c2c_he = container_of(he, struct c2c_hist_entry, he); + mem_region = c2c_he->mem_region; + +switch (mem_region) { +case PERF_MEM_REGION_NA : +case PERF_MEM_REGION_RSVD : +scnprintf (buf,sizeof (buf),"N/A" ); +break ; +case PERF_MEM_REGION_MMIO : +scnprintf (buf,sizeof (buf),"MMIO" ); +break ; +case PERF_MEM_REGION_MEM0 : +case PERF_MEM_REGION_MEM1 : +case PERF_MEM_REGION_MEM2 : +case PERF_MEM_REGION_MEM3 : +case PERF_MEM_REGION_MEM4 : +case PERF_MEM_REGION_MEM5 : +case PERF_MEM_REGION_MEM6 : +case PERF_MEM_REGION_MEM7 : +scnprintf (buf,sizeof (buf),"Mem-%d" , + mem_region -PERF_MEM_REGION_MEM0 ); +break ; +default : +scnprintf (buf,sizeof (buf),"N/A" ); +break ; + } + +return scnprintf (hpp->buf, hpp->size,"%*s" , width, buf); +} +static int offset_entry (struct perf_hpp_fmt *fmt,struct perf_hpp *hpp,struct hist_entry *he) {@@ -1360,6 +1417,14 @@ static struct c2c_dimension dim_dcacheline_node = { .width = 4, }; +static struct c2c_dimension dim_dcacheline_mem_region = { + .header =HEADER_LOW ("Region" ), + .name ="dcacheline_mem_region" , + .cmp = empty_cmp, + .entry = dcacheline_node_mem_region, + .width =6 , +}; +static struct c2c_dimension dim_dcacheline_count = { .header =HEADER_LOW ("PA cnt" ), .name ="dcacheline_count" ,@@ -1791,6 +1856,7 @@ static struct c2c_dimension dim_dcacheline_num_empty = {static struct c2c_dimension *dimensions[] = { &dim_dcacheline, + &dim_dcacheline_mem_region, &dim_dcacheline_node, &dim_dcacheline_count, &dim_offset,@@ -2854,8 +2920,11 @@ static int ui_quirks(void)/* Fix the zero line for dcacheline column. */ buf =fill_line (chk_double_cl ?"Double-Cacheline" :"Cacheline" , dim_dcacheline.width + + (c2c.show_mem_region ? + dim_dcacheline_mem_region.width :0 ) + dim_dcacheline_node.width + - dim_dcacheline_count.width +4 ); + dim_dcacheline_count.width + + (c2c.show_mem_region ?6 :4 ));if (!buf)return -ENOMEM ;@@ -3107,7 +3176,8 @@ static int perf_c2c__report(int argc, const char **argv) OPT_END() };int err =0 ; -const char *output_str, *sort_str =NULL ; +const char *sort_str =NULL ; +char *output_str =NULL ;struct perf_env *env;annotation_options__init ();@@ -3272,9 +3342,16 @@ static int perf_c2c__report(int argc, const char **argv) goto out_mem2node; } -if (c2c.display !=DISPLAY_SNP_PEER ) - output_str ="cl_idx," + c2c.show_mem_region =perf_header__has_feat (&session->header, +HEADER_MEMORY_RANGES ); +if (c2c.show_mem_region) + dim_dcacheline.header.line[0 ].span =3 ; + +if (c2c.display !=DISPLAY_SNP_PEER ) { + if (asprintf(&output_str, + "cl_idx," "dcacheline," + "%s" "dcacheline_node," "dcacheline_count," "percent_costly_snoop,"@@ -3286,10 +3363,17 @@ static int perf_c2c__report(int argc, const char **argv) "ld_fbhit,ld_l1hit,ld_l2hit," "ld_lclhit,lcl_hitm," "ld_rmthit,rmt_hitm," -"dram_lcl,dram_rmt" ; - else - output_str ="cl_idx," + "dram_lcl,dram_rmt", + c2c.show_mem_region ? + "dcacheline_mem_region," : "") < 0) { + err = -ENOMEM ; + goto out_mem2node; + } + }else { + if (asprintf(&output_str, + "cl_idx," "dcacheline," + "%s" "dcacheline_node," "dcacheline_count," "percent_costly_snoop,"@@ -3301,7 +3385,13 @@ static int perf_c2c__report(int argc, const char **argv) "ld_fbhit,ld_l1hit,ld_l2hit," "ld_lclhit,lcl_hitm," "ld_rmthit,rmt_hitm," -"dram_lcl,dram_rmt" ; + "dram_lcl,dram_rmt", + c2c.show_mem_region ? + "dcacheline_mem_region," : "") < 0) { + err = -ENOMEM ; + goto out_mem2node; + } + }if (c2c.display ==DISPLAY_TOT_HITM ) sort_str ="tot_hitm" ;@@ -3315,7 +3405,7 @@ static int perf_c2c__report(int argc, const char **argv) err =c2c_hists__reinit (&c2c.hists, output_str, sort_str,perf_session__env (session));if (err) {pr_err ("Failed to reinitialize hists\n" ); - goto out_mem2node; + goto out_str; }ui_progress__init (&prog, c2c.hists.hists.nr_entries,"Sorting..." );@@ -3324,17 +3414,19 @@ static int perf_c2c__report(int argc, const char **argv)hists__output_resort_cb (&c2c.hists.hists, &prog, resort_shared_cl_cb); err =hists__iterate_cb (&c2c.hists.hists, resort_cl_cb,perf_session__env (session));if (err) - goto out_mem2node; + goto out_str;ui_progress__finish ();if (ui_quirks ()) {pr_err ("failed to setup UI\n" ); - goto out_mem2node; + goto out_str; }perf_c2c_display (session); +out_str: +free (output_str); out_mem2node:mem2node__exit (&c2c.mem2node); out_session:tools/perf/util/c2c.h +1
-0@@ -33,6 +33,7 @@ struct c2c_hist_entry {unsigned long *nodeset;struct c2c_stats *node_stats;unsigned int cacheline_idx; +unsigned int mem_region;struct compute_stats cstats;
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v12 4/6] perf tools: Show memory region in perf-c2c subcommand
Quoted 1 line · Dapeng
Reviewed-by Dapeng Mi <[email protected]>
Is this needed since you're the author of the patch? I'm keeping just the Signed-off-by,
- Arnaldo
Quoted 316 lines
Thanks.
Quoted 312 lines · Thomas Falcon
From: Dapeng Mi <[email protected]>
Add memory region field to the cacheline list view to help users identify the memory region to which the cacheline belongs. The memory region field was included with the introduction of support for the Off-module Response facility (OMR) [1] in Intel's Diamond Rapids and Nova Lake architectures.
An example of the new perf c2c output including the memory region field is shown below:
# Index Address Region Node PA cnt Hitm Total LclHitm RmtHitm records Loads # ..... .................. ...... .... ...... ....... ....... ....... ....... ....... ....... # 0 0xffffffff84eb0040 N/A 0 1205 23.25% 544 544 0 1677 1677 1 0xffffffff84f03a80 N/A 0 1 18.12% 424 424 0 585 585 [...] 19 0xffffffff845bc840 Mem-0 0 13 0.30% 7 7 0 31 31 20 0xff3bbba284520a00 N/A 0 10 0.26% 6 6 0 11 11 21 0xff3bbbe0bc833500 N/A 0 24 0.26% 6 6 0 30 30[1]: https://lore.kernel.org/all/[email protected]/
Assisted-by Sashiko:gemini-3.1-pro-previewAssisted-by GitHub-Copilot:claude-opus-4-8Reviewed-by Ian Rogers <[email protected]>Reviewed-by Namhyung Kim <[email protected]>Signed-off-by Dapeng Mi <[email protected]>Co-developed-by Thomas Falcon <[email protected]>Signed-off-by Thomas Falcon <[email protected]>---
v11: perf-c2c: revert to only recording a real memory region for a
cacheline
v10: only updatemem_regionfor real cache/memory regions so N/A samples
don't overwrite a valid region; add #include <stdio.h> for asprintf (Sashiko)
v9: Update perf-c2c to include cache region reporting (Dapeng Mi)
v8: Update developer tags and commit message with real example
output (Dapeng Mi)
v7: fixoutput_strallocation error handling which introduced
a memory leak (Sashiko)
v6: rebased onto 7.3-rc1
v5: make the cacheline header span andui_quirks()width
fixup depend on memory-region availability (Namhyung Kim)
v4: correctly handleoutput_strmemory allocation failure
v3: make memory region reporting conditional on feature bit--- tools/perf/builtin-c2c.c | 114 +++++++++++++++++++++++++++++++++++---- tools/perf/util/c2c.h | 1 + 2 files changed, 104 insertions(+), 11 deletions(-)tools/perf/builtin-c2c.c +103
-11@@ -14,6 +14,7 @@#include <inttypes.h> #include <stdlib.h> #include <string.h> +#include <stdio.h> #include <asm/bug.h> #include <linux/compiler.h> @@ -72,6 +73,7 @@ struct perf_c2c {bool show_src;bool show_all; +bool show_mem_region;bool use_stdio;bool stats_only;bool symbol_full;@@ -248,6 +250,18 @@ static void c2c_he__set_node(struct c2c_hist_entry *c2c_he, } } +static void c2c_he__set_mem_region (struct c2c_hist_entry *c2c_he, +unsigned int mem_region) +{ +if (WARN_ONCE (mem_region >PERF_MEM_REGION_MEM7 , +"WARNING: invalid memory region ID\n" )) +return ; + +/* Update mem_region only if it really accesses memory */ +if (mem_region >=PERF_MEM_REGION_MMIO ) + c2c_he->mem_region = mem_region; +} +static void compute_stats (struct c2c_hist_entry *c2c_he,struct c2c_stats *stats,u64 weight)@@ -306,6 +320,7 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused,struct addr_location al;struct mem_info *mi =NULL ;struct callchain_cursor *cursor; +unsigned int mem_region;int ret;addr_location__init (&al);@@ -333,6 +348,7 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused, }c2c_decode_stats (&stats, mi); + mem_region =mem_info__data_src (mi)->mem_region; he = hists__add_entry_ops(&c2c_hists->hists, &c2c_entry_ops, &al, NULL, NULL, mi, NULL,@@ -349,6 +365,7 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused,c2c_he__set_cpu (c2c_he, sample);c2c_he__set_node (c2c_he, sample);c2c_he__set_evsel (c2c_he, evsel); +c2c_he__set_mem_region (c2c_he, mem_region);hists__inc_nr_samples (&c2c_hists->hists, he->filtered);@@ -402,6 +419,7 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused,c2c_he__set_cpu (c2c_he, sample);c2c_he__set_node (c2c_he, sample);c2c_he__set_evsel (c2c_he, evsel); +c2c_he__set_mem_region (c2c_he, mem_region);hists__inc_nr_samples (&c2c_hists->hists, he->filtered); ret =hist_entry__append_callchain (he, sample);@@ -540,6 +558,45 @@ dcacheline_node_count(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,return scnprintf (hpp->buf, hpp->size,"%*lu" , width, c2c_he->paddr_cnt); } +static int +dcacheline_node_mem_region (struct perf_hpp_fmt *fmt,struct perf_hpp *hpp, +struct hist_entry *he) +{ +int width =c2c_width (fmt, hpp, he->hists); +struct c2c_hist_entry *c2c_he; +unsigned int mem_region; +char buf[20 ]; + + c2c_he = container_of(he, struct c2c_hist_entry, he); + mem_region = c2c_he->mem_region; + +switch (mem_region) { +case PERF_MEM_REGION_NA : +case PERF_MEM_REGION_RSVD : +scnprintf (buf,sizeof (buf),"N/A" ); +break ; +case PERF_MEM_REGION_MMIO : +scnprintf (buf,sizeof (buf),"MMIO" ); +break ; +case PERF_MEM_REGION_MEM0 : +case PERF_MEM_REGION_MEM1 : +case PERF_MEM_REGION_MEM2 : +case PERF_MEM_REGION_MEM3 : +case PERF_MEM_REGION_MEM4 : +case PERF_MEM_REGION_MEM5 : +case PERF_MEM_REGION_MEM6 : +case PERF_MEM_REGION_MEM7 : +scnprintf (buf,sizeof (buf),"Mem-%d" , + mem_region -PERF_MEM_REGION_MEM0 ); +break ; +default : +scnprintf (buf,sizeof (buf),"N/A" ); +break ; + } + +return scnprintf (hpp->buf, hpp->size,"%*s" , width, buf); +} +static int offset_entry (struct perf_hpp_fmt *fmt,struct perf_hpp *hpp,struct hist_entry *he) {@@ -1360,6 +1417,14 @@ static struct c2c_dimension dim_dcacheline_node = { .width = 4, }; +static struct c2c_dimension dim_dcacheline_mem_region = { + .header =HEADER_LOW ("Region" ), + .name ="dcacheline_mem_region" , + .cmp = empty_cmp, + .entry = dcacheline_node_mem_region, + .width =6 , +}; +static struct c2c_dimension dim_dcacheline_count = { .header =HEADER_LOW ("PA cnt" ), .name ="dcacheline_count" ,@@ -1791,6 +1856,7 @@ static struct c2c_dimension dim_dcacheline_num_empty = {static struct c2c_dimension *dimensions[] = { &dim_dcacheline, + &dim_dcacheline_mem_region, &dim_dcacheline_node, &dim_dcacheline_count, &dim_offset,@@ -2854,8 +2920,11 @@ static int ui_quirks(void)/* Fix the zero line for dcacheline column. */ buf =fill_line (chk_double_cl ?"Double-Cacheline" :"Cacheline" , dim_dcacheline.width + + (c2c.show_mem_region ? + dim_dcacheline_mem_region.width :0 ) + dim_dcacheline_node.width + - dim_dcacheline_count.width +4 ); + dim_dcacheline_count.width + + (c2c.show_mem_region ?6 :4 ));if (!buf)return -ENOMEM ;@@ -3107,7 +3176,8 @@ static int perf_c2c__report(int argc, const char **argv) OPT_END() };int err =0 ; -const char *output_str, *sort_str =NULL ; +const char *sort_str =NULL ; +char *output_str =NULL ;struct perf_env *env;annotation_options__init ();@@ -3272,9 +3342,16 @@ static int perf_c2c__report(int argc, const char **argv) goto out_mem2node; } -if (c2c.display !=DISPLAY_SNP_PEER ) - output_str ="cl_idx," + c2c.show_mem_region =perf_header__has_feat (&session->header, +HEADER_MEMORY_RANGES ); +if (c2c.show_mem_region) + dim_dcacheline.header.line[0 ].span =3 ; + +if (c2c.display !=DISPLAY_SNP_PEER ) { + if (asprintf(&output_str, + "cl_idx," "dcacheline," + "%s" "dcacheline_node," "dcacheline_count," "percent_costly_snoop,"@@ -3286,10 +3363,17 @@ static int perf_c2c__report(int argc, const char **argv) "ld_fbhit,ld_l1hit,ld_l2hit," "ld_lclhit,lcl_hitm," "ld_rmthit,rmt_hitm," -"dram_lcl,dram_rmt" ; - else - output_str ="cl_idx," + "dram_lcl,dram_rmt", + c2c.show_mem_region ? + "dcacheline_mem_region," : "") < 0) { + err = -ENOMEM ; + goto out_mem2node; + } + }else { + if (asprintf(&output_str, + "cl_idx," "dcacheline," + "%s" "dcacheline_node," "dcacheline_count," "percent_costly_snoop,"@@ -3301,7 +3385,13 @@ static int perf_c2c__report(int argc, const char **argv) "ld_fbhit,ld_l1hit,ld_l2hit," "ld_lclhit,lcl_hitm," "ld_rmthit,rmt_hitm," -"dram_lcl,dram_rmt" ; + "dram_lcl,dram_rmt", + c2c.show_mem_region ? + "dcacheline_mem_region," : "") < 0) { + err = -ENOMEM ; + goto out_mem2node; + } + }if (c2c.display ==DISPLAY_TOT_HITM ) sort_str ="tot_hitm" ;@@ -3315,7 +3405,7 @@ static int perf_c2c__report(int argc, const char **argv) err =c2c_hists__reinit (&c2c.hists, output_str, sort_str,perf_session__env (session));if (err) {pr_err ("Failed to reinitialize hists\n" ); - goto out_mem2node; + goto out_str; }ui_progress__init (&prog, c2c.hists.hists.nr_entries,"Sorting..." );@@ -3324,17 +3414,19 @@ static int perf_c2c__report(int argc, const char **argv)hists__output_resort_cb (&c2c.hists.hists, &prog, resort_shared_cl_cb); err =hists__iterate_cb (&c2c.hists.hists, resort_cl_cb,perf_session__env (session));if (err) - goto out_mem2node; + goto out_str;ui_progress__finish ();if (ui_quirks ()) {pr_err ("failed to setup UI\n" ); - goto out_mem2node; + goto out_str; }perf_c2c_display (session); +out_str: +free (output_str); out_mem2node:mem2node__exit (&c2c.mem2node); out_session:tools/perf/util/c2c.h +1
-0@@ -33,6 +33,7 @@ struct c2c_hist_entry {unsigned long *nodeset;struct c2c_stats *node_stats;unsigned int cacheline_idx; +unsigned int mem_region;struct compute_stats cstats;
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v12 4/6] perf tools: Show memory region in perf-c2c subcommand
Quoted 5 lines · Arnaldo Carvalho de Melo
Quoted 1 line · Dapeng
Reviewed-by Dapeng Mi <[email protected]>Is this needed since you're the author of the patch? I'm keeping just the Signed-off-by,
I'll keep it since I saw a Co-developed-by tag, meaning maybe there were changes after you initially created this patch...
- Arnaldo
Quoted 314 lines
Quoted 314 lines · Thomas Falcon
Quoted 312 lines
From: Dapeng Mi <[email protected]>
Add memory region field to the cacheline list view to help users identify the memory region to which the cacheline belongs. The memory region field was included with the introduction of support for the Off-module Response facility (OMR) [1] in Intel's Diamond Rapids and Nova Lake architectures.
An example of the new perf c2c output including the memory region field is shown below:
# Index Address Region Node PA cnt Hitm Total LclHitm RmtHitm records Loads # ..... .................. ...... .... ...... ....... ....... ....... ....... ....... ....... # 0 0xffffffff84eb0040 N/A 0 1205 23.25% 544 544 0 1677 1677 1 0xffffffff84f03a80 N/A 0 1 18.12% 424 424 0 585 585 [...] 19 0xffffffff845bc840 Mem-0 0 13 0.30% 7 7 0 31 31 20 0xff3bbba284520a00 N/A 0 10 0.26% 6 6 0 11 11 21 0xff3bbbe0bc833500 N/A 0 24 0.26% 6 6 0 30 30[1]: https://lore.kernel.org/all/[email protected]/
Assisted-by Sashiko:gemini-3.1-pro-previewAssisted-by GitHub-Copilot:claude-opus-4-8Reviewed-by Ian Rogers <[email protected]>Reviewed-by Namhyung Kim <[email protected]>Signed-off-by Dapeng Mi <[email protected]>Co-developed-by Thomas Falcon <[email protected]>Signed-off-by Thomas Falcon <[email protected]>---
v11: perf-c2c: revert to only recording a real memory region for a
cacheline
v10: only updatemem_regionfor real cache/memory regions so N/A samples
don't overwrite a valid region; add #include <stdio.h> for asprintf (Sashiko)
v9: Update perf-c2c to include cache region reporting (Dapeng Mi)
v8: Update developer tags and commit message with real example
output (Dapeng Mi)
v7: fixoutput_strallocation error handling which introduced
a memory leak (Sashiko)
v6: rebased onto 7.3-rc1
v5: make the cacheline header span andui_quirks()width
fixup depend on memory-region availability (Namhyung Kim)
v4: correctly handleoutput_strmemory allocation failure
v3: make memory region reporting conditional on feature bit--- tools/perf/builtin-c2c.c | 114 +++++++++++++++++++++++++++++++++++---- tools/perf/util/c2c.h | 1 + 2 files changed, 104 insertions(+), 11 deletions(-)tools/perf/builtin-c2c.c +103
-11@@ -14,6 +14,7 @@#include <inttypes.h> #include <stdlib.h> #include <string.h> +#include <stdio.h> #include <asm/bug.h> #include <linux/compiler.h> @@ -72,6 +73,7 @@ struct perf_c2c {bool show_src;bool show_all; +bool show_mem_region;bool use_stdio;bool stats_only;bool symbol_full;@@ -248,6 +250,18 @@ static void c2c_he__set_node(struct c2c_hist_entry *c2c_he, } } +static void c2c_he__set_mem_region (struct c2c_hist_entry *c2c_he, +unsigned int mem_region) +{ +if (WARN_ONCE (mem_region >PERF_MEM_REGION_MEM7 , +"WARNING: invalid memory region ID\n" )) +return ; + +/* Update mem_region only if it really accesses memory */ +if (mem_region >=PERF_MEM_REGION_MMIO ) + c2c_he->mem_region = mem_region; +} +static void compute_stats (struct c2c_hist_entry *c2c_he,struct c2c_stats *stats,u64 weight)@@ -306,6 +320,7 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused,struct addr_location al;struct mem_info *mi =NULL ;struct callchain_cursor *cursor; +unsigned int mem_region;int ret;addr_location__init (&al);@@ -333,6 +348,7 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused, }c2c_decode_stats (&stats, mi); + mem_region =mem_info__data_src (mi)->mem_region; he = hists__add_entry_ops(&c2c_hists->hists, &c2c_entry_ops, &al, NULL, NULL, mi, NULL,@@ -349,6 +365,7 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused,c2c_he__set_cpu (c2c_he, sample);c2c_he__set_node (c2c_he, sample);c2c_he__set_evsel (c2c_he, evsel); +c2c_he__set_mem_region (c2c_he, mem_region);hists__inc_nr_samples (&c2c_hists->hists, he->filtered);@@ -402,6 +419,7 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused,c2c_he__set_cpu (c2c_he, sample);c2c_he__set_node (c2c_he, sample);c2c_he__set_evsel (c2c_he, evsel); +c2c_he__set_mem_region (c2c_he, mem_region);hists__inc_nr_samples (&c2c_hists->hists, he->filtered); ret =hist_entry__append_callchain (he, sample);@@ -540,6 +558,45 @@ dcacheline_node_count(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,return scnprintf (hpp->buf, hpp->size,"%*lu" , width, c2c_he->paddr_cnt); } +static int +dcacheline_node_mem_region (struct perf_hpp_fmt *fmt,struct perf_hpp *hpp, +struct hist_entry *he) +{ +int width =c2c_width (fmt, hpp, he->hists); +struct c2c_hist_entry *c2c_he; +unsigned int mem_region; +char buf[20 ]; + + c2c_he = container_of(he, struct c2c_hist_entry, he); + mem_region = c2c_he->mem_region; + +switch (mem_region) { +case PERF_MEM_REGION_NA : +case PERF_MEM_REGION_RSVD : +scnprintf (buf,sizeof (buf),"N/A" ); +break ; +case PERF_MEM_REGION_MMIO : +scnprintf (buf,sizeof (buf),"MMIO" ); +break ; +case PERF_MEM_REGION_MEM0 : +case PERF_MEM_REGION_MEM1 : +case PERF_MEM_REGION_MEM2 : +case PERF_MEM_REGION_MEM3 : +case PERF_MEM_REGION_MEM4 : +case PERF_MEM_REGION_MEM5 : +case PERF_MEM_REGION_MEM6 : +case PERF_MEM_REGION_MEM7 : +scnprintf (buf,sizeof (buf),"Mem-%d" , + mem_region -PERF_MEM_REGION_MEM0 ); +break ; +default : +scnprintf (buf,sizeof (buf),"N/A" ); +break ; + } + +return scnprintf (hpp->buf, hpp->size,"%*s" , width, buf); +} +static int offset_entry (struct perf_hpp_fmt *fmt,struct perf_hpp *hpp,struct hist_entry *he) {@@ -1360,6 +1417,14 @@ static struct c2c_dimension dim_dcacheline_node = { .width = 4, }; +static struct c2c_dimension dim_dcacheline_mem_region = { + .header =HEADER_LOW ("Region" ), + .name ="dcacheline_mem_region" , + .cmp = empty_cmp, + .entry = dcacheline_node_mem_region, + .width =6 , +}; +static struct c2c_dimension dim_dcacheline_count = { .header =HEADER_LOW ("PA cnt" ), .name ="dcacheline_count" ,@@ -1791,6 +1856,7 @@ static struct c2c_dimension dim_dcacheline_num_empty = {static struct c2c_dimension *dimensions[] = { &dim_dcacheline, + &dim_dcacheline_mem_region, &dim_dcacheline_node, &dim_dcacheline_count, &dim_offset,@@ -2854,8 +2920,11 @@ static int ui_quirks(void)/* Fix the zero line for dcacheline column. */ buf =fill_line (chk_double_cl ?"Double-Cacheline" :"Cacheline" , dim_dcacheline.width + + (c2c.show_mem_region ? + dim_dcacheline_mem_region.width :0 ) + dim_dcacheline_node.width + - dim_dcacheline_count.width +4 ); + dim_dcacheline_count.width + + (c2c.show_mem_region ?6 :4 ));if (!buf)return -ENOMEM ;@@ -3107,7 +3176,8 @@ static int perf_c2c__report(int argc, const char **argv) OPT_END() };int err =0 ; -const char *output_str, *sort_str =NULL ; +const char *sort_str =NULL ; +char *output_str =NULL ;struct perf_env *env;annotation_options__init ();@@ -3272,9 +3342,16 @@ static int perf_c2c__report(int argc, const char **argv) goto out_mem2node; } -if (c2c.display !=DISPLAY_SNP_PEER ) - output_str ="cl_idx," + c2c.show_mem_region =perf_header__has_feat (&session->header, +HEADER_MEMORY_RANGES ); +if (c2c.show_mem_region) + dim_dcacheline.header.line[0 ].span =3 ; + +if (c2c.display !=DISPLAY_SNP_PEER ) { + if (asprintf(&output_str, + "cl_idx," "dcacheline," + "%s" "dcacheline_node," "dcacheline_count," "percent_costly_snoop,"@@ -3286,10 +3363,17 @@ static int perf_c2c__report(int argc, const char **argv) "ld_fbhit,ld_l1hit,ld_l2hit," "ld_lclhit,lcl_hitm," "ld_rmthit,rmt_hitm," -"dram_lcl,dram_rmt" ; - else - output_str ="cl_idx," + "dram_lcl,dram_rmt", + c2c.show_mem_region ? + "dcacheline_mem_region," : "") < 0) { + err = -ENOMEM ; + goto out_mem2node; + } + }else { + if (asprintf(&output_str, + "cl_idx," "dcacheline," + "%s" "dcacheline_node," "dcacheline_count," "percent_costly_snoop,"@@ -3301,7 +3385,13 @@ static int perf_c2c__report(int argc, const char **argv) "ld_fbhit,ld_l1hit,ld_l2hit," "ld_lclhit,lcl_hitm," "ld_rmthit,rmt_hitm," -"dram_lcl,dram_rmt" ; + "dram_lcl,dram_rmt", + c2c.show_mem_region ? + "dcacheline_mem_region," : "") < 0) { + err = -ENOMEM ; + goto out_mem2node; + } + }if (c2c.display ==DISPLAY_TOT_HITM ) sort_str ="tot_hitm" ;@@ -3315,7 +3405,7 @@ static int perf_c2c__report(int argc, const char **argv) err =c2c_hists__reinit (&c2c.hists, output_str, sort_str,perf_session__env (session));if (err) {pr_err ("Failed to reinitialize hists\n" ); - goto out_mem2node; + goto out_str; }ui_progress__init (&prog, c2c.hists.hists.nr_entries,"Sorting..." );@@ -3324,17 +3414,19 @@ static int perf_c2c__report(int argc, const char **argv)hists__output_resort_cb (&c2c.hists.hists, &prog, resort_shared_cl_cb); err =hists__iterate_cb (&c2c.hists.hists, resort_cl_cb,perf_session__env (session));if (err) - goto out_mem2node; + goto out_str;ui_progress__finish ();if (ui_quirks ()) {pr_err ("failed to setup UI\n" ); - goto out_mem2node; + goto out_str; }perf_c2c_display (session); +out_str: +free (output_str); out_mem2node:mem2node__exit (&c2c.mem2node); out_session:tools/perf/util/c2c.h +1
-0@@ -33,6 +33,7 @@ struct c2c_hist_entry {unsigned long *nodeset;struct c2c_stats *node_stats;unsigned int cacheline_idx; +unsigned int mem_region;struct compute_stats cstats;
PATCH v12 5/6 perf tools: Show memory region in perf-script subcommand
In reply to Thomas FalconFrom: Dapeng Mi <[email protected]>
Show the memory region in perf-script subcommand. Memory region is found in the mem_region field of the memory information data source. This field was included with the introduction of support for the Off-module Response facility (OMR) [1] in Intel's Diamond Rapids and Nova Lake Architectures.
An example of perf-script output with the new memory region field is shown below:
thread 5/0 ... |OP LOAD|LVL L3 hit|SNP HitM|TLB L1 or L2 hit|LCK No|BLK N/A|Region Local-shared-cache ffffffff9f002aba
thread 2/0 ... |OP LOAD|LVL L3 hit|SNP None|TLB L1 or L2 hit|LCK No|BLK N/A|Region Local-shared-cache ffffffff9dc54c95
thread 8/0 ... |OP LOAD|LVL L3 hit|SNP HitM|TLB L1 or L2 hit|LCK No|BLK N/A|Region Other-non-shared-cache ffffffff9dc54db3
thread 0/0 ... |OP LOAD|LVL LFB/MAB hit|SNP None|TLB L1 or L2 hit|LCK No|BLK Addr|Region N/A ffffffff9dc54db3
thread 2/0 ... |OP LOAD|LVL L0 hit|SNP None|TLB L1 or L2 hit|LCK Yes|BLK N/A|Region N/A ffffffff9f002a8c
thread 0/0 ... |OP LOAD|LVL L3 hit|SNP HitM or Fwd|TLB L1 or L2 hit|LCK No|BLK N/A|Region Local-non-shared-cache ffffffff9f002aba
thread 0/0 ... |OP LOAD|LVL L3 hit|SNP None|TLB L1 or L2 hit|LCK No|BLK N/A|Region Local-shared-cache ffffffff9dc54ca7
thread 30/0 ... |OP LOAD|LVL LFB/MAB hit|SNP None|TLB L1 or L2 hit|LCK Yes|BLK N/A|Region N/A ffffffff9dcc1ff2
thread 30/0 ... |OP LOAD|LVL RAM hit|SNP None|TLB L1 or L2 hit|LCK No|BLK N/A|Region Mem-0 ffffffff9dc54c95
thread 19/0 ... |OP LOAD|LVL LFB/MAB hit|SNP None|TLB L1 or L2 hit|LCK No|BLK N/A|Region N/A ffffffff9f002cbb
thread 19/0 ... |OP LOAD|LVL L3 hit|SNP HitM or Fwd|TLB L1 or L2 hit|LCK No|BLK N/A|Region Local-non-shared-cache ffffffff9f002aba[1]: https://lore.kernel.org/all/[email protected]/
---
v10: use a forward declaration of struct perf_session in mem-events.h
instead of including session.h; include session.h directly where needed (Sashiko)
v8: Update developer tags and commit message with real example output
v4: Drop the global show-region flag; pass perf_session to
perf_script__meminfo_scnprintf() and gate the Region field on the feature bit, with a pipe-mode fallback
v3: make memory region reporting conditional on feature bit
--- tools/perf/builtin-script.c | 13 +-- tools/perf/util/mem-events.c | 87 ++++++++++++++++++- tools/perf/util/mem-events.h | 4 +- .../scripting-engines/trace-event-python.c | 6 +- 4 files changed, 100 insertions(+), 10 deletions(-)
tools/perf/builtin-script.c +7 -6
@@ -2153,11 +2153,12 @@ static int evlist__max_name_len(struct evlist *evlist)return max; } -static int data_src__fprintf (u64 data_src,FILE *fp) +static int data_src__fprintf (struct perf_session *session, +u64 data_src,FILE *fp) {struct mem_info *mi =mem_info__new (); -char decode[100 ]; -char out[100 ]; +char decode[200 ]; +char out[200 ];static int maxlen;int len;
@@ -2165,10 +2166,10 @@ static int data_src__fprintf(u64 data_src, FILE *fp)return -ENOMEM ;mem_info__data_src (mi)->val = data_src; -perf_script__meminfo_scnprintf (decode,100 , mi); +perf_script__meminfo_scnprintf (decode,200 , mi, session);mem_info__put (mi); - len =scnprintf (out,100 ,"%16" PRIx64" %s" , data_src, decode); + len =scnprintf (out,200 ,"%16" PRIx64" %s" , data_src, decode);if (maxlen < len) maxlen = len;
@@ -2562,7 +2563,7 @@ static void process_event(struct perf_script *script,perf_sample__fprintf_addr (sample, thread, evsel, fp);if (PRINT_FIELD (DATA_SRC )) -data_src__fprintf (sample->data_src, fp); +data_src__fprintf (evsel__session (evsel), sample->data_src, fp);if (PRINT_FIELD (WEIGHT ))fprintf (fp,"%16" PRIu64, sample->weight);
tools/perf/util/mem-events.c +86 -1
106 lines not on this page · raw message
tools/perf/util/mem-events.h +3 -1
@@ -24,6 +24,7 @@ enum {struct evsel ;struct mem_info ;struct perf_pmu ; +struct perf_session ;extern unsigned int perf_mem_events__loads_ldlat;extern struct perf_mem_event perf_mem_events[PERF_MEM_EVENTS__MAX ];
@@ -47,7 +48,8 @@ int perf_mem__snp_scnprintf(char *out, size_t sz, const struct mem_info *mem_infint perf_mem__lck_scnprintf (char *out,size_t sz,const struct mem_info *mem_info);int perf_mem__blk_scnprintf (char *out,size_t sz,const struct mem_info *mem_info); -int perf_script__meminfo_scnprintf (char *bf,size_t size,const struct mem_info *mem_info); +int perf_script__meminfo_scnprintf (char *bf,size_t size,const struct mem_info *mem_info, +struct perf_session *session);struct c2c_stats {u32 nr_entries;
tools/perf/util/scripting-engines/trace-event-python.c +4 -2
@@ -58,6 +58,7 @@#include "stat.h" #include "mem-events.h" #include "util/perf_regs.h" +#include "util/session.h" #define _PyUnicode_FromString (arg) \ PyUnicode_FromString(arg)
@@ -694,8 +695,9 @@ static void set_sample_read_in_dict(PyObject *dict_sample, struct perf_sample *sstatic void set_sample_datasrc_in_dict (PyObject *dict,struct perf_sample *sample) { +struct perf_session *session =evsel__session (sample->evsel);struct mem_info *mi =mem_info__new (); -char decode[100 ]; +char decode[200 ];if (!mi)Py_FatalError ("couldn't create mem-info" );
@@ -704,7 +706,7 @@ static void set_sample_datasrc_in_dict(PyObject *dict, PyLong_FromUnsignedLongLong(sample->data_src));mem_info__data_src (mi)->val = sample->data_src; -perf_script__meminfo_scnprintf (decode,100 , mi); +perf_script__meminfo_scnprintf (decode,200 , mi, session);mem_info__put (mi); pydict_set_item_string_decref(dict, "datasrc_decode",
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v12 5/6] perf tools: Show memory region in perf-script subcommand
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 15 lines
From: Dapeng Mi <[email protected]>
Show the memory region in perf-script subcommand. Memory region is found in the
mem_regionfield of the memory information data source. This field was included with the introduction of support for the Off-module Response facility (OMR) [1] in Intel's Diamond Rapids and Nova Lake Architectures.An example of perf-script output with the new memory region field is shown below:
thread 5/0 ... |OP LOAD|LVL L3 hit|SNP HitM|TLB L1 or L2 hit|LCK No|BLK N/A|Region Local-shared-cache ffffffff9f002aba thread 2/0 ... |OP LOAD|LVL L3 hit|SNP None|TLB L1 or L2 hit|LCK No|BLK N/A|Region Local-shared-cache ffffffff9dc54c95 thread 8/0 ... |OP LOAD|LVL L3 hit|SNP HitM|TLB L1 or L2 hit|LCK No|BLK N/A|Region Other-non-shared-cache ffffffff9dc54db3 thread 0/0 ... |OP LOAD|LVL LFB/MAB hit|SNP None|TLB L1 or L2 hit|LCK No|BLK Addr|Region N/A ffffffff9dc54db3
Quoted 6 lines
[ ... ]Reviewed-by Ian Rogers <[email protected]>Reviewed-by Namhyung Kim <[email protected]>Signed-off-by Dapeng Mi <[email protected]>Co-developed-by Thomas Falcon <[email protected]>Signed-off-by Thomas Falcon <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
PATCH v12 6/6 perf c2c: print memory region data with stdio output
In reply to Thomas FalconPrint memory range data in perf-c2c subcommand. Only available in stdio mode currently. If memory ranges are not supported or present, print nothing.
Example output of perf c2c report --stdio:
=================================================
Memory Ranges
=================================================
Range 0: [0x0000000000000000-0x00000000bfffffff] Node 0, local region id 0, remote region id 255 Range 1: [0x0000000100000000-0x000000203fffffff] Node 0, local region id 0, remote region id 255 Range 2: [0x0000008000000000-0x0000027fffffffff] Node -2, local region id 1, remote region id 255 Range 3: [0x0000028000000000-0x0000047fffffffff] Node -2, local region id 1, remote region id 255 Range 4: [0x0000048000000000-0x000004ffffffffff] Node -2, local region id 1, remote region id 255
---
v10: Fixup double blank line before print_memory_ranges_info() define
--- tools/perf/builtin-c2c.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
tools/perf/builtin-c2c.c +29 -0
@@ -2597,6 +2597,33 @@ static void print_c2c_info(FILE *out, struct perf_session *session)fprintf (out," Cacheline data grouping : %s\n" , c2c.cl_sort); } +static void print_memory_ranges_info (FILE *out,struct perf_session *session) +{ +struct perf_env *env =perf_session__env (session); +int nr_ranges =0 ; + +if (!perf_header__has_feat (&session->header,HEADER_MEMORY_RANGES )) +return ; + nr_ranges = env->nr_memory_ranges; +if (nr_ranges ==0 ) { +pr_debug ("No memory ranges found, skipping\n" ); +return ; + } + +fprintf (out,"\n" ); +fprintf (out,"=================================================\n" ); +fprintf (out," Memory Ranges \n" ); +fprintf (out,"=================================================\n" ); + +for (int i =0 ; i < nr_ranges; i++) { +struct memory_range *r = &env->memory_ranges[i]; + +fprintf (out,"Range %d: [0x%016" PRIx64"-0x%016" PRIx64"] Node %d, local region id %u, remote region id %u\n" , + i, r->base, r->base + r->length -1 , r->node, + r->local_region_id, r->remote_region_id); + } +} +static void perf_c2c__hists_fprintf (FILE *out,struct perf_session *session) {setup_pager ();
@@ -2610,6 +2637,8 @@ static void perf_c2c__hists_fprintf(FILE *out, struct perf_session *session)if (c2c.stats_only)return ; +print_memory_ranges_info (out, session); +fprintf (out,"\n" );fprintf (out,"=================================================\n" );fprintf (out," Shared Data Cache Line Table \n" );
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v12 6/6] perf c2c: print memory region data with stdio output
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 15 lines
Print memory range data in perf-c2c subcommand. Only available in stdio mode currently. If memory ranges are not supported or present, print nothing.
Example output of perf c2c report --stdio:
=================================================
Memory Ranges
=================================================
Range 0: [0x0000000000000000-0x00000000bfffffff] Node 0, local region id 0, remote region id 255 Range 1: [0x0000000100000000-0x000000203fffffff] Node 0, local region id 0, remote region id 255 Range 2: [0x0000008000000000-0x0000027fffffffff] Node -2, local region id 1, remote region id 255 Range 3: [0x0000028000000000-0x0000047fffffffff] Node -2, local region id 1, remote region id 255 Range 4: [0x0000048000000000-0x000004ffffffffff] Node -2, local region id 1, remote region id 255
Quoted 4 lines
Assisted-by Sashiko:gemini-3.1-pro-previewReviewed-by Ian Rogers <[email protected]>Reviewed-by Namhyung Kim <[email protected]>Signed-off-by Thomas Falcon <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
Quoted 1 line · Thomas Falcon
Add support for two memory-related reporting features in the perf tool:
<SNIP>
Quoted 11 lines
Include a change allowing
PERF_MEM_LVLNUM_L0to be printed in perf-mem output as well.[1]: https://lore.kernel.org/all/[email protected]/
[2]: https://lore.kernel.org/lkml/[email protected]/
[3]: MRRM definition allow for future expansion for the OS to assign these region IDs.v12:
-- Fixed typo in bounds checking for max supported memory ranges when
reading header data
Thanks, applied to perf-tools-next, for v7.4.
- Arnaldo
PATCH v11 4/6 perf tools: Show memory region in perf-c2c subcommand
In reply to Thomas FalconFrom: Dapeng Mi <[email protected]>
Add memory region field to the cacheline list view to help users identify the memory region to which the cacheline belongs. The memory region field was included with the introduction of support for the Off-module Response facility (OMR) [1] in Intel's Diamond Rapids and Nova Lake architectures.
An example of the new perf c2c output including the memory region field is shown below:
# Index Address Region Node PA cnt Hitm Total LclHitm RmtHitm records Loads
# ..... .................. ...... .... ...... ....... ....... ....... ....... ....... .......
#
0 0xffffffff84eb0040 N/A 0 1205 23.25% 544 544 0 1677 1677
1 0xffffffff84f03a80 N/A 0 1 18.12% 424 424 0 585 585
[...]
19 0xffffffff845bc840 Mem-0 0 13 0.30% 7 7 0 31 31
20 0xff3bbba284520a00 N/A 0 10 0.26% 6 6 0 11 11
21 0xff3bbbe0bc833500 N/A 0 24 0.26% 6 6 0 30 30[1]: https://lore.kernel.org/all/[email protected]/
---
v11: perf-c2c: revert to only recording a real memory region for a
cacheline
v10: only update mem_region for real cache/memory regions so N/A samples
don't overwrite a valid region; add #include <stdio.h> for asprintf (Sashiko)
v9: Update perf-c2c to include cache region reporting (Dapeng Mi)
v8: Update developer tags and commit message with real example
output (Dapeng Mi)
v7: fix output_str allocation error handling which introduced
a memory leak (Sashiko)
v6: rebased onto 7.3-rc1
v5: make the cacheline header span and ui_quirks() width
fixup depend on memory-region availability (Namhyung Kim)
v4: correctly handle output_str memory allocation failure
v3: make memory region reporting conditional on feature bit
--- tools/perf/builtin-c2c.c | 114 +++++++++++++++++++++++++++++++++++---- tools/perf/util/c2c.h | 1 + 2 files changed, 104 insertions(+), 11 deletions(-)
tools/perf/builtin-c2c.c +103 -11
@@ -14,6 +14,7 @@#include <inttypes.h> #include <stdlib.h> #include <string.h> +#include <stdio.h> #include <asm/bug.h> #include <linux/compiler.h>
@@ -72,6 +73,7 @@ struct perf_c2c {bool show_src;bool show_all; +bool show_mem_region;bool use_stdio;bool stats_only;bool symbol_full;
@@ -248,6 +250,18 @@ static void c2c_he__set_node(struct c2c_hist_entry *c2c_he, } } +static void c2c_he__set_mem_region (struct c2c_hist_entry *c2c_he, +unsigned int mem_region) +{ +if (WARN_ONCE (mem_region >PERF_MEM_REGION_MEM7 , +"WARNING: invalid memory region ID\n" )) +return ; + +/* Update mem_region only if it really accesses memory */ +if (mem_region >=PERF_MEM_REGION_MMIO ) + c2c_he->mem_region = mem_region; +} +static void compute_stats (struct c2c_hist_entry *c2c_he,struct c2c_stats *stats,u64 weight)
@@ -306,6 +320,7 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused,struct addr_location al;struct mem_info *mi =NULL ;struct callchain_cursor *cursor; +unsigned int mem_region;int ret;addr_location__init (&al);
@@ -333,6 +348,7 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused, }c2c_decode_stats (&stats, mi); + mem_region =mem_info__data_src (mi)->mem_region; he = hists__add_entry_ops(&c2c_hists->hists, &c2c_entry_ops, &al, NULL, NULL, mi, NULL,
@@ -349,6 +365,7 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused,c2c_he__set_cpu (c2c_he, sample);c2c_he__set_node (c2c_he, sample);c2c_he__set_evsel (c2c_he, evsel); +c2c_he__set_mem_region (c2c_he, mem_region);hists__inc_nr_samples (&c2c_hists->hists, he->filtered);
@@ -402,6 +419,7 @@ static int process_sample_event(const struct perf_tool *tool __maybe_unused,c2c_he__set_cpu (c2c_he, sample);c2c_he__set_node (c2c_he, sample);c2c_he__set_evsel (c2c_he, evsel); +c2c_he__set_mem_region (c2c_he, mem_region);hists__inc_nr_samples (&c2c_hists->hists, he->filtered); ret =hist_entry__append_callchain (he, sample);
@@ -540,6 +558,45 @@ dcacheline_node_count(struct perf_hpp_fmt *fmt, struct perf_hpp *hpp,return scnprintf (hpp->buf, hpp->size,"%*lu" , width, c2c_he->paddr_cnt); } +static int +dcacheline_node_mem_region (struct perf_hpp_fmt *fmt,struct perf_hpp *hpp, +struct hist_entry *he) +{ +int width =c2c_width (fmt, hpp, he->hists); +struct c2c_hist_entry *c2c_he; +unsigned int mem_region; +char buf[20 ]; + + c2c_he = container_of(he, struct c2c_hist_entry, he); + mem_region = c2c_he->mem_region; + +switch (mem_region) { +case PERF_MEM_REGION_NA : +case PERF_MEM_REGION_RSVD : +scnprintf (buf,sizeof (buf),"N/A" ); +break ; +case PERF_MEM_REGION_MMIO : +scnprintf (buf,sizeof (buf),"MMIO" ); +break ; +case PERF_MEM_REGION_MEM0 : +case PERF_MEM_REGION_MEM1 : +case PERF_MEM_REGION_MEM2 : +case PERF_MEM_REGION_MEM3 : +case PERF_MEM_REGION_MEM4 : +case PERF_MEM_REGION_MEM5 : +case PERF_MEM_REGION_MEM6 : +case PERF_MEM_REGION_MEM7 : +scnprintf (buf,sizeof (buf),"Mem-%d" , + mem_region -PERF_MEM_REGION_MEM0 ); +break ; +default : +scnprintf (buf,sizeof (buf),"N/A" ); +break ; + } + +return scnprintf (hpp->buf, hpp->size,"%*s" , width, buf); +} +static int offset_entry (struct perf_hpp_fmt *fmt,struct perf_hpp *hpp,struct hist_entry *he) {
@@ -1360,6 +1417,14 @@ static struct c2c_dimension dim_dcacheline_node = { .width = 4, }; +static struct c2c_dimension dim_dcacheline_mem_region = { + .header =HEADER_LOW ("Region" ), + .name ="dcacheline_mem_region" , + .cmp = empty_cmp, + .entry = dcacheline_node_mem_region, + .width =6 , +}; +static struct c2c_dimension dim_dcacheline_count = { .header =HEADER_LOW ("PA cnt" ), .name ="dcacheline_count" ,
@@ -1791,6 +1856,7 @@ static struct c2c_dimension dim_dcacheline_num_empty = {static struct c2c_dimension *dimensions[] = { &dim_dcacheline, + &dim_dcacheline_mem_region, &dim_dcacheline_node, &dim_dcacheline_count, &dim_offset,
@@ -2854,8 +2920,11 @@ static int ui_quirks(void)/* Fix the zero line for dcacheline column. */ buf =fill_line (chk_double_cl ?"Double-Cacheline" :"Cacheline" , dim_dcacheline.width + + (c2c.show_mem_region ? + dim_dcacheline_mem_region.width :0 ) + dim_dcacheline_node.width + - dim_dcacheline_count.width +4 ); + dim_dcacheline_count.width + + (c2c.show_mem_region ?6 :4 ));if (!buf)return -ENOMEM ;
@@ -3107,7 +3176,8 @@ static int perf_c2c__report(int argc, const char **argv) OPT_END() };int err =0 ; -const char *output_str, *sort_str =NULL ; +const char *sort_str =NULL ; +char *output_str =NULL ;struct perf_env *env;annotation_options__init ();
@@ -3272,9 +3342,16 @@ static int perf_c2c__report(int argc, const char **argv) goto out_mem2node; } -if (c2c.display !=DISPLAY_SNP_PEER ) - output_str ="cl_idx," + c2c.show_mem_region =perf_header__has_feat (&session->header, +HEADER_MEMORY_RANGES ); +if (c2c.show_mem_region) + dim_dcacheline.header.line[0 ].span =3 ; + +if (c2c.display !=DISPLAY_SNP_PEER ) { + if (asprintf(&output_str, + "cl_idx," "dcacheline," + "%s" "dcacheline_node," "dcacheline_count," "percent_costly_snoop,"
@@ -3286,10 +3363,17 @@ static int perf_c2c__report(int argc, const char **argv) "ld_fbhit,ld_l1hit,ld_l2hit," "ld_lclhit,lcl_hitm," "ld_rmthit,rmt_hitm," -"dram_lcl,dram_rmt" ; - else - output_str ="cl_idx," + "dram_lcl,dram_rmt", + c2c.show_mem_region ? + "dcacheline_mem_region," : "") < 0) { + err = -ENOMEM ; + goto out_mem2node; + } + }else { + if (asprintf(&output_str, + "cl_idx," "dcacheline," + "%s" "dcacheline_node," "dcacheline_count," "percent_costly_snoop,"
@@ -3301,7 +3385,13 @@ static int perf_c2c__report(int argc, const char **argv) "ld_fbhit,ld_l1hit,ld_l2hit," "ld_lclhit,lcl_hitm," "ld_rmthit,rmt_hitm," -"dram_lcl,dram_rmt" ; + "dram_lcl,dram_rmt", + c2c.show_mem_region ? + "dcacheline_mem_region," : "") < 0) { + err = -ENOMEM ; + goto out_mem2node; + } + }if (c2c.display ==DISPLAY_TOT_HITM ) sort_str ="tot_hitm" ;
@@ -3315,7 +3405,7 @@ static int perf_c2c__report(int argc, const char **argv) err =c2c_hists__reinit (&c2c.hists, output_str, sort_str,perf_session__env (session));if (err) {pr_err ("Failed to reinitialize hists\n" ); - goto out_mem2node; + goto out_str; }ui_progress__init (&prog, c2c.hists.hists.nr_entries,"Sorting..." );
@@ -3324,17 +3414,19 @@ static int perf_c2c__report(int argc, const char **argv)hists__output_resort_cb (&c2c.hists.hists, &prog, resort_shared_cl_cb); err =hists__iterate_cb (&c2c.hists.hists, resort_cl_cb,perf_session__env (session));if (err) - goto out_mem2node; + goto out_str;ui_progress__finish ();if (ui_quirks ()) {pr_err ("failed to setup UI\n" ); - goto out_mem2node; + goto out_str; }perf_c2c_display (session); +out_str: +free (output_str); out_mem2node:mem2node__exit (&c2c.mem2node); out_session:
tools/perf/util/c2c.h +1 -0
@@ -33,6 +33,7 @@ struct c2c_hist_entry {unsigned long *nodeset;struct c2c_stats *node_stats;unsigned int cacheline_idx; +unsigned int mem_region;struct compute_stats cstats;
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v11 4/6] perf tools: Show memory region in perf-c2c subcommand
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 23 lines
From: Dapeng Mi <[email protected]>
Add memory region field to the cacheline list view to help users identify the memory region to which the cacheline belongs. The memory region field was included with the introduction of support for the Off-module Response facility (OMR) [1] in Intel's Diamond Rapids and Nova Lake architectures.
An example of the new perf c2c output including the memory region field is shown below:
# Index Address Region Node PA cnt Hitm Total LclHitm RmtHitm records Loads # ..... .................. ...... .... ...... ....... ....... ....... ....... ....... ....... # 0 0xffffffff84eb0040 N/A 0 1205 23.25% 544 544 0 1677 1677 1 0xffffffff84f03a80 N/A 0 1 18.12% 424 424 0 585 585 [...] 19 0xffffffff845bc840 Mem-0 0 13 0.30% 7 7 0 31 31 20 0xff3bbba284520a00 N/A 0 10 0.26% 6 6 0 11 11 21 0xff3bbbe0bc833500 N/A 0 24 0.26% 6 6 0 30 30
Quoted 7 lines
Assisted-by Sashiko:gemini-3.1-pro-previewAssisted-by GitHub-Copilot:claude-opus-4-8Reviewed-by Ian Rogers <[email protected]>Reviewed-by Namhyung Kim <[email protected]>Signed-off-by Dapeng Mi <[email protected]>Co-developed-by Thomas Falcon <[email protected]>Signed-off-by Thomas Falcon <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
PATCH v11 5/6 perf tools: Show memory region in perf-script subcommand
In reply to Thomas FalconFrom: Dapeng Mi <[email protected]>
Show the memory region in perf-script subcommand. Memory region is found in the mem_region field of the memory information data source. This field was included with the introduction of support for the Off-module Response facility (OMR) [1] in Intel's Diamond Rapids and Nova Lake Architectures.
An example of perf-script output with the new memory region field is shown below:
thread 5/0 ... |OP LOAD|LVL L3 hit|SNP HitM|TLB L1 or L2 hit|LCK No|BLK N/A|Region Local-shared-cache ffffffff9f002aba
thread 2/0 ... |OP LOAD|LVL L3 hit|SNP None|TLB L1 or L2 hit|LCK No|BLK N/A|Region Local-shared-cache ffffffff9dc54c95
thread 8/0 ... |OP LOAD|LVL L3 hit|SNP HitM|TLB L1 or L2 hit|LCK No|BLK N/A|Region Other-non-shared-cache ffffffff9dc54db3
thread 0/0 ... |OP LOAD|LVL LFB/MAB hit|SNP None|TLB L1 or L2 hit|LCK No|BLK Addr|Region N/A ffffffff9dc54db3
thread 2/0 ... |OP LOAD|LVL L0 hit|SNP None|TLB L1 or L2 hit|LCK Yes|BLK N/A|Region N/A ffffffff9f002a8c
thread 0/0 ... |OP LOAD|LVL L3 hit|SNP HitM or Fwd|TLB L1 or L2 hit|LCK No|BLK N/A|Region Local-non-shared-cache ffffffff9f002aba
thread 0/0 ... |OP LOAD|LVL L3 hit|SNP None|TLB L1 or L2 hit|LCK No|BLK N/A|Region Local-shared-cache ffffffff9dc54ca7
thread 30/0 ... |OP LOAD|LVL LFB/MAB hit|SNP None|TLB L1 or L2 hit|LCK Yes|BLK N/A|Region N/A ffffffff9dcc1ff2
thread 30/0 ... |OP LOAD|LVL RAM hit|SNP None|TLB L1 or L2 hit|LCK No|BLK N/A|Region Mem-0 ffffffff9dc54c95
thread 19/0 ... |OP LOAD|LVL LFB/MAB hit|SNP None|TLB L1 or L2 hit|LCK No|BLK N/A|Region N/A ffffffff9f002cbb
thread 19/0 ... |OP LOAD|LVL L3 hit|SNP HitM or Fwd|TLB L1 or L2 hit|LCK No|BLK N/A|Region Local-non-shared-cache ffffffff9f002aba[1]: https://lore.kernel.org/all/[email protected]/
---
v10: use a forward declaration of struct perf_session in mem-events.h
instead of including session.h; include session.h directly where needed (Sashiko)
v8: Update developer tags and commit message with real example output
v4: Drop the global show-region flag; pass perf_session to
perf_script__meminfo_scnprintf() and gate the Region field on the feature bit, with a pipe-mode fallback
v3: make memory region reporting conditional on feature bit
--- tools/perf/builtin-script.c | 13 +-- tools/perf/util/mem-events.c | 87 ++++++++++++++++++- tools/perf/util/mem-events.h | 4 +- .../scripting-engines/trace-event-python.c | 6 +- 4 files changed, 100 insertions(+), 10 deletions(-)
tools/perf/builtin-script.c +7 -6
@@ -2153,11 +2153,12 @@ static int evlist__max_name_len(struct evlist *evlist)return max; } -static int data_src__fprintf (u64 data_src,FILE *fp) +static int data_src__fprintf (struct perf_session *session, +u64 data_src,FILE *fp) {struct mem_info *mi =mem_info__new (); -char decode[100 ]; -char out[100 ]; +char decode[200 ]; +char out[200 ];static int maxlen;int len;
@@ -2165,10 +2166,10 @@ static int data_src__fprintf(u64 data_src, FILE *fp)return -ENOMEM ;mem_info__data_src (mi)->val = data_src; -perf_script__meminfo_scnprintf (decode,100 , mi); +perf_script__meminfo_scnprintf (decode,200 , mi, session);mem_info__put (mi); - len =scnprintf (out,100 ,"%16" PRIx64" %s" , data_src, decode); + len =scnprintf (out,200 ,"%16" PRIx64" %s" , data_src, decode);if (maxlen < len) maxlen = len;
@@ -2562,7 +2563,7 @@ static void process_event(struct perf_script *script,perf_sample__fprintf_addr (sample, thread, evsel, fp);if (PRINT_FIELD (DATA_SRC )) -data_src__fprintf (sample->data_src, fp); +data_src__fprintf (evsel__session (evsel), sample->data_src, fp);if (PRINT_FIELD (WEIGHT ))fprintf (fp,"%16" PRIu64, sample->weight);
tools/perf/util/mem-events.c +86 -1
106 lines not on this page · raw message
tools/perf/util/mem-events.h +3 -1
@@ -24,6 +24,7 @@ enum {struct evsel ;struct mem_info ;struct perf_pmu ; +struct perf_session ;extern unsigned int perf_mem_events__loads_ldlat;extern struct perf_mem_event perf_mem_events[PERF_MEM_EVENTS__MAX ];
@@ -47,7 +48,8 @@ int perf_mem__snp_scnprintf(char *out, size_t sz, const struct mem_info *mem_infint perf_mem__lck_scnprintf (char *out,size_t sz,const struct mem_info *mem_info);int perf_mem__blk_scnprintf (char *out,size_t sz,const struct mem_info *mem_info); -int perf_script__meminfo_scnprintf (char *bf,size_t size,const struct mem_info *mem_info); +int perf_script__meminfo_scnprintf (char *bf,size_t size,const struct mem_info *mem_info, +struct perf_session *session);struct c2c_stats {u32 nr_entries;
tools/perf/util/scripting-engines/trace-event-python.c +4 -2
@@ -58,6 +58,7 @@#include "stat.h" #include "mem-events.h" #include "util/perf_regs.h" +#include "util/session.h" #define _PyUnicode_FromString (arg) \ PyUnicode_FromString(arg)
@@ -694,8 +695,9 @@ static void set_sample_read_in_dict(PyObject *dict_sample, struct perf_sample *sstatic void set_sample_datasrc_in_dict (PyObject *dict,struct perf_sample *sample) { +struct perf_session *session =evsel__session (sample->evsel);struct mem_info *mi =mem_info__new (); -char decode[100 ]; +char decode[200 ];if (!mi)Py_FatalError ("couldn't create mem-info" );
@@ -704,7 +706,7 @@ static void set_sample_datasrc_in_dict(PyObject *dict, PyLong_FromUnsignedLongLong(sample->data_src));mem_info__data_src (mi)->val = sample->data_src; -perf_script__meminfo_scnprintf (decode,100 , mi); +perf_script__meminfo_scnprintf (decode,200 , mi, session);mem_info__put (mi); pydict_set_item_string_decref(dict, "datasrc_decode",
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v11 5/6] perf tools: Show memory region in perf-script subcommand
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 15 lines
From: Dapeng Mi <[email protected]>
Show the memory region in perf-script subcommand. Memory region is found in the
mem_regionfield of the memory information data source. This field was included with the introduction of support for the Off-module Response facility (OMR) [1] in Intel's Diamond Rapids and Nova Lake Architectures.An example of perf-script output with the new memory region field is shown below:
thread 5/0 ... |OP LOAD|LVL L3 hit|SNP HitM|TLB L1 or L2 hit|LCK No|BLK N/A|Region Local-shared-cache ffffffff9f002aba thread 2/0 ... |OP LOAD|LVL L3 hit|SNP None|TLB L1 or L2 hit|LCK No|BLK N/A|Region Local-shared-cache ffffffff9dc54c95 thread 8/0 ... |OP LOAD|LVL L3 hit|SNP HitM|TLB L1 or L2 hit|LCK No|BLK N/A|Region Other-non-shared-cache ffffffff9dc54db3 thread 0/0 ... |OP LOAD|LVL LFB/MAB hit|SNP None|TLB L1 or L2 hit|LCK No|BLK Addr|Region N/A ffffffff9dc54db3
Quoted 6 lines
[ ... ]Reviewed-by Ian Rogers <[email protected]>Reviewed-by Namhyung Kim <[email protected]>Signed-off-by Dapeng Mi <[email protected]>Co-developed-by Thomas Falcon <[email protected]>Signed-off-by Thomas Falcon <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
PATCH v11 6/6 perf c2c: print memory region data with stdio output
In reply to Thomas FalconPrint memory range data in perf-c2c subcommand. Only available in stdio mode currently. If memory ranges are not supported or present, print nothing.
Example output of perf c2c report --stdio:
=================================================
Memory Ranges
=================================================
Range 0: [0x0000000000000000-0x00000000bfffffff] Node 0, local region id 0, remote region id 255 Range 1: [0x0000000100000000-0x000000203fffffff] Node 0, local region id 0, remote region id 255 Range 2: [0x0000008000000000-0x0000027fffffffff] Node -2, local region id 1, remote region id 255 Range 3: [0x0000028000000000-0x0000047fffffffff] Node -2, local region id 1, remote region id 255 Range 4: [0x0000048000000000-0x000004ffffffffff] Node -2, local region id 1, remote region id 255
---
v10: Fixup double blank line before print_memory_ranges_info() define
--- tools/perf/builtin-c2c.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
tools/perf/builtin-c2c.c +29 -0
@@ -2597,6 +2597,33 @@ static void print_c2c_info(FILE *out, struct perf_session *session)fprintf (out," Cacheline data grouping : %s\n" , c2c.cl_sort); } +static void print_memory_ranges_info (FILE *out,struct perf_session *session) +{ +struct perf_env *env =perf_session__env (session); +int nr_ranges =0 ; + +if (!perf_header__has_feat (&session->header,HEADER_MEMORY_RANGES )) +return ; + nr_ranges = env->nr_memory_ranges; +if (nr_ranges ==0 ) { +pr_debug ("No memory ranges found, skipping\n" ); +return ; + } + +fprintf (out,"\n" ); +fprintf (out,"=================================================\n" ); +fprintf (out," Memory Ranges \n" ); +fprintf (out,"=================================================\n" ); + +for (int i =0 ; i < nr_ranges; i++) { +struct memory_range *r = &env->memory_ranges[i]; + +fprintf (out,"Range %d: [0x%016" PRIx64"-0x%016" PRIx64"] Node %d, local region id %u, remote region id %u\n" , + i, r->base, r->base + r->length -1 , r->node, + r->local_region_id, r->remote_region_id); + } +} +static void perf_c2c__hists_fprintf (FILE *out,struct perf_session *session) {setup_pager ();
@@ -2610,6 +2637,8 @@ static void perf_c2c__hists_fprintf(FILE *out, struct perf_session *session)if (c2c.stats_only)return ; +print_memory_ranges_info (out, session); +fprintf (out,"\n" );fprintf (out,"=================================================\n" );fprintf (out," Shared Data Cache Line Table \n" );
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v11 6/6] perf c2c: print memory region data with stdio output
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 15 lines
Print memory range data in perf-c2c subcommand. Only available in stdio mode currently. If memory ranges are not supported or present, print nothing.
Example output of perf c2c report --stdio:
=================================================
Memory Ranges
=================================================
Range 0: [0x0000000000000000-0x00000000bfffffff] Node 0, local region id 0, remote region id 255 Range 1: [0x0000000100000000-0x000000203fffffff] Node 0, local region id 0, remote region id 255 Range 2: [0x0000008000000000-0x0000027fffffffff] Node -2, local region id 1, remote region id 255 Range 3: [0x0000028000000000-0x0000047fffffffff] Node -2, local region id 1, remote region id 255 Range 4: [0x0000048000000000-0x000004ffffffffff] Node -2, local region id 1, remote region id 255
Quoted 4 lines
Assisted-by Sashiko:gemini-3.1-pro-previewReviewed-by Ian Rogers <[email protected]>Reviewed-by Namhyung Kim <[email protected]>Signed-off-by Thomas Falcon <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6