From patchwork Wed Feb 27 18:23:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Crowe X-Patchwork-Id: 1049086 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-100297-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=mcrowe.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="O9tE4Jnx"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 448kcV3n8bz9s00 for ; Thu, 28 Feb 2019 05:24:58 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id; q=dns; s= default; b=kKb21XU0KsTLdpz6VhtCIh4umzTu7DRiiVFskikvskMAehAnrMIYA PzQiFDkbj68e39+bJQOj3bLe9fVoxpGo63yd7E1nABbY/wngVlI1Dk2JifViAVD1 /BcnvLZTzfOLs5OY6F1BUhfrbxHnj3k04MPCuUOYn1/zfgXHDiIrtE= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id; s=default; bh=YRQv3WTDHV5JOTkQ9E8znCZtuo4=; b=O9tE4JnxANKhCQX2V//9TT2MfWbP cFPVNus/eqpAukqgUtbiFki6kYcgDQnI33c/0nvjRMcVGixu8qnI+s9U2oGX1Zfe p4oCtnxhxioN7L9kCBQAAzpXeN2WRokRRUsWWiMyUNljyM94Wes7Hd4yK01rharv yZoenJoua2zI48E= Received: (qmail 108807 invoked by alias); 27 Feb 2019 18:24:51 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 108395 invoked by uid 89); 27 Feb 2019 18:24:36 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-6.6 required=5.0 tests=BAYES_00, GIT_PATCH_2, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 spammy=austin, H*r:smtp, responded, H*MI:mac X-HELO: avasout02.plus.net X-CM-Score: 0.00 From: Mike Crowe To: libc-alpha@sourceware.org Cc: Mike Crowe Subject: [PATCH 0/7] Implement proposed POSIX _clockwait variants of existing _timedwait functions Date: Wed, 27 Feb 2019 18:23:50 +0000 Message-Id: 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 first part of that implementation in glibc, it contains 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) 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 and lowlevellock-futex functions. pthread_mutex_clocklock is not yet implemented because doing so requires a version of __lll_timedlock_wait that supports both CLOCK_MONOTONIC and CLOCK_REALTIME. This function is currently architecture specific. I plan to work on that next, if these changes are considered acceptable. 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. A number of tests have been updated to use struct timespec rather than struct timeval so that they can call clock_gettime(CLOCK_MONOTONIC) rather then gettimeofday. To make this easier I created the support/timespec.h header file to contain functions to add and subtract timespec structures borrowed from sysdeps/pthread/posix-timer.h. There's probably a better place for these, but I don't know where that might be. 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" on x86_64 and arm64. Earlier versions were tested on arm. I haven't updated the ChangeLog, NEWS or architecture abilists yet (so some tests fail on arm64), but will do so if the rest of the changes are acceptable. Thanks to everyone that commented on previous versions of this patch (when the single new function was called pthread_cond_timedwaitonclock_np.) They have been a great help, and I hope that I have incorporated their feedback correctly. [1] https://sourceware.org/ml/libc-alpha/2015-07/msg00193.html [2] http://austingroupbugs.net/view.php?id=1216 Mike Crowe (7): 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/tst-rwlock14: Test pthread/rwlock_timedwrlock correctly nptl/tst-rwlock: Use clock_gettime/timespec rather than gettimeofday/timeval nptl: Add POSIX-proposed pthread_rwlock_clockrdlock & pthread_rwlock_clockwrlock conform/data/semaphore.h-data | 1 +- manual/threads.texi | 58 ++++- nptl/Makefile | 8 +- nptl/Versions | 5 +- nptl/forward.c | 5 +- nptl/nptl-init.c | 1 +- nptl/pthreadP.h | 4 +- nptl/pthread_cond_wait.c | 45 ++- nptl/pthread_mutex_timedlock.c | 8 +- nptl/pthread_rwlock_clockrdlock.c | 27 ++- nptl/pthread_rwlock_clockwrlock.c | 27 ++- 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 | 28 ++- nptl/tst-cond11.c | 30 +- nptl/tst-cond26.c | 91 +++++++- nptl/tst-cond27.c | 113 +++++++++- nptl/tst-rwlock14.c | 159 +++++++++++- nptl/tst-rwlock6.c | 132 ++++++---- nptl/tst-rwlock7.c | 108 +++++--- nptl/tst-rwlock9.c | 90 +++++-- nptl/tst-sem13.c | 50 +++- nptl/tst-sem17.c | 57 ++++- nptl/tst-sem5.c | 30 +- support/timespec.h | 27 ++- sysdeps/nptl/futex-internal.h | 7 +- sysdeps/nptl/lowlevellock-futex.h | 14 +- sysdeps/nptl/pthread-functions.h | 4 +- sysdeps/nptl/pthread.h | 21 ++- sysdeps/pthread/semaphore.h | 4 +- sysdeps/unix/sysv/linux/futex-internal.h | 26 +- sysdeps/unix/sysv/linux/lowlevellock-futex.h | 29 +- sysdeps/unix/sysv/linux/x86_64/64/libpthread.abilist | 4 +- 40 files changed, 1124 insertions(+), 215 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-sem17.c create mode 100644 support/timespec.h base-commit: a04549c19407a29a271779598a9518f9baf959e0