From patchwork Tue Jun 25 00:08:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 33374 Received: (qmail 18594 invoked by alias); 25 Jun 2019 00:11:30 -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 18529 invoked by uid 89); 25 Jun 2019 00:11:30 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy= X-HELO: esa4.hgst.iphmx.com DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1561421489; x=1592957489; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SVv6OJv7gjLA9MHR1c6lX7OkmNIS8fIj0GwE3P/WBLw=; b=DCfZveb4grzQl0bH3mv2f3SxoI7DmBKhD/ekNXPqa1dc0doL+CFTddOa 2FoWTg+nHDdWLtcc5i9NvcPQ81W3YIlej2iCUOgTxofjrWgcOvwc+HYHS rBDta2Gcc78zsNBIi7DET4lVxiFETIkI3TFTycgaGOhs8jVm9bJ//XEqx DhRbdG9BNfnxYLDhgCayYCgzigoh4F1DuFObjidOH+KFtvPo/aYDKHHPX yuYefselYD8db3C5NxzESUNKPA7jREZIRb0nZzM8QHi6EC7u9qvN9frNf PvvqG9p8UpWwjBoZJ/+HOC+7E6d0cu7+wICtfL4gPXHKFtP3GmeTj39DE A==; IronPort-SDR: ESWQZL3xUGodRtQdG4nlhtR/ZwEczMpHcbY8w8B22VX/xr3jeWGu3nBWygqRnMikRdT6vRTW4k 6G+S49qbvCJlOoM7xR75fIKMxIzD9hGOAs2PhRdRnw2DIspwvwLBAbhbz+JS4kYS1sv/U+iIIV 6KW1TaU6YikZKEWDDtJ6/xj51sXndZP7/iuauq1CgyGrfq+gR1dl1ZAnoTLvowkAN+ySlaZoNX EzTpk0K+DFM+Sf9jAbv+0P3ahAxVttPqomxE2Cas6m9FMDwR27NGJY0FG1uyf/IUhDldExH3N+ qm3iOM4ZJsKg1vJTR3q9i/yH IronPort-SDR: JyTmtp1D4e6nopH/24nFsiQx3OAr3RHq3qo41DKzEh3WY703nrAbWcHXFygmCADqtvRRad5V+/ INWzDvaA3XQ6CDVMvD26ADRArbRsHIWXdm9zku8t2LkVMNcok99ex8GWSN7Ug+ExK/GsDPshc0 dhxSLjB17P7b4g/Hvt2+53j3XRNF1Qwvo3v1T6wl2j9QE/ej2j5SYCivAIEyL1kXYFTQMFKv+6 TnheE6robux6zC7b0TC5WiOaJma0fqOUevH3ejuw/Q50algAdW+gp1WQYHpbdij1XU6mSlUsm3 K7o= From: Alistair Francis To: libc-alpha@sourceware.org Cc: arnd@arndb.de, adhemerval.zanella@linaro.org, fweimer@redhat.com, palmer@sifive.com, macro@wdc.com, zongbox@gmail.com, zong@andestech.com, alistair.francis@wdc.com, alistair23@gmail.com Subject: [RFC v2 05/20] sysdeps/nanosleep: Use clock_nanosleep_time64 if avaliable Date: Mon, 24 Jun 2019 17:08:58 -0700 Message-Id: In-Reply-To: References: MIME-Version: 1.0 The nanosleep syscall is not supported on newer 32-bit platforms (such as RV32). To fix this issue let's use clock_nanosleep_time64 if it is avaliable. Let's use CLOCK_REALTIME when calling clock_nanosleep_time64 as the Linux specification says: "POSIX.1 specifies that nanosleep() should measure time against the CLOCK_REALTIME clock. However, Linux measures the time using the CLOCK_MONOTONIC clock. This probably does not matter, since the POSIX.1 specification for clock_settime(2) says that discontinuous changes in CLOCK_REALTIME should not affect nanosleep()" Signed-off-by: Alistair Francis --- ChangeLog | 6 ++++++ nptl/thrd_sleep.c | 19 ++++++++++++++++++- sysdeps/unix/sysv/linux/nanosleep.c | 12 ++++++++++++ sysdeps/unix/sysv/linux/nanosleep_nocancel.c | 11 +++++++++++ 4 files changed, 47 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 05291d7825..b90c5ab60c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2019-06-21 Alistair Francis + + * nptl/thrd_sleep.c: Use clock_nanosleep_time64 instead of nanosleep. + * sysdeps/unix/sysv/linux/nanosleep.c: Likewise. + * sysdeps/unix/sysv/linux/nanosleep_nocancel.c: Likewise. + 2019-06-20 Dmitry V. Levin Florian Weimer diff --git a/nptl/thrd_sleep.c b/nptl/thrd_sleep.c index 07a51808df..09f8c7159f 100644 --- a/nptl/thrd_sleep.c +++ b/nptl/thrd_sleep.c @@ -25,7 +25,24 @@ int thrd_sleep (const struct timespec* time_point, struct timespec* remaining) { INTERNAL_SYSCALL_DECL (err); - int ret = INTERNAL_SYSCALL_CANCEL (nanosleep, err, time_point, remaining); + int ret; + +#ifdef __ASSUME_TIME64_SYSCALLS + ret = INTERNAL_SYSCALL_CANCEL (clock_nanosleep_time64, err, + CLOCK_REALTIME, 0, time_point, remaining); +#else +# ifdef __NR_clock_nanosleep_time64 + long int ret_64 = INTERNAL_SYSCALL_CANCEL (clock_nanosleep_time64, err, + CLOCK_REALTIME, 0, time_point, remaining); + if (ret_64 == 0 || errno != ENOSYS) { + ret = ret_64; + } else { + ret = INTERNAL_SYSCALL_CANCEL (nanosleep, err, time_point, remaining); + } +# else + ret = INTERNAL_SYSCALL_CANCEL (nanosleep, err, time_point, remaining); +# endif +#endif if (INTERNAL_SYSCALL_ERROR_P (ret, err)) { /* C11 states thrd_sleep function returns -1 if it has been interrupted diff --git a/sysdeps/unix/sysv/linux/nanosleep.c b/sysdeps/unix/sysv/linux/nanosleep.c index f14ae565af..c2d6e2f766 100644 --- a/sysdeps/unix/sysv/linux/nanosleep.c +++ b/sysdeps/unix/sysv/linux/nanosleep.c @@ -25,7 +25,19 @@ int __nanosleep (const struct timespec *requested_time, struct timespec *remaining) { + +#ifdef __ASSUME_TIME64_SYSCALLS + return SYSCALL_CANCEL (clock_nanosleep_time64, CLOCK_REALTIME, 0, + requested_time, remaining); +#else +# ifdef __NR_clock_nanosleep_time64 + long int ret = SYSCALL_CANCEL (clock_nanosleep_time64, CLOCK_REALTIME, 0, + requested_time, remaining); + if (ret == 0 || errno != ENOSYS) + return ret; +# endif return SYSCALL_CANCEL (nanosleep, requested_time, remaining); +#endif } hidden_def (__nanosleep) weak_alias (__nanosleep, nanosleep) diff --git a/sysdeps/unix/sysv/linux/nanosleep_nocancel.c b/sysdeps/unix/sysv/linux/nanosleep_nocancel.c index 122ba627ff..f411a1c6c2 100644 --- a/sysdeps/unix/sysv/linux/nanosleep_nocancel.c +++ b/sysdeps/unix/sysv/linux/nanosleep_nocancel.c @@ -24,6 +24,17 @@ int __nanosleep_nocancel (const struct timespec *requested_time, struct timespec *remaining) { +#ifdef __ASSUME_TIME64_SYSCALLS + return INLINE_SYSCALL_CALL (clock_nanosleep_time64, CLOCK_REALTIME, 0, + requested_time, remaining); +#else +# ifdef __NR_clock_nanosleep_time64 + long int ret = INLINE_SYSCALL_CALL (clock_nanosleep_time64, CLOCK_REALTIME, 0, + requested_time, remaining); + if (ret == 0 || errno != ENOSYS) + return ret; +# endif return INLINE_SYSCALL_CALL (nanosleep, requested_time, remaining); +#endif } hidden_def (__nanosleep_nocancel)