Skip to contentSkip to conversation

Implement pv_read_some

PATCH Superseded Felix Schmoll 2 participants 4 messages Jul 20, 2017 – Jul 21, 2017

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 Implement pv_read_some

Implement reading from PV console. Making use of polling.

---
Changed since v2:
* Change function name from pv_read to pv_read_some
* Add comment to function name
* Remove unnecessary code

---
 common/console.c      | 24 ++++++++++++++++++++++++
 include/xtf/console.h |  2 ++
 2 files changed, 26 insertions(+)
common/console.c +24 -0
index 7cb2361..1b79652 100644
@@ -46,6 +46,30 @@ static size_t pv_console_write_some(const char *buf, size_t len)
 }
 
 /*
+ * 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.
+ */
+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.
  */
include/xtf/console.h +2 -0
index 2a93c06..caec790 100644
@@ -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 */
 
 /*
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw
Quoted 19 lines · Felix Schmoll

Implement reading from PV console. Making use of polling.

---
Changed since v2:
* Change function name from pv_read to pv_read_some
* Add comment to function name
* Remove unnecessary code

---
  common/console.c      | 24 ++++++++++++++++++++++++
  include/xtf/console.h |  2 ++
  2 files changed, 26 insertions(+)
common/console.c +0 -0
index 7cb2361..1b79652 100644

common/console.c static size_t pv_console_write_some(const char *buf, size_t len) · line 51

Quoted 6 lines
common/console.c +3 -0
@@ -46,6 +46,30 @@ static size_t pv_console_write_some(const char *buf, size_t len)
  }
 
  /*
+ * 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.

Much better. Just one final question. Do you intend this function to block until data becomes available? (because that appears to be how it behaves.)

~Andrew

Quoted 29 lines
common/console.c +21 -0
+ */
+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.
   */
include/xtf/console.h +0 -0
index 2a93c06..caec790 100644

include/xtf/console.h void init_pv_console(xencons_interface_t *ring, · line 32

Quoted 8 lines
include/xtf/console.h +2 -0
@@ -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 */
 
  /*

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#2 lore raw
Quoted 7 lines

Much better. Just one final question. Do you intend this function to block until data becomes available? (because that appears to be how it behaves.)

Yes. I could split it up into two functions if that bothers you. Or do you just want me to include that in the comment?

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#3 lore raw
Quoted 8 lines · Felix Schmoll

Much better. Just one final question. Do you intend this function to block until data becomes available? (because that appears to be how it behaves.)

Yes. I could split it up into two functions if that bothers you. Or do you just want me to include that in the comment?

Just include it in the comment.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel