linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: yskelg@gmail.com
Cc: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	 Arnaldo Carvalho de Melo <acme@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	 Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>,  Ian Rogers <irogers@google.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	 "Liang, Kan" <kan.liang@linux.intel.com>,
	Gautham Shenoy <gautham.shenoy@amd.com>,
	 K Prateek Nayak <kprateek.nayak@amd.com>,
	skhan@linuxfoundation.org,  Austin Kim <austindh.kim@gmail.com>,
	shjy180909@gmail.com,  linux-perf-users@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	 linux-kernel-mentees@lists.linuxfoundation.org
Subject: Re: [PATCH] perf stat: allocation check when calculating cache instance ID
Date: Tue, 28 May 2024 11:56:32 -0700	[thread overview]
Message-ID: <CAM9d7cjhwO99e0GLKf54V+1g7cdppL3hwjpgB3cdid7YzytkMA@mail.gmail.com> (raw)
In-Reply-To: <20240527090300.17864-1-yskelg@gmail.com>

Hello Yunseong,

On Mon, May 27, 2024 at 2:06 AM <yskelg@gmail.com> wrote:
>
> From: Yunseong Kim <yskelg@gmail.com>
>
> Adds an allocation check for cpu_map before perf_cpu_map__min() accessing

I think perf_cpu_map__min() works well with NULL.

Thanks,
Namhyung

>
> Signed-off-by: Yunseong Kim <yskelg@gmail.com>
> ---
>  tools/perf/builtin-stat.c | 24 +++++++++++++-----------
>  1 file changed, 13 insertions(+), 11 deletions(-)
>
> diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
> index 35f79b48e8dc..1f238824abb2 100644
> --- a/tools/perf/builtin-stat.c
> +++ b/tools/perf/builtin-stat.c
> @@ -1291,20 +1291,22 @@ static struct option stat_options[] = {
>   */
>  static int cpu__get_cache_id_from_map(struct perf_cpu cpu, char *map)
>  {
> -       int id;
> +       int id = cpu.cpu;
>         struct perf_cpu_map *cpu_map = perf_cpu_map__new(map);
>
> -       /*
> -        * If the map contains no CPU, consider the current CPU to
> -        * be the first online CPU in the cache domain else use the
> -        * first online CPU of the cache domain as the ID.
> -        */
> -       id = perf_cpu_map__min(cpu_map).cpu;
> -       if (id == -1)
> -               id = cpu.cpu;
> +       if (cpu_map) {
> +               /*
> +                * If the map contains no CPU, consider the current CPU to
> +                * be the first online CPU in the cache domain else use the
> +                * first online CPU of the cache domain as the ID.
> +                */
> +               id = perf_cpu_map__min(cpu_map).cpu;
> +               if (id == -1)
> +                       id = cpu.cpu;
>
> -       /* Free the perf_cpu_map used to find the cache ID */
> -       perf_cpu_map__put(cpu_map);
> +               /* Free the perf_cpu_map used to find the cache ID */
> +               perf_cpu_map__put(cpu_map);
> +       }
>
>         return id;
>  }
> --
> 2.34.1
>

  reply	other threads:[~2024-05-28 18:56 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-27  9:03 [PATCH] perf stat: allocation check when calculating cache instance ID yskelg
2024-05-28 18:56 ` Namhyung Kim [this message]
2024-05-30 11:43   ` Yunseong Kim

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=CAM9d7cjhwO99e0GLKf54V+1g7cdppL3hwjpgB3cdid7YzytkMA@mail.gmail.com \
    --to=namhyung@kernel.org \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=austindh.kim@gmail.com \
    --cc=gautham.shenoy@amd.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@linux.intel.com \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-kernel-mentees@lists.linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=shjy180909@gmail.com \
    --cc=skhan@linuxfoundation.org \
    --cc=yskelg@gmail.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;
as well as URLs for NNTP newsgroup(s).