[PATCHv2] aio_suspend64: Fix clock discrepancy

Message ID 20250314194749.1238016-1-samuel.thibault@ens-lyon.org (mailing list archive)
State Accepted
Delegated to: Adhemerval Zanella Netto
Headers
Series [PATCHv2] aio_suspend64: Fix clock discrepancy |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent
linaro-tcwg-bot/tcwg_glibc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_glibc_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 success Test passed
redhat-pt-bot/TryBot-32bit success Build for i686

Commit Message

Samuel Thibault March 14, 2025, 7:47 p.m. UTC
  cc5d5852c65e ("y2038: Convert aio_suspend to support 64 bit time")
switched from __clock_gettime (CLOCK_REALTIME, &now); to __clock_gettime64
(CLOCK_MONOTONIC, &ts);, but pthread_cond_timedwait is based on the
absolute realtime clock, so migrate to using pthread_cond_clockwait to
select CLOCK_MONOTONIC. Also fix AIO_MISC_WAIT into passing
CLOCK_MONOTONIC to __futex_abstimed_wait64.
---
 rt/aio_suspend.c        | 3 ++-
 sysdeps/nptl/aio_misc.h | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)
  

Comments

Adhemerval Zanella Netto March 20, 2025, 7:30 p.m. UTC | #1
On 14/03/25 16:47, Samuel Thibault wrote:
> cc5d5852c65e ("y2038: Convert aio_suspend to support 64 bit time")
> switched from __clock_gettime (CLOCK_REALTIME, &now); to __clock_gettime64
> (CLOCK_MONOTONIC, &ts);, but pthread_cond_timedwait is based on the
> absolute realtime clock, so migrate to using pthread_cond_clockwait to
> select CLOCK_MONOTONIC. Also fix AIO_MISC_WAIT into passing
> CLOCK_MONOTONIC to __futex_abstimed_wait64.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

> ---
>  rt/aio_suspend.c        | 3 ++-
>  sysdeps/nptl/aio_misc.h | 2 +-
>  2 files changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/rt/aio_suspend.c b/rt/aio_suspend.c
> index 2257cd80d4..75d9d515d0 100644
> --- a/rt/aio_suspend.c
> +++ b/rt/aio_suspend.c
> @@ -195,7 +195,8 @@ ___aio_suspend_time64 (const struct aiocb *const list[], int nent,
>        result = do_aio_misc_wait (&cntr, timeout == NULL ? NULL : &ts);
>  #else
>        struct timespec ts32 = valid_timespec64_to_timespec (ts);
> -      result = pthread_cond_timedwait (&cond, &__aio_requests_mutex,
> +      result = pthread_cond_clockwait (&cond, &__aio_requests_mutex,
> +				       CLOCK_MONOTONIC,
>  				       timeout == NULL ? NULL : &ts32);
>  #endif
>  
> diff --git a/sysdeps/nptl/aio_misc.h b/sysdeps/nptl/aio_misc.h
> index ddc5acc379..87fd759f13 100644
> --- a/sysdeps/nptl/aio_misc.h
> +++ b/sysdeps/nptl/aio_misc.h
> @@ -50,7 +50,7 @@
>  		FUTEX_PRIVATE);						      \
>  	    else							      \
>  	      status = __futex_abstimed_wait64 ((unsigned int *) futexaddr,   \
> -		oldval, CLOCK_REALTIME, timeout, FUTEX_PRIVATE); 	      \
> +		oldval, CLOCK_MONOTONIC, timeout, FUTEX_PRIVATE); 	      \
>  	    if (status != EAGAIN)					      \
>  	      break;							      \
>  									      \
  

Patch

diff --git a/rt/aio_suspend.c b/rt/aio_suspend.c
index 2257cd80d4..75d9d515d0 100644
--- a/rt/aio_suspend.c
+++ b/rt/aio_suspend.c
@@ -195,7 +195,8 @@  ___aio_suspend_time64 (const struct aiocb *const list[], int nent,
       result = do_aio_misc_wait (&cntr, timeout == NULL ? NULL : &ts);
 #else
       struct timespec ts32 = valid_timespec64_to_timespec (ts);
-      result = pthread_cond_timedwait (&cond, &__aio_requests_mutex,
+      result = pthread_cond_clockwait (&cond, &__aio_requests_mutex,
+				       CLOCK_MONOTONIC,
 				       timeout == NULL ? NULL : &ts32);
 #endif
 
diff --git a/sysdeps/nptl/aio_misc.h b/sysdeps/nptl/aio_misc.h
index ddc5acc379..87fd759f13 100644
--- a/sysdeps/nptl/aio_misc.h
+++ b/sysdeps/nptl/aio_misc.h
@@ -50,7 +50,7 @@ 
 		FUTEX_PRIVATE);						      \
 	    else							      \
 	      status = __futex_abstimed_wait64 ((unsigned int *) futexaddr,   \
-		oldval, CLOCK_REALTIME, timeout, FUTEX_PRIVATE); 	      \
+		oldval, CLOCK_MONOTONIC, timeout, FUTEX_PRIVATE); 	      \
 	    if (status != EAGAIN)					      \
 	      break;							      \
 									      \