PageRenderTime 43ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/include/linux/sunrpc/sched.h

https://gitlab.com/Sean.W/pru-linux-drivers
C Header | 276 lines | 200 code | 33 blank | 43 comment | 7 complexity | 56de7e28e82f3f5ac82dea07176079ff MD5 | raw file
  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_call_ops;
  27. struct rpc_wait_queue;
  28. struct rpc_wait {
  29. struct list_head list; /* wait queue links */
  30. struct list_head links; /* Links to related tasks */
  31. struct list_head timer_list; /* Timer list */
  32. unsigned long expires;
  33. };
  34. /*
  35. * This is the RPC task struct
  36. */
  37. struct rpc_task {
  38. #ifdef RPC_DEBUG
  39. unsigned long tk_magic; /* 0xf00baa */
  40. #endif
  41. atomic_t tk_count; /* Reference count */
  42. struct list_head tk_task; /* global list of tasks */
  43. struct rpc_clnt * tk_client; /* RPC client */
  44. struct rpc_rqst * tk_rqstp; /* RPC request */
  45. int tk_status; /* result of last operation */
  46. /*
  47. * RPC call state
  48. */
  49. struct rpc_message tk_msg; /* RPC call info */
  50. __u8 tk_garb_retry;
  51. __u8 tk_cred_retry;
  52. /*
  53. * callback to be executed after waking up
  54. * action next procedure for async tasks
  55. * tk_ops caller callbacks
  56. */
  57. void (*tk_callback)(struct rpc_task *);
  58. void (*tk_action)(struct rpc_task *);
  59. const struct rpc_call_ops *tk_ops;
  60. void * tk_calldata;
  61. unsigned long tk_timeout; /* timeout for rpc_sleep() */
  62. unsigned short tk_flags; /* misc flags */
  63. unsigned long tk_runstate; /* Task run status */
  64. struct workqueue_struct *tk_workqueue; /* Normally rpciod, but could
  65. * be any workqueue
  66. */
  67. struct rpc_wait_queue *tk_waitqueue; /* RPC wait queue we're on */
  68. union {
  69. struct work_struct tk_work; /* Async task work queue */
  70. struct rpc_wait tk_wait; /* RPC wait */
  71. } u;
  72. unsigned short tk_timeouts; /* maj timeouts */
  73. size_t tk_bytes_sent; /* total bytes sent */
  74. unsigned long tk_start; /* RPC task init timestamp */
  75. long tk_rtt; /* round-trip time (jiffies) */
  76. pid_t tk_owner; /* Process id for batching tasks */
  77. unsigned char tk_priority : 2;/* Task priority */
  78. #ifdef RPC_DEBUG
  79. unsigned short tk_pid; /* debugging aid */
  80. #endif
  81. };
  82. #define tk_xprt tk_client->cl_xprt
  83. /* support walking a list of tasks on a wait queue */
  84. #define task_for_each(task, pos, head) \
  85. list_for_each(pos, head) \
  86. if ((task=list_entry(pos, struct rpc_task, u.tk_wait.list)),1)
  87. #define task_for_first(task, head) \
  88. if (!list_empty(head) && \
  89. ((task=list_entry((head)->next, struct rpc_task, u.tk_wait.list)),1))
  90. typedef void (*rpc_action)(struct rpc_task *);
  91. struct rpc_call_ops {
  92. void (*rpc_call_prepare)(struct rpc_task *, void *);
  93. void (*rpc_call_done)(struct rpc_task *, void *);
  94. void (*rpc_release)(void *);
  95. };
  96. struct rpc_task_setup {
  97. struct rpc_task *task;
  98. struct rpc_clnt *rpc_client;
  99. const struct rpc_message *rpc_message;
  100. const struct rpc_call_ops *callback_ops;
  101. void *callback_data;
  102. struct workqueue_struct *workqueue;
  103. unsigned short flags;
  104. signed char priority;
  105. };
  106. /*
  107. * RPC task flags
  108. */
  109. #define RPC_TASK_ASYNC 0x0001 /* is an async task */
  110. #define RPC_TASK_SWAPPER 0x0002 /* is swapping in/out */
  111. #define RPC_CALL_MAJORSEEN 0x0020 /* major timeout seen */
  112. #define RPC_TASK_ROOTCREDS 0x0040 /* force root creds */
  113. #define RPC_TASK_DYNAMIC 0x0080 /* task was kmalloc'ed */
  114. #define RPC_TASK_KILLED 0x0100 /* task was killed */
  115. #define RPC_TASK_SOFT 0x0200 /* Use soft timeouts */
  116. #define RPC_TASK_SOFTCONN 0x0400 /* Fail if can't connect */
  117. #define RPC_IS_ASYNC(t) ((t)->tk_flags & RPC_TASK_ASYNC)
  118. #define RPC_IS_SWAPPER(t) ((t)->tk_flags & RPC_TASK_SWAPPER)
  119. #define RPC_DO_ROOTOVERRIDE(t) ((t)->tk_flags & RPC_TASK_ROOTCREDS)
  120. #define RPC_ASSASSINATED(t) ((t)->tk_flags & RPC_TASK_KILLED)
  121. #define RPC_IS_SOFT(t) ((t)->tk_flags & RPC_TASK_SOFT)
  122. #define RPC_IS_SOFTCONN(t) ((t)->tk_flags & RPC_TASK_SOFTCONN)
  123. #define RPC_TASK_RUNNING 0
  124. #define RPC_TASK_QUEUED 1
  125. #define RPC_TASK_ACTIVE 2
  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_IS_ACTIVATED(t) test_bit(RPC_TASK_ACTIVE, &(t)->tk_runstate)
  145. /*
  146. * Task priorities.
  147. * Note: if you change these, you must also change
  148. * the task initialization definitions below.
  149. */
  150. #define RPC_PRIORITY_LOW (-1)
  151. #define RPC_PRIORITY_NORMAL (0)
  152. #define RPC_PRIORITY_HIGH (1)
  153. #define RPC_PRIORITY_PRIVILEGED (2)
  154. #define RPC_NR_PRIORITY (1 + RPC_PRIORITY_PRIVILEGED - RPC_PRIORITY_LOW)
  155. struct rpc_timer {
  156. struct timer_list timer;
  157. struct list_head list;
  158. unsigned long expires;
  159. };
  160. /*
  161. * RPC synchronization objects
  162. */
  163. struct rpc_wait_queue {
  164. spinlock_t lock;
  165. struct list_head tasks[RPC_NR_PRIORITY]; /* task queue for each priority level */
  166. pid_t owner; /* process id of last task serviced */
  167. unsigned char maxpriority; /* maximum priority (0 if queue is not a priority queue) */
  168. unsigned char priority; /* current priority */
  169. unsigned char count; /* # task groups remaining serviced so far */
  170. unsigned char nr; /* # tasks remaining for cookie */
  171. unsigned short qlen; /* total # tasks waiting in queue */
  172. struct rpc_timer timer_list;
  173. #ifdef RPC_DEBUG
  174. const char * name;
  175. #endif
  176. };
  177. /*
  178. * This is the # requests to send consecutively
  179. * from a single cookie. The aim is to improve
  180. * performance of NFS operations such as read/write.
  181. */
  182. #define RPC_BATCH_COUNT 16
  183. #define RPC_IS_PRIORITY(q) ((q)->maxpriority > 0)
  184. /*
  185. * Function prototypes
  186. */
  187. struct rpc_task *rpc_new_task(const struct rpc_task_setup *);
  188. struct rpc_task *rpc_run_task(const struct rpc_task_setup *);
  189. struct rpc_task *rpc_run_bc_task(struct rpc_rqst *req,
  190. const struct rpc_call_ops *ops);
  191. void rpc_put_task(struct rpc_task *);
  192. void rpc_exit_task(struct rpc_task *);
  193. void rpc_release_calldata(const struct rpc_call_ops *, void *);
  194. void rpc_killall_tasks(struct rpc_clnt *);
  195. void rpc_execute(struct rpc_task *);
  196. void rpc_init_priority_wait_queue(struct rpc_wait_queue *, const char *);
  197. void rpc_init_wait_queue(struct rpc_wait_queue *, const char *);
  198. void rpc_destroy_wait_queue(struct rpc_wait_queue *);
  199. void rpc_sleep_on(struct rpc_wait_queue *, struct rpc_task *,
  200. rpc_action action);
  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. void rpc_wake_up_status(struct rpc_wait_queue *, int);
  206. int rpc_queue_empty(struct rpc_wait_queue *);
  207. void rpc_delay(struct rpc_task *, unsigned long);
  208. void * rpc_malloc(struct rpc_task *, size_t);
  209. void rpc_free(void *);
  210. int rpciod_up(void);
  211. void rpciod_down(void);
  212. int __rpc_wait_for_completion_task(struct rpc_task *task, int (*)(void *));
  213. #ifdef RPC_DEBUG
  214. void rpc_show_tasks(void);
  215. #endif
  216. int rpc_init_mempool(void);
  217. void rpc_destroy_mempool(void);
  218. extern struct workqueue_struct *rpciod_workqueue;
  219. void rpc_prepare_task(struct rpc_task *task);
  220. static inline void rpc_exit(struct rpc_task *task, int status)
  221. {
  222. task->tk_status = status;
  223. task->tk_action = rpc_exit_task;
  224. }
  225. static inline int rpc_wait_for_completion_task(struct rpc_task *task)
  226. {
  227. return __rpc_wait_for_completion_task(task, NULL);
  228. }
  229. static inline void rpc_task_set_priority(struct rpc_task *task, unsigned char prio)
  230. {
  231. task->tk_priority = prio - RPC_PRIORITY_LOW;
  232. }
  233. static inline int rpc_task_has_priority(struct rpc_task *task, unsigned char prio)
  234. {
  235. return (task->tk_priority + RPC_PRIORITY_LOW == prio);
  236. }
  237. #ifdef RPC_DEBUG
  238. static inline const char * rpc_qname(struct rpc_wait_queue *q)
  239. {
  240. return ((q && q->name) ? q->name : "unknown");
  241. }
  242. #endif
  243. #endif /* _LINUX_SUNRPC_SCHED_H_ */