Date: Sun, 30 Nov 2008 05:55:24 +0000 (UTC) From: Jason Evans <jasone@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r185468 - head/lib/libc/stdlib Message-ID: <200811300555.mAU5tOZX074568@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jasone Date: Sun Nov 30 05:55:24 2008 New Revision: 185468 URL: http://svn.freebsd.org/changeset/base/185468 Log: Do not spin when trying to lock on a single-CPU system. Reported by: davidxu Modified: head/lib/libc/stdlib/malloc.c Modified: head/lib/libc/stdlib/malloc.c ============================================================================== --- head/lib/libc/stdlib/malloc.c Sun Nov 30 05:45:18 2008 (r185467) +++ head/lib/libc/stdlib/malloc.c Sun Nov 30 05:55:24 2008 (r185468) @@ -1262,18 +1262,20 @@ malloc_spin_lock(pthread_mutex_t *lock) if (__isthreaded) { if (_pthread_mutex_trylock(lock) != 0) { - unsigned i; - volatile unsigned j; + /* Exponentially back off if there are multiple CPUs. */ + if (ncpus > 1) { + unsigned i; + volatile unsigned j; + + for (i = 1; i <= SPIN_LIMIT_2POW; i++) { + for (j = 0; j < (1U << i); j++) { + ret++; + CPU_SPINWAIT; + } - /* Exponentially back off. */ - for (i = 1; i <= SPIN_LIMIT_2POW; i++) { - for (j = 0; j < (1U << i); j++) { - ret++; - CPU_SPINWAIT; + if (_pthread_mutex_trylock(lock) == 0) + return (ret); } - - if (_pthread_mutex_trylock(lock) == 0) - return (ret); } /*
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200811300555.mAU5tOZX074568>