Add HPET emulation to qemu (v2)
RFC PATCH 1/1 Add HPET emulation to qemu (v2)
Major changes:
- Rebased to register-based operations for ease of save/restore.
- Looked through Xen's hpet implementation and picked up a bunch of things, though not quite everything yet. Thanks!
- PIT and RTC are entirely disabled in legacy mode, not just their interrupts.
There is still a bunch to do but I'm re-posting primarily because of the switch to register-based. I have still only tested with a linux guest. Windows guest is next on my list... as soon as I return from my week vacation.
I've been playing with CONFIG_NO_HZ and been surprised by the results. I was trying to reproduce the wakeup every 10ms that Samuel Thibault mentioned, thinking the HPET would improve it. But for an idle guest in both cases (with and without HPET), the number of wakeups per second was relatively low (28). Ultimately this depends on exactly what the guest is doing
when idle, so maybe the HPET won't provide any improvement here. But in any case, I didn't see the 10ms wakeup cycle with CONFIG_NO_HZ. If anyone can shed any light on this, I could look into it more if need be.
***
Makefile.target | 2 hw/hpet.c | 441 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ hw/i8254.c | 11 + hw/mc146818rtc.c | 30 +++ hw/pc.c | 2 5 files changed, 483 insertions(+), 3 deletions(-)
***
Makefile.target +1 -1
@@ -536,7 +536,7 @@ ifeq ($(TARGET_BASE_ARCH), i386) OBJS+= ide.o pckbd.o ps2.o vga.o $(SOUND_HW) dma.o OBJS+= fdc.o mc146818rtc.o serial.o i8259.o i8254.o pcspk.o pc.o OBJS+= cirrus_vga.o apic.o parallel.o acpi.o piix_pci.o -OBJS+= usb-uhci.o vmmouse.o vmport.o vmware_vga.o +OBJS+= usb-uhci.o vmmouse.o vmport.o vmware_vga.o hpet.o CPPFLAGS += -DHAS_AUDIO -DHAS_AUDIO_CHOICE endif ifeq ($(TARGET_BASE_ARCH), ppc)
hw/hpet.c new file +441 -0
441 lines not on this page · raw message
hw/i8254.c +11 -0
@@ -26,6 +26,9 @@#include "isa.h" #include "qemu-timer.h" +#if definedTARGET_I386 || definedTARGET_X86_64 +extern int hpet_legacy; +#endif //#define DEBUG_PIT #define RW_STATE_LSB 1
@@ -367,6 +370,14 @@ static void pit_irq_timer_update(PITChannelState *s, int64_t current_time)if (!s->irq_timer)return ; + +#if definedTARGET_I386 || definedTARGET_X86_64 +if (hpet_legacy) { +qemu_del_timer (s->irq_timer); +return ; + } +#endif + expire_time =pit_get_next_transition_time (s, current_time); irq_level =pit_get_out1 (s, current_time);qemu_set_irq (s->irq, irq_level);
hw/mc146818rtc.c +28 -2
@@ -27,6 +27,10 @@#include "pc.h" #include "isa.h" +#if definedTARGET_I386 || definedTARGET_X86_64 +extern int hpet_legacy; +#endif +//#define DEBUG_CMOS #define RTC_SECONDS 0
@@ -80,7 +84,11 @@ static void rtc_timer_update(RTCState *s, int64_t current_time) period_code = s->cmos_data[RTC_REG_A ] &0x0f ; if (period_code != 0 && +#if definedTARGET_I386 || definedTARGET_X86_64 + (s->cmos_data[RTC_REG_B] & REG_B_PIE) && !hpet_legacy) { +#else (s->cmos_data[RTC_REG_B] & REG_B_PIE)) { +#endif if (period_code <=2 ) period_code +=7 ;/* period in 32 Khz cycles */
@@ -101,7 +109,10 @@ static void rtc_periodic_timer(void *opaque)rtc_timer_update (s, s->next_periodic_time); s->cmos_data[RTC_REG_C ] |=0xc0 ; -qemu_irq_raise (s->irq); +#if definedTARGET_I386 || definedTARGET_X86_64 + if (!hpet_legacy) +#endif +qemu_irq_raise (s->irq); }static void cmos_ioport_write (void *opaque,uint32_t addr,uint32_t data)
@@ -281,6 +292,12 @@ static void rtc_update_second(void *opaque)RTCState *s = opaque;int64_t delay; +#if definedTARGET_I386 || definedTARGET_X86_64 +if (hpet_legacy) { +qemu_del_timer (s->second_timer2); +return ; + } +#endif /* if the oscillator is not in normal operation, we do not update */ if ((s->cmos_data[RTC_REG_A ] &0x70 ) !=0x20 ) { s->next_second_time += ticks_per_sec;
@@ -306,6 +323,12 @@ static void rtc_update_second2(void *opaque) {RTCState *s = opaque; +#if definedTARGET_I386 || definedTARGET_X86_64 +if (hpet_legacy) { +qemu_del_timer (s->second_timer); +return ; + } +#endif if (!(s->cmos_data[RTC_REG_B ] ®_B_SET )) {rtc_copy_date (s); }
@@ -359,7 +382,10 @@ static uint32_t cmos_ioport_read(void *opaque, uint32_t addr)break ;case RTC_REG_C : ret = s->cmos_data[s->cmos_index]; -qemu_irq_lower (s->irq); +#if definedTARGET_I386 || definedTARGET_X86_64 + if (!hpet_legacy) +#endif +qemu_irq_lower (s->irq); s->cmos_data[RTC_REG_C ] =0x00 ;break ;default :
hw/pc.c +2 -0
@@ -46,6 +46,7 @@#define ACPI_DATA_SIZE 0x10000#define MAX_IDE_BUS 2 +void hpet_init (qemu_irq irq);static fdctrl_t *floppy_controller;static RTCState *rtc_state;
@@ -925,6 +926,7 @@ static void pc_init1(ram_addr_t ram_size, int vga_ram_size, } pit =pit_init (0x40 , i8259[0 ]);pcspk_init (pit); +hpet_init (i8259);if (pci_enabled) {pic_set_alt_irq_func (isa_pic, ioapic_set_irq, ioapic); }
Quoted 4 lines · Beth Kon, le Sat 02 Aug 2008 06:05:14 -0500, a écrit :
I was trying to reproduce the wakeup every 10ms that Samuel Thibault mentioned, thinking the HPET would improve it. But for an idle guest in both cases (with and without HPET), the number of wakeups per second was relatively low (28).
I was referring to vl.c's timeout = 10; which makes the select call use a timeout of 10ms. That said, "/* If all cpus are halted then wait until the next IRQ */", so maybe that's why you get slower wakeups per second. I'm still surprised because of the call to qemu_mod_timer in pit_irq_timer_update which should setup at least a 100Hz timer with linux guests (when they don't have HPET available).
Samuel
Quoted 5 lines · Samuel Thibault
Quoted 2 lines · Beth Kon, le Sat 02 Aug 2008 06:05:14 -0500, a écrit :
I was trying to reproduce the wakeup every 10ms that Samuel Thibault mentioned, thinking the HPET would improve it. But for an idle guest in both cases (with and without HPET), the number of wakeups per second was relatively low (28).
Quoted 7 lines
I was referring to vl.c's timeout = 10; which makes the select call use a timeout of 10ms. That said, "/* If all cpus are halted then wait until the next IRQ */", so maybe that's why you get slower wakeups per second. I'm still surprised because of the call to
qemu_mod_timerinpit_irq_timer_updatewhich should setup at least a 100Hz timer with linux guests (when they don't have HPET available).
The patch disables that when hpet is active.
Regards,
Anthony Liguori
Quoted 4 lines
Samuel
Quoted 17 lines · Anthony Liguori, le Sat 02 Aug 2008 09:46:30 -0500, a écrit :
Quoted 8 lines · Samuel Thibault
Quoted 5 lines · Beth Kon, le Sat 02 Aug 2008 06:05:14 -0500, a écrit :
I was trying to reproduce the wakeup every 10ms that Samuel Thibault mentioned, thinking the HPET would improve it. But for an idle guest in both cases (with and without HPET), the number of wakeups per second was relatively low (28).
Quoted 7 lines
I was referring to vl.c's timeout = 10; which makes the select call use a timeout of 10ms. That said, "/* If all cpus are halted then wait until the next IRQ */", so maybe that's why you get slower wakeups per second. I'm still surprised because of the call to
qemu_mod_timerinpit_irq_timer_updatewhich should setup at least a 100Hz timer with linux guests (when they don't have HPET available).
Quoted 1 line
The patch disables that when hpet is active.
That's why I would expect, indeed, but he is reporting that _without_ HPET he gets low wakeups per second already.
Samuel
Quoted 18 lines · Samuel Thibault, le Sat 02 Aug 2008 18:21:03 +0100, a écrit :
Quoted 17 lines · Anthony Liguori, le Sat 02 Aug 2008 09:46:30 -0500, a écrit :
Quoted 15 lines · Samuel Thibault
Quoted 5 lines · Beth Kon, le Sat 02 Aug 2008 06:05:14 -0500, a écrit :
I was trying to reproduce the wakeup every 10ms that Samuel Thibault mentioned, thinking the HPET would improve it. But for an idle guest in both cases (with and without HPET), the number of wakeups per second was relatively low (28).
I was referring to vl.c's timeout = 10; which makes the select call use a timeout of 10ms. That said, "/* If all cpus are halted then wait until the next IRQ */", so maybe that's why you get slower wakeups per second. I'm still surprised because of the call to
qemu_mod_timerinpit_irq_timer_updatewhich should setup at least a 100Hz timer with linux guests (when they don't have HPET available).
Quoted 3 lines
Quoted 1 line
The patch disables that when hpet is active.
That's why I would expect, indeed, but he is reporting that _without_
what*
Quoted 1 line
HPET he gets low wakeups per second already.
Samuel
Quoted 18 lines · Samuel Thibault
Quoted 17 lines · Anthony Liguori, le Sat 02 Aug 2008 09:46:30 -0500, a écrit :
Quoted 15 lines · Samuel Thibault
Quoted 5 lines · Beth Kon, le Sat 02 Aug 2008 06:05:14 -0500, a écrit :
I was trying to reproduce the wakeup every 10ms that Samuel Thibault mentioned, thinking the HPET would improve it. But for an idle guest in both cases (with and without HPET), the number of wakeups per second was relatively low (28).
I was referring to vl.c's timeout = 10; which makes the select call use a timeout of 10ms. That said, "/* If all cpus are halted then wait until the next IRQ */", so maybe that's why you get slower wakeups per second. I'm still surprised because of the call to
qemu_mod_timerinpit_irq_timer_updatewhich should setup at least a 100Hz timer with linux guests (when they don't have HPET available).
Quoted 6 lines
Quoted 1 line
The patch disables that when hpet is active.
That's why I would expect, indeed, but he is reporting that _without_ HPET he gets low wakeups per second already.
Samuel
Yes, 28 is incorrect. I was misinterpreting the output of powertop, shown here:
Wakeups-from-idle per second : 27.7 interval: 10.0s
no ACPI power usage estimate available
Top causes for wakeups:
46.1% ( 63.9) qemu-system-x86 : schedule_timeout (process_timeout)
36.5% ( 50.6) qemu-system-x86 : sys_timer_settime (posix_timer_fn)
...
The "Wakeups-from-idle per second" reports 27.7, but the powertop source code shows that this value is the total wakeups-per-second divided by the number of online processors. So the proper number of wakeups-per-second caused by the select is 63.9, which makes more sense.
Looking at the main_loop code, there is no way to get a timeout of greater than 10 without setting icount.
Quoted 4 lines
--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 4 lines
Elizabeth Kon (Beth) IBM Linux Technology Center Open Hypervisor Team email: [email protected]
Quoted 6 lines
I've been playing with
CONFIG_NO_HZand been surprised by the results. I was trying to reproduce the wakeup every 10ms that Samuel Thibault mentioned, thinking the HPET would improve it. But for an idle guest in both cases (with and without HPET), the number of wakeups per second was relatively low (28). Ultimately this depends on exactly what the guest is doing
Linux can use the existing acpi PM timer a NO_HZ clocksource.
Paul