sched.h 8.5 KB

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