Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp251763rdg; Thu, 12 Oct 2023 04:57:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGM0WmvPGyIvVGNQCmBSbw9T0pfxCBWMvS4vxrmJtFUbG6HmoYSmzyx91EAJvokpw6y48AY X-Received: by 2002:a17:902:934a:b0:1c6:636:e40a with SMTP id g10-20020a170902934a00b001c60636e40amr21210912plp.14.1697111835371; Thu, 12 Oct 2023 04:57:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697111835; cv=none; d=google.com; s=arc-20160816; b=d1ET69HeKWOk8pt2uXWw5rSczPKPSyApolZUAo3FxTh69+3KyfGd8/N4AOUYtr7NhA 9APDv0ElZblaG6usFaL9e5y3i9BKlQF82xMRXr8JzrQIFnaXlcP/1xfUuYllW+oCgMcL DEC+4VYfvIOynVgEqhVI4q16plLEgv6v/uLDMPkLtz3mmiOmDhFomdKulKhO0nuvuRB6 hfk003MjHwGm99TBiYsWifHMojMham6bZiKz9xxwpd7kFz4jEeFkd5IfLKuHDHKJ4Mjh e1sq+k00g/lc2CYYhmRrKdkxyS1E8VYoNfjGDTLy0bSP7f8kvSxgXvnmFZSHyzA4WkWb kJOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to :organization:from:references:to:content-language:subject:user-agent :mime-version:date:message-id:dkim-signature; bh=+MyDhuJWENbn0NUBKoXNNq1pL/Min3wBgr9A5BjAIRI=; fh=W3U2V5NWgOp/qb3+mq+iAX2Phz2PcGd1A8pr7VsL1jc=; b=FXNQ876Ere0WgsJeH8B4ZJadmQ0yRGrdHFwBgzT/e/i7d5CWFqTQqNlZtz8c+nlFhb SywgC37PUw+lR8IpMxxWFsj9EtrnN1NULWWKELVXu85RBOs+YNfwWXW0W35IQumDX1a7 hGeuBpPj+IA558BBRTkUYfMsyI8jlQ34aGTPANnJEhkVj85jySthtoxA8w9fHoNhgM8w 7iGGlIM+Pe+XA055sDYGxmvPZD31a4PD2PQFQhYgb3+L04O4aCtbXojea5gff1GOiPyC DGqJgRN3WLxVMHh+H/KSgl+U2++ouhxT/wFGEqc/sVe+f7AwTVv0t/w819GiKIY+X6Jl /0Pg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dA4CtIKT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id y10-20020a17090322ca00b001c5f5153e41si1728421plg.535.2023.10.12.04.57.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 04:57:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=dA4CtIKT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 96AF280C257B; Thu, 12 Oct 2023 04:57:09 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378551AbjJLL4Z (ORCPT + 99 others); Thu, 12 Oct 2023 07:56:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378605AbjJLLzx (ORCPT ); Thu, 12 Oct 2023 07:55:53 -0400 Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A7B146B2; Thu, 12 Oct 2023 04:53:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1697111632; x=1728647632; h=message-id:date:mime-version:subject:to:references:from: in-reply-to:content-transfer-encoding; bh=QA1p18R7UDwNmgDTB/KVX0W8rktazNm38PC98o9ymH4=; b=dA4CtIKTonuRwIjaaDsWYzJjw/yxBiFN3CdtQmriAHwxm0eIy44erwIV aPvlLN06+qUVJoVIs8YqggXmBofDO/SGwlUXjCHmZmJu8bJBJQYBx/peP b+eLAGx34hzwM+sazuPkFSW31bpj3is2mvC3w/qaw5pWMH984YRLMl6IV KgGlsMjR0LPi4wAyIb91/ODa2orW5wOTK2ykbNO8opOgXHODmrxC8J8un Q3qTLkaeq3Qabq3PwEouDT+jEFJB0VIJq6K3QDoxcHiPUIqGVuZmyJ2WR 4cCZ/BGHRzCc4oU6Xa7vehFBCE16TBP6ZxBs4xgKAmQoymZodIoY71haz A==; X-IronPort-AV: E=McAfee;i="6600,9927,10860"; a="415949597" X-IronPort-AV: E=Sophos;i="6.03,218,1694761200"; d="scan'208";a="415949597" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Oct 2023 04:53:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10860"; a="870545759" X-IronPort-AV: E=Sophos;i="6.03,218,1694761200"; d="scan'208";a="870545759" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO [10.0.2.15]) ([10.252.41.84]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Oct 2023 04:53:20 -0700 Message-ID: Date: Thu, 12 Oct 2023 14:53:18 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1 6/7] perf pmu-events: Remember the events and metrics table Content-Language: en-US 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 , Thomas Richter , Ravi Bangoria , Kajol Jain , Jing Zhang , Kan Liang , Yang Jihong , coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org References: <20231007021326.4156714-1-irogers@google.com> <20231007021326.4156714-7-irogers@google.com> From: Adrian Hunter Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki In-Reply-To: <20231007021326.4156714-7-irogers@google.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,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 agentk.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 (agentk.vger.email [0.0.0.0]); Thu, 12 Oct 2023 04:57:09 -0700 (PDT) On 7/10/23 05: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) { > + char *cpuid = perf_pmu__getcpuid(pmu); Seems to assume the function is never called with a pmu that would give a different result for perf_pmu__getcpuid(pmu) > + > + /* > + * 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; > + } > } > + free(cpuid); > } > - free(cpuid); > if (!pmu) > return table; > > @@ -1015,13 +1019,17 @@ const struct pmu_events_table *perf_pmu__find_events_table(struct perf_pmu *pmu) > > const struct pmu_metrics_table *perf_pmu__find_metrics_table(struct perf_pmu *pmu) > { > - const struct pmu_metrics_table *table = NULL; > - char *cpuid = perf_pmu__getcpuid(pmu); > + static const struct pmu_metrics_table *table; > + char *cpuid; > int i; > > + if (table) > + return table; Ditto > + > /* on some platforms which uses cpus map, cpuid can be NULL for > * PMUs other than CORE PMUs. > */ > + cpuid = perf_pmu__getcpuid(pmu); > if (!cpuid) > return NULL; >