sched.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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. atomic_t tk_count; /* Reference count */
  40. int tk_status; /* result of last operation */
  41. struct list_head tk_task; /* global list of tasks */
  42. /*
  43. * callback to be executed after waking up
  44. * action next procedure for async tasks
  45. */
  46. void (*tk_callback)(struct rpc_task *);
  47. void (*tk_action)(struct rpc_task *);
  48. unsigned long tk_timeout; /* timeout for rpc_sleep() */
  49. unsigned long tk_runstate; /* Task run status */
  50. struct rpc_wait_queue *tk_waitqueue; /* RPC wait queue we're on */
  51. union {
  52. struct work_struct tk_work; /* Async task work queue */
  53. struct rpc_wait tk_wait; /* RPC wait */
  54. } u;
  55. /*
  56. * RPC call state
  57. */
  58. struct rpc_message tk_msg; /* RPC call info */
  59. void * tk_calldata; /* Caller private data */
  60. const struct rpc_call_ops *tk_ops; /* Caller callbacks */
  61. struct rpc_clnt * tk_client; /* RPC client */
  62. struct rpc_xprt * tk_xprt; /* Transport */
  63. struct rpc_rqst * tk_rqstp; /* RPC request */
  64. struct workqueue_struct *tk_workqueue; /* Normally rpciod, but could
  65. * be any workqueue
  66. */
  67. ktime_t tk_start; /* RPC task init timestamp */
  68. pid_t tk_owner; /* Process id for batching tasks */
  69. unsigned short tk_flags; /* misc flags */
  70. unsigned short tk_timeouts; /* maj timeouts */
  71. #if IS_ENABLED(CONFIG_SUNRPC_DEBUG) || IS_ENABLED(CONFIG_TRACEPOINTS)
  72. unsigned short tk_pid; /* debugging aid */
  73. #endif
  74. unsigned char tk_priority : 2,/* Task priority */
  75. tk_garb_retry : 2,
  76. tk_cred_retry : 2,
  77. tk_rebind_retry : 2;
  78. };
  79. typedef void (*rpc_action)(struct rpc_task *);
  80. struct rpc_call_ops {
  81. void (*rpc_call_prepare)(struct rpc_task *, void *);
  82. void (*rpc_call_done)(struct rpc_task *, void *);
  83. void (*rpc_count_stats)(struct rpc_task *, void *);
  84. void (*rpc_release)(void *);
  85. };
  86. struct rpc_task_setup {
  87. struct rpc_task *task;
  88. struct rpc_clnt *rpc_client;
  89. struct rpc_xprt *rpc_xprt;
  90. const struct rpc_message *rpc_message;
  91. const struct rpc_call_ops *callback_ops;
  92. void *callback_data;
  93. struct workqueue_struct *workqueue;
  94. unsigned short flags;
  95. signed char priority;
  96. };
  97. /*
  98. * RPC task flags
  99. */
  100. #define RPC_TASK_ASYNC 0x0001 /* is an async task */
  101. #define RPC_TASK_SWAPPER 0x0002 /* is swapping in/out */
  102. #define RPC_CALL_MAJORSEEN 0x0020 /* major timeout seen */
  103. #define RPC_TASK_ROOTCREDS 0x0040 /* force root creds */
  104. #define RPC_TASK_DYNAMIC 0x0080 /* task was kmalloc'ed */
  105. #define RPC_TASK_KILLED 0x0100 /* task was killed */
  106. #define RPC_TASK_SOFT 0x0200 /* Use soft timeouts */
  107. #define RPC_TASK_SOFTCONN 0x0400 /* Fail if can't connect */
  108. #define RPC_TASK_SENT 0x0800 /* message was sent */
  109. #define RPC_TASK_TIMEOUT 0x1000 /* fail with ETIMEDOUT on timeout */
  110. #define RPC_TASK_NOCONNECT 0x2000 /* return ENOTCONN if not connected */
  111. #define RPC_TASK_NO_RETRANS_TIMEOUT 0x4000 /* wait forever for a reply */
  112. #define RPC_IS_ASYNC(t) ((t)->tk_flags & RPC_TASK_ASYNC)
  113. #define RPC_IS_SWAPPER(t) ((t)->tk_flags & RPC_TASK_SWAPPER)
  114. #define RPC_DO_ROOTOVERRIDE(t) ((t)->tk_flags & RPC_TASK_ROOTCREDS)
  115. #define RPC_ASSASSINATED(t) ((t)->tk_flags & RPC_TASK_KILLED)
  116. #define RPC_IS_SOFT(t) ((t)->tk_flags & (RPC_TASK_SOFT|RPC_TASK_TIMEOUT))
  117. #define RPC_IS_SOFTCONN(t) ((t)->tk_flags & RPC_TASK_SOFTCONN)
  118. #define RPC_WAS_SENT(t) ((t)->tk_flags & RPC_TASK_SENT)
  119. #define RPC_TASK_RUNNING 0
  120. #define RPC_TASK_QUEUED 1
  121. #define RPC_TASK_ACTIVE 2
  122. #define RPC_IS_RUNNING(t) test_bit(RPC_TASK_RUNNING, &(t)->tk_runstate)
  123. #define rpc_set_running(t) set_bit(RPC_TASK_RUNNING, &(t)->tk_runstate)
  124. #define rpc_test_and_set_running(t) \
  125. test_and_set_bit(RPC_TASK_RUNNING, &(t)->tk_runstate)
  126. #define rpc_clear_running(t) \
  127. do { \
  128. smp_mb__before_atomic(); \
  129. clear_bit(RPC_TASK_RUNNING, &(t)->tk_runstate); \
  130. smp_mb__after_atomic(); \
  131. } while (0)
  132. #define RPC_IS_QUEUED(t) test_bit(RPC_TASK_QUEUED, &(t)->tk_runstate)
  133. #define rpc_set_queued(t) set_bit(RPC_TASK_QUEUED, &(t)->tk_runstate)
  134. #define rpc_clear_queued(t) \
  135. do { \
  136. smp_mb__before_atomic(); \
  137. clear_bit(RPC_TASK_QUEUED, &(t)->tk_runstate); \
  138. smp_mb__after_atomic(); \
  139. } while (0)
  140. #define RPC_IS_ACTIVATED(t) test_bit(RPC_TASK_ACTIVE, &(t)->tk_runstate)
  141. /*
  142. * Task priorities.
  143. * Note: if you change these, you must also change
  144. * the task initialization definitions below.
  145. */
  146. #define RPC_PRIORITY_LOW (-1)
  147. #define RPC_PRIORITY_NORMAL (0)
  148. #define RPC_PRIORITY_HIGH (1)
  149. #define RPC_PRIORITY_PRIVILEGED (2)
  150. #define RPC_NR_PRIORITY (1 + RPC_PRIORITY_PRIVILEGED - RPC_PRIORITY_LOW)
  151. struct rpc_timer {
  152. struct timer_list timer;
  153. struct list_head list;
  154. unsigned long expires;
  155. };
  156. /*
  157. * RPC synchronization objects
  158. */
  159. struct rpc_wait_queue {
  160. spinlock_t lock;
  161. struct list_head tasks[RPC_NR_PRIORITY]; /* task queue for each priority level */
  162. pid_t owner; /* process id of last task serviced */
  163. unsigned char maxpriority; /* maximum priority (0 if queue is not a priority queue) */
  164. unsigned char priority; /* current priority */
  165. unsigned char nr; /* # tasks remaining for cookie */
  166. unsigned short qlen; /* total # tasks waiting in queue */
  167. struct rpc_timer timer_list;
  168. #if IS_ENABLED(CONFIG_SUNRPC_DEBUG) || IS_ENABLED(CONFIG_TRACEPOINTS)
  169. const char * name;
  170. #endif
  171. };
  172. /*
  173. * This is the # requests to send consecutively
  174. * from a single cookie. The aim is to improve
  175. * performance of NFS operations such as read/write.
  176. */
  177. #define RPC_BATCH_COUNT 16
  178. #define RPC_IS_PRIORITY(q) ((q)->maxpriority > 0)
  179. /*
  180. * Function prototypes
  181. */
  182. struct rpc_task *rpc_new_task(const struct rpc_task_setup *);
  183. struct rpc_task *rpc_run_task(const struct rpc_task_setup *);
  184. struct rpc_task *rpc_run_bc_task(struct rpc_rqst *req);
  185. void rpc_put_task(struct rpc_task *);
  186. void rpc_put_task_async(struct rpc_task *);
  187. void rpc_exit_task(struct rpc_task *);
  188. void rpc_exit(struct rpc_task *, int);
  189. void rpc_release_calldata(const struct rpc_call_ops *, void *);
  190. void rpc_killall_tasks(struct rpc_clnt *);
  191. void rpc_execute(struct rpc_task *);
  192. void rpc_init_priority_wait_queue(struct rpc_wait_queue *, const char *);
  193. void rpc_init_wait_queue(struct rpc_wait_queue *, const char *);
  194. void rpc_destroy_wait_queue(struct rpc_wait_queue *);
  195. void rpc_sleep_on(struct rpc_wait_queue *, struct rpc_task *,
  196. rpc_action action);
  197. void rpc_sleep_on_priority(struct rpc_wait_queue *,
  198. struct rpc_task *,
  199. rpc_action action,
  200. int priority);
  201. void rpc_wake_up_queued_task(struct rpc_wait_queue *,
  202. struct rpc_task *);
  203. void rpc_wake_up(struct rpc_wait_queue *);
  204. struct rpc_task *rpc_wake_up_next(struct rpc_wait_queue *);
  205. struct rpc_task *rpc_wake_up_first_on_wq(struct workqueue_struct *wq,
  206. struct rpc_wait_queue *,
  207. bool (*)(struct rpc_task *, void *),
  208. void *);
  209. struct rpc_task *rpc_wake_up_first(struct rpc_wait_queue *,
  210. bool (*)(struct rpc_task *, void *),
  211. void *);
  212. void rpc_wake_up_status(struct rpc_wait_queue *, int);
  213. void rpc_delay(struct rpc_task *, unsigned long);
  214. int rpc_malloc(struct rpc_task *);
  215. void rpc_free(struct rpc_task *);
  216. int rpciod_up(void);
  217. void rpciod_down(void);
  218. int __rpc_wait_for_completion_task(struct rpc_task *task, wait_bit_action_f *);
  219. #if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
  220. struct net;
  221. void rpc_show_tasks(struct net *);
  222. #endif
  223. int rpc_init_mempool(void);
  224. void rpc_destroy_mempool(void);
  225. extern struct workqueue_struct *rpciod_workqueue;
  226. extern struct workqueue_struct *xprtiod_workqueue;
  227. void rpc_prepare_task(struct rpc_task *task);
  228. static inline int rpc_wait_for_completion_task(struct rpc_task *task)
  229. {
  230. return __rpc_wait_for_completion_task(task, NULL);
  231. }
  232. #if IS_ENABLED(CONFIG_SUNRPC_DEBUG) || IS_ENABLED(CONFIG_TRACEPOINTS)
  233. static inline const char * rpc_qname(const struct rpc_wait_queue *q)
  234. {
  235. return ((q && q->name) ? q->name : "unknown");
  236. }
  237. static inline void rpc_assign_waitqueue_name(struct rpc_wait_queue *q,
  238. const char *name)
  239. {
  240. q->name = name;
  241. }
  242. #else
  243. static inline void rpc_assign_waitqueue_name(struct rpc_wait_queue *q,
  244. const char *name)
  245. {
  246. }
  247. #endif
  248. #if IS_ENABLED(CONFIG_SUNRPC_SWAP)
  249. int rpc_clnt_swap_activate(struct rpc_clnt *clnt);
  250. void rpc_clnt_swap_deactivate(struct rpc_clnt *clnt);
  251. #else
  252. static inline int
  253. rpc_clnt_swap_activate(struct rpc_clnt *clnt)
  254. {
  255. return -EINVAL;
  256. }
  257. static inline void
  258. rpc_clnt_swap_deactivate(struct rpc_clnt *clnt)
  259. {
  260. }
  261. #endif /* CONFIG_SUNRPC_SWAP */
  262. #endif /* _LINUX_SUNRPC_SCHED_H_ */