Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp2014062lqp; Sat, 23 Mar 2024 21:58:30 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVYdbIG9DIXHY+cfKhwjcXfQl6E0zreUS8xnzoYKtdzs+2wMNbyTlfoa4OjQQagM3Mr7wxkkLGtd1+LBde7w9h63XQ31blGO4j6RHSxAA== X-Google-Smtp-Source: AGHT+IFTsGb1vkv023cxPSiMYeNghA5hW0+eZNH3nveu9ydaculP+lbgkr5O+vK7/tCoHQc7ithL X-Received: by 2002:a05:6358:7e41:b0:17e:6a48:fe86 with SMTP id p1-20020a0563587e4100b0017e6a48fe86mr4547544rwm.3.1711256310306; Sat, 23 Mar 2024 21:58:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711256310; cv=pass; d=google.com; s=arc-20160816; b=S0Kq4iYpG8mZaW4n+AVC0tuKYA3XmwyfW7cYRtNgEX9u6l/PGnr/szcrf3urqQLn1Z lWZQmYvIy3c2JXXK4/tqeS0KaBx8dH0Z7WNGirJS3jliUnwm0PcV01te1vdLFP5Gb+iQ 2EDOErJDWQImgIHQiwTN9smD8gBzS9+I1iEwOsc8L8G+lSBrlH82Drm055GxuQLa8Oe8 47fL+cihOr3k7vFQCbbMbQCuxQIgTaeFqy86tfSLpQ5Wp8ZxeF+PNfvzae8ouGjvr+LE jljlQE96B3qaUmGgK0cqwTB5Iugqd01PE5tqOz/U3eBpurgXCfjgCCfarscxY/jWv4fA 5vrA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=JY//JH8+Rx3oZ3x/aWWGC7L77LyNr1dunyhwT54TMMI=; fh=jRoJqjlRIAInStF2ktSDo6O02MO0Y0uAFWvbcvx2a+s=; b=L/AOhzd3t/7j99GlJi9GEH/3rFAyRT/EIXW/IXxuk8XZ5XiVT3iGhHitwyISfgtk2a QSl1VQT74MubruCOhfeSVQ5WoSpFUKEta3hPvbcpZ58+m9ygLV4EsXfzbJh/1JADPyft S+aJOibsGf9qNE9isCcoJcOKSCIwuxxcvSH2DX6DyVdK9htZeuJmaYuZpHshDYeD3vmr YtFsL1HmQXO1HAMXmpdESuwcy632D6jeCD99V2tZflGqjDxxckytZKCfQjFgVSH6I1z3 6sjYgkKm9I/Pizs4yQJJwy6+0+CBih5dnZSAKx3SyNOEZiXJNMNdfYNxK4NS5idRrVOB 9mtg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=3Xqo8yzy; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-112587-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112587-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id gl7-20020a17090b120700b0029bc34c3c5fsi5141323pjb.117.2024.03.23.21.58.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Mar 2024 21:58:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-112587-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=3Xqo8yzy; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-112587-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-112587-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id EBA7D282550 for ; Sun, 24 Mar 2024 04:58:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1B40F944F; Sun, 24 Mar 2024 04:58:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="3Xqo8yzy" Received: from mail-qt1-f181.google.com (mail-qt1-f181.google.com [209.85.160.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5D5E6134BE for ; Sun, 24 Mar 2024 04:58:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711256302; cv=none; b=NHtC24WbOCQg+8S17qVkFK0IXw2yV+lG2RFHXKBfrbwN9kXHJpE79/coCBVFPfJ6NDSgjfvpgCumfb/fiFB8cPtWDRl6v2aVmudBu+WC8Yyf1JBYJFYFQv+BWt6DPSz917hdt2kj8/4oPFDSS3wZSjyOE2lPFzGyFn4pua1mtHk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711256302; c=relaxed/simple; bh=Gu6WmAVAclfnwbUUBsxi8oNc/q6lur63hnxYQBkX69M=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=UNRrkwNxDZpWrCSSnk4w8VbaRSgcWsICa34sf9C6D5l7eFBVd3o8XF7/+5sJBUld7OMKFxWR3L6pS/b79od/gAY/NWxQTq9a3trO5OS5X8IsL+tvb/wMn3PTEt77P3SXfzJCRmD+ItSe3+P/07Xa8WMeQ5BqKGHeJspDuDNQgk0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=3Xqo8yzy; arc=none smtp.client-ip=209.85.160.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-qt1-f181.google.com with SMTP id d75a77b69052e-428405a0205so200071cf.1 for ; Sat, 23 Mar 2024 21:58:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711256299; x=1711861099; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=JY//JH8+Rx3oZ3x/aWWGC7L77LyNr1dunyhwT54TMMI=; b=3Xqo8yzyu7AboN8rUdFa24jMTlwP1QfIitrvWr8HFXt/1fCsn+0uqAQQ8vkLSc63oe 1Yozn94AfVLdYyhcNJlliFEfida7g5jzrfzefxfsKx4j8AGCLV45IGIdFR3wqgNQiEAS RsoblSkUkxFvEp6v2mmv5QQPJlf1bXIVwC5f5zXLK3k7Gc4+0ZbpI4ytsGXExDuAKu57 sXKbHGUUOx93A5D3/HBxB7tZomRUeXFhqShcZ7h9CTGvf4+Q6lkuTS2Kzdl67Nw9oQJL ofCxsJ6puCG0Igb7UY6Qc57wzBdm4VcdQ4/Xif/yjONY2tSbw6nRHVKYVSAxFRyT8yKx tlvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711256299; x=1711861099; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JY//JH8+Rx3oZ3x/aWWGC7L77LyNr1dunyhwT54TMMI=; b=Uc+OBpHJCUAY/cLHZOVNiNPbRUuyHbk0Y75vl9BXolVo5t/a4zSvvLDxNqcAeCT5Mr dgmVEBxJsS+Fi7OBxeJ25h1jZzMi2TwO7cp9Mnl+uXfMPG4oQI9HAuCdKthpd4C6xaBR eV3YqB1VYxY5zpORmJLEf0M/IeWcx2mNCGu4SUFCjzst6z4cCgUmLlls1IQIijnR0wYj btVEomBRRhL5kNVi7JPcGpjpX/DnjqbbIEMqJtWxSV+xXPdsgNbSt9ZHz4B7A4eF/Ysj MIMNoEL/MGS6c35OU9g7X6uzEaimpn0XmejLh7wOw/lYGvZxt8oJN7MXDwx1SEJ5KBLc EwHQ== X-Forwarded-Encrypted: i=1; AJvYcCWO2lV0Ea0co5lAo7a/GIZQ7jsScSKuCD9MYafmahbdEM9MGLX19wv0MXkJPCSjTUddv9mOssAY7hLXGgv2wvMUBJjx/bCq0POuD5D5 X-Gm-Message-State: AOJu0Yx1abObDkCKcSdgO6fpdWZ7eYJ7EfeSBUMo13rayqL+cj3ROTGf WqaYAZSX9tWDwOov+cWGTIAi0YhoMMhqJDMvAyJeDp4N878LqAi/8MXmLEw8XWabBHS7r+lKbH3 8vgDxXZhD1RskyZ+hLOvwrCWFnD588AKVbnud X-Received: by 2002:a05:622a:3ce:b0:431:55a:57fa with SMTP id k14-20020a05622a03ce00b00431055a57famr909008qtx.16.1711256299136; Sat, 23 Mar 2024 21:58:19 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240209031441.943012-1-weilin.wang@intel.com> <20240209031441.943012-7-weilin.wang@intel.com> In-Reply-To: <20240209031441.943012-7-weilin.wang@intel.com> From: Ian Rogers Date: Sat, 23 Mar 2024 21:58:08 -0700 Message-ID: Subject: Re: [RFC PATCH v4 06/15] perf stat: Add functions to get counter info To: weilin.wang@intel.com Cc: Kan Liang , Namhyung Kim , Arnaldo Carvalho de Melo , Peter Zijlstra , Ingo Molnar , Alexander Shishkin , Jiri Olsa , Adrian Hunter , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Perry Taylor , Samantha Alt , Caleb Biggers , Mark Rutland Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Feb 8, 2024 at 7:14=E2=80=AFPM wrote: > > From: Weilin Wang > > Add data structure metricgroup__pmu_counters to represent hardware counte= rs > available in the system. > > Add functions to parse pmu-events and create the list of pmu_info_list to > hold the counter information of the system. > > Add functions to free pmu_info_list and event_info_list before exit > grouping for hardware-grouping method > > This method would fall back to normal grouping when event json files do n= ot > support hardware aware grouping. > > Signed-off-by: Weilin Wang Reviewed-by: Ian Rogers Thanks, Ian > --- > tools/perf/util/metricgroup.c | 101 ++++++++++++++++++++++++++++++++-- > 1 file changed, 97 insertions(+), 4 deletions(-) > > diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.= c > index 2a917220fb34..9061ed4ca015 100644 > --- a/tools/perf/util/metricgroup.c > +++ b/tools/perf/util/metricgroup.c > @@ -179,6 +179,20 @@ struct metricgroup__event_info { > DECLARE_BITMAP(counters, NR_COUNTERS); > }; > > +/** > + * A node is the counter availability of a pmu. > + * This info is built up at the beginning from JSON file and > + * used as a reference in metric grouping process. > + */ > +struct metricgroup__pmu_counters { > + struct list_head nd; > + /** The name of the pmu the event collected on. */ > + const char *name; > + /** The number of gp counters in the pmu. */ > + size_t num_counters; > + size_t num_fixed_counters; > +}; > + > /** > * Each group is one node in the group string list. > */ > @@ -1530,6 +1544,27 @@ static int parse_counter(const char *counter, > return 0; > } > > +static void metricgroup__free_event_info(struct list_head > + *event_info_list) > +{ > + struct metricgroup__event_info *e, *tmp; > + > + list_for_each_entry_safe(e, tmp, event_info_list, nd) { > + list_del_init(&e->nd); > + free(e); > + } > +} > + > +static void metricgroup__free_pmu_info(struct list_head *pmu_info_list) > +{ > + struct metricgroup__pmu_counters *p, *tmp; > + > + list_for_each_entry_safe(p, tmp, pmu_info_list, nd) { > + list_del_init(&p->nd); > + free(p); > + } > +} > + > static struct metricgroup__event_info *event_info__new(const char *name, > const char *pmu_nam= e, > const char *counter= , > @@ -1548,7 +1583,7 @@ static struct metricgroup__event_info *event_info__= new(const char *name, > > e->name =3D name; > e->free_counter =3D free_counter; > - e->pmu_name =3D strdup(pmu_name); > + e->pmu_name =3D pmu_name; > if (free_counter) { > ret =3D set_counter_bitmap(0, e->counters); > if (ret) > @@ -1583,7 +1618,9 @@ static int metricgroup__add_metric_event_callback(c= onst struct pmu_event *pe, > struct metricgroup__add_metric_event_data *d =3D data; > > if (!strcasecmp(pe->name, d->event_name)) { > - event =3D event_info__new(d->event_id, pe->pmu, pe->count= er, /*free_counter=3D*/false); > + if (!pe->counters) > + return -EINVAL; > + event =3D event_info__new(d->event_id, pe->pmu, pe->count= ers, /*free_counter=3D*/false); > if (!event) > return -ENOMEM; > list_add(&event->nd, d->list); > @@ -1622,7 +1659,7 @@ static int get_metricgroup_events(const char *full_= id, > .event_name =3D id, > .event_id =3D full_id, > }; > - ret =3D pmu_events_table_for_each_event(table, > + ret =3D pmu_events_table__for_each_event(table, /*pmu=3D*= /NULL, > metricgroup__add_metric_event_callback, &= data); > } > > @@ -1631,6 +1668,57 @@ static int get_metricgroup_events(const char *full= _id, > return ret; > } > > +static struct metricgroup__pmu_counters *pmu_layout__new(const struct pm= u_layout *pl) > +{ > + struct metricgroup__pmu_counters *l; > + > + l =3D zalloc(sizeof(*l)); > + > + if (!l) > + return NULL; > + > + l->name =3D pl->pmu; > + l->num_counters =3D pl->num_counters; > + l->num_fixed_counters =3D pl->num_fixed_counters; > + pr_debug("create new pmu_layout: [pmu]=3D%s, [gp_size]=3D%ld, [fi= xed_size]=3D%ld\n", > + l->name, l->num_counters, l->num_fixed_counters); > + return l; > +} > + > +static int metricgroup__add_pmu_layout_callback(const struct pmu_layout = *pl, > + void *data) > +{ > + struct metricgroup__pmu_counters *pmu; > + struct list_head *d =3D data; > + int ret =3D 0; > + > + pmu =3D pmu_layout__new(pl); > + if (!pmu) > + return -ENOMEM; > + list_add(&pmu->nd, d); > + return ret; > +} > + > +/** > + * get_pmu_counter_layouts - Find counter info of the architecture from > + * the pmu_layouts table > + * @pmu_info_list: the list that the new counter info of a pmu is added = to. > + * @table: pmu_layouts table that is searched for counter info. > + */ > +static int get_pmu_counter_layouts(struct list_head *pmu_info_list, > + const struct pmu_layouts_table > + *table) > +{ > + LIST_HEAD(list); > + int ret; > + > + ret =3D pmu_layouts_table__for_each_layout(table, > + metricgroup__add_pmu_layo= ut_callback, &list); > + > + list_splice(&list, pmu_info_list); > + return ret; > +} > + > /** > * hw_aware_build_grouping - Build event groupings by reading counter > * requirement of the events and counter available on the system from > @@ -1649,6 +1737,7 @@ static int hw_aware_build_grouping(struct expr_pars= e_ctx *ctx __maybe_unused, > LIST_HEAD(event_info_list); > size_t bkt; > const struct pmu_events_table *etable =3D perf_pmu__find_events_t= able(NULL); > + const struct pmu_layouts_table *ltable =3D perf_pmu__find_layouts= _table(NULL); > > #define RETURN_IF_NON_ZERO(x) do { if (x) return x; } while (0) > hashmap__for_each_entry(ctx->ids, cur, bkt) { > @@ -1658,9 +1747,13 @@ static int hw_aware_build_grouping(struct expr_par= se_ctx *ctx __maybe_unused, > > ret =3D get_metricgroup_events(id, etable, &event_info_li= st); > if (ret) > - return ret; > + goto err_out; > } > + ret =3D get_pmu_counter_layouts(&pmu_info_list, ltable); > > +err_out: > + metricgroup__free_event_info(&event_info_list); > + metricgroup__free_pmu_info(&pmu_info_list); > return ret; > #undef RETURN_IF_NON_ZERO > } > -- > 2.42.0 >