mutex: don't attempt to use CLOCK_MONOTONIC
authorJens Axboe <axboe@kernel.dk>
Mon, 20 Feb 2012 08:18:43 +0000 (09:18 +0100)
committerJens Axboe <axboe@kernel.dk>
Mon, 20 Feb 2012 08:18:43 +0000 (09:18 +0100)
It's a bit of a mess. Some platforms don't have
pthread_condattr_setclock(), some have it but it appears NOT to set
the block correctly.

Accept that we have to use the realtime clock for timed mutex and just
don't touch the clock settings.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
mutex.c
os/os-aix.h
os/os-freebsd.h
os/os-linux.h

diff --git a/mutex.c b/mutex.c
index 94e11884424cd203cd1f3357fef33250ffbd94eb..3b94beffc7342ae2f13879126e2da3433cb5bbf1 100644 (file)
--- a/mutex.c
+++ b/mutex.c
@@ -17,8 +17,6 @@
 #include "time.h"
 #include "gettime.h"
 
 #include "time.h"
 #include "gettime.h"
 
-static clockid_t fio_clk_id = CLOCK_REALTIME;
-
 void fio_mutex_remove(struct fio_mutex *mutex)
 {
        pthread_cond_destroy(&mutex->cond);
 void fio_mutex_remove(struct fio_mutex *mutex)
 {
        pthread_cond_destroy(&mutex->cond);
@@ -63,9 +61,6 @@ struct fio_mutex *fio_mutex_init(int value)
        pthread_condattr_init(&cond);
 #ifdef FIO_HAVE_PSHARED_MUTEX
        pthread_condattr_setpshared(&cond, PTHREAD_PROCESS_SHARED);
        pthread_condattr_init(&cond);
 #ifdef FIO_HAVE_PSHARED_MUTEX
        pthread_condattr_setpshared(&cond, PTHREAD_PROCESS_SHARED);
-#endif
-#ifdef FIO_HAVE_PTHREAD_CONDATTR_SETCLOCK
-       pthread_condattr_setclock(&cond, fio_clk_id);
 #endif
        pthread_cond_init(&mutex->cond, &cond);
 
 #endif
        pthread_cond_init(&mutex->cond, &cond);
 
@@ -97,10 +92,9 @@ int fio_mutex_down_timeout(struct fio_mutex *mutex, unsigned int seconds)
        struct timespec t;
        int ret = 0;
 
        struct timespec t;
        int ret = 0;
 
-       fio_gettime(&tv_s, NULL);
-
-       clock_gettime(fio_clk_id, &t);
-       t.tv_sec += seconds;
+       gettimeofday(&tv_s, NULL);
+       t.tv_sec = tv_s.tv_sec + seconds;
+       t.tv_nsec = tv_s.tv_usec * 1000;
 
        pthread_mutex_lock(&mutex->lock);
 
 
        pthread_mutex_lock(&mutex->lock);
 
@@ -199,19 +193,3 @@ void fio_mutex_up_write(struct fio_mutex *mutex)
                pthread_cond_signal(&mutex->cond);
        pthread_mutex_unlock(&mutex->lock);
 }
                pthread_cond_signal(&mutex->cond);
        pthread_mutex_unlock(&mutex->lock);
 }
-
-static void fio_init fio_mutex_global_init(void)
-{
-#ifdef FIO_HAVE_PTHREAD_CONDATTR_SETCLOCK
-#ifdef FIO_HAVE_CLOCK_MONOTONIC
-       pthread_condattr_t cond;
-
-       pthread_condattr_init(&cond);
-
-       if (!pthread_condattr_setclock(&cond, CLOCK_MONOTONIC))
-               fio_clk_id = CLOCK_MONOTONIC;
-
-       pthread_condattr_destroy(&cond);
-#endif
-#endif
-}
index 3cbc80f32c47fd681505ac2916037289cc4154ba..2f75bf8f3f45fec7f0bdcc1f0234cd3b43172a2c 100644 (file)
@@ -14,7 +14,6 @@
 #define FIO_HAVE_ODIRECT
 #define FIO_USE_GENERIC_RAND
 #define FIO_HAVE_CLOCK_MONOTONIC
 #define FIO_HAVE_ODIRECT
 #define FIO_USE_GENERIC_RAND
 #define FIO_HAVE_CLOCK_MONOTONIC
-#define FIO_HAVE_PTHREAD_CONDATTR_SETCLOCK
 
 /*
  * This is broken on AIX if _LARGE_FILES is defined...
 
 /*
  * This is broken on AIX if _LARGE_FILES is defined...
index 976bd8427007bbb2a01573a02c30c4c24c6eab36..9fbc6236cbbdc74a41bc45893598816b89a65c65 100644 (file)
@@ -19,7 +19,6 @@
 #define FIO_HAVE_CHARDEV_SIZE
 #define FIO_HAVE_GETTID
 #define FIO_HAVE_CLOCK_MONOTONIC
 #define FIO_HAVE_CHARDEV_SIZE
 #define FIO_HAVE_GETTID
 #define FIO_HAVE_CLOCK_MONOTONIC
-#define FIO_HAVE_PTHREAD_CONDATTR_SETCLOCK
 
 #define OS_MAP_ANON            MAP_ANON
 
 
 #define OS_MAP_ANON            MAP_ANON
 
index 61dfa30315c9d05e319866465dcc78a963e87db7..9f547fffe635ad0f652b1baa6a579032bdacc801 100644 (file)
@@ -44,7 +44,6 @@
 #define FIO_HAVE_TRIM
 #define FIO_HAVE_BINJECT
 #define FIO_HAVE_CLOCK_MONOTONIC
 #define FIO_HAVE_TRIM
 #define FIO_HAVE_BINJECT
 #define FIO_HAVE_CLOCK_MONOTONIC
-#define FIO_HAVE_PTHREAD_CONDATTR_SETCLOCK
 #define FIO_HAVE_GETTID
 
 /*
 #define FIO_HAVE_GETTID
 
 /*