Lines Matching refs:worker
169 struct worker *manager; /* L: purely informational */
251 struct worker *rescuer; /* MD: rescue worker */
407 #define for_each_pool_worker(worker, pool) \ argument
408 list_for_each_entry((worker), &(pool)->workers, node) \
815 static struct worker *first_idle_worker(struct worker_pool *pool) in first_idle_worker()
820 return list_first_entry(&pool->idle_list, struct worker, entry); in first_idle_worker()
834 struct worker *worker = first_idle_worker(pool); in wake_up_worker() local
836 if (likely(worker)) in wake_up_worker()
837 wake_up_process(worker->task); in wake_up_worker()
848 struct worker *worker = kthread_data(task); in wq_worker_running() local
850 if (!worker->sleeping) in wq_worker_running()
852 if (!(worker->flags & WORKER_NOT_RUNNING)) in wq_worker_running()
853 atomic_inc(&worker->pool->nr_running); in wq_worker_running()
854 worker->sleeping = 0; in wq_worker_running()
867 struct worker *next, *worker = kthread_data(task); in wq_worker_sleeping() local
875 if (worker->flags & WORKER_NOT_RUNNING) in wq_worker_sleeping()
878 pool = worker->pool; in wq_worker_sleeping()
881 if (worker->sleeping) in wq_worker_sleeping()
884 worker->sleeping = 1; in wq_worker_sleeping()
933 struct worker *worker = kthread_data(task); in wq_worker_last_func() local
935 return worker->last_func; in wq_worker_last_func()
948 static inline void worker_set_flags(struct worker *worker, unsigned int flags) in worker_set_flags() argument
950 struct worker_pool *pool = worker->pool; in worker_set_flags()
952 WARN_ON_ONCE(worker->task != current); in worker_set_flags()
956 !(worker->flags & WORKER_NOT_RUNNING)) { in worker_set_flags()
960 worker->flags |= flags; in worker_set_flags()
973 static inline void worker_clr_flags(struct worker *worker, unsigned int flags) in worker_clr_flags() argument
975 struct worker_pool *pool = worker->pool; in worker_clr_flags()
976 unsigned int oflags = worker->flags; in worker_clr_flags()
978 WARN_ON_ONCE(worker->task != current); in worker_clr_flags()
980 worker->flags &= ~flags; in worker_clr_flags()
988 if (!(worker->flags & WORKER_NOT_RUNNING)) in worker_clr_flags()
1025 static struct worker *find_worker_executing_work(struct worker_pool *pool, in find_worker_executing_work()
1028 struct worker *worker; in find_worker_executing_work() local
1030 hash_for_each_possible(pool->busy_hash, worker, hentry, in find_worker_executing_work()
1032 if (worker->current_work == work && in find_worker_executing_work()
1033 worker->current_func == work->func) in find_worker_executing_work()
1034 return worker; in find_worker_executing_work()
1352 struct worker *worker; in is_chained_work() local
1354 worker = current_wq_worker(); in is_chained_work()
1359 return worker && worker->current_pwq->wq == wq; in is_chained_work()
1438 struct worker *worker; in __queue_work() local
1442 worker = find_worker_executing_work(last_pool, work); in __queue_work()
1444 if (worker && worker->current_pwq->wq == wq) { in __queue_work()
1445 pwq = worker->current_pwq; in __queue_work()
1768 static void worker_enter_idle(struct worker *worker) in worker_enter_idle() argument
1770 struct worker_pool *pool = worker->pool; in worker_enter_idle()
1772 if (WARN_ON_ONCE(worker->flags & WORKER_IDLE) || in worker_enter_idle()
1773 WARN_ON_ONCE(!list_empty(&worker->entry) && in worker_enter_idle()
1774 (worker->hentry.next || worker->hentry.pprev))) in worker_enter_idle()
1778 worker->flags |= WORKER_IDLE; in worker_enter_idle()
1780 worker->last_active = jiffies; in worker_enter_idle()
1783 list_add(&worker->entry, &pool->idle_list); in worker_enter_idle()
1808 static void worker_leave_idle(struct worker *worker) in worker_leave_idle() argument
1810 struct worker_pool *pool = worker->pool; in worker_leave_idle()
1812 if (WARN_ON_ONCE(!(worker->flags & WORKER_IDLE))) in worker_leave_idle()
1814 worker_clr_flags(worker, WORKER_IDLE); in worker_leave_idle()
1816 list_del_init(&worker->entry); in worker_leave_idle()
1819 static struct worker *alloc_worker(int node) in alloc_worker()
1821 struct worker *worker; in alloc_worker() local
1823 worker = kzalloc_node(sizeof(*worker), GFP_KERNEL, node); in alloc_worker()
1824 if (worker) { in alloc_worker()
1825 INIT_LIST_HEAD(&worker->entry); in alloc_worker()
1826 INIT_LIST_HEAD(&worker->scheduled); in alloc_worker()
1827 INIT_LIST_HEAD(&worker->node); in alloc_worker()
1829 worker->flags = WORKER_PREP; in alloc_worker()
1831 return worker; in alloc_worker()
1843 static void worker_attach_to_pool(struct worker *worker, in worker_attach_to_pool() argument
1852 set_cpus_allowed_ptr(worker->task, pool->attrs->cpumask); in worker_attach_to_pool()
1860 worker->flags |= WORKER_UNBOUND; in worker_attach_to_pool()
1862 list_add_tail(&worker->node, &pool->workers); in worker_attach_to_pool()
1863 worker->pool = pool; in worker_attach_to_pool()
1876 static void worker_detach_from_pool(struct worker *worker) in worker_detach_from_pool() argument
1878 struct worker_pool *pool = worker->pool; in worker_detach_from_pool()
1883 list_del(&worker->node); in worker_detach_from_pool()
1884 worker->pool = NULL; in worker_detach_from_pool()
1891 worker->flags &= ~(WORKER_UNBOUND | WORKER_REBOUND); in worker_detach_from_pool()
1909 static struct worker *create_worker(struct worker_pool *pool) in create_worker()
1911 struct worker *worker = NULL; in create_worker() local
1920 worker = alloc_worker(pool->node); in create_worker()
1921 if (!worker) in create_worker()
1924 worker->id = id; in create_worker()
1932 worker->task = kthread_create_on_node(worker_thread, worker, pool->node, in create_worker()
1934 if (IS_ERR(worker->task)) in create_worker()
1937 set_user_nice(worker->task, pool->attrs->nice); in create_worker()
1938 kthread_bind_mask(worker->task, pool->attrs->cpumask); in create_worker()
1941 worker_attach_to_pool(worker, pool); in create_worker()
1945 worker->pool->nr_workers++; in create_worker()
1946 worker_enter_idle(worker); in create_worker()
1947 wake_up_process(worker->task); in create_worker()
1950 return worker; in create_worker()
1955 kfree(worker); in create_worker()
1969 static void destroy_worker(struct worker *worker) in destroy_worker() argument
1971 struct worker_pool *pool = worker->pool; in destroy_worker()
1976 if (WARN_ON(worker->current_work) || in destroy_worker()
1977 WARN_ON(!list_empty(&worker->scheduled)) || in destroy_worker()
1978 WARN_ON(!(worker->flags & WORKER_IDLE))) in destroy_worker()
1984 list_del_init(&worker->entry); in destroy_worker()
1985 worker->flags |= WORKER_DIE; in destroy_worker()
1986 wake_up_process(worker->task); in destroy_worker()
1996 struct worker *worker; in idle_worker_timeout() local
2000 worker = list_entry(pool->idle_list.prev, struct worker, entry); in idle_worker_timeout()
2001 expires = worker->last_active + IDLE_WORKER_TIMEOUT; in idle_worker_timeout()
2008 destroy_worker(worker); in idle_worker_timeout()
2133 static bool manage_workers(struct worker *worker) in manage_workers() argument
2135 struct worker_pool *pool = worker->pool; in manage_workers()
2141 pool->manager = worker; in manage_workers()
2165 static void process_one_work(struct worker *worker, struct work_struct *work) in process_one_work() argument
2170 struct worker_pool *pool = worker->pool; in process_one_work()
2173 struct worker *collision; in process_one_work()
2204 hash_add(pool->busy_hash, &worker->hentry, (unsigned long)work); in process_one_work()
2205 worker->current_work = work; in process_one_work()
2206 worker->current_func = work->func; in process_one_work()
2207 worker->current_pwq = pwq; in process_one_work()
2214 strscpy(worker->desc, pwq->wq->name, WORKER_DESC_LEN); in process_one_work()
2225 worker_set_flags(worker, WORKER_CPU_INTENSIVE); in process_one_work()
2272 worker->current_func(work); in process_one_work()
2277 trace_workqueue_execute_end(work, worker->current_func); in process_one_work()
2285 worker->current_func); in process_one_work()
2304 worker_clr_flags(worker, WORKER_CPU_INTENSIVE); in process_one_work()
2307 worker->last_func = worker->current_func; in process_one_work()
2310 hash_del(&worker->hentry); in process_one_work()
2311 worker->current_work = NULL; in process_one_work()
2312 worker->current_func = NULL; in process_one_work()
2313 worker->current_pwq = NULL; in process_one_work()
2329 static void process_scheduled_works(struct worker *worker) in process_scheduled_works() argument
2331 while (!list_empty(&worker->scheduled)) { in process_scheduled_works()
2332 struct work_struct *work = list_first_entry(&worker->scheduled, in process_scheduled_works()
2334 process_one_work(worker, work); in process_scheduled_works()
2362 struct worker *worker = __worker; in worker_thread() local
2363 struct worker_pool *pool = worker->pool; in worker_thread()
2371 if (unlikely(worker->flags & WORKER_DIE)) { in worker_thread()
2373 WARN_ON_ONCE(!list_empty(&worker->entry)); in worker_thread()
2376 set_task_comm(worker->task, "kworker/dying"); in worker_thread()
2377 ida_simple_remove(&pool->worker_ida, worker->id); in worker_thread()
2378 worker_detach_from_pool(worker); in worker_thread()
2379 kfree(worker); in worker_thread()
2383 worker_leave_idle(worker); in worker_thread()
2390 if (unlikely(!may_start_working(pool)) && manage_workers(worker)) in worker_thread()
2398 WARN_ON_ONCE(!list_empty(&worker->scheduled)); in worker_thread()
2407 worker_clr_flags(worker, WORKER_PREP | WORKER_REBOUND); in worker_thread()
2418 process_one_work(worker, work); in worker_thread()
2419 if (unlikely(!list_empty(&worker->scheduled))) in worker_thread()
2420 process_scheduled_works(worker); in worker_thread()
2422 move_linked_works(work, &worker->scheduled, NULL); in worker_thread()
2423 process_scheduled_works(worker); in worker_thread()
2427 worker_set_flags(worker, WORKER_PREP); in worker_thread()
2436 worker_enter_idle(worker); in worker_thread()
2466 struct worker *rescuer = __rescuer; in rescuer_thread()
2600 struct worker *worker; in check_flush_dependency() local
2605 worker = current_wq_worker(); in check_flush_dependency()
2610 WARN_ONCE(worker && ((worker->current_pwq->wq->flags & in check_flush_dependency()
2613 worker->current_pwq->wq->name, worker->current_func, in check_flush_dependency()
2655 struct work_struct *target, struct worker *worker) in insert_wq_barrier() argument
2677 if (worker) in insert_wq_barrier()
2678 head = worker->scheduled.next; in insert_wq_barrier()
2980 struct worker *worker = NULL; in start_flush_work() local
3000 worker = find_worker_executing_work(pool, work); in start_flush_work()
3001 if (!worker) in start_flush_work()
3003 pwq = worker->current_pwq; in start_flush_work()
3008 insert_wq_barrier(pwq, barr, work, worker); in start_flush_work()
3536 struct worker *worker; in put_unbound_pool() local
3564 while ((worker = first_idle_worker(pool))) in put_unbound_pool()
3565 destroy_worker(worker); in put_unbound_pool()
4215 struct worker *rescuer; in init_rescuer()
4376 struct worker *rescuer = wq->rescuer; in destroy_workqueue()
4489 struct worker *worker = current_wq_worker(); in current_work() local
4491 return worker ? worker->current_work : NULL; in current_work()
4505 struct worker *worker = current_wq_worker(); in current_is_workqueue_rescuer() local
4507 return worker && worker->rescue_wq; in current_is_workqueue_rescuer()
4598 struct worker *worker = current_wq_worker(); in set_worker_desc() local
4601 if (worker) { in set_worker_desc()
4603 vsnprintf(worker->desc, sizeof(worker->desc), fmt, args); in set_worker_desc()
4629 struct worker *worker; in print_worker_info() local
4638 worker = kthread_probe_data(task); in print_worker_info()
4644 copy_from_kernel_nofault(&fn, &worker->current_func, sizeof(fn)); in print_worker_info()
4645 copy_from_kernel_nofault(&pwq, &worker->current_pwq, sizeof(pwq)); in print_worker_info()
4648 copy_from_kernel_nofault(desc, worker->desc, sizeof(desc) - 1); in print_worker_info()
4684 struct worker *worker; in show_pwq() local
4695 hash_for_each(pool->busy_hash, bkt, worker, hentry) { in show_pwq()
4696 if (worker->current_pwq == pwq) { in show_pwq()
4705 hash_for_each(pool->busy_hash, bkt, worker, hentry) { in show_pwq()
4706 if (worker->current_pwq != pwq) in show_pwq()
4710 task_pid_nr(worker->task), in show_pwq()
4711 worker->rescue_wq ? "(RESCUER)" : "", in show_pwq()
4712 worker->current_func); in show_pwq()
4713 list_for_each_entry(work, &worker->scheduled, entry) in show_pwq()
4799 struct worker *worker; in show_workqueue_state() local
4814 list_for_each_entry(worker, &pool->idle_list, entry) { in show_workqueue_state()
4816 task_pid_nr(worker->task)); in show_workqueue_state()
4847 struct worker *worker = kthread_data(task); in wq_worker_comm() local
4848 struct worker_pool *pool = worker->pool; in wq_worker_comm()
4857 if (worker->desc[0] != '\0') { in wq_worker_comm()
4858 if (worker->current_work) in wq_worker_comm()
4860 worker->desc); in wq_worker_comm()
4863 worker->desc); in wq_worker_comm()
4892 struct worker *worker; in unbind_workers() local
4905 for_each_pool_worker(worker, pool) in unbind_workers()
4906 worker->flags |= WORKER_UNBOUND; in unbind_workers()
4950 struct worker *worker; in rebind_workers() local
4961 for_each_pool_worker(worker, pool) in rebind_workers()
4962 WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task, in rebind_workers()
4969 for_each_pool_worker(worker, pool) { in rebind_workers()
4970 unsigned int worker_flags = worker->flags; in rebind_workers()
4981 wake_up_process(worker->task); in rebind_workers()
5001 WRITE_ONCE(worker->flags, worker_flags); in rebind_workers()
5020 struct worker *worker; in restore_unbound_workers_cpumask() local
5031 for_each_pool_worker(worker, pool) in restore_unbound_workers_cpumask()
5032 WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task, &cpumask) < 0); in restore_unbound_workers_cpumask()