From nobody Sun Dec 14 06:16:21 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B1EFBC433FE for ; Mon, 3 Oct 2022 07:30:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231417AbiJCHad (ORCPT ); Mon, 3 Oct 2022 03:30:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231445AbiJCH3J (ORCPT ); Mon, 3 Oct 2022 03:29:09 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18D0A2BDD; Mon, 3 Oct 2022 00:19:53 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 210BAB80E85; Mon, 3 Oct 2022 07:19:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5849FC433D6; Mon, 3 Oct 2022 07:19:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664781577; bh=bQOQHFWXu0Y1xHZRrvTz4L2+IME1DPD6dr71obT4YDM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AmxX4gkJME4pKQ6Szs7ZWMB8JhFs5sjMWuM4uxvVbqabO/tJeanVmAjQ1Kw/iITm3 j6F3yn0q4XrqjYlhNvuzXC0hycZ3nyjH5Sdaarf6oHdFrNxOmduSHsxesK0+WxmmLb +cqxQEQqIpjuQu06qcPFoaHzo0ErDyf+dpfSgA4Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Ian Rogers , Andi Kleen , Adrian Hunter , Alexander Antonov , Alexander Shishkin , Andrew Kilroy , Andrew Morton , Changbin Du , Denys Zagorui , Fabian Hemmer , Felix Fietkau , Heiko Carstens , Ingo Molnar , Jacob Keller , Jiapeng Chong , Jin Yao , Jiri Olsa , Joakim Zhang , John Garry , Kajol Jain , Kan Liang , Kees Kook , Mark Rutland , Namhyung Kim , Nicholas Fraser , Nick Desaulniers , Paul Clarke , Peter Zijlstra , Riccardo Mancini , Sami Tolvanen , ShihCheng Tu , Song Liu , Stephane Eranian , Sumanth Korikkar , Thomas Richter , Wan Jiabing , Zhen Lei , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 5.15 71/83] perf metric: Add documentation and rename a variable. Date: Mon, 3 Oct 2022 09:11:36 +0200 Message-Id: <20221003070723.771956822@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20221003070721.971297651@linuxfoundation.org> References: <20221003070721.971297651@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Ian Rogers [ Upstream commit 68074811dfb9529bb7cade0e67d42c7f7bf209e6 ] Documentation to make current functionality clearer. Rename a variable called 'metric' to 'metric_name' as it can be ambiguous as to whether a string is the name of a metric or the expression. Signed-off-by: Ian Rogers Acked-by: Andi Kleen Cc: Adrian Hunter Cc: Alexander Antonov Cc: Alexander Shishkin Cc: Andrew Kilroy Cc: Andrew Morton Cc: Changbin Du Cc: Denys Zagorui Cc: Fabian Hemmer Cc: Felix Fietkau Cc: Heiko Carstens Cc: Ingo Molnar Cc: Jacob Keller Cc: Jiapeng Chong Cc: Jin Yao Cc: Jiri Olsa Cc: Joakim Zhang Cc: John Garry Cc: Kajol Jain Cc: Kan Liang Cc: Kees Kook Cc: Mark Rutland Cc: Namhyung Kim Cc: Nicholas Fraser Cc: Nick Desaulniers Cc: Paul Clarke Cc: Peter Zijlstra Cc: Riccardo Mancini Cc: Sami Tolvanen Cc: ShihCheng Tu Cc: Song Liu Cc: Stephane Eranian Cc: Sumanth Korikkar Cc: Thomas Richter Cc: Wan Jiabing Cc: Zhen Lei Link: https://lore.kernel.org/r/20211015172132.1162559-7-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo Stable-dep-of: 71c86cda750b ("perf parse-events: Remove "not supported" hyb= rid cache events") Signed-off-by: Sasha Levin --- tools/perf/util/metricgroup.c | 59 ++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 29b747ac31c1..2dc2a0dcf846 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -772,13 +772,27 @@ int __weak arch_get_runtimeparam(struct pmu_event *pe= __maybe_unused) =20 struct metricgroup_add_iter_data { struct list_head *metric_list; - const char *metric; + const char *metric_name; struct expr_ids *ids; int *ret; bool *has_match; bool metric_no_group; }; =20 +/** + * __add_metric - Add a metric to metric_list. + * @metric_list: The list the metric is added to. + * @pe: The pmu_event containing the metric to be added. + * @metric_no_group: Should events written to events be grouped "{}" or + * global. Grouping is the default but due to multiplexi= ng the + * user may override. + * @runtime: A special argument for the parser only known at runtime. + * @mp: The pointer to a location holding the first metric added to metric + * list. It is initialized here if this is the first metric. + * @parent: The last entry in a linked list of metrics being + * added/resolved. This is maintained to detect recursion. + * @ids: Storage for parent list. + */ static int __add_metric(struct list_head *metric_list, struct pmu_event *pe, bool metric_no_group, @@ -1068,7 +1082,7 @@ static int metricgroup__add_metric_sys_event_iter(str= uct pmu_event *pe, struct metric *m =3D NULL; int ret; =20 - if (!match_pe_metric(pe, d->metric)) + if (!match_pe_metric(pe, d->metric_name)) return 0; =20 ret =3D add_metric(d->metric_list, pe, d->metric_no_group, &m, NULL, d->i= ds); @@ -1087,7 +1101,22 @@ static int metricgroup__add_metric_sys_event_iter(st= ruct pmu_event *pe, return ret; } =20 -static int metricgroup__add_metric(const char *metric, bool metric_no_grou= p, +/** + * metricgroup__add_metric - Find and add a metric, or a metric group. + * @metric_name: The name of the metric or metric group. For example, "IPC" + * could be the name of a metric and "TopDownL1" the name of= a + * metric group. + * @metric_no_group: Should events written to events be grouped "{}" or + * global. Grouping is the default but due to multiplexi= ng the + * user may override. + * @events: an out argument string of events that need to be parsed and + * associated with the metric. For example, the metric "IPC" would + * create an events string like "{instructions,cycles}:W". + * @metric_list: The list that the metric or metric group are added to. + * @map: The map that is searched for metrics, most commonly the table for= the + * architecture perf is running upon. + */ +static int metricgroup__add_metric(const char *metric_name, bool metric_no= _group, struct strbuf *events, struct list_head *metric_list, struct pmu_events_map *map) @@ -1099,7 +1128,11 @@ static int metricgroup__add_metric(const char *metri= c, bool metric_no_group, int i, ret; bool has_match =3D false; =20 - map_for_each_metric(pe, i, map, metric) { + /* + * Iterate over all metrics seeing if metric matches either the name or + * group. When it does add the metric to the list. + */ + map_for_each_metric(pe, i, map, metric_name) { has_match =3D true; m =3D NULL; =20 @@ -1122,7 +1155,7 @@ static int metricgroup__add_metric(const char *metric= , bool metric_no_group, .fn =3D metricgroup__add_metric_sys_event_iter, .data =3D (void *) &(struct metricgroup_add_iter_data) { .metric_list =3D &list, - .metric =3D metric, + .metric_name =3D metric_name, .metric_no_group =3D metric_no_group, .ids =3D &ids, .has_match =3D &has_match, @@ -1161,6 +1194,22 @@ static int metricgroup__add_metric(const char *metri= c, bool metric_no_group, return ret; } =20 +/** + * metricgroup__add_metric_list - Find and add metrics, or metric groups, + * specified in a list. + * @list: the list of metrics or metric groups. For example, "IPC,CPI,TopD= ownL1" + * would match the IPC and CPI metrics, and TopDownL1 would match a= ll + * the metrics in the TopDownL1 group. + * @metric_no_group: Should events written to events be grouped "{}" or + * global. Grouping is the default but due to multiplexi= ng the + * user may override. + * @events: an out argument string of events that need to be parsed and + * associated with the metric. For example, the metric "IPC" would + * create an events string like "{instructions,cycles}:W". + * @metric_list: The list that metrics are added to. + * @map: The map that is searched for metrics, most commonly the table for= the + * architecture perf is running upon. + */ static int metricgroup__add_metric_list(const char *list, bool metric_no_g= roup, struct strbuf *events, struct list_head *metric_list, --=20 2.35.1