Re: [PATCH v2 RESEND] perf tools: makes CPUINFO_PROC to array for different kernel version

2014-10-23 Thread Wang Nan
Hi Arnaldo,

A have posted a v3 patch based on your git repository. Please refer to:

https://lkml.org/lkml/2014/10/23/711 .

Thanks.


On 2014/10/24 7:53, Arnaldo Carvalho de Melo wrote:
> Em Fri, Oct 24, 2014 at 08:26:13AM +0900, Namhyung Kim escreveu:
>> On Wed, 22 Oct 2014 15:40:14 +0800, Wang Nan wrote:
>>> After kernel 3.7 (commit b4b8f770eb10a1bccaf8aa0ec1956e2dd7ed1e0a),
>>> /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.
> 
>>> Signed-off-by: Wang Nan 
>  
>> Acked-by: Namhyung Kim 
> 
> So now this will work with older kernels and new ones? Cool, thanks for
> working on it, but:
> 
> [acme@ssdandy linux]$ patch -p1 < /wb/1.patch 
> patching file tools/perf/perf.h
> Hunk #1 FAILED at 6.
> Hunk #2 FAILED at 15.
> Hunk #3 FAILED at 25.
> Hunk #4 FAILED at 40.
> Hunk #5 FAILED at 74.
> Hunk #6 FAILED at 91.
> 6 out of 6 hunks FAILED -- saving rejects to file tools/perf/perf.h.rej
> patching file tools/perf/util/header.c
> Hunk #1 succeeded at 579 (offset 29 lines).
> Hunk #2 succeeded at 636 (offset 29 lines).
> [acme@ssdandy linux]$
> 
> [acme@ssdandy linux]$ git log --oneline tools/perf/perf.h | head -10
> 87c43ee perf tools: Export usage string and option table of perf record
> 72a128a perf tools: Move callchain config from record_opts to callchain_param
> 73a31b7 perf tools: Move ACCESS_ONCE from perf.h header
> 82baa0e perf tools: Move sys_perf_event_open function from perf.h
> 43599d1 perf tools: Move syscall and arch specific defines from perf.h
> 2c83bc0 perf tools: Move perf_call_graph_mode enum from perf.h
> 0776eb5 perf tools: Move sample data structures from perf.h
> 36446f4 perf tools: Remove PR_TASK_PERF_EVENTS_* from perf.h
> 273a0a7 perf tools: Remove asmlinkage define from perf.h
> 1b7ae1c perf tools: Remove min define from perf.h
> [acme@ssdandy linux]$
> 
> This is:
> 
> git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git perf/core
> 
> If you don't have time to fix this up, I'll try to find time tomorrow
> and do it.
> 
> - Arnaldo
> 




--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2 RESEND] perf tools: makes CPUINFO_PROC to array for different kernel version

2014-10-23 Thread Arnaldo Carvalho de Melo
Em Fri, Oct 24, 2014 at 08:26:13AM +0900, Namhyung Kim escreveu:
> On Wed, 22 Oct 2014 15:40:14 +0800, Wang Nan wrote:
> > After kernel 3.7 (commit b4b8f770eb10a1bccaf8aa0ec1956e2dd7ed1e0a),
> > /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.

> > Signed-off-by: Wang Nan 
 
> Acked-by: Namhyung Kim 

So now this will work with older kernels and new ones? Cool, thanks for
working on it, but:

[acme@ssdandy linux]$ patch -p1 < /wb/1.patch 
patching file tools/perf/perf.h
Hunk #1 FAILED at 6.
Hunk #2 FAILED at 15.
Hunk #3 FAILED at 25.
Hunk #4 FAILED at 40.
Hunk #5 FAILED at 74.
Hunk #6 FAILED at 91.
6 out of 6 hunks FAILED -- saving rejects to file tools/perf/perf.h.rej
patching file tools/perf/util/header.c
Hunk #1 succeeded at 579 (offset 29 lines).
Hunk #2 succeeded at 636 (offset 29 lines).
[acme@ssdandy linux]$

