mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Leo Yan <leo.yan@arm.com>
To: Thomas Falcon <thomas.falcon@intel.com>,
	peterz@infradead.org, mingo@redhat.com, acme@kernel.org,
	namhyung@kernel.org, mark.rutland@arm.com,
	alexander.shishkin@linux.intel.com, jolsa@kernel.org,
	irogers@google.com, adrian.hunter@intel.com,
	kan.liang@linux.intel.com
Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] perf mem: Fix printing PERF_MEM_LVLNUM_{L2_MHB|MSC}
Date: Wed, 25 Sep 2024 21:16:50 +0100	[thread overview]
Message-ID: <6d409278-988b-4c09-adfb-5e075c9b326e@arm.com> (raw)
In-Reply-To: <20240925183633.49653-1-thomas.falcon@intel.com>

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
> 
> 

  reply	other threads:[~2024-09-25 20:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-25 18:36 Thomas Falcon
2024-09-25 20:16 ` Leo Yan [this message]
2024-09-25 21:40   ` Falcon, Thomas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6d409278-988b-4c09-adfb-5e075c9b326e@arm.com \
    --to=leo.yan@arm.com \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=thomas.falcon@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®