Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JBeGx-0004Vq-75 for qemu-devel@nongnu.org; Sun, 06 Jan 2008 17:47:15 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JBeGw-0004VY-Kg for qemu-devel@nongnu.org; Sun, 06 Jan 2008 17:47:14 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JBeGw-0004VS-Cs for qemu-devel@nongnu.org; Sun, 06 Jan 2008 17:47:14 -0500 Received: from 0xc2c0b63d.fbbft3nxf1.bf-dhcp.tele.dk ([194.192.182.61] helo=smtp.hotelhot.dk) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1JBeGw-0001hH-7J for qemu-devel@nongnu.org; Sun, 06 Jan 2008 17:47:14 -0500 Received: from smtp.hotelhot.dk (localhost [127.0.0.1]) by smtp.hotelhot.dk (Postfix) with ESMTP id 8AF9E14314 for ; Sun, 6 Jan 2008 23:47:10 +0100 (CET) Received: from kalibalik.dk (dhcp251.kalibalik.dk [192.168.0.251]) by smtp.hotelhot.dk (Postfix) with SMTP id 745BF14312 for ; Sun, 6 Jan 2008 23:47:09 +0100 (CET) From: Anders Melchiorsen Date: Sun, 06 Jan 2008 23:47:08 +0100 Message-ID: <878x32shar.fsf@dylle.kalibalik.dk> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Subject: [Qemu-devel] [PATCH] RTC dyntick 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 --=-=-= Hello. This patch stops the qemu seconds timer when the RTC is not used. Once the cmos is accessed, the skipped seconds are accounted for, and the timer is enabled again. In case interrupts are to be delivered, the timer is not disabled. I have obviously gone mad from staring too much at PowerTOP, as this really is a micro-optimization. On the other hand, this change eliminates the last host-induced periodic timer in my kvm setup, so it seems worth the trouble. Please comment, does it make sense? Anders. --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=qemu-rtc-dyntick.diff diff --git a/qemu/hw/mc146818rtc.c b/qemu/hw/mc146818rtc.c index e1e6427..fd00f3a 100644 --- a/qemu/hw/mc146818rtc.c +++ b/qemu/hw/mc146818rtc.c @@ -72,6 +72,7 @@ struct RTCState { static void rtc_set_time(RTCState *s); static void rtc_copy_date(RTCState *s); +static void rtc_catchup(RTCState *s); static void rtc_timer_update(RTCState *s, int64_t current_time) { @@ -108,6 +109,8 @@ static void cmos_ioport_write(void *opaque, uint32_t addr, uint32_t data) { RTCState *s = opaque; + rtc_catchup(s); + if ((addr & 1) == 0) { s->cmos_index = data & 0x7f; } else { @@ -334,13 +337,48 @@ static void rtc_update_second2(void *opaque) s->cmos_data[RTC_REG_A] &= ~REG_A_UIP; s->next_second_time += ticks_per_sec; - qemu_mod_timer(s->second_timer, s->next_second_time); + + /* Keep going only if interrupts are needed */ + if (s->cmos_data[RTC_REG_B] & (REG_B_AIE | REG_B_UIE)) { + qemu_mod_timer(s->second_timer, s->next_second_time); + } +} + +static void rtc_catchup(RTCState *s) +{ + int64_t now; + + if (!qemu_timer_pending(s->second_timer) && + !qemu_timer_pending(s->second_timer2)) { + + /* Count the seconds passed since last access */ + now = qemu_get_clock(vm_clock); + + while (s->next_second_time <= now) { + rtc_next_second(&s->current_tm); + s->next_second_time += ticks_per_sec; + } + + if (!(s->cmos_data[RTC_REG_B] & REG_B_SET)) { + rtc_copy_date(s); + } + + /* Restart the right timer */ + if ((s->next_second_time - now) < ticks_per_sec/100) { + rtc_update_second(s); + } else { + qemu_mod_timer(s->second_timer, s->next_second_time); + } + } } static uint32_t cmos_ioport_read(void *opaque, uint32_t addr) { RTCState *s = opaque; int ret; + + rtc_catchup(s); + if ((addr & 1) == 0) { return 0xff; } else { --=-=-=--