From: Yunseong Kim <yskelg@gmail.com>
To: Namhyung Kim <namhyung@kernel.org>
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: Thu, 30 May 2024 20:43:32 +0900 [thread overview]
Message-ID: <53c7cbf0-ebf9-455b-bcec-d61830c7999b@gmail.com> (raw)
In-Reply-To: <CAM9d7cjhwO99e0GLKf54V+1g7cdppL3hwjpgB3cdid7YzytkMA@mail.gmail.com>
On 5/29/24 3:56 오전, Namhyung Kim wrote:
> 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
Thank you for your code review Namhyung.
I'll try to find a more useful improvement and patch it next time!
Warm Regards,
Yunseong Kim
>>
>> 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
>>
prev parent reply other threads:[~2024-05-30 11:43 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
2024-05-30 11:43 ` Yunseong Kim [this message]
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=53c7cbf0-ebf9-455b-bcec-d61830c7999b@gmail.com \
--to=yskelg@gmail.com \
--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=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=shjy180909@gmail.com \
--cc=skhan@linuxfoundation.org \
/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).