Lines Matching full:work
18 * This is the generic async execution mechanism. Work items as are
21 * normal work items and the other for high priority ones) and some extra
238 PWQ_STAT_STARTED, /* work items started execution */
239 PWQ_STAT_COMPLETED, /* work items completed execution */
245 PWQ_STAT_RESCUED, /* linked work items executed by rescuer */
269 * When pwq->nr_active >= max_active, new work item is queued to
273 * All work items marked with WORK_STRUCT_INACTIVE do not participate in
274 * nr_active and all work items in pwq->inactive_works are marked with
275 * WORK_STRUCT_INACTIVE. But not all WORK_STRUCT_INACTIVE work items are
277 * pool->worklist or worker->scheduled. Those work itmes are only struct
279 * in nr_active. For non-barrier work item, it is marked with
318 * to start executing a work item, it should increment ->nr using
320 * ->max, the pwq is queued on ->pending_pwqs. As in-flight work items finish
332 * The externally visible workqueue. It relays the issued work items to
340 int work_color; /* WQ: current work color */
412 * Per-cpu work items which run for longer than the following threshold are
414 * management to prevent them from noticeably delaying other per-cpu work items.
452 /* PL&A: allowable cpus for unbound wqs and work items */
464 /* CPU where unbound work was last round robin scheduled from this CPU */
468 * Local execution of unbound work items is no longer guaranteed. The
469 * following always forces round-robin CPU selection on unbound work items
613 struct work_struct *work = addr; in work_is_static_object() local
615 return test_bit(WORK_STRUCT_STATIC_BIT, work_data_bits(work)); in work_is_static_object()
624 struct work_struct *work = addr; in work_fixup_init() local
628 cancel_work_sync(work); in work_fixup_init()
629 debug_object_init(work, &work_debug_descr); in work_fixup_init()
642 struct work_struct *work = addr; in work_fixup_free() local
646 cancel_work_sync(work); in work_fixup_free()
647 debug_object_free(work, &work_debug_descr); in work_fixup_free()
662 static inline void debug_work_activate(struct work_struct *work) in debug_work_activate() argument
664 debug_object_activate(work, &work_debug_descr); in debug_work_activate()
667 static inline void debug_work_deactivate(struct work_struct *work) in debug_work_deactivate() argument
669 debug_object_deactivate(work, &work_debug_descr); in debug_work_deactivate()
672 void __init_work(struct work_struct *work, int onstack) in __init_work() argument
675 debug_object_init_on_stack(work, &work_debug_descr); in __init_work()
677 debug_object_init(work, &work_debug_descr); in __init_work()
681 void destroy_work_on_stack(struct work_struct *work) in destroy_work_on_stack() argument
683 debug_object_free(work, &work_debug_descr); in destroy_work_on_stack()
687 void destroy_delayed_work_on_stack(struct delayed_work *work) in destroy_delayed_work_on_stack() argument
689 timer_destroy_on_stack(&work->timer); in destroy_delayed_work_on_stack()
690 debug_object_free(&work->work, &work_debug_descr); in destroy_delayed_work_on_stack()
695 static inline void debug_work_activate(struct work_struct *work) { } in debug_work_activate() argument
696 static inline void debug_work_deactivate(struct work_struct *work) { } in debug_work_deactivate() argument
773 * While queued, %WORK_STRUCT_PWQ is set and non flag bits of a work's data
778 * can be used to set the pwq, pool or clear work->data. These functions should
779 * only be called while the work is owned - ie. while the PENDING bit is set.
782 * corresponding to a work. Pool is available once the work has been
784 * available only while the work item is queued.
786 static inline void set_work_data(struct work_struct *work, unsigned long data) in set_work_data() argument
788 WARN_ON_ONCE(!work_pending(work)); in set_work_data()
789 atomic_long_set(&work->data, data | work_static(work)); in set_work_data()
792 static void set_work_pwq(struct work_struct *work, struct pool_workqueue *pwq, in set_work_pwq() argument
795 set_work_data(work, (unsigned long)pwq | WORK_STRUCT_PENDING | in set_work_pwq()
799 static void set_work_pool_and_keep_pending(struct work_struct *work, in set_work_pool_and_keep_pending() argument
802 set_work_data(work, ((unsigned long)pool_id << WORK_OFFQ_POOL_SHIFT) | in set_work_pool_and_keep_pending()
806 static void set_work_pool_and_clear_pending(struct work_struct *work, in set_work_pool_and_clear_pending() argument
811 * test_and_set_bit(PENDING) and ensures all updates to @work made in set_work_pool_and_clear_pending()
816 set_work_data(work, ((unsigned long)pool_id << WORK_OFFQ_POOL_SHIFT) | in set_work_pool_and_clear_pending()
821 * work->current_func, which is executed afterwards. This possible in set_work_pool_and_clear_pending()
823 * the same @work. E.g. consider this case: in set_work_pool_and_clear_pending()
834 * 7 work->current_func() { in set_work_pool_and_clear_pending()
841 * a @work is not queued in a hope, that CPU#1 will eventually in set_work_pool_and_clear_pending()
842 * finish the queued @work. Meanwhile CPU#1 does not see in set_work_pool_and_clear_pending()
854 static struct pool_workqueue *get_work_pwq(struct work_struct *work) in get_work_pwq() argument
856 unsigned long data = atomic_long_read(&work->data); in get_work_pwq()
865 * get_work_pool - return the worker_pool a given work was associated with
866 * @work: the work item of interest
877 * Return: The worker_pool @work was last associated with. %NULL if none.
879 static struct worker_pool *get_work_pool(struct work_struct *work) in get_work_pool() argument
881 unsigned long data = atomic_long_read(&work->data); in get_work_pool()
1077 * find_worker_executing_work - find worker which is executing a work
1079 * @work: work to find worker for
1081 * Find a worker which is executing @work on @pool by searching
1082 * @pool->busy_hash which is keyed by the address of @work. For a worker
1083 * to match, its current execution should match the address of @work and
1084 * its work function. This is to avoid unwanted dependency between
1085 * unrelated work executions through a work item being recycled while still
1088 * This is a bit tricky. A work item may be freed once its execution
1090 * another work item. If the same work item address ends up being reused
1092 * recycled work item as currently executing and make it wait until the
1095 * This function checks the work item address and work function to avoid
1097 * work function which can introduce dependency onto itself through a
1098 * recycled work item. Well, if somebody wants to shoot oneself in the
1100 * actually occurs, it should be easy to locate the culprit work function.
1106 * Pointer to worker which is executing @work if found, %NULL
1110 struct work_struct *work) in find_worker_executing_work() argument
1115 (unsigned long)work) in find_worker_executing_work()
1116 if (worker->current_work == work && in find_worker_executing_work()
1117 worker->current_func == work->func) in find_worker_executing_work()
1125 * @work: start of series of works to be scheduled
1126 * @head: target list to append @work to
1129 * Schedule linked works starting from @work to @head. Work series to be
1130 * scheduled starts at @work and includes any consecutive work with
1137 static void move_linked_works(struct work_struct *work, struct list_head *head, in move_linked_works() argument
1146 list_for_each_entry_safe_from(work, n, NULL, entry) { in move_linked_works()
1147 list_move_tail(&work->entry, head); in move_linked_works()
1148 if (!(*work_data_bits(work) & WORK_STRUCT_LINKED)) in move_linked_works()
1162 * assign_work - assign a work item and its linked work items to a worker
1163 * @work: work to assign
1167 * Assign @work and its linked work items to @worker. If @work is already being
1170 * If @nextp is not NULL, it's updated to point to the next work of the last
1171 * scheduled work. This allows assign_work() to be nested inside
1174 * Returns %true if @work was successfully assigned to @worker. %false if @work
1177 static bool assign_work(struct work_struct *work, struct worker *worker, in assign_work() argument
1186 * A single work shouldn't be executed concurrently by multiple workers. in assign_work()
1187 * __queue_work() ensures that @work doesn't jump to a different pool in assign_work()
1189 * @work is not executed concurrently by multiple workers from the same in assign_work()
1190 * pool. Check whether anyone is already processing the work. If so, in assign_work()
1191 * defer the work to the currently executing one. in assign_work()
1193 collision = find_worker_executing_work(pool, work); in assign_work()
1195 move_linked_works(work, &collision->scheduled, nextp); in assign_work()
1199 move_linked_works(work, &worker->scheduled, nextp); in assign_work()
1230 * @pool may have pending work items. Wake up worker if necessary. Returns
1252 * Idle @worker is about to execute @work and waking up provides an in kick_pool()
1269 struct work_struct *work = list_first_entry(&pool->worklist, in kick_pool() local
1275 get_work_pwq(work)->stats[PWQ_STAT_REPATRIATED]++; in kick_pool()
1286 * Concurrency-managed per-cpu work items that hog CPU for longer than
1288 * which prevents them from stalling other concurrency-managed work items. If a
1289 * work function keeps triggering this mechanism, it's likely that the work item
1292 * wq_cpu_intensive_report() tracks work functions which trigger such conditions
1294 * workqueues as appropriate. To avoid flooding the console, each violating work
1404 * CPU intensive auto-detection cares about how long a work item hogged in wq_worker_running()
1482 * CPU_INTENSIVE to avoid stalling other concurrency-managed work items. in wq_worker_tick()
1509 * wq_worker_last_func - retrieve worker's last work function
1510 * @task: Task to retrieve last work function of.
1529 * The last work function %current executed as a worker, NULL if it
1530 * hasn't executed any work yet.
1674 struct work_struct *work) in __pwq_activate_work() argument
1676 unsigned long *wdb = work_data_bits(work); in __pwq_activate_work()
1679 trace_workqueue_activate_work(work); in __pwq_activate_work()
1682 move_linked_works(work, &pwq->pool->worklist, NULL); in __pwq_activate_work()
1778 * pwq_activate_first_inactive - Activate the first inactive work item on a pwq
1782 * Activate the first inactive work item of @pwq if available and allowed by
1785 * Returns %true if an inactive work item has been activated. %false if no
1786 * inactive work item is found or max_active limit is reached.
1790 struct work_struct *work = in pwq_activate_first_inactive() local
1794 if (work && pwq_tryinc_nr_active(pwq, fill)) { in pwq_activate_first_inactive()
1795 __pwq_activate_work(pwq, work); in pwq_activate_first_inactive()
1808 * ensure proper work item ordering::
1820 * to unplug the next oldest one to start its work item execution. Note that
1855 struct work_struct *work; in node_activate_pending_pwq() local
1884 * $pwq may not have any inactive work items due to e.g. cancellations. in node_activate_pending_pwq()
1887 work = list_first_entry_or_null(&pwq->inactive_works, in node_activate_pending_pwq()
1889 if (!work) { in node_activate_pending_pwq()
1895 * Acquire an nr_active count and activate the inactive work item. If in node_activate_pending_pwq()
1896 * $pwq still has inactive work items, rotate it to the end of the in node_activate_pending_pwq()
1898 * inactive work items are not activated in queueing order which is fine in node_activate_pending_pwq()
1903 __pwq_activate_work(pwq, work); in node_activate_pending_pwq()
1927 * Decrement @pwq's nr_active and try to activate the first inactive work item.
1945 * inactive work item on @pwq itself. in pwq_dec_nr_active()
1976 * @work_data: work_data of work which left the queue
1978 * A work either has completed or is removed from pending queue,
1984 * work item is complete.
2020 * try_to_grab_pending - steal work item from worklist and disable irq
2021 * @work: work item to steal
2025 * Try to grab PENDING bit of @work. This function can handle @work in any
2031 * 1 if @work was pending and we successfully stole PENDING
2032 * 0 if @work was idle and we claimed PENDING
2037 * On >= 0 return, the caller owns @work's PENDING bit. To avoid getting
2038 * interrupted while holding PENDING and @work off queue, irq must be
2047 static int try_to_grab_pending(struct work_struct *work, u32 cflags, in try_to_grab_pending() argument
2057 struct delayed_work *dwork = to_delayed_work(work); in try_to_grab_pending()
2069 if (!test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work))) in try_to_grab_pending()
2077 pool = get_work_pool(work); in try_to_grab_pending()
2083 * work->data is guaranteed to point to pwq only while the work in try_to_grab_pending()
2084 * item is queued on pwq->wq, and both updating work->data to point in try_to_grab_pending()
2086 * pwq->pool->lock. This in turn guarantees that, if work->data in try_to_grab_pending()
2087 * points to pwq which is associated with a locked pool, the work in try_to_grab_pending()
2090 pwq = get_work_pwq(work); in try_to_grab_pending()
2092 unsigned long work_data = *work_data_bits(work); in try_to_grab_pending()
2094 debug_work_deactivate(work); in try_to_grab_pending()
2097 * A cancelable inactive work item must be in the in try_to_grab_pending()
2101 * An inactive work item cannot be deleted directly because in try_to_grab_pending()
2102 * it might have linked barrier work items which, if left in try_to_grab_pending()
2105 * barrier work items to the worklist when deleting the grabbed in try_to_grab_pending()
2111 move_linked_works(work, &pwq->pool->worklist, NULL); in try_to_grab_pending()
2113 list_del_init(&work->entry); in try_to_grab_pending()
2116 * work->data points to pwq iff queued. Let's point to pool. As in try_to_grab_pending()
2117 * this destroys work->data needed by the next step, stash it. in try_to_grab_pending()
2119 set_work_pool_and_keep_pending(work, pool->id, in try_to_grab_pending()
2137 * work_grab_pending - steal work item from worklist and disable irq
2138 * @work: work item to steal
2142 * Grab PENDING bit of @work. @work can be in any stable state - idle, on timer
2149 * Returns %true if @work was pending. %false if idle.
2151 static bool work_grab_pending(struct work_struct *work, u32 cflags, in work_grab_pending() argument
2157 ret = try_to_grab_pending(work, cflags, irq_flags); in work_grab_pending()
2165 * insert_work - insert a work into a pool
2166 * @pwq: pwq @work belongs to
2167 * @work: work to insert
2171 * Insert @work which belongs to @pwq after @head. @extra_flags is or'd to
2177 static void insert_work(struct pool_workqueue *pwq, struct work_struct *work, in insert_work() argument
2180 debug_work_activate(work); in insert_work()
2182 /* record the work call stack in order to print it in KASAN reports */ in insert_work()
2183 kasan_record_aux_stack(work); in insert_work()
2185 /* we own @work, set data and link */ in insert_work()
2186 set_work_pwq(work, pwq, extra_flags); in insert_work()
2187 list_add_tail(&work->entry, head); in insert_work()
2192 * Test whether @work is being queued from another work executing on the
2201 * Return %true iff I'm a worker executing a work item on @wq. If in is_chained_work()
2208 * When queueing an unbound work item to a wq, prefer local CPU if allowed
2236 struct work_struct *work) in __queue_work() argument
2244 * While a work item is PENDING && off queue, a task trying to in __queue_work()
2254 * queues a new work item to a wq after destroy_workqueue(wq). in __queue_work()
2258 work->func, wq->name))) { in __queue_work()
2263 /* pwq which will be used unless @work is executing elsewhere */ in __queue_work()
2275 * If @work was previously on a different pool, it might still be in __queue_work()
2276 * running there, in which case the work needs to be queued on that in __queue_work()
2279 * For ordered workqueue, work items must be queued on the newest pwq in __queue_work()
2283 last_pool = get_work_pool(work); in __queue_work()
2289 worker = find_worker_executing_work(last_pool, work); in __queue_work()
2308 * another pwq replacing it in cpu_pwq or while work items are executing in __queue_work()
2323 trace_workqueue_queue_work(req_cpu, pwq, work); in __queue_work()
2325 if (WARN_ON(!list_empty(&work->entry))) in __queue_work()
2332 * Limit the number of concurrently active work items to max_active. in __queue_work()
2333 * @work must also queue behind existing inactive work items to maintain in __queue_work()
2340 trace_workqueue_activate_work(work); in __queue_work()
2341 insert_work(pwq, work, &pool->worklist, work_flags); in __queue_work()
2345 insert_work(pwq, work, &pwq->inactive_works, work_flags); in __queue_work()
2353 static bool clear_pending_if_disabled(struct work_struct *work) in clear_pending_if_disabled() argument
2355 unsigned long data = *work_data_bits(work); in clear_pending_if_disabled()
2363 set_work_pool_and_clear_pending(work, offqd.pool_id, in clear_pending_if_disabled()
2369 * queue_work_on - queue work on specific cpu
2370 * @cpu: CPU number to execute work on
2372 * @work: work to queue
2374 * We queue the work to a specific CPU, the caller must ensure it
2380 * Return: %false if @work was already on a queue, %true otherwise.
2383 struct work_struct *work) in queue_work_on() argument
2390 if (!test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work)) && in queue_work_on()
2391 !clear_pending_if_disabled(work)) { in queue_work_on()
2392 __queue_work(cpu, wq, work); in queue_work_on()
2408 * available CPU if we need to schedule this work.
2431 * queue_work_node - queue work on a "random" cpu for a given NUMA node
2432 * @node: NUMA node that we are targeting the work for
2434 * @work: work to queue
2436 * We queue the work to a "random" CPU within a given NUMA node. The basic
2437 * idea here is to provide a way to somehow associate work with a given
2448 * Return: %false if @work was already on a queue, %true otherwise.
2451 struct work_struct *work) in queue_work_node() argument
2469 if (!test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work)) && in queue_work_node()
2470 !clear_pending_if_disabled(work)) { in queue_work_node()
2473 __queue_work(cpu, wq, work); in queue_work_node()
2487 __queue_work(dwork->cpu, dwork->wq, &dwork->work); in delayed_work_timer_fn()
2495 struct work_struct *work = &dwork->work; in __queue_delayed_work() local
2500 WARN_ON_ONCE(!list_empty(&work->entry)); in __queue_delayed_work()
2503 * If @delay is 0, queue @dwork->work immediately. This is for in __queue_delayed_work()
2509 __queue_work(cpu, wq, &dwork->work); in __queue_delayed_work()
2533 * queue_delayed_work_on - queue work on specific CPU after delay
2534 * @cpu: CPU number to execute work on
2536 * @dwork: work to queue
2542 * this will prevent queueing of @dwork->work unless the offlined CPU
2545 * Return: %false if @work was already on a queue, %true otherwise. If
2552 struct work_struct *work = &dwork->work; in queue_delayed_work_on() local
2559 if (!test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work)) && in queue_delayed_work_on()
2560 !clear_pending_if_disabled(work)) { in queue_delayed_work_on()
2571 * mod_delayed_work_on - modify delay of or queue a delayed work on specific CPU
2572 * @cpu: CPU number to execute work on
2574 * @dwork: work to queue
2579 * zero, @work is guaranteed to be scheduled immediately regardless of its
2594 ret = work_grab_pending(&dwork->work, WORK_CANCEL_DELAYED, &irq_flags); in mod_delayed_work_on()
2596 if (!clear_pending_if_disabled(&dwork->work)) in mod_delayed_work_on()
2610 __queue_work(WORK_CPU_UNBOUND, rwork->wq, &rwork->work); in rcu_work_rcufn()
2615 * queue_rcu_work - queue work after a RCU grace period
2617 * @rwork: work to queue
2626 struct work_struct *work = &rwork->work; in queue_rcu_work() local
2630 * inside @rwork and disabled the inner work. in queue_rcu_work()
2632 if (!test_and_set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work)) && in queue_rcu_work()
2633 !WARN_ON_ONCE(clear_pending_if_disabled(work))) { in queue_rcu_work()
2940 * @work: the pool's work for handling these idle workers
2947 * context, hence the split between timer callback and work item.
2949 static void idle_cull_fn(struct work_struct *work) in idle_cull_fn() argument
2951 struct worker_pool *pool = container_of(work, struct worker_pool, idle_cull_work); in idle_cull_fn()
2985 static void send_mayday(struct work_struct *work) in send_mayday() argument
2987 struct pool_workqueue *pwq = get_work_pwq(work); in send_mayday()
3012 struct work_struct *work; in pool_mayday_timeout() local
3024 list_for_each_entry(work, &pool->worklist, entry) in pool_mayday_timeout()
3025 send_mayday(work); in pool_mayday_timeout()
3124 * process_one_work - process single work
3126 * @work: work to process
3128 * Process @work. This function contains all the logics necessary to
3129 * process a single work including synchronization against and
3132 * call this function to process a work.
3137 static void process_one_work(struct worker *worker, struct work_struct *work) in process_one_work() argument
3141 struct pool_workqueue *pwq = get_work_pwq(work); in process_one_work()
3152 * work->lockdep_map, make a copy and use that here. in process_one_work()
3156 lockdep_copy_map(&lockdep_map, &work->lockdep_map); in process_one_work()
3163 debug_work_deactivate(work); in process_one_work()
3164 hash_add(pool->busy_hash, &worker->hentry, (unsigned long)work); in process_one_work()
3165 worker->current_work = work; in process_one_work()
3166 worker->current_func = work->func; in process_one_work()
3170 work_data = *work_data_bits(work); in process_one_work()
3179 list_del_init(&work->entry); in process_one_work()
3185 * execution of the pending work items. in process_one_work()
3193 * chain execution of the pending work items for WORKER_NOT_RUNNING in process_one_work()
3200 * update to @work. Also, do this inside @pool->lock so that in process_one_work()
3204 set_work_pool_and_clear_pending(work, pool->id, pool_offq_flags(pool)); in process_one_work()
3228 * read-recursive acquire on the work(queue) 'locks', but this will then in process_one_work()
3237 trace_workqueue_execute_start(work); in process_one_work()
3238 worker->current_func(work); in process_one_work()
3240 * While we must be careful to not use "work" after this, the trace in process_one_work()
3243 trace_workqueue_execute_end(work, worker->current_func); in process_one_work()
3264 * kernels, where a requeueing work item waiting for something to in process_one_work()
3265 * happen could deadlock with stop_machine as such work item could in process_one_work()
3279 * CPU intensive by wq_worker_tick() if @work hogged CPU longer than in process_one_work()
3303 * may change while processing a work, so this function repeatedly
3304 * fetches a work from the top and executes it.
3312 struct work_struct *work; in process_scheduled_works() local
3315 while ((work = list_first_entry_or_null(&worker->scheduled, in process_scheduled_works()
3321 process_one_work(worker, work); in process_scheduled_works()
3341 * work items regardless of their specific target workqueue. The only
3342 * exception is work items which belong to workqueues with a rescuer which
3382 * preparing to process a work or actually processing it. in worker_thread()
3397 struct work_struct *work = in worker_thread() local
3401 if (assign_work(work, worker, NULL)) in worker_thread()
3408 * pool->lock is held and there's no work to process and no need to in worker_thread()
3428 * Regular work processing on a pool may block trying to create a new
3460 * shouldn't have any work pending, but @wq->maydays may still have in rescuer_thread()
3462 * all the work items before the rescuer got to them. Go through in rescuer_thread()
3475 struct work_struct *work, *n; in rescuer_thread() local
3491 list_for_each_entry_safe(work, n, &pool->worklist, entry) { in rescuer_thread()
3492 if (get_work_pwq(work) == pwq && in rescuer_thread()
3493 assign_work(work, rescuer, &n)) in rescuer_thread()
3501 * The above execution of rescued work items could in rescuer_thread()
3505 * that such back-to-back work items, which may be in rescuer_thread()
3576 struct work_struct *work = in bh_worker() local
3580 if (assign_work(work, worker, NULL)) in bh_worker()
3612 struct work_struct work; member
3617 static void drain_dead_softirq_workfn(struct work_struct *work) in drain_dead_softirq_workfn() argument
3620 container_of(work, struct wq_drain_dead_softirq_work, work); in drain_dead_softirq_workfn()
3625 * @pool's CPU is dead and we want to execute its still pending work in drain_dead_softirq_workfn()
3626 * items from this BH work item which is running on a different CPU. As in drain_dead_softirq_workfn()
3627 * its CPU is dead, @pool can't be kicked and, as work execution path in drain_dead_softirq_workfn()
3644 * still are pending work items, reschedule self and return so that we in drain_dead_softirq_workfn()
3649 queue_work(system_bh_highpri_wq, work); in drain_dead_softirq_workfn()
3651 queue_work(system_bh_wq, work); in drain_dead_softirq_workfn()
3658 * @cpu is dead. Drain the remaining BH work items on the current CPU. It's
3662 * on). Let's keep it simple and drain them synchronously. These are BH work
3676 INIT_WORK_ONSTACK(&dead_work.work, drain_dead_softirq_workfn); in workqueue_softirq_dead()
3681 queue_work(system_bh_highpri_wq, &dead_work.work); in workqueue_softirq_dead()
3683 queue_work(system_bh_wq, &dead_work.work); in workqueue_softirq_dead()
3686 destroy_work_on_stack(&dead_work.work); in workqueue_softirq_dead()
3693 * @target_work: work item being flushed (NULL for workqueue flushes)
3694 * @from_cancel: are we called from the work cancel path
3697 * If this is not the cancel path (which implies work being flushed is either
3727 struct work_struct work; member
3732 static void wq_barrier_func(struct work_struct *work) in wq_barrier_func() argument
3734 struct wq_barrier *barr = container_of(work, struct wq_barrier, work); in wq_barrier_func()
3739 * insert_wq_barrier - insert a barrier work
3742 * @target: target work to attach @barr to
3751 * try_to_grab_pending() can't determine whether the work to be
3753 * flag of the previous work while there must be a valid next work
3754 * after a work with LINKED flag set.
3781 INIT_WORK_ONSTACK_KEY(&barr->work, wq_barrier_func, in insert_wq_barrier()
3783 __set_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(&barr->work)); in insert_wq_barrier()
3789 /* The barrier work item does not participate in nr_active. */ in insert_wq_barrier()
3812 insert_work(pwq, &barr->work, head, work_flags); in insert_wq_barrier()
3819 * @work_color: new work color, < 0 for no-op
3917 static void touch_work_lockdep_map(struct work_struct *work, in touch_work_lockdep_map() argument
3924 lock_map_acquire(&work->lockdep_map); in touch_work_lockdep_map()
3925 lock_map_release(&work->lockdep_map); in touch_work_lockdep_map()
3933 * __flush_workqueue - ensure that any scheduled work has run to completion.
3936 * This function sleeps until all work items which were queued on entry
4095 * work items on @wq can queue further work items on it. @wq is flushed
4144 static bool start_flush_work(struct work_struct *work, struct wq_barrier *barr, in start_flush_work() argument
4153 pool = get_work_pool(work); in start_flush_work()
4161 pwq = get_work_pwq(work); in start_flush_work()
4166 worker = find_worker_executing_work(pool, work); in start_flush_work()
4173 check_flush_dependency(wq, work, from_cancel); in start_flush_work()
4175 insert_wq_barrier(pwq, barr, work, worker); in start_flush_work()
4178 touch_work_lockdep_map(work, wq); in start_flush_work()
4184 * For single threaded workqueues the deadlock happens when the work in start_flush_work()
4185 * is after the work issuing the flush_work(). For rescuer equipped in start_flush_work()
4200 static bool __flush_work(struct work_struct *work, bool from_cancel) in __flush_work() argument
4207 if (WARN_ON(!work->func)) in __flush_work()
4210 if (!start_flush_work(work, &barr, from_cancel)) in __flush_work()
4215 * that @work must have been executing during start_flush_work() and in __flush_work()
4216 * can't currently be queued. Its data must contain OFFQ bits. If @work in __flush_work()
4221 unsigned long data = *work_data_bits(work); in __flush_work()
4228 * running by keeping flipping BH. If the BH work item in __flush_work()
4249 destroy_work_on_stack(&barr.work); in __flush_work()
4254 * flush_work - wait for a work to finish executing the last queueing instance
4255 * @work: the work to flush
4257 * Wait until @work has finished execution. @work is guaranteed to be idle
4261 * %true if flush_work() waited for the work to finish execution,
4264 bool flush_work(struct work_struct *work) in flush_work() argument
4267 return __flush_work(work, false); in flush_work()
4273 * @dwork: the delayed work to flush
4275 * Delayed timer is cancelled and the pending work is queued for
4280 * %true if flush_work() waited for the work to finish execution,
4287 __queue_work(dwork->cpu, dwork->wq, &dwork->work); in flush_delayed_work()
4289 return flush_work(&dwork->work); in flush_delayed_work()
4295 * @rwork: the rcu work to flush
4298 * %true if flush_rcu_work() waited for the work to finish execution,
4303 if (test_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(&rwork->work))) { in flush_rcu_work()
4305 flush_work(&rwork->work); in flush_rcu_work()
4308 return flush_work(&rwork->work); in flush_rcu_work()
4320 WARN_ONCE(true, "workqueue: work disable count overflowed\n"); in work_offqd_disable()
4328 WARN_ONCE(true, "workqueue: work disable count underflowed\n"); in work_offqd_enable()
4331 static bool __cancel_work(struct work_struct *work, u32 cflags) in __cancel_work() argument
4337 ret = work_grab_pending(work, cflags, &irq_flags); in __cancel_work()
4339 work_offqd_unpack(&offqd, *work_data_bits(work)); in __cancel_work()
4344 set_work_pool_and_clear_pending(work, offqd.pool_id, in __cancel_work()
4350 static bool __cancel_work_sync(struct work_struct *work, u32 cflags) in __cancel_work_sync() argument
4354 ret = __cancel_work(work, cflags | WORK_CANCEL_DISABLE); in __cancel_work_sync()
4356 if (*work_data_bits(work) & WORK_OFFQ_BH) in __cancel_work_sync()
4362 * Skip __flush_work() during early boot when we know that @work isn't in __cancel_work_sync()
4366 __flush_work(work, true); in __cancel_work_sync()
4369 enable_work(work); in __cancel_work_sync()
4377 bool cancel_work(struct work_struct *work) in cancel_work() argument
4379 return __cancel_work(work, 0); in cancel_work()
4384 * cancel_work_sync - cancel a work and wait for it to finish
4385 * @work: the work to cancel
4387 * Cancel @work and wait for its execution to finish. This function can be used
4388 * even if the work re-queues itself or migrates to another workqueue. On return
4389 * from this function, @work is guaranteed to be not pending or executing on any
4392 * cancel_work_sync(&delayed_work->work) must not be used for delayed_work's.
4395 * Must be called from a sleepable context if @work was last queued on a non-BH
4397 * if @work was last queued on a BH workqueue.
4399 * Returns %true if @work was pending, %false otherwise.
4401 bool cancel_work_sync(struct work_struct *work) in cancel_work_sync() argument
4403 return __cancel_work_sync(work, 0); in cancel_work_sync()
4408 * cancel_delayed_work - cancel a delayed work
4417 * The work callback function may still be running on return, unless
4418 * it returns %true and the work doesn't re-arm itself. Explicitly flush or
4425 return __cancel_work(&dwork->work, WORK_CANCEL_DELAYED); in cancel_delayed_work()
4430 * cancel_delayed_work_sync - cancel a delayed work and wait for it to finish
4431 * @dwork: the delayed work cancel
4440 return __cancel_work_sync(&dwork->work, WORK_CANCEL_DELAYED); in cancel_delayed_work_sync()
4445 * disable_work - Disable and cancel a work item
4446 * @work: work item to disable
4448 * Disable @work by incrementing its disable count and cancel it if currently
4449 * pending. As long as the disable count is non-zero, any attempt to queue @work
4453 * Can be called from any context. Returns %true if @work was pending, %false
4456 bool disable_work(struct work_struct *work) in disable_work() argument
4458 return __cancel_work(work, WORK_CANCEL_DISABLE); in disable_work()
4463 * disable_work_sync - Disable, cancel and drain a work item
4464 * @work: work item to disable
4466 * Similar to disable_work() but also wait for @work to finish if currently
4469 * Must be called from a sleepable context if @work was last queued on a non-BH
4471 * if @work was last queued on a BH workqueue.
4473 * Returns %true if @work was pending, %false otherwise.
4475 bool disable_work_sync(struct work_struct *work) in disable_work_sync() argument
4477 return __cancel_work_sync(work, WORK_CANCEL_DISABLE); in disable_work_sync()
4482 * enable_work - Enable a work item
4483 * @work: work item to enable
4485 * Undo disable_work[_sync]() by decrementing @work's disable count. @work can
4491 bool enable_work(struct work_struct *work) in enable_work() argument
4496 work_grab_pending(work, 0, &irq_flags); in enable_work()
4498 work_offqd_unpack(&offqd, *work_data_bits(work)); in enable_work()
4500 set_work_pool_and_clear_pending(work, offqd.pool_id, in enable_work()
4509 * disable_delayed_work - Disable and cancel a delayed work item
4510 * @dwork: delayed work item to disable
4512 * disable_work() for delayed work items.
4516 return __cancel_work(&dwork->work, in disable_delayed_work()
4522 * disable_delayed_work_sync - Disable, cancel and drain a delayed work item
4523 * @dwork: delayed work item to disable
4525 * disable_work_sync() for delayed work items.
4529 return __cancel_work_sync(&dwork->work, in disable_delayed_work_sync()
4535 * enable_delayed_work - Enable a delayed work item
4536 * @dwork: delayed work item to enable
4538 * enable_work() for delayed work items.
4542 return enable_work(&dwork->work); in enable_delayed_work()
4569 struct work_struct *work = per_cpu_ptr(works, cpu); in schedule_on_each_cpu() local
4571 INIT_WORK(work, func); in schedule_on_each_cpu()
4572 schedule_work_on(cpu, work); in schedule_on_each_cpu()
4586 * @ew: guaranteed storage for the execute work structure (must
4587 * be available when the work executes)
4598 fn(&ew->work); in execute_in_process_context()
4602 INIT_WORK(&ew->work, fn); in execute_in_process_context()
4603 schedule_work(&ew->work); in execute_in_process_context()
4957 * which implies no work queued to the pool, which implies no worker can in put_unbound_pool()
5066 static void pwq_release_workfn(struct kthread_work *work) in pwq_release_workfn() argument
5068 struct pool_workqueue *pwq = container_of(work, struct pool_workqueue, in pwq_release_workfn()
5315 * of newly queued work items until execution of older work items in in apply_wqattrs_prepare()
5384 * work items are affine to the pod it was issued on. Older pwqs are released as
5385 * in-flight work items finish. Note that a work item which repeatedly requeues
5418 * executing the work items for the workqueue will lose their CPU affinity and
5421 * responsibility to flush the work item from CPU_DOWN_PREPARE.
5601 * activate inactive work items accordingly. If @wq is freezing, clear
5623 * Update @wq->max/min_active and then kick inactive work items if more in wq_adjust_max_active()
5624 * active work items are allowed. This doesn't break work item ordering in wq_adjust_max_active()
5625 * because new work items are always queued behind existing inactive in wq_adjust_max_active()
5626 * work items if there are any. in wq_adjust_max_active()
5638 * Round-robin through pwq's activating the first inactive work item in wq_adjust_max_active()
5841 * Safely destroy a workqueue. All work currently pending will be done first.
5843 * This function does NOT guarantee that non-pending work that has been
5976 * interdependent work items. Instead, an unbound workqueue is guaranteed to be
5977 * able to process min_active number of interdependent work items which is
5997 * current_work - retrieve %current task's work struct
6002 * Return: work struct if %current task is a workqueue worker, %NULL otherwise.
6016 * work functions to determine whether it's being run off the rescuer task.
6068 * work_busy - test whether a work is currently pending or running
6069 * @work: the work to be tested
6071 * Test whether @work is currently pending or running. There is no
6078 unsigned int work_busy(struct work_struct *work) in work_busy() argument
6084 if (work_pending(work)) in work_busy()
6088 pool = get_work_pool(work); in work_busy()
6091 if (find_worker_executing_work(pool, work)) in work_busy()
6102 * set_worker_desc - set description for the current work item
6106 * This function can be called by a running work function to describe what
6107 * the work item is about. If the worker task gets dumped, this
6129 * If @task is a worker and currently executing a work item, print out the
6131 * set_worker_desc() by the currently executing work item.
6225 static void pr_cont_work(bool comma, struct work_struct *work, struct pr_cont_work_struct *pcwsp) in pr_cont_work() argument
6227 if (work->func == wq_barrier_func) { in pr_cont_work()
6230 barr = container_of(work, struct wq_barrier, work); in pr_cont_work()
6238 pr_cont_work_flush(comma, work->func, pcwsp); in pr_cont_work()
6246 struct work_struct *work; in show_pwq() local
6275 list_for_each_entry(work, &worker->scheduled, entry) in show_pwq()
6276 pr_cont_work(false, work, &pcws); in show_pwq()
6283 list_for_each_entry(work, &pool->worklist, entry) { in show_pwq()
6284 if (get_work_pwq(work) == pwq) { in show_pwq()
6293 list_for_each_entry(work, &pool->worklist, entry) { in show_pwq()
6294 if (get_work_pwq(work) != pwq) in show_pwq()
6297 pr_cont_work(comma, work, &pcws); in show_pwq()
6298 comma = !(*work_data_bits(work) & WORK_STRUCT_LINKED); in show_pwq()
6308 list_for_each_entry(work, &pwq->inactive_works, entry) { in show_pwq()
6309 pr_cont_work(comma, work, &pcws); in show_pwq()
6310 comma = !(*work_data_bits(work) & WORK_STRUCT_LINKED); in show_pwq()
6343 * drivers that queue work while holding locks in show_one_workqueue()
6376 /* How long the first pending work is waiting for a worker. */ in show_one_worker_pool()
6382 * queue work while holding locks also taken in their write in show_one_worker_pool()
6500 * are a lot of assumptions on strong associations among work, pwq and
6546 * unbound chain execution of currently pending work items. in unbind_workers()
6736 struct work_struct work; member
6742 static void work_for_cpu_fn(struct work_struct *work) in work_for_cpu_fn() argument
6744 struct work_for_cpu *wfc = container_of(work, struct work_for_cpu, work); in work_for_cpu_fn()
6766 INIT_WORK_ONSTACK_KEY(&wfc.work, work_for_cpu_fn, key); in work_on_cpu_key()
6767 schedule_work_on(cpu, &wfc.work); in work_on_cpu_key()
6768 flush_work(&wfc.work); in work_on_cpu_key()
6769 destroy_work_on_stack(&wfc.work); in work_on_cpu_key()
7038 * max_active RW int : maximum number of in-flight work items
7470 * flush dependency, a concurrency managed work item which stays RUNNING
7495 * Show workers that might prevent the processing of pending work items.
7497 * Pending work items should be handled by another idle worker
7512 * drivers that queue work while holding locks in show_cpu_pool_hog()
7743 * boot code to create workqueues and queue/cancel work items. Actual work item
7898 * been created and work items queued on them, but there are no kworkers
7899 * executing the work items yet. Populate the worker pools with the initial