From owner-freebsd-amd64@FreeBSD.ORG Wed Jul 18 16:12:00 2012 Return-Path: Delivered-To: freebsd-amd64@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 43C99106566B for ; Wed, 18 Jul 2012 16:12:00 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.zoral.com.ua (mx0.zoral.com.ua [91.193.166.200]) by mx1.freebsd.org (Postfix) with ESMTP id 86A0E8FC0C for ; Wed, 18 Jul 2012 16:11:59 +0000 (UTC) Received: from skuns.kiev.zoral.com.ua (localhost [127.0.0.1]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id q6IGC11W040867; Wed, 18 Jul 2012 19:12:01 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: from deviant.kiev.zoral.com.ua (kostik@localhost [127.0.0.1]) by deviant.kiev.zoral.com.ua (8.14.5/8.14.5) with ESMTP id q6IGBmQK032323; Wed, 18 Jul 2012 19:11:48 +0300 (EEST) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.5/8.14.5/Submit) id q6IGBmn8032322; Wed, 18 Jul 2012 19:11:48 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Wed, 18 Jul 2012 19:11:48 +0300 From: Konstantin Belousov To: Bruce Evans Message-ID: <20120718161148.GV2676@deviant.kiev.zoral.com.ua> References: <201207172150.q6HLoFvB096742@freefall.freebsd.org> <20120718103210.E834@besplex.bde.org> <20120718035220.GO2676@deviant.kiev.zoral.com.ua> <20120718140523.X1862@besplex.bde.org> <20120718050958.GQ2676@deviant.kiev.zoral.com.ua> <20120718153554.O2195@besplex.bde.org> <20120718081003.GT2676@deviant.kiev.zoral.com.ua> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="HqPpMaT+a6TeY/Q4" Content-Disposition: inline In-Reply-To: <20120718081003.GT2676@deviant.kiev.zoral.com.ua> User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: clamav-milter 0.95.2 at skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-4.0 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on skuns.kiev.zoral.com.ua Cc: freebsd-amd64@freebsd.org Subject: curpcb X-BeenThere: freebsd-amd64@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting FreeBSD to the AMD64 platform List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Jul 2012 16:12:00 -0000 --HqPpMaT+a6TeY/Q4 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jul 18, 2012 at 11:10:03AM +0300, Konstantin Belousov wrote: > On Wed, Jul 18, 2012 at 04:59:38PM +1000, Bruce Evans wrote: > > On Wed, 18 Jul 2012, Konstantin Belousov wrote: > > Putting the definiton in machine/pcpu.h should avoid changing the > > prerequistes for machine/pcb.h. > >=20 > > >#ifndef _KERNEL > > >/* stuff that *used* to be included by user.h, or is now needed */ > > > > > >Please note the location in pcb.h an not in machine/pcpu.h, where it > > >cannot work for technical reasons (struct pcpu is not defined yet). > >=20 > > Not applicable -- see above. > No, this cannot work. machine/pcpu.h defines PCPU_MD_FIELDS which is used > to provide md part of the struct pcpu. Below is the tested patch which converts all users of PCPU_GET(curpcb) for amd64. diff --git a/sys/amd64/amd64/fpu.c b/sys/amd64/amd64/fpu.c index f88aba7..fe4bcf1 100644 --- a/sys/amd64/amd64/fpu.c +++ b/sys/amd64/amd64/fpu.c @@ -327,7 +327,7 @@ fpuexit(struct thread *td) critical_enter(); if (curthread =3D=3D 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 @@ fputrap_x87(void) * wherever they are. */ if (PCPU_GET(fpcurthread) !=3D curthread) { - pcb_save =3D PCPU_GET(curpcb)->pcb_save; + pcb_save =3D curpcb->pcb_save; control =3D pcb_save->sv_env.en_cw; status =3D pcb_save->sv_env.en_sw; } else { @@ -567,7 +567,7 @@ fputrap_sse(void) =20 critical_enter(); if (PCPU_GET(fpcurthread) !=3D curthread) - mxcsr =3D PCPU_GET(curpcb)->pcb_save->sv_env.en_mxcsr; + mxcsr =3D curpcb->pcb_save->sv_env.en_mxcsr; else stmxcsr(&mxcsr); critical_exit(); @@ -609,7 +609,7 @@ fpudna(void) * Record new context early in case frstor causes a trap. */ PCPU_SET(fpcurthread, curthread); - pcb =3D PCPU_GET(curpcb); + pcb =3D curpcb; =20 fpu_clean_state(); =20 @@ -970,7 +970,7 @@ fpu_kern_thread(u_int flags) { struct pcb *pcb; =20 - pcb =3D PCPU_GET(curpcb); + pcb =3D curpcb; KASSERT((curthread->td_pflags & TDP_KTHREAD) !=3D 0, ("Only kthread may use fpu_kern_thread")); KASSERT(pcb->pcb_save =3D=3D get_pcb_user_save_pcb(pcb), @@ -987,5 +987,5 @@ is_fpu_kern_thread(u_int flags) =20 if ((curthread->td_pflags & TDP_KTHREAD) =3D=3D 0) return (0); - return ((PCPU_GET(curpcb)->pcb_flags & PCB_KERNFPU) !=3D 0); + return ((curpcb->pcb_flags & PCB_KERNFPU) !=3D 0); } diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c index 8044fe5..cd3ebc5 100644 --- a/sys/amd64/amd64/machdep.c +++ b/sys/amd64/amd64/machdep.c @@ -996,7 +996,7 @@ exec_setregs(struct thread *td, struct image_params *im= gp, u_long stack) pcb->pcb_dr3 =3D 0; pcb->pcb_dr6 =3D 0; pcb->pcb_dr7 =3D 0; - if (pcb =3D=3D PCPU_GET(curpcb)) { + if (pcb =3D=3D curpcb) { /* * Clear the debug registers on the running * CPU, otherwise they will end up affecting diff --git a/sys/amd64/amd64/trap.c b/sys/amd64/amd64/trap.c index 57d1cc2..d035a7e 100644 --- a/sys/amd64/amd64/trap.c +++ b/sys/amd64/amd64/trap.c @@ -520,9 +520,8 @@ trap(struct trapframe *frame) frame->tf_rip =3D (long)fsbase_load_fault; goto out; } - if (PCPU_GET(curpcb)->pcb_onfault !=3D NULL) { - frame->tf_rip =3D - (long)PCPU_GET(curpcb)->pcb_onfault; + if (curpcb->pcb_onfault !=3D NULL) { + frame->tf_rip =3D (long)curpcb->pcb_onfault; goto out; } break; @@ -708,7 +707,7 @@ trap_pfault(frame, usermode) * it normally, and panic immediately. */ if (!usermode && (td->td_intr_nesting_level !=3D 0 || - PCPU_GET(curpcb)->pcb_onfault =3D=3D NULL)) { + curpcb->pcb_onfault =3D=3D NULL)) { trap_fatal(frame, eva); return (-1); } @@ -764,8 +763,8 @@ trap_pfault(frame, usermode) nogo: if (!usermode) { if (td->td_intr_nesting_level =3D=3D 0 && - PCPU_GET(curpcb)->pcb_onfault !=3D NULL) { - frame->tf_rip =3D (long)PCPU_GET(curpcb)->pcb_onfault; + curpcb->pcb_onfault !=3D NULL) { + frame->tf_rip =3D (long)curpcb->pcb_onfault; return (0); } trap_fatal(frame, eva); diff --git a/sys/amd64/include/pcb.h b/sys/amd64/include/pcb.h index 22cbbe2..d814902 100644 --- a/sys/amd64/include/pcb.h +++ b/sys/amd64/include/pcb.h @@ -144,6 +144,17 @@ void makectx(struct trapframe *, struct pcb *); int savectx(struct pcb *) __returns_twice; void resumectx(struct pcb *); =20 +static __inline __pure2 struct pcb * +__curpcb(void) +{ + struct pcb *pcb; + + __asm("movq %%gs:%1,%0" : "=3Dr" (pcb) + : "m" (((struct pcpu *)NULL)->pc_curpcb)); + return (pcb); +} +#define curpcb (__curpcb()) + #endif =20 #endif /* _AMD64_PCB_H_ */ diff --git a/sys/sys/user.h b/sys/sys/user.h index accb7c3..ab1c7a7 100644 --- a/sys/sys/user.h +++ b/sys/sys/user.h @@ -35,6 +35,7 @@ #ifndef _SYS_USER_H_ #define _SYS_USER_H_ =20 +#include #include #ifndef _KERNEL /* stuff that *used* to be included by user.h, or is now needed */ --HqPpMaT+a6TeY/Q4 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (FreeBSD) iEYEARECAAYFAlAG4EMACgkQC3+MBN1Mb4itQgCgkv18eX4mYzsCvunFVKGRZaV1 OrMAoMwpCnf+YQQ6PHButBnkUltL7p7s =rmjd -----END PGP SIGNATURE----- --HqPpMaT+a6TeY/Q4--