Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 6 Jul 2013 01:22:05 +0200
From:      Davide Italiano <davide@freebsd.org>
To:        freebsd-amd64@freebsd.org, freebsd-threads@freebsd.org
Subject:   Accessing struct pthread from kernel
Message-ID:  <CACYV=-H_T98QPWOLS=0iHxgt1Om-sR3p8ogqFCsZHFiZDLtosg@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
Hi,
as a preliminary step in the implementation of adaptive spinning for
umtx, I'm switching the pthread/umtx code so that a thread that
acquires a pthread_mutex writes the address of struct pthread in the
owner field of the lock instead of the thread id (tid). This is
because having struct pthread pointer allows easily to access
informations of the thread, and makes easy to get the state of the
thread exported from the kernel (once this will be implemented).

For what concerns the libthr side, the internal function
_get_curthread() goes into the TLS to obtain the struct field of
curthread, so I'm done.
OTOH, I'm quite unsure instead about how to get address of struct
pthread for curthread from the kernel side (for example, in
do_lock_umutex() sys/kern/kern_umtx.c).

I guess I need to write some MD code because the TLS is different on
the various architecture supported in FreeBSD, and as a first step I
focused on amd64.
It looks like from the SDM that %%fs register points to the base of
the TLS, so I think that accessing using curthread->td_pcb->pcb_fsbase
(and then adding the proper offset to acces the right field) is a
viable solution to do this. Am I correct?
In particular what worries me is if the read of 'struct pthread' for
curthread from the TLS register is atomic with respect to preemptions.

Alternatively, is there an (easier way) to accomplish this task?

Thanks,

-- 
Davide

"There are no solved problems; there are only problems that are more
or less solved" -- Henri Poincare



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CACYV=-H_T98QPWOLS=0iHxgt1Om-sR3p8ogqFCsZHFiZDLtosg>