Lines Matching full:work
297 * functions which do some additional work in non-modular code such as
777 * when they finish. There is defined a safe point for freezing when one work
786 struct kthread_work *work; in kthread_worker_fn() local
809 work = NULL; in kthread_worker_fn()
812 work = list_first_entry(&worker->work_list, in kthread_worker_fn()
814 list_del_init(&work->node); in kthread_worker_fn()
816 worker->current_work = work; in kthread_worker_fn()
819 if (work) { in kthread_worker_fn()
820 kthread_work_func_t func = work->func; in kthread_worker_fn()
822 trace_sched_kthread_work_execute_start(work); in kthread_worker_fn()
823 work->func(work); in kthread_worker_fn()
825 * Avoid dereferencing work after this point. The trace in kthread_worker_fn()
828 trace_sched_kthread_work_execute_end(work, func); in kthread_worker_fn()
914 * how to handle pending work items, prevent queuing new ones, and
947 * Returns true when the work could not be queued at the moment.
952 struct kthread_work *work) in queuing_blocked() argument
956 return !list_empty(&work->node) || work->canceling; in queuing_blocked()
960 struct kthread_work *work) in kthread_insert_work_sanity_check() argument
963 WARN_ON_ONCE(!list_empty(&work->node)); in kthread_insert_work_sanity_check()
964 /* Do not use a work with >1 worker, see kthread_queue_work() */ in kthread_insert_work_sanity_check()
965 WARN_ON_ONCE(work->worker && work->worker != worker); in kthread_insert_work_sanity_check()
968 /* insert @work before @pos in @worker */
970 struct kthread_work *work, in kthread_insert_work() argument
973 kthread_insert_work_sanity_check(worker, work); in kthread_insert_work()
975 trace_sched_kthread_work_queue_work(worker, work); in kthread_insert_work()
977 list_add_tail(&work->node, pos); in kthread_insert_work()
978 work->worker = worker; in kthread_insert_work()
986 * @work: kthread_work to queue
988 * Queue @work to work processor @task for async execution. @task
990 * if @work was successfully queued, %false if it was already pending.
992 * Reinitialize the work if it needs to be used by another worker.
996 struct kthread_work *work) in kthread_queue_work() argument
1002 if (!queuing_blocked(worker, work)) { in kthread_queue_work()
1003 kthread_insert_work(worker, work, &worker->work_list); in kthread_queue_work()
1013 * delayed work when the timer expires.
1022 struct kthread_work *work = &dwork->work; in kthread_delayed_work_timer_fn() local
1023 struct kthread_worker *worker = work->worker; in kthread_delayed_work_timer_fn()
1027 * This might happen when a pending work is reinitialized. in kthread_delayed_work_timer_fn()
1034 /* Work must not be used with >1 worker, see kthread_queue_work(). */ in kthread_delayed_work_timer_fn()
1035 WARN_ON_ONCE(work->worker != worker); in kthread_delayed_work_timer_fn()
1037 /* Move the work from worker->delayed_work_list. */ in kthread_delayed_work_timer_fn()
1038 WARN_ON_ONCE(list_empty(&work->node)); in kthread_delayed_work_timer_fn()
1039 list_del_init(&work->node); in kthread_delayed_work_timer_fn()
1040 if (!work->canceling) in kthread_delayed_work_timer_fn()
1041 kthread_insert_work(worker, work, &worker->work_list); in kthread_delayed_work_timer_fn()
1052 struct kthread_work *work = &dwork->work; in __kthread_queue_delayed_work() local
1057 * If @delay is 0, queue @dwork->work immediately. This is for in __kthread_queue_delayed_work()
1063 kthread_insert_work(worker, work, &worker->work_list); in __kthread_queue_delayed_work()
1068 kthread_insert_work_sanity_check(worker, work); in __kthread_queue_delayed_work()
1070 list_add(&work->node, &worker->delayed_work_list); in __kthread_queue_delayed_work()
1071 work->worker = worker; in __kthread_queue_delayed_work()
1077 * kthread_queue_delayed_work - queue the associated kthread work
1083 * If the work has not been pending it starts a timer that will queue
1084 * the work after the given @delay. If @delay is zero, it queues the
1085 * work immediately.
1087 * Return: %false if the @work has already been pending. It means that
1088 * either the timer was running or the work was queued. It returns %true
1095 struct kthread_work *work = &dwork->work; in kthread_queue_delayed_work() local
1101 if (!queuing_blocked(worker, work)) { in kthread_queue_delayed_work()
1112 struct kthread_work work; member
1116 static void kthread_flush_work_fn(struct kthread_work *work) in kthread_flush_work_fn() argument
1119 container_of(work, struct kthread_flush_work, work); in kthread_flush_work_fn()
1125 * @work: work to flush
1127 * If @work is queued or executing, wait for it to finish execution.
1129 void kthread_flush_work(struct kthread_work *work) in kthread_flush_work() argument
1132 KTHREAD_WORK_INIT(fwork.work, kthread_flush_work_fn), in kthread_flush_work()
1138 worker = work->worker; in kthread_flush_work()
1143 /* Work must not be used with >1 worker, see kthread_queue_work(). */ in kthread_flush_work()
1144 WARN_ON_ONCE(work->worker != worker); in kthread_flush_work()
1146 if (!list_empty(&work->node)) in kthread_flush_work()
1147 kthread_insert_work(worker, &fwork.work, work->node.next); in kthread_flush_work()
1148 else if (worker->current_work == work) in kthread_flush_work()
1149 kthread_insert_work(worker, &fwork.work, in kthread_flush_work()
1163 * not manipulate the work list_head any longer.
1168 static void kthread_cancel_delayed_work_timer(struct kthread_work *work, in kthread_cancel_delayed_work_timer() argument
1172 container_of(work, struct kthread_delayed_work, work); in kthread_cancel_delayed_work_timer()
1173 struct kthread_worker *worker = work->worker; in kthread_cancel_delayed_work_timer()
1181 work->canceling++; in kthread_cancel_delayed_work_timer()
1185 work->canceling--; in kthread_cancel_delayed_work_timer()
1189 * This function removes the work from the worker queue.
1192 * the timer used by delayed work is not running, e.g. by calling
1195 * The work might still be in use when this function finishes. See the
1198 * Return: %true if @work was pending and successfully canceled,
1199 * %false if @work was not pending
1201 static bool __kthread_cancel_work(struct kthread_work *work) in __kthread_cancel_work() argument
1204 * Try to remove the work from a worker list. It might either in __kthread_cancel_work()
1207 if (!list_empty(&work->node)) { in __kthread_cancel_work()
1208 list_del_init(&work->node); in __kthread_cancel_work()
1216 * kthread_mod_delayed_work - modify delay of or queue a kthread delayed work
1218 * @dwork: kthread delayed work to queue
1223 * @work is guaranteed to be queued immediately.
1227 * A special case is when the work is being canceled in parallel.
1242 struct kthread_work *work = &dwork->work; in kthread_mod_delayed_work() local
1249 if (!work->worker) { in kthread_mod_delayed_work()
1254 /* Work must not be used with >1 worker, see kthread_queue_work() */ in kthread_mod_delayed_work()
1255 WARN_ON_ONCE(work->worker != worker); in kthread_mod_delayed_work()
1258 * Temporary cancel the work but do not fight with another command in kthread_mod_delayed_work()
1259 * that is canceling the work as well. in kthread_mod_delayed_work()
1265 * when doing so. But the work can be removed from the queue (list) in kthread_mod_delayed_work()
1269 kthread_cancel_delayed_work_timer(work, &flags); in kthread_mod_delayed_work()
1270 if (work->canceling) { in kthread_mod_delayed_work()
1275 ret = __kthread_cancel_work(work); in kthread_mod_delayed_work()
1285 static bool __kthread_cancel_work_sync(struct kthread_work *work, bool is_dwork) in __kthread_cancel_work_sync() argument
1287 struct kthread_worker *worker = work->worker; in __kthread_cancel_work_sync()
1295 /* Work must not be used with >1 worker, see kthread_queue_work(). */ in __kthread_cancel_work_sync()
1296 WARN_ON_ONCE(work->worker != worker); in __kthread_cancel_work_sync()
1299 kthread_cancel_delayed_work_timer(work, &flags); in __kthread_cancel_work_sync()
1301 ret = __kthread_cancel_work(work); in __kthread_cancel_work_sync()
1303 if (worker->current_work != work) in __kthread_cancel_work_sync()
1307 * The work is in progress and we need to wait with the lock released. in __kthread_cancel_work_sync()
1310 work->canceling++; in __kthread_cancel_work_sync()
1312 kthread_flush_work(work); in __kthread_cancel_work_sync()
1314 work->canceling--; in __kthread_cancel_work_sync()
1323 * kthread_cancel_work_sync - cancel a kthread work and wait for it to finish
1324 * @work: the kthread work to cancel
1326 * Cancel @work and wait for its execution to finish. This function
1327 * can be used even if the work re-queues itself. On return from this
1328 * function, @work is guaranteed to be not pending or executing on any CPU.
1330 * kthread_cancel_work_sync(&delayed_work->work) must not be used for
1333 * The caller must ensure that the worker on which @work was last
1336 * Return: %true if @work was pending, %false otherwise.
1338 bool kthread_cancel_work_sync(struct kthread_work *work) in kthread_cancel_work_sync() argument
1340 return __kthread_cancel_work_sync(work, false); in kthread_cancel_work_sync()
1345 * kthread_cancel_delayed_work_sync - cancel a kthread delayed work and
1347 * @dwork: the kthread delayed work to cancel
1355 return __kthread_cancel_work_sync(&dwork->work, true); in kthread_cancel_delayed_work_sync()
1369 KTHREAD_WORK_INIT(fwork.work, kthread_flush_work_fn), in kthread_flush_worker()
1373 kthread_queue_work(worker, &fwork.work); in kthread_flush_worker()