Fast sigblock (AKA rtld speedup)

Konstantin Belousov kostikbel at gmail.com
Sat Jan 12 09:38:46 UTC 2013


On Sat, Jan 12, 2013 at 04:17:27AM -0500, Alfred Perlstein wrote:
> On 1/12/13 12:32 AM, Konstantin Belousov wrote:
> > On Sat, Jan 12, 2013 at 08:27:06AM +0800, David Xu wrote:
> >> On 2013/01/12 07:29, Jilles Tjoelker wrote:
> >>> On Fri, Jan 11, 2013 at 10:49:38PM +0200, Konstantin Belousov wrote:
> >>>> http://people.freebsd.org/~kib/misc/rtld-sigblock.3.patch
> >>> The new fields td_sigblock_ptr and td_sigblock_val are in the part that
> >>> is zeroed for new threads, while the code in rtld appears to expect them
> >>> to be copied (on fork, vfork and pthread_create). The fields are
> >>> correctly zeroed on exec.
> >>>
> >>> Sharing the magic variable between threads means that one thread holding
> >>> an rtld lock will block signals for all other threads as well. This is
> >>> different from how the normal signal mask works but I don't know whether
> >>> it may break things. However, the patch depends on it in some way
> >>> because sigtd() does not know about fast sigblock and will therefore
> >>> happily select a thread that is fast-sigblocking to handle a signal
> >>> directed at the process.
> >>>
> >>> Although libthr's postpone approach is somewhat ugly, it does not depend
> >>> on any non-standard kernel features and does not delay the default
> >>> action. Would it be possible to move that code to libc to make things
> >>> easier for rtld? It looks like this requires teaching libc about various
> >>> threading concepts, though.
> >> Long time ago, if i remembered correctly, kib said that he wanted to
> >> merge libthr code into libc, I don't know its state.
> > Yes, this is correct, and I still want this.
> 
> Can we just do this already?
I estimate the initial efforts for this as 2-3 weeks of full-time work.

> 
> No offense intended if the challenge is technical, I'm assuming it's 
> political?
> 
> It's only 10 years overdue.
The KSE was removed in 2008, so it could only be done for the 5 years.

That said, the hardest issue with the merge is to preserve the ABI, esp.
in regard to the libthr and its namespace. For the binaries, the threading
symbols still must come from the libthr, while the merge left as an
implementation detail. I implemented the required features for rtld, namely
ELF filters support, not so long time ago, and there were still bug fixes
as recent as of 2012, after libstdc++ was split.

Also, we do not want the threading initialized before first additional
thread is created, as well as we do not want libc to use real locking
primitives before that. The same holds for rtld locks.

The main motivation for the merge is the loadable modules which are
linked against -lpthread, while the process which loads them is not.
Since libthr interposes several libc interfaces, such processes end up
with the completely broken linkage. As an example, the errno is still
resolved to the single-threaded function, so the checks for the error
cause return garbage after libthr load.

I tried to cover the issue by marking libthr as not dlopen-able, but
the outcry was too loud.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 834 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-arch/attachments/20130112/8e2c07d4/attachment.sig>


More information about the freebsd-arch mailing list