SMP Parallel problem

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.
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: SMP Parallel problem

Post by gerryg400 »

...and i have 8 cores emulated
Oh. I thought you were running on bare metal ! Which emulator are you using ?

If I were trying to debug this problem I would disassemble the executable and examine it. Can you post the disassembled executable ?
If a trainstation is where trains stop, what is a workstation ?
User avatar
lemonyii
Member
Member
Posts: 153
Joined: Thu Mar 25, 2010 11:28 pm
Location: China

Re: SMP Parallel problem

Post by lemonyii »

congratulations gerryg400! YOU hit the boom!
the solution is so simple:

Code: Select all

....
		kbd_init();
		wait = false;
	} else {
		vga_prt( "A" );
		//cpu_init();
		while( wait );
	}
	vga_prt( "B" );
	//sched();
	while(1);	
}
Nothing different right? And i even turned on -O2!
the key problem is, vga_prt is with no lock! the reason is, when the wait is set false by bsp, all aps go to print at a same time to print "B", (but "A" is printed seperately, because bsp release them seperately, with an allocation between them. ), so we can see only one 'B'.
how i found it is just because i redefined page table in bootloader to map a larger space for kernel at the beginning, and i suddenly see 7 As and 3 Bs... so, you know...
gerryg400 wrote:Oh. I thought you were running on bare metal ! Which emulator are you using ?
i don't have a bare metal, u will know that if u are in china. chinese students even professors have little device for their research, not like u. china is not poor now, but its people is even poorer than before. i love my country more than u can feel, but i hate its political environment. u think China is People's Republic? i will tell u NO!
but i use bochs for multi-core, sometimes virtualbox, qemu just for single core because it's really slow for SMP.
If I were trying to debug this problem I would disassemble the executable and examine it. Can you post the disassembled executable ?
i disasm sometimes but not often, since i would combine printing things and bochsdbg. disasm is not a good way as your kernel grows. but combine symbol table and bochsdbg (breakpoint, disassemble little piece of code) would be better. i don't have better way.
keeping the whole kernel arch and its logic in your brain clearly, will help a lot i think.

thx
Enjoy my life!------A fish with a tattooed retina
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: SMP Parallel problem

Post by Brendan »

Hi,
lemonyii wrote:congratulations gerryg400! YOU hit the boom!
the solution is so simple:
Cool :)


Gerry400 already got one of my "at least 2 problems" (and found more that I didn't even notice!). The other one hasn't been mentioned yet (a race condition): The AP CPUs could call "vga_prt()" before the BSP has called "vga_init();". To fix that the AP CPUs should do the "wait(wait);" before they do "vga_prt( "C" );".


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.
Post Reply