From owner-freebsd-threads@FreeBSD.ORG Wed Jun 21 10:12:24 2006 Return-Path: X-Original-To: freebsd-threads@freebsd.org Delivered-To: freebsd-threads@freebsd.org Received: from [127.0.0.1] (localhost [127.0.0.1]) by hub.freebsd.org (Postfix) with ESMTP id 5208516A479; Wed, 21 Jun 2006 10:12:22 +0000 (UTC) (envelope-from davidxu@freebsd.org) Message-ID: <44991B87.1020104@freebsd.org> Date: Wed, 21 Jun 2006 18:12:23 +0800 From: David Xu User-Agent: Mozilla/5.0 (X11; U; FreeBSD i386; en-US; rv:1.7.12) Gecko/20060519 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Divacky Roman References: <20060620120948.GA8288@stud.fit.vutbr.cz> <200606210658.24741.davidxu@freebsd.org> <20060621080916.GA81422@stud.fit.vutbr.cz> In-Reply-To: <20060621080916.GA81422@stud.fit.vutbr.cz> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Cc: threads@freebsd.org, hackers@freebsd.org, freebsd-threads@freebsd.org Subject: Re: TLS - implementing linux one in fbsd X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Jun 2006 10:12:24 -0000 Divacky Roman wrote: >>The M:N and 1:1 threading in FreeBSD use different mechanisms to >>implement TLS, M:N implements it in userland, while 1:1 implements it in >>kernel. the thr_new or thr_create are used for 1:1 threading, right >>now libthr uses thr_new to atomically setup a thread, this includes, >>storing TID, setting TLS, and maybe signal mask( not implemented ) , >>cpu affinity mask etcs(not implemented), scheduling scope, in one word, >>it is intended to map most part of pthread_attr into kernel world. > > > but on the kernel level the implementation must be the same.. I mean the > mangling of %gs. right? > > There is no such standard that a kernel must implement it in that way, we happens to implement it in kernel with GDT, before this, thread libraries were using LDT. The offical TLS standard only defined ABI in userspace: http://people.redhat.com/drepper/tls.pdf M:N thread library only set GDT entry once, for Variant II TLS (x86), the userland scheduler just replaces some pointers in TCB, it does not have to set TLS via syscall later. but 1:1 thread library will just let kernel context switch code to update it for next thread. > > well.. in linux the thread creation and setting up the tls is done using > separate syscalls. I plan to extend clone() syscall to use thr_create() or > thr_new() (if the flags tell me its thread) but I am afraid I'l have to modify > those syscalls to not to setup TLS (some flag) because linux wants to set it > separately. > You can try, but the thr_xx syscalls were not designed to implement linux clone() syscall, they are only used by libthr to implement 1:1 threading. >>I think it is used for futex, and the childtid is use to implement >>pthread_join and garbage collection in thread library, the parent tid >>pointer (if I recall correctly) is used by parent thread to retrieve >>child tid. > > > this is the next step... I think all the magic is done in their libc (or > somewhere) and I basically just need to malloc some space for this info > and clear/set it on proces creation/exit > > we don't save childtid pointer and clear it at thread exiting time like Linux did, we use thr_exit() which passes a pointer to let kernel write a value into the address, this lets libthr's garbage collection code work. the thr syscalls may be extented to save childtid pointer somewhere in kernel by adding another flag, and clear it to zero when thread is exiting like Linux did. > the cpu_set_user_tls() is then what I need I think... maybe some modifications > needed but it shuold be basiscally the thing. > > the linux syscall set_thread_area() just loads GDT with that info.. thats the > same like ours cpu_set_use_tls(), right? > Right. > thnx for your information! > > roman