From patchwork Mon Sep 18 11:52:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jing Zhang X-Patchwork-Id: 141372 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp2596363vqi; Mon, 18 Sep 2023 04:56:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHdKcXqOIBzs/Awm0NmXRfUwmj34O+PkIKl1XDtNDqe3EmjCI72NwMApi09qeRKkZHbnmeS X-Received: by 2002:a9d:798d:0:b0:6b9:67e4:eba7 with SMTP id h13-20020a9d798d000000b006b967e4eba7mr9418227otm.23.1695038200545; Mon, 18 Sep 2023 04:56:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695038200; cv=none; d=google.com; s=arc-20160816; b=RQwD8jlSvqfGheclKXZHsv75zj6+SRdLXLalSl9H7w0Ka/CysKv5qrRzHLI34/oQWc GUd7eOw1Y8fCVzyT4LRIE3TroQXOVo3GQjwoF4kHB+f2/3DD1Izve0vv9q04lgRYLfGK MoqsUe7oGqEamNbDnKnVg/6wKW04U7xW8t8QI8sIOaxM9ua5wffUT4IbytIQjb2ONjP1 gzGJ1OY5C5UD8BpUzA4lJD7q12dvaH++w4dEVE4KUjyZAQmf+HhpY9QCHVkITLuY8UPS eMtlNupI0Gwj+bKAsEgPQNIkMwGmMqhCho39I6FDTLv8cSIE/pDZGdTkjgIHX/34KBfr b6dw== 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:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id b13-20020a63d80d000000b0057828b85ae3si5268759pgh.439.2023.09.18.04.56.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 04:56:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id 8F7C480A49A2; Mon, 18 Sep 2023 04:53:56 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241346AbjIRLxK (ORCPT + 27 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 groat.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 (groat.vger.email [0.0.0.0]); Mon, 18 Sep 2023 04:53:56 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777376376127436099 X-GMAIL-MSGID: 1777376376127436099 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);