Lines Matching refs:sw
27 struct submit_worker *sw = NULL; in __get_submit_worker() local
30 sw = &wq->workers[start]; in __get_submit_worker()
31 if (sw->flags & SW_F_IDLE) in __get_submit_worker()
32 return sw; in __get_submit_worker()
33 if (!(*best) || sw->seq < (*best)->seq) in __get_submit_worker()
34 *best = sw; in __get_submit_worker()
44 struct submit_worker *sw, *best = NULL; in get_submit_worker() local
48 sw = __get_submit_worker(wq, next, wq->max_workers - 1, &best); in get_submit_worker()
49 if (!sw && next) in get_submit_worker()
50 sw = __get_submit_worker(wq, 0, next - 1, &best); in get_submit_worker()
55 if (!sw) in get_submit_worker()
56 sw = best; in get_submit_worker()
58 if (sw->index == wq->next_free_worker) { in get_submit_worker()
59 if (sw->index + 1 < wq->max_workers) in get_submit_worker()
60 wq->next_free_worker = sw->index + 1; in get_submit_worker()
65 return sw; in get_submit_worker()
73 struct submit_worker *sw = &wq->workers[i]; in all_sw_idle() local
75 if (!(sw->flags & SW_F_IDLE)) in all_sw_idle()
103 struct submit_worker *sw; in workqueue_enqueue() local
105 sw = get_submit_worker(wq); in workqueue_enqueue()
106 assert(sw); in workqueue_enqueue()
108 pthread_mutex_lock(&sw->lock); in workqueue_enqueue()
109 flist_add_tail(&work->list, &sw->work_list); in workqueue_enqueue()
110 sw->seq = ++wq->work_seq; in workqueue_enqueue()
111 sw->flags &= ~SW_F_IDLE; in workqueue_enqueue()
112 pthread_mutex_unlock(&sw->lock); in workqueue_enqueue()
114 pthread_cond_signal(&sw->cond); in workqueue_enqueue()
117 static void handle_list(struct submit_worker *sw, struct flist_head *list) in handle_list() argument
119 struct workqueue *wq = sw->wq; in handle_list()
125 wq->ops.fn(sw, work); in handle_list()
131 struct submit_worker *sw = data; in worker_thread() local
132 struct workqueue *wq = sw->wq; in worker_thread()
136 sk_out_assign(sw->sk_out); in worker_thread()
146 ret = workqueue_init_worker(sw); in worker_thread()
148 pthread_mutex_lock(&sw->lock); in worker_thread()
149 sw->flags |= SW_F_RUNNING; in worker_thread()
151 sw->flags |= SW_F_ERROR; in worker_thread()
152 pthread_mutex_unlock(&sw->lock); in worker_thread()
158 if (sw->flags & SW_F_ERROR) in worker_thread()
162 pthread_mutex_lock(&sw->lock); in worker_thread()
164 if (flist_empty(&sw->work_list)) { in worker_thread()
165 if (sw->flags & SW_F_EXIT) { in worker_thread()
166 pthread_mutex_unlock(&sw->lock); in worker_thread()
170 if (workqueue_pre_sleep_check(sw)) { in worker_thread()
171 pthread_mutex_unlock(&sw->lock); in worker_thread()
172 workqueue_pre_sleep(sw); in worker_thread()
173 pthread_mutex_lock(&sw->lock); in worker_thread()
180 if (!flist_empty(&sw->work_list)) in worker_thread()
183 if (sw->flags & SW_F_EXIT) { in worker_thread()
184 pthread_mutex_unlock(&sw->lock); in worker_thread()
186 } else if (!(sw->flags & SW_F_IDLE)) { in worker_thread()
187 sw->flags |= SW_F_IDLE; in worker_thread()
188 wq->next_free_worker = sw->index; in worker_thread()
193 wq->ops.update_acct_fn(sw); in worker_thread()
195 pthread_cond_wait(&sw->cond, &sw->lock); in worker_thread()
198 flist_splice_init(&sw->work_list, &local_list); in worker_thread()
200 pthread_mutex_unlock(&sw->lock); in worker_thread()
201 handle_list(sw, &local_list); in worker_thread()
205 wq->ops.update_acct_fn(sw); in worker_thread()
212 static void free_worker(struct submit_worker *sw, unsigned int *sum_cnt) in free_worker() argument
214 struct workqueue *wq = sw->wq; in free_worker()
216 workqueue_exit_worker(sw, sum_cnt); in free_worker()
218 pthread_cond_destroy(&sw->cond); in free_worker()
219 pthread_mutex_destroy(&sw->lock); in free_worker()
222 wq->ops.free_worker_fn(sw); in free_worker()
225 static void shutdown_worker(struct submit_worker *sw, unsigned int *sum_cnt) in shutdown_worker() argument
227 pthread_join(sw->thread, NULL); in shutdown_worker()
228 free_worker(sw, sum_cnt); in shutdown_worker()
234 struct submit_worker *sw; in workqueue_exit() local
241 sw = &wq->workers[i]; in workqueue_exit()
243 pthread_mutex_lock(&sw->lock); in workqueue_exit()
244 sw->flags |= SW_F_EXIT; in workqueue_exit()
245 pthread_cond_signal(&sw->cond); in workqueue_exit()
246 pthread_mutex_unlock(&sw->lock); in workqueue_exit()
252 sw = &wq->workers[i]; in workqueue_exit()
253 if (sw->flags & SW_F_ACCOUNTED) in workqueue_exit()
255 pthread_mutex_lock(&sw->lock); in workqueue_exit()
256 sw->flags |= SW_F_ACCOUNTED; in workqueue_exit()
257 pthread_mutex_unlock(&sw->lock); in workqueue_exit()
258 shutdown_worker(sw, &sum_cnt); in workqueue_exit()
273 struct submit_worker *sw = &wq->workers[index]; in start_worker() local
276 INIT_FLIST_HEAD(&sw->work_list); in start_worker()
278 ret = mutex_cond_init_pshared(&sw->lock, &sw->cond); in start_worker()
282 sw->wq = wq; in start_worker()
283 sw->index = index; in start_worker()
284 sw->sk_out = sk_out; in start_worker()
287 ret = wq->ops.alloc_worker_fn(sw); in start_worker()
292 ret = pthread_create(&sw->thread, NULL, worker_thread, sw); in start_worker()
294 pthread_mutex_lock(&sw->lock); in start_worker()
295 sw->flags = SW_F_IDLE; in start_worker()
296 pthread_mutex_unlock(&sw->lock); in start_worker()
300 free_worker(sw, NULL); in start_worker()
342 struct submit_worker *sw; in workqueue_init() local
347 sw = &wq->workers[i]; in workqueue_init()
348 pthread_mutex_lock(&sw->lock); in workqueue_init()
349 if (sw->flags & SW_F_RUNNING) in workqueue_init()
351 if (sw->flags & SW_F_ERROR) in workqueue_init()
353 pthread_mutex_unlock(&sw->lock); in workqueue_init()