Natanael Copa wrote:
> Note that there are 64 CPU cores. I have only tested with that many cores on 
> aarch64.

You could vary the number of CPU cores using the 'taskset' command.

What I see in an Alpine Linux 3.20 / x86_64 VM:

$ time taskset -c 0,1,2,3,4,5,6,7 ./test-pthread-rwlock
real time 0.74 sec

$ time taskset -c 0,1,2,3 ./test-pthread-rwlock
$ time taskset -c 4,5,6,7 ./test-pthread-rwlock
real time 1.06 sec

$ time taskset -c 0,1 ./test-pthread-rwlock
$ time taskset -c 2,3 ./test-pthread-rwlock
$ time taskset -c 4,5 ./test-pthread-rwlock
$ time taskset -c 6,7 ./test-pthread-rwlock
real time 1.99 sec

$ time taskset -c 0 ./test-pthread-rwlock
$ time taskset -c 1 ./test-pthread-rwlock
$ time taskset -c 2 ./test-pthread-rwlock
real time 3.78 sec

> Not sure the exact codepath it takes on GNU libc systems. Is it the
> same as with musl libc?

At this point, I would concentrate on the musl side. One of the
interesting questions is why SCHED_FIFO and SCHED_RR are faster by 25%
than SCHED_OTHER, even on x86_64.

> > Note: Most Gnulib applications don't use pthread_rwlock directly, but
> > the glthread_rwlock facility. On musl systems, it works around the
> > possible writer starvation by reimplementing read-write locks based
> > on condition variables. This may be slower for a single operation,
> > but it is guaranteed to avoid writer starvation and therefore is
> > preferrable globally. This is why you don't see a timeout in
> > './test-lock', only in './test-pthread-rwlock'.
> 
> Wait a second. The test does not run the gnulib locking? It just tests
> the system (musl libc) pthread rwlock, while the app (gettext) would
> use the gnulib implementation?

You are right that it's confusing: The test contains some test fixture,
that starts 20 threads, does atomic operations, and finally pthread_join().
And, within that test fixture, it does the pthread_rwlock_* operations.
It could also be a problem with the test fixture, e.g. with the atomic
operations, currently implemented via semaphores. You can try to replace
in atomic-int-posix.h
  #define USE_VOLATILE 0    by    #define USE_VOLATILE 1
or
  disable the use of semaphores,
and see whether that has an effect.

Bruno




Reply via email to