Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/include/linux/sunrpc/sched.h |
| 3 | * |
| 4 | * Scheduling primitives for kernel Sun RPC. |
| 5 | * |
| 6 | * Copyright (C) 1996, Olaf Kirch <okir@monad.swb.de> |
| 7 | */ |
| 8 | |
| 9 | #ifndef _LINUX_SUNRPC_SCHED_H_ |
| 10 | #define _LINUX_SUNRPC_SCHED_H_ |
| 11 | |
| 12 | #include <linux/timer.h> |
| 13 | #include <linux/sunrpc/types.h> |
| 14 | #include <linux/spinlock.h> |
| 15 | #include <linux/wait.h> |
| 16 | #include <linux/workqueue.h> |
| 17 | #include <linux/sunrpc/xdr.h> |
| 18 | |
| 19 | /* |
| 20 | * This is the actual RPC procedure call info. |
| 21 | */ |
| 22 | struct rpc_procinfo; |
| 23 | struct rpc_message { |
| 24 | struct rpc_procinfo * rpc_proc; /* Procedure information */ |
| 25 | void * rpc_argp; /* Arguments */ |
| 26 | void * rpc_resp; /* Result */ |
| 27 | struct rpc_cred * rpc_cred; /* Credentials */ |
| 28 | }; |
| 29 | |
| 30 | struct rpc_wait_queue; |
| 31 | struct rpc_wait { |
| 32 | struct list_head list; /* wait queue links */ |
| 33 | struct list_head links; /* Links to related tasks */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | struct rpc_wait_queue * rpc_waitq; /* RPC wait queue we're on */ |
| 35 | }; |
| 36 | |
| 37 | /* |
| 38 | * This is the RPC task struct |
| 39 | */ |
| 40 | struct rpc_task { |
| 41 | #ifdef RPC_DEBUG |
| 42 | unsigned long tk_magic; /* 0xf00baa */ |
| 43 | #endif |
| 44 | struct list_head tk_task; /* global list of tasks */ |
| 45 | struct rpc_clnt * tk_client; /* RPC client */ |
| 46 | struct rpc_rqst * tk_rqstp; /* RPC request */ |
| 47 | int tk_status; /* result of last operation */ |
| 48 | |
| 49 | /* |
| 50 | * RPC call state |
| 51 | */ |
| 52 | struct rpc_message tk_msg; /* RPC call info */ |
| 53 | __u32 * tk_buffer; /* XDR buffer */ |
| 54 | size_t tk_bufsize; |
| 55 | __u8 tk_garb_retry; |
| 56 | __u8 tk_cred_retry; |
| 57 | |
| 58 | unsigned long tk_cookie; /* Cookie for batching tasks */ |
| 59 | |
| 60 | /* |
| 61 | * timeout_fn to be executed by timer bottom half |
| 62 | * callback to be executed after waking up |
| 63 | * action next procedure for async tasks |
| 64 | * exit exit async task and report to caller |
| 65 | */ |
| 66 | void (*tk_timeout_fn)(struct rpc_task *); |
| 67 | void (*tk_callback)(struct rpc_task *); |
| 68 | void (*tk_action)(struct rpc_task *); |
| 69 | void (*tk_exit)(struct rpc_task *); |
| 70 | void (*tk_release)(struct rpc_task *); |
| 71 | void * tk_calldata; |
| 72 | |
| 73 | /* |
| 74 | * tk_timer is used for async processing by the RPC scheduling |
| 75 | * primitives. You should not access this directly unless |
| 76 | * you have a pathological interest in kernel oopses. |
| 77 | */ |
| 78 | struct timer_list tk_timer; /* kernel timer */ |
| 79 | unsigned long tk_timeout; /* timeout for rpc_sleep() */ |
| 80 | unsigned short tk_flags; /* misc flags */ |
| 81 | unsigned char tk_active : 1;/* Task has been activated */ |
| 82 | unsigned char tk_priority : 2;/* Task priority */ |
| 83 | unsigned long tk_runstate; /* Task run status */ |
| 84 | struct workqueue_struct *tk_workqueue; /* Normally rpciod, but could |
| 85 | * be any workqueue |
| 86 | */ |
| 87 | union { |
| 88 | struct work_struct tk_work; /* Async task work queue */ |
| 89 | struct rpc_wait tk_wait; /* RPC wait */ |
| 90 | } u; |
| 91 | #ifdef RPC_DEBUG |
| 92 | unsigned short tk_pid; /* debugging aid */ |
| 93 | #endif |
| 94 | }; |
| 95 | #define tk_auth tk_client->cl_auth |
| 96 | #define tk_xprt tk_client->cl_xprt |
| 97 | |
| 98 | /* support walking a list of tasks on a wait queue */ |
| 99 | #define task_for_each(task, pos, head) \ |
| 100 | list_for_each(pos, head) \ |
| 101 | if ((task=list_entry(pos, struct rpc_task, u.tk_wait.list)),1) |
| 102 | |
| 103 | #define task_for_first(task, head) \ |
| 104 | if (!list_empty(head) && \ |
| 105 | ((task=list_entry((head)->next, struct rpc_task, u.tk_wait.list)),1)) |
| 106 | |
| 107 | /* .. and walking list of all tasks */ |
| 108 | #define alltask_for_each(task, pos, head) \ |
| 109 | list_for_each(pos, head) \ |
| 110 | if ((task=list_entry(pos, struct rpc_task, tk_task)),1) |
| 111 | |
| 112 | typedef void (*rpc_action)(struct rpc_task *); |
| 113 | |
| 114 | /* |
| 115 | * RPC task flags |
| 116 | */ |
| 117 | #define RPC_TASK_ASYNC 0x0001 /* is an async task */ |
| 118 | #define RPC_TASK_SWAPPER 0x0002 /* is swapping in/out */ |
| 119 | #define RPC_TASK_CHILD 0x0008 /* is child of other task */ |
| 120 | #define RPC_CALL_MAJORSEEN 0x0020 /* major timeout seen */ |
| 121 | #define RPC_TASK_ROOTCREDS 0x0040 /* force root creds */ |
| 122 | #define RPC_TASK_DYNAMIC 0x0080 /* task was kmalloc'ed */ |
| 123 | #define RPC_TASK_KILLED 0x0100 /* task was killed */ |
| 124 | #define RPC_TASK_SOFT 0x0200 /* Use soft timeouts */ |
| 125 | #define RPC_TASK_NOINTR 0x0400 /* uninterruptible task */ |
| 126 | |
| 127 | #define RPC_IS_ASYNC(t) ((t)->tk_flags & RPC_TASK_ASYNC) |
| 128 | #define RPC_IS_CHILD(t) ((t)->tk_flags & RPC_TASK_CHILD) |
| 129 | #define RPC_IS_SWAPPER(t) ((t)->tk_flags & RPC_TASK_SWAPPER) |
| 130 | #define RPC_DO_ROOTOVERRIDE(t) ((t)->tk_flags & RPC_TASK_ROOTCREDS) |
| 131 | #define RPC_ASSASSINATED(t) ((t)->tk_flags & RPC_TASK_KILLED) |
| 132 | #define RPC_IS_ACTIVATED(t) ((t)->tk_active) |
| 133 | #define RPC_DO_CALLBACK(t) ((t)->tk_callback != NULL) |
| 134 | #define RPC_IS_SOFT(t) ((t)->tk_flags & RPC_TASK_SOFT) |
| 135 | #define RPC_TASK_UNINTERRUPTIBLE(t) ((t)->tk_flags & RPC_TASK_NOINTR) |
| 136 | |
| 137 | #define RPC_TASK_RUNNING 0 |
| 138 | #define RPC_TASK_QUEUED 1 |
| 139 | #define RPC_TASK_WAKEUP 2 |
| 140 | #define RPC_TASK_HAS_TIMER 3 |
| 141 | |
| 142 | #define RPC_IS_RUNNING(t) (test_bit(RPC_TASK_RUNNING, &(t)->tk_runstate)) |
| 143 | #define rpc_set_running(t) (set_bit(RPC_TASK_RUNNING, &(t)->tk_runstate)) |
| 144 | #define rpc_test_and_set_running(t) \ |
| 145 | (test_and_set_bit(RPC_TASK_RUNNING, &(t)->tk_runstate)) |
| 146 | #define rpc_clear_running(t) \ |
| 147 | do { \ |
| 148 | smp_mb__before_clear_bit(); \ |
| 149 | clear_bit(RPC_TASK_RUNNING, &(t)->tk_runstate); \ |
| 150 | smp_mb__after_clear_bit(); \ |
| 151 | } while (0) |
| 152 | |
| 153 | #define RPC_IS_QUEUED(t) (test_bit(RPC_TASK_QUEUED, &(t)->tk_runstate)) |
| 154 | #define rpc_set_queued(t) (set_bit(RPC_TASK_QUEUED, &(t)->tk_runstate)) |
| 155 | #define rpc_clear_queued(t) \ |
| 156 | do { \ |
| 157 | smp_mb__before_clear_bit(); \ |
| 158 | clear_bit(RPC_TASK_QUEUED, &(t)->tk_runstate); \ |
| 159 | smp_mb__after_clear_bit(); \ |
| 160 | } while (0) |
| 161 | |
| 162 | #define rpc_start_wakeup(t) \ |
| 163 | (test_and_set_bit(RPC_TASK_WAKEUP, &(t)->tk_runstate) == 0) |
| 164 | #define rpc_finish_wakeup(t) \ |
| 165 | do { \ |
| 166 | smp_mb__before_clear_bit(); \ |
| 167 | clear_bit(RPC_TASK_WAKEUP, &(t)->tk_runstate); \ |
| 168 | smp_mb__after_clear_bit(); \ |
| 169 | } while (0) |
| 170 | |
| 171 | /* |
| 172 | * Task priorities. |
| 173 | * Note: if you change these, you must also change |
| 174 | * the task initialization definitions below. |
| 175 | */ |
| 176 | #define RPC_PRIORITY_LOW 0 |
| 177 | #define RPC_PRIORITY_NORMAL 1 |
| 178 | #define RPC_PRIORITY_HIGH 2 |
| 179 | #define RPC_NR_PRIORITY (RPC_PRIORITY_HIGH+1) |
| 180 | |
| 181 | /* |
| 182 | * RPC synchronization objects |
| 183 | */ |
| 184 | struct rpc_wait_queue { |
| 185 | spinlock_t lock; |
| 186 | struct list_head tasks[RPC_NR_PRIORITY]; /* task queue for each priority level */ |
| 187 | unsigned long cookie; /* cookie of last task serviced */ |
| 188 | unsigned char maxpriority; /* maximum priority (0 if queue is not a priority queue) */ |
| 189 | unsigned char priority; /* current priority */ |
| 190 | unsigned char count; /* # task groups remaining serviced so far */ |
| 191 | unsigned char nr; /* # tasks remaining for cookie */ |
| 192 | #ifdef RPC_DEBUG |
| 193 | const char * name; |
| 194 | #endif |
| 195 | }; |
| 196 | |
| 197 | /* |
| 198 | * This is the # requests to send consecutively |
| 199 | * from a single cookie. The aim is to improve |
| 200 | * performance of NFS operations such as read/write. |
| 201 | */ |
| 202 | #define RPC_BATCH_COUNT 16 |
| 203 | |
| 204 | #ifndef RPC_DEBUG |
| 205 | # define RPC_WAITQ_INIT(var,qname) { \ |
| 206 | .lock = SPIN_LOCK_UNLOCKED, \ |
| 207 | .tasks = { \ |
| 208 | [0] = LIST_HEAD_INIT(var.tasks[0]), \ |
| 209 | [1] = LIST_HEAD_INIT(var.tasks[1]), \ |
| 210 | [2] = LIST_HEAD_INIT(var.tasks[2]), \ |
| 211 | }, \ |
| 212 | } |
| 213 | #else |
| 214 | # define RPC_WAITQ_INIT(var,qname) { \ |
| 215 | .lock = SPIN_LOCK_UNLOCKED, \ |
| 216 | .tasks = { \ |
| 217 | [0] = LIST_HEAD_INIT(var.tasks[0]), \ |
| 218 | [1] = LIST_HEAD_INIT(var.tasks[1]), \ |
| 219 | [2] = LIST_HEAD_INIT(var.tasks[2]), \ |
| 220 | }, \ |
| 221 | .name = qname, \ |
| 222 | } |
| 223 | #endif |
| 224 | # define RPC_WAITQ(var,qname) struct rpc_wait_queue var = RPC_WAITQ_INIT(var,qname) |
| 225 | |
| 226 | #define RPC_IS_PRIORITY(q) ((q)->maxpriority > 0) |
| 227 | |
| 228 | /* |
| 229 | * Function prototypes |
| 230 | */ |
| 231 | struct rpc_task *rpc_new_task(struct rpc_clnt *, rpc_action, int flags); |
| 232 | struct rpc_task *rpc_new_child(struct rpc_clnt *, struct rpc_task *parent); |
| 233 | void rpc_init_task(struct rpc_task *, struct rpc_clnt *, |
| 234 | rpc_action exitfunc, int flags); |
| 235 | void rpc_release_task(struct rpc_task *); |
| 236 | void rpc_killall_tasks(struct rpc_clnt *); |
| 237 | int rpc_execute(struct rpc_task *); |
| 238 | void rpc_run_child(struct rpc_task *parent, struct rpc_task *child, |
| 239 | rpc_action action); |
| 240 | void rpc_init_priority_wait_queue(struct rpc_wait_queue *, const char *); |
| 241 | void rpc_init_wait_queue(struct rpc_wait_queue *, const char *); |
| 242 | void rpc_sleep_on(struct rpc_wait_queue *, struct rpc_task *, |
| 243 | rpc_action action, rpc_action timer); |
| 244 | void rpc_wake_up_task(struct rpc_task *); |
| 245 | void rpc_wake_up(struct rpc_wait_queue *); |
| 246 | struct rpc_task *rpc_wake_up_next(struct rpc_wait_queue *); |
| 247 | void rpc_wake_up_status(struct rpc_wait_queue *, int); |
| 248 | void rpc_delay(struct rpc_task *, unsigned long); |
| 249 | void * rpc_malloc(struct rpc_task *, size_t); |
| 250 | int rpciod_up(void); |
| 251 | void rpciod_down(void); |
| 252 | void rpciod_wake_up(void); |
| 253 | #ifdef RPC_DEBUG |
| 254 | void rpc_show_tasks(void); |
| 255 | #endif |
| 256 | int rpc_init_mempool(void); |
| 257 | void rpc_destroy_mempool(void); |
| 258 | |
| 259 | static inline void rpc_exit(struct rpc_task *task, int status) |
| 260 | { |
| 261 | task->tk_status = status; |
| 262 | task->tk_action = NULL; |
| 263 | } |
| 264 | |
| 265 | #ifdef RPC_DEBUG |
| 266 | static inline const char * rpc_qname(struct rpc_wait_queue *q) |
| 267 | { |
| 268 | return ((q && q->name) ? q->name : "unknown"); |
| 269 | } |
| 270 | #endif |
| 271 | |
| 272 | #endif /* _LINUX_SUNRPC_SCHED_H_ */ |