From nobody Wed Dec 17 23:14:05 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 7E9C71B966 for ; Thu, 2 May 2024 04:01:34 +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=1714622495; cv=none; b=S35hNcAkrTo2F3+fIZkPUMkG7VdEDgCYIkKVLA8fPZuUx4JFo/EFIJTMIb+P74BjbVpBXchwgmNUzZEtkhus4VA8bPml2XDSrZ2lqIqeGYPVceup97zjZrZq10+F+DtrrvwFLmJaHW7QsHE1TAPK6dsNA43P1KH75Rac875ZNvU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714622495; c=relaxed/simple; bh=01vMB1KAw5wjuORt+f71dP6s7wJwUTqpWCn3nJ5VDhk=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=AvuBmdwhpXpl+yoe75VhuMhP+5R8EYObtgEkt1HX71YGFEBVe+HhbVy48mGp3H+wF8W0pYvdIJfCJYU15IYEeuYaIslxPj1mp3spPaIsirvIBxvVIkPQUb0ietJ7b+TcStzwc2y/zR97V48Q1EZVXNiAP2+CZvnG/jiTFlr9LLE= 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=SKjMP7fS; 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="SKjMP7fS" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-de54ccab44aso15392310276.3 for ; Wed, 01 May 2024 21:01:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714622493; x=1715227293; 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=fTAc4mAl8zd/O4NoKom13X8oEiD4EoCVZF5Gt5A9RVY=; b=SKjMP7fS62qF2LO38WyzqKzIqL/CLrMrPLrMHRAi3kLYurekiYTQqajFCxCM0W6RCR mU7o8s2e4SixEv8/qCdV8Rjhtw3MKMJKAH3MXCXGJj/GLxeMOiFAzUu1p7Shi6kkmngy 0NswzalFaRaNlUqK3MPOM4CVqvvlJmzKnyJKdarWAgU8hsLiu8Kg8cNbTTcj1op4eTDt BhBJfawK+GJS8BTNEzM9Gtm0zhGwWLah4gYWe/aM3ZvpqNcGlciKDuNl9S6wzPT1GZXm ncvLTzMtPaimSqPqkvlvViQU0GJZ3L2kBkiu9geL88lqb5dZFrxCED6ViF2vRMvwj26c Cgjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714622493; x=1715227293; 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=fTAc4mAl8zd/O4NoKom13X8oEiD4EoCVZF5Gt5A9RVY=; b=ceUiGg+fkfpTpJfalKQP8dp5urtswBJfLwQzWyBq6WisEVtjmi97zlCqGl2X2UG1H9 hO242USq/uL4e/fXyF/1RjneM4DuM+aLmjepk13IuMWjf01R+Oukt4OhSQANDffSxZCd H5l+LqJCFkoimGs+7kGz+jtzbAc56sMdnoHEJ64EQN2qcrHsJuo+MzrqruPGTeQKwQOg k+vYOsyeqdqil/xx2s3fiQibqdxp2Cyrg1OOx19pCfAArlvrTWZ/sZGcl/++1D3ihN0f aUDPPDiZBOh1OiM29gidKN02WIvPV6+uNsAIzbwNuOoOWHDF6XQqfJ2+en9w/jF6xMhu CI4g== X-Forwarded-Encrypted: i=1; AJvYcCXxGAcvM61H724uCkvNMJFqecgWedSS5tAtiih3E6kLzhYc5o1QmzAE2/Hw+hDOKSq3Ts3kVIn3Hx0/baHsEwO6VPfH9eAj128DqoA8 X-Gm-Message-State: AOJu0YxRWlu5ClAbPlF8ZfF6XmNH0W2NZsgnkT888a5+3RrLHGD7gFc4 OdKl0xH3Oixt0gteOi0CERHIU16zK4CuAOPpk7osaf3cJLuPkOHolqr9M1AgOidnR2sAqfZdMcy Q1HEqSw== X-Google-Smtp-Source: AGHT+IHery9aso1o+6JwiNEaTVoNE485WqWMxBoHyyVYKWymEIvRiBj05j1BTb66Gp07jSFp+uVsFpUuj+Nn X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:53b9:bbda:1daa:17d3]) (user=irogers job=sendgmr) by 2002:a25:6806:0:b0:de4:5ec1:57af with SMTP id d6-20020a256806000000b00de45ec157afmr221754ybc.10.1714622493557; Wed, 01 May 2024 21:01:33 -0700 (PDT) Date: Wed, 1 May 2024 21:01:07 -0700 In-Reply-To: <20240502040112.2111157-1-irogers@google.com> Message-Id: <20240502040112.2111157-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: <20240502040112.2111157-1-irogers@google.com> X-Mailer: git-send-email 2.45.0.rc0.197.gbae5840b3b-goog Subject: [PATCH v4 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 --- 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.rc0.197.gbae5840b3b-goog From nobody Wed Dec 17 23:14:05 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 9B6801CD02 for ; Thu, 2 May 2024 04:01:36 +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=1714622498; cv=none; b=VD0qiyhC+BIbFOTHjOyCSx3DCjdEV/JgVbdsrXZmu+D+rRRG5yXrT8itOsB4XGFc/MLwWYiT/OF2v+a5vEsFA2sbPCqpH1qVuE1QycV6NovAgT+yRsF2fpIi0aravaFm3zvpJ9J42ZpHEQTR72QAZFxbFqE1SeifPK72m69LM+s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714622498; c=relaxed/simple; bh=RiQ3QH8Mevr7c85qmwqOFnFf8n7v8w8+896FGDtfLBk=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=MhuDEMjt/EuxkTAYafQnSqmM/wkI3JEDE0NcQqpJgRoahPhV03HHefV8eAiZjisa3mf1RiHQ3Ez8ScKGYjUCoAhhXRUKngVj9BNL6i8QYAHcM3Az2ROKBL4kwqzk42uWEUl60FbHLKO+3hF1Nyi7VH3aUjKTAKJr935m2V4zHEE= 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=eURM4FrN; 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="eURM4FrN" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-de8b66d59f7so609286276.0 for ; Wed, 01 May 2024 21:01:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714622496; x=1715227296; 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=YK4M7DhO5mIJIFP1QifUvK0BbiOYwnyjSGyXVIhqvoc=; b=eURM4FrNL+rV5M5jGHtUmXebIP7s+6tV09lWMhLoOkB5oUe95jtHIZhHMSF8rOC/8a p3p61sV/fol1XY16MrcNf7uho3djCk7BMFxJD9NURm7ZeyJslSVg3clElCdP7BA1PKpb q/EaOwEOebVpdRdd+MADbQDCFdLY1wkQyjelDg9QE5jJjLu5dLFVBvWLZG8RJnsPw4Cz 8fd16JwLyVvPf7TI7gbTZh1D/BaAE8Pja7WogT838qlIu/KpbLrCPR6Bo30gxpHh4cQ3 c231EHottefKA5ZI0qvAFh/gg5k0AGs6JCovnszhmAjsW4nOGh7/S5HuDAMEN7CJXX0m 3H1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714622496; x=1715227296; 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=YK4M7DhO5mIJIFP1QifUvK0BbiOYwnyjSGyXVIhqvoc=; b=YTyEiVPxPArdN/f0dzUO0K7ZgxmYt/LCvd0Hf82xlNA4uI/CBXgOBrF3/5fRbcirCn 1RjCplaEbznvSm7239LIxmK4GCAOiF6g84f71z4xCCooEz7xjkJaYWr/xQoc1dtL+WGg OFRxElF2nyhImZNQ63D6dVHoasHYqRLY4QwS6MeThTlfSHs3uAvHTYI180OK8Gs0P5vw /6MH4tjTyqYlK0Lezj8lekBOuaPMrgk6pHqcJfJd+zaJRO8gaXXTDkPjmBeNMeVcDEHa L0OEySh3gVnVza9SBHtvE8YF7NR9IqG485Avni82CFLRSzclp6L+2kfxZHZTaGuD5hs8 ObFw== X-Forwarded-Encrypted: i=1; AJvYcCWtRl/G8spNLBElRRNELNu+zOG/6yajqT4n+N/JoVCMUgprm+8pI/TvpEU34iz0HONIMXb+6dU8/c6Hgg4gpKJ6Q8VzU8mQNgeypR1M X-Gm-Message-State: AOJu0YziQGz9keoQlPUBUirLr7X4fmwndm7c/BojCbE5LFXnoXSJDopA QbDV/TtJKapW4RhQaQEnq+w98wrU2NZU/fVTkO/fArcrxn1gocFN1iF1k01DqK5PS3vSOfD6uOH 59wCcRg== X-Google-Smtp-Source: AGHT+IFPc6nblxvkSStjTR2HZemwo65gYU0j5fOsBfVD2NY3SXd8R9XN1dTAVlFK+TBORZ9QnkCT8WE7n4M0 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:53b9:bbda:1daa:17d3]) (user=irogers job=sendgmr) by 2002:a05:6902:100a:b0:dd9:2782:d1c6 with SMTP id w10-20020a056902100a00b00dd92782d1c6mr419962ybt.1.1714622495773; Wed, 01 May 2024 21:01:35 -0700 (PDT) Date: Wed, 1 May 2024 21:01:08 -0700 In-Reply-To: <20240502040112.2111157-1-irogers@google.com> Message-Id: <20240502040112.2111157-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: <20240502040112.2111157-1-irogers@google.com> X-Mailer: git-send-email 2.45.0.rc0.197.gbae5840b3b-goog Subject: [PATCH v4 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 --- .../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.rc0.197.gbae5840b3b-goog From nobody Wed Dec 17 23:14:05 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 236BB20328 for ; Thu, 2 May 2024 04:01:39 +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=1714622501; cv=none; b=j4/3dPdk6t5sy7HiWwr1RaPoZ1YmxUtyJTf+4Gp3i+Wyl/H7l5yzBB/rNLxVmPruah9DdnS25dXmOJwdO+7oh0f5Pd7/uPnrqoMuI5Pu5OOGiToRBztq2nw4jS8ig6n5czPTdYaYFCVX3lzZmnpx6wHczwWediKlh4kHj2UUdTA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714622501; c=relaxed/simple; bh=rPW19hYSO7RGqRfHddBDviu6GP9SvPkIiu2QRpiXrYs=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=Hh8o5s41qJv9qgfN9ym6dmqhNDME7lf8E12c5Czxr/M1zzaJXmXOvjKAYTIUwNko2rk5OtKoi3+dHNwdgsKFj6vLVZMPbmL37TSp6w5RT6MHKXCSDAhKGb+mQXFqku75PDiLz6wCZOwtom6PW+whKsxPzKz1qUWKN5cEuFeFyPk= 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=LUvpiH+H; 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="LUvpiH+H" Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc647f65573so17494251276.2 for ; Wed, 01 May 2024 21:01:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714622498; x=1715227298; 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=UFIWOY8jDJKM4dfzjBXMQ4LXTpCjbhELgrhO1onJTMY=; b=LUvpiH+HcK9ZI9a91oxmdEkOAfGQFf+vUt0JIUyKUjDGpVtHHl5WViRiwxmsuw8zIp dngPyPWLN5JDI4QSb5pMuSx55N3YvYEdWpurvFKy3HnVl8ByUAAFvvyU3tvVRBc15oMt gu+s6CEPJlpQRwrBChXL6CmoyYCYxNHdzXLutZKKdbGg46LY77vGZv0zjCYec3JXs9sh jeGglF5MCPB2Dm9VtfhNqBQW1CoQh7fUSNdzrjcyLmdRCvmL5BZ8FJnIJWAwpGbF9ixV SDMMhRhec/fZ5JSD7iUUf3GpblqpVlsiALunoFfc/71p8/oX1EgKmOOvyh4dPUTk9w8U Dj3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714622498; x=1715227298; 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=UFIWOY8jDJKM4dfzjBXMQ4LXTpCjbhELgrhO1onJTMY=; b=kC49zArq//ff+hg+fhbLufrlBe3AvNinDdM76RBxmVtFtSAaOipQnX/JMBELu518fg Raf3ENOMAAKwRU3Q4kAavNUElYmErsY1+Pr6Ex4h2BXT4IQV3hx53UElFzWzOCqAQZ7h SOE0Ad1xIdOGjWAVbvrWw04AwQNGQr26UqQtAugxInLfUSiz+sb4bT3rtcNEc+UxTsKz aYwYGCvXUK9z8JmPQFAoh356cpToq89nOdrPJE0O137dkwrPisNCYIKAwEQtDqsei4kP v4as5RSZct4dyoRqMmpLISBdSMZZ1p5nItEc4XxN88w0KVOYlFyp4uefpVTYGTeRsZdo 83Mw== X-Forwarded-Encrypted: i=1; AJvYcCVmSQ4QdjhwWXWjJnSPy34zPLvx48ckqxp6EbyDGVadVSkCVKjBmZ8I9MkpUWIxuEQI+EA9leSigTVwltXLozO5LRr20E8fKN8hjIt0 X-Gm-Message-State: AOJu0YxNlb++Ei6I3ImC9OmRnDO+pXW5jA6D5CsEu7R4cXqd1fOvDogv v/PtKeEtwWMOuo+LLzeNFW5PX7c92reRXidhNC0/hmyIvE2O4uXiZaAs4J1wnaKAIe6aXxTKcb5 rsTzW5Q== X-Google-Smtp-Source: AGHT+IF+BCS1WL6IjGsHkPhZ8CbpaPJ2nTkMIy3woz0Zcz7J/MVsxiPZF/itdvVYOFpasehpF7RysnrtOjdB X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:53b9:bbda:1daa:17d3]) (user=irogers job=sendgmr) by 2002:a05:6902:1081:b0:dc9:c54e:c5eb with SMTP id v1-20020a056902108100b00dc9c54ec5ebmr236712ybu.7.1714622498221; Wed, 01 May 2024 21:01:38 -0700 (PDT) Date: Wed, 1 May 2024 21:01:09 -0700 In-Reply-To: <20240502040112.2111157-1-irogers@google.com> Message-Id: <20240502040112.2111157-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: <20240502040112.2111157-1-irogers@google.com> X-Mailer: git-send-email 2.45.0.rc0.197.gbae5840b3b-goog Subject: [PATCH v4 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 --- 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.rc0.197.gbae5840b3b-goog From nobody Wed Dec 17 23:14:05 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 450A41B815 for ; Thu, 2 May 2024 04:01:41 +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=1714622504; cv=none; b=TKUPDSvdGAlm1GCWb6rK4JUR4gxjU4qywfWDxfp7/p1NZuo2s4AFOxPXsfr7+VeUL0rJLBxt5a6taIzodYrRBRXPMpaQYkwzzgEEeVjoOY2i+m4NDOZ+gRh8jlq8MLhZVRXGwkbudEgGgT6zu01IVFuMa5hKHcewkwcK6Vc1r6E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714622504; c=relaxed/simple; bh=D5OMauP5AuCov1guhgbdWScnCkzXcr/I299bo8RBj6k=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=n9pNA4nMnL+rOaK30ladHjgjk7HlErFyfEIRawUGugHl6diuBHUS1RNZro09/nydLXPFuWnUUcsTqCDO1OzPvCQjsnRE0/oXuep92GaTSi9M6HJb/8SMfErDeFaeSQbuv9/getNtpaa+seWSgdPW/nV61VfmzS9f9mCfeBXEMZ4= 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=HdfEWEtL; 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="HdfEWEtL" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-61df903af62so38295477b3.1 for ; Wed, 01 May 2024 21:01:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714622500; x=1715227300; 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=zj5k9BmjFkiNlgtOsdr7K0ZIJlrTlzid/tiIdg6PkY0=; b=HdfEWEtLlPXV3FxXI7abed8OOsYp1973dsOjNct52Zz/LHUiwz4HfBvg1oMywk2hBM ya3nis1Oy6X9wkcPFzJ4yfFnvYo6ayAZpRJLf1nRlrjf+0bhWOSD7sR6RtDubrj2LzD0 slIt5aDhRxZGjM4Pqa+W/aAHJYp0sBFyzbaMqQXpvFITNLqeibEVW/HATrYANePdFcbl UiGUFwJeARn+p6kK4Tp5JKWPCYNp8QmwE4WrjDG2YKQ1YdhWpuufRuk4G2YxmBRbJT1O +rEauZ19QuhTzXrF4y3hGNomxNDiCz6xZBPB14rBgW+VR3fL3zzhpUXBIP8fwVzRreCG eweQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714622500; x=1715227300; 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=zj5k9BmjFkiNlgtOsdr7K0ZIJlrTlzid/tiIdg6PkY0=; b=RjVlSKUVkGPRVkfFF3fl2pV1du5L6bd50lzrNCo+sYkaOwwMiSyFFWx/fbcoQIYp6I zAJuZpIF4uNBJf2j996Qvh7aknEAwl9VdSUK8TaUSVsHAMPBOOMtgZmJ2IWWa6bvk9dq F/bgDfmaqK4ZCyaULCJPYOn11Ba4ZHFYIMRvZkYTfA6W/cmOagolBYFrI16IIVz7reku cq+gUgu8n9tQl6f12Y+le7NeR1Yq2yMZ3YKcmspat1j6XlwktUgRGrBsmxJe6OINyktv cwETKqcSX1kgow99tVtHSmUGsDMJvh6R4jJBY1Qb7+P3qXWXYw9kdEjjAn/r/UxBpwVm dLKg== X-Forwarded-Encrypted: i=1; AJvYcCVVMCVXJ7PBBrZlv1HUZiubk/jkdDNyKLUWN5Pz4B5YJkqKrOhHo2YcnXAib9I345hIH7THAbCV0Ic/818V0S9iHJ49PPDvY8qpF/J9 X-Gm-Message-State: AOJu0YyascpaQ6SmFX7cP/7H99cSs6UWJiUJh5G9JmmR71jnJ+kCSLls y+R0Kebxe2sRI/WxA4PE/x+gfxo1ecMC6ELsYy0XBORDp0klCMHn0AVbomfhg8PxbMOQL7J8At/ myeAorQ== X-Google-Smtp-Source: AGHT+IGy993J8GFdln8sE7kiQrkDZ93nSMDEZ7PwjE7ki+RPa1Jf/e3JPjs+s3pUexiz3atQA+nO6NsljxC2 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:53b9:bbda:1daa:17d3]) (user=irogers job=sendgmr) by 2002:a81:5296:0:b0:61a:d355:168f with SMTP id g144-20020a815296000000b0061ad355168fmr210922ywb.5.1714622500327; Wed, 01 May 2024 21:01:40 -0700 (PDT) Date: Wed, 1 May 2024 21:01:10 -0700 In-Reply-To: <20240502040112.2111157-1-irogers@google.com> Message-Id: <20240502040112.2111157-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: <20240502040112.2111157-1-irogers@google.com> X-Mailer: git-send-email 2.45.0.rc0.197.gbae5840b3b-goog Subject: [PATCH v4 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 --- tools/perf/tests/pmu.c | 77 ++++++++++++++++++++++++++++++++++++++++++ tools/perf/util/pmu.c | 69 +++++++++++++++++++++++++------------ 2 files changed, 125 insertions(+), 21 deletions(-) diff --git a/tools/perf/tests/pmu.c b/tools/perf/tests/pmu.c index 424ebdb0f09d..6e18a4c447ce 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,62 @@ 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; + 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); + ret =3D TEST_FAIL; + 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.rc0.197.gbae5840b3b-goog From nobody Wed Dec 17 23:14:05 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 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="sUfkcg6U" 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-Google-Smtp-Source: AGHT+IHuvDPgdMYMqU1KAVIzctXRTwXejg5EogKa/A5SRYyv5g/TLtdTh7pUBzRwY753FJB0LEUBz3q6R/iX 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-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 --- 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 =20 /* 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; } =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.rc0.197.gbae5840b3b-goog From nobody Wed Dec 17 23:14:05 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 8E6C421350 for ; Thu, 2 May 2024 04:01:45 +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=1714622507; cv=none; b=DTUaigLAtsksqhnI3YrPnv18/W6bR5ZuCkzYC3wP+eWbFbO6yzjqTkc5ErmZEkVdiCHDbxukJ5/tX82J6XzE20wY2vkh3lS1YDZHopxAY0zD8ZwVzboXdfB3lb0x3pmE7mT5qAa4acRx0gMztBbfVTGt9yIUlpScEAspL97ncxM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714622507; c=relaxed/simple; bh=LoJaLXnrm+cg8gCQVbKrK6hyShTPLrxvjEHVqlnkjD4=; h=Date:In-Reply-To:Message-Id:Mime-Version:References:Subject:From: To:Cc:Content-Type; b=kr1/6k3/ZfS5EgLiMb7FV21a/dRepTPcwF5fcZwqOj4clglwTcQq8ItZgd89JgKGroAk20DawSj/rzw/YTFXXNqWItcoGVx2Ae/LqdqzWLKz/gYkDra/nz3NZgony+WEtH7HYlWRPJFNAmc8rcA+Dw9YNVXT1DYWXj4UTgIDeP4= 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=Pbg8y/w1; 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="Pbg8y/w1" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-61be26af113so57770647b3.1 for ; Wed, 01 May 2024 21:01:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1714622505; x=1715227305; 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=K/IDkFm8YQdijjzsBD7Gmtx7FjqcThxAwNDMqnP0dcc=; b=Pbg8y/w1NbWBRnrNdLzSHe+8ev5OFroRA2HhlerOQE87xcqN+Nhf7hRUn8Ch1a9Rjn Js6tEGHPCvFjram0B1YhozGZ/P3IqTa29iACJ4jT4GibRYaQG2UqAmxLjzRCC80ApjGH DdjkzKZ+WW4ZnHadak2AWVTgx6euE3Bl56mbYPTRnAvYUUuHAN1uLV4dxsq433zhIUju o934dIFrjaXCrZpJQkvsirl6lLAP6AP+VUZbTQCnPvXca+pR4EqpPxBUgxPOiTgGGYY/ 5qvzxU+nBfU9rxtLRZcDGFwLSYpD3/MTU4ZphFRPcDvQK8PUKHZokyHUxwiU9hcJuBhT aLAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714622505; x=1715227305; 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=K/IDkFm8YQdijjzsBD7Gmtx7FjqcThxAwNDMqnP0dcc=; b=wAFJULppgPdu/45KJvJaEfP99JExo1DkICecE3nr9vFVfwz5AJdi6AYf2Q4EbBOcpS ABypeRIDSjYwKfI0PlKnIL35HdpGymi0ANAG/Hhsabr5QxhGGSPazdHOw/sssDeW+/F1 ZpwEuporYA4/TV67fPyyoBOukrsFHrygVN2J0gnF8ClQ2MnBeoRaxQCvRGObPwjWgJG/ 6sPBfG1P9OOKD3Wp2QvshGYX/xyUd4a61zXgHXK0sdBNwut2fvtoEui6ZH1wl8aXzxIe XL7XXTXGUVw/M/geaDMnCQp19evDXx9Ow1FTNsFafJ3GFZIEdT+3R2OrJkl7ea00fDWS Uz1A== X-Forwarded-Encrypted: i=1; AJvYcCWHwPFNNTbbXiYHIerSpdJnGRQokGmv7erNfuQlBqTprayRcNPka/3Vpsi39Z55IKc/PuPNw2P/sd4VQZdRy9w3bUYLyBfXLuCo6fue X-Gm-Message-State: AOJu0YwDbplJWJUBzmFvGNb8Nn0o7YZEtzy6A4vtlxr0ZivIPCVEnRkw eeF7z/6ztSJ/BRcLvs0SKlYC/dvSfnXMT+apbihE3T4yoVJiqAVQ/wKxiQLLpSaX6WqpqY/QpIJ /uzT1yw== X-Google-Smtp-Source: AGHT+IG9tEfOjT0Eqpu9vPzzzQYNyox7AbGmb0IH8fHWMXswZ+Y7bTVgg5flv7C0k5tYmnCX3kAUVqz3wCb6 X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:53b9:bbda:1daa:17d3]) (user=irogers job=sendgmr) by 2002:a05:690c:b1b:b0:611:2c40:e8d0 with SMTP id cj27-20020a05690c0b1b00b006112c40e8d0mr1109843ywb.3.1714622504797; Wed, 01 May 2024 21:01:44 -0700 (PDT) Date: Wed, 1 May 2024 21:01:12 -0700 In-Reply-To: <20240502040112.2111157-1-irogers@google.com> Message-Id: <20240502040112.2111157-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: <20240502040112.2111157-1-irogers@google.com> X-Mailer: git-send-email 2.45.0.rc0.197.gbae5840b3b-goog Subject: [PATCH v4 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 --- 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.rc0.197.gbae5840b3b-goog