Message ID | 20231221070449.1809020-1-songshuaishuai@tinylab.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-7917-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2483:b0:fb:cd0c:d3e with SMTP id q3csp235253dyi; Wed, 20 Dec 2023 23:08:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IGBMywo68rJlcU7eQwIwwTgAKyJDmrvuDgzrq9oVGAW7rCXEmXfqEpgMnv2rp96aR9Co42Q X-Received: by 2002:a05:622a:1ca:b0:427:8aa6:80ec with SMTP id t10-20020a05622a01ca00b004278aa680ecmr2957020qtw.34.1703142516059; Wed, 20 Dec 2023 23:08:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703142516; cv=none; d=google.com; s=arc-20160816; b=WPfoEURx+T6Fkrm61A3K/pdzG3kM7j0xS9HLJ9EQlGeIeC5rIGIb9WNQf3ZLpimLW4 EPozQTmLLlcV8s12DmtzO+sjG3357/V1noRxGRkVnNfmTOiLyi9Ei2X2erE13NT4hLnQ 4llT3fpfAcOPwt2wA1erlF8+OMY3wB8koxCrWEjNZR+RwDS1uyRlfxJMypQ8tKOX1qhF DMeNHrjkcPkSUJs5N14eQh0dNzBI9Fqfw3a6i/VTmjwDeriXedBSN7Z5kQfPK5r7t+fE EF6Z8KjIqY6iisSSbV7qCNlzpqHS+1hC+QYBLv9hZXX4hIsmq2mbHeF1MK9AB302GteP cjXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=feedback-id:content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from; bh=2kCpclMViSGlwXrSv3CtFtlNcJ4mho2Ep2ftdnuTju8=; fh=LcwsEwUc0nskXWIisAZlnFARUuQjme5qsFxrcuddZeU=; b=diWUBYHb+5XSQmhnGEMxZxPaMfyU6XHlKe+X+HBlbICd8gdzb7O4JudhJ8QO/gnKGV nzwsLwE41eeNdeJ9RWEDt6kvYxlP+oTPAl9xgO1OPQQJQ91DW0Rxn7gUKFXwZHFExJEr kWY/A5yE/tTTGbDIEV7NCm5hVJHs5djdoZVychiykG4VYDmf7YDQMtbxeMka1WJWw7om vV4CQ9lO/BbvzV63Ugu/Vm3gMnjDwOQ13EiWleliDXXA2dM79TrygryWOHdH5/DjW0DD /5pQbNga18gv1fucRe6K+KsHRH6RBwM4QHbADB0yDoXVGKAoJCYH0a6BubT8KhuqA6ER GVWw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-7917-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7917-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id v17-20020a05622a145100b00423735315c3si1576575qtx.179.2023.12.20.23.08.35 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 23:08:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-7917-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-7917-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7917-ouuuleilei=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 B09E31C22B5F for <ouuuleilei@gmail.com>; Thu, 21 Dec 2023 07:08:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 11EC414AB5; Thu, 21 Dec 2023 07:08:21 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) (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 4881114F8B for <linux-kernel@vger.kernel.org>; Thu, 21 Dec 2023 07:08:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=tinylab.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=tinylab.org X-QQ-mid: bizesmtp72t1703142306tblaxfeg Received: from localhost.localdomain ( [58.240.82.166]) by bizesmtp.qq.com (ESMTP) with id ; Thu, 21 Dec 2023 15:05:03 +0800 (CST) X-QQ-SSF: 01200000000000B0B000000A0000000 X-QQ-FEAT: 90EFqYDyPxDH2HniTLYrCGVM0lzrYT3J1RBkPF9OpvfqEomvd8LqAX4a2tFyP xSskE1SPFeB1dab/nMJmmyK4Y9eJfkhfxTN0p1KXoy1nOMYslvqKxIyVlwSEdJqNvOCLDKF XgQjKtBH6p+699LlifhZnx/2Idjh20GPiIVkwyMC/YeBMf+kAXAMnlTWMAGy3JthyNUPf4X Ft7TWogOJrWFV8LOOodC4XwVZntDYS2OxioYlfK5J/FJ2gHyayBMBSZyYpwv8pqHwalauHu JXdc1ul8HXjoERHkBWfjEK+Gnx8f1iQEs/0MrQwSOarrEwGRQYFUSBTCh58CrslSZtFUWVB /kU/RXtpsjPVKXkEIjE2v9uqMsUT7k08Os/cDOx X-QQ-GoodBg: 0 X-BIZMAIL-ID: 7023690611978233006 From: Song Shuai <songshuaishuai@tinylab.org> To: paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, andy.chiu@sifive.com, greentime.hu@sifive.com, conor.dooley@microchip.com, guoren@kernel.org, songshuaishuai@tinylab.org, bjorn@rivosinc.com, xiao.w.wang@intel.com, heiko@sntech.de, ruinland.tsai@sifive.com Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] riscv: vector: Check SR_SD before saving vstate Date: Thu, 21 Dec 2023 15:04:49 +0800 Message-Id: <20231221070449.1809020-1-songshuaishuai@tinylab.org> X-Mailer: git-send-email 2.20.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz4a-0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785874366668850137 X-GMAIL-MSGID: 1785874366668850137 |
Series |
riscv: vector: Check SR_SD before saving vstate
|
|
Commit Message
Song Shuai
Dec. 21, 2023, 7:04 a.m. UTC
The SD bit summarizes the dirty states of FS, VS, or XS fields,
providing a "fast check" before saving fstate or vstate.
Let __switch_to_vector() check SD bit as __switch_to_fpu() does.
Fixes: 3a2df6323def ("riscv: Add task switch support for vector")
Signed-off-by: Song Shuai <songshuaishuai@tinylab.org>
---
arch/riscv/include/asm/vector.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
Comments
> -----Original Message----- > From: Song Shuai <songshuaishuai@tinylab.org> > Sent: Thursday, December 21, 2023 3:05 PM > To: paul.walmsley@sifive.com; palmer@dabbelt.com; > aou@eecs.berkeley.edu; andy.chiu@sifive.com; greentime.hu@sifive.com; > conor.dooley@microchip.com; guoren@kernel.org; > songshuaishuai@tinylab.org; bjorn@rivosinc.com; Wang, Xiao W > <xiao.w.wang@intel.com>; heiko@sntech.de; ruinland.tsai@sifive.com > Cc: linux-riscv@lists.infradead.org; linux-kernel@vger.kernel.org > Subject: [PATCH] riscv: vector: Check SR_SD before saving vstate > > The SD bit summarizes the dirty states of FS, VS, or XS fields, > providing a "fast check" before saving fstate or vstate. > > Let __switch_to_vector() check SD bit as __switch_to_fpu() does. It looks a duplication of status check since the __switch_to_*() internally will check the ext specific status bit. Can we just remove SR_SD check for the fpu() case? BRs, Xiao > > Fixes: 3a2df6323def ("riscv: Add task switch support for vector") > Signed-off-by: Song Shuai <songshuaishuai@tinylab.org> > --- > arch/riscv/include/asm/vector.h | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/arch/riscv/include/asm/vector.h b/arch/riscv/include/asm/vector.h > index 87aaef656257..d30fa56f67c6 100644 > --- a/arch/riscv/include/asm/vector.h > +++ b/arch/riscv/include/asm/vector.h > @@ -190,7 +190,8 @@ static inline void __switch_to_vector(struct > task_struct *prev, > struct pt_regs *regs; > > regs = task_pt_regs(prev); > - riscv_v_vstate_save(prev, regs); > + if (unlikely(regs->status & SR_SD)) > + riscv_v_vstate_save(prev, regs); > riscv_v_vstate_restore(next, task_pt_regs(next)); > } > > -- > 2.20.1
On Thu, Dec 21, 2023 at 3:37 PM Wang, Xiao W <xiao.w.wang@intel.com> wrote: > > > > > -----Original Message----- > > From: Song Shuai <songshuaishuai@tinylab.org> > > Sent: Thursday, December 21, 2023 3:05 PM > > To: paul.walmsley@sifive.com; palmer@dabbelt.com; > > aou@eecs.berkeley.edu; andy.chiu@sifive.com; greentime.hu@sifive.com; > > conor.dooley@microchip.com; guoren@kernel.org; > > songshuaishuai@tinylab.org; bjorn@rivosinc.com; Wang, Xiao W > > <xiao.w.wang@intel.com>; heiko@sntech.de; ruinland.tsai@sifive.com > > Cc: linux-riscv@lists.infradead.org; linux-kernel@vger.kernel.org > > Subject: [PATCH] riscv: vector: Check SR_SD before saving vstate > > > > The SD bit summarizes the dirty states of FS, VS, or XS fields, > > providing a "fast check" before saving fstate or vstate. > > > > Let __switch_to_vector() check SD bit as __switch_to_fpu() does. > > It looks a duplication of status check since the __switch_to_*() internally will check the ext specific status bit. > Can we just remove SR_SD check for the fpu() case? Hi, I came to the same question when adding the Vector context switch. I think the better solution is to skip saving both fpu and vector if the SD is clear. However, this may make code less maintainable because fpu and vector code are scattered and we must mix code together by doing that. Also, we will have to duplicate has_fpu and has_vector check because of the branch dependency e.g. if (likely((regs->status & SR_SD))) { if (has_fpu()) fstate_save() if (has_vector()) vstate_save() } if (has_fpu()) <--- duplicated check (nop) fstate_restore() if (has_vector()) <--- same vstate_restore() So, it really is "Is it worth to trade extra nop with SR_SD that potentially skip one SR_*S check" Besides, with user space libraries start embracing Vector, I don't expect SR_SD would be in "cleared" state very often. Though I haven't done any real-world experiment yet. > > BRs, > Xiao > > > > > Fixes: 3a2df6323def ("riscv: Add task switch support for vector") > > Signed-off-by: Song Shuai <songshuaishuai@tinylab.org> > > --- > > arch/riscv/include/asm/vector.h | 3 ++- > > 1 file changed, 2 insertions(+), 1 deletion(-) > > > > diff --git a/arch/riscv/include/asm/vector.h b/arch/riscv/include/asm/vector.h > > index 87aaef656257..d30fa56f67c6 100644 > > --- a/arch/riscv/include/asm/vector.h > > +++ b/arch/riscv/include/asm/vector.h > > @@ -190,7 +190,8 @@ static inline void __switch_to_vector(struct > > task_struct *prev, > > struct pt_regs *regs; > > > > regs = task_pt_regs(prev); > > - riscv_v_vstate_save(prev, regs); > > + if (unlikely(regs->status & SR_SD)) > > + riscv_v_vstate_save(prev, regs); > > riscv_v_vstate_restore(next, task_pt_regs(next)); > > } > > > > -- > > 2.20.1 > Thanks, Andy
Hello: This patch was applied to riscv/linux.git (for-next) by Palmer Dabbelt <palmer@rivosinc.com>: On Thu, 21 Dec 2023 15:04:49 +0800 you wrote: > The SD bit summarizes the dirty states of FS, VS, or XS fields, > providing a "fast check" before saving fstate or vstate. > > Let __switch_to_vector() check SD bit as __switch_to_fpu() does. > > Fixes: 3a2df6323def ("riscv: Add task switch support for vector") > Signed-off-by: Song Shuai <songshuaishuai@tinylab.org> > > [...] Here is the summary with links: - riscv: vector: Check SR_SD before saving vstate https://git.kernel.org/riscv/c/e1b76bc00ed1 You are awesome, thank you!
Hi Palmer, On Thu, Jan 11, 2024 at 10:50 PM <patchwork-bot+linux-riscv@kernel.org> wrote: > > Hello: > > This patch was applied to riscv/linux.git (for-next) IIUC the conclusion for this thread is not to check SD bit for either vector or fpu. The patch for this was sent together with the kernel-mode vector series and has been reviewed-by both Song and Guo. > by Palmer Dabbelt <palmer@rivosinc.com>: > > On Thu, 21 Dec 2023 15:04:49 +0800 you wrote: > > The SD bit summarizes the dirty states of FS, VS, or XS fields, > > providing a "fast check" before saving fstate or vstate. > > > > Let __switch_to_vector() check SD bit as __switch_to_fpu() does. > > > > Fixes: 3a2df6323def ("riscv: Add task switch support for vector") > > Signed-off-by: Song Shuai <songshuaishuai@tinylab.org> > > > > [...] > > Here is the summary with links: > - riscv: vector: Check SR_SD before saving vstate > https://git.kernel.org/riscv/c/e1b76bc00ed1 > > You are awesome, thank you! > -- > Deet-doot-dot, I am a bot. > https://korg.docs.kernel.org/patchwork/pwbot.html > > Please let me know if I missed anything. Thanks, Andy
On Thu, 11 Jan 2024 07:16:06 PST (-0800), andy.chiu@sifive.com wrote: > Hi Palmer, > > On Thu, Jan 11, 2024 at 10:50 PM <patchwork-bot+linux-riscv@kernel.org> wrote: >> >> Hello: >> >> This patch was applied to riscv/linux.git (for-next) > > IIUC the conclusion for this thread is not to check SD bit for either > vector or fpu. The patch for this was sent together with the > kernel-mode vector series and has been reviewed-by both Song and Guo. > >> by Palmer Dabbelt <palmer@rivosinc.com>: >> >> On Thu, 21 Dec 2023 15:04:49 +0800 you wrote: >> > The SD bit summarizes the dirty states of FS, VS, or XS fields, >> > providing a "fast check" before saving fstate or vstate. >> > >> > Let __switch_to_vector() check SD bit as __switch_to_fpu() does. >> > >> > Fixes: 3a2df6323def ("riscv: Add task switch support for vector") >> > Signed-off-by: Song Shuai <songshuaishuai@tinylab.org> >> > >> > [...] >> >> Here is the summary with links: >> - riscv: vector: Check SR_SD before saving vstate >> https://git.kernel.org/riscv/c/e1b76bc00ed1 >> >> You are awesome, thank you! >> -- >> Deet-doot-dot, I am a bot. >> https://korg.docs.kernel.org/patchwork/pwbot.html >> >> > > Please let me know if I missed anything. Sorry, I must have misunderstood. I'm dropping it.
diff --git a/arch/riscv/include/asm/vector.h b/arch/riscv/include/asm/vector.h index 87aaef656257..d30fa56f67c6 100644 --- a/arch/riscv/include/asm/vector.h +++ b/arch/riscv/include/asm/vector.h @@ -190,7 +190,8 @@ static inline void __switch_to_vector(struct task_struct *prev, struct pt_regs *regs; regs = task_pt_regs(prev); - riscv_v_vstate_save(prev, regs); + if (unlikely(regs->status & SR_SD)) + riscv_v_vstate_save(prev, regs); riscv_v_vstate_restore(next, task_pt_regs(next)); }