diff options
| author | Shehjar Tikoo <shehjart@zresearch.com> | 2009-03-16 07:03:02 -0700 | 
|---|---|---|
| committer | Anand V. Avati <avati@amp.gluster.com> | 2009-03-17 17:17:49 +0530 | 
| commit | 8e3e0e776cc04ad9f840383c4693ee73adc79558 (patch) | |
| tree | a27c6c3d147e3994d3535bc754112f7fb4df1151 /xlators/performance/io-threads/src/io-threads.c | |
| parent | 3a83fdc459a620d5ce0360bcf5fa071118d5430f (diff) | |
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 <avati@amp.gluster.com>
Diffstat (limited to 'xlators/performance/io-threads/src/io-threads.c')
| -rw-r--r-- | xlators/performance/io-threads/src/io-threads.c | 76 | 
1 files changed, 50 insertions, 26 deletions
diff --git a/xlators/performance/io-threads/src/io-threads.c b/xlators/performance/io-threads/src/io-threads.c index ce42a9834..6a30184aa 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; i<conf->thread_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)  {  | 
