Zbr's days.

About :: TODO :: Blog :: RSS :: Old blog :: Projects :: GIT :: Gallery :: Notes

Sun, 11 Feb 2007

Some thoughts about M:N threading nad NPTL.


While I was busy kicking various AIO designs I completely missed time to do real interesting low-level threading stuff. So, some thoughts.

Locking into glibc NPTL sources I noticed that x86 uses %gs register as so called thread-pointer register. To get current thread pointer glibc uses following code:

# define THREAD_SELF \
  ({ struct pthread *__self;						      \
       asm ("movl %%gs:%c1,%0" : "=r" (__self)				      \
   	  : "i" (offsetof (struct pthread, header.self)));		      \
       __self;})
%gs itself shows to the descriptor in GDT, but it is always 51, while GDT only holds 32 descriptors, %%cs for example contains 115 - one question (the last minute though - GDT entries are of 8 bytes each, so it is possible, that value stored in register should be divided to 8 to get actual entry... Will check out tomorrow.).
Another one - what does it mean "%%gs:%c1" - it will be transferred as "%%gs:immediate_parameter_1", i.e. "%%gs:some_num", for example "%%gs:0" works, but it does not work with usual register like %%eax, only %%gs. Similar access to %%cs, %%ds and other segment registers ends up with segmentation fault.

It looks like walking in the dark room with exact knowledge that there is at least one rake...
But I will find an exit soon.

/devel/threading :: Link / Comments ()