Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp1873248rwo; Sun, 23 Jul 2023 02:35:04 -0700 (PDT) X-Google-Smtp-Source: APBJJlES25O1Y6v7ndtTBXJfgqgpLK/ZyNx0V/uk5VAD58zHHynMej7TnaYmgDP/7sCmZXeRKOSd X-Received: by 2002:a17:902:f542:b0:1ba:fe63:6622 with SMTP id h2-20020a170902f54200b001bafe636622mr9804576plf.32.1690104904747; Sun, 23 Jul 2023 02:35:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690104904; cv=none; d=google.com; s=arc-20160816; b=hWg1NbmdWwl++IAXxFpdhZL6TnxBlVM76rOUiEQzdBOv1qDntD33Wb5kO+voYOy5EG XJDLJa5vFFk0RKo+hgihZRXzpT9z1EYs1b6tQvWCyI1Q4SPR+7GS2Tyv4J3+2wuvcQUV Y6psVN60PzXKBmEoYBUrW4CqMKfaW0/87Hrnikt0Uy0UMKxBIwM+lsY37vIAVCBBalOw imfRcKSPt0MZi4qK6vUyNZ3r6wwijO1Rk/it+jnAoL1k7yLULx0wXAPhZiAsmY3+WZ53 Fy2AfNlkrxRkCwMIHCQiz4jJKA3FZapEDo59vK16vHwR2uz4WUR9QzWVFRwaImfYM5Ge 3zXQ== 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=6Wax4c3HGRssm9fH3j65i8E1gEZq7hg8rPujtnaOf6g=; fh=eOu1KI7Hso2e/GDSxGFBosdiY3Bqk8zRJrvUK8bVCkE=; b=MCYtR3eFxLU0f7PD6Q0yP/gHYMmcSaY1KNs32Xz467eq6tS4GAV2ViZ106M3ndkWTB M1rpDdKkx9I7jLtBf+ctrX7Wmo0WK/rCeqbQLnFerZswVYHRUrVM7i9QNrD0g1XIxG9P OhLaPXfUxDz9AzO3q4h0lzEm8ZcRP+u0frBPY/uN7xnouKC7qZZXmHZvDao6K+xbEOup k1gj4h0rGYIeG6ZUWzf6eJGn/wGbQeFXfWXVnC5uvxPOgkFZ9hNpwdh3QfHuHDVjWe9T zKoI6Bw4CqUppQSiwJ6k7sQBSC8CdvBf9Y45w1WOEIGUO66P66QnU4kxamOttuaGv3/m ue0g== 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 s19-20020a170902c65300b001ac84f87b0fsi6430907pls.339.2023.07.23.02.34.52; Sun, 23 Jul 2023 02:35:04 -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 S229897AbjGWIWe (ORCPT + 99 others); Sun, 23 Jul 2023 04:22:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53726 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229452AbjGWIWc (ORCPT ); Sun, 23 Jul 2023 04:22:32 -0400 Received: from out30-100.freemail.mail.aliyun.com (out30-100.freemail.mail.aliyun.com [115.124.30.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB99710D1; Sun, 23 Jul 2023 01:22:28 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R101e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046049;MF=renyu.zj@linux.alibaba.com;NM=1;PH=DS;RN=20;SR=0;TI=SMTPD_---0Vnzn8Vl_1690100542; Received: from srmbuffer011165236051.sqa.net(mailfrom:renyu.zj@linux.alibaba.com fp:SMTPD_---0Vnzn8Vl_1690100542) by smtp.aliyun-inc.com; Sun, 23 Jul 2023 16:22:23 +0800 From: Jing Zhang To: John Garry , Ian Rogers Cc: Will Deacon , Mark Rutland , Robin Murphy , James Clark , Mike Leach , Leo Yan , Ilkka Koskinen , Alexander Shishkin , Jiri Olsa , Namhyung Kim , 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 v4 1/4] perf metric: Event "Compat" value supports matching multiple identifiers Date: Sun, 23 Jul 2023 16:21:50 +0800 Message-Id: <1690100513-61165-2-git-send-email-renyu.zj@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1690100513-61165-1-git-send-email-renyu.zj@linux.alibaba.com> References: <1690100513-61165-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, T_SCC_BODY_TEXT_LINE,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/metric. Since a Compat value can only match one identifier, when adding the same event alias and metric to PMUs with different identifiers, each identifier needs to be defined once, which is not streamlined enough. So let "Compat" value supports matching multiple identifiers. For example, the Compat value {abcde;123*} can match the PMU identifier "abcde" and the the PMU identifier with the prefix "123", where "*" is a wildcard. Tokens in Unit field are delimited by ';' with no spaces. Signed-off-by: Jing Zhang --- tools/perf/util/metricgroup.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index f3559be..c910df0 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -456,6 +456,31 @@ struct metricgroup_iter_data { void *data; }; +static bool match_pmu_identifier(const char *id, const char *compat) +{ + char *tmp = NULL, *tok, *str; + bool res; + int n; + + 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; +} + static int metricgroup__sys_event_iter(const struct pmu_metric *pm, const struct pmu_metrics_table *table, void *data) @@ -468,7 +493,7 @@ static int metricgroup__sys_event_iter(const struct pmu_metric *pm, while ((pmu = perf_pmu__scan(pmu))) { - if (!pmu->id || strcmp(pmu->id, pm->compat)) + if (!pmu->id || !match_pmu_identifier(pmu->id, pm->compat)) continue; return d->fn(pm, table, d->data); -- 1.8.3.1