From owner-svn-src-all@FreeBSD.ORG Thu Jun 20 23:04:42 2013 Return-Path: Delivered-To: svn-src-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 4E0FA78A; Thu, 20 Jun 2013 23:04:42 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail108.syd.optusnet.com.au (mail108.syd.optusnet.com.au [211.29.132.59]) by mx1.freebsd.org (Postfix) with ESMTP id 138151BC3; Thu, 20 Jun 2013 23:04:41 +0000 (UTC) Received: from c122-106-156-23.carlnfd1.nsw.optusnet.com.au (c122-106-156-23.carlnfd1.nsw.optusnet.com.au [122.106.156.23]) by mail108.syd.optusnet.com.au (Postfix) with ESMTPS id 34A8C1A0B10; Fri, 21 Jun 2013 09:04:35 +1000 (EST) Date: Fri, 21 Jun 2013 09:04:34 +1000 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Bruce Evans Subject: Re: svn commit: r252032 - head/sys/amd64/include In-Reply-To: <20130621081116.E1151@besplex.bde.org> Message-ID: <20130621090207.F1318@besplex.bde.org> References: <201306201430.r5KEU4G5049115@svn.freebsd.org> <20130621065839.J916@besplex.bde.org> <20130621081116.E1151@besplex.bde.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.0 cv=eqSHVfVX c=1 sm=1 a=0l9hOOMEwYoA:10 a=kj9zAlcOel0A:10 a=PO7r1zJSAAAA:8 a=JzwRw_2MAAAA:8 a=gvJhbHXk4isA:10 a=WtSis1_khTDf0p0YjwUA:9 a=CjuIK1q_8ugA:10 a=ebeQFi2P/qHVC0Yw9JDJ4g==:117 Cc: svn-src-head@FreeBSD.org, svn-src-all@FreeBSD.org, src-committers@FreeBSD.org, Konstantin Belousov X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list 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, 20 Jun 2013 23:04:42 -0000 On Fri, 21 Jun 2013, Bruce Evans wrote: > On Fri, 21 Jun 2013, I wrote: > >> On Thu, 20 Jun 2013, Konstantin Belousov wrote: >>> ... >>> @@ -44,7 +44,7 @@ counter_u64_add(counter_u64_t c, int64_t >>> ... >> The i386 version of the counter asm doesn't support the immediate >> constraint for technical reasons. 64 bit counters are too large and >> slow to use on i386, especially when they are implemented as they are >> without races. > > Actual testing showed that it is only about twice as slow as a direct > increment. With the enclosed test program (a userland version hacked > on a bit to avoid pcpu), on ref10-i386 the times are: > - loop overhead: 1 cycle > - direct unlocked increment of a uint32_t: 6 cycles > - direct unlocked increment of a uint64_t: 7 cycles > - non-inline function unlocked increment of a uint64_t: 7.5 cycles > - counter_u64_add(): 14 cycles > - non-inline counter_u64_add(): 18 cycles > ... Actually enclosing the test program: % #include % #include % % static inline void % counter_64_inc_8b(volatile uint64_t *p, int64_t inc) % { % % __asm __volatile( % "movl %%ds:(%%esi),%%eax\n\t" % "movl %%ds:4(%%esi),%%edx\n" % "1:\n\t" % "movl %%eax,%%ebx\n\t" % "movl %%edx,%%ecx\n\t" % "addl (%%edi),%%ebx\n\t" % "adcl 4(%%edi),%%ecx\n\t" % "cmpxchg8b %%ds:(%%esi)\n\t" % "jnz 1b" % : % : "S" (p), "D" (&inc) % : "memory", "cc", "eax", "edx", "ebx", "ecx"); % } % % uint32_t cpu_feature = 1; % % typedef volatile uint64_t *counter_u64_t; % % static void % #if 1 % inline % #else % __noinline % #endif % counter_u64_add(counter_u64_t c, int64_t inc) % { % % #if 1 % if ((cpu_feature & 1) == 1) { % counter_64_inc_8b(c, inc); % } % #elif 0 % if ((cpu_feature & 1) == 1) { % *c += inc; % } % #else % *c += inc; % #endif % } % % uint64_t mycounter[1]; % % int % main(void) % { % unsigned i; % % for (i = 0; i < 1861955704; i++) /* sysctl -n machdep.tsc_freq */ % counter_u64_add(mycounter, 1); % printf("%ju\n", (uintmax_t)mycounter[0]); % } Bruce