Skip to contentSkip to conversation

tools/perf: Add loongarch cpuinfo and fix build warning

PATCH Superseded Yanteng Si 2 participants 6 messages Aug 26, 2023 – Aug 28, 2023

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Yanteng Si

author
#0 lore raw

v3 cover tools/perf: Add loongarch cpuinfo and fix build warning

v3:
* Using strcasest() correctly.
* Picking Huacai's Acked tag, I seem to have lost it in the last version.

v2:
* Switch to strcasestr().
* Use "test -f" instead of "[-f FILE]".

v1:
* 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 (3):
perf/tools: Allow to use cpuinfo on LoongArch perf/trace: Fix mmap_flags for archs use generic mman.h perf/trace: Use "test -f" instead of "[-f FILE]"

 tools/perf/trace/beauty/mmap_flags.sh | 7 +++++--
 tools/perf/trace/beauty/mmap_prot.sh  | 5 +++--
 tools/perf/util/header.c              | 2 ++
 tools/perf/util/svghelper.c           | 2 +-
 4 files changed, 11 insertions(+), 5 deletions(-)
Signature · 1 line
2.31.4
author
#1 lore raw

PATCH v3 1/3 perf/tools: Allow to use cpuinfo on LoongArch

Define 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 | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)
tools/perf/util/header.c +2 -0
index 52fbf526fe74..c6e19192bd28 100644
@@ -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 +1 -1
index 5c62d3118c41..2e141126b0d6 100644
@@ -331,7 +331,7 @@ 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;
 			}
Signature · 1 line
2.31.4
author
#2 lore raw

PATCH v3 2/3 perf/trace: Fix mmap_flags for archs use generic mman.h

In reply to Yanteng Si

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
index 3022597c8c17..d035b29fc5ec 100755
@@ -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
author
#3 lore raw

PATCH v3 3/3 perf/trace: Use "test -f" instead of "[-f FILE]"

In reply to Yanteng Si

It will be simpler without that extra subshell, so let's use "test -f".

---
 tools/perf/trace/beauty/mmap_flags.sh | 9 ++++++---
 tools/perf/trace/beauty/mmap_prot.sh  | 5 +++--
 2 files changed, 9 insertions(+), 5 deletions(-)
tools/perf/trace/beauty/mmap_flags.sh +6 -3
index d035b29fc5ec..6ecdb3c5a99e 100755
@@ -19,7 +19,8 @@ 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:]]*.*'
-([ -f ${arch_mman} ] && grep -E -q $regex ${arch_mman}) && \
+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"	| \
 	xargs printf "\t[ilog2(%s) + 1] = \"%s\",\n#ifndef MAP_%s\n#define MAP_%s %s\n#endif\n")
@@ -28,12 +29,14 @@ grep -E -q $regex ${linux_mman} && \
 	grep -E -vw 'MAP_(UNINITIALIZED|TYPE|SHARED_VALIDATE)' | \
 	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")
