Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp6122570rdb; Mon, 18 Sep 2023 05:06:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFt8mSMp02wH7cwS/tr1tHfVukaOBp2sF/FFtZjsmgduME4AX+2GTChIL/9VeQx3E9+GPXS X-Received: by 2002:a17:902:e884:b0:1bb:2020:be0d with SMTP id w4-20020a170902e88400b001bb2020be0dmr11171022plg.14.1695038804198; Mon, 18 Sep 2023 05:06:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695038804; cv=none; d=google.com; s=arc-20160816; b=X3RGA/jNEtlM40wdEtTOCbowCoMETDooI57z5m6LfwUXDhcGwnoliuU502+a8H2Ep9 IXajb7GkqnlhBG/uYE3ZZgHZHioBV566Pscr/T7t9SpEAVH3jmWV9jdTM7+CPcWD0H0O avbcgr4bfV3+3Dh/EYxGc8CAZ7QoN798CImujkjPyqvzX3IdervifAnxN3+JSPF0KUi1 aon0/8MeTFotLrJYHfnmTjvk0q62q1LY3w4sMnATubMYYk/xSYYlTkFEboyZuHe7O/x4 MMFTq7aPZHFHkPqvxXea34EVV6PUB7eQj0EDGr5f3wYhOgkiWqd+xpPNdvkLu9vi2gz2 TV3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=OwV5c0sYhgDiSmZo+sCuGD9fDD/j99ylCgz72MdTbfg=; fh=9KkEy5BETl+n6HvtEwBLK4NkRgCt0Iv6FwLxABl1azE=; b=KQXZVL1GWQ9QQHi3ldCF406DaHNWf5WZD2OH1fTHdwrYTvVuVZ6sEnhF1T8tX+wlsI R4RxF7V+Cbm+T36cuQUmnKo7W/tCse7u+87Vrk5mQjxzfp7zsaXpgzO0upgwPud+Hrze W0DpSOw7woRW350u7OKrF0jb/ql7dzVMltr+M3rbkDLtXBGT4vuCjJdYv8V/DsYfCgO0 COnLHrkeWWVQe3WCKgbxbEirLOnQcoexQBYqkfHlwManHaDXTJ+pRauEa+8RzTz1gPPV 53OC0spDLXfBxdTxFVTb87GhQwfD0oJg5B3v5sgRUeYK+abMiDNK5nwdIWfbibfET770 97sg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id x13-20020a170902ec8d00b001b9d180fd9asi3321479plg.121.2023.09.18.05.06.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 05:06:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 08EC48021EFA; Mon, 18 Sep 2023 04:53:41 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241776AbjIRLxK (ORCPT + 99 others); Mon, 18 Sep 2023 07:53:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241749AbjIRLwz (ORCPT ); Mon, 18 Sep 2023 07:52:55 -0400 Received: from out30-98.freemail.mail.aliyun.com (out30-98.freemail.mail.aliyun.com [115.124.30.98]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55379E6; Mon, 18 Sep 2023 04:52:49 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R201e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046056;MF=renyu.zj@linux.alibaba.com;NM=1;PH=DS;RN=21;SR=0;TI=SMTPD_---0VsMQsjd_1695037964; Received: from srmbuffer011165236051.sqa.net(mailfrom:renyu.zj@linux.alibaba.com fp:SMTPD_---0VsMQsjd_1695037964) by smtp.aliyun-inc.com; Mon, 18 Sep 2023 19:52:45 +0800 From: Jing Zhang To: John Garry , Ian Rogers Cc: 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 , Jing Zhang , Shuai Xue Subject: [PATCH v9 1/7] perf pmu: "Compat" supports regular expression matching identifiers Date: Mon, 18 Sep 2023 19:52:29 +0800 Message-Id: <1695037955-107983-2-git-send-email-renyu.zj@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1695037955-107983-1-git-send-email-renyu.zj@linux.alibaba.com> References: <1695037955-107983-1-git-send-email-renyu.zj@linux.alibaba.com> X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Mon, 18 Sep 2023 04:53:41 -0700 (PDT) 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 = { .name = "fake", @@ -875,6 +876,24 @@ static bool pmu_uncore_alias_match(const char *pmu_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) != 0) { + /* Warn unable to generate match particular string. */ + pr_info("Invalid regular expression %s\n", compat); + return false; + } + + match = !regexec(&re, id, 1, pmatch, 0); + regfree(&re); + + return match; +} + static int pmu_add_cpu_aliases_map_callback(const struct pmu_event *pe, const struct pmu_events_table *table __maybe_unused, void *vdata) @@ -915,8 +934,8 @@ static int pmu_add_sys_aliases_iter_fn(const struct 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->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