[acme@ssdandy linux]$ git log --oneline tools/perf/perf.h | head -10
87c43ee perf tools: Export usage string and option table of perf record
72a128a perf tools: Move callchain config from record_opts to callchain_param
73a31b7 perf tools: Move ACCESS_ONCE from perf.h header
82baa0e perf tools: Move sys_perf_event_open function from perf.h
43599d1 perf tools: Move syscall and arch specific defines from perf.h
2c83bc0 perf tools: Move perf_call_graph_mode enum from perf.h
0776eb5 perf tools: Move sample data structures from perf.h
36446f4 perf tools: Remove PR_TASK_PERF_EVENTS_* from perf.h
273a0a7 perf tools: Remove asmlinkage define from perf.h
1b7ae1c perf tools: Remove min define from perf.h
[acme@ssdandy linux]$

This is:

git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git perf/core

If you don't have time to fix this up, I'll try to find time tomorrow
and do it.

- Arnaldo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2 RESEND] perf tools: makes CPUINFO_PROC to array for different kernel version

2014-10-23 Thread Namhyung Kim
On Wed, 22 Oct 2014 15:40:14 +0800, Wang Nan wrote:
> After kernel 3.7 (commit b4b8f770eb10a1bccaf8aa0ec1956e2dd7ed1e0a),
> /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.
>
> Signed-off-by: Wang Nan 

Acked-by: Namhyung Kim 

Thanks,
Namhyung


