Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp3135184rdb; Fri, 22 Sep 2023 21:40:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEExl4Sqq7X5cuxt6z7OexwBQOE4hZCjyhWnqhdw/lvJcB/zZaCR/x06G0fi1OBGeXpYef5 X-Received: by 2002:a05:6870:414d:b0:1d6:925:840d with SMTP id r13-20020a056870414d00b001d60925840dmr1710423oad.55.1695444055365; Fri, 22 Sep 2023 21:40:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695444055; cv=none; d=google.com; s=arc-20160816; b=N9anCOPaAyV8mv23TqcA5vE9dgrnbVgOv/WKbYI9yNYsd+UID5g/UHyTmOC7ijaEnb TBxzpUG7uAaPZnpZBHJDzQqLkKalzwhIvK3kAZhGBcGtN6rONlx4LrlLMwpBInarb5IP mXhANd0w84oJ858UPUzgqalZlaBwj11e4IQ9SbHkOAJtxMgRSWo6tKVZrzYTvfMIg4U9 nVArGsBF0nXrepArSyfQA6vWSrKH+o3K8fgupHNm0b3WqkO4uwMcdLlxuhzmN7r04bNC Wa4oFPYpYT3wP2aRTM4+rTw8hEq3gzZk2TBkhMkMPz/YksRUNP4XGBc/xUC5Fw4mTeGf 5bVA== 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=zgDKgKLNOq5UPjSMrvVQpqlAFLCGyJRKW8sSQYfce5A=; fh=u8xkv/KR/Q4wOfABmLr1yq/G8qAgpn8D5gwhBvQWXb8=; b=b5/FJzuXHyWwfgBgHiZmm/w+b97AF+gWGjVxxsraigjwtCwMK5rs0EiAjv5YgEE6pG /ghfeOfQV/Je9o00L7h4D9WJArExJfzLQnyC44eDrTg2QpJ0UqfJprld30MuDPLbCYaP VDbBlE3fS/XMVWdzuzB3wjRJuNrCIRriF8k5gl1922YNqa+fqvlwVQ/SHHnk7w2KFFD8 U6F2zJj4j9MVVNjFnwroXYmfkmYiw1sFyg2kyVwrKOuUQsueSjUcb8eCwmb+xRXF9jtQ vx03bkl4KIyLGylF2lDTbtGAsrP4Od2Ure3mWzSFfGNiw7L35s+Tz4Z1nL8IboWB1S70 nBXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=KW1foPL4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id o18-20020a170903211200b001c0d17abff8si5031764ple.256.2023.09.22.21.40.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 21:40:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=KW1foPL4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id EA8A682164F3; Fri, 22 Sep 2023 07:58:53 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231833AbjIVO64 (ORCPT + 99 others); Fri, 22 Sep 2023 10:58:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230171AbjIVO6z (ORCPT ); Fri, 22 Sep 2023 10:58:55 -0400 Received: from mail-qt1-x833.google.com (mail-qt1-x833.google.com [IPv6:2607:f8b0:4864:20::833]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20C5BCE for ; Fri, 22 Sep 2023 07:58:49 -0700 (PDT) Received: by mail-qt1-x833.google.com with SMTP id d75a77b69052e-414ba610766so392601cf.0 for ; Fri, 22 Sep 2023 07:58:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695394728; x=1695999528; 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=zgDKgKLNOq5UPjSMrvVQpqlAFLCGyJRKW8sSQYfce5A=; b=KW1foPL4LoxlqJ4kP58yEZ52r9JbHSW+br9xWL0P8bA3pyaY6C24K54rDUa4hN0kQ1 ifS3cPIxFkufgO4KP3Y9qj7Dzsy1DQl1JLeu3skymEQY35VW49riqe2mpxQmqmcm/yTg UWZe/29O6v1OO8NsnSA+YPpxG+qIObk1Q2SNhUVNmUpFThrUVippYPqmpfC1rJjtRF+a nzL21JcnODfpBreHCInR6BYywqOmcs5dJ5tFCL2lX1nNiL/WfGhkIY/gB/MdZ1u7ytIG 6BYU8+DRHNP/f1vFdA1lT+y7LK4uuilQOg+5PrIvWCLk2W0f9+lHiNP+mjQnw4x8RKs6 XN1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695394728; x=1695999528; 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=zgDKgKLNOq5UPjSMrvVQpqlAFLCGyJRKW8sSQYfce5A=; b=F5yI55/uTjaNyVEfqJdrlYaNBRXDJDdfKsI/4MPh/OFXQLraRY69vm7aj8xJL4u7DR hcsMSfLowC0q+cl19mPAdwD6vewA1kgbM4nxlNfpSpNZODBZKbHyQwuogL7p+DgWw2I2 ZbX01MCz1tDUgFM9qAHIS0EvuRIHVEwFzvYUSGDfCHarpRxh4UlmuKRLwtPIlFwMInA0 4EqvdBzy99t1SJ7pyA6QdW+uDpB1fUSpxbc5eTl8VNShjD/EDaUz/Xx/gK3UR9VKXywR N8gSZ4jO3RX8M2a5Ha0zgCiTWtBw8jh3Hh3WW4KdRHtIJzbdVPZ64H7fjJIhrRtKQ5vS YVPQ== X-Gm-Message-State: AOJu0Yx9KBW95y1uSWLMu0Xy8oEIaIsu6nTH6l7Q0TYs9FTga7ziqlnq VN/Fxg7WeenrnAhmybF5xvfcHTWjNDZh8ggxpjyv7A== X-Received: by 2002:a05:622a:1191:b0:403:eeb9:a76 with SMTP id m17-20020a05622a119100b00403eeb90a76mr181867qtk.17.1695394728023; Fri, 22 Sep 2023 07:58:48 -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> <0f5bbe93-1875-ff9b-a1d8-8518a8cf3e84@linux.alibaba.com> In-Reply-To: <0f5bbe93-1875-ff9b-a1d8-8518a8cf3e84@linux.alibaba.com> From: Ian Rogers Date: Fri, 22 Sep 2023 07:58:35 -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=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Fri, 22 Sep 2023 07:58:54 -0700 (PDT) On Fri, Sep 22, 2023 at 1:19=E2=80=AFAM Jing Zhang wrote: > > > > =E5=9C=A8 2023/9/21 =E4=B8=8A=E5=8D=882:36, Ian Rogers =E5=86=99=E9=81=93= : > > 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 "4340= 1" > >> 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 *pm= u_name, 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(i= d); > > } > > > > Ok, will do. > > > > 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. > > Could you please describe the function of pmu-event.l in more detail? I m= ay not fully understand it. So for now there's no need for a pmu-event.l, I'm fine with the code as-is. The issue for using regular expressions is that we need to compile (regcomp) then use them (regexec), and in this new code the result of the parsing is discarded - perhaps we can save on some compiling with a 1 element cache, let's wait to see performance data saying it is an issue. If we were to compile the regular expressions at build time with flex then the runtime cost, any caching, etc. is unnecessary. Hope this makes sense. Thanks, Ian > Thanks, > Jing > > > > > Thanks, > > Ian > > > >> + regfree(&re); > >> + > >> + return match; > >> +} > >> + > >> static int pmu_add_cpu_aliases_map_callback(const struct pmu_event *p= e, > >> const struct pmu_events_table = *table __maybe_unused, > >> void *vdata) > >> @@ -915,8 +934,8 @@ static int pmu_add_sys_aliases_iter_fn(const struc= t pmu_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->i= d)) { > >> 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 *pm= u, > >> 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 *sv= al); > >> > >> -- > >> 1.8.3.1 > >>