Commit 1fd09e29 authored by Ian Rogers's avatar Ian Rogers Committed by Arnaldo Carvalho de Melo

perf metric: Add --metric-no-threshold option

Thresholds may need additional events, this can impact things like
sharing groups of events to avoid multiplexing. Add a flag to make the
threshold calculations optional. The threshold will still be computed
if no additional events are necessary.
Signed-off-by: default avatarIan Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
Cc: Andrii Nakryiko <andrii@kernel.org>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Eduard Zingerman <eddyz87@gmail.com>
Cc: Florian Fischer <florian.fischer@muhq.space>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Sean Christopherson <seanjc@google.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-stm32@st-md-mailman.stormreply.com
Link: https://lore.kernel.org/r/20230219092848.639226-39-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 79802934
...@@ -1256,6 +1256,8 @@ static struct option stat_options[] = { ...@@ -1256,6 +1256,8 @@ static struct option stat_options[] = {
"don't group metric events, impacts multiplexing"), "don't group metric events, impacts multiplexing"),
OPT_BOOLEAN(0, "metric-no-merge", &stat_config.metric_no_merge, OPT_BOOLEAN(0, "metric-no-merge", &stat_config.metric_no_merge,
"don't try to share events between metrics in a group"), "don't try to share events between metrics in a group"),
OPT_BOOLEAN(0, "metric-no-threshold", &stat_config.metric_no_threshold,
"don't try to share events between metrics in a group "),
OPT_BOOLEAN(0, "topdown", &topdown_run, OPT_BOOLEAN(0, "topdown", &topdown_run,
"measure top-down statistics"), "measure top-down statistics"),
OPT_UINTEGER(0, "td-level", &stat_config.topdown_level, OPT_UINTEGER(0, "td-level", &stat_config.topdown_level,
...@@ -1852,6 +1854,7 @@ static int add_default_attributes(void) ...@@ -1852,6 +1854,7 @@ static int add_default_attributes(void)
return metricgroup__parse_groups(evsel_list, "transaction", return metricgroup__parse_groups(evsel_list, "transaction",
stat_config.metric_no_group, stat_config.metric_no_group,
stat_config.metric_no_merge, stat_config.metric_no_merge,
stat_config.metric_no_threshold,
stat_config.user_requested_cpu_list, stat_config.user_requested_cpu_list,
stat_config.system_wide, stat_config.system_wide,
&stat_config.metric_events); &stat_config.metric_events);
...@@ -2519,6 +2522,7 @@ int cmd_stat(int argc, const char **argv) ...@@ -2519,6 +2522,7 @@ int cmd_stat(int argc, const char **argv)
metricgroup__parse_groups(evsel_list, metrics, metricgroup__parse_groups(evsel_list, metrics,
stat_config.metric_no_group, stat_config.metric_no_group,
stat_config.metric_no_merge, stat_config.metric_no_merge,
stat_config.metric_no_threshold,
stat_config.user_requested_cpu_list, stat_config.user_requested_cpu_list,
stat_config.system_wide, stat_config.system_wide,
&stat_config.metric_events); &stat_config.metric_events);
......
...@@ -187,8 +187,7 @@ static int expand_metric_events(void) ...@@ -187,8 +187,7 @@ static int expand_metric_events(void)
rblist__init(&metric_events); rblist__init(&metric_events);
pme_test = find_core_metrics_table("testarch", "testcpu"); pme_test = find_core_metrics_table("testarch", "testcpu");
ret = metricgroup__parse_groups_test(evlist, pme_test, metric_str, ret = metricgroup__parse_groups_test(evlist, pme_test, metric_str, &metric_events);
false, false, &metric_events);
if (ret < 0) { if (ret < 0) {
pr_debug("failed to parse '%s' metric\n", metric_str); pr_debug("failed to parse '%s' metric\n", metric_str);
goto out; goto out;
......
...@@ -98,7 +98,6 @@ static int __compute_metric(const char *name, struct value *vals, ...@@ -98,7 +98,6 @@ static int __compute_metric(const char *name, struct value *vals,
/* Parse the metric into metric_events list. */ /* Parse the metric into metric_events list. */
pme_test = find_core_metrics_table("testarch", "testcpu"); pme_test = find_core_metrics_table("testarch", "testcpu");
err = metricgroup__parse_groups_test(evlist, pme_test, name, err = metricgroup__parse_groups_test(evlist, pme_test, name,
false, false,
&metric_events); &metric_events);
if (err) if (err)
goto out; goto out;
......
...@@ -846,9 +846,7 @@ static int test__parsing_callback(const struct pmu_metric *pm, ...@@ -846,9 +846,7 @@ static int test__parsing_callback(const struct pmu_metric *pm,
perf_evlist__set_maps(&evlist->core, cpus, NULL); perf_evlist__set_maps(&evlist->core, cpus, NULL);
runtime_stat__init(&st); runtime_stat__init(&st);
err = metricgroup__parse_groups_test(evlist, table, pm->metric_name, err = metricgroup__parse_groups_test(evlist, table, pm->metric_name, &metric_events);
false, false,
&metric_events);
if (err) { if (err) {
if (!strcmp(pm->metric_name, "M1") || !strcmp(pm->metric_name, "M2") || if (!strcmp(pm->metric_name, "M1") || !strcmp(pm->metric_name, "M2") ||
!strcmp(pm->metric_name, "M3")) { !strcmp(pm->metric_name, "M3")) {
......
...@@ -771,6 +771,7 @@ struct metricgroup_add_iter_data { ...@@ -771,6 +771,7 @@ struct metricgroup_add_iter_data {
int *ret; int *ret;
bool *has_match; bool *has_match;
bool metric_no_group; bool metric_no_group;
bool metric_no_threshold;
const char *user_requested_cpu_list; const char *user_requested_cpu_list;
bool system_wide; bool system_wide;
struct metric *root_metric; struct metric *root_metric;
...@@ -786,6 +787,7 @@ static int add_metric(struct list_head *metric_list, ...@@ -786,6 +787,7 @@ static int add_metric(struct list_head *metric_list,
const struct pmu_metric *pm, const struct pmu_metric *pm,
const char *modifier, const char *modifier,
bool metric_no_group, bool metric_no_group,
bool metric_no_threshold,
const char *user_requested_cpu_list, const char *user_requested_cpu_list,
bool system_wide, bool system_wide,
struct metric *root_metric, struct metric *root_metric,
...@@ -813,6 +815,7 @@ static int add_metric(struct list_head *metric_list, ...@@ -813,6 +815,7 @@ static int add_metric(struct list_head *metric_list,
static int resolve_metric(struct list_head *metric_list, static int resolve_metric(struct list_head *metric_list,
const char *modifier, const char *modifier,
bool metric_no_group, bool metric_no_group,
bool metric_no_threshold,
const char *user_requested_cpu_list, const char *user_requested_cpu_list,
bool system_wide, bool system_wide,
struct metric *root_metric, struct metric *root_metric,
...@@ -861,8 +864,8 @@ static int resolve_metric(struct list_head *metric_list, ...@@ -861,8 +864,8 @@ static int resolve_metric(struct list_head *metric_list,
*/ */
for (i = 0; i < pending_cnt; i++) { for (i = 0; i < pending_cnt; i++) {
ret = add_metric(metric_list, &pending[i].pm, modifier, metric_no_group, ret = add_metric(metric_list, &pending[i].pm, modifier, metric_no_group,
user_requested_cpu_list, system_wide, root_metric, visited, metric_no_threshold, user_requested_cpu_list, system_wide,
table); root_metric, visited, table);
if (ret) if (ret)
break; break;
} }
...@@ -879,6 +882,7 @@ static int resolve_metric(struct list_head *metric_list, ...@@ -879,6 +882,7 @@ static int resolve_metric(struct list_head *metric_list,
* @metric_no_group: Should events written to events be grouped "{}" or * @metric_no_group: Should events written to events be grouped "{}" or
* global. Grouping is the default but due to multiplexing the * global. Grouping is the default but due to multiplexing the
* user may override. * user may override.
* @metric_no_threshold: Should threshold expressions be ignored?
* @runtime: A special argument for the parser only known at runtime. * @runtime: A special argument for the parser only known at runtime.
* @user_requested_cpu_list: Command line specified CPUs to record on. * @user_requested_cpu_list: Command line specified CPUs to record on.
* @system_wide: Are events for all processes recorded. * @system_wide: Are events for all processes recorded.
...@@ -894,6 +898,7 @@ static int __add_metric(struct list_head *metric_list, ...@@ -894,6 +898,7 @@ static int __add_metric(struct list_head *metric_list,
const struct pmu_metric *pm, const struct pmu_metric *pm,
const char *modifier, const char *modifier,
bool metric_no_group, bool metric_no_group,
bool metric_no_threshold,
int runtime, int runtime,
const char *user_requested_cpu_list, const char *user_requested_cpu_list,
bool system_wide, bool system_wide,
...@@ -974,10 +979,12 @@ static int __add_metric(struct list_head *metric_list, ...@@ -974,10 +979,12 @@ static int __add_metric(struct list_head *metric_list,
* Threshold expressions are built off the actual metric. Switch * Threshold expressions are built off the actual metric. Switch
* to use that in case of additional necessary events. Change * to use that in case of additional necessary events. Change
* the visited node name to avoid this being flagged as * the visited node name to avoid this being flagged as
* recursion. * recursion. If the threshold events are disabled, just use the
* metric's name as a reference. This allows metric threshold
* computation if there are sufficient events.
*/ */
assert(strstr(pm->metric_threshold, pm->metric_name)); assert(strstr(pm->metric_threshold, pm->metric_name));
expr = pm->metric_threshold; expr = metric_no_threshold ? pm->metric_name : pm->metric_threshold;
visited_node.name = "__threshold__"; visited_node.name = "__threshold__";
} }
if (expr__find_ids(expr, NULL, root_metric->pctx) < 0) { if (expr__find_ids(expr, NULL, root_metric->pctx) < 0) {
...@@ -987,8 +994,8 @@ static int __add_metric(struct list_head *metric_list, ...@@ -987,8 +994,8 @@ static int __add_metric(struct list_head *metric_list,
if (!ret) { if (!ret) {
/* Resolve referenced metrics. */ /* Resolve referenced metrics. */
ret = resolve_metric(metric_list, modifier, metric_no_group, ret = resolve_metric(metric_list, modifier, metric_no_group,
user_requested_cpu_list, system_wide, metric_no_threshold, user_requested_cpu_list,
root_metric, &visited_node, table); system_wide, root_metric, &visited_node, table);
} }
if (ret) { if (ret) {
if (is_root) if (is_root)
...@@ -1035,6 +1042,7 @@ static int add_metric(struct list_head *metric_list, ...@@ -1035,6 +1042,7 @@ static int add_metric(struct list_head *metric_list,
const struct pmu_metric *pm, const struct pmu_metric *pm,
const char *modifier, const char *modifier,
bool metric_no_group, bool metric_no_group,
bool metric_no_threshold,
const char *user_requested_cpu_list, const char *user_requested_cpu_list,
bool system_wide, bool system_wide,
struct metric *root_metric, struct metric *root_metric,
...@@ -1046,9 +1054,9 @@ static int add_metric(struct list_head *metric_list, ...@@ -1046,9 +1054,9 @@ static int add_metric(struct list_head *metric_list,
pr_debug("metric expr %s for %s\n", pm->metric_expr, pm->metric_name); pr_debug("metric expr %s for %s\n", pm->metric_expr, pm->metric_name);
if (!strstr(pm->metric_expr, "?")) { if (!strstr(pm->metric_expr, "?")) {
ret = __add_metric(metric_list, pm, modifier, metric_no_group, 0, ret = __add_metric(metric_list, pm, modifier, metric_no_group,
user_requested_cpu_list, system_wide, root_metric, metric_no_threshold, 0, user_requested_cpu_list,
visited, table); system_wide, root_metric, visited, table);
} else { } else {
int j, count; int j, count;
...@@ -1060,9 +1068,9 @@ static int add_metric(struct list_head *metric_list, ...@@ -1060,9 +1068,9 @@ static int add_metric(struct list_head *metric_list,
*/ */
for (j = 0; j < count && !ret; j++) for (j = 0; j < count && !ret; j++)
ret = __add_metric(metric_list, pm, modifier, metric_no_group, j, ret = __add_metric(metric_list, pm, modifier, metric_no_group,
user_requested_cpu_list, system_wide, metric_no_threshold, j, user_requested_cpu_list,
root_metric, visited, table); system_wide, root_metric, visited, table);
} }
return ret; return ret;
...@@ -1079,8 +1087,8 @@ static int metricgroup__add_metric_sys_event_iter(const struct pmu_metric *pm, ...@@ -1079,8 +1087,8 @@ static int metricgroup__add_metric_sys_event_iter(const struct pmu_metric *pm,
return 0; return 0;
ret = add_metric(d->metric_list, pm, d->modifier, d->metric_no_group, ret = add_metric(d->metric_list, pm, d->modifier, d->metric_no_group,
d->user_requested_cpu_list, d->system_wide, d->metric_no_threshold, d->user_requested_cpu_list,
d->root_metric, d->visited, d->table); d->system_wide, d->root_metric, d->visited, d->table);
if (ret) if (ret)
goto out; goto out;
...@@ -1124,6 +1132,7 @@ struct metricgroup__add_metric_data { ...@@ -1124,6 +1132,7 @@ struct metricgroup__add_metric_data {
const char *modifier; const char *modifier;
const char *user_requested_cpu_list; const char *user_requested_cpu_list;
bool metric_no_group; bool metric_no_group;
bool metric_no_threshold;
bool system_wide; bool system_wide;
bool has_match; bool has_match;
}; };
...@@ -1141,8 +1150,9 @@ static int metricgroup__add_metric_callback(const struct pmu_metric *pm, ...@@ -1141,8 +1150,9 @@ static int metricgroup__add_metric_callback(const struct pmu_metric *pm,
data->has_match = true; data->has_match = true;
ret = add_metric(data->list, pm, data->modifier, data->metric_no_group, ret = add_metric(data->list, pm, data->modifier, data->metric_no_group,
data->user_requested_cpu_list, data->system_wide, data->metric_no_threshold, data->user_requested_cpu_list,
/*root_metric=*/NULL, /*visited_metrics=*/NULL, table); data->system_wide, /*root_metric=*/NULL,
/*visited_metrics=*/NULL, table);
} }
return ret; return ret;
} }
...@@ -1163,7 +1173,7 @@ static int metricgroup__add_metric_callback(const struct pmu_metric *pm, ...@@ -1163,7 +1173,7 @@ static int metricgroup__add_metric_callback(const struct pmu_metric *pm,
* architecture perf is running upon. * architecture perf is running upon.
*/ */
static int metricgroup__add_metric(const char *metric_name, const char *modifier, static int metricgroup__add_metric(const char *metric_name, const char *modifier,
bool metric_no_group, bool metric_no_group, bool metric_no_threshold,
const char *user_requested_cpu_list, const char *user_requested_cpu_list,
bool system_wide, bool system_wide,
struct list_head *metric_list, struct list_head *metric_list,
...@@ -1179,6 +1189,7 @@ static int metricgroup__add_metric(const char *metric_name, const char *modifier ...@@ -1179,6 +1189,7 @@ static int metricgroup__add_metric(const char *metric_name, const char *modifier
.metric_name = metric_name, .metric_name = metric_name,
.modifier = modifier, .modifier = modifier,
.metric_no_group = metric_no_group, .metric_no_group = metric_no_group,
.metric_no_threshold = metric_no_threshold,
.user_requested_cpu_list = user_requested_cpu_list, .user_requested_cpu_list = user_requested_cpu_list,
.system_wide = system_wide, .system_wide = system_wide,
.has_match = false, .has_match = false,
...@@ -1241,6 +1252,7 @@ static int metricgroup__add_metric(const char *metric_name, const char *modifier ...@@ -1241,6 +1252,7 @@ static int metricgroup__add_metric(const char *metric_name, const char *modifier
* architecture perf is running upon. * architecture perf is running upon.
*/ */
static int metricgroup__add_metric_list(const char *list, bool metric_no_group, static int metricgroup__add_metric_list(const char *list, bool metric_no_group,
bool metric_no_threshold,
const char *user_requested_cpu_list, const char *user_requested_cpu_list,
bool system_wide, struct list_head *metric_list, bool system_wide, struct list_head *metric_list,
const struct pmu_metrics_table *table) const struct pmu_metrics_table *table)
...@@ -1259,7 +1271,8 @@ static int metricgroup__add_metric_list(const char *list, bool metric_no_group, ...@@ -1259,7 +1271,8 @@ static int metricgroup__add_metric_list(const char *list, bool metric_no_group,
*modifier++ = '\0'; *modifier++ = '\0';
ret = metricgroup__add_metric(metric_name, modifier, ret = metricgroup__add_metric(metric_name, modifier,
metric_no_group, user_requested_cpu_list, metric_no_group, metric_no_threshold,
user_requested_cpu_list,
system_wide, metric_list, table); system_wide, metric_list, table);
if (ret == -EINVAL) if (ret == -EINVAL)
pr_err("Cannot find metric or group `%s'\n", metric_name); pr_err("Cannot find metric or group `%s'\n", metric_name);
...@@ -1449,6 +1462,7 @@ static int parse_ids(bool metric_no_merge, struct perf_pmu *fake_pmu, ...@@ -1449,6 +1462,7 @@ static int parse_ids(bool metric_no_merge, struct perf_pmu *fake_pmu,
static int parse_groups(struct evlist *perf_evlist, const char *str, static int parse_groups(struct evlist *perf_evlist, const char *str,
bool metric_no_group, bool metric_no_group,
bool metric_no_merge, bool metric_no_merge,
bool metric_no_threshold,
const char *user_requested_cpu_list, const char *user_requested_cpu_list,
bool system_wide, bool system_wide,
struct perf_pmu *fake_pmu, struct perf_pmu *fake_pmu,
...@@ -1463,7 +1477,7 @@ static int parse_groups(struct evlist *perf_evlist, const char *str, ...@@ -1463,7 +1477,7 @@ static int parse_groups(struct evlist *perf_evlist, const char *str,
if (metric_events_list->nr_entries == 0) if (metric_events_list->nr_entries == 0)
metricgroup__rblist_init(metric_events_list); metricgroup__rblist_init(metric_events_list);
ret = metricgroup__add_metric_list(str, metric_no_group, ret = metricgroup__add_metric_list(str, metric_no_group, metric_no_threshold,
user_requested_cpu_list, user_requested_cpu_list,
system_wide, &metric_list, table); system_wide, &metric_list, table);
if (ret) if (ret)
...@@ -1598,6 +1612,7 @@ int metricgroup__parse_groups(struct evlist *perf_evlist, ...@@ -1598,6 +1612,7 @@ int metricgroup__parse_groups(struct evlist *perf_evlist,
const char *str, const char *str,
bool metric_no_group, bool metric_no_group,
bool metric_no_merge, bool metric_no_merge,
bool metric_no_threshold,
const char *user_requested_cpu_list, const char *user_requested_cpu_list,
bool system_wide, bool system_wide,
struct rblist *metric_events) struct rblist *metric_events)
...@@ -1608,18 +1623,19 @@ int metricgroup__parse_groups(struct evlist *perf_evlist, ...@@ -1608,18 +1623,19 @@ int metricgroup__parse_groups(struct evlist *perf_evlist,
return -EINVAL; return -EINVAL;
return parse_groups(perf_evlist, str, metric_no_group, metric_no_merge, return parse_groups(perf_evlist, str, metric_no_group, metric_no_merge,
user_requested_cpu_list, system_wide, metric_no_threshold, user_requested_cpu_list, system_wide,
/*fake_pmu=*/NULL, metric_events, table); /*fake_pmu=*/NULL, metric_events, table);
} }
int metricgroup__parse_groups_test(struct evlist *evlist, int metricgroup__parse_groups_test(struct evlist *evlist,
const struct pmu_metrics_table *table, const struct pmu_metrics_table *table,
const char *str, const char *str,
bool metric_no_group,
bool metric_no_merge,
struct rblist *metric_events) struct rblist *metric_events)
{ {
return parse_groups(evlist, str, metric_no_group, metric_no_merge, return parse_groups(evlist, str,
/*metric_no_group=*/false,
/*metric_no_merge=*/false,
/*metric_no_threshold=*/false,
/*user_requested_cpu_list=*/NULL, /*user_requested_cpu_list=*/NULL,
/*system_wide=*/false, /*system_wide=*/false,
&perf_pmu__fake, metric_events, table); &perf_pmu__fake, metric_events, table);
......
...@@ -70,14 +70,13 @@ int metricgroup__parse_groups(struct evlist *perf_evlist, ...@@ -70,14 +70,13 @@ int metricgroup__parse_groups(struct evlist *perf_evlist,
const char *str, const char *str,
bool metric_no_group, bool metric_no_group,
bool metric_no_merge, bool metric_no_merge,
bool metric_no_threshold,
const char *user_requested_cpu_list, const char *user_requested_cpu_list,
bool system_wide, bool system_wide,
struct rblist *metric_events); struct rblist *metric_events);
int metricgroup__parse_groups_test(struct evlist *evlist, int metricgroup__parse_groups_test(struct evlist *evlist,
const struct pmu_metrics_table *table, const struct pmu_metrics_table *table,
const char *str, const char *str,
bool metric_no_group,
bool metric_no_merge,
struct rblist *metric_events); struct rblist *metric_events);
void metricgroup__print(const struct print_callbacks *print_cb, void *print_state); void metricgroup__print(const struct print_callbacks *print_cb, void *print_state);
......
...@@ -814,7 +814,8 @@ static void generic_metric(struct perf_stat_config *config, ...@@ -814,7 +814,8 @@ static void generic_metric(struct perf_stat_config *config,
char metric_bf[64]; char metric_bf[64];
if (metric_threshold && if (metric_threshold &&
expr__parse(&threshold, pctx, metric_threshold) == 0) { expr__parse(&threshold, pctx, metric_threshold) == 0 &&
!isnan(threshold)) {
color = fpclassify(threshold) == FP_ZERO color = fpclassify(threshold) == FP_ZERO
? PERF_COLOR_GREEN : PERF_COLOR_RED; ? PERF_COLOR_GREEN : PERF_COLOR_RED;
} }
......
...@@ -159,6 +159,7 @@ struct perf_stat_config { ...@@ -159,6 +159,7 @@ struct perf_stat_config {
bool no_csv_summary; bool no_csv_summary;
bool metric_no_group; bool metric_no_group;
bool metric_no_merge; bool metric_no_merge;
bool metric_no_threshold;
bool stop_read_counter; bool stop_read_counter;
bool iostat_run; bool iostat_run;
char *user_requested_cpu_list; char *user_requested_cpu_list;
......
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