Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 9 Feb 2023 07:56:48 GMT
From:      Dmitry Chagin <dchagin@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: b69b287a0969 - stable/13 - linux(4): Microoptimize rt_sendsig() on amd64.
Message-ID:  <202302090756.3197umDM093023@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by dchagin:

URL: https://cgit.FreeBSD.org/src/commit/?id=b69b287a0969b9dd27a3184b2141e9a580a64535

commit b69b287a0969b9dd27a3184b2141e9a580a64535
Author:     Dmitry Chagin <dchagin@FreeBSD.org>
AuthorDate: 2023-02-02 17:21:37 +0000
Commit:     Dmitry Chagin <dchagin@FreeBSD.org>
CommitDate: 2023-02-09 07:55:24 +0000

    linux(4): Microoptimize rt_sendsig() on amd64.
    
    Drop proc lock earlier, before copying user stuff.
    
    Pointed out by:         kib
    Reviewed by:            kib
    Differential Revision:  https://reviews.freebsd.org/D38326
    MFC after:              1 week
    
    (cherry picked from commit 6ad07a4b2bdf0856545ff8495a7b3396695814fa)
---
 sys/amd64/linux/linux_sysvec.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/sys/amd64/linux/linux_sysvec.c b/sys/amd64/linux/linux_sysvec.c
index 9e36f8739556..d7e33ccb8b70 100644
--- a/sys/amd64/linux/linux_sysvec.c
+++ b/sys/amd64/linux/linux_sysvec.c
@@ -464,16 +464,29 @@ linux_rt_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
 	LINUX_CTR4(rt_sendsig, "%p, %d, %p, %u",
 	    catcher, sig, mask, code);
 
-	/* Save user context. */
 	bzero(&sf, sizeof(sf));
-	bsd_to_linux_sigset(mask, &sf.sf_uc.uc_sigmask);
-	sf.sf_uc.uc_mcontext.sc_mask = sf.sf_uc.uc_sigmask;
-
 	sf.sf_uc.uc_stack.ss_sp = PTROUT(td->td_sigstk.ss_sp);
 	sf.sf_uc.uc_stack.ss_size = td->td_sigstk.ss_size;
 	sf.sf_uc.uc_stack.ss_flags = (td->td_pflags & TDP_ALTSTACK)
 	    ? ((oonstack) ? LINUX_SS_ONSTACK : 0) : LINUX_SS_DISABLE;
 
+	/* Allocate space for the signal handler context. */
+	if ((td->td_pflags & TDP_ALTSTACK) != 0 && !oonstack &&
+	    SIGISMEMBER(psp->ps_sigonstack, sig)) {
+		sp = (caddr_t)td->td_sigstk.ss_sp + td->td_sigstk.ss_size;
+	} else
+		sp = (caddr_t)regs->tf_rsp - 128;
+
+	mtx_unlock(&psp->ps_mtx);
+	PROC_UNLOCK(p);
+
+	/* Make room, keeping the stack aligned. */
+	sp -= sizeof(struct l_rt_sigframe);
+	sfp = (struct l_rt_sigframe *)((unsigned long)sp & ~0xFul);
+
+	/* Save user context. */
+	bsd_to_linux_sigset(mask, &sf.sf_uc.uc_sigmask);
+	sf.sf_uc.uc_mcontext.sc_mask   = sf.sf_uc.uc_sigmask;
 	sf.sf_uc.uc_mcontext.sc_rdi    = regs->tf_rdi;
 	sf.sf_uc.uc_mcontext.sc_rsi    = regs->tf_rsi;
 	sf.sf_uc.uc_mcontext.sc_rdx    = regs->tf_rdx;
@@ -497,19 +510,6 @@ linux_rt_sendsig(sig_t catcher, ksiginfo_t *ksi, sigset_t *mask)
 	sf.sf_uc.uc_mcontext.sc_trapno = bsd_to_linux_trapcode(code);
 	sf.sf_uc.uc_mcontext.sc_cr2    = (register_t)ksi->ksi_addr;
 
-	/* Allocate space for the signal handler context. */
-	if ((td->td_pflags & TDP_ALTSTACK) != 0 && !oonstack &&
-	    SIGISMEMBER(psp->ps_sigonstack, sig)) {
-		sp = (caddr_t)td->td_sigstk.ss_sp + td->td_sigstk.ss_size;
-	} else
-		sp = (caddr_t)regs->tf_rsp - 128;
-	sp -= sizeof(struct l_rt_sigframe);
-	/* Align to 16 bytes. */
-	sfp = (struct l_rt_sigframe *)((unsigned long)sp & ~0xFul);
-
-	mtx_unlock(&psp->ps_mtx);
-	PROC_UNLOCK(p);
-
 	get_fpcontext(td, &mc, NULL, NULL);
 	KASSERT(mc.mc_fpformat != _MC_FPFMT_NODEV, ("fpu not present"));
 	svfp = (struct savefpu *)mc.mc_fpstate;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202302090756.3197umDM093023>