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 29E5ECDB46E for ; Thu, 12 Oct 2023 11:56:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378627AbjJLL41 (ORCPT ); Thu, 12 Oct 2023 07:56:27 -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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; >