From owner-freebsd-threads@FreeBSD.ORG Tue Jun 17 06:41:14 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 5D49A37B401 for ; Tue, 17 Jun 2003 06:41:14 -0700 (PDT) Received: from park.rambler.ru (park.rambler.ru [81.19.64.101]) by mx1.FreeBSD.org (Postfix) with ESMTP id D081743FA3 for ; Tue, 17 Jun 2003 06:41:12 -0700 (PDT) (envelope-from is@rambler-co.ru) Received: from is.park.rambler.ru (is.park.rambler.ru [81.19.64.102]) by park.rambler.ru (8.12.6/8.12.6) with ESMTP id h5HDfBmF051534 for ; Tue, 17 Jun 2003 17:41:11 +0400 (MSD) Date: Tue, 17 Jun 2003 17:41:11 +0400 (MSD) From: Igor Sysoev X-Sender: is@is To: threads@freebsd.org In-Reply-To: <20030617071810.GA2451@dhcp01.pn.xcllnt.net> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Subject: Re: Nvidia, TLS and __thread keyword -- an observation 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, 17 Jun 2003 13:41:14 -0000 On Tue, 17 Jun 2003, Marcel Moolenaar wrote: > There's a definite advantage to supporting the __thread keyword in > userland and we should add the support. It really isn't that hard, > but it requires some thought and testing. In most cases you simply > point your thread pointer between the control structure and the > thread local segments. If the thread implementation uses gs register to point to thread specific data: gs -> [ thread specific data ] [ tls_array ] then this C code __thread int a; a = 1; can be translated to mov tls_key, %ecx mov $gs:tls_array, %eax mov (%eax,%ecx,4), %eax mov $1, (%eax) In FreeBSD we use gs to point to KSE specific data gs -> [ KSE specific data ] [ current thread ] -> [ thread specfic data ] [ tls_array ] and then same C code can be translate to mov tls_key, %ecx mov $gs:current_thread, %eax mov tls_array(%eax), %eax mov (%eax,%ecx,4), %eax mov $1, (%eax) And I think we should use this scheme not only in libkse but in libthr too to be binary compatible. Igor Sysoev http://sysoev.ru/en/