Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2354471rdh; Tue, 26 Sep 2023 23:08:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEmNvWn+5cmA/CciR28HObrmEeggjnJZm2EBXYnsNzSxYt+E8wYScdZ6XAZNuSes7tGUpc1 X-Received: by 2002:a17:902:c38d:b0:1c0:d5c6:748f with SMTP id g13-20020a170902c38d00b001c0d5c6748fmr805577plg.67.1695794922638; Tue, 26 Sep 2023 23:08:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695794922; cv=none; d=google.com; s=arc-20160816; b=RQi8tzM/ugbQkVZxMYG/8XRasILyHLqUU5sF9Za5U/KMRJcM/c87OAuZfo/ilm7WAi LohTM4YWu5TnhaCUTVu5mCFm0AkLU4OOqNOjI7NUIW+0C+rEFW1V+/ymPvjrNXtb3OmV i0h+JYLtnXjjfAV3tO2AJD37T+vpZ55+oIyVFDe5GN1FBqnv9+zlDymeQhAA/wwNAeGE 6O/qPqS8atuIcouOLgMzvLgfYZwP28o3m5B3KVHcM7+xvoWb0Fdz7wlPwvcmlcmh4Apc 30SRtGfPiYtVW7Eh5HO00/HlU+LPbOsnvqzeu5kkSXXeo3ggJ2kR/eyDp4tK0zWj8/yi ObRA== 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=bpHr7s4TD0w8V+hqkj5SiMN23aMHCA8LL9kkxNzbDWM=; fh=9KkEy5BETl+n6HvtEwBLK4NkRgCt0Iv6FwLxABl1azE=; b=oMTFVRj9t6THzQkuxUQ+xUCUhDt+sOcqJOfIled+CZ+6ByRAz4Fs559Xc1ZIRNTmlU vheKDMqDURHOyuDZ9YM5fkO6e8N8m2SeVAiUxdAXzJAQ9EeHWP0RQwu2Uyp/8xxYySoX bwnYTtXDhUe6Uo/tE28zBQqCf8+pGjGJxb7BDG1H/Lcd2RFvdhDPFxYvYsZJYHDKOEQT XQZmN2N3rhdzHEVFE0vOiYBz7BTIxOlMKkgMEnImhRjmdu7EWqRFgskUzBcuALWVe+Wz 6CFV58+XisiUSx6uJ+AkK4Lq8Iz5rgplnVtPJtitOuy6lm0fR+hOw5zAarJjiKr/ErT9 LAKg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id i9-20020a170902c94900b001bdc387b3a3si15964511pla.189.2023.09.26.23.08.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 23:08:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 8AD0A806C37E; Tue, 26 Sep 2023 23:01:13 -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 S229584AbjI0GAK (ORCPT + 99 others); Wed, 27 Sep 2023 02:00:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229495AbjI0GAF (ORCPT ); Wed, 27 Sep 2023 02:00:05 -0400 Received: from out30-101.freemail.mail.aliyun.com (out30-101.freemail.mail.aliyun.com [115.124.30.101]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8510D6; Tue, 26 Sep 2023 23:00:03 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R181e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045176;MF=renyu.zj@linux.alibaba.com;NM=1;PH=DS;RN=21;SR=0;TI=SMTPD_---0VszCdMF_1695794400; Received: from srmbuffer011165236051.sqa.net(mailfrom:renyu.zj@linux.alibaba.com fp:SMTPD_---0VszCdMF_1695794400) by smtp.aliyun-inc.com; Wed, 27 Sep 2023 14:00:00 +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 v11 1/7] perf pmu: "Compat" supports regular expression matching identifiers Date: Wed, 27 Sep 2023 13:59:45 +0800 Message-Id: <1695794391-34817-2-git-send-email-renyu.zj@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1695794391-34817-1-git-send-email-renyu.zj@linux.alibaba.com> References: <1695794391-34817-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]); Tue, 26 Sep 2023 23:01:13 -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 Reviewed-by: Ian Rogers Tested-by: Ian Rogers --- tools/perf/util/pmu.c | 27 +++++++++++++++++++++++++-- tools/perf/util/pmu.h | 1 + 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 0d81c05..5b41750 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", @@ -870,6 +871,28 @@ 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); + if (match) { + /* Ensure a full match. */ + match = pmatch[0].rm_so == 0 && (size_t)pmatch[0].rm_eo == strlen(id); + } + 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) @@ -910,8 +933,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 04b317b..a682c6b 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -239,6 +239,7 @@ void pmu_add_cpu_aliases_table(struct perf_pmu *pmu, char *perf_pmu__getcpuid(struct perf_pmu *pmu); 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