Lines Matching refs:wqe
39 * One for each thread in a wqe pool
47 struct io_wqe *wqe;
138 static bool create_io_worker(struct io_wq *wq, struct io_wqe *wqe, int index);
140 static bool io_acct_cancel_pending_work(struct io_wqe *wqe,
157 static inline struct io_wqe_acct *io_get_acct(struct io_wqe *wqe, bool bound)
159 return &wqe->acct[bound ? IO_WQ_ACCT_BOUND : IO_WQ_ACCT_UNBOUND];
162 static inline struct io_wqe_acct *io_work_get_acct(struct io_wqe *wqe,
165 return io_get_acct(wqe, !(work->flags & IO_WQ_WORK_UNBOUND));
170 return io_get_acct(worker->wqe, worker->flags & IO_WORKER_F_BOUND);
186 return test_bit(IO_WQ_BIT_EXIT, &worker->wqe->wq->state);
192 struct io_wqe *wqe = worker->wqe;
193 struct io_wq *wq = wqe->wq;
196 raw_spin_lock(&worker->wqe->lock);
198 raw_spin_unlock(&worker->wqe->lock);
216 struct io_wqe *wqe = worker->wqe;
217 struct io_wq *wq = wqe->wq;
232 raw_spin_lock(&wqe->lock);
241 raw_spin_unlock(&wqe->lock);
244 io_worker_ref_put(wqe->wq);
260 static bool io_wqe_activate_free_worker(struct io_wqe *wqe,
272 hlist_nulls_for_each_entry_rcu(worker, n, &wqe->free_list, nulls_node) {
293 static bool io_wqe_create_worker(struct io_wqe *wqe, struct io_wqe_acct *acct)
302 raw_spin_lock(&wqe->lock);
304 raw_spin_unlock(&wqe->lock);
308 raw_spin_unlock(&wqe->lock);
310 atomic_inc(&wqe->wq->worker_refs);
311 return create_io_worker(wqe->wq, wqe, acct->index);
325 struct io_wqe *wqe;
330 wqe = worker->wqe;
331 wq = wqe->wq;
332 acct = &wqe->acct[worker->create_index];
333 raw_spin_lock(&wqe->lock);
338 raw_spin_unlock(&wqe->lock);
340 create_io_worker(wq, wqe, worker->create_index);
353 struct io_wqe *wqe = worker->wqe;
354 struct io_wq *wq = wqe->wq;
397 __must_hold(wqe->lock)
400 struct io_wqe *wqe = worker->wqe;
407 atomic_inc(&wqe->wq->worker_refs);
408 raw_spin_unlock(&wqe->lock);
410 raw_spin_lock(&wqe->lock);
418 static void __io_worker_busy(struct io_wqe *wqe, struct io_worker *worker,
420 __must_hold(wqe->lock)
435 static void __io_worker_idle(struct io_wqe *wqe, struct io_worker *worker)
436 __must_hold(wqe->lock)
440 hlist_nulls_add_head_rcu(&worker->nulls_node, &wqe->free_list);
449 static bool io_wait_on_hash(struct io_wqe *wqe, unsigned int hash)
451 struct io_wq *wq = wqe->wq;
455 if (list_empty(&wqe->wait.entry)) {
456 __add_wait_queue(&wq->hash->wait, &wqe->wait);
459 list_del_init(&wqe->wait.entry);
469 __must_hold(wqe->lock)
474 struct io_wqe *wqe = worker->wqe;
489 tail = wqe->hash_tail[hash];
492 if (!test_and_set_bit(hash, &wqe->wq->hash->map)) {
493 wqe->hash_tail[hash] = NULL;
511 raw_spin_unlock(&wqe->lock);
512 unstalled = io_wait_on_hash(wqe, stall_hash);
513 raw_spin_lock(&wqe->lock);
516 if (wq_has_sleeper(&wqe->wq->hash->wait))
517 wake_up(&wqe->wq->hash->wait);
547 static void io_wqe_enqueue(struct io_wqe *wqe, struct io_wq_work *work);
550 __releases(wqe->lock)
553 struct io_wqe *wqe = worker->wqe;
554 struct io_wq *wq = wqe->wq;
569 __io_worker_busy(wqe, worker, work);
571 raw_spin_unlock(&wqe->lock);
597 io_wqe_enqueue(wqe, linked);
607 raw_spin_lock(&wqe->lock);
608 /* skip unnecessary unlock-lock wqe->lock */
611 raw_spin_unlock(&wqe->lock);
615 raw_spin_lock(&wqe->lock);
623 struct io_wqe *wqe = worker->wqe;
624 struct io_wq *wq = wqe->wq;
638 raw_spin_lock(&wqe->lock);
646 raw_spin_unlock(&wqe->lock);
651 __io_worker_idle(wqe, worker);
652 raw_spin_unlock(&wqe->lock);
667 raw_spin_lock(&wqe->lock);
709 raw_spin_lock(&worker->wqe->lock);
711 raw_spin_unlock(&worker->wqe->lock);
714 static void io_init_new_worker(struct io_wqe *wqe, struct io_worker *worker,
719 set_cpus_allowed_ptr(tsk, wqe->cpu_mask);
722 raw_spin_lock(&wqe->lock);
723 hlist_nulls_add_head_rcu(&worker->nulls_node, &wqe->free_list);
724 list_add_tail_rcu(&worker->all_list, &wqe->all_list);
726 raw_spin_unlock(&wqe->lock);
759 struct io_wqe *wqe;
763 wqe = worker->wqe;
764 tsk = create_io_thread(io_wqe_worker, worker, wqe->node);
766 io_init_new_worker(wqe, worker, tsk);
773 raw_spin_lock(&wqe->lock);
781 while (io_acct_cancel_pending_work(wqe, acct, &match))
782 raw_spin_lock(&wqe->lock);
784 raw_spin_unlock(&wqe->lock);
785 io_worker_ref_put(wqe->wq);
804 static bool create_io_worker(struct io_wq *wq, struct io_wqe *wqe, int index)
806 struct io_wqe_acct *acct = &wqe->acct[index];
812 worker = kzalloc_node(sizeof(*worker), GFP_KERNEL, wqe->node);
816 raw_spin_lock(&wqe->lock);
818 raw_spin_unlock(&wqe->lock);
824 worker->wqe = wqe;
831 tsk = create_io_thread(io_wqe_worker, worker, wqe->node);
833 io_init_new_worker(wqe, worker, tsk);
849 static bool io_wq_for_each_worker(struct io_wqe *wqe,
856 list_for_each_entry_rcu(worker, &wqe->all_list, all_list) {
877 static void io_run_cancel(struct io_wq_work *work, struct io_wqe *wqe)
879 struct io_wq *wq = wqe->wq;
888 static void io_wqe_insert_work(struct io_wqe *wqe, struct io_wq_work *work)
890 struct io_wqe_acct *acct = io_work_get_acct(wqe, work);
901 tail = wqe->hash_tail[hash];
902 wqe->hash_tail[hash] = work;
914 static void io_wqe_enqueue(struct io_wqe *wqe, struct io_wq_work *work)
916 struct io_wqe_acct *acct = io_work_get_acct(wqe, work);
924 if (test_bit(IO_WQ_BIT_EXIT, &wqe->wq->state) ||
926 io_run_cancel(work, wqe);
930 raw_spin_lock(&wqe->lock);
931 io_wqe_insert_work(wqe, work);
935 do_create = !io_wqe_activate_free_worker(wqe, acct);
938 raw_spin_unlock(&wqe->lock);
944 did_create = io_wqe_create_worker(wqe, acct);
948 raw_spin_lock(&wqe->lock);
957 if (io_acct_cancel_pending_work(wqe, acct, &match))
958 raw_spin_lock(&wqe->lock);
960 raw_spin_unlock(&wqe->lock);
966 struct io_wqe *wqe = wq->wqes[numa_node_id()];
968 io_wqe_enqueue(wqe, work);
1002 static inline void io_wqe_remove_pending(struct io_wqe *wqe,
1006 struct io_wqe_acct *acct = io_work_get_acct(wqe, work);
1010 if (io_wq_is_hashed(work) && work == wqe->hash_tail[hash]) {
1014 wqe->hash_tail[hash] = prev_work;
1016 wqe->hash_tail[hash] = NULL;
1021 static bool io_acct_cancel_pending_work(struct io_wqe *wqe,
1024 __releases(wqe->lock)
1033 io_wqe_remove_pending(wqe, work, prev);
1034 raw_spin_unlock(&wqe->lock);
1035 io_run_cancel(work, wqe);
1044 static void io_wqe_cancel_pending_work(struct io_wqe *wqe,
1049 raw_spin_lock(&wqe->lock);
1051 struct io_wqe_acct *acct = io_get_acct(wqe, i == 0);
1053 if (io_acct_cancel_pending_work(wqe, acct, match)) {
1059 raw_spin_unlock(&wqe->lock);
1062 static void io_wqe_cancel_running_work(struct io_wqe *wqe,
1066 io_wq_for_each_worker(wqe, io_wq_worker_cancel, match);
1086 struct io_wqe *wqe = wq->wqes[node];
1088 io_wqe_cancel_pending_work(wqe, &match);
1100 struct io_wqe *wqe = wq->wqes[node];
1102 io_wqe_cancel_running_work(wqe, &match);
1117 struct io_wqe *wqe = container_of(wait, struct io_wqe, wait);
1124 struct io_wqe_acct *acct = &wqe->acct[i];
1127 io_wqe_activate_free_worker(wqe, acct);
1157 struct io_wqe *wqe;
1162 wqe = kzalloc_node(sizeof(struct io_wqe), GFP_KERNEL, alloc_node);
1163 if (!wqe)
1165 wq->wqes[node] = wqe;
1166 if (!alloc_cpumask_var(&wqe->cpu_mask, GFP_KERNEL))
1168 cpumask_copy(wqe->cpu_mask, cpumask_of_node(node));
1169 wqe->node = alloc_node;
1170 wqe->acct[IO_WQ_ACCT_BOUND].max_workers = bounded;
1171 wqe->acct[IO_WQ_ACCT_UNBOUND].max_workers =
1173 INIT_LIST_HEAD(&wqe->wait.entry);
1174 wqe->wait.func = io_wqe_hash_wake;
1176 struct io_wqe_acct *acct = &wqe->acct[i];
1182 wqe->wq = wq;
1183 raw_spin_lock_init(&wqe->lock);
1184 INIT_HLIST_NULLS_HEAD(&wqe->free_list, 0);
1185 INIT_LIST_HEAD(&wqe->all_list);
1213 return worker->wqe->wq == data;
1250 struct io_wqe *wqe = wq->wqes[node];
1252 io_wq_for_each_worker(wqe, io_wq_worker_wake, NULL);
1274 struct io_wqe *wqe = wq->wqes[node];
1279 io_wqe_cancel_pending_work(wqe, &match);
1280 free_cpumask_var(wqe->cpu_mask);
1281 kfree(wqe);
1305 cpumask_set_cpu(od->cpu, worker->wqe->cpu_mask);
1307 cpumask_clear_cpu(od->cpu, worker->wqe->cpu_mask);
1346 struct io_wqe *wqe = wq->wqes[i];
1349 cpumask_copy(wqe->cpu_mask, mask);
1351 cpumask_copy(wqe->cpu_mask, cpumask_of_node(i));
1381 struct io_wqe *wqe = wq->wqes[node];
1384 raw_spin_lock(&wqe->lock);
1386 acct = &wqe->acct[i];
1392 raw_spin_unlock(&wqe->lock);