Date: Mon, 15 Jan 2001 13:17:21 -0800 (PST) From: John Baldwin <jhb@FreeBSD.org> To: "Justin T. Gibbs" <gibbs@scsiguy.com> Cc: Peter Wemm <peter@netplex.com.au>, Poul-Henning Kamp <phk@critter.freebsd.dk>, Wilko Bulte <wkb@freebie.demon.nl>, cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org, Bruce Evans <bde@zeta.org.au> Subject: Re: cvs commit: src/sys/i386/conf GENERIC Message-ID: <XFMail.010115131721.jhb@FreeBSD.org> In-Reply-To: <200101152012.f0FKCns56756@aslan.scsiguy.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On 15-Jan-01 Justin T. Gibbs wrote: >>So are you ready to write the code in trap() to handle an illegal instruction >>fault in userland that decodes and executes all variants of cmpxchg? The new >>threading code in libc will be using atomic_cmpset() from userland, which is >>going to be the main hurdle to get over. > > This is the wrong way to handle it. Have atomic_cmpset() perform a fixup > of the calling code on first entry and the result will be code as optimized > as possible for the processor type the code is running on. If the user > decides to write their own code that uses cmpxchg, they get what they > deserve, but the primitives should not require a *fault* to work correctly. *sigh* Go look at the 386 version of atomic_cmpset in atomic.h: #if defined(I386_CPU) static __inline int atomic_cmpset_int(volatile u_int *dst, u_int exp, u_int src) { int res = exp; __asm __volatile( " pushfl ; " " cli ; " " cmpl %1,%3 ; " " jne 1f ; " " movl %2,%3 ; " "1: " " sete %%al; " " movzbl %%al,%0 ; " " popfl ; " "# atomic_cmpset_int" : "=a" (res) /* 0 (result) */ : "0" (exp), /* 1 */ "r" (src), /* 2 */ "m" (*(dst)) /* 3 */ : "memory"); return (res); } See those 'cli' and 'popfl' instrucitons? Those are _privileged_. Userland can't disable/enable interrupts, so we have to trap into the kernel to do this no matter what. If you want to patch the code to do a syscall instead of a cmpxchg instruction, fine. However, emulating atomic_cmpset in userland on a 386 requires a trap into the kernel. Please assume for at least 1 minute that the SMPng guys are not complete bumbling idiots and that we may have actually thought about this for at least 5 minutes. -- John Baldwin <jhb@FreeBSD.org> -- http://www.FreeBSD.org/~jhb/ PGP Key: http://www.baldwin.cx/~john/pgpkey.asc "Power Users Use the Power to Serve!" - http://www.FreeBSD.org/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?XFMail.010115131721.jhb>