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 6A310388CC1D for ; Mon, 21 Jun 2021 07:45:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6A310388CC1D 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 4C98E828BC; Mon, 21 Jun 2021 09:45:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1624261515; bh=MbM9AuyqI3EpWRjxLB5yaWpUCfZxVOfSFoy/lQVUZV4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=xRm9aF6VIwe6Eih96IyDvwd/LIc5bx3HLR1tAnQ0IeeGI307oWUmUI9FRsOjWKHdH +bAHjoo0WypKSpwB0zGZKX9L5pvDO+xKf+P28f7D1DwoEjkaTwx42bflG0eUjJtncR /zpPQWVSI1uTUsYYq+K5EeeAf/o+C+sfxR/RIBqiaX/XoBkInjLZPWHILq5lmCutUP BrDfZ6pLTvHtWZUW5eD48mkTWLrms7vGxoDA2RNg8hrly0SfHX9V1kYy6W5buWzqxH s+PCYfBCdS1/Fsaa4ljHUg7u3EzoDxqsgLDxxHCmkSwhLORg8+gUi6VLgsVJj52MK9 C76o1PWN0no8g== Date: Mon, 21 Jun 2021 09:45:14 +0200 From: Lukasz Majewski To: Adhemerval Zanella Cc: libc-alpha@sourceware.org, Carlos O'Donell Subject: Re: [PATCH 17/18] linux: Only use 64-bit syscall if required for internal futex Message-ID: <20210621094514.0fdafe92@ktm> In-Reply-To: <20210617115104.1359598-18-adhemerval.zanella@linaro.org> References: <20210617115104.1359598-1-adhemerval.zanella@linaro.org> <20210617115104.1359598-18-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_/qLXDnR7=fueaRngXiehl1MF"; 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:45:18 -0000 --Sig_/qLXDnR7=fueaRngXiehl1MF Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable On Thu, 17 Jun 2021 08:51:03 -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. > --- > nptl/futex-internal.c | 52 > +++++++++++++++++++++++------------ sysdeps/nptl/futex-internal.h | > 24 ++++++++++------ 2 files changed, 50 insertions(+), 26 deletions(-) >=20 > diff --git a/nptl/futex-internal.c b/nptl/futex-internal.c > index 850bf4fd83..277e60986e 100644 > --- a/nptl/futex-internal.c > +++ b/nptl/futex-internal.c > @@ -32,9 +32,6 @@ __futex_abstimed_wait_common32 (unsigned int* > futex_word, struct timespec ts32, *pts32 =3D NULL; > if (abstime !=3D NULL) > { > - if (! in_time_t_range (abstime->tv_sec)) > - return -EOVERFLOW; > - > ts32 =3D valid_timespec64_to_timespec (*abstime); > pts32 =3D &ts32; > } > @@ -52,12 +49,28 @@ __futex_abstimed_wait_common32 (unsigned int* > futex_word,=20 > static int > __futex_abstimed_wait_common64 (unsigned int* futex_word, > - unsigned int expected, clockid_t > clockid, > + unsigned int expected, int op, > const struct __timespec64* abstime, > int private, bool cancel) > { > - unsigned int clockbit; > + if (cancel) > + return INTERNAL_SYSCALL_CANCEL (futex_time64, futex_word, op, > expected, > + abstime, NULL /* Unused. */, > + FUTEX_BITSET_MATCH_ANY); > + else > + return INTERNAL_SYSCALL_CALL (futex_time64, futex_word, op, > expected, > + abstime, NULL /* Ununsed. */, > + FUTEX_BITSET_MATCH_ANY); > +} > + > +static int > +__futex_abstimed_wait_common (unsigned int* futex_word, > + unsigned int expected, clockid_t > clockid, > + const struct __timespec64* abstime, > + int private, bool cancel) > +{ > int err; > + unsigned int clockbit; > =20 > /* Work around the fact that the kernel rejects negative timeout > values despite them being valid. */ > @@ -70,16 +83,19 @@ __futex_abstimed_wait_common64 (unsigned int* > futex_word, clockbit =3D (clockid =3D=3D CLOCK_REALTIME) ? > FUTEX_CLOCK_REALTIME : 0; int op =3D __lll_private_flag > (FUTEX_WAIT_BITSET | clockbit, private);=20 > - if (cancel) > - err =3D INTERNAL_SYSCALL_CANCEL (futex_time64, futex_word, op, > expected, > - abstime, NULL /* Unused. */, > - FUTEX_BITSET_MATCH_ANY); > +#ifdef __ASSUME_TIME64_SYSCALLS > + err =3D __futex_abstimed_wait_common64 (futex_word, expected, op, > abstime, > + private, cancel); > +#else > + bool is32bit =3D abstime !=3D NULL ? in_time_t_range (abstime->tv_sec) > : true; > + if (!is32bit) > + { > + err =3D __futex_abstimed_wait_common64 (futex_word, expected, > op, abstime, > + private, cancel); > + if (err =3D=3D -ENOSYS) > + err =3D -EOVERFLOW; > + } > else > - err =3D INTERNAL_SYSCALL_CALL (futex_time64, futex_word, op, > expected, > - abstime, NULL /* Ununsed. */, > - FUTEX_BITSET_MATCH_ANY); > -#ifndef __ASSUME_TIME64_SYSCALLS > - if (err =3D=3D -ENOSYS) > err =3D __futex_abstimed_wait_common32 (futex_word, expected, op, > abstime, private, cancel); > #endif > @@ -109,8 +125,8 @@ __futex_abstimed_wait64 (unsigned int* > futex_word, unsigned int expected, clockid_t clockid, > const struct __timespec64* abstime, int > private) { > - return __futex_abstimed_wait_common64 (futex_word, expected, > clockid, > - abstime, private, false); > + return __futex_abstimed_wait_common (futex_word, expected, clockid, > + abstime, private, false); > } > libc_hidden_def (__futex_abstimed_wait64) > =20 > @@ -120,7 +136,7 @@ __futex_abstimed_wait_cancelable64 (unsigned int* > futex_word, const struct __timespec64* abstime, > int private) > { > - return __futex_abstimed_wait_common64 (futex_word, expected, > clockid, > - abstime, private, true); > + return __futex_abstimed_wait_common (futex_word, expected, clockid, > + abstime, private, true); > } > libc_hidden_def (__futex_abstimed_wait_cancelable64) > diff --git a/sysdeps/nptl/futex-internal.h > b/sysdeps/nptl/futex-internal.h index 969ab2bf4b..b54fdd44c1 100644 > --- a/sysdeps/nptl/futex-internal.h > +++ b/sysdeps/nptl/futex-internal.h > @@ -254,15 +254,23 @@ static __always_inline int > futex_lock_pi64 (int *futex_word, const struct __timespec64 *abstime, > int private) > { > - int err =3D INTERNAL_SYSCALL_CALL (futex_time64, futex_word, > - __lll_private_flag > - (FUTEX_LOCK_PI, private), 0, > abstime); -#ifndef __ASSUME_TIME64_SYSCALLS > - if (err =3D=3D -ENOSYS) > + int err; > +#ifdef __ASSUME_TIME64_SYSCALLS > + err =3D INTERNAL_SYSCALL_CALL (futex_time64, futex_word, > + __lll_private_flag (FUTEX_LOCK_PI, > private), 0, > + abstime); > +#else > + bool is32bit =3D abstime !=3D NULL ? in_time_t_range (abstime->tv_sec) > : true; > + if (!is32bit) > + { > + err =3D INTERNAL_SYSCALL_CALL (futex_time64, futex_word, > + __lll_private_flag > (FUTEX_LOCK_PI, private), > + 0, abstime); > + if (err =3D=3D -ENOSYS) > + err =3D -EOVERFLOW; > + } > + else > { > - if (abstime !=3D NULL && ! in_time_t_range (abstime->tv_sec)) > - return EOVERFLOW; > - > struct timespec ts32; > if (abstime !=3D NULL) > ts32 =3D valid_timespec64_to_timespec (*abstime); 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_/qLXDnR7=fueaRngXiehl1MF Content-Type: application/pgp-signature Content-Description: OpenPGP digital signature -----BEGIN PGP SIGNATURE----- iQEzBAEBCgAdFiEEgAyFJ+N6uu6+XupJAR8vZIA0zr0FAmDQQ4oACgkQAR8vZIA0 zr37lwf+O5w8xHtgwFP374Fpn56FqnOJ2Jl22wpNc2rU7bJfRFOOEUxp2Lp7nXXc tc1I/04JTNq9xExgpPIZ0/nSHba7qWRiyRqxbmIigJN2nJUUhh9dqx1f0/N+32l3 hv0Hg3Z8PM0gzPlc+352UwACQOhlpHLvQLrdST7Prhm/ZgzSj9ISDRCBv5QpM8hx 3s8TYGn4ClbMlOZoH7hTaWGgHQP14SMYpd0Pgas0x5F2jUjG0mBcYA28hNWO3lyc DxYM8jX6Udr9YEES3v5RxRIogIu72+7IbAjowAjmrkHJbaLwE20L1PDA82t6azoO /sekAnSuIjpTUaUOV/rXHNsCJbdN9w== =Hnm4 -----END PGP SIGNATURE----- --Sig_/qLXDnR7=fueaRngXiehl1MF--