Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp71712lqp; Fri, 12 Apr 2024 10:43:18 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVg4bVPPkU6OmdZkXTsl8eQUKHvOyauqe71ebJ5VDSILPlO8OjAmEiUc5we38CCCf4conugyuj9lYP+NHYB5u0YZb/AyUGlznEEB1ncZg== X-Google-Smtp-Source: AGHT+IEXmwjlpxzD1RlX6nJ2sG/8e+Cqj9NXnPsQ5YWnKB8aefYoeySr4V3+I5qEFVXMmfsFnszH X-Received: by 2002:a81:ef02:0:b0:615:20db:4a4d with SMTP id o2-20020a81ef02000000b0061520db4a4dmr2999451ywm.35.1712943797960; Fri, 12 Apr 2024 10:43:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712943797; cv=pass; d=google.com; s=arc-20160816; b=rOBpfSy9bbRAw8LdTliblnuvjO7o8JgT37aysnVCkiVQj0JUOf0fN1cjgdGKERSVRF GSL3ldefmC9UFxq+T83WxsSVfU4x7UDOgZ94yXiV6iwroeUSGY6Gx3CbC+046xb6LcKN ERjfcrMAAb0gFyAIBmYN375UPHIFHmSYby3X+R6ZuCe6Pq7j5sBlaqs/oqazyVWH4JYa dwUgYRLru+fYfg2MDjEz+lLgDIsKn17Sg8KS8+ZjwfsM4itz8DYkWYaVKSmLTq9ErtjD RgB/56j2g6T8L3AyYoi0myPHFYGQTVa8kkN97R6+IZ8B0gqy73EV+fobO2E8caIGc3WH QELA== 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:dkim-signature; bh=8YRvEt+OTF00KrpCNHpUGlZ7toxHUQ85PqnBkH5iiOI=; fh=sLYIxuoB5FWmVCaw7M2ajgpdr6zfNo680T4RAFsw1hU=; b=Rn9OGY7uPAsbC5tmDk1OtsfpzfVyUCmTg/Eh3HgSsZynxM34DgiCLgLHWTWZHx9OmF BN3Gtzr43b349s+57O7bmKLvo3J7yFZ7ThohCx9xTJ7Q7Xq9UdSQJ9F8pDdGFnHlGoZH ce0k7pVayX71T6yPH814izNkqvCHCfsMT9eTwGNEYzaveqPPldUJs+mHh0G1IR+QKFmc 0+ZrObldu/YWxFfUEAcbzebsK3CqVqim47QixvHVUkSSov1nxDTSY/5iFUOSImMXp00P 4RiXrsV4EVcttE0sEonHGs0JS9b4Es1B5NrYeNBa0NtAORHjpTbPfJ/BdMhq/fdsGurJ KziA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="VREmx/I4"; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-143149-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143149-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id p2-20020a0cf682000000b0069b49061859si4071414qvn.554.2024.04.12.10.43.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 10:43:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-143149-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b="VREmx/I4"; arc=pass (i=1 spf=pass spfdomain=rivosinc.com dkim=pass dkdomain=rivosinc-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-143149-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143149-linux.lists.archive=gmail.com@vger.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 8D8911C21FFA for ; Fri, 12 Apr 2024 17:43:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C026A14E2DA; Fri, 12 Apr 2024 17:43:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b="VREmx/I4" Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (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 9925114D456 for ; Fri, 12 Apr 2024 17:43:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712943788; cv=none; b=LaZj4AOZDufEkP51w6AUYb+GhMb/rX28PMWdK6G4FBOm8XBnTqvsS1SfcyyKboSjTww1/17au+9JzBLzRqqvNjZHBbKaYbJa5U+umILQi6EdVkyIUbBmhJ6YLGUvjkyy9+3fg8ha2u36ECVu3qKN47WD+VVv84i1hnNAXrKKAXc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712943788; c=relaxed/simple; bh=398UBf0wjuXyW1KRcz0N92ExG8gOAwZvnLb+5hA8430=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Ufdj6tSsLSIM07yNZE1iUGG0RM/aG/Tq9BRvOGp0gmaONXWyusHOdL4sVyh0NBU3UH2X7IpKM+76xNBAvG2VzQBiUrTYB0JMC/h6TOZWzPVy90HAl4bBrx6zh7ZPf0Ha62zFTImZBpEKb5yV2LZvDjInIdy83nGM3tgkFDJb3jY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com; spf=pass smtp.mailfrom=rivosinc.com; dkim=pass (2048-bit key) header.d=rivosinc-com.20230601.gappssmtp.com header.i=@rivosinc-com.20230601.gappssmtp.com header.b=VREmx/I4; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1e5b6e8f662so5900925ad.0 for ; Fri, 12 Apr 2024 10:43:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1712943786; x=1713548586; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=8YRvEt+OTF00KrpCNHpUGlZ7toxHUQ85PqnBkH5iiOI=; b=VREmx/I4Bl8fL+erIIvIEgsEoPlqugBORJ930NOMVQeeB8gjpQm0aFTE3G73Jvtrgx B1rAIbF3LXz5Mdnck0/OYdjc3aLIYWNlMq9S7+w8lXvp7DGbceXEfM47U0o1+4wQ6kuo rEB5HpjVvcbkb8hrDI4vcHc0CcMKQxvF8VGrgAZyHrC0zFs4BLnJ4xZNwHZWENg03/Sd lLPrOe7tstnqZZ8p3E0QTAaCoYg+5GlDjhoZr3on5BpjgnnZOru3nbH82Y6WaK/H3P/6 kdySzfhHxh8ZGab/OalYe9YkNBc6SdlT6XRz4xPlCBezUQ718IoXkN5Tkm4B/cFyuuzb hLdw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712943786; x=1713548586; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=8YRvEt+OTF00KrpCNHpUGlZ7toxHUQ85PqnBkH5iiOI=; b=GKV88SZCmaSLOHlXN21QkxOybaFBofzjlvuQOskcpyB6uZoY7foQz4YqteOQWOOafg Vedmx9Rn1FXHmtapmnpnbnO3e5ltAWxTbXqDncgpe/zqaDN9deFowQNMMbVL2apr7UrL 3k9/BlXICJC69eRY3Qzh7v0FaAsPoO8tixZTF9yS1A+7wFZkf+XgE3rK8pA0lBg4KQNw bn/LX60Rx82RadW+MxKFX+cSZ4RtQPJNJniWZAlPHVJ3XZHtd2ua4r0Ox4gOdIrc70yL a6JjQc2Mq6b4+tg6mJa3shQwbSAyp8RnNZEl+64fyqQkJS1Fgtan6MKZND57N65QYAj2 x9ZQ== X-Forwarded-Encrypted: i=1; AJvYcCXSjb4GpipumggNZgCm+8F5rsXED3pyKOOY1J7KkuMrCc2v7MWt2lpgS6hHhi4ED7EYG9XywW8BACGpVNq25gSD3BdIi9WSwRQAEMZV X-Gm-Message-State: AOJu0Yztrs9YDtZ5y+XThuOWo2PjXn4nZzoSqhuEJeXy7fu7YRhMupIk /LhASRKnNi51AofAulQeUmiv0D81V8h5EY85CHVXU01ej3skl+7142pU5R2ajI0= X-Received: by 2002:a17:902:d303:b0:1e0:bae4:48f9 with SMTP id b3-20020a170902d30300b001e0bae448f9mr3205407plc.32.1712943785937; Fri, 12 Apr 2024 10:43:05 -0700 (PDT) Received: from ghost ([2601:647:5700:6860:121b:da6b:94f1:304]) by smtp.gmail.com with ESMTPSA id h9-20020a170902f2c900b001e0e5722788sm3287804plc.17.2024.04.12.10.43.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 10:43:05 -0700 (PDT) Date: Fri, 12 Apr 2024 10:43:02 -0700 From: Charlie Jenkins To: Conor Dooley Cc: Conor Dooley , Rob Herring , Krzysztof Kozlowski , Paul Walmsley , Palmer Dabbelt , Albert Ou , Guo Ren , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Evan Green , =?iso-8859-1?Q?Cl=E9ment_L=E9ger?= , Jonathan Corbet , Shuah Khan , linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Palmer Dabbelt , linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: Re: [PATCH 08/19] riscv: Introduce vendor variants of extension helpers Message-ID: References: <20240411-dev-charlie-support_thead_vector_6_9-v1-0-4af9815ec746@rivosinc.com> <20240411-dev-charlie-support_thead_vector_6_9-v1-8-4af9815ec746@rivosinc.com> <20240412-dwarf-shower-5a7300fcd283@wendy> 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: <20240412-dwarf-shower-5a7300fcd283@wendy> On Fri, Apr 12, 2024 at 12:49:57PM +0100, Conor Dooley wrote: > On Thu, Apr 11, 2024 at 09:11:14PM -0700, Charlie Jenkins wrote: > > Create vendor variants of the existing extension helpers. If the > > existing functions were instead modified to support vendor extensions, a > > branch based on the ext value being greater than > > RISCV_ISA_VENDOR_EXT_BASE would have to be introduced. This additional > > branch would have an unnecessary performance impact. > > > > Signed-off-by: Charlie Jenkins > > I've not looked at the "main" patch in the series that adds all of the > probing and structures for representing this info yet beyond a cursory > glance, but it feels like we're duplicating a bunch of infrastructure > here before it is necessary. The IDs are all internal to Linux, so I'd > rather we kept everything in the same structure until we have more than > a handful of vendor extensions. With this patch (and the theadpmu stuff) > we will have three vendor extensions which feels like a drop in the > bucket compared to the standard ones. It is not duplicating infrastructure. If we merge this into the existing infrastructure, we would be littering if (ext > RISCV_ISA_VENDOR_EXT_BASE) in __riscv_isa_extension_available. This is particularily important exactly because we have so few vendor extensions currently so this check would be irrelevant in the vast majority of cases. It is also unecessary to push off the refactoring until we have some "sufficient" amount of vendor extensions to deem changing the infrastructure when I already have the patch available here. This does not introduce any extra overhead to existing functions and will be able to support vendors into the future. - Charlie > > > > --- > > arch/riscv/include/asm/cpufeature.h | 54 +++++++++++++++++++++++++++++++++++++ > > arch/riscv/kernel/cpufeature.c | 34 ++++++++++++++++++++--- > > 2 files changed, 84 insertions(+), 4 deletions(-) > > > > diff --git a/arch/riscv/include/asm/cpufeature.h b/arch/riscv/include/asm/cpufeature.h > > index db2ab037843a..8f19e3681b4f 100644 > > --- a/arch/riscv/include/asm/cpufeature.h > > +++ b/arch/riscv/include/asm/cpufeature.h > > @@ -89,6 +89,10 @@ bool __riscv_isa_extension_available(const unsigned long *isa_bitmap, unsigned i > > #define riscv_isa_extension_available(isa_bitmap, ext) \ > > __riscv_isa_extension_available(isa_bitmap, RISCV_ISA_EXT_##ext) > > > > +bool __riscv_isa_vendor_extension_available(const unsigned long *vendor_isa_bitmap, unsigned int bit); > > +#define riscv_isa_vendor_extension_available(isa_bitmap, ext) \ > > + __riscv_isa_vendor_extension_available(isa_bitmap, RISCV_ISA_VENDOR_EXT_##ext) > > + > > static __always_inline bool > > __riscv_has_extension_likely_alternatives(const unsigned long ext) > > { > > @@ -117,6 +121,8 @@ __riscv_has_extension_unlikely_alternatives(const unsigned long ext) > > return true; > > } > > > > +/* Standard extension helpers */ > > + > > static __always_inline bool > > riscv_has_extension_likely(const unsigned long ext) > > { > > @@ -163,4 +169,52 @@ static __always_inline bool riscv_cpu_has_extension_unlikely(int cpu, const unsi > > return __riscv_isa_extension_available(hart_isa[cpu].isa, ext); > > } > > > > +/* Vendor extension helpers */ > > + > > +static __always_inline bool > > +riscv_has_vendor_extension_likely(const unsigned long ext) > > +{ > > + compiletime_assert(ext < RISCV_ISA_VENDOR_EXT_MAX, > > + "ext must be < RISCV_ISA_VENDOR_EXT_MAX"); > > + > > + if (IS_ENABLED(CONFIG_RISCV_ALTERNATIVE)) > > + return __riscv_has_extension_likely_alternatives(ext); > > + else > > + return __riscv_isa_vendor_extension_available(NULL, ext); > > +} > > + > > +static __always_inline bool > > +riscv_has_vendor_extension_unlikely(const unsigned long ext) > > +{ > > + compiletime_assert(ext < RISCV_ISA_VENDOR_EXT_MAX, > > + "ext must be < RISCV_ISA_VENDOR_EXT_MAX"); > > + > > + if (IS_ENABLED(CONFIG_RISCV_ALTERNATIVE)) > > + return __riscv_has_extension_unlikely_alternatives(ext); > > + else > > + return __riscv_isa_vendor_extension_available(NULL, ext); > > +} > > + > > +static __always_inline bool riscv_cpu_has_vendor_extension_likely(int cpu, const unsigned long ext) > > +{ > > + compiletime_assert(ext < RISCV_ISA_VENDOR_EXT_MAX, > > + "ext must be < RISCV_ISA_VENDOR_EXT_MAX"); > > + > > + if (IS_ENABLED(CONFIG_RISCV_ALTERNATIVE)) > > + return __riscv_has_extension_likely_alternatives(ext); > > + else > > + return __riscv_isa_vendor_extension_available(hart_isa_vendor[cpu].isa, ext); > > +} > > + > > +static __always_inline bool riscv_cpu_has_vendor_extension_unlikely(int cpu, const unsigned long ext) > > +{ > > + compiletime_assert(ext < RISCV_ISA_VENDOR_EXT_MAX, > > + "ext must be < RISCV_ISA_VENDOR_EXT_MAX"); > > + > > + if (IS_ENABLED(CONFIG_RISCV_ALTERNATIVE)) > > + return __riscv_has_extension_unlikely_alternatives(ext); > > + else > > + return __riscv_isa_vendor_extension_available(hart_isa_vendor[cpu].isa, ext); > > +} > > Same stuff about constant folding applies to these, I think these should > just mirror the existing functions (if needed at all). > > Cheers, > Conor.