multiprocessor testing

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
GLneo
Member
Member
Posts: 237
Joined: Wed Dec 20, 2006 7:56 pm

multiprocessor testing

Post by GLneo »

hello everybody... i am very confused about multiprocessing but i think i got it working, i have bochs and i set it to the "BIOS-bochs-8-processors" and i dont know how to test if my kernel is using more than 1 processor, anyone know of a way to find this out ???

thx!
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: multiprocessor testing

Post by Brendan »

Hi,
GLneo wrote:hello everybody... i am very confused about multiprocessing but i think i got it working, i have bochs and i set it to the "BIOS-bochs-8-processors" and i dont know how to test if my kernel is using more than 1 processor, anyone know of a way to find this out ???
If Bochs was compiled with debugging, you can do "control+c" and single step to watch what each CPUs is doing. Alternatively (with or without debugging), you can see the state of each CPU in "bochslog.txt" when you exit Bochs.

From the guest software, a CPU can change anything in memory to tell another CPU that it's there. When starting AP CPUs I tend to use something like "lock inc dword [CPUcount]" on each AP CPU with the BSP CPU waiting for "CPUcount" to increase.

You could also get each CPU to send one character to I/O port 0xE9 (if that's enabled), or even do something like:

Code: Select all

    mov esi,[localApicAddress]
    mov eax,[esi+LAPIC.APID_ID]
    shr eax,24
.stop:
    inc dword [0x000B8000+eax*4]
    jmp .stop
In this case each CPU repeatedly increments a different part of video display memory (because each CPU has a different local APIC ID).


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.
GLneo
Member
Member
Posts: 237
Joined: Wed Dec 20, 2006 7:56 pm

Post by GLneo »

hmmm.... bochs only lists cpu0, i think i'm more confused than I thought. how do i start more processors??? apic???

thx
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Post by Brendan »

Hi,
GLneo wrote:hmmm.... bochs only lists cpu0, i think i'm more confused than I thought.
If Bochs only lists one CPU, then Bochs isn't setup to emulate more than one CPU.

If Bochs lists several CPUs but some of them are still in the BIOS (either in CS = 0xF000 or CS = 0xFFFFF000), then your OS hasn't started the extra CPUs.
GLneo wrote:how do i start more processors??? apic???
To start the other CPUs properly, you need to detect the other CPUs (using tables from Intel's Multiprocessor specification, or using ACPI tables). Then you need to send an "INIT-SIPI-SIPI" sequence to each CPU the BIOS told you about. This sequence is meant to be a series of 3 interprocessor interrupts with special INIT or SIPI interrupt types (sent by using the local APIC of any already running CPU), but I've found that usually the last SIPI isn't necessary.

There's an example of the code to actually start a CPU (after they've been detected) in my source code. Please note this code doesn't support external local APICs (the 82489DX chips used with very early Pentium and 80486 systems) - they have a slightly different startup procedure and slightly different behaviour for some other things (I don't intend to support them). To make the time delays a little more accurate I also reprogram the PIT to 1 KHz, but "close enough" is generally good enough for this (my code works fine with the default 55 ms/18.2 Hz PIT 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.
Post Reply