This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH v4 00/12] nptl: Implement POSIX-proposed _clock variants of existing _timed functions


My attempts[1] to add a variant of pthread_cond_timedwait that would accept
a clockid_t parameter led me to propose[2] to The Austin Group the addition
of an entire family of functions that accept a clockid_t parameter to
indicate the clock that the timespec absolute timeout parameter should be
measured against. They responded positively to the request but an
implementation is required before the proposal can proceed.

This patch series is the second version of the first part of that
implementation in glibc, it contains implementations and tests for
four new functions:

int pthread_cond_clockwait(pthread_cond_t *cond, pthread_mutex_t *mutex,
                           clockid_t clock, const struct timespec *abstime)

int pthread_rwlock_clockrdlock(pthread_rwlock_t *rwlock, clockid_t clock,
                               const struct timespec *abstime)

int pthread_rwlock_clockwrlock(pthread_rwlock_t *rwlock, clockid_t clock,
                               const struct timespec *abstime)

int sem_clockwait(sem_t *restrict, clockid_t clock_id, const struct
                  timespec *restrict)

int pthread_mutex_clocklock (pthread_mutex_t *mutex,
			     clockid_t clockid,
			     const struct timespec *abstime)

These are implemented by replacing the underlying equivalent _timed
functions with ones that accept a clockid_t parameter, and then
implementing the existing _timed functions by passing CLOCK_REALTIME
to the new implementation. This requires clockid_t parameters to be
added to the underlying futex-internal, lowlevellock-futex and
lowlevellock functions.

glibc-specific functions, such as pthread_timedjoin_np are next on the
list after that.

The mq_clockreceive and mq_clocksend functions corresponding to
mq_timedreceive and mq_timedsend require kernel changes before they can be
implemented in glibc.

As implemented, passing an unsupported or invalid clock to these functions
yields EINVAL. I considered returning ENOTSUP for valid-but-unsupported
clocks, but I was worried that there was a risk that the list of valid
clocks would not be updated when a new clock was added to glibc.

Rather than duplicating tests, I've parameterised them so that the same
tests can be run on the existing timedwait functions and the new clockwait
functions.

The changes have been tested with "make check" and "make check-abi" on
x86, x86_64, arm and arm64. I've attempted to update the abilists for
all architectures, but cannot test all of them.

I've compile-tested the powerpc and s390-specific implementations of
lll_clockwait. Although I've updated the sparc32-specific
implementation, I have been unable to test it since it appears that
even Debian hasn't supported sparc32 for nearly twenty years! I was
able to compile-test sparc64 though.

Thanks to everyone that commented on previous versions of this patch
series. They have been a great help, and I hope that I have
incorporated their feedback correctly.

Adhemerval Zanella suggested that timespec validity checks could be
consolidated. I think that's a good idea, but it would need to be a
different change. This series doesn't really make that change any
harder to do, and I can try to tackle that separately.

I've not updated the dates in the ChangeLog entries. Presumably that's
best done just before this lands to ensure that the dates are
monotonic. :)

Changes since v3[7]:

* Include previously-separate pthread_mutex_clocklock
  implementation[6] too.
* Add commit to remove futex_supports_exact_relative_timeouts as
  suggested by Adhemerval Zanella.
* Use xclock_now in new tst-cond27.c.
* Disable verbose output from tst-rwlock6.c by default.
* Add verbose_printf to libsupport and use it in tst-rwlock6.c and
  tst-cond11.c.
* Improve NEWS entry.
* Update comments in futex-internal.h to indicate that the clock for
  abstimed waits is now specified rather than always being
  CLOCK_REALTIME.
* Add __nonnull attribute to __pthread_cond_clockwait declaration.
* Improve comment for lowlevellock.h:__lll_clocklock.
* Cope with __clock_gettime failure in __lll_timedlock_wait.
* Add sparc32 implementation of lll_clocklock.

Changes since v2[5]:
* Don't update hurd abilist since the new functions aren't (yet) in
  htl.

Changes since v1[4]:
* Many whitespace/formatting cleanups
* Rebase on top of tests that use libsupport
* Use futex_abstimed_supported_clockid in __pthread_cond_clockwait.
* Update all abilists.
* Add to NEWS.

