Date: Tue, 5 Aug 2003 17:15:17 -0700 (PDT) From: Julian Elischer <julian@elischer.org> To: Mike Makonnen <mtm@identd.net> Cc: Marcel Moolenaar <marcel@xcllnt.net> Subject: Re: cvs commit: src/sys/i386/i386 sys_machdep.c Message-ID: <Pine.BSF.4.21.0308051651070.82100-100000@InterJet.elischer.org> In-Reply-To: <20030805231633.GA24684@kokeb.ambesa.net>
next in thread | previous in thread | raw e-mail | index | archive | help
check the change Dan just checked in... FreeBSD src repository Modified files: lib/libpthread/arch/i386/i386 pthread_md.c Log: Use auto LDT allocation for i386. Revision Changes Path 1.2 +6 -63 src/lib/libpthread/arch/i386/i386/pthread_md.c I have been thinking about this.. I assume you have some cached threads around, so you'd not be calling this every time there is a new thread.. For KSE we only do this for a new KSE which is a less frequent operation. On Tue, 5 Aug 2003, Mike Makonnen wrote: > 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). The value returned is the slot number so you need to << by 3 and set the Local bit for a legit value for %gs It is the same value that was returned before except that the kernel choses it for you if you specify a location of LDT_AUTO_ALLOC instead of a legal slot number. (i.e. Do whatever you are doing now with the return value before you put it into %gs.) > > 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@identd.net | D228 1A6F C64E 120A A1C9 A3AA DAE1 E2AF DBCC 68B9 > mtm@FreeBSD.Org| FreeBSD - Unleash the Daemon! > _______________________________________________ > freebsd-threads@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-threads > To unsubscribe, send any mail to "freebsd-threads-unsubscribe@freebsd.org" >
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0308051651070.82100-100000>