tools/perf: Add loongarch cpuinfo and fix build warning
Subsystems (2)
cover tools/perf: Add loongarch cpuinfo and fix build warning
* LoongArch and riscv don't have tools/arch/xxxxx/include/uapi/asm/mman.h, let's modify the detection rules.
* Allow to use cpuinfo on loongarch.
Yanteng Si (2):
perf/trace: Fix mmap_flags for archs use generic mman.h perf/tools: Allow to use cpuinfo on loongarch
tools/perf/trace/beauty/mmap_flags.sh | 2 +- tools/perf/util/header.c | 2 ++ tools/perf/util/svghelper.c | 7 ++++++- 3 files changed, 9 insertions(+), 2 deletions(-)
Signature · 1 line
2.31.4
PATCH 1/2 perf/trace: Fix mmap_flags for archs use generic mman.h
Silence this warning:
grep: /root/linux-next/tools/arch/xxxxx/include/uapi/asm//mman.h:
No such file or directory
--- tools/perf/trace/beauty/mmap_flags.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/trace/beauty/mmap_flags.sh +1 -1
@@ -19,7 +19,7 @@ arch_mman=${arch_header_dir}/mman.h printf "static const char *mmap_flags[] = {\n" regex='^[[:space:]]*#[[:space:]]*define[[:space:]]+MAP_([[:alnum:]_]+)[[:space:]]+(0x[[:xdigit:]]+)[[:space:]]*.*' -grep -E -q $regex ${arch_mman} && \ +([ -f ${arch_mman} ] && grep -E -q $regex ${arch_mman}) && \ (grep -E $regex ${arch_mman} | \ sed -r "s/$regex/\2 \1 \1 \1 \2/g" | \ xargs printf "\t[ilog2(%s) + 1] = \"%s\",\n#ifndef MAP_%s\n#define MAP_%s %s\n#endif\n")
Signature · 1 line
2.31.4
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v1 1/2] perf/trace: Fix mmap_flags for archs use generic mman.h
Em Tue, Aug 22, 2023 at 05:32:06PM +0800, Yanteng Si escreveu:
Quoted 16 lines
Silence this warning:
grep:
/root/linux-next/tools/arch/xxxxx/include/uapi/asm//mman.h:
No such file or directorySigned-off-by Yanteng Si <[email protected]>--- tools/perf/trace/beauty/mmap_flags.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/perf/trace/beauty/mmap_flags.sh +0
-0
tools/perf/trace/beauty/mmap_flags.sh arch_mman=${arch_header_dir}/mman.h · line 25
Quoted 8 lines
tools/perf/trace/beauty/mmap_flags.sh +1
-1@@ -19,7 +19,7 @@ arch_mman=${arch_header_dir}/mman.h printf "static const char *mmap_flags[] = {\n" regex='^[[:space:]]*#[[:space:]]*define[[:space:]]+MAP_([[:alnum:]_]+)[[:space:]]+(0x[[:xdigit:]]+)[[:space:]]*.*' -grep -E -q $regex ${arch_mman} && \ +([ -f ${arch_mman} ] && grep -E -q $regex ${arch_mman}) && \ (grep -E $regex ${arch_mman} | \ sed -r "s/$regex/\2 \1 \1 \1 \2/g" | \ xargs printf "\t[ilog2(%s) + 1] = \"%s\",\n#ifndef MAP_%s\n#define MAP_%s %s\n#endif\n")
Humm, wouldn't this be simpler without that extra subshell? Like this:
tools/perf/trace/beauty/mmap_flags.sh +1 -0
@@ -19,6 +19,7 @@ arch_mman=${arch_header_dir}/mman.h printf "static const char *mmap_flags[] = {\n" regex='^[[:space:]]*#[[:space:]]*define[[:space:]]+MAP_([[:alnum:]_]+)[[:space:]]+(0x[[:xdigit:]]+)[[:space:]]*.*' +test -f ${arch_mman} && \ grep -E -q $regex ${arch_mman} && \ (grep -E $regex ${arch_mman} | \ sed -r "s/$regex/\2 \1 \1 \1 \2/g" | \
Re: [PATCH v1 1/2] perf/trace: Fix mmap_flags for archs use generic mman.h
Quoted 31 lines · Arnaldo Carvalho de Melo
Em Tue, Aug 22, 2023 at 05:32:06PM +0800, Yanteng Si escreveu:
Quoted 15 lines
Silence this warning:
grep:
/root/linux-next/tools/arch/xxxxx/include/uapi/asm//mman.h:
No such file or directorySigned-off-by Yanteng Si <[email protected]>--- tools/perf/trace/beauty/mmap_flags.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/perf/trace/beauty/mmap_flags.sh +0
-0tools/perf/trace/beauty/mmap_flags.sh arch_mman=${arch_header_dir}/mman.h · line 25
Quoted 8 lines
tools/perf/trace/beauty/mmap_flags.sh +1
-1@@ -19,7 +19,7 @@ arch_mman=${arch_header_dir}/mman.h printf "static const char *mmap_flags[] = {\n" regex='^[[:space:]]*#[[:space:]]*define[[:space:]]+MAP_([[:alnum:]_]+)[[:space:]]+(0x[[:xdigit:]]+)[[:space:]]*.*' -grep -E -q $regex ${arch_mman} && \ +([ -f ${arch_mman} ] && grep -E -q $regex ${arch_mman}) && \ (grep -E $regex ${arch_mman} | \ sed -r "s/$regex/\2 \1 \1 \1 \2/g" | \ xargs printf "\t[ilog2(%s) + 1] = \"%s\",\n#ifndef MAP_%s\n#define MAP_%s %s\n#endif\n")Humm, wouldn't this be simpler without that extra subshell? Like this:
tools/perf/trace/beauty/mmap_flags.sh +0
-0
tools/perf/trace/beauty/mmap_flags.sh arch_mman=${arch_header_dir}/mman.h · line 22
Quoted 4 lines
tools/perf/trace/beauty/mmap_flags.sh +1
-0@@ -19,6 +19,7 @@ arch_mman=${arch_header_dir}/mman.h printf "static const char *mmap_flags[] = {\n" regex='^[[:space:]]*#[[:space:]]*define[[:space:]]+MAP_([[:alnum:]_]+)[[:space:]]+(0x[[:xdigit:]]+)[[:space:]]*.*' +test -f ${arch_mman} && \
The following lines have already used the [ ! -f ${arch_mman}, so let's stay consistent?
Thanks,
Yanteng
Quoted 3 lines
tools/perf/trace/beauty/mmap_flags.sh +0
-0grep -E -q $regex ${arch_mman} && \ (grep -E $regex ${arch_mman} | \ sed -r "s/$regex/\2 \1 \1 \1 \2/g" | \
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v1 1/2] perf/trace: Fix mmap_flags for archs use generic mman.h
Em Wed, Aug 23, 2023 at 03:11:01PM +0800, Yanteng Si escreveu:
Quoted 26 lines · Arnaldo Carvalho de Melo
Quoted 24 lines
Em Tue, Aug 22, 2023 at 05:32:06PM +0800, Yanteng Si escreveu:
Quoted 14 lines
Silence this warning:
grep:
/root/linux-next/tools/arch/xxxxx/include/uapi/asm//mman.h:
No such file or directorySigned-off-by Yanteng Si <[email protected]>--- tools/perf/trace/beauty/mmap_flags.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/perf/trace/beauty/mmap_flags.sh +0
-0tools/perf/trace/beauty/mmap_flags.sh arch_mman=${arch_header_dir}/mman.h · line 24
Quoted 7 lines
tools/perf/trace/beauty/mmap_flags.sh +1
-1@@ -19,7 +19,7 @@ arch_mman=${arch_header_dir}/mman.h printf "static const char *mmap_flags[] = {\n" regex='^[[:space:]]*#[[:space:]]*define[[:space:]]+MAP_([[:alnum:]_]+)[[:space:]]+(0x[[:xdigit:]]+)[[:space:]]*.*' -grep -E -q $regex ${arch_mman} && \ +([ -f ${arch_mman} ] && grep -E -q $regex ${arch_mman}) && \ (grep -E $regex ${arch_mman} | \ sed -r "s/$regex/\2 \1 \1 \1 \2/g" | \ xargs printf "\t[ilog2(%s) + 1] = \"%s\",\n#ifndef MAP_%s\n#define MAP_%s %s\n#endif\n")Humm, wouldn't this be simpler without that extra subshell? Like this:
Quoted 11 lines
tools/perf/trace/beauty/mmap_flags.sh arch_mman=${arch_header_dir}/mman.h · line 21
Quoted 8 lines
tools/perf/trace/beauty/mmap_flags.sh +1
-0@@ -19,6 +19,7 @@ arch_mman=${arch_header_dir}/mman.h printf "static const char *mmap_flags[] = {\n" regex='^[[:space:]]*#[[:space:]]*define[[:space:]]+MAP_([[:alnum:]_]+)[[:space:]]+(0x[[:xdigit:]]+)[[:space:]]*.*' +test -f ${arch_mman} && \The following lines have already used the [ ! -f ${arch_mman}, so let's stay consistent?
Well, we can make it consistent by simplifying the other places where the long, equivalent test is being done, which I think is the way to go, agreed?
- Arnaldo
Quoted 9 lines
Thanks,
Yanteng
Quoted 3 lines
tools/perf/trace/beauty/mmap_flags.sh +0
-0grep -E -q $regex ${arch_mman} && \ (grep -E $regex ${arch_mman} | \ sed -r "s/$regex/\2 \1 \1 \1 \2/g" | \
Signature · 1 line
- Arnaldo
Re: [PATCH v1 1/2] perf/trace: Fix mmap_flags for archs use generic mman.h
Quoted 36 lines · Arnaldo Carvalho de Melo
Em Wed, Aug 23, 2023 at 03:11:01PM +0800, Yanteng Si escreveu:
Quoted 25 lines · Arnaldo Carvalho de Melo
Quoted 24 lines
Em Tue, Aug 22, 2023 at 05:32:06PM +0800, Yanteng Si escreveu:
Quoted 14 lines
Silence this warning:
grep:
/root/linux-next/tools/arch/xxxxx/include/uapi/asm//mman.h:
No such file or directorySigned-off-by Yanteng Si <[email protected]>--- tools/perf/trace/beauty/mmap_flags.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/perf/trace/beauty/mmap_flags.sh +0
-0tools/perf/trace/beauty/mmap_flags.sh arch_mman=${arch_header_dir}/mman.h · line 24
Quoted 7 lines
tools/perf/trace/beauty/mmap_flags.sh +1
-1@@ -19,7 +19,7 @@ arch_mman=${arch_header_dir}/mman.h printf "static const char *mmap_flags[] = {\n" regex='^[[:space:]]*#[[:space:]]*define[[:space:]]+MAP_([[:alnum:]_]+)[[:space:]]+(0x[[:xdigit:]]+)[[:space:]]*.*' -grep -E -q $regex ${arch_mman} && \ +([ -f ${arch_mman} ] && grep -E -q $regex ${arch_mman}) && \ (grep -E $regex ${arch_mman} | \ sed -r "s/$regex/\2 \1 \1 \1 \2/g" | \ xargs printf "\t[ilog2(%s) + 1] = \"%s\",\n#ifndef MAP_%s\n#define MAP_%s %s\n#endif\n")Humm, wouldn't this be simpler without that extra subshell? Like this:
Quoted 10 lines
tools/perf/trace/beauty/mmap_flags.sh arch_mman=${arch_header_dir}/mman.h · line 21
Quoted 8 lines
tools/perf/trace/beauty/mmap_flags.sh +1
-0@@ -19,6 +19,7 @@ arch_mman=${arch_header_dir}/mman.h printf "static const char *mmap_flags[] = {\n" regex='^[[:space:]]*#[[:space:]]*define[[:space:]]+MAP_([[:alnum:]_]+)[[:space:]]+(0x[[:xdigit:]]+)[[:space:]]*.*' +test -f ${arch_mman} && \The following lines have already used the [ ! -f ${arch_mman}, so let's stay consistent?
Quoted 3 lines
Well, we can make it consistent by simplifying the other places where the long, equivalent test is being done, which I think is the way to go, agreed?
I agree, but this is not suitable to be done in the fix patch, I will split it out and make a new patch.
Thanks
Yanteng
Quoted 10 lines
- Arnaldo
Quoted 7 lines
Thanks,
Yanteng
Quoted 3 lines
tools/perf/trace/beauty/mmap_flags.sh +0
-0grep -E -q $regex ${arch_mman} && \ (grep -E $regex ${arch_mman} | \ sed -r "s/$regex/\2 \1 \1 \1 \2/g" | \
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v1 1/2] perf/trace: Fix mmap_flags for archs use generic mman.h
Em Thu, Aug 24, 2023 at 10:22:57AM +0800, Yanteng Si escreveu:
Quoted 38 lines · Arnaldo Carvalho de Melo
Quoted 36 lines
Em Wed, Aug 23, 2023 at 03:11:01PM +0800, Yanteng Si escreveu:
Quoted 35 lines · Arnaldo Carvalho de Melo
Quoted 29 lines
Em Tue, Aug 22, 2023 at 05:32:06PM +0800, Yanteng Si escreveu:
Quoted 14 lines
Silence this warning:
grep:
/root/linux-next/tools/arch/xxxxx/include/uapi/asm//mman.h:
No such file or directorySigned-off-by Yanteng Si <[email protected]>--- tools/perf/trace/beauty/mmap_flags.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tools/perf/trace/beauty/mmap_flags.sh +0
-0tools/perf/trace/beauty/mmap_flags.sh arch_mman=${arch_header_dir}/mman.h · line 24
Quoted 7 lines
tools/perf/trace/beauty/mmap_flags.sh +1
-1@@ -19,7 +19,7 @@ arch_mman=${arch_header_dir}/mman.h printf "static const char *mmap_flags[] = {\n" regex='^[[:space:]]*#[[:space:]]*define[[:space:]]+MAP_([[:alnum:]_]+)[[:space:]]+(0x[[:xdigit:]]+)[[:space:]]*.*' -grep -E -q $regex ${arch_mman} && \ +([ -f ${arch_mman} ] && grep -E -q $regex ${arch_mman}) && \ (grep -E $regex ${arch_mman} | \ sed -r "s/$regex/\2 \1 \1 \1 \2/g" | \ xargs printf "\t[ilog2(%s) + 1] = \"%s\",\n#ifndef MAP_%s\n#define MAP_%s %s\n#endif\n")Humm, wouldn't this be simpler without that extra subshell? Like this:
tools/perf/trace/beauty/mmap_flags.sh +0
-0tools/perf/trace/beauty/mmap_flags.sh arch_mman=${arch_header_dir}/mman.h · line 21
Quoted 3 lines
tools/perf/trace/beauty/mmap_flags.sh +1
-0@@ -19,6 +19,7 @@ arch_mman=${arch_header_dir}/mman.h printf "static const char *mmap_flags[] = {\n" regex='^[[:space:]]*#[[:space:]]*define[[:space:]]+MAP_([[:alnum:]_]+)[[:space:]]+(0x[[:xdigit:]]+)[[:space:]]*.*' +test -f ${arch_mman} && \The following lines have already used the [ ! -f ${arch_mman}, so let's stay consistent?
Quoted 6 lines
Quoted 3 lines
Well, we can make it consistent by simplifying the other places where the long, equivalent test is being done, which I think is the way to go, agreed?
I agree, but this is not suitable to be done in the fix patch, I will split it out and make a new patch.
Sure, send the one with the fix, already using the simple form, then convert the rest to the simpler form.
Thanks,
- Arnaldo
PATCH 2/2 perf/tools: Allow to use cpuinfo on loongarch
In reply to Yanteng SiDefine these macros so that the CPU name can be displayed when running perf report and perf timechart.
--- tools/perf/util/header.c | 2 ++ tools/perf/util/svghelper.c | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-)
tools/perf/util/header.c +2 -0
@@ -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
tools/perf/util/svghelper.c +6 -1
@@ -322,6 +322,11 @@ void svg_waiting(int Yslot, int cpu, u64 start, u64 end, const char *backtrace)static char *cpu_model (void ) { +#if defined(__loongarch__) +#define CPU_TYPE "Model Name" +#else +#define CPU_TYPE "model name" +#endif static char cpu_m[255 ];char buf[256 ];FILE *file;
@@ -331,7 +336,7 @@ static char *cpu_model(void) file =fopen ("/proc/cpuinfo" ,"r" );if (file) {while (fgets (buf,255 , file)) { -if (strstr (buf,"model name" )) { +if (strstr (buf,CPU_TYPE )) {strlcpy (cpu_m, &buf[13 ],255 );break ; }
Signature · 1 line
2.31.4
Arnaldo Carvalho de Melo
maintainerRe: [PATCH v1 2/2] perf/tools: Allow to use cpuinfo on loongarch
Em Tue, Aug 22, 2023 at 05:32:07PM +0800, Yanteng Si escreveu:
Quoted 39 lines
Define these macros so that the CPU name can be displayed when running perf report and perf timechart.
Signed-off-by Yanteng Si <[email protected]>--- tools/perf/util/header.c | 2 ++ tools/perf/util/svghelper.c | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-)tools/perf/util/header.c +2
-0@@ -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 tools/perf/util/svghelper.c +5
-0@@ -322,6 +322,11 @@ void svg_waiting(int Yslot, int cpu, u64 start, u64 end, const char *backtrace)static char *cpu_model (void ) { +#if defined(__loongarch__) +#define CPU_TYPE "Model Name" +#else +#define CPU_TYPE "model name" +#endif static char cpu_m[255 ];char buf[256 ];FILE *file;
tools/perf/util/svghelper.c static char *cpu_model(void) · line 339
Quoted 5 lines
tools/perf/util/svghelper.c +1
-1@@ -331,7 +336,7 @@ static char *cpu_model(void) file =fopen ("/proc/cpuinfo" ,"r" );if (file) {while (fgets (buf,255 , file)) { -if (strstr (buf,"model name" )) { +if (strstr (buf,CPU_TYPE )) {
Isn't it better to just switch to strcasestr()?
- Arnaldo
Quoted 6 lines
tools/perf/util/svghelper.c +0
-0strlcpy (cpu_m, &buf[13 ],255 );break ; }Signature · 1 line
2.31.4
Signature · 1 line
- Arnaldo
Re: [PATCH v1 2/2] perf/tools: Allow to use cpuinfo on loongarch
Quoted 38 lines · Arnaldo Carvalho de Melo
Em Tue, Aug 22, 2023 at 05:32:07PM +0800, Yanteng Si escreveu:
Quoted 37 lines
Define these macros so that the CPU name can be displayed when running perf report and perf timechart.
Signed-off-by Yanteng Si <[email protected]>--- tools/perf/util/header.c | 2 ++ tools/perf/util/svghelper.c | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-)tools/perf/util/header.c +2
-0@@ -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 tools/perf/util/svghelper.c +5
-0@@ -322,6 +322,11 @@ void svg_waiting(int Yslot, int cpu, u64 start, u64 end, const char *backtrace)static char *cpu_model (void ) { +#if defined(__loongarch__) +#define CPU_TYPE "Model Name" +#else +#define CPU_TYPE "model name" +#endif static char cpu_m[255 ];char buf[256 ];
Quoted 8 lines
tools/perf/util/svghelper.c static char *cpu_model(void) · line 339
Quoted 7 lines
tools/perf/util/svghelper.c +1
-1FILE *file;@@ -331,7 +336,7 @@ static char *cpu_model(void) file =fopen ("/proc/cpuinfo" ,"r" );if (file) {while (fgets (buf,255 , file)) { -if (strstr (buf,"model name" )) { +if (strstr (buf,CPU_TYPE )) {Isn't it better to just switch to
strcasestr()?
OK!
Thanks,
Yanteng
Quoted 9 lines
- Arnaldo
Quoted 6 lines
tools/perf/util/svghelper.c +0
-0strlcpy (cpu_m, &buf[13 ],255 );break ; }Signature · 1 line
2.31.4
For this series:
Quoted 18 lines · Yanteng Si
* LoongArch and riscv don't have
tools/arch/xxxxx/include/uapi/asm/mman.h, let's modify the detection rules.
* Allow to use cpuinfo on loongarch.Yanteng Si (2):
perf/trace: Fixmmap_flagsfor archs use genericmman.hperf/tools: Allow to use cpuinfo on loongarchtools/perf/trace/beauty/mmap_flags.sh | 2 +- tools/perf/util/header.c | 2 ++ tools/perf/util/svghelper.c | 7 ++++++- 3 files changed, 9 insertions(+), 2 deletions(-)--
2.31.4