Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 29 Jun 2022 14:54:52 GMT
From:      Andrew Turner <andrew@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: baf8f20a4af4 - main - Split out vfp_new_thread
Message-ID:  <202206291454.25TEsqOx048561@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by andrew:

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

commit baf8f20a4af43283a1fbee49b0c2ad906074f20f
Author:     Andrew Turner <andrew@FreeBSD.org>
AuthorDate: 2022-06-24 11:53:15 +0000
Commit:     Andrew Turner <andrew@FreeBSD.org>
CommitDate: 2022-06-29 14:15:43 +0000

    Split out vfp_new_thread
    
    To keep the vfp thread creation code in one place move into vfp.c. This
    will also help with adding SVE support as it depends on VFP.
    
    Reviewed by:    markj
    Sponsored by:   The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D35615
---
 sys/arm64/arm64/vfp.c        | 26 ++++++++++++++++++++++++++
 sys/arm64/arm64/vm_machdep.c | 10 +++++-----
 sys/arm64/include/vfp.h      |  1 +
 3 files changed, 32 insertions(+), 5 deletions(-)

diff --git a/sys/arm64/arm64/vfp.c b/sys/arm64/arm64/vfp.c
index a481b5ebb3ba..8fc756f8a888 100644
--- a/sys/arm64/arm64/vfp.c
+++ b/sys/arm64/arm64/vfp.c
@@ -199,6 +199,32 @@ vfp_save_state(struct thread *td, struct pcb *pcb)
 	critical_exit();
 }
 
+/*
+ * Update the VFP state for a forked process or new thread. The PCB will
+ * have been copied from the old thread.
+ */
+void
+vfp_new_thread(struct thread *newtd, struct thread *oldtd, bool fork)
+{
+	struct pcb *newpcb;
+
+	newpcb = newtd->td_pcb;
+
+	/* Kernel threads start with clean VFP */
+	if ((oldtd->td_pflags & TDP_KTHREAD) != 0) {
+		newpcb->pcb_fpflags &=
+		    ~(PCB_FP_STARTED | PCB_FP_KERN | PCB_FP_NOSAVE);
+	} else {
+		MPASS((newpcb->pcb_fpflags & (PCB_FP_KERN|PCB_FP_NOSAVE)) == 0);
+		if (!fork) {
+			newpcb->pcb_fpflags &= ~PCB_FP_STARTED;
+		}
+	}
+
+	newpcb->pcb_fpusaved = &newpcb->pcb_fpustate;
+	newpcb->pcb_vfpcpu = UINT_MAX;
+}
+
 /*
  * Reset the FP state to avoid leaking state from the parent process across
  * execve() (and to ensure that we get a consistent floating point environment
diff --git a/sys/arm64/arm64/vm_machdep.c b/sys/arm64/arm64/vm_machdep.c
index feb439314f50..006bf5127d25 100644
--- a/sys/arm64/arm64/vm_machdep.c
+++ b/sys/arm64/arm64/vm_machdep.c
@@ -109,8 +109,8 @@ cpu_fork(struct thread *td1, struct proc *p2, struct thread *td2, int flags)
 	td2->td_pcb->pcb_x[20] = (uintptr_t)td2;
 	td2->td_pcb->pcb_lr = (uintptr_t)fork_trampoline;
 	td2->td_pcb->pcb_sp = (uintptr_t)td2->td_frame;
-	td2->td_pcb->pcb_fpusaved = &td2->td_pcb->pcb_fpustate;
-	td2->td_pcb->pcb_vfpcpu = UINT_MAX;
+
+	vfp_new_thread(td2, td1, true);
 
 	/* Setup to release spin count in fork_exit(). */
 	td2->td_md.md_spinlock_count = 1;
@@ -187,9 +187,9 @@ cpu_copy_thread(struct thread *td, struct thread *td0)
 	td->td_pcb->pcb_x[20] = (uintptr_t)td;
 	td->td_pcb->pcb_lr = (uintptr_t)fork_trampoline;
 	td->td_pcb->pcb_sp = (uintptr_t)td->td_frame;
-	td->td_pcb->pcb_fpflags &= ~(PCB_FP_STARTED | PCB_FP_KERN | PCB_FP_NOSAVE);
-	td->td_pcb->pcb_fpusaved = &td->td_pcb->pcb_fpustate;
-	td->td_pcb->pcb_vfpcpu = UINT_MAX;
+
+	/* Update VFP state for the new thread */
+	vfp_new_thread(td, td0, false);
 
 	/* Setup to release spin count in fork_exit(). */
 	td->td_md.md_spinlock_count = 1;
diff --git a/sys/arm64/include/vfp.h b/sys/arm64/include/vfp.h
index b28c6edf3c53..a450a5f31fdd 100644
--- a/sys/arm64/include/vfp.h
+++ b/sys/arm64/include/vfp.h
@@ -68,6 +68,7 @@ struct thread;
 
 void	vfp_init(void);
 void	vfp_discard(struct thread *);
+void	vfp_new_thread(struct thread *, struct thread *, bool);
 void	vfp_reset_state(struct thread *, struct pcb *);
 void	vfp_restore_state(void);
 void	vfp_save_state(struct thread *, struct pcb *);



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