Page 1 of 1
Per Processor Data
Posted: Sat Mar 24, 2007 8:25 am
by sid.koolwizard
Hello Everyone...
This is my first post...
I m working on os project from few weeks..
my scheduler on single processor is working fine...
but dont know how to implement per processor data...
for e.q. to store thread que for each processor...
how do sheduler know from which processor it is running and how to access data for dat processor...
please help me..
Posted: Sat Mar 24, 2007 8:33 am
by earlz
U must use TSS(if using 386+)
Posted: Sat Mar 24, 2007 9:17 am
by sid.koolwizard
I am using TSS but only single TSS for all the process...
but how know from which processor code is executing by TSS..
i mean in multi processor systems...
i want to implement SMP
Posted: Sat Mar 24, 2007 1:36 pm
by bluecode
There is the
Multiprocessor Specification, which will tell you how to startup the other processors. You can identify the processors by their APIC Id, which is unique for every cpu. But remember that you need some spinlocks/mutex/semaphore code...
Re: Per Processor Data
Posted: Sun Mar 25, 2007 12:11 am
by Brendan
Hi,
sid.koolwizard wrote:I m working on os project from few weeks..
my scheduler on single processor is working fine...
but dont know how to implement per processor data...
for e.q. to store thread que for each processor...
how do sheduler know from which processor it is running and how to access data for dat processor...
I use an array of "CPU data structures" where the CPUs local APIC ID is an index into this array. Local APIC ID's are 8-bit, fast to find and guaranteed to be unique.
For this you'd need a 256 entry array (but with paging and large "CPU data structures" you don't need to map RAM to entries for CPUs that aren't present).
I also setup FS base differently on each CPU so that ir points to the CPU's entry in the array. This means that most of the time (unless you're looking at one CPUs data from another CPU) you can just use a segment override instead of finding the address of the entry in the array.
For TSSs, it's easy enough to put each CPUs TSS data into it's "CPU data structure", along with scheduler queues, CPU identification, locality information, etc.
Cheers,
Brendan
Posted: Sun Mar 25, 2007 10:04 pm
by mystran
sid.koolwizard wrote:I am using TSS but only single TSS for all the process...
but how know from which processor code is executing by TSS..
i mean in multi processor systems...
i want to implement SMP
You need at least one TSS per processor, no matter what you do, because you need to have different ESP0 values in the TSS for each processor, so that if different processors get interrupts/exceptions from userspace at the same time, they don't try to use the same stack at the same time.
Since interrupts/exceptions will push flags, cs, eip, and possibly errorcode (depending on exception) before you have chance to figure out what processor you are on, there's nothing you can do but have then use different stacks, mandating the use of separate TSSes for each processor.
Ofcourse one straight-forward implementation is to keep the kernel-stack of currently executing thread in relevant processors ESP0, then switching threads by swapping kernel-stacks, but whether or not you use this scheme, you can't avoid having separate TSS for each processor.