[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] Add a "consumed" parameter to the buffer declaration, and use this to advance
# HG changeset patch # User emellor@xxxxxxxxxxxxxxxxxxxxxx # Node ID 2b8efe11096b8a79cff66929455c54ab69812d75 # Parent 06b80b837c92b5d6f6a50a2a569313293659d8f5 Add a "consumed" parameter to the buffer declaration, and use this to advance through the buffer when the data are read by console clients. This avoids a costly memmove with every read from the console. Signed-off-by: Ewan Mellor <ewan@xxxxxxxxxxxxx> diff -r 06b80b837c92 -r 2b8efe11096b tools/console/daemon/io.c --- a/tools/console/daemon/io.c Tue Dec 6 16:40:50 2005 +++ b/tools/console/daemon/io.c Tue Dec 6 17:10:59 2005 @@ -48,6 +48,7 @@ struct buffer { char *data; + size_t consumed; size_t size; size_t capacity; size_t max_capacity; @@ -109,12 +110,17 @@ if (buffer->max_capacity && buffer->size > buffer->max_capacity) { - memmove(buffer->data + (buffer->size - - buffer->max_capacity), - buffer->data, buffer->max_capacity); - buffer->data = realloc(buffer->data, - buffer->max_capacity); + /* Discard the middle of the data. */ + + size_t over = buffer->size - buffer->max_capacity; + char *maxpos = buffer->data + buffer->max_capacity; + + memmove(maxpos - over, maxpos, over); + buffer->data = realloc(buffer->data, buffer->max_capacity); buffer->size = buffer->capacity = buffer->max_capacity; + + if (buffer->consumed > buffer->max_capacity - over) + buffer->consumed = buffer->max_capacity - over; } } @@ -123,11 +129,13 @@ return buffer->size == 0; } -static void buffer_advance(struct buffer *buffer, size_t size) -{ - size = MIN(size, buffer->size); - memmove(buffer->data, buffer + size, buffer->size - size); - buffer->size -= size; +static void buffer_advance(struct buffer *buffer, size_t len) +{ + buffer->consumed += len; + if (buffer->consumed == buffer->size) { + buffer->consumed = 0; + buffer->size = 0; + } } static bool domain_is_valid(int domid) @@ -327,6 +335,7 @@ dom->tty_fd = -1; dom->is_dead = false; dom->buffer.data = 0; + dom->buffer.consumed = 0; dom->buffer.size = 0; dom->buffer.capacity = 0; dom->buffer.max_capacity = 0; @@ -474,8 +483,12 @@ { ssize_t len; - len = write(dom->tty_fd, dom->buffer.data, dom->buffer.size); - if (len < 1) { + len = write(dom->tty_fd, dom->buffer.data + dom->buffer.consumed, + dom->buffer.size - dom->buffer.consumed); + if (len < 1) { + dolog(LOG_DEBUG, "Write failed on domain %d: %d, %d\n", + dom->domid, len, errno); + close(dom->tty_fd); dom->tty_fd = -1; _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |