PERFORCE change 94635 for review

Peter Wemm peter at FreeBSD.org
Tue Apr 4 21:18:13 UTC 2006


http://perforce.freebsd.org/chv.cgi?CH=94635

Change 94635 by peter at peter_daintree on 2006/04/04 21:17:47

	IFC @94632

Affected files ...

.. //depot/projects/hammer/etc/rc.subr#34 integrate
.. //depot/projects/hammer/lib/libc/stdlib/malloc.3#11 integrate
.. //depot/projects/hammer/lib/libc/stdlib/malloc.c#27 integrate
.. //depot/projects/hammer/lib/libthr/arch/amd64/amd64/pthread_md.c#2 integrate
.. //depot/projects/hammer/lib/libthr/arch/amd64/include/pthread_md.h#2 integrate
.. //depot/projects/hammer/lib/libthr/arch/i386/i386/pthread_md.c#6 integrate
.. //depot/projects/hammer/lib/libthr/arch/i386/include/pthread_md.h#5 integrate
.. //depot/projects/hammer/lib/libthr/pthread.map#9 integrate
.. //depot/projects/hammer/lib/libthr/thread/Makefile.inc#14 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_attr.c#5 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_barrier.c#5 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_barrierattr.c#3 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_cancel.c#11 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_clean.c#3 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_concurrency.c#3 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_cond.c#13 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_condattr.c#2 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_create.c#22 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_detach.c#10 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_equal.c#2 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_exit.c#18 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_fork.c#3 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_getprio.c#2 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_getschedparam.c#4 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_info.c#7 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_init.c#23 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_join.c#14 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_kill.c#2 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_list.c#6 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_main_np.c#3 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_multi_np.c#2 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_mutex.c#29 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_mutexattr.c#5 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_private.h#31 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_pspinlock.c#2 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_resume_np.c#8 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_rtld.c#2 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_rwlock.c#7 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_rwlockattr.c#2 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_self.c#3 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_setprio.c#2 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_setschedparam.c#9 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_sig.c#13 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_single_np.c#2 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_spec.c#3 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_spinlock.c#11 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_stack.c#6 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_suspend_np.c#6 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_switch_np.c#2 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_syscalls.c#11 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_umtx.c#2 integrate
.. //depot/projects/hammer/lib/libthr/thread/thr_yield.c#2 integrate
.. //depot/projects/hammer/release/doc/zh_CN.GB2312/relnotes/common/new.sgml#10 integrate
.. //depot/projects/hammer/share/man/man4/mfi.4#2 integrate
.. //depot/projects/hammer/share/man/man8/rc.subr.8#8 integrate
.. //depot/projects/hammer/sys/alpha/include/kdb.h#3 integrate
.. //depot/projects/hammer/sys/amd64/amd64/gdb_machdep.c#13 integrate
.. //depot/projects/hammer/sys/amd64/amd64/pmap.c#151 integrate
.. //depot/projects/hammer/sys/amd64/include/gdb_machdep.h#4 integrate
.. //depot/projects/hammer/sys/amd64/include/kdb.h#3 integrate
.. //depot/projects/hammer/sys/dev/acpica/Osd/OsdHardware.c#16 integrate
.. //depot/projects/hammer/sys/dev/hwpmc/hwpmc_x86.c#5 integrate
.. //depot/projects/hammer/sys/dev/iicbus/if_ic.c#12 integrate
.. //depot/projects/hammer/sys/dev/iicbus/iic.c#8 integrate
.. //depot/projects/hammer/sys/dev/scc/scc_bfe.h#2 integrate
.. //depot/projects/hammer/sys/dev/scc/scc_core.c#2 integrate
.. //depot/projects/hammer/sys/dev/uart/uart_dev_z8530.c#13 integrate
.. //depot/projects/hammer/sys/i386/i386/exception.s#13 integrate
.. //depot/projects/hammer/sys/i386/include/kdb.h#3 integrate
.. //depot/projects/hammer/sys/ia64/ia64/interrupt.c#22 integrate
.. //depot/projects/hammer/sys/ia64/include/kdb.h#3 integrate
.. //depot/projects/hammer/sys/kern/subr_kdb.c#18 integrate
.. //depot/projects/hammer/sys/kern/vfs_bio.c#69 integrate
.. //depot/projects/hammer/sys/kern/vfs_subr.c#104 integrate
.. //depot/projects/hammer/sys/net/if_media.h#15 integrate
.. //depot/projects/hammer/sys/netinet/in_pcb.c#40 integrate
.. //depot/projects/hammer/sys/netinet/tcp_input.c#61 integrate
.. //depot/projects/hammer/sys/netinet/tcp_subr.c#56 integrate
.. //depot/projects/hammer/sys/netipsec/ipsec.c#12 integrate
.. //depot/projects/hammer/sys/netipsec/keysock.c#12 integrate
.. //depot/projects/hammer/sys/sparc64/include/kdb.h#3 integrate
.. //depot/projects/hammer/sys/sys/umtx.h#13 integrate
.. //depot/projects/hammer/sys/ufs/ffs/ffs_softdep.c#36 integrate
.. //depot/projects/hammer/sys/ufs/ufs/ufsmount.h#10 integrate
.. //depot/projects/hammer/usr.bin/calendar/calendars/calendar.freebsd#46 integrate
.. //depot/projects/hammer/usr.bin/find/find.1#19 integrate

