Time goes fast in Bochs

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
Dandee Yuyo
Member
Member
Posts: 47
Joined: Fri Nov 09, 2007 6:46 pm
Location: Argentina

Time goes fast in Bochs

Post by Dandee Yuyo »

Hi, I'm facing a problem with Bochs, and maybe someone ran into this before. I don't know if I'm doing something wrong or if it's simply a bochs issue.

Very early in my kernel I read the CMOS date and time and after reprogrammed the 8259 to map IRQ above the one's reserved by Intel. I installed an ISR to service the timer IRQ (the one that click 18.2 per second), and the result is that the time is going darn fast on bochs.

I tried on QEMU and real hardware and is working OK dough.

Has someone seen this before?

I also noticed that the A20 line seems to be always enabled in both emus...
NaN - Not a Nerd
Working on: Physical Memory Management with a 5-lod mipmap XD
User avatar
JackScott
Member
Member
Posts: 1036
Joined: Thu Dec 21, 2006 3:03 am
Location: Hobart, Australia
Mastodon: https://aus.social/@jackscottau
Matrix: @JackScottAU:matrix.org
GitHub: https://github.com/JackScottAU
Contact:

Post by JackScott »

http://bochs.sourceforge.net/doc/docboo ... SOPT-CLOCK

That will explain the clock running at the wrong speed. It appears that in the current version there is no way to fix it (edit: documentation out of date?). But it is an explanation at least. Essentially Bochs doesn't bother 'hlt'ing when you wait for an interrupt... it just creates the interrupt straight away.

As for the A20, no idea. I use GRUB.
Last edited by JackScott on Mon Nov 12, 2007 8:08 pm, edited 1 time in total.
frank
Member
Member
Posts: 729
Joined: Sat Dec 30, 2006 2:31 pm
Location: East Coast, USA

Post by frank »

I think that

Code: Select all

clock: sync=realtime
does a good job of slowing down the simulation to close to normal time.
User avatar
Dandee Yuyo
Member
Member
Posts: 47
Joined: Fri Nov 09, 2007 6:46 pm
Location: Argentina

Post by Dandee Yuyo »

Thank you guys. I'll give a try to the realtime setting.
NaN - Not a Nerd
Working on: Physical Memory Management with a 5-lod mipmap XD
User avatar
Dandee Yuyo
Member
Member
Posts: 47
Joined: Fri Nov 09, 2007 6:46 pm
Location: Argentina

Post by Dandee Yuyo »

frank wrote:I think that

Code: Select all

clock: sync=realtime
does a good job of slowing down the simulation to close to normal time.
It didn't work. All I got is this (I'm running a Windows build)

Code: Select all

========================================================================
                       Bochs x86 Emulator 2.0.2
                           January 21, 2003
========================================================================
00000000000i[     ] reading configuration from bochsrc.txt
00000000000p[     ] >>PANIC<< bochsrc.txt: directive 'clock' not understood
00000000000i[SYS  ] Last time is 0
00000000000i[     ] restoring default signal behavior
========================================================================
Bochs is exiting with the following message:
[     ] bochsrc.txt: directive 'clock' not understood
========================================================================
00000000000i[CTRL ] quit_sim called with exit code 1
[/code]
NaN - Not a Nerd
Working on: Physical Memory Management with a 5-lod mipmap XD
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

How about using the latest version...
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
AndrewAPrice
Member
Member
Posts: 2309
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Post by AndrewAPrice »

I wish time actually went fast in Bochs rather than just the clock. In Bochs my memory manager takes around 3 seconds to initialise (it sets up page tables and bitmaps), but happens seemingly instantly on every other emulator and on real systems.
My OS is Perception.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

You'll have to tweak these numbers to get some performance:

Code: Select all

# 60 fps (ips / vga_update)
vga_update_interval: 100000
# 6 MHz processor
cpu: ips=6000000
# slow down the clock to match processor
clock: sync=slowdown, time0=local
iirc ips and update_interval are by default rather low - if you up ips alone it will not help as it will spend relatively more time redrawing the screen. Depending on what you want, you should compute the vga update to be somewhere between 1 fps and 100 fps.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
AndrewAPrice
Member
Member
Posts: 2309
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Post by AndrewAPrice »

Combuster wrote:

Code: Select all

# 6 MHz processor
cpu: ips=6000000
I can understand why now, thanks! I wonder who's design decision it was to make the processor default at 6 million instructions per second?
My OS is Perception.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

I wonder who's design decision it was to make the processor default at 6 million instructions per second?
Ahem, that was from MY config file :D - just a suggestion what you should be aware of...
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Post by bewing »

Combuster wrote:How about using the latest version...
Didn't somebody mention something about making a sticky thread for Bochs-related stuff, somewhere? I can't find it. I'm compiling the most recent version, and there are 11 compiler warnings that worry me some. (If you ignore the hundred warnings about signed/unsigned assignments.) The one that worries me the most is:

Code: Select all

	unsigned long op1_32, diff_32;
	diff_32 = -op1_32;
That is the actual code that the current ver of Bochs uses to calculate all NEG opcodes. Isn't using negation that way "undefined behavior" in C/C++? I personally have no idea how any of my compilers will respond to that code.

So, in general, my question is: I have seen a few people mention recently running into Bochs bugs. Are they in the current version (2.3.5)?
I know that 2.0.2 had several deadly ones.
User avatar
inflater
Member
Member
Posts: 1309
Joined: Thu Sep 28, 2006 10:32 am
Location: Slovakia
Contact:

Post by inflater »

@Combuster: So why this syntax...

Code: Select all

# 60 fps (ips / vga_update)
vga_update_interval: 1500000
# 90 MHz processor
cpu: ips=90000000
# slow down the clock to match processor
clock: sync=slowdown, time0=local
makes the update interval too slow? I tried also "sync=realtime" but it the same as "slowdown".
The CPU in PortixOS is detected now as 90 MHz, but a real Pentium I hadn't response time >1200 ms... :lol:
My web site: http://inflater.wz.cz (Slovak)
Derrick operating system: http://derrick.xf.cz (Slovak and English :P)
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

inflater wrote:@Combuster: So why this syntax...

Code: Select all

# 60 fps (ips / vga_update)
vga_update_interval: 1500000
# 90 MHz processor
cpu: ips=90000000
# slow down the clock to match processor
clock: sync=slowdown, time0=local
makes the update interval too slow? I tried also "sync=realtime" but it the same as "slowdown".
The CPU in PortixOS is detected now as 90 MHz, but a real Pentium I hadn't response time >1200 ms... :lol:
Three things:
- The host processor must be well in the GHz to actually be able to emulate a ~100MHz processor
- The pentium is pipelined and can do 2 instructions per clock
- You still have the overhead of 60 redraws / sec which take significant time. If you have tried the likes of DOSBox which has a similar ips/fps configuration you might have noticed that you can get up to 30% more performance by lowering the number of frames that are actually drawn. Try increasing the VGA update interval to lower the FPS.

If you're still unsatisfied, get a virtual machine instead of an emulator.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
mystran
Member
Member
Posts: 670
Joined: Thu Mar 08, 2007 11:08 am

Post by mystran »

Just reprogram the PIT and it'll work. It's just the default setting that's off.
The real problem with goto is not with the control transfer, but with environments. Properly tail-recursive closures get both right.
Post Reply