From owner-freebsd-threads@FreeBSD.ORG Tue Aug 5 17:15:24 2003 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 48F9737B401 for ; Tue, 5 Aug 2003 17:15:24 -0700 (PDT) Received: from rwcrmhc12.comcast.net (rwcrmhc12.comcast.net [216.148.227.85]) by mx1.FreeBSD.org (Postfix) with ESMTP id B84EB43F85 for ; Tue, 5 Aug 2003 17:15:23 -0700 (PDT) (envelope-from julian@elischer.org) Received: from interjet.elischer.org ([12.233.125.100]) by attbi.com (rwcrmhc12) with ESMTP id <20030806001523014007ojm4e>; Wed, 6 Aug 2003 00:15:23 +0000 Received: from localhost (localhost.elischer.org [127.0.0.1]) by InterJet.elischer.org (8.9.1a/8.9.1) with ESMTP id RAA95621; Tue, 5 Aug 2003 17:15:18 -0700 (PDT) Date: Tue, 5 Aug 2003 17:15:17 -0700 (PDT) From: Julian Elischer To: Mike Makonnen In-Reply-To: <20030805231633.GA24684@kokeb.ambesa.net> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII cc: freebsd-threads@FreeBSD.Org cc: Marcel Moolenaar Subject: Re: cvs commit: src/sys/i386/i386 sys_machdep.c X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 06 Aug 2003 00:15:24 -0000 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" >