Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 13 Aug 1999 09:21:52 +1000
From:      Peter Jeremy <jeremyp@gsmx07.alcatel.com.au>
To:        FreeBSD-gnats-submit@FreeBSD.ORG
Subject:   i386/13111: Improvement for atomic operations in KLDs
Message-ID:  <99Aug13.090225est.40340@border.alcanet.com.au>

next in thread | raw e-mail | index | archive | help

>Number:         13111
>Category:       i386
>Synopsis:       Improvement for atomic operations in KLDs
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Aug 12 16:30:00 PDT 1999
>Closed-Date:
>Last-Modified:
>Originator:     Peter Jeremy
>Release:        FreeBSD 4.0-CURRENT i386
>Organization:
Alcatel Australia Limited
>Environment:

	cvs-cur 5563

>Description:

	The i386 atomic operations were recently re-written by Matt
	Dillon to actually generate atomic code for both UP and SMP
	configurations.  In order to generate KLDs that are portable
	between UP and SMP, KLDs are always compiled with `lock'
	prefixes - which are quite slow, even on UP systems.

	The following patch creates a set of callable functions which
	are linked into the kernel.  The KLD compilation options are
	changed to call these functions, rather than in-lining the
	atomic operations.

	This approach makes atomic operations from KLDs significantly
	faster on UP systems (though somewhat slower on SMP systems).

>How-To-Repeat:

	code inspection

>Fix:
	
Index: src/sys/i386/conf/files.i386
===================================================================
RCS file: /home/CVSROOT/./src/sys/i386/conf/files.i386,v
retrieving revision 1.258
diff -u -r1.258 files.i386
--- files.i386	1999/08/09 10:34:38	1.258
+++ files.i386	1999/08/12 10:18:49
@@ -117,6 +117,8 @@
 i386/eisa/eisaconf.c		optional	eisa
 i386/eisa/if_fea.c		optional	fea
 i386/eisa/if_vx_eisa.c		optional	vx
+i386/i386/atomic.c		standard				\
+	compile-with	"${CC} -c ${CFLAGS} ${DEFINED_PROF:S/^$/-fomit-frame-pointer/} $<"
 i386/i386/autoconf.c		standard
 i386/i386/bios.c		standard
 i386/i386/bioscall.s		standard
Index: src/sys/i386/include/atomic.h
===================================================================
RCS file: /home/CVSROOT/./src/sys/i386/include/atomic.h,v
retrieving revision 1.4
diff -u -r1.4 atomic.h
--- atomic.h	1999/07/23 23:45:19	1.4
+++ atomic.h	1999/08/12 10:10:11
@@ -54,9 +54,19 @@
  */
 
 /*
- * Make kernel modules portable between UP and SMP.
+ * The above functions are expanded inline in the statically-linked
+ * kernel.  Lock prefixes are generated if an SMP kernel is being
+ * built.
+ *
+ * Kernel modules call real functions which are built into the kernel.
+ * This allows kernel modules to be portable between UP and SMP systems.
  */
-#if defined(SMP) || defined(KLD_MODULE)
+#if defined(KLD_MODULE)
+#define ATOMIC_ASM(NAME, TYPE, OP, V)			\
+	extern void atomic_##NAME##_##TYPE(volatile u_##TYPE *p, u_##TYPE v);
+
+#else /* !KLD_MODULE */
+#if defined(SMP)
 #define MPLOCKED	"lock ; "
 #else
 #define MPLOCKED
@@ -74,6 +84,7 @@
 			 : "=m" (*p)			\
 			 :  "0" (*p), "ir" (V)); 	\
 }
+#endif /* KLD_MODULE */
 
 ATOMIC_ASM(set,	     char,  "orb %2,%0",   v)
 ATOMIC_ASM(clear,    char,  "andb %2,%0", ~v)
--- /dev/null	Fri Aug 13 02:44:50 1999
+++ src/sys/i386/i386/atomic.c	Thu Aug 12 20:26:24 1999
@@ -0,0 +1,47 @@
+/*-
+ * Copyright (c) 1999 Peter Jeremy
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *	$Id $
+ */
+
+/* This file creates publically callable functions to perform various
+ * simple arithmetic on memory which is atomic in the presence of
+ * interrupts and multiple processors.
+ */
+#include <sys/types.h>
+
+/* Firstly make atomic.h generate prototypes as it will for kernel modules */
+#define KLD_MODULE
+#include <machine/atomic.h>
+#undef _MACHINE_ATOMIC_H_	/* forget we included it */
+#undef KLD_MODULE
+#undef ATOMIC_ASM
+
+/* Make atomic.h generate public functions */
+#define static
+#undef __inline
+#define __inline
+
+#include <machine/atomic.h>

>Release-Note:
>Audit-Trail:
>Unformatted:


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?99Aug13.090225est.40340>