Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp1567604rdb; Wed, 20 Sep 2023 12:51:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IELOAxpamQNbUaXhJg7WTrwyZLia1aVI1ge4ezmmBbE+cD33re2EeAAm5eYnmQJpLCcplwe X-Received: by 2002:a05:6358:9107:b0:135:a10e:1ed0 with SMTP id q7-20020a056358910700b00135a10e1ed0mr3177138rwq.23.1695239506225; Wed, 20 Sep 2023 12:51:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695239506; cv=none; d=google.com; s=arc-20160816; b=VgaZlMq2sB84KFzzxqELXqRTZILKyBS/ETl9MLj1mwJprbd7A7k+SimHi+A/XNgyoz KBsK/UbJ/lyLEX8qpYAdTtfpuLNBgZ3P3NHNE+3dN+Uv4K9Td4vIXOGhXNHd425Pz08e IuBleLUee8MSEF33o/mifJ3GWcm13Zj+nvN0HK9EBeN8jxdV3mBPy7dfQDyWlnwZrhuu Dt+q2fs/UxOe3E+1bEYKHY25exvaCppTbLvoUKPfAeACZjAGgGJ/32ipd3IjPdgNjh3T iUjadREIaB0GXpZcwbpobemZRoycigWVZmYGA0ugomNx31AknYj2nVbhbNkquuCBEPC5 JGog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=0O+D8ee7zVjlDA63SdSMbPU/xhmCnjuF2y/9Wte3IZU=; fh=u8xkv/KR/Q4wOfABmLr1yq/G8qAgpn8D5gwhBvQWXb8=; b=fYBzPX1ntIiuX4mw69G7mFB//DCtX6NGzTMqNzh4gt39hA05GyubZlezmp2NOp73t1 f0UqYdYmE4lz8t5fhwbJeaL/mmYoW5MD2PpBDbjVIY0qL1knVUwQgdDr5avKZL1d51wo bodEQ7LwHyJ9KLFRCWJFTXKmV1Jf2szgw3ZU5WBGj7Z+FnNVbkBdGIacEX++ib4BlJsn THIjemrz7uR+Up3H9Gy/4yW/k0oLFw03Aaw7BQNbH2SsF/hXiPObyS3va7j0bjlYiIqf zbNtWrF5jDLo9pKT5g96otmhmJEQZ3UknrDL/yjBkmAc7q2hHRQs2U6J0uLpDq74bWlu YNgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=NQJOdJ8W; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id i12-20020a633c4c000000b00578a6aaae10si1621290pgn.86.2023.09.20.12.51.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Sep 2023 12:51:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=NQJOdJ8W; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id BF0AA80440DF; Wed, 20 Sep 2023 11:37:16 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229753AbjITShP (ORCPT + 99 others); Wed, 20 Sep 2023 14:37:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229708AbjITShO (ORCPT ); Wed, 20 Sep 2023 14:37:14 -0400 Received: from mail-qt1-x835.google.com (mail-qt1-x835.google.com [IPv6:2607:f8b0:4864:20::835]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7A17CC for ; Wed, 20 Sep 2023 11:37:07 -0700 (PDT) Received: by mail-qt1-x835.google.com with SMTP id d75a77b69052e-41513d2cca7so65791cf.0 for ; Wed, 20 Sep 2023 11:37:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695235027; x=1695839827; 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=0O+D8ee7zVjlDA63SdSMbPU/xhmCnjuF2y/9Wte3IZU=; b=NQJOdJ8WxdL54Ou233drNw7O9zKHOOoHyyW6zSoT/ZS08d2yM70cmDN+pncETN+dwe b4wWDGIaPwHx2Dh5p/m9z7mQmHxRZ6nsLELHK7+R2NozymYYfX74airpiEkj9xc/afvr SXwtqySL/KV1AsMsxSJ6FT9gOr9Tr9eL1kglQL8uI9BtAKxP57f/7/bjLZZ7qUPwyovw IUzQrn+YCrlSrPIeLMraAPUuakiOTyhPLjXoeVJ5srGkYJllT2ed8ZUom/RZ9YP8o2cT uQNjJAb9UjZqkEaVDJCdZR9fBiRzGoR2EBmfmyeXdSZtEr/Zq0Z7KYPc0oc4O/sWklo5 8bHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695235027; x=1695839827; 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=0O+D8ee7zVjlDA63SdSMbPU/xhmCnjuF2y/9Wte3IZU=; b=Hh89Nkk/HCT0U33HdXbH7MiifWTvWSs9R/ubcpu0+FXgLPV5wHYz5PXFEw+8/q4tHV GakpOEkfoiQ8G90pX8D6ehpqho9iO7TTTpznY7yZh3aUBZI59fGHoCHs1N/rr7wS777n 7FWS5IBEtFhaLsPt+GTCreOtVJniVSxuBX0QSWFw7V1DkyTrevd8XymeStclMqWsfENl vkqTrJIQehF9rm+lwRu5yxwj/T7KdjTuXWfmzMEzlxHYpS2PX8Gt10VAULEHctQ6HrOf OP7N304u/lqYAb0v/5R3UrnDmHzauIGEFmXnYgpDox9Q+g1OguW2vlnUFb2/Vn+7vk4L RMIw== X-Gm-Message-State: AOJu0Yze2ImJItbuGcOkDAaoMviC7ZX35tKzX36KtyAPWbYt4OEltOPN EBmq8e8ybNeAJQRNTzoBEc8HN8638Elco6KDEfMIUA== X-Received: by 2002:ac8:4e4a:0:b0:416:ea40:6e8c with SMTP id e10-20020ac84e4a000000b00416ea406e8cmr21592qtw.6.1695235026683; Wed, 20 Sep 2023 11:37:06 -0700 (PDT) MIME-Version: 1.0 References: <1695037955-107983-1-git-send-email-renyu.zj@linux.alibaba.com> <1695037955-107983-2-git-send-email-renyu.zj@linux.alibaba.com> In-Reply-To: <1695037955-107983-2-git-send-email-renyu.zj@linux.alibaba.com> From: Ian Rogers Date: Wed, 20 Sep 2023 11:36:55 -0700 Message-ID: Subject: Re: [PATCH v9 1/7] perf pmu: "Compat" supports regular expression matching identifiers To: Jing Zhang Cc: John Garry , Will Deacon , James Clark , Arnaldo Carvalho de Melo , Mark Rutland , Mike Leach , Leo Yan , Namhyung Kim , Peter Zijlstra , Ingo Molnar , Alexander Shishkin , Jiri Olsa , Adrian Hunter , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-doc@vger.kernel.org, Zhuo Song , Shuai Xue Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Wed, 20 Sep 2023 11:37:16 -0700 (PDT) On Mon, Sep 18, 2023 at 4:52=E2=80=AFAM Jing Zhang wrote: > > The jevent "Compat" is used for uncore PMU alias or metric definitions. > > The same PMU driver has different PMU identifiers due to different > hardware versions and types, but they may have some common PMU event. > Since a Compat value can only match one identifier, when adding the > same event alias to PMUs with different identifiers, each identifier > needs to be defined once, which is not streamlined enough. > > So let "Compat" support using regular expression to match identifiers > for uncore PMU alias. For example, if the "Compat" value is set to > "43401|43c01", it would be able to match PMU identifiers such as "43401" > or "43c01", which correspond to CMN600_r0p0 or CMN700_r0p0. > > Signed-off-by: Jing Zhang > --- > tools/perf/util/pmu.c | 23 +++++++++++++++++++++-- > tools/perf/util/pmu.h | 1 + > 2 files changed, 22 insertions(+), 2 deletions(-) > > diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c > index e215985..7e2242f 100644 > --- a/tools/perf/util/pmu.c > +++ b/tools/perf/util/pmu.c > @@ -28,6 +28,7 @@ > #include "strbuf.h" > #include "fncache.h" > #include "util/evsel_config.h" > +#include > > struct perf_pmu perf_pmu__fake =3D { > .name =3D "fake", > @@ -875,6 +876,24 @@ static bool pmu_uncore_alias_match(const char *pmu_n= ame, const char *name) > return res; > } > > +bool pmu_uncore_identifier_match(const char *compat, const char *id) > +{ > + regex_t re; > + regmatch_t pmatch[1]; > + int match; > + > + if (regcomp(&re, compat, REG_EXTENDED) !=3D 0) { > + /* Warn unable to generate match particular string. */ > + pr_info("Invalid regular expression %s\n", compat); > + return false; > + } > + > + match =3D !regexec(&re, id, 1, pmatch, 0); I wonder if we can make the regular expressions like "^(434|436|43c|43a)" more like "(434|436|43c|43a).*", so that we fully match the id string, by here doing: if (match) { /* Ensure a full match. */ match =3D pmatch[0].rm_so =3D=3D 0 && pmatch[0].rm_eo =3D=3D strlen(id); } I think longer term we can use jevents.py to generate a pmu-events.l, which would have a contents something like: (434|436|43c|43a).* { return PMU_....;} That should make the matching faster but may add some restrictions onto the regular expression. Thanks, Ian > + regfree(&re); > + > + return match; > +} > + > static int pmu_add_cpu_aliases_map_callback(const struct pmu_event *pe, > const struct pmu_events_table *ta= ble __maybe_unused, > void *vdata) > @@ -915,8 +934,8 @@ static int pmu_add_sys_aliases_iter_fn(const struct p= mu_event *pe, > if (!pe->compat || !pe->pmu) > return 0; > > - if (!strcmp(pmu->id, pe->compat) && > - pmu_uncore_alias_match(pe->pmu, pmu->name)) { > + if (pmu_uncore_alias_match(pe->pmu, pmu->name) && > + pmu_uncore_identifier_match(pe->compat, pmu->id))= { > perf_pmu__new_alias(pmu, > pe->name, > pe->desc, > diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h > index bd5d804..fc155ce 100644 > --- a/tools/perf/util/pmu.h > +++ b/tools/perf/util/pmu.h > @@ -240,6 +240,7 @@ void pmu_add_cpu_aliases_table(struct perf_pmu *pmu, > char *perf_pmu__getcpuid(struct perf_pmu *pmu); > const struct pmu_events_table *pmu_events_table__find(void); > const struct pmu_metrics_table *pmu_metrics_table__find(void); > +bool pmu_uncore_identifier_match(const char *compat, const char *id); > > int perf_pmu__convert_scale(const char *scale, char **end, double *sval)= ; > > -- > 1.8.3.1 >