Differences ...

==== //depot/projects/hammer/etc/rc.subr#34 (text+ko) ====

@@ -1,7 +1,7 @@
-# $NetBSD: rc.subr,v 1.60 2003/07/26 05:13:47 lukem Exp $
-# $FreeBSD: src/etc/rc.subr,v 1.50 2006/03/23 16:48:32 flz Exp $
+# $NetBSD: rc.subr,v 1.65 2004/10/12 14:45:29 lukem Exp $
+# $FreeBSD: src/etc/rc.subr,v 1.51 2006/04/04 10:52:15 flz Exp $
 #
-# Copyright (c) 1997-2002 The NetBSD Foundation, Inc.
+# Copyright (c) 1997-2004 The NetBSD Foundation, Inc.
 # All rights reserved.
 #
 # This code is derived from software contributed to The NetBSD Foundation
@@ -39,6 +39,8 @@
 #	functions used by various rc scripts
 #
 
+: ${rcvar_manpage:='rc.conf(5)'}
+
 #
 #	Operating System dependent/independent variables
 #
@@ -138,12 +140,13 @@
 		return 1
 		;;
 	*)
-		warn "\$${1} is not set properly - see rc.conf(5)."
+		warn "\$${1} is not set properly - see ${rcvar_manpage}."
 		return 1
 		;;
 	esac
 }
 
+#
 # reverse_list list
 #	print the list in reverse order
 #
@@ -598,7 +601,7 @@
 
 		start)
 			if [ -z "$rc_fast" -a -n "$rc_pid" ]; then
-				echo "${name} already running? (pid=$rc_pid)."
+				echo 1>&2 "${name} already running? (pid=$rc_pid)."
 				return 1
 			fi
 
@@ -612,7 +615,7 @@
 					#
 			for _f in $required_vars; do
 				if ! checkyesno $_f; then
-					warn "\$${_f} is not set."
+					warn "\$${_f} is not enabled."
 					if [ -z "$rc_force" ]; then
 						return 1
 					fi
@@ -684,10 +687,10 @@
 			if [ -z "$rc_pid" ]; then
 				[ -n "$rc_fast" ] && return 0
 				if [ -n "$pidfile" ]; then
-					echo \
+					echo 1>&2 \
 				    "${name} not running? (check $pidfile)."
 				else
-					echo "${name} not running?"
+					echo 1>&2 "${name} not running?"
 				fi
 				return 1
 			fi
@@ -729,10 +732,10 @@
 		reload)
 			if [ -z "$rc_pid" ]; then
 				if [ -n "$pidfile" ]; then
-					echo \
+					echo 1>&2 \
 				    "${name} not running? (check $pidfile)."
 				else
-					echo "${name} not running?"
+					echo 1>&2 "${name} not running?"
 				fi
 				return 1
 			fi
@@ -854,7 +857,7 @@
 }
 
 #
-# load_rc_config
+# load_rc_config command
 #	Source in the configuration file for a given command.
 #
 load_rc_config()
@@ -898,6 +901,25 @@
 		;;
 	esac
 }
+  
+#
+# load_rc_config_var cmd var
+#	Read the rc.conf(5) var for cmd and set in the
+#	current shell, using load_rc_config in a subshell to prevent
+#	unwanted side effects from other variable assignments.
+#
+load_rc_config_var()
+{
+	if [ $# -ne 2 ]; then
+		err 3 'USAGE: load_rc_config_var cmd var'
+	fi
+	eval $(eval '(
+		load_rc_config '$1' >/dev/null;
+                if [ -n "${'$2'}" -o "${'$2'-UNSET}" != "UNSET" ]; then
+			echo '$2'=\'\''${'$2'}\'\'';
+		fi
+	)' )
+}
 
 #
 # rc_usage commands
@@ -1065,6 +1087,8 @@
 	fi
 }
 
