From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 9E8C53858C53 for ; Thu, 25 Jan 2024 17:41:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9E8C53858C53 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9E8C53858C53 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706204464; cv=none; b=UCzRLxuvPqwbbHv9+jsLGF9D0DinFrXvs7dctZxMRpBbFQSNmZ0wJocCugCD4wWyduqLV7aA13K+YHMA+fZtcqAXvaIhchRYvTtAqdqIRQywwQCs0riyjeoemYrsz24twNWPYZPGEdQ+Ho8i5Kk3ANWQmN+YrEPC882/pxil6dQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706204464; c=relaxed/simple; bh=2nNW5dtiiGdEOd3fWw4KxKK7xCJ6iH0nYiVcnZnVPh0=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=fflHFi3Qzv5RywEfU296Tm+CfQUcO/r9b90eBLESAC9SSJaRJAl7Ctp8PCYnS0O7EkOphy3Gr89soheUecVNc1TsToItxMty1hm7Iu2BPBtNT/49x1PRV2MiLrq1zZFWd/YEgWzF/HWuDxUvs7fBZ5u1JXe5be2ug9fCbPiFPEI= ARC-Authentication-Results: i=1; server2.sourceware.org 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 AB6851FB; Thu, 25 Jan 2024 09:41:46 -0800 (PST) Received: from localhost (e121540-lin.manchester.arm.com [10.32.110.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8A53B3F73F; Thu, 25 Jan 2024 09:41:01 -0800 (PST) From: Richard Sandiford To: Victor Do Nascimento Mail-Followup-To: Victor Do Nascimento ,, , , richard.sandiford@arm.com Cc: , , Subject: Re: [PATCH v4 4/4] aarch64: Add explicit checks for implicit LSE/LSE2 requirements. References: <20240124171853.3112540-1-victor.donascimento@arm.com> <20240124171853.3112540-5-victor.donascimento@arm.com> Date: Thu, 25 Jan 2024 17:41:00 +0000 In-Reply-To: <20240124171853.3112540-5-victor.donascimento@arm.com> (Victor Do Nascimento's message of "Wed, 24 Jan 2024 17:17:33 +0000") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-21.2 required=5.0 tests=BAYES_00,GIT_PATCH_0,KAM_DMARC_NONE,KAM_DMARC_STATUS,KAM_LAZY_DOMAIN_SECURITY,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Victor Do Nascimento writes: > At present, Evaluation of both `has_lse2(hwcap)' and > `has_lse128(hwcap)' may require issuing an `mrs' instruction to query > a system register. This instruction, when issued from user-space > results in a trap by the kernel which then returns the value read in > by the system register. Given the undesirable nature of the > computational expense associated with the context switch, it is > important to implement mechanisms to, wherever possible, forgo the > operation. > > In light of this, given how other architectural requirements serving > as prerequisites have long been assigned HWCAP bits by the kernel, we > can inexpensively query for their availability before attempting to > read any system registers. Where one of these early tests fail, we > can assert that the main feature of interest (be it LSE2 or LSE128) > cannot be present, allowing us to return from the function early and > skip the unnecessary expensive kernel-mediated access to system > registers. > > libatomic/ChangeLog: > > * config/linux/aarch64/host-config.h (has_lse2): Add test for LSE. > (has_lse128): Add test for LSE2. FAOD, the previous OK for this patch still stands. Thanks, Richard > --- > libatomic/config/linux/aarch64/host-config.h | 13 ++++++++++--- > 1 file changed, 10 insertions(+), 3 deletions(-) > > diff --git a/libatomic/config/linux/aarch64/host-config.h b/libatomic/config/linux/aarch64/host-config.h > index 1bc7d839232..4e354124063 100644 > --- a/libatomic/config/linux/aarch64/host-config.h > +++ b/libatomic/config/linux/aarch64/host-config.h > @@ -64,8 +64,13 @@ typedef struct __ifunc_arg_t { > static inline bool > has_lse2 (unsigned long hwcap, const __ifunc_arg_t *features) > { > + /* Check for LSE2. */ > if (hwcap & HWCAP_USCAT) > return true; > + /* No point checking further for atomic 128-bit load/store if LSE > + prerequisite not met. */ > + if (!(hwcap & HWCAP_ATOMICS)) > + return false; > if (!(hwcap & HWCAP_CPUID)) > return false; > > @@ -99,9 +104,11 @@ has_lse128 (unsigned long hwcap, const __ifunc_arg_t *features) > support in older kernels as it is of CPU feature absence. Try fallback > method to guarantee LSE128 is not implemented. > > - In the absence of HWCAP_CPUID, we are unable to check for LSE128. */ > - if (!(hwcap & HWCAP_CPUID)) > - return false; > + In the absence of HWCAP_CPUID, we are unable to check for LSE128. > + If feature check available, check LSE2 prerequisite before proceeding. */ > + if (!(hwcap & HWCAP_CPUID) || !(hwcap & HWCAP_USCAT)) > + return false; > + > unsigned long isar0; > asm volatile ("mrs %0, ID_AA64ISAR0_EL1" : "=r" (isar0)); > if (AT_FEAT_FIELD (isar0) >= 3)