scheduler_core.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /*
  2. * Copyright (c) 2014-2021 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for
  6. * any purpose with or without fee is hereby granted, provided that the
  7. * above copyright notice and this permission notice appear in all
  8. * copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  11. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  12. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  13. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  14. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  15. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  16. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  17. * PERFORMANCE OF THIS SOFTWARE.
  18. */
  19. #if !defined(__SCHEDULER_CORE_H)
  20. #define __SCHEDULER_CORE_H
  21. #include <qdf_threads.h>
  22. #include <qdf_timer.h>
  23. #include <scheduler_api.h>
  24. #include <qdf_list.h>
  25. #ifndef SCHEDULER_CORE_MAX_MESSAGES
  26. #define SCHEDULER_CORE_MAX_MESSAGES 4000
  27. #endif
  28. #ifndef WLAN_SCHED_REDUCTION_LIMIT
  29. #define WLAN_SCHED_REDUCTION_LIMIT 32
  30. #endif
  31. #define SCHEDULER_NUMBER_OF_MSG_QUEUE 6
  32. #define SCHEDULER_WRAPPER_MAX_FAIL_COUNT (SCHEDULER_CORE_MAX_MESSAGES * 3)
  33. #define SCHEDULER_WATCHDOG_TIMEOUT (10 * 1000) /* 10s */
  34. #ifdef CONFIG_AP_PLATFORM
  35. #define SCHED_DEBUG_PANIC(msg)
  36. #else
  37. #define SCHED_DEBUG_PANIC(msg) QDF_DEBUG_PANIC(msg)
  38. #endif
  39. #define sched_fatal(params...) \
  40. QDF_TRACE_FATAL(QDF_MODULE_ID_SCHEDULER, params)
  41. #define sched_err(params...) \
  42. QDF_TRACE_ERROR(QDF_MODULE_ID_SCHEDULER, params)
  43. #define sched_warn(params...) \
  44. QDF_TRACE_WARN(QDF_MODULE_ID_SCHEDULER, params)
  45. #define sched_info(params...) \
  46. QDF_TRACE_INFO(QDF_MODULE_ID_SCHEDULER, params)
  47. #define sched_debug(params...) \
  48. QDF_TRACE_DEBUG(QDF_MODULE_ID_SCHEDULER, params)
  49. #define sched_nofl_fatal(params...) \
  50. QDF_TRACE_FATAL_NO_FL(QDF_MODULE_ID_SCHEDULER, params)
  51. #define sched_nofl_err(params...) \
  52. QDF_TRACE_ERROR_NO_FL(QDF_MODULE_ID_SCHEDULER, params)
  53. #define sched_nofl_warn(params...) \
  54. QDF_TRACE_WARN_NO_FL(QDF_MODULE_ID_SCHEDULER, params)
  55. #define sched_nofl_info(params...) \
  56. QDF_TRACE_INFO_NO_FL(QDF_MODULE_ID_SCHEDULER, params)
  57. #define sched_nofl_debug(params...) \
  58. QDF_TRACE_DEBUG_NO_FL(QDF_MODULE_ID_SCHEDULER, params)
  59. #define sched_enter() sched_debug("Enter")
  60. #define sched_exit() sched_debug("Exit")
  61. /**
  62. * struct scheduler_mq_type - scheduler message queue
  63. * @mq_lock: message queue lock
  64. * @mq_list: message queue list
  65. * @qid: queue id
  66. */
  67. struct scheduler_mq_type {
  68. qdf_spinlock_t mq_lock;
  69. qdf_list_t mq_list;
  70. QDF_MODULE_ID qid;
  71. };
  72. /**
  73. * struct scheduler_mq_ctx - scheduler message queue context
  74. * @sch_msg_q: scheduler message queue
  75. * @scheduler_msg_qid_to_qidx: message qid to qidx mapping
  76. * @scheduler_msg_process_fn: array of message queue handler function pointers
  77. */
  78. struct scheduler_mq_ctx {
  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. * @watchdog_msg_type: 'type' of the current msg being processed
  96. * @hdd_callback: os if suspend callback
  97. * @legacy_wma_handler: legacy wma message handler
  98. * @legacy_sys_handler: legacy sys message handler
  99. * @timeout: timeout value for scheduler watchdog timer
  100. * @watchdog_timer: timer for triggering a scheduler watchdog bite
  101. * @watchdog_callback: the callback of the current msg being processed
  102. */
  103. struct scheduler_ctx {
  104. struct scheduler_mq_ctx queue_ctx;
  105. qdf_event_t sch_start_event;
  106. qdf_thread_t *sch_thread;
  107. qdf_event_t sch_shutdown;
  108. qdf_wait_queue_head_t sch_wait_queue;
  109. unsigned long sch_event_flag;
  110. qdf_event_t resume_sch_event;
  111. qdf_spinlock_t sch_thread_lock;
  112. uint8_t sch_last_qidx;
  113. uint16_t watchdog_msg_type;
  114. hdd_suspend_callback hdd_callback;
  115. scheduler_msg_process_fn_t legacy_wma_handler;
  116. scheduler_msg_process_fn_t legacy_sys_handler;
  117. uint32_t timeout;
  118. qdf_timer_t watchdog_timer;
  119. void *watchdog_callback;
  120. };
  121. /**
  122. * scheduler_core_msg_dup() - duplicate the given scheduler message
  123. * @msg: the message to duplicated
  124. *
  125. * Note: Duplicated messages must be freed using scheduler_core_msg_free().
  126. *
  127. * Return: pointer to the duplicated message
  128. */
  129. struct scheduler_msg *scheduler_core_msg_dup(struct scheduler_msg *msg);
  130. /**
  131. * scheduler_core_msg_free() - free the given scheduler message
  132. * @msg: the duplicated message to free
  133. *
  134. * Return: None
  135. */
  136. void scheduler_core_msg_free(struct scheduler_msg *msg);
  137. /**
  138. * scheduler_get_context() - to get scheduler context
  139. *
  140. * This routine is used retrieve scheduler context
  141. *
  142. * Return: Pointer to scheduler context
  143. */
  144. struct scheduler_ctx *scheduler_get_context(void);
  145. /**
  146. * scheduler_thread() - spawned thread will execute this routine
  147. * @arg: pointer to scheduler context
  148. *
  149. * Newly created thread will use this routine to perform its duty
  150. *
  151. * Return: none
  152. */
  153. int scheduler_thread(void *arg);
  154. /**
  155. * scheduler_create_ctx() - to create scheduler context
  156. *
  157. * This routine is used to create scheduler context
  158. *
  159. * Return: QDF_STATUS based on success or failure
  160. */
  161. QDF_STATUS scheduler_create_ctx(void);
  162. /**
  163. * scheduler_destroy_ctx() - to destroy scheduler context
  164. *
  165. * This routine is used to destroy scheduler context
  166. *
  167. * Return: QDF_STATUS based on success or failure
  168. */
  169. QDF_STATUS scheduler_destroy_ctx(void);
  170. /**
  171. * scheduler_mq_put() - put message in the back of queue
  172. * @msg_q: Pointer to the message queue
  173. * @msg: the message to enqueue
  174. *
  175. * This function is used to put message in back of provided message
  176. * queue
  177. *
  178. * Return: none
  179. */
  180. void scheduler_mq_put(struct scheduler_mq_type *msg_q,
  181. struct scheduler_msg *msg);
  182. /**
  183. * scheduler_mq_put_front() - put message in the front of queue
  184. * @msg_q: Pointer to the message queue
  185. * @msg: the message to enqueue
  186. *
  187. * This function is used to put message in front of provided message
  188. * queue
  189. *
  190. * Return: none
  191. */
  192. void scheduler_mq_put_front(struct scheduler_mq_type *msg_q,
  193. struct scheduler_msg *msg);
  194. /**
  195. * scheduler_mq_get() - to get message from message queue
  196. * @msg_q: Pointer to the message queue
  197. *
  198. * This function is used to get message from given message queue
  199. *
  200. * Return: none
  201. */
  202. struct scheduler_msg *scheduler_mq_get(struct scheduler_mq_type *msg_q);
  203. /**
  204. * scheduler_queues_init() - to initialize all the modules' queues
  205. * @sched_ctx: pointer to scheduler context
  206. *
  207. * This function is used to initialize the queues for all the modules
  208. *
  209. * Return: QDF_STATUS based on success of failure
  210. */
  211. QDF_STATUS scheduler_queues_init(struct scheduler_ctx *sched_ctx);
  212. /**
  213. * scheduler_queues_deinit() - to de-initialize all the modules' queues
  214. * @sched_ctx: pointer to scheduler context
  215. *
  216. * This function is used to de-initialize the queues for all the modules
  217. *
  218. * Return: QDF_STATUS based on success of failure
  219. */
  220. QDF_STATUS scheduler_queues_deinit(struct scheduler_ctx *sched_ctx);
  221. /**
  222. * scheduler_queues_flush() - flush all of the scheduler queues
  223. * @sched_ctx: pointer to scheduler context
  224. *
  225. * This routine is used to clean the module's queues
  226. *
  227. * Return: none
  228. */
  229. void scheduler_queues_flush(struct scheduler_ctx *sched_ctx);
  230. #endif