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 057CFCDB482 for ; Mon, 16 Oct 2023 08:48:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232781AbjJPIsq (ORCPT ); Mon, 16 Oct 2023 04:48:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232618AbjJPIso (ORCPT ); Mon, 16 Oct 2023 04:48:44 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9E149DE; Mon, 16 Oct 2023 01:48:40 -0700 (PDT) Received: from kwepemm000003.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4S89gQ0Z6bzrTd6; Mon, 16 Oct 2023 16:45:54 +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; Mon, 16 Oct 2023 16:48:34 +0800 Subject: Re: [PATCH v2 6/7] perf pmu-events: Remember the perf_events_map for a PMU To: Ian Rogers References: <20231012175645.1849503-1-irogers@google.com> <20231012175645.1849503-7-irogers@google.com> From: Yang Jihong 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 , , , , Message-ID: Date: Mon, 16 Oct 2023 16:48:33 +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: <20231012175645.1849503-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/13 1:56, Ian Rogers wrote: > strcmp_cpuid_str performs regular expression comparisons and so per > CPUID linear searches over the perf_events_map are expensive. Add a > helper function called map_for_pmu that does the search but also > caches the map specific to a PMU. As the PMU may differ, also cache > the CPUID string so that PMUs with the same CPUID string don't require > the linear search and regular expression comparisons. This speeds > loading PMUs as the search is done once per PMU to find the > appropriate tables. > > Signed-off-by: Ian Rogers > --- > tools/perf/pmu-events/jevents.py | 109 ++++++++++++++++++++----------- > 1 file changed, 70 insertions(+), 39 deletions(-) > > diff --git a/tools/perf/pmu-events/jevents.py b/tools/perf/pmu-events/jevents.py > index 96dc74c90b20..3c091ab75305 100755 > --- a/tools/perf/pmu-events/jevents.py > +++ b/tools/perf/pmu-events/jevents.py > @@ -976,68 +976,99 @@ int pmu_metrics_table__for_each_metric(const struct pmu_metrics_table *table, > return 0; > } > > -const struct pmu_events_table *perf_pmu__find_events_table(struct perf_pmu *pmu) > +static const struct pmu_events_map *map_for_pmu(struct perf_pmu *pmu) > { > - const struct pmu_events_table *table = NULL; > - char *cpuid = perf_pmu__getcpuid(pmu); > + static struct { > + const struct pmu_events_map *map; > + struct perf_pmu *pmu; > + } last_result; > + static struct { > + const struct pmu_events_map *map; > + char *cpuid; > + } last_map_search; > + static bool has_last_result, has_last_map_search; > + const struct pmu_events_map *map = NULL; > + char *cpuid = NULL; > size_t i; > > - /* on some platforms which uses cpus map, cpuid can be NULL for > + if (has_last_result && last_result.pmu == pmu) > + return last_result.map; > + Currently, perf_pmu__find_events_table() is invoked only by perf_pmu__lookup(). Because the `pmu` is alloc memory each time (see perf_pmu__lookup()), the `pmu` is different each time when calling perf_pmu__find_events_table(). Therefore, the condition is false. IIUC, has_last_result is introduced to avoid reading cpuid every time. From the above, this variable does not work. Therefore, can we remove it? In addition to the above questions, the patch is already being tested: Tested-by: Yang Jihong Thanks, Yang