> ---
>  tools/perf/perf.h| 24 
>  tools/perf/util/header.c | 27 +--
>  2 files changed, 33 insertions(+), 18 deletions(-)
>
> diff --git a/tools/perf/perf.h b/tools/perf/perf.h
> index 32bd102..1a23392 100644
> --- a/tools/perf/perf.h
> +++ b/tools/perf/perf.h
> @@ -6,7 +6,7 @@
>  #if defined(__i386__)
>  #define rmb()asm volatile("lock; addl $0,0(%%esp)" ::: 
> "memory")
>  #define cpu_relax()  asm volatile("rep; nop" ::: "memory");
> -#define CPUINFO_PROC "model name"
> +#define CPUINFO_PROC {"model name"}
>  #ifndef __NR_perf_event_open
>  # define __NR_perf_event_open 336
>  #endif
> @@ -15,7 +15,7 @@
>  #if defined(__x86_64__)
>  #define rmb()asm volatile("lfence" ::: "memory")
>  #define cpu_relax()  asm volatile("rep; nop" ::: "memory");
> -#define CPUINFO_PROC "model name"
> +#define CPUINFO_PROC {"model name"}
>  #ifndef __NR_perf_event_open
>  # define __NR_perf_event_open 298
>  #endif
> @@ -25,7 +25,7 @@
>  #include "../../arch/powerpc/include/uapi/asm/unistd.h"
>  #define rmb()asm volatile ("sync" ::: "memory")
>  #define cpu_relax()  asm volatile ("" ::: "memory");
> -#define CPUINFO_PROC "cpu"
> +#define CPUINFO_PROC {"cpu"}
>  #endif
>  
>  #ifdef __s390__
> @@ -40,31 +40,31 @@
>  # define rmb()   asm volatile("" ::: "memory")
>  #endif
>  #define cpu_relax()  asm volatile("" ::: "memory")
> -#define CPUINFO_PROC "cpu type"
> +#define CPUINFO_PROC {"cpu type"}
>  #endif
>  
>  #ifdef __hppa__
>  #define rmb()asm volatile("" ::: "memory")
>  #define cpu_relax()  asm volatile("" ::: "memory");
> -#define CPUINFO_PROC "cpu"
> +#define CPUINFO_PROC {"cpu"}
>  #endif
>  
>  #ifdef __sparc__
>  #define rmb()asm volatile("":::"memory")
>  #define cpu_relax()  asm volatile("":::"memory")
> -#define CPUINFO_PROC "cpu"
> +#define CPUINFO_PROC {"cpu"}
>  #endif
>  
>  #ifdef __alpha__
>  #define rmb()asm volatile("mb" ::: "memory")
>  #define cpu_relax()  asm volatile("" ::: "memory")
> -#define CPUINFO_PROC "cpu model"
> +#define CPUINFO_PROC {"cpu model"}
>  #endif
>  
>  #ifdef __ia64__
>  #define rmb()asm volatile ("mf" ::: "memory")
>  #define cpu_relax()  asm volatile ("hint @pause" ::: "memory")
> -#define CPUINFO_PROC "model name"
> +#define CPUINFO_PROC {"model name"}
>  #endif
>  
>  #ifdef __arm__
> @@ -74,7 +74,7 @@
>   */
>  #define rmb()((void(*)(void))0x0fa0)()
>  #define cpu_relax()  asm volatile("":::"memory")
> -#define CPUINFO_PROC "Processor"
> +#define CPUINFO_PROC {"model name", "Processor"}
>  #endif
>  
>  #ifdef __aarch64__
> @@ -91,19 +91,19 @@
>   : /* no input */\
>   : "memory")
>  #define cpu_relax()  asm volatile("" ::: "memory")
> -#define CPUINFO_PROC "cpu model"
> +#define CPUINFO_PROC {"cpu model"}
>  #endif
>  
>  #ifdef __arc__
>  #define rmb()asm volatile("" ::: "memory")
>  #define cpu_relax()  rmb()
> -#define CPUINFO_PROC "Processor"
> +#define CPUINFO_PROC {"Processor"}
>  #endif
>  
>  #ifdef __metag__
>  #define rmb()asm volatile("" ::: "memory")
>  #define cpu_relax()  asm volatile("" ::: "memory")
> -#define CPUINFO_PROC "CPU"
> +#define CPUINFO_PROC {"CPU"}
>  #endif
>  
>  #include 
> diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
> index b59350f..d48f571 100644
> --- a/tools/perf/util/header.c
> +++ b/tools/perf/util/header.c
> @@ -550,16 +550,12 @@ static int write_version(int fd, struct perf_header *h 
> __maybe_unused,
>   return do_write_string(fd, perf_version_string);
>  }
>  
> -static int write_cpudesc(int fd, struct perf_header *h __maybe_unused,
> -struct perf_evlist *evlist __maybe_unused)
> +static int __write_cpudesc(int fd, const char *cpuinfo_proc)
>  {
> -#ifndef CPUINFO_PROC
> -#define CPUINFO_PROC NULL
> -#endif
>   FILE *file;
>   char *buf = NULL;
>   char *s, *p;
> - const char *search = CPUINFO_PROC;
> + const char *search = cpuinfo_proc;
>   size_t len = 0;
>   int ret = -1;
>  
> @@ -611,6 +607,25 @@ done:
>   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", }
> 

Re: [PATCH v2 RESEND] perf tools: makes CPUINFO_PROC to array for different kernel version

2014-10-23 Thread Namhyung Kim
On Wed, 22 Oct 2014 15:40:14 +0800, Wang Nan wrote:
 After kernel 3.7 (commit b4b8f770eb10a1bccaf8aa0ec1956e2dd7ed1e0a),
 /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.

 Signed-off-by: Wang Nan wangn...@huawei.com

Acked-by: Namhyung Kim namhy...@kernel.org

Thanks,
Namhyung


 ---
  tools/perf/perf.h| 24 
  tools/perf/util/header.c | 27 +--
  2 files changed, 33 insertions(+), 18 deletions(-)

 diff --git a/tools/perf/perf.h b/tools/perf/perf.h
 index 32bd102..1a23392 100644
 --- a/tools/perf/perf.h
 +++ b/tools/perf/perf.h
 @@ -6,7 +6,7 @@
  #if defined(__i386__)
  #define rmb()asm volatile(lock; addl $0,0(%%esp) ::: 
 memory)
  #define cpu_relax()  asm volatile(rep; nop ::: memory);
 -#define CPUINFO_PROC model name
 +#define CPUINFO_PROC {model name}
  #ifndef __NR_perf_event_open
  # define __NR_perf_event_open 336
  #endif
 @@ -15,7 +15,7 @@
  #if defined(__x86_64__)
  #define rmb()asm volatile(lfence ::: memory)
  #define cpu_relax()  asm volatile(rep; nop ::: memory);
 -#define CPUINFO_PROC model name
 +#define CPUINFO_PROC {model name}
  #ifndef __NR_perf_event_open
  # define __NR_perf_event_open 298
  #endif
 @@ -25,7 +25,7 @@
  #include ../../arch/powerpc/include/uapi/asm/unistd.h
  #define rmb()asm volatile (sync ::: memory)
  #define cpu_relax()  asm volatile ( ::: memory);
 -#define CPUINFO_PROC cpu
 +#define CPUINFO_PROC {cpu}
  #endif
  
  #ifdef __s390__
 @@ -40,31 +40,31 @@
  # define rmb()   asm volatile( ::: memory)
  #endif
  #define cpu_relax()  asm volatile( ::: memory)
 -#define CPUINFO_PROC cpu type
 +#define CPUINFO_PROC {cpu type}
  #endif
  
  #ifdef __hppa__
  #define rmb()asm volatile( ::: memory)
  #define cpu_relax()  asm volatile( ::: memory);
 -#define CPUINFO_PROC cpu
 +#define CPUINFO_PROC {cpu}
  #endif
  
  #ifdef __sparc__
  #define rmb()asm volatile(:::memory)
  #define cpu_relax()  asm volatile(:::memory)
 -#define CPUINFO_PROC cpu
 +#define CPUINFO_PROC {cpu}
  #endif
  
  #ifdef __alpha__
  #define rmb()asm volatile(mb ::: memory)
  #define cpu_relax()  asm volatile( ::: memory)
 -#define CPUINFO_PROC cpu model
 +#define CPUINFO_PROC {cpu model}
  #endif
  
  #ifdef __ia64__
  #define rmb()asm volatile (mf ::: memory)
  #define cpu_relax()  asm volatile (hint @pause ::: memory)
 -#define CPUINFO_PROC model name
 +#define CPUINFO_PROC {model name}
  #endif
  
  #ifdef __arm__
 @@ -74,7 +74,7 @@
   */
  #define rmb()((void(*)(void))0x0fa0)()
  #define cpu_relax()  asm volatile(:::memory)
 -#define CPUINFO_PROC Processor
 +#define CPUINFO_PROC {model name, Processor}
  #endif
  
  #ifdef __aarch64__
 @@ -91,19 +91,19 @@
   : /* no input */\
   : memory)
  #define cpu_relax()  asm volatile( ::: memory)
 -#define CPUINFO_PROC cpu model
 +#define CPUINFO_PROC {cpu model}
  #endif
  
  #ifdef __arc__
  #define rmb()asm volatile( ::: memory)
  #define cpu_relax()  rmb()
 -#define CPUINFO_PROC Processor
 +#define CPUINFO_PROC {Processor}
  #endif
  
  #ifdef __metag__
  #define rmb()asm volatile( ::: memory)
  #define cpu_relax()  asm volatile( ::: memory)
 -#define CPUINFO_PROC CPU
 +#define CPUINFO_PROC {CPU}
  #endif
  
  #include time.h
 diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
 index b59350f..d48f571 100644
 --- a/tools/perf/util/header.c
 +++ b/tools/perf/util/header.c
 @@ -550,16 +550,12 @@ static int write_version(int fd, struct perf_header *h 
 __maybe_unused,
   return do_write_string(fd, perf_version_string);
  }
  
 -static int write_cpudesc(int fd, struct perf_header *h __maybe_unused,
 -struct perf_evlist *evlist __maybe_unused)
 +static int __write_cpudesc(int fd, const char *cpuinfo_proc)
  {
 -#ifndef CPUINFO_PROC
 -#define CPUINFO_PROC NULL
 -#endif
   FILE *file;
   char *buf = NULL;
   char *s, *p;
 - const char *search = CPUINFO_PROC;
 + const char *search = cpuinfo_proc;
   size_t len = 0;
   int ret = -1;
  
 @@ -611,6 +607,25 @@ done:
   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)

