Lines Matching +full:wake +full:- +full:up

1 // SPDX-License-Identifier: GPL-2.0-only
54 * rpciod-related stuff
62 if (current->flags & PF_WQ_WORKER) in rpc_task_gfp_mask()
70 if (cmpxchg(&task->tk_rpc_status, 0, rpc_status) == 0) in rpc_task_set_rpc_status()
78 unsigned long timeout = READ_ONCE(task->tk_timeout); in rpc_task_timeout()
83 return timeout - now; in rpc_task_timeout()
91 * queue->lock and bh_disabled in order to avoid races within
97 if (list_empty(&task->u.tk_wait.timer_list)) in __rpc_disable_timer()
99 task->tk_timeout = 0; in __rpc_disable_timer()
100 list_del(&task->u.tk_wait.timer_list); in __rpc_disable_timer()
101 if (list_empty(&queue->timer_list.list)) in __rpc_disable_timer()
102 cancel_delayed_work(&queue->timer_list.dwork); in __rpc_disable_timer()
109 queue->timer_list.expires = expires; in rpc_set_queue_timer()
113 expires -= now; in rpc_set_queue_timer()
114 mod_delayed_work(rpciod_workqueue, &queue->timer_list.dwork, expires); in rpc_set_queue_timer()
118 * Set up a timer for the current task.
124 task->tk_timeout = timeout; in __rpc_add_timer()
125 if (list_empty(&queue->timer_list.list) || time_before(timeout, queue->timer_list.expires)) in __rpc_add_timer()
127 list_add(&task->u.tk_wait.timer_list, &queue->timer_list.list); in __rpc_add_timer()
132 if (queue->priority != priority) { in rpc_set_waitqueue_priority()
133 queue->priority = priority; in rpc_set_waitqueue_priority()
134 queue->nr = 1U << priority; in rpc_set_waitqueue_priority()
140 rpc_set_waitqueue_priority(queue, queue->maxpriority); in rpc_reset_waitqueue_priority()
152 if (t->tk_owner == task->tk_owner) { in __rpc_list_enqueue_task()
153 list_add_tail(&task->u.tk_wait.links, in __rpc_list_enqueue_task()
154 &t->u.tk_wait.links); in __rpc_list_enqueue_task()
155 /* Cache the queue head in task->u.tk_wait.list */ in __rpc_list_enqueue_task()
156 task->u.tk_wait.list.next = q; in __rpc_list_enqueue_task()
157 task->u.tk_wait.list.prev = NULL; in __rpc_list_enqueue_task()
161 INIT_LIST_HEAD(&task->u.tk_wait.links); in __rpc_list_enqueue_task()
162 list_add_tail(&task->u.tk_wait.list, q); in __rpc_list_enqueue_task()
174 if (task->u.tk_wait.list.prev == NULL) { in __rpc_list_dequeue_task()
175 list_del(&task->u.tk_wait.links); in __rpc_list_dequeue_task()
178 if (!list_empty(&task->u.tk_wait.links)) { in __rpc_list_dequeue_task()
179 t = list_first_entry(&task->u.tk_wait.links, in __rpc_list_dequeue_task()
183 q = t->u.tk_wait.list.next; in __rpc_list_dequeue_task()
184 list_add_tail(&t->u.tk_wait.list, q); in __rpc_list_dequeue_task()
185 list_del(&task->u.tk_wait.links); in __rpc_list_dequeue_task()
187 list_del(&task->u.tk_wait.list); in __rpc_list_dequeue_task()
197 if (unlikely(queue_priority > queue->maxpriority)) in __rpc_add_wait_queue_priority()
198 queue_priority = queue->maxpriority; in __rpc_add_wait_queue_priority()
199 __rpc_list_enqueue_task(&queue->tasks[queue_priority], task); in __rpc_add_wait_queue_priority()
209 INIT_LIST_HEAD(&task->u.tk_wait.timer_list); in __rpc_add_wait_queue()
213 list_add_tail(&task->u.tk_wait.list, &queue->tasks[0]); in __rpc_add_wait_queue()
214 task->tk_waitqueue = queue; in __rpc_add_wait_queue()
215 queue->qlen++; in __rpc_add_wait_queue()
239 list_del(&task->u.tk_wait.list); in __rpc_remove_wait_queue()
240 queue->qlen--; in __rpc_remove_wait_queue()
247 spin_lock_init(&queue->lock); in __rpc_init_priority_wait_queue()
248 for (i = 0; i < ARRAY_SIZE(queue->tasks); i++) in __rpc_init_priority_wait_queue()
249 INIT_LIST_HEAD(&queue->tasks[i]); in __rpc_init_priority_wait_queue()
250 queue->maxpriority = nr_queues - 1; in __rpc_init_priority_wait_queue()
252 queue->qlen = 0; in __rpc_init_priority_wait_queue()
253 queue->timer_list.expires = 0; in __rpc_init_priority_wait_queue()
254 INIT_DELAYED_WORK(&queue->timer_list.dwork, __rpc_queue_timer_fn); in __rpc_init_priority_wait_queue()
255 INIT_LIST_HEAD(&queue->timer_list.list); in __rpc_init_priority_wait_queue()
273 cancel_delayed_work_sync(&queue->timer_list.dwork); in rpc_destroy_wait_queue()
281 return -ERESTARTSYS; in rpc_wait_bit_killable()
288 struct rpc_clnt *clnt = task->tk_client; in rpc_task_set_debuginfo()
290 /* Might be a task carrying a reverse-direction operation */ in rpc_task_set_debuginfo()
294 task->tk_pid = atomic_inc_return(&rpc_pid); in rpc_task_set_debuginfo()
298 task->tk_pid = atomic_inc_return(&clnt->cl_pid); in rpc_task_set_debuginfo()
309 set_bit(RPC_TASK_ACTIVE, &task->tk_runstate); in rpc_set_active()
315 * and then waking up all tasks that were sleeping.
319 void *m = &task->tk_runstate; in rpc_complete_task()
327 spin_lock_irqsave(&wq->lock, flags); in rpc_complete_task()
328 clear_bit(RPC_TASK_ACTIVE, &task->tk_runstate); in rpc_complete_task()
329 ret = atomic_dec_and_test(&task->tk_count); in rpc_complete_task()
332 spin_unlock_irqrestore(&wq->lock, flags); in rpc_complete_task()
340 * to enforce taking of the wq->lock and hence avoid races with
345 return out_of_line_wait_on_bit(&task->tk_runstate, RPC_TASK_ACTIVE, in rpc_wait_for_completion_task()
370 INIT_WORK(&task->u.tk_work, rpc_async_schedule); in rpc_make_runnable()
371 queue_work(wq, &task->u.tk_work); in rpc_make_runnable()
374 wake_up_bit(&task->tk_runstate, RPC_TASK_QUEUED); in rpc_make_runnable()
381 * NB: An RPC task will only receive interrupt-driven events as long
412 task->tk_status = -ETIMEDOUT; in __rpc_sleep_on_priority_timeout()
417 if (action && !WARN_ON_ONCE(task->tk_callback != NULL)) in rpc_set_tk_callback()
418 task->tk_callback = action; in rpc_set_tk_callback()
425 task->tk_status = -EIO; in rpc_sleep_check_activated()
443 spin_lock(&q->lock); in rpc_sleep_on_timeout()
444 __rpc_sleep_on_priority_timeout(q, task, timeout, task->tk_priority); in rpc_sleep_on_timeout()
445 spin_unlock(&q->lock); in rpc_sleep_on_timeout()
457 WARN_ON_ONCE(task->tk_timeout != 0); in rpc_sleep_on()
461 spin_lock(&q->lock); in rpc_sleep_on()
462 __rpc_sleep_on_priority(q, task, task->tk_priority); in rpc_sleep_on()
463 spin_unlock(&q->lock); in rpc_sleep_on()
473 priority -= RPC_PRIORITY_LOW; in rpc_sleep_on_priority_timeout()
477 spin_lock(&q->lock); in rpc_sleep_on_priority_timeout()
479 spin_unlock(&q->lock); in rpc_sleep_on_priority_timeout()
489 WARN_ON_ONCE(task->tk_timeout != 0); in rpc_sleep_on_priority()
490 priority -= RPC_PRIORITY_LOW; in rpc_sleep_on_priority()
494 spin_lock(&q->lock); in rpc_sleep_on_priority()
496 spin_unlock(&q->lock); in rpc_sleep_on_priority()
501 * __rpc_do_wake_up_task_on_wq - wake up a single rpc_task
504 * @task: task to be woken up
506 * Caller must hold queue->lock, and have cleared the task queued flag.
512 /* Has the task been executed yet? If not, we cannot wake it up! */ in __rpc_do_wake_up_task_on_wq()
514 printk(KERN_ERR "RPC: Inactive task (%p) being woken up!\n", task); in __rpc_do_wake_up_task_on_wq()
526 * Wake up a queued task while the queue lock is being held
535 if (task->tk_waitqueue == queue) { in rpc_wake_up_task_on_wq_queue_action_locked()
546 * Wake up a queued task while the queue lock is being held
556 * Wake up a task on a specific queue
562 spin_lock(&queue->lock); in rpc_wake_up_queued_task()
564 spin_unlock(&queue->lock); in rpc_wake_up_queued_task()
570 task->tk_status = *(int *)status; in rpc_task_action_set_status()
583 * rpc_wake_up_queued_task_set_status - wake up a task and set task->tk_status
588 * If @task is queued on @queue, then it is woken up, and @task->tk_status is
597 spin_lock(&queue->lock); in rpc_wake_up_queued_task_set_status()
599 spin_unlock(&queue->lock); in rpc_wake_up_queued_task_set_status()
603 * Wake up the next task on a priority queue.
613 q = &queue->tasks[RPC_NR_PRIORITY - 1]; in __rpc_find_next_queued_priority()
614 if (queue->maxpriority > RPC_PRIORITY_PRIVILEGED && !list_empty(q)) { in __rpc_find_next_queued_priority()
622 q = &queue->tasks[queue->priority]; in __rpc_find_next_queued_priority()
623 if (!list_empty(q) && queue->nr) { in __rpc_find_next_queued_priority()
624 queue->nr--; in __rpc_find_next_queued_priority()
633 if (q == &queue->tasks[0]) in __rpc_find_next_queued_priority()
634 q = &queue->tasks[queue->maxpriority]; in __rpc_find_next_queued_priority()
636 q = q - 1; in __rpc_find_next_queued_priority()
641 } while (q != &queue->tasks[queue->priority]); in __rpc_find_next_queued_priority()
647 rpc_set_waitqueue_priority(queue, (unsigned int)(q - &queue->tasks[0])); in __rpc_find_next_queued_priority()
656 if (!list_empty(&queue->tasks[0])) in __rpc_find_next_queued()
657 return list_first_entry(&queue->tasks[0], struct rpc_task, u.tk_wait.list); in __rpc_find_next_queued()
662 * Wake up the first task on the wait queue.
670 spin_lock(&queue->lock); in rpc_wake_up_first_on_wq()
675 spin_unlock(&queue->lock); in rpc_wake_up_first_on_wq()
681 * Wake up the first task on the wait queue.
696 * Wake up the next task on the wait queue.
705 * rpc_wake_up_locked - wake up all rpc_tasks
722 * rpc_wake_up - wake up all rpc_tasks
725 * Grabs queue->lock
729 spin_lock(&queue->lock); in rpc_wake_up()
731 spin_unlock(&queue->lock); in rpc_wake_up()
736 * rpc_wake_up_status_locked - wake up all rpc_tasks and set their status value.
753 * rpc_wake_up_status - wake up all rpc_tasks and set their status value.
757 * Grabs queue->lock
761 spin_lock(&queue->lock); in rpc_wake_up_status()
763 spin_unlock(&queue->lock); in rpc_wake_up_status()
775 spin_lock(&queue->lock); in __rpc_queue_timer_fn()
777 list_for_each_entry_safe(task, n, &queue->timer_list.list, u.tk_wait.timer_list) { in __rpc_queue_timer_fn()
778 timeo = task->tk_timeout; in __rpc_queue_timer_fn()
780 trace_rpc_task_timeout(task, task->tk_action); in __rpc_queue_timer_fn()
781 task->tk_status = -ETIMEDOUT; in __rpc_queue_timer_fn()
788 if (!list_empty(&queue->timer_list.list)) in __rpc_queue_timer_fn()
790 spin_unlock(&queue->lock); in __rpc_queue_timer_fn()
795 if (task->tk_status == -ETIMEDOUT) in __rpc_atrun()
796 task->tk_status = 0; in __rpc_atrun()
809 * Helper to call task->tk_ops->rpc_call_prepare
813 task->tk_ops->rpc_call_prepare(task, task->tk_calldata); in rpc_prepare_task()
820 task->tk_garb_retry = 2; in rpc_init_task_statistics()
821 task->tk_cred_retry = 2; in rpc_init_task_statistics()
824 task->tk_start = ktime_get(); in rpc_init_task_statistics()
830 task->tk_timeouts = 0; in rpc_reset_task_statistics()
831 task->tk_flags &= ~(RPC_CALL_MAJORSEEN|RPC_TASK_SENT); in rpc_reset_task_statistics()
836 * Helper that calls task->tk_ops->rpc_call_done if it exists
840 trace_rpc_task_end(task, task->tk_action); in rpc_exit_task()
841 task->tk_action = NULL; in rpc_exit_task()
842 if (task->tk_ops->rpc_count_stats) in rpc_exit_task()
843 task->tk_ops->rpc_count_stats(task, task->tk_calldata); in rpc_exit_task()
844 else if (task->tk_client) in rpc_exit_task()
845 rpc_count_iostats(task, task->tk_client->cl_metrics); in rpc_exit_task()
846 if (task->tk_ops->rpc_call_done != NULL) { in rpc_exit_task()
847 trace_rpc_task_call_done(task, task->tk_ops->rpc_call_done); in rpc_exit_task()
848 task->tk_ops->rpc_call_done(task, task->tk_calldata); in rpc_exit_task()
849 if (task->tk_action != NULL) { in rpc_exit_task()
864 if (!rpc_task_set_rpc_status(task, -ERESTARTSYS)) in rpc_signal_task()
866 trace_rpc_task_signalled(task, task->tk_action); in rpc_signal_task()
867 set_bit(RPC_TASK_SIGNALLED, &task->tk_runstate); in rpc_signal_task()
869 queue = READ_ONCE(task->tk_waitqueue); in rpc_signal_task()
880 queue = READ_ONCE(task->tk_waitqueue); in rpc_task_try_cancel()
887 task->tk_status = status; in rpc_exit()
888 task->tk_action = rpc_exit_task; in rpc_exit()
889 rpc_wake_up_queued_task(task->tk_waitqueue, task); in rpc_exit()
895 if (ops->rpc_release != NULL) in rpc_release_calldata()
896 ops->rpc_release(calldata); in rpc_release_calldata()
903 if (!atomic_read(&xprt->swapper)) in xprt_needs_memalloc()
905 return test_bit(XPRT_LOCKED, &xprt->state) && xprt->snd_task == tk; in xprt_needs_memalloc()
916 unsigned long pflags = current->flags; in __rpc_execute()
930 do_action = task->tk_action; in __rpc_execute()
933 (status = READ_ONCE(task->tk_rpc_status)) != 0) { in __rpc_execute()
934 task->tk_status = status; in __rpc_execute()
938 if (task->tk_callback) { in __rpc_execute()
939 do_action = task->tk_callback; in __rpc_execute()
940 task->tk_callback = NULL; in __rpc_execute()
945 xprt_needs_memalloc(task->tk_xprt, task)) in __rpc_execute()
946 current->flags |= PF_MEMALLOC; in __rpc_execute()
960 * The queue->lock protects against races with in __rpc_execute()
968 queue = task->tk_waitqueue; in __rpc_execute()
969 spin_lock(&queue->lock); in __rpc_execute()
971 spin_unlock(&queue->lock); in __rpc_execute()
974 /* Wake up any task that has an exit status */ in __rpc_execute()
975 if (READ_ONCE(task->tk_rpc_status) != 0) { in __rpc_execute()
977 spin_unlock(&queue->lock); in __rpc_execute()
981 spin_unlock(&queue->lock); in __rpc_execute()
986 trace_rpc_task_sync_sleep(task, task->tk_action); in __rpc_execute()
987 status = out_of_line_wait_on_bit(&task->tk_runstate, in __rpc_execute()
993 * -ERESTARTSYS. In order to catch any callbacks that in __rpc_execute()
994 * clean up after sleeping on some queue, we don't in __rpc_execute()
999 trace_rpc_task_sync_wake(task, task->tk_action); in __rpc_execute()
1009 * User-visible entry point to the scheduler.
1039 * rpc_malloc - allocate RPC buffer resources
1047 * returning -ENOMEM and suppressing warning if the request cannot
1057 struct rpc_rqst *rqst = task->tk_rqstp; in rpc_malloc()
1058 size_t size = rqst->rq_callsize + rqst->rq_rcvsize; in rpc_malloc()
1072 return -ENOMEM; in rpc_malloc()
1074 buf->len = size; in rpc_malloc()
1075 rqst->rq_buffer = buf->data; in rpc_malloc()
1076 rqst->rq_rbuffer = (char *)rqst->rq_buffer + rqst->rq_callsize; in rpc_malloc()
1082 * rpc_free - free RPC buffer resources allocated via rpc_malloc
1088 void *buffer = task->tk_rqstp->rq_buffer; in rpc_free()
1093 size = buf->len; in rpc_free()
1108 atomic_set(&task->tk_count, 1); in rpc_init_task()
1109 task->tk_flags = task_setup_data->flags; in rpc_init_task()
1110 task->tk_ops = task_setup_data->callback_ops; in rpc_init_task()
1111 task->tk_calldata = task_setup_data->callback_data; in rpc_init_task()
1112 INIT_LIST_HEAD(&task->tk_task); in rpc_init_task()
1114 task->tk_priority = task_setup_data->priority - RPC_PRIORITY_LOW; in rpc_init_task()
1115 task->tk_owner = current->tgid; in rpc_init_task()
1118 task->tk_workqueue = task_setup_data->workqueue; in rpc_init_task()
1120 task->tk_xprt = rpc_task_get_xprt(task_setup_data->rpc_client, in rpc_init_task()
1121 xprt_get(task_setup_data->rpc_xprt)); in rpc_init_task()
1123 task->tk_op_cred = get_rpccred(task_setup_data->rpc_op_cred); in rpc_init_task()
1125 if (task->tk_ops->rpc_call_prepare != NULL) in rpc_init_task()
1126 task->tk_action = rpc_prepare_task; in rpc_init_task()
1146 struct rpc_task *task = setup_data->task; in rpc_new_task()
1152 rpc_release_calldata(setup_data->callback_ops, in rpc_new_task()
1153 setup_data->callback_data); in rpc_new_task()
1154 return ERR_PTR(-ENOMEM); in rpc_new_task()
1160 task->tk_flags |= flags; in rpc_new_task()
1165 * rpc_free_task - release rpc task and perform cleanups
1167 * Note that we free up the rpc_task _after_ rpc_release_calldata()
1172 * on the same address and won't execute them concurrently - ie. it
1185 unsigned short tk_flags = task->tk_flags; in rpc_free_task()
1187 put_rpccred(task->tk_op_cred); in rpc_free_task()
1188 rpc_release_calldata(task->tk_ops, task->tk_calldata); in rpc_free_task()
1205 if (task->tk_msg.rpc_cred) { in rpc_release_resources_task()
1206 if (!(task->tk_flags & RPC_TASK_CRED_NOREF)) in rpc_release_resources_task()
1207 put_cred(task->tk_msg.rpc_cred); in rpc_release_resources_task()
1208 task->tk_msg.rpc_cred = NULL; in rpc_release_resources_task()
1217 INIT_WORK(&task->u.tk_work, rpc_async_release); in rpc_final_put_task()
1218 queue_work(q, &task->u.tk_work); in rpc_final_put_task()
1225 if (atomic_dec_and_test(&task->tk_count)) { in rpc_do_put_task()
1239 rpc_do_put_task(task, task->tk_workqueue); in rpc_put_task_async()
1250 * Note: at this point we have been removed from rpc_clnt->cl_tasks, in rpc_release_task()
1251 * so it should be safe to use task->tk_count as a test for whether in rpc_release_task()
1254 if (atomic_read(&task->tk_count) != 1 + !RPC_IS_ASYNC(task)) { in rpc_release_task()
1255 /* Wake up anyone who may be waiting for task completion */ in rpc_release_task()
1259 if (!atomic_dec_and_test(&task->tk_count)) in rpc_release_task()
1262 rpc_final_put_task(task, task->tk_workqueue); in rpc_release_task()
1267 return try_module_get(THIS_MODULE) ? 0 : -EINVAL; in rpciod_up()
1276 * Start up the rpciod workqueue.
1362 return -ENOMEM; in rpc_init_mempool()