Received: from eggs.gnu.org ([2001:4830:134:3::10]:44333) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XuMnY-0003u6-H3 for qemu-devel@nongnu.org; Fri, 28 Nov 2014 09:45:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XuMnP-0007hp-Dd for qemu-devel@nongnu.org; Fri, 28 Nov 2014 09:45:28 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34498) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XuMnP-0007hN-75 for qemu-devel@nongnu.org; Fri, 28 Nov 2014 09:45:19 -0500 From: Markus Armbruster References: <1417183941-26329-1-git-send-email-pbonzini@redhat.com> <1417183941-26329-2-git-send-email-pbonzini@redhat.com> Date: Fri, 28 Nov 2014 15:45:08 +0100 In-Reply-To: <1417183941-26329-2-git-send-email-pbonzini@redhat.com> (Paolo Bonzini's message of "Fri, 28 Nov 2014 15:12:15 +0100") Message-ID: <87h9xj2xl7.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH 1/7] coroutine-ucontext: use __thread List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: kwolf@redhat.com, ming.lei@canonical.com, pl@kamp.de, qemu-devel@nongnu.org, stefanha@redhat.com Paolo Bonzini writes: > ELF thread local storage is about 10% faster on tests/test-coroutine's > perf/cost test. The timing on my machine is 160ns per iteration with > pthread TLS, 145 with ELF TLS. > > Based on a patch by Kevin Wolf and Peter Lieven, but redone to follow > the model of coroutine-win32.c (including the important "noinline" > attribute!!!). > > Platforms without thread-local storage (OpenBSD probably?) will need > a new-enough GCC for this to compile, in order to use the same emutls > support that Windows already relies on. [...] > @@ -193,15 +155,22 @@ void qemu_coroutine_delete(Coroutine *co_) > g_free(co); > } > > +/* This function is marked noinline to prevent GCC from inlining it > + * into coroutine_trampoline(). If we allow it to do that then it > + * hoists the code to get the address of the TLS variable "current" > + * out of the while() loop. This is an invalid transformation because > + * the SwitchToFiber() call may be called when running thread A but > + * return in thread B, and so we might be in a different thread > + * context each time round the loop. > + */ > CoroutineAction qemu_coroutine_switch(Coroutine *from_, Coroutine *to_, > CoroutineAction action) Err, did you forget the actual __attribute__((noinline))? > { > CoroutineUContext *from = DO_UPCAST(CoroutineUContext, base, from_); > CoroutineUContext *to = DO_UPCAST(CoroutineUContext, base, to_); > - CoroutineThreadState *s = coroutine_get_thread_state(); > int ret; > > - s->current = to_; > + current = to_; > > ret = sigsetjmp(from->env, 0); > if (ret == 0) { [...]