[1] https://sourceware.org/ml/libc-alpha/2015-07/msg00193.html
[2] http://austingroupbugs.net/view.php?id=1216
[3] https://sourceware.org/ml/libc-alpha/2019-05/msg00031.html
[4] https://sourceware.org/ml/libc-alpha/2019-02/msg00637.html
[5] https://sourceware.org/ml/libc-alpha/2019-05/msg00131.html
[6] https://sourceware.org/ml/libc-alpha/2019-06/msg00010.html
[7] https://sourceware.org/ml/libc-alpha/2019-05/msg00600.html

Mike Crowe (12):
  support: Add xclock_now helper function.
  support: Invent verbose_printf macro
  nptl: Convert various tests to use libsupport
  nptl: Add clockid parameter to futex timed wait calls
  nptl: Add POSIX-proposed sem_clockwait
  nptl: Add POSIX-proposed pthread_cond_clockwait
  nptl: pthread_rwlock: Move timeout validation into _full functions
  nptl: Add POSIX-proposed pthread_rwlock_clockrdlock & pthread_rwlock_clockwrlock
  nptl: Rename lll_timedlock to lll_clocklock and add clockid parameter
  nptl: Add POSIX-proposed pthread_mutex_clocklock
  Update NEWS for new _clockwait and _clocklock functions
  nptl: Remove futex_supports_exact_relative_timeouts

 ChangeLog                                                       | 498 +++++++-
 NEWS                                                            |   9 +-
 manual/threads.texi                                             |  58 +-
 nptl/DESIGN-systemtap-probes.txt                                |   3 +-
 nptl/Makefile                                                   |  10 +-
 nptl/Versions                                                   |   6 +-
 nptl/eintr.c                                                    |  12 +-
 nptl/forward.c                                                  |   5 +-
 nptl/lll_timedlock_wait.c                                       |  15 +-
 nptl/nptl-init.c                                                |   1 +-
 nptl/pthreadP.h                                                 |   5 +-
 nptl/pthread_cond_wait.c                                        |  63 +-
 nptl/pthread_condattr_setclock.c                                |   5 +-
 nptl/pthread_mutex_timedlock.c                                  |  50 +-
 nptl/pthread_rwlock_clockrdlock.c                               |  29 +-
 nptl/pthread_rwlock_clockwrlock.c                               |  29 +-
 nptl/pthread_rwlock_common.c                                    |  32 +-
 nptl/pthread_rwlock_rdlock.c                                    |   2 +-
 nptl/pthread_rwlock_timedrdlock.c                               |  12 +-
 nptl/pthread_rwlock_timedwrlock.c                               |  12 +-
 nptl/pthread_rwlock_wrlock.c                                    |   2 +-
 nptl/sem_clockwait.c                                            |  45 +-
 nptl/sem_timedwait.c                                            |   3 +-
 nptl/sem_wait.c                                                 |   3 +-
 nptl/sem_waitcommon.c                                           |  15 +-
 nptl/tst-abstime.c                                              |  10 +-
 nptl/tst-cond11.c                                               |  38 +-
 nptl/tst-cond26.c                                               |  77 +-
 nptl/tst-cond27.c                                               |  66 +-
 nptl/tst-eintr1.c                                               |  52 +-
 nptl/tst-eintr2.c                                               |  60 +-
 nptl/tst-eintr3.c                                               |  23 +-
 nptl/tst-eintr4.c                                               |  15 +-
 nptl/tst-eintr5.c                                               |  40 +-
 nptl/tst-mutex-errorcheck.c                                     |  29 +-
 nptl/tst-mutex11.c                                              |  69 +-
 nptl/tst-mutex5.c                                               | 184 +---
 nptl/tst-mutex9.c                                               | 151 +--
 nptl/tst-rwlock14.c                                             |  12 +-
 nptl/tst-rwlock6.c                                              |  95 +-
 nptl/tst-rwlock7.c                                              |  83 +-
 nptl/tst-rwlock9.c                                              | 102 +-
 nptl/tst-sem13.c                                                |  39 +-
 nptl/tst-sem17.c                                                |  76 +-
 nptl/tst-sem5.c                                                 |  23 +-
 support/test-driver.h                                           |   8 +-
 support/xtime.h                                                 |  10 +-
 sysdeps/nptl/futex-internal.h                                   |  18 +-
 sysdeps/nptl/lowlevellock-futex.h                               |  13 +-
 sysdeps/nptl/lowlevellock.h                                     |  16 +-
 sysdeps/nptl/pthread-functions.h                                |   4 +-
 sysdeps/nptl/pthread.h                                          |  36 +-
 sysdeps/pthread/semaphore.h                                     |   7 +-
 sysdeps/sparc/sparc32/lll_timedlock_wait.c                      |   2 +-
 sysdeps/sparc/sparc32/lowlevellock.c                            |  15 +-
 sysdeps/unix/sysv/linux/aarch64/libpthread.abilist              |   5 +-
 sysdeps/unix/sysv/linux/alpha/libpthread.abilist                |   5 +-
 sysdeps/unix/sysv/linux/arm/libpthread.abilist                  |   5 +-
 sysdeps/unix/sysv/linux/csky/libpthread.abilist                 |   5 +-
 sysdeps/unix/sysv/linux/futex-internal.h                        |  34 +-
 sysdeps/unix/sysv/linux/hppa/libpthread.abilist                 |   5 +-
 sysdeps/unix/sysv/linux/i386/libpthread.abilist                 |   5 +-
 sysdeps/unix/sysv/linux/ia64/libpthread.abilist                 |   5 +-
 sysdeps/unix/sysv/linux/lowlevellock-futex.h                    |  33 +-
 sysdeps/unix/sysv/linux/m68k/coldfire/libpthread.abilist        |   5 +-
 sysdeps/unix/sysv/linux/m68k/m680x0/libpthread.abilist          |   5 +-
 sysdeps/unix/sysv/linux/microblaze/libpthread.abilist           |   5 +-
 sysdeps/unix/sysv/linux/mips/mips32/libpthread.abilist          |   5 +-
 sysdeps/unix/sysv/linux/mips/mips64/libpthread.abilist          |   5 +-
 sysdeps/unix/sysv/linux/nios2/libpthread.abilist                |   5 +-
 sysdeps/unix/sysv/linux/powerpc/elision-timed.c                 |   6 +-
 sysdeps/unix/sysv/linux/powerpc/lowlevellock.h                  |   9 +-
 sysdeps/unix/sysv/linux/powerpc/powerpc32/libpthread.abilist    |   5 +-
 sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libpthread.abilist |   5 +-
 sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libpthread.abilist |   5 +-
 sysdeps/unix/sysv/linux/riscv/rv64/libpthread.abilist           |   5 +-
 sysdeps/unix/sysv/linux/s390/elision-timed.c                    |   6 +-
 sysdeps/unix/sysv/linux/s390/lowlevellock.h                     |   9 +-
 sysdeps/unix/sysv/linux/s390/s390-32/libpthread.abilist         |   5 +-
 sysdeps/unix/sysv/linux/s390/s390-64/libpthread.abilist         |   5 +-
 sysdeps/unix/sysv/linux/sh/libpthread.abilist                   |   5 +-
 sysdeps/unix/sysv/linux/sparc/lowlevellock.h                    |  11 +-
 sysdeps/unix/sysv/linux/sparc/sparc32/libpthread.abilist        |   5 +-
 sysdeps/unix/sysv/linux/sparc/sparc64/libpthread.abilist        |   5 +-
 sysdeps/unix/sysv/linux/x86/elision-timed.c                     |   6 +-
 sysdeps/unix/sysv/linux/x86/lowlevellock.h                      |  11 +-
 sysdeps/unix/sysv/linux/x86_64/64/libpthread.abilist            |   5 +-
 sysdeps/unix/sysv/linux/x86_64/x32/libpthread.abilist           |   5 +-
 88 files changed, 1867 insertions(+), 675 deletions(-)
 create mode 100644 nptl/pthread_rwlock_clockrdlock.c
 create mode 100644 nptl/pthread_rwlock_clockwrlock.c
 create mode 100644 nptl/sem_clockwait.c
 create mode 100644 nptl/tst-cond26.c
 create mode 100644 nptl/tst-cond27.c
 create mode 100644 nptl/tst-mutex11.c
 create mode 100644 nptl/tst-sem17.c

base-commit: 02d8b5ab1c89bcef2627d2b621bfb35b573852c2
-- 
git-series 0.9.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]