Commit 05530a79 authored by Ian Rogers's avatar Ian Rogers Committed by Arnaldo Carvalho de Melo

perf metricgroup: Add options to not group or merge

Add --metric-no-group that causes all events within metrics to not be
grouped. This can allow the event to get more time when multiplexed, but
may also lower accuracy.
Add --metric-no-merge option. By default events in different metrics may
be shared if the group of events for one metric is the same or larger
than that of the second. Sharing may increase or lower accuracy and so
is now configurable.
Signed-off-by: default avatarIan Rogers <irogers@google.com>
Acked-by: default avatarJiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Andrii Nakryiko <andriin@fb.com>
Cc: Cong Wang <xiyou.wangcong@gmail.com>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kim Phillips <kim.phillips@amd.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Song Liu <songliubraving@fb.com>
Cc: Srikar Dronamraju <srikar@linux.vnet.ibm.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Vince Weaver <vincent.weaver@maine.edu>
Cc: bpf@vger.kernel.org
Cc: netdev@vger.kernel.org
Link: http://lore.kernel.org/lkml/20200520182011.32236-7-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 2440689d
...@@ -236,6 +236,25 @@ filter out the startup phase of the program, which is often very different. ...@@ -236,6 +236,25 @@ filter out the startup phase of the program, which is often very different.
Print statistics of transactional execution if supported. Print statistics of transactional execution if supported.
--metric-no-group::
By default, events to compute a metric are placed in weak groups. The
group tries to enforce scheduling all or none of the events. The
--metric-no-group option places events outside of groups and may
increase the chance of the event being scheduled - leading to more
accuracy. However, as events may not be scheduled together accuracy
for metrics like instructions per cycle can be lower - as both metrics
may no longer be being measured at the same time.
--metric-no-merge::
By default metric events in different weak groups can be shared if one
group contains all the events needed by another. In such cases one
group will be eliminated reducing event multiplexing and making it so
that certain groups of metrics sum to 100%. A downside to sharing a
group is that the group may require multiplexing and so accuracy for a
small group that need not have multiplexing is lowered. This option
forbids the event merging logic from sharing events between groups and
may be used to increase accuracy in this case.
STAT RECORD STAT RECORD
----------- -----------
Stores stat data into perf data file. Stores stat data into perf data file.
......
...@@ -910,7 +910,10 @@ static int parse_metric_groups(const struct option *opt, ...@@ -910,7 +910,10 @@ static int parse_metric_groups(const struct option *opt,
const char *str, const char *str,
int unset __maybe_unused) int unset __maybe_unused)
{ {
return metricgroup__parse_groups(opt, str, &stat_config.metric_events); return metricgroup__parse_groups(opt, str,
stat_config.metric_no_group,
stat_config.metric_no_merge,
&stat_config.metric_events);
} }
static struct option stat_options[] = { static struct option stat_options[] = {
...@@ -988,6 +991,10 @@ static struct option stat_options[] = { ...@@ -988,6 +991,10 @@ static struct option stat_options[] = {
"ms to wait before starting measurement after program start"), "ms to wait before starting measurement after program start"),
OPT_CALLBACK_NOOPT(0, "metric-only", &stat_config.metric_only, NULL, OPT_CALLBACK_NOOPT(0, "metric-only", &stat_config.metric_only, NULL,
"Only print computed metrics. No raw values", enable_metric_only), "Only print computed metrics. No raw values", enable_metric_only),
OPT_BOOLEAN(0, "metric-no-group", &stat_config.metric_no_group,
"don't group metric events, impacts multiplexing"),
OPT_BOOLEAN(0, "metric-no-merge", &stat_config.metric_no_merge,
"don't try to share events between metrics in a group"),
OPT_BOOLEAN(0, "topdown", &topdown_run, OPT_BOOLEAN(0, "topdown", &topdown_run,
"measure topdown level 1 statistics"), "measure topdown level 1 statistics"),
OPT_BOOLEAN(0, "smi-cost", &smi_cost, OPT_BOOLEAN(0, "smi-cost", &smi_cost,
...@@ -1512,6 +1519,8 @@ static int add_default_attributes(void) ...@@ -1512,6 +1519,8 @@ static int add_default_attributes(void)
struct option opt = { .value = &evsel_list }; struct option opt = { .value = &evsel_list };
return metricgroup__parse_groups(&opt, "transaction", return metricgroup__parse_groups(&opt, "transaction",
stat_config.metric_no_group,
stat_config.metric_no_merge,
&stat_config.metric_events); &stat_config.metric_events);
} }
......
...@@ -95,11 +95,15 @@ struct egroup { ...@@ -95,11 +95,15 @@ struct egroup {
/** /**
* Find a group of events in perf_evlist that correpond to those from a parsed * Find a group of events in perf_evlist that correpond to those from a parsed
* metric expression. * metric expression. Note, as find_evsel_group is called in the same order as
* perf_evlist was constructed, metric_no_merge doesn't need to test for
* underfilling a group.
* @perf_evlist: a list of events something like: {metric1 leader, metric1 * @perf_evlist: a list of events something like: {metric1 leader, metric1
* sibling, metric1 sibling}:W,duration_time,{metric2 leader, metric2 sibling, * sibling, metric1 sibling}:W,duration_time,{metric2 leader, metric2 sibling,
* metric2 sibling}:W,duration_time * metric2 sibling}:W,duration_time
* @pctx: the parse context for the metric expression. * @pctx: the parse context for the metric expression.
* @metric_no_merge: don't attempt to share events for the metric with other
* metrics.
* @has_constraint: is there a contraint on the group of events? In which case * @has_constraint: is there a contraint on the group of events? In which case
* the events won't be grouped. * the events won't be grouped.
* @metric_events: out argument, null terminated array of evsel's associated * @metric_events: out argument, null terminated array of evsel's associated
...@@ -109,6 +113,7 @@ struct egroup { ...@@ -109,6 +113,7 @@ struct egroup {
*/ */
static struct evsel *find_evsel_group(struct evlist *perf_evlist, static struct evsel *find_evsel_group(struct evlist *perf_evlist,
struct expr_parse_ctx *pctx, struct expr_parse_ctx *pctx,
bool metric_no_merge,
bool has_constraint, bool has_constraint,
struct evsel **metric_events, struct evsel **metric_events,
unsigned long *evlist_used) unsigned long *evlist_used)
...@@ -132,6 +137,9 @@ static struct evsel *find_evsel_group(struct evlist *perf_evlist, ...@@ -132,6 +137,9 @@ static struct evsel *find_evsel_group(struct evlist *perf_evlist,
*/ */
if (has_constraint && ev->weak_group) if (has_constraint && ev->weak_group)
continue; continue;
/* Ignore event if already used and merging is disabled. */
if (metric_no_merge && test_bit(ev->idx, evlist_used))
continue;
if (!has_constraint && ev->leader != current_leader) { if (!has_constraint && ev->leader != current_leader) {
/* /*
* Start of a new group, discard the whole match and * Start of a new group, discard the whole match and
...@@ -142,8 +150,23 @@ static struct evsel *find_evsel_group(struct evlist *perf_evlist, ...@@ -142,8 +150,23 @@ static struct evsel *find_evsel_group(struct evlist *perf_evlist,
sizeof(struct evsel *) * idnum); sizeof(struct evsel *) * idnum);
current_leader = ev->leader; current_leader = ev->leader;
} }
if (hashmap__find(&pctx->ids, ev->name, (void **)&val_ptr)) if (hashmap__find(&pctx->ids, ev->name, (void **)&val_ptr)) {
if (has_constraint) {
/*
* Events aren't grouped, ensure the same event
* isn't matched from two groups.
*/
for (i = 0; i < matched_events; i++) {
if (!strcmp(ev->name,
metric_events[i]->name)) {
break;
}
}
if (i != matched_events)
continue;
}
metric_events[matched_events++] = ev; metric_events[matched_events++] = ev;
}
if (matched_events == events_to_match) if (matched_events == events_to_match)
break; break;
} }
...@@ -175,6 +198,7 @@ static struct evsel *find_evsel_group(struct evlist *perf_evlist, ...@@ -175,6 +198,7 @@ static struct evsel *find_evsel_group(struct evlist *perf_evlist,
} }
static int metricgroup__setup_events(struct list_head *groups, static int metricgroup__setup_events(struct list_head *groups,
bool metric_no_merge,
struct evlist *perf_evlist, struct evlist *perf_evlist,
struct rblist *metric_events_list) struct rblist *metric_events_list)
{ {
...@@ -200,8 +224,9 @@ static int metricgroup__setup_events(struct list_head *groups, ...@@ -200,8 +224,9 @@ static int metricgroup__setup_events(struct list_head *groups,
break; break;
} }
evsel = find_evsel_group(perf_evlist, &eg->pctx, evsel = find_evsel_group(perf_evlist, &eg->pctx,
eg->has_constraint, metric_events, metric_no_merge,
evlist_used); eg->has_constraint, metric_events,
evlist_used);
if (!evsel) { if (!evsel) {
pr_debug("Cannot resolve %s: %s\n", pr_debug("Cannot resolve %s: %s\n",
eg->metric_name, eg->metric_expr); eg->metric_name, eg->metric_expr);
...@@ -523,7 +548,9 @@ int __weak arch_get_runtimeparam(void) ...@@ -523,7 +548,9 @@ int __weak arch_get_runtimeparam(void)
} }
static int __metricgroup__add_metric(struct list_head *group_list, static int __metricgroup__add_metric(struct list_head *group_list,
struct pmu_event *pe, int runtime) struct pmu_event *pe,
bool metric_no_group,
int runtime)
{ {
struct egroup *eg; struct egroup *eg;
...@@ -536,7 +563,7 @@ static int __metricgroup__add_metric(struct list_head *group_list, ...@@ -536,7 +563,7 @@ static int __metricgroup__add_metric(struct list_head *group_list,
eg->metric_expr = pe->metric_expr; eg->metric_expr = pe->metric_expr;
eg->metric_unit = pe->unit; eg->metric_unit = pe->unit;
eg->runtime = runtime; eg->runtime = runtime;
eg->has_constraint = metricgroup__has_constraint(pe); eg->has_constraint = metric_no_group || metricgroup__has_constraint(pe);
if (expr__find_other(pe->metric_expr, NULL, &eg->pctx, runtime) < 0) { if (expr__find_other(pe->metric_expr, NULL, &eg->pctx, runtime) < 0) {
expr__ctx_clear(&eg->pctx); expr__ctx_clear(&eg->pctx);
...@@ -563,7 +590,8 @@ static int __metricgroup__add_metric(struct list_head *group_list, ...@@ -563,7 +590,8 @@ static int __metricgroup__add_metric(struct list_head *group_list,
return 0; return 0;
} }
static int metricgroup__add_metric(const char *metric, struct strbuf *events, static int metricgroup__add_metric(const char *metric, bool metric_no_group,
struct strbuf *events,
struct list_head *group_list) struct list_head *group_list)
{ {
struct pmu_events_map *map = perf_pmu__find_map(NULL); struct pmu_events_map *map = perf_pmu__find_map(NULL);
...@@ -593,7 +621,9 @@ static int metricgroup__add_metric(const char *metric, struct strbuf *events, ...@@ -593,7 +621,9 @@ static int metricgroup__add_metric(const char *metric, struct strbuf *events,
if (!strstr(pe->metric_expr, "?")) { if (!strstr(pe->metric_expr, "?")) {
ret = __metricgroup__add_metric(group_list, ret = __metricgroup__add_metric(group_list,
pe, 1); pe,
metric_no_group,
1);
if (ret) if (ret)
return ret; return ret;
} else { } else {
...@@ -608,7 +638,8 @@ static int metricgroup__add_metric(const char *metric, struct strbuf *events, ...@@ -608,7 +638,8 @@ static int metricgroup__add_metric(const char *metric, struct strbuf *events,
for (j = 0; j < count; j++) { for (j = 0; j < count; j++) {
ret = __metricgroup__add_metric( ret = __metricgroup__add_metric(
group_list, pe, j); group_list, pe,
metric_no_group, j);
if (ret) if (ret)
return ret; return ret;
} }
...@@ -630,7 +661,8 @@ static int metricgroup__add_metric(const char *metric, struct strbuf *events, ...@@ -630,7 +661,8 @@ static int metricgroup__add_metric(const char *metric, struct strbuf *events,
return 0; return 0;
} }
static int metricgroup__add_metric_list(const char *list, struct strbuf *events, static int metricgroup__add_metric_list(const char *list, bool metric_no_group,
struct strbuf *events,
struct list_head *group_list) struct list_head *group_list)
{ {
char *llist, *nlist, *p; char *llist, *nlist, *p;
...@@ -645,7 +677,8 @@ static int metricgroup__add_metric_list(const char *list, struct strbuf *events, ...@@ -645,7 +677,8 @@ static int metricgroup__add_metric_list(const char *list, struct strbuf *events,
strbuf_addf(events, "%s", ""); strbuf_addf(events, "%s", "");
while ((p = strsep(&llist, ",")) != NULL) { while ((p = strsep(&llist, ",")) != NULL) {
ret = metricgroup__add_metric(p, events, group_list); ret = metricgroup__add_metric(p, metric_no_group, events,
group_list);
if (ret == -EINVAL) { if (ret == -EINVAL) {
fprintf(stderr, "Cannot find metric or group `%s'\n", fprintf(stderr, "Cannot find metric or group `%s'\n",
p); p);
...@@ -672,8 +705,10 @@ static void metricgroup__free_egroups(struct list_head *group_list) ...@@ -672,8 +705,10 @@ static void metricgroup__free_egroups(struct list_head *group_list)
} }
int metricgroup__parse_groups(const struct option *opt, int metricgroup__parse_groups(const struct option *opt,
const char *str, const char *str,
struct rblist *metric_events) bool metric_no_group,
bool metric_no_merge,
struct rblist *metric_events)
{ {
struct parse_events_error parse_error; struct parse_events_error parse_error;
struct evlist *perf_evlist = *(struct evlist **)opt->value; struct evlist *perf_evlist = *(struct evlist **)opt->value;
...@@ -683,7 +718,8 @@ int metricgroup__parse_groups(const struct option *opt, ...@@ -683,7 +718,8 @@ int metricgroup__parse_groups(const struct option *opt,
if (metric_events->nr_entries == 0) if (metric_events->nr_entries == 0)
metricgroup__rblist_init(metric_events); metricgroup__rblist_init(metric_events);
ret = metricgroup__add_metric_list(str, &extra_events, &group_list); ret = metricgroup__add_metric_list(str, metric_no_group,
&extra_events, &group_list);
if (ret) if (ret)
return ret; return ret;
pr_debug("adding %s\n", extra_events.buf); pr_debug("adding %s\n", extra_events.buf);
...@@ -694,8 +730,8 @@ int metricgroup__parse_groups(const struct option *opt, ...@@ -694,8 +730,8 @@ int metricgroup__parse_groups(const struct option *opt,
goto out; goto out;
} }
strbuf_release(&extra_events); strbuf_release(&extra_events);
ret = metricgroup__setup_events(&group_list, perf_evlist, ret = metricgroup__setup_events(&group_list, metric_no_merge,
metric_events); perf_evlist, metric_events);
out: out:
metricgroup__free_egroups(&group_list); metricgroup__free_egroups(&group_list);
return ret; return ret;
......
...@@ -29,8 +29,10 @@ struct metric_event *metricgroup__lookup(struct rblist *metric_events, ...@@ -29,8 +29,10 @@ struct metric_event *metricgroup__lookup(struct rblist *metric_events,
struct evsel *evsel, struct evsel *evsel,
bool create); bool create);
int metricgroup__parse_groups(const struct option *opt, int metricgroup__parse_groups(const struct option *opt,
const char *str, const char *str,
struct rblist *metric_events); bool metric_no_group,
bool metric_no_merge,
struct rblist *metric_events);
void metricgroup__print(bool metrics, bool groups, char *filter, void metricgroup__print(bool metrics, bool groups, char *filter,
bool raw, bool details); bool raw, bool details);
......
...@@ -111,6 +111,8 @@ struct perf_stat_config { ...@@ -111,6 +111,8 @@ struct perf_stat_config {
bool all_user; bool all_user;
bool percore_show_thread; bool percore_show_thread;
bool summary; bool summary;
bool metric_no_group;
bool metric_no_merge;
FILE *output; FILE *output;
unsigned int interval; unsigned int interval;
unsigned int timeout; unsigned int timeout;
......
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