Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp1427234lqm; Thu, 2 May 2024 14:45:30 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX4eZu1D+ZE+kT7SNoMcD/PgqzhUhRx+7xDhrAiu6+r9k5XtLvZ6o3uCQogxExiL/FJ3six8+YZPxq1WtUGThY2YqLdqCMaWid3yYyJDw== X-Google-Smtp-Source: AGHT+IFvDRk3o1euWQfaVnSMCcKvDlkKC0uDal+qto4Y6w7hZplLz/H1ffyiM6rUJ8R4x0ysC/g8 X-Received: by 2002:a05:6a20:dea6:b0:1a7:807:ca2 with SMTP id la38-20020a056a20dea600b001a708070ca2mr1026772pzb.29.1714686329768; Thu, 02 May 2024 14:45:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714686329; cv=pass; d=google.com; s=arc-20160816; b=Uf0j4oGu3aBRXh5Spg3dYdns/fkMt4PUsJRFQ61StZkVFxOqzSZ7arid48e6dUSCFE Li1hO7noiUAXYRkzm3W1bunAW7Jf61026MNKg43pw4IM1HjnuCmIS5f03oMCMZBLVSBG n1XA/L5Dq+H4+8M8y+gy3RKu5RNN153+YwNT2iDdbSXEjQ09GqAeSjyG2Ceb31G9Cmii pVdbWPmLaD2BiRFph7lH/CIjUp1whJ6GdlbQGwrY11Ld9hCGVyuVpV7PKNtMPZnPMxEt gK/kseYWE9fWnbYVf9pzbxNF1ABIMCMzwo1kIkf9K9t0OWoRkCDViMc48ahlZLGpP1WE X0aA== 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=T7T7WZEjBuFkXStQU5evNsW0vwkcSQvyjHQCUzxlSFc=; fh=acH/5L4GQ0TvBh06MA1BIlT2vEMSMn0GfYwSamEJTho=; b=hDGfegJluPnqquHxsIbDezK55DdbJB7LUi/GpORl1JKdV7ITYWYGuxMoSkbLlOkX88 hwZAMg1cTIrpkOTtrguoVKsIuoNyjuLc3cnLfeLZLZSLMlo3X9YQilKsLe+6oe4ztZhv 6bojB/zSdGe7CpJwGBFsZcSxofzOr8LAHC1BU0zk/PTXEH6+cUiSwmE4XDp0MJFS1e75 0IE4uPUz64KrAsUEgVLpeGZdw0N4ruaCoJAPKE40vtrnL4ntdI1nJ282hGcnMj2qOu4i R+TAsTilgc1sv+KbFCh1wwaqpmMg/xG+8q0P6tJUEQkFb38aHT5GSsfQl+zhcWhUjSx4 T/vw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=xl8Wz12R; 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-166948-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-166948-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id ll12-20020a056a00728c00b006ea8952e51asi1665875pfb.165.2024.05.02.14.45.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 May 2024 14:45:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-166948-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=xl8Wz12R; 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-166948-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-166948-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 204B6B23438 for ; Thu, 2 May 2024 21:36:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D3822181D00; Thu, 2 May 2024 21:35:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="xl8Wz12R" 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 6F5EE1C0DF9 for ; Thu, 2 May 2024 21:35:22 +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=1714685723; cv=none; b=BTBRGIsUJCxRU7da6dCN6yK5Jc8wkzll/0Dfs/Cu4hFq5iBykm/POsj+YKuuHYbBAAN3d1PEfPmno4mkYKDMWyy/zvLtt6YZ2TqoBU1/NfGsiE6LVa6bgqjsDkVmj+Ys2pe4/GdOACco57NFTWDE1+gTB+lx2obuxnBhCOCKqR0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714685723; c=relaxed/simple; bh=LzaODOpcY1x8MkLGsXtF6i/yozt96RkuIzwffZUTjTI=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=mFAivuwPcAPcI4W1Y0260TQv4uQXG8wL5fWT5MP7KSh8FQJqLT83apCJxdMm/lRASibFuoKlLGClPrKgkQ9ApWh+n1Nj3dpPOkXDhuXJxt0tf71+6hzt9QLrBQkqOzrX9oHy349cc8rvs/X+grNq1mf5W1RXLT6y5EEJ7ru9Vtc= 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=xl8Wz12R; 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-61e0c1f7169so17497687b3.0 for ; Thu, 02 May 2024 14:35:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714685721; x=1715290521; 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=T7T7WZEjBuFkXStQU5evNsW0vwkcSQvyjHQCUzxlSFc=; b=xl8Wz12Rcp13Q/R9K3ZKDgHeMG3daNhNNtmMFlP4T3x3Fl0JoynsVvlrzL/Ng2vT02 Fq05Ipow1LywJHw1lqChpQsD+gnu/PQVLdNS8iM0kMVebrXmsjVdj9xVD4crQkbnyJzm 42OQGvom/Tlc82ZEJMn7mGtlF3HINOYzsEmwjq86micgsAZPV7VQTr1fKQazwInatBHE L17NS99R8M2+Yu1Zxwqkuc3keA9JwAMZCA36SvJCuiOQ7s78sly/wrYDrvFN8oeEEQDL g3JGgteJ190moI1a5vdfC8N8tO2QHZpxKAWmkyx8itBpz/zWD6Fa78d9H3S6rxfxtAWX 4umg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714685721; x=1715290521; 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=T7T7WZEjBuFkXStQU5evNsW0vwkcSQvyjHQCUzxlSFc=; b=aNMyv/R3FUN5gcUzH/wFqCnoARxiY904IccEUIHq/Q6yGyhuyIfzjvIa8+RA7mNOao OTKBaHveGts3WTNMYEZG6KktCrNZ11oOd8KkfTek3XuP97FsheGC52oK4yZbUv1PU+Sn 9wXmryP9jV5MZWGj18vm7qhXDXwSvkpqrPix7c/ctz972UGzYlvfJ7le9NGdk2bQThCM dQ8CeH3Lf8KdYPuNQLXk1/uJYVbq6LDubDZ3kNFBiUHO5ZHn+ARXeQyhvAlYgjyeJZpm vj6/GL0Ye01wOcyywPlx3YXnqa86yDU39Ff4r7A+s2pOEaWx/ejDhTCT6K7R0ZuFOoY3 VPNQ== X-Forwarded-Encrypted: i=1; AJvYcCUuLxdYkpD69uh+ghefCKZ3I5BRmdf8CjJlKlq/zjIrdUbtIWni/gUTJWoaH+DeFGKEvPoojI6bHCzBvlIN8mKJTPQn01/CdpA8OTIe X-Gm-Message-State: AOJu0YyVpwUKWEGZbaEbAGJ+Y0lLXX+kOwC5x+JiCpDmmyZEn7SXsj8K jFH0Efg6YMMDOVjDZS63ELmU/lqK3uuJlrqUD+XEFtpG7wBdj1Bv3QLQSFh7uKPaEbr0sozJxst 1FQ6udA== X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:deba:378d:2d3a:2641]) (user=irogers job=sendgmr) by 2002:a05:6902:1505:b0:de5:9ecc:46b6 with SMTP id q5-20020a056902150500b00de59ecc46b6mr318413ybu.6.1714685721504; Thu, 02 May 2024 14:35:21 -0700 (PDT) Date: Thu, 2 May 2024 14:35:06 -0700 In-Reply-To: <20240502213507.2339733-1-irogers@google.com> Message-Id: <20240502213507.2339733-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: <20240502213507.2339733-1-irogers@google.com> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog Subject: [PATCH v5 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 Reviewed-by: Kan Liang --- 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 071cfc51b52c..06cc0e46cb28 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); @@ -251,9 +256,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.rc1.225.g2a3ae87e7f-goog