* [PATCH] perf mem: Fix printing PERF_MEM_LVLNUM_{L2_MHB|MSC} @ 2024-09-25 18:36 Thomas Falcon 2024-09-25 20:16 ` Leo Yan 0 siblings, 1 reply; 3+ messages in thread From: Thomas Falcon @ 2024-09-25 18:36 UTC (permalink / raw) To: peterz, mingo, acme, namhyung, mark.rutland, alexander.shishkin, jolsa, irogers, adrian.hunter, kan.liang Cc: linux-perf-users, linux-kernel, Thomas Falcon 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: Kan Liang <kan.liang@linux.intel.com> --- tools/perf/util/mem-events.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/perf/util/mem-events.c b/tools/perf/util/mem-events.c index 051feb93ed8d..c630aca5bd93 100644 --- a/tools/perf/util/mem-events.c +++ b/tools/perf/util/mem-events.c @@ -366,6 +366,8 @@ static const char * const mem_lvl[] = { }; static const char * const mem_lvlnum[] = { + [PERF_MEM_LVLNUM_L2_MHB] = "L2 MHB", + [PERF_MEM_LVLNUM_MSC] = "Memory-side Cache", [PERF_MEM_LVLNUM_UNC] = "Uncached", [PERF_MEM_LVLNUM_CXL] = "CXL", [PERF_MEM_LVLNUM_IO] = "I/O", -- 2.46.0 ^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] perf mem: Fix printing PERF_MEM_LVLNUM_{L2_MHB|MSC} 2024-09-25 18:36 [PATCH] perf mem: Fix printing PERF_MEM_LVLNUM_{L2_MHB|MSC} Thomas Falcon @ 2024-09-25 20:16 ` Leo Yan 2024-09-25 21:40 ` Falcon, Thomas 0 siblings, 1 reply; 3+ messages in thread From: Leo Yan @ 2024-09-25 20:16 UTC (permalink / raw) To: Thomas Falcon, peterz, mingo, acme, namhyung, mark.rutland, alexander.shishkin, jolsa, irogers, adrian.hunter, kan.liang Cc: linux-perf-users, linux-kernel On 9/25/2024 7:36 PM, Thomas Falcon wrote: > > > 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: Kan Liang <kan.liang@linux.intel.com> This change is fine for me. But for later avoid same issues, I would like to improve a bit: static const char * const mem_lvlnum[] = { [PERF_MEM_LVLNUM_L1] = "L1", [PERF_MEM_LVLNUM_L2] = "L2", [PERF_MEM_LVLNUM_L3] = "L3", [PERF_MEM_LVLNUM_L4] = "L4", [PERF_MEM_LVLNUM_L2_MHB] = "L2 MHB", [PERF_MEM_LVLNUM_MSC] = "Memory-side Cache", ... }; Then in the function perf_mem__lvl_scnprintf() : if (mem_lvlnum[lvl]) l += scnprintf(out + l, sz - l, mem_lvlnum[lvl]); else l += scnprintf(out + l, sz - l, "Unknown level %d", lvl); This can help us easily to catch unexpected memory level. Thanks, Leo > --- > tools/perf/util/mem-events.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/tools/perf/util/mem-events.c b/tools/perf/util/mem-events.c > index 051feb93ed8d..c630aca5bd93 100644 > --- a/tools/perf/util/mem-events.c > +++ b/tools/perf/util/mem-events.c > @@ -366,6 +366,8 @@ static const char * const mem_lvl[] = { > }; > > static const char * const mem_lvlnum[] = { > + [PERF_MEM_LVLNUM_L2_MHB] = "L2 MHB", > + [PERF_MEM_LVLNUM_MSC] = "Memory-side Cache", > [PERF_MEM_LVLNUM_UNC] = "Uncached", > [PERF_MEM_LVLNUM_CXL] = "CXL", > [PERF_MEM_LVLNUM_IO] = "I/O", > -- > 2.46.0 > > ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] perf mem: Fix printing PERF_MEM_LVLNUM_{L2_MHB|MSC} 2024-09-25 20:16 ` Leo Yan @ 2024-09-25 21:40 ` Falcon, Thomas 0 siblings, 0 replies; 3+ messages in thread From: Falcon, Thomas @ 2024-09-25 21:40 UTC (permalink / raw) To: alexander.shishkin@linux.intel.com, leo.yan@arm.com, peterz@infradead.org, acme@kernel.org, mingo@redhat.com, mark.rutland@arm.com, Hunter, Adrian, namhyung@kernel.org, jolsa@kernel.org, kan.liang@linux.intel.com, irogers@google.com Cc: linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org On Wed, 2024-09-25 at 21:16 +0100, Leo Yan wrote: > On 9/25/2024 7:36 PM, Thomas Falcon wrote: > > > > > > 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: Kan Liang <kan.liang@linux.intel.com> > > This change is fine for me. But for later avoid same issues, I would > like to > improve a bit: > > static const char * const mem_lvlnum[] = { > [PERF_MEM_LVLNUM_L1] = "L1", > [PERF_MEM_LVLNUM_L2] = "L2", > [PERF_MEM_LVLNUM_L3] = "L3", > [PERF_MEM_LVLNUM_L4] = "L4", > [PERF_MEM_LVLNUM_L2_MHB] = "L2 MHB", > [PERF_MEM_LVLNUM_MSC] = "Memory-side Cache", > ... > }; > > Then in the function perf_mem__lvl_scnprintf() : > > if (mem_lvlnum[lvl]) > l += scnprintf(out + l, sz - l, mem_lvlnum[lvl]); > else > l += scnprintf(out + l, sz - l, "Unknown level %d", lvl); > > This can help us easily to catch unexpected memory level. > Thank you! I will send an updated v2 with your suggested changes. Tom > Thanks, > Leo > > > --- > > tools/perf/util/mem-events.c | 2 ++ > > 1 file changed, 2 insertions(+) > > > > diff --git a/tools/perf/util/mem-events.c b/tools/perf/util/mem- > > events.c > > index 051feb93ed8d..c630aca5bd93 100644 > > --- a/tools/perf/util/mem-events.c > > +++ b/tools/perf/util/mem-events.c > > @@ -366,6 +366,8 @@ static const char * const mem_lvl[] = { > > }; > > > > static const char * const mem_lvlnum[] = { > > + [PERF_MEM_LVLNUM_L2_MHB] = "L2 MHB", > > + [PERF_MEM_LVLNUM_MSC] = "Memory-side Cache", > > [PERF_MEM_LVLNUM_UNC] = "Uncached", > > [PERF_MEM_LVLNUM_CXL] = "CXL", > > [PERF_MEM_LVLNUM_IO] = "I/O", > > -- > > 2.46.0 > > > > ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-09-25 21:40 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2024-09-25 18:36 [PATCH] perf mem: Fix printing PERF_MEM_LVLNUM_{L2_MHB|MSC} Thomas Falcon 2024-09-25 20:16 ` Leo Yan 2024-09-25 21:40 ` Falcon, Thomas
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).