scheduler_core.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. /*
  2. * Copyright (c) 2014-2021 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. #ifndef SCHEDULER_CORE_MAX_MESSAGES
  25. #define SCHEDULER_CORE_MAX_MESSAGES 4000
  26. #endif
  27. #ifndef WLAN_SCHED_REDUCTION_LIMIT
  28. #define WLAN_SCHED_REDUCTION_LIMIT 32
  29. #endif
  30. #define SCHEDULER_NUMBER_OF_MSG_QUEUE 6
  31. #define SCHEDULER_WRAPPER_MAX_FAIL_COUNT (SCHEDULER_CORE_MAX_MESSAGES * 3)
  32. #define SCHEDULER_WATCHDOG_TIMEOUT (10 * 1000) /* 10s */
  33. #ifdef CONFIG_AP_PLATFORM
  34. #define SCHED_DEBUG_PANIC(msg)
  35. #else
  36. #define SCHED_DEBUG_PANIC(msg) QDF_DEBUG_PANIC(msg)
  37. #endif
  38. #define sched_fatal(params...) \
  39. QDF_TRACE_FATAL(QDF_MODULE_ID_SCHEDULER, params)
  40. #define sched_err(params...) \
  41. QDF_TRACE_ERROR(QDF_MODULE_ID_SCHEDULER, params)
  42. #define sched_warn(params...) \
  43. QDF_TRACE_WARN(QDF_MODULE_ID_SCHEDULER, params)
  44. #define sched_info(params...) \
  45. QDF_TRACE_INFO(QDF_MODULE_ID_SCHEDULER, params)
  46. #define sched_debug(params...) \
  47. QDF_TRACE_DEBUG(QDF_MODULE_ID_SCHEDULER, params)
  48. #define sched_nofl_fatal(params...) \
  49. QDF_TRACE_FATAL_NO_FL(QDF_MODULE_ID_SCHEDULER, params)
  50. #define sched_nofl_err(params...) \
  51. QDF_TRACE_ERROR_NO_FL(QDF_MODULE_ID_SCHEDULER, params)
  52. #define sched_nofl_warn(params...) \
  53. QDF_TRACE_WARN_NO_FL(QDF_MODULE_ID_SCHEDULER, params)
  54. #define sched_nofl_info(params...) \
  55. QDF_TRACE_INFO_NO_FL(QDF_MODULE_ID_SCHEDULER, params)
  56. #define sched_nofl_debug(params...) \
  57. QDF_TRACE_DEBUG_NO_FL(QDF_MODULE_ID_SCHEDULER, params)
  58. #define sched_enter() sched_debug("Enter")
  59. #define sched_exit() sched_debug("Exit")
  60. /**
  61. * struct scheduler_mq_type - scheduler message queue
  62. * @mq_lock: message queue lock
  63. * @mq_list: message queue list
  64. * @qid: queue id
  65. */
  66. struct scheduler_mq_type {
  67. qdf_spinlock_t mq_lock;
  68. qdf_list_t mq_list;
  69. QDF_MODULE_ID qid;
  70. };
  71. /**
  72. * struct scheduler_mq_ctx - scheduler message queue context
  73. * @sch_msg_q: scheduler message queue
  74. * @scheduler_msg_qid_to_qidx: message qid to qidx mapping
  75. * @scheduler_msg_process_fn: array of message queue handler function pointers
  76. */
  77. struct scheduler_mq_ctx {
  78. struct scheduler_mq_type sch_msg_q[SCHEDULER_NUMBER_OF_MSG_QUEUE];
  79. uint8_t scheduler_msg_qid_to_qidx[QDF_MODULE_ID_MAX];
  80. QDF_STATUS (*scheduler_msg_process_fn[SCHEDULER_NUMBER_OF_MSG_QUEUE])
  81. (struct scheduler_msg *msg);
  82. };
  83. /**
  84. * struct scheduler_ctx - scheduler context
  85. * @queue_ctx: message queue context
  86. * @sch_start_event: scheduler thread start wait event
  87. * @sch_thread: scheduler thread
  88. * @sch_shutdown: scheduler thread shutdown wait event
  89. * @sch_wait_queue: scheduler wait queue
  90. * @sch_event_flag: scheduler events flag
  91. * @resume_sch_event: scheduler resume wait event
  92. * @sch_thread_lock: scheduler thread lock
  93. * @sch_last_qidx: scheduler last qidx allocation
  94. * @watchdog_msg_type: 'type' of the current msg being processed
  95. * @hdd_callback: os if suspend callback
  96. * @legacy_wma_handler: legacy wma message handler
  97. * @legacy_sys_handler: legacy sys message handler
  98. * @timeout: timeout value for scheduler watchdog timer
  99. * @watchdog_timer: timer for triggering a scheduler watchdog bite
  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. uint16_t watchdog_msg_type;
  113. hdd_suspend_callback hdd_callback;
  114. scheduler_msg_process_fn_t legacy_wma_handler;
  115. scheduler_msg_process_fn_t legacy_sys_handler;
  116. uint32_t timeout;
  117. qdf_timer_t watchdog_timer;
  118. void *watchdog_callback;
  119. };
  120. /**
  121. * scheduler_core_msg_dup() duplicate the given scheduler message
  122. * @msg: the message to duplicated
  123. *
  124. * Note: Duplicated messages must be freed using scheduler_core_msg_free().
  125. *
  126. * Return: pointer to the duplicated message
  127. */
  128. struct scheduler_msg *scheduler_core_msg_dup(struct scheduler_msg *msg);
  129. /**
  130. * scheduler_core_msg_free() - free the given scheduler message
  131. * @msg: the duplicated message to free
  132. *
  133. * Return: None
  134. */
  135. void scheduler_core_msg_free(struct scheduler_msg *msg);
  136. /**
  137. * scheduler_get_context() - to get scheduler context
  138. *
  139. * This routine is used retrieve scheduler context
  140. *
  141. * Return: Pointer to scheduler context
  142. */
  143. struct scheduler_ctx *scheduler_get_context(void);
  144. /**
  145. * scheduler_thread() - spawned thread will execute this routine
  146. * @arg: pointer to scheduler context
  147. *
  148. * Newly created thread will use this routine to perform its duty
  149. *
  150. * Return: none
  151. */
  152. int scheduler_thread(void *arg);
  153. /**
  154. * scheduler_create_ctx() - to create scheduler context
  155. *
  156. * This routine is used to create scheduler context
  157. *
  158. * Return: QDF_STATUS based on success or failure
  159. */
  160. QDF_STATUS scheduler_create_ctx(void);
  161. /**
  162. * scheduler_destroy_ctx() - to destroy scheduler context
  163. *
  164. * This routine is used to destroy scheduler context
  165. *
  166. * Return: QDF_STATUS based on success or failure
  167. */
  168. QDF_STATUS scheduler_destroy_ctx(void);
  169. /**
  170. * scheduler_mq_put() - put message in the back of queue
  171. * @msg_q: Pointer to the message queue
  172. * @msg: the message to enqueue
  173. *
  174. * This function is used to put message in back of provided message
  175. * queue
  176. *
  177. * Return: none
  178. */
  179. void scheduler_mq_put(struct scheduler_mq_type *msg_q,
  180. struct scheduler_msg *msg);
  181. /**
  182. * scheduler_mq_put_front() - put message in the front of queue
  183. * @msg_q: Pointer to the message queue
  184. * @msg: the message to enqueue
  185. *
  186. * This function is used to put message in front of provided message
  187. * queue
  188. *
  189. * Return: none
  190. */
  191. void scheduler_mq_put_front(struct scheduler_mq_type *msg_q,
  192. struct scheduler_msg *msg);
  193. /**
  194. * scheduler_mq_get() - to get message from message queue
  195. * @msg_q: Pointer to the message queue
  196. *
  197. * This function is used to get message from given message queue
  198. *
  199. * Return: none
  200. */
  201. struct scheduler_msg *scheduler_mq_get(struct scheduler_mq_type *msg_q);
  202. /**
  203. * scheduler_queues_init() - to initialize all the modules' queues
  204. * @sched_ctx: pointer to scheduler context
  205. *
  206. * This function is used to initialize the queues for all the modules
  207. *
  208. * Return: QDF_STATUS based on success of failure
  209. */
  210. QDF_STATUS scheduler_queues_init(struct scheduler_ctx *sched_ctx);
  211. /**
  212. * scheduler_queues_deinit() - to de-initialize all the modules' queues
  213. * @sched_ctx: pointer to scheduler context
  214. *
  215. * This function is used to de-initialize the queues for all the modules
  216. *
  217. * Return: QDF_STATUS based on success of failure
  218. */
  219. QDF_STATUS scheduler_queues_deinit(struct scheduler_ctx *gp_sch_ctx);
  220. /**
  221. * scheduler_queues_flush() - flush all of the scheduler queues
  222. * @sch_ctx: pointer to scheduler context
  223. *
  224. * This routine is used to clean the module's queues
  225. *
  226. * Return: none
  227. */
  228. void scheduler_queues_flush(struct scheduler_ctx *sched_ctx);
  229. #endif