From: Steven Rostedt <rostedt@goodmis.org>
To: virtualization@lists.osdl.org,
Glauber de Oliveira Costa <glommer@gmail.com>,
Rusty Russell <rusty@rustcorp.com.au>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH] Lguest launcher, child starving parent
Date: Thu, 05 Apr 2007 16:40:20 -0400 [thread overview]
Message-ID: <1175805620.24675.9.camel@localhost.localdomain> (raw)
Glauber noticed long delays between hitting a key, and seeing data come
up on the virtual console. Looking into this, I found that the
wake_parent routine that reads from all devices was actually starving
out the parent after sending the parent a signal to wake up.
The thing is, the child which takes the console input is recognized by
the scheduler as an interactive process. The parent, doesn't do so
much, so it is recognized more as a CPU hog. So the child easily gets a
higher priority than the parent.
So when the child receives data from the console, it sends a signal to
the parent and then does another select. The problem is that the select
doesn't actually read from the device, and will return immediately since
their is still data pending until it is read. But it's the parent that
reads the data. So the child actually starves the parent from reading
the data by spinning and waiting for it to read the data.
The fix I implemented was to have the child wait for a response from the
parent before going on. Since there was already communication between
the parent and child via a pipe, I used that. This time, the data
returned by the pipe is either everything went fine (fd == -1) or the
device should be ignored (fd >= 0).
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Index: linux-2.6-lguest/Documentation/lguest/lguest.c
===================================================================
--- linux-2.6-lguest.orig/Documentation/lguest/lguest.c 2007-04-05 16:13:08.000000000 -0400
+++ linux-2.6-lguest/Documentation/lguest/lguest.c 2007-04-05 16:16:31.000000000 -0400
@@ -328,15 +328,15 @@ static void wake_parent(int pipefd, stru
for (;;) {
fd_set rfds = devices->infds;
+ int ignorefd;
select(devices->max_infd+1, &rfds, NULL, NULL, NULL);
- if (FD_ISSET(pipefd, &rfds)) {
- int ignorefd;
- if (read(pipefd, &ignorefd, sizeof(ignorefd)) == 0)
- exit(0);
- FD_CLR(ignorefd, &devices->infds);
- }
kill(getppid(), SIGUSR1);
+ /* wait for parent response */
+ if (read(pipefd, &ignorefd, sizeof(ignorefd)) == 0)
+ exit(0);
+ if (ignorefd >= 0)
+ FD_CLR(ignorefd, &devices->infds);
}
}
@@ -594,6 +594,7 @@ static void handle_output(int fd, unsign
static void handle_input(int fd, int childfd, struct device_list *devices)
{
struct timeval poll = { .tv_sec = 0, .tv_usec = 0 };
+ int fdok = -1;
for (;;) {
struct device *i;
@@ -608,7 +609,9 @@ static void handle_input(int fd, int chi
FD_CLR(i->fd, &devices->infds);
/* Tell child to ignore it too... */
write(childfd, &i->fd, sizeof(i->fd));
- }
+ } else
+ /* Tell child to continue */
+ write(childfd, &fdok, sizeof(fdok));
}
}
}
next reply other threads:[~2007-04-05 20:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-04-05 20:40 Steven Rostedt [this message]
2007-04-06 3:17 ` [PATCH] Lguest launcher, child starving parent Rusty Russell
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=1175805620.24675.9.camel@localhost.localdomain \
--to=rostedt@goodmis.org \
--cc=glommer@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rusty@rustcorp.com.au \
--cc=virtualization@lists.osdl.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).