From patchwork Wed Sep 27 05:59:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jing Zhang X-Patchwork-Id: 145184 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp2417174vqu; Tue, 26 Sep 2023 23:11:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGddWP0Fjt+KQCuGJpEE6XI+RLwqNLWGMVsfS0WbFPGb9U7HdCxFNUDywUUlV7WUHH4PLf6 X-Received: by 2002:a05:620a:394b:b0:774:2c35:3796 with SMTP id qs11-20020a05620a394b00b007742c353796mr1049207qkn.34.1695795102428; Tue, 26 Sep 2023 23:11:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695795102; cv=none; d=google.com; s=arc-20160816; b=EQHIccZoFhjyc/nH1ZPPnxytTK7IZcG3Id5SLFFHI3Jss8CMA/v7Em9U74ljPW3g3L KasmGx5zkXwEdXirvS0KxoTyGEwvWaa21et+piWVSWe94IKCz3zRoMW0Ww2fFY5nYNOX mxEQ0qu0HGcXdtZlhjDDRBy04V/ZeIak/8SD8pJTliXgNBOR3OFScdWHxW0EvzSC628G 5/Qlsmyp6jNgYRfCmlNy1SOMrfOmJlnQdg/56wneZTc5OxMnswncqrDiVecNGQby8lm3 MJtWtf8yRl6YW9dGq99s7MvEQoGIz3gKdhykG7nLieYaRVyf2ZZqZiwJjaahuzE8fWTh SqiQ== 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 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id u71-20020a63854a000000b00578bdc2ccadsi14945953pgd.197.2023.09.26.23.11.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 23:11:42 -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; 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=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 morse.vger.email (Postfix) with ESMTP id 8DE6080B19E9; Tue, 26 Sep 2023 23:00:36 -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 S229590AbjI0GAK (ORCPT + 25 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 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]); Tue, 26 Sep 2023 23:00:36 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778170045171728791 X-GMAIL-MSGID: 1778170045171728791 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);