Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp4239195rwd; Tue, 30 May 2023 02:27:15 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7AG0heXOiiabQNVIy4lH4QujjKr3EbGEKKpMXe3pgBgoAPolT2++Uu3mcxSoraJtyryzqz X-Received: by 2002:a05:6a20:549c:b0:110:29b9:9652 with SMTP id i28-20020a056a20549c00b0011029b99652mr2004551pzk.56.1685438835274; Tue, 30 May 2023 02:27:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685438835; cv=none; d=google.com; s=arc-20160816; b=qUreDqvSGwl6e5OQ18gXoxtrXtOQvrfp7JA3WtKeLLZCGM8mNTdxVQeJHXHogT2QZ6 bkqCoPbJi6ETm1qM3WMPclc0rVygykM+ft/brE7IKIGUUYCTeqKaAOY5zzFCcIDL6JG6 E4fVXJRQcxoeQ2zcwYK9fClNoE2avMg+jr1Gg8PIbv72YMsAJlmfbGpDAESb2eV/Dk0M aaCFEjgdEDiLCUftuNCf0WrRS4xuPLO8hE61nrAXD+ioxD0IBvPC1wkBYV6n4eE1uJzH yPpdjGgrlBYHBg/AK8MbEVNMcoxxTa1dlXemTqwuZ+xlBoQEf5pB2bDJfLZWhW14CZec VNiQ== 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=KThkymt1yogVjo1EnmcyDChbpWKdi6B1GbwqdfEohwQ=; b=gKJBnY2Hg2NQu8Q8emF6A/33p0GOZkqPBHXT8wk25gwF1LX5tBH0XC0KBFlTLdOyTH XFIMx8bHDeULQLSjtyZOoVkD+VZH4Ns2BlYZSvu3pqjfcgb/PMxrBE4y4D76E70Ki7R5 uf8zG88I4puLLJxpBTH5/GxQxQRS8qjRia8WRqUP6Wh0M5jWxc06KNlQeQPw2Fvo5Yf6 yTVSaecNj82uGaUlHaNfswzrZ8z1V54k051YaEekwcCiEf2DMy0Xwkou0Gm3bmJA4lAT NjsLBtDc9hW+VxVE2qV1KHfZDaeiGRxWgOOEnSBIzdjFYy0K5N9K+D0X7+DB/P+vy/TJ r+Vw== 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 125-20020a620683000000b0063b82c09424si1003869pfg.151.2023.05.30.02.27.02; Tue, 30 May 2023 02:27:15 -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 S230474AbjE3JU0 (ORCPT + 99 others); Tue, 30 May 2023 05:20:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230422AbjE3JUI (ORCPT ); Tue, 30 May 2023 05:20:08 -0400 Received: from out30-98.freemail.mail.aliyun.com (out30-98.freemail.mail.aliyun.com [115.124.30.98]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BC1DF3; Tue, 30 May 2023 02:19:47 -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=ay29a033018046050;MF=renyu.zj@linux.alibaba.com;NM=1;PH=DS;RN=19;SR=0;TI=SMTPD_---0Vjt6o.s_1685438382; Received: from srmbuffer011165236051.sqa.net(mailfrom:renyu.zj@linux.alibaba.com fp:SMTPD_---0Vjt6o.s_1685438382) by smtp.aliyun-inc.com; Tue, 30 May 2023 17:19:42 +0800 From: Jing Zhang To: John Garry , Ian Rogers , Will Deacon , Shuai Xue , Robin Murphy Cc: James Clark , Mike Leach , Leo Yan , Mark Rutland , 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, Zhuo Song , Jing Zhang Subject: [PATCH v3 2/7] perf metric: Event "Compat" value supports matching multiple identifiers Date: Tue, 30 May 2023 17:19:29 +0800 Message-Id: <1685438374-33287-3-git-send-email-renyu.zj@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1685438374-33287-1-git-send-email-renyu.zj@linux.alibaba.com> References: <1685438374-33287-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_NONE,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 "arm_cmn600;arm_cmn700;arm_ci700" can match the PMU identifier "arm_cmn600X" or "arm_cmn700X" or "arm_ci700X", where "X" is a wildcard. Tokens in Unit field are delimited by ';'. Signed-off-by: Jing Zhang --- tools/perf/util/metricgroup.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index f3559be..c12ccd9 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -456,6 +456,28 @@ struct metricgroup_iter_data { void *data; }; +static bool match_pmu_identifier(const char *id, const char *compat) +{ + char *tmp = NULL, *tok, *str; + bool res; + + str = strdup(compat); + if (!str) + return false; + + tok = strtok_r(str, ";", &tmp); + for (; tok; tok = strtok_r(NULL, ";", &tmp)) { + if (!strncmp(id, tok, strlen(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 +490,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