Lines Matching refs:worker
168 struct worker *manager; /* L: purely informational */
250 struct worker *rescuer; /* I: rescue worker */
407 #define for_each_pool_worker(worker, pool) \ argument
408 list_for_each_entry((worker), &(pool)->workers, node) \
816 static struct worker *first_idle_worker(struct worker_pool *pool) in first_idle_worker()
821 return list_first_entry(&pool->idle_list, struct worker, entry); in first_idle_worker()
835 struct worker *worker = first_idle_worker(pool); in wake_up_worker() local
837 if (likely(worker)) in wake_up_worker()
838 wake_up_process(worker->task); in wake_up_worker()
854 struct worker *worker = kthread_data(task); in wq_worker_waking_up() local
856 if (!(worker->flags & WORKER_NOT_RUNNING)) { in wq_worker_waking_up()
857 WARN_ON_ONCE(worker->pool->cpu != cpu); in wq_worker_waking_up()
858 atomic_inc(&worker->pool->nr_running); in wq_worker_waking_up()
878 struct worker *worker = kthread_data(task), *to_wakeup = NULL; in wq_worker_sleeping() local
886 if (worker->flags & WORKER_NOT_RUNNING) in wq_worker_sleeping()
889 pool = worker->pool; in wq_worker_sleeping()
922 static inline void worker_set_flags(struct worker *worker, unsigned int flags) in worker_set_flags() argument
924 struct worker_pool *pool = worker->pool; in worker_set_flags()
926 WARN_ON_ONCE(worker->task != current); in worker_set_flags()
930 !(worker->flags & WORKER_NOT_RUNNING)) { in worker_set_flags()
934 worker->flags |= flags; in worker_set_flags()
947 static inline void worker_clr_flags(struct worker *worker, unsigned int flags) in worker_clr_flags() argument
949 struct worker_pool *pool = worker->pool; in worker_clr_flags()
950 unsigned int oflags = worker->flags; in worker_clr_flags()
952 WARN_ON_ONCE(worker->task != current); in worker_clr_flags()
954 worker->flags &= ~flags; in worker_clr_flags()
962 if (!(worker->flags & WORKER_NOT_RUNNING)) in worker_clr_flags()
999 static struct worker *find_worker_executing_work(struct worker_pool *pool, in find_worker_executing_work()
1002 struct worker *worker; in find_worker_executing_work() local
1004 hash_for_each_possible(pool->busy_hash, worker, hentry, in find_worker_executing_work()
1006 if (worker->current_work == work && in find_worker_executing_work()
1007 worker->current_func == work->func) in find_worker_executing_work()
1008 return worker; in find_worker_executing_work()
1320 struct worker *worker; in is_chained_work() local
1322 worker = current_wq_worker(); in is_chained_work()
1327 return worker && worker->current_pwq->wq == wq; in is_chained_work()
1403 struct worker *worker; in __queue_work() local
1407 worker = find_worker_executing_work(last_pool, work); in __queue_work()
1409 if (worker && worker->current_pwq->wq == wq) { in __queue_work()
1410 pwq = worker->current_pwq; in __queue_work()
1649 static void worker_enter_idle(struct worker *worker) in worker_enter_idle() argument
1651 struct worker_pool *pool = worker->pool; in worker_enter_idle()
1653 if (WARN_ON_ONCE(worker->flags & WORKER_IDLE) || in worker_enter_idle()
1654 WARN_ON_ONCE(!list_empty(&worker->entry) && in worker_enter_idle()
1655 (worker->hentry.next || worker->hentry.pprev))) in worker_enter_idle()
1659 worker->flags |= WORKER_IDLE; in worker_enter_idle()
1661 worker->last_active = jiffies; in worker_enter_idle()
1664 list_add(&worker->entry, &pool->idle_list); in worker_enter_idle()
1689 static void worker_leave_idle(struct worker *worker) in worker_leave_idle() argument
1691 struct worker_pool *pool = worker->pool; in worker_leave_idle()
1693 if (WARN_ON_ONCE(!(worker->flags & WORKER_IDLE))) in worker_leave_idle()
1695 worker_clr_flags(worker, WORKER_IDLE); in worker_leave_idle()
1697 list_del_init(&worker->entry); in worker_leave_idle()
1700 static struct worker *alloc_worker(int node) in alloc_worker()
1702 struct worker *worker; in alloc_worker() local
1704 worker = kzalloc_node(sizeof(*worker), GFP_KERNEL, node); in alloc_worker()
1705 if (worker) { in alloc_worker()
1706 INIT_LIST_HEAD(&worker->entry); in alloc_worker()
1707 INIT_LIST_HEAD(&worker->scheduled); in alloc_worker()
1708 INIT_LIST_HEAD(&worker->node); in alloc_worker()
1710 worker->flags = WORKER_PREP; in alloc_worker()
1712 return worker; in alloc_worker()
1724 static void worker_attach_to_pool(struct worker *worker, in worker_attach_to_pool() argument
1733 set_cpus_allowed_ptr(worker->task, pool->attrs->cpumask); in worker_attach_to_pool()
1741 worker->flags |= WORKER_UNBOUND; in worker_attach_to_pool()
1743 list_add_tail(&worker->node, &pool->workers); in worker_attach_to_pool()
1744 worker->pool = pool; in worker_attach_to_pool()
1757 static void worker_detach_from_pool(struct worker *worker) in worker_detach_from_pool() argument
1759 struct worker_pool *pool = worker->pool; in worker_detach_from_pool()
1764 list_del(&worker->node); in worker_detach_from_pool()
1765 worker->pool = NULL; in worker_detach_from_pool()
1772 worker->flags &= ~(WORKER_UNBOUND | WORKER_REBOUND); in worker_detach_from_pool()
1790 static struct worker *create_worker(struct worker_pool *pool) in create_worker()
1792 struct worker *worker = NULL; in create_worker() local
1801 worker = alloc_worker(pool->node); in create_worker()
1802 if (!worker) in create_worker()
1805 worker->id = id; in create_worker()
1813 worker->task = kthread_create_on_node(worker_thread, worker, pool->node, in create_worker()
1815 if (IS_ERR(worker->task)) in create_worker()
1818 set_user_nice(worker->task, pool->attrs->nice); in create_worker()
1819 kthread_bind_mask(worker->task, pool->attrs->cpumask); in create_worker()
1822 worker_attach_to_pool(worker, pool); in create_worker()
1826 worker->pool->nr_workers++; in create_worker()
1827 worker_enter_idle(worker); in create_worker()
1828 wake_up_process(worker->task); in create_worker()
1831 return worker; in create_worker()
1836 kfree(worker); in create_worker()
1850 static void destroy_worker(struct worker *worker) in destroy_worker() argument
1852 struct worker_pool *pool = worker->pool; in destroy_worker()
1857 if (WARN_ON(worker->current_work) || in destroy_worker()
1858 WARN_ON(!list_empty(&worker->scheduled)) || in destroy_worker()
1859 WARN_ON(!(worker->flags & WORKER_IDLE))) in destroy_worker()
1865 list_del_init(&worker->entry); in destroy_worker()
1866 worker->flags |= WORKER_DIE; in destroy_worker()
1867 wake_up_process(worker->task); in destroy_worker()
1877 struct worker *worker; in idle_worker_timeout() local
1881 worker = list_entry(pool->idle_list.prev, struct worker, entry); in idle_worker_timeout()
1882 expires = worker->last_active + IDLE_WORKER_TIMEOUT; in idle_worker_timeout()
1889 destroy_worker(worker); in idle_worker_timeout()
2014 static bool manage_workers(struct worker *worker) in manage_workers() argument
2016 struct worker_pool *pool = worker->pool; in manage_workers()
2022 pool->manager = worker; in manage_workers()
2046 static void process_one_work(struct worker *worker, struct work_struct *work) in process_one_work() argument
2051 struct worker_pool *pool = worker->pool; in process_one_work()
2054 struct worker *collision; in process_one_work()
2085 hash_add(pool->busy_hash, &worker->hentry, (unsigned long)work); in process_one_work()
2086 worker->current_work = work; in process_one_work()
2087 worker->current_func = work->func; in process_one_work()
2088 worker->current_pwq = pwq; in process_one_work()
2095 strscpy(worker->desc, pwq->wq->name, WORKER_DESC_LEN); in process_one_work()
2106 worker_set_flags(worker, WORKER_CPU_INTENSIVE); in process_one_work()
2153 worker->current_func(work); in process_one_work()
2166 worker->current_func); in process_one_work()
2185 worker_clr_flags(worker, WORKER_CPU_INTENSIVE); in process_one_work()
2188 hash_del(&worker->hentry); in process_one_work()
2189 worker->current_work = NULL; in process_one_work()
2190 worker->current_func = NULL; in process_one_work()
2191 worker->current_pwq = NULL; in process_one_work()
2207 static void process_scheduled_works(struct worker *worker) in process_scheduled_works() argument
2209 while (!list_empty(&worker->scheduled)) { in process_scheduled_works()
2210 struct work_struct *work = list_first_entry(&worker->scheduled, in process_scheduled_works()
2212 process_one_work(worker, work); in process_scheduled_works()
2240 struct worker *worker = __worker; in worker_thread() local
2241 struct worker_pool *pool = worker->pool; in worker_thread()
2249 if (unlikely(worker->flags & WORKER_DIE)) { in worker_thread()
2251 WARN_ON_ONCE(!list_empty(&worker->entry)); in worker_thread()
2254 set_task_comm(worker->task, "kworker/dying"); in worker_thread()
2255 ida_simple_remove(&pool->worker_ida, worker->id); in worker_thread()
2256 worker_detach_from_pool(worker); in worker_thread()
2257 kfree(worker); in worker_thread()
2261 worker_leave_idle(worker); in worker_thread()
2268 if (unlikely(!may_start_working(pool)) && manage_workers(worker)) in worker_thread()
2276 WARN_ON_ONCE(!list_empty(&worker->scheduled)); in worker_thread()
2285 worker_clr_flags(worker, WORKER_PREP | WORKER_REBOUND); in worker_thread()
2296 process_one_work(worker, work); in worker_thread()
2297 if (unlikely(!list_empty(&worker->scheduled))) in worker_thread()
2298 process_scheduled_works(worker); in worker_thread()
2300 move_linked_works(work, &worker->scheduled, NULL); in worker_thread()
2301 process_scheduled_works(worker); in worker_thread()
2305 worker_set_flags(worker, WORKER_PREP); in worker_thread()
2314 worker_enter_idle(worker); in worker_thread()
2344 struct worker *rescuer = __rescuer; in rescuer_thread()
2472 struct worker *worker; in check_flush_dependency() local
2477 worker = current_wq_worker(); in check_flush_dependency()
2482 WARN_ONCE(worker && ((worker->current_pwq->wq->flags & in check_flush_dependency()
2485 worker->current_pwq->wq->name, worker->current_func, in check_flush_dependency()
2527 struct work_struct *target, struct worker *worker) in insert_wq_barrier() argument
2549 if (worker) in insert_wq_barrier()
2550 head = worker->scheduled.next; in insert_wq_barrier()
2852 struct worker *worker = NULL; in start_flush_work() local
2872 worker = find_worker_executing_work(pool, work); in start_flush_work()
2873 if (!worker) in start_flush_work()
2875 pwq = worker->current_pwq; in start_flush_work()
2880 insert_wq_barrier(pwq, barr, work, worker); in start_flush_work()
3354 struct worker *worker; in put_unbound_pool() local
3381 while ((worker = first_idle_worker(pool))) in put_unbound_pool()
3382 destroy_worker(worker); in put_unbound_pool()
4022 struct worker *rescuer; in init_rescuer()
4264 struct worker *worker = current_wq_worker(); in current_work() local
4266 return worker ? worker->current_work : NULL; in current_work()
4280 struct worker *worker = current_wq_worker(); in current_is_workqueue_rescuer() local
4282 return worker && worker->rescue_wq; in current_is_workqueue_rescuer()
4371 struct worker *worker = current_wq_worker(); in set_worker_desc() local
4374 if (worker) { in set_worker_desc()
4376 vsnprintf(worker->desc, sizeof(worker->desc), fmt, args); in set_worker_desc()
4402 struct worker *worker; in print_worker_info() local
4411 worker = kthread_probe_data(task); in print_worker_info()
4417 probe_kernel_read(&fn, &worker->current_func, sizeof(fn)); in print_worker_info()
4418 probe_kernel_read(&pwq, &worker->current_pwq, sizeof(pwq)); in print_worker_info()
4421 probe_kernel_read(desc, worker->desc, sizeof(desc) - 1); in print_worker_info()
4457 struct worker *worker; in show_pwq() local
4467 hash_for_each(pool->busy_hash, bkt, worker, hentry) { in show_pwq()
4468 if (worker->current_pwq == pwq) { in show_pwq()
4477 hash_for_each(pool->busy_hash, bkt, worker, hentry) { in show_pwq()
4478 if (worker->current_pwq != pwq) in show_pwq()
4482 task_pid_nr(worker->task), in show_pwq()
4483 worker == pwq->wq->rescuer ? "(RESCUER)" : "", in show_pwq()
4484 worker->current_func); in show_pwq()
4485 list_for_each_entry(work, &worker->scheduled, entry) in show_pwq()
4571 struct worker *worker; in show_workqueue_state() local
4586 list_for_each_entry(worker, &pool->idle_list, entry) { in show_workqueue_state()
4588 task_pid_nr(worker->task)); in show_workqueue_state()
4619 struct worker *worker = kthread_data(task); in wq_worker_comm() local
4620 struct worker_pool *pool = worker->pool; in wq_worker_comm()
4629 if (worker->desc[0] != '\0') { in wq_worker_comm()
4630 if (worker->current_work) in wq_worker_comm()
4632 worker->desc); in wq_worker_comm()
4635 worker->desc); in wq_worker_comm()
4664 struct worker *worker; in unbind_workers() local
4677 for_each_pool_worker(worker, pool) in unbind_workers()
4678 worker->flags |= WORKER_UNBOUND; in unbind_workers()
4722 struct worker *worker; in rebind_workers() local
4733 for_each_pool_worker(worker, pool) in rebind_workers()
4734 WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task, in rebind_workers()
4741 for_each_pool_worker(worker, pool) { in rebind_workers()
4742 unsigned int worker_flags = worker->flags; in rebind_workers()
4753 wake_up_process(worker->task); in rebind_workers()
4773 WRITE_ONCE(worker->flags, worker_flags); in rebind_workers()
4792 struct worker *worker; in restore_unbound_workers_cpumask() local
4803 for_each_pool_worker(worker, pool) in restore_unbound_workers_cpumask()
4804 WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task, &cpumask) < 0); in restore_unbound_workers_cpumask()