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); }