From patchwork Mon Aug 7 07:51:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jing Zhang X-Patchwork-Id: 131734 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp1297044vqr; Mon, 7 Aug 2023 01:13:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHCzj37sh8xmBvXQY2Ns74LTrpBA0RERNHDKZ/VZTPSg0GaxcUREa2i7kfDRWcgH5cSZ4p6 X-Received: by 2002:a05:6a20:3243:b0:13b:a016:465b with SMTP id hm3-20020a056a20324300b0013ba016465bmr6834415pzc.19.1691396007667; Mon, 07 Aug 2023 01:13:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691396007; cv=none; d=google.com; s=arc-20160816; b=O9G+XMn2qfBmzx9JPipXSCt8TOmQFu01glUkVasAgPxIoCACSoV2rOwRVuwXFS9Jeq yzCqT3dhMKFViTp8faxqQLelEbSNDL+rhtUhgDmNy6WQdDwmrKkRzNC//Gaj05Q3xVxx F1Kkceoc6gUtCfBphBpqIavNjrDTUBHF5hBd9OelFACDO8fzpxxrfnm+SGB2HsCyisee ggAvwwbV7MMCDouMC9KKlZfvnwJWvDJt7Q6KpPwENqQ023wPYPgBtvhp2MWANrTUA7uM /qpofqBAbW96X3TF9a3q4NtvJxycYvla9n46uEKGTcpSqVujyfZIrs04w7ivTMMFzme7 Zf0A== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z11-20020a6552cb000000b00553c4551a08si4962751pgp.887.2023.08.07.01.13.14; Mon, 07 Aug 2023 01:13:27 -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 S230478AbjHGHvn (ORCPT + 99 others); Mon, 7 Aug 2023 03:51:43 -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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773557259915988081 X-GMAIL-MSGID: 1773557259915988081 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);