From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88C5FE95A82 for ; Sun, 8 Oct 2023 09:36:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344558AbjJHJgW (ORCPT ); Sun, 8 Oct 2023 05:36:22 -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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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