Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1206239rdb; Wed, 24 Jan 2024 07:57:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IE2ZU3soFohFO1byWDGk12uiHfN3CdN6ZeKhMUZXos07quNV2Ht9SPWsxkFvmaLnXZcv4L4 X-Received: by 2002:ad4:5967:0:b0:686:ac5b:fe7d with SMTP id eq7-20020ad45967000000b00686ac5bfe7dmr1711265qvb.125.1706111861493; Wed, 24 Jan 2024 07:57:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706111861; cv=pass; d=google.com; s=arc-20160816; b=N6WLs+r8zEjMOu9Z68lYBSRE8H//je1jFr7EVf5ZYi8IZL2sWZ11NsGeh5SvNrQItY HuIoR6a0x73EkcgLoCHiHJ+skacRHh1tCTr2KCn3eW6AFXmHVuFm55kdM4fqAJ79hlGU BJqWNpYqlWykdsSO8yX0v6BdPWA7KtJyH0ccBau07ldkMj0nOJ/PA6c6LJPATKmclmD7 F1bw90Hu3yoUGjAyrILpDRcxEulNvuYRW86ZnVVeX0OZoih5cc4kcS0/BsR6+TxMIndR gm0z0t4yZmQwHFaorGKvCYQTbHq4GC4vT290FRnprIfwhWgNgr5ad+OouvksCndXjx1Y WIMQ== 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=0vHGUU7w7sxAywce6jeZBVR/SVXGvRMcD5jS2PLJAMw=; fh=ZWraEf5Qm7BHJeckG5Ereq4+e7KUVKfmTPl2jlKE6rw=; b=AzWTxVqfdQ2sItrY3LgCQIuK8kpE7B3gZ9WL1EOasRQub7Jheqb8MAGOJQJ4oT+SFr zU+sQt/OGuotpj58aCjSoIKUhEkiWCbOOlTO6KypOFG52EplTfFCRjPxO6kPz8O6Vo0d pN92lkdyF9kHtgCIOtM//gZ4qoGZyZvu578fXKgj3lN4GUE8eri2GDKW4ik5czXs/LaX YeGOE0yCgGGM6SzwNl9oaNaR+TZ8AsYO2qDjwXFAgSLjR9wJ8crsWAaAr2AROyQ7AVN4 Fww9IhCgbcQrzpFDyH9d8szUPkY6VzlKFJDC5O0bUwoo6fVzUzdpbciUL4W/Hzh/2ICx N7fQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Uccq1EsL; 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-37293-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37293-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id u1-20020a0cb681000000b0068538a3d9e3si10572027qvd.212.2024.01.24.07.57.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 07:57:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-37293-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Uccq1EsL; 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-37293-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37293-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id C75BD1C237D1 for ; Wed, 24 Jan 2024 15:57:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 35AE37CF09; Wed, 24 Jan 2024 15:57:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Uccq1EsL" Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 A57621E503 for ; Wed, 24 Jan 2024 15:57:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706111852; cv=none; b=XqOCkJbXgOMxn1pZLJGCOk4Q4Gcyw9fel2/DR3WQLPSWExW40Fe6Sd+Go7hHxZ2w0KnEEk/s1F0nKih26mrnay/CBIBn3Pf9lEu2a6T7lyJoD9tMPow15+g8XHj5uKEi3g9KcwGN0u7PC1BLkIRHxmhHFYz1zmcanKzUZX43H3o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706111852; c=relaxed/simple; bh=59AdwdtgM5YTqYQccogZ5V6a4viQM3dqI7tLjQuTMpc=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=sYkiI9Pp7Q51rFO4OU8Qo0uTr3CyzCWEYxjajy7soIf0Ziyl3rwqTDuRpJQVcTXfuif8otQ2UaAhLUnvC+qcIJR5TEYnsubLHyjPs+VnL49FgIPVBlMyXcof27erLt0kDWzC1BCa0xASR3GsU3Q12gMbFaHQ4stpoYezdrmZoV4= 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=Uccq1EsL; arc=none smtp.client-ip=209.85.214.178 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-pl1-f178.google.com with SMTP id d9443c01a7336-1d76f1e3e85so180395ad.0 for ; Wed, 24 Jan 2024 07:57:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706111850; x=1706716650; 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=0vHGUU7w7sxAywce6jeZBVR/SVXGvRMcD5jS2PLJAMw=; b=Uccq1EsLyhB02nQ2ov6fbLGZCQFhguyeaC83XnAHiOF7o8TmHixKFyLxcKnH8rv/7T 29tAR77sQ2NMqpKX1J77dwhiVaJgjIil7tFqLHPIOWjmhRNNYzewtrmyoOW1/dXOvurz XU/S1wAj91KxxUcjvCpFFmff4Y6G8ld1hVXTBpU2hibA9Py4+kqAKHUzCqNIAUvEIsrM Tf5Y5G7gIPRLcA37+PPZpf34bWr4B/GrpxG8Y9xdua/1zRgmxE0xg3OMa5hcO6yAW1So e0NaaJtn59zln/NHZAyftvuxGxEuzCcZxEE+bj5nRcfemB6v9dc77mIYBy1syFfWVpIU jKOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706111850; x=1706716650; 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=0vHGUU7w7sxAywce6jeZBVR/SVXGvRMcD5jS2PLJAMw=; b=IHUoqGMINQBZyBvTW8HKQ9l3eYTrGIVrTsz1r2WIO4E3rR5yVaJXDLwEhVHqPxG64w t806yDNqEJxqOeQJkttExwSXiP/c07BRrY4iEfNZQNyuWEwI6WsXTMNCipnrNo/49gO4 r1WbQ+N/CVul5zCsjGfWp5OwztddinzvxFFn0+ttVHgl2WnfpE9RvoJ4m9d3Jyg0540/ XXtSXFQmZmLMA+IIoZoOvTAEqZcnvcPEqiYOovPz4qh35mIL1QjErq9d7+DpHdNol0Qf hvX7d7x78FdG2DKwdLa9zMse9Q5OkHpN/6gCw69Vj2TvbHTLwEZCP6b841X6nHaQj37v xO5g== X-Gm-Message-State: AOJu0YwCLGOyeH2tISS6vUgsgxr1hjlNHMeSD5mZXNxJEfKGqsVqi6jE aZIMoAAF48dxgeJ9Zwh8b38FT8Tyuwc6g8Wl6Cc+5g84s69fEOUoibn2RyZ42akFg+TQKCaKYyD f06zs/P33s+VCQ10IlgVROq866fVQ9jEDfBjZ X-Received: by 2002:a17:902:d4c3:b0:1d4:d451:b439 with SMTP id o3-20020a170902d4c300b001d4d451b439mr152655plg.5.1706111849630; Wed, 24 Jan 2024 07:57:29 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20231212230224.1473300-1-weilin.wang@intel.com> <20231212230224.1473300-10-weilin.wang@intel.com> In-Reply-To: <20231212230224.1473300-10-weilin.wang@intel.com> From: Ian Rogers Date: Wed, 24 Jan 2024 07:57:18 -0800 Message-ID: Subject: Re: [RFC PATCH v3 08/18] perf stat: Add functions to get counter info To: weilin.wang@intel.com Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Kan Liang , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Perry Taylor , Samantha Alt , Caleb Biggers , Mark Rutland , Yang Jihong Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Dec 12, 2023 at 3:03=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 > --- > tools/perf/util/metricgroup.c | 85 +++++++++++++++++++++++++++++++++-- > tools/perf/util/metricgroup.h | 15 +++++++ > 2 files changed, 97 insertions(+), 3 deletions(-) > > diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.= c > index 24268882d355..a393584c7a73 100644 > --- a/tools/perf/util/metricgroup.c > +++ b/tools/perf/util/metricgroup.c > @@ -1507,6 +1507,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= , > @@ -1525,7 +1546,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) > @@ -1560,6 +1581,8 @@ 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)) { > + if (!pe->counter) > + return -EINVAL; > event =3D event_info__new(d->event_id, pe->pmu, pe->count= er, /*free_counter=3D*/false); > if (!event) > return -ENOMEM; > @@ -1599,7 +1622,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); > } > > @@ -1608,6 +1631,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->size =3D pl->size; > + l->fixed_size =3D pl->fixed_size; > + pr_debug("create new pmu_layout: [pmu]=3D%s, [gp_size]=3D%ld, [fi= xed_size]=3D%ld\n", > + l->name, l->size, l->fixed_size); > + 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 > @@ -1626,6 +1700,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) { > @@ -1635,9 +1710,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 > } > diff --git a/tools/perf/util/metricgroup.h b/tools/perf/util/metricgroup.= h > index 3704545c9a11..802ca15e7c6b 100644 > --- a/tools/perf/util/metricgroup.h > +++ b/tools/perf/util/metricgroup.h > @@ -94,6 +94,21 @@ 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; > + //DECLARE_BITMAP(counter_bits, NR_COUNTERS); nit: this can go. > + /** The number of gp counters in the pmu. */ > + size_t size; > + size_t fixed_size; nit: same naming concern. Thanks, Ian > +}; > + > /** > * Each group is one node in the group string list. > */ > -- > 2.39.3 >