Skip to contentSkip to conversation

libqos: use microseconds instead of iterations for virtio timeout

PATCH Applied Stefan Hajnoczi 3 participants 7 messages Sep 29, 2014 – Oct 11, 2014

lore
Share & tools
lore
#0 lore raw

v2 cover libqos: use microseconds instead of iterations for virtio timeout

v2:
* Implement "no interrupt" test properly, added Patch 1 [Peter]

Fix the race condition that leads to Travis "make check" failures.

Stefan Hajnoczi (2):
libqos: improve event_index test with timeout
libqos: use microseconds instead of iterations for virtio timeout

 tests/libqos/virtio.c   | 50 ++++++++++++++++++++++++++++++++------------
 tests/libqos/virtio.h   | 13 ++++++++----
 tests/virtio-blk-test.c | 55 +++++++++++++++++++++++--------------------------
 3 files changed, 72 insertions(+), 46 deletions(-)
Signature · 1 line
1.9.3
#1 lore raw

PATCH v2 1/2 libqos: improve event_index test with timeout

The virtio event_index feature lets the device driver tell the device how many requests to process before raising the next interrupt. virtio-blk-test.c tries to verify that the device does not raise an interrupt unnecessarily.

Unfortunately the test has a race condition. It spins checking for an interrupt up to 100 times and then assumes the request has finished. On a slow host the I/O request could still be in flight and the test would fail.

This patch waits for the request to complete, or until a 30-second timeout is reached. If an interrupt is raised while waiting the test fails since the device was not supposed to raise interrupts.

---
 tests/libqos/virtio.c   | 22 ++++++++++++++++++++++
 tests/libqos/virtio.h   |  5 +++++
 tests/virtio-blk-test.c |  8 ++++----
 3 files changed, 31 insertions(+), 4 deletions(-)
tests/libqos/virtio.c +22 -0
index 9b6de2c..009325d 100644
@@ -91,6 +91,28 @@ bool qvirtio_wait_queue_isr(const QVirtioBus *bus, QVirtioDevice *d,
     return timeout != 0;
 }
 
+/* Wait for the status byte at given guest memory address to be set
+ *
+ * The virtqueue interrupt must not be raised, making this useful for testing
+ * event_index functionality.
+ */
+uint8_t qvirtio_wait_status_byte_no_isr(const QVirtioBus *bus,
+                                        QVirtioDevice *d,
+                                        QVirtQueue *vq,
+                                        uint64_t addr,
+                                        gint64 timeout_us)
+{
+    gint64 start_time = g_get_monotonic_time();
+    uint8_t val;
+
+    while ((val = readb(addr)) == 0xff) {
+        clock_step(100);
+        g_assert(!bus->get_queue_isr_status(d, vq));
+        g_assert(g_get_monotonic_time() - start_time <= timeout_us);
+    }
+    return val;
+}
+
 bool qvirtio_wait_config_isr(const QVirtioBus *bus, QVirtioDevice *d,
                                                             uint64_t timeout)
 {
tests/libqos/virtio.h +5 -0
index 70b3376..bc7518e 100644
@@ -162,6 +162,11 @@ void qvirtio_set_driver_ok(const QVirtioBus *bus, QVirtioDevice *d);
 
 bool qvirtio_wait_queue_isr(const QVirtioBus *bus, QVirtioDevice *d,
                                             QVirtQueue *vq, uint64_t timeout);
+uint8_t qvirtio_wait_status_byte_no_isr(const QVirtioBus *bus,
+                                        QVirtioDevice *d,
+                                        QVirtQueue *vq,
+                                        uint64_t addr,
+                                        gint64 timeout_us);
 bool qvirtio_wait_config_isr(const QVirtioBus *bus, QVirtioDevice *d,
                                                             uint64_t timeout);
 QVirtQueue *qvirtqueue_setup(const QVirtioBus *bus, QVirtioDevice *d,
tests/virtio-blk-test.c +4 -4
index 588666c..0e3bfa7 100644
@@ -42,6 +42,7 @@
 
 #define TEST_IMAGE_SIZE         (64 * 1024 * 1024)
 #define QVIRTIO_BLK_TIMEOUT     100
+#define QVIRTIO_BLK_TIMEOUT_US  (30 * 1000 * 1000)
 #define PCI_SLOT                0x04
 #define PCI_FN                  0x00
 
@@ -595,10 +596,9 @@ static void pci_idx(void)
     qvirtqueue_kick(&qvirtio_pci, &dev->vdev, &vqpci->vq, free_head);
 
     /* No notification expected */
-    g_assert(!qvirtio_wait_queue_isr(&qvirtio_pci, &dev->vdev, &vqpci->vq,
-                                                        QVIRTIO_BLK_TIMEOUT));
-
-    status = readb(req_addr + 528);
+    status = qvirtio_wait_status_byte_no_isr(&qvirtio_pci, &dev->vdev,
+                                             &vqpci->vq, req_addr + 528,
+                                             QVIRTIO_BLK_TIMEOUT_US);
     g_assert_cmpint(status, ==, 0);
 
     guest_free(alloc, req_addr);
Signature · 1 line
1.9.3
#2 lore raw

Re: [Qemu-devel] [PATCH v2 1/2] libqos: improve event_index test with timeout

Quoted 10 lines · Stefan Hajnoczi

The virtio event_index feature lets the device driver tell the device how many requests to process before raising the next interrupt. virtio-blk-test.c tries to verify that the device does not raise an interrupt unnecessarily.

Unfortunately the test has a race condition. It spins checking for an interrupt up to 100 times and then assumes the request has finished. On a slow host the I/O request could still be in flight and the test would fail.

Quoted 5 lines

This patch waits for the request to complete, or until a 30-second timeout is reached. If an interrupt is raised while waiting the test fails since the device was not supposed to raise interrupts.

Hi; just noticed this breaks 'make check' build on MacOSX:

/Users/pm215/src/qemu/tests/libqos/virtio.c:84:25: warning: implicit declaration of function

      'g_get_monotonic_time' is invalid in C99 [-Wimplicit-function-declaration]
    gint64 start_time = g_get_monotonic_time();
                        ^

(and subsequent linker error).

g_get_monotonic_time() only appeared in glib 2.28, and our minimum is 2.12.

thanks
-- PMM

#3 lore raw

Re: [Qemu-devel] [PATCH v2 1/2] libqos: improve event_index test with timeout

Quoted 11 lines · Peter Maydell

Hi; just noticed this breaks 'make check' build on MacOSX:

/Users/pm215/src/qemu/tests/libqos/virtio.c:84:25: warning: implicit declaration of function

      'g_get_monotonic_time' is invalid in C99 [-Wimplicit-function-declaration]
    gint64 start_time = g_get_monotonic_time();
                        ^

(and subsequent linker error).

g_get_monotonic_time() only appeared in glib 2.28, and our minimum is 2.12.

vhost-user-test.c has a helper function that has a fallback for not having g_get_monotonic_time(); we probably want to put that somewhere more generally accessible.

-- PMM

#4 lore raw

PATCH v2 2/2 libqos: use microseconds instead of iterations for virtio timeout

In reply to Stefan Hajnoczi

Some hosts are slow or overloaded so test execution takes a long time. Test cases use timeouts to protect against an infinite loop stalling the test forever (especially important in automated test setups).

Commit 6cd14054b67774cc58a51fca6660cfa1d3c08059 ("libqos virtio:
Increase ISR timeout") increased the clock_step() value in an attempt to lengthen the virtio interrupt wait timeout, but timeout failures are still occuring on the Travis automated testing platform.

This is because clock_step() only affects the guest's virtual time. Virtio requests can be bottlenecked on host disk I/O latency - which cannot be improved by stepping the clock, so the fix was ineffective.

This patch changes the qvirtio_wait_queue_isr() and qvirtio_wait_config_isr() timeout mechanism from loop iterations to microseconds. This way the test case can specify an absolute 30 second timeout. Number of loop iterations is not a reliable timeout mechanism since the speed depends on many factors including host performance.

Tests should no longer timeout on overloaded Travis instances.

---
 tests/libqos/virtio.c   | 30 ++++++++++++++++--------------
 tests/libqos/virtio.h   |  8 ++++----
 tests/virtio-blk-test.c | 47 ++++++++++++++++++++++-------------------------
 3 files changed, 42 insertions(+), 43 deletions(-)
tests/libqos/virtio.c +16 -14
index 009325d..a061289 100644
@@ -78,17 +78,18 @@ void qvirtio_set_driver_ok(const QVirtioBus *bus, QVirtioDevice *d)
                 QVIRTIO_DRIVER_OK | QVIRTIO_DRIVER | QVIRTIO_ACKNOWLEDGE);
 }
 
-bool qvirtio_wait_queue_isr(const QVirtioBus *bus, QVirtioDevice *d,
-                                            QVirtQueue *vq, uint64_t timeout)
+void qvirtio_wait_queue_isr(const QVirtioBus *bus, QVirtioDevice *d,
+                            QVirtQueue *vq, gint64 timeout_us)
 {
-    do {
+    gint64 start_time = g_get_monotonic_time();
+
+    for (;;) {
         clock_step(100);
         if (bus->get_queue_isr_status(d, vq)) {
-            break; /* It has ended */
+            return;
         }
-    } while (--timeout);
-
-    return timeout != 0;
+        g_assert(g_get_monotonic_time() - start_time <= timeout_us);
+    }
 }
 
 /* Wait for the status byte at given guest memory address to be set
@@ -113,17 +114,18 @@ uint8_t qvirtio_wait_status_byte_no_isr(const QVirtioBus *bus,
     return val;
 }
 
-bool qvirtio_wait_config_isr(const QVirtioBus *bus, QVirtioDevice *d,
-                                                            uint64_t timeout)
+void qvirtio_wait_config_isr(const QVirtioBus *bus, QVirtioDevice *d,
+                             gint64 timeout_us)
 {
-    do {
+    gint64 start_time = g_get_monotonic_time();
+
+    for (;;) {
         clock_step(100);
         if (bus->get_config_isr_status(d)) {
-            break; /* It has ended */
+            return;
         }
