[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 04/12] char: introduce backend tx queue
From: |
Anthony Liguori |
Subject: |
[Qemu-devel] [PATCH 04/12] char: introduce backend tx queue |
Date: |
Mon, 1 Aug 2011 09:23:02 -0500 |
While the front tx queue has no flow control, the backend tx queue uses a
polling function to determine when the front end can receive data.
To convert this to the new queue model, we simply try to flush the backend tx
queue whenever we poll. We then return the remaining space in the queue as
the value of the polling function.
Signed-off-by: Anthony Liguori <address@hidden>
---
qemu-char.c | 49 ++++++++++++++++++++++++++++++++++++++++---------
qemu-char.h | 3 ++-
2 files changed, 42 insertions(+), 10 deletions(-)
diff --git a/qemu-char.c b/qemu-char.c
index 3f9b32c..2746652 100644
--- a/qemu-char.c
+++ b/qemu-char.c
@@ -173,6 +173,11 @@ static size_t char_queue_read(CharQueue *q, void *data,
size_t size)
return i;
}
+static uint32_t char_queue_get_avail(CharQueue *q)
+{
+ return sizeof(q->ring) - (q->prod - q->cons);
+}
+
static void qemu_chr_flush_fe_tx(CharDriverState *s)
{
uint8_t buf[MAX_CHAR_QUEUE_RING];
@@ -200,23 +205,49 @@ int qemu_chr_fe_write(CharDriverState *s, const uint8_t
*buf, int len)
return ret;
}
-int qemu_chr_ioctl(CharDriverState *s, int cmd, void *arg)
+static void qemu_chr_flush_be_tx(CharDriverState *s)
{
- if (!s->chr_ioctl)
- return -ENOTSUP;
- return s->chr_ioctl(s, cmd, arg);
+ uint8_t buf[MAX_CHAR_QUEUE_RING];
+ int len;
+
+ /* Only drain what the be can handle */
+ len = s->chr_can_read(s->handler_opaque);
+ if (len == 0) {
+ return;
+ }
+
+ len = char_queue_read(&s->be_tx, buf, len);
+
+ /* We only drained what we knew the be could handle so we don't need to
+ * requeue any data. */
+ s->chr_read(s, buf, len);
}
int qemu_chr_be_can_write(CharDriverState *s)
{
- if (!s->chr_can_read)
- return 0;
- return s->chr_can_read(s->handler_opaque);
+ /* Try to flush any queued data before returning how much data we can
+ * accept. */
+ qemu_chr_flush_be_tx(s);
+
+ return char_queue_get_avail(&s->be_tx);
}
-void qemu_chr_be_write(CharDriverState *s, uint8_t *buf, int len)
+int qemu_chr_be_write(CharDriverState *s, uint8_t *buf, int len)
{
- s->chr_read(s->handler_opaque, buf, len);
+ int ret;
+
+ ret = char_queue_write(&s->be_tx, buf, len);
+
+ qemu_chr_flush_be_tx(s);
+
+ return ret;
+}
+
+int qemu_chr_ioctl(CharDriverState *s, int cmd, void *arg)
+{
+ if (!s->chr_ioctl)
+ return -ENOTSUP;
+ return s->chr_ioctl(s, cmd, arg);
}
int qemu_chr_get_msgfd(CharDriverState *s)
diff --git a/qemu-char.h b/qemu-char.h
index bb9c1a7..85735b5 100644
--- a/qemu-char.h
+++ b/qemu-char.h
@@ -85,6 +85,7 @@ struct CharDriverState {
int avail_connections;
CharQueue fe_tx;
+ CharQueue be_tx;
QTAILQ_ENTRY(CharDriverState) next;
};
@@ -109,7 +110,7 @@ void qemu_chr_add_handlers(CharDriverState *s,
int qemu_chr_ioctl(CharDriverState *s, int cmd, void *arg);
void qemu_chr_generic_open(CharDriverState *s);
int qemu_chr_be_can_write(CharDriverState *s);
-void qemu_chr_be_write(CharDriverState *s, uint8_t *buf, int len);
+int qemu_chr_be_write(CharDriverState *s, uint8_t *buf, int len);
int qemu_chr_get_msgfd(CharDriverState *s);
void qemu_chr_accept_input(CharDriverState *s);
int qemu_chr_add_client(CharDriverState *s, int fd);
--
1.7.4.1
- [Qemu-devel] [PATCH 06/12] char: add an edge event API for the front ends, (continued)
- [Qemu-devel] [PATCH 06/12] char: add an edge event API for the front ends, Anthony Liguori, 2011/08/01
- [Qemu-devel] [PATCH 09/12] char: rename qemu_chr_guest_open() -> qemu_chr_fe_open(), Anthony Liguori, 2011/08/01
- [Qemu-devel] [PATCH 11/12] char: make all devices do qemu_chr_fe_open(), Anthony Liguori, 2011/08/01
- [Qemu-devel] [PATCH 08/12] char: make monitor use new style interface, Anthony Liguori, 2011/08/01
- [Qemu-devel] [PATCH 10/12] char: rename qemu_chr_guest_close() -> qemu_chr_fe_close(), Anthony Liguori, 2011/08/01
- [Qemu-devel] [PATCH 12/12] char: enforce the use of qemu_chr_guest_open(), Anthony Liguori, 2011/08/01
- [Qemu-devel] [PATCH 04/12] char: introduce backend tx queue,
Anthony Liguori <=
- Re: [Qemu-devel] [PATCH 00/12][RFC] char: add flow control and fix guest_[open|close], Alon Levy, 2011/08/01
- Re: [Qemu-devel] [PATCH 00/12][RFC] char: add flow control and fix guest_[open|close], Hans de Goede, 2011/08/01
- Re: [Qemu-devel] [PATCH 00/12][RFC] char: add flow control and fix guest_[open|close], Blue Swirl, 2011/08/01
- Re: [Qemu-devel] [PATCH 00/12][RFC] char: add flow control and fix guest_[open|close], Amit Shah, 2011/08/04