]> xenbits.xensource.com Git - people/andrewcoop/xen-test-framework.git/commitdiff
Implement pv_read_some
authorFelix Schmoll <eggi.innovations@gmail.com>
Mon, 24 Jul 2017 06:24:15 +0000 (08:24 +0200)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 25 Jul 2017 10:55:53 +0000 (11:55 +0100)
Implement reading from PV console. Making use of polling.

Signed-off-by: Felix Schmoll <eggi.innovations@gmail.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
common/console.c
include/xtf/console.h

index 7cb2361d531dd12f1f21fac2b1bef2b1bacb414d..0724fc9f4e2cc81aad6f5c6ea1806a21ca79ba73 100644 (file)
@@ -45,6 +45,33 @@ static size_t pv_console_write_some(const char *buf, size_t len)
     return s;
 }
 
+/*
+ * Read out data from the pv ring, either until buffer is filled or no
+ * more data are available. Might result in partial strings, depending
+ * on how xenconsoled passes in data.
+ *
+ * Will block if no data are available.
+ */
+size_t pv_console_read_some(char *buf, size_t len)
+{
+    size_t s = 0;
+    uint32_t cons, prod;
+
+    while ( !test_and_clear_bit(pv_evtchn, shared_info.evtchn_pending) ||
+            (pv_ring->in_cons == pv_ring->in_prod) )
+        hypercall_poll(pv_evtchn);
+
+    cons = pv_ring->in_cons;
+    prod = LOAD_ACQUIRE(&pv_ring->in_prod);
+
+    while ( (s < len) && (0 < (prod - cons)) )
+        buf[s++] = pv_ring->in[cons++ & (sizeof(pv_ring->in) - 1)];
+
+    STORE_RELEASE(&pv_ring->in_cons, cons);
+
+    return s;
+}
+
 /*
  * Write some data into the pv ring, synchronously waiting for all data to be
  * consumed.
index 2a93c06d85d4681ab1463fa64b9e9f20c5991f22..caec790c78e90e37d76c3754654d262fbda3af02 100644 (file)
@@ -25,6 +25,8 @@ void init_pv_console(xencons_interface_t *ring,
 void vprintk(const char *fmt, va_list args) __printf(1, 0);
 void printk(const char *fmt, ...) __printf(1, 2);
 
+size_t pv_console_read_some(char *buf, size_t len);
+
 #endif /* XTF_CONSOLE_H */
 
 /*