Skip to content

Commit 6a453d5

Browse files
perf tools: add infrastructure for PMU specific configuration
This patchset adds PMU driver specific configuration to the parser infrastructure by preceding any term with the '@' letter. As such doing something like: perf -e some_event/@drv1,@drv2=drv_config/ ... will see 'drv1' and 'drv2=config' being added to the list of evsel config terms. Token 'drv1' and 'drv2=config' are not processed in user space and are meant to be interpreted by the PMU driver. First the lexer/parser are supplemented with the required definitions to recognise the driver specific configuration. From there they are simply added to the list of event terms. The bulk of the work is done in function "parse_events_add_pmu()" where driver config event terms are added to a new list of driver config terms, which in turn spliced with the event's new driver configuration list. Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
1 parent 809a241 commit 6a453d5

6 files changed

Lines changed: 80 additions & 18 deletions

File tree

tools/perf/util/evsel.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ void perf_evsel__init(struct perf_evsel *evsel,
211211
evsel->bpf_fd = -1;
212212
INIT_LIST_HEAD(&evsel->node);
213213
INIT_LIST_HEAD(&evsel->config_terms);
214+
INIT_LIST_HEAD(&evsel->drv_config_terms);
214215
perf_evsel__object.init(evsel);
215216
evsel->sample_size = __perf_evsel__sample_size(attr->sample_type);
216217
perf_evsel__calc_id_pos(evsel);

tools/perf/util/evsel.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ enum {
4444
PERF_EVSEL__CONFIG_TERM_CALLGRAPH,
4545
PERF_EVSEL__CONFIG_TERM_STACK_USER,
4646
PERF_EVSEL__CONFIG_TERM_INHERIT,
47+
PERF_EVSEL__CONFIG_TERM_DRV_CFG,
4748
PERF_EVSEL__CONFIG_TERM_MAX,
4849
};
4950

@@ -55,6 +56,7 @@ struct perf_evsel_config_term {
5556
u64 freq;
5657
bool time;
5758
char *callgraph;
59+
char *drv_cfg;
5860
u64 stack_user;
5961
bool inherit;
6062
} val;
@@ -75,6 +77,7 @@ struct perf_evsel_config_term {
7577
* PERF_SAMPLE_IDENTIFIER) in a non-sample event i.e. if sample_id_all
7678
* is used there is an id sample appended to non-sample events
7779
* @priv: And what is in its containing unnamed union are tool specific
80+
* @drv_config_terms: List of configurables sent directly to the PMU driver
7881
*/
7982
struct perf_evsel {
8083
struct list_head node;
@@ -123,6 +126,7 @@ struct perf_evsel {
123126
char *group_name;
124127
bool cmdline_group_boundary;
125128
struct list_head config_terms;
129+
struct list_head drv_config_terms;
126130
int bpf_fd;
127131
};
128132

tools/perf/util/parse-events.c

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ static struct perf_evsel *
285285
__add_event(struct list_head *list, int *idx,
286286
struct perf_event_attr *attr,
287287
char *name, struct cpu_map *cpus,
288-
struct list_head *config_terms)
288+
struct list_head *config_terms,
289+
struct list_head *drv_config_terms)
289290
{
290291
struct perf_evsel *evsel;
291292

@@ -304,6 +305,9 @@ __add_event(struct list_head *list, int *idx,
304305
if (config_terms)
305306
list_splice(config_terms, &evsel->config_terms);
306307

308+
if (drv_config_terms)
309+
list_splice(drv_config_terms, &evsel->drv_config_terms);
310+
307311
list_add_tail(&evsel->node, list);
308312
return evsel;
309313
}
@@ -312,7 +316,8 @@ static int add_event(struct list_head *list, int *idx,
312316
struct perf_event_attr *attr, char *name,
313317
struct list_head *config_terms)
314318
{
315-
return __add_event(list, idx, attr, name, NULL, config_terms) ? 0 : -ENOMEM;
319+
return __add_event(list, idx, attr, name,
320+
NULL, config_terms, NULL) ? 0 : -ENOMEM;
316321
}
317322

318323
static int parse_aliases(char *str, const char *names[][PERF_EVSEL__MAX_ALIASES], int size)
@@ -823,7 +828,8 @@ static int config_term_pmu(struct perf_event_attr *attr,
823828
struct parse_events_term *term,
824829
struct parse_events_error *err)
825830
{
826-
if (term->type_term == PARSE_EVENTS__TERM_TYPE_USER)
831+
if (term->type_term == PARSE_EVENTS__TERM_TYPE_USER ||
832+
term->type_term == PARSE_EVENTS__TERM_TYPE_DRV_CFG)
827833
/*
828834
* Always succeed for sysfs terms, as we dont know
829835
* at this point what type they need to have.
@@ -869,10 +875,7 @@ static int config_attr(struct perf_event_attr *attr,
869875
return 0;
870876
}
871877

872-
static int get_config_terms(struct list_head *head_config,
873-
struct list_head *head_terms __maybe_unused)
874-
{
875-
#define ADD_CONFIG_TERM(__type, __name, __val) \
878+
#define ADD_CONFIG_TERM(__type, __name, __val, __head_terms) \
876879
do { \
877880
struct perf_evsel_config_term *__t; \
878881
\
@@ -883,33 +886,43 @@ do { \
883886
INIT_LIST_HEAD(&__t->list); \
884887
__t->type = PERF_EVSEL__CONFIG_TERM_ ## __type; \
885888
__t->val.__name = __val; \
886-
list_add_tail(&__t->list, head_terms); \
889+
list_add_tail(&__t->list, __head_terms); \
887890
} while (0)
888891

892+
static int get_config_terms(struct list_head *head_config,
893+
struct list_head *head_terms __maybe_unused)
894+
{
889895
struct parse_events_term *term;
890896

891897
list_for_each_entry(term, head_config, list) {
892898
switch (term->type_term) {
893899
case PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD:
894-
ADD_CONFIG_TERM(PERIOD, period, term->val.num);
900+
ADD_CONFIG_TERM(PERIOD, period,
901+
term->val.num, head_terms);
895902
break;
896903
case PARSE_EVENTS__TERM_TYPE_SAMPLE_FREQ:
897-
ADD_CONFIG_TERM(FREQ, freq, term->val.num);
904+
ADD_CONFIG_TERM(FREQ, freq,
905+
term->val.num, head_terms);
898906
break;
899907
case PARSE_EVENTS__TERM_TYPE_TIME:
900-
ADD_CONFIG_TERM(TIME, time, term->val.num);
908+
ADD_CONFIG_TERM(TIME, time,
909+
term->val.num, head_terms);
901910
break;
902911
case PARSE_EVENTS__TERM_TYPE_CALLGRAPH:
903-
ADD_CONFIG_TERM(CALLGRAPH, callgraph, term->val.str);
912+
ADD_CONFIG_TERM(CALLGRAPH, callgraph,
913+
term->val.str, head_terms);
904914
break;
905915
case PARSE_EVENTS__TERM_TYPE_STACKSIZE:
906-
ADD_CONFIG_TERM(STACK_USER, stack_user, term->val.num);
916+
ADD_CONFIG_TERM(STACK_USER, stack_user,
917+
term->val.num, head_terms);
907918
break;
908919
case PARSE_EVENTS__TERM_TYPE_INHERIT:
909-
ADD_CONFIG_TERM(INHERIT, inherit, term->val.num ? 1 : 0);
920+
ADD_CONFIG_TERM(INHERIT, inherit,
921+
term->val.num ? 1 : 0, head_terms);
910922
break;
911923
case PARSE_EVENTS__TERM_TYPE_NOINHERIT:
912-
ADD_CONFIG_TERM(INHERIT, inherit, term->val.num ? 0 : 1);
924+
ADD_CONFIG_TERM(INHERIT, inherit,
925+
term->val.num ? 0 : 1, head_terms);
913926
break;
914927
default:
915928
break;
@@ -919,6 +932,21 @@ do { \
919932
return 0;
920933
}
921934

935+
static int get_drv_config_terms(struct list_head *head_config,
936+
struct list_head *head_terms)
937+
{
938+
struct parse_events_term *term;
939+
940+
list_for_each_entry(term, head_config, list) {
941+
if (term->type_term != PARSE_EVENTS__TERM_TYPE_DRV_CFG)
942+
continue;
943+
944+
ADD_CONFIG_TERM(DRV_CFG, drv_cfg, term->val.str, head_terms);
945+
}
946+
947+
return 0;
948+
}
949+
922950
int parse_events_add_tracepoint(struct list_head *list, int *idx,
923951
char *sys, char *event,
924952
struct parse_events_error *err,
@@ -989,6 +1017,7 @@ int parse_events_add_pmu(struct parse_events_evlist *data,
9891017
struct perf_pmu *pmu;
9901018
struct perf_evsel *evsel;
9911019
LIST_HEAD(config_terms);
1020+
LIST_HEAD(drv_config_terms);
9921021

9931022
pmu = perf_pmu__find(name);
9941023
if (!pmu)
@@ -1003,7 +1032,8 @@ int parse_events_add_pmu(struct parse_events_evlist *data,
10031032

10041033
if (!head_config) {
10051034
attr.type = pmu->type;
1006-
evsel = __add_event(list, &data->idx, &attr, NULL, pmu->cpus, NULL);
1035+
evsel = __add_event(list, &data->idx, &attr,
1036+
NULL, pmu->cpus, NULL, NULL);
10071037
return evsel ? 0 : -ENOMEM;
10081038
}
10091039

@@ -1020,12 +1050,15 @@ int parse_events_add_pmu(struct parse_events_evlist *data,
10201050
if (get_config_terms(head_config, &config_terms))
10211051
return -ENOMEM;
10221052

1053+
if (get_drv_config_terms(head_config, &drv_config_terms))
1054+
return -ENOMEM;
1055+
10231056
if (perf_pmu__config(pmu, &attr, head_config, data->error))
10241057
return -EINVAL;
10251058

10261059
evsel = __add_event(list, &data->idx, &attr,
10271060
pmu_event_name(head_config), pmu->cpus,
1028-
&config_terms);
1061+
&config_terms, &drv_config_terms);
10291062
if (evsel) {
10301063
evsel->unit = info.unit;
10311064
evsel->scale = info.scale;

tools/perf/util/parse-events.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ enum {
6868
PARSE_EVENTS__TERM_TYPE_CALLGRAPH,
6969
PARSE_EVENTS__TERM_TYPE_STACKSIZE,
7070
PARSE_EVENTS__TERM_TYPE_NOINHERIT,
71-
PARSE_EVENTS__TERM_TYPE_INHERIT
71+
PARSE_EVENTS__TERM_TYPE_INHERIT,
72+
PARSE_EVENTS__TERM_TYPE_DRV_CFG,
7273
};
7374

7475
struct parse_events_term {

tools/perf/util/parse-events.l

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ static int str(yyscan_t scanner, int token)
5353
return token;
5454
}
5555

56+
static int drv_str(yyscan_t scanner, int token)
57+
{
58+
YYSTYPE *yylval = parse_events_get_lval(scanner);
59+
char *text = parse_events_get_text(scanner);
60+
61+
/* Strip off the '@' */
62+
yylval->str = strdup(text + 1);
63+
return token;
64+
}
65+
5666
#define REWIND(__alloc) \
5767
do { \
5868
YYSTYPE *__yylval = parse_events_get_lval(yyscanner); \
@@ -123,6 +133,7 @@ num_hex 0x[a-fA-F0-9]+
123133
num_raw_hex [a-fA-F0-9]+
124134
name [a-zA-Z_*?][a-zA-Z0-9_*?.]*
125135
name_minus [a-zA-Z_*?][a-zA-Z0-9\-_*?.]*
136+
drv_cfg_term [a-zA-Z0-9_\.]+(=[a-zA-Z0-9_*?\.:]+)?
126137
/* If you add a modifier you need to update check_modifier() */
127138
modifier_event [ukhpPGHSDI]+
128139
modifier_bp [rwx]{1,3}
@@ -196,6 +207,7 @@ no-inherit { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_NOINHERIT); }
196207
, { return ','; }
197208
"/" { BEGIN(INITIAL); return '/'; }
198209
{name_minus} { return str(yyscanner, PE_NAME); }
210+
@{drv_cfg_term} { return drv_str(yyscanner, PE_DRV_CFG_TERM); }
199211
}
200212

201213
<mem>{

tools/perf/util/parse-events.y

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ static inc_group_count(struct list_head *list,
4848
%token PE_PREFIX_MEM PE_PREFIX_RAW PE_PREFIX_GROUP
4949
%token PE_ERROR
5050
%token PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_KERNEL_PMU_EVENT
51+
%token PE_DRV_CFG_TERM
5152
%type <num> PE_VALUE
5253
%type <num> PE_VALUE_SYM_HW
5354
%type <num> PE_VALUE_SYM_SW
@@ -62,6 +63,7 @@ static inc_group_count(struct list_head *list,
6263
%type <str> PE_MODIFIER_BP
6364
%type <str> PE_EVENT_NAME
6465
%type <str> PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_KERNEL_PMU_EVENT
66+
%type <str> PE_DRV_CFG_TERM
6567
%type <num> value_sym
6668
%type <head> event_config
6769
%type <term> event_term
@@ -573,6 +575,15 @@ PE_TERM
573575
ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, 1, &@1, NULL));
574576
$$ = term;
575577
}
578+
|
579+
PE_DRV_CFG_TERM
580+
{
581+
struct parse_events_term *term;
582+
583+
ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_DRV_CFG,
584+
$1, $1, &@1, NULL));
585+
$$ = term;
586+
}
576587

577588
sep_dc: ':' |
578589

0 commit comments

Comments
 (0)