Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1595761lqa; Mon, 29 Apr 2024 13:04:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU6aeEP8O5WszE2RWXw5qajpi4x9UdwXwC6TN732sBCGhm/RQnmKY9AuLgMwf1t1hawj3fHIf2aTWUGxooIR1h5vRmaZTwd1ZUuDglmHQ== X-Google-Smtp-Source: AGHT+IHZlwCpsH2rl/t7hrXKX3O3vP0n0m4+NkbH8n21CxC/tH28CFBxKhqCfJnXVAQ3BYP+u/Kd X-Received: by 2002:a17:906:11d3:b0:a58:e735:512c with SMTP id o19-20020a17090611d300b00a58e735512cmr5050812eja.20.1714421053649; Mon, 29 Apr 2024 13:04:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714421053; cv=pass; d=google.com; s=arc-20160816; b=DG6K3bu7PK5QdP9riXC0gk6Eme/St5JzGdDVMEYi4uXiWLng7/6LcbjxM7t6GcPzRg SX7f+spPrgVaeeTXj+qayH5/4jmuveQoJaclA+9Undr1Z9cwkR9+t4mjh36SheYGt8d8 bfbGR71sbQn0Ad6WZHmSYLFRuENVrl77WaMeH/gzyZ6Hn8h+TLQPRz86f702jeWNkY9F rh1nBojib/ge126WJ8nT3aR5ciPg77zFBMhjo0WOrueZ/NIurvXyMdeXYK4462Xwuqss TEKDqDPGwhlDh9qXXcgLsHDlRrSm6oUXtZU/Mv8trRPXS5dyeBcf9z7pCimTU63/vafv 4mFg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:references:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:in-reply-to:date :dkim-signature; bh=sNfu8Xy7Q56dzltFDRS+tQNs0guv+YCXtYt4P68p4eQ=; fh=2gStIsSPddacrTnlf8AE9EAww4UekYYX4iAr9V66ovA=; b=kRKijCcO1Doc5c3AabinZKUJA+TdOO5nkzeluyt0SPGADZIb+n3gtJKMzp+s2sHx7n PVyNnRGVUp8KQK5+gF9EnnQ5sz6GYsjd18ySerKzpfc9SoxSq6UeGlVXx8HvP+aBXq1Y n9Npy4Ede/RUAtD1LOTmwUPf9bOVxBr9HJ9TKXtpA6kOrrp+9ZdmtVyPhls3KbAd77Zb oXM1biydkxe6Td5ziuPG6HRd9pPXaE9PQtViIJJNiKTCV2qW22nkCl5ZOAIyWpOqKLnG 3TAxh7qUMUIwncWW005sra0pLrbHRJ0MRLVIzA4YA2w2I7WybgkrtbvAZyNvqACuZoUG V7sg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=jyCg1iCF; 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-162993-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-162993-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. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id d5-20020a170906370500b00a51d2dadd18si14326028ejc.549.2024.04.29.13.04.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 13:04:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-162993-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=jyCg1iCF; 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-162993-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-162993-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 365581F22BFB for ; Mon, 29 Apr 2024 20:04:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B8FBA1494A7; Mon, 29 Apr 2024 20:02:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="jyCg1iCF" 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 349F6146A6C for ; Mon, 29 Apr 2024 20:02:53 +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=1714420974; cv=none; b=Ygs3wdRihx8WZYCH15/iC0YLcxYbp7zo5SgbG6Cowf2aj3MuLnXIxVzLULIFk7bjKZKcfkDObTBzMkgjKnBCcqjMR1g1GGMJr9UH7iqkb3CHNMb/3J5PheOICapOd1Te5BjUv/UjoX+Grcr1i+dqNtyI/S0hIGsMZbDbWl4U6WQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714420974; c=relaxed/simple; bh=Unxtsgv9pMjovJEC2q3+izNqU1jvDayjR6yTMLvqpEc=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=moXajjcXs9n8rOTtf4PxYt7sa4ptDoAlPd3734yCWCWLjwqfYSddTPWppcOoHvaDlTprTmFqplgY+lFaylB6Ci8EcPZnJQtv2erh6Umiz4UiFlzKcgsF1a7klalFOJzBx3tRwv29O/ygd2mZVeLRpYqNL9G5WNxtxNBq1oVdqRg= 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=jyCg1iCF; 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-61be8f9ca09so859037b3.2 for ; Mon, 29 Apr 2024 13:02:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714420972; x=1715025772; darn=vger.kernel.org; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=sNfu8Xy7Q56dzltFDRS+tQNs0guv+YCXtYt4P68p4eQ=; b=jyCg1iCFJC+rXZABCEfXaVW54lDhrlfHLxgtPNayFNAElh35jD4CicQSUVjvwxxwl4 7Nbnf+OuApgqu5OOKhG6tofS9aQzeCunz6LtIKf6Ax5tMcND6u3Fod7WWakMrRqEPVL4 JxDSneHO6ag2Od98jzvwC+SYt+Ho9DJihTnOBSckGcN4lMf1Aw1WcV6u4jx9nCynECqB t8eQ1R7YI5ck6oqijst4wG7mJYk0seEqLMuBlDojwq72OiAoWx9iinCibGhocNH1FvpN m8jmFj2ap3Hs/zCPcWoG7+acebLS0NzZSDmkq/c27moeDWXkKz6D7IyfbNmbCSZ3sOLo r4yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714420972; x=1715025772; h=cc: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=sNfu8Xy7Q56dzltFDRS+tQNs0guv+YCXtYt4P68p4eQ=; b=Kyb/V1fDVMCUCz7JQn8UG+7OV+mr26RO3tVAm/zkM2NcpMD6zG1bgDeuEfo4FGI16F 8/Iu987AZBMmN9yhSaf2N1obf47jgzvlIiqBViprg0RnOlY/s5j6e4zbonWxJu/M82C3 dXBGVTKNsHMgrpLUVTdQo1VJFTS6iRXiTKjYxkJs65WYe2PDO25y9aemmafn8VCc4ZRV 1fpIZ7Cl1ubLN6NyGe0lC6KOks4EoAUNpAHDfRbe8ViiHbRT0/2aueR/9DOU+ZOJpeMl MvgNR5doDw6K25UPNF5isNMqGV7ZwsB9zfUDIf+i+DcDR0626UiEpvWMSyN4KNDB29+z z8qw== X-Forwarded-Encrypted: i=1; AJvYcCV8B0kALuFhwBdieHIRkDnw3aSRSoo6oqOxl3TkU6NdNTMim0M55jQaTU8tpJc+m9SRNuXO44fE2KQKsBIQ+nxJdI3GTBQUJFugBlY3 X-Gm-Message-State: AOJu0YzR7jT8O7+rzE02oFMjVbURZKQUv3JzzorGw1EsAWipQG27esi7 +sJKbsp4IQnz9WFbSlPhDhYBex9lL0lqblkh7Hc7nBt05HkHLJe4xchIzxniUiZpktMqph087bZ 9kD5AJg== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:c137:aa10:25e1:8f1e]) (user=irogers job=sendgmr) by 2002:a0d:dd81:0:b0:618:9007:a15d with SMTP id g123-20020a0ddd81000000b006189007a15dmr3201802ywe.9.1714420972132; Mon, 29 Apr 2024 13:02:52 -0700 (PDT) Date: Mon, 29 Apr 2024 13:02:25 -0700 In-Reply-To: <20240429200225.1271876-1-irogers@google.com> Message-Id: <20240429200225.1271876-7-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240429200225.1271876-1-irogers@google.com> X-Mailer: git-send-email 2.44.0.769.g3c40516874-goog Subject: [PATCH v3 6/6] perf pmu: Assume sysfs events are always the same case From: Ian Rogers To: Kan Liang , Thomas Richter , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Jiri Olsa , Bjorn Helgaas , Jonathan Corbet , Randy Dunlap , Jing Zhang , James Clark , Ravi Bangoria , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org Cc: Ian Rogers 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 either lower or uppercase. It 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. Ensure pmu_aliases_parse is called before all uses of the aliases list, but remove some "pmu->sysfs_aliases_loaded" tests as they are now part of the function. Signed-off-by: Ian Rogers --- tools/perf/util/pmu.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 7849be4bfea1..7275076e6d83 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -425,9 +425,30 @@ 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) { + bool has_sysfs_event; + char event_file_name[FILENAME_MAX + 8]; + /* + * Test if alias/event 'name' exists in the PMU's sysfs/events + * directory. If not skip parsing the sysfs aliases. Syfs event + * name must be all lower or all upper case. + */ + 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]); + + has_sysfs_event = perf_pmu__file_exists(pmu, event_file_name); + if (!has_sysfs_event) { + for (size_t i = 7, n = 7 + strlen(name); i < n; i++) + event_file_name[i] = toupper(event_file_name[i]); + + has_sysfs_event = perf_pmu__file_exists(pmu, event_file_name); + } + if (has_sysfs_event) + pmu_aliases_parse(pmu); + + } list_for_each_entry(alias, &pmu->aliases, list) { if (!strcasecmp(alias->name, name)) return alias; @@ -1717,9 +1738,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) @@ -1778,6 +1797,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; @@ -2193,6 +2213,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.769.g3c40516874-goog