+_rc_subr_loaded=:
+
 # make_symlink src link
 #	Make a symbolic link 'link' to src from basedir. If the
 #	directory in which link is to be created does not exist

==== //depot/projects/hammer/lib/libc/stdlib/malloc.3#11 (text+ko) ====

@@ -30,9 +30,9 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)malloc.3	8.1 (Berkeley) 6/4/93
-.\" $FreeBSD: src/lib/libc/stdlib/malloc.3,v 1.68 2006/03/28 22:16:04 jasone Exp $
+.\" $FreeBSD: src/lib/libc/stdlib/malloc.3,v 1.69 2006/04/04 20:27:53 jasone Exp $
 .\"
-.Dd March 28, 2006
+.Dd April 4, 2006
 .Dt MALLOC 3
 .Os
 .Sh NAME
@@ -316,6 +316,11 @@
 The
 .Fn free
 function returns no value.
+.Pp
+The
+.Fn malloc_usable_size
+function returns the usable size of the allocation pointed to by
+.Fa ptr .
 .Sh IMPLEMENTATION NOTES
 This allocator uses multiple arenas in order to reduce lock contention for
 threaded programs on multi-processor systems.

==== //depot/projects/hammer/lib/libc/stdlib/malloc.c#27 (text+ko) ====

@@ -66,7 +66,7 @@
  *   |          | Sub-page       |   1 kB |
  *   |          |                |   2 kB |
  *   |====================================|
- *   | Medium                    |   4 kB |
+ *   | Large                     |   4 kB |
  *   |                           |   8 kB |
  *   |                           |  16 kB |
  *   |                           |    ... |
@@ -74,7 +74,7 @@
  *   |                           | 512 kB |
  *   |                           |   1 MB |
  *   |====================================|
- *   | Large                     |   2 MB |
+ *   | Huge                      |   2 MB |
  *   |                           |   4 MB |
  *   |                           |   6 MB |
  *   |                           |    ... |
@@ -85,11 +85,11 @@
  *   Small : Each size class is segregated into its own set of runs.  Each run
  *           maintains a bitmap of which regions are free/allocated.
  *
- *   Medium : Each allocation is backed by a dedicated run.  Metadata are stored
- *            in the associated arena chunk header maps.
+ *   Large : Each allocation is backed by a dedicated run.  Metadata are stored
+ *           in the associated arena chunk header maps.
  *
- *   Large : Each allocation is backed by a dedicated contiguous set of chunks.
- *           Metadata are stored in a separate red-black tree.
+ *   Huge : Each allocation is backed by a dedicated contiguous set of chunks.
+ *          Metadata are stored in a separate red-black tree.
  *
  *******************************************************************************
  */
@@ -143,8 +143,10 @@
 	(a_qr_b)->a_field.qre_prev = t;					\
 } while (0)
 
-/* qr_meld() and qr_split() are functionally equivalent, so there's no need to
- * have two copies of the code. */
+/*
+ * qr_meld() and qr_split() are functionally equivalent, so there's no need to
+ * have two copies of the code.
+ */
 #define	qr_split(a_qr_a, a_qr_b, a_type, a_field)			\
 	qr_meld((a_qr_a), (a_qr_b), a_type, a_field)
 
@@ -173,7 +175,7 @@
 
 /*
  * In order to disable various extra features that may have negative
- * performance impacts, (assertions, expanded statistics, redzones), define
+ * performance impacts, (assertions, expanded statistics), define
  * NO_MALLOC_EXTRAS.
  */
 /* #define NO_MALLOC_EXTRAS */
@@ -183,7 +185,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdlib/malloc.c,v 1.120 2006/03/30 20:25:52 jasone Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdlib/malloc.c,v 1.122 2006/04/04 19:46:28 jasone Exp $");
 
 #include "libc_private.h"
 #ifdef MALLOC_DEBUG
@@ -348,8 +350,12 @@
 	spinlock_t	lock;
 } malloc_mutex_t;
 
+/* Set to true once the allocator has been initialized. */
 static bool malloc_initialized = false;
 
+/* Used to avoid initialization races. */
+static malloc_mutex_t init_lock = {_SPINLOCK_INITIALIZER};
+
 /******************************************************************************/
 /*
  * Statistics data structures.
@@ -654,7 +660,7 @@
  */
 
 /* Used as a special "nil" return value for malloc(0). */
-static int		nil;
+static const int	nil;
 
 /* Number of CPUs. */
 static unsigned		ncpus;
@@ -1498,62 +1504,125 @@
 /* Generate red-black tree code for arena chunks. */
 RB_GENERATE_STATIC(arena_chunk_tree_s, arena_chunk_s, link, arena_chunk_comp);
 
