Lines Matching refs:wq
52 struct io_wq *wq; member
145 static bool create_io_worker(struct io_wq *wq, struct io_wq_acct *acct);
147 static bool io_acct_cancel_pending_work(struct io_wq *wq,
151 static void io_wq_cancel_tw_create(struct io_wq *wq);
174 static inline struct io_wq_acct *io_get_acct(struct io_wq *wq, bool bound) in io_get_acct() argument
176 return &wq->acct[bound ? IO_WQ_ACCT_BOUND : IO_WQ_ACCT_UNBOUND]; in io_get_acct()
179 static inline struct io_wq_acct *io_work_get_acct(struct io_wq *wq, in io_work_get_acct() argument
182 return io_get_acct(wq, !(work_flags & IO_WQ_WORK_UNBOUND)); in io_work_get_acct()
190 static void io_worker_ref_put(struct io_wq *wq) in io_worker_ref_put() argument
192 if (atomic_dec_and_test(&wq->worker_refs)) in io_worker_ref_put()
193 complete(&wq->worker_done); in io_worker_ref_put()
203 return test_bit(IO_WQ_BIT_EXIT, &worker->wq->state); in io_wq_worker_stopped()
209 struct io_wq *wq = worker->wq; in io_worker_cancel_cb() local
215 io_worker_ref_put(wq); in io_worker_cancel_cb()
232 struct io_wq *wq = worker->wq; in io_worker_exit() local
236 struct callback_head *cb = task_work_cancel_match(wq->task, in io_worker_exit()
261 io_worker_ref_put(wq); in io_worker_exit()
321 static bool io_wq_create_worker(struct io_wq *wq, struct io_wq_acct *acct) in io_wq_create_worker() argument
338 atomic_inc(&wq->worker_refs); in io_wq_create_worker()
339 return create_io_worker(wq, acct); in io_wq_create_worker()
352 struct io_wq *wq; in create_worker_cb() local
358 wq = worker->wq; in create_worker_cb()
375 create_io_worker(wq, acct); in create_worker_cb()
379 io_worker_ref_put(wq); in create_worker_cb()
389 struct io_wq *wq = worker->wq; in io_queue_worker_create() local
392 if (test_bit(IO_WQ_BIT_EXIT, &wq->state)) in io_queue_worker_create()
406 atomic_inc(&wq->worker_refs); in io_queue_worker_create()
408 if (!task_work_add(wq->task, &worker->create_work, TWA_SIGNAL)) { in io_queue_worker_create()
415 if (test_bit(IO_WQ_BIT_EXIT, &wq->state)) in io_queue_worker_create()
416 io_wq_cancel_tw_create(wq); in io_queue_worker_create()
417 io_worker_ref_put(wq); in io_queue_worker_create()
420 io_worker_ref_put(wq); in io_queue_worker_create()
426 io_worker_ref_put(wq); in io_queue_worker_create()
457 struct io_wq *wq = worker->wq; in io_wq_dec_running() local
475 atomic_inc(&wq->worker_refs); in io_wq_dec_running()
505 static bool io_wait_on_hash(struct io_wq *wq, unsigned int hash) in io_wait_on_hash() argument
509 spin_lock_irq(&wq->hash->wait.lock); in io_wait_on_hash()
510 if (list_empty(&wq->wait.entry)) { in io_wait_on_hash()
511 __add_wait_queue(&wq->hash->wait, &wq->wait); in io_wait_on_hash()
512 if (!test_bit(hash, &wq->hash->map)) { in io_wait_on_hash()
514 list_del_init(&wq->wait.entry); in io_wait_on_hash()
518 spin_unlock_irq(&wq->hash->wait.lock); in io_wait_on_hash()
523 struct io_wq *wq) in io_get_next_work() argument
545 tail = wq->hash_tail[hash]; in io_get_next_work()
548 if (!test_and_set_bit(hash, &wq->hash->map)) { in io_get_next_work()
549 wq->hash_tail[hash] = NULL; in io_get_next_work()
568 unstalled = io_wait_on_hash(wq, stall_hash); in io_get_next_work()
572 if (wq_has_sleeper(&wq->hash->wait)) in io_get_next_work()
573 wake_up(&wq->hash->wait); in io_get_next_work()
600 struct io_wq *wq = worker->wq; in io_worker_handle_work() local
601 bool do_kill = test_bit(IO_WQ_BIT_EXIT, &wq->state); in io_worker_handle_work()
613 work = io_get_next_work(acct, wq); in io_worker_handle_work()
661 io_wq_enqueue(wq, linked); in io_worker_handle_work()
665 spin_lock_irq(&wq->hash->wait.lock); in io_worker_handle_work()
666 clear_bit(hash, &wq->hash->map); in io_worker_handle_work()
668 spin_unlock_irq(&wq->hash->wait.lock); in io_worker_handle_work()
669 if (wq_has_sleeper(&wq->hash->wait)) in io_worker_handle_work()
670 wake_up(&wq->hash->wait); in io_worker_handle_work()
684 struct io_wq *wq = worker->wq; in io_wq_worker() local
691 snprintf(buf, sizeof(buf), "iou-wrk-%d", wq->task->pid); in io_wq_worker()
694 while (!test_bit(IO_WQ_BIT_EXIT, &wq->state)) { in io_wq_worker()
733 wq->cpu_mask); in io_wq_worker()
737 if (test_bit(IO_WQ_BIT_EXIT, &wq->state) && io_acct_run_queue(acct)) in io_wq_worker()
780 static void io_init_new_worker(struct io_wq *wq, struct io_wq_acct *acct, struct io_worker *worker, in io_init_new_worker() argument
785 set_cpus_allowed_ptr(tsk, wq->cpu_mask); in io_init_new_worker()
838 struct io_wq *wq; in create_worker_cont() local
843 wq = worker->wq; in create_worker_cont()
847 io_init_new_worker(wq, acct, worker, tsk); in create_worker_cont()
861 while (io_acct_cancel_pending_work(wq, acct, &match)) in create_worker_cont()
866 io_worker_ref_put(wq); in create_worker_cont()
886 static bool create_io_worker(struct io_wq *wq, struct io_wq_acct *acct) in create_io_worker() argument
900 io_worker_ref_put(wq); in create_io_worker()
905 worker->wq = wq; in create_io_worker()
912 io_init_new_worker(wq, acct, worker, tsk); in create_io_worker()
949 static bool io_wq_for_each_worker(struct io_wq *wq, in io_wq_for_each_worker() argument
954 if (!io_acct_for_each_worker(&wq->acct[i], func, data)) in io_wq_for_each_worker()
968 static void io_run_cancel(struct io_wq_work *work, struct io_wq *wq) in io_run_cancel() argument
977 static void io_wq_insert_work(struct io_wq *wq, struct io_wq_acct *acct, in io_wq_insert_work() argument
990 tail = wq->hash_tail[hash]; in io_wq_insert_work()
991 wq->hash_tail[hash] = work; in io_wq_insert_work()
1003 void io_wq_enqueue(struct io_wq *wq, struct io_wq_work *work) in io_wq_enqueue() argument
1006 struct io_wq_acct *acct = io_work_get_acct(wq, work_flags); in io_wq_enqueue()
1018 if (test_bit(IO_WQ_BIT_EXIT, &wq->state) || in io_wq_enqueue()
1020 io_run_cancel(work, wq); in io_wq_enqueue()
1025 io_wq_insert_work(wq, acct, work, work_flags); in io_wq_enqueue()
1037 did_create = io_wq_create_worker(wq, acct); in io_wq_enqueue()
1049 io_acct_cancel_pending_work(wq, acct, &match); in io_wq_enqueue()
1094 static inline void io_wq_remove_pending(struct io_wq *wq, in io_wq_remove_pending() argument
1102 if (io_wq_is_hashed(work) && work == wq->hash_tail[hash]) { in io_wq_remove_pending()
1106 wq->hash_tail[hash] = prev_work; in io_wq_remove_pending()
1108 wq->hash_tail[hash] = NULL; in io_wq_remove_pending()
1113 static bool io_acct_cancel_pending_work(struct io_wq *wq, in io_acct_cancel_pending_work() argument
1125 io_wq_remove_pending(wq, acct, work, prev); in io_acct_cancel_pending_work()
1127 io_run_cancel(work, wq); in io_acct_cancel_pending_work()
1137 static void io_wq_cancel_pending_work(struct io_wq *wq, in io_wq_cancel_pending_work() argument
1143 struct io_wq_acct *acct = io_get_acct(wq, i == 0); in io_wq_cancel_pending_work()
1145 if (io_acct_cancel_pending_work(wq, acct, match)) { in io_wq_cancel_pending_work()
1161 static void io_wq_cancel_running_work(struct io_wq *wq, in io_wq_cancel_running_work() argument
1167 io_acct_cancel_running_work(&wq->acct[i], match); in io_wq_cancel_running_work()
1172 enum io_wq_cancel io_wq_cancel_cb(struct io_wq *wq, work_cancel_fn *cancel, in io_wq_cancel_cb() argument
1194 io_wq_cancel_pending_work(wq, &match); in io_wq_cancel_cb()
1198 io_wq_cancel_running_work(wq, &match); in io_wq_cancel_cb()
1212 struct io_wq *wq = container_of(wait, struct io_wq, wait); in io_wq_hash_wake() local
1219 struct io_wq_acct *acct = &wq->acct[i]; in io_wq_hash_wake()
1231 struct io_wq *wq; in io_wq_create() local
1236 wq = kzalloc(sizeof(struct io_wq), GFP_KERNEL); in io_wq_create()
1237 if (!wq) in io_wq_create()
1241 wq->hash = data->hash; in io_wq_create()
1245 if (!alloc_cpumask_var(&wq->cpu_mask, GFP_KERNEL)) in io_wq_create()
1247 cpuset_cpus_allowed(data->task, wq->cpu_mask); in io_wq_create()
1248 wq->acct[IO_WQ_ACCT_BOUND].max_workers = bounded; in io_wq_create()
1249 wq->acct[IO_WQ_ACCT_UNBOUND].max_workers = in io_wq_create()
1251 INIT_LIST_HEAD(&wq->wait.entry); in io_wq_create()
1252 wq->wait.func = io_wq_hash_wake; in io_wq_create()
1254 struct io_wq_acct *acct = &wq->acct[i]; in io_wq_create()
1266 wq->task = get_task_struct(data->task); in io_wq_create()
1267 atomic_set(&wq->worker_refs, 1); in io_wq_create()
1268 init_completion(&wq->worker_done); in io_wq_create()
1269 ret = cpuhp_state_add_instance_nocalls(io_wq_online, &wq->cpuhp_node); in io_wq_create()
1271 put_task_struct(wq->task); in io_wq_create()
1275 return wq; in io_wq_create()
1278 free_cpumask_var(wq->cpu_mask); in io_wq_create()
1279 kfree(wq); in io_wq_create()
1290 return worker->wq == data; in io_task_work_match()
1293 void io_wq_exit_start(struct io_wq *wq) in io_wq_exit_start() argument
1295 set_bit(IO_WQ_BIT_EXIT, &wq->state); in io_wq_exit_start()
1298 static void io_wq_cancel_tw_create(struct io_wq *wq) in io_wq_cancel_tw_create() argument
1302 while ((cb = task_work_cancel_match(wq->task, io_task_work_match, wq)) != NULL) { in io_wq_cancel_tw_create()
1316 static void io_wq_exit_workers(struct io_wq *wq) in io_wq_exit_workers() argument
1318 if (!wq->task) in io_wq_exit_workers()
1321 io_wq_cancel_tw_create(wq); in io_wq_exit_workers()
1324 io_wq_for_each_worker(wq, io_wq_worker_wake, NULL); in io_wq_exit_workers()
1326 io_worker_ref_put(wq); in io_wq_exit_workers()
1327 wait_for_completion(&wq->worker_done); in io_wq_exit_workers()
1329 spin_lock_irq(&wq->hash->wait.lock); in io_wq_exit_workers()
1330 list_del_init(&wq->wait.entry); in io_wq_exit_workers()
1331 spin_unlock_irq(&wq->hash->wait.lock); in io_wq_exit_workers()
1333 put_task_struct(wq->task); in io_wq_exit_workers()
1334 wq->task = NULL; in io_wq_exit_workers()
1337 static void io_wq_destroy(struct io_wq *wq) in io_wq_destroy() argument
1344 cpuhp_state_remove_instance_nocalls(io_wq_online, &wq->cpuhp_node); in io_wq_destroy()
1345 io_wq_cancel_pending_work(wq, &match); in io_wq_destroy()
1346 free_cpumask_var(wq->cpu_mask); in io_wq_destroy()
1347 io_wq_put_hash(wq->hash); in io_wq_destroy()
1348 kfree(wq); in io_wq_destroy()
1351 void io_wq_put_and_exit(struct io_wq *wq) in io_wq_put_and_exit() argument
1353 WARN_ON_ONCE(!test_bit(IO_WQ_BIT_EXIT, &wq->state)); in io_wq_put_and_exit()
1355 io_wq_exit_workers(wq); in io_wq_put_and_exit()
1356 io_wq_destroy(wq); in io_wq_put_and_exit()
1369 cpumask_set_cpu(od->cpu, worker->wq->cpu_mask); in io_wq_worker_affinity()
1371 cpumask_clear_cpu(od->cpu, worker->wq->cpu_mask); in io_wq_worker_affinity()
1375 static int __io_wq_cpu_online(struct io_wq *wq, unsigned int cpu, bool online) in __io_wq_cpu_online() argument
1383 io_wq_for_each_worker(wq, io_wq_worker_affinity, &od); in __io_wq_cpu_online()
1390 struct io_wq *wq = hlist_entry_safe(node, struct io_wq, cpuhp_node); in io_wq_cpu_online() local
1392 return __io_wq_cpu_online(wq, cpu, true); in io_wq_cpu_online()
1397 struct io_wq *wq = hlist_entry_safe(node, struct io_wq, cpuhp_node); in io_wq_cpu_offline() local
1399 return __io_wq_cpu_online(wq, cpu, false); in io_wq_cpu_offline()
1433 int io_wq_max_workers(struct io_wq *wq, int *new_count) in io_wq_max_workers() argument
1454 acct = &wq->acct[i]; in io_wq_max_workers()