Skip to content

Commit 9fe8895

Browse files
kimphillamdacmel
authored andcommitted
perf env: Add perf_env__cpuid, perf_env__{nr_}pmu_mappings
To be used by IBS raw data display: It needs the recorder's cpuid in order to determine which errata workarounds to apply to the data, and the pmu_mappings are needed in order to figure out which PMU sample type is IBS Fetch vs. IBS Op. When not available from perf.data, we assume local operation, and retrieve cpuid and pmu mappings directly from the running system. Signed-off-by: Kim Phillips <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Boris Ostrovsky <[email protected]> Cc: Ian Rogers <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Joao Martins <[email protected]> Cc: Konrad Rzeszutek Wilk <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Michael Petlan <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Robert Richter <[email protected]> Cc: Stephane Eranian <[email protected]> Link: https //lore.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent d2930ed commit 9fe8895

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

tools/perf/util/env.c

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <sys/utsname.h>
1111
#include <stdlib.h>
1212
#include <string.h>
13+
#include "strbuf.h"
1314

1415
struct perf_env perf_env;
1516

@@ -306,6 +307,45 @@ int perf_env__read_cpu_topology_map(struct perf_env *env)
306307
return 0;
307308
}
308309

310+
int perf_env__read_pmu_mappings(struct perf_env *env)
311+
{
312+
struct perf_pmu *pmu = NULL;
313+
u32 pmu_num = 0;
314+
struct strbuf sb;
315+
316+
while ((pmu = perf_pmu__scan(pmu))) {
317+
if (!pmu->name)
318+
continue;
319+
pmu_num++;
320+
}
321+
if (!pmu_num) {
322+
pr_debug("pmu mappings not available\n");
323+
return -ENOENT;
324+
}
325+
env->nr_pmu_mappings = pmu_num;
326+
327+
if (strbuf_init(&sb, 128 * pmu_num) < 0)
328+
return -ENOMEM;
329+
330+
while ((pmu = perf_pmu__scan(pmu))) {
331+
if (!pmu->name)
332+
continue;
333+
if (strbuf_addf(&sb, "%u:%s", pmu->type, pmu->name) < 0)
334+
goto error;
335+
/* include a NULL character at the end */
336+
if (strbuf_add(&sb, "", 1) < 0)
337+
goto error;
338+
}
339+
340+
env->pmu_mappings = strbuf_detach(&sb, NULL);
341+
342+
return 0;
343+
344+
error:
345+
strbuf_release(&sb);
346+
return -1;
347+
}
348+
309349
int perf_env__read_cpuid(struct perf_env *env)
310350
{
311351
char cpuid[128];
@@ -404,6 +444,44 @@ const char *perf_env__arch(struct perf_env *env)
404444
return normalize_arch(arch_name);
405445
}
406446

447+
const char *perf_env__cpuid(struct perf_env *env)
448+
{
449+
int status;
450+
451+
if (!env || !env->cpuid) { /* Assume local operation */
452+
status = perf_env__read_cpuid(env);
453+
if (status)
454+
return NULL;
455+
}
456+
457+
return env->cpuid;
458+
}
459+
460+
int perf_env__nr_pmu_mappings(struct perf_env *env)
461+
{
462+
int status;
463+
464+
if (!env || !env->nr_pmu_mappings) { /* Assume local operation */
465+
status = perf_env__read_pmu_mappings(env);
466+
if (status)
467+
return 0;
468+
}
469+
470+
return env->nr_pmu_mappings;
471+
}
472+
473+
const char *perf_env__pmu_mappings(struct perf_env *env)
474+
{
475+
int status;
476+
477+
if (!env || !env->pmu_mappings) { /* Assume local operation */
478+
status = perf_env__read_pmu_mappings(env);
479+
if (status)
480+
return NULL;
481+
}
482+
483+
return env->pmu_mappings;
484+
}
407485

408486
int perf_env__numa_node(struct perf_env *env, int cpu)
409487
{

tools/perf/util/env.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,16 @@ int perf_env__kernel_is_64_bit(struct perf_env *env);
149149
int perf_env__set_cmdline(struct perf_env *env, int argc, const char *argv[]);
150150

151151
int perf_env__read_cpuid(struct perf_env *env);
152+
int perf_env__read_pmu_mappings(struct perf_env *env);
153+
int perf_env__nr_pmu_mappings(struct perf_env *env);
154+
const char *perf_env__pmu_mappings(struct perf_env *env);
155+
152156
int perf_env__read_cpu_topology_map(struct perf_env *env);
153157

154158
void cpu_cache_level__free(struct cpu_cache_level *cache);
155159

156160
const char *perf_env__arch(struct perf_env *env);
161+
const char *perf_env__cpuid(struct perf_env *env);
157162
const char *perf_env__raw_arch(struct perf_env *env);
158163
int perf_env__nr_cpus_avail(struct perf_env *env);
159164

0 commit comments

Comments
 (0)