Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp743631rdb; Fri, 6 Oct 2023 19:14:31 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEx04OwnN89OrPCT8LMxhE8NK7rcD5fhUJxVUfhrSseQTvl8pC7LZxpdHE2/er/BJgLZkVG X-Received: by 2002:a05:6e02:930:b0:351:2288:e132 with SMTP id o16-20020a056e02093000b003512288e132mr8836081ilt.21.1696644871392; Fri, 06 Oct 2023 19:14:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696644871; cv=none; d=google.com; s=arc-20160816; b=zOTyB1m37tyIE95z8bu1pp7kuWn3jpNqOqLUWi36uvfAOufGNvfoOMH/jXizTFhN5X FB91U89COjB9+7PmD5M/KDuqXrhLKAs5DJbZTVKwfGlNbT+t2symLwAYkmVLjbe7HWyS CzLb1VLoz4HE9IECqcqKZTyihhEWS6lKubu+0hFYR0sroc27Imd6n2b6fqQqgTnI5Gn7 rJRBprdpkpewZAHjVxEtQ/ewOfLyyF98i3itXdmMvsMxKuNN9bKzFUSy7fE/YfbVi8mn dYeC+sNeSHcYO0CZZnq0ZyLsHixzQ5X5U8gbXq1pvlJjghZowmcpYD+UD5JdKoyCyiVF TffQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=2nlT7Ayc6FK2ENh5HApqpyv4FDoAbHTS/CAmbKpgFgU=; fh=/5tleBjPDujrXIYss611tAyhfELId0etfY4oKm6i49Q=; b=U4L7BlyIL2/QfKKF7O9S6P78r71/lavS2Uxut2FBolRawCqTP5RP5NcQWoAfjZ9wfF FiakXElC07tTbNpLxoh6PMt6nrmYEF5Pz7znsaMp+MxpCH3+JTOq5t7K5uGmcTYPaYmX E2HxyILDnCyqSavZyi4WeGaTRFowL5Ecbd6adEbgJdieTHPhspEdi93j4hEcJ8S+OlXp WUBaxAV4N82g8yZgUZlfIyk8WLUU0DLi0IpPyWYF8iW8n0Fz3KCp5gKe3b71MdEUkhjH +y618dTCudbzYLH+e8w73Jyxg2/SIvcB+MNVzWYr90k4D9M2wuPqJelRNawrFFWO6NDn gjHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=KVt12koF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id a72-20020a63904b000000b00563deb65f93si5000626pge.200.2023.10.06.19.14.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 19:14:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=KVt12koF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id E43238040E58; Fri, 6 Oct 2023 19:14:28 -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 S1343489AbjJGCON (ORCPT + 99 others); Fri, 6 Oct 2023 22:14:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234126AbjJGCOH (ORCPT ); Fri, 6 Oct 2023 22:14:07 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5AE36111 for ; Fri, 6 Oct 2023 19:14:02 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d8153284d6eso3729991276.3 for ; Fri, 06 Oct 2023 19:14:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696644841; x=1697249641; darn=vger.kernel.org; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :from:to:cc:subject:date:message-id:reply-to; bh=2nlT7Ayc6FK2ENh5HApqpyv4FDoAbHTS/CAmbKpgFgU=; b=KVt12koF9lOZAI4EXiciPQ4EuRna0sLnyltatR2YMMKhwQEeVEA18EGT2GtRpTDURy oM+iqas1pxCdAC6QRhFCe7zAxO/AXftg1pX2PczCTYOyeVO7Wbz7S3JNpXWPmVHefxfT j2YCWQSEMbKFkz0ai3b7qINURgbw+OrulMx7rHCwJMzge6/v30pOq2JYwo8SksJI5yiU kE391MoYlPVZxkjv7+45FB3F33bY5mvtyOZzeZg9tsB0FQN1+4iGjW2lv90ujPRBJPAd 5rLq+7G8dG/IUtUkLeeeT5yvEsg1CQ9hOBN/usMjo8GR8OIjPB0FR7zwzH3GzCPDvxN3 9dgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696644841; x=1697249641; h=to:from:subject:references:mime-version:message-id:in-reply-to:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2nlT7Ayc6FK2ENh5HApqpyv4FDoAbHTS/CAmbKpgFgU=; b=YJxJ9B2pcZNdxNXuVPKR4VI8V9c1gB0iS1ssfUraN3I4FsUSww7SBDUrFA+ZC3NyuU qoBGpB5kbFHGuLWOnDJ17DwZakmDYbMeIgpyv4WKBa4vMNK9JuCGbAiwoQGUO8PIwbdS ZR97NqnovCM15227GSrQnAW0Ved6hiJvzQP/NvR55AhYtJi2Uz1PcznNdT6mh6X3jOUj 4Z6bUp3eu2JQYZ30t+/UBlzoXwEyzCpATXMoqSs5k5iTVh7mmLoOBOO68nZy+fPx4jV7 dkp3M9uZvwgM+u9MXYLi0aA34UsjO1GecwuLds1SY0KQMjchyKCvien1x8pwwGXkn2Go eALw== X-Gm-Message-State: AOJu0YxZ/ocIKnd7/NmiYksLgRDbOm836NOz376OLnRsZ8g5T5vo6cG+ Ql/LNb/nPJ2PdzQDxkKs1ACKI8XZVPQ2 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:7031:b36b:6c77:bfd0]) (user=irogers job=sendgmr) by 2002:a05:6902:180e:b0:d77:984e:c770 with SMTP id cf14-20020a056902180e00b00d77984ec770mr169264ybb.5.1696644841134; Fri, 06 Oct 2023 19:14:01 -0700 (PDT) Date: Fri, 6 Oct 2023 19:13:25 -0700 In-Reply-To: <20231007021326.4156714-1-irogers@google.com> Message-Id: <20231007021326.4156714-7-irogers@google.com> Mime-Version: 1.0 References: <20231007021326.4156714-1-irogers@google.com> X-Mailer: git-send-email 2.42.0.609.gbb76f46606-goog Subject: [PATCH v1 6/7] perf pmu-events: Remember the events and metrics table From: Ian Rogers To: 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 , Ian Rogers , Adrian Hunter , 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-4.8 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=no 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]); Fri, 06 Oct 2023 19:14:29 -0700 (PDT) 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); + + /* + * 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; + /* 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; -- 2.42.0.609.gbb76f46606-goog