-static inline void
-arena_run_mask_free_set(arena_run_t *run, unsigned reg)
+static inline void *
+arena_run_reg_alloc(arena_run_t *run, arena_bin_t *bin)
 {
-	unsigned elm, bit;
+	void *ret;
+	unsigned i, mask, bit, regind;
 
 	assert(run->magic == ARENA_RUN_MAGIC);
-	assert(reg < run->bin->nregs);
+
+	for (i = run->regs_minelm; i < REGS_MASK_NELMS; i++) {
+		mask = run->regs_mask[i];
+		if (mask != 0) {
+			/* Usable allocation found. */
+			bit = ffs(mask) - 1;
+
+			regind = ((i << (SIZEOF_INT_2POW + 3)) + bit);
+			ret = (void *)&((char *)run)[bin->reg0_offset
+			    + (bin->reg_size * regind)];
+
+			/* Clear bit. */
+			mask ^= (1 << bit);
+			run->regs_mask[i] = mask;
 
-	elm = reg >> (SIZEOF_INT_2POW + 3);
-	if (elm < run->regs_minelm)
-		run->regs_minelm = elm;
-	bit = reg - (elm << (SIZEOF_INT_2POW + 3));
-	assert((run->regs_mask[elm] & (1 << bit)) == 0);
-	run->regs_mask[elm] |= (1 << bit);
+			return (ret);
+		} else {
+			/*
+			 * Make a note that nothing before this element
+			 * contains a free region.
+			 */
+			run->regs_minelm = i + 1;
+		}
+	}
+	/* Not reached. */
+	assert(0);
 }
 
 static inline void
-arena_run_mask_free_unset(arena_run_t *run, unsigned reg)
+arena_run_reg_dalloc(arena_run_t *run, arena_bin_t *bin, void *ptr, size_t size)
 {
-	unsigned elm, bit;
+	unsigned diff, regind, elm, bit;
 
 	assert(run->magic == ARENA_RUN_MAGIC);
-	assert(reg < run->bin->nregs);
 
-	elm = reg >> (SIZEOF_INT_2POW + 3);
-	bit = reg - (elm << (SIZEOF_INT_2POW + 3));
-	assert((run->regs_mask[elm] & (1 << bit)) != 0);
-	run->regs_mask[elm] ^= (1 << bit);
-}
+	/*
+	 * Avoid doing division with a variable divisor if possible.  This
+	 * single operation can reduce allocator throughput by around 20%!
+	 */
+#define POW2_CASE(p)							\
+		case (1 << (p)):					\
+			regind = diff >> (p);				\
+			break;
+#define QUANTUM_CASE(n)							\
+		case ((n) << QUANTUM_2POW_MIN):				\
+			regind = diff / ((n) << QUANTUM_2POW_MIN);	\
+			break;
 
-static inline unsigned
-arena_run_search(arena_run_t *run)
-{
-	unsigned i, mask, bit;
+	/*
+	 * These assertions make sure that the switch statement matches
+	 * compile-time configuration.
+	 */
+	assert(tiny_min_2pow >= 1);
+	assert(QUANTUM_2POW_MIN >= 3 && QUANTUM_2POW_MIN <= 4);
+	assert(SMALL_MAX_2POW_DEFAULT == 9);
 
-	assert(run->magic == ARENA_RUN_MAGIC);
+	diff = (unsigned)((uintptr_t)ptr - (uintptr_t)run - bin->reg0_offset);
+	switch (size) {
+		POW2_CASE(1)
+		POW2_CASE(2)
+#if (QUANTUM_2POW_MIN > 3)
+		POW2_CASE(3)
+#endif
+		QUANTUM_CASE(1)
+		QUANTUM_CASE(2)
+		QUANTUM_CASE(3)
+		QUANTUM_CASE(4)
+		QUANTUM_CASE(5)
+		QUANTUM_CASE(6)
+		QUANTUM_CASE(7)
+		QUANTUM_CASE(8)
+		QUANTUM_CASE(9)
+		QUANTUM_CASE(10)
+		QUANTUM_CASE(11)
+		QUANTUM_CASE(12)
+		QUANTUM_CASE(13)
+		QUANTUM_CASE(14)
+		QUANTUM_CASE(15)
+		QUANTUM_CASE(16)
+		QUANTUM_CASE(17)
+		QUANTUM_CASE(18)
+		QUANTUM_CASE(19)
+		QUANTUM_CASE(20)
+		QUANTUM_CASE(21)
+		QUANTUM_CASE(22)
+		QUANTUM_CASE(23)
+		QUANTUM_CASE(24)
+		QUANTUM_CASE(25)
+		QUANTUM_CASE(26)
+		QUANTUM_CASE(27)
+		QUANTUM_CASE(28)
+		QUANTUM_CASE(29)
+		QUANTUM_CASE(30)
+		QUANTUM_CASE(31)
+		QUANTUM_CASE(32)
 
-	for (i = run->regs_minelm; i < REGS_MASK_NELMS; i++) {
-		mask = run->regs_mask[i];
-		if (mask != 0) {
-			bit = ffs(mask);
-			if (bit != 0) {
-				/* Usable allocation found. */
-				return ((i << (SIZEOF_INT_2POW + 3))
-				    + bit - 1);
-			}
-		} else {
-			/*
-			 * Make a note that nothing before this element
-			 * contains a free region.
-			 */
-			run->regs_minelm = i + 1;
-		}
+		POW2_CASE(10)
+		POW2_CASE(11)
+		POW2_CASE(12) /* Handle up to 8 kB pages. */
+		default:
+			regind = diff / size;
 	}
+#undef POW2_CASE
+#undef QUANTUM_CASE
+	assert(regind < bin->nregs);
 
-	return (UINT_MAX);
+	elm = regind >> (SIZEOF_INT_2POW + 3);
+	if (elm < run->regs_minelm)
+		run->regs_minelm = elm;
+	bit = regind - (elm << (SIZEOF_INT_2POW + 3));
+	assert((run->regs_mask[elm] & (1 << bit)) == 0);
+	run->regs_mask[elm] |= (1 << bit);
 }
 
 static void
@@ -1638,7 +1707,7 @@
 		header_size += pagesize - (header_size % pagesize);
 	}
 
