Subject: TLS
To: None <port-i386@netbsd.org>
From: Emmanuel Dreyfus <manu@netbsd.org>
List: port-i386
Date: 07/20/2006 22:17:40
Hi

We need TLS (Thread Local Storage) for Linux emulation. As I understood,
this feature may also be of some interest as a native one.

Here is how it works (as far as I understood. I must confess I'm a x86
illetrate).

A single GDT slot is used by all threads that use TLS. The thread access
its TLS using the GS segment pointer. The kernel is responsible for
switching the GDT slot on thread context switch, so that each thread
find the right values in the GDT to get access to its TLS. The GDT info
for each thread is stored in the PCB.

Below is a patch containing my first attempt at implementing the thing.
For now it just crash on kernel boot:

isapnp0: no ISA Plug 'n Play devices found
timecounter: Timecounter "clockinterrupt" frequency 100 Hz quality 0
uvm_fault(0xc0914600, 0, 2) -> 0xe
kernel: supervisor trap page fault, code=0
Stopped in pid 0.1 (swapper) at 0xc0894a04:     addb    %al,0(%eax)
db> bt
cpu_info_primary(c0914c20,0,c03dbf14,c0914c20,3f2) at 0xc0894a04
ltsleep(c530f300,20,c07fcef3,19,0) at netbsd:ltsleep+0x33f
fdprobe(c530f300,c087c050,c09fcbe0,0,c07ceb56) at netbsd:fdprobe+0xdc
config_match(c530f300,c087c050,c09fcbe0,0,c087c050) at
netbsd:config_match+0x28
mapply(c09fcb20,c087c050,10,10,0) at netbsd:mapply+0x41
config_search_loc(0,c530f300,0,0,c09fcbe0) at
netbsd:config_search_loc+0xba
config_found_sm_loc(c530f300,0,0,c09fcbe0,c058f4d8) at
netbsd:config_found_sm_lo
c+0x26
config_found(c530f300,c09fcbe0,c058f4d8,0,0) at netbsd:config_found+0x1a

No idea what happens. Input is welcome.

http://ftp.espci.fr/shadow/manu/tls.diff

NB: Linux uses three TLS per process. I made an implementation that
mimics the thing. 

-- 
Emmanuel Dreyfus
http://hcpnet.free.fr/pubz
manu@netbsd.org