12 #include <linux/module.h>
14 #include <linux/sched.h>
16 #include <linux/slab.h>
28 #define RPCDBG_FACILITY RPCDBG_SCHED
31 #define CREATE_TRACE_POINTS
37 #define RPC_BUFFER_MAXSIZE (2048)
38 #define RPC_BUFFER_POOLSIZE (8)
39 #define RPC_TASK_POOLSIZE (8)
45 static void rpc_async_schedule(
struct work_struct *);
47 static void __rpc_queue_timer_fn(
unsigned long ptr);
69 dprintk(
"RPC: %5u disabling timer\n", task->tk_pid);
92 dprintk(
"RPC: %5u setting alarm for %lu ms\n",
97 rpc_set_queue_timer(queue, task->
u.
tk_wait.expires);
104 static void __rpc_add_wait_queue_priority(
struct rpc_wait_queue *queue,
106 unsigned char queue_priority)
111 INIT_LIST_HEAD(&task->
u.
tk_wait.links);
112 q = &queue->
tasks[queue_priority];
134 unsigned char queue_priority)
139 __rpc_add_wait_queue_priority(queue, task, queue_priority);
148 dprintk(
"RPC: %5u added to queue %p \"%s\"\n",
149 task->tk_pid, queue, rpc_qname(queue));
155 static void __rpc_remove_wait_queue_priority(
struct rpc_task *task)
159 if (!list_empty(&task->
u.
tk_wait.links)) {
172 __rpc_disable_timer(queue, task);
174 __rpc_remove_wait_queue_priority(task);
177 dprintk(
"RPC: %5u removed from queue %p \"%s\"\n",
178 task->tk_pid, queue, rpc_qname(queue));
184 queue->
count = 1 << (priority * 2);
193 static inline void rpc_reset_waitqueue_priority(
struct rpc_wait_queue *queue)
195 rpc_set_waitqueue_priority(queue, queue->
maxpriority);
196 rpc_set_waitqueue_owner(queue, 0);
199 static void __rpc_init_priority_wait_queue(
struct rpc_wait_queue *queue,
const char *qname,
unsigned char nr_queues)
205 INIT_LIST_HEAD(&queue->
tasks[i]);
207 rpc_reset_waitqueue_priority(queue);
211 rpc_assign_waitqueue_name(queue, qname);
222 __rpc_init_priority_wait_queue(queue, qname, 1);
232 static int rpc_wait_bit_killable(
void *
word)
234 if (fatal_signal_pending(
current))
241 static void rpc_task_set_debuginfo(
struct rpc_task *task)
248 static inline void rpc_task_set_debuginfo(
struct rpc_task *task)
253 static void rpc_set_active(
struct rpc_task *task)
257 rpc_task_set_debuginfo(task);
265 static int rpc_complete_task(
struct rpc_task *task)
278 if (waitqueue_active(wq))
280 spin_unlock_irqrestore(&wq->
lock, flags);
294 action = rpc_wait_bit_killable;
307 static void rpc_make_runnable(
struct rpc_task *task)
328 unsigned char queue_priority)
330 dprintk(
"RPC: %5u sleep_on(queue \"%s\" time %lu)\n",
331 task->tk_pid, rpc_qname(q), jiffies);
333 trace_rpc_task_sleep(task->
tk_client, task, q);
335 __rpc_add_wait_queue(q, task, queue_priority);
339 __rpc_add_timer(q, task);
351 spin_lock_bh(&q->
lock);
352 __rpc_sleep_on_priority(q, task, action, task->
tk_priority);
353 spin_unlock_bh(&q->
lock);
366 spin_lock_bh(&q->
lock);
368 spin_unlock_bh(&q->
lock);
380 dprintk(
"RPC: %5u __rpc_wake_up_task (now %lu)\n",
381 task->tk_pid, jiffies);
385 printk(
KERN_ERR "RPC: Inactive task (%p) being woken up!\n", task);
389 trace_rpc_task_wakeup(task->
tk_client, task, queue);
391 __rpc_remove_wait_queue(queue, task);
393 rpc_make_runnable(task);
395 dprintk(
"RPC: __rpc_wake_up_task done\n");
404 __rpc_do_wake_up_task(queue, task);
414 spin_lock_bh(&queue->
lock);
416 spin_unlock_bh(&queue->
lock);
426 spin_lock_bh(&queue->
lock);
427 rpc_wake_up_task_queue_locked(queue, task);
428 spin_unlock_bh(&queue->
lock);
444 if (!list_empty(q)) {
449 list_move_tail(&task->
u.
tk_wait.list, q);
462 if (q == &queue->
tasks[0])
466 if (!list_empty(q)) {
472 rpc_reset_waitqueue_priority(queue);
476 rpc_set_waitqueue_priority(queue, (
unsigned int)(q - &queue->
tasks[0]));
478 rpc_set_waitqueue_owner(queue, task->
tk_owner);
486 return __rpc_find_next_queued_priority(queue);
487 if (!list_empty(&queue->
tasks[0]))
500 dprintk(
"RPC: wake_up_first(%p \"%s\")\n",
501 queue, rpc_qname(queue));
502 spin_lock_bh(&queue->
lock);
503 task = __rpc_find_next_queued(queue);
505 if (
func(task, data))
506 rpc_wake_up_task_queue_locked(queue, task);
510 spin_unlock_bh(&queue->
lock);
516 static bool rpc_wake_up_next_func(
struct rpc_task *task,
void *
data)
540 spin_lock_bh(&queue->
lock);
543 while (!list_empty(head)) {
548 rpc_wake_up_task_queue_locked(queue, task);
550 if (head == &queue->
tasks[0])
554 spin_unlock_bh(&queue->
lock);
569 spin_lock_bh(&queue->
lock);
572 while (!list_empty(head)) {
578 rpc_wake_up_task_queue_locked(queue, task);
580 if (head == &queue->
tasks[0])
584 spin_unlock_bh(&queue->
lock);
588 static void __rpc_queue_timer_fn(
unsigned long ptr)
592 unsigned long expires, now, timeo;
594 spin_lock(&queue->
lock);
599 dprintk(
"RPC: %5u timeout\n", task->tk_pid);
601 rpc_wake_up_task_queue_locked(queue, task);
604 if (expires == now ||
time_after(expires, timeo))
608 rpc_set_queue_timer(queue, expires);
609 spin_unlock(&queue->
lock);
612 static void __rpc_atrun(
struct rpc_task *task)
636 rpc_init_task_statistics(
struct rpc_task *task)
648 rpc_reset_task_statistics(
struct rpc_task *task)
653 rpc_init_task_statistics(task);
668 rpc_reset_task_statistics(task);
691 static void __rpc_execute(
struct rpc_task *task)
697 dprintk(
"RPC: %5u __rpc_execute flags=0x%x\n",
710 if (do_action ==
NULL) {
718 if (do_action ==
NULL)
739 spin_lock_bh(&queue->
lock);
741 spin_unlock_bh(&queue->
lock);
745 spin_unlock_bh(&queue->
lock);
750 dprintk(
"RPC: %5u sync task going to sleep\n", task->tk_pid);
761 dprintk(
"RPC: %5u got signal\n", task->tk_pid);
766 dprintk(
"RPC: %5u sync task resuming\n", task->tk_pid);
769 dprintk(
"RPC: %5u return %d, status %d\n", task->tk_pid, status,
772 rpc_release_task(task);
786 rpc_set_active(task);
787 rpc_make_runnable(task);
833 dprintk(
"RPC: %5u allocated buffer of size %zu at %p\n",
834 task->tk_pid, size, buf);
855 dprintk(
"RPC: freeing buffer of size %zu at %p\n",
870 memset(task, 0,
sizeof(*task));
875 INIT_LIST_HEAD(&task->
tk_task);
886 rpc_init_task_statistics(task);
888 dprintk(
"RPC: new task initialized, procpid %u\n",
904 unsigned short flags = 0;
907 task = rpc_alloc_task();
916 rpc_init_task(task, setup_data);
918 dprintk(
"RPC: allocated task %p\n", task);
922 static void rpc_free_task(
struct rpc_task *task)
928 dprintk(
"RPC: %5u freeing task\n", task->tk_pid);
934 static void rpc_async_release(
struct work_struct *work)
939 static void rpc_release_resources_task(
struct rpc_task *task)
943 if (task->
tk_msg.rpc_cred) {
950 static void rpc_final_put_task(
struct rpc_task *task,
963 rpc_release_resources_task(task);
964 rpc_final_put_task(task, q);
970 rpc_do_put_task(task,
NULL);
980 static void rpc_release_task(
struct rpc_task *task)
982 dprintk(
"RPC: %5u release task\n", task->tk_pid);
986 rpc_release_resources_task(task);
995 if (!rpc_complete_task(task))
1017 static int rpciod_start(
void)
1024 dprintk(
"RPC: creating workqueue rpciod\n");
1026 rpciod_workqueue = wq;
1027 return rpciod_workqueue !=
NULL;
1030 static void rpciod_stop(
void)
1034 if (rpciod_workqueue ==
NULL)
1036 dprintk(
"RPC: destroying workqueue rpciod\n");
1039 rpciod_workqueue =
NULL;
1047 if (rpc_buffer_mempool)
1049 if (rpc_task_mempool)
1053 if (rpc_buffer_slabp)
1066 if (!rpciod_start())
1073 if (!rpc_task_slabp)
1079 if (!rpc_buffer_slabp)
1083 if (!rpc_task_mempool)
1087 if (!rpc_buffer_mempool)