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.
Has anyone else had issue with the PIT when using VirtualBox?
No matter what frequency value I use, it seems that the PIT in virtual box takes the same amount of time - about 1 second. This makes for pretty crappy multi-processing. I have to assume then that Windows & other OSes don't use the PIT for their timing... because they run just fine in VirtualBox.
That's weird because I've tried this on several host machines too and I get the same results.
What's weirder is, if (using VirtualBox) I set the PIT to ~1000Hz and I repeatedly query the RTC for the current time, it takes about 35 seconds for one second to pass on the RTC... And if I set the PIT to 100Hz, it takes about 2-4 seconds for one second to pass... If I set it to 10Hz I get almost accurate timing...
Changing the frequency of the PIT shouln't affect the RTC -- it doesn't on real hardware. I don't get it...
-m32 wrote:That's weird because I've tried this on several host machines too and I get the same results.
What's weirder is, if (using VirtualBox) I set the PIT to ~1000Hz and I repeatedly query the RTC for the current time, it takes about 35 seconds for one second to pass on the RTC... And if I set the PIT to 100Hz, it takes about 2-4 seconds for one second to pass... If I set it to 10Hz I get almost accurate timing...
Changing the frequency of the PIT shouln't affect the RTC -- it doesn't on real hardware. I don't get it...
Has it occurred to you that the frequency the RTC updates at isn't changing, but the number of instructions executed per second in your main polling loop will decrease as you increase the frequency of interrupts? Thus, maybe it's just that the emulation isn't fast enough to cope and your RTC polling loop ends up running dog slow.
Not only that, but emulators run as user space processes and as such it is difficult->impossible to have a clock emulation frequency greater than the host OS's fastest signal/interrupt mechanism, so at a frequency of 1KHz who knows what the emulator is actually doing, because it sure as hell can't get vtimer interrupts at that frequency...
Has it occurred to you that the frequency the RTC updates at isn't changing, but the number of instructions executed per second in your main polling loop will decrease as you increase the frequency of interrupts? Thus, maybe it's just that the emulation isn't fast enough to cope and your RTC polling loop ends up running dog slow.
Well my polling loop is only 3 lines, outb, inb and putc. I can't imagine that such a small amount of machine instruction causes such a HUGE delay. Besides, If I use a frequency like 100Hz, there's no reason to have it take 4 seconds for one second to register in the RTC. 100Hz is completely reasonable.
Not only that, but emulators run as user space processes and as such it is difficult->impossible to have a clock emulation frequency greater than the host OS's fastest signal/interrupt mechanism, so at a frequency of 1KHz who knows what the emulator is actually doing, because it sure as hell can't get vtimer interrupts at that frequency...
I understand that, my point was only to demonstrate the major discrepancy in the timing as it is not experienced in any other machine virtualizer.
Has it occurred to you that the frequency the RTC updates at isn't changing, but the number of instructions executed per second in your main polling loop will decrease as you increase the frequency of interrupts? Thus, maybe it's just that the emulation isn't fast enough to cope and your RTC polling loop ends up running dog slow.
Well my polling loop is only 3 lines, outb, inb and putc. I can't imagine that such a small amount of machine instruction causes such a HUGE delay. Besides, If I use a frequency like 100Hz, there's no reason to have it take 4 seconds for one second to register in the RTC. 100Hz is completely reasonable.
I understand that, my point was only to demonstrate the major discrepancy in the timing as it is not experienced in any other machine virtualizer.
outb/inb and putc (which I assume writes to the VGA framebuffer internally?) are some of the most expensive instructions to virtualize. A lot of virtualizers will trap on the outb, trap again on inb, get through a few dozen putc instructions and trap on the framebuffer write ... each trap is tens or hundreds of thousands of instructions. It is astonishingly tricky to keep time moving in a VM, and almost impossible with a hard-to-virtualize workload like an I/O-heavy tight loop. To get into too much detail ... I/Os are extremely bad for VT/SVM-based virtualizers, so VIrtualBox (which is VT-based KVM + qemu internally) will do badly but VMware (which can run in other modes) and Bochs (which is all emulation) are likely to do better.
Put more work in the loop, or a "sti; hlt;" (which is often used to "catch up" time) and wait for interrupt delivery from the PIC.
Anyway, this kind of deviated from my original point.. setting the PIT in VirtualBox doesn't seem to have an effect on the frequency of interrupts fired. 10Hz, 20Hz, 100Hz, 1000Hz, whatever, it still takes at least 1 second to get an interrupt. - And that's with no code in my int handler except putting a period (.) on the screen. No matter how much machine instruction there is, still 1 second for the PIT interval.
Like I said it doesn't happen on any other virtualizer or hardware.