Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp1327596rdb; Sun, 8 Oct 2023 02:36:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG9bnS6sswBxUb1dTm56grxI/pxsMAXky5Qah2X8zlCCHdrnm3iovVyAUz43XhsfQgiVGWh X-Received: by 2002:a05:6870:230d:b0:1d6:5561:c2e6 with SMTP id w13-20020a056870230d00b001d65561c2e6mr14986296oao.42.1696757799603; Sun, 08 Oct 2023 02:36:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696757799; cv=none; d=google.com; s=arc-20160816; b=Q9qrt5TiG6r7dG/+reMGEcqOVBJu1A6SqCgGp/yDMGdCH4b4AB5ypEaEfuze0SOsLh FUjSzsAzT5LppjZz0ZNsHUxEVtiXSK5clS2rSCThAjZNk/NaOTgkXDlvbaYk/hYbdDJX b0hZQxrSLtWCL+BlwoMYMctg8IU3OlfzhiQTiztY1flCUE30jCpmvwRuLXMHL8ayxsN9 j0LEWydgqMeozdZn1hpuRwYNdXAxlwgSZtUwCMsjJWgLMBJHP4Q7N9WyHc+M8XYaqqyF dqcBGSGh1qJja8rjysnm5FK3luoD9ppiygkqdld41vz24dkyUmAKK6rcTU5074XwNsLM OQoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=Yg3JZLsKEJar/PhkBQjtLJKKfmBaIolUaQ2S+lLRjLM=; fh=jbmOSGUchZEKR4LEDAoLM1eo1gXVILbTIscF78rloxo=; b=bP5qNk1Nf0jNnj4rTj60yGjWMeiE2QVHaPZxtXuye95DJhcxkI9trDQxkbdYpc6CtF i7lJIgCpQrnfSVaEzAwIfaPdvdCzfpahx9DKOavi+ae/6BaMHGq801wOLxaFkDC1UKrO akNwkLTwSvbO9zMp7G7insIKprBK0s7UEWpqHKMgdvhJe9SVsZ3UbR2ZRf8EIU5/ariN 8i40Zquf8Z4WQ9QYiZomwEO3GH96rIbF/z8cOerf52B591ktT1F/ILN/uV3GhzI3J12q yLqKHJsNG16ir10CTI/TXve34I9wp7r9e6CQsJs3G+YzY7G7IHj4gzm8LL6xz4MbTQPk rDDg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id z2-20020a1709027e8200b001bbcddd6e82si7445729pla.91.2023.10.08.02.36.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Oct 2023 02:36:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 2D02D80412E8; Sun, 8 Oct 2023 02:36:37 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344310AbjJHJgU (ORCPT + 99 others); Sun, 8 Oct 2023 05:36:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230441AbjJHJgT (ORCPT ); Sun, 8 Oct 2023 05:36:19 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A141BB6; Sun, 8 Oct 2023 02:36:17 -0700 (PDT) Received: from kwepemm000003.china.huawei.com (unknown [172.30.72.55]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4S3H4h31CJzRhp3; Sun, 8 Oct 2023 17:32:20 +0800 (CST) Received: from [10.67.111.205] (10.67.111.205) by kwepemm000003.china.huawei.com (7.193.23.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Sun, 8 Oct 2023 17:36:14 +0800 Subject: Re: [PATCH v1 6/7] perf pmu-events: Remember the events and metrics table To: Ian Rogers CC: Suzuki K Poulose , Mike Leach , James Clark , Leo Yan , John Garry , Will Deacon , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Thomas Richter , Ravi Bangoria , Kajol Jain , Jing Zhang , Kan Liang , , , , References: <20231007021326.4156714-1-irogers@google.com> <20231007021326.4156714-7-irogers@google.com> <39b28ad5-8086-76ed-a4c6-bfc8271d226b@huawei.com> From: Yang Jihong Message-ID: Date: Sun, 8 Oct 2023 17:36:13 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [10.67.111.205] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemm000003.china.huawei.com (7.193.23.66) X-CFilter-Loop: Reflected X-Spam-Status: No, score=1.0 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Sun, 08 Oct 2023 02:36:37 -0700 (PDT) Hello, On 2023/10/8 13:49, Ian Rogers wrote: > On Sat, Oct 7, 2023 at 8:39 PM Yang Jihong wrote: >> >> Hello, >> >> On 2023/10/7 10:13, Ian Rogers wrote: >>> strcmp_cpuid_str performs regular expression comparisons. Avoid >>> repeated computation of the table by remembering the table in a >>> static. >>> >>> Signed-off-by: Ian Rogers >>> --- >>> tools/perf/pmu-events/jevents.py | 48 +++++++++++++++++++------------- >>> 1 file changed, 28 insertions(+), 20 deletions(-) >>> >>> diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py >>> index fd009752b427..8d8d5088c53c 100755 >>> --- a/tools/perf/pmu-events/jevents.py >>> +++ b/tools/perf/pmu-events/jevents.py >>> @@ -978,28 +978,32 @@ int pmu_metrics_table__for_each_metric(const struct pmu_metrics_table *table, >>> >>> const struct pmu_events_table *perf_pmu__find_events_table(struct perf_pmu *pmu) >>> { >>> - const struct pmu_events_table *table = NULL; >>> - char *cpuid = perf_pmu__getcpuid(pmu); >>> + static const struct pmu_events_table *table; >>> size_t i; >>> >>> - /* on some platforms which uses cpus map, cpuid can be NULL for >>> - * PMUs other than CORE PMUs. >>> - */ >>> - if (!cpuid) >>> - return NULL; >>> - >>> - i = 0; >>> - for (;;) { >>> - const struct pmu_events_map *map = &pmu_events_map[i++]; >>> - if (!map->arch) >>> - break; >>> - >>> - if (!strcmp_cpuid_str(map->cpuid, cpuid)) { >>> - table = &map->event_table; >>> - break; >>> + if (!table) { >> If there is no matched table in pmu_events_map, >> perf_pmu__find_events_table() will enter this branch for repeated search >> each time. >> Or do we need to use another variable to indicate whether the search has >> been performed? > > Agreed, the behavior will match the existing behavior. Longer term I > want to remove this code. Do you have a scenario we should optimize > for here? > Yes, the CPU of the environment I'm using is "AuthenticAMD-15-6B-1" (not in the pmu_events_map). As a result, the search is repeated every time. (If `perf record true` is executed once, the search is repeated for 6 times.) This commit avoids repeated lookups to improve performance, so if it's feasible, is it best to consider improving performance in this case as well? Thanks, Yang