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 435F7CDB465 for ; Mon, 16 Oct 2023 09:50:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230434AbjJPJuV (ORCPT ); Mon, 16 Oct 2023 05:50:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230152AbjJPJuT (ORCPT ); Mon, 16 Oct 2023 05:50:19 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E93AB4; Mon, 16 Oct 2023 02:50:16 -0700 (PDT) Received: from kwepemm000003.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4S8C09669BzvPxM; Mon, 16 Oct 2023 17:45:29 +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 17:50:11 +0800 Subject: Re: [PATCH v2 6/7] perf pmu-events: Remember the perf_events_map for a PMU 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: <20231012175645.1849503-1-irogers@google.com> <20231012175645.1849503-7-irogers@google.com> From: Yang Jihong Message-ID: Date: Mon, 16 Oct 2023 17:50:10 +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: 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/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; > + > + cpuid = perf_pmu__getcpuid(pmu); For the software pmu, we do not need to look for the events table. It seems that the software pmu can be filtered out in perf_pmu__lookup() to reduce unnecessary perf_pmu__find_events_table() calls. I tried to submit a patch, please see if it helps: https://lore.kernel.org/all/20231016093309.726436-1-yangjihong1@huawei.com/ Thanks, Yang