Lines Matching refs:worker
169 struct worker *manager; /* L: purely informational */
251 struct worker *rescuer; /* I: rescue worker */
410 #define for_each_pool_worker(worker, pool) \ argument
411 list_for_each_entry((worker), &(pool)->workers, node) \
819 static struct worker *first_idle_worker(struct worker_pool *pool) in first_idle_worker()
824 return list_first_entry(&pool->idle_list, struct worker, entry); in first_idle_worker()
838 struct worker *worker = first_idle_worker(pool); in wake_up_worker() local
840 if (likely(worker)) in wake_up_worker()
841 wake_up_process(worker->task); in wake_up_worker()
852 struct worker *worker = kthread_data(task); in wq_worker_running() local
854 if (!worker->sleeping) in wq_worker_running()
856 if (!(worker->flags & WORKER_NOT_RUNNING)) in wq_worker_running()
857 atomic_inc(&worker->pool->nr_running); in wq_worker_running()
858 worker->sleeping = 0; in wq_worker_running()
870 struct worker *next, *worker = kthread_data(task); in wq_worker_sleeping() local
878 if (worker->flags & WORKER_NOT_RUNNING) in wq_worker_sleeping()
881 pool = worker->pool; in wq_worker_sleeping()
883 if (WARN_ON_ONCE(worker->sleeping)) in wq_worker_sleeping()
886 worker->sleeping = 1; in wq_worker_sleeping()
935 struct worker *worker = kthread_data(task); in wq_worker_last_func() local
937 return worker->last_func; in wq_worker_last_func()
950 static inline void worker_set_flags(struct worker *worker, unsigned int flags) in worker_set_flags() argument
952 struct worker_pool *pool = worker->pool; in worker_set_flags()
954 WARN_ON_ONCE(worker->task != current); in worker_set_flags()
958 !(worker->flags & WORKER_NOT_RUNNING)) { in worker_set_flags()
962 worker->flags |= flags; in worker_set_flags()
975 static inline void worker_clr_flags(struct worker *worker, unsigned int flags) in worker_clr_flags() argument
977 struct worker_pool *pool = worker->pool; in worker_clr_flags()
978 unsigned int oflags = worker->flags; in worker_clr_flags()
980 WARN_ON_ONCE(worker->task != current); in worker_clr_flags()
982 worker->flags &= ~flags; in worker_clr_flags()
990 if (!(worker->flags & WORKER_NOT_RUNNING)) in worker_clr_flags()
1027 static struct worker *find_worker_executing_work(struct worker_pool *pool, in find_worker_executing_work()
1030 struct worker *worker; in find_worker_executing_work() local
1032 hash_for_each_possible(pool->busy_hash, worker, hentry, in find_worker_executing_work()
1034 if (worker->current_work == work && in find_worker_executing_work()
1035 worker->current_func == work->func) in find_worker_executing_work()
1036 return worker; in find_worker_executing_work()
1351 struct worker *worker; in is_chained_work() local
1353 worker = current_wq_worker(); in is_chained_work()
1358 return worker && worker->current_pwq->wq == wq; in is_chained_work()
1435 struct worker *worker; in __queue_work() local
1439 worker = find_worker_executing_work(last_pool, work); in __queue_work()
1441 if (worker && worker->current_pwq->wq == wq) { in __queue_work()
1442 pwq = worker->current_pwq; in __queue_work()
1765 static void worker_enter_idle(struct worker *worker) in worker_enter_idle() argument
1767 struct worker_pool *pool = worker->pool; in worker_enter_idle()
1769 if (WARN_ON_ONCE(worker->flags & WORKER_IDLE) || in worker_enter_idle()
1770 WARN_ON_ONCE(!list_empty(&worker->entry) && in worker_enter_idle()
1771 (worker->hentry.next || worker->hentry.pprev))) in worker_enter_idle()
1775 worker->flags |= WORKER_IDLE; in worker_enter_idle()
1777 worker->last_active = jiffies; in worker_enter_idle()
1780 list_add(&worker->entry, &pool->idle_list); in worker_enter_idle()
1805 static void worker_leave_idle(struct worker *worker) in worker_leave_idle() argument
1807 struct worker_pool *pool = worker->pool; in worker_leave_idle()
1809 if (WARN_ON_ONCE(!(worker->flags & WORKER_IDLE))) in worker_leave_idle()
1811 worker_clr_flags(worker, WORKER_IDLE); in worker_leave_idle()
1813 list_del_init(&worker->entry); in worker_leave_idle()
1816 static struct worker *alloc_worker(int node) in alloc_worker()
1818 struct worker *worker; in alloc_worker() local
1820 worker = kzalloc_node(sizeof(*worker), GFP_KERNEL, node); in alloc_worker()
1821 if (worker) { in alloc_worker()
1822 INIT_LIST_HEAD(&worker->entry); in alloc_worker()
1823 INIT_LIST_HEAD(&worker->scheduled); in alloc_worker()
1824 INIT_LIST_HEAD(&worker->node); in alloc_worker()
1826 worker->flags = WORKER_PREP; in alloc_worker()
1828 return worker; in alloc_worker()
1840 static void worker_attach_to_pool(struct worker *worker, in worker_attach_to_pool() argument
1849 set_cpus_allowed_ptr(worker->task, pool->attrs->cpumask); in worker_attach_to_pool()
1857 worker->flags |= WORKER_UNBOUND; in worker_attach_to_pool()
1859 list_add_tail(&worker->node, &pool->workers); in worker_attach_to_pool()
1860 worker->pool = pool; in worker_attach_to_pool()
1873 static void worker_detach_from_pool(struct worker *worker) in worker_detach_from_pool() argument
1875 struct worker_pool *pool = worker->pool; in worker_detach_from_pool()
1880 list_del(&worker->node); in worker_detach_from_pool()
1881 worker->pool = NULL; in worker_detach_from_pool()
1888 worker->flags &= ~(WORKER_UNBOUND | WORKER_REBOUND); in worker_detach_from_pool()
1906 static struct worker *create_worker(struct worker_pool *pool) in create_worker()
1908 struct worker *worker = NULL; in create_worker() local
1917 worker = alloc_worker(pool->node); in create_worker()
1918 if (!worker) in create_worker()
1921 worker->id = id; in create_worker()
1929 worker->task = kthread_create_on_node(worker_thread, worker, pool->node, in create_worker()
1931 if (IS_ERR(worker->task)) in create_worker()
1934 set_user_nice(worker->task, pool->attrs->nice); in create_worker()
1935 kthread_bind_mask(worker->task, pool->attrs->cpumask); in create_worker()
1938 worker_attach_to_pool(worker, pool); in create_worker()
1942 worker->pool->nr_workers++; in create_worker()
1943 worker_enter_idle(worker); in create_worker()
1944 wake_up_process(worker->task); in create_worker()
1947 return worker; in create_worker()
1952 kfree(worker); in create_worker()
1966 static void destroy_worker(struct worker *worker) in destroy_worker() argument
1968 struct worker_pool *pool = worker->pool; in destroy_worker()
1973 if (WARN_ON(worker->current_work) || in destroy_worker()
1974 WARN_ON(!list_empty(&worker->scheduled)) || in destroy_worker()
1975 WARN_ON(!(worker->flags & WORKER_IDLE))) in destroy_worker()
1981 list_del_init(&worker->entry); in destroy_worker()
1982 worker->flags |= WORKER_DIE; in destroy_worker()
1983 wake_up_process(worker->task); in destroy_worker()
1993 struct worker *worker; in idle_worker_timeout() local
1997 worker = list_entry(pool->idle_list.prev, struct worker, entry); in idle_worker_timeout()
1998 expires = worker->last_active + IDLE_WORKER_TIMEOUT; in idle_worker_timeout()
2005 destroy_worker(worker); in idle_worker_timeout()
2130 static bool manage_workers(struct worker *worker) in manage_workers() argument
2132 struct worker_pool *pool = worker->pool; in manage_workers()
2138 pool->manager = worker; in manage_workers()
2162 static void process_one_work(struct worker *worker, struct work_struct *work) in process_one_work() argument
2167 struct worker_pool *pool = worker->pool; in process_one_work()
2170 struct worker *collision; in process_one_work()
2201 hash_add(pool->busy_hash, &worker->hentry, (unsigned long)work); in process_one_work()
2202 worker->current_work = work; in process_one_work()
2203 worker->current_func = work->func; in process_one_work()
2204 worker->current_pwq = pwq; in process_one_work()
2211 strscpy(worker->desc, pwq->wq->name, WORKER_DESC_LEN); in process_one_work()
2222 worker_set_flags(worker, WORKER_CPU_INTENSIVE); in process_one_work()
2269 worker->current_func(work); in process_one_work()
2282 worker->current_func); in process_one_work()
2301 worker_clr_flags(worker, WORKER_CPU_INTENSIVE); in process_one_work()
2304 worker->last_func = worker->current_func; in process_one_work()
2307 hash_del(&worker->hentry); in process_one_work()
2308 worker->current_work = NULL; in process_one_work()
2309 worker->current_func = NULL; in process_one_work()
2310 worker->current_pwq = NULL; in process_one_work()
2326 static void process_scheduled_works(struct worker *worker) in process_scheduled_works() argument
2328 while (!list_empty(&worker->scheduled)) { in process_scheduled_works()
2329 struct work_struct *work = list_first_entry(&worker->scheduled, in process_scheduled_works()
2331 process_one_work(worker, work); in process_scheduled_works()
2359 struct worker *worker = __worker; in worker_thread() local
2360 struct worker_pool *pool = worker->pool; in worker_thread()
2368 if (unlikely(worker->flags & WORKER_DIE)) { in worker_thread()
2370 WARN_ON_ONCE(!list_empty(&worker->entry)); in worker_thread()
2373 set_task_comm(worker->task, "kworker/dying"); in worker_thread()
2374 ida_simple_remove(&pool->worker_ida, worker->id); in worker_thread()
2375 worker_detach_from_pool(worker); in worker_thread()
2376 kfree(worker); in worker_thread()
2380 worker_leave_idle(worker); in worker_thread()
2387 if (unlikely(!may_start_working(pool)) && manage_workers(worker)) in worker_thread()
2395 WARN_ON_ONCE(!list_empty(&worker->scheduled)); in worker_thread()
2404 worker_clr_flags(worker, WORKER_PREP | WORKER_REBOUND); in worker_thread()
2415 process_one_work(worker, work); in worker_thread()
2416 if (unlikely(!list_empty(&worker->scheduled))) in worker_thread()
2417 process_scheduled_works(worker); in worker_thread()
2419 move_linked_works(work, &worker->scheduled, NULL); in worker_thread()
2420 process_scheduled_works(worker); in worker_thread()
2424 worker_set_flags(worker, WORKER_PREP); in worker_thread()
2433 worker_enter_idle(worker); in worker_thread()
2463 struct worker *rescuer = __rescuer; in rescuer_thread()
2591 struct worker *worker; in check_flush_dependency() local
2596 worker = current_wq_worker(); in check_flush_dependency()
2601 WARN_ONCE(worker && ((worker->current_pwq->wq->flags & in check_flush_dependency()
2604 worker->current_pwq->wq->name, worker->current_func, in check_flush_dependency()
2646 struct work_struct *target, struct worker *worker) in insert_wq_barrier() argument
2668 if (worker) in insert_wq_barrier()
2669 head = worker->scheduled.next; in insert_wq_barrier()
2971 struct worker *worker = NULL; in start_flush_work() local
2991 worker = find_worker_executing_work(pool, work); in start_flush_work()
2992 if (!worker) in start_flush_work()
2994 pwq = worker->current_pwq; in start_flush_work()
2999 insert_wq_barrier(pwq, barr, work, worker); in start_flush_work()
3516 struct worker *worker; in put_unbound_pool() local
3543 while ((worker = first_idle_worker(pool))) in put_unbound_pool()
3544 destroy_worker(worker); in put_unbound_pool()
4194 struct worker *rescuer; in init_rescuer()
4439 struct worker *worker = current_wq_worker(); in current_work() local
4441 return worker ? worker->current_work : NULL; in current_work()
4455 struct worker *worker = current_wq_worker(); in current_is_workqueue_rescuer() local
4457 return worker && worker->rescue_wq; in current_is_workqueue_rescuer()
4548 struct worker *worker = current_wq_worker(); in set_worker_desc() local
4551 if (worker) { in set_worker_desc()
4553 vsnprintf(worker->desc, sizeof(worker->desc), fmt, args); in set_worker_desc()
4579 struct worker *worker; in print_worker_info() local
4588 worker = kthread_probe_data(task); in print_worker_info()
4594 probe_kernel_read(&fn, &worker->current_func, sizeof(fn)); in print_worker_info()
4595 probe_kernel_read(&pwq, &worker->current_pwq, sizeof(pwq)); in print_worker_info()
4598 probe_kernel_read(desc, worker->desc, sizeof(desc) - 1); in print_worker_info()
4634 struct worker *worker; in show_pwq() local
4644 hash_for_each(pool->busy_hash, bkt, worker, hentry) { in show_pwq()
4645 if (worker->current_pwq == pwq) { in show_pwq()
4654 hash_for_each(pool->busy_hash, bkt, worker, hentry) { in show_pwq()
4655 if (worker->current_pwq != pwq) in show_pwq()
4659 task_pid_nr(worker->task), in show_pwq()
4660 worker == pwq->wq->rescuer ? "(RESCUER)" : "", in show_pwq()
4661 worker->current_func); in show_pwq()
4662 list_for_each_entry(work, &worker->scheduled, entry) in show_pwq()
4748 struct worker *worker; in show_workqueue_state() local
4763 list_for_each_entry(worker, &pool->idle_list, entry) { in show_workqueue_state()
4765 task_pid_nr(worker->task)); in show_workqueue_state()
4796 struct worker *worker = kthread_data(task); in wq_worker_comm() local
4797 struct worker_pool *pool = worker->pool; in wq_worker_comm()
4806 if (worker->desc[0] != '\0') { in wq_worker_comm()
4807 if (worker->current_work) in wq_worker_comm()
4809 worker->desc); in wq_worker_comm()
4812 worker->desc); in wq_worker_comm()
4841 struct worker *worker; in unbind_workers() local
4854 for_each_pool_worker(worker, pool) in unbind_workers()
4855 worker->flags |= WORKER_UNBOUND; in unbind_workers()
4899 struct worker *worker; in rebind_workers() local
4910 for_each_pool_worker(worker, pool) in rebind_workers()
4911 WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task, in rebind_workers()
4918 for_each_pool_worker(worker, pool) { in rebind_workers()
4919 unsigned int worker_flags = worker->flags; in rebind_workers()
4930 wake_up_process(worker->task); in rebind_workers()
4950 WRITE_ONCE(worker->flags, worker_flags); in rebind_workers()
4969 struct worker *worker; in restore_unbound_workers_cpumask() local
4980 for_each_pool_worker(worker, pool) in restore_unbound_workers_cpumask()
4981 WARN_ON_ONCE(set_cpus_allowed_ptr(worker->task, &cpumask) < 0); in restore_unbound_workers_cpumask()