From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org, Wang Nan <wangnan0@huawei.com>,
Li Zefan <lizefan@huawei.com>, Namhyung Kim <namhyung@kernel.org>,
Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [PATCH 19/32] perf tools: Make CPUINFO_PROC an array to support different kernel versions
Date: Tue, 28 Oct 2014 11:32:13 -0200 [thread overview]
Message-ID: <1414503146-22789-20-git-send-email-acme@kernel.org> (raw)
In-Reply-To: <1414503146-22789-1-git-send-email-acme@kernel.org>
From: Wang Nan <wangnan0@huawei.com>
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.
v2 -> v3:
- Rebase:
git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux.git perf/core
Signed-off-by: Wang Nan <wangnan0@huawei.com>
Acked-by: Namhyung 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.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
tools/perf/perf-sys.h | 30 +++++++++++++++---------------
| 27 +++++++++++++++++++++------
2 files changed, 36 insertions(+), 21 deletions(-)
diff --git a/tools/perf/perf-sys.h b/tools/perf/perf-sys.h
index 937e4324ad94..a3b13d7dc1d4 100644
--- a/tools/perf/perf-sys.h
+++ b/tools/perf/perf-sys.h
@@ -13,7 +13,7 @@
#define wmb() 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 CPUINFO_PROC "model name"
+#define CPUINFO_PROC {"model name"}
#ifndef __NR_perf_event_open
# define __NR_perf_event_open 336
#endif
@@ -30,7 +30,7 @@
#define wmb() asm volatile("sfence" ::: "memory")
#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
@@ -47,14 +47,14 @@
#define mb() asm volatile ("sync" ::: "memory")
#define wmb() asm volatile ("sync" ::: "memory")
#define rmb() asm volatile ("sync" ::: "memory")
-#define CPUINFO_PROC "cpu"
+#define CPUINFO_PROC {"cpu"}
#endif
#ifdef __s390__
#define mb() asm volatile("bcr 15,0" ::: "memory")
#define wmb() 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
#ifdef __sh__
@@ -67,14 +67,14 @@
# define wmb() asm volatile("" ::: "memory")
# define rmb() asm volatile("" ::: "memory")
#endif
-#define CPUINFO_PROC "cpu type"
+#define CPUINFO_PROC {"cpu type"}
#endif
#ifdef __hppa__
#define mb() asm volatile("" ::: "memory")
#define wmb() asm volatile("" ::: "memory")
#define rmb() asm volatile("" ::: "memory")
-#define CPUINFO_PROC "cpu"
+#define CPUINFO_PROC {"cpu"}
#endif
#ifdef __sparc__
@@ -87,14 +87,14 @@
#endif
#define wmb() asm volatile("":::"memory")
#define rmb() asm volatile("":::"memory")
-#define CPUINFO_PROC "cpu"
+#define CPUINFO_PROC {"cpu"}
#endif
#ifdef __alpha__
#define mb() asm volatile("mb" ::: "memory")
#define wmb() asm volatile("wmb" ::: "memory")
#define rmb() asm volatile("mb" ::: "memory")
-#define CPUINFO_PROC "cpu model"
+#define CPUINFO_PROC {"cpu model"}
#endif
#ifdef __ia64__
@@ -102,7 +102,7 @@
#define wmb() asm volatile ("mf" ::: "memory")
#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__
@@ -113,7 +113,7 @@
#define mb() ((void(*)(void))0xffff0fa0)()
#define wmb() ((void(*)(void))0xffff0fa0)()
#define rmb() ((void(*)(void))0xffff0fa0)()
-#define CPUINFO_PROC "Processor"
+#define CPUINFO_PROC {"model name", "Processor"}
#endif
#ifdef __aarch64__
@@ -133,28 +133,28 @@
: "memory")
#define wmb() mb()
#define rmb() mb()
-#define CPUINFO_PROC "cpu model"
+#define CPUINFO_PROC {"cpu model"}
#endif
#ifdef __arc__
#define mb() asm volatile("" ::: "memory")
#define wmb() asm volatile("" ::: "memory")
#define rmb() asm volatile("" ::: "memory")
-#define CPUINFO_PROC "Processor"
+#define CPUINFO_PROC {"Processor"}
#endif
#ifdef __metag__
#define mb() asm volatile("" ::: "memory")
#define wmb() asm volatile("" ::: "memory")
#define rmb() asm volatile("" ::: "memory")
-#define CPUINFO_PROC "CPU"
+#define CPUINFO_PROC {"CPU"}
#endif
#ifdef __xtensa__
#define mb() asm volatile("memw" ::: "memory")
#define wmb() asm volatile("memw" ::: "memory")
#define rmb() asm volatile("" ::: "memory")
-#define CPUINFO_PROC "core ID"
+#define CPUINFO_PROC {"core ID"}
#endif
#ifdef __tile__
@@ -162,7 +162,7 @@
#define wmb() asm volatile ("mf" ::: "memory")
#define rmb() asm volatile ("mf" ::: "memory")
#define cpu_relax() asm volatile ("mfspr zero, PASS" ::: "memory")
-#define CPUINFO_PROC "model name"
+#define CPUINFO_PROC {"model name"}
#endif
#define barrier() asm volatile ("" ::: "memory")
--git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 39b80ac9f698..0ecf4a304cbc 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -579,16 +579,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;
@@ -640,6 +636,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 *evlist __maybe_unused)
{
--
1.9.3
next prev parent reply other threads:[~2014-10-28 13:38 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-28 13:31 [GIT PULL 00/32] perf/core improvements and fixes Arnaldo Carvalho de Melo
2014-10-28 13:31 ` [PATCH 01/32] perf tools powerpc: Cache the DWARF debug info Arnaldo Carvalho de Melo
2014-10-29 6:39 ` Namhyung Kim
2014-10-29 21:26 ` Sukadev Bhattiprolu
2014-10-31 3:10 ` Namhyung Kim
2014-10-28 13:31 ` [PATCH 02/32] perf tools: Set thread->mg.machine in all places Arnaldo Carvalho de Melo
2014-10-28 13:31 ` [PATCH 03/32] perf tools: A thread's machine can be found via thread->mg->machine Arnaldo Carvalho de Melo
2014-10-28 13:31 ` [PATCH 04/32] perf thread: Adopt resolve_callchain method from machine Arnaldo Carvalho de Melo
2014-10-28 13:31 ` [PATCH 05/32] perf callchains: Use thread->mg->machine Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 06/32] perf tests: Remove misplaced __maybe_unused Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 07/32] perf tests: Use thread->mg->machine Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 08/32] perf tools: Add PARSE_OPT_DISABLED flag Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 09/32] perf tools: Export usage string and option table of perf record Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 10/32] perf kvm: Print kvm specific --help output Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 11/32] perf tools: Add support for exclusive option Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 12/32] perf probe: Use PARSE_OPT_EXCLUSIVE flag Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 13/32] perf callchain: Use global caching provided by libunwind Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 14/32] perf tools: Ensure return negative value when write header error Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 15/32] perf pmu: Let pmu's with no events show up on perf list Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 16/32] perf tools: Build programs to copy 32-bit compatibility Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 17/32] perf tools: Add support for 32-bit compatibility VDSOs Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 18/32] perf tools: Do not attempt to run perf-read-vdso32 if it wasn't built Arnaldo Carvalho de Melo
2014-10-28 13:32 ` Arnaldo Carvalho de Melo [this message]
2014-10-28 13:32 ` [PATCH 20/32] perf pmu: Add proper error handling to print_pmu_events() Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 21/32] perf tools: Fix report -F abort for data without branch info Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 22/32] perf tools: Fix report -F in_tx " Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 23/32] perf tools: Fix report -F mispredict " Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 24/32] perf tools: Fix report -F symbol_to " Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 25/32] perf tools: Fix report -F symbol_from " Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 26/32] perf tools: Fix report -F dso_to " Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 27/32] perf tools: Fix report -F dso_from " Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 28/32] perf tools: Add facility to export data in database-friendly way Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 29/32] perf scripting python: Extend interface to export data in a " Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 30/32] perf script: Add Python script to export to postgresql Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 31/32] perf probe: Trivial typo fix for --demangle Arnaldo Carvalho de Melo
2014-10-28 13:32 ` [PATCH 32/32] perf probe: Add --quiet option to suppress output result message Arnaldo Carvalho de Melo
2014-10-29 9:11 ` [GIT PULL 00/32] perf/core improvements and fixes Ingo Molnar
2014-10-29 12:58 ` Arnaldo Carvalho de Melo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1414503146-22789-20-git-send-email-acme@kernel.org \
--to=acme@kernel.org \
--cc=acme@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lizefan@huawei.com \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=wangnan0@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).