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 1D1EEE95A8F for ; Sun, 8 Oct 2023 03:39:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344357AbjJHDja (ORCPT ); Sat, 7 Oct 2023 23:39:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344309AbjJHDj2 (ORCPT ); Sat, 7 Oct 2023 23:39:28 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A534AB9; Sat, 7 Oct 2023 20:39:26 -0700 (PDT) Received: from kwepemm000003.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4S379T3S4JzTmNK; Sun, 8 Oct 2023 11:35:57 +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 11:39:21 +0800 Subject: Re: [PATCH v1 6/7] perf pmu-events: Remember the events and metrics table To: Ian Rogers , 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> From: Yang Jihong Message-ID: <39b28ad5-8086-76ed-a4c6-bfc8271d226b@huawei.com> Date: Sun, 8 Oct 2023 11:39:20 +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: <20231007021326.4156714-7-irogers@google.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.111.205] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) 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/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? Thanks, Yang