Re: [PATCH v2 RESEND] perf tools: makes CPUINFO_PROC to array for different kernel version

2014-10-23 Thread Arnaldo Carvalho de Melo
Em Fri, Oct 24, 2014 at 08:26:13AM +0900, Namhyung Kim escreveu:
 On Wed, 22 Oct 2014 15:40:14 +0800, Wang Nan wrote:
  After kernel 3.7 (commit b4b8f770eb10a1bccaf8aa0ec1956e2dd7ed1e0a),
  /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.

  Signed-off-by: Wang Nan wangn...@huawei.com
 
 Acked-by: Namhyung Kim namhy...@kernel.org

So now this will work with older kernels and new ones? Cool, thanks for
working on it, but:

[acme@ssdandy linux]$ patch -p1  /wb/1.patch 
patching file tools/perf/perf.h
Hunk #1 FAILED at 6.
Hunk #2 FAILED at 15.
Hunk #3 FAILED at 25.
Hunk #4 FAILED at 40.
Hunk #5 FAILED at 74.
Hunk #6 FAILED at 91.
6 out of 6 hunks FAILED -- saving rejects to file tools/perf/perf.h.rej
patching file tools/perf/util/header.c
Hunk #1 succeeded at 579 (offset 29 lines).
Hunk #2 succeeded at 636 (offset 29 lines).
[acme@ssdandy linux]$

