From patchwork Sun Jul 23 08:21:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jing Zhang X-Patchwork-Id: 124441 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp1177845vqg; Sun, 23 Jul 2023 02:34:29 -0700 (PDT) X-Google-Smtp-Source: APBJJlHSCtJQcFB/fP8PRTOZ1x6200S3eiC9njvrwVhlnVeeY9cIIC/pC4bNAjgjHCJYzGI+zTiL X-Received: by 2002:a17:907:7f90:b0:99b:56d4:82bb with SMTP id qk16-20020a1709077f9000b0099b56d482bbmr10983681ejc.6.1690104869413; Sun, 23 Jul 2023 02:34:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690104869; cv=none; d=google.com; s=arc-20160816; b=CEtZPomuqKV2F8q/fYglAc160QctA3rbeD50SU7GPy3qJ9WdldliZNv8uKrcRjbzp1 DwMmGbw13SkPDic/S2HVo6kpyiJHOm4MjJl9FQNw+oHSLcdFJy0IljDeZnkMvRzbOCc+ NnqTR++gMOn9fRybmDEqZqLhCn3qT2z3TkyeJeANV47T4Vz0EsOvYekw/2zcEeBfrcgb 3anGBvfutsmvyrOXnZNs6ySiJREBaqncUFvKg+N+udZy/0fQeR4/bVnQLTDrRZkDinOA eBCVfGwOuNaTqYCnkIGbijBXepvFYhKPIssoFTd0R6H8MlciNgO1ydSxMn5ygQFb+/sL oWAA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u5-20020a17090617c500b0098843bd4387si4790608eje.320.2023.07.23.02.34.05; Sun, 23 Jul 2023 02:34:29 -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 S229898AbjGWIWe (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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772203403533144750 X-GMAIL-MSGID: 1772203403533144750 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);