Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp2682147rwb; Mon, 7 Aug 2023 01:25:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFnoGBBbaoU0w+kEV128tHZSDixN+ps2Wh1xDyfzIRWiBwI7mau6+c2jqogWuS1MwDwoGUC X-Received: by 2002:a17:902:ea84:b0:1bc:50f9:8f20 with SMTP id x4-20020a170902ea8400b001bc50f98f20mr6053169plb.23.1691396710817; Mon, 07 Aug 2023 01:25:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691396710; cv=none; d=google.com; s=arc-20160816; b=BbNdAwRKtKJjA4969EsL6aB/hylYaqzxvT24h+Myc/Ht4AC3lhpWbFw04WEFtXF0ec RRe0w8q1cVSxkA2qHHO+pmNQe+GSrNuLSLhWsJMnDNbIyvaKNC9Vd+W+DUcm8GD0181p IhSjT132yOBfGrKyLrcmcfLFAPgv6Y6aOj+TPisoQ5zIZa6GgbrzcfP0XFRSNOH6F6Dl nHCAoF5lDoWt/L1kPbbBkIILtrRaLsD5Wmky7ZuIfXG1s0HIxNqmkyYcKxTdMKgt0PDH FKUK/mO33vwilUst6hsIhZ+R+Mk29qVBU48pmCN6EW0BZIiwDgXlpRYAylSQPXPrGuLh zB/w== 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=gWL/S4tBJi2ymcUhPnZfHybwx6dhF72DX/QQjkuc2rc=; fh=7pF9AUGuuVLtftwWy2EJKaooMcBit4LAHr6bHM40jlQ=; b=vUUM7+tSpcx+6mcX78r/8t7FccoXzkBM7iWzXKUS3PfND9khb8rXxnR93PkLv8+SJ/ MMOv1wrAxFSwD5kXlYKQpFWPOkunHgUE2k6nOAyKyJtpcrh1qk9BSnNGEoUxnNQWSIMH q3TIL0Mqk9Qpl5RY2mUMxHZLS3Msjyhixa+xX90RKgCKqIQQElFZmRvbr3UfxWSED5vG gAZgQftTmDTLFBUktd+cXVtxPA4+71AxqvxNH1QHlVRCpqiNGyEox9kD9ge048T5SVEX c2D0cefF9VRZWeG7SPInP/4pmwfjfNTLPDvqGgncKcHXHLuUz27/7a8zWDUVrrPvZIlc K3ow== 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 y2-20020a17090322c200b001bba3bfd21asi5462314plg.260.2023.08.07.01.24.59; Mon, 07 Aug 2023 01:25:10 -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 S230467AbjHGHvm (ORCPT + 99 others); Mon, 7 Aug 2023 03:51:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229517AbjHGHvl (ORCPT ); Mon, 7 Aug 2023 03:51:41 -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 AE18A1700; Mon, 7 Aug 2023 00:51:39 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R171e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045192;MF=renyu.zj@linux.alibaba.com;NM=1;PH=DS;RN=21;SR=0;TI=SMTPD_---0VpC-03F_1691394694; Received: from srmbuffer011165236051.sqa.net(mailfrom:renyu.zj@linux.alibaba.com fp:SMTPD_---0VpC-03F_1691394694) by smtp.aliyun-inc.com; Mon, 07 Aug 2023 15:51:35 +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 v6 1/7] perf pmu: "Compat" supports matching multiple identifiers Date: Mon, 7 Aug 2023 15:51:19 +0800 Message-Id: <1691394685-61240-2-git-send-email-renyu.zj@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1691394685-61240-1-git-send-email-renyu.zj@linux.alibaba.com> References: <1691394685-61240-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 --- 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