Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Issue 609363003: Add implementation of pthread_rwlock based on NaCl futexs (Closed)

Created:
6 years, 2 months ago by Sam Clegg
Modified:
6 years, 2 months ago
Reviewers:
Mark Seaborn
CC:
native-client-reviews_googlegroups.com
Project:
nacl
Visibility:
Public.

Description

Add implementation of pthread_rwlock based on NaCl futexs This implementation almost completely based on the implementation within bionic (libc/bionic/pthread_rwlock.cpp) BUG= https://code.google.com/p/nativeclient/issues/detail?id=3960 TEST= run_rwlock_test

Patch Set 1 #

Patch Set 2 : #

Total comments: 23

Patch Set 3 : #

Unified diffs Side-by-side diffs Delta from patch set Stats (+482 lines, -1 line) Patch
M src/untrusted/pthread/nacl.scons View 1 chunk +1 line, -0 lines 0 comments Download
A src/untrusted/pthread/nc_rwlock.c View 1 chunk +276 lines, -0 lines 0 comments Download
M src/untrusted/pthread/pthread.h View 3 chunks +44 lines, -1 line 0 comments Download
M src/untrusted/pthread/pthread.gyp View 1 chunk +1 line, -0 lines 0 comments Download
M tests/threads/nacl.scons View 1 chunk +13 lines, -0 lines 0 comments Download
A tests/threads/rwlock_test.c View 1 2 1 chunk +147 lines, -0 lines 0 comments Download

Messages

