From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) by sourceware.org (Postfix) with ESMTPS id E7ADD388C008 for ; Mon, 21 Jun 2021 07:46:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E7ADD388C008 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=denx.de Received: from ktm (85-222-111-42.dynamic.chello.pl [85.222.111.42]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: lukma@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id BF57A828BC; Mon, 21 Jun 2021 09:46:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1624261575; bh=bD7ZQFtT3d6KP2B1qa/CreUHiyRFIgnfWlPWmbHo2LA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=R7rGA9na49U6NEVBRxB4LqLyWK7iMWbyxqDVMQW1ahDLIn+tcIlq36hs/ssEYJG8n uJz3n1+ONSjSZ74TN5FvT5049p7J796emQz1EXgtQLETSHj+qNn4b0pJOcQ6wYD+Ah r8W1Ud2WQrCDr5u6czIL4gjcTB6EzObR2B9KzFMEjDBrhBxt/xvdP4rniAHDUmSUeB EnqDUiNJWbycx0ZVor8vSBEwraZ/vQ7+rtdc/w0kHel3cM5YZJyX2k+Z56vFFGJX8s jfsEYnJGAfx/0nfXNRLgzHKsyI/UZvmpKa/u+bbmjhQUb9eLDfJ4vIDg0EBkxVeQB/ 6VCKXIJvopzQA== Date: Mon, 21 Jun 2021 09:46:14 +0200 From: Lukasz Majewski To: Adhemerval Zanella Cc: libc-alpha@sourceware.org, Carlos O'Donell Subject: Re: [PATCH 18/18] linux: Only use 64-bit syscall if required for clock_nanosleep Message-ID: <20210621094614.0a41138e@ktm> In-Reply-To: <20210617115104.1359598-19-adhemerval.zanella@linaro.org> References: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> <20210617115104.1359598-19-adhemerval.zanella@linaro.org> Organization: denx.de X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; boundary="Sig_/GhX9i1boUaXu_4hPPD4K3pV"; protocol="application/pgp-signature" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Jun 2021 07:46:18 -0000 --Sig_/GhX9i1boUaXu_4hPPD4K3pV Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable On Thu, 17 Jun 2021 08:51:04 -0300 Adhemerval Zanella wrote: > For !__ASSUME_TIME64_SYSCALLS there is no need to issue a 64-bit > syscall if the provided timeout fits in a 32-bit one. The 64-bit > usage should be rare since the timeout is a relative one. >=20 > Checked on i686-linux-gnu on a 4.15 kernel and on a 5.11 kernel > (with and without --enable-kernel=3D5.1) and on x86_64-linux-gnu. > --- > sysdeps/unix/sysv/linux/clock_nanosleep.c | 47 > +++++++++++++---------- time/Makefile | > 9 +++++ time/tst-clock_nanosleep.c | 40 > +++++++++++-------- 3 files changed, 60 insertions(+), 36 deletions(-) >=20 > diff --git a/sysdeps/unix/sysv/linux/clock_nanosleep.c > b/sysdeps/unix/sysv/linux/clock_nanosleep.c index > 007f1736cb..46b0f1e269 100644 --- > a/sysdeps/unix/sysv/linux/clock_nanosleep.c +++ > b/sysdeps/unix/sysv/linux/clock_nanosleep.c @@ -27,8 +27,9 @@ > /* We can simply use the syscall. The CPU clocks are not supported > with this function. */ > int > -__clock_nanosleep_time64 (clockid_t clock_id, int flags, const > struct __timespec64 *req, > - struct __timespec64 *rem) > +__clock_nanosleep_time64 (clockid_t clock_id, int flags, > + const struct __timespec64 *req, > + struct __timespec64 *rem) > { > if (clock_id =3D=3D CLOCK_THREAD_CPUTIME_ID) > return EINVAL; > @@ -37,33 +38,37 @@ __clock_nanosleep_time64 (clockid_t clock_id, int > flags, const struct __timespec=20 > /* If the call is interrupted by a signal handler or encounters an > error, it returns a positive value similar to errno. */ > + > #ifndef __NR_clock_nanosleep_time64 > # define __NR_clock_nanosleep_time64 __NR_clock_nanosleep > #endif > - int r =3D INTERNAL_SYSCALL_CANCEL (clock_nanosleep_time64, clock_id, > - flags, req, rem); > - > -#ifndef __ASSUME_TIME64_SYSCALLS > - if (r =3D=3D 0 || r !=3D -ENOSYS) > - return -r; > =20 > - if (! in_time_t_range (req->tv_sec)) > + int r; > +#ifdef __ASSUME_TIME64_SYSCALLS > + r =3D INTERNAL_SYSCALL_CANCEL (clock_nanosleep_time64, clock_id, > flags, req, > + rem); > +#else > + bool is32bit =3D in_time_t_range (req->tv_sec); > + if (!is32bit) > { > - __set_errno (EOVERFLOW); > - return -1; > + r =3D INTERNAL_SYSCALL_CANCEL (clock_nanosleep_time64, clock_id, > flags, > + req, rem); > + if (r =3D=3D -ENOSYS) > + r =3D -EOVERFLOW; > } > - > - struct timespec tr32; > - struct timespec ts32 =3D valid_timespec64_to_timespec (*req); > - r =3D INTERNAL_SYSCALL_CANCEL (clock_nanosleep, clock_id, flags, > - &ts32, &tr32); > - if (INTERNAL_SYSCALL_ERROR_P (r)) > + else > { > - if (r =3D=3D -EINTR && rem !=3D NULL && (flags & TIMER_ABSTIME) = =3D=3D 0) > - *rem =3D valid_timespec_to_timespec64 (tr32); > + struct timespec tr32; > + struct timespec ts32 =3D valid_timespec64_to_timespec (*req); > + r =3D INTERNAL_SYSCALL_CANCEL (clock_nanosleep, clock_id, flags, > &ts32, > + &tr32); > + if (INTERNAL_SYSCALL_ERROR_P (r)) > + { > + if (r =3D=3D -EINTR && rem !=3D NULL && (flags & TIMER_ABSTIME) > =3D=3D 0) > + *rem =3D valid_timespec_to_timespec64 (tr32); > + } > } > -#endif /* __ASSUME_TIME64_SYSCALLS */ > - > +#endif > return -r; > } > =20 > diff --git a/time/Makefile b/time/Makefile > index c84bd5d3ec..0bea84966c 100644 > --- a/time/Makefile > +++ b/time/Makefile > @@ -86,6 +86,15 @@ $(objpfx)tst-strftime2.out: $(gen-locales) > $(objpfx)tst-strftime3.out: $(gen-locales) > endif > =20 > +ifeq (yes,$(build-shared)) > +librt =3D $(common-objpfx)rt/librt.so > +else > +librt =3D $(common-objpfx)rt/librt.a > +endif > + > +$(objpfx)tst-clock_nanosleep: $(librt) > +$(objpfx)tst-clock_nanosleep-time64: $(librt) > + > tz-cflags =3D -DTZDIR=3D'"$(zonedir)"' \ > -DTZDEFAULT=3D'"$(localtime-file)"' \ > -DTZDEFRULES=3D'"$(posixrules-file)"' > diff --git a/time/tst-clock_nanosleep.c b/time/tst-clock_nanosleep.c > index 47537435c1..a5a7f9430a 100644 > --- a/time/tst-clock_nanosleep.c > +++ b/time/tst-clock_nanosleep.c > @@ -20,38 +20,48 @@ > #include > #include > #include > - > +#include > +#include > +#include > =20 > /* Test that clock_nanosleep() does sleep. */ > -static int > -do_test (void) > +static void > +clock_nanosleep_test (void) > { > /* Current time. */ > struct timeval tv1; > - (void) gettimeofday (&tv1, NULL); > + gettimeofday (&tv1, NULL); > =20 > - struct timespec ts; > - ts.tv_sec =3D 1; > - ts.tv_nsec =3D 0; > + struct timespec ts =3D { 1, 0 }; > TEMP_FAILURE_RETRY (clock_nanosleep (CLOCK_REALTIME, 0, &ts, &ts)); > =20 > /* At least one second must have passed. */ > struct timeval tv2; > - (void) gettimeofday (&tv2, NULL); > + gettimeofday (&tv2, NULL); > =20 > tv2.tv_sec -=3D tv1.tv_sec; > tv2.tv_usec -=3D tv1.tv_usec; > if (tv2.tv_usec < 0) > --tv2.tv_sec; > =20 > - if (tv2.tv_sec < 1) > - { > - puts ("clock_nanosleep didn't sleep long enough"); > - return 1; > - } > + TEST_VERIFY (tv2.tv_sec >=3D 1); > +} > + > +static void > +clock_nanosleep_large_timeout (void) > +{ > + support_create_timer (0, 100000000, false, NULL); > + struct timespec ts =3D { TYPE_MAXIMUM (time_t), 0 }; > + int r =3D clock_nanosleep (CLOCK_REALTIME, 0, &ts, NULL); > + TEST_VERIFY (r =3D=3D EINTR || r =3D=3D EOVERFLOW); > +} > =20 > +static int > +do_test (void) > +{ > + clock_nanosleep_test (); > + clock_nanosleep_large_timeout (); > return 0; > } > =20 > -#define TEST_FUNCTION do_test () > -#include "../test-skeleton.c" > +#include Reviewed-by: Lukasz Majewski Best regards, Lukasz Majewski -- DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma@denx.de --Sig_/GhX9i1boUaXu_4hPPD4K3pV Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- iQEzBAEBCgAdFiEEgAyFJ+N6uu6+XupJAR8vZIA0zr0FAmDQQ8cACgkQAR8vZIA0 zr2CDAgAtye4ZLq9IiMXHAbGtOQ6bZyYBEw2gF3yu2wkGJaeNVGN8fARUkTMO8pS zfPgvX5PIRl+LsuznSpU/aY44x20cTEP/Bm1PoLU8uoMf6PFGMoWK83mjSUdkzPJ pMbNbmZmk1N0dnlhM8ZsRarQMzOh+0Lv2LcxE3h7P1LFmn3VtKrNFKkaob+axr/F BXgpW2PmfCMs3JmFgBMgZlyfRrVyWZqamMU7WJvARl7kSz8/O1oKEfYZE8gv1IKi f7M/ve4A5zNFrx2Z4THzKbhWGP48rBYd85OxeqoCuPxYnCEg/H3O2BJj4oChFWu7 5kR4EDR77VKmDb/BMW22qXdZjVKkYQ== =CKb6 -----END PGP SIGNATURE----- --Sig_/GhX9i1boUaXu_4hPPD4K3pV--