Lines Matching refs:worker
167 struct worker *manager; /* L: purely informational */
250 struct worker *rescuer; /* I: rescue worker */
393 #define for_each_pool_worker(worker, pool) \ argument
394 list_for_each_entry((worker), &(pool)->workers, node) \
828 static struct worker *first_idle_worker(struct worker_pool *pool) in first_idle_worker()
833 return list_first_entry(&pool->idle_list, struct worker, entry); in first_idle_worker()
847 struct worker *worker = first_idle_worker(pool); in wake_up_worker() local
849 if (likely(worker)) in wake_up_worker()
850 wake_up_process(worker->task); in wake_up_worker()
866 struct worker *worker = kthread_data(task); in wq_worker_waking_up() local
868 if (!(worker->flags & WORKER_NOT_RUNNING)) { in wq_worker_waking_up()
869 WARN_ON_ONCE(worker->pool->cpu != cpu); in wq_worker_waking_up()
870 atomic_inc(&worker->pool->nr_running); in wq_worker_waking_up()
891 struct worker *worker = kthread_data(task), *to_wakeup = NULL; in wq_worker_sleeping() local
899 if (worker->flags & WORKER_NOT_RUNNING) in wq_worker_sleeping()
902 pool = worker->pool; in wq_worker_sleeping()
935 static inline void worker_set_flags(struct worker *worker, unsigned int flags) in worker_set_flags() argument
937 struct worker_pool *pool = worker->pool; in worker_set_flags()
939 WARN_ON_ONCE(worker->task != current); in worker_set_flags()
943 !(worker->flags & WORKER_NOT_RUNNING)) { in worker_set_flags()
947 worker->flags |= flags; in worker_set_flags()
960 static inline void worker_clr_flags(struct worker *worker, unsigned int flags) in worker_clr_flags() argument
962 struct worker_pool *pool = worker->pool; in worker_clr_flags()
963 unsigned int oflags = worker->flags; in worker_clr_flags()
965 WARN_ON_ONCE(worker->task != current); in worker_clr_flags()
967 worker->flags &= ~flags; in worker_clr_flags()
975 if (!(worker->flags & WORKER_NOT_RUNNING)) in worker_clr_flags()
1012 static struct worker *find_worker_executing_work(struct worker_pool *pool, in find_worker_executing_work()
1015 struct worker *worker; in find_worker_executing_work() local
1017 hash_for_each_possible(pool->busy_hash, worker, hentry, in find_worker_executing_work()
1019 if (worker->current_work == work && in find_worker_executing_work()
1020 worker->current_func == work->func) in find_worker_executing_work()
1021 return worker; in find_worker_executing_work()
1331 struct worker *worker; in is_chained_work() local
1333 worker = current_wq_worker(); in is_chained_work()
1338 return worker && worker->current_pwq->wq == wq; in is_chained_work()
1381 struct worker *worker; in __queue_work() local
1385 worker = find_worker_executing_work(last_pool, work); in __queue_work()
1387 if (worker && worker->current_pwq->wq == wq) { in __queue_work()
1388 pwq = worker->current_pwq; in __queue_work()
1593 static void worker_enter_idle(struct worker *worker) in worker_enter_idle() argument
1595 struct worker_pool *pool = worker->pool; in worker_enter_idle()
1597 if (WARN_ON_ONCE(worker->flags & WORKER_IDLE) || in worker_enter_idle()
1598 WARN_ON_ONCE(!list_empty(&worker->entry) && in worker_enter_idle()
1599 (worker->hentry.next || worker->hentry.pprev))) in worker_enter_idle()
1603 worker->flags |= WORKER_IDLE; in worker_enter_idle()
1605 worker->last_active = jiffies; in worker_enter_idle()
1608 list_add(&worker->entry, &pool->idle_list); in worker_enter_idle()
1633 static void worker_leave_idle(struct worker *worker) in worker_leave_idle() argument
1635 struct worker_pool *pool = worker->pool; in worker_leave_idle()
1637 if (WARN_ON_ONCE(!(worker->flags & WORKER_IDLE))) in worker_leave_idle()
1639 worker_clr_flags(worker, WORKER_IDLE); in worker_leave_idle()
1641 list_del_init(&worker->entry); in worker_leave_idle()
1644 static struct worker *alloc_worker(int node) in alloc_worker()
1646 struct worker *worker; in alloc_worker() local
1648 worker = kzalloc_node(sizeof(*worker), GFP_KERNEL, node); in alloc_worker()
1649 if (worker) { in alloc_worker()
1650 INIT_LIST_HEAD(&worker->entry); in alloc_worker()
1651 INIT_LIST_HEAD(&worker->scheduled); in alloc_worker()
1652 INIT_LIST_HEAD(&worker->node); in alloc_worker()
1654 worker->flags = WORKER_PREP; in alloc_worker()
1656 return worker; in alloc_worker()
1668 static void worker_attach_to_pool(struct worker *worker, in worker_attach_to_pool() argument
1677 set_cpus_allowed_ptr(worker->task, pool->attrs->cpumask); in worker_attach_to_pool()
1685 worker->flags |= WORKER_UNBOUND; in worker_attach_to_pool()
1687 list_add_tail(&worker->node, &pool->workers); in worker_attach_to_pool()
1701 static void worker_detach_from_pool(struct worker *worker, in worker_detach_from_pool() argument
1707 list_del(&worker->node); in worker_detach_from_pool()
1713 worker->flags &= ~(WORKER_UNBOUND | WORKER_REBOUND); in worker_detach_from_pool()
1731 static struct worker *create_worker(struct worker_pool *pool) in create_worker()
1733 struct worker *worker = NULL; in create_worker() local
1742 worker = alloc_worker(pool->node); in create_worker()
1743 if (!worker) in create_worker()
1746 worker->pool = pool; in create_worker()
1747 worker->id = id; in create_worker()
1755 worker->task = kthread_create_on_node(worker_thread, worker, pool->node, in create_worker()
1757 if (IS_ERR(worker->task)) in create_worker()
1760 set_user_nice(worker->task, pool->attrs->nice); in create_worker()
1763 worker->task->flags |= PF_NO_SETAFFINITY; in create_worker()
1766 worker_attach_to_pool(worker, pool); in create_worker()
1770 worker->pool->nr_workers++; in create_worker()
1771 worker_enter_idle(worker); in create_worker()
1772 wake_up_process(worker->task); in create_worker()
1775 return worker; in create_worker()
1780 kfree(worker); in create_worker()
1794 static void destroy_worker(struct worker *worker) in destroy_worker() argument
1796 struct worker_pool *pool = worker->pool; in destroy_worker()
1801 if (WARN_ON(worker->current_work) || in destroy_worker()
1802 WARN_ON(!list_empty(&worker->scheduled)) || in destroy_worker()
1803 WARN_ON(!(worker->flags & WORKER_IDLE))) in destroy_worker()
1809 list_del_init(&worker->entry); in destroy_worker()
1810 worker->flags |= WORKER_DIE; in destroy_worker()
1811 wake_up_process(worker->task); in destroy_worker()
1821 struct worker *worker; in idle_worker_timeout() local
1825 worker = list_entry(pool->idle_list.prev, struct worker, entry); in idle_worker_timeout()
1826 expires = worker->last_active + IDLE_WORKER_TIMEOUT; in idle_worker_timeout()
1833 destroy_worker(worker); in idle_worker_timeout()
1958 static bool manage_workers(struct worker *worker) in manage_workers() argument
1960 struct worker_pool *pool = worker->pool; in manage_workers()
1974 pool->manager = worker; in manage_workers()
1997 static void process_one_work(struct worker *worker, struct work_struct *work) in process_one_work() argument
2002 struct worker_pool *pool = worker->pool; in process_one_work()
2005 struct worker *collision; in process_one_work()
2036 hash_add(pool->busy_hash, &worker->hentry, (unsigned long)work); in process_one_work()
2037 worker->current_work = work; in process_one_work()
2038 worker->current_func = work->func; in process_one_work()
2039 worker->current_pwq = pwq; in process_one_work()
2051 worker_set_flags(worker, WORKER_CPU_INTENSIVE); in process_one_work()
2076 worker->current_func(work); in process_one_work()
2089 worker->current_func); in process_one_work()
2108 worker_clr_flags(worker, WORKER_CPU_INTENSIVE); in process_one_work()
2111 hash_del(&worker->hentry); in process_one_work()
2112 worker->current_work = NULL; in process_one_work()
2113 worker->current_func = NULL; in process_one_work()
2114 worker->current_pwq = NULL; in process_one_work()
2115 worker->desc_valid = false; in process_one_work()
2131 static void process_scheduled_works(struct worker *worker) in process_scheduled_works() argument
2133 while (!list_empty(&worker->scheduled)) { in process_scheduled_works()
2134 struct work_struct *work = list_first_entry(&worker->scheduled, in process_scheduled_works()
2136 process_one_work(worker, work); in process_scheduled_works()
2154 struct worker *worker = __worker; in worker_thread() local
2155 struct worker_pool *pool = worker->pool; in worker_thread()
2158 worker->task->flags |= PF_WQ_WORKER; in worker_thread()
2163 if (unlikely(worker->flags & WORKER_DIE)) { in worker_thread()
2165 WARN_ON_ONCE(!list_empty(&worker->entry)); in worker_thread()
2166 worker->task->flags &= ~PF_WQ_WORKER; in worker_thread()
2168 set_task_comm(worker->task, "kworker/dying"); in worker_thread()
2169 ida_simple_remove(&pool->worker_ida, worker->id); in worker_thread()
2170 worker_detach_from_pool(worker, pool); in worker_thread()
2171 kfree(worker); in worker_thread()
2175 worker_leave_idle(worker); in worker_thread()
2182 if (unlikely(!may_start_working(pool)) && manage_workers(worker)) in worker_thread()
2190 WARN_ON_ONCE(!list_empty(&worker->scheduled)); in worker_thread()
2199 worker_clr_flags(worker, WORKER_PREP | WORKER_REBOUND); in worker_thread()
2208 process_one_work(worker, work); in worker_thread()
2209 if (unlikely(!list_empty(&worker->scheduled))) in worker_thread()
2210 process_scheduled_works(worker); in worker_thread()
2212 move_linked_works(work, &worker->scheduled, NULL); in worker_thread()
2213 process_scheduled_works(worker); in worker_thread()
2217 worker_set_flags(worker, WORKER_PREP); in worker_thread()
2226 worker_enter_idle(worker); in worker_thread()
2256 struct worker *rescuer = __rescuer; in rescuer_thread()
2403 struct work_struct *target, struct worker *worker) in insert_wq_barrier() argument
2423 if (worker) in insert_wq_barrier()
2424 head = worker->scheduled.next; in insert_wq_barrier()
2720 struct worker *worker = NULL; in start_flush_work() local
2740 worker = find_worker_executing_work(pool, work); in start_flush_work()
2741 if (!worker) in start_flush_work()
2743 pwq = worker->current_pwq; in start_flush_work()
2746 insert_wq_barrier(pwq, barr, work, worker); in start_flush_work()
3211 struct worker *worker; in put_unbound_pool() local
3236 while ((worker = first_idle_worker(pool))) in put_unbound_pool()
3237 destroy_worker(worker); in put_unbound_pool()
3903 struct worker *rescuer; in __alloc_workqueue_key()
4071 struct worker *worker = current_wq_worker(); in current_is_workqueue_rescuer() local
4073 return worker && worker->rescue_wq; in current_is_workqueue_rescuer()
4162 struct worker *worker = current_wq_worker(); in set_worker_desc() local
4165 if (worker) { in set_worker_desc()
4167 vsnprintf(worker->desc, sizeof(worker->desc), fmt, args); in set_worker_desc()
4169 worker->desc_valid = true; in set_worker_desc()
4194 struct worker *worker; in print_worker_info() local
4203 worker = probe_kthread_data(task); in print_worker_info()
4209 probe_kernel_read(&fn, &worker->current_func, sizeof(fn)); in print_worker_info()
4210 probe_kernel_read(&pwq, &worker->current_pwq, sizeof(pwq)); in print_worker_info()
4215 probe_kernel_read(&desc_valid, &worker->desc_valid, sizeof(desc_valid)); in print_worker_info()
4217 probe_kernel_read(desc, worker->desc, sizeof(desc) - 1); in print_worker_info()
4253 struct worker *worker; in show_pwq() local
4263 hash_for_each(pool->busy_hash, bkt, worker, hentry) { in show_pwq()
4264 if (worker->current_pwq == pwq) { in show_pwq()
4273 hash_for_each(pool->busy_hash, bkt, worker, hentry) { in show_pwq()
4274 if (worker->current_pwq != pwq) in show_pwq()
4278 task_pid_nr(worker->task), in show_pwq()
4279 worker == pwq->wq->rescuer ? "(RESCUER)" : "", in show_pwq()
4280 worker->current_func); in show_pwq()
4281 list_for_each_entry(work, &worker->scheduled, entry) in show_pwq()
4361 struct worker *worker; in show_workqueue_state() local
4374 list_for_each_entry(worker, &pool->idle_list, entry) { in show_workqueue_state()
4376 task_pid_nr(worker->task)); in show_workqueue_state()
4406 struct worker *worker; in wq_unbind_fn() local
4419 for_each_pool_worker(worker, pool) in wq_unbind_fn()
4420 worker->flags |= WORKER_UNBOUND; in wq_unbind_fn()
4464 struct worker *worker; in rebind_workers() local
4475 for_each_pool_worker(worker, pool) in rebind_workers()
4476 WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task, in rebind_workers()
4493 for_each_pool_worker(worker, pool) { in rebind_workers()
4494 unsigned int worker_flags = worker->flags; in rebind_workers()
4505 wake_up_process(worker->task); in rebind_workers()
4525 ACCESS_ONCE(worker->flags) = worker_flags; in rebind_workers()
4544 struct worker *worker; in restore_unbound_workers_cpumask() local
4558 for_each_pool_worker(worker, pool) in restore_unbound_workers_cpumask()
4559 WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task, in restore_unbound_workers_cpumask()