From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60673) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W5Bcp-0008VG-9I for qemu-devel@nongnu.org; Mon, 20 Jan 2014 04:58:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W5Bcj-00040I-5r for qemu-devel@nongnu.org; Mon, 20 Jan 2014 04:58:35 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56648) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W5Bci-000409-U5 for qemu-devel@nongnu.org; Mon, 20 Jan 2014 04:58:29 -0500 Date: Mon, 20 Jan 2014 10:58:20 +0100 From: Kevin Wolf Message-ID: <20140120095820.GD3267@dhcp-200-207.str.redhat.com> References: <1389968119-24771-1-git-send-email-kwolf@redhat.com> <1389968119-24771-28-git-send-email-kwolf@redhat.com> <52D9C2F4.5040708@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <52D9C2F4.5040708@redhat.com> Subject: Re: [Qemu-devel] [PATCH v3 27/29] qemu-io: New command 'sleep' List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Max Reitz Cc: pbonzini@redhat.com, pl@kamp.de, qemu-devel@nongnu.org, stefanha@redhat.com, xiawenc@linux.vnet.ibm.com Am 18.01.2014 um 00:55 hat Max Reitz geschrieben: > On 17.01.2014 15:15, Kevin Wolf wrote: > >There is no easy way to check that a request correctly waits for a > >different request. With a sleep command we can at least approximate it. > > > >Signed-off-by: Kevin Wolf > >--- > > qemu-io-cmds.c | 42 ++++++++++++++++++++++++++++++++++++++++++ > > 1 file changed, 42 insertions(+) > > > >diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c > >index 85e4982..978a3a0 100644 > >--- a/qemu-io-cmds.c > >+++ b/qemu-io-cmds.c > >@@ -12,6 +12,7 @@ > > #include "block/block_int.h" > > #include "block/qapi.h" > > #include "qemu/main-loop.h" > >+#include "qemu/timer.h" > > #define CMD_NOFILE_OK 0x01 > >@@ -2038,6 +2039,46 @@ static const cmdinfo_t abort_cmd = { > > .oneline = "simulate a program crash using abort(3)", > > }; > >+static void sleep_cb(void *opaque) > >+{ > >+ bool *expired = opaque; > >+ *expired = true; > >+} > >+ > >+static int sleep_f(BlockDriverState *bs, int argc, char **argv) > >+{ > >+ char *endptr; > >+ long ms; > >+ struct QEMUTimer *timer; > >+ bool expired = false; > >+ > >+ ms = strtol(argv[1], &endptr, 0); > >+ if (ms < 0 || *endptr != '\0') { > >+ printf("%s is not a valid number\n", argv[1]); > >+ return 0; > >+ } > >+ > >+ timer = timer_new_ns(QEMU_CLOCK_HOST, sleep_cb, &expired); > >+ timer_mod(timer, qemu_clock_get_ns(QEMU_CLOCK_HOST) + SCALE_MS * ms); > >+ > >+ while (!expired) { > > I don't know whether compilers don't optimize accesses to variables > whose addresses have been given to other functions, but shouldn't > expired be marked volatile just to be sure? That would be a pretty broken compiler, and we're already using the same pattern all over qemu without volatile, so no. (And if there was a problem, I guess we'd rather use barriers than volatile variables.) Kevin