Lines Matching full:work

979  * when they finish. There is defined a safe point for freezing when one work
988 struct kthread_work *work; in kthread_worker_fn() local
1011 work = NULL; in kthread_worker_fn()
1014 work = list_first_entry(&worker->work_list, in kthread_worker_fn()
1016 list_del_init(&work->node); in kthread_worker_fn()
1018 worker->current_work = work; in kthread_worker_fn()
1021 if (work) { in kthread_worker_fn()
1022 kthread_work_func_t func = work->func; in kthread_worker_fn()
1024 trace_sched_kthread_work_execute_start(work); in kthread_worker_fn()
1025 work->func(work); in kthread_worker_fn()
1027 * Avoid dereferencing work after this point. The trace in kthread_worker_fn()
1030 trace_sched_kthread_work_execute_end(work, func); in kthread_worker_fn()
1119 * how to handle pending work items, prevent queuing new ones, and
1151 * Returns true when the work could not be queued at the moment.
1156 struct kthread_work *work) in queuing_blocked() argument
1160 return !list_empty(&work->node) || work->canceling; in queuing_blocked()
1164 struct kthread_work *work) in kthread_insert_work_sanity_check() argument
1167 WARN_ON_ONCE(!list_empty(&work->node)); in kthread_insert_work_sanity_check()
1168 /* Do not use a work with >1 worker, see kthread_queue_work() */ in kthread_insert_work_sanity_check()
1169 WARN_ON_ONCE(work->worker && work->worker != worker); in kthread_insert_work_sanity_check()
1172 /* insert @work before @pos in @worker */
1174 struct kthread_work *work, in kthread_insert_work() argument
1177 kthread_insert_work_sanity_check(worker, work); in kthread_insert_work()
1179 trace_sched_kthread_work_queue_work(worker, work); in kthread_insert_work()
1181 list_add_tail(&work->node, pos); in kthread_insert_work()
1182 work->worker = worker; in kthread_insert_work()
1190 * @work: kthread_work to queue
1192 * Queue @work to work processor @task for async execution. @task
1194 * if @work was successfully queued, %false if it was already pending.
1196 * Reinitialize the work if it needs to be used by another worker.
1200 struct kthread_work *work) in kthread_queue_work() argument
1206 if (!queuing_blocked(worker, work)) { in kthread_queue_work()
1207 kthread_insert_work(worker, work, &worker->work_list); in kthread_queue_work()
1217 * delayed work when the timer expires.
1227 struct kthread_work *work = &dwork->work; in kthread_delayed_work_timer_fn() local
1228 struct kthread_worker *worker = work->worker; in kthread_delayed_work_timer_fn()
1232 * This might happen when a pending work is reinitialized. in kthread_delayed_work_timer_fn()
1239 /* Work must not be used with >1 worker, see kthread_queue_work(). */ in kthread_delayed_work_timer_fn()
1240 WARN_ON_ONCE(work->worker != worker); in kthread_delayed_work_timer_fn()
1242 /* Move the work from worker->delayed_work_list. */ in kthread_delayed_work_timer_fn()
1243 WARN_ON_ONCE(list_empty(&work->node)); in kthread_delayed_work_timer_fn()
1244 list_del_init(&work->node); in kthread_delayed_work_timer_fn()
1245 if (!work->canceling) in kthread_delayed_work_timer_fn()
1246 kthread_insert_work(worker, work, &worker->work_list); in kthread_delayed_work_timer_fn()
1257 struct kthread_work *work = &dwork->work; in __kthread_queue_delayed_work() local
1262 * If @delay is 0, queue @dwork->work immediately. This is for in __kthread_queue_delayed_work()
1268 kthread_insert_work(worker, work, &worker->work_list); in __kthread_queue_delayed_work()
1273 kthread_insert_work_sanity_check(worker, work); in __kthread_queue_delayed_work()
1275 list_add(&work->node, &worker->delayed_work_list); in __kthread_queue_delayed_work()
1276 work->worker = worker; in __kthread_queue_delayed_work()
1282 * kthread_queue_delayed_work - queue the associated kthread work
1288 * If the work has not been pending it starts a timer that will queue
1289 * the work after the given @delay. If @delay is zero, it queues the
1290 * work immediately.
1292 * Return: %false if the @work has already been pending. It means that
1293 * either the timer was running or the work was queued. It returns %true
1300 struct kthread_work *work = &dwork->work; in kthread_queue_delayed_work() local
1306 if (!queuing_blocked(worker, work)) { in kthread_queue_delayed_work()
1317 struct kthread_work work; member
1321 static void kthread_flush_work_fn(struct kthread_work *work) in kthread_flush_work_fn() argument
1324 container_of(work, struct kthread_flush_work, work); in kthread_flush_work_fn()
1330 * @work: work to flush
1332 * If @work is queued or executing, wait for it to finish execution.
1334 void kthread_flush_work(struct kthread_work *work) in kthread_flush_work() argument
1337 KTHREAD_WORK_INIT(fwork.work, kthread_flush_work_fn), in kthread_flush_work()
1343 worker = work->worker; in kthread_flush_work()
1348 /* Work must not be used with >1 worker, see kthread_queue_work(). */ in kthread_flush_work()
1349 WARN_ON_ONCE(work->worker != worker); in kthread_flush_work()
1351 if (!list_empty(&work->node)) in kthread_flush_work()
1352 kthread_insert_work(worker, &fwork.work, work->node.next); in kthread_flush_work()
1353 else if (worker->current_work == work) in kthread_flush_work()
1354 kthread_insert_work(worker, &fwork.work, in kthread_flush_work()
1368 * not manipulate the work list_head any longer.
1373 static void kthread_cancel_delayed_work_timer(struct kthread_work *work, in kthread_cancel_delayed_work_timer() argument
1377 container_of(work, struct kthread_delayed_work, work); in kthread_cancel_delayed_work_timer()
1378 struct kthread_worker *worker = work->worker; in kthread_cancel_delayed_work_timer()
1386 work->canceling++; in kthread_cancel_delayed_work_timer()
1390 work->canceling--; in kthread_cancel_delayed_work_timer()
1394 * This function removes the work from the worker queue.
1397 * the timer used by delayed work is not running, e.g. by calling
1400 * The work might still be in use when this function finishes. See the
1403 * Return: %true if @work was pending and successfully canceled,
1404 * %false if @work was not pending
1406 static bool __kthread_cancel_work(struct kthread_work *work) in __kthread_cancel_work() argument
1409 * Try to remove the work from a worker list. It might either in __kthread_cancel_work()
1412 if (!list_empty(&work->node)) { in __kthread_cancel_work()
1413 list_del_init(&work->node); in __kthread_cancel_work()
1421 * kthread_mod_delayed_work - modify delay of or queue a kthread delayed work
1423 * @dwork: kthread delayed work to queue
1428 * @work is guaranteed to be queued immediately.
1432 * A special case is when the work is being canceled in parallel.
1447 struct kthread_work *work = &dwork->work; in kthread_mod_delayed_work() local
1454 if (!work->worker) { in kthread_mod_delayed_work()
1459 /* Work must not be used with >1 worker, see kthread_queue_work() */ in kthread_mod_delayed_work()
1460 WARN_ON_ONCE(work->worker != worker); in kthread_mod_delayed_work()
1463 * Temporary cancel the work but do not fight with another command in kthread_mod_delayed_work()
1464 * that is canceling the work as well. in kthread_mod_delayed_work()
1470 * when doing so. But the work can be removed from the queue (list) in kthread_mod_delayed_work()
1474 kthread_cancel_delayed_work_timer(work, &flags); in kthread_mod_delayed_work()
1475 if (work->canceling) { in kthread_mod_delayed_work()
1480 ret = __kthread_cancel_work(work); in kthread_mod_delayed_work()
1490 static bool __kthread_cancel_work_sync(struct kthread_work *work, bool is_dwork) in __kthread_cancel_work_sync() argument
1492 struct kthread_worker *worker = work->worker; in __kthread_cancel_work_sync()
1500 /* Work must not be used with >1 worker, see kthread_queue_work(). */ in __kthread_cancel_work_sync()
1501 WARN_ON_ONCE(work->worker != worker); in __kthread_cancel_work_sync()
1504 kthread_cancel_delayed_work_timer(work, &flags); in __kthread_cancel_work_sync()
1506 ret = __kthread_cancel_work(work); in __kthread_cancel_work_sync()
1508 if (worker->current_work != work) in __kthread_cancel_work_sync()
1512 * The work is in progress and we need to wait with the lock released. in __kthread_cancel_work_sync()
1515 work->canceling++; in __kthread_cancel_work_sync()
1517 kthread_flush_work(work); in __kthread_cancel_work_sync()
1519 work->canceling--; in __kthread_cancel_work_sync()
1528 * kthread_cancel_work_sync - cancel a kthread work and wait for it to finish
1529 * @work: the kthread work to cancel
1531 * Cancel @work and wait for its execution to finish. This function
1532 * can be used even if the work re-queues itself. On return from this
1533 * function, @work is guaranteed to be not pending or executing on any CPU.
1535 * kthread_cancel_work_sync(&delayed_work->work) must not be used for
1538 * The caller must ensure that the worker on which @work was last
1541 * Return: %true if @work was pending, %false otherwise.
1543 bool kthread_cancel_work_sync(struct kthread_work *work) in kthread_cancel_work_sync() argument
1545 return __kthread_cancel_work_sync(work, false); in kthread_cancel_work_sync()
1550 * kthread_cancel_delayed_work_sync - cancel a kthread delayed work and
1552 * @dwork: the kthread delayed work to cancel
1560 return __kthread_cancel_work_sync(&dwork->work, true); in kthread_cancel_delayed_work_sync()
1574 KTHREAD_WORK_INIT(fwork.work, kthread_flush_work_fn), in kthread_flush_worker()
1578 kthread_queue_work(worker, &fwork.work); in kthread_flush_worker()
1591 * Note that this function is not responsible for handling delayed work, so
1592 * caller should be responsible for queuing or canceling all delayed work items