sched.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  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/ktime.h>
  12. #include <linux/sunrpc/types.h>
  13. #include <linux/spinlock.h>
  14. #include <linux/wait.h>
  15. #include <linux/workqueue.h>
  16. #include <linux/sunrpc/xdr.h>
  17. /*
  18. * This is the actual RPC procedure call info.
  19. */
  20. struct rpc_procinfo;
  21. struct rpc_message {
  22. struct rpc_procinfo * rpc_proc; /* Procedure information */
  23. void * rpc_argp; /* Arguments */
  24. void * rpc_resp; /* Result */
  25. struct rpc_cred * rpc_cred; /* Credentials */
  26. };
  27. struct rpc_call_ops;
  28. struct rpc_wait_queue;
  29. struct rpc_wait {
  30. struct list_head list; /* wait queue links */
  31. struct list_head links; /* Links to related tasks */
  32. struct list_head timer_list; /* Timer list */
  33. unsigned long expires;
  34. };
  35. /*
  36. * This is the RPC task struct
  37. */
  38. struct rpc_task {
  39. #ifdef RPC_DEBUG
  40. unsigned long tk_magic; /* 0xf00baa */
  41. #endif
  42. atomic_t tk_count; /* Reference count */
  43. struct list_head tk_task; /* global list of tasks */
  44. struct rpc_clnt * tk_client; /* RPC client */
  45. struct rpc_rqst * tk_rqstp; /* RPC request */
  46. int tk_status; /* result of last operation */
  47. /*
  48. * RPC call state
  49. */
  50. struct rpc_message tk_msg; /* RPC call info */
  51. __u8 tk_garb_retry;
  52. __u8 tk_cred_retry;
  53. /*
  54. * callback to be executed after waking up
  55. * action next procedure for async tasks
  56. * tk_ops caller callbacks
  57. */
  58. void (*tk_callback)(struct rpc_task *);
  59. void (*tk_action)(struct rpc_task *);
  60. const struct rpc_call_ops *tk_ops;
  61. void * tk_calldata;
  62. unsigned long tk_timeout; /* timeout for rpc_sleep() */
  63. unsigned short tk_flags; /* misc flags */
  64. unsigned long tk_runstate; /* Task run status */
  65. struct workqueue_struct *tk_workqueue; /* Normally rpciod, but could
  66. * be any workqueue
  67. */
  68. struct rpc_wait_queue *tk_waitqueue; /* RPC wait queue we're on */
  69. union {
  70. struct work_struct tk_work; /* Async task work queue */
  71. struct rpc_wait tk_wait; /* RPC wait */
  72. } u;
  73. unsigned short tk_timeouts; /* maj timeouts */
  74. ktime_t tk_start; /* RPC task init timestamp */
  75. pid_t tk_owner; /* Process id for batching tasks */
  76. unsigned char tk_priority : 2;/* Task priority */
  77. #ifdef RPC_DEBUG
  78. unsigned short tk_pid; /* debugging aid */
  79. #endif
  80. };
  81. #define tk_xprt tk_client->cl_xprt
  82. /* support walking a list of tasks on a wait queue */
  83. #define task_for_each(task, pos, head) \
  84. list_for_each(pos, head) \
  85. if ((task=list_entry(pos, struct rpc_task, u.tk_wait.list)),1)
  86. #define task_for_first(task, head) \
  87. if (!list_empty(head) && \
  88. ((task=list_entry((head)->next, struct rpc_task, u.tk_wait.list)),1))
  89. typedef void (*rpc_action)(struct rpc_task *);
  90. struct rpc_call_ops {
  91. void (*rpc_call_prepare)(struct rpc_task *, void *);
  92. void (*rpc_call_done)(struct rpc_task *, void *);
  93. void (*rpc_release)(void *);
  94. };
  95. struct rpc_task_setup {
  96. struct rpc_task *task;
  97. struct rpc_clnt *rpc_client;
  98. const struct rpc_message *rpc_message;
  99. const struct rpc_call_ops *callback_ops;
  100. void *callback_data;
  101. struct workqueue_struct *workqueue;
  102. unsigned short flags;
  103. signed char priority;
  104. };
  105. /*
  106. * RPC task flags
  107. */
  108. #define RPC_TASK_ASYNC 0x0001 /* is an async task */
  109. #define RPC_TASK_SWAPPER 0x0002 /* is swapping in/out */
  110. #define RPC_CALL_MAJORSEEN 0x0020 /* major timeout seen */
  111. #define RPC_TASK_ROOTCREDS 0x0040 /* force root creds */
  112. #define RPC_TASK_DYNAMIC 0x0080 /* task was kmalloc'ed */
  113. #define RPC_TASK_KILLED 0x0100 /* task was killed */
  114. #define RPC_TASK_SOFT 0x0200 /* Use soft timeouts */
  115. #define RPC_TASK_SOFTCONN 0x0400 /* Fail if can't connect */
  116. #define RPC_IS_ASYNC(t) ((t)->tk_flags & RPC_TASK_ASYNC)
  117. #define RPC_IS_SWAPPER(t) ((t)->tk_flags & RPC_TASK_SWAPPER)
  118. #define RPC_DO_ROOTOVERRIDE(t) ((t)->tk_flags & RPC_TASK_ROOTCREDS)
  119. #define RPC_ASSASSINATED(t) ((t)->tk_flags & RPC_TASK_KILLED)
  120. #define RPC_IS_SOFT(t) ((t)->tk_flags & RPC_TASK_SOFT)
  121. #define RPC_IS_SOFTCONN(t) ((t)->tk_flags & RPC_TASK_SOFTCONN)
  122. #define RPC_TASK_RUNNING 0
  123. #define RPC_TASK_QUEUED 1
  124. #define RPC_TASK_ACTIVE 2
  125. #define RPC_IS_RUNNING(t) test_bit(RPC_TASK_RUNNING, &(t)->tk_runstate)
  126. #define rpc_set_running(t) set_bit(RPC_TASK_RUNNING, &(t)->tk_runstate)
  127. #define rpc_test_and_set_running(t) \
  128. test_and_set_bit(RPC_TASK_RUNNING, &(t)->tk_runstate)
  129. #define rpc_clear_running(t) \
  130. do { \
  131. smp_mb__before_clear_bit(); \
  132. clear_bit(RPC_TASK_RUNNING, &(t)->tk_runstate); \
  133. smp_mb__after_clear_bit(); \
  134. } while (0)
  135. #define RPC_IS_QUEUED(t) test_bit(RPC_TASK_QUEUED, &(t)->tk_runstate)
  136. #define rpc_set_queued(t) set_bit(RPC_TASK_QUEUED, &(t)->tk_runstate)
  137. #define rpc_clear_queued(t) \
  138. do { \
  139. smp_mb__before_clear_bit(); \
  140. clear_bit(RPC_TASK_QUEUED, &(t)->tk_runstate); \
  141. smp_mb__after_clear_bit(); \
  142. } while (0)
  143. #define RPC_IS_ACTIVATED(t) test_bit(RPC_TASK_ACTIVE, &(t)->tk_runstate)
  144. /*
  145. * Task priorities.
  146. * Note: if you change these, you must also change
  147. * the task initialization definitions below.
  148. */
  149. #define RPC_PRIORITY_LOW (-1)
  150. #define RPC_PRIORITY_NORMAL (0)
  151. #define RPC_PRIORITY_HIGH (1)
  152. #define RPC_PRIORITY_PRIVILEGED (2)
  153. #define RPC_NR_PRIORITY (1 + RPC_PRIORITY_PRIVILEGED - RPC_PRIORITY_LOW)
  154. struct rpc_timer {
  155. struct timer_list timer;
  156. struct list_head list;
  157. unsigned long expires;
  158. };
  159. /*
  160. * RPC synchronization objects
  161. */
  162. struct rpc_wait_queue {
  163. spinlock_t lock;
  164. struct list_head tasks[RPC_NR_PRIORITY]; /* task queue for each priority level */
  165. pid_t owner; /* process id of last task serviced */
  166. unsigned char maxpriority; /* maximum priority (0 if queue is not a priority queue) */
  167. unsigned char priority; /* current priority */
  168. unsigned char count; /* # task groups remaining serviced so far */
  169. unsigned char nr; /* # tasks remaining for cookie */
  170. unsigned short qlen; /* total # tasks waiting in queue */
  171. struct rpc_timer timer_list;
  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. #define RPC_IS_PRIORITY(q) ((q)->maxpriority > 0)
  183. /*
  184. * Function prototypes
  185. */
  186. struct rpc_task *rpc_new_task(const struct rpc_task_setup *);
  187. struct rpc_task *rpc_run_task(const struct rpc_task_setup *);
  188. struct rpc_task *rpc_run_bc_task(struct rpc_rqst *req,
  189. const struct rpc_call_ops *ops);
  190. void rpc_put_task(struct rpc_task *);
  191. void rpc_exit_task(struct rpc_task *);
  192. void rpc_release_calldata(const struct rpc_call_ops *, void *);
  193. void rpc_killall_tasks(struct rpc_clnt *);
  194. void rpc_execute(struct rpc_task *);
  195. void rpc_init_priority_wait_queue(struct rpc_wait_queue *, const char *);
  196. void rpc_init_wait_queue(struct rpc_wait_queue *, const char *);
  197. void rpc_destroy_wait_queue(struct rpc_wait_queue *);
  198. void rpc_sleep_on(struct rpc_wait_queue *, struct rpc_task *,
  199. rpc_action action);
  200. void rpc_wake_up_queued_task(struct rpc_wait_queue *,
  201. struct rpc_task *);
  202. void rpc_wake_up(struct rpc_wait_queue *);
  203. struct rpc_task *rpc_wake_up_next(struct rpc_wait_queue *);
  204. void rpc_wake_up_status(struct rpc_wait_queue *, int);
  205. int rpc_queue_empty(struct rpc_wait_queue *);
  206. void rpc_delay(struct rpc_task *, unsigned long);
  207. void * rpc_malloc(struct rpc_task *, size_t);
  208. void rpc_free(void *);
  209. int rpciod_up(void);
  210. void rpciod_down(void);
  211. int __rpc_wait_for_completion_task(struct rpc_task *task, int (*)(void *));
  212. #ifdef RPC_DEBUG
  213. void rpc_show_tasks(void);
  214. #endif
  215. int rpc_init_mempool(void);
  216. void rpc_destroy_mempool(void);
  217. extern struct workqueue_struct *rpciod_workqueue;
  218. void rpc_prepare_task(struct rpc_task *task);
  219. static inline void rpc_exit(struct rpc_task *task, int status)
  220. {
  221. task->tk_status = status;
  222. task->tk_action = rpc_exit_task;
  223. }
  224. static inline int rpc_wait_for_completion_task(struct rpc_task *task)
  225. {
  226. return __rpc_wait_for_completion_task(task, NULL);
  227. }
  228. static inline void rpc_task_set_priority(struct rpc_task *task, unsigned char prio)
  229. {
  230. task->tk_priority = prio - RPC_PRIORITY_LOW;
  231. }
  232. static inline int rpc_task_has_priority(struct rpc_task *task, unsigned char prio)
  233. {
  234. return (task->tk_priority + RPC_PRIORITY_LOW == prio);
  235. }
  236. #ifdef RPC_DEBUG
  237. static inline const char * rpc_qname(struct rpc_wait_queue *q)
  238. {
  239. return ((q && q->name) ? q->name : "unknown");
  240. }
  241. #endif
  242. #endif /* _LINUX_SUNRPC_SCHED_H_ */