Skip to content

Commit fcc7cc3

Browse files
captain5050namhyung
authored andcommitted
perf metricgroups: Add NO_THRESHOLD_AND_NMI constraint
Thresholds can increase the number of counters a metric needs. The NMI watchdog can take away a counter (hopefully the buddy watchdog will become the default and this will no longer be true). Add a new constraint for the case that a metric and its thresholds would fit in counters but only if the NMI watchdog isn't enabled. Either the threshold or the NMI watchdog should be disabled to make the metric fit. Wire this up into the metric__group_events logic. Signed-off-by: Ian Rogers <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Namhyung Kim <[email protected]>
1 parent 8dcd27b commit fcc7cc3

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

tools/perf/pmu-events/jevents.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ def convert_metric_constraint(metric_constraint: str) -> Optional[str]:
235235
'NO_GROUP_EVENTS_NMI': '2',
236236
'NO_NMI_WATCHDOG': '2',
237237
'NO_GROUP_EVENTS_SMT': '3',
238+
'NO_THRESHOLD_AND_NMI': '4',
238239
}
239240
return metric_constraint_to_enum[metric_constraint]
240241

tools/perf/pmu-events/pmu-events.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,21 @@ enum metric_event_groups {
2525
*/
2626
MetricNoGroupEvents = 1,
2727
/**
28-
* @MetricNoGroupEventsNmi: Don't group events for the metric if the NMI
29-
* watchdog is enabled.
28+
* @MetricNoGroupEventsNmi:
29+
* Don't group events for the metric if the NMI watchdog is enabled.
3030
*/
3131
MetricNoGroupEventsNmi = 2,
3232
/**
33-
* @MetricNoGroupEventsSmt: Don't group events for the metric if SMT is
34-
* enabled.
33+
* @MetricNoGroupEventsSmt:
34+
* Don't group events for the metric if SMT is enabled.
3535
*/
3636
MetricNoGroupEventsSmt = 3,
37+
/**
38+
* @MetricNoGroupEventsThresholdAndNmi:
39+
* Don't group events for the metric thresholds and if the NMI watchdog
40+
* is enabled.
41+
*/
42+
MetricNoGroupEventsThresholdAndNmi = 4,
3743
};
3844
/*
3945
* Describe each PMU event. Each CPU has a table of PMU events.

tools/perf/util/metricgroup.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ static void metric__watchdog_constraint_hint(const char *name, bool foot)
179179
" echo 1 > /proc/sys/kernel/nmi_watchdog\n");
180180
}
181181

182-
static bool metric__group_events(const struct pmu_metric *pm)
182+
static bool metric__group_events(const struct pmu_metric *pm, bool metric_no_threshold)
183183
{
184184
switch (pm->event_grouping) {
185185
case MetricNoGroupEvents:
@@ -191,6 +191,13 @@ static bool metric__group_events(const struct pmu_metric *pm)
191191
return false;
192192
case MetricNoGroupEventsSmt:
193193
return !smt_on();
194+
case MetricNoGroupEventsThresholdAndNmi:
195+
if (metric_no_threshold)
196+
return true;
197+
if (!sysctl__nmi_watchdog_enabled())
198+
return true;
199+
metric__watchdog_constraint_hint(pm->metric_name, /*foot=*/false);
200+
return false;
194201
case MetricGroupEvents:
195202
default:
196203
return true;
@@ -212,6 +219,7 @@ static void metric__free(struct metric *m)
212219
static struct metric *metric__new(const struct pmu_metric *pm,
213220
const char *modifier,
214221
bool metric_no_group,
222+
bool metric_no_threshold,
215223
int runtime,
216224
const char *user_requested_cpu_list,
217225
bool system_wide)
@@ -246,7 +254,7 @@ static struct metric *metric__new(const struct pmu_metric *pm,
246254
}
247255
m->pctx->sctx.runtime = runtime;
248256
m->pctx->sctx.system_wide = system_wide;
249-
m->group_events = !metric_no_group && metric__group_events(pm);
257+
m->group_events = !metric_no_group && metric__group_events(pm, metric_no_threshold);
250258
m->metric_refs = NULL;
251259
m->evlist = NULL;
252260

@@ -831,8 +839,8 @@ static int __add_metric(struct list_head *metric_list,
831839
* This metric is the root of a tree and may reference other
832840
* metrics that are added recursively.
833841
*/
834-
root_metric = metric__new(pm, modifier, metric_no_group, runtime,
835-
user_requested_cpu_list, system_wide);
842+
root_metric = metric__new(pm, modifier, metric_no_group, metric_no_threshold,
843+
runtime, user_requested_cpu_list, system_wide);
836844
if (!root_metric)
837845
return -ENOMEM;
838846

0 commit comments

Comments
 (0)