Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 21 Jun 2006 18:12:23 +0800
From:      David Xu <davidxu@freebsd.org>
To:        Divacky Roman <xdivac02@stud.fit.vutbr.cz>
Cc:        threads@freebsd.org, hackers@freebsd.org, freebsd-threads@freebsd.org
Subject:   Re: TLS - implementing linux one in fbsd
Message-ID:  <44991B87.1020104@freebsd.org>
In-Reply-To: <20060621080916.GA81422@stud.fit.vutbr.cz>
References:  <20060620120948.GA8288@stud.fit.vutbr.cz>	<200606210658.24741.davidxu@freebsd.org> <20060621080916.GA81422@stud.fit.vutbr.cz>

next in thread | previous in thread | raw e-mail | index | archive | help
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





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?44991B87.1020104>