qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	Anthony Liguori <aliguori@us.ibm.com>,
	Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>,
	Blue Swirl <blauwirbel@gmail.com>,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: [Qemu-devel] [PATCH v3 3/4] coroutine: add check-coroutine --benchmark-lifecycle
Date: Fri, 13 May 2011 10:26:31 +0100	[thread overview]
Message-ID: <1305278792-20933-4-git-send-email-stefanha@linux.vnet.ibm.com> (raw)
In-Reply-To: <1305278792-20933-1-git-send-email-stefanha@linux.vnet.ibm.com>

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 <stefanha@linux.vnet.ibm.com>
---
 check-coroutine.c |   48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 48 insertions(+), 0 deletions(-)

diff --git a/check-coroutine.c b/check-coroutine.c
index f65ac2e..5a42c49 100644
--- a/check-coroutine.c
+++ b/check-coroutine.c
@@ -11,8 +11,10 @@
  *
  */
 
+#include <string.h>
 #include <stdlib.h>
 #include <stdio.h>
+#include <sys/time.h>
 #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;
+    suseconds_t 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 <iterations>]\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

  parent reply	other threads:[~2011-05-13  9:26 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-13  9:26 [Qemu-devel] [PATCH v3 0/4] Coroutines for better asynchronous programming Stefan Hajnoczi
2011-05-13  9:26 ` [Qemu-devel] [PATCH v3 1/4] coroutine: introduce coroutines Stefan Hajnoczi
2011-05-13 10:32   ` Paolo Bonzini
2011-05-13 11:19     ` Stefan Hajnoczi
2011-05-13  9:26 ` [Qemu-devel] [PATCH v3 2/4] coroutine: add check-coroutine automated tests Stefan Hajnoczi
2011-05-13  9:26 ` Stefan Hajnoczi [this message]
2011-05-13  9:26 ` [Qemu-devel] [PATCH v3 4/4] coroutine: pool coroutines to speed up creation Stefan Hajnoczi
2011-05-14  6:55 ` [Qemu-devel] [PATCH v3 0/4] Coroutines for better asynchronous programming Corentin Chary
2011-05-14  7:45   ` Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1305278792-20933-4-git-send-email-stefanha@linux.vnet.ibm.com \
    --to=stefanha@linux.vnet.ibm.com \
    --cc=aliguori@us.ibm.com \
    --cc=blauwirbel@gmail.com \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).