Total messages: 6 (1 generated)
Sam Clegg
Sending out for initial review to get early feedback on basic approach. Mark, do you ...
6 years, 2 months ago (2014-09-29 21:33:16 UTC) #2
Sam Clegg
Ping. Can you take a quick look. If this looks about right I'll write some ...
6 years, 2 months ago (2014-10-02 19:41:18 UTC) #3
Mark Seaborn
On 2014/10/02 19:41:18, Sam Clegg wrote: > Ping. Can you take a quick look. If ...
6 years, 2 months ago (2014-10-02 19:58:51 UTC) #4
Sam Clegg
https://codereview.chromium.org/609363003/diff/20001/src/untrusted/pthread/nc_rwlock.c File src/untrusted/pthread/nc_rwlock.c (right): https://codereview.chromium.org/609363003/diff/20001/src/untrusted/pthread/nc_rwlock.c#newcode20 src/untrusted/pthread/nc_rwlock.c:20: * This implemtation is based on the one found ...
6 years, 2 months ago (2014-10-02 23:12:01 UTC) #5
Sam Clegg
6 years, 2 months ago (2014-10-03 15:48:03 UTC) #6
On 2014/10/02 23:12:01, Sam Clegg wrote:
>
https://codereview.chromium.org/609363003/diff/20001/src/untrusted/pthread/nc...
> File src/untrusted/pthread/nc_rwlock.c (right):
> 
>
https://codereview.chromium.org/609363003/diff/20001/src/untrusted/pthread/nc...
> src/untrusted/pthread/nc_rwlock.c:20: * This implemtation is based on the one
> found in the bionic C library
> On 2014/10/02 19:58:51, Mark Seaborn wrote:
> > typo
> 
> Done.
> 
>
https://codereview.chromium.org/609363003/diff/20001/src/untrusted/pthread/nc...
> src/untrusted/pthread/nc_rwlock.c:26: *  - remove unsuppored features such as
> PTHREAD_PROCESS_PRIVATE/SHARED.
> On 2014/10/02 19:58:51, Mark Seaborn wrote:
> > typo
> 
> Done.
> 
>
https://codereview.chromium.org/609363003/diff/20001/src/untrusted/pthread/nc...
> src/untrusted/pthread/nc_rwlock.c:117: * This is actually a race read as
there's
> nothing that guarantees the
> On 2014/10/02 19:58:51, Mark Seaborn wrote:
> > This is not true with PNaCl, where "volatile" makes this an atomic read.
> 
> Acknowledged.
> 
>
https://codereview.chromium.org/609363003/diff/20001/src/untrusted/pthread/nc...
> src/untrusted/pthread/nc_rwlock.c:122: int32_t cur_state = rwlock->state;  /*
> C++11 relaxed atomic read */
> On 2014/10/02 19:58:51, Mark Seaborn wrote:
> > This isn't in C++. :-)
> 
> Acknowledged.
> 
>
https://codereview.chromium.org/609363003/diff/20001/src/untrusted/pthread/nc...
> src/untrusted/pthread/nc_rwlock.c:123: if (__predict_true(cur_state >= 0)) {
> On 2014/10/02 19:58:51, Mark Seaborn wrote:
> > I don't know if nacl-gcc has __predict.  Please run trybots.
> 
> Acknowledged.
> 
>
https://codereview.chromium.org/609363003/diff/20001/src/untrusted/pthread/nc...
> src/untrusted/pthread/nc_rwlock.c:140: if (ret == -ETIMEDOUT) {
> On 2014/10/02 19:58:50, Mark Seaborn wrote:
> > "ret == ETIMEDOUT".  Please add test coverage.
> 
> Done.
> 
>
https://codereview.chromium.org/609363003/diff/20001/src/untrusted/pthread/nc...
> src/untrusted/pthread/nc_rwlock.c:140: if (ret == -ETIMEDOUT) {
> On 2014/10/02 19:58:50, Mark Seaborn wrote:
> > "ret == ETIMEDOUT".  Please add test coverage.
> 
> Done.
> 
>
https://codereview.chromium.org/609363003/diff/20001/src/untrusted/pthread/nc...
> src/untrusted/pthread/nc_rwlock.c:168: * should be sequentially consistent.
> (currently enforced by
> On 2014/10/02 19:58:51, Mark Seaborn wrote:
> > Capitalise as "Currently" and add "."
> 
> Done.
> 
>
https://codereview.chromium.org/609363003/diff/20001/src/untrusted/pthread/nc...
> src/untrusted/pthread/nc_rwlock.c:210: return
> __pthread_rwlock_timedwrlock(rwlock, abs_timeout);
> On 2014/10/02 19:58:51, Mark Seaborn wrote:
> > pthread_rwlock_timedwrlock() and __pthread_rwlock_timedwrlock() do the same
> > thing, so you might as well merge the two.
> 
> Done.
> 
>
https://codereview.chromium.org/609363003/diff/20001/src/untrusted/pthread/nc...
> src/untrusted/pthread/nc_rwlock.c:267: if
> (__predict_false(rwlock->pending_readers > 0
> On 2014/10/02 19:58:51, Mark Seaborn wrote:
> > I can't see any distinction between pending_readers and pending_writers. 
> > Presumably you might as well merge the two and have a single
"pending_waiters"
> > field?
> 
> Thats what Hans Boehm said too :)
> https://android-review.googlesource.com/#/c/95031/
> 
>
https://codereview.chromium.org/609363003/diff/20001/src/untrusted/pthread/nc...
> src/untrusted/pthread/nc_rwlock.c:269:
> __libnacl_irt_futex.futex_wake(&rwlock->state, INT_MAX, NULL);
> On 2014/10/02 19:58:51, Mark Seaborn wrote:
> > Waking all the waiters doesn't seem very efficient...
> > 
> > It's not very fair, either.  If there are many readers, I imagine it could
> lead
> > to starvation of writers.
> > 
> > Do you know what the difference is between the two algorithms that Bionic
> > has/had?  How much more efficient is the direct-futex-based one over the
> > pthread_mutex+cond-based one?  Any idea how it compares with glibc's
> algorithm?
> 
> The change is here:
> https://android-review.googlesource.com/#/c/95031/
> 
> Its not clear to me what was wrong with the old one or why they changed. It
also
> seems that they lost the writer starvation logic in the transition...  but the
> code was reviewed by Hans Boehm.
> 
> Also, it loos like the previous implementation, while reducing writer
> starvation, still wakes up all waiters with pthread_cond_broadcast each
> time anyone unlocks.

I decided to keep things simple I go with my own implementation based on pthread
mutex and condvar: https://codereview.chromium.org/623863002/.
My implementation deals with writer starvation as well as the thundering hurd
problem, but is slightly more expensive in terms of the number of low level
operations in each call.

Powered by Google App Engine
This is Rietveld 408576698