modify GDT in MP-System at runtime

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
WeirdCat
Posts: 11
Joined: Thu Feb 05, 2009 5:13 am
Location: Berlin, Germany

modify GDT in MP-System at runtime

Post by WeirdCat »

How do you best add entries to the GDT (for TSSs and LDTs) on a multi processor system at runtime and propagate them to all CPUs?

At the moment the limit of my GDT is as small as possible, but if I wanted to add additional entries at runtime I had to increase the limit and propagate the new value to all CPUs. To spare me the process of propagating changes I'm planning to just set the GDT limit to 0xFFFF and fill all unused entries with zeroes. To prevent the loading of invalid entries I'm planning to use a locked CMPXCHG8B to modify GDT entries. Is this wise, or do I could get in trouble with this later on?

TIA,
Ash
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Re: modify GDT in MP-System at runtime

Post by AJ »

Hi,

Before you even load the GDT on the AP's, you have presumambly detected (and therefore know the number of) processors. Why not simply create a GDT after AP detection, when you know the exact number of entries you need?

Cheers,
Adam
WeirdCat
Posts: 11
Joined: Thu Feb 05, 2009 5:13 am
Location: Berlin, Germany

Re: modify GDT in MP-System at runtime

Post by WeirdCat »

AJ wrote:Before you even load the GDT on the AP's, you have presumambly detected (and therefore know the number of) processors. Why not simply create a GDT after AP detection, when you know the exact number of entries you need?
This would be a viable solution if I only create one TSS/CPU, but I think I will give each Task it's own TSS and since they should be spawnable at runtime I need a way to modify the GDT at runtime.

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

Re: modify GDT in MP-System at runtime

Post by Brendan »

Hi,
Ash wrote:This would be a viable solution if I only create one TSS/CPU, but I think I will give each Task it's own TSS and since they should be spawnable at runtime I need a way to modify the GDT at runtime.
In this case, you need 2 TSS descriptors in the GDT for each CPU (where you change the TSS descriptor just before doing the task switch to avoid the "maximum of 8190 tasks" limit), but each pair of TSS descriptors are only used by one CPU (no locks needed) and could be allocated/setup during boot (unless you want to support hot-plug CPUs).


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.
WeirdCat
Posts: 11
Joined: Thu Feb 05, 2009 5:13 am
Location: Berlin, Germany

Re: modify GDT in MP-System at runtime

Post by WeirdCat »

Brendan wrote:In this case, you need 2 TSS descriptors in the GDT for each CPU (where you change the TSS descriptor just before doing the task switch to avoid the "maximum of 8190 tasks" limit), but each pair of TSS descriptors are only used by one CPU (no locks needed) and could be allocated/setup during boot (unless you want to support hot-plug CPUs).
Isn't there a CPU internal cache for segment descriptors that you sidestep when you constantly overwrite a TSS descriptor? I'm not sure how relevant this in reality is, but on the other hand a 4k tasks limit ((1xTSS+1xLDT)/Task) doesn't seem to hard to me. My Vista runs < 100 processes with < 1000 threads at the moment. ;-)
Post Reply