[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v1 11/11] char/cadence_uart: Implement Tx flow contr
From: |
Peter Crosthwaite |
Subject: |
[Qemu-devel] [PATCH v1 11/11] char/cadence_uart: Implement Tx flow control |
Date: |
Mon, 16 Dec 2013 17:46:12 -0800 |
If the UART back-end blocks, buffer in the Tx FIFO to try again later.
This stops the IO-thread busy waiting on char back-ends (which causes
all sorts of performance problems).
Signed-off-by: Peter Crosthwaite <address@hidden>
---
hw/char/cadence_uart.c | 31 +++++++++++++++++++++++++++++--
1 file changed, 29 insertions(+), 2 deletions(-)
diff --git a/hw/char/cadence_uart.c b/hw/char/cadence_uart.c
index 3be110c..6516a3e 100644
--- a/hw/char/cadence_uart.c
+++ b/hw/char/cadence_uart.c
@@ -286,6 +286,34 @@ static void uart_write_rx_fifo(void *opaque, const uint8_t
*buf, int size)
uart_update_status(s);
}
+static gboolean cadence_uart_xmit(GIOChannel *chan, GIOCondition cond,
+ void *opaque)
+{
+ UartState *s = opaque;
+ int ret;
+
+ /* instant drain the fifo when there's no back-end */
+ if (!s->chr) {
+ s->tx_count = 0;
+ }
+
+ if (!s->tx_count) {
+ return FALSE;
+ }
+
+ ret = qemu_chr_fe_write(s->chr, s->tx_fifo, s->tx_count);
+ s->tx_count -= ret;
+ memmove(s->tx_fifo, s->tx_fifo + ret, s->tx_count);
+
+ if (s->tx_count) {
+ int r = qemu_chr_fe_add_watch(s->chr, G_IO_OUT, cadence_uart_xmit, s);
+ assert(r);
+ }
+
+ uart_update_status(s);
+ return FALSE;
+}
+
static void uart_write_tx_fifo(UartState *s, const uint8_t *buf, int size)
{
if ((s->r[R_CR] & UART_CR_TX_DIS) || !(s->r[R_CR] & UART_CR_TX_EN)) {
@@ -306,8 +334,7 @@ static void uart_write_tx_fifo(UartState *s, const uint8_t
*buf, int size)
memcpy(s->tx_fifo + s->tx_count, buf, size);
s->tx_count += size;
- qemu_chr_fe_write_all(s->chr, s->tx_fifo, s->tx_count);
- s->tx_count = 0;
+ cadence_uart_xmit(NULL, G_IO_OUT, s);
}
static void uart_receive(void *opaque, const uint8_t *buf, int size)
--
1.8.5.1
- Re: [Qemu-devel] [PATCH v1 01/11] char/cadence_uart: Mark struct fields as public/private, (continued)
- [Qemu-devel] [PATCH v1 02/11] char/cadence_uart: Add missing uart_update_state, Peter Crosthwaite, 2013/12/16
- [Qemu-devel] [PATCH v1 03/11] char/cadence_uart: Fix reset., Peter Crosthwaite, 2013/12/16
- [Qemu-devel] [PATCH v1 04/11] char/cadence_uart: s/r_fifo/rx_fifo, Peter Crosthwaite, 2013/12/16
- [Qemu-devel] [PATCH v1 05/11] char/cadence_uart: Simplify status generation, Peter Crosthwaite, 2013/12/16
- [Qemu-devel] [PATCH v1 06/11] char/cadence_uart: Define Missing SR/ISR fields, Peter Crosthwaite, 2013/12/16
- [Qemu-devel] [PATCH v1 07/11] char/cadence_uart: Remove TX timer & add TX FIFO state, Peter Crosthwaite, 2013/12/16
- [Qemu-devel] [PATCH v1 08/11] char/cadence_uart: Fix can_receive logic, Peter Crosthwaite, 2013/12/16
- [Qemu-devel] [PATCH v1 09/11] char/cadence_uart: Use the TX fifo for transmission, Peter Crosthwaite, 2013/12/16
- [Qemu-devel] [PATCH v1 10/11] char/cadence_uart: Delete redundant rx rst logic, Peter Crosthwaite, 2013/12/16
- [Qemu-devel] [PATCH v1 11/11] char/cadence_uart: Implement Tx flow control,
Peter Crosthwaite <=