Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2362325rdg; Mon, 16 Oct 2023 01:48:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHgF5KNoGw70qfQ4s1ZwTnoZkVLCkGFfwpSeAY+8hXGPdfE0vhkmuiJGvmgXMVyS3yvmAp+ X-Received: by 2002:a05:6358:279c:b0:143:2f7e:aa with SMTP id l28-20020a056358279c00b001432f7e00aamr41896382rwb.28.1697446136382; Mon, 16 Oct 2023 01:48:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697446136; cv=none; d=google.com; s=arc-20160816; b=RHczsIM+TCoNPRmjkmnU5P2q4AbHtzoVAW5ASvilgLBa5xl+6azrt4MD1he3f0PxiG x4GcDeS4MfhoggOLkvcwDOgEASoyzHCTO57eI5GaRsyzN+nS0Rcon4dJsfRZxVq3RphU XbFCEm08wnNoTO3Kl/VupAarHQ9tOo5lpKNRcOA3ETFzK3c5NiiaxMnio7qhQHFBgyxB /D1YoDZceGnLUs8PI7aCiNwDlMIxCYPLShzMMXCbVqgEri7Gra/To6YgMMIPhRdldefl x//O4YwtWinT8uhglvnnFmiuHdq3miyZ2Tn8cmcw9ey6eB4D6gYoVX9ecXVWfOUtZUPy rqBA== 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:cc:from :references:to:subject; bh=GOwqKaOrTQQZMLow4eH/k+o8x0s96YO3/pLhCdT++jc=; fh=jbmOSGUchZEKR4LEDAoLM1eo1gXVILbTIscF78rloxo=; b=Coo5cAM0byqRqfaSV9zimsPZ0dV8iKKrcgChcnk2j+qa7dqVTyRMP0mqKqWzUVRUz4 WKuu15NcOVz8ShGXN1dtjne/l2b47s1NkIKqWI2qmCkIFsAuLnJTeSx0j2GWtZ3YqjBk SLIWEHB3RpaKJmr6W6vgNTZr48JnRDPnmtufTs6aE6MD+nMrCzOI1vvuhkCqmMqTtgGw OkkTrCf/T8yw3KsQi0oF0oA1yJm+GgofT0R6QMPUgzKNR+MjNV1KO85ta1YVB8SXKBa6 ec2/rRZdF9ADEhZATlTSR5UiU/1PYiG7f0GwOiq5P0ox03Winzk8fnBFkQCUGkkTujef EwwQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id bq9-20020a056a000e0900b0068e26ca7f00si21764564pfb.39.2023.10.16.01.48.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 01:48:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id 281AD80C650E; Mon, 16 Oct 2023 01:48:54 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232745AbjJPIsp (ORCPT + 99 others); Mon, 16 Oct 2023 04:48:45 -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 X-Spam-Status: No, score=-4.1 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.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 (morse.vger.email [0.0.0.0]); Mon, 16 Oct 2023 01:48:54 -0700 (PDT) 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