From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Yanteng Si <siyanteng@loongson.cn>
Cc: mingo@redhat.com, peterz@infradead.org, mark.rutland@arm.com,
alexander.shishkin@linux.intel.com, jolsa@kernel.org,
namhyung@kernel.org, irogers@google.com, adrian.hunter@intel.com,
chenhuacai@kernel.org, linux-perf-users@vger.kernel.org,
loongson-kernel@lists.loongnix.cn, loongarch@lists.linux.dev
Subject: Re: [PATCH v2 1/3] perf/tools: Allow to use cpuinfo on LoongArch
Date: Fri, 25 Aug 2023 10:45:16 -0300 [thread overview]
Message-ID: <ZOiwbNrwaodRfbSN@kernel.org> (raw)
In-Reply-To: <db968a186a10e4629fe10c26a1210f7126ad41ec.1692962043.git.siyanteng@loongson.cn>
Em Fri, Aug 25, 2023 at 07:28:02PM +0800, Yanteng Si escreveu:
> Define these macros so that the CPU name can be displayed
> when running perf report and perf timechart.
>
> Signed-off-by: Yanteng Si <siyanteng@loongson.cn>
> ---
> tools/perf/util/header.c | 2 ++
> tools/perf/util/svghelper.c | 5 ++++-
> 2 files changed, 6 insertions(+), 1 deletion(-)
>
> diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
> index 52fbf526fe74..c6e19192bd28 100644
> --- a/tools/perf/util/header.c
> +++ b/tools/perf/util/header.c
> @@ -456,6 +456,8 @@ static int write_cpudesc(struct feat_fd *ff,
> #define CPUINFO_PROC { "Processor", }
> #elif defined(__xtensa__)
> #define CPUINFO_PROC { "core ID", }
> +#elif defined(__loongarch__)
> +#define CPUINFO_PROC { "Model Name", }
> #else
> #define CPUINFO_PROC { "model name", }
> #endif
> diff --git a/tools/perf/util/svghelper.c b/tools/perf/util/svghelper.c
> index 5c62d3118c41..5744a3036b01 100644
> --- a/tools/perf/util/svghelper.c
> +++ b/tools/perf/util/svghelper.c
> @@ -331,7 +331,10 @@ static char *cpu_model(void)
> file = fopen("/proc/cpuinfo", "r");
> if (file) {
> while (fgets(buf, 255, file)) {
> - if (strstr(buf, "model name")) {
> + if (strcasestr(buf, "Model Name")) {
> + strlcpy(cpu_m, &buf[13], 255);
> + break;
> + } else if (strcasestr(buf, "model name")) {
> strlcpy(cpu_m, &buf[13], 255);
Hey, the point of strcasestr() is to do a case _insensitive_ substring
search, so all we need is:
> --- a/tools/perf/util/svghelper.c
> +++ b/tools/perf/util/svghelper.c
> @@ -331,7 +331,10 @@ static char *cpu_model(void)
> file = fopen("/proc/cpuinfo", "r");
> if (file) {
> while (fgets(buf, 255, file)) {
> - if (strstr(buf, "model name")) {
> + if (strcasestr(buf, "model Name")) {
> strlcpy(cpu_m, &buf[13], 255);
> break;
Right? I'm doing this change while applying your patches.
See:
[acme@five c]$ grep -m1 "model name" /proc/cpuinfo | ./strcasestr "Model NAME"
needle=Model NAME
haystack=model name : AMD Ryzen 9 5950X 16-Core Processor
found: model name : AMD Ryzen 9 5950X 16-Core Processor
found[13..]: AMD Ryzen 9 5950X 16-Core Processor
[acme@five c]$ grep -m1 "model name" /proc/cpuinfo | ./strcasestr "model name"
needle=model name
haystack=model name : AMD Ryzen 9 5950X 16-Core Processor
found: model name : AMD Ryzen 9 5950X 16-Core Processor
found[13..]: AMD Ryzen 9 5950X 16-Core Processor
[acme@five c]$ grep -m1 "model name" /proc/cpuinfo | ./strcasestr "Model Name"
needle=Model Name
haystack=model name : AMD Ryzen 9 5950X 16-Core Processor
found: model name : AMD Ryzen 9 5950X 16-Core Processor
found[13..]: AMD Ryzen 9 5950X 16-Core Processor
acme@five c]$ echo "Model Name : AMD Ryzen 9 5950X 16-Core Processor" | ./strcasestr "model name"
needle=model name
haystack=Model Name : AMD Ryzen 9 5950X 16-Core Processor
found: Model Name : AMD Ryzen 9 5950X 16-Core Processor
found[13..]: AMD Ryzen 9 5950X 16-Core Processor
[acme@five c]$ echo "MODEL NAME : AMD Ryzen 9 5950X 16-Core Processor" | ./strcasestr "model name"
needle=model name
haystack=MODEL NAME : AMD Ryzen 9 5950X 16-Core Processor
found: MODEL NAME : AMD Ryzen 9 5950X 16-Core Processor
found[13..]: AMD Ryzen 9 5950X 16-Core Processor
[acme@five c]$
[acme@five c]$ cat strcasestr.c
#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
char *needle = argv[1], haystack[128], *found;
printf("needle=%s\n", needle);
fgets(haystack, sizeof(haystack), stdin);
printf("haystack=%s\n", haystack);
found = strcasestr(haystack, needle);
printf("found: %s", found);
printf("found[13..]: %s", found + 13);
return 0;
}
[acme@five c]$
next prev parent reply other threads:[~2023-08-25 13:45 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-25 11:28 [PATCH v2 0/3] tools/perf: Add loongarch cpuinfo and fix build warning Yanteng Si
2023-08-25 11:28 ` [PATCH v2 1/3] perf/tools: Allow to use cpuinfo on LoongArch Yanteng Si
2023-08-25 13:45 ` Arnaldo Carvalho de Melo [this message]
2023-08-26 9:19 ` Yanteng Si
2023-08-25 11:28 ` [PATCH v2 2/3] perf/trace: Fix mmap_flags for archs use generic mman.h Yanteng Si
2023-08-25 11:28 ` [PATCH v2 3/3] perf/tools: Use "test -f" instead of "[-f FILE]" Yanteng Si
2023-08-26 9:42 ` Xi Ruoyao
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=ZOiwbNrwaodRfbSN@kernel.org \
--to=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=chenhuacai@kernel.org \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=loongarch@lists.linux.dev \
--cc=loongson-kernel@lists.loongnix.cn \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=siyanteng@loongson.cn \
/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