Re: TLS - implementing linux one in fbsd



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


_______________________________________________
freebsd-hackers@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@xxxxxxxxxxx"



Relevant Pages

  • Re: User-mode Linux (Was: modify syscall nr on-the-fly)
    ... User-mode Linux in it's start-up tests tries to modify syscall number (to be ... catches SIGTRAP it tries to modify EAX of child thread ... as well as copies the syscall arguments into the kernel address space. ...
    (freebsd-hackers)
  • Re: [9fans] why not Lvx for Plan 9?
    ... Here are 2 versions of linux libc tls and notls. ... global descriptor table in the kernel. ...
    (comp.os.plan9)
  • Re: TLS - implementing linux one in fbsd
    ... In kernel there's thr_newsyscall or thread_create ... I didnt find the connection between threading library and kernel ... storing TID, setting TLS, and maybe signal mask, ... I dont know how FreeBSD ...
    (freebsd-hackers)
  • Re: Assignment of GDT entries
    ... aware of segments, for a rather perverse reason: the TLS stuff. ... Or is it only used in kernel code? ... and obviously we'd like to keep them in the same cacheline too. ...
    (Linux-Kernel)
  • Re: modify syscall nr on-the-fly
    ... User-mode Linux in it's start-up tests tries to modify syscall number (to be ... catches SIGTRAP it tries to modify EAX of child thread ... as well as copies the syscall arguments into the kernel address space. ...
    (freebsd-hackers)