tools/perf: Add loongarch cpuinfo and fix build warning
Subsystems (2)
v4 cover tools/perf: Add loongarch cpuinfo and fix build warning
v4:
* Modify commit message. [3/3]
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
PATCH v4 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
@@ -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
@@ -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
PATCH v4 2/3 perf/trace: Fix mmap_flags for archs use generic mman.h
In reply to Yanteng SiSilence 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
PATCH v4 3/3 perf/trace: Use "test -f" instead of "[-f FILE]"
In reply to Yanteng Si"[" 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 "[]".
--- 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
@@ -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
@@ -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
Arnaldo Carvalho de Melo
maintainerEm Tue, Aug 29, 2023 at 09:21:10PM +0800, Yanteng Si escreveu:
Quoted 2 lines
v4:
* Modify commit message. [3/3]
Thanks, I updated the commit log messages adding the Acked-by and the new description for 3/3 since I hadn't published this in perf-tools-next yet.
- Arnaldo
Quoted 27 lines
v3:
* Usingstrcasest()correctly.
* Picking Huacai's Acked tag, I seem to have lost it in the last version.v2:
* Switch tostrcasestr().
* Use "test -f" instead of "[-f FILE]".v1:
* LoongArch and riscv don't havetools/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: Fixmmap_flagsfor archs use genericmman.hperf/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
Signature · 1 line
- Arnaldo