Commit dc0a6202 authored by Adrian Hunter's avatar Adrian Hunter Committed by Arnaldo Carvalho de Melo

perf tools: Let default config be defined for a PMU

This allows default config terms to be provided for a PMU. So, for
example, when the Intel PT PMU is added, it will be possible to specify:

	intel_pt//

which will be the same as:

	intel_pt/tsc=1,noretcomp=0/

meaning that the trace should contain TSC timestamps and perform 'return
compression'.

An important consideration of this patch is that it must be possible to
overwrite the default values.  That has meant changing the logic so that
a zero value can replace a non-zero value.
Signed-off-by: default avatarAdrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1406786474-9306-7-git-send-email-adrian.hunter@intel.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent c501e90b
...@@ -152,7 +152,7 @@ int test__pmu(void) ...@@ -152,7 +152,7 @@ int test__pmu(void)
if (ret) if (ret)
break; break;
ret = perf_pmu__config_terms(&formats, &attr, terms); ret = perf_pmu__config_terms(&formats, &attr, terms, false);
if (ret) if (ret)
break; break;
......
...@@ -643,7 +643,12 @@ int parse_events_add_pmu(struct list_head *list, int *idx, ...@@ -643,7 +643,12 @@ int parse_events_add_pmu(struct list_head *list, int *idx,
if (!pmu) if (!pmu)
return -EINVAL; return -EINVAL;
if (pmu->default_config) {
memcpy(&attr, pmu->default_config,
sizeof(struct perf_event_attr));
} else {
memset(&attr, 0, sizeof(attr)); memset(&attr, 0, sizeof(attr));
}
if (!head_config) { if (!head_config) {
attr.type = pmu->type; attr.type = pmu->type;
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <stdbool.h>
#include <dirent.h> #include <dirent.h>
#include <api/fs/fs.h> #include <api/fs/fs.h>
#include <locale.h> #include <locale.h>
...@@ -387,6 +388,12 @@ static struct cpu_map *pmu_cpumask(const char *name) ...@@ -387,6 +388,12 @@ static struct cpu_map *pmu_cpumask(const char *name)
return cpus; return cpus;
} }
struct perf_event_attr *__attribute__((weak))
perf_pmu__get_default_config(struct perf_pmu *pmu __maybe_unused)
{
return NULL;
}
static struct perf_pmu *pmu_lookup(const char *name) static struct perf_pmu *pmu_lookup(const char *name)
{ {
struct perf_pmu *pmu; struct perf_pmu *pmu;
...@@ -421,6 +428,9 @@ static struct perf_pmu *pmu_lookup(const char *name) ...@@ -421,6 +428,9 @@ static struct perf_pmu *pmu_lookup(const char *name)
pmu->name = strdup(name); pmu->name = strdup(name);
pmu->type = type; pmu->type = type;
list_add_tail(&pmu->list, &pmus); list_add_tail(&pmu->list, &pmus);
pmu->default_config = perf_pmu__get_default_config(pmu);
return pmu; return pmu;
} }
...@@ -479,28 +489,24 @@ pmu_find_format(struct list_head *formats, char *name) ...@@ -479,28 +489,24 @@ pmu_find_format(struct list_head *formats, char *name)
} }
/* /*
* Returns value based on the format definition (format parameter) * Sets value based on the format definition (format parameter)
* and unformated value (value parameter). * and unformated value (value parameter).
*
* TODO maybe optimize a little ;)
*/ */
static __u64 pmu_format_value(unsigned long *format, __u64 value) static void pmu_format_value(unsigned long *format, __u64 value, __u64 *v,
bool zero)
{ {
unsigned long fbit, vbit; unsigned long fbit, vbit;
__u64 v = 0;
for (fbit = 0, vbit = 0; fbit < PERF_PMU_FORMAT_BITS; fbit++) { for (fbit = 0, vbit = 0; fbit < PERF_PMU_FORMAT_BITS; fbit++) {
if (!test_bit(fbit, format)) if (!test_bit(fbit, format))
continue; continue;
if (!(value & (1llu << vbit++))) if (value & (1llu << vbit++))
continue; *v |= (1llu << fbit);
else if (zero)
v |= (1llu << fbit); *v &= ~(1llu << fbit);
} }
return v;
} }
/* /*
...@@ -509,7 +515,8 @@ static __u64 pmu_format_value(unsigned long *format, __u64 value) ...@@ -509,7 +515,8 @@ static __u64 pmu_format_value(unsigned long *format, __u64 value)
*/ */
static int pmu_config_term(struct list_head *formats, static int pmu_config_term(struct list_head *formats,
struct perf_event_attr *attr, struct perf_event_attr *attr,
struct parse_events_term *term) struct parse_events_term *term,
bool zero)
{ {
struct perf_pmu_format *format; struct perf_pmu_format *format;
__u64 *vp; __u64 *vp;
...@@ -548,18 +555,19 @@ static int pmu_config_term(struct list_head *formats, ...@@ -548,18 +555,19 @@ static int pmu_config_term(struct list_head *formats,
* non-hardcoded terms, here's the place to translate * non-hardcoded terms, here's the place to translate
* them into value. * them into value.
*/ */
*vp |= pmu_format_value(format->bits, term->val.num); pmu_format_value(format->bits, term->val.num, vp, zero);
return 0; return 0;
} }
int perf_pmu__config_terms(struct list_head *formats, int perf_pmu__config_terms(struct list_head *formats,
struct perf_event_attr *attr, struct perf_event_attr *attr,
struct list_head *head_terms) struct list_head *head_terms,
bool zero)
{ {
struct parse_events_term *term; struct parse_events_term *term;
list_for_each_entry(term, head_terms, list) list_for_each_entry(term, head_terms, list)
if (pmu_config_term(formats, attr, term)) if (pmu_config_term(formats, attr, term, zero))
return -EINVAL; return -EINVAL;
return 0; return 0;
...@@ -573,8 +581,10 @@ int perf_pmu__config_terms(struct list_head *formats, ...@@ -573,8 +581,10 @@ int perf_pmu__config_terms(struct list_head *formats,
int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr, int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr,
struct list_head *head_terms) struct list_head *head_terms)
{ {
bool zero = !!pmu->default_config;
attr->type = pmu->type; attr->type = pmu->type;
return perf_pmu__config_terms(&pmu->format, attr, head_terms); return perf_pmu__config_terms(&pmu->format, attr, head_terms, zero);
} }
static struct perf_pmu_alias *pmu_find_alias(struct perf_pmu *pmu, static struct perf_pmu_alias *pmu_find_alias(struct perf_pmu *pmu,
......
...@@ -13,9 +13,12 @@ enum { ...@@ -13,9 +13,12 @@ enum {
#define PERF_PMU_FORMAT_BITS 64 #define PERF_PMU_FORMAT_BITS 64
struct perf_event_attr;
struct perf_pmu { struct perf_pmu {
char *name; char *name;
__u32 type; __u32 type;
struct perf_event_attr *default_config;
struct cpu_map *cpus; struct cpu_map *cpus;
struct list_head format; /* HEAD struct perf_pmu_format -> list */ struct list_head format; /* HEAD struct perf_pmu_format -> list */
struct list_head aliases; /* HEAD struct perf_pmu_alias -> list */ struct list_head aliases; /* HEAD struct perf_pmu_alias -> list */
...@@ -27,7 +30,8 @@ int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr, ...@@ -27,7 +30,8 @@ int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr,
struct list_head *head_terms); struct list_head *head_terms);
int perf_pmu__config_terms(struct list_head *formats, int perf_pmu__config_terms(struct list_head *formats,
struct perf_event_attr *attr, struct perf_event_attr *attr,
struct list_head *head_terms); struct list_head *head_terms,
bool zero);
int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms, int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms,
const char **unit, double *scale); const char **unit, double *scale);
struct list_head *perf_pmu__alias(struct perf_pmu *pmu, struct list_head *perf_pmu__alias(struct perf_pmu *pmu,
...@@ -46,4 +50,7 @@ void print_pmu_events(const char *event_glob, bool name_only); ...@@ -46,4 +50,7 @@ void print_pmu_events(const char *event_glob, bool name_only);
bool pmu_have_event(const char *pname, const char *name); bool pmu_have_event(const char *pname, const char *name);
int perf_pmu__test(void); int perf_pmu__test(void);
struct perf_event_attr *perf_pmu__get_default_config(struct perf_pmu *pmu);
#endif /* __PMU_H */ #endif /* __PMU_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment