[Midnightbsd-cvs] src [7963] trunk/sys/amd64: introduce curpcb magic var

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Wed Sep 14 19:32:11 EDT 2016


Revision: 7963
          http://svnweb.midnightbsd.org/src/?rev=7963
Author:   laffer1
Date:     2016-09-14 19:32:11 -0400 (Wed, 14 Sep 2016)
Log Message:
-----------
introduce curpcb magic var

Modified Paths:
--------------
    trunk/sys/amd64/amd64/fpu.c
    trunk/sys/amd64/amd64/machdep.c
    trunk/sys/amd64/amd64/trap.c
    trunk/sys/amd64/amd64/vm_machdep.c
    trunk/sys/amd64/include/pcpu.h

Modified: trunk/sys/amd64/amd64/fpu.c
===================================================================
--- trunk/sys/amd64/amd64/fpu.c	2016-09-14 23:03:00 UTC (rev 7962)
+++ trunk/sys/amd64/amd64/fpu.c	2016-09-14 23:32:11 UTC (rev 7963)
@@ -327,7 +327,7 @@
 	critical_enter();
 	if (curthread == PCPU_GET(fpcurthread)) {
 		stop_emulating();
-		fpusave(PCPU_GET(curpcb)->pcb_save);
+		fpusave(curpcb->pcb_save);
 		start_emulating();
 		PCPU_SET(fpcurthread, 0);
 	}
