Bochs PIT broken?

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
tkausl
Posts: 17
Joined: Tue Jul 14, 2015 9:54 pm

Bochs PIT broken?

Post by tkausl »

Hello,

I've tried setting up the PIT with the following code:

Code: Select all

  uint32_t divisor = 1193182 / 50;
  outb(0x43, 0x36);
  u8int l = (u8int)(divisor & 0xFF);
  u8int h = (u8int)( (divisor>>8) & 0xFF );
  outb(0x40, l);
  for(int i = 0; i < 1000000; i++); // Does neither work with nor without this loop
  outb(0x40, h);
For some Reason, Bochs spams me with timer-interrupts, a lot more than i requested.My first and only process sleeps for 50 ticks, prints something and goes back to sleeping. In Bochs, this spams my terminal like hell, if i start it in VirtualBox, i get one print (approx.) every second (its like every ~.9 seconds or so). Am i doing something wrong here?
bradbobak
Member
Member
Posts: 26
Joined: Fri Apr 14, 2006 11:00 pm

Re: Bochs PIT broken?

Post by bradbobak »

I had this issue before..i think adding the following to the bochsrc.txt may solve the problem.

Code: Select all

clock: sync=slowdown
tkausl
Posts: 17
Joined: Tue Jul 14, 2015 9:54 pm

Re: Bochs PIT broken?

Post by tkausl »

bradbobak wrote:I had this issue before..i think adding the following to the bochsrc.txt may solve the problem.

Code: Select all

clock: sync=slowdown
It helps, but now everything is loading like hours :mrgreen:

Code: Select all

clock: sync=realtime
seems to help too, i've to test this tomorrow.
User avatar
Kazinsal
Member
Member
Posts: 559
Joined: Wed Jul 13, 2011 7:38 pm
Libera.chat IRC: Kazinsal
Location: Vancouver
Contact:

Re: Bochs PIT broken?

Post by Kazinsal »

Bochs is a terribly old emulator from the 90s. It has barely changed since then, as you can probably tell by the near complete lack of anything resembling a sane interface and configuration structure.

Don't use Bochs. Use a sane virtual machine that can use hardware virtualization and dynamic translation like QEMU or VirtualBox.
Nable
Member
Member
Posts: 453
Joined: Tue Nov 08, 2011 11:35 am

Re: Bochs PIT broken?

Post by Nable »

Kazinsal wrote:Bochs is a terribly old emulator from the 90s. It has barely changed since then, as you can probably tell by the near complete lack of anything resembling a sane interface and configuration structure.

Don't use Bochs. Use a sane virtual machine that can use hardware virtualization and dynamic translation like QEMU or VirtualBox.
Hey, please, cool down a bit. Bochs is a simulator, it's really accurate and provides unique information when something goes wrong with your custom software.

QEmu and VirtualBox are quick-and-dirty solutions (OK, QEmu-KVM isn't dirty but it's still not very useful while debugging some obscure cases that you have while writing your own OS or VMM) for running common products (Windows/*nix) that you aren't going to debug.

Bochs can be compared to AMD SimNow or, possibly, Simics.
It's a great tool but as most good tools it's neither versatile nor trivial to use.

Btw, it's funny when one says "sane" about VMM that can happily run broken code that doesn't work on real hardware (and in Bochs, yes). Isn't it the real insanity?
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Bochs PIT broken?

Post by Brendan »

Hi,

For emulators, there's 3 very different use cases:
  • You want it to run as fast as possible while maintaining "virtual time = real time". In this case it's impossible to make it deterministic. This is the "sync=realtime" option in Bochs.
  • You want it to be deterministic while maintaining "virtual time = real time". In this case it can't run as fast as possible. This is the "sync=slowdown" option in Bochs.
  • You want it to be deterministic and run as fast as possible. In this case it can't ensure "virtual time = real time". This is the "sync=none" option in Bochs.
For "sync=slowdown"; the "IPS" setting determines how fast the virtual machine should try to run. If Bochs determines that the virtual machine is running faster than IPS says it should then Bochs will slow the virtual machine down; and if Bochs determines that the virtual machine is running slower than IPS says it should then there's nothing Bochs can do about it (IPS is set wrong) and "virtual time = real time" gets broken. This means that for this case you probably want to set "IPS" to about "90% of as fast as possible" so that Bochs doesn't deliberately slow it down too much, but there's no risk of "virtual time = real time" getting broken.

For "sync=none"; the "IPS" setting is used to determine how much virtual time has passed (where virtual time has nothing to do with real time at all). E.g. if you set IPS to 100000 then Bochs does 100000 instructions per virtual second (where 1 virtual second might be 10 ms of real time, or 10 seconds of real time, or anything else). In this case, you can set the IPS setting to anything you like, but might want to set IPS so that virtual time is close to real time.

Most emulators aren't as flexible as Bochs and force you to use the equivalent of "sync=realtime" without giving you any choice. This is fine for most things, but "non-deterministic" makes it extremely hard to debug things like race conditions (that are effected by different timing).


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.
tkausl
Posts: 17
Joined: Tue Jul 14, 2015 9:54 pm

Re: Bochs PIT broken?

Post by tkausl »

Thanks Brendan for the in-depth information.

Normally i wouldn't care, but i've implemented multithreading now and i was testing my sleep() function, i want/need to precisely know tick-speed and if my 11931 divisor just ticks like hell, there is nothing i can do about :( But in VirtualBox at least it looks like 100 ticks are 1 second, might be little bit more or less.
Peterbjornx
Member
Member
Posts: 116
Joined: Thu May 06, 2010 4:34 am
Libera.chat IRC: peterbjornx
Location: Leiden, The Netherlands
Contact:

Re: Bochs PIT broken?

Post by Peterbjornx »

In my experience QEmu's PIT isn't to be trusted either: my kernel used it as its timebase and although it kept accurate time on real hardware it was unable to do so in QEmu: a single second took over half a minute!
Post Reply