Date: Tue, 30 Oct 2007 05:57:37 +0000 (UTC) From: David Xu <davidxu@FreeBSD.org> To: src-committers@FreeBSD.org, cvs-src@FreeBSD.org, cvs-all@FreeBSD.org Subject: cvs commit: src/lib/libthr/thread thr_init.c thr_mutex.c thr_private.h Message-ID: <200710300557.l9U5vbEv020354@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
davidxu 2007-10-30 05:57:37 UTC FreeBSD src repository Modified files: lib/libthr/thread thr_init.c thr_mutex.c thr_private.h Log: Add my recent work of adaptive spin mutex code. Use two environments variable to tune pthread mutex performance: 1. LIBPTHREAD_SPINLOOPS If a pthread mutex is being locked by another thread, this environment variable sets total number of spin loops before the current thread sleeps in kernel, this saves a syscall overhead if the mutex will be unlocked very soon (well written application code). 2. LIBPTHREAD_YIELDLOOPS If a pthread mutex is being locked by other threads, this environment variable sets total number of sched_yield() loops before the currrent thread sleeps in kernel. if a pthread mutex is locked, the current thread gives up cpu, but will not sleep in kernel, this means, current thread does not set contention bit in mutex, but let lock owner to run again if the owner is on kernel's run queue, and when lock owner unlocks the mutex, it does not need to enter kernel and do lots of work to resume mutex waiters, in some cases, this saves lots of syscall overheads for mutex owner. In my practice, sometimes LIBPTHREAD_YIELDLOOPS can massively improve performance than LIBPTHREAD_SPINLOOPS, this depends on application. These two environments are global to all pthread mutex, there is no interface to set them for each pthread mutex, the default values are zero, this means spinning is turned off by default. Revision Changes Path 1.47 +9 -1 src/lib/libthr/thread/thr_init.c 1.56 +37 -45 src/lib/libthr/thread/thr_mutex.c 1.79 +4 -1 src/lib/libthr/thread/thr_private.h
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200710300557.l9U5vbEv020354>