qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Nathan <nejucomo@gmail.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] Poor clone/SIGALRM interaction on linux host.
Date: Mon, 2 Feb 2009 17:37:58 -0800	[thread overview]
Message-ID: <13f991410902021737o3dbccbdbk77c0dd012e15f401@mail.gmail.com> (raw)

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

Hello,

I apologize if this problem is off topic.  I have not determined if
this issue is specific to the Google Android project or not.


The symptoms:

When I run the android emulator which is built atop qemu, the process
enters a busy loop in which it repeatedly calls clone on linux which
returns ERESTARTNOINTR.

Interspersed between each clone call were many SIGALRMs.

This was all determined using strace.


The hypothesis:

After googling a bit, I believe my symptoms are explained within this post:
http://kerneltrap.org/mailarchive/linux-kernel/2007/4/28/83322

-namely, SIGALRM interrupts a clone call, and the clone operation is
aborted.  Because the SIGALRM frequency is much greater than the
frequency of calls to clone, it does not complete for an arbitrarily
long time.


The fix:

If this hypothesis is correct, the best fix is probably to delay
launching the timer until after clone.  I leave this as an exercise to
the reader.  (In other words, I didn't look into it deeply enough.
;-)


The test:

I tested my hypothesis by altering the SIGALRM rate set by setitimer
to make it *10 times slower* in the qemu source tree tracked inside
the Android platform project.  The diff from the Android fork is
attached.

By viewing the android revision log (stored in a git repository) it
looks like this fork was created from qemu 0.8.2.  If this issue has
already been addressed in the Qemu main trunk, or if the diff does not
match the current state, let me know so I can work with the Google
fork to follow this issue.

However, I don't believe this patch should be integrated into Qemu,
but should only serve to illustrate the issue.


The environment:

My kernel is:
$ uname -a
Linux hackbox 2.6.24-19-virtual #1 SMP Wed Jun 18 15:52:10 UTC 2008
i686 GNU/Linux

This is Ubuntu:
$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 8.04.2
Release:	8.04
Codename:	hardy

It is running as a vmware guest in VMWare Workstation 6.0.2 build-59824.

The vmware guest is incredibly slow.  After some tinkering I have an
unverified hunch that I had configured its memory to too large a value
and the host system was swapping the guests "physical" memory to disk.

Whatever the case, the running speed of processes on the guest was
incredibly slow.


Further information:

I've brought this issue to the attention of the Android platform team here:
http://code.google.com/p/android/issues/detail?id=138&can=1&q=qemu&colspec=ID%20Type%20Version%20Security%20Status%20Owner%20Summary


Regards,
Nathan Wilcox

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

$ git diff google_qemu_stream isec_nathan_timer_tweak
diff --git a/qemu_timers.c b/qemu_timers.c
index 2dc0806..d521315 100644
--- a/qemu_timers.c
+++ b/qemu_timers.c
@@ -29,6 +29,13 @@ QEMUClock *vm_clock;
 /***********************************************************/
 /* real time host monotonic timer */

+/* Hacked by nathan@isecpartners.com to prevent busy spin during clone
+ * on a slow linux vm guest:
+ */
+#define ORIGINAL_QEMU_UNIX_USEC 999
+#define TWEAKED_QEMU_UNIX_USEC 9999
+#define QEMU_UNIX_USEC TWEAKED_QEMU_UNIX_USEC
+
 /* digit: the following two variables are used to implement high-resolution
  * poll-based interrupts. the idea is to be able to generate an emulated
  * interrupt every millisecond, even on non-Linux platforms which don't have
@@ -917,9 +924,9 @@ static int unix_start_timer(struct qemu_alarm_timer *t)

     itv.it_interval.tv_sec = 0;
     /* for i386 kernel 2.6 to get 1 ms */
-    itv.it_interval.tv_usec = 999;
+    itv.it_interval.tv_usec = QEMU_UNIX_USEC;
     itv.it_value.tv_sec = 0;
-    itv.it_value.tv_usec = 10 * 1000;
+    itv.it_value.tv_usec = 10 * (QEMU_TIMER_REALTIME + 1);

     err = setitimer(ITIMER_REAL, &itv, NULL);
     if (err)

                 reply	other threads:[~2009-02-03  1:38 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=13f991410902021737o3dbccbdbk77c0dd012e15f401@mail.gmail.com \
    --to=nejucomo@gmail.com \
    --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).