From owner-freebsd-threads@FreeBSD.ORG Tue Aug 5 16:16:40 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 7A37737B401 for ; Tue, 5 Aug 2003 16:16:40 -0700 (PDT) Received: from pool-151-200-10-97.res.east.verizon.net (pool-138-88-38-229.res.east.verizon.net [138.88.38.229]) by mx1.FreeBSD.org (Postfix) with ESMTP id C0BD743FA3 for ; Tue, 5 Aug 2003 16:16:38 -0700 (PDT) (envelope-from mtm@identd.net) Received: from kokeb.ambesa.net (vq3ew69v45uqt1ja@localhost [127.0.0.1]) id h75NGb1h025102; Tue, 5 Aug 2003 19:16:37 -0400 (EDT) (envelope-from mtm@identd.net) Received: (from mtm@localhost) by kokeb.ambesa.net (8.12.9/8.12.9/Submit) id h75NGYjK025101; Tue, 5 Aug 2003 19:16:34 -0400 (EDT) (envelope-from mtm@identd.net) X-Authentication-Warning: kokeb.ambesa.net: mtm set sender to mtm@identd.net using -f Date: Tue, 5 Aug 2003 19:16:34 -0400 From: Mike Makonnen To: Marcel Moolenaar Message-ID: <20030805231633.GA24684@kokeb.ambesa.net> References: <002e01c358ce$6df2ecd0$0701a8c0@tiger> <20030802195243.GA3396@kokeb.ambesa.net> <20030802210339.GB25026@dhcp01.pn.xcllnt.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030802210339.GB25026@dhcp01.pn.xcllnt.net> User-Agent: Mutt/1.4.1i X-Operating-System: FreeBSD/5.1-CURRENT (i386) cc: freebsd-threads@FreeBSD.Org 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: Tue, 05 Aug 2003 23:16:40 -0000 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@identd.net | D228 1A6F C64E 120A A1C9 A3AA DAE1 E2AF DBCC 68B9 mtm@FreeBSD.Org| FreeBSD - Unleash the Daemon!