qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Anthony Liguori <anthony@codemonkey.ws>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 3/4] Improve character device read performance
Date: Sun, 16 Jul 2006 13:14:29 -0500	[thread overview]
Message-ID: <44BA8205.7020304@codemonkey.ws> (raw)

[-- Attachment #1: Type: text/plain, Size: 26 bytes --]

Regards,

Anthony Liguori

[-- Attachment #2: chrdev_partial_read.diff --]
[-- Type: text/x-patch, Size: 1484 bytes --]

# 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);
     }

                 reply	other threads:[~2006-07-16 18:18 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=44BA8205.7020304@codemonkey.ws \
    --to=anthony@codemonkey.ws \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).