* [RFC PATCH 0/2] powerpc/perf: Implement get_cpu_str()
@ 2014-07-24 7:46 Sukadev Bhattiprolu
2014-07-24 7:47 ` [RFC PATCH 1/2] powerpc/perf: include util/util.h and remove stringify macros Sukadev Bhattiprolu
2014-07-24 7:47 ` [RFC PATCH 2/2] powerpc/perf: Implement get_cpu_str() Sukadev Bhattiprolu
0 siblings, 2 replies; 6+ messages in thread
From: Sukadev Bhattiprolu @ 2014-07-24 7:46 UTC (permalink / raw)
To: andi; +Cc: Arnaldo Carvalho de Melo, Jiri Olsa, Michael Ellerman, linux-kernel
These two patches implement get_cpu_str() for powerpc.
get_cpu_str() will allow users to cache their perf event JSON files
and skip having to specify the --events-file with each perf invocation.
These patches are based on the commit
commit 4a5e890
Author: Andi Kleen <ak@linux.intel.com>
Date: Fri Jun 13 15:14:14 2014 -0700
perf, tools: Add a --no-desc flag to perf list
in Andi Kleen's tree
git://git.kernel.org/pub/scm/linux/kernel/git/ak/linux-misc
At this point, I am mostly looking for feedback on the changes around
cache_cpu_str() and the get_cpu_str().
^ permalink raw reply [flat|nested] 6+ messages in thread
* [RFC PATCH 1/2] powerpc/perf: include util/util.h and remove stringify macros
2014-07-24 7:46 [RFC PATCH 0/2] powerpc/perf: Implement get_cpu_str() Sukadev Bhattiprolu
@ 2014-07-24 7:47 ` Sukadev Bhattiprolu
2014-07-24 14:02 ` Arnaldo Carvalho de Melo
2014-07-28 8:26 ` [tip:perf/core] perf powerpc: Include util/ util.h " tip-bot for Sukadev Bhattiprolu
2014-07-24 7:47 ` [RFC PATCH 2/2] powerpc/perf: Implement get_cpu_str() Sukadev Bhattiprolu
1 sibling, 2 replies; 6+ messages in thread
From: Sukadev Bhattiprolu @ 2014-07-24 7:47 UTC (permalink / raw)
To: andi; +Cc: Arnaldo Carvalho de Melo, Jiri Olsa, Michael Ellerman, linux-kernel
[RFC PATCH 1/2] powerpc/perf: include util/util.h and remove stringify macros
The stringify macros are defined in tools/perf/util/util.h and
don't need to be redfined specfiically for powerpc.
Signed-off-by: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
---
| 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
--git a/tools/perf/arch/powerpc/util/header.c b/tools/perf/arch/powerpc/util/header.c
index 2f7073d..6c1b8a7 100644
--- a/tools/perf/arch/powerpc/util/header.c
+++ b/tools/perf/arch/powerpc/util/header.c
@@ -5,9 +5,7 @@
#include <string.h>
#include "../../util/header.h"
-
-#define __stringify_1(x) #x
-#define __stringify(x) __stringify_1(x)
+#include "../../util/util.h"
#define mfspr(rn) ({unsigned long rval; \
asm volatile("mfspr %0," __stringify(rn) \
--
1.7.9.5
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [RFC PATCH 2/2] powerpc/perf: Implement get_cpu_str()
2014-07-24 7:46 [RFC PATCH 0/2] powerpc/perf: Implement get_cpu_str() Sukadev Bhattiprolu
2014-07-24 7:47 ` [RFC PATCH 1/2] powerpc/perf: include util/util.h and remove stringify macros Sukadev Bhattiprolu
@ 2014-07-24 7:47 ` Sukadev Bhattiprolu
2014-07-25 2:55 ` Michael Ellerman
1 sibling, 1 reply; 6+ messages in thread
From: Sukadev Bhattiprolu @ 2014-07-24 7:47 UTC (permalink / raw)
To: andi; +Cc: Arnaldo Carvalho de Melo, Jiri Olsa, Michael Ellerman, linux-kernel
[RFC PATCH 2/2] powerpc/perf: Implement get_cpu_str()
get_cpu_str() returns a string identifying the CPU type on the system.
This string is then used to locate a cached JSON file which defines
the list of PMU events supported by the CPU.
Eg: if get_cpu_str() returns "power8", the perf tool would refer to the
PMU events defined in ~/.cache/pmu-events/power8.json.
Signed-off-by: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
---
| 69 +++++++++++++++++++++++++++++++++
tools/perf/perf.c | 11 ++++++
tools/perf/perf.h | 2 +
3 files changed, 82 insertions(+)
--git a/tools/perf/arch/powerpc/util/header.c b/tools/perf/arch/powerpc/util/header.c
index 6c1b8a7..4d82593 100644
--- a/tools/perf/arch/powerpc/util/header.c
+++ b/tools/perf/arch/powerpc/util/header.c
@@ -3,9 +3,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <elf.h>
+#include <link.h>
#include "../../util/header.h"
#include "../../util/util.h"
+#include "../../util/jevents.h"
#define mfspr(rn) ({unsigned long rval; \
asm volatile("mfspr %0," __stringify(rn) \
@@ -15,6 +18,8 @@
#define PVR_VER(pvr) (((pvr) >> 16) & 0xFFFF) /* Version field */
#define PVR_REV(pvr) (((pvr) >> 0) & 0xFFFF) /* Revison field */
+static char *cached_cpu_str;
+
int
get_cpuid(char *buffer, size_t sz)
{
@@ -32,3 +37,67 @@ get_cpuid(char *buffer, size_t sz)
}
return -1;
}
+
+static void dup_platform(char *platform)
+{
+ char *bp;
+
+ bp = cached_cpu_str = malloc(128);
+ if (!bp)
+ return;
+
+ /*
+ * Platform could be POWER8 or POWER8E. Exclude any suffixes
+ * after the digit(s)
+ */
+ while (isalpha(*platform))
+ *bp++ = tolower(*platform++);
+
+ while (isdigit(*platform))
+ *bp++ = *platform++;
+ *bp = '\0';
+}
+
+static void *find_auxv(void)
+{
+ char **envp;
+
+ /*
+ * Exec() copies the AUX Variables after the environment variables.
+ */
+ envp = environ;
+ while (*envp)
+ envp++;
+ envp++;
+
+ return envp;
+}
+
+void cache_cpu_str(void)
+{
+ ElfW(auxv_t) * auxv;
+
+ auxv = (ElfW(auxv_t)*)find_auxv();
+
+ while (auxv->a_type != AT_NULL) {
+ if (auxv->a_type == AT_BASE_PLATFORM) {
+ dup_platform((char *)auxv->a_un.a_val);
+ return;
+ }
+ auxv++;
+ }
+}
+
+/*
+ * Return an identier string for the CPU on this system.
+ *
+ * On Non-NULL return, assume that the caller will free the
+ * returned string buffer.
+ */
+char *get_cpu_str(void)
+{
+ if (cached_cpu_str)
+ return strdup(cached_cpu_str);
+
+ return NULL;
+}
diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index 95c58fc..fb9beb0 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -452,6 +452,10 @@ void pthread__unblock_sigwinch(void)
pthread_sigmask(SIG_UNBLOCK, &set, NULL);
}
+__attribute__((weak)) void cache_cpu_str(void)
+{
+}
+
int main(int argc, const char **argv)
{
const char *cmd;
@@ -460,6 +464,13 @@ int main(int argc, const char **argv)
page_size = sysconf(_SC_PAGE_SIZE);
cacheline_size = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
+ /*
+ * Architectures that rely on AUXV variables to determine
+ * CPU type must cache the cpu type before setenv() calls
+ * So do that early.
+ */
+ cache_cpu_str();
+
cmd = perf_extract_argv0_path(argv[0]);
if (!cmd)
cmd = "perf-help";
diff --git a/tools/perf/perf.h b/tools/perf/perf.h
index 510c65f..406fd5c 100644
--- a/tools/perf/perf.h
+++ b/tools/perf/perf.h
@@ -65,4 +65,6 @@ struct record_opts {
unsigned initial_delay;
};
+extern void cache_cpu_str(void);
+
#endif
--
1.7.9.5
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [RFC PATCH 1/2] powerpc/perf: include util/util.h and remove stringify macros
2014-07-24 7:47 ` [RFC PATCH 1/2] powerpc/perf: include util/util.h and remove stringify macros Sukadev Bhattiprolu
@ 2014-07-24 14:02 ` Arnaldo Carvalho de Melo
2014-07-28 8:26 ` [tip:perf/core] perf powerpc: Include util/ util.h " tip-bot for Sukadev Bhattiprolu
1 sibling, 0 replies; 6+ messages in thread
From: Arnaldo Carvalho de Melo @ 2014-07-24 14:02 UTC (permalink / raw)
To: Sukadev Bhattiprolu; +Cc: andi, Jiri Olsa, Michael Ellerman, linux-kernel
Em Thu, Jul 24, 2014 at 12:47:18AM -0700, Sukadev Bhattiprolu escreveu:
> [RFC PATCH 1/2] powerpc/perf: include util/util.h and remove stringify macros
>
> The stringify macros are defined in tools/perf/util/util.h and
> don't need to be redfined specfiically for powerpc.
This one can be picked independelty, done.
- Arnaldo
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [RFC PATCH 2/2] powerpc/perf: Implement get_cpu_str()
2014-07-24 7:47 ` [RFC PATCH 2/2] powerpc/perf: Implement get_cpu_str() Sukadev Bhattiprolu
@ 2014-07-25 2:55 ` Michael Ellerman
0 siblings, 0 replies; 6+ messages in thread
From: Michael Ellerman @ 2014-07-25 2:55 UTC (permalink / raw)
To: Sukadev Bhattiprolu
Cc: andi, Arnaldo Carvalho de Melo, Jiri Olsa, linux-kernel
On Thu, 2014-07-24 at 00:47 -0700, Sukadev Bhattiprolu wrote:
> [RFC PATCH 2/2] powerpc/perf: Implement get_cpu_str()
>
> get_cpu_str() returns a string identifying the CPU type on the system.
> This string is then used to locate a cached JSON file which defines
> the list of PMU events supported by the CPU.
>
> Eg: if get_cpu_str() returns "power8", the perf tool would refer to the
> PMU events defined in ~/.cache/pmu-events/power8.json.
Hi Suka,
I know we talked internally a while ago about using AT_BASE_PLATFORM, but that
was before I looked closely at Andi's patches last week.
I think we're better off using the PVR directly, it's less magic, it gives us
more flexibility and it's easier to get at.
So get_cpu_str() would just return eg. "004b0201-core".
We would handle the mapping of that name to an event file either in the
download script via the mapfile, or just by using symlinks.
cheers
^ permalink raw reply [flat|nested] 6+ messages in thread
* [tip:perf/core] perf powerpc: Include util/ util.h and remove stringify macros
2014-07-24 7:47 ` [RFC PATCH 1/2] powerpc/perf: include util/util.h and remove stringify macros Sukadev Bhattiprolu
2014-07-24 14:02 ` Arnaldo Carvalho de Melo
@ 2014-07-28 8:26 ` tip-bot for Sukadev Bhattiprolu
1 sibling, 0 replies; 6+ messages in thread
From: tip-bot for Sukadev Bhattiprolu @ 2014-07-28 8:26 UTC (permalink / raw)
To: linux-tip-commits
Cc: acme, linux-kernel, hpa, mingo, michaele, andi, jolsa, tglx, sukadev
Commit-ID: c94b93cbca59435dfc0f2a838fea55bd632145d3
Gitweb: http://git.kernel.org/tip/c94b93cbca59435dfc0f2a838fea55bd632145d3
Author: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
AuthorDate: Thu, 24 Jul 2014 00:47:18 -0700
Committer: Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Thu, 24 Jul 2014 11:00:39 -0300
perf powerpc: Include util/util.h and remove stringify macros
The stringify macros are defined in tools/perf/util/util.h and don't
need to be redfined specfiically for powerpc.
Signed-off-by: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Michael Ellerman <michaele@au1.ibm.com>
Link: http://lkml.kernel.org/r/20140724074718.GB18829@us.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
| 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
--git a/tools/perf/arch/powerpc/util/header.c b/tools/perf/arch/powerpc/util/header.c
index 2f7073d..6c1b8a7 100644
--- a/tools/perf/arch/powerpc/util/header.c
+++ b/tools/perf/arch/powerpc/util/header.c
@@ -5,9 +5,7 @@
#include <string.h>
#include "../../util/header.h"
-
-#define __stringify_1(x) #x
-#define __stringify(x) __stringify_1(x)
+#include "../../util/util.h"
#define mfspr(rn) ({unsigned long rval; \
asm volatile("mfspr %0," __stringify(rn) \
^ permalink raw reply related [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-07-28 8:27 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-24 7:46 [RFC PATCH 0/2] powerpc/perf: Implement get_cpu_str() Sukadev Bhattiprolu
2014-07-24 7:47 ` [RFC PATCH 1/2] powerpc/perf: include util/util.h and remove stringify macros Sukadev Bhattiprolu
2014-07-24 14:02 ` Arnaldo Carvalho de Melo
2014-07-28 8:26 ` [tip:perf/core] perf powerpc: Include util/ util.h " tip-bot for Sukadev Bhattiprolu
2014-07-24 7:47 ` [RFC PATCH 2/2] powerpc/perf: Implement get_cpu_str() Sukadev Bhattiprolu
2014-07-25 2:55 ` Michael Ellerman
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.