From owner-freebsd-amd64@FreeBSD.ORG Sun Jul 7 16:48:08 2013 Return-Path: Delivered-To: freebsd-amd64@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id D97912BE; Sun, 7 Jul 2013 16:48:08 +0000 (UTC) (envelope-from julian@freebsd.org) Received: from vps1.elischer.org (vps1.elischer.org [204.109.63.16]) by mx1.freebsd.org (Postfix) with ESMTP id B0DBE1B86; Sun, 7 Jul 2013 16:48:08 +0000 (UTC) Received: from jre-mbp.elischer.org (ppp121-45-226-51.lns20.per1.internode.on.net [121.45.226.51]) (authenticated bits=0) by vps1.elischer.org (8.14.5/8.14.5) with ESMTP id r67GlvQ8002275 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Sun, 7 Jul 2013 09:48:01 -0700 (PDT) (envelope-from julian@freebsd.org) Message-ID: <51D99BB7.1020101@freebsd.org> Date: Mon, 08 Jul 2013 00:47:51 +0800 From: Julian Elischer User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130620 Thunderbird/17.0.7 MIME-Version: 1.0 To: Davide Italiano Subject: Re: Accessing struct pthread from kernel References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Mailman-Approved-At: Sun, 07 Jul 2013 23:19:05 +0000 Cc: freebsd-amd64@freebsd.org, freebsd-threads@freebsd.org X-BeenThere: freebsd-amd64@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Porting FreeBSD to the AMD64 platform List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 07 Jul 2013 16:48:08 -0000 On 7/6/13 7:22 AM, Davide Italiano wrote: > Hi, > as a preliminary step in the implementation of adaptive spinning for > umtx, I'm switching the pthread/umtx code so that a thread that > acquires a pthread_mutex writes the address of struct pthread in the > owner field of the lock instead of the thread id (tid). This is > because having struct pthread pointer allows easily to access > informations of the thread, and makes easy to get the state of the > thread exported from the kernel (once this will be implemented). > > For what concerns the libthr side, the internal function > _get_curthread() goes into the TLS to obtain the struct field of > curthread, so I'm done. > OTOH, I'm quite unsure instead about how to get address of struct > pthread for curthread from the kernel side (for example, in > do_lock_umutex() sys/kern/kern_umtx.c). > > I guess I need to write some MD code because the TLS is different on > the various architecture supported in FreeBSD, and as a first step I > focused on amd64. > It looks like from the SDM that %%fs register points to the base of > the TLS, so I think that accessing using curthread->td_pcb->pcb_fsbase > (and then adding the proper offset to acces the right field) is a > viable solution to do this. Am I correct? > In particular what worries me is if the read of 'struct pthread' for > curthread from the TLS register is atomic with respect to preemptions. > > Alternatively, is there an (easier way) to accomplish this task? there is a struct pthread for each tid (and visa versa) you could notify the kernel of it when you make a new thread. (new arg/call) for what it's worth the M:N threading system used to do something like this, with a user callback straucture supplied to the kernel.. > > Thanks, >