scheduler_core.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. #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. #define __sched_log(level, format, args...) \
  34. QDF_TRACE(QDF_MODULE_ID_SCHEDULER, level, FL(format), ## args)
  35. #define sched_fatal(format, args...) \
  36. __sched_log(QDF_TRACE_LEVEL_FATAL, format, ## args)
  37. #define sched_err(format, args...) \
  38. __sched_log(QDF_TRACE_LEVEL_ERROR, format, ## args)
  39. #define sched_warn(format, args...) \
  40. __sched_log(QDF_TRACE_LEVEL_WARN, format, ## args)
  41. #define sched_info(format, args...) \
  42. __sched_log(QDF_TRACE_LEVEL_INFO, format, ## args)
  43. #define sched_debug(format, args...) \
  44. __sched_log(QDF_TRACE_LEVEL_DEBUG, format, ## args)
  45. #define sched_enter() sched_debug("Enter")
  46. #define sched_exit() sched_debug("Exit")
  47. /**
  48. * struct scheduler_mq_type - scheduler message queue
  49. * @mq_lock: message queue lock
  50. * @mq_list: message queue list
  51. * @qid: queue id
  52. */
  53. struct scheduler_mq_type {
  54. qdf_spinlock_t mq_lock;
  55. qdf_list_t mq_list;
  56. QDF_MODULE_ID qid;
  57. };
  58. /**
  59. * struct scheduler_mq_ctx - scheduler message queue context
  60. * @sch_msg_q: scheduler message queue
  61. * @scheduler_msg_qid_to_qidx: message qid to qidx mapping
  62. * @scheduler_msg_process_fn: array of message queue handler function pointers
  63. */
  64. struct scheduler_mq_ctx {
  65. struct scheduler_mq_type sch_msg_q[SCHEDULER_NUMBER_OF_MSG_QUEUE];
  66. uint8_t scheduler_msg_qid_to_qidx[QDF_MODULE_ID_MAX];
  67. QDF_STATUS (*scheduler_msg_process_fn[SCHEDULER_NUMBER_OF_MSG_QUEUE])
  68. (struct scheduler_msg *msg);
  69. };
  70. /**
  71. * struct scheduler_ctx - scheduler context
  72. * @queue_ctx: message queue context
  73. * @sch_start_event: scheduler thread start wait event
  74. * @sch_thread: scheduler thread
  75. * @sch_shutdown: scheduler thread shutdown wait event
  76. * @sch_wait_queue: scheduler wait queue
  77. * @sch_event_flag: scheduler events flag
  78. * @resume_sch_event: scheduler resume wait event
  79. * @sch_thread_lock: scheduler thread lock
  80. * @sch_last_qidx: scheduler last qidx allocation
  81. * @hdd_callback: os if suspend callback
  82. * @legacy_wma_handler: legacy wma message handler
  83. * @legacy_sys_handler: legacy sys message handler
  84. * @watchdog_timer: timer for triggering a scheduler watchdog bite
  85. * @watchdog_msg_type: 'type' of the current msg being processed
  86. * @watchdog_callback: the callback of the current msg being processed
  87. */
  88. struct scheduler_ctx {
  89. struct scheduler_mq_ctx queue_ctx;
  90. qdf_event_t sch_start_event;
  91. qdf_thread_t *sch_thread;
  92. qdf_event_t sch_shutdown;
  93. qdf_wait_queue_head_t sch_wait_queue;
  94. unsigned long sch_event_flag;
  95. qdf_event_t resume_sch_event;
  96. qdf_spinlock_t sch_thread_lock;
  97. uint8_t sch_last_qidx;
  98. hdd_suspend_callback hdd_callback;
  99. scheduler_msg_process_fn_t legacy_wma_handler;
  100. scheduler_msg_process_fn_t legacy_sys_handler;
  101. qdf_timer_t watchdog_timer;
  102. uint16_t watchdog_msg_type;
  103. void *watchdog_callback;
  104. };
  105. /**
  106. * scheduler_core_msg_dup() duplicate the given scheduler message
  107. * @msg: the message to duplicated
  108. *
  109. * Note: Duplicated messages must be freed using scheduler_core_msg_free().
  110. *
  111. * Return: pointer to the duplicated message
  112. */
  113. struct scheduler_msg *scheduler_core_msg_dup(struct scheduler_msg *msg);
  114. /**
  115. * scheduler_core_msg_free() - free the given scheduler message
  116. * @msg: the duplicated message to free
  117. *
  118. * Return: None
  119. */
  120. void scheduler_core_msg_free(struct scheduler_msg *msg);
  121. /**
  122. * scheduler_get_context() - to get scheduler context
  123. *
  124. * This routine is used retrieve scheduler context
  125. *
  126. * Return: Pointer to scheduler context
  127. */
  128. struct scheduler_ctx *scheduler_get_context(void);
  129. /**
  130. * scheduler_thread() - spawned thread will execute this routine
  131. * @arg: pointer to scheduler context
  132. *
  133. * Newly created thread will use this routine to perform its duty
  134. *
  135. * Return: none
  136. */
  137. int scheduler_thread(void *arg);
  138. /**
  139. * scheduler_create_ctx() - to create scheduler context
  140. *
  141. * This routine is used to create scheduler context
  142. *
  143. * Return: QDF_STATUS based on success or failure
  144. */
  145. QDF_STATUS scheduler_create_ctx(void);
  146. /**
  147. * scheduler_destroy_ctx() - to destroy scheduler context
  148. *
  149. * This routine is used to destroy scheduler context
  150. *
  151. * Return: QDF_STATUS based on success or failure
  152. */
  153. QDF_STATUS scheduler_destroy_ctx(void);
  154. /**
  155. * scheduler_mq_put() - put message in the back of queue
  156. * @msg_q: Pointer to the message queue
  157. * @msg: the message to enqueue
  158. *
  159. * This function is used to put message in back of provided message
  160. * queue
  161. *
  162. * Return: none
  163. */
  164. void scheduler_mq_put(struct scheduler_mq_type *msg_q,
  165. struct scheduler_msg *msg);
  166. /**
  167. * scheduler_mq_put_front() - put message in the front of queue
  168. * @msg_q: Pointer to the message queue
  169. * @msg: the message to enqueue
  170. *
  171. * This function is used to put message in front of provided message
  172. * queue
  173. *
  174. * Return: none
  175. */
  176. void scheduler_mq_put_front(struct scheduler_mq_type *msg_q,
  177. struct scheduler_msg *msg);
  178. /**
  179. * scheduler_mq_get() - to get message from message queue
  180. * @msg_q: Pointer to the message queue
  181. *
  182. * This function is used to get message from given message queue
  183. *
  184. * Return: none
  185. */
  186. struct scheduler_msg *scheduler_mq_get(struct scheduler_mq_type *msg_q);
  187. /**
  188. * scheduler_queues_init() - to initialize all the modules' queues
  189. * @sched_ctx: pointer to scheduler context
  190. *
  191. * This function is used to initialize the queues for all the modules
  192. *
  193. * Return: QDF_STATUS based on success of failure
  194. */
  195. QDF_STATUS scheduler_queues_init(struct scheduler_ctx *sched_ctx);
  196. /**
  197. * scheduler_queues_deinit() - to de-initialize all the modules' queues
  198. * @sched_ctx: pointer to scheduler context
  199. *
  200. * This function is used to de-initialize the queues for all the modules
  201. *
  202. * Return: QDF_STATUS based on success of failure
  203. */
  204. QDF_STATUS scheduler_queues_deinit(struct scheduler_ctx *gp_sch_ctx);
  205. /**
  206. * scheduler_queues_flush() - flush all of the scheduler queues
  207. * @sch_ctx: pointer to scheduler context
  208. *
  209. * This routine is used to clean the module's queues
  210. *
  211. * Return: none
  212. */
  213. void scheduler_queues_flush(struct scheduler_ctx *sched_ctx);
  214. #endif