From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1G2BCk-0007qi-TF for qemu-devel@nongnu.org; Sun, 16 Jul 2006 14:18:58 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1G2BCk-0007qF-4D for qemu-devel@nongnu.org; Sun, 16 Jul 2006 14:18:58 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1G2BCj-0007q9-PI for qemu-devel@nongnu.org; Sun, 16 Jul 2006 14:18:57 -0400 Received: from [70.116.9.243] (helo=localhost.localdomain) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1G2BFD-0007K7-Ce for qemu-devel@nongnu.org; Sun, 16 Jul 2006 14:21:31 -0400 Received: from localhost ([127.0.0.1]) by localhost.localdomain with esmtp (Exim 4.60) (envelope-from ) id 1G2B8U-0001Ns-VW for qemu-devel@nongnu.org; Sun, 16 Jul 2006 13:14:35 -0500 Message-ID: <44BA8205.7020304@codemonkey.ws> Date: Sun, 16 Jul 2006 13:14:29 -0500 From: Anthony Liguori MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------030100010102030008050907" Subject: [Qemu-devel] [PATCH 3/4] Improve character device read performance Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org This is a multi-part message in MIME format. --------------030100010102030008050907 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Regards, Anthony Liguori --------------030100010102030008050907 Content-Type: text/x-patch; name="chrdev_partial_read.diff" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="chrdev_partial_read.diff" # HG changeset patch # User anthony@localhost.localdomain # Node ID 32d5f77cf5e8c5a15b38b1fa86f588f374ebd3ad # Parent 0e52f303222037247747558d43d72b5b89817828 Sometimes partial reads occur even though there's still data to be read. This patch makes sure that we read all the data that's available to read. This has a huge performance impact for the shmem character device since. diff -r 0e52f3032220 -r 32d5f77cf5e8 vl.c --- a/vl.c Sun Jul 16 17:04:01 2006 +++ b/vl.c Sun Jul 16 17:23:21 2006 @@ -1205,6 +1205,29 @@ return s->max_size; } +static int fd_read_blocks(int fd) +{ + fd_set rfds; + struct timeval tv; + int ret; + + again: + FD_ZERO(&rfds); + FD_SET(fd, &rfds); + + tv.tv_sec = 0; + tv.tv_usec = 0; + + ret = select(fd + 1, &rfds, NULL, NULL, &tv); + if (ret == -1) { + if (errno == EINTR) + goto again; + return -1; + } + + return !FD_ISSET(fd, &rfds); +} + static void fd_chr_read(void *opaque) { CharDriverState *chr = opaque; @@ -1217,7 +1240,25 @@ len = s->max_size; if (len == 0) return; - size = read(s->fd_in, buf, len); + + for (size = 0; size < len;) { + int l; + l = read(s->fd_in, buf + size, len - size); + if (l == -1) { + if (errno == EINTR) + continue; + break; + } else if (l == 0) { + break; + } + + size += l; + + if (size < len && fd_read_blocks(s->fd_in)) + break; + } + + if (size > 0) { s->fd_read(s->fd_opaque, buf, size); } --------------030100010102030008050907--