[acme@ssdandy linux]$ git log --oneline tools/perf/perf.h | head -10
87c43ee perf tools: Export usage string and option table of perf record
72a128a perf tools: Move callchain config from record_opts to callchain_param
73a31b7 perf tools: Move ACCESS_ONCE from perf.h header
82baa0e perf tools: Move sys_perf_event_open function from perf.h
43599d1 perf tools: Move syscall and arch specific defines from perf.h
2c83bc0 perf tools: Move perf_call_graph_mode enum from perf.h
0776eb5 perf tools: Move sample data structures from perf.h
36446f4 perf tools: Remove PR_TASK_PERF_EVENTS_* from perf.h
273a0a7 perf tools: Remove asmlinkage define from perf.h
1b7ae1c perf tools: Remove min define from perf.h
[acme@ssdandy linux]$

This is:

git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git perf/core

If you don't have time to fix this up, I'll try to find time tomorrow
and do it.

- Arnaldo
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2 RESEND] perf tools: makes CPUINFO_PROC to array for different kernel version

2014-10-23 Thread Wang Nan
Hi Arnaldo,

A have posted a v3 patch based on your git repository. Please refer to:

https://lkml.org/lkml/2014/10/23/711 .

Thanks.


On 2014/10/24 7:53, Arnaldo Carvalho de Melo wrote:
 Em Fri, Oct 24, 2014 at 08:26:13AM +0900, Namhyung Kim escreveu:
 On Wed, 22 Oct 2014 15:40:14 +0800, Wang Nan wrote:
 After kernel 3.7 (commit b4b8f770eb10a1bccaf8aa0ec1956e2dd7ed1e0a),
 /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.
 
 Signed-off-by: Wang Nan wangn...@huawei.com
  
 Acked-by: Namhyung Kim namhy...@kernel.org
 
 So now this will work with older kernels and new ones? Cool, thanks for
 working on it, but:
 
 [acme@ssdandy linux]$ patch -p1  /wb/1.patch 
 patching file tools/perf/perf.h
 Hunk #1 FAILED at 6.
 Hunk #2 FAILED at 15.
 Hunk #3 FAILED at 25.
 Hunk #4 FAILED at 40.
 Hunk #5 FAILED at 74.
 Hunk #6 FAILED at 91.
 6 out of 6 hunks FAILED -- saving rejects to file tools/perf/perf.h.rej
 patching file tools/perf/util/header.c
 Hunk #1 succeeded at 579 (offset 29 lines).
 Hunk #2 succeeded at 636 (offset 29 lines).
 [acme@ssdandy linux]$
 
 [acme@ssdandy linux]$ git log --oneline tools/perf/perf.h | head -10
 87c43ee perf tools: Export usage string and option table of perf record
 72a128a perf tools: Move callchain config from record_opts to callchain_param
 73a31b7 perf tools: Move ACCESS_ONCE from perf.h header
 82baa0e perf tools: Move sys_perf_event_open function from perf.h
 43599d1 perf tools: Move syscall and arch specific defines from perf.h
 2c83bc0 perf tools: Move perf_call_graph_mode enum from perf.h
 0776eb5 perf tools: Move sample data structures from perf.h
 36446f4 perf tools: Remove PR_TASK_PERF_EVENTS_* from perf.h
 273a0a7 perf tools: Remove asmlinkage define from perf.h
 1b7ae1c perf tools: Remove min define from perf.h
 [acme@ssdandy linux]$
 
 This is:
 
 git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git perf/core
 
 If you don't have time to fix this up, I'll try to find time tomorrow
 and do it.
 
 - Arnaldo
 




--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v2 RESEND] perf tools: makes CPUINFO_PROC to array for different kernel version

2014-10-22 Thread Wang Nan
After kernel 3.7 (commit b4b8f770eb10a1bccaf8aa0ec1956e2dd7ed1e0a),
/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.

Signed-off-by: Wang Nan 
Cc: Namhyung Kim 
---
 tools/perf/perf.h| 24 
 tools/perf/util/header.c | 27 +--
 2 files changed, 33 insertions(+), 18 deletions(-)

diff --git a/tools/perf/perf.h b/tools/perf/perf.h
index 32bd102..1a23392 100644
--- a/tools/perf/perf.h
+++ b/tools/perf/perf.h
@@ -6,7 +6,7 @@
 #if defined(__i386__)
 #define rmb()  asm volatile("lock; addl $0,0(%%esp)" ::: "memory")
 #define cpu_relax()asm volatile("rep; nop" ::: "memory");
-#define CPUINFO_PROC   "model name"
+#define CPUINFO_PROC   {"model name"}
 #ifndef __NR_perf_event_open
 # define __NR_perf_event_open 336
 #endif
@@ -15,7 +15,7 @@
 #if defined(__x86_64__)
 #define rmb()  asm volatile("lfence" ::: "memory")
 #define cpu_relax()asm volatile("rep; nop" ::: "memory");
-#define CPUINFO_PROC   "model name"
+#define CPUINFO_PROC   {"model name"}
 #ifndef __NR_perf_event_open
 # define __NR_perf_event_open 298
 #endif
@@ -25,7 +25,7 @@
 #include "../../arch/powerpc/include/uapi/asm/unistd.h"
 #define rmb()  asm volatile ("sync" ::: "memory")
 #define cpu_relax()asm volatile ("" ::: "memory");
-#define CPUINFO_PROC   "cpu"
+#define CPUINFO_PROC   {"cpu"}
 #endif
 
 #ifdef __s390__
@@ -40,31 +40,31 @@
 # define rmb() asm volatile("" ::: "memory")
 #endif
 #define cpu_relax()asm volatile("" ::: "memory")
-#define CPUINFO_PROC   "cpu type"
+#define CPUINFO_PROC   {"cpu type"}
 #endif
 
 #ifdef __hppa__
 #define rmb()  asm volatile("" ::: "memory")
 #define cpu_relax()asm volatile("" ::: "memory");
