cvs commit: src/sys/i386/i386 sys_machdep.c

Mike Makonnen mtm at identd.net
Tue Aug 5 16:16:40 PDT 2003


On Sat, Aug 02, 2003 at 02:03:39PM -0700, Marcel Moolenaar wrote:
> On Sat, Aug 02, 2003 at 03:52:44PM -0400, Mike Makonnen wrote:
> > 
> > As I indicated to Julian, I don't have time to do this now. I will
> > be going off-line in a couple of weeks for I don't know how long.
> > In the mean time I have a bunch of other stuff I have to get to.
> > But, if someone else wants to do it I can tell you exactly
> > what you need to do. It's relatively simple.
> 
> Can you post the description to threads@?
> I'll see if I can find a spare moment...

When I went back over the code, to write this summary
I found it is going to be much easier than I thought
at first. Assuming, i386_set_ldt() returns the auto-allocated
LDT slot we just have to load that into %gs, instead of
the ldt_index (which points into the ldt_entries array).

So, if someone can tell me what the magic number for
auto-allocation is I can take care of this tonight. But,
because I'll be offline soon I'll go ahead and post
the background on how that code works just in case someone
needs to mess with it.

The pointers to pthread structures are kept in the array
ldt_entries[MAX_THR]. Currently, MAX_THR is set to 128, but
since we start at index NLDT the maximum number of simultaneous
threads in an application is MAX_THR - NLDT. The global variable
ldt_free is used to keep track of the next free index in the
array. To facilitate this, when libthr is first initialized
each entry in the array contains a pointer to the next free
index. The ldt_free variable is then set to point to the first
free entry in the array (ldt_entries[NLDT]) and the contents
of that index (as preveiously stated) will be a pointer to
the next free entry in the array (in this case
ldt_entries[NLDT + 1]). When a new pthread is created, ldt_free
is dereferenced to find the next empty entry. It is set to this
entry and the contents of the previous entry it pointed to
are overwritten with the address of the newly created pthread.
When a thread exits the array index it occupied is overwritten
by a pointer to ldt_free and ldt_free is pointed to the
array index that held the just freed pthread.

Another thing that happens when a new pthread is created is that
we setup a segment descriptor structure which points into the
ldt_entries entry we just setup for our newly created pthread.
This segment descripter pointing into ldt_entries is what is
passed into i386_set_ldt(). If the call to i386_set_ldt() succeeds
we then load the LDT index into %gs.

So, there should be no need to bump up any limits or anything
to accomodate this change.

Cheers.
-- 
Mike Makonnen  | GPG-KEY: http://www.identd.net/~mtm/mtm.asc
mtm at identd.net | D228 1A6F C64E 120A A1C9  A3AA DAE1 E2AF DBCC 68B9
mtm at FreeBSD.Org| FreeBSD - Unleash the Daemon!


More information about the freebsd-threads mailing list