scheduler_core.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /*
  2. * Copyright (c) 2014-2018 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #if !defined(__SCHEDULER_CORE_H)
  19. #define __SCHEDULER_CORE_H
  20. #include <qdf_threads.h>
  21. #include <qdf_timer.h>
  22. #include <scheduler_api.h>
  23. #include <qdf_list.h>
  24. #ifdef CONFIG_MCL
  25. #define SCHEDULER_CORE_MAX_MESSAGES 1000
  26. #else
  27. #define SCHEDULER_CORE_MAX_MESSAGES 2000
  28. #endif
  29. #define SCHEDULER_NUMBER_OF_MSG_QUEUE 6
  30. #define SCHEDULER_WRAPPER_MAX_FAIL_COUNT (SCHEDULER_CORE_MAX_MESSAGES * 3)
  31. #define SCHEDULER_WATCHDOG_TIMEOUT (10 * 1000) /* 10s */
  32. #define __sched_log(level, format, args...) \
  33. QDF_TRACE(QDF_MODULE_ID_SCHEDULER, level, FL(format), ## args)
  34. #define sched_fatal(format, args...) \
  35. __sched_log(QDF_TRACE_LEVEL_FATAL, format, ## args)
  36. #define sched_err(format, args...) \
  37. __sched_log(QDF_TRACE_LEVEL_ERROR, format, ## args)
  38. #define sched_warn(format, args...) \
  39. __sched_log(QDF_TRACE_LEVEL_WARN, format, ## args)
  40. #define sched_info(format, args...) \
  41. __sched_log(QDF_TRACE_LEVEL_INFO, format, ## args)
  42. #define sched_debug(format, args...) \
  43. __sched_log(QDF_TRACE_LEVEL_DEBUG, format, ## args)
  44. #define sched_enter() sched_debug("Enter")
  45. #define sched_exit() sched_debug("Exit")
  46. /**
  47. * struct scheduler_mq_type - scheduler message queue
  48. * @mq_lock: message queue lock
  49. * @mq_list: message queue list
  50. * @qid: queue id
  51. */
  52. struct scheduler_mq_type {
  53. qdf_spinlock_t mq_lock;
  54. qdf_list_t mq_list;
  55. QDF_MODULE_ID qid;
  56. };
  57. /**
  58. * struct scheduler_msg_wrapper - scheduler message wrapper
  59. * @msg_node: message node
  60. * @msg_buf: message buffer pointer
  61. */
  62. struct scheduler_msg_wrapper {
  63. qdf_list_node_t msg_node;
  64. struct scheduler_msg *msg_buf;
  65. };
  66. /**
  67. * struct scheduler_mq_ctx - scheduler message queue context
  68. * @msg_buffers: array of message buffers
  69. * @msg_wrappers: array of message wrappers
  70. * @free_msg_q: free message queue
  71. * @sch_msg_q: scheduler message queue
  72. * @scheduler_msg_qid_to_qidx: message qid to qidx mapping
  73. * @scheduler_msg_process_fn: array of message queue handler function pointers
  74. */
  75. struct scheduler_mq_ctx {
  76. struct scheduler_msg msg_buffers[SCHEDULER_CORE_MAX_MESSAGES];
  77. struct scheduler_msg_wrapper msg_wrappers[SCHEDULER_CORE_MAX_MESSAGES];
  78. struct scheduler_mq_type free_msg_q;
  79. struct scheduler_mq_type sch_msg_q[SCHEDULER_NUMBER_OF_MSG_QUEUE];
  80. uint8_t scheduler_msg_qid_to_qidx[QDF_MODULE_ID_MAX];
  81. QDF_STATUS (*scheduler_msg_process_fn[SCHEDULER_NUMBER_OF_MSG_QUEUE])
  82. (struct scheduler_msg *msg);
  83. };
  84. /**
  85. * struct scheduler_ctx - scheduler context
  86. * @queue_ctx: message queue context
  87. * @sch_start_event: scheduler thread start wait event
  88. * @sch_thread: scheduler thread
  89. * @sch_shutdown: scheduler thread shutdown wait event
  90. * @sch_wait_queue: scheduler wait queue
  91. * @sch_event_flag: scheduler events flag
  92. * @resume_sch_event: scheduler resume wait event
  93. * @sch_thread_lock: scheduler thread lock
  94. * @sch_last_qidx: scheduler last qidx allocation
  95. * @hdd_callback: os if suspend callback
  96. * @legacy_wma_handler: legacy wma message handler
  97. * @legacy_sys_handler: legacy sys message handler
  98. * @watchdog_timer: timer for triggering a scheduler watchdog bite
  99. * @watchdog_msg_type: 'type' of the current msg being processed
  100. * @watchdog_callback: the callback of the current msg being processed
  101. */
  102. struct scheduler_ctx {
  103. struct scheduler_mq_ctx queue_ctx;
  104. qdf_event_t sch_start_event;
  105. qdf_thread_t *sch_thread;
  106. qdf_event_t sch_shutdown;
  107. qdf_wait_queue_head_t sch_wait_queue;
  108. unsigned long sch_event_flag;
  109. qdf_event_t resume_sch_event;
  110. qdf_spinlock_t sch_thread_lock;
  111. uint8_t sch_last_qidx;
  112. hdd_suspend_callback hdd_callback;
  113. scheduler_msg_process_fn_t legacy_wma_handler;
  114. scheduler_msg_process_fn_t legacy_sys_handler;
  115. qdf_timer_t watchdog_timer;
  116. uint16_t watchdog_msg_type;
  117. void *watchdog_callback;
  118. };
  119. /**
  120. * scheduler_get_context() - to get scheduler context
  121. *
  122. * This routine is used retrieve scheduler context
  123. *
  124. * Return: Pointer to scheduler context
  125. */
  126. struct scheduler_ctx *scheduler_get_context(void);
  127. /**
  128. * scheduler_thread() - spawned thread will execute this routine
  129. * @arg: pointer to scheduler context
  130. *
  131. * Newly created thread will use this routine to perform its duty
  132. *
  133. * Return: none
  134. */
  135. int scheduler_thread(void *arg);
  136. /**
  137. * scheduler_cleanup_queues() - to clean up the given module's queue
  138. * @sch_ctx: pointer to scheduler context
  139. * @idx: index of the queue which needs to be cleanup.
  140. *
  141. * This routine is used to clean the module's queue provided by
  142. * user through idx field
  143. *
  144. * Return: none
  145. */
  146. void scheduler_cleanup_queues(struct scheduler_ctx *sch_ctx, int idx);
  147. /**
  148. * scheduler_create_ctx() - to create scheduler context
  149. *
  150. * This routine is used to create scheduler context
  151. *
  152. * Return: QDF_STATUS based on success or failure
  153. */
  154. QDF_STATUS scheduler_create_ctx(void);
  155. /**
  156. * scheduler_destroy_ctx() - to destroy scheduler context
  157. *
  158. * This routine is used to destroy scheduler context
  159. *
  160. * Return: QDF_STATUS based on success or failure
  161. */
  162. QDF_STATUS scheduler_destroy_ctx(void);
  163. /**
  164. * scheduler_mq_init() - initialize scheduler message queue
  165. * @msg_q: Pointer to the message queue
  166. *
  167. * This function initializes the Message queue.
  168. *
  169. * Return: qdf status
  170. */
  171. QDF_STATUS scheduler_mq_init(struct scheduler_mq_type *msg_q);
  172. /**
  173. * scheduler_mq_deinit() - de-initialize scheduler message queue
  174. * @msg_q: Pointer to the message queue
  175. *
  176. * This function de-initializes scheduler message queue
  177. *
  178. * Return: none
  179. */
  180. void scheduler_mq_deinit(struct scheduler_mq_type *msg_q);
  181. /**
  182. * scheduler_mq_put() - put message in the back of queue
  183. * @msg_q: Pointer to the message queue
  184. * @msg_wrapper: pointer to message wrapper
  185. *
  186. * This function is used to put message in back of provided message
  187. * queue
  188. *
  189. * Return: none
  190. */
  191. void scheduler_mq_put(struct scheduler_mq_type *msg_q,
  192. struct scheduler_msg_wrapper *msg_wrapper);
  193. /**
  194. * scheduler_mq_put_front() - put message in the front of queue
  195. * @msg_q: Pointer to the message queue
  196. * @msg_wrapper: pointer to message wrapper
  197. *
  198. * This function is used to put message in front of provided message
  199. * queue
  200. *
  201. * Return: none
  202. */
  203. void scheduler_mq_put_front(struct scheduler_mq_type *msg_q,
  204. struct scheduler_msg_wrapper *msg_wrapper);
  205. /**
  206. * scheduler_mq_get() - to get message from message queue
  207. * @msg_q: Pointer to the message queue
  208. *
  209. * This function is used to get message from given message queue
  210. *
  211. * Return: none
  212. */
  213. struct scheduler_msg_wrapper *scheduler_mq_get(struct scheduler_mq_type *msg_q);
  214. /**
  215. * scheduler_is_mq_empty() - to check if message queue is empty
  216. * @msg_q: Pointer to the message queue
  217. *
  218. * This function is used to check if message queue is empty
  219. *
  220. * Return: true or false
  221. */
  222. bool scheduler_is_mq_empty(struct scheduler_mq_type *msg_q);
  223. /**
  224. * scheduler_queues_init() - to initialize all the modules' queues
  225. * @sched_ctx: pointer to scheduler context
  226. *
  227. * This function is used to initialize the queues for all the modules
  228. *
  229. * Return: QDF_STATUS based on success of failure
  230. */
  231. QDF_STATUS scheduler_queues_init(struct scheduler_ctx *sched_ctx);
  232. /**
  233. * scheduler_queues_deinit() - to de-initialize all the modules' queues
  234. * @sched_ctx: pointer to scheduler context
  235. *
  236. * This function is used to de-initialize the queues for all the modules
  237. *
  238. * Return: QDF_STATUS based on success of failure
  239. */
  240. QDF_STATUS scheduler_queues_deinit(struct scheduler_ctx *gp_sch_ctx);
  241. #endif