Received: by 2002:a05:7412:bc1a:b0:d7:7d3a:4fe2 with SMTP id ki26csp1333343rdb; Mon, 21 Aug 2023 04:57:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHhd3RO1f6g2RtHaxc+0Yv5ddWcg8hgkPwWi3dqooE6g5m+cxe9RykxY9i5m5C2JBrFWHJy X-Received: by 2002:aa7:c318:0:b0:522:1fd2:ca7a with SMTP id l24-20020aa7c318000000b005221fd2ca7amr4365036edq.29.1692619075230; Mon, 21 Aug 2023 04:57:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692619075; cv=none; d=google.com; s=arc-20160816; b=zv4GdfN4JHw6QmjOqQHTobvZa/Oiwo+J1/IK5qC1by1XY3YO/60GBvnm/zvQ9501Ws 9IFtkak7yoywom+qy4L08Qb+56LxKEx6Mk53uYqNoymKECQBU90XZVG+c7CGTnLLMiuG 6ikVbMu8h0dbtKgiQimBb8tadaMWNuikySUbPo3njbkmV9fll1RfaCntFWmnXRwL0SkE wn24BeGyefi0Z2ieTxUKnfAMvL+69yf1/6IzQYw994XW3fEOZhH70LmwjsxWJiH5wrGI 4F3pPGu/uXbiXAXVAX/9hMVaZT3mwCdICymTNJnSLP5LILOlgWWXchTBb4tX1ucpE/Xv T43A== 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=21Gl/nGY8Fz0qaFi4Ux6NVgfGwhNbZ3pq/BCaA5zfG4=; fh=7pF9AUGuuVLtftwWy2EJKaooMcBit4LAHr6bHM40jlQ=; b=inZYWyd7aTgxXP6lCleRrsf3/3/IgLsZ0De/TLh7/8pLuOH2iARV1aoq5bxBWJHt/0 Oo47jNd8rS4+RjVMYIEVwxTYs8DI3x87uqDfsljWrkhNnSFnyBMO6ED81SEeoTnwKBc7 iwyefm+Q9tzTigUKQFnEIiDF2t7gF/r5Y8usfsdcUElZphDm1ts81zT4vPGBFG5/Hqka 839meVJf58qxkK1nsXZ/39FkdHiQpW6hbC7Rxj1gfFq0QxkYUs6T9kKezjWGS2mPbawG 11x3OEbzYnPfH+y/2ccyTDmxjNkK++ytrJ2xdeO34UMi1vFB1iYKMh/255ae1t9O6xsQ VI4Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n21-20020aa7c695000000b0052a129d7112si220897edq.161.2023.08.21.04.57.30; Mon, 21 Aug 2023 04:57:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234035AbjHUIge (ORCPT + 99 others); Mon, 21 Aug 2023 04:36:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234029AbjHUIgd (ORCPT ); Mon, 21 Aug 2023 04:36:33 -0400 Received: from out30-99.freemail.mail.aliyun.com (out30-99.freemail.mail.aliyun.com [115.124.30.99]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FC44B5; Mon, 21 Aug 2023 01:36:30 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R131e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046050;MF=renyu.zj@linux.alibaba.com;NM=1;PH=DS;RN=21;SR=0;TI=SMTPD_---0VqEq8BB_1692606986; Received: from srmbuffer011165236051.sqa.net(mailfrom:renyu.zj@linux.alibaba.com fp:SMTPD_---0VqEq8BB_1692606986) by smtp.aliyun-inc.com; Mon, 21 Aug 2023 16:36:27 +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 v7 1/8] perf pmu: "Compat" supports matching multiple identifiers Date: Mon, 21 Aug 2023 16:36:10 +0800 Message-Id: <1692606977-92009-2-git-send-email-renyu.zj@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1692606977-92009-1-git-send-email-renyu.zj@linux.alibaba.com> References: <1692606977-92009-1-git-send-email-renyu.zj@linux.alibaba.com> X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL autolearn=ham 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 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" supports matching multiple identifiers for uncore PMU alias. For example, the Compat value {43401;436*} can match the PMU identifier "43401", that is, CMN600_r0p0, and the PMU identifier with the prefix "436", that is, all CMN650, where "*" is a wildcard. Tokens in Unit field are delimited by ';' with no spaces. Signed-off-by: Jing Zhang Reviewed-by: John Garry --- tools/perf/util/pmu.c | 33 +++++++++++++++++++++++++++++++-- tools/perf/util/pmu.h | 1 + 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index ad209c8..6402423 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -776,6 +776,35 @@ static bool pmu_uncore_alias_match(const char *pmu_name, const char *name) return res; } +bool pmu_uncore_identifier_match(const char *id, const char *compat) +{ + char *tmp = NULL, *tok, *str; + bool res; + int n; + + /* + * The strdup() call is necessary here because "compat" is a const str* + * type and cannot be used as an argument to strtok_r(). + */ + str = strdup(compat); + if (!str) + return false; + + tok = strtok_r(str, ";", &tmp); + for (; tok; tok = strtok_r(NULL, ";", &tmp)) { + n = strlen(tok); + if ((tok[n - 1] == '*' && !strncmp(id, tok, n - 1)) || + !strcmp(id, tok)) { + res = true; + goto out; + } + } + res = false; +out: + free(str); + return res; +} + struct pmu_add_cpu_aliases_map_data { struct list_head *head; const char *name; @@ -847,8 +876,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(pmu->id, pe->compat)) { __perf_pmu__new_alias(idata->head, -1, (char *)pe->name, (char *)pe->desc, diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index b9a02de..9d4385d 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -241,6 +241,7 @@ void pmu_add_cpu_aliases_table(struct list_head *head, 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 *id, const char *compat); void perf_pmu_free_alias(struct perf_pmu_alias *alias); int perf_pmu__convert_scale(const char *scale, char **end, double *sval); -- 1.8.3.1