qdf_threads.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. /*
  2. * Copyright (c) 2014-2021 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2022-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. /**
  20. * DOC: qdf_threads
  21. * QCA driver framework (QDF) thread related APIs
  22. */
  23. #if !defined(__QDF_THREADS_H)
  24. #define __QDF_THREADS_H
  25. #include <qdf_types.h>
  26. #include "i_qdf_threads.h"
  27. typedef __qdf_thread_t qdf_thread_t;
  28. typedef QDF_STATUS (*qdf_thread_func)(void *context);
  29. /* Function declarations and documentation */
  30. void qdf_sleep(uint32_t ms_interval);
  31. void qdf_sleep_us(uint32_t us_interval);
  32. void qdf_busy_wait(uint32_t us_interval);
  33. /**
  34. * qdf_set_wake_up_idle() - set wakeup idle value
  35. * @idle: true/false value for wake up idle
  36. *
  37. * Return: none
  38. */
  39. void qdf_set_wake_up_idle(bool idle);
  40. /**
  41. * qdf_set_user_nice() - set thread's nice value
  42. * @thread: pointer to thread
  43. * @nice: nice value
  44. *
  45. * Return: void
  46. */
  47. void qdf_set_user_nice(qdf_thread_t *thread, long nice);
  48. /**
  49. * qdf_create_thread() - create a kernel thread
  50. * @thread_handler: pointer to thread handler
  51. * @data: data
  52. * @thread_name: thread name
  53. *
  54. * Return: pointer to created kernel thread on success else NULL
  55. */
  56. qdf_thread_t *qdf_create_thread(int (*thread_handler)(void *data), void *data,
  57. const char thread_name[]);
  58. /**
  59. * qdf_thread_run() - run the given function in a new thread
  60. *
  61. * You must call qdf_thread_join() to avoid a reasource leak!
  62. * For more flexibility, use qdf_create_thread() instead.
  63. * @callback: callback function
  64. * @context: context
  65. *
  66. * Return: a new qdf_thread pointer
  67. */
  68. qdf_thread_t *qdf_thread_run(qdf_thread_func callback, void *context);
  69. /**
  70. * qdf_thread_join() - signal and wait for a thread to stop
  71. * @thread: pointer to thread
  72. *
  73. * This sets a flag that the given thread can check to see if it should exit.
  74. * The thread can check to see if this flag has been set by calling
  75. * qdf_thread_should_stop().
  76. *
  77. * Return: QDF_STATUS - the return value from the thread function
  78. */
  79. QDF_STATUS qdf_thread_join(qdf_thread_t *thread);
  80. /**
  81. * qdf_thread_should_stop() - true if the current thread was signalled to stop
  82. *
  83. * If qdf_thread_join() has been called on the current thread, this API returns
  84. * true. Otherwise, this returns false.
  85. *
  86. * Return: true if the current thread should stop
  87. */
  88. bool qdf_thread_should_stop(void);
  89. /**
  90. * qdf_wake_up_process() - wake up given thread
  91. * @thread: pointer to thread which needs to be woken up
  92. *
  93. * Return: none
  94. */
  95. int qdf_wake_up_process(qdf_thread_t *thread);
  96. /**
  97. * qdf_print_thread_trace() - prints the stack trace of the given thread
  98. * @thread: the thread for which the stack trace will be printed
  99. *
  100. * Return: None
  101. */
  102. void qdf_print_thread_trace(qdf_thread_t *thread);
  103. /**
  104. * qdf_get_current_task() - get current task struct
  105. *
  106. * Return: pointer to task struct
  107. */
  108. qdf_thread_t *qdf_get_current_task(void);
  109. /**
  110. * qdf_get_current_pid() - get current task's process id
  111. *
  112. * Return: current task's process id (int)
  113. */
  114. int qdf_get_current_pid(void);
  115. /**
  116. * qdf_get_current_comm() - get current task's command name
  117. *
  118. * Return: current task's command name(char *)
  119. */
  120. const char *qdf_get_current_comm(void);
  121. /**
  122. * qdf_thread_set_cpus_allowed_mask() - set cpu mask for a particular thread
  123. * @thread: thread for which new cpu mask is set
  124. * @new_mask: new cpu mask to be set for the thread
  125. *
  126. * Return: None
  127. */
  128. void
  129. qdf_thread_set_cpus_allowed_mask(qdf_thread_t *thread, qdf_cpu_mask *new_mask);
  130. /**
  131. * qdf_cpumask_clear() - clear all cpus in a cpumask
  132. * @dstp: cpumask pointer
  133. *
  134. * Return: None
  135. */
  136. void qdf_cpumask_clear(qdf_cpu_mask *dstp);
  137. /**
  138. * qdf_cpumask_set_cpu() - set a cpu in a cpumask
  139. * @cpu: cpu number
  140. * @dstp: cpumask pointer
  141. *
  142. * Return: None
  143. */
  144. void qdf_cpumask_set_cpu(unsigned int cpu, qdf_cpu_mask *dstp);
  145. /**
  146. * qdf_cpumask_setall - set all cpus
  147. * @dstp: cpumask pointer
  148. *
  149. * Return: None
  150. */
  151. void qdf_cpumask_setall(qdf_cpu_mask *dstp);
  152. /**
  153. * qdf_cpumask_clear_cpu() - clear a cpu in a cpumask
  154. * @cpu: cpu number
  155. * @dstp: cpumask pointer
  156. *
  157. * Return: None
  158. */
  159. void qdf_cpumask_clear_cpu(unsigned int cpu, qdf_cpu_mask *dstp);
  160. /**
  161. * qdf_cpumask_empty - Check if cpu_mask is empty
  162. * @srcp: cpumask pointer
  163. *
  164. * Return: true or false
  165. *
  166. */
  167. bool qdf_cpumask_empty(const qdf_cpu_mask *srcp);
  168. /**
  169. * qdf_cpumask_copy - Copy srcp cpumask to dstp
  170. * @srcp: source cpumask pointer
  171. * @dstp: destination cpumask pointer
  172. *
  173. * Return: None
  174. *
  175. */
  176. void qdf_cpumask_copy(qdf_cpu_mask *dstp,
  177. const qdf_cpu_mask *srcp);
  178. /**
  179. * qdf_cpumask_or - set *dstp = *src1p | *src2p
  180. * @dstp: the cpumask result
  181. * @src1p: the first input
  182. * @src2p: the second input
  183. *
  184. * Return: None
  185. */
  186. void qdf_cpumask_or(qdf_cpu_mask *dstp, qdf_cpu_mask *src1p,
  187. qdf_cpu_mask *src2p);
  188. /**
  189. * qdf_thread_cpumap_print_to_pagebuf - copies the cpumask into the buffer
  190. * either as comma-separated list of cpus or hex values of cpumask
  191. * @list: indicates whether the cpumap is list or not
  192. * @new_mask: the cpumask to copy
  193. * @new_mask_str: the buffer to copy into
  194. *
  195. * This functions copies the cpu mask set for the thread by
  196. * qdf_thread_set_cpus_allowed_mask() to new_mask_str
  197. *
  198. * Return: None
  199. */
  200. void
  201. qdf_thread_cpumap_print_to_pagebuf(bool list, char *new_mask_str,
  202. qdf_cpu_mask *new_mask);
  203. /**
  204. * qdf_cpumask_and - *dstp = *src1p & *src2p
  205. * @dstp: the cpumask result
  206. * @src1p: the first input
  207. * @src2p: the second input
  208. *
  209. * Return: If *@dstp is empty, returns false, else returns true
  210. */
  211. bool
  212. qdf_cpumask_and(qdf_cpu_mask *dstp, const qdf_cpu_mask *src1p,
  213. const qdf_cpu_mask *src2p);
  214. /**
  215. * qdf_cpumask_andnot - *dstp = *src1p & ~*src2p
  216. * @dstp: the cpumask result
  217. * @src1p: the first input
  218. * @src2p: the second input
  219. *
  220. * Return: If *@dstp is empty, returns false, else returns true
  221. */
  222. bool
  223. qdf_cpumask_andnot(qdf_cpu_mask *dstp, const qdf_cpu_mask *src1p,
  224. const qdf_cpu_mask *src2p);
  225. /**
  226. * qdf_cpumask_equal - *src1p == *src2p
  227. * @src1p: the first input
  228. * @src2p: the second input
  229. *
  230. * Return: If *@src1p == *@src2p return true, else return false
  231. */
  232. bool
  233. qdf_cpumask_equal(const qdf_cpu_mask *src1p, const qdf_cpu_mask *src2p);
  234. /**
  235. * qdf_cpumask_complement - *dstp = ~*srcp
  236. * @dstp: the cpumask result
  237. * @srcp: the input to invert
  238. *
  239. * Return: None
  240. */
  241. void
  242. qdf_cpumask_complement(qdf_cpu_mask *dstp, const qdf_cpu_mask *srcp);
  243. #if defined(WALT_GET_CPU_TAKEN_SUPPORT) && IS_ENABLED(CONFIG_SCHED_WALT)
  244. /**
  245. * qdf_walt_get_cpus_taken - Get taken CPUs
  246. *
  247. * Return: Taken CPUs
  248. */
  249. qdf_cpu_mask qdf_walt_get_cpus_taken(void);
  250. /*
  251. * qdf_walt_get_cpus_taken_supported: walt_get_cpus_taken supported
  252. *
  253. * Return: true if walt_get_cpus_taken API is supported
  254. */
  255. static inline bool
  256. qdf_walt_get_cpus_taken_supported(void)
  257. {
  258. return true;
  259. }
  260. #else
  261. static inline
  262. qdf_cpu_mask qdf_walt_get_cpus_taken(void)
  263. {
  264. qdf_cpu_mask mask;
  265. qdf_cpumask_clear(&mask);
  266. return mask;
  267. }
  268. static inline bool
  269. qdf_walt_get_cpus_taken_supported(void)
  270. {
  271. return false;
  272. }
  273. #endif
  274. #endif /* __QDF_THREADS_H */