Commit 493c3031 authored by Wang Nan's avatar Wang Nan Committed by Arnaldo Carvalho de Melo

perf tools: Make CPUINFO_PROC an array to support different kernel versions

After kernel 3.7 (commit b4b8f770),
/proc/cpuinfo replaces 'Processor' to 'model name'.

This patch makes CPUINFO_PROC to an array and provides two choices for
ARM, makes it compatible for different kernel version.

v1 -> v2: minor changes as suggested by Namhyung Kim:

 - Doesn't pass @h and @evlist to __write_cpudesc;
 - Coding style fix.

v2 -> v3:
  - Rebase:
    git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git perf/core
Signed-off-by: default avatarWang Nan <wangnan0@huawei.com>
Acked-by: default avatarNamhyung Kim <namhyung@kernel.org>
Cc: Li Zefan <lizefan@huawei.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/1414115126-7479-1-git-send-email-wangnan0@huawei.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 380b5143
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#define wmb() asm volatile("lock; addl $0,0(%%esp)" ::: "memory") #define wmb() asm volatile("lock; addl $0,0(%%esp)" ::: "memory")
#define rmb() asm volatile("lock; addl $0,0(%%esp)" ::: "memory") #define rmb() asm volatile("lock; addl $0,0(%%esp)" ::: "memory")
#define cpu_relax() asm volatile("rep; nop" ::: "memory"); #define cpu_relax() asm volatile("rep; nop" ::: "memory");
#define CPUINFO_PROC "model name" #define CPUINFO_PROC {"model name"}
#ifndef __NR_perf_event_open #ifndef __NR_perf_event_open
# define __NR_perf_event_open 336 # define __NR_perf_event_open 336
#endif #endif
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#define wmb() asm volatile("sfence" ::: "memory") #define wmb() asm volatile("sfence" ::: "memory")
#define rmb() asm volatile("lfence" ::: "memory") #define rmb() asm volatile("lfence" ::: "memory")
#define cpu_relax() asm volatile("rep; nop" ::: "memory"); #define cpu_relax() asm volatile("rep; nop" ::: "memory");
#define CPUINFO_PROC "model name" #define CPUINFO_PROC {"model name"}
#ifndef __NR_perf_event_open #ifndef __NR_perf_event_open
# define __NR_perf_event_open 298 # define __NR_perf_event_open 298
#endif #endif
...@@ -47,14 +47,14 @@ ...@@ -47,14 +47,14 @@
#define mb() asm volatile ("sync" ::: "memory") #define mb() asm volatile ("sync" ::: "memory")
#define wmb() asm volatile ("sync" ::: "memory") #define wmb() asm volatile ("sync" ::: "memory")
#define rmb() asm volatile ("sync" ::: "memory") #define rmb() asm volatile ("sync" ::: "memory")
#define CPUINFO_PROC "cpu" #define CPUINFO_PROC {"cpu"}
#endif #endif
#ifdef __s390__ #ifdef __s390__
#define mb() asm volatile("bcr 15,0" ::: "memory") #define mb() asm volatile("bcr 15,0" ::: "memory")
#define wmb() asm volatile("bcr 15,0" ::: "memory") #define wmb() asm volatile("bcr 15,0" ::: "memory")
#define rmb() asm volatile("bcr 15,0" ::: "memory") #define rmb() asm volatile("bcr 15,0" ::: "memory")
#define CPUINFO_PROC "vendor_id" #define CPUINFO_PROC {"vendor_id"}
#endif #endif
#ifdef __sh__ #ifdef __sh__
...@@ -67,14 +67,14 @@ ...@@ -67,14 +67,14 @@
# define wmb() asm volatile("" ::: "memory") # define wmb() asm volatile("" ::: "memory")
# define rmb() asm volatile("" ::: "memory") # define rmb() asm volatile("" ::: "memory")
#endif #endif
#define CPUINFO_PROC "cpu type" #define CPUINFO_PROC {"cpu type"}
#endif #endif
#ifdef __hppa__ #ifdef __hppa__
#define mb() asm volatile("" ::: "memory") #define mb() asm volatile("" ::: "memory")
#define wmb() asm volatile("" ::: "memory") #define wmb() asm volatile("" ::: "memory")
#define rmb() asm volatile("" ::: "memory") #define rmb() asm volatile("" ::: "memory")
#define CPUINFO_PROC "cpu" #define CPUINFO_PROC {"cpu"}
#endif #endif
#ifdef __sparc__ #ifdef __sparc__
...@@ -87,14 +87,14 @@ ...@@ -87,14 +87,14 @@
#endif #endif
#define wmb() asm volatile("":::"memory") #define wmb() asm volatile("":::"memory")
#define rmb() asm volatile("":::"memory") #define rmb() asm volatile("":::"memory")
#define CPUINFO_PROC "cpu" #define CPUINFO_PROC {"cpu"}
#endif #endif
#ifdef __alpha__ #ifdef __alpha__
#define mb() asm volatile("mb" ::: "memory") #define mb() asm volatile("mb" ::: "memory")
#define wmb() asm volatile("wmb" ::: "memory") #define wmb() asm volatile("wmb" ::: "memory")
#define rmb() asm volatile("mb" ::: "memory") #define rmb() asm volatile("mb" ::: "memory")
#define CPUINFO_PROC "cpu model" #define CPUINFO_PROC {"cpu model"}
#endif #endif
#ifdef __ia64__ #ifdef __ia64__
...@@ -102,7 +102,7 @@ ...@@ -102,7 +102,7 @@
#define wmb() asm volatile ("mf" ::: "memory") #define wmb() asm volatile ("mf" ::: "memory")
#define rmb() asm volatile ("mf" ::: "memory") #define rmb() asm volatile ("mf" ::: "memory")
#define cpu_relax() asm volatile ("hint @pause" ::: "memory") #define cpu_relax() asm volatile ("hint @pause" ::: "memory")
#define CPUINFO_PROC "model name" #define CPUINFO_PROC {"model name"}
#endif #endif
#ifdef __arm__ #ifdef __arm__
...@@ -113,7 +113,7 @@ ...@@ -113,7 +113,7 @@
#define mb() ((void(*)(void))0xffff0fa0)() #define mb() ((void(*)(void))0xffff0fa0)()
#define wmb() ((void(*)(void))0xffff0fa0)() #define wmb() ((void(*)(void))0xffff0fa0)()
#define rmb() ((void(*)(void))0xffff0fa0)() #define rmb() ((void(*)(void))0xffff0fa0)()
#define CPUINFO_PROC "Processor" #define CPUINFO_PROC {"model name", "Processor"}
#endif #endif
#ifdef __aarch64__ #ifdef __aarch64__
...@@ -133,28 +133,28 @@ ...@@ -133,28 +133,28 @@
: "memory") : "memory")
#define wmb() mb() #define wmb() mb()
#define rmb() mb() #define rmb() mb()
#define CPUINFO_PROC "cpu model" #define CPUINFO_PROC {"cpu model"}
#endif #endif
#ifdef __arc__ #ifdef __arc__
#define mb() asm volatile("" ::: "memory") #define mb() asm volatile("" ::: "memory")
#define wmb() asm volatile("" ::: "memory") #define wmb() asm volatile("" ::: "memory")
#define rmb() asm volatile("" ::: "memory") #define rmb() asm volatile("" ::: "memory")
#define CPUINFO_PROC "Processor" #define CPUINFO_PROC {"Processor"}
#endif #endif
#ifdef __metag__ #ifdef __metag__
#define mb() asm volatile("" ::: "memory") #define mb() asm volatile("" ::: "memory")
#define wmb() asm volatile("" ::: "memory") #define wmb() asm volatile("" ::: "memory")
#define rmb() asm volatile("" ::: "memory") #define rmb() asm volatile("" ::: "memory")
#define CPUINFO_PROC "CPU" #define CPUINFO_PROC {"CPU"}
#endif #endif
#ifdef __xtensa__ #ifdef __xtensa__
#define mb() asm volatile("memw" ::: "memory") #define mb() asm volatile("memw" ::: "memory")
#define wmb() asm volatile("memw" ::: "memory") #define wmb() asm volatile("memw" ::: "memory")
#define rmb() asm volatile("" ::: "memory") #define rmb() asm volatile("" ::: "memory")
#define CPUINFO_PROC "core ID" #define CPUINFO_PROC {"core ID"}
#endif #endif
#ifdef __tile__ #ifdef __tile__
...@@ -162,7 +162,7 @@ ...@@ -162,7 +162,7 @@
#define wmb() asm volatile ("mf" ::: "memory") #define wmb() asm volatile ("mf" ::: "memory")
#define rmb() asm volatile ("mf" ::: "memory") #define rmb() asm volatile ("mf" ::: "memory")
#define cpu_relax() asm volatile ("mfspr zero, PASS" ::: "memory") #define cpu_relax() asm volatile ("mfspr zero, PASS" ::: "memory")
#define CPUINFO_PROC "model name" #define CPUINFO_PROC {"model name"}
#endif #endif
#define barrier() asm volatile ("" ::: "memory") #define barrier() asm volatile ("" ::: "memory")
......
...@@ -579,16 +579,12 @@ static int write_version(int fd, struct perf_header *h __maybe_unused, ...@@ -579,16 +579,12 @@ static int write_version(int fd, struct perf_header *h __maybe_unused,
return do_write_string(fd, perf_version_string); return do_write_string(fd, perf_version_string);
} }
static int write_cpudesc(int fd, struct perf_header *h __maybe_unused, static int __write_cpudesc(int fd, const char *cpuinfo_proc)
struct perf_evlist *evlist __maybe_unused)
{ {
#ifndef CPUINFO_PROC
#define CPUINFO_PROC NULL
#endif
FILE *file; FILE *file;
char *buf = NULL; char *buf = NULL;
char *s, *p; char *s, *p;
const char *search = CPUINFO_PROC; const char *search = cpuinfo_proc;
size_t len = 0; size_t len = 0;
int ret = -1; int ret = -1;
...@@ -638,6 +634,25 @@ static int write_cpudesc(int fd, struct perf_header *h __maybe_unused, ...@@ -638,6 +634,25 @@ static int write_cpudesc(int fd, struct perf_header *h __maybe_unused,
return ret; return ret;
} }
static int write_cpudesc(int fd, struct perf_header *h __maybe_unused,
struct perf_evlist *evlist __maybe_unused)
{
#ifndef CPUINFO_PROC
#define CPUINFO_PROC {"model name", }
#endif
const char *cpuinfo_procs[] = CPUINFO_PROC;
unsigned int i;
for (i = 0; i < ARRAY_SIZE(cpuinfo_procs); i++) {
int ret;
ret = __write_cpudesc(fd, cpuinfo_procs[i]);
if (ret >= 0)
return ret;
}
return -1;
}
static int write_nrcpus(int fd, struct perf_header *h __maybe_unused, static int write_nrcpus(int fd, struct perf_header *h __maybe_unused,
struct perf_evlist *evlist __maybe_unused) struct perf_evlist *evlist __maybe_unused)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment