From nobody Wed Dec 17 20:44:03 2025 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 6820C181CEC for ; Thu, 2 May 2024 21:35:13 +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=1714685714; cv=none; b=PdeaG5u1cnSESsDA1DowJHdYR1z0FIrJFPKEiBlx4/c1VarSzfMuSKunrTXqgSmbqVKCOZohI7qEZAEqlzJMxjbV0nb3gHDMI68kS7zVJBQkkohp77n4RiZecSDM8AcRRiTb8MvH3AKonaTbEdl1BWJTd5nqWftgOnvQZ1CPPPE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714685714; c=relaxed/simple; bh=tOBCq5saQrvaRbLejKaKunkpMMX6Ijqd8fdc3WGaBWs=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=k5X+lbb7FJesoPx99/2vNQerG8LZ6voCIX7b0RNCbfSIq5wCp/jzd87uMLy/HaF0Su4lXA8IVfQFvaty491oppgUdFfRVphjZH/h0ppJHy1JoAmaBkB1F3kC8Nddh9sYnQDteP6Q3kxwd9afpMubs7g+NCnSfAFEZ+YniNydGaM= 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=E+IyvtLr; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="E+IyvtLr" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-61be26af113so74452577b3.1 for ; Thu, 02 May 2024 14:35:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714685712; x=1715290512; 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=dFxWFm3XAkSXgRMvbK6qHWYFEQhk7mOXO6rOJepfIcg=; b=E+IyvtLrE+ta45BkDrFrm/un0HEYJbQ7HG8iGmlIKL7SUgBoftftFssyMvSmFLNIql FDk03Dq0LM8sWGKkbylwm6lWHHXj7cIbpfuX8zBOG8kyVT2nzD4C30auJPhkXO3Sy3sl JN6iiA/vNfvH3K+LRmkBwyYSLcvzQXtlBZv3EaKUuR5NqPAXm5kpowd6T/GpxMf+c1R7 lYN3ng7izVsEJ5KRooFOWMek93F907K7CRKkUbjAZeeNtUOLLrzl5FQJXHIW1lMAYN+p 4glbcaAkiR1pxE6+Nuajy5z+M5RGvKsiEZpmp+lJAHI859aRA7gK919ng/kVMuRTtI0u KXpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714685712; x=1715290512; 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=dFxWFm3XAkSXgRMvbK6qHWYFEQhk7mOXO6rOJepfIcg=; b=fIL+xCOFHknnA4zXoxrSLjL5SN0c185UV+jKeofSTMjOkLTjT7lbYyQBK0PdggWgkf FN+CYHmhlg2iNdjrh/lAOlTLTYlqojL+ow0ECJ8FH+rYd4Y3hvwL/Qk/L9Nmn0sM+s00 dbTES9a78B21bDD+i/8b5p8ZxIqLI+VSPU0kiEqKuFuIhckqIR+LNTrow58zEORAf4w8 CaWXZYzxIqOu4kS+TcALeS2XWHAatwZ6HyFRz1ZVKmElZZ1JD4BvYZJ152LMANQupzEN XhDiQikatH7bVKBJZM1g1iaXAwDViIbcX7sUZ15uZyIeXhysRDdMYxJ5zDL6MvUpMGXo rDTg== X-Forwarded-Encrypted: i=1; AJvYcCVi+4dp0LBQZruj/AVbQF2cmAU/XQDwjRhKLOWvEEeC0yr3Vc1H3zq3ckh4QKSs6mf8lZq5w8Ftzv7WbUs7AEqfZuCRAjEWxFJgRilJ X-Gm-Message-State: AOJu0Yy+j7RHqzJe0Gm0Xvc0HILZIGpfbPPdopd7sla92U9EKqGx1OHz HivKhsDv0zmeWRXaIVJUMrfuRNIYAdLpn18VYaLy/378WUXMFypYBv/XjS7ZDII9AWke/7v/nMq +Z9g2ug== X-Google-Smtp-Source: AGHT+IEk1ODDvzdT8Cb7sSOH6uOhMZt/Y9YdELjl+b5F3Z2u0EmkSmoN0mV5UaRdfxOH1tTAE0u7bHdeFpJO X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:deba:378d:2d3a:2641]) (user=irogers job=sendgmr) by 2002:a05:6902:f88:b0:de4:fa0d:ab3e with SMTP id ft8-20020a0569020f8800b00de4fa0dab3emr169767ybb.8.1714685712509; Thu, 02 May 2024 14:35:12 -0700 (PDT) Date: Thu, 2 May 2024 14:35:02 -0700 In-Reply-To: <20240502213507.2339733-1-irogers@google.com> Message-Id: <20240502213507.2339733-2-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 1/6] perf test pmu-events: Make it clearer that pmu-events tests json events 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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add json to the test name. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang Tested-by: Thomas Richter --- tools/perf/tests/pmu-events.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/tests/pmu-events.c b/tools/perf/tests/pmu-events.c index 47a7c3277540..7b2c34462fcb 100644 --- a/tools/perf/tests/pmu-events.c +++ b/tools/perf/tests/pmu-events.c @@ -1105,6 +1105,6 @@ static struct test_case pmu_events_tests[] =3D { }; =20 struct test_suite suite__pmu_events =3D { - .desc =3D "PMU events", + .desc =3D "PMU json event tests", .test_cases =3D pmu_events_tests, }; --=20 2.45.0.rc1.225.g2a3ae87e7f-goog From nobody Wed Dec 17 20:44:03 2025 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 7A7301836F0 for ; Thu, 2 May 2024 21:35:15 +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=1714685716; cv=none; b=GqW6BO23hToR8PJdacOnrekHRbGuT2TStqh1tkR6MC5wOIC5aWnmcCbPCzJ1iRqnbt999aRvrW7MioT1SbwHNwsNVDnNlOIWPRnezVvyTcuOlmTJYkVV4ZSiClXeyUr7beZKT3i12gnhWSdZxPGvUOhs5i3G6wQExPff2FOzbcw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714685716; c=relaxed/simple; bh=+iC8656RV+1z9SNt/rVmkZ8TfblJJXHmOmw6MoV2AOA=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=UB5QuwhqByJwFvhS6VCUR5661pXAjv973BTAWVouv+EvYnIK0TiEt3lIV7N+PmZLi6sNYyWHNva0q3BAS4LQ3IxIZ/JA0tok3aoEJLbFtVr+8FAiGpYNYVS5Ur4/1rGL9ygvOdZgJXZoaAGorfy8RCBKwtGW2Jt/mRTdvBwSlZE= 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=YKmUWmoh; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="YKmUWmoh" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-de60321ce6cso8326630276.1 for ; Thu, 02 May 2024 14:35:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714685714; x=1715290514; 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=zgV4xf5fQxiR7aZHDngtpEH48nFcBFO3YN7qW93R/WY=; b=YKmUWmohHCI3nJNqF0x0QwKfeyQLFnr3qoAF3UJwHEcseRz57D1mJvvfgXq86Ob1HM q4vP+URgT99hwigCINta0rPI4elFwXbp5HU6Pdbv6qlYxGbH7xA+fzAREWVM9bhJmocC iuQ1FKbVzV3P7Dqcy/wt25N4cJHGQ7SNWgUYj7IlKus2uyHWGMbfVfWEn9cDMWgzMKUn AGuxGXtrDjT5JTQqTyC0EnhDVqY6Y6FSsF+4nAA2kfl0gFfvTDu+OtMcjGd/7wsM53Yv fAPnF1EaXEOZl5RILKLoSn4tkmEV1IWlqw6U0EKz0z6HNwhEtzST1Th4euXyOmURNGcK DTWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714685714; x=1715290514; 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=zgV4xf5fQxiR7aZHDngtpEH48nFcBFO3YN7qW93R/WY=; b=wki/eeZpJpw5St/d6/TlS3Pe+TrBdkkRjAYqwYJT3of2LTsnOxRwDgkuLd0NlpkPCu V+yfnmKpCeZKt693NRVw2FLpmMOJofIvfIN5XCmG0xGZ2CJ3CxnR1DfYZr2+YQfKIEQc yypU7VSgWlE/LxUACQ6NUgtraJnJSFhXGjTJnGC9Son0ZuFuug6D+LBBIAA6D3abwNgM lCzkVNAmXkJDvawFYmwAWFNyf5ZWQ8YHvJUdV5Pp/FhfPoV9NcSMWMs+bM2NW95DujvG i1/APJKfryrrxw8XAakbkUMPeng6spRGk8IVSvphzxTQCbu1jYPWnzVPZG/x7yA0ZzKM D6Cg== X-Forwarded-Encrypted: i=1; AJvYcCXvRXfPTDjewqu1xhEuQx98tg4veXZ8cr7B6cNQaHj0RFEJf6T2MIVp6QEBWrn6JLGotuZdkyO9t26CW1s6Rk8Lgpcffl1/SMXAg49x X-Gm-Message-State: AOJu0Yyao+XnfuR0XgGhUKlUtznKlV7gJ1aKqAwsMYzcmcMAnLTb4HQr FsW4NYJtazcvAsqFl1lXpS3kPasR7IhLvXR6sMkFqVrmFhd6TZcziU2hi254z5VYOWN7IgrUdag ouxN7aA== X-Google-Smtp-Source: AGHT+IEXj+L7mG/mFxFwq34rU15M9trIcDqflnvzeDMxWFJfivTAbhdOHNL6yQyts7hcKK3NVMlyQZ6Ci0F9 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:deba:378d:2d3a:2641]) (user=irogers job=sendgmr) by 2002:a05:6902:1007:b0:dc6:d233:ffdd with SMTP id w7-20020a056902100700b00dc6d233ffddmr322304ybt.0.1714685714546; Thu, 02 May 2024 14:35:14 -0700 (PDT) Date: Thu, 2 May 2024 14:35:03 -0700 In-Reply-To: <20240502213507.2339733-1-irogers@google.com> Message-Id: <20240502213507.2339733-3-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 2/6] perf Document: Sysfs event names must be lower or upper 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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" To avoid directory scans in perf it is going to be assumed that sysfs event names are either lower or upper case. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang Tested-by: Thomas Richter --- .../ABI/testing/sysfs-bus-event_source-devices-events | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-bus-event_source-devices-event= s b/Documentation/ABI/testing/sysfs-bus-event_source-devices-events index 77de58d03822..e7efeab2ee83 100644 --- a/Documentation/ABI/testing/sysfs-bus-event_source-devices-events +++ b/Documentation/ABI/testing/sysfs-bus-event_source-devices-events @@ -37,6 +37,12 @@ Description: Per-pmu performance monitoring events speci= fic to the running syste performance monitoring event supported by the . The name of the file is the name of the event. =20 + As performance monitoring event names are case + insensitive in the perf tool, the perf tool only looks + for lower or upper case event names in sysfs to avoid + scanning the directory. It is therefore required the + name of the event here is either lower or upper case. + File contents: =20 [=3D][,[=3D]]... --=20 2.45.0.rc1.225.g2a3ae87e7f-goog From nobody Wed Dec 17 20:44:03 2025 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 C16451A38C7 for ; Thu, 2 May 2024 21:35:17 +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=1714685719; cv=none; b=WWlzxc0yhwh8Ul1Id3HkkuDFIPDdi6KTA1i9JlzYWVz/XO27KIEiRCnSJP/OOxAm3DO1LrEnXhqNelCCYTWuJ76UR4Xh6TTaoem4psrkKEZ3oRirewUTvQHaK4+9EOIX+P5CG2NzTBanhbkySFZrcTwpWAvAhbYLG/EI4T6Xs/0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714685719; c=relaxed/simple; bh=Sefgb1dIMIUu5Y3bIt15Ku+/ZrLmHFLxlJ/4mRLQQXs=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=BblDRQKX2J9VzP4lS2jzaGrERPta1fSn7vsKN3b26UH/FOTyoJp9IOyPHWmqGHwNOdMOVIebzN48p83wB+kQ2C0e6bnJFUPbq8v+v/MUX3/Ekpk6uOkAvYzZBGHUiyOm8p8vcQ3EsUDx1/xAR4XaFAra585b9E5q1dUyZlLuG/Y= 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=xsBetYns; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="xsBetYns" Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-dc6b26845cdso12875031276.3 for ; Thu, 02 May 2024 14:35:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714685717; x=1715290517; 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=ZeBoV5zeEIYf5sTMbzFl5y0Yw10CZZTQHT5jBZAFh80=; b=xsBetYns7OKH1QER07INTKTNzOE+QDwCGBNUGsN/EPAWyKmG+Xl6+b0gsCp0Ec3NGn 0w/KZ4e3AbbHE+Tc8KWytYY4t//zNFMEqMQWVRB/nLuzc2QZMZrPcW9ur9a3gd4zeBNd 4EdmodRKhsUKEkfaq6FDj7fe/ZPPYDpHosd5R3pAQzbiYcMxfeEBINvDo+ylXw6ODjw8 BHatXAtveK0YvVBD8wtu4Y6svL04FfMORsY0eg7C0dToq7MP9Gab1W/Nqyv8K+NZpuQr G167n2a4LbqwKBeprMNTr9s0tSETPVMPLvnIl8uj6wdGJJG56sRa5lQErgGjF5yUoMOE dh1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714685717; x=1715290517; 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=ZeBoV5zeEIYf5sTMbzFl5y0Yw10CZZTQHT5jBZAFh80=; b=dex90wn3h+hrLuEa0lkJxsetSo41SbshgStgSJJC7/fDt8VVgvZYnjSciHy8Ws3vjZ CNO5OetDd5Ob1w4SemuNYprgR3JMacsku1gseOzN7KzZywLQ2fRe1LmhTcWEGnVBb27T dj6Yr28t6vkvtu9xBkt5PKbguCuXaVHMZaBv0dkv/RX0PNkXFpLhwYePljbObU+JscrY DZLTG/Y3i5kCaTZD+700LMasgTVLGXBXpnw/0VQXb3dwZx6aBEN/cxp51WEZIJXd+5Ax +YKgIrzmgt2h4XhuBGiVFJGdYpaPOmlbFyW2RgHRcEajD8zd0k+MtmahnPF8G7Hsfudx 2ORA== X-Forwarded-Encrypted: i=1; AJvYcCWkjmYhsNID6fvXH5d+lZIobTs891RXRZH6z9U+eUdYRuH4i9J/RR02BcRu/luM9TzlWT+pePQj1xWBFRnzfv/v4VbpYCahconDYR9o X-Gm-Message-State: AOJu0Yy95VHY4SVMfCGj8cXss3PT/2XD+8tFFMDf/wR7p8yVHUVTZ6TA /2OoWie9a83RKE67b5UCmYJBZhF4NsbF+cbidxL4C/Ej9ra5koelCw2RdRrbAsScvtodTrtJPT5 NCQWehA== X-Google-Smtp-Source: AGHT+IFVm+N4vOCBELoibMwAWsexRiPO+CQ7Q3lw7ee3vrpAhMdFcogtWwY5bE4+1b3flh1CjOH5AyqZVf/x X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:deba:378d:2d3a:2641]) (user=irogers job=sendgmr) by 2002:a05:6902:10c1:b0:de5:3003:4b7d with SMTP id w1-20020a05690210c100b00de530034b7dmr304699ybu.0.1714685716802; Thu, 02 May 2024 14:35:16 -0700 (PDT) Date: Thu, 2 May 2024 14:35:04 -0700 In-Reply-To: <20240502213507.2339733-1-irogers@google.com> Message-Id: <20240502213507.2339733-4-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 3/6] perf test pmu: Refactor format test and exposed test APIs 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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In tests/pmu.c, make a common utility that creates a PMU in mkdtemp directory and uses regular PMU parsing logic to load that PMU. Formats must still be eagerly loaded as by default the PMU code assumes devices are going to be in sysfs. In util/pmu.[ch], hide perf_pmu__format_parse but add the eager argument to perf_pmu__lookup called by perf_pmus__add_test_pmu. Later patches will eagerly load other non-sysfs files when eager loading is enabled. In tests/pmu.c, rather than manually constructing a list of term arguments, just use the term parsing code from a string. Add more comments and debug logging. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang Tested-by: Thomas Richter --- tools/perf/tests/pmu.c | 319 ++++++++++++++++----------------- tools/perf/util/parse-events.c | 2 +- tools/perf/util/parse-events.h | 2 +- tools/perf/util/pmu.c | 11 +- tools/perf/util/pmu.h | 4 +- tools/perf/util/pmus.c | 16 +- tools/perf/util/pmus.h | 2 + 7 files changed, 177 insertions(+), 179 deletions(-) diff --git a/tools/perf/tests/pmu.c b/tools/perf/tests/pmu.c index 8f18127d876a..424ebdb0f09d 100644 --- a/tools/perf/tests/pmu.c +++ b/tools/perf/tests/pmu.c @@ -2,203 +2,186 @@ #include "parse-events.h" #include "pmu.h" #include "tests.h" +#include "debug.h" #include #include #include -#include -#include -#include - -/* Simulated format definitions. */ -static struct test_format { - const char *name; - const char *value; -} test_formats[] =3D { - { "krava01", "config:0-1,62-63\n", }, - { "krava02", "config:10-17\n", }, - { "krava03", "config:5\n", }, - { "krava11", "config1:0,2,4,6,8,20-28\n", }, - { "krava12", "config1:63\n", }, - { "krava13", "config1:45-47\n", }, - { "krava21", "config2:0-3,10-13,20-23,30-33,40-43,50-53,60-63\n", }, - { "krava22", "config2:8,18,48,58\n", }, - { "krava23", "config2:28-29,38\n", }, -}; - -/* Simulated users input. */ -static struct parse_events_term test_terms[] =3D { - { - .config =3D "krava01", - .val.num =3D 15, - .type_val =3D PARSE_EVENTS__TERM_TYPE_NUM, - .type_term =3D PARSE_EVENTS__TERM_TYPE_USER, - }, - { - .config =3D "krava02", - .val.num =3D 170, - .type_val =3D PARSE_EVENTS__TERM_TYPE_NUM, - .type_term =3D PARSE_EVENTS__TERM_TYPE_USER, - }, - { - .config =3D "krava03", - .val.num =3D 1, - .type_val =3D PARSE_EVENTS__TERM_TYPE_NUM, - .type_term =3D PARSE_EVENTS__TERM_TYPE_USER, - }, - { - .config =3D "krava11", - .val.num =3D 27, - .type_val =3D PARSE_EVENTS__TERM_TYPE_NUM, - .type_term =3D PARSE_EVENTS__TERM_TYPE_USER, - }, - { - .config =3D "krava12", - .val.num =3D 1, - .type_val =3D PARSE_EVENTS__TERM_TYPE_NUM, - .type_term =3D PARSE_EVENTS__TERM_TYPE_USER, - }, - { - .config =3D "krava13", - .val.num =3D 2, - .type_val =3D PARSE_EVENTS__TERM_TYPE_NUM, - .type_term =3D PARSE_EVENTS__TERM_TYPE_USER, - }, - { - .config =3D "krava21", - .val.num =3D 119, - .type_val =3D PARSE_EVENTS__TERM_TYPE_NUM, - .type_term =3D PARSE_EVENTS__TERM_TYPE_USER, - }, - { - .config =3D "krava22", - .val.num =3D 11, - .type_val =3D PARSE_EVENTS__TERM_TYPE_NUM, - .type_term =3D PARSE_EVENTS__TERM_TYPE_USER, - }, - { - .config =3D "krava23", - .val.num =3D 2, - .type_val =3D PARSE_EVENTS__TERM_TYPE_NUM, - .type_term =3D PARSE_EVENTS__TERM_TYPE_USER, - }, -}; - -/* - * Prepare format directory data, exported by kernel - * at /sys/bus/event_source/devices//format. - */ -static char *test_format_dir_get(char *dir, size_t sz) -{ - unsigned int i; - - snprintf(dir, sz, "/tmp/perf-pmu-test-format-XXXXXX"); - if (!mkdtemp(dir)) - return NULL; - - for (i =3D 0; i < ARRAY_SIZE(test_formats); i++) { - char name[PATH_MAX]; - struct test_format *format =3D &test_formats[i]; - FILE *file; - - scnprintf(name, PATH_MAX, "%s/%s", dir, format->name); - - file =3D fopen(name, "w"); - if (!file) - return NULL; - - if (1 !=3D fwrite(format->value, strlen(format->value), 1, file)) - break; +#include +#include +#include =20 - fclose(file); - } - - return dir; -} +/* Fake PMUs created in temp directory. */ +static LIST_HEAD(test_pmus); =20 -/* Cleanup format directory. */ -static int test_format_dir_put(char *dir) +/* Cleanup test PMU directory. */ +static int test_pmu_put(const char *dir, struct perf_pmu *pmu) { char buf[PATH_MAX + 20]; + int ret; =20 - snprintf(buf, sizeof(buf), "rm -f %s/*\n", dir); - if (system(buf)) - return -1; + if (scnprintf(buf, sizeof(buf), "rm -fr %s", dir) < 0) { + pr_err("Failure to set up buffer for \"%s\"\n", dir); + return -EINVAL; + } + ret =3D system(buf); + if (ret) + pr_err("Failure to \"%s\"\n", buf); =20 - snprintf(buf, sizeof(buf), "rmdir %s\n", dir); - return system(buf); + list_del(&pmu->list); + perf_pmu__delete(pmu); + return ret; } =20 -static void add_test_terms(struct parse_events_terms *terms) +/* + * Prepare test PMU directory data, normally exported by kernel at + * /sys/bus/event_source/devices//. Give as input a buffer to hold th= e file + * path, the result is PMU loaded using that directory. + */ +static struct perf_pmu *test_pmu_get(char *dir, size_t sz) { - unsigned int i; + /* Simulated format definitions. */ + const struct test_format { + const char *name; + const char *value; + } test_formats[] =3D { + { "krava01", "config:0-1,62-63\n", }, + { "krava02", "config:10-17\n", }, + { "krava03", "config:5\n", }, + { "krava11", "config1:0,2,4,6,8,20-28\n", }, + { "krava12", "config1:63\n", }, + { "krava13", "config1:45-47\n", }, + { "krava21", "config2:0-3,10-13,20-23,30-33,40-43,50-53,60-63\n", }, + { "krava22", "config2:8,18,48,58\n", }, + { "krava23", "config2:28-29,38\n", }, + }; + char name[PATH_MAX]; + int dirfd, file; + struct perf_pmu *pmu =3D NULL; + ssize_t len; + + /* Create equivalent of sysfs mount point. */ + scnprintf(dir, sz, "/tmp/perf-pmu-test-XXXXXX"); + if (!mkdtemp(dir)) { + pr_err("mkdtemp failed\n"); + dir[0] =3D '\0'; + return NULL; + } + dirfd =3D open(dir, O_DIRECTORY); + if (dirfd < 0) { + pr_err("Failed to open test directory \"%s\"\n", dir); + goto err_out; + } =20 - for (i =3D 0; i < ARRAY_SIZE(test_terms); i++) { - struct parse_events_term *clone; + /* Create the test PMU directory and give it a perf_event_attr type numbe= r. */ + if (mkdirat(dirfd, "perf-pmu-test", 0755) < 0) { + pr_err("Failed to mkdir PMU directory\n"); + goto err_out; + } + file =3D openat(dirfd, "perf-pmu-test/type", O_WRONLY | O_CREAT, 0600); + if (!file) { + pr_err("Failed to open for writing file \"type\"\n"); + goto err_out; + } + len =3D strlen("9999"); + if (write(file, "9999\n", len) < len) { + close(file); + pr_err("Failed to write to 'type' file\n"); + goto err_out; + } + close(file); =20 - parse_events_term__clone(&clone, &test_terms[i]); - list_add_tail(&clone->list, &terms->terms); + /* Create format directory and files. */ + if (mkdirat(dirfd, "perf-pmu-test/format", 0755) < 0) { + pr_err("Failed to mkdir PMU format directory\n)"); + goto err_out; } + for (size_t i =3D 0; i < ARRAY_SIZE(test_formats); i++) { + const struct test_format *format =3D &test_formats[i]; + + if (scnprintf(name, PATH_MAX, "perf-pmu-test/format/%s", format->name) <= 0) { + pr_err("Failure to set up path for \"%s\"\n", format->name); + goto err_out; + } + file =3D openat(dirfd, name, O_WRONLY | O_CREAT, 0600); + if (!file) { + pr_err("Failed to open for writing file \"%s\"\n", name); + goto err_out; + } + + if (write(file, format->value, strlen(format->value)) < 0) { + pr_err("Failed to write to file \"%s\"\n", name); + close(file); + goto err_out; + } + close(file); + } + + /* Make the PMU reading the files created above. */ + pmu =3D perf_pmus__add_test_pmu(dirfd, "perf-pmu-test"); + if (!pmu) + pr_err("Test PMU creation failed\n"); + +err_out: + if (!pmu) + test_pmu_put(dir, pmu); + if (dirfd >=3D 0) + close(dirfd); + return pmu; } =20 -static int test__pmu(struct test_suite *test __maybe_unused, int subtest _= _maybe_unused) +static int test__pmu_format(struct test_suite *test __maybe_unused, int su= btest __maybe_unused) { char dir[PATH_MAX]; - char *format; - struct parse_events_terms terms; struct perf_event_attr attr; - struct perf_pmu *pmu; - int fd; - int ret; + struct parse_events_terms terms; + int ret =3D TEST_FAIL; + struct perf_pmu *pmu =3D test_pmu_get(dir, sizeof(dir)); =20 - parse_events_terms__init(&terms); - add_test_terms(&terms); - pmu =3D zalloc(sizeof(*pmu)); - if (!pmu) { - parse_events_terms__exit(&terms); - return -ENOMEM; - } + if (!pmu) + return TEST_FAIL; =20 - INIT_LIST_HEAD(&pmu->format); - INIT_LIST_HEAD(&pmu->aliases); - INIT_LIST_HEAD(&pmu->caps); - format =3D test_format_dir_get(dir, sizeof(dir)); - if (!format) { - free(pmu); - parse_events_terms__exit(&terms); - return -EINVAL; + parse_events_terms__init(&terms); + if (parse_events_terms(&terms, + "krava01=3D15,krava02=3D170,krava03=3D1,krava11=3D27,krava12=3D1," + "krava13=3D2,krava21=3D119,krava22=3D11,krava23=3D2", + NULL)) { + pr_err("Term parsing failed\n"); + goto err_out; } =20 memset(&attr, 0, sizeof(attr)); - - fd =3D open(format, O_DIRECTORY); - if (fd < 0) { - ret =3D fd; - goto out; + ret =3D perf_pmu__config_terms(pmu, &attr, &terms, /*zero=3D*/false, /*er= r=3D*/NULL); + if (ret) { + pr_err("perf_pmu__config_terms failed"); + goto err_out; } =20 - pmu->name =3D strdup("perf-pmu-test"); - ret =3D perf_pmu__format_parse(pmu, fd, /*eager_load=3D*/true); - if (ret) - goto out; + if (attr.config !=3D 0xc00000000002a823) { + pr_err("Unexpected config value %llx\n", attr.config); + goto err_out; + } + if (attr.config1 !=3D 0x8000400000000145) { + pr_err("Unexpected config1 value %llx\n", attr.config1); + goto err_out; + } + if (attr.config2 !=3D 0x0400000020041d07) { + pr_err("Unexpected config2 value %llx\n", attr.config2); + goto err_out; + } =20 - ret =3D perf_pmu__config_terms(pmu, &attr, &terms, /*zero=3D*/false, /*er= r=3D*/NULL); - if (ret) - goto out; - - ret =3D -EINVAL; - if (attr.config !=3D 0xc00000000002a823) - goto out; - if (attr.config1 !=3D 0x8000400000000145) - goto out; - if (attr.config2 !=3D 0x0400000020041d07) - goto out; - - ret =3D 0; -out: - test_format_dir_put(format); - perf_pmu__delete(pmu); + ret =3D TEST_OK; +err_out: parse_events_terms__exit(&terms); + test_pmu_put(dir, pmu); return ret; } =20 -DEFINE_SUITE("Parse perf pmu format", pmu); +static struct test_case tests__pmu[] =3D { + TEST_CASE("Parsing with PMU format directory", pmu_format), + { .name =3D NULL, } +}; + +struct test_suite suite__pmu =3D { + .desc =3D "Sysfs PMU tests", + .test_cases =3D tests__pmu, +}; diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 0f308b4db2b9..2b9ede311c31 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -2585,7 +2585,7 @@ int parse_events_term__term(struct parse_events_term = **term, } =20 int parse_events_term__clone(struct parse_events_term **new, - struct parse_events_term *term) + const struct parse_events_term *term) { char *str; struct parse_events_term temp =3D *term; diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index 5695308efab9..e7ac1f13376d 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -178,7 +178,7 @@ int parse_events_term__term(struct parse_events_term **= term, enum parse_events__term_type term_rhs, void *loc_term, void *loc_val); int parse_events_term__clone(struct parse_events_term **new, - struct parse_events_term *term); + const struct parse_events_term *term); void parse_events_term__delete(struct parse_events_term *term); =20 void parse_events_terms__delete(struct parse_events_terms *terms); diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 74dd5bd49d9a..fbbc535ed93f 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -182,7 +182,7 @@ static void perf_pmu_format__load(const struct perf_pmu= *pmu, struct perf_pmu_fo * Parse & process all the sysfs attributes located under * the directory specified in 'dir' parameter. */ -int perf_pmu__format_parse(struct perf_pmu *pmu, int dirfd, bool eager_loa= d) +static int perf_pmu__format_parse(struct perf_pmu *pmu, int dirfd, bool ea= ger_load) { struct dirent *evt_ent; DIR *format_dir; @@ -232,7 +232,7 @@ int perf_pmu__format_parse(struct perf_pmu *pmu, int di= rfd, bool eager_load) * located at: * /sys/bus/event_source/devices//format as sysfs group attributes. */ -static int pmu_format(struct perf_pmu *pmu, int dirfd, const char *name) +static int pmu_format(struct perf_pmu *pmu, int dirfd, const char *name, b= ool eager_load) { int fd; =20 @@ -241,7 +241,7 @@ static int pmu_format(struct perf_pmu *pmu, int dirfd, = const char *name) return 0; =20 /* it'll close the fd */ - if (perf_pmu__format_parse(pmu, fd, /*eager_load=3D*/false)) + if (perf_pmu__format_parse(pmu, fd, eager_load)) return -1; =20 return 0; @@ -994,7 +994,8 @@ perf_pmu__arch_init(struct perf_pmu *pmu) pmu->mem_events =3D perf_mem_events; } =20 -struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const= char *name) +struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const= char *name, + bool eager_load) { struct perf_pmu *pmu; __u32 type; @@ -1023,7 +1024,7 @@ struct perf_pmu *perf_pmu__lookup(struct list_head *p= mus, int dirfd, const char * type value and format definitions. Load both right * now. */ - if (pmu_format(pmu, dirfd, name)) + if (pmu_format(pmu, dirfd, name, eager_load)) goto err; =20 pmu->is_core =3D is_pmu_core(name); diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h index 93d03bd3ecbe..561716aa2b25 100644 --- a/tools/perf/util/pmu.h +++ b/tools/perf/util/pmu.h @@ -214,7 +214,6 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct = parse_events_terms *head_ struct parse_events_error *err); int perf_pmu__find_event(struct perf_pmu *pmu, const char *event, void *st= ate, pmu_event_callback cb); =20 -int perf_pmu__format_parse(struct perf_pmu *pmu, int dirfd, bool eager_loa= d); void perf_pmu_format__set_value(void *format, int config, unsigned long *b= its); bool perf_pmu__has_format(const struct perf_pmu *pmu, const char *name); int perf_pmu__for_each_format(struct perf_pmu *pmu, void *state, pmu_forma= t_callback cb); @@ -272,7 +271,8 @@ int perf_pmu__pathname_scnprintf(char *buf, size_t size, int perf_pmu__event_source_devices_fd(void); int perf_pmu__pathname_fd(int dirfd, const char *pmu_name, const char *fil= ename, int flags); =20 -struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const= char *lookup_name); +struct perf_pmu *perf_pmu__lookup(struct list_head *pmus, int dirfd, const= char *lookup_name, + bool eager_load); struct perf_pmu *perf_pmu__create_placeholder_core_pmu(struct list_head *c= ore_pmus); void perf_pmu__delete(struct perf_pmu *pmu); struct perf_pmu *perf_pmus__find_core_pmu(void); diff --git a/tools/perf/util/pmus.c b/tools/perf/util/pmus.c index 2fd369e45832..b9b4c5eb5002 100644 --- a/tools/perf/util/pmus.c +++ b/tools/perf/util/pmus.c @@ -124,7 +124,8 @@ struct perf_pmu *perf_pmus__find(const char *name) return NULL; =20 dirfd =3D perf_pmu__event_source_devices_fd(); - pmu =3D perf_pmu__lookup(core_pmu ? &core_pmus : &other_pmus, dirfd, name= ); + pmu =3D perf_pmu__lookup(core_pmu ? &core_pmus : &other_pmus, dirfd, name, + /*eager_load=3D*/false); close(dirfd); =20 if (!pmu) { @@ -159,7 +160,8 @@ static struct perf_pmu *perf_pmu__find2(int dirfd, cons= t char *name) if (core_pmu && read_sysfs_core_pmus) return NULL; =20 - return perf_pmu__lookup(core_pmu ? &core_pmus : &other_pmus, dirfd, name); + return perf_pmu__lookup(core_pmu ? &core_pmus : &other_pmus, dirfd, name, + /*eager_load=3D*/false); } =20 static int pmus_cmp(void *priv __maybe_unused, @@ -696,3 +698,13 @@ struct perf_pmu *perf_pmus__find_core_pmu(void) { return perf_pmus__scan_core(NULL); } + +struct perf_pmu *perf_pmus__add_test_pmu(int test_sysfs_dirfd, const char = *name) +{ + /* + * Some PMU functions read from the sysfs mount point, so care is + * needed, hence passing the eager_load flag to load things like the + * format files. + */ + return perf_pmu__lookup(&other_pmus, test_sysfs_dirfd, name, /*eager_load= =3D*/true); +} diff --git a/tools/perf/util/pmus.h b/tools/perf/util/pmus.h index eec599d8aebd..9d4ded80b8e9 100644 --- a/tools/perf/util/pmus.h +++ b/tools/perf/util/pmus.h @@ -24,4 +24,6 @@ int perf_pmus__num_core_pmus(void); bool perf_pmus__supports_extended_type(void); char *perf_pmus__default_pmu_name(void); =20 +struct perf_pmu *perf_pmus__add_test_pmu(int test_sysfs_dirfd, const char = *name); + #endif /* __PMUS_H */ --=20 2.45.0.rc1.225.g2a3ae87e7f-goog From nobody Wed Dec 17 20:44:03 2025 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 2C2B5181BB5 for ; Thu, 2 May 2024 21:35:19 +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=1714685721; cv=none; b=h6w9OR1KcBLkRzVJVYT64WeKWKHvHhUgnhY21H3rXbBfht7pKiMq0wchqKIeyDBI3yLzSIlw1/+UWUTwthTcmqQrBwqdPK9iwUijyMz+fJoUFPFEHLWY83yu6osnowgfXsWly5Pa6j44LlRCKZ3mTpOnQDfNwEnBeqfy5iw22Ag= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714685721; c=relaxed/simple; bh=X1QsoG0vLLHMD6bYIGg+5REMFKVWWB6D6zVlb4tr+OU=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=XMFj3c6i0ja8adUlbDm8d0S2vEgXnru0+X1j3MxbFbVOb73AJGoyV9B1qJySLlnmUS73xk598cs2VmrZVfd78yheDqfx0i/77KIGuv50EA+PynMvYVYbMVHo02sEEBqFV9gdXgyI3rex8iZp9opBLwpc6FDCHl72y9ucq+/h+qU= 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=s9TeswoT; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="s9TeswoT" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-ddaf2f115f2so13163175276.3 for ; Thu, 02 May 2024 14:35:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714685719; x=1715290519; 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=ZcJ4dsH8uWA+9WkKKoxf0bqU8/vdoA/sy+ZzRXrUB+k=; b=s9TeswoTIF+tYNSr+NLvoqeNSQTBjUTnG3/G8QNBB0z+vvKBWJkTFLvT6+fhA8qtvb HAyldA2mSAPNjYSFZ6T+J2qLPIB3lvWsG0IlGKmnqYcF6ES19xdLGje0N/Z60K6ChQdS BWc1/b/GL0BUwMUhIzgmWdzjE+/AKme7fQVRmQWrCmeJIO9+GsjUlGqddBJalb94SsSc 4sGamKvMJBi2C1PbN0Kdrm0baywbz4eQR7VuP3+8DEzBqxsQzSSV+0WwxeLcIIB1hf41 mE17a9dCebWQtrSGq6YHDle4QkFNjZscdJU5xQXquqntvm2a5ba+/sT3vZZuZF4e0S7r ZUcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714685719; x=1715290519; 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=ZcJ4dsH8uWA+9WkKKoxf0bqU8/vdoA/sy+ZzRXrUB+k=; b=vR8+WaNqhP0veSC07AVJKTnIDmUWFrVhzuRrE/Dk8rq4J+gdg82ErZAgmcaSyx27Tk 43CRE1wNP9izXrX68LA1roLiRN3+AGz+jalA1PiJ5kUnRoGhpraEm3fWLxXixPezswYW OOPwJqzj8MNNlWOsRTZoXw8/L3KJqS27SMFQnbvH5RDK68/69SkuyRXHp8TqjxNCPdYN /6V+TCTdOo3cHLeavUicYU6f6rFH4qatsNE8STgst8hl3FwquQVTjCtUo6J7xG6VS3KY Sxkh7rTy0mgrWxH7LMrQ9yTmZ7DaszbSVT4STE4SOAMtnyXYW+/WO19nmWWygDELRPAA j1MA== X-Forwarded-Encrypted: i=1; AJvYcCV2W2t7GJxOa02JMRY++fn3FQtvjywP5aTCAfnNEhSnW9sQ/TEiBYV3jeti5MvLysgudE7FhNEebOELXCGArVNJ74V8fUk5xHHwT/Fs X-Gm-Message-State: AOJu0YxBi/yhWJXSek8j5FxyPakD58iWUZAAQJo1S7pGFjQKEnaS9Vif 7qyNJ2ZROOycZkXxeDMhPtPlFMd4cnvseFUKWAnzdJdfIqSfd3iGovG38akL4PHPOmxEuwlX793 RbM4ZaA== X-Google-Smtp-Source: AGHT+IEIkMwDF/cN1AEdH7g/G9QzA/amSuozpCAl+dsFpzt4DY7+TlBgmiW83jmEoBeSdl1e7SJTkhQjgFqA X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:deba:378d:2d3a:2641]) (user=irogers job=sendgmr) by 2002:a05:6902:1082:b0:dce:5218:c89b with SMTP id v2-20020a056902108200b00dce5218c89bmr157125ybu.5.1714685719171; Thu, 02 May 2024 14:35:19 -0700 (PDT) Date: Thu, 2 May 2024 14:35:05 -0700 In-Reply-To: <20240502213507.2339733-1-irogers@google.com> Message-Id: <20240502213507.2339733-5-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 4/6] perf test pmu: Add an eagerly loaded event test 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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Allow events/aliases to be eagerly loaded for a PMU. Factor out the pmu_aliases_parse to allow this. Parse a test event and check it configures the attribute as expected. There is overlap with the parse-events tests, but this test is done with a PMU created in a temp directory and doesn't rely on PMUs in sysfs. Signed-off-by: Ian Rogers Reviewed-by: Kan Liang Tested-by: Thomas Richter --- tools/perf/tests/pmu.c | 76 ++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/pmu.c | 69 ++++++++++++++++++++++++++------------ 2 files changed, 124 insertions(+), 21 deletions(-) diff --git a/tools/perf/tests/pmu.c b/tools/perf/tests/pmu.c index 424ebdb0f09d..071cfc51b52c 100644 --- a/tools/perf/tests/pmu.c +++ b/tools/perf/tests/pmu.c @@ -1,4 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 +#include "evlist.h" +#include "evsel.h" #include "parse-events.h" #include "pmu.h" #include "tests.h" @@ -54,6 +56,9 @@ static struct perf_pmu *test_pmu_get(char *dir, size_t sz) { "krava22", "config2:8,18,48,58\n", }, { "krava23", "config2:28-29,38\n", }, }; + const char *test_event =3D "krava01=3D15,krava02=3D170,krava03=3D1,krava1= 1=3D27,krava12=3D1," + "krava13=3D2,krava21=3D119,krava22=3D11,krava23=3D2\n"; + char name[PATH_MAX]; int dirfd, file; struct perf_pmu *pmu =3D NULL; @@ -116,6 +121,24 @@ static struct perf_pmu *test_pmu_get(char *dir, size_t= sz) close(file); } =20 + /* Create test event. */ + if (mkdirat(dirfd, "perf-pmu-test/events", 0755) < 0) { + pr_err("Failed to mkdir PMU events directory\n"); + goto err_out; + } + file =3D openat(dirfd, "perf-pmu-test/events/test-event", O_WRONLY | O_CR= EAT, 0600); + if (!file) { + pr_err("Failed to open for writing file \"type\"\n"); + goto err_out; + } + len =3D strlen(test_event); + if (write(file, test_event, len) < len) { + close(file); + pr_err("Failed to write to 'test-event' file\n"); + goto err_out; + } + close(file); + /* Make the PMU reading the files created above. */ pmu =3D perf_pmus__add_test_pmu(dirfd, "perf-pmu-test"); if (!pmu) @@ -176,8 +199,61 @@ static int test__pmu_format(struct test_suite *test __= maybe_unused, int subtest return ret; } =20 +static int test__pmu_events(struct test_suite *test __maybe_unused, int su= btest __maybe_unused) +{ + char dir[PATH_MAX]; + struct parse_events_error err; + struct evlist *evlist; + struct evsel *evsel; + struct perf_event_attr *attr; + int ret =3D TEST_FAIL; + struct perf_pmu *pmu =3D test_pmu_get(dir, sizeof(dir)); + const char *event =3D "perf-pmu-test/test-event/"; + + + if (!pmu) + return TEST_FAIL; + + evlist =3D evlist__new(); + if (evlist =3D=3D NULL) { + pr_err("Failed allocation"); + goto err_out; + } + parse_events_error__init(&err); + ret =3D parse_events(evlist, event, &err); + if (ret) { + pr_debug("failed to parse event '%s', err %d\n", event, ret); + parse_events_error__print(&err, event); + if (parse_events_error__contains(&err, "can't access trace events")) + ret =3D TEST_SKIP; + goto err_out; + } + evsel =3D evlist__first(evlist); + attr =3D &evsel->core.attr; + if (attr->config !=3D 0xc00000000002a823) { + pr_err("Unexpected config value %llx\n", attr->config); + goto err_out; + } + if (attr->config1 !=3D 0x8000400000000145) { + pr_err("Unexpected config1 value %llx\n", attr->config1); + goto err_out; + } + if (attr->config2 !=3D 0x0400000020041d07) { + pr_err("Unexpected config2 value %llx\n", attr->config2); + goto err_out; + } + + ret =3D TEST_OK; +err_out: + parse_events_error__exit(&err); + evlist__delete(evlist); + test_pmu_put(dir, pmu); + return ret; +} + static struct test_case tests__pmu[] =3D { TEST_CASE("Parsing with PMU format directory", pmu_format), + TEST_CASE("Parsing with PMU event", pmu_events), { .name =3D NULL, } }; =20 diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index fbbc535ed93f..7849be4bfea1 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c @@ -597,33 +597,18 @@ static inline bool pmu_alias_info_file(const char *na= me) * Reading the pmu event aliases definition, which should be located at: * /sys/bus/event_source/devices//events as sysfs group attributes. */ -static int pmu_aliases_parse(struct perf_pmu *pmu) +static int __pmu_aliases_parse(struct perf_pmu *pmu, int events_dir_fd) { - char path[PATH_MAX]; struct dirent *evt_ent; DIR *event_dir; - size_t len; - int fd, dir_fd; =20 - len =3D perf_pmu__event_source_devices_scnprintf(path, sizeof(path)); - if (!len) - return 0; - scnprintf(path + len, sizeof(path) - len, "%s/events", pmu->name); - - dir_fd =3D open(path, O_DIRECTORY); - if (dir_fd =3D=3D -1) { - pmu->sysfs_aliases_loaded =3D true; - return 0; - } - - event_dir =3D fdopendir(dir_fd); - if (!event_dir){ - close (dir_fd); + event_dir =3D fdopendir(events_dir_fd); + if (!event_dir) return -EINVAL; - } =20 while ((evt_ent =3D readdir(event_dir))) { char *name =3D evt_ent->d_name; + int fd; FILE *file; =20 if (!strcmp(name, ".") || !strcmp(name, "..")) @@ -635,7 +620,7 @@ static int pmu_aliases_parse(struct perf_pmu *pmu) if (pmu_alias_info_file(name)) continue; =20 - fd =3D openat(dir_fd, name, O_RDONLY); + fd =3D openat(events_dir_fd, name, O_RDONLY); if (fd =3D=3D -1) { pr_debug("Cannot open %s\n", name); continue; @@ -653,11 +638,50 @@ static int pmu_aliases_parse(struct perf_pmu *pmu) } =20 closedir(event_dir); - close (dir_fd); pmu->sysfs_aliases_loaded =3D true; return 0; } =20 +static int pmu_aliases_parse(struct perf_pmu *pmu) +{ + char path[PATH_MAX]; + size_t len; + int events_dir_fd, ret; + + if (pmu->sysfs_aliases_loaded) + return 0; + + len =3D perf_pmu__event_source_devices_scnprintf(path, sizeof(path)); + if (!len) + return 0; + scnprintf(path + len, sizeof(path) - len, "%s/events", pmu->name); + + events_dir_fd =3D open(path, O_DIRECTORY); + if (events_dir_fd =3D=3D -1) { + pmu->sysfs_aliases_loaded =3D true; + return 0; + } + ret =3D __pmu_aliases_parse(pmu, events_dir_fd); + close(events_dir_fd); + return ret; +} + +static int pmu_aliases_parse_eager(struct perf_pmu *pmu, int sysfs_fd) +{ + char path[FILENAME_MAX + 7]; + int ret, events_dir_fd; + + scnprintf(path, sizeof(path), "%s/events", pmu->name); + events_dir_fd =3D openat(sysfs_fd, path, O_DIRECTORY, 0); + if (events_dir_fd =3D=3D -1) { + pmu->sysfs_aliases_loaded =3D true; + return 0; + } + ret =3D __pmu_aliases_parse(pmu, events_dir_fd); + close(events_dir_fd); + return ret; +} + static int pmu_alias_terms(struct perf_pmu_alias *alias, int err_loc, stru= ct list_head *terms) { struct parse_events_term *term, *cloned; @@ -1042,6 +1066,9 @@ struct perf_pmu *perf_pmu__lookup(struct list_head *p= mus, int dirfd, const char =20 perf_pmu__arch_init(pmu); =20 + if (eager_load) + pmu_aliases_parse_eager(pmu, dirfd); + return pmu; err: zfree(&pmu->name); --=20 2.45.0.rc1.225.g2a3ae87e7f-goog From nobody Wed Dec 17 20:44:03 2025 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="xl8Wz12R" 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-Google-Smtp-Source: AGHT+IE96253la+W5w82RGrU9iiMHjmCN4kCK9hxJ4G+nZztuN23VK1xyUEq3B6SHLIS30WBMQYFp2AOkzVP 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-Transfer-Encoding: quoted-printable 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 Tested-by: Thomas Richter --- 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 =20 /* 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; } =20 +static bool permitted_event_name(const char *name) +{ + bool has_lower =3D false, has_upper =3D false; + + for (size_t i =3D 0; i < strlen(name); i++) { + char c =3D name[i]; + + if (islower(c)) { + if (has_upper) + return false; + has_lower =3D true; + continue; + } + if (isupper(c)) { + if (has_lower) + return false; + has_upper =3D true; + continue; + } + if (!isdigit(c) && c !=3D '.' && c !=3D '_' && c !=3D '-') + 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 =3D sysfs__mountpoint(); + int ret =3D 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 =3D opendir(path); + if (!pmu_dir) { + pr_err("Error opening \"%s\"\n", path); + return TEST_FAIL; + } + while ((pmu_dent =3D 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 =3D opendir(path); + if (!event_dir) { + pr_debug("Skipping as no event directory \"%s\"\n", path); + continue; + } + while ((event_dent =3D readdir(event_dir))) { + const char *event_name =3D 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 =3D TEST_FAIL; + } + } + closedir(event_dir); + } + closedir(pmu_dir); + return ret; +} + static struct test_case tests__pmu[] =3D { 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 =3D NULL, } }; =20 --=20 2.45.0.rc1.225.g2a3ae87e7f-goog From nobody Wed Dec 17 20:44:03 2025 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 EF3691C65E2 for ; Thu, 2 May 2024 21:35:24 +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=1714685726; cv=none; b=KfhdODPnIxCM+ucT1FtlDImFRBs4++huy9lJ9mmnIaoq369H6QjbtlwKlk85pisknA25Iq4rGtGTReb7R04Pn0qdTp9ieT0GQbvfRUOj8HW00J/pl8Mq6kYx3bC/5g6GpA7sM/RxkIOGvwNNlk70uCFzEDQ4hBsdos/Qo7oUnCs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714685726; c=relaxed/simple; bh=Pei9FjfxNCt9/le6x5BPnnFpH/hEQXyCatDiI/W1Bzc=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=WQ5kiz1ehbrSfzaExhjzr4MlW4TLTjixIFFtgwBeRuHL4bFn7bmN4vGFiO0+LG8OSEWnyRbXH9c1086EtKwbmJwgd9GmrdRrV19USG0P97UhTErxF8qmLYT4wRXNx5WjkDG3vwWoPqChb2uZLqNNS8Yr7YcJuy9c4T4Rw/s0m/4= 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=a7GV7zUd; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="a7GV7zUd" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc647f65573so19523273276.2 for ; Thu, 02 May 2024 14:35:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714685724; x=1715290524; 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=SoTICCWwv6tX/HbgMsdPi7+zO/SiphKA5G7fH/pnoRM=; b=a7GV7zUdbysTXtPZUhGjyr2mndHosQOMsiQGmscNGvxZ1ea8pBf58mpzxK4f+Cz+Gx ChgTfnLqHyDDoeq1RHZiAWPhMvZ71VFa8I8k8iWIk8FZT9qfqFqDP829vr2aZvSuy88d MUhnD34hOFInA7JrlkUamK4wDjskEvChDTNx71mm0nF0nb3752jQzEmSMZ5k6+P6Hxxw YxuzNpLhGyj87ZpaZrAHzsbTE1vU7ubG6Lk9IdzGnAkDiSFAKvrwvKGpBAc2+N5P2skQ ghoEe05E8ChlMjuUZfrEHjVb+OreW4gL6bigZj1KEwUuwJicPd8umRHErFSKXe1mcDrk GkZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714685724; x=1715290524; 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=SoTICCWwv6tX/HbgMsdPi7+zO/SiphKA5G7fH/pnoRM=; b=miwluamJbD9vVtoVbwysZe5zcqjY0pXLRNFd81frfG2K3fR/OnC1aWjhjbI2zyG2c/ GqTDpjIGzu3PsU0ywpKdPp9lkh8Bu4D+cccbr3/TLwSqrTQeaAhD5aMU3SoFXpPOsS9+ rZeQeNumrujn6gWde0ThM0uqlsjlA7CEwR4TanNgSefe3a8zvxeOYttNh0FresH65MI+ 13fwzdH1ITVEDA0KNOyoM5YBPOMkZr86ENqafi5Ogbn4K7BiNsAZCGUb+DDTdk7gMdXE PChk3/WrOzx1MsykkU0vf3Iz9tzEBt9V4bETAlcjJmGSVshqxH4V4fI5I0OY1wRFXXDQ HopQ== X-Forwarded-Encrypted: i=1; AJvYcCVBUebtMEN0nUvuKMTPLI5mLj1uzn/nfXXqYJrsHTC+skQqXfFmSBbAa52jB8DABTUHmOFdfFWpBw9chTeiDuZyWs+pMJObi3mpEMkI X-Gm-Message-State: AOJu0Yw3FfZOzP4ZnN0Lxyy3M4UDqSEoRBYFsPB8M9vJyq9hD8zWtkx+ We6bVniEElupOZoZoJcMo+677JZ1vK1nIYaPxyUNJ+biHfIhv3jwgo7dA28RhPVIRa8BvFBPNTD jFqfysQ== X-Google-Smtp-Source: AGHT+IFPDyIcGTsj+ZN2uF59ksuwxGJWvgfUhi/mm/njKwzy6Ue/D+z+knrRVjZ38wSxWjQwWJnDIX/IgZW3 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:deba:378d:2d3a:2641]) (user=irogers job=sendgmr) by 2002:a05:6902:1004:b0:de4:7be7:1c2d with SMTP id w4-20020a056902100400b00de47be71c2dmr313438ybt.11.1714685723816; Thu, 02 May 2024 14:35:23 -0700 (PDT) Date: Thu, 2 May 2024 14:35:07 -0700 In-Reply-To: <20240502213507.2339733-1-irogers@google.com> Message-Id: <20240502213507.2339733-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: <20240502213507.2339733-1-irogers@google.com> X-Mailer: git-send-email 2.45.0.rc1.225.g2a3ae87e7f-goog Subject: [PATCH v5 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-Transfer-Encoding: quoted-printable 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 Reviewed-by: Kan Liang Tested-by: Thomas Richter --- 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..b3b072feef02 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(str= uct perf_pmu *pmu, { struct perf_pmu_alias *alias; =20 - 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]; =20 + /* + * Test if alias/event 'name' exists in the PMU's sysfs/events + * directory. If not skip parsing the sysfs aliases. Sysfs 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 =3D 7, n =3D 7 + strlen(name); i < n; i++) + event_file_name[i] =3D tolower(event_file_name[i]); + + has_sysfs_event =3D perf_pmu__file_exists(pmu, event_file_name); + if (!has_sysfs_event) { + for (size_t i =3D 7, n =3D 7 + strlen(name); i < n; i++) + event_file_name[i] =3D toupper(event_file_name[i]); + + has_sysfs_event =3D 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; =20 - if (!pmu->sysfs_aliases_loaded) - pmu_aliases_parse(pmu); - + pmu_aliases_parse(pmu); nr =3D pmu->sysfs_aliases; =20 if (pmu->cpu_aliases_added) @@ -1778,6 +1797,7 @@ int perf_pmu__for_each_event(struct perf_pmu *pmu, bo= ol skip_duplicate_pmus, struct strbuf sb; =20 strbuf_init(&sb, /*hint=3D*/ 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_pm= u *pmu, u64 config) if (!pmu) return NULL; =20 + pmu_aliases_parse(pmu); pmu_add_cpu_aliases(pmu); list_for_each_entry(event, &pmu->aliases, list) { struct perf_event_attr attr =3D {.config =3D 0,}; --=20 2.45.0.rc1.225.g2a3ae87e7f-goog