From 1c4d58fe57162a5247356dc95aa6204f26cbf4fe Mon Sep 17 00:00:00 2001 From: Shehjar Tikoo Date: Wed, 10 Jun 2009 01:25:38 +0000 Subject: io-threads: Fix missed notification in sem_timedwait We're performing a calculation for skewing idle time that resulted in a timespec.tv_nsec value becoming larger than 1000 million or less than 0, forcing sem_timedwait to return with an EINVAL instead of waiting for a request notification from sem_post in iot_notify_worker(). This resulted in a missed notification that resulted in a hang followed by a timeout on the protocol/client side. This commit avoids the over- and under-flow in tv_nsec by skewing the tv_sec value instead. Signed-off-by: Anand V. Avati --- xlators/performance/io-threads/src/io-threads.c | 5 ++--- xlators/performance/io-threads/src/io-threads.h | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) (limited to 'xlators/performance/io-threads') diff --git a/xlators/performance/io-threads/src/io-threads.c b/xlators/performance/io-threads/src/io-threads.c index f16833609bf..c3575654bb5 100644 --- a/xlators/performance/io-threads/src/io-threads.c +++ b/xlators/performance/io-threads/src/io-threads.c @@ -79,16 +79,15 @@ int iot_notify_wait (iot_worker_t *worker, int idletime) { struct timeval tv; - struct timespec ts; + struct timespec ts = {0, }; int waitres = 0; gettimeofday (&tv, NULL); - ts.tv_sec = tv.tv_sec + idletime; /* Slightly skew the idle time for threads so that, we dont * have all of them rushing to exit at the same time, if * they've been idle. */ - ts.tv_nsec = skew_usec_idle_time (tv.tv_usec) * 1000; + ts.tv_sec = skew_sec_idle_time (tv.tv_sec + idletime); #ifndef HAVE_SPINLOCK waitres = pthread_cond_timedwait (&worker->notifier, &worker->qlock, diff --git a/xlators/performance/io-threads/src/io-threads.h b/xlators/performance/io-threads/src/io-threads.h index ec17356942b..3e806aa78e9 100644 --- a/xlators/performance/io-threads/src/io-threads.h +++ b/xlators/performance/io-threads/src/io-threads.h @@ -58,8 +58,8 @@ typedef enum { }iot_state_t; #define iot_worker_active(wrk) ((wrk)->state == IOT_STATE_ACTIVE) -#define MAX_IDLE_SKEW 1000 /* usecs */ -#define skew_usec_idle_time(usec) ((usec) + (random () % MAX_IDLE_SKEW)) +#define MAX_IDLE_SKEW 4 /* In secs */ +#define skew_sec_idle_time(sec) ((sec) + (random () % MAX_IDLE_SKEW)) #define IOT_DEFAULT_IDLE 180 /* In secs. */ #define IOT_MIN_THREADS 2 -- cgit