Commit 180a5013 authored by Ian Rogers's avatar Ian Rogers Committed by Arnaldo Carvalho de Melo

perf metrics: Improve variable names

has_constraint implies the NMI_WATCHDOG_CONSTRAINT and if the
constraint is detected it causes events not to be grouped. Most of the
code cares about whether events are grouped or not, so rename
has_constraint to group_events.

Also remove group from metricgroup___watchdog_constraint_hint as the
warning is specific to a metric. Make the warning message agree with
this too.
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-3-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 484b2a84
...@@ -136,10 +136,9 @@ struct metric { ...@@ -136,10 +136,9 @@ struct metric {
/** Optional null terminated array of referenced metrics. */ /** Optional null terminated array of referenced metrics. */
struct metric_ref *metric_refs; struct metric_ref *metric_refs;
/** /**
* Is there a constraint on the group of events? In which case the * Should events of the metric be grouped?
* events won't be grouped.
*/ */
bool has_constraint; bool group_events;
/** /**
* Parsed events for the metric. Optional as events may be taken from a * Parsed events for the metric. Optional as events may be taken from a
* different metric whose group contains all the IDs necessary for this * different metric whose group contains all the IDs necessary for this
...@@ -148,12 +147,12 @@ struct metric { ...@@ -148,12 +147,12 @@ struct metric {
struct evlist *evlist; struct evlist *evlist;
}; };
static void metricgroup___watchdog_constraint_hint(const char *name, bool foot) static void metric__watchdog_constraint_hint(const char *name, bool foot)
{ {
static bool violate_nmi_constraint; static bool violate_nmi_constraint;
if (!foot) { if (!foot) {
pr_warning("Splitting metric group %s into standalone metrics.\n", name); pr_warning("Not grouping metric %s's events.\n", name);
violate_nmi_constraint = true; violate_nmi_constraint = true;
return; return;
} }
...@@ -167,18 +166,18 @@ static void metricgroup___watchdog_constraint_hint(const char *name, bool foot) ...@@ -167,18 +166,18 @@ static void metricgroup___watchdog_constraint_hint(const char *name, bool foot)
" echo 1 > /proc/sys/kernel/nmi_watchdog\n"); " echo 1 > /proc/sys/kernel/nmi_watchdog\n");
} }
static bool metricgroup__has_constraint(const struct pmu_metric *pm) static bool metric__group_events(const struct pmu_metric *pm)
{ {
if (!pm->metric_constraint) if (!pm->metric_constraint)
return false; return true;
if (!strcmp(pm->metric_constraint, "NO_NMI_WATCHDOG") && if (!strcmp(pm->metric_constraint, "NO_NMI_WATCHDOG") &&
sysctl__nmi_watchdog_enabled()) { sysctl__nmi_watchdog_enabled()) {
metricgroup___watchdog_constraint_hint(pm->metric_name, false); metric__watchdog_constraint_hint(pm->metric_name, /*foot=*/false);
return true; return false;
} }
return false; return true;
} }
static void metric__free(struct metric *m) static void metric__free(struct metric *m)
...@@ -227,7 +226,7 @@ static struct metric *metric__new(const struct pmu_metric *pm, ...@@ -227,7 +226,7 @@ static struct metric *metric__new(const struct pmu_metric *pm,
} }
m->pctx->sctx.runtime = runtime; m->pctx->sctx.runtime = runtime;
m->pctx->sctx.system_wide = system_wide; m->pctx->sctx.system_wide = system_wide;
m->has_constraint = metric_no_group || metricgroup__has_constraint(pm); m->group_events = !metric_no_group && metric__group_events(pm);
m->metric_refs = NULL; m->metric_refs = NULL;
m->evlist = NULL; m->evlist = NULL;
...@@ -637,7 +636,7 @@ static int decode_all_metric_ids(struct evlist *perf_evlist, const char *modifie ...@@ -637,7 +636,7 @@ static int decode_all_metric_ids(struct evlist *perf_evlist, const char *modifie
static int metricgroup__build_event_string(struct strbuf *events, static int metricgroup__build_event_string(struct strbuf *events,
const struct expr_parse_ctx *ctx, const struct expr_parse_ctx *ctx,
const char *modifier, const char *modifier,
bool has_constraint) bool group_events)
{ {
struct hashmap_entry *cur; struct hashmap_entry *cur;
size_t bkt; size_t bkt;
...@@ -662,7 +661,7 @@ static int metricgroup__build_event_string(struct strbuf *events, ...@@ -662,7 +661,7 @@ static int metricgroup__build_event_string(struct strbuf *events,
} }
/* Separate events with commas and open the group if necessary. */ /* Separate events with commas and open the group if necessary. */
if (no_group) { if (no_group) {
if (!has_constraint) { if (group_events) {
ret = strbuf_addch(events, '{'); ret = strbuf_addch(events, '{');
RETURN_IF_NON_ZERO(ret); RETURN_IF_NON_ZERO(ret);
} }
...@@ -716,7 +715,7 @@ static int metricgroup__build_event_string(struct strbuf *events, ...@@ -716,7 +715,7 @@ static int metricgroup__build_event_string(struct strbuf *events,
RETURN_IF_NON_ZERO(ret); RETURN_IF_NON_ZERO(ret);
} }
} }
if (!no_group && !has_constraint) { if (!no_group && group_events) {
ret = strbuf_addf(events, "}:W"); ret = strbuf_addf(events, "}:W");
RETURN_IF_NON_ZERO(ret); RETURN_IF_NON_ZERO(ret);
} }
...@@ -1252,7 +1251,7 @@ static int metricgroup__add_metric_list(const char *list, bool metric_no_group, ...@@ -1252,7 +1251,7 @@ static int metricgroup__add_metric_list(const char *list, bool metric_no_group,
* Warn about nmi_watchdog if any parsed metrics had the * Warn about nmi_watchdog if any parsed metrics had the
* NO_NMI_WATCHDOG constraint. * NO_NMI_WATCHDOG constraint.
*/ */
metricgroup___watchdog_constraint_hint(NULL, true); metric__watchdog_constraint_hint(NULL, /*foot=*/true);
/* No metrics. */ /* No metrics. */
if (count == 0) if (count == 0)
return -EINVAL; return -EINVAL;
...@@ -1295,7 +1294,7 @@ static void find_tool_events(const struct list_head *metric_list, ...@@ -1295,7 +1294,7 @@ static void find_tool_events(const struct list_head *metric_list,
} }
/** /**
* build_combined_expr_ctx - Make an expr_parse_ctx with all has_constraint * build_combined_expr_ctx - Make an expr_parse_ctx with all !group_events
* metric IDs, as the IDs are held in a set, * metric IDs, as the IDs are held in a set,
* duplicates will be removed. * duplicates will be removed.
* @metric_list: List to take metrics from. * @metric_list: List to take metrics from.
...@@ -1315,7 +1314,7 @@ static int build_combined_expr_ctx(const struct list_head *metric_list, ...@@ -1315,7 +1314,7 @@ static int build_combined_expr_ctx(const struct list_head *metric_list,
return -ENOMEM; return -ENOMEM;
list_for_each_entry(m, metric_list, nd) { list_for_each_entry(m, metric_list, nd) {
if (m->has_constraint && !m->modifier) { if (!m->group_events && !m->modifier) {
hashmap__for_each_entry(m->pctx->ids, cur, bkt) { hashmap__for_each_entry(m->pctx->ids, cur, bkt) {
dup = strdup(cur->pkey); dup = strdup(cur->pkey);
if (!dup) { if (!dup) {
...@@ -1342,14 +1341,14 @@ static int build_combined_expr_ctx(const struct list_head *metric_list, ...@@ -1342,14 +1341,14 @@ static int build_combined_expr_ctx(const struct list_head *metric_list,
* @fake_pmu: used when testing metrics not supported by the current CPU. * @fake_pmu: used when testing metrics not supported by the current CPU.
* @ids: the event identifiers parsed from a metric. * @ids: the event identifiers parsed from a metric.
* @modifier: any modifiers added to the events. * @modifier: any modifiers added to the events.
* @has_constraint: false if events should be placed in a weak group. * @group_events: should events be placed in a weak group.
* @tool_events: entries set true if the tool event of index could be present in * @tool_events: entries set true if the tool event of index could be present in
* the overall list of metrics. * the overall list of metrics.
* @out_evlist: the created list of events. * @out_evlist: the created list of events.
*/ */
static int parse_ids(bool metric_no_merge, struct perf_pmu *fake_pmu, static int parse_ids(bool metric_no_merge, struct perf_pmu *fake_pmu,
struct expr_parse_ctx *ids, const char *modifier, struct expr_parse_ctx *ids, const char *modifier,
bool has_constraint, const bool tool_events[PERF_TOOL_MAX], bool group_events, const bool tool_events[PERF_TOOL_MAX],
struct evlist **out_evlist) struct evlist **out_evlist)
{ {
struct parse_events_error parse_error; struct parse_events_error parse_error;
...@@ -1393,7 +1392,7 @@ static int parse_ids(bool metric_no_merge, struct perf_pmu *fake_pmu, ...@@ -1393,7 +1392,7 @@ static int parse_ids(bool metric_no_merge, struct perf_pmu *fake_pmu,
} }
} }
ret = metricgroup__build_event_string(&events, ids, modifier, ret = metricgroup__build_event_string(&events, ids, modifier,
has_constraint); group_events);
if (ret) if (ret)
return ret; return ret;
...@@ -1458,7 +1457,7 @@ static int parse_groups(struct evlist *perf_evlist, const char *str, ...@@ -1458,7 +1457,7 @@ static int parse_groups(struct evlist *perf_evlist, const char *str,
if (!ret && combined && hashmap__size(combined->ids)) { if (!ret && combined && hashmap__size(combined->ids)) {
ret = parse_ids(metric_no_merge, fake_pmu, combined, ret = parse_ids(metric_no_merge, fake_pmu, combined,
/*modifier=*/NULL, /*modifier=*/NULL,
/*has_constraint=*/true, /*group_events=*/false,
tool_events, tool_events,
&combined_evlist); &combined_evlist);
} }
...@@ -1476,7 +1475,7 @@ static int parse_groups(struct evlist *perf_evlist, const char *str, ...@@ -1476,7 +1475,7 @@ static int parse_groups(struct evlist *perf_evlist, const char *str,
struct metric *n; struct metric *n;
struct metric_expr *expr; struct metric_expr *expr;
if (combined_evlist && m->has_constraint) { if (combined_evlist && !m->group_events) {
metric_evlist = combined_evlist; metric_evlist = combined_evlist;
} else if (!metric_no_merge) { } else if (!metric_no_merge) {
/* /*
...@@ -1507,7 +1506,7 @@ static int parse_groups(struct evlist *perf_evlist, const char *str, ...@@ -1507,7 +1506,7 @@ static int parse_groups(struct evlist *perf_evlist, const char *str,
} }
if (!metric_evlist) { if (!metric_evlist) {
ret = parse_ids(metric_no_merge, fake_pmu, m->pctx, m->modifier, ret = parse_ids(metric_no_merge, fake_pmu, m->pctx, m->modifier,
m->has_constraint, tool_events, &m->evlist); m->group_events, tool_events, &m->evlist);
if (ret) if (ret)
goto out; goto out;
......
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