From patchwork Mon Nov 4 19:30:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 35635 Received: (qmail 119053 invoked by alias); 4 Nov 2019 19:30:26 -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 118989 invoked by uid 89); 4 Nov 2019 19:30:23 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.6 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=avoidance X-HELO: mail-qt1-f195.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=to:cc:references:from:openpgp:autocrypt:subject:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=RFbmzlRfyqWLEJh9q+XjSFf5AIMd6ovnHcC9MAveoaM=; b=rDxXn+mwMZ9nC5ephza3bQS/wqqA0E7hwqd/sP+VMGvW9MYLN0DPuvAUru5ES9hnUr iNbgoXuHOfip/FpDsWqZmzmQ0Dn4e59nyvqrt2h01c079QOQ06Wi/ah4QVrZXlCsVLef VK9/WQaTNboPFAPvqObxHKnprlTeihAeJjtZ7qRURVhzLZYyRQsWQ14yJPpiOBYaJgQi 704dLQsun5lEYlnzFT5ENI1l/JVDyUAb2SFTKueSfw+5MtMTRAxrOj4vEHv+D4VSjIOu Rc9o6GCgVWAfyxTVF5MXi6WHeir4lUtZzenqqcmTq/g9YRv8TmcoAFx0gJnlS39IvhjU 45Qw== Return-Path: To: Alistair Francis Cc: GNU C Library References: <20191024234106.27081-1-alistair.francis@wdc.com> <4c256164-2eb3-aab4-2a32-9d4e1e1f473e@linaro.org> From: Adhemerval Zanella Openpgp: preference=signencrypt Subject: Re: [PATCH v2] sysdeps/nanosleep: Use clock_nanosleep_time64 if avaliable Message-ID: <6e51cc8e-f6cd-ebbe-36d6-95df96199ad9@linaro.org> Date: Mon, 4 Nov 2019 16:30:11 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: On 04/11/2019 15:16, Alistair Francis wrote: > On Tue, Oct 29, 2019 at 1:16 PM Adhemerval Zanella > wrote: >> >> >> >> On 24/10/2019 20:41, Alistair Francis wrote: >> >> There is no need to replicate all the syscall logic, nanosleep can be implemented >> with __clock_nanosleep. You can do: >> >> int >> __nanosleep (const struct timespec *requested_time, >> struct timespec *remaining) >> { >> int ret = __clock_nanosleep (CLOCK_REALTIME, 0, requested_time, remaining); >> if (ret != 0) >> { >> __set_errno (-ret); >> return -1; >> } >> return ret; >> } > > This doesn't work as __clock_nanosleep() isn't avaliable in nptl so it > fails to compile. My v3 patch attempted to fix this, but that also > doesn't work and ends up squishing some patches together. For this case you will need to add __clock_nanosleep as a GLIBC_PRIVATE exported symbol from libc and add a hidden_proto/hidden_def for libc internal plt avoidance (as below). However, I agree with Joseph and Florian that for this case it would be better to move the symbol from libpthread to libc. I will send a patch to refactor it. diff --git a/sysdeps/unix/sysv/linux/Versions b/sysdeps/unix/sysv/linux/Versions index d385085c61..475abb5004 100644 --- a/sysdeps/unix/sysv/linux/Versions +++ b/sysdeps/unix/sysv/linux/Versions @@ -187,5 +187,6 @@ libc { __sigtimedwait; # functions used by nscd __netlink_assert_response; + __clock_nanosleep; } } diff --git a/sysdeps/unix/sysv/linux/clock_nanosleep.c b/sysdeps/unix/sysv/linux/clock_nanosleep.c index 1f240b8720..f3c6fd2d5f 100644 --- a/sysdeps/unix/sysv/linux/clock_nanosleep.c +++ b/sysdeps/unix/sysv/linux/clock_nanosleep.c @@ -42,7 +42,7 @@ __clock_nanosleep (clockid_t clock_id, int flags, const struct timespec *req, return (INTERNAL_SYSCALL_ERROR_P (r, err) ? INTERNAL_SYSCALL_ERRNO (r, err) : 0); } - +libc_hidden_def (__clock_nanosleep) versioned_symbol (libc, __clock_nanosleep, clock_nanosleep, GLIBC_2_17); /* clock_nanosleep moved to libc in version 2.17; old binaries may expect the symbol version it had in librt. */ diff --git a/sysdeps/unix/sysv/linux/nanosleep.c b/sysdeps/unix/sysv/linux/nanosleep.c index 6787909248..1e2481847b 100644 --- a/sysdeps/unix/sysv/linux/nanosleep.c +++ b/sysdeps/unix/sysv/linux/nanosleep.c @@ -25,7 +25,14 @@ int __nanosleep (const struct timespec *requested_time, struct timespec *remaining) { - return SYSCALL_CANCEL (nanosleep, requested_time, remaining); + //return SYSCALL_CANCEL (nanosleep, requested_time, remaining); + int ret = __clock_nanosleep (CLOCK_REALTIME, 0, requested_time, remaining); + if (ret != 0) + { + __set_errno (-ret); + return -1; + } + return ret; } hidden_def (__nanosleep) weak_alias (__nanosleep, nanosleep)