From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754507AbYKMSfb (ORCPT ); Thu, 13 Nov 2008 13:35:31 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751635AbYKMSfW (ORCPT ); Thu, 13 Nov 2008 13:35:22 -0500 Received: from hrndva-omtalb.mail.rr.com ([71.74.56.122]:40536 "EHLO hrndva-omtalb.mail.rr.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751584AbYKMSfW (ORCPT ); Thu, 13 Nov 2008 13:35:22 -0500 Date: Thu, 13 Nov 2008 13:35:20 -0500 (EST) From: Steven Rostedt X-X-Sender: rostedt@gandalf.stny.rr.com To: Andi Kleen cc: =?ISO-8859-15?Q?Fr=E9d=E9ric_Weisbecker?= , Ingo Molnar , Linux Kernel Subject: Re: [PATCH 1/2] tracing/function-return-tracer: Make the function return tracer lockless In-Reply-To: <20081113182937.GZ3810@one.firstfloor.org> Message-ID: References: <491B4F0A.3080901@gmail.com> <87od0jd6ds.fsf@basil.nowhere.org> <20081113171220.GX3810@one.firstfloor.org> <20081113173451.GY3810@one.firstfloor.org> <20081113182937.GZ3810@one.firstfloor.org> User-Agent: Alpine 1.10 (DEB 962 2008-03-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 13 Nov 2008, Andi Kleen wrote: > On Thu, Nov 13, 2008 at 12:32:23PM -0500, Steven Rostedt wrote: > > > > On Thu, 13 Nov 2008, Andi Kleen wrote: > > > > > > So the answer to this is: > > > > > > > > i = index++; > > > > barrier(); > > > > write to index i (not index); > > > > > > That was my first thought when I wrote the original email, > > > but the disadvantage is that barrier() is a big hammer > > > that flushes everything and can make the code much worse. > > > That is why I suggested local_add_return() instead. > > > > barrier() is a compiler barrier, does nothing with the caches, and is > > quite cheap. We only need a compiler barrier because we are only > > I did not refer to CPU caches, but the compiler's register allocation > [ok if you want the registers are the "level 0 cache"]. A memory barrier > all messes it up. That is why it is better to only clobber specific > memory regions, which is what local_* does. > #define barrier() __asm__ __volatile__("": : :"memory") static inline long local_add_return(long i, local_t *l) { long __i; #ifdef CONFIG_M386 unsigned long flags; if (unlikely(boot_cpu_data.x86 <= 3)) goto no_xadd; #endif /* Modern 486+ processor */ __i = i; asm volatile(_ASM_XADD "%0, %1;" : "+r" (i), "+m" (l->a.counter) : : "memory"); return i + __i; #ifdef CONFIG_M386 no_xadd: /* Legacy 386 processor */ local_irq_save(flags); __i = local_read(l); local_set(l, i + __i); local_irq_restore(flags); return i + __i; #endif } Now tell me again how local_* is more efficient than barrier? Not to mention, if this is ever used on other archs with load-linked and store-conditional, it gets even worse. -- Steve