Received: from eggs.gnu.org ([2001:4830:134:3::10]:45297) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XHZZZ-0008Ly-VG for qemu-devel@nongnu.org; Wed, 13 Aug 2014 10:30:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XHZZU-00021F-UA for qemu-devel@nongnu.org; Wed, 13 Aug 2014 10:30:41 -0400 Received: from wanbli.kerneis.info ([176.31.113.173]:42484) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XHZZU-0001zO-D9 for qemu-devel@nongnu.org; Wed, 13 Aug 2014 10:30:36 -0400 In-Reply-To: <20140813142729.GB3091@irqsave.net> References: <1407924527-32687-1-git-send-email-ming.lei@canonical.com> <20140813142729.GB3091@irqsave.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 From: Gabriel Kerneis Date: Wed, 13 Aug 2014 16:31:28 +0200 Message-ID: Subject: Re: [Qemu-devel] [PATCH v1] test-coroutine: test cost introduced by coroutine List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?ISO-8859-1?Q?Beno=EEt_Canet?= , Ming Lei Cc: Kevin Wolf , Peter Maydell , qemu-devel@nongnu.org, Charlie Shepherd , Stefan Hajnoczi , Paolo Bonzini On 13 août 2014 16:27:29 CEST, "Benoît Canet" wrote: > The Wednesday 13 Aug 2014 à 18:08:47 (+0800), Ming Lei wrote : > > This test runs dummy function with coroutine by using > > two enter and one yield since which is a common usage. > > > > So we can see the cost introduced by corouting for running > > one function, for example: > > > > Run operation 20000000 iterations 4.841071 s, 4131K operations/s > > 242ns per coroutine > > > > Signed-off-by: Ming Lei > > --- > > tests/test-coroutine.c | 30 ++++++++++++++++++++++++++++++ > > 1 file changed, 30 insertions(+) > > > > diff --git a/tests/test-coroutine.c b/tests/test-coroutine.c > > index 6e634f4..e22fae1 100644 > > --- a/tests/test-coroutine.c > > +++ b/tests/test-coroutine.c > > @@ -311,6 +311,35 @@ static void perf_baseline(void) > > maxcycles, duration); > > } > > > > +static __attribute__((noinline)) void perf_cost_func(void *opaque) > > +{ > > + qemu_coroutine_yield(); > > +} > > + > > +static void perf_cost(void) > > +{ > > + const unsigned long maxcycles = 40000000; > > + unsigned long i = 0; > > + double duration; > > + unsigned long ops; > > + Coroutine *co; > > + > > + g_test_timer_start(); > > + while (i++ < maxcycles) { > > + co = qemu_coroutine_create(perf_cost_func); > > I am not sure qemu_coroutine_create is systematically used. > I rather believe the code try to reuse existing coroutine. Isn't it what the coroutine pool is for? Is there really code duplicating it manually? > > > + qemu_coroutine_enter(co, &i); > > + qemu_coroutine_enter(co, NULL); > > + } > > + duration = g_test_timer_elapsed(); > > + ops = (long)(maxcycles / (duration * 1000)); > > + > > + g_test_message("Run operation %lu iterations %f s, %luK > operations/s, " > > + "%luns per coroutine", > > + maxcycles, > > + duration, ops, > > + (unsigned long)(1000000000 * duration) / > maxcycles); > > +} > > + > > int main(int argc, char **argv) > > { > > g_test_init(&argc, &argv, NULL); > > @@ -325,6 +354,7 @@ int main(int argc, char **argv) > > g_test_add_func("/perf/nesting", perf_nesting); > > g_test_add_func("/perf/yield", perf_yield); > > g_test_add_func("/perf/function-call", perf_baseline); > > + g_test_add_func("/perf/cost", perf_cost); > > } > > return g_test_run(); > > } > > -- > > 1.7.9.5 > > > > -- Gabriel