From owner-svn-src-head@FreeBSD.ORG Thu May 3 09:17:32 2012 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 0B05D106566B; Thu, 3 May 2012 09:17:32 +0000 (UTC) (envelope-from davidxu@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id D066D8FC0C; Thu, 3 May 2012 09:17:31 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q439HVYA029732; Thu, 3 May 2012 09:17:31 GMT (envelope-from davidxu@svn.freebsd.org) Received: (from davidxu@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q439HVln029728; Thu, 3 May 2012 09:17:31 GMT (envelope-from davidxu@svn.freebsd.org) Message-Id: <201205030917.q439HVln029728@svn.freebsd.org> From: David Xu Date: Thu, 3 May 2012 09:17:31 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r234947 - head/lib/libthr/thread X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 May 2012 09:17:32 -0000 Author: davidxu Date: Thu May 3 09:17:31 2012 New Revision: 234947 URL: http://svn.freebsd.org/changeset/base/234947 Log: MFp4: Enqueue thread in LIFO, this can cause starvation, but it gives better performance. Use _thr_queuefifo to control the frequency of FIFO vs LIFO, you can use environment string LIBPTHREAD_QUEUE_FIFO to configure the variable. Modified: head/lib/libthr/thread/thr_init.c head/lib/libthr/thread/thr_private.h head/lib/libthr/thread/thr_sleepq.c Modified: head/lib/libthr/thread/thr_init.c ============================================================================== --- head/lib/libthr/thread/thr_init.c Thu May 3 08:56:43 2012 (r234946) +++ head/lib/libthr/thread/thr_init.c Thu May 3 09:17:31 2012 (r234947) @@ -112,6 +112,7 @@ size_t _thr_stack_initial = THR_STACK_I int _thr_page_size; int _thr_spinloops; int _thr_yieldloops; +int _thr_queuefifo = 4; int _gc_count; struct umutex _mutex_static_lock = DEFAULT_UMUTEX; struct umutex _cond_static_lock = DEFAULT_UMUTEX; @@ -470,6 +471,9 @@ init_private(void) env = getenv("LIBPTHREAD_YIELDLOOPS"); if (env) _thr_yieldloops = atoi(env); + env = getenv("LIBPTHREAD_QUEUE_FIFO"); + if (env) + _thr_queuefifo = atoi(env); TAILQ_INIT(&_thr_atfork_list); } init_once = 1; Modified: head/lib/libthr/thread/thr_private.h ============================================================================== --- head/lib/libthr/thread/thr_private.h Thu May 3 08:56:43 2012 (r234946) +++ head/lib/libthr/thread/thr_private.h Thu May 3 09:17:31 2012 (r234947) @@ -710,6 +710,7 @@ extern size_t _thr_stack_initial __hidde extern int _thr_page_size __hidden; extern int _thr_spinloops __hidden; extern int _thr_yieldloops __hidden; +extern int _thr_queuefifo __hidden; /* Garbage thread count. */ extern int _gc_count __hidden; Modified: head/lib/libthr/thread/thr_sleepq.c ============================================================================== --- head/lib/libthr/thread/thr_sleepq.c Thu May 3 08:56:43 2012 (r234946) +++ head/lib/libthr/thread/thr_sleepq.c Thu May 3 09:17:31 2012 (r234947) @@ -39,6 +39,7 @@ struct sleepqueue_chain { struct umutex sc_lock; + int sc_enqcnt; LIST_HEAD(, sleepqueue) sc_queues; int sc_type; }; @@ -124,7 +125,10 @@ _sleepq_add(void *wchan, struct pthread } td->sleepqueue = NULL; td->wchan = wchan; - TAILQ_INSERT_TAIL(&sq->sq_blocked, td, wle); + if (((++sc->sc_enqcnt << _thr_queuefifo) & 0xff) != 0) + TAILQ_INSERT_HEAD(&sq->sq_blocked, td, wle); + else + TAILQ_INSERT_TAIL(&sq->sq_blocked, td, wle); } int