Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp888617lqm; Wed, 1 May 2024 21:02:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUWRlzRM52ldmQqVh7XHg4jeSVZdTXrkD9EH5qVwDzWjqldCfpxyHUuakMjj3yIMxVKfyyTnWO7fzAE2NmdqCG7i7oxNAlQyUW4lqT6UA== X-Google-Smtp-Source: AGHT+IGmWgPbqmHEZjXA2i5e/QPp0ht2Yd9fJ94DSjQ+lEhPNlI/JftxSClmDoqtjucUd+HLx64B X-Received: by 2002:a05:622a:1a90:b0:43a:db77:100a with SMTP id s16-20020a05622a1a9000b0043adb77100amr5150552qtc.34.1714622560038; Wed, 01 May 2024 21:02:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714622560; cv=pass; d=google.com; s=arc-20160816; b=gYSKV5vxjJBbrwZJl31/KzfvvTvEmIgZHEnJrOcYr93v5Nt8lY9PonXB7h8xtovlIW m0k5ZQAN9xn63Akm3wD2ukApqDp0X9qmwu1ATwmWCbSJS1rnoGBftsLfCNWjPy/LiNJu Ah/eJBqXFWYpLkrtebnKriB1jGMXqLY57hyWsnp9OkuNiEK0yQGdD7/dN45gAc8WlSS/ ODDf8g1BLObWsWscC65sIebY23E3MsRuI9NuA/9yc20iwujv1XDssATu7EyvtpQjo2Q2 3t5xGGIFNfKRQayovauO30pQPTcyk4mNmoN5UCXVNN9PIxavmZjBtR5fwKEdMHXQkJ4B aH+g== 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=PvcT6sTjs9yRF+sI2DXtTPhOJ6C0kmP7SfXTIs7MZwY=; fh=jR5sLp+f/dg+DauHKBLMMfprplc+4bxviEHj43KDEug=; b=O6ZlkWPlkwn3lxbH9hibZkbVNUKthcuiP1lEvURulIsr02Bsn0n+eT4EgseGUFDqSZ pZFuNhq7B6iSVByYeO0o1g9UI5qpd5MlcamVezJbHPwtk7JVj/ulgWORJ9acPxn73jOz 8tQ7OzIFrFEtJVK4HzMzZSg6u0iWvBGYtK4cl88WYPiZLABAa2WUWRrkk/eBDOEzbyWB wwwpLoHdfoQJz+2tLhPvxh3bwO1kKcmGWEizL0lP+Ww4w+xOpTYDuoskeD8DqKMjG7Q0 2qPmF++x3ZOyRB6kS1aZvlC+2P6kVnSxRzdWEiPVkIsau5dKpm8eeYP87wEe+O3hEa0W 1fgw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=sUfkcg6U; 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-165955-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-165955-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 f1-20020ac87f01000000b0043af937c171si159870qtk.211.2024.05.01.21.02.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 May 2024 21:02:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-165955-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=sUfkcg6U; 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-165955-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-165955-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 B2AD71C216C5 for ; Thu, 2 May 2024 04:02:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A70751C695; Thu, 2 May 2024 04:01:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="sUfkcg6U" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.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 9E8D62135B for ; Thu, 2 May 2024 04:01:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714622505; cv=none; b=XmmXNEagX6P//VgDM2H0edG5NMyEiK8NPQk0wZPFDCows0wfQdh9YM1kT3tFzZUCB/qV+8r7nQkpSi/ADdAt+YcmhNcneV1sJ/YSRVfbDpi2bpGI1UFsliWkK6mEZG1XgsHxAXWyYxgPmkjS33wrVgUmfaCDZ11PRY6Y7qHEnMg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714622505; c=relaxed/simple; bh=iUxzUsA824hpm1sIfELCborfXgMpM064szlvgEyGsAw=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=V64tzybOPUH9b8mt3cm/3ZFiFREXBzgvdZ5KWg9MK3R7pHwZLIVTJuxNLEStHsV1HR5D6hE/X00otucI8bf0GHo75c2TBEHTP+BnEHeQ8S7SGoxMc42U62WhsKGPJYLVxS9Y4jqVjOr4aa92ST/cHrIuluJuBVds3U5K/aSEbjU= 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=sUfkcg6U; arc=none smtp.client-ip=209.85.219.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-yb1-f202.google.com with SMTP id 3f1490d57ef6-de54ccab44aso15392583276.3 for ; Wed, 01 May 2024 21:01:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714622502; x=1715227302; 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=PvcT6sTjs9yRF+sI2DXtTPhOJ6C0kmP7SfXTIs7MZwY=; b=sUfkcg6UNbAtyps8iYNKK+2Fn1HLddjODzdMlgzgXQndfIlt06yQ9BUf3Nyb3xwTAd Zt7qBntZFQpFclXDfUJPjr6KiUFkziql8w3xBKU80uAJ6wA0A3h1yZnJIvR5EKTcryq6 GfyAWrL8MT5W5IyjroS/hGXIUH4j5bD302RPZaCeAPH8Sq0IVozJH0deTZ9dtvSrowcZ scNbag7gv7HnAIiy5LeQYmvlM3RGLrfgZu3eivhxLPmVrW2YUGQm83JxdXEZwbyrTVoP F/V7y1ZLO9eMaw4lIpAHub2cRFUFVKYrxwJffBNvdu1RDTPUw7jqmewRCncY+Cg/ZTY+ gJ3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714622502; x=1715227302; 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=PvcT6sTjs9yRF+sI2DXtTPhOJ6C0kmP7SfXTIs7MZwY=; b=pszwBPdhET9QdCwLGlOBItTO8QoBaTVYyg7CEWK4rFHYLm+wml48lEV77IY2LXhYOa kGc0rS7lQnuCMvG4SqF2S/YBs+GA49r84rCWxJYNL3QRZ5yblmDdS+TkYLUOjZ/GelUo 91cSDkDL2p2C+roNpj0gWuHV6Uwcgan1JYmzpKTsImIC42pwcNg3451FrXfNCe+hwjZv Qe0ixzFtXycF5xC1Ylo2s+8czI6tENLjVzlaPOoitPuG/+O5q3MYYFrcq6oXkaOZPrxZ mXnRenpFgPy/poX3l5J4K8kiFfkHydGnffaMIcfcW9doQDC8Vr5T7UhtwYpNoWMnOVjy FChQ== X-Forwarded-Encrypted: i=1; AJvYcCVvgXVFOEY+wVxNL6JTPSfn73fKuI4VXAGhgyL4uaTx2+e9XWahFM3KFHwMt3GeM5BHltgo4NmRQRGnsGpG4cYtX7io3TDXcqjisgIE X-Gm-Message-State: AOJu0YwHrf8YNpfe+UclGg4dtFwB9cwJGJ8NMLqPZ9f+tf3SWcM72Gxr uRgRp3QsUghoIaZJpB82kwj3jf7kBFNIkxuLGtKObf01UYv1vcLZfsLzEOOoqLvln+IzGpsUW/N 5nW6QAg== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:53b9:bbda:1daa:17d3]) (user=irogers job=sendgmr) by 2002:a05:6902:102a:b0:de8:ac4a:1bce with SMTP id x10-20020a056902102a00b00de8ac4a1bcemr252339ybt.13.1714622502619; Wed, 01 May 2024 21:01:42 -0700 (PDT) Date: Wed, 1 May 2024 21:01:11 -0700 In-Reply-To: <20240502040112.2111157-1-irogers@google.com> Message-Id: <20240502040112.2111157-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: <20240502040112.2111157-1-irogers@google.com> X-Mailer: git-send-email 2.45.0.rc0.197.gbae5840b3b-goog Subject: [PATCH v4 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 6e18a4c447ce..bcbe58fb7d66 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); @@ -252,9 +257,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.45.0.rc0.197.gbae5840b3b-goog