From owner-cvs-all Mon Jan 15 13:20:23 2001 Delivered-To: cvs-all@freebsd.org Received: from meow.osd.bsdi.com (meow.osd.bsdi.com [204.216.28.88]) by hub.freebsd.org (Postfix) with ESMTP id DE50E37B402; Mon, 15 Jan 2001 13:20:02 -0800 (PST) Received: from laptop.baldwin.cx (john@jhb-laptop.osd.bsdi.com [204.216.28.241]) by meow.osd.bsdi.com (8.11.1/8.9.3) with ESMTP id f0FLFn193088; Mon, 15 Jan 2001 13:15:49 -0800 (PST) (envelope-from jhb@FreeBSD.org) Message-ID: X-Mailer: XFMail 1.4.0 on FreeBSD X-Priority: 3 (Normal) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit MIME-Version: 1.0 In-Reply-To: <200101152012.f0FKCns56756@aslan.scsiguy.com> Date: Mon, 15 Jan 2001 13:17:21 -0800 (PST) From: John Baldwin To: "Justin T. Gibbs" Subject: Re: cvs commit: src/sys/i386/conf GENERIC Cc: Peter Wemm Cc: Peter Wemm , Poul-Henning Kamp , Wilko Bulte , cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org, Bruce Evans Sender: owner-cvs-all@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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 -- 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