[PATCH RFC 8/9] perf metrics: Stop metricgroup__add_metric_sys_event_iter if already matched

John Garry john.g.garry at oracle.com
Wed Jun 28 03:29:48 PDT 2023


Functions like pmu_for_each_sys_event() may be inefficient, as we only
stop itering for an error. Often when itering, we may want to stop early
as we already found what we're looking for.

Return 1 in metricgroup__add_metric_sys_event_iter() when we want to stop.
Nobody checks the error code from callers anyway - those are
pmu_metrics_table_for_each_metric() ->
metricgroup__add_metric_sys_event_iter() and pmu_for_each_sys_metric() ->
metricgroup__sys_event_iter() -> metricgroup__add_metric_sys_event_iter().

Signed-off-by: John Garry <john.g.garry at oracle.com>
---
 tools/perf/util/metricgroup.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
index 111ad4e3eb6b..c045b111db84 100644
--- a/tools/perf/util/metricgroup.c
+++ b/tools/perf/util/metricgroup.c
@@ -1130,7 +1130,12 @@ static int metricgroup__add_metric_sys_event_iter(const struct pmu_metric *pm,
 
 out:
 	*(d->ret) = ret;
-	return ret;
+	/*
+	 * Return 1 as we don't want to iter any more, as either:
+	 * a. We found a match
+	 * b. We tried to add a metric, which errored
+	 */
+	return 1;
 }
 
 /**
-- 
2.35.3




More information about the linux-arm-kernel mailing list