aboutsummaryrefslogtreecommitdiff
path: root/nptl/DESIGN-rwlock.txt
diff options
context:
space:
mode:
authorTorvald Riegel <triegel@redhat.com>2014-05-22 16:00:12 +0200
committerTorvald Riegel <triegel@redhat.com>2017-01-10 11:50:17 +0100
commitcc25c8b4c1196a8c29e9a45b1e096b99a87b7f8c (patch)
tree52c5358896bc1ce9ad2081f179e72a1edac5fa6f /nptl/DESIGN-rwlock.txt
parentfbb31e20bc41957c5f3d6550f0178590cf473043 (diff)
downloadglibc-cc25c8b4c1196a8c29e9a45b1e096b99a87b7f8c.zip
glibc-cc25c8b4c1196a8c29e9a45b1e096b99a87b7f8c.tar.gz
glibc-cc25c8b4c1196a8c29e9a45b1e096b99a87b7f8c.tar.bz2
New pthread rwlock that is more scalable.
This replaces the pthread rwlock with a new implementation that uses a more scalable algorithm (primarily through not using a critical section anymore to make state changes). The fast path for rdlock acquisition and release is now basically a single atomic read-modify write or CAS and a few branches. See nptl/pthread_rwlock_common.c for details. * nptl/DESIGN-rwlock.txt: Remove. * nptl/lowlevelrwlock.sym: Remove. * nptl/Makefile: Add new tests. * nptl/pthread_rwlock_common.c: New file. Contains the new rwlock. * nptl/pthreadP.h (PTHREAD_RWLOCK_PREFER_READER_P): Remove. (PTHREAD_RWLOCK_WRPHASE, PTHREAD_RWLOCK_WRLOCKED, PTHREAD_RWLOCK_RWAITING, PTHREAD_RWLOCK_READER_SHIFT, PTHREAD_RWLOCK_READER_OVERFLOW, PTHREAD_RWLOCK_WRHANDOVER, PTHREAD_RWLOCK_FUTEX_USED): New. * nptl/pthread_rwlock_init.c (__pthread_rwlock_init): Adapt to new implementation. * nptl/pthread_rwlock_rdlock.c (__pthread_rwlock_rdlock_slow): Remove. (__pthread_rwlock_rdlock): Adapt. * nptl/pthread_rwlock_timedrdlock.c (pthread_rwlock_timedrdlock): Adapt. * nptl/pthread_rwlock_timedwrlock.c (pthread_rwlock_timedwrlock): Adapt. * nptl/pthread_rwlock_trywrlock.c (pthread_rwlock_trywrlock): Adapt. * nptl/pthread_rwlock_tryrdlock.c (pthread_rwlock_tryrdlock): Adapt. * nptl/pthread_rwlock_unlock.c (pthread_rwlock_unlock): Adapt. * nptl/pthread_rwlock_wrlock.c (__pthread_rwlock_wrlock_slow): Remove. (__pthread_rwlock_wrlock): Adapt. * nptl/tst-rwlock10.c: Adapt. * nptl/tst-rwlock11.c: Adapt. * nptl/tst-rwlock17.c: New file. * nptl/tst-rwlock18.c: New file. * nptl/tst-rwlock19.c: New file. * nptl/tst-rwlock2b.c: New file. * nptl/tst-rwlock8.c: Adapt. * nptl/tst-rwlock9.c: Adapt. * sysdeps/aarch64/nptl/bits/pthreadtypes.h (pthread_rwlock_t): Adapt. * sysdeps/arm/nptl/bits/pthreadtypes.h (pthread_rwlock_t): Adapt. * sysdeps/hppa/nptl/bits/pthreadtypes.h (pthread_rwlock_t): Adapt. * sysdeps/ia64/nptl/bits/pthreadtypes.h (pthread_rwlock_t): Adapt. * sysdeps/m68k/nptl/bits/pthreadtypes.h (pthread_rwlock_t): Adapt. * sysdeps/microblaze/nptl/bits/pthreadtypes.h (pthread_rwlock_t): Adapt. * sysdeps/mips/nptl/bits/pthreadtypes.h (pthread_rwlock_t): Adapt. * sysdeps/nios2/nptl/bits/pthreadtypes.h (pthread_rwlock_t): Adapt. * sysdeps/s390/nptl/bits/pthreadtypes.h (pthread_rwlock_t): Adapt. * sysdeps/sh/nptl/bits/pthreadtypes.h (pthread_rwlock_t): Adapt. * sysdeps/sparc/nptl/bits/pthreadtypes.h (pthread_rwlock_t): Adapt. * sysdeps/tile/nptl/bits/pthreadtypes.h (pthread_rwlock_t): Adapt. * sysdeps/unix/sysv/linux/alpha/bits/pthreadtypes.h (pthread_rwlock_t): Adapt. * sysdeps/unix/sysv/linux/powerpc/bits/pthreadtypes.h (pthread_rwlock_t): Adapt. * sysdeps/x86/bits/pthreadtypes.h (pthread_rwlock_t): Adapt. * nptl/nptl-printers.py (): Adapt. * nptl/nptl_lock_constants.pysym: Adapt. * nptl/test-rwlock-printers.py: Adapt. * nptl/test-rwlockattr-printers.c: Adapt. * nptl/test-rwlockattr-printers.py: Adapt.
Diffstat (limited to 'nptl/DESIGN-rwlock.txt')
-rw-r--r--nptl/DESIGN-rwlock.txt113
1 files changed, 0 insertions, 113 deletions
diff --git a/nptl/DESIGN-rwlock.txt b/nptl/DESIGN-rwlock.txt
deleted file mode 100644
index 810d1b8..0000000
--- a/nptl/DESIGN-rwlock.txt
+++ /dev/null
@@ -1,113 +0,0 @@
-Reader Writer Locks pseudocode
-==============================
-
- pthread_rwlock_rdlock(pthread_rwlock_t *rwlock);
- pthread_rwlock_unlock(pthread_rwlock_t *rwlock);
- pthread_rwlock_wrlock(pthread_rwlock_t *rwlock);
-
-struct pthread_rwlock_t {
-
- unsigned int lock:
- - internal mutex
-
- unsigned int writers_preferred;
- - locking mode: 0 recursive, readers preferred
- 1 nonrecursive, writers preferred
-
- unsigned int readers;
- - number of read-only references various threads have
-
- pthread_t writer;
- - descriptor of the writer or 0
-
- unsigned int readers_wakeup;
- - 'all readers should wake up' futex.
-
- unsigned int writer_wakeup;
- - 'one writer should wake up' futex.
-
- unsigned int nr_readers_queued;
- - number of readers queued up.
-
- unsigned int nr_writers_queued;
- - number of writers queued up.
-}
-
-pthread_rwlock_rdlock(pthread_rwlock_t *rwlock)
-{
- lll_lock(rwlock->lock);
- for (;;) {
- if (!rwlock->writer && (!rwlock->nr_writers_queued ||
- !rwlock->writers_preferred))
- break;
-
- rwlock->nr_readers_queued++;
- val = rwlock->readers_wakeup;
- lll_unlock(rwlock->lock);
-
- futex_wait(&rwlock->readers_wakeup, val)
-
- lll_lock(rwlock->lock);
- rwlock->nr_readers_queued--;
- }
- rwlock->readers++;
- lll_unlock(rwlock->lock);
-}
-
-pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock)
-{
- int result = EBUSY;
- lll_lock(rwlock->lock);
- if (!rwlock->writer && (!rwlock->nr_writers_queued ||
- !rwlock->writers_preferred))
- rwlock->readers++;
- lll_unlock(rwlock->lock);
- return result;
-}
-
-pthread_rwlock_wrlock(pthread_rwlock_t *rwlock)
-{
- lll_lock(rwlock->lock);
- for (;;) {
- if (!rwlock->writer && !rwlock->readers)
- break;
-
- rwlock->nr_writers_queued++;
- val = rwlock->writer_wakeup;
- lll_unlock(rwlock->lock);
-
- futex_wait(&rwlock->writer_wakeup, val);
-
- lll_lock(rwlock->lock);
- rwlock->nr_writers_queued--;
- }
- rwlock->writer = pthread_self();
- lll_unlock(rwlock->lock);
-}
-
-pthread_rwlock_unlock(pthread_rwlock_t *rwlock)
-{
- lll_lock(rwlock->lock);
-
- if (rwlock->writer)
- rwlock->writer = 0;
- else
- rwlock->readers--;
-
- if (!rwlock->readers) {
- if (rwlock->nr_writers_queued) {
- ++rwlock->writer_wakeup;
- lll_unlock(rwlock->lock);
- futex_wake(&rwlock->writer_wakeup, 1);
- return;
- } else
- if (rwlock->nr_readers_queued) {
- ++rwlock->readers_wakeup;
- lll_unlock(rwlock->lock);
- futex_wake(&rwlock->readers_wakeup, MAX_INT);
- return;
- }
- }
-
- lll_unlock(rwlock->lock);
-}