-([ ! -f ${arch_mman} ] || grep -E -q '#[[:space:]]*include[[:space:]]+.*uapi/asm-generic/mman.*' ${arch_mman}) &&
+( ! test -f ${arch_mman} || \
+grep -E -q '#[[:space:]]*include[[:space:]]+.*uapi/asm-generic/mman.*' ${arch_mman}) &&
 (grep -E $regex ${header_dir}/mman-common.h | \
 	grep -E -vw 'MAP_(UNINITIALIZED|TYPE|SHARED_VALIDATE)' | \
 	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")
-([ ! -f ${arch_mman} ] || grep -E -q '#[[:space:]]*include[[:space:]]+.*uapi/asm-generic/mman.h>.*' ${arch_mman}) &&
+( ! test -f ${arch_mman} || \
+grep -E -q '#[[:space:]]*include[[:space:]]+.*uapi/asm-generic/mman.h>.*' ${arch_mman}) &&
 (grep -E $regex ${header_dir}/mman.h | \
 	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")
tools/perf/trace/beauty/mmap_prot.sh +3 -2
index 49e8c865214b..4436fcd6e861 100755
@@ -17,12 +17,13 @@ prefix="PROT"
 
 printf "static const char *mmap_prot[] = {\n"
 regex=`printf '^[[:space:]]*#[[:space:]]*define[[:space:]]+%s_([[:alnum:]_]+)[[:space:]]+(0x[[:xdigit:]]+)[[:space:]]*.*' ${prefix}`
-([ ! -f ${arch_mman} ] || grep -E -q '#[[:space:]]*include[[:space:]]+.*uapi/asm-generic/mman.*' ${arch_mman}) &&
+( ! test -f ${arch_mman} \
+|| grep -E -q '#[[:space:]]*include[[:space:]]+.*uapi/asm-generic/mman.*' ${arch_mman}) &&
 (grep -E $regex ${common_mman} | \
 	grep -E -vw PROT_NONE | \
 	sed -r "s/$regex/\2 \1 \1 \1 \2/g"	| \
 	xargs printf "\t[ilog2(%s) + 1] = \"%s\",\n#ifndef ${prefix}_%s\n#define ${prefix}_%s %s\n#endif\n")
-[ -f ${arch_mman} ] && grep -E -q $regex ${arch_mman} &&
+test -f ${arch_mman} && grep -E -q $regex ${arch_mman} &&
 (grep -E $regex ${arch_mman} | \
 	grep -E -vw PROT_NONE | \
 	sed -r "s/$regex/\2 \1 \1 \1 \2/g"	| \
Signature · 1 line
2.31.4
#4 lore raw

Re: [PATCH v3 3/3] perf/trace: Use "test -f" instead of "[-f FILE]"

Quoted 2 lines · Yanteng Si

It will be simpler without that extra subshell, so let's use "test -f".

Sorry for duplicated reply (I replied to v2 minutes ago), but I cannot understand this sentence. [ ... ] has nothing to do with subshell, it's just a syntax variant of "test".

Quoted 76 lines

---
 tools/perf/trace/beauty/mmap_flags.sh | 9 ++++++--- tools/perf/trace/beauty/mmap_prot.sh  | 5 +++--

 2 files changed, 9 insertions(+), 5 deletions(-)
tools/perf/trace/beauty/mmap_flags.sh +0 -0
index d035b29fc5ec..6ecdb3c5a99e 100755
@@ -19,7 +19,8 @@ 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:]]*.*'

tools/perf/trace/beauty/mmap_flags.sh +2 -1
-([ -f ${arch_mman} ] && grep -E -q $regex ${arch_mman}) && \
+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"      | \
        xargs printf "\t[ilog2(%s) + 1] = \"%s\",\n#ifndef MAP_%s\n#define MAP_%s %s\n#endif\n")

tools/perf/trace/beauty/mmap_flags.sh +0 -0
@@ -28,12 +29,14 @@ grep -E -q $regex ${linux_mman} && \
         grep -E -vw 'MAP_(UNINITIALIZED|TYPE|SHARED_VALIDATE)' | \
         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")
-([ ! -f ${arch_mman} ] || grep -E -q '#[[:space:]]*include[[:space:]]+.*uapi/asm-generic/mman.*' ${arch_mman}) &&

