From owner-freebsd-threads@FreeBSD.ORG Mon Jun 16 19:23:51 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 E9D8A37B401 for ; Mon, 16 Jun 2003 19:23:51 -0700 (PDT) Received: from hqemgate00.nvidia.com (hqemgate00.nvidia.com [216.228.112.144]) by mx1.FreeBSD.org (Postfix) with ESMTP id 208B743FD7 for ; Mon, 16 Jun 2003 19:23:51 -0700 (PDT) (envelope-from gareth@nvidia.com) Received: from mail-sc-0.nvidia.com (Not Verified[172.16.217.105]) id ; Mon, 16 Jun 2003 19:26:37 -0700 Received: by mail-sc-0.nvidia.com with Internet Mail Service (5.5.2653.19) id ; Mon, 16 Jun 2003 19:23:17 -0700 Message-ID: <2D32959E172B8F4D9B02F68266BE421401A6D7EA@mail-sc-3.nvidia.com> From: Gareth Hughes To: 'Alexander Kabaev' Date: Mon, 16 Jun 2003 19:23:15 -0700 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: text/plain cc: threads@freebsd.org cc: zander@mail.minion.de cc: 'Julian Elischer' cc: Andy Ritger cc: Daniel Eischen Subject: RE: NVIDIA and TLS 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 02:23:52 -0000 On Mon, 16 Jun 2003 Alexander Kabaev wrote: > > You do not understand. Whether or not it is better only time will tell. > ELF TLS standard is defined in a way, that only a _specific_ threads > implementation can reap full benefits, most other are penalized by the > segment access reloads on every thread context switch. > > [snip] > > So the choice is either to pay penalty implementing TLS through callable > entry, or by making context switches more expensive than they have to > be. > > I am obviously not thrilled with the standard, but I guess I'll have > live with it since I have nothing better to offer on my own anyway. To save you the trouble, I'll copy the relevant information out of Drepper's document (sections 3.4.2, 4.1.2, 4.2.2). C code: extern __thread int x; &x; Assembly code, General Dynamic access model: leal x@tlsgd(%ebx),%eax call __tls_get_addr@plt C code: static __thread int x1; static __thread int x2; &x1; &x2; Assembly code, Local Dynamic access model: leal x1@tlsldm(%ebx),%eax call __tls_get_addr@plt ... leal x1@dtpoff(%eax),%edx ... leal x2@dtpoff(%eax),%edx I don't see any segment register use there, do you? That's the implementation of the dynamic TLS access models on x86 (specifically, the GNU variants, not the Sun variants). You implement __tls_get_addr() however you need to. Only the static access models require the use of %gs. If you don't want to use %gs, then go right ahead and only implement the dynamic access models. __thread variable access will be slower on FreeBSD in some cases (those that could potentially use the static access models), but you're free to implement whatever kind of thread library you want, including one that does not touch nor use the %gs segment register. -- Gareth Hughes (gareth@nvidia.com) OpenGL Developer, NVIDIA Corporation