diff options
| author | Kevin Vigor <kvigor@fb.com> | 2017-01-23 10:27:52 -0800 |
|---|---|---|
| committer | Kevin Vigor <kvigor@fb.com> | 2017-01-23 10:27:52 -0800 |
| commit | f80281c05e3f1c0ead5910586c7e81f047add623 (patch) | |
| tree | f58cac77acef73cfdf14d420bd10613ad3dc1850 /xlators/performance | |
| parent | 6f6a21f1bbc5131e70b42d89a5ac8d8aa709ad3f (diff) | |
| parent | b21c51e6f0baa5145923637f54e79d221ca59cff (diff) | |
Merge remote-tracking branch 'origin/release-3.8' into merge-3.8
Change-Id: Ie6c73dee0b6798af4a69c43c0b03c3d02ff36aa2
Diffstat (limited to 'xlators/performance')
| -rw-r--r-- | xlators/performance/io-threads/src/io-threads.c | 89 | ||||
| -rw-r--r-- | xlators/performance/io-threads/src/io-threads.h | 3 |
2 files changed, 70 insertions, 22 deletions
diff --git a/xlators/performance/io-threads/src/io-threads.c b/xlators/performance/io-threads/src/io-threads.c index 5ab38890df3..79845316315 100644 --- a/xlators/performance/io-threads/src/io-threads.c +++ b/xlators/performance/io-threads/src/io-threads.c @@ -153,9 +153,8 @@ iot_worker (void *data) struct timespec sleep_till = {0, }; int ret = 0; int pri = -1; - char timeout = 0; - char bye = 0; struct timespec sleep = {0,}; + gf_boolean_t bye = _gf_false; conf = data; this = conf->this; @@ -169,6 +168,12 @@ iot_worker (void *data) pri = -1; } while (conf->queue_size == 0) { + if (conf->down) { + bye = _gf_true;/*Avoid sleep*/ + break; + } + + conf->sleep_count++; clock_gettime (CLOCK_REALTIME_COARSE, &sleep_till); sleep_till.tv_sec += conf->idle_time; @@ -179,48 +184,48 @@ iot_worker (void *data) &sleep_till); conf->sleep_count--; - if (ret == ETIMEDOUT) { - timeout = 1; + if (conf->down || ret == ETIMEDOUT) { + bye = _gf_true; break; } } - if (timeout) { - if (conf->curr_count > IOT_MIN_THREADS) { + if (bye) { + if (conf->down || + conf->curr_count > IOT_MIN_THREADS) { conf->curr_count--; - bye = 1; + if (conf->curr_count == 0) + pthread_cond_broadcast (&conf->cond); gf_msg_debug (conf->this->name, 0, - "timeout, terminated. conf->curr_count=%d", + "terminated. " + "conf->curr_count=%d", conf->curr_count); } else { - timeout = 0; + bye = _gf_false; } } - stub = __iot_dequeue (conf, &pri, &sleep); - if (!stub && (sleep.tv_sec || sleep.tv_nsec)) { - pthread_cond_timedwait(&conf->cond, - &conf->mutex, &sleep); - pthread_mutex_unlock(&conf->mutex); - continue; + if (!bye) { + stub = __iot_dequeue (conf, &pri, &sleep); + if (!stub && (sleep.tv_sec || sleep.tv_nsec)) { + pthread_cond_timedwait(&conf->cond, + &conf->mutex, + &sleep); + pthread_mutex_unlock(&conf->mutex); + continue; + } } } pthread_mutex_unlock (&conf->mutex); if (stub) /* guard against spurious wakeups */ call_resume (stub); + stub = NULL; if (bye) break; } - if (pri != -1) { - pthread_mutex_lock (&conf->mutex); - { - conf->ac_iot_count[pri]--; - } - pthread_mutex_unlock (&conf->mutex); - } return NULL; } @@ -975,6 +980,7 @@ init (xlator_t *this) "pthread_cond_init failed (%d)", ret); goto out; } + conf->cond_inited = _gf_true; if ((ret = pthread_mutex_init(&conf->mutex, NULL)) != 0) { gf_msg (this->name, GF_LOG_ERROR, 0, @@ -982,6 +988,7 @@ init (xlator_t *this) "pthread_mutex_init failed (%d)", ret); goto out; } + conf->mutex_inited = _gf_true; set_stack_size (conf); @@ -1039,12 +1046,50 @@ out: return ret; } +static void +iot_exit_threads (iot_conf_t *conf) +{ + pthread_mutex_lock (&conf->mutex); + { + conf->down = _gf_true; + /*Let all the threads know that xl is going down*/ + pthread_cond_broadcast (&conf->cond); + while (conf->curr_count)/*Wait for threads to exit*/ + pthread_cond_wait (&conf->cond, &conf->mutex); + } + pthread_mutex_unlock (&conf->mutex); +} + +int +notify (xlator_t *this, int32_t event, void *data, ...) +{ + iot_conf_t *conf = this->private; + + if (GF_EVENT_PARENT_DOWN == event) + iot_exit_threads (conf); + + default_notify (this, event, data); + + return 0; +} void fini (xlator_t *this) { iot_conf_t *conf = this->private; + if (!conf) + return; + + if (conf->mutex_inited && conf->cond_inited) + iot_exit_threads (conf); + + if (conf->cond_inited) + pthread_cond_destroy (&conf->cond); + + if (conf->mutex_inited) + pthread_mutex_destroy (&conf->mutex); + GF_FREE (conf); this->private = NULL; diff --git a/xlators/performance/io-threads/src/io-threads.h b/xlators/performance/io-threads/src/io-threads.h index e5c97f690a2..673e1967617 100644 --- a/xlators/performance/io-threads/src/io-threads.h +++ b/xlators/performance/io-threads/src/io-threads.h @@ -82,6 +82,9 @@ struct iot_conf { xlator_t *this; size_t stack_size; + gf_boolean_t down; /*PARENT_DOWN event is notified*/ + gf_boolean_t mutex_inited; + gf_boolean_t cond_inited; struct iot_least_throttle throttle; }; |