tools/perf/trace/beauty/mmap_flags.sh +2 -0
+( ! test -f ${arch_mman} || \
+grep -E -q '#[[:space:]]*include[[:space:]]+.*uapi/asm-

generic/mman.*' ${arch_mman}) &&
 (grep -E $regex ${header_dir}/mman-common.h | \
        grep -E -vw 'MAP_(UNINITIALIZED|TYPE|SHARED_VALIDATE)' | \
        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")
-([ ! -f ${arch_mman} ] || grep -E -q '#[[:space:]]*include[[:space:]]+.*uapi/asm-generic/mman.h>.*' ${arch_mman}) &&

tools/perf/trace/beauty/mmap_flags.sh +2 -0
+( ! test -f ${arch_mman} || \
+grep -E -q '#[[:space:]]*include[[:space:]]+.*uapi/asm-

generic/mman.h>.*' ${arch_mman}) &&
 (grep -E $regex ${header_dir}/mman.h | \
        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")

tools/perf/trace/beauty/mmap_prot.sh +0 -0
index 49e8c865214b..4436fcd6e861 100755
@@ -17,12 +17,13 @@ prefix="PROT"


 printf "static const char *mmap_prot[] = {\n" regex=printf '^[[:space:]]*#[[:space:]]*define[[:space:]]+%s_([[:alnum:]_]+)[[:spac e:]]+(0x[[:xdigit:]]+)[[:space:]]*.*' ${prefix}
-([ ! -f ${arch_mman} ] || grep -E -q '#[[:space:]]*include[[:space:]]+.*uapi/asm-generic/mman.*' ${arch_mman}) &&
+( ! test -f ${arch_mman} \
+|| grep -E -q '#[[:space:]]*include[[:space:]]+.*uapi/asm- generic/mman.*' ${arch_mman}) &&
 (grep -E $regex ${common_mman} | \
        grep -E -vw PROT_NONE | \
        sed -r "s/$regex/\2 \1 \1 \1 \2/g"      | \
        xargs printf "\t[ilog2(%s) + 1] = \"%s\",\n#ifndef ${prefix}_%s\n#define ${prefix}_%s %s\n#endif\n")
-[ -f ${arch_mman} ] && grep -E -q $regex ${arch_mman} && +test -f ${arch_mman} && grep -E -q $regex ${arch_mman} && (grep -E $regex ${arch_mman} | \
        grep -E -vw PROT_NONE | \
        sed -r "s/$regex/\2 \1 \1 \1 \2/g"      | \

Signature · 2 lines
Xi Ruoyao <[email protected]>
School of Aerospace Science and Technology, Xidian University
author
#5 lore raw

Re: [PATCH v3 3/3] perf/trace: Use "test -f" instead of "[-f FILE]"

Quoted 7 lines · Xi Ruoyao
Quoted 2 lines · Yanteng Si

It will be simpler without that extra subshell, so let's use "test -f".

Sorry for duplicated reply (I replied to v2 minutes ago), but I cannot understand this sentence. [ ... ] has nothing to do with subshell, it's just a syntax variant of "test".

Sorry, I mean is that "[" is part of the shell builtin test (and a synonym for it),

 not a link to the external command /usr/bin/test.

Using the "test" is simpler because it avoids a lot of "[]".

I'm going to write that in v4, agree?

Thanks,

Yanteng

Quoted 76 lines
Quoted 76 lines
---
  tools/perf/trace/beauty/mmap_flags.sh | 9 ++++++---
  tools/perf/trace/beauty/mmap_prot.sh  | 5 +++--
  2 files changed, 9 insertions(+), 5 deletions(-)
tools/perf/trace/beauty/mmap_flags.sh +0 -0
index d035b29fc5ec..6ecdb3c5a99e 100755
@@ -19,7 +19,8 @@ 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:]]*.*'

tools/perf/trace/beauty/mmap_flags.sh +2 -1
-([ -f ${arch_mman} ] && grep -E -q $regex ${arch_mman}) && \
+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"      | \
         xargs printf "\t[ilog2(%s) + 1] = \"%s\",\n#ifndef

MAP_%s\n#define MAP_%s %s\n#endif\n")

tools/perf/trace/beauty/mmap_flags.sh +0 -1
@@ -28,12 +29,14 @@ grep -E -q $regex ${linux_mman} && \
         grep -E -vw 'MAP_(UNINITIALIZED|TYPE|SHARED_VALIDATE)' | \
         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")
-([ ! -f ${arch_mman} ] || grep -E -q

'#[[:space:]]*include[[:space:]]+.*uapi/asm-generic/mman.*' ${arch_mman}) &&

tools/perf/trace/beauty/mmap_flags.sh +2 -0
+( ! test -f ${arch_mman} || \
+grep -E -q '#[[:space:]]*include[[:space:]]+.*uapi/asm-

generic/mman.*' ${arch_mman}) &&
 (grep -E $regex ${header_dir}/mman-common.h | \
        grep -E -vw 'MAP_(UNINITIALIZED|TYPE|SHARED_VALIDATE)' | \
        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")
-([ ! -f ${arch_mman} ] || grep -E -q '#[[:space:]]*include[[:space:]]+.*uapi/asm-generic/mman.h>.*' ${arch_mman}) &&

tools/perf/trace/beauty/mmap_flags.sh +2 -0
+( ! test -f ${arch_mman} || \
+grep -E -q '#[[:space:]]*include[[:space:]]+.*uapi/asm-

generic/mman.h>.*' ${arch_mman}) &&
 (grep -E $regex ${header_dir}/mman.h | \
        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")

tools/perf/trace/beauty/mmap_prot.sh +0 -0
index 49e8c865214b..4436fcd6e861 100755
@@ -17,12 +17,13 @@ prefix="PROT"
 
  printf "static const char *mmap_prot[] = {\n"
  regex=`printf

'^[[:space:]]*#[[:space:]]*define[[:space:]]+%s_([[:alnum:]_]+)[[:spac e:]]+(0x[[:xdigit:]]+)[[:space:]]*.*' ${prefix}`
-([ ! -f ${arch_mman} ] || grep -E -q '#[[:space:]]*include[[:space:]]+.*uapi/asm-generic/mman.*' ${arch_mman}) &&
+( ! test -f ${arch_mman} \
+|| grep -E -q '#[[:space:]]*include[[:space:]]+.*uapi/asm- generic/mman.*' ${arch_mman}) &&
 (grep -E $regex ${common_mman} | \
        grep -E -vw PROT_NONE | \
        sed -r "s/$regex/\2 \1 \1 \1 \2/g"      | \
        xargs printf "\t[ilog2(%s) + 1] = \"%s\",\n#ifndef
${prefix}_%s\n#define ${prefix}_%s %s\n#endif\n")
-[ -f ${arch_mman} ] && grep -E -q $regex ${arch_mman} && +test -f ${arch_mman} && grep -E -q $regex ${arch_mman} &&
 (grep -E $regex ${arch_mman} | \
        grep -E -vw PROT_NONE | \
        sed -r "s/$regex/\2 \1 \1 \1 \2/g"      | \