Qemu is being a B****

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
piranha
Member
Member
Posts: 1391
Joined: Thu Dec 21, 2006 7:42 pm
Location: Unknown. Momentum is pretty certain, however.
Contact:

Qemu is being a B****

Post by piranha »

I have been using Qemu to test my OS, and have found some issues with it.

Firstly, sometimes I will build my OS (using my automated script) and it'll be fine, and Qemu will start, but only the kernel will load, and then it reaches a certain point and it will freeze. There is nothing in the code to do that. But then I will close Qemu and make no changes to the code, rebuild and run Qemu again and it will work fine. Whats that about? It's annoying as hell.

Second, when I have my OS running, and I switch focus from Qemu back to Qemu, my kernel will randomly crash. But if I keep focus, there are no problems. How can I fix this?

_JL_
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
User avatar
suthers
Member
Member
Posts: 672
Joined: Tue Feb 20, 2007 3:00 pm
Location: London UK
Contact:

Re: Qemu is being a B****

Post by suthers »

I sometimes make rebuild and run my code from the same code and get different results with bochs to....
Jules
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:

Re: Qemu is being a B****

Post by Combuster »

"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 ]
Korona
Member
Member
Posts: 1000
Joined: Thu May 17, 2007 1:27 pm
Contact:

Re: Qemu is being a B****

Post by Korona »

Yes, that problem is probably caused by race conditions. I also experienced race conditions while testing in qemu that did not show up in bochs or vmware. Qemus (as well as virtualbox') timing seems to be less deterministic than bochs' and vmware's timing. At least that is a good way to get rid of race conditions that are hard to find. (It's better than running the os many times on real pc while wondering why it crashes sometimes :D)
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].
User avatar
Stevo14
Member
Member
Posts: 179
Joined: Fri Mar 07, 2008 3:40 am
Location: Arad, Romania

Re: Qemu is being a B****

Post by Stevo14 »

@piranha:
It just so happens that I checked out your source tree and built your kernel earlier today (I like to do this kind of thing when I'm bored...). If it helps any, I saw the same thing happen here. I guess that means that the problem is not computer-specific or emulator-specific. Probably a race condition like the Combuster and Korona said. I seem to remember experiencing this with my kernel when I was still using a lot of the code from JamesM's tutorials. After I re-wrote several parts myself (specifically the memory manager) and the problem went away.
User avatar
piranha
Member
Member
Posts: 1391
Joined: Thu Dec 21, 2006 7:42 pm
Location: Unknown. Momentum is pretty certain, however.
Contact:

Re: Qemu is being a B****

Post by piranha »

Are there any common things that cause this?
Anyway to fix it?

-JL
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
Korona
Member
Member
Posts: 1000
Joined: Thu May 17, 2007 1:27 pm
Contact:

Re: Qemu is being a B****

Post by Korona »

Race condition usually occur when two threads try to access and manipulate one shared resource without proper synchronization. They can be caused by many reasons; the "easiest" way to get rid of them is to protect all structures with spinlocks or semaphores (or with cli -> manipulate -> sti on single processor machines). Pay attention to the order of the lock / unlock operations or your application will suffer from deadlocks.
Last edited by Korona on Wed Jun 25, 2008 3:20 am, edited 1 time in total.
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].
User avatar
suthers
Member
Member
Posts: 672
Joined: Tue Feb 20, 2007 3:00 pm
Location: London UK
Contact:

Re: Qemu is being a B****

Post by suthers »

I'm far from having multithreading and at the time when I had this problem, I didn't even have a PIT controller yet... (I was having problems with my IDT).
Weird...
Jules
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:

Re: Qemu is being a B****

Post by Combuster »

Last time I had a race was when IRQ0 fired when I couldn't use it, so you don't really need two tasks to get one.
The PIT is usually still running if you haven't touched it...

But finding the cause of them is usually pretty tricky.
"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 ]
Post Reply