From: "Liang, Kan" <kan.liang@linux.intel.com>
To: weilin.wang@intel.com, Ian Rogers <irogers@google.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@kernel.org>, Namhyung Kim <namhyung@kernel.org>,
Adrian Hunter <adrian.hunter@intel.com>
Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org,
Perry Taylor <perry.taylor@intel.com>,
Samantha Alt <samantha.alt@intel.com>,
Caleb Biggers <caleb.biggers@intel.com>,
Mark Rutland <mark.rutland@arm.com>
Subject: Re: [RFC PATCH 02/25] perf stat: Add basic functions for the hardware-grouping stat cmd option
Date: Tue, 26 Sep 2023 11:10:51 -0400 [thread overview]
Message-ID: <ccd091ec-d650-e522-8152-c37d00d952d8@linux.intel.com> (raw)
In-Reply-To: <20230925061824.3818631-3-weilin.wang@intel.com>
On 2023-09-25 2:18 a.m., weilin.wang@intel.com wrote:
> From: Weilin Wang <weilin.wang@intel.com>
>
> Add the first set of functions for the hardware-grouping method. Function
> hw_awre_parse_groups() is the entry point of this metric grouping method.
> It does metric grouping on a combined list of events and will create a list
> of grouping strings as final results of the grouping method. These grouping
> strings will be used in the same mannor as existing metric grouping
> process.
>
> This patch needs to be used together with the following a few patches
> together to function correctly.
If this one depends on the later patches, you may consider to change the
order of the patches. Let the dependent patch be first. We should only
enable a new feature when all the pieces are ready.
Thanks,
Kan
>
> Signed-off-by: Weilin Wang <weilin.wang@intel.com>
> ---
> tools/perf/util/metricgroup.c | 206 ++++++++++++++++++++++++++++++++++
> tools/perf/util/metricgroup.h | 9 ++
> 2 files changed, 215 insertions(+)
>
> diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c
> index b08af6860..063c92c71 100644
> --- a/tools/perf/util/metricgroup.c
> +++ b/tools/perf/util/metricgroup.c
> @@ -1432,6 +1432,101 @@ static int build_combined_expr_ctx(const struct list_head *metric_list,
> return ret;
> }
>
> +/**
> + * hw_aware_build_grouping - Build event groupings by reading counter
> + * requirement of the events and counter available on the system from
> + * pmu-events.
> + * @ctx: the event identifiers parsed from metrics.
> + * @groupings: header to the list of final event grouping.
> + * @modifier: any modifiers added to the events.
> + */
> +static int hw_aware_build_grouping(struct expr_parse_ctx *ctx __maybe_unused,
> + struct list_head *groupings __maybe_unused,
> + const char *modifier __maybe_unused)
> +{
> + int ret = 0;
> +
> + pr_debug("This is a placeholder\n");
> + return ret;
> +}
> +
> +static void group_str_free(struct metricgroup__group_strs *g)
> +{
> + if (!g)
> + return;
> +
> + strbuf_release(&g->grouping_str);
> + free(g);
> +}
> +
> +static void metricgroup__free_grouping_strs(struct list_head
> + *grouping_strs)
> +{
> + struct metricgroup__group_strs *g, *tmp;
> +
> + list_for_each_entry_safe(g, tmp, grouping_strs, nd) {
> + list_del_init(&g->nd);
> + group_str_free(g);
> + }
> +}
> +
> +/**
> + * hw_aware_parse_ids - Build the event string for the ids and parse them
> + * creating an evlist. The encoded metric_ids are decoded. Events are placed
> + * into groups based on event counter requirements and counter availabilities of
> + * the system.
> + * @metric_no_merge: is metric sharing explicitly disabled.
> + * @fake_pmu: used when testing metrics not supported by the current CPU.
> + * @ids: the event identifiers parsed from a metric.
> + * @modifier: any modifiers added to the events.
> + * @out_evlist: the created list of events.
> + */
> +static int hw_aware_parse_ids(struct perf_pmu *fake_pmu,
> + struct expr_parse_ctx *ids, const char *modifier,
> + struct evlist **out_evlist)
> +{
> + struct parse_events_error parse_error;
> + struct evlist *parsed_evlist;
> + LIST_HEAD(groupings);
> + struct metricgroup__group_strs *group;
> + int ret;
> +
> + *out_evlist = NULL;
> + ret = hw_aware_build_grouping(ids, &groupings, modifier);
> + if (ret) {
> + metricgroup__free_grouping_strs(&groupings);
> + return ret;
> + }
> +
> + parsed_evlist = evlist__new();
> + if (!parsed_evlist) {
> + ret = -ENOMEM;
> + goto err_out;
> + }
> + list_for_each_entry(group, &groupings, nd) {
> + struct strbuf *events = &group->grouping_str;
> +
> + pr_debug("Parsing metric events '%s'\n", events->buf);
> + parse_events_error__init(&parse_error);
> + ret = __parse_events(parsed_evlist, events->buf, /*pmu_filter=*/NULL,
> + &parse_error, fake_pmu, /*warn_if_reordered=*/false);
> + if (ret) {
> + parse_events_error__print(&parse_error, events->buf);
> + goto err_out;
> + }
> + ret = decode_all_metric_ids(parsed_evlist, modifier);
> + if (ret)
> + goto err_out;
> + }
> + *out_evlist = parsed_evlist;
> + parsed_evlist = NULL;
> +err_out:
> + parse_events_error__exit(&parse_error);
> + evlist__delete(parsed_evlist);
> + metricgroup__free_grouping_strs(&groupings);
> + return ret;
> +}
> +
> /**
> * parse_ids - Build the event string for the ids and parse them creating an
> * evlist. The encoded metric_ids are decoded.
> @@ -1520,6 +1615,114 @@ static int parse_ids(bool metric_no_merge, struct perf_pmu *fake_pmu,
> return ret;
> }
>
> +static int hw_aware_parse_groups(struct evlist *perf_evlist,
> + const char *pmu, const char *str,
> + bool metric_no_threshold,
> + const char *user_requested_cpu_list,
> + bool system_wide,
> + struct perf_pmu *fake_pmu,
> + struct rblist *metric_events_list,
> + const struct pmu_metrics_table *table)
> +{
> + struct evlist *combined_evlist = NULL;
> + LIST_HEAD(metric_list);
> + struct metric *m;
> + int ret;
> + bool metric_no_group = false;
> + bool metric_no_merge = false;
> +
> + if (metric_events_list->nr_entries == 0)
> + metricgroup__rblist_init(metric_events_list);
> + ret = metricgroup__add_metric_list(pmu, str, metric_no_group, metric_no_threshold,
> + user_requested_cpu_list,
> + system_wide, &metric_list, table);
> + if (ret)
> + goto out;
> +
> + /* Sort metrics from largest to smallest. */
> + list_sort(NULL, &metric_list, metric_list_cmp);
> +
> + if (!metric_no_merge) {
> + struct expr_parse_ctx *combined = NULL;
> +
> + ret = build_combined_expr_ctx(&metric_list, &combined);
> +
> + if (!ret && combined && hashmap__size(combined->ids)) {
> + ret = hw_aware_parse_ids(fake_pmu, combined,
> + /*modifier=*/NULL,
> + &combined_evlist);
> + }
> +
> + if (ret)
> + goto out;
> +
> + if (combined)
> + expr__ctx_free(combined);
> + }
> +
> + list_for_each_entry(m, &metric_list, nd) {
> + struct metric_expr *expr;
> + struct metric_event *me;
> + struct evsel **metric_events;
> +
> + ret = setup_metric_events(fake_pmu ? "all" : m->pmu, m->pctx->ids,
> + combined_evlist, &metric_events);
> + if (ret) {
> + pr_debug("Cannot resolve IDs for %s: %s\n",
> + m->metric_name, m->metric_expr);
> + goto out;
> + }
> +
> + me = metricgroup__lookup(metric_events_list, metric_events[0], true);
> +
> + expr = malloc(sizeof(struct metric_expr));
> + if (!expr) {
> + ret = -ENOMEM;
> + free(metric_events);
> + goto out;
> + }
> +
> + expr->metric_refs = m->metric_refs;
> + m->metric_refs = NULL;
> + expr->metric_expr = m->metric_expr;
> + if (m->modifier) {
> + char *tmp;
> +
> + if (asprintf(&tmp, "%s:%s", m->metric_name, m->modifier) < 0)
> + expr->metric_name = NULL;
> + else
> + expr->metric_name = tmp;
> + } else {
> + expr->metric_name = strdup(m->metric_name);
> + }
> +
> + if (!expr->metric_name) {
> + ret = -ENOMEM;
> + free(metric_events);
> + goto out;
> + }
> + expr->metric_threshold = m->metric_threshold;
> + expr->metric_unit = m->metric_unit;
> + expr->metric_events = metric_events;
> + expr->runtime = m->pctx->sctx.runtime;
> + list_add(&expr->nd, &me->head);
> + }
> +
> + if (combined_evlist) {
> + evlist__splice_list_tail(perf_evlist, &combined_evlist->core.entries);
> + evlist__delete(combined_evlist);
> + }
> +
> + list_for_each_entry(m, &metric_list, nd) {
> + if (m->evlist)
> + evlist__splice_list_tail(perf_evlist, &m->evlist->core.entries);
> + }
> +
> +out:
> + metricgroup__free_metrics(&metric_list);
> + return ret;
> +}
> +
> static int parse_groups(struct evlist *perf_evlist,
> const char *pmu, const char *str,
> bool metric_no_group,
> @@ -1699,6 +1902,9 @@ int metricgroup__parse_groups(struct evlist *perf_evlist,
> return -EINVAL;
> if (hardware_aware_grouping) {
> pr_debug("Use hardware aware grouping instead of traditional metric grouping method\n");
> + return hw_aware_parse_groups(perf_evlist, pmu, str,
> + metric_no_threshold, user_requested_cpu_list, system_wide,
> + /*fake_pmu=*/NULL, metric_events, table);
> }
>
>
> diff --git a/tools/perf/util/metricgroup.h b/tools/perf/util/metricgroup.h
> index 779f6ede1..89809df85 100644
> --- a/tools/perf/util/metricgroup.h
> +++ b/tools/perf/util/metricgroup.h
> @@ -6,6 +6,7 @@
> #include <linux/rbtree.h>
> #include <stdbool.h>
> #include "pmu-events/pmu-events.h"
> +#include "strbuf.h"
>
> struct evlist;
> struct evsel;
> @@ -66,6 +67,14 @@ struct metric_expr {
> int runtime;
> };
>
> +/**
> + * Each group is one node in the group string list.
> + */
> +struct metricgroup__group_strs {
> + struct list_head nd;
> + struct strbuf grouping_str;
> +};
> +
> struct metric_event *metricgroup__lookup(struct rblist *metric_events,
> struct evsel *evsel,
> bool create);
next prev parent reply other threads:[~2023-09-26 15:17 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-25 6:17 [RFC PATCH 00/25] Perf stat metric grouping with hardware information weilin.wang
2023-09-25 6:18 ` [RFC PATCH 01/25] perf stat: Add hardware-grouping cmd option to perf stat weilin.wang
2023-09-26 14:50 ` Liang, Kan
2023-09-25 6:18 ` [RFC PATCH 02/25] perf stat: Add basic functions for the hardware-grouping stat cmd option weilin.wang
2023-09-26 15:10 ` Liang, Kan [this message]
2023-09-25 6:18 ` [RFC PATCH 03/25] perf pmu-events: Add functions in jevent.py weilin.wang
2023-09-26 15:17 ` Liang, Kan
2023-09-25 6:18 ` [RFC PATCH 04/25] perf pmu-events: Add counter info into JSON files for SapphireRapids weilin.wang
2023-09-26 15:20 ` Liang, Kan
2023-09-25 6:18 ` [RFC PATCH 05/25] perf pmu-events: Add event counter data for Cascadelakex weilin.wang
2023-09-25 6:18 ` [RFC PATCH 06/25] perf pmu-events: Add event counter data for Icelakex weilin.wang
2023-09-25 6:18 ` [RFC PATCH 07/25] perf stat: Add helper functions for hardware-grouping method weilin.wang
2023-09-26 15:28 ` Liang, Kan
2023-09-25 6:18 ` [RFC PATCH 08/25] perf stat: Add functions to get counter info weilin.wang
2023-09-26 15:37 ` Liang, Kan
2023-09-25 6:18 ` [RFC PATCH 09/25] perf stat: Add helper functions for hardware-grouping method weilin.wang
2023-09-26 3:37 ` Yang Jihong
2023-09-26 20:51 ` Wang, Weilin
2023-09-25 6:18 ` [RFC PATCH 10/25] perf stat: Add helper functions to " weilin.wang
2023-09-26 3:44 ` Yang Jihong
2023-09-26 15:55 ` Liang, Kan
2023-09-25 6:18 ` [RFC PATCH 11/25] perf stat: Add utility " weilin.wang
2023-09-26 16:02 ` Liang, Kan
2023-09-25 6:18 ` [RFC PATCH 12/25] perf stat: Add more functions for " weilin.wang
2023-09-25 6:18 ` [RFC PATCH 13/25] perf stat: Add functions to " weilin.wang
2023-09-26 16:18 ` Liang, Kan
2023-09-25 6:18 ` [RFC PATCH 14/25] perf stat: Add build string function and topdown events handling in hardware-grouping weilin.wang
2023-09-26 16:21 ` Liang, Kan
2023-09-25 6:18 ` [RFC PATCH 15/25] perf stat: Add function to combine metrics for hardware-grouping weilin.wang
2023-09-25 6:18 ` [RFC PATCH 16/25] perf stat: Update keyword core to default_core to adjust to the changes for events with no unit weilin.wang
2023-09-26 16:25 ` Liang, Kan
2023-09-25 6:18 ` [RFC PATCH 17/25] perf stat: Handle taken alone in hardware-grouping weilin.wang
2023-09-25 6:18 ` [RFC PATCH 18/25] perf stat: Handle NMI " weilin.wang
2023-09-25 6:18 ` [RFC PATCH 19/25] perf stat: Handle grouping method fall back " weilin.wang
2023-09-25 6:18 ` [RFC PATCH 20/25] perf stat: Code refactoring " weilin.wang
2023-09-25 6:18 ` [RFC PATCH 21/25] perf stat: Add tool events support " weilin.wang
2023-09-25 6:18 ` [RFC PATCH 22/25] perf stat: Add TSC " weilin.wang
2023-09-26 16:35 ` Liang, Kan
2023-09-25 6:18 ` [RFC PATCH 23/25] perf stat: Fix a return error issue " weilin.wang
2023-09-26 16:36 ` Liang, Kan
2023-09-25 6:18 ` [RFC PATCH 24/25] perf stat: Add check to ensure correctness in platform that does not support hardware-grouping weilin.wang
2023-09-26 16:38 ` Liang, Kan
2023-09-25 6:18 ` [RFC PATCH 25/25] perf pmu-events: Add event counter data for Tigerlake weilin.wang
2023-09-26 16:41 ` Liang, Kan
2023-09-25 18:29 ` [RFC PATCH 00/25] Perf stat metric grouping with hardware information Ian Rogers
2023-09-26 20:40 ` Wang, Weilin
2023-09-26 14:43 ` Liang, Kan
2023-09-26 16:48 ` Liang, Kan
2023-09-26 20:40 ` Wang, Weilin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ccd091ec-d650-e522-8152-c37d00d952d8@linux.intel.com \
--to=kan.liang@linux.intel.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=caleb.biggers@intel.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=perry.taylor@intel.com \
--cc=peterz@infradead.org \
--cc=samantha.alt@intel.com \
--cc=weilin.wang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).