powerpc/perf: Implement get_cpu_str()
cover powerpc/perf: Implement get_cpu_str()
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 <[email protected]> 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().
RFC PATCH 1/2 powerpc/perf: include util/util.h and remove stringify macros
[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.
--- tools/perf/arch/powerpc/util/header.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
tools/perf/arch/powerpc/util/header.c +1 -3
@@ -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) \
Signature · 1 line
1.7.9.5
Arnaldo Carvalho de Melo
maintainerRe: [RFC PATCH 1/2] powerpc/perf: include util/util.h and remove stringify macros
Em Thu, Jul 24, 2014 at 12:47:18AM -0700, Sukadev Bhattiprolu escreveu:
Quoted 4 lines
[RFC PATCH 1/2] powerpc/perf: include
util/util.hand remove stringify macrosThe stringify macros are defined in
tools/perf/util/util.hand don't need to be redfined specfiically for powerpc.
This one can be picked independelty, done.
- Arnaldo
tip-bot for Sukadev Bhattiprolu
merge bot[tip:perf/core] perf powerpc: Include util/ util.h and remove stringify macros
In reply to Sukadev Bhattiproluperf powerpc: Include util/util.h and remove stringify macros
Commit-ID: c94b93cbca59435dfc0f2a838fea55bd632145d3 Gitweb: http://git.kernel.org/tip/c94b93cbca59435dfc0f2a838fea55bd632145d3 Author: Sukadev Bhattiprolu <[email protected]> AuthorDate: Thu, 24 Jul 2014 00:47:18 -0700 Committer: Arnaldo Carvalho de Melo <[email protected]> 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.
--- tools/perf/arch/powerpc/util/header.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
tools/perf/arch/powerpc/util/header.c +1 -3
@@ -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) \
RFC PATCH 2/2 powerpc/perf: Implement get_cpu_str()
In reply to Sukadev Bhattiprolu[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.
--- tools/perf/arch/powerpc/util/header.c | 69 +++++++++++++++++++++++++++++++++ tools/perf/perf.c | 11 ++++++ tools/perf/perf.h | 2 + 3 files changed, 82 insertions(+)
tools/perf/arch/powerpc/util/header.c +69 -0
@@ -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 ; +}
tools/perf/perf.c +11 -0
@@ -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" ;
tools/perf/perf.h +2 -0
@@ -65,4 +65,6 @@ struct record_opts { unsigned initial_delay; }; +extern void cache_cpu_str (void ); +#endif
Signature · 1 line
1.7.9.5
Quoted 8 lines · Sukadev Bhattiprolu
[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