-#define CPUINFO_PROC   "cpu"
+#define CPUINFO_PROC   {"cpu"}
 #endif
 
 #ifdef __sparc__
 #define rmb()  asm volatile("":::"memory")
 #define cpu_relax()asm volatile("":::"memory")
-#define CPUINFO_PROC   "cpu"
+#define CPUINFO_PROC   {"cpu"}
 #endif
 
 #ifdef __alpha__
 #define rmb()  asm volatile("mb" ::: "memory")
 #define cpu_relax()asm volatile("" ::: "memory")
-#define CPUINFO_PROC   "cpu model"
+#define CPUINFO_PROC   {"cpu model"}
 #endif
 
 #ifdef __ia64__
 #define rmb()  asm volatile ("mf" ::: "memory")
 #define cpu_relax()asm volatile ("hint @pause" ::: "memory")
-#define CPUINFO_PROC   "model name"
+#define CPUINFO_PROC   {"model name"}
 #endif
 
 #ifdef __arm__
@@ -74,7 +74,7 @@
  */
 #define rmb()  ((void(*)(void))0x0fa0)()
 #define cpu_relax()asm volatile("":::"memory")
-#define CPUINFO_PROC   "Processor"
+#define CPUINFO_PROC   {"model name", "Processor"}
 #endif
 
 #ifdef __aarch64__
@@ -91,19 +91,19 @@
: /* no input */\
: "memory")
 #define cpu_relax()asm volatile("" ::: "memory")
-#define CPUINFO_PROC   "cpu model"
+#define CPUINFO_PROC   {"cpu model"}
 #endif
 
 #ifdef __arc__
 #define rmb()  asm volatile("" ::: "memory")
 #define cpu_relax()rmb()
-#define CPUINFO_PROC   "Processor"
+#define CPUINFO_PROC   {"Processor"}
 #endif
 
 #ifdef __metag__
 #define rmb()  asm volatile("" ::: "memory")
 #define cpu_relax()asm volatile("" ::: "memory")
-#define CPUINFO_PROC   "CPU"
+#define CPUINFO_PROC   {"CPU"}
 #endif
 
 #include 
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index b59350f..d48f571 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -550,16 +550,12 @@ static int write_version(int fd, struct perf_header *h 
__maybe_unused,
return do_write_string(fd, perf_version_string);
 }
 
