Added FORCE_MONOTONIC_FIX CFLAG to avoid hangs on timedwait (#202 #142)

This commit is contained in:
Wolfgang Hommel
2019-08-23 10:29:53 +02:00
parent 30ba0b852a
commit ba32d1b01c
5 changed files with 21 additions and 3 deletions

3
NEWS
View File

@@ -19,6 +19,9 @@ Since 0.9.7:
- Updated glibc compatibility settings for various platforms
- Support for clock_nanosleep() with realtime and monotonic clocks
- Support for epoll_wait(), epoll_pwait(), and pselect()
- src/Makefile CFLAG FORCE_MONOTONIC_FIX should be set (only) on
platforms where the test program hangs forever at the
CLOCK_MONOTONIC test.
Since 0.9.6:
- Julien Gilli added an option to disable monotonic time faking

6
README
View File

@@ -83,6 +83,12 @@ documentation whether it can be achieved by using libfaketime directly.
e.g., by checking whether certain environment variables are set or whether
libfaketime-specific files are present.
* CLOCK_MONOTONIC test: Running "make test" performs a series of tests after
successful compilation of the libfaketime library. On some platforms, the
"CLOCK_MONOTONIC test" will apparently hang forever. If and only if this
happens on your platform, add the CFLAG -DFORCE_MONOTONIC_FIX to
src/Makefile and recompile libfaketime. Do not set FORCE_MONOTONIC_FIX on
platforms where the test does not hang.
3. Installation
---------------

View File

@@ -30,6 +30,13 @@
# FAKE_PTHREAD
# - Intercept pthread_cond_timedwait
#
# FORCE_MONOTONIC_FIX
# - If the test program hangs forever on
# " pthread_cond_timedwait: CLOCK_MONOTONIC test
# (Intentionally sleeping 1 second...) "
# then add -DFORCE_MONOTONIC_FIX to CFLAGS and recompile.
# (This is a platform-specific issue we cannot handle at run-time.)
#
# MULTI_ARCH
# - If MULTI_ARCH is set, the faketime wrapper program will put a literal
# $LIB into the LD_PRELOAD environment variable it creates, which makes
@@ -50,8 +57,8 @@
# Change PREFIX to where you want libfaketime (libraries and wrapper binary) installed.
# LIBDIRNAME is relative to PREFIX. The default is to install into $PREFIX/lib/faketime,
# but you can set LIBDIRNAME to, e.g., /lib64 if you want to install it elsewhere.
# LIBDIRNAME has been introduced to support MultiLib systems. Please do not change the
# default value on MultiArch systems.
# LIBDIRNAME has been introduced to support MultiLib systems. Please do not change the
# default value on MultiArch systems.
#
# For testing in the current directory without installation, try make PREFIX= LIBDIRNAME='.'

View File

@@ -3124,9 +3124,11 @@ int pthread_cond_timedwait_common(pthread_cond_t *cond, pthread_mutex_t *mutex,
fake time needs to be passed to pthread_cond_timedwait for
CLOCK_MONOTONIC. */
#ifndef __ARM_ARCH
#ifndef FORCE_MONOTONIC_FIX
if(clk_id == CLOCK_MONOTONIC)
timespecadd(&faketime, &tdiff_actual, &tp);
else
#endif
#endif
timespecadd(&realtime, &tdiff_actual, &tp);

View File

@@ -97,7 +97,7 @@ void* pthread_test(void* args)
timeToWait.tv_nsec = now.tv_nsec;
printf("pthread_cond_timedwait: CLOCK_MONOTONIC test\n");
printf("(Intentionally sleeping 1 second...)\n");
printf("(Intentionally sleeping 1 second..., see docs about CLOCK_MONOTONIC test)\n");
fflush(stdout);
pthread_mutex_lock(&fakeMutex);