@@ -547,7 +547,7 @@
 	 * wherever they are.
 	 */
 	if (PCPU_GET(fpcurthread) != curthread) {
-		pcb_save = PCPU_GET(curpcb)->pcb_save;
+		pcb_save = curpcb->pcb_save;
 		control = pcb_save->sv_env.en_cw;
 		status = pcb_save->sv_env.en_sw;
 	} else {
@@ -567,7 +567,7 @@
 
 	critical_enter();
 	if (PCPU_GET(fpcurthread) != curthread)
-		mxcsr = PCPU_GET(curpcb)->pcb_save->sv_env.en_mxcsr;
+		mxcsr = curpcb->pcb_save->sv_env.en_mxcsr;
 	else
 		stmxcsr(&mxcsr);
 	critical_exit();
@@ -609,7 +609,7 @@
 	 * Record new context early in case frstor causes a trap.
 	 */
 	PCPU_SET(fpcurthread, curthread);
-	pcb = PCPU_GET(curpcb);
+	pcb = curpcb;
 
 	fpu_clean_state();
 
@@ -970,7 +970,7 @@
 {
 	struct pcb *pcb;
 
-	pcb = PCPU_GET(curpcb);
+	pcb = curpcb;
 	KASSERT((curthread->td_pflags & TDP_KTHREAD) != 0,
 	    ("Only kthread may use fpu_kern_thread"));
 	KASSERT(pcb->pcb_save == get_pcb_user_save_pcb(pcb),
@@ -987,5 +987,5 @@
 
 	if ((curthread->td_pflags & TDP_KTHREAD) == 0)
 		return (0);
-	return ((PCPU_GET(curpcb)->pcb_flags & PCB_KERNFPU) != 0);
+	return ((curpcb->pcb_flags & PCB_KERNFPU) != 0);
 }

Modified: trunk/sys/amd64/amd64/machdep.c
===================================================================
--- trunk/sys/amd64/amd64/machdep.c	2016-09-14 23:03:00 UTC (rev 7962)
+++ trunk/sys/amd64/amd64/machdep.c	2016-09-14 23:32:11 UTC (rev 7963)
@@ -968,7 +968,7 @@
 		pcb->pcb_dr3 = 0;
 		pcb->pcb_dr6 = 0;
 		pcb->pcb_dr7 = 0;
-		if (pcb == PCPU_GET(curpcb)) {
+		if (pcb == curpcb) {
 			/*
 			 * Clear the debug registers on the running
 			 * CPU, otherwise they will end up affecting

Modified: trunk/sys/amd64/amd64/trap.c
===================================================================
--- trunk/sys/amd64/amd64/trap.c	2016-09-14 23:03:00 UTC (rev 7962)
+++ trunk/sys/amd64/amd64/trap.c	2016-09-14 23:32:11 UTC (rev 7963)
@@ -523,9 +523,8 @@
 				frame->tf_rip = (long)fsbase_load_fault;
 				goto out;
 			}
-			if (PCPU_GET(curpcb)->pcb_onfault != NULL) {
-				frame->tf_rip =
-				    (long)PCPU_GET(curpcb)->pcb_onfault;
+			if (curpcb->pcb_onfault != NULL) {
+				frame->tf_rip = (long)curpcb->pcb_onfault;
 				goto out;
 			}
 			break;
@@ -728,7 +727,7 @@
 		 * it normally, and panic immediately.
 		 */
 		if (!usermode && (td->td_intr_nesting_level != 0 ||
-		    PCPU_GET(curpcb)->pcb_onfault == NULL)) {
+		    curpcb->pcb_onfault == NULL)) {
 			trap_fatal(frame, eva);
 			return (-1);
 		}
@@ -784,8 +783,8 @@
 nogo:
 	if (!usermode) {
 		if (td->td_intr_nesting_level == 0 &&
-		    PCPU_GET(curpcb)->pcb_onfault != NULL) {
-			frame->tf_rip = (long)PCPU_GET(curpcb)->pcb_onfault;
+		    curpcb->pcb_onfault != NULL) {
+			frame->tf_rip = (long)curpcb->pcb_onfault;
 			return (0);
 		}
 		trap_fatal(frame, eva);

Modified: trunk/sys/amd64/amd64/vm_machdep.c
===================================================================
--- trunk/sys/amd64/amd64/vm_machdep.c	2016-09-14 23:03:00 UTC (rev 7962)
+++ trunk/sys/amd64/amd64/vm_machdep.c	2016-09-14 23:32:11 UTC (rev 7963)
@@ -90,6 +90,10 @@
 static volatile u_int	cpu_reset_proxy_active;
 #endif
 
+CTASSERT((struct thread **)OFFSETOF_CURTHREAD ==
+    &((struct pcpu *)NULL)->pc_curthread);
+CTASSERT((struct pcb **)OFFSETOF_CURPCB == &((struct pcpu *)NULL)->pc_curpcb);
+
 struct savefpu *
 get_pcb_user_save_td(struct thread *td)
 {

Modified: trunk/sys/amd64/include/pcpu.h
===================================================================
--- trunk/sys/amd64/include/pcpu.h	2016-09-14 23:03:00 UTC (rev 7962)
+++ trunk/sys/amd64/include/pcpu.h	2016-09-14 23:32:11 UTC (rev 7963)
@@ -216,16 +216,36 @@
 #define	PCPU_PTR(member)	__PCPU_PTR(pc_ ## member)
 #define	PCPU_SET(member, val)	__PCPU_SET(pc_ ## member, val)
 
+#define	OFFSETOF_CURTHREAD	0
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wnull-dereference"
+#endif
 static __inline __pure2 struct thread *
 __curthread(void)
 {
 	struct thread *td;
 
-	__asm("movq %%gs:0,%0" : "=r" (td));
+	__asm("movq %%gs:%1,%0" : "=r" (td)
+	    : "m" (*(char *)OFFSETOF_CURTHREAD));
 	return (td);
 }
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
 #define	curthread		(__curthread())
 
+#define	OFFSETOF_CURPCB		32
+static __inline __pure2 struct pcb *
+__curpcb(void)
+{
+	struct pcb *pcb;
+
+	__asm("movq %%gs:%1,%0" : "=r" (pcb) : "m" (*(char *)OFFSETOF_CURPCB));
+	return (pcb);
+}
+#define	curpcb		(__curpcb())
+
 #define	IS_BSP()	(PCPU_GET(cpuid) == 0)
 
 #else /* !lint || defined(__GNUCLIKE_ASM) && defined(__GNUCLIKE___TYPEOF) */



More information about the Midnightbsd-cvs mailing list