Skip to content

Commit be335ec

Browse files
John Garryacmel
John Garry
authored andcommitted
perf metricgroup: Support adding metrics for system PMUs
Currently adding metrics for core- or uncore-based events matched by CPUID is supported. Extend this for system events. Signed-off-by: John Garry <[email protected]> Acked-by: Kajol Jain <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Ian Rogers <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Joakim Zhang <[email protected]> Cc: Kan Liang <[email protected]> Cc: Kim Phillips <[email protected]> Cc: Leo Yan <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Mathieu Poirier <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Shaokun Zhang <[email protected]> Cc: Will Deacon <[email protected]> Cc: [email protected] Cc: [email protected] Link: http://lore.kernel.org/lkml/[email protected] [ Reorder 'struct metricgroup_add_iter_data' field to avoid alignment holes ] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent a36fadb commit be335ec

File tree

1 file changed

+60
-6
lines changed

1 file changed

+60
-6
lines changed

tools/perf/util/metricgroup.c

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,12 @@ static bool match_metric(const char *n, const char *list)
415415
return false;
416416
}
417417

418+
static bool match_pe_metric(struct pmu_event *pe, const char *metric)
419+
{
420+
return match_metric(pe->metric_group, metric) ||
421+
match_metric(pe->metric_name, metric);
422+
}
423+
418424
struct mep {
419425
struct rb_node nd;
420426
const char *name;
@@ -757,6 +763,16 @@ int __weak arch_get_runtimeparam(struct pmu_event *pe __maybe_unused)
757763
return 1;
758764
}
759765

766+
struct metricgroup_add_iter_data {
767+
struct list_head *metric_list;
768+
const char *metric;
769+
struct metric **m;
770+
struct expr_ids *ids;
771+
int *ret;
772+
bool *has_match;
773+
bool metric_no_group;
774+
};
775+
760776
static int __add_metric(struct list_head *metric_list,
761777
struct pmu_event *pe,
762778
bool metric_no_group,
@@ -866,10 +882,11 @@ static int __add_metric(struct list_head *metric_list,
866882
return 0;
867883
}
868884

869-
#define map_for_each_event(__pe, __idx, __map) \
870-
for (__idx = 0, __pe = &__map->table[__idx]; \
871-
__pe->name || __pe->metric_group || __pe->metric_name; \
872-
__pe = &__map->table[++__idx])
885+
#define map_for_each_event(__pe, __idx, __map) \
886+
if (__map) \
887+
for (__idx = 0, __pe = &__map->table[__idx]; \
888+
__pe->name || __pe->metric_group || __pe->metric_name; \
889+
__pe = &__map->table[++__idx])
873890

874891
#define map_for_each_metric(__pe, __idx, __map, __metric) \
875892
map_for_each_event(__pe, __idx, __map) \
@@ -1037,6 +1054,29 @@ static int add_metric(struct list_head *metric_list,
10371054
return ret;
10381055
}
10391056

1057+
static int metricgroup__add_metric_sys_event_iter(struct pmu_event *pe,
1058+
void *data)
1059+
{
1060+
struct metricgroup_add_iter_data *d = data;
1061+
int ret;
1062+
1063+
if (!match_pe_metric(pe, d->metric))
1064+
return 0;
1065+
1066+
ret = add_metric(d->metric_list, pe, d->metric_no_group, d->m, NULL, d->ids);
1067+
if (ret)
1068+
return ret;
1069+
1070+
ret = resolve_metric(d->metric_no_group,
1071+
d->metric_list, NULL, d->ids);
1072+
if (ret)
1073+
return ret;
1074+
1075+
*(d->has_match) = true;
1076+
1077+
return *d->ret;
1078+
}
1079+
10401080
static int metricgroup__add_metric(const char *metric, bool metric_no_group,
10411081
struct strbuf *events,
10421082
struct list_head *metric_list,
@@ -1067,6 +1107,22 @@ static int metricgroup__add_metric(const char *metric, bool metric_no_group,
10671107
goto out;
10681108
}
10691109

1110+
{
1111+
struct metricgroup_iter_data data = {
1112+
.fn = metricgroup__add_metric_sys_event_iter,
1113+
.data = (void *) &(struct metricgroup_add_iter_data) {
1114+
.metric_list = &list,
1115+
.metric = metric,
1116+
.metric_no_group = metric_no_group,
1117+
.m = &m,
1118+
.ids = &ids,
1119+
.has_match = &has_match,
1120+
.ret = &ret,
1121+
},
1122+
};
1123+
1124+
pmu_for_each_sys_event(metricgroup__sys_event_iter, &data);
1125+
}
10701126
/* End of pmu events. */
10711127
if (!has_match) {
10721128
ret = -EINVAL;
@@ -1193,8 +1249,6 @@ int metricgroup__parse_groups(const struct option *opt,
11931249
struct evlist *perf_evlist = *(struct evlist **)opt->value;
11941250
struct pmu_events_map *map = perf_pmu__find_map(NULL);
11951251

1196-
if (!map)
1197-
return 0;
11981252

11991253
return parse_groups(perf_evlist, str, metric_no_group,
12001254
metric_no_merge, NULL, metric_events, map);

0 commit comments

Comments
 (0)