-    } while (--timeout);
-
-    return timeout != 0;
+        g_assert(g_get_monotonic_time() - start_time <= timeout_us);
+    }
 }
 
 void qvring_init(const QGuestAllocator *alloc, QVirtQueue *vq, uint64_t addr)
tests/libqos/virtio.h +4 -4
index bc7518e..29fbacb 100644
@@ -160,15 +160,15 @@ void qvirtio_set_acknowledge(const QVirtioBus *bus, QVirtioDevice *d);
 void qvirtio_set_driver(const QVirtioBus *bus, QVirtioDevice *d);
 void qvirtio_set_driver_ok(const QVirtioBus *bus, QVirtioDevice *d);
 
-bool qvirtio_wait_queue_isr(const QVirtioBus *bus, QVirtioDevice *d,
-                                            QVirtQueue *vq, uint64_t timeout);
+void qvirtio_wait_queue_isr(const QVirtioBus *bus, QVirtioDevice *d,
+                            QVirtQueue *vq, gint64 timeout_us);
 uint8_t qvirtio_wait_status_byte_no_isr(const QVirtioBus *bus,
                                         QVirtioDevice *d,
                                         QVirtQueue *vq,
                                         uint64_t addr,
                                         gint64 timeout_us);
-bool qvirtio_wait_config_isr(const QVirtioBus *bus, QVirtioDevice *d,
-                                                            uint64_t timeout);
+void qvirtio_wait_config_isr(const QVirtioBus *bus, QVirtioDevice *d,
+                             gint64 timeout_us);
 QVirtQueue *qvirtqueue_setup(const QVirtioBus *bus, QVirtioDevice *d,
                                         QGuestAllocator *alloc, uint16_t index);
 
tests/virtio-blk-test.c +22 -25

125 lines not on this page · raw message

Signature · 1 line
1.9.3
Reviewed-by on the v2 series
#5 lore raw
In reply to Stefan Hajnoczi

Il 29/09/2014 17:40, Stefan Hajnoczi ha scritto:

Quoted 5 lines

v2:
* Implement "no interrupt" test properly, added Patch 1 [Peter]

Fix the race condition that leads to Travis "make check" failures.

Quoted 9 lines

Stefan Hajnoczi (2):
libqos: improve event_index test with timeout
libqos: use microseconds instead of iterations for virtio timeout

 tests/libqos/virtio.c   | 50 ++++++++++++++++++++++++++++++++------------
 tests/libqos/virtio.h   | 13 ++++++++----
 tests/virtio-blk-test.c | 55 +++++++++++++++++++++++--------------------------
 3 files changed, 72 insertions(+), 46 deletions(-)
#6 lore raw
In reply to Stefan Hajnoczi
Quoted 5 lines · Stefan Hajnoczi

v2:
* Implement "no interrupt" test properly, added Patch 1 [Peter]

Fix the race condition that leads to Travis "make check" failures.

Quoted 8 lines

Stefan Hajnoczi (2):
libqos: improve event_index test with timeout
libqos: use microseconds instead of iterations for virtio timeout

 tests/libqos/virtio.c   | 50 ++++++++++++++++++++++++++++++++------------
 tests/libqos/virtio.h   | 13 ++++++++----
 tests/virtio-blk-test.c | 55 +++++++++++++++++++++++--------------------------
 3 files changed, 72 insertions(+), 46 deletions(-)

Applied, thanks.

-- PMM