views:

334

answers:

2

( I ask because it was before serious SMP and multicore that I studied OS. I like to have some vision of how code is being executed. )

If I have a multicore x86 CPU booting directly into my program. Can someone recommend a website which describes what assembler commands do I have to control affinity?

+3  A: 

Affinity is not determined by the CPU state and can therefore not be modified by assembly (alone). You need participation of the OS. And each OS will have a specific call to do this.

What the OS will do: the OS will have a scheduler, which is in effect a program who determines which process runs when on what processor. With setting the affinity as a user, you configure this scheduler.

And if you wouldn't have a OS (which the question seems to imply I think), then you're writing the scheduler yourself and you will have own control of the configuration and you will probably start with a global runqueue and for each processor (core) watch this runqueue, and retrieve processes to run from it.

So how does this work then? During boot, only one CPU is running. If you as the OS are ready for it, you 'boot' the other CPUs which start executing your code, and which will probably run a kind of scheduler.

For an example implementation, see Linux 2.6.29 arch/x86/kernel/smpboot.c function do_boot_cpu(), which brings a CPU online in several ways using APIC.

Rutger Nijlunsing
A: 

Here's a pretty good explanation of how QNX does it. It doesn't go as far as supplying the required ASM (which would be platform dependant anyway) but it may help with the concepts:

http://www.embedded.com/columns/technicalinsights/183702309?_requestid=408789

and a range of articles from the same site

http://www.embedded.com/products/integratedcircuits/173400008?_requestid=409058

SpliFF