Implement pv_read
PATCH 1/1 Implement pv_read
Implement reading from PV console. Making use of polling.
Signed-off-by Felix Schmoll <[email protected]>
---
This is based on the console-branch of andyhhp, so that one has to be merged before applying this patch.
--- common/console.c | 27 ++++++++++++++++++++++----- include/xtf/console.h | 2 ++ 2 files changed, 24 insertions(+), 5 deletions(-)
common/console.c +22 -5
@@ -7,6 +7,8 @@#include <xtf/libc.h> #include <xtf/traps.h> +#include <xen/sched.h> +/* * Output functions, registered if/when available. * Possibilities:
@@ -45,6 +47,24 @@ static size_t pv_console_write_some(const char *buf, size_t len)return s; } +extern shared_info_t shared_info; +size_t pv_console_read (char *buf,size_t len) +{ +while ( !test_and_clear_bit (pv_evtchn, shared_info.evtchn_pending) || + (pv_ring->in_cons == pv_ring->in_prod ) ) +hypercall_poll (pv_evtchn); + +size_t s =0 ; +uint32_t 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.
@@ -70,9 +90,7 @@ static void pv_console_write(const char *buf, size_t len) {while (ACCESS_ONCE (pv_ring->out_cons) == cons ) { -if ( !test_and_clear_bit (pv_evtchn, - shared_info.evtchn_pending) ) -hypercall_poll (pv_evtchn); +hypercall_yield (); } }
@@ -81,8 +99,7 @@ static void pv_console_write(const char *buf, size_t len)/* Wait for xenconsoled to consume all the data we gave. */ while (ACCESS_ONCE (pv_ring->out_cons) != pv_ring->out_prod ) { -if ( !test_and_clear_bit (pv_evtchn, shared_info.evtchn_pending) ) -hypercall_poll (pv_evtchn); +hypercall_yield (); } }
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 (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
Quoted 26 lines · Felix Schmoll
Implement reading from PV console. Making use of polling.
Signed-off-by Felix Schmoll <[email protected]>---
This is based on the console-branch of andyhhp, so that one has to be merged before applying this patch.--- common/console.c | 27 ++++++++++++++++++++++----- include/xtf/console.h | 2 ++ 2 files changed, 24 insertions(+), 5 deletions(-)common/console.c +2
-0@@ -7,6 +7,8 @@#include <xtf/libc.h> #include <xtf/traps.h> +#include <xen/sched.h> +/* * Output functions, registered if/when available. * Possibilities:
common/console.c static size_t pv_console_write_some(const char *buf, size_t len) · line 54
Quoted 8 lines
common/console.c +5
-0@@ -45,6 +47,24 @@ static size_t pv_console_write_some(const char *buf, size_t len)return s; } +extern shared_info_t shared_info; +size_t pv_console_read (char *buf,size_t len) +{ +while ( !test_and_clear_bit (pv_evtchn, shared_info.evtchn_pending) || + (pv_ring->in_cons == pv_ring->in_prod ) )
Extraneous space after in_prod.
common/console.c static size_t pv_console_write_some(const char *buf, size_t len) · line 58
Quoted 4 lines
common/console.c +4
-0+hypercall_poll (pv_evtchn); + +size_t s =0 ; +uint32_t cons = pv_ring->in_cons, prod =LOAD_ACQUIRE (&pv_ring->in_prod);
Please move the declarations to the beginning of this function.
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel