From 8e3e0e776cc04ad9f840383c4693ee73adc79558 Mon Sep 17 00:00:00 2001 From: Shehjar Tikoo Date: Mon, 16 Mar 2009 07:03:02 -0700 Subject: IO-threads Cleanup: Change workers list to dynamically allocated array Worker threads were represented as a list in iot_conf_t which made us traverse the list of workers in order to decide which thread gets the request. Now we represent the workers as a dynamically allocated array so that we can just index into the array to schedule the file. Signed-off-by: Anand V. Avati --- xlators/performance/io-threads/src/io-threads.c | 76 ++++++++++++++++--------- xlators/performance/io-threads/src/io-threads.h | 3 +- 2 files changed, 51 insertions(+), 28 deletions(-) diff --git a/xlators/performance/io-threads/src/io-threads.c b/xlators/performance/io-threads/src/io-threads.c index ce42a98348f..6a30184aaa3 100644 --- a/xlators/performance/io-threads/src/io-threads.c +++ b/xlators/performance/io-threads/src/io-threads.c @@ -41,16 +41,16 @@ iot_schedule (iot_conf_t *conf, iot_file_t *file, ino_t ino) { - int32_t cnt = (ino % conf->thread_count); - iot_worker_t *trav = conf->workers.next; + int32_t idx = 0; + iot_worker_t *selected_worker = NULL; + + idx = (ino % conf->thread_count); + selected_worker = conf->workers[idx]; - for (; cnt; cnt--) - trav = trav->next; - if (file) - file->worker = trav; - trav->fd_count++; - return trav; + file->worker = selected_worker; + + return selected_worker; } int32_t @@ -1078,33 +1078,57 @@ iot_worker (void *arg) } } -static void -workers_init (iot_conf_t *conf) +static iot_worker_t ** +allocate_worker_array (int count) { - int i; + iot_worker_t ** warr = NULL; - conf->workers.next = &conf->workers; - conf->workers.prev = &conf->workers; + warr = CALLOC (count, sizeof(iot_worker_t *)); + ERR_ABORT (warr); - for (i=0; ithread_count; i++) { + return warr; +} - iot_worker_t *worker = CALLOC (1, sizeof (*worker)); - ERR_ABORT (worker); +static iot_worker_t * +allocate_worker (iot_conf_t * conf) +{ + iot_worker_t *wrk = NULL; - worker->next = &conf->workers; - worker->prev = conf->workers.prev; - worker->next->prev = worker; - worker->prev->next = worker; + wrk = CALLOC (1, sizeof (iot_worker_t)); + ERR_ABORT (wrk); - INIT_LIST_HEAD (&worker->rqlist); - pthread_mutex_init (&worker->qlock, NULL); - pthread_cond_init (&worker->dq_cond, NULL); - worker->conf = conf; + INIT_LIST_HEAD (&wrk->rqlist); + wrk->conf = conf; + pthread_cond_init (&wrk->dq_cond, NULL); + pthread_mutex_init (&wrk->qlock, NULL); - pthread_create (&worker->thread, NULL, iot_worker, worker); - } + return wrk; } +static void +allocate_workers (iot_conf_t *conf, + int count, + int start_alloc_idx) +{ + int i, end_count; + + end_count = count + start_alloc_idx; + for (i = start_alloc_idx; i < end_count; i++) { + conf->workers[i] = allocate_worker (conf); + pthread_create (&conf->workers[i]->thread, NULL, iot_worker, + conf->workers[i]); + } +} + +static void +workers_init (iot_conf_t *conf) +{ + conf->workers = allocate_worker_array (conf->thread_count); + allocate_workers (conf, conf->thread_count, 0); +} + + + int32_t init (xlator_t *this) { diff --git a/xlators/performance/io-threads/src/io-threads.h b/xlators/performance/io-threads/src/io-threads.h index 73a76fa8fe2..9798a09ed1d 100644 --- a/xlators/performance/io-threads/src/io-threads.h +++ b/xlators/performance/io-threads/src/io-threads.h @@ -56,7 +56,6 @@ struct iot_request { }; struct iot_worker { - struct iot_worker *next, *prev; struct list_head rqlist; /* List of requests assigned to me. */ struct iot_conf *conf; int64_t q,dq; @@ -77,7 +76,7 @@ struct iot_file { struct iot_conf { int32_t thread_count; int32_t misc_thread_index; /* Used to schedule the miscellaneous calls like checksum */ - struct iot_worker workers; + struct iot_worker ** workers; struct iot_file files; pthread_mutex_t files_lock; -- cgit