From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:33469) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QNNR2-0004N9-5g for qemu-devel@nongnu.org; Fri, 20 May 2011 07:00:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QNNR1-0005KO-3Z for qemu-devel@nongnu.org; Fri, 20 May 2011 07:00:00 -0400 Received: from mtagate3.uk.ibm.com ([194.196.100.163]:40838) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QNNR0-0005Ij-QX for qemu-devel@nongnu.org; Fri, 20 May 2011 06:59:58 -0400 Received: from d06nrmr1507.portsmouth.uk.ibm.com (d06nrmr1507.portsmouth.uk.ibm.com [9.149.38.233]) by mtagate3.uk.ibm.com (8.13.1/8.13.1) with ESMTP id p4KAxkiC002375 for ; Fri, 20 May 2011 10:59:46 GMT Received: from d06av12.portsmouth.uk.ibm.com (d06av12.portsmouth.uk.ibm.com [9.149.37.247]) by d06nrmr1507.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p4KAxk482629860 for ; Fri, 20 May 2011 11:59:46 +0100 Received: from d06av12.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av12.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p4KAxjUc028962 for ; Fri, 20 May 2011 04:59:45 -0600 From: Stefan Hajnoczi Date: Fri, 20 May 2011 11:59:37 +0100 Message-Id: <1305889177-10490-4-git-send-email-stefanha@linux.vnet.ibm.com> In-Reply-To: <1305889177-10490-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1305889177-10490-1-git-send-email-stefanha@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH v4 3/3] coroutine: add check-coroutine --benchmark-lifecycle List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Anthony Liguori , Stefan Hajnoczi , Blue Swirl , Paolo Bonzini , Venkateswararao Jujjuri Add a microbenchmark for coroutine create, enter, and return (aka lifecycle). This is a useful benchmark because users are expected to create many coroutines, one per I/O request for example, and we therefore need to provide good performance in that scenario. To run: make check-coroutine ./check-coroutine --benchmark-lifecycle 20000000 This will do 20,000,000 coroutine create, enter, return iterations and print the resulting time. Signed-off-by: Stefan Hajnoczi --- check-coroutine.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 48 insertions(+), 0 deletions(-) diff --git a/check-coroutine.c b/check-coroutine.c index f65ac2e..8ed1a4f 100644 --- a/check-coroutine.c +++ b/check-coroutine.c @@ -11,8 +11,10 @@ * */ +#include #include #include +#include #include "qemu-coroutine.h" static const char *cur_test_name; @@ -163,6 +165,43 @@ static void test_lifecycle(void) test_assert(done, "expected done to be true (second time)"); } +/* + * Lifecycle benchmark + */ + +static void coroutine_fn empty_coroutine(void *opaque) +{ + /* Do nothing */ +} + +static void benchmark_lifecycle(const char *iterations) +{ + Coroutine *coroutine; + unsigned int i, max; + struct timeval start, finish; + time_t dsec; + long dusec; + + max = atoi(iterations); + + gettimeofday(&start, NULL); + for (i = 0; i < max; i++) { + coroutine = qemu_coroutine_create(empty_coroutine); + qemu_coroutine_enter(coroutine, NULL); + } + gettimeofday(&finish, NULL); + + dsec = finish.tv_sec - start.tv_sec; + if (finish.tv_usec < start.tv_usec) { + dsec--; + dusec = finish.tv_usec + 1000000 - start.tv_usec; + } else { + dusec = finish.tv_usec - start.tv_usec; + } + printf("Lifecycle %u iterations: %lu sec %lu us\n", + max, dsec, dusec); +} + #define TESTCASE(fn) { #fn, fn } int main(int argc, char **argv) { @@ -179,6 +218,15 @@ int main(int argc, char **argv) }; int i; + if (argc == 3 && strcmp(argv[1], "--benchmark-lifecycle") == 0) { + benchmark_lifecycle(argv[2]); + return EXIT_SUCCESS; + } else if (argc != 1) { + fprintf(stderr, "usage: %s [--benchmark-lifecycle ]\n", + argv[0]); + return EXIT_FAILURE; + } + for (i = 0; testcases[i].name; i++) { cur_test_name = testcases[i].name; printf("%s\n", testcases[i].name); -- 1.7.4.4