Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf mem: Fix printing PERF_MEM_LVLNUM_{L2_MHB|MSC}

With commit 8ec9497d3ef34 ("tools/include: Sync uapi/linux/perf.h
with the kernel sources"), 'perf mem report' gives an incorrect memory
access string.
...
0.02% 1 3644 L5 hit [.] 0x0000000000009b0e mlc [.] 0x00007fce43f59480
...

This occurs because, if no entry exists in mem_lvlnum, perf_mem__lvl_scnprintf
will default to 'L%d, lvl', which in this case for PERF_MEM_LVLNUM_L2_MHB is 0x05.
Add entries for PERF_MEM_LVLNUM_L2_MHB and PERF_MEM_LVLNUM_MSC to mem_lvlnum,
so that the correct strings are printed.
...
0.02% 1 3644 L2 MHB hit [.] 0x0000000000009b0e mlc [.] 0x00007fce43f59480
...

Fixes: 8ec9497d3ef34 ("tools/include: Sync uapi/linux/perf.h with the kernel sources")
Suggested-by: Kan Liang <kan.liang@linux.intel.com>
Signed-off-by: Thomas Falcon <thomas.falcon@intel.com>
Reviewed-by: Leo Yan <leo.yan@arm.com>
Link: https://lore.kernel.org/r/20240926144040.77897-1-thomas.falcon@intel.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>

authored by

Thomas Falcon and committed by
Namhyung Kim
4f23fc34 6adeb277

+7 -1
+7 -1
tools/perf/util/mem-events.c
··· 366 366 }; 367 367 368 368 static const char * const mem_lvlnum[] = { 369 + [PERF_MEM_LVLNUM_L1] = "L1", 370 + [PERF_MEM_LVLNUM_L2] = "L2", 371 + [PERF_MEM_LVLNUM_L3] = "L3", 372 + [PERF_MEM_LVLNUM_L4] = "L4", 373 + [PERF_MEM_LVLNUM_L2_MHB] = "L2 MHB", 374 + [PERF_MEM_LVLNUM_MSC] = "Memory-side Cache", 369 375 [PERF_MEM_LVLNUM_UNC] = "Uncached", 370 376 [PERF_MEM_LVLNUM_CXL] = "CXL", 371 377 [PERF_MEM_LVLNUM_IO] = "I/O", ··· 454 448 if (mem_lvlnum[lvl]) 455 449 l += scnprintf(out + l, sz - l, mem_lvlnum[lvl]); 456 450 else 457 - l += scnprintf(out + l, sz - l, "L%d", lvl); 451 + l += scnprintf(out + l, sz - l, "Unknown level %d", lvl); 458 452 459 453 l += scnprintf(out + l, sz - l, " %s", hit_miss); 460 454 return l;