wqueue.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /****************************************************************************
  2. * sched/wqueue/wqueue.h
  3. *
  4. * Copyright (C) 2014, 2016, 2018 Gregory Nutt. All rights reserved.
  5. * Author: Gregory Nutt <gnutt@nuttx.org>
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in
  15. * the documentation and/or other materials provided with the
  16. * distribution.
  17. * 3. Neither the name NuttX nor the names of its contributors may be
  18. * used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. ****************************************************************************/
  35. #ifndef __SCHED_WQUEUE_WQUEUE_H
  36. #define __SCHED_WQUEUE_WQUEUE_H
  37. /****************************************************************************
  38. * Included Files
  39. ****************************************************************************/
  40. #include <nuttx/config.h>
  41. #include <sys/types.h>
  42. #include <stdbool.h>
  43. #include <queue.h>
  44. #include <nuttx/clock.h>
  45. #ifdef CONFIG_SCHED_WORKQUEUE
  46. /****************************************************************************
  47. * Pre-processor Definitions
  48. ****************************************************************************/
  49. /* Kernel thread names */
  50. #define HPWORKNAME "hpwork"
  51. #define LPWORKNAME "lpwork"
  52. /****************************************************************************
  53. * Public Type Definitions
  54. ****************************************************************************/
  55. /* This represents one worker */
  56. struct kworker_s
  57. {
  58. pid_t pid; /* The task ID of the worker thread */
  59. volatile bool busy; /* True: Worker is not available */
  60. };
  61. /* This structure defines the state of one kernel-mode work queue */
  62. struct kwork_wqueue_s
  63. {
  64. struct dq_queue_s q; /* The queue of pending work */
  65. struct kworker_s worker[1]; /* Describes a worker thread */
  66. };
  67. /* This structure defines the state of one high-priority work queue. This
  68. * structure must be cast-compatible with kwork_wqueue_s.
  69. */
  70. #ifdef CONFIG_SCHED_HPWORK
  71. struct hp_wqueue_s
  72. {
  73. struct dq_queue_s q; /* The queue of pending work */
  74. /* Describes each thread in the high priority queue's thread pool */
  75. struct kworker_s worker[CONFIG_SCHED_HPNTHREADS];
  76. };
  77. #endif
  78. /* This structure defines the state of one low-priority work queue. This
  79. * structure must be cast compatible with kwork_wqueue_s
  80. */
  81. #ifdef CONFIG_SCHED_LPWORK
  82. struct lp_wqueue_s
  83. {
  84. struct dq_queue_s q; /* The queue of pending work */
  85. /* Describes each thread in the low priority queue's thread pool */
  86. struct kworker_s worker[CONFIG_SCHED_LPNTHREADS];
  87. };
  88. #endif
  89. /****************************************************************************
  90. * Public Data
  91. ****************************************************************************/
  92. #ifdef CONFIG_SCHED_HPWORK
  93. /* The state of the kernel mode, high priority work queue. */
  94. extern struct hp_wqueue_s g_hpwork;
  95. #endif
  96. #ifdef CONFIG_SCHED_LPWORK
  97. /* The state of the kernel mode, low priority work queue(s). */
  98. extern struct lp_wqueue_s g_lpwork;
  99. #endif
  100. /****************************************************************************
  101. * Public Function Prototypes
  102. ****************************************************************************/
  103. /****************************************************************************
  104. * Name: work_hpstart
  105. *
  106. * Description:
  107. * Start the high-priority, kernel-mode work queue.
  108. *
  109. * Input Parameters:
  110. * None
  111. *
  112. * Returned Value:
  113. * The task ID of the worker thread is returned on success. A negated
  114. * errno value is returned on failure.
  115. *
  116. ****************************************************************************/
  117. #ifdef CONFIG_SCHED_HPWORK
  118. int work_hpstart(void);
  119. #endif
  120. /****************************************************************************
  121. * Name: work_lpstart
  122. *
  123. * Description:
  124. * Start the low-priority, kernel-mode worker thread(s)
  125. *
  126. * Input Parameters:
  127. * None
  128. *
  129. * Returned Value:
  130. * The task ID of the worker thread is returned on success. A negated
  131. * errno value is returned on failure.
  132. *
  133. ****************************************************************************/
  134. #ifdef CONFIG_SCHED_LPWORK
  135. int work_lpstart(void);
  136. #endif
  137. /****************************************************************************
  138. * Name: work_process
  139. *
  140. * Description:
  141. * This is the logic that performs actions placed on any work list. This
  142. * logic is the common underlying logic to all work queues. This logic is
  143. * part of the internal implementation of each work queue; it should not
  144. * be called from application level logic.
  145. *
  146. * Input Parameters:
  147. * wqueue - Describes the work queue to be processed
  148. * wndx - The worker thread index
  149. *
  150. * Returned Value:
  151. * None
  152. *
  153. ****************************************************************************/
  154. void work_process(FAR struct kwork_wqueue_s *wqueue, int wndx);
  155. /****************************************************************************
  156. * Name: work_notifier_initialize
  157. *
  158. * Description:
  159. * Set up the notification data structures for normal operation.
  160. *
  161. ****************************************************************************/
  162. #ifdef CONFIG_WQUEUE_NOTIFIER
  163. void work_notifier_initialize(void);
  164. #endif
  165. #endif /* CONFIG_SCHED_WORKQUEUE */
  166. #endif /* __SCHED_WQUEUE_WQUEUE_H */