fi
print_config "POSIX pshared support" "$posix_pshared"
+##########################################
+# POSIX pthread_condattr_setclock() probe
+if test "$pthread_condattr_setclock" != "yes" ; then
+ pthread_condattr_setclock="no"
+fi
+cat > $TMPC <<EOF
+#include <pthread.h>
+int main(void)
+{
+ pthread_condattr_t condattr;
+ pthread_condattr_setclock(&condattr, CLOCK_MONOTONIC);
+ return 0;
+}
+EOF
+if compile_prog "" "$LIBS" "pthread_condattr_setclock" ; then
+ pthread_condattr_setclock=yes
+fi
+print_config "pthread_condattr_setclock() support" "$pthread_condattr_setclock"
+
##########################################
# solaris aio probe
if test "$solaris_aio" != "yes" ; then
if test "$posix_pshared" = "yes" ; then
output_sym "CONFIG_PSHARED"
fi
+if test "$pthread_condattr_setclock" = "yes" ; then
+ output_sym "CONFIG_PTHREAD_CONDATTR_SETCLOCK"
+fi
if test "$have_asprintf" = "yes" ; then
output_sym "CONFIG_HAVE_ASPRINTF"
fi
int fio_sem_down_timeout(struct fio_sem *sem, unsigned int msecs)
{
- struct timeval tv_s;
struct timespec base;
struct timespec t;
int ret = 0;
assert(sem->magic == FIO_SEM_MAGIC);
- gettimeofday(&tv_s, NULL);
- base.tv_sec = t.tv_sec = tv_s.tv_sec;
- base.tv_nsec = t.tv_nsec = tv_s.tv_usec * 1000;
+#ifdef CONFIG_PTHREAD_CONDATTR_SETCLOCK
+ clock_gettime(CLOCK_MONOTONIC, &t);
+#else
+ clock_gettime(CLOCK_REALTIME, &t);
+#endif
+
+ base = t;
t.tv_sec += msecs / 1000;
t.tv_nsec += ((msecs * 1000000ULL) % 1000000000);
{
struct helper_data *hd = data;
unsigned int msec_to_next_event, next_log, next_ss = STEADYSTATE_MSEC;
- struct timeval tv;
struct timespec ts, last_du, last_ss;
int ret = 0;
sk_out_assign(hd->sk_out);
- gettimeofday(&tv, NULL);
- ts.tv_sec = tv.tv_sec;
- ts.tv_nsec = tv.tv_usec * 1000;
+#ifdef CONFIG_PTHREAD_CONDATTR_SETCLOCK
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+#else
+ clock_gettime(CLOCK_REALTIME, &ts);
+#endif
memcpy(&last_du, &ts, sizeof(ts));
memcpy(&last_ss, &ts, sizeof(ts));
pthread_mutex_lock(&hd->lock);
pthread_cond_timedwait(&hd->cond, &hd->lock, &ts);
- gettimeofday(&tv, NULL);
- ts.tv_sec = tv.tv_sec;
- ts.tv_nsec = tv.tv_usec * 1000;
+#ifdef CONFIG_PTHREAD_CONDATTR_SETCLOCK
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+#else
+ clock_gettime(CLOCK_REALTIME, &ts);
+#endif
if (hd->reset) {
memcpy(&last_du, &ts, sizeof(ts));
int i, ret;
struct timespec ts;
pthread_attr_t tattr;
+ pthread_condattr_t cattr;
struct idle_prof_thread *ipt;
ipc.nr_cpus = cpus_online();
if (ipc.opt == IDLE_PROF_OPT_NONE)
return;
+ ret = pthread_condattr_init(&cattr);
+ assert(ret == 0);
+#ifdef CONFIG_PTHREAD_CONDATTR_SETCLOCK
+ ret = pthread_condattr_setclock(&cattr, CLOCK_MONOTONIC);
+ assert(ret == 0);
+#endif
+
if ((ret = pthread_attr_init(&tattr))) {
log_err("fio: pthread_attr_init %s\n", strerror(ret));
return;
break;
}
- if ((ret = pthread_cond_init(&ipt->cond, NULL))) {
+ if ((ret = pthread_cond_init(&ipt->cond, &cattr))) {
ipc.status = IDLE_PROF_STATUS_ABORT;
log_err("fio: pthread_cond_init %s\n", strerror(ret));
break;
pthread_mutex_lock(&ipt->init_lock);
while ((ipt->state != TD_EXITED) &&
(ipt->state!=TD_INITIALIZED)) {
- fio_gettime(&ts, NULL);
+#ifdef CONFIG_PTHREAD_CONDATTR_SETCLOCK
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+#else
+ clock_gettime(CLOCK_REALTIME, &ts);
+#endif
ts.tv_sec += 1;
pthread_cond_timedwait(&ipt->cond, &ipt->init_lock, &ts);
}
return ret;
}
#endif
+
+#ifdef CONFIG_PTHREAD_CONDATTR_SETCLOCK
+ ret = pthread_condattr_setclock(&cattr, CLOCK_MONOTONIC);
+ if (ret) {
+ log_err("pthread_condattr_setclock: %s\n", strerror(ret));
+ return ret;
+ }
+#endif
+
ret = pthread_cond_init(cond, &cattr);
if (ret) {
log_err("pthread_cond_init: %s\n", strerror(ret));
* Copyright (C) 2016 Jens Axboe
*
*/
+
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
static void init_thread(struct thread_data *thread)
{
- pthread_cond_init(&thread->cond, NULL);
- pthread_cond_init(&thread->done_cond, NULL);
+ pthread_condattr_t cattr;
+ int ret;
+
+ ret = pthread_condattr_init(&cattr);
+ assert(ret == 0);
+#ifdef CONFIG_PTHREAD_CONDATTR_SETCLOCK
+ ret = pthread_condattr_setclock(&cattr, CLOCK_MONOTONIC);
+ assert(ret == 0);
+#endif
+ pthread_cond_init(&thread->cond, &cattr);
+ pthread_cond_init(&thread->done_cond, &cattr);
pthread_mutex_init(&thread->lock, NULL);
pthread_mutex_init(&thread->done_lock, NULL);
thread->exit = 0;
pthread_mutex_lock(&thread->done_lock);
if (fn) {
- struct timeval tv;
struct timespec ts;
- gettimeofday(&tv, NULL);
- ts.tv_sec = tv.tv_sec + 1;
- ts.tv_nsec = tv.tv_usec * 1000ULL;
+#ifdef CONFIG_PTHREAD_CONDATTR_SETCLOCK
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+#else
+ clock_gettime(CLOCK_REALTIME, &ts);
+#endif
+ ts.tv_sec++;
pthread_cond_timedwait(&thread->done_cond, &thread->done_lock, &ts);
fn(wt);
int main(int argc, char *argv[])
{
+ pthread_condattr_t cattr;
struct timeval s, re, we;
struct reader_thread *rt;
struct writer_thread *wt;
size_t bytes;
off_t off;
int fd, seq;
+ int ret;
if (parse_options(argc, argv))
return 1;
seq = 0;
bytes = 0;
+ ret = pthread_condattr_init(&cattr);
+ assert(ret == 0);
+#ifdef CONFIG_PTHREAD_CONDATTR_SETCLOCK
+ ret = pthread_condattr_setclock(&cattr, CLOCK_MONOTONIC);
+ assert(ret == 0);
+#endif
+
gettimeofday(&s, NULL);
while (sb.st_size) {
struct work_item *work;
size_t this_len;
struct timespec ts;
- struct timeval tv;
prune_done_entries(wt);
work->seq = ++seq;
work->writer = wt;
work->reader = rt;
- pthread_cond_init(&work->cond, NULL);
+ pthread_cond_init(&work->cond, &cattr);
pthread_mutex_init(&work->lock, NULL);
queue_work(rt, work);
- gettimeofday(&tv, NULL);
- ts.tv_sec = tv.tv_sec;
- ts.tv_nsec = tv.tv_usec * 1000ULL;
+#ifdef CONFIG_PTHREAD_CONDATTR_SETCLOCK
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+#else
+ clock_gettime(CLOCK_REALTIME, &ts);
+#endif
ts.tv_nsec += max_us * 1000ULL;
if (ts.tv_nsec >= 1000000000ULL) {
ts.tv_nsec -= 1000000000ULL;