VirtualBox HPET Problems

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
LiamT
Posts: 9
Joined: Sun Jul 12, 2015 2:21 am
Contact:

VirtualBox HPET Problems

Post by LiamT »

Hello!

Recently, i've been trying to get the HPET to work properly as a source for event timing in my kernel. As much as I love the PIT, I'd like something with a little more precision (and the ability to provide a stable time source).
It took me a couple of tries to figure it out, but my HPET code seems to work reliably in VMWare. The problem is that it fails silently while running in VirtualBox. I was wondering if anybody else has tried to do this on vbox and succeeded.

What i'm trying to do is set up a one-shot interrupt from the HPET to trigger a timer callback. VirtualBox is reporting an HPET via ACPI, and the information i'm getting seems to be sane. I've made sure my I/O APIC mapping is set up properly, and i'm using level triggered interrupts. ( This is so that i can detect an overrun of the HPET timer beyond my intended interrupt time, supposing the delta between the time that was current during delta calculation and the time that i set the HPET counter enabled was smaller than the actual time that passed ).

I have the comparator already set up as 32-bit, level triggered, interrupts disabled.

Every time I set the HPET counter comparator to trigger, i do these steps (which took some trial and error to figure out, as the HPET specification is somewhat ambiguous:
source file

Code: Select all

::HW::ACPI::HPET :: SetCounterComparratorWritable ( & CounterInfo, true );
::HW::ACPI::HPET :: WriteCounterComparrator32 ( & CounterInfo, NextInternalTimeout );
::HW::ACPI::HPET :: ClearCounterInterruptLevel ( & CounterInfo );
::HW::ACPI::HPET :: SetCounterEnabled ( & CounterInfo, true );
If the naming here isn't obvious, what i'm doing here is enabling the comparator write, writing the comparator (32 bits, because this is an x86 kernel), clearing the interrupt level, and then enabling interrupts from the counter.

Like I said before, this works perfectly fine in VMWare, which i usually trust to be more accurate and more quick-to-fail on problems, but seems to just not work in virtualbox. I'm really stuck here, and at the moment, I don't have hardware I feel comfortable testing on, so any help here would be greatly appreciated.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: VirtualBox HPET Problems

Post by Brendan »

Hi,
LiamT wrote:Recently, i've been trying to get the HPET to work properly as a source for event timing in my kernel. As much as I love the PIT, I'd like something with a little more precision (and the ability to provide a stable time source).
It took me a couple of tries to figure it out, but my HPET code seems to work reliably in VMWare. The problem is that it fails silently while running in VirtualBox. I was wondering if anybody else has tried to do this on vbox and succeeded.
There's multiple OSs (Windows, Linux, etc) that use HPET on VirtualBox successfully; and while it is technically possible that the version of VirtualBox you're using has some sort of bug, it's much more likely that the problem is in your code.

All of the details you've provided seem fine; but there isn't really enough details to find (or exclude) a huge number of possible problems.
LiamT wrote:Like I said before, this works perfectly fine in VMWare, which i usually trust to be more accurate and more quick-to-fail on problems, but seems to just not work in virtualbox.
Qemu is another (free) emulator that supports HPET.

At the moment you've got test results that could represent anything in the range from "works on all computers, except for one emulator" all the way to "doesn't work on any computer, except for one emulator". ;)
LiamT wrote:I'm really stuck here, and at the moment, I don't have hardware I feel comfortable testing on, so any help here would be greatly appreciated.
You have hardware you could test on, but don't feel comfortable testing on it? That seems odd to me. Unless your code tries to write to hard disks or tries to modifying CMOS; it's extremely unlikely that executing your code on real hardware will cause a problem that can't be solved by pressing a reset button.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
LiamT
Posts: 9
Joined: Sun Jul 12, 2015 2:21 am
Contact:

Re: VirtualBox HPET Problems

Post by LiamT »

There's multiple OSs (Windows, Linux, etc) that use HPET on VirtualBox successfully; and while it is technically possible that the version of VirtualBox you're using has some sort of bug, it's much more likely that the problem is in your code.
I suppose so! It wouldn't make sense that a problem this large would go unnoticed and unfixed, especially in the current version of such widely used software. Actually, what gave me this idea in the first place is that while I was still trying to come up with a solution for a tracking clock using the HPET's trigger-on-equal comparator (rather than a trigger-on-greater-than-or-equal), I tried using edge triggered mode. In the process of testing this, i actually caused virtualbox to fail quite catastrophically. More than a triple fault, the timer interrupt firing seemed to cause the actual Virtualbox process to crash on the host side, before it could write anything to the VM's log file. I figured that I had set up the APIC wrong and it must have been a quirk of not properly following interrupt routing rules, but even with interrupts disabled and the I/O APIC entry disabled, it would still crash consistently when I triggered an edge interrupt via an HPET comparator. That being said, It is still entirely possible that i've set up the HPET incorrectly and the HPET virtualization/driver code is not fault-tolerant.
All of the details you've provided seem fine; but there isn't really enough details to find (or exclude) a huge number of possible problems.
Qemu is another (free) emulator that supports HPET.

At the moment you've got test results that could represent anything in the range from "works on all computers, except for one emulator" all the way to "doesn't work on any computer, except for one emulator". ;)
Thank you for the reminder. I should have thought to test on another HPET capable VM, but I didn't realize that QEMU was. (oops )
You have hardware you could test on, but don't feel comfortable testing on it?
Or I should say, I have hardware near me that I could test on, but the owner doesn't feel comfortable with me testing on it. My development machine is a macintosh, and I'm not too excited about dealing with that mess of a boot-loader hack. I'll try QEMU, and get back to the thread if i figure anything out.

Thanks Brendan!
Techel
Member
Member
Posts: 215
Joined: Fri Jan 30, 2015 4:57 pm
Location: Germany
Contact:

Re: VirtualBox HPET Problems

Post by Techel »

There's a hardware-testing thread right here in the forums, have a look at it.
MollenOS
Member
Member
Posts: 202
Joined: Wed Oct 26, 2011 12:00 pm

Re: VirtualBox HPET Problems

Post by MollenOS »

You can take a look at my HPET driver if you want, and see if it does anything differently, it works for me on VirtualBox

https://github.com/Fadekraft/MollenOS/b ... pet/Hpet.c

The code is a mess, and that im sorry for, I still need to rewrite it a bit and finish the driver.
Post Reply