qdf_threads.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * Copyright (c) 2014-2021 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2022 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: pointer to thread
  51. * @nice: nice value
  52. *
  53. * Return: pointer to created kernel thread on success else NULL
  54. */
  55. qdf_thread_t *qdf_create_thread(int (*thread_handler)(void *data), void *data,
  56. const char thread_name[]);
  57. /**
  58. * qdf_thread_run() - run the given function in a new thread
  59. *
  60. * You must call qdf_thread_join() to avoid a reasource leak!
  61. *
  62. * For more flexibility, use qdf_create_thread() instead.
  63. *
  64. * Return: a new qdf_thread pointer
  65. */
  66. qdf_thread_t *qdf_thread_run(qdf_thread_func callback, void *context);
  67. /**
  68. * qdf_thread_join() - signal and wait for a thread to stop
  69. *
  70. * This sets a flag that the given thread can check to see if it should exit.
  71. * The thread can check to see if this flag has been set by calling
  72. * qdf_thread_should_stop().
  73. *
  74. * Return: QDF_STATUS - the return value from the thread function
  75. */
  76. QDF_STATUS qdf_thread_join(qdf_thread_t *thread);
  77. /**
  78. * qdf_thread_should_stop() - true if the current thread was signalled to stop
  79. *
  80. * If qdf_thread_join() has been called on the current thread, this API returns
  81. * true. Otherwise, this returns false.
  82. *
  83. * Return: true if the current thread should stop
  84. */
  85. bool qdf_thread_should_stop(void);
  86. /**
  87. * qdf_wake_up_process() - wake up given thread
  88. * @thread: pointer to thread which needs to be woken up
  89. *
  90. * Return: none
  91. */
  92. int qdf_wake_up_process(qdf_thread_t *thread);
  93. /**
  94. * qdf_print_stack_trace_thread() - prints the stack trace of the given thread
  95. * @thread: the thread for which the stack trace will be printed
  96. *
  97. * Return: None
  98. */
  99. void qdf_print_thread_trace(qdf_thread_t *thread);
  100. /**
  101. * qdf_get_current_task() - get current task struct
  102. *
  103. * Return: pointer to task struct
  104. */
  105. qdf_thread_t *qdf_get_current_task(void);
  106. /**
  107. * qdf_get_current_pid() - get current task's process id
  108. *
  109. * Return: current task's process id (int)
  110. */
  111. int qdf_get_current_pid(void);
  112. /**
  113. * qdf_get_current_comm() - get current task's command name
  114. *
  115. * Return: current task's command name(char *)
  116. */
  117. const char *qdf_get_current_comm(void);
  118. /**
  119. * qdf_thread_set_cpus_allowed_mask() - set cpu mask for a particular thread
  120. * @thread: thread for which new cpu mask is set
  121. * @new_mask: new cpu mask to be set for the thread
  122. *
  123. * Return: None
  124. */
  125. void
  126. qdf_thread_set_cpus_allowed_mask(qdf_thread_t *thread, qdf_cpu_mask *new_mask);
  127. /**
  128. * qdf_cpumask_clear() - clear all cpus in a cpumask
  129. * @dstp: cpumask pointer
  130. *
  131. * Return: None
  132. */
  133. void qdf_cpumask_clear(qdf_cpu_mask *dstp);
  134. /**
  135. * qdf_cpumask_set_cpu() - set a cpu in a cpumask
  136. * @cpu: cpu number
  137. * @dstp: cpumask pointer
  138. *
  139. * Return: None
  140. */
  141. void qdf_cpumask_set_cpu(unsigned int cpu, qdf_cpu_mask *dstp);
  142. /**
  143. * qdf_cpumask_setall - set all cpus
  144. * @dstp: cpumask pointer
  145. *
  146. * Return: None
  147. */
  148. void qdf_cpumask_setall(qdf_cpu_mask *dstp);
  149. /**
  150. * qdf_cpumask_clear_cpu() - clear a cpu in a cpumask
  151. * @cpu: cpu number
  152. * @dstp: cpumask pointer
  153. *
  154. * Return: None
  155. */
  156. void qdf_cpumask_clear_cpu(unsigned int cpu, qdf_cpu_mask *dstp);
  157. /**
  158. * qdf_cpumask_empty - Check if cpu_mask is empty
  159. * @srcp: cpumask pointer
  160. *
  161. * Return: true or false
  162. *
  163. */
  164. bool qdf_cpumask_empty(const qdf_cpu_mask *srcp);
  165. /**
  166. * qdf_cpumask_copy - Copy srcp cpumask to dstp
  167. * @srcp: source cpumask pointer
  168. * @dstp: destination cpumask pointer
  169. *
  170. * Return: None
  171. *
  172. */
  173. void qdf_cpumask_copy(qdf_cpu_mask *dstp,
  174. const qdf_cpu_mask *srcp);
  175. /**
  176. * qdf_cpumask_or - set *dstp = *src1p | *src2p
  177. * @dstp: the cpumask result
  178. * @src1p: the first input
  179. * @src2p: the second input
  180. *
  181. * Return: None
  182. */
  183. void qdf_cpumask_or(qdf_cpu_mask *dstp, qdf_cpu_mask *src1p,
  184. qdf_cpu_mask *src2p);
  185. #endif /* __QDF_THREADS_H */