-	header_npages = header_size / pagesize;
+	header_npages = header_size >> pagesize_2pow;
 	pow2_header_npages = pow2_ceil(header_npages);
 
 	/*
@@ -1665,7 +1734,7 @@
 	 * the beginning of the chunk, which we just took care of by
 	 * "allocating" the leading pages.
 	 */
-	while (map_offset < (chunk_size / pagesize)) {
+	while (map_offset < (chunk_size >> pagesize_2pow)) {
 		log2_run_pages = ffs(map_offset) - 1;
 		run_pages = (1 << log2_run_pages);
 		for (i = 0; i < run_pages; i++) {
@@ -1858,7 +1927,7 @@
 	 * large enough.  Look for a precise fit, but do not pass up a chunk
 	 * that has a run which is large enough to split.
 	 */
-	min_ind = ffs(size / pagesize) - 1;
+	min_ind = ffs(size >> pagesize_2pow) - 1;
 	RB_FOREACH(chunk, arena_chunk_tree_s, &arena->chunks) {
 		for (i = min_ind;
 		    i < (opt_chunk_2pow - pagesize_2pow);
@@ -2044,18 +2113,12 @@
     size_t size)
 {
 	void *ret;
-	unsigned regind;
 
 	assert(run->magic == ARENA_RUN_MAGIC);
 	assert(run->nfree > 0);
 
-	regind = arena_run_search(run);
-	assert(regind != UINT_MAX);
-	assert(regind < bin->nregs);
-
-	ret = (void *)&((char *)run)[bin->reg0_offset + (bin->reg_size
-	    * regind)];
-	arena_run_mask_free_unset(run, regind);
+	ret = arena_run_reg_alloc(run, bin);
+	assert(ret != NULL);
 	run->nfree--;
 	if (run->nfree < run->free_min) {
 		/* Promote run to higher fullness quartile. */
@@ -2256,7 +2319,6 @@
 	if (mapelm.large == false) {
 		arena_run_t *run;
 		arena_bin_t *bin;
-		unsigned regind;
 
 		/* Small allocation. */
 
@@ -2270,10 +2332,8 @@
 		if (opt_junk)
 			memset(ptr, 0x5a, size);
 
-		regind = (unsigned)(((uintptr_t)ptr - (uintptr_t)run
-		    - bin->reg0_offset) / size);
 		malloc_mutex_lock(&arena->mtx);
-		arena_run_mask_free_set(run, regind);
+		arena_run_reg_dalloc(run, bin, ptr, size);
 		run->nfree++;
 		if (run->nfree > run->free_max) {
 			/* Demote run to lower fullness quartile. */
@@ -2913,12 +2973,6 @@
 malloc_init(void)
 {
 
-	/*
-	 * We always initialize before threads are created, since any thread
-	 * creation first triggers allocations.
-	 */
-	assert(__isthreaded == 0 || malloc_initialized);
-
 	if (malloc_initialized == false)
 		return (malloc_init_hard());
 
@@ -2933,6 +2987,16 @@
 	char buf[PATH_MAX + 1];
 	const char *opts;
 
+	malloc_mutex_lock(&init_lock);
+	if (malloc_initialized) {
+		/*
+		 * Another thread initialized the allocator before this one
+		 * acquired init_lock.
+		 */
+		malloc_mutex_unlock(&init_lock);
+		return (false);
+	}
+
 	/* Get number of CPUs. */
 	{
 		int mib[2];
@@ -3283,8 +3347,10 @@
 
 	/* Allocate and initialize arenas. */
 	arenas = (arena_t **)base_alloc(sizeof(arena_t *) * narenas);
-	if (arenas == NULL)
+	if (arenas == NULL) {
+		malloc_mutex_unlock(&init_lock);
 		return (true);
+	}
 	/*
 	 * Zero the array.  In practice, this should always be pre-zeroed,
 	 * since it was just mmap()ed, but let's be sure.
@@ -3296,12 +3362,15 @@
 	 * arena_choose_hard().
 	 */
 	arenas_extend(0);
-	if (arenas[0] == NULL)
+	if (arenas[0] == NULL) {
+		malloc_mutex_unlock(&init_lock);
 		return (true);
+	}
 
 	malloc_mutex_init(&arenas_mtx);
 
 	malloc_initialized = true;
+	malloc_mutex_unlock(&init_lock);
 	return (false);
 }
 
@@ -3325,7 +3394,7 @@
 
 	if (size == 0) {
 		if (opt_sysv == false)
-			ret = &nil;
+			ret = (void *)&nil;
 		else
 			ret = NULL;
 		goto RETURN;
@@ -3407,11 +3476,17 @@
 	num_size = num * size;
 	if (num_size == 0) {
 		if (opt_sysv == false)
-			ret = &nil;
+			ret = (void *)&nil;
 		else
 			ret = NULL;
 		goto RETURN;
-	} else if (num_size / size != num) {
+	/*
+	 * Try to avoid division here.  We know that it isn't possible to
+	 * overflow during multiplication if neither operand uses any of the
+	 * most significant half of the bits in a size_t.
+	 */
+	} else if (((num | size) & (SIZE_T_MAX << (sizeof(size_t) << 2)))
+	    && (num_size / size != num)) {
 		/* size_t overflow. */
 		ret = NULL;
 		goto RETURN;
@@ -3474,7 +3549,7 @@
 		if (ptr != &nil && ptr != NULL)
 			idalloc(ptr);
 
-		ret = &nil;
+		ret = (void *)&nil;
 	}
 
 	UTRACE(ptr, size, ret);

==== //depot/projects/hammer/lib/libthr/arch/amd64/amd64/pthread_md.c#2 (text+ko) ====

@@ -23,7 +23,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD: src/lib/libthr/arch/amd64/amd64/pthread_md.c,v 1.1 2005/04/02 01:19:57 davidxu Exp $
+ * $FreeBSD: src/lib/libthr/arch/amd64/amd64/pthread_md.c,v 1.2 2006/04/04 03:26:05 davidxu Exp $
  */
 
 #include <sys/types.h>
@@ -38,13 +38,11 @@
 _tcb_ctor(struct pthread *thread, int initial)
 {
 	struct tcb *tcb;
-	void *oldtls;
 
 	if (initial)
-		__asm __volatile("movq %%fs:0, %0" : "=r" (oldtls));
+		__asm __volatile("movq %%fs:0, %0" : "=r" (tcb));
 	else
-		oldtls = NULL;
-	tcb = _rtld_allocate_tls(oldtls, sizeof(struct tcb), 16);
+		tcb = _rtld_allocate_tls(NULL, sizeof(struct tcb), 16);
 	if (tcb)
 		tcb->tcb_thread = thread;
 	return (tcb);

==== //depot/projects/hammer/lib/libthr/arch/amd64/include/pthread_md.h#2 (text+ko) ====

@@ -24,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/lib/libthr/arch/amd64/include/pthread_md.h,v 1.1 2005/04/02 01:19:57 davidxu Exp $
+ * $FreeBSD: src/lib/libthr/arch/amd64/include/pthread_md.h,v 1.3 2006/04/04 03:35:26 davidxu Exp $
  */
 
 /*
@@ -91,13 +91,9 @@
 	return (TCB_GET64(tcb_self));
 }
 
-extern struct pthread *_thr_initial;
-
 static __inline struct pthread *
 _get_curthread(void)
 {
-	if (_thr_initial)
-		return (TCB_GET64(tcb_thread));
-	return (NULL);
+	return (TCB_GET64(tcb_thread));
 }
 #endif

==== //depot/projects/hammer/lib/libthr/arch/i386/i386/pthread_md.c#6 (text+ko) ====

@@ -24,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/lib/libthr/arch/i386/i386/pthread_md.c,v 1.6 2006/01/07 06:01:43 davidxu Exp $
+ * $FreeBSD: src/lib/libthr/arch/i386/i386/pthread_md.c,v 1.7 2006/04/04 03:26:06 davidxu Exp $
  */
 
 #include <sys/types.h>
@@ -39,14 +39,11 @@
 _tcb_ctor(struct pthread *thread, int initial)
 {
 	struct tcb *tcb;
-	void *oldtls;
 
 	if (initial)
-		__asm __volatile("movl %%gs:0, %0" : "=r" (oldtls));
+		__asm __volatile("movl %%gs:0, %0" : "=r" (tcb));
 	else
-		oldtls = NULL;
-
-	tcb = _rtld_allocate_tls(oldtls, sizeof(struct tcb), 16);
+		tcb = _rtld_allocate_tls(NULL, sizeof(struct tcb), 16);
 	if (tcb)
 		tcb->tcb_thread = thread;
 	return (tcb);

==== //depot/projects/hammer/lib/libthr/arch/i386/include/pthread_md.h#5 (text+ko) ====

@@ -24,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/lib/libthr/arch/i386/include/pthread_md.h,v 1.5 2005/10/29 03:08:43 davidxu Exp $
+ * $FreeBSD: src/lib/libthr/arch/i386/include/pthread_md.h,v 1.7 2006/04/04 03:35:25 davidxu Exp $
  */
 
 /*
@@ -94,14 +94,10 @@
 	return (TCB_GET32(tcb_self));
 }
 
-extern struct pthread *_thr_initial;
-
 /* Get the current thread. */
 static __inline struct pthread *
 _get_curthread(void)
 {
-	if (_thr_initial)
-		return (TCB_GET32(tcb_thread));
-	return (NULL);
+	return (TCB_GET32(tcb_thread));
 }
 #endif

==== //depot/projects/hammer/lib/libthr/pthread.map#9 (text+ko) ====

@@ -1,4 +1,4 @@
-# $FreeBSD: src/lib/libthr/pthread.map,v 1.13 2006/03/08 23:47:04 davidxu Exp $
+# $FreeBSD: src/lib/libthr/pthread.map,v 1.14 2006/04/04 02:57:49 davidxu Exp $
 LIBTHREAD_1_0 {
 global:
 	___creat;
@@ -16,8 +16,8 @@
 	__pthread_cond_wait;
 	__pthread_mutex_init;
 	__pthread_mutex_lock;
+	__pthread_mutex_timedlock;
 	__pthread_mutex_trylock;
-	__pthread_mutex_timedlock;
 	__read;
 	__readv;
 	__recvfrom;
@@ -26,6 +26,9 @@
 	__sendmsg;
 	__sendto;
 	__sigsuspend;
+	__sigtimedwait;
+	__sigwait;
+	__sigwaitinfo;
 	__wait4;
 	__write;
 	__writev;
@@ -43,7 +46,6 @@
 	_pthread_barrierattr_getpshared;
 	_pthread_barrierattr_init;
 	_pthread_barrierattr_setpshared;
-	_pthread_attr_default;
 	_pthread_attr_destroy;
 	_pthread_attr_get_np;
 	_pthread_attr_getdetachstate;
@@ -75,7 +77,6 @@
 	_pthread_cond_signal;
 	_pthread_cond_timedwait;
 	_pthread_cond_wait;
-	_pthread_condattr_default;
 	_pthread_condattr_destroy;
 	_pthread_condattr_getclock;
 	_pthread_condattr_getpshared;
@@ -104,7 +105,6 @@
 	_pthread_mutex_timedlock;
 	_pthread_mutex_trylock;
 	_pthread_mutex_unlock;
-	_pthread_mutexattr_default;
 	_pthread_mutexattr_destroy;
 	_pthread_mutexattr_getkind_np;
 	_pthread_mutexattr_getprioceiling;
@@ -156,21 +156,18 @@
 	_pthread_timedjoin_np;
 	_pthread_yield;
 	_raise;
-	_sem_close;
 	_sem_destroy;
 	_sem_getvalue;
 	_sem_init;
-	_sem_open;
 	_sem_post;
 	_sem_timedwait;
 	_sem_trywait;
-	_sem_unlink;
 	_sem_wait;
 	_sigaction;
 	_sigprocmask;
 	_sigsuspend;
+	_sigtimedwait;
 	_sigwait;
-	_sigtimedwait;
 	_sigwaitinfo;
 	_sleep;
 	_spinlock;
@@ -181,7 +178,10 @@
 	_usleep;
 	_vfork;
 	_wait;
+	_wait4;
 	_waitpid;
+	_write;
+	_writev;
 	accept;
 	aio_suspend;
 	close;
@@ -320,21 +320,16 @@
 	recvfrom;
 	recvmsg;
 	select;
-	sem_close;
 	sem_destroy;
 	sem_getvalue;
 	sem_init;
-	sem_open;
 	sem_post;
 	sem_timedwait;
 	sem_trywait;
-	sem_unlink;
 	sem_wait;
 	sendmsg;
 	sendto;
 	sigaction;
-	sigaltstack;
-	sigpending;
 	sigprocmask;
 	sigsuspend;
 	sigwait;

==== //depot/projects/hammer/lib/libthr/thread/Makefile.inc#14 (text+ko) ====

@@ -1,4 +1,4 @@
-# $FreeBSD: src/lib/libthr/thread/Makefile.inc,v 1.15 2006/03/27 23:50:21 davidxu Exp $
+# $FreeBSD: src/lib/libthr/thread/Makefile.inc,v 1.16 2006/04/04 02:57:49 davidxu Exp $
 
 # thr sources
 .PATH: ${.CURDIR}/thread
@@ -39,7 +39,6 @@
 	thr_rwlockattr.c \
 	thr_self.c \
 	thr_sem.c \
-	thr_seterrno.c \
 	thr_setprio.c \
 	thr_setschedparam.c \
 	thr_sig.c \

==== //depot/projects/hammer/lib/libthr/thread/thr_attr.c#5 (text+ko) ====

@@ -93,14 +93,16 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/lib/libthr/thread/thr_attr.c,v 1.4 2006/01/09 03:59:51 davidxu Exp $
+ * $FreeBSD: src/lib/libthr/thread/thr_attr.c,v 1.5 2006/04/04 02:57:49 davidxu Exp $
  */
 
+#include "namespace.h"
 #include <errno.h>
 #include <pthread.h>
 #include <stdlib.h>
 #include <string.h>
 #include <pthread_np.h>
+#include "un-namespace.h"
 
 #include "thr_private.h"
 

==== //depot/projects/hammer/lib/libthr/thread/thr_barrier.c#5 (text+ko) ====

@@ -23,12 +23,14 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/lib/libthr/thread/thr_barrier.c,v 1.4 2005/04/04 23:43:53 davidxu Exp $
+ * $FreeBSD: src/lib/libthr/thread/thr_barrier.c,v 1.5 2006/04/04 02:57:49 davidxu Exp $
  */
 
+#include "namespace.h"
 #include <errno.h>
 #include <stdlib.h>
 #include <pthread.h>
+#include "un-namespace.h"
 
 #include "thr_private.h"
 
@@ -54,10 +56,12 @@
 
 int
 _pthread_barrier_init(pthread_barrier_t *barrier,
-		      const pthread_barrierattr_t *attr, int count)
+		      const pthread_barrierattr_t *attr, unsigned count)
 {
 	pthread_barrier_t	bar;
 
+	(void)attr;
+
 	if (barrier == NULL || count <= 0)
 		return (EINVAL);
 

==== //depot/projects/hammer/lib/libthr/thread/thr_barrierattr.c#3 (text+ko) ====

@@ -25,12 +25,14 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  * DAMAGE.
  *
- * $FreeBSD: src/lib/libthr/thread/thr_barrierattr.c,v 1.2 2005/04/02 01:20:00 davidxu Exp $
+ * $FreeBSD: src/lib/libthr/thread/thr_barrierattr.c,v 1.3 2006/04/04 02:57:49 davidxu Exp $
  */
 
+#include "namespace.h"
 #include <errno.h>
 #include <stdlib.h>
 #include <pthread.h>
+#include "un-namespace.h"
 
 #include "thr_private.h"
 

==== //depot/projects/hammer/lib/libthr/thread/thr_cancel.c#11 (text+ko) ====

@@ -23,11 +23,13 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD: src/lib/libthr/thread/thr_cancel.c,v 1.12 2006/03/25 07:03:13 davidxu Exp $
+ * $FreeBSD: src/lib/libthr/thread/thr_cancel.c,v 1.13 2006/04/04 02:57:49 davidxu Exp $
  *
  */
 
+#include "namespace.h"
 #include <pthread.h>
+#include "un-namespace.h"
 
 #include "thr_private.h"
 
@@ -36,8 +38,6 @@
 __weak_reference(_pthread_setcanceltype, pthread_setcanceltype);
 __weak_reference(_pthread_testcancel, pthread_testcancel);

>>> TRUNCATED FOR MAIL (1000 lines) <<<


More information about the p4-projects mailing list