Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1595534lqa; Mon, 29 Apr 2024 13:03:51 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUfPNGOXqNiRLbBjsJFjSKbDJQWeJasMjodq256+RAy2R9B3AopxTdnU+2gaFMfdjXzc9x33d36i+kZzqCdKwqDi/p8a80CX+Dox5e88w== X-Google-Smtp-Source: AGHT+IG6ixnqTqH+KZyYzHYkHVJmqC52PafUEuN5hgYl5V2UktkclGTZqFACICfV7+dwCd4HGH1o X-Received: by 2002:a05:6102:5094:b0:47a:40f0:d343 with SMTP id bl20-20020a056102509400b0047a40f0d343mr924774vsb.32.1714421031007; Mon, 29 Apr 2024 13:03:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714421030; cv=pass; d=google.com; s=arc-20160816; b=0Ea3ACuXu6YuNSmjbptzUMEujG7pILGR7yf0fD2xrajn9xm9dOLzLwscmk4jT+unet x7p0aCREwO+HwlzNBoNfgPl48Nnl7rG70aLxXrRxPA7tkw1K976rABHTEFNwwrD0uzAM NXg/Ao/uBpXcalG5NM47AzbK+VYIa5v/1uazVnM+IJCs0KVhGP4jz5O1mKhuLA76zYWb QEWnSyzfOXone8Roy541+mziX7yPh/TgYhJdlgaL+ukrLuSPYk8EUTeXqeylWpG4Z/wB mkbK4WQvTSKXwdvdCNxXKm3adXvl/ZZn/Znwrs4GKvtmdkYaYiMKavEUU2YBj0rNwirV +5Dw== 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=ST8QMxONeyaCSSADxQ7gE/hk81EFR0HpWu5Q0a0nK/c=; fh=lEgCoZLLF5hnyaQtDIkashLZHHHvccIKJumo+x0RhG0=; b=h/6jTL1X30+SpuMNnbJHNgH8QvJJLW/WjjB6rbqmH0vJKdIu6ukcSFrskZTLRFznQT HbtnkOqnxicbzH6I9Q8h+IoL9q2S2Oqkx9L58BbL8C+qah//R1k+2aTrLjcXKyCSPpsb M51t6w0PTXOdR03qp6MyZBz8gPvZvtCdUhBNQjIRwMf5UeoXMceW/ComBX9Ua6GO84Co rshJ2vLxoNzq9e9pDm3oHWQFAlATcyYzkjOgDMnIPOYY8Cwqqu70c08I/EOz1srQEqW2 zohztsDM9mi019gW8c7tWZTMQahpcqL5Ans3VhSCBEzC2Txism0mogJbV0L/Qh9CZwDv eRMg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=yEPD+lg1; 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-162992-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-162992-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id e22-20020a0561020f9600b0047bc610a0fcsi5329136vsv.316.2024.04.29.13.03.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 13:03:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-162992-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=yEPD+lg1; 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-162992-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-162992-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id A89001C21A40 for ; Mon, 29 Apr 2024 20:03:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5E01F146D4B; Mon, 29 Apr 2024 20:02:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="yEPD+lg1" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 EA14E14534F for ; Mon, 29 Apr 2024 20:02:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714420972; cv=none; b=H6Rt/mc8wexJiSuneyylNutT5FNU8UXSstQBes6DL4SnOzZgZpz07Hx4rx2Bm6ddll1qNcSZCupwNDpVp9lr2DgeXdaTBRCIjE0q8vaqIRzc/cpOV+2RJzIc1vb2gGqpXfPWCB1hzx9ctukli11bltOci/ZK69UgkPY+9Wnib5s= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714420972; c=relaxed/simple; bh=i7OIixObrBK6wLYTL3j3asD5BAu4/Nn0mVDSiF2+fSc=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=FnHsJ5BYyrecNw0A/Q5jBpqVgvbcMgU+F0GpS33cuADX18nuav6vwTA732d3/tTPoxFmCNOo121be2lJ99EgWU/BNVY82w72h3gGDvh2RIr1vPMOIiBOqWkadwQfk6kYEmsTvtm6T3Jv3j63wazfXp/bsT6rAMFRcJEVt7ruIBc= 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=yEPD+lg1; arc=none smtp.client-ip=209.85.219.201 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-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc64f63d768so9610377276.2 for ; Mon, 29 Apr 2024 13:02:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714420970; x=1715025770; 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=ST8QMxONeyaCSSADxQ7gE/hk81EFR0HpWu5Q0a0nK/c=; b=yEPD+lg1F8kAXPEHKQXsDxPiGfRIUfBtyRYk6hB4/RNhsCLah894gvZkIoGHTcKFne HMDKe0afvrfPxOlXy+6WyHaQyv9WiVUpe3n6m9crGN2qrs+UDZakugsQlfRl3JZQFITT RRiputSmbYhlJmBXDrrE6o00j+oP1EUNkTRU+LWH4riYVnDqPS5viKUeZwpNn75BgBbP GX7vGYRkpG/5nAij/4bsMSp2vY/QEY3Zlfk4CyLKTwTNznWRvTupyKYxwxEKkOEHP7a0 abo7IQdD9hc56EbYiT46tTse5aIhXmZUGHspLCGKWfdtQjCHCk3J6PsXg1u1ZEvpkvAF Gtww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714420970; x=1715025770; 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=ST8QMxONeyaCSSADxQ7gE/hk81EFR0HpWu5Q0a0nK/c=; b=F8g5PSGhTyKhHiBEs7gdZCiUZFqHILdn00lvxY/4BiLLitdzPueM2a2WcTNKykp4ZC CfV7hb5T0mCs/IDFrPWsZR4F3bfoEhJ683e0Pov43ZSFpRrrdk9hOSjSTpERqZ2ivkii LQfM8xZRttHYHUdqco0pFyswvF/yZAQIJVoTgJampagCQl/2VjWREWChkcuBCsKu14sx cv9/Iw9m6NyyqgO7L2qinGpDFCx0RdvdZY1NPd+Cg2aUS1Urg9cALenrF9GTAtwn+ryp q+QCww7fhgQ4Cpte1Tb7d3TYlSVxW1LwYXAtl5viOe28sFjFP9WoViAQVVvxenH8RxXA 1HNg== X-Forwarded-Encrypted: i=1; AJvYcCW/AdKbuw9vde+r/iMJl7YD2gJtR4/NJdgTQzjHkqP58oIcJvCmYnRXXabFRbh151i/KBMNPOfYyvJNfHAufOqC2Aia2yJ2KT+GzZVt X-Gm-Message-State: AOJu0YysRs/8Az93KSKtmlDyOxUoVgOC5W8TH6Wir64ls+eN4EQncaDH TbOhqxmRDy74XS155cACSj2vQ2n2HJDeo+drFglWu7kM/K/02jtPnkFwAkXKnbbhhwP01xTll4+ OMGLElw== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:c137:aa10:25e1:8f1e]) (user=irogers job=sendgmr) by 2002:a05:6902:18ca:b0:dcc:c57c:8873 with SMTP id ck10-20020a05690218ca00b00dccc57c8873mr3789929ybb.9.1714420969922; Mon, 29 Apr 2024 13:02:49 -0700 (PDT) Date: Mon, 29 Apr 2024 13:02:24 -0700 In-Reply-To: <20240429200225.1271876-1-irogers@google.com> Message-Id: <20240429200225.1271876-6-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 5/6] perf test pmu: Test all sysfs PMU event names are 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" Being either lower or upper case means event name probes can avoid scanning the directory doing case insensitive comparisons, just the lower or upper case version of the name can be checked for existence. For the majority of PMUs event names are all lower case, upper case names are present on S390. Signed-off-by: Ian Rogers --- tools/perf/tests/pmu.c | 90 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/tools/perf/tests/pmu.c b/tools/perf/tests/pmu.c index f4e9a39534cb..ea21b4db10e1 100644 --- a/tools/perf/tests/pmu.c +++ b/tools/perf/tests/pmu.c @@ -5,12 +5,17 @@ #include "pmu.h" #include "tests.h" #include "debug.h" +#include "fncache.h" +#include +#include +#include #include #include #include #include #include #include +#include /* Fake PMUs created in temp directory. */ static LIST_HEAD(test_pmus); @@ -241,9 +246,94 @@ static int test__pmu_events(struct test_suite *test __maybe_unused, int subtest return ret; } +static bool permitted_event_name(const char *name) +{ + bool has_lower = false, has_upper = false; + + for (size_t i = 0; i < strlen(name); i++) { + char c = name[i]; + + if (islower(c)) { + if (has_upper) + return false; + has_lower = true; + continue; + } + if (isupper(c)) { + if (has_lower) + return false; + has_upper = true; + continue; + } + if (!isdigit(c) && c != '.' && c != '_' && c != '-') + return false; + } + return true; +} + +static int test__pmu_event_names(struct test_suite *test __maybe_unused, + int subtest __maybe_unused) +{ + char path[PATH_MAX]; + DIR *pmu_dir, *event_dir; + struct dirent *pmu_dent, *event_dent; + const char *sysfs = sysfs__mountpoint(); + int ret = TEST_OK; + + if (!sysfs) { + pr_err("Sysfs not mounted\n"); + return TEST_FAIL; + } + + snprintf(path, sizeof(path), "%s/bus/event_source/devices/", sysfs); + pmu_dir = opendir(path); + if (!pmu_dir) { + pr_err("Error opening \"%s\"\n", path); + return TEST_FAIL; + } + while ((pmu_dent = readdir(pmu_dir))) { + if (!strcmp(pmu_dent->d_name, ".") || + !strcmp(pmu_dent->d_name, "..")) + continue; + + snprintf(path, sizeof(path), "%s/bus/event_source/devices/%s/type", + sysfs, pmu_dent->d_name); + + /* Does it look like a PMU? */ + if (!file_available(path)) + continue; + + /* Process events. */ + snprintf(path, sizeof(path), "%s/bus/event_source/devices/%s/events", + sysfs, pmu_dent->d_name); + + event_dir = opendir(path); + if (!event_dir) { + pr_debug("Skipping as no event directory \"%s\"\n", path); + continue; + } + while ((event_dent = readdir(event_dir))) { + const char *event_name = event_dent->d_name; + + if (!strcmp(event_name, ".") || !strcmp(event_name, "..")) + continue; + + if (!permitted_event_name(event_name)) { + pr_err("Invalid sysfs event name: %s/%s\n", + pmu_dent->d_name, event_name); + ret = TEST_FAIL; + } + } + closedir(event_dir); + } + closedir(pmu_dir); + return ret; +} + static struct test_case tests__pmu[] = { TEST_CASE("Parsing with PMU format directory", pmu_format), TEST_CASE("Parsing with PMU event", pmu_events), + TEST_CASE("PMU event names", pmu_event_names), { .name = NULL, } }; -- 2.44.0.769.g3c40516874-goog