Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp317694lqp; Fri, 12 Apr 2024 21:08:29 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVqkisbpGUM48XpQFgrteNv30i9YWIXt4B+Q+xE4fnpJstA0v2yusuGY/bY8ROgQOFtVtgY0bBhoNI+CMPPGStsKGRQbYhlPBcvZE7GGA== X-Google-Smtp-Source: AGHT+IE9D+NokL+sTczvb0qXqn+obTxl9pA8RFCP8aLxX98ONIhLpAs7rteWEPS3Xyy5zXxeFqlI X-Received: by 2002:a50:a69e:0:b0:56d:b687:5a45 with SMTP id e30-20020a50a69e000000b0056db6875a45mr2900421edc.1.1712981309419; Fri, 12 Apr 2024 21:08:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712981309; cv=pass; d=google.com; s=arc-20160816; b=NIlkuQffAkQilAQBct2h4P2XYxt776OLFadQkP2sXg9sHPUGc1gcfIhCLp4tKTBMdY nRMsXuH/HLRWQvtzST/8VOB3Mz/sLleSgkja74bGCZ6NUoQUxHksj4N4+xAjVmjHTrSD lKk0i5lv3V0lz3GKdWJBY5l6djuxP2LPYA/YlXta1NxJykY8ggOvjEy0ndFsazioqDam H2DBI1roIT9CBr6w4UWiu6ben7mjggMjEekW2F/UNyXFuZjWv+JqntcGF2QIKMqnf9xH Bk/GhLr4uyJJiH7lLagu93hu73kkOmJjhdubMjiblO0shXz3df4NX3725W4Dr9Zi12u1 ii+w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=to:from:subject:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:message-id:date:dkim-signature; bh=1vfm6D8vbfikeYPBREDbfZMw+ntrB8izme+ZrPR5K4g=; fh=UDQq8yyRVNtRSXGofyYNqsVLOfsGUoyrJnXVNEHQ2P0=; b=oSDpLCQ2npSExuZbysdP/4oUbd3F7Hz0MImO0iz181g5rNFewsJS+3eNrhv4zEbcF7 pULMTeOhzz0Fw3QoC96GzYfYRw+aqvs0fhpkK64FSP9tQ7u+CR5YZTJ1rtEWF0E2p41o VHQVz2zrY4T9S3lMISH1f6/bkQeqPJ1NT5CQQ7nPsn/f0tCgi7UHX7Jjs1O42IdCHy3o K3OrV/w5JYdtME+oIXN68bnHpcu6ACls3WzrKsOXg9t047GhrNcuAs6lKZVNGg2LMhb7 M9kPhGSgZ3oYiV0Z2wn4AsVG+gwExQ50hSVYCPO3hRPVKUrCg90EhmiIc4u0EzAsu0IJ JtOQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="jnlUx/Vm"; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-143570-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143570-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 27-20020a508e5b000000b0057000ca5f1dsi1005990edx.217.2024.04.12.21.08.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 21:08:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-143570-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="jnlUx/Vm"; arc=pass (i=1 spf=pass spfdomain=flex--irogers.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-143570-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143570-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 26B471F22F6A for ; Sat, 13 Apr 2024 04:08:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3BD961BF38; Sat, 13 Apr 2024 04:08:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="jnlUx/Vm" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 93500199B0 for ; Sat, 13 Apr 2024 04:08:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712981299; cv=none; b=eOSL0yzq4cFxVplL7NfGVi2QC8w8bGIs0JQxLI7ORTXQrMobROxPFTgWNmsZJuLm26HnCOSXBdhu6qXBSIa4w2Vtev9HSQo2Kq+F5+kxbJeBYrLR+LrdS0lN3MVRxLtWfih/wq1lZLnbdzTe+BR65rDYnXdj6UJynr2MNmI4H20= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712981299; c=relaxed/simple; bh=psg6T4xGQd7JrMIyC4K0Af0EDOUtPx/yuI+ni4g9NhA=; h=Date:Message-Id:Mime-Version:Subject:From:To:Content-Type; b=iVSy6jIXrtqHIW4cJ0sSg7iPmcnW451kVDMe+P/m2my+K5P1g9pVt6b5tlrAmchyuiusXNauSddwzqwk7x35DctwLN1Yj6hf4NZbc1EZgU94kd+a/BKglkYZ8TU6d9WVsgPKCwm5xnNvNvvuy8yPpNtMHNKBpL8s1H5gZnGihiQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=jnlUx/Vm; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-60cc00203faso28621607b3.2 for ; Fri, 12 Apr 2024 21:08:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712981295; x=1713586095; darn=vger.kernel.org; h=to:from:subject:mime-version:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=1vfm6D8vbfikeYPBREDbfZMw+ntrB8izme+ZrPR5K4g=; b=jnlUx/Vm7xS7cK4wn4FmWlBvrQFc5piwalUmAgG1dqtNq0WTj4YpOjbOxndfw3wrPq vITcySn76KJoMfUkrQXbdtCEWJ8/OCADAjD+88bgkoekN3oEwOP96tJ/mJLWKq77590b qYq+7xPxHRsMB44GdMvPYiEXCelRuuLCXPbXEbhCdenJWZkELpfbNqvfJJy9LQWtuSnK E1RAgtBBNaF6RaQDiKFGHcQhNxcKFzKj3aQAFyTHVCaT+MWINNode5xt/+TYELo7QTbP P0EeLlBWVnyHGT5YKvkHcL+ApFjo4/dlV0qkFheDz8QCffDA8rqzhxJYLBgqnDQdEAJZ +onA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712981295; x=1713586095; h=to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=1vfm6D8vbfikeYPBREDbfZMw+ntrB8izme+ZrPR5K4g=; b=guMbPFqp8v1uzljiTe79AcswMXaVPC6zpbMKcwBrh/FMDBHn56rIaEDW2IItwb5ZtD A6UC+uxdR60wrtDHqFM0RYHw8+ldbfpUPf8pGz7Xfp5FBz2vqAgjo/6BBtbI5h1IXgyq RRQYoZcgoaRJfdKdUBfoBHnhiYLj/58nrJh9RzUaX0cDetEzSc6Zw5+Mbau5GRuwqhWz gCm1gl6146lPagwkcPcuk8Wvh2Isntf4+IQ4Xxju8AYG1iZwB/jcpuBxHVx94MoUvG7Z d/27IW1P/tlsw8hQvpYXZxHFY8tHdIGHdbg8rE87GOVAKtFRUmtl1Zh3N3c6m998EciI P9wA== X-Forwarded-Encrypted: i=1; AJvYcCVOaLHTzy5spABvG1AjWIXGDgWYoFOaw1C3SupGeooesEyYOTZ12qnWWp0P3GohyehyaBEyMyYDKOkMi1nKDzHToO+BT8j94F3T0jIR X-Gm-Message-State: AOJu0Yy7Rs7yUjbWOJizr0LpudtF7HJI2N24/GQNJjuh5pvjSdwuCQwR UAj+jdqZyxSBOtO21Ew2p3vngt2/ohZRMo+KmJPwsLz1QgUujAuGWoyO1XHmzusxheEx6eOHtj0 OLR/Jug== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:bcbe:4239:4b57:df45]) (user=irogers job=sendgmr) by 2002:a81:49c7:0:b0:615:4295:2871 with SMTP id w190-20020a8149c7000000b0061542952871mr1016283ywa.7.1712981295572; Fri, 12 Apr 2024 21:08:15 -0700 (PDT) Date: Fri, 12 Apr 2024 21:08:12 -0700 Message-Id: <20240413040812.4042051-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.44.0.683.g7961c838ac-goog Subject: [RFC PATCH v1] perf pmu: Assume sysfs events are always lowercase From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Kan Liang , James Clark , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Perf event names aren't case sensitive. For sysfs events the entire directory of events is read then iterated comparing names in a case insensitive way, most often to see if an event is present. Consider: $ perf stat -e inst_retired.any true The event inst_retired.any may be present in any PMU, so every PMU's sysfs events are loaded and then searched with strcasecmp to see if any match. This event is only present on the cpu PMU as a json event so a lot of events were loaded from sysfs unnecessarily just to prove an event didn't exist there. This change avoids loading all the events by assuming sysfs event names are always lowercase. It then uses file exists and only loads the events when the desired event is present. For the example above, the number of openat calls measured by perf trace on a tigerlake laptop goes from 325 down to 255. The reduction will be larger for machines with many PMUs, particularly replicated uncore PMUs. Make pmu_aliases_parse early return when aliases are loaded, ensure the function is called before all uses of the aliases list. Signed-off-by: Ian Rogers --- tools/perf/util/pmu.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index ab30f22eaf10..ce72c99e4f61 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -425,9 +425,16 @@ static struct perf_pmu_alias *perf_pmu__find_alias(struct perf_pmu *pmu, { struct perf_pmu_alias *alias; - if (load && !pmu->sysfs_aliases_loaded) - pmu_aliases_parse(pmu); + if (load && !pmu->sysfs_aliases_loaded) { + char event_file_name[FILENAME_MAX + 8]; + scnprintf(event_file_name, sizeof(event_file_name), "events/%s", name); + for (size_t i = 7, n = 7 + strlen(name); i < n; i++) + event_file_name[i] = tolower(event_file_name[i]); + + if (perf_pmu__file_exists(pmu, event_file_name)) + pmu_aliases_parse(pmu); + } list_for_each_entry(alias, &pmu->aliases, list) { if (!strcasecmp(alias->name, name)) return alias; @@ -605,6 +612,9 @@ static int pmu_aliases_parse(struct perf_pmu *pmu) size_t len; int fd, dir_fd; + if (pmu->sysfs_aliases_loaded) + return 0; + len = perf_pmu__event_source_devices_scnprintf(path, sizeof(path)); if (!len) return 0; @@ -1689,9 +1699,7 @@ size_t perf_pmu__num_events(struct perf_pmu *pmu) { size_t nr; - if (!pmu->sysfs_aliases_loaded) - pmu_aliases_parse(pmu); - + pmu_aliases_parse(pmu); nr = pmu->sysfs_aliases; if (pmu->cpu_aliases_added) @@ -1750,6 +1758,7 @@ int perf_pmu__for_each_event(struct perf_pmu *pmu, bool skip_duplicate_pmus, struct strbuf sb; strbuf_init(&sb, /*hint=*/ 0); + pmu_aliases_parse(pmu); pmu_add_cpu_aliases(pmu); list_for_each_entry(event, &pmu->aliases, list) { size_t buf_used; @@ -2154,6 +2163,7 @@ const char *perf_pmu__name_from_config(struct perf_pmu *pmu, u64 config) if (!pmu) return NULL; + pmu_aliases_parse(pmu); pmu_add_cpu_aliases(pmu); list_for_each_entry(event, &pmu->aliases, list) { struct perf_event_attr attr = {.config = 0,}; -- 2.44.0.683.g7961c838ac-goog