From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F267DC5AD49 for ; Mon, 26 May 2025 08:41:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=oZ5BGD3L7URdD3Dnqez8ZQuzBp7ZdUq+R6QqNJbTHrs=; b=BzULszHJl4h+KK GCNy/KHWKzQW4u8at8tC0xV+Xr17Ek2ceweP5nYBq0DWujeEACbgKn/uTg/O3ZZjmpayxiULZNGx5 sxoCVIOMD4+I1rC5sKFpPKStQ8fB/wLo2+3CgcanL6WUSR8inosK08C9rbA8VyIGeH5TfYC+lViP8 uobbKpbanPPCWPowiwQGwjcyh8KF9+Bq1ydAX46T0E3b1c1v751REfdncIcTImY/21CXCZDSynu57 o0SZgs8wxLCAaKVFCwm00i9vDO798GixjDTXjgNpCDCDYLOZAsQ8lJw+6/j48uGNnLuwU6j4ON6aK JC/VOLdwMPcz4nNbWs3Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1uJTOu-00000008PeJ-2Fz7; Mon, 26 May 2025 08:41:40 +0000 Received: from mail-ed1-x52b.google.com ([2a00:1450:4864:20::52b]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1uJTOr-00000008Pcm-16Ko for kvm-riscv@lists.infradead.org; Mon, 26 May 2025 08:41:39 +0000 Received: by mail-ed1-x52b.google.com with SMTP id 4fb4d7f45d1cf-6045e69c9a8so2006673a12.3 for ; Mon, 26 May 2025 01:41:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1748248895; x=1748853695; darn=lists.infradead.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=lgi+BI+UxQxxje7YEG6nl3Jn6VhfFhFL9BZoJyhkgXs=; b=mPYrVOXK9HtkBdOjLT+5lR86OVvN2ZNTRm7jIfFYFVxt3CMIatMXupb7d0Iey5FJc7 t2/hhonGLsVprnmxolc0Zl9CkGhQALaZDTcu0wENlhalSF3qRTeSfMGhJu/j6tUkvUSd gHsGTeXyI30WlN4K7+qMKl64kLJaHh5ENmQraF4pETaVipdEbUVFiC1V+NdoLqMt3FYZ jOsgTYN8vQkyffHE6UH4h1D4B9GV81gEtrFFe/ezbIERcdpg0p+KaqRw/xhBbgaHC4Bl mYum7UzC6TbUPfNix5qGSJMuIdHi2C9fNbQiNFm4eaXD9UiXpxbWbKsKZhxOBhSohjpW /1fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748248895; x=1748853695; h=in-reply-to:content-transfer-encoding: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=lgi+BI+UxQxxje7YEG6nl3Jn6VhfFhFL9BZoJyhkgXs=; b=gSCrmiGWCzO76Qyfep6KTBvOC9IU+ou0ZEjwij3pCwV/lFIHEG8OYxM5CW9sdJKEzw FpCA6E9C/+l6rwoVH6yb3a4TLF7Hht3ET8uLn/v1GIM0NsBz8qP7hZdggwmpR+7rVwgi RaTyZIs6F3PHntDaUPbD6FWPSC1kfWzqet2Bf3xGZypZTmj5CrI2DexTaS7fIDdg3vzo FAsAIxPkEDlAOY4P5JAjRyZD2uh9OaUO3EklGMN2Sj8H+bJURw0Y7H4q6uRD5cquCMeL 3gqmdR9aOEit19krsJ0GyWvxcMfV59cqpggX6hxL585nWwONecJzqNytGyWnZxfoPq1S XRiA== X-Forwarded-Encrypted: i=1; AJvYcCW7SfZrnGGqEYSzTOIkGju20ZXkBxZ6eELGsImJVCr5SrUYRzrOYt1w22pMCTCPxiz/RA4+sps4TCc=@lists.infradead.org X-Gm-Message-State: AOJu0Yz/jqs2BhK28F1uSv608tE2bCIdO0mn0bRby1EbyQNtcJ19yz4l UktgPDXrBlxjz7PWJOTwI6ekj0o84NFIYICX0bwEVQLNatypbpMA+JuuGHH0MCZKsi8= X-Gm-Gg: ASbGncvSW4JJ++9xsq5rivsx9TSHQzfjFqKH/+Vhaze53exbTNUtnjrhzA5ZIcRnQEr A6t6zcYOhPx8dp8CCZBI3KZdCmRgft9/U7zoS4WoVwVAz4gCMUOE3ywrkEFY+DistB7vO5bK45z cPf2i+PIPgh/43ot8Pxng8FN07+s1YFrO53UDhKtcEKFvdHOAGUE4U8B87rxu3Jzrj42U0qYP1K QpwQpQzu/0JCcdaPwb7okMHCkUIj7zyloKXypQHgjWsV1VCobmcA8wYx2wHa+M+3mCk3P51VWsy R3wJa5XrMxD1UhAB/m5BBYSk/I9LWC+v7+xgBAUvrX0LlNspp92dq9mSetxRZo+XZZyfTcjAdC6 vGhy3 X-Google-Smtp-Source: AGHT+IG8/VYDbfxt/MCOP+EaLwsXzbrnjfrXlbSUZYq06meSDTM4WfgPl2nsylybH23Wd9Lf5xvIZg== X-Received: by 2002:a05:6402:4404:b0:602:1b8b:2902 with SMTP id 4fb4d7f45d1cf-602d9bf086amr6150523a12.15.1748248894652; Mon, 26 May 2025 01:41:34 -0700 (PDT) Received: from localhost (cst2-173-28.cust.vodafone.cz. [31.30.173.28]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-604b79dc22fsm1148466a12.14.2025.05.26.01.41.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 May 2025 01:41:34 -0700 (PDT) Date: Mon, 26 May 2025 10:41:33 +0200 From: Andrew Jones To: =?utf-8?B?Q2zDqW1lbnQgTMOpZ2Vy?= Cc: Charlie Jenkins , Paul Walmsley , Palmer Dabbelt , Anup Patel , Atish Patra , Shuah Khan , Jonathan Corbet , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org, Samuel Holland , Deepak Gupta Subject: Re: [PATCH v8 09/14] riscv: misaligned: move emulated access uniformity check in a function Message-ID: <20250526-baaca3f03adcac2b6488f040@orel> References: <20250523101932.1594077-1-cleger@rivosinc.com> <20250523101932.1594077-10-cleger@rivosinc.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250526_014137_305126_B05100F3 X-CRM114-Status: GOOD ( 31.91 ) X-BeenThere: kvm-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Sender: "kvm-riscv" Errors-To: kvm-riscv-bounces+kvm-riscv=archiver.kernel.org@lists.infradead.org On Fri, May 23, 2025 at 09:21:51PM +0200, Cl=E9ment L=E9ger wrote: > = > = > On 23/05/2025 20:30, Charlie Jenkins wrote: > > On Fri, May 23, 2025 at 12:19:26PM +0200, Cl=E9ment L=E9ger wrote: > >> Split the code that check for the uniformity of misaligned accesses > >> performance on all cpus from check_unaligned_access_emulated_all_cpus() > >> to its own function which will be used for delegation check. No > >> functional changes intended. > >> > >> Signed-off-by: Cl=E9ment L=E9ger > >> Reviewed-by: Andrew Jones > >> --- > >> arch/riscv/kernel/traps_misaligned.c | 20 ++++++++++++++------ > >> 1 file changed, 14 insertions(+), 6 deletions(-) > >> > >> diff --git a/arch/riscv/kernel/traps_misaligned.c b/arch/riscv/kernel/= traps_misaligned.c > >> index f1b2af515592..7ecaa8103fe7 100644 > >> --- a/arch/riscv/kernel/traps_misaligned.c > >> +++ b/arch/riscv/kernel/traps_misaligned.c > >> @@ -645,6 +645,18 @@ bool __init check_vector_unaligned_access_emulate= d_all_cpus(void) > >> } > >> #endif > >> = > >> +static bool all_cpus_unaligned_scalar_access_emulated(void) > >> +{ > >> + int cpu; > >> + > >> + for_each_online_cpu(cpu) > >> + if (per_cpu(misaligned_access_speed, cpu) !=3D > >> + RISCV_HWPROBE_MISALIGNED_SCALAR_EMULATED) > >> + return false; > >> + > >> + return true; > >> +} > > = > > This ends up wasting time when !CONFIG_RISCV_SCALAR_MISALIGNED since it > > will always return false in that case. Maybe there is a way to simplify > > the ifdefs and still have performant code, but I don't think this is a > > big enough problem to prevent this patch from merging. > = > Yeah I though of that as well but the amount of call to this function is > probably well below 10 times so I guess it does not really matters in > that case to justify yet another ifdef ? Would it need an ifdef? Or can we just do if (!IS_ENABLED(CONFIG_RISCV_SCALAR_MISALIGNED)) return false; at the top of the function? While the function wouldn't waste much time since it's not called much and would return false on the first check done in the loop, since it's a static function, adding the IS_ENABLED() check would likely allow the compiler to completely remove it and all the branches depending on it. Thanks, drew > = > > = > > Reviewed-by: Charlie Jenkins > > Tested-by: Charlie Jenkins > = > Thanks, > = > Cl=E9ment > = > > = > >> + > >> #ifdef CONFIG_RISCV_SCALAR_MISALIGNED > >> = > >> static bool unaligned_ctl __read_mostly; > >> @@ -683,8 +695,6 @@ static int cpu_online_check_unaligned_access_emula= ted(unsigned int cpu) > >> = > >> bool __init check_unaligned_access_emulated_all_cpus(void) > >> { > >> - int cpu; > >> - > >> /* > >> * We can only support PR_UNALIGN controls if all CPUs have misalign= ed > >> * accesses emulated since tasks requesting such control can run on = any > >> @@ -692,10 +702,8 @@ bool __init check_unaligned_access_emulated_all_c= pus(void) > >> */ > >> on_each_cpu(check_unaligned_access_emulated, NULL, 1); > >> = > >> - for_each_online_cpu(cpu) > >> - if (per_cpu(misaligned_access_speed, cpu) > >> - !=3D RISCV_HWPROBE_MISALIGNED_SCALAR_EMULATED) > >> - return false; > >> + if (!all_cpus_unaligned_scalar_access_emulated()) > >> + return false; > >> = > >> unaligned_ctl =3D true; > >> return true; > >> -- = > >> 2.49.0 > >> > = -- = kvm-riscv mailing list kvm-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/kvm-riscv From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) (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 EC010158DD4 for ; Mon, 26 May 2025 08:41:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748248898; cv=none; b=XDNPS7jI1Q6+2NQF0PWRPPJNwyLcV2QF3FNd4W1bY3X4IISs9KHBI5H5bMfYBnqNRy7tVl910vc8ZsnkiKdcwIcHmieTV+U27FwNn4667eO9udTKBHXdXpAonjnHzIDeq3sYN4fs2LoWtX59t82aehNVbA+hAIRj2t1RtTZ0WNQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748248898; c=relaxed/simple; bh=AfxOAmXX1HdyQc0nVIo6KqK7evO8C9QirK7XVJr4/KY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bjc5u82hGop6LfLiD8C39QRRJAAsKfApterCX2Q/4+GD9U4CJNafNTIw1k/bs0JbglyhMqwO8V6qV1RIHfVuddKwIQYFm2wjC2NbVOYcD67FocyQQs5RaBLU6KaMRsjj9Gx+VTpiQjhbT+tfxKmbv7t+SQE/DYMqf31+aVlA/zA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com; spf=pass smtp.mailfrom=ventanamicro.com; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b=IS2wliyk; arc=none smtp.client-ip=209.85.208.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ventanamicro.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ventanamicro.com header.i=@ventanamicro.com header.b="IS2wliyk" Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-602e203db66so2672161a12.1 for ; Mon, 26 May 2025 01:41:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1748248895; x=1748853695; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=lgi+BI+UxQxxje7YEG6nl3Jn6VhfFhFL9BZoJyhkgXs=; b=IS2wliykKG0JexCU4dAuudzmJDVbE//5gSgXk16sewo1lWnES+4bQtkGITnENjAUtu Q83sWWdR+5JmPjg/k6zDofVl3ZAL88VJq8AzewWF8IUMLizCdOmAunLIpV5udJGxjquZ yGVjlFfNGx2c5cnhprO+f3zZXGzieiDPl0EYohxwcl8yaCxNH58gFpcmRV24cwIKQvLd 2HsCk5vKoe6hcjNl1Le08FUTAsaYFe1/p4sj2xB2ACkvcHo0RktKonXTtHBfbo3qsvlm oKnB9zwYhXDCWC+XtrB4SIliiI9aE0sx/VZpD1c/baDa3ci1WdmPThLHu63aPRr6UauO FMEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748248895; x=1748853695; h=in-reply-to:content-transfer-encoding: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=lgi+BI+UxQxxje7YEG6nl3Jn6VhfFhFL9BZoJyhkgXs=; b=Mt1fLNDJOYNSH3bX0K+nqhe62WfFeFD0BXCTBR2dJURMS4zhuDWiDynBAJmZaclV1k Cupit/5E5FIXrc6COSKkDBQKUJOodCvMkT9QT1bYtoM57P+sABHGBLkWYDMlGRKtp9pf uL598G8ztBcipSOle6FTPH8CjO8j0luZjggacunaWVGCVY5aDiwrelnXIom7Y0m1DGIt AIWvcA1Jp2LAZSseYZH7YYUnuEqk1aLhcQT+k47NFvLTUjRO/qzAmDUhacvnQhppr5oS ijpSN2O2qPl4XMV5+/oRdymN6+/uE8YLTt9VJxmJmrr/3N5M8X6IPL/MKzFquUIeJ7Vf W5ew== X-Forwarded-Encrypted: i=1; AJvYcCXt1Pr8zyrK56+vIdXfXw2s95UAvjUesnbsUj7/WQq+MHWXALgS+alyNbnwXDaJT12hdAs=@vger.kernel.org X-Gm-Message-State: AOJu0Ywbra3NAMV2QvqYeDnRKUUms34fYX+mYukx0tuxyBXrVbVEo1tM JOJMO/j9+KzGaiESk5EeTpdik2ct9E5x4aIz6h42VtqAd8KdWnHWZC6umFG+G46oIiU= X-Gm-Gg: ASbGncsqrJH/r89ABJC0+Ay+GDl3oqAjfNj1Mw4nsNWbIF6ghzVY9t0fmBKxOWtdon5 SrpPyQ2KAQIezB1WfUIY9MLWU6H3dKQQp5HuGqrsVCB4z0ITWBAvByEDQGNQ/Q5PDziJf5mu516 b33K12eJilOFIgZ67B4eRM8UNq+n+skIDXll1bgNbxgrBYinOb9JHp3sU4Rnzwq0yTZHfZ9dCJ7 D/5v8o30bq0Sgo96cdv8EK/oHG5QqNZsKH3+Y2EogGjPMWf20Nhc+46SjxcZIJHV02dV/1x+CE0 VF1Ox+qHnUz7TTGM9NHPIVqrBYbDEklaAqFYt0nCnEBzWv7Pfz2tWhboWKRfCqqd9lDJeap5AGB LTSKj X-Google-Smtp-Source: AGHT+IG8/VYDbfxt/MCOP+EaLwsXzbrnjfrXlbSUZYq06meSDTM4WfgPl2nsylybH23Wd9Lf5xvIZg== X-Received: by 2002:a05:6402:4404:b0:602:1b8b:2902 with SMTP id 4fb4d7f45d1cf-602d9bf086amr6150523a12.15.1748248894652; Mon, 26 May 2025 01:41:34 -0700 (PDT) Received: from localhost (cst2-173-28.cust.vodafone.cz. [31.30.173.28]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-604b79dc22fsm1148466a12.14.2025.05.26.01.41.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 May 2025 01:41:34 -0700 (PDT) Date: Mon, 26 May 2025 10:41:33 +0200 From: Andrew Jones To: =?utf-8?B?Q2zDqW1lbnQgTMOpZ2Vy?= Cc: Charlie Jenkins , Paul Walmsley , Palmer Dabbelt , Anup Patel , Atish Patra , Shuah Khan , Jonathan Corbet , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org, Samuel Holland , Deepak Gupta Subject: Re: [PATCH v8 09/14] riscv: misaligned: move emulated access uniformity check in a function Message-ID: <20250526-baaca3f03adcac2b6488f040@orel> References: <20250523101932.1594077-1-cleger@rivosinc.com> <20250523101932.1594077-10-cleger@rivosinc.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Fri, May 23, 2025 at 09:21:51PM +0200, Clément Léger wrote: > > > On 23/05/2025 20:30, Charlie Jenkins wrote: > > On Fri, May 23, 2025 at 12:19:26PM +0200, Clément Léger wrote: > >> Split the code that check for the uniformity of misaligned accesses > >> performance on all cpus from check_unaligned_access_emulated_all_cpus() > >> to its own function which will be used for delegation check. No > >> functional changes intended. > >> > >> Signed-off-by: Clément Léger > >> Reviewed-by: Andrew Jones > >> --- > >> arch/riscv/kernel/traps_misaligned.c | 20 ++++++++++++++------ > >> 1 file changed, 14 insertions(+), 6 deletions(-) > >> > >> diff --git a/arch/riscv/kernel/traps_misaligned.c b/arch/riscv/kernel/traps_misaligned.c > >> index f1b2af515592..7ecaa8103fe7 100644 > >> --- a/arch/riscv/kernel/traps_misaligned.c > >> +++ b/arch/riscv/kernel/traps_misaligned.c > >> @@ -645,6 +645,18 @@ bool __init check_vector_unaligned_access_emulated_all_cpus(void) > >> } > >> #endif > >> > >> +static bool all_cpus_unaligned_scalar_access_emulated(void) > >> +{ > >> + int cpu; > >> + > >> + for_each_online_cpu(cpu) > >> + if (per_cpu(misaligned_access_speed, cpu) != > >> + RISCV_HWPROBE_MISALIGNED_SCALAR_EMULATED) > >> + return false; > >> + > >> + return true; > >> +} > > > > This ends up wasting time when !CONFIG_RISCV_SCALAR_MISALIGNED since it > > will always return false in that case. Maybe there is a way to simplify > > the ifdefs and still have performant code, but I don't think this is a > > big enough problem to prevent this patch from merging. > > Yeah I though of that as well but the amount of call to this function is > probably well below 10 times so I guess it does not really matters in > that case to justify yet another ifdef ? Would it need an ifdef? Or can we just do if (!IS_ENABLED(CONFIG_RISCV_SCALAR_MISALIGNED)) return false; at the top of the function? While the function wouldn't waste much time since it's not called much and would return false on the first check done in the loop, since it's a static function, adding the IS_ENABLED() check would likely allow the compiler to completely remove it and all the branches depending on it. Thanks, drew > > > > > Reviewed-by: Charlie Jenkins > > Tested-by: Charlie Jenkins > > Thanks, > > Clément > > > > >> + > >> #ifdef CONFIG_RISCV_SCALAR_MISALIGNED > >> > >> static bool unaligned_ctl __read_mostly; > >> @@ -683,8 +695,6 @@ static int cpu_online_check_unaligned_access_emulated(unsigned int cpu) > >> > >> bool __init check_unaligned_access_emulated_all_cpus(void) > >> { > >> - int cpu; > >> - > >> /* > >> * We can only support PR_UNALIGN controls if all CPUs have misaligned > >> * accesses emulated since tasks requesting such control can run on any > >> @@ -692,10 +702,8 @@ bool __init check_unaligned_access_emulated_all_cpus(void) > >> */ > >> on_each_cpu(check_unaligned_access_emulated, NULL, 1); > >> > >> - for_each_online_cpu(cpu) > >> - if (per_cpu(misaligned_access_speed, cpu) > >> - != RISCV_HWPROBE_MISALIGNED_SCALAR_EMULATED) > >> - return false; > >> + if (!all_cpus_unaligned_scalar_access_emulated()) > >> + return false; > >> > >> unaligned_ctl = true; > >> return true; > >> -- > >> 2.49.0 > >> > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 03038C54FB3 for ; Mon, 26 May 2025 08:41:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=4rZ3sYfIEAuIPbuemU77zPaBd2g3MGP73XQ9TzQszqk=; b=lZSXmJPSCFZFwi wytbaX5RWV0wEeiAnk1YBDJuMRvYCoNdWDFja3clp2oixBK66Km2Diz8521lK60V1ANaK+iCKw4f6 8qfDhgH0spDkz0KP89uxbOdfY+qXBZYy/HnIywdt988gQH6b4GqgYLdF74Xu7TCPuEFzR7szY84Ts I7kdYoqzdo6zpYz5z1MClCefBV3H1rKK4GO2dEST1AYYEYZtHOn7++rDVxtaMc9UFQt49/VgQsizM BYIUx8at1VdAv334YyswZ+fTmMQJc/LFnkagaDDJQoQUgFN2qbg4Seqcu4QJ/1/ra/Z8l6v1Yzg0u LlLw/4rL82rZ2wy+WrRA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1uJTOt-00000008PeC-45mt; Mon, 26 May 2025 08:41:39 +0000 Received: from mail-ed1-x536.google.com ([2a00:1450:4864:20::536]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1uJTOr-00000008Pcn-16RY for linux-riscv@lists.infradead.org; Mon, 26 May 2025 08:41:38 +0000 Received: by mail-ed1-x536.google.com with SMTP id 4fb4d7f45d1cf-60477f1a044so1277839a12.0 for ; Mon, 26 May 2025 01:41:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1748248895; x=1748853695; darn=lists.infradead.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=lgi+BI+UxQxxje7YEG6nl3Jn6VhfFhFL9BZoJyhkgXs=; b=mPYrVOXK9HtkBdOjLT+5lR86OVvN2ZNTRm7jIfFYFVxt3CMIatMXupb7d0Iey5FJc7 t2/hhonGLsVprnmxolc0Zl9CkGhQALaZDTcu0wENlhalSF3qRTeSfMGhJu/j6tUkvUSd gHsGTeXyI30WlN4K7+qMKl64kLJaHh5ENmQraF4pETaVipdEbUVFiC1V+NdoLqMt3FYZ jOsgTYN8vQkyffHE6UH4h1D4B9GV81gEtrFFe/ezbIERcdpg0p+KaqRw/xhBbgaHC4Bl mYum7UzC6TbUPfNix5qGSJMuIdHi2C9fNbQiNFm4eaXD9UiXpxbWbKsKZhxOBhSohjpW /1fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748248895; x=1748853695; h=in-reply-to:content-transfer-encoding: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=lgi+BI+UxQxxje7YEG6nl3Jn6VhfFhFL9BZoJyhkgXs=; b=WUk4tQqpQUaiM5UpKL0tFHV99tEXYGMpP2HikzzkL1wXfP6Vt/XO2rZdj/AKmrzxip CwApLQSy1ErtXd8YaHGFV+Bne7SC8G+gfHqFBGYL3R0DMBhkEnEjlNfQV7CQmwxiLM1+ xf2eXFFNYds5+XtlpCui/rtm7D0+4AlYtnYqtTazQOHpYIZ1TKvQZySMM16k6cNu1spA eM7yWqGTBR+GrpA8ZR+6PjJhLM9noqaxVJwBJaIG1ynBEhgEqWLN+P26ED0zC4+s2xN6 W5SrAUvSHhgHYihKSoBEbjE4+JnfLWVED2JnI2TTZMInRdMvGLzpNG8pche3LTgXnwQc /hrQ== X-Forwarded-Encrypted: i=1; AJvYcCWTD5Yl7zeNv/59VxNmAxej36MF9pHzN9sCku3+NV0nDcVNtb3L0s/So+WJ5++YIroPioS7XnokKkIleA==@lists.infradead.org X-Gm-Message-State: AOJu0Yyska015uFGLXDK7g2rMXJA9bVgRGgP2PDBxt1IHwy0bdqZRcLf UZ/rPqLaQ38BGx7EnR/uo6JLgBGjcCVgBMLGac22DF6IRWOogsSAC6DUjUxm9HpMdN4= X-Gm-Gg: ASbGnctCnQozbyPmIA6O0ouHMjFrgMQbHAVYjnS81+9kYKQFPfPnZ8z9Po7zRCoNEna McaK4GAESXunHRUt2ztB2V0hsY4K9G9wQ/QwC9lXO5xTeYEgIt11qst7EYDCnJRIezpC8pCh+yR ynzDiOMSf4LpTuMkeaV50huIHmTGdAbC9EXs+uqUwnissvahZsCz5s7mOqhOZJnlVRMJOPn9mce i/CI0Cyrv04xi7HImg8ZyA5U8nhyXEsNLvX++bqg9JQnuK/wMQnRsKZ3axMmqkErc5K1U8jlvU2 uyoCgKCLA/JR7fGfn5i0wpZ/ElQZxq9Fe2w1gY2lAcVUYgkNttBJ4Uo3I+TkKFLRBao5LBweZyh SJsbF X-Google-Smtp-Source: AGHT+IG8/VYDbfxt/MCOP+EaLwsXzbrnjfrXlbSUZYq06meSDTM4WfgPl2nsylybH23Wd9Lf5xvIZg== X-Received: by 2002:a05:6402:4404:b0:602:1b8b:2902 with SMTP id 4fb4d7f45d1cf-602d9bf086amr6150523a12.15.1748248894652; Mon, 26 May 2025 01:41:34 -0700 (PDT) Received: from localhost (cst2-173-28.cust.vodafone.cz. [31.30.173.28]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-604b79dc22fsm1148466a12.14.2025.05.26.01.41.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 May 2025 01:41:34 -0700 (PDT) Date: Mon, 26 May 2025 10:41:33 +0200 From: Andrew Jones To: =?utf-8?B?Q2zDqW1lbnQgTMOpZ2Vy?= Cc: Charlie Jenkins , Paul Walmsley , Palmer Dabbelt , Anup Patel , Atish Patra , Shuah Khan , Jonathan Corbet , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org, Samuel Holland , Deepak Gupta Subject: Re: [PATCH v8 09/14] riscv: misaligned: move emulated access uniformity check in a function Message-ID: <20250526-baaca3f03adcac2b6488f040@orel> References: <20250523101932.1594077-1-cleger@rivosinc.com> <20250523101932.1594077-10-cleger@rivosinc.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250526_014137_309246_43E8E87F X-CRM114-Status: GOOD ( 31.91 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org On Fri, May 23, 2025 at 09:21:51PM +0200, Cl=E9ment L=E9ger wrote: > = > = > On 23/05/2025 20:30, Charlie Jenkins wrote: > > On Fri, May 23, 2025 at 12:19:26PM +0200, Cl=E9ment L=E9ger wrote: > >> Split the code that check for the uniformity of misaligned accesses > >> performance on all cpus from check_unaligned_access_emulated_all_cpus() > >> to its own function which will be used for delegation check. No > >> functional changes intended. > >> > >> Signed-off-by: Cl=E9ment L=E9ger > >> Reviewed-by: Andrew Jones > >> --- > >> arch/riscv/kernel/traps_misaligned.c | 20 ++++++++++++++------ > >> 1 file changed, 14 insertions(+), 6 deletions(-) > >> > >> diff --git a/arch/riscv/kernel/traps_misaligned.c b/arch/riscv/kernel/= traps_misaligned.c > >> index f1b2af515592..7ecaa8103fe7 100644 > >> --- a/arch/riscv/kernel/traps_misaligned.c > >> +++ b/arch/riscv/kernel/traps_misaligned.c > >> @@ -645,6 +645,18 @@ bool __init check_vector_unaligned_access_emulate= d_all_cpus(void) > >> } > >> #endif > >> = > >> +static bool all_cpus_unaligned_scalar_access_emulated(void) > >> +{ > >> + int cpu; > >> + > >> + for_each_online_cpu(cpu) > >> + if (per_cpu(misaligned_access_speed, cpu) !=3D > >> + RISCV_HWPROBE_MISALIGNED_SCALAR_EMULATED) > >> + return false; > >> + > >> + return true; > >> +} > > = > > This ends up wasting time when !CONFIG_RISCV_SCALAR_MISALIGNED since it > > will always return false in that case. Maybe there is a way to simplify > > the ifdefs and still have performant code, but I don't think this is a > > big enough problem to prevent this patch from merging. > = > Yeah I though of that as well but the amount of call to this function is > probably well below 10 times so I guess it does not really matters in > that case to justify yet another ifdef ? Would it need an ifdef? Or can we just do if (!IS_ENABLED(CONFIG_RISCV_SCALAR_MISALIGNED)) return false; at the top of the function? While the function wouldn't waste much time since it's not called much and would return false on the first check done in the loop, since it's a static function, adding the IS_ENABLED() check would likely allow the compiler to completely remove it and all the branches depending on it. Thanks, drew > = > > = > > Reviewed-by: Charlie Jenkins > > Tested-by: Charlie Jenkins > = > Thanks, > = > Cl=E9ment > = > > = > >> + > >> #ifdef CONFIG_RISCV_SCALAR_MISALIGNED > >> = > >> static bool unaligned_ctl __read_mostly; > >> @@ -683,8 +695,6 @@ static int cpu_online_check_unaligned_access_emula= ted(unsigned int cpu) > >> = > >> bool __init check_unaligned_access_emulated_all_cpus(void) > >> { > >> - int cpu; > >> - > >> /* > >> * We can only support PR_UNALIGN controls if all CPUs have misalign= ed > >> * accesses emulated since tasks requesting such control can run on = any > >> @@ -692,10 +702,8 @@ bool __init check_unaligned_access_emulated_all_c= pus(void) > >> */ > >> on_each_cpu(check_unaligned_access_emulated, NULL, 1); > >> = > >> - for_each_online_cpu(cpu) > >> - if (per_cpu(misaligned_access_speed, cpu) > >> - !=3D RISCV_HWPROBE_MISALIGNED_SCALAR_EMULATED) > >> - return false; > >> + if (!all_cpus_unaligned_scalar_access_emulated()) > >> + return false; > >> = > >> unaligned_ctl =3D true; > >> return true; > >> -- = > >> 2.49.0 > >> > = _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv