Bochs RTC , Qemu PIT 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
shacknetisp
Member
Member
Posts: 29
Joined: Wed Jan 25, 2012 2:37 pm

Bochs RTC , Qemu PIT Problems

Post by shacknetisp »

While developing my kernel's clock, I noticed an interesting problem:
When I read from Bochs' RTC, it shows the time much faster than it really is.
When I use qemu's PIT, it is slower than Bochs'
Maybe I'm not configuring something?

Thanks!
Last edited by shacknetisp on Mon Aug 20, 2012 9:01 am, edited 2 times in total.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: Bochs RTC bug, Qemu PIT bug!

Post by JamesM »

Don't shout "bug" unless you've legitimately found one and can reproduce it.

You'll make a lot of people angry.
shacknetisp
Member
Member
Posts: 29
Joined: Wed Jan 25, 2012 2:37 pm

Re: Bochs RTC bug, Qemu PIT bug!

Post by shacknetisp »

Sorry! :oops:
I thought it must be a bug since I used code that works on real hardware...
shacknetisp
Member
Member
Posts: 29
Joined: Wed Jan 25, 2012 2:37 pm

Re: Bochs RTC , Qemu PIT Problems

Post by shacknetisp »

OK, I've got a work-around, but I still don't know WHY it is happening.
Nable
Member
Member
Posts: 453
Joined: Tue Nov 08, 2011 11:35 am

Re: Bochs RTC , Qemu PIT Problems

Post by Nable »

What do you mean by 'than it really is' ?

Bochs is more a simulator, than emulator: i mean it's more aimed to accuracy of CPU behavior than to real-time work. Unless you configure it to do some syncronization, it won't try to sync with host clock (and in most cases it's a rather bad idea to add this syncronization overhead). Although, the ratio between emulated clock and emulation cycles is kept accurate. It's better for you to read more about it's configuration.

Then, QEMU is more intended for fast and dirty work. It's emulation cycles are not predictable periods of time but guest OS clock is almost real-time (in terms of host clock).
shacknetisp
Member
Member
Posts: 29
Joined: Wed Jan 25, 2012 2:37 pm

Re: Bochs RTC , Qemu PIT Problems

Post by shacknetisp »

So that's why it doesn't work on bochs...
But I've just been testing on a Thinkpad T60, and it acted like bochs! :?:
(I had been running on a dell Inspiron 1501).
Nable
Member
Member
Posts: 453
Joined: Tue Nov 08, 2011 11:35 am

Re: Bochs RTC , Qemu PIT Problems

Post by Nable »

I still don't catch what are you comparing guest clock (and which guest clock: TSC, RTC, HPET) with (wall clock, TSC?).

Please, give more details about your experiments.
shacknetisp
Member
Member
Posts: 29
Joined: Wed Jan 25, 2012 2:37 pm

Re: Bochs RTC , Qemu PIT Problems

Post by shacknetisp »

Well, I've set both Bochs' RTC and the Dell's RTC to my local time.
Reading from the RTC once every second, it increments the second by 4 or 5 times for every second on the wall clock.

And for Qemu, it's PIT frequency is less than bochs'.
I set a timer to run in 10 PIT ticks:
Bochs: runs in (about) 1 second.
Qemu: runs in (about) 3 seconds.
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Bochs RTC , Qemu PIT Problems

Post by bluemoon »

The whole idea of using PIT to calibrate RTC is questionable.

PIT subject to many factor, including hardware delays, bus delay, interrupt latency, and many things.
When you set it to 18.2Hz for example, you may not get 18.2 tick per second, even on real hardware - if it look like it happen, it's pure luck.

Then, on top of that is the emulator overhead - most emulator do not provide accurate PIT (in term of real world wall clock) for various reasons.

As a side note, RTC in most computer is inaccurate compare to real world clock.
shacknetisp
Member
Member
Posts: 29
Joined: Wed Jan 25, 2012 2:37 pm

Re: Bochs RTC , Qemu PIT Problems

Post by shacknetisp »

Thanks!
I guess I'll read some more on the RTC and PIT and see if I missed anything.
(I'll probably feel stupid :( )
Post Reply