From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 2/2] qemu-timer: change unix timer to dynticks
Date: Thu, 9 Jun 2011 13:10:25 +0200 [thread overview]
Message-ID: <1307617825-17149-3-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1307617825-17149-1-git-send-email-pbonzini@redhat.com>
A timer that wakes up every millisecond puts a lot of stress on the
iothread. The large amount of IPIs causes very high context switch
activity, making emulation slow and the UI unusable. This is by the
way the same reason why the Windows timers were switched to dynticks.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Tested-by: Alexander Graf <agraf@suse.de>
---
qemu-timer.c | 40 ++++++++++++++++++++++++++++------------
1 files changed, 28 insertions(+), 12 deletions(-)
diff --git a/qemu-timer.c b/qemu-timer.c
index 4141b6e..5d78cc4 100644
--- a/qemu-timer.c
+++ b/qemu-timer.c
@@ -227,6 +227,7 @@ static void win32_rearm_timer(struct qemu_alarm_timer *t);
static int unix_start_timer(struct qemu_alarm_timer *t);
static void unix_stop_timer(struct qemu_alarm_timer *t);
+static void unix_rearm_timer(struct qemu_alarm_timer *t);
#ifdef __linux__
@@ -309,7 +310,7 @@ static struct qemu_alarm_timer alarm_timers[] = {
/* ...otherwise try RTC */
{"rtc", rtc_start_timer, rtc_stop_timer, NULL},
#endif
- {"unix", unix_start_timer, unix_stop_timer, NULL},
+ {"unix", unix_start_timer, unix_stop_timer, unix_rearm_timer},
#else
{"mmtimer", mm_start_timer, mm_stop_timer, NULL},
{"mmtimer2", mm_start_timer, mm_stop_timer, mm_rearm_timer},
@@ -1010,8 +1011,6 @@ static void dynticks_rearm_timer(struct qemu_alarm_timer *t)
static int unix_start_timer(struct qemu_alarm_timer *t)
{
struct sigaction act;
- struct itimerval itv;
- int err;
/* timer signal */
sigfillset(&act.sa_mask);
@@ -1019,18 +1018,35 @@ static int unix_start_timer(struct qemu_alarm_timer *t)
act.sa_handler = host_alarm_handler;
sigaction(SIGALRM, &act, NULL);
+ return 0;
+}
- itv.it_interval.tv_sec = 0;
- /* for i386 kernel 2.6 to get 1 ms */
- itv.it_interval.tv_usec = 999;
- itv.it_value.tv_sec = 0;
- itv.it_value.tv_usec = 10 * 1000;
+static void unix_rearm_timer(struct qemu_alarm_timer *t)
+{
+ struct itimerval itv;
+ int64_t nearest_delta_ns = INT64_MAX;
+ int err;
- err = setitimer(ITIMER_REAL, &itv, NULL);
- if (err)
- return -1;
+ assert(alarm_has_dynticks(t));
+ if (!active_timers[QEMU_CLOCK_REALTIME] &&
+ !active_timers[QEMU_CLOCK_VIRTUAL] &&
+ !active_timers[QEMU_CLOCK_HOST])
+ return;
- return 0;
+ nearest_delta_ns = qemu_next_alarm_deadline();
+ if (nearest_delta_ns < MIN_TIMER_REARM_NS)
+ nearest_delta_ns = MIN_TIMER_REARM_NS;
+
+ itv.it_interval.tv_sec = 0;
+ itv.it_interval.tv_usec = 0; /* 0 for one-shot timer */
+ itv.it_value.tv_sec = nearest_delta_ns / 1000000000;
+ itv.it_value.tv_usec = (nearest_delta_ns % 1000000000) / 1000;
+ err = setitimer(ITIMER_REAL, &itv, NULL);
+ if (err) {
+ perror("setitimer");
+ fprintf(stderr, "Internal timer error: aborting\n");
+ exit(1);
+ }
}
static void unix_stop_timer(struct qemu_alarm_timer *t)
--
1.7.4.4
next prev parent reply other threads:[~2011-06-09 11:10 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-06-09 11:10 [Qemu-devel] [PATCH 0/2] iothread improvements for Mac OS X Paolo Bonzini
2011-06-09 11:10 ` [Qemu-devel] [PATCH 1/2] iothread: replace fair_mutex with a condition variable Paolo Bonzini
2011-06-09 11:10 ` Paolo Bonzini [this message]
2011-06-27 14:07 ` [Qemu-devel] [PATCH 0/2] iothread improvements for Mac OS X Paolo Bonzini
2011-06-29 4:26 ` Alexandre Raymond
2011-07-23 16:54 ` Anthony Liguori
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=1307617825-17149-3-git-send-email-pbonzini@redhat.com \
--to=pbonzini@redhat.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).