From owner-svn-src-all@FreeBSD.ORG Thu Jan 19 05:57:56 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 23C1D106566B; Thu, 19 Jan 2012 05:57:56 +0000 (UTC) (envelope-from listlog2011@gmail.com) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id E86988FC15; Thu, 19 Jan 2012 05:57:55 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.5/8.14.5) with ESMTP id q0J5vpra058026; Thu, 19 Jan 2012 05:57:52 GMT (envelope-from listlog2011@gmail.com) Message-ID: <4F17B0DE.3060008@gmail.com> Date: Thu, 19 Jan 2012 13:57:50 +0800 From: David Xu User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:9.0) Gecko/20111222 Thunderbird/9.0.1 MIME-Version: 1.0 To: davidxu@freebsd.org References: <201201160615.q0G6FE9r019542@svn.freebsd.org> <201201170957.47718.jhb@freebsd.org> <4F1629D5.4020605@gmail.com> <201201181009.23221.jhb@freebsd.org> <4F178CDC.3030807@gmail.com> In-Reply-To: <4F178CDC.3030807@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Cc: svn-src-head@freebsd.org, svn-src-all@freebsd.org, src-committers@freebsd.org, John Baldwin Subject: Re: svn commit: r230201 - head/lib/libc/gen X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: davidxu@freebsd.org List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Jan 2012 05:57:56 -0000 On 2012/1/19 11:24, David Xu wrote: > On 2012/1/18 23:09, John Baldwin wrote: >> On Tuesday, January 17, 2012 9:09:25 pm David Xu wrote: >>> On 2012/1/17 22:57, John Baldwin wrote: >>>> On Monday, January 16, 2012 1:15:14 am David Xu wrote: >>>>> Author: davidxu >>>>> Date: Mon Jan 16 06:15:14 2012 >>>>> New Revision: 230201 >>>>> URL: http://svn.freebsd.org/changeset/base/230201 >>>>> >>>>> Log: >>>>> Insert read memory barriers. >>>> I think using atomic_load_acq() on sem->nwaiters would be clearer >>>> as it would >>>> indicate which variable you need to ensure is read after other >>>> operations. In >>>> general I think raw rmb/wmb usage should be avoided when possible >>>> as it is >>>> does not describe the programmer's intent as well. >>>> >>> Yes, I had considered that I may use atomic_load_acq(), but at that >>> time, >>> I thought it emits a bus locking, right ? so I just picked up rmb() >>> which >>> only affects current cpu. maybe atomic_load_acq() does same thing with >>> rmb() ? >>> it is still unclear to me. >> atomic_load_acq() is the same as rmb(). Right now it uses a locked >> instruction on amd64, but it could easily switch to lfence/sfence >> instead. I >> had patches to do that but I think bde@ had done some benchmarks that >> showed >> that change made no difference. >> > I wish there is a version uses lfence for atomic_load_acq(). I always > think > bus locking is expensive on a multiple-core machine. Here we work on > large > machine found that even current rwlock in libthr is not scale well if > most threads are readers, we have to implement CSNZI-like rwlock to avoid > CPU conflict. > http://people.csail.mit.edu/mareko/spaa09-scalablerwlocks.pdf > > I have just done a benchmark on my notebook which is a 4 SMT sandy bridge > CPU i3 2310m. > http://people.freebsd.org/~davidxu/bench/semaphore/ > > > The load_acq uses atomic locking is much slower than lfence: > http://people.freebsd.org/~davidxu/bench/semaphore/ministat.txt > > > benchmark program: > http://people.freebsd.org/~davidxu/bench/semaphore/sem_test.c > > rdtsc() may not work on SMP, so I have updated it to use clock_gettime to get total time. http://people.freebsd.org/~davidxu/bench/semaphore2/ Still, lfence is a lot faster than atomic lock.