-static int write_cpudesc(int fd, struct perf_header *h __maybe_unused,
-  struct perf_evlist *evlist __maybe_unused)
+static int __write_cpudesc(int fd, const char *cpuinfo_proc)
 {
-#ifndef CPUINFO_PROC
-#define CPUINFO_PROC NULL
-#endif
FILE *file;
char *buf = NULL;
char *s, *p;
-   const char *search = CPUINFO_PROC;
+   const char *search = cpuinfo_proc;
size_t len = 0;
int ret = -1;
 
@@ -611,6 +607,25 @@ done:
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 

[PATCH v2 RESEND] perf tools: makes CPUINFO_PROC to array for different kernel version

2014-10-22 Thread Wang Nan
After kernel 3.7 (commit b4b8f770eb10a1bccaf8aa0ec1956e2dd7ed1e0a),
/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.

Signed-off-by: Wang Nan wangn...@huawei.com
Cc: Namhyung Kim namhy...@kernel.org
---
 tools/perf/perf.h| 24 
 tools/perf/util/header.c | 27 +--
 2 files changed, 33 insertions(+), 18 deletions(-)

diff --git a/tools/perf/perf.h b/tools/perf/perf.h
index 32bd102..1a23392 100644
--- a/tools/perf/perf.h
+++ b/tools/perf/perf.h
@@ -6,7 +6,7 @@
 #if defined(__i386__)
 #define rmb()  asm volatile(lock; addl $0,0(%%esp) ::: memory)
 #define cpu_relax()asm volatile(rep; nop ::: memory);
-#define CPUINFO_PROC   model name
+#define CPUINFO_PROC   {model name}
 #ifndef __NR_perf_event_open
 # define __NR_perf_event_open 336
 #endif
@@ -15,7 +15,7 @@
 #if defined(__x86_64__)
 #define rmb()  asm volatile(lfence ::: memory)
 #define cpu_relax()asm volatile(rep; nop ::: memory);
-#define CPUINFO_PROC   model name
+#define CPUINFO_PROC   {model name}
 #ifndef __NR_perf_event_open
 # define __NR_perf_event_open 298
 #endif
@@ -25,7 +25,7 @@
 #include ../../arch/powerpc/include/uapi/asm/unistd.h
 #define rmb()  asm volatile (sync ::: memory)
 #define cpu_relax()asm volatile ( ::: memory);
-#define CPUINFO_PROC   cpu
+#define CPUINFO_PROC   {cpu}
 #endif
 
 #ifdef __s390__
@@ -40,31 +40,31 @@
 # define rmb() asm volatile( ::: memory)
 #endif
 #define cpu_relax()asm volatile( ::: memory)
-#define CPUINFO_PROC   cpu type
+#define CPUINFO_PROC   {cpu type}
 #endif
 
 #ifdef __hppa__
 #define rmb()  asm volatile( ::: memory)
 #define cpu_relax()asm volatile( ::: memory);
-#define CPUINFO_PROC   cpu
+#define CPUINFO_PROC   {cpu}
 #endif
 
 #ifdef __sparc__
 #define rmb()  asm volatile(:::memory)
 #define cpu_relax()asm volatile(:::memory)
-#define CPUINFO_PROC   cpu
+#define CPUINFO_PROC   {cpu}
 #endif
 
 #ifdef __alpha__
 #define rmb()  asm volatile(mb ::: memory)
 #define cpu_relax()asm volatile( ::: memory)
-#define CPUINFO_PROC   cpu model
+#define CPUINFO_PROC   {cpu model}
 #endif
 
 #ifdef __ia64__
 #define rmb()  asm volatile (mf ::: memory)
 #define cpu_relax()asm volatile (hint @pause ::: memory)
-#define CPUINFO_PROC   model name
+#define CPUINFO_PROC   {model name}
 #endif
 
 #ifdef __arm__
@@ -74,7 +74,7 @@
  */
 #define rmb()  ((void(*)(void))0x0fa0)()
 #define cpu_relax()asm volatile(:::memory)
-#define CPUINFO_PROC   Processor
+#define CPUINFO_PROC   {model name, Processor}
 #endif
 
 #ifdef __aarch64__
@@ -91,19 +91,19 @@
: /* no input */\
: memory)
 #define cpu_relax()asm volatile( ::: memory)
-#define CPUINFO_PROC   cpu model
+#define CPUINFO_PROC   {cpu model}
 #endif
 
 #ifdef __arc__
 #define rmb()  asm volatile( ::: memory)
 #define cpu_relax()rmb()
-#define CPUINFO_PROC   Processor
+#define CPUINFO_PROC   {Processor}
 #endif
 
 #ifdef __metag__
 #define rmb()  asm volatile( ::: memory)
 #define cpu_relax()asm volatile( ::: memory)
-#define CPUINFO_PROC   CPU
+#define CPUINFO_PROC   {CPU}
 #endif
 
 #include time.h
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index b59350f..d48f571 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -550,16 +550,12 @@ static int write_version(int fd, struct perf_header *h 
__maybe_unused,
return do_write_string(fd, perf_version_string);
 }
 
-static int write_cpudesc(int fd, struct perf_header *h __maybe_unused,
-  struct perf_evlist *evlist __maybe_unused)
+static int __write_cpudesc(int fd, const char *cpuinfo_proc)
 {
-#ifndef CPUINFO_PROC
-#define CPUINFO_PROC NULL
-#endif
FILE *file;
char *buf = NULL;
char *s, *p;
-   const char *search = CPUINFO_PROC;
+   const char *search = cpuinfo_proc;
size_t len = 0;
int ret = -1;
 
@@ -611,6 +607,25 @@ done:
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,
struct perf_evlist