From owner-svn-src-all@FreeBSD.ORG Sat Nov 22 22:20:00 2008 Return-Path: Delivered-To: svn-src-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E2E491065674; Sat, 22 Nov 2008 22:19:59 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from mail.terabit.net.ua (mail.terabit.net.ua [195.137.202.147]) by mx1.freebsd.org (Postfix) with ESMTP id 87D928FC1A; Sat, 22 Nov 2008 22:19:59 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from skuns.zoral.com.ua ([91.193.166.194] helo=mail.zoral.com.ua) by mail.terabit.net.ua with esmtps (TLSv1:AES256-SHA:256) (Exim 4.63 (FreeBSD)) (envelope-from ) id 1L40pY-000189-SM; Sun, 23 Nov 2008 00:19:57 +0200 Received: from deviant.kiev.zoral.com.ua (root@deviant.kiev.zoral.com.ua [10.1.1.148]) by mail.zoral.com.ua (8.14.2/8.14.2) with ESMTP id mAMMJsVH077325 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 23 Nov 2008 00:19:54 +0200 (EET) (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.3/8.14.3) with ESMTP id mAMMJsj0047892; Sun, 23 Nov 2008 00:19:54 +0200 (EET) (envelope-from kostikbel@gmail.com) Received: (from kostik@localhost) by deviant.kiev.zoral.com.ua (8.14.3/8.14.3/Submit) id mAMMJrWF047891; Sun, 23 Nov 2008 00:19:53 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: deviant.kiev.zoral.com.ua: kostik set sender to kostikbel@gmail.com using -f Date: Sun, 23 Nov 2008 00:19:53 +0200 From: Kostik Belousov To: Scott Long Message-ID: <20081122221953.GO6408@deviant.kiev.zoral.com.ua> References: <200811220555.mAM5tuIJ007781@svn.freebsd.org> <20081122112949.GA6408@deviant.kiev.zoral.com.ua> <3c1674c90811221326m41e229f7p6abbc0eb473e900e@mail.gmail.com> <49288222.5060205@samsco.org> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="vNrHrykRFvLVX6W3" Content-Disposition: inline In-Reply-To: <49288222.5060205@samsco.org> User-Agent: Mutt/1.4.2.3i X-Virus-Scanned: ClamAV version 0.93.3, clamav-milter version 0.93.3 on skuns.kiev.zoral.com.ua X-Virus-Status: Clean X-Spam-Status: No, score=-4.4 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 X-Virus-Scanned: mail.terabit.net.ua 1L40pY-000189-SM dcdb72959fa04b012c3a604d40122628 X-Terabit: YES Cc: svn-src-head@FreeBSD.org, svn-src-all@FreeBSD.org, src-committers@FreeBSD.org, kmacy@FreeBSD.org Subject: Re: svn commit: r185162 - in head: . sys/amd64/include sys/arm/include sys/conf sys/dev/bce sys/dev/cxgb sys/dev/cxgb/sys sys/dev/cxgb/ulp/iw_cxgb sys/dev/mxge sys/dev/nxge sys/i386/include sys/i386/in... X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 22 Nov 2008 22:20:00 -0000 --vNrHrykRFvLVX6W3 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Nov 22, 2008 at 03:05:22PM -0700, Scott Long wrote: > A neat hack would be for the kernel linker to scan the text and do a > drop-in replacement of the opcode that is appropriate for the platform. > I can't see how a CPU_XXX definition would work because it's just a > compile time construct, one that can be included with any kernel > compile. Yes, it is possible to do that. Less drastic change is to directly check features. I moved slow code to separate section to eliminate unconditional jump in fast path. Only compile-tested. diff --git a/sys/conf/ldscript.i386 b/sys/conf/ldscript.i386 index a94f32f..49d9636 100644 --- a/sys/conf/ldscript.i386 +++ b/sys/conf/ldscript.i386 @@ -45,6 +45,7 @@ SECTIONS .text : { *(.text) + *(.text.offpath) *(.stub) /* .gnu.warning sections are handled specially by elf32.em. */ *(.gnu.warning) diff --git a/sys/i386/include/atomic.h b/sys/i386/include/atomic.h index f6bcf0c..5806d41 100644 --- a/sys/i386/include/atomic.h +++ b/sys/i386/include/atomic.h @@ -32,11 +32,38 @@ #error this file needs sys/cdefs.h as a prerequisite #endif =20 - +#ifdef _KERNEL #if defined(I686_CPU) -#define mb() __asm__ __volatile__ ("mfence;": : :"memory") -#define wmb() __asm__ __volatile__ ("sfence;": : :"memory") -#define rmb() __asm__ __volatile__ ("lfence;": : :"memory") +#define mb() __asm__ __volatile__ ( \ + "testl\t$0x04000000,cpu_feature\n" \ + "\tje\t2f\n" \ + "\tmfence\n" \ + "1:\n" \ + "\t.section\t.text.offpath\n" \ + "2:\tlock;addl\t$0,cpu_feature\n" \ + "\tjmp\t1b\n" \ + "\t.text" \ + : : :"memory") +#define wmb() __asm__ __volatile__ ( \ + "testl\t$0x02000000,cpu_feature\n" \ + "\tje\t2f\n" \ + "\tsfence\n" \ + "1:\n" \ + "\t.section\t.text.offpath\n" \ + "2:\tlock;addl\t$0,cpu_feature\n" \ + "\tjmp\t1b\n" \ + "\t.text" \ + : : :"memory") +#define rmb() __asm__ __volatile__ ( \ + "testl\t$0x04000000,cpu_feature\n" \ + "\tje\t2f\n" \ + "\tlfence\n" \ + "1:\n" \ + "\t.section\t.text.offpath\n" \ + "2:\tlock;addl\t$0,cpu_feature\n" \ + "\tjmp\t1b\n" \ + "\t.text" \ + : : :"memory") #else /* * do we need a serializing instruction? @@ -45,7 +72,7 @@ #define wmb() #define rmb() #endif - +#endif =20 /* * Various simple operations on memory, each of which is atomic in the --vNrHrykRFvLVX6W3 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (FreeBSD) iEYEARECAAYFAkkohYkACgkQC3+MBN1Mb4gGfgCbBbHvxaGmEChWn9k662Yui5z8 NYUAoLpu9ZpAWJTSvkO/71MLhvkmFVck =CVAC -----END PGP SIGNATURE----- --vNrHrykRFvLVX6W3--