Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 26 Dec 2015 12:15:43 -0500 (EST)
From:      Daniel Eischen <deischen@freebsd.org>
To:        Konstantin Belousov <kostikbel@gmail.com>
Cc:        John Baldwin <jhb@freebsd.org>, freebsd-arch@freebsd.org, freebsd-threads@freebsd.org
Subject:   Re: libthr shared locks
Message-ID:  <Pine.GSO.4.64.1512261151550.19056@sea.ntplx.net>
In-Reply-To: <20151226105409.GH3625@kib.kiev.ua>
References:  <20151223172528.GT3625@kib.kiev.ua> <4199356.DlQeWDh27F@ralph.baldwin.cx> <Pine.GSO.4.64.1512240836460.9582@sea.ntplx.net> <5496837.TbTQtANDNj@ralph.baldwin.cx> <Pine.GSO.4.64.1512241338340.10649@sea.ntplx.net> <20151224191408.GA3625@kib.kiev.ua> <Pine.GSO.4.64.1512251310090.14902@sea.ntplx.net> <20151226105409.GH3625@kib.kiev.ua>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sat, 26 Dec 2015, Konstantin Belousov wrote:

> On Fri, Dec 25, 2015 at 01:18:14PM -0500, Daniel Eischen wrote:
>> On Thu, 24 Dec 2015, Konstantin Belousov wrote:
>>
>>> On Thu, Dec 24, 2015 at 01:46:25PM -0500, Daniel Eischen wrote:
>>>> Can we still implement things like robust and priority mutexes in a
>>>> pshared mutex with Konstantin's implementation?  The rest of the world
>>>> (Linux, Solaris anyway) use structs and get by just fine ABI-wise.
>>>
>>> Yes, we do. I intend to do this as the next stage, planned the
>>> implementation and did some preparations for it in the current patch.
>>> This raises the question, why do you suppose that my approach with
>>> the off-page would not allow it ? I am asking not to argument, but to
>>> understand a possible shortcoming in the approach, which I missed.
>>
>> No, I was merely inquiring, if this is on your agenda, that's
>> good.
>>
>>> From the implementation PoV, off-page is completely equivalent to the
>>> in-line structs approach, and the difference is only in the initial
>>> translation of say pthread_mutex_t to the structure (off-page lookup vs.
>>> identity). The issues with maintaining the lists of the owned robust of
>>> pi mutexes are same, and in fact you could see some non-trivial traces
>>> of this in the _mutex_fork() reimplementation in my patch.
>>>
>>> Linux and Solaris get (large enough) structs early enough to avoid the ABI
>>> issues.  I remember Linux changing FILE layout in early days of glibc 2.0
>>> and resulting pain, while they already had the GNU symbol versioning
>>> working and used.
>>
>> I guess the issue now is the apparent speedups without having the
>> extra de-reference.  8-10% for things like mysql might be worth
>> considering the userland structs.
>
> I am sorry for the delay in answering, I read the David' patch you pointed
> out, and it took time to get through 9KLOCs patch which is not applicable
> to the current sources.

It is the holidays, I'm sure everyone is busy with other things.
I am in the same camp :-)

> I should note that the patch is not immediately useable, not due to
> the source code drift, but because the patch combines many unrelated
> things, and I do not agree with everything in it.

Yeah, I would advocate only committing part of David's patch,
in stages.  Just the part that implements the struct change and
shared synch primitives.  Other changes may no longer apply or
can be done later.

> E.g., I found quite interesting the notion that our libthr fork() does
> not work when called from the signal handler. I do not quite understand
> how the detection of the situation is done in the patch, and I do not
> agree with the cleanup of the 'in sighandler' state on longjmp. I
> think that this part of the patch is obsoleted by libthr intercepting
> signals and postponing signal delivery until a critical section is
> exited.

I think libthr has always done that (postpoining until critical
section is exited).  But there are libc (and perhaps other)
locks that may be left locked on a fork().  Really (according
to POSIX), a fork() from a threaded program can only be used
to exec() something.

> Patch adds yet another private malloc(), now to libthr. I think that
> cooperating with rtld and share the same allocator would be more
> reasonable.

I tend to agree.

> Notes above are to explain why I think that productizing the David' patch
> is huge work, IMO significantly more than just 'test and commit'.
>
> Returning to the point of potential gain in performance due to the
> ABI change. As I already stated in my previous replies, I am quite
> worried about the impact of the ABI change, and I think that potential
> destabilizations, which would manifest itself in the subtle and hard to
> diagnose ways (i.e. it is not a sigsegv outright on the start) is huge
> setback for the change.

I guess I am just not that worried about the ABI change when combined
with a library version bump.  We use to do this for every new major
release, it isn't anything that hasn't been done before.  We never
supported 2 thread libraries in the same executable, and it is
obvious when that happens (I think we even instrumented libc_r,
or was it rtld?, to emit a warning when that happened.  My memory
is fuzzy).  With poudriere, our new package system, I would think
we would be better off now than 10 years ago?

I do note that I was initially wrong in thinking that port revision
bumps could help alleviate any pain.  A port could be built in
-stable with the revision bump just as well as in -current (or 11).
What would be needed is for pkg to understand that any port built
for 10 and previous could not run on 11+ (just to be on the safe
side).

> OTOH, we should be able to plan such change, which requires much more
> drastic measures to be implementable. I started thinking about it, and
> I noted that what is needed is solved by renaming libthr to something
> else, e.g. libthr2. One of the issue which is not solved by the dso
> version bump (not to even mention versioned symbols bump) is the
> static linker bringing both libthr.so.3 and libthr.so.4 into the same
> process, by the mere use of -lpthread by different objects at different
> times. Then, libthr and hypothetical libthr2 should check and prevent
> activation of image which loads both.
>
> But these are longtime to evaluate and implement. The feature at hand
> does not require ABI change, as my patch demostrated. Yes, shared
> mutexes would be more naturally implemented with the inline locks, and
> avoidance of an indirection in the libthr is also good, but lets not mix
> significant ABI change and some less ambitious feature. My approach does
> not lock out future strategies.

I agree, but the work that you are doing now would be basically
thrown out later on.  I will not stand in your way and appreciate
any work you do.  I would just rather that the struct change be
made now for 11, even without any pshared or other changes.  For
once the struct change is made, pshared or other additions can
be made afterward, even in the 11 branch because they would not
break the ABI.

-- 
DE



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.GSO.4.64.1512261151550.19056>