Received: by 2002:a05:7208:3188:b0:7e:5202:c8b4 with SMTP id r8csp891918rbd; Fri, 23 Feb 2024 06:52:09 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU9xXCAW3e3aPJgBGehEosZWlk5eilh3gl23EkBEJnTbacFedZXWSWshZBuRnchDanzbZUQfwcVwI6IoN6fCEF/kDzUNWk0MD5AOPZMOA== X-Google-Smtp-Source: AGHT+IEYJ++eZqnAD9rLtZw4Qy7zZmEZMaqylU1sAl4NozVoU6LeKF7C5T7qUDb+0dSyjHUadefc X-Received: by 2002:ac8:5c92:0:b0:42d:d026:f1b2 with SMTP id r18-20020ac85c92000000b0042dd026f1b2mr22943qta.14.1708699928716; Fri, 23 Feb 2024 06:52:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708699928; cv=pass; d=google.com; s=arc-20160816; b=BXrLwxDdRNIfQ4g8gazEbH2Gq1DwqgxMf8jmgXAjseFGdE3OQHdXXsUNYHec5tHMzr GlU3iW9LPoN+EmQp5+scJ5fkugCC5i1KM0+Nzz0BxCZ8W3IdEcfLXeas5S4n6VYBSroa AEGzmBtunmYh1NPuHn5c1j1c4MRHuT4fm9To01ig/ytMVRLihp7pKh0y4TF76+0pAlQs t0r7Lggz4zCWfmGCWvf9iqyaKTiAVXMfjZJBl7dGTTpklBNmuh2ntTSdDSkK21oAsId2 YELp1o4ElaR2+6ndTvJM/WKygp+WufIMSd2xwMn2IGqUPMz4sjpiVQzFwUwObSXyZLwC kDPw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:message-id:user-agent:references :in-reply-to:subject:cc:to:from:date:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:dkim-signature; bh=8kgcEGCWzCzQZTTJSdM1ldFVruttL1M6bKtSIrqgzfY=; fh=tV8XE+KDxQifo83U+PJk2hZUi+QdIIIkG9/9AmwlOYI=; b=sb6ze9bOtDMR+/dH0Xa33z02CkR1fNQ8GCZ2CG8FGamD04n8WP3kuUEDF71qrrVXQP ui1rAaJ8S1BdgWnwKJ94LQBSAUgkgpSy2Qejdjteq0aQxr8CXTQNJtdsuNPFQDYIWqLV yYARhu1npcIE2zjNHV5gNsqhFpnmotCh3dokBI+yeSxQyKaTmO4wZWNhBI2TZvhYObEE rzUlSbH82CoJhZhKAtC2bgIyICbdvwdTYz/kyfhQCrq33zx3aA2HNk06n4ib2lAM+BF7 olgFnezbkXCWt+LTuBWN+Vr+C8Nw8ett242kBCemMmu8w9wxPBJb/Uzd1ATnc55xzjpE DgSg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Om1OHLt0; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-78539-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78539-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id s28-20020a05622a1a9c00b0042e6a1bec87si428307qtc.553.2024.02.23.06.52.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 06:52:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-78539-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Om1OHLt0; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-78539-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78539-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 6A5B91C22FCA for ; Fri, 23 Feb 2024 14:52:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 196B082C69; Fri, 23 Feb 2024 14:49:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Om1OHLt0" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 100101272B5; Fri, 23 Feb 2024 14:49:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708699760; cv=none; b=kUb1SHhXYZQELllEHYgGCW77iALy2PwA7TsUJoXpvoVGu/KqdrfmMCZ0jcx8NrOA6qdW61SGeSt/JUAzN5NC2+BYYpdDJ5ALeIqFxuQftdRN3JDslv/X8ipjjfuatWCfbTubLCKO62iqj8OHogZ0OsZgUev2MStLU8rX5emEhic= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708699760; c=relaxed/simple; bh=PEc1cihrzX0ifdXmwzn5PbXGXkCz3NEiplMz3IcV62M=; h=MIME-Version:Date:From:To:Cc:Subject:In-Reply-To:References: Message-ID:Content-Type; b=YR6uSxdKLKI/IKbXJe01eqiOmlW8Pgj2Zsbg7v85U1Ee6OlRB56hUPzfrfWcnyxBjVqQosZlRyGdstdTu/o8iqhy0vbqReRPBrBzVXvtSayyt1jXgTIpmiqxvPRN0tZQ0qRBrEdFkwoFAYzxYED+RgwjNzrAabuCLVsTwR0Dn6A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Om1OHLt0; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 81A1FC433B2; Fri, 23 Feb 2024 14:49:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708699759; bh=PEc1cihrzX0ifdXmwzn5PbXGXkCz3NEiplMz3IcV62M=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=Om1OHLt0MhTFZLBFunKGxQ4jvDKzGUyDVwjxBB7OSG7AMWKq+AWf06xg45mWcdH+a IriIvRcHPRpMYFP4bGA1yU3oyt8MS1LDnBnC+9Hwbv10mB6BJ3H2CGrbg7rLf8QbOy zaW8JSbPU08sC1UI/8m7qZ2IjyLtYfJZCTWVvodBXlMGMkjEDST3zPDXi8eUeGP8pC fWZMVaRFE3uA3s3z67sG1Mt19dgmYDjFeSlrG0WJtkpiHbKxvTh6hSfwK+HiVNEzDk dyAOvQrmI8sB0Lr0oxt93jYw5mGoK9pNZprS2qkAGmPagrRL1oPMvkA906so1Ggohg mUWCYUv6WnWUw== Received: from disco-boy.misterjones.org ([217.182.43.188] helo=www.loen.fr) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rdWrV-0067Ic-6S; Fri, 23 Feb 2024 14:49:17 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Fri, 23 Feb 2024 14:49:16 +0000 From: Marc Zyngier To: Mark Rutland Cc: linux-kernel@vger.kernel.org, acme@redhat.com, irogers@google.com, james.clark@arm.com, john.g.garry@oracle.com, leo.yan@linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, marcan@marcan.st, mike.leach@linaro.org, namhyung@kernel.org, suzuki.poulose@arm.com, tmricht@linux.ibm.com, will@kernel.org Subject: Re: [PATCH v2] perf print-events: make is_event_supported() more robust In-Reply-To: <20240126145605.1005472-1-mark.rutland@arm.com> References: <20240126145605.1005472-1-mark.rutland@arm.com> User-Agent: Roundcube Webmail/1.4.15 Message-ID: <8bc9dcbab11aa25115d0d278d353188e@kernel.org> X-Sender: maz@kernel.org Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit X-SA-Exim-Connect-IP: 217.182.43.188 X-SA-Exim-Rcpt-To: mark.rutland@arm.com, linux-kernel@vger.kernel.org, acme@redhat.com, irogers@google.com, james.clark@arm.com, john.g.garry@oracle.com, leo.yan@linaro.org, linux-arm-kernel@lists.infradead.org, linux-perf-users@vger.kernel.org, marcan@marcan.st, mike.leach@linaro.org, namhyung@kernel.org, suzuki.poulose@arm.com, tmricht@linux.ibm.com, will@kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false On 2024-01-26 14:56, Mark Rutland wrote: > Currently the perf tool doesn't detect support for extended event types > on Apple M1/M2 systems, and will not auto-expand plain PERF_EVENT_TYPE > hardware events into per-PMU events. This is due to the detection of > extended event types not handling mandatory filters required by the > M1/M2 PMU driver. > > PMU drivers and the core perf_events code can require that > perf_event_attr::exclude_* filters are configured in a specific way and > may reject certain configurations of filters, for example: > > (a) Many PMUs lack support for any event filtering, and require all > perf_event_attr::exclude_* bits to be clear. This includes Alpha's > CPU PMU, and ARM CPU PMUs prior to the introduction of PMUv2 in > ARMv7, > > (b) When /proc/sys/kernel/perf_event_paranoid >= 2, the perf core > requires that perf_event_attr::exclude_kernel is set. > > (c) The Apple M1/M2 PMU requires that perf_event_attr::exclude_guest is > set as the hardware PMU does not count while a guest is running > (but > might be extended in future to do so). > > In is_event_supported(), we try to account for cases (a) and (b), first > attempting to open an event without any filters, and if this fails, > retrying with perf_event_attr::exclude_kernel set. We do not account > for > case (c), or any other filters that drivers could theoretically require > to be set. > > Thus is_event_supported() will fail to detect support for any events > targeting an Apple M1/M2 PMU, even where events would be supported with > perf_event_attr:::exclude_guest set. > > Since commit: > > 82fe2e45cdb00de4 ("perf pmus: Check if we can encode the PMU number > in perf_event_attr.type") > > ... we use is_event_supported() to detect support for extended types, > with the PMU ID encoded into the perf_event_attr::type. As above, on an > Apple M1/M2 system this will always fail to detect that the event is > supported, and consequently we fail to detect support for extended > types > even when these are supported, as they have been since commit: > > 5c816728651ae425 ("arm_pmu: Add PERF_PMU_CAP_EXTENDED_HW_TYPE > capability") > > Due to this, the perf tool will not automatically expand plain > PERF_TYPE_HARDWARE events into per-PMU events, even when all the > necessary kernel support is present. > > This patch updates is_event_supported() to additionally try opening > events with perf_event_attr::exclude_guest set, allowing support for > events to be detected on Apple M1/M2 systems. I believe that this is > sufficient for all contemporary CPU PMU drivers, though in future it > may > be necessary to check for other combinations of filter bits. > > I've deliberately changed the check to not expect a specific error code > for missing filters, as today ;the kernel may return a number of > different error codes for missing filters (e.g. -EACCESS, -EINVAL, or > -EOPNOTSUPP) depending on why and where the filter configuration is > rejected, and retrying for any error is more robust. > > Note that this does not remove the need for commit: > > a24d9d9dc096fc0d ("perf parse-events: Make legacy events lower > priority than sysfs/JSON") > > ... which is still necessary so that named-pmu/event/ events work on > kernels without extended type support, even if the event name happens > to > be the same as a PERF_EVENT_TYPE_HARDWARE event (e.g. as is the case > for > the M1/M2 PMU's 'cycles' and 'instructions' events). > > Fixes: 82fe2e45cdb00de4 ("perf pmus: Check if we can encode the PMU > number in perf_event_attr.type") > Signed-off-by: Mark Rutland > Tested-by: Ian Rogers > Tested-by: James Clark > Cc: Arnaldo Carvalho de Melo > Cc: Hector Martin > Cc: Ian Rogers > Cc: James Clark > Cc: John Garry > Cc: Leo Yan > Cc: Marc Zyngier > Cc: Mike Leach > Cc: Namhyung Kim > Cc: Suzuki K Poulose > Cc: Thomas Richter > Cc: Will Deacon Tested-by: Marc Zyngier M. -- Jazz is not dead. It just smells funny...