From patchwork Sat Oct 7 02:13:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13412157 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9E15FE94139 for ; Sat, 7 Oct 2023 02:14:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:To:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=X6xAet8IWdNVnL1qU6Pec35GhHuEqJrcpWoQ0x9ennw=; b=uWCEAQRiJsehHV JWQmgJIjjhkydMLpsn6IRKw4gsN3WEXCqQEFSplanFGEk6s0f8NTO5y6r/MFqwunYlUGWZ5xTsmR+ rxsqBI+MrkdzN2laxh52aRQVwjD3vFiJTupbGClkGU5V4WNqWrOVSmIwbHq0J+QX1jsmWmDDmQp29 OJkxJg+erU24wwvvuXn9Joz/a31fhLqQdKC8YTXAItM5Dp+qVLDZtLDg2KdHsmlYr299kuj5r/SDx LzQ1MBY8z5RE/4GSPj3svS52MmoSOCYv5G21ZzLkGoHALdruZ7Gng2Hi0o+LbL92eZ+/R78gXqx7g UJPV9ghHwNbwjSYiVr+w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qowpT-006niO-2u; Sat, 07 Oct 2023 02:14:07 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qowpO-006nea-1U for linux-arm-kernel@lists.infradead.org; Sat, 07 Oct 2023 02:14:04 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5a2318df875so42255117b3.2 for ; Fri, 06 Oct 2023 19:14:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696644841; x=1697249641; darn=lists.infradead.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=h6H+fDM5evP2jbCkF5opZJ4TtUu8myTN/80S4kplgDmAe5s8QXTjfb/oO1JmGBSNFo cs7jaVPwGhjDmF9dCxHsd1v9gr/hu+yI3VoEKyBpA76fM5Nnkg8sCDa+Yxtv9CVAWZoM ZUy1IMRQTk0n26kC9+SNiPhrITxoa2hqo4RAxtWfWofwD2x9aeC5UmPiW2AO1q6AgMw4 lhcx4fQMwevMQ+BdfPSupgg3sieGT21/Vry7b9CNWhjBGCTDoINmWDnlMRibfS4NptIA VJJGRem5myJvqvSHL/Cek7XTkMGNdLS7wI+kDgVQSPBPyM074DcNHpcRDTDZRuezimfB faTw== 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=n5e+Id7xfIEMlWlQZvmHD+2bot/JYSHURMXWH93PFhgg766u96P8Xw0UpD4DMbPofN 8FZFY/PHGjBchMqL/cJQKGy7EqZg0Ggpwg8pxGEc5JVjKtJFTVTYfrbVWc+pe+s4cttg vObGun1m74AhVlXnqaP0NZxoORsfJRWwl4zd7iYhuSdmVByJfDKYREY0c42F2+pRstx7 b/5JTm9AezGuRw6pHMwpftXmBulMLzbHmFEUUr7kFgYgGq9LH4jcAqab619Q7bpP+kCy TRcye3NvIOiU9yzFPMUXk+4AyHFRrqWZr7PFVtgzbpEwgNr1ZnpmHyoI8bah7lQKzrA/ hoPw== X-Gm-Message-State: AOJu0Yxl6JYdheM5LWM+PXVsgCl16OBZrE+T/jWwLb3M1CnJil3/OFwO o9VLd+/dthRNV9hEG/+SIsMbkxw1vq5N X-Google-Smtp-Source: AGHT+IHKgnAs25/YJ43kvuHhiiWC2cjxg2u8JYxG3dDXPATXMZW8zvYw7dr0dQFaibX0XwBeXqVh6XfAHREW 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231006_191402_500035_C8CCD14B X-CRM114-Status: GOOD ( 16.85 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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;