Received: by 2002:ab2:784b:0:b0:1fd:adc2:8405 with SMTP id m11csp302309lqp; Mon, 10 Jun 2024 04:57:10 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV/58tFCTnxFzc7YpOO4n8lRi5CRfjJ/j1xMCsbQiYg81UWXN1AmXVORX6t2SbK0xpAGvWF6Wr1oI1QIfKh+H/YhgHunTSIgthNH0c5dA== X-Google-Smtp-Source: AGHT+IF+bcVdSed6i8Nw6Xx+hRP7O7NWktL95e5kXQlCPnnwMTi3XaBUc5BYZBS8qM4709kpgjE8 X-Received: by 2002:a05:6122:30a7:b0:4d8:7789:dd0d with SMTP id 71dfb90a1353d-4eb562c38c4mr8554550e0c.15.1718020630285; Mon, 10 Jun 2024 04:57:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718020630; cv=pass; d=google.com; s=arc-20160816; b=hxnH9Xrr+y4nF+0jCaN9Z2NnAUECjLPVsXm6KUxNjJ2/mDSVnnRXw3leKiA+AMQ+/4 peTy4Hzs11M0GyzhrZ359SVqi8xBIpsOEYect5ocHR3SesNOHJMJtjQSW6FVKaOyBrh2 iquLDEgMK71DmzGVb5Mz8gbOMwKP25RgeTigDp4FQdzQIcCulWy7Js/UcMj3ZKT8dDCq 8i9yI0VERtOKKpceQ0x8MFtm9RjHoPNeMORtBv9XVRon/nZzKQVriSyucOJMp2E1n5kC 2InDv7DddLw5ypP6u+2Rzq4ASEHxbXE8eWaKha0tUl1FqbrMF27ktNuCYWh4pD6Q7ZCZ VCVQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=+qiys15n7/7AMSRD1PoNprFlpJNBMqTqzr32KXx1tt4=; fh=qgMfJgvzXFQidiVGYujudC5/sUCtdt6StJkY7gN6rRQ=; b=OZAn/4p4vCCKTEkvYoYmZzjQCZgqk3liAyITl9AKJm/9SODHipJkWC1DquU4IsKs7b BqqYNjXMLcC5GKIY9HnVJiWf4g42V45mAPiq3lavUq2tw8EzIab/a5sMlmmPwCgDfcE9 BUjQud90cSwjJmbjX5wen/pKyRD4DxSjJ4FdqHO7h99ps/KIjfsLT/uIOd0DnsmsQC5V ZuHrJCEB9BqOInNmTAkQvL6/wgm0hPUu0am+Im82Y3DDSUXnQ9d2kJFSPnLH+xnfJ9iq ZeBrw45HdiUDgGc7IYdS8nWg6mkHVcH0WFwDYSKI/8NSXZvoQbJpbzmBsCTG6LoIWw5G aE/w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-208111-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208111-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id af79cd13be357-79568d9b991si309261185a.249.2024.06.10.04.57.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 04:57:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-208111-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; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-208111-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208111-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id DA5291C2205E for ; Mon, 10 Jun 2024 11:57:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5449212FB13; Mon, 10 Jun 2024 11:55:17 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C35DB7F7F5; Mon, 10 Jun 2024 11:55:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718020516; cv=none; b=MZW/LyMIpt5GrBIqcBM/z8MIhNjxSgVj27Ezhw/kT9lZvlPeQxiAxGYzAg4zpW8o32kfTgdQRFRCQiUoOg716BKPuSioVVyh4/duAWADxQOBWkU5tm2JLMgRBt4bpZOSC5QiFgmJ+AZUBB2fEfPd7i0KYWKDb5W8T3kbBRoUWZA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718020516; c=relaxed/simple; bh=lHU2JJLgCKo26fwvGAKkI/5vfcLyhRaN2Ta0zIemFAk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=peFYEI6abi5dFe8ytIMj0UfEDVVsfNZvywAvbiPGlwv6up9Zxjesvxh8qeT+DQAOZpDZ29/sMowxKU44ZtqlPRNPVshcP1wDvVcemJ4RrTYzRlOEuPLCOWK7ruLJmJu8WHJr6QYKc9Zi2PYp6U5tZpPE59s1k6xbDLzDiBRs8do= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B3BD112FC; Mon, 10 Jun 2024 04:55:38 -0700 (PDT) Received: from J2N7QTR9R3 (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D8F903F58B; Mon, 10 Jun 2024 04:55:10 -0700 (PDT) Date: Mon, 10 Jun 2024 12:55:08 +0100 From: Mark Rutland To: "Rob Herring (Arm)" Cc: Russell King , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , Will Deacon , Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, kvmarm@lists.linux.dev Subject: Re: [PATCH 9/9] perf: arm_pmuv3: Add support for Armv9.4 PMU instruction counter Message-ID: References: <20240607-arm-pmu-3-9-icntr-v1-0-c7bd2dceff3b@kernel.org> <20240607-arm-pmu-3-9-icntr-v1-9-c7bd2dceff3b@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240607-arm-pmu-3-9-icntr-v1-9-c7bd2dceff3b@kernel.org> On Fri, Jun 07, 2024 at 02:31:34PM -0600, Rob Herring (Arm) wrote: > Armv9.4/8.9 PMU adds optional support for a fixed instruction counter > similar to the fixed cycle counter. Support for the feature is indicated > in the ID_AA64DFR1_EL1 register PMICNTR field. The counter is not > accessible in AArch32. > > Existing userspace using direct counter access won't know how to handle > the fixed instruction counter, so we have to avoid using the counter > when user access is requested. > > Signed-off-by: Rob Herring (Arm) > --- > arch/arm/include/asm/arm_pmuv3.h | 21 +++++++++++++++++++++ > arch/arm64/include/asm/arm_pmuv3.h | 29 +++++++++++++++++++++++++++++ > arch/arm64/kvm/pmu.c | 8 ++++++-- > arch/arm64/tools/sysreg | 25 +++++++++++++++++++++++++ > drivers/perf/arm_pmuv3.c | 28 ++++++++++++++++++++++++++-- > include/linux/perf/arm_pmu.h | 8 ++++++-- > include/linux/perf/arm_pmuv3.h | 4 +++- > 7 files changed, 116 insertions(+), 7 deletions(-) > > diff --git a/arch/arm/include/asm/arm_pmuv3.h b/arch/arm/include/asm/arm_pmuv3.h > index ac2cf37b57e3..b836537ddfbf 100644 > --- a/arch/arm/include/asm/arm_pmuv3.h > +++ b/arch/arm/include/asm/arm_pmuv3.h > @@ -10,6 +10,7 @@ > #include > > #define ARMV8_PMU_CYCLE_IDX 31 > +#define ARMV8_PMU_INSTR_IDX 32 /* Not accessible from AArch32 */ As with ARMV8_PMU_CYCLE_IDX, I reckon this should live in (with the comment above) so that we don't need separate definitions for arm & arm64. [...] > diff --git a/arch/arm64/tools/sysreg b/arch/arm64/tools/sysreg > index 231817a379b5..8ab6e09871de 100644 > --- a/arch/arm64/tools/sysreg > +++ b/arch/arm64/tools/sysreg > @@ -2029,6 +2029,31 @@ Sysreg FAR_EL1 3 0 6 0 0 > Field 63:0 ADDR > EndSysreg > > +Sysreg PMICNTR_EL0 3 3 9 4 0 > +Field 63:0 ICNT > +EndSysreg LGTM per ARM DDI 0487K.a, section D23.5.15, pages 8989 to 8992. > + > +Sysreg PMICFILTR_EL0 3 3 9 6 0 > +Res0 63:59 > +Field 58 SYNC > +Field 57:56 VS The 'VS' field doesn't seem to be in the ARM ARM (ARM DDI 0487K.a); is that defined in a supplement? > +Res0 55:32 > +Field 31 P > +Field 30 U > +Field 29 NSK > +Field 28 NSU > +Field 27 NSH > +Field 26 M > +Res0 25 > +Field 24 SH > +Field 23 T > +Field 22 RLK > +Field 21 RLU > +Field 20 RLH > +Res0 19:16 > +Field 15:0 evtCount > +EndSysreg Aside from 'VS', this LGTM per ARM DDI 0487K.a, section D23.5.14, pages 8981 to 8988. One important thing to note is that this doesn't have the threshold controls (TC, TE, TH); so if threshold events make sense for instruction events, we cannot place those in the dedicated isntruction counter. [...] > @@ -931,6 +939,18 @@ static int armv8pmu_get_event_idx(struct pmu_hw_events *cpuc, > return -EAGAIN; > } > > + /* > + * Always prefer to place a instruction counter into the instruction counter, > + * but don't expose the instruction counter to userspace access as userspace > + * may not know how to handle it. > + */ > + if (test_bit(ARMV8_PMU_INSTR_IDX, cpu_pmu->cntr_mask) && > + (evtype == ARMV8_PMUV3_PERFCTR_INST_RETIRED) && > + !armv8pmu_event_want_user_access(event)) { > + if (!test_and_set_bit(ARMV8_PMU_INSTR_IDX, cpuc->used_mask)) > + return ARMV8_PMU_INSTR_IDX; > + } I reckon this'd be a bit clearer if we check the evtype first, as with cycles, e.g. /* * Always prefer to place a instruction counter into the instruction counter, * but don't expose the instruction counter to userspace access as userspace * may not know how to handle it. */ if (evtype == ARMV8_PMUV3_PERFCTR_INST_RETIRED) { if (test_bit(ARMV8_PMU_INSTR_IDX, cpu_pmu->cntr_mask) && !armv8pmu_event_want_user_access(event) && !test_and_set_bit(ARMV8_PMU_INSTR_IDX, cpuc->used_mask)) return ARMV8_PMU_INSTR_IDX; } As above, we might need to check for threshold controls, but I'll need to go page that in. Mark.