sched_note.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. /****************************************************************************
  2. * include/nuttx/sched_note.h
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one or more
  5. * contributor license agreements. See the NOTICE file distributed with
  6. * this work for additional information regarding copyright ownership. The
  7. * ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance with the
  9. * License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. * License for the specific language governing permissions and limitations
  17. * under the License.
  18. *
  19. ****************************************************************************/
  20. #ifndef __INCLUDE_NUTTX_SCHED_NOTE_H
  21. #define __INCLUDE_NUTTX_SCHED_NOTE_H
  22. /****************************************************************************
  23. * Included Files
  24. ****************************************************************************/
  25. #include <nuttx/config.h>
  26. #include <sys/types.h>
  27. #include <stdint.h>
  28. #include <stdbool.h>
  29. #include <stdarg.h>
  30. #include <nuttx/sched.h>
  31. #ifdef CONFIG_SCHED_INSTRUMENTATION
  32. /****************************************************************************
  33. * Pre-processor Definitions
  34. ****************************************************************************/
  35. /* Provide defaults for some configuration settings (could be undefined with
  36. * old configuration files)
  37. */
  38. #ifndef CONFIG_SCHED_INSTRUMENTATION_CPUSET
  39. # define CONFIG_SCHED_INSTRUMENTATION_CPUSET 0xffff
  40. #endif
  41. /****************************************************************************
  42. * Public Types
  43. ****************************************************************************/
  44. /* This type identifies a note structure */
  45. enum note_type_e
  46. {
  47. NOTE_START = 0,
  48. NOTE_STOP = 1,
  49. NOTE_SUSPEND = 2,
  50. NOTE_RESUME = 3
  51. #ifdef CONFIG_SMP
  52. ,
  53. NOTE_CPU_START = 4,
  54. NOTE_CPU_STARTED = 5,
  55. NOTE_CPU_PAUSE = 6,
  56. NOTE_CPU_PAUSED = 7,
  57. NOTE_CPU_RESUME = 8,
  58. NOTE_CPU_RESUMED = 9
  59. #endif
  60. #ifdef CONFIG_SCHED_INSTRUMENTATION_PREEMPTION
  61. ,
  62. NOTE_PREEMPT_LOCK = 10,
  63. NOTE_PREEMPT_UNLOCK = 11
  64. #endif
  65. #ifdef CONFIG_SCHED_INSTRUMENTATION_CSECTION
  66. ,
  67. NOTE_CSECTION_ENTER = 12,
  68. NOTE_CSECTION_LEAVE = 13
  69. #endif
  70. #ifdef CONFIG_SCHED_INSTRUMENTATION_SPINLOCKS
  71. ,
  72. NOTE_SPINLOCK_LOCK = 14,
  73. NOTE_SPINLOCK_LOCKED = 15,
  74. NOTE_SPINLOCK_UNLOCK = 16,
  75. NOTE_SPINLOCK_ABORT = 17
  76. #endif
  77. #ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
  78. ,
  79. NOTE_SYSCALL_ENTER = 18,
  80. NOTE_SYSCALL_LEAVE = 19
  81. #endif
  82. #ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
  83. ,
  84. NOTE_IRQ_ENTER = 20,
  85. NOTE_IRQ_LEAVE = 21
  86. #endif
  87. };
  88. /* This structure provides the common header of each note */
  89. struct note_common_s
  90. {
  91. uint8_t nc_length; /* Length of the note */
  92. uint8_t nc_type; /* See enum note_type_e */
  93. uint8_t nc_priority; /* Thread/task priority */
  94. #ifdef CONFIG_SMP
  95. uint8_t nc_cpu; /* CPU thread/task running on */
  96. #endif
  97. uint8_t nc_pid[2]; /* ID of the thread/task */
  98. uint8_t nc_systime[4]; /* Time when note was buffered */
  99. };
  100. /* This is the specific form of the NOTE_START note */
  101. struct note_start_s
  102. {
  103. struct note_common_s nst_cmn; /* Common note parameters */
  104. #if CONFIG_TASK_NAME_SIZE > 0
  105. char nst_name[1]; /* Start of the name of the thread/task */
  106. #endif
  107. };
  108. /* This is the specific form of the NOTE_STOP note */
  109. struct note_stop_s
  110. {
  111. struct note_common_s nsp_cmn; /* Common note parameters */
  112. };
  113. /* This is the specific form of the NOTE_SUSPEND note */
  114. struct note_suspend_s
  115. {
  116. struct note_common_s nsu_cmn; /* Common note parameters */
  117. uint8_t nsu_state; /* Task state */
  118. };
  119. /* This is the specific form of the NOTE_RESUME note */
  120. struct note_resume_s
  121. {
  122. struct note_common_s nre_cmn; /* Common note parameters */
  123. };
  124. #ifdef CONFIG_SMP
  125. /* This is the specific form of the NOTE_CPU_START note */
  126. struct note_cpu_start_s
  127. {
  128. struct note_common_s ncs_cmn; /* Common note parameters */
  129. uint8_t ncs_target; /* CPU being started */
  130. };
  131. /* This is the specific form of the NOTE_CPU_STARTED note */
  132. struct note_cpu_started_s
  133. {
  134. struct note_common_s ncs_cmn; /* Common note parameters */
  135. };
  136. /* This is the specific form of the NOTE_CPU_PAUSE note */
  137. struct note_cpu_pause_s
  138. {
  139. struct note_common_s ncp_cmn; /* Common note parameters */
  140. uint8_t ncp_target; /* CPU being paused */
  141. };
  142. /* This is the specific form of the NOTE_CPU_PAUSED note */
  143. struct note_cpu_paused_s
  144. {
  145. struct note_common_s ncp_cmn; /* Common note parameters */
  146. };
  147. /* This is the specific form of the NOTE_CPU_RESUME note */
  148. struct note_cpu_resume_s
  149. {
  150. struct note_common_s ncr_cmn; /* Common note parameters */
  151. uint8_t ncr_target; /* CPU being resumed */
  152. };
  153. /* This is the specific form of the NOTE_CPU_RESUMED note */
  154. struct note_cpu_resumed_s
  155. {
  156. struct note_common_s ncr_cmn; /* Common note parameters */
  157. };
  158. #endif
  159. #ifdef CONFIG_SCHED_INSTRUMENTATION_PREEMPTION
  160. /* This is the specific form of the NOTE_PREEMPT_LOCK/UNLOCK note */
  161. struct note_preempt_s
  162. {
  163. struct note_common_s npr_cmn; /* Common note parameters */
  164. uint8_t npr_count[2]; /* Count of nested locks */
  165. };
  166. #endif /* CONFIG_SCHED_INSTRUMENTATION_PREEMPTION */
  167. #ifdef CONFIG_SCHED_INSTRUMENTATION_CSECTION
  168. /* This is the specific form of the NOTE_CSECTION_ENTER/LEAVE note */
  169. struct note_csection_s
  170. {
  171. struct note_common_s ncs_cmn; /* Common note parameters */
  172. #ifdef CONFIG_SMP
  173. uint8_t ncs_count[2]; /* Count of nested csections */
  174. #endif
  175. };
  176. #endif /* CONFIG_SCHED_INSTRUMENTATION_CSECTION */
  177. #ifdef CONFIG_SCHED_INSTRUMENTATION_SPINLOCKS
  178. /* This is the specific form of the NOTE_SPINLOCK_LOCK/LOCKED/UNLOCK/ABORT
  179. * note.
  180. */
  181. struct note_spinlock_s
  182. {
  183. struct note_common_s nsp_cmn; /* Common note parameters */
  184. FAR void *nsp_spinlock; /* Address of spinlock */
  185. uint8_t nsp_value; /* Value of spinlock */
  186. };
  187. #endif /* CONFIG_SCHED_INSTRUMENTATION_SPINLOCKS */
  188. #ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
  189. /* This is the specific form of the NOTE_SYSCALL_ENTER/LEAVE notes */
  190. struct note_syscall_enter_s
  191. {
  192. struct note_common_s nsc_cmn; /* Common note parameters */
  193. uint8_t nsc_nr; /* System call number */
  194. };
  195. struct note_syscall_leave_s
  196. {
  197. struct note_common_s nsc_cmn; /* Common note parameters */
  198. uintptr_t nsc_result; /* Result of the system call */
  199. uint8_t nsc_nr; /* System call number */
  200. };
  201. #endif /* CONFIG_SCHED_INSTRUMENTATION_SYSCALL */
  202. #ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
  203. /* This is the specific form of the NOTE_IRQ_ENTER/LEAVE notes */
  204. struct note_irqhandler_s
  205. {
  206. struct note_common_s nih_cmn; /* Common note parameters */
  207. uint8_t nih_irq; /* IRQ number */
  208. };
  209. #endif /* CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER */
  210. /****************************************************************************
  211. * Public Function Prototypes
  212. ****************************************************************************/
  213. /****************************************************************************
  214. * Name: sched_note_*
  215. *
  216. * Description:
  217. * If instrumentation of the scheduler is enabled, then some outboard
  218. * logic must provide the following interfaces. These interfaces are not
  219. * available to application code.
  220. *
  221. * Input Parameters:
  222. * tcb - The TCB of the thread.
  223. *
  224. * Returned Value:
  225. * None
  226. *
  227. ****************************************************************************/
  228. void sched_note_start(FAR struct tcb_s *tcb);
  229. void sched_note_stop(FAR struct tcb_s *tcb);
  230. void sched_note_suspend(FAR struct tcb_s *tcb);
  231. void sched_note_resume(FAR struct tcb_s *tcb);
  232. #ifdef CONFIG_SMP
  233. void sched_note_cpu_start(FAR struct tcb_s *tcb, int cpu);
  234. void sched_note_cpu_started(FAR struct tcb_s *tcb);
  235. void sched_note_cpu_pause(FAR struct tcb_s *tcb, int cpu);
  236. void sched_note_cpu_paused(FAR struct tcb_s *tcb);
  237. void sched_note_cpu_resume(FAR struct tcb_s *tcb, int cpu);
  238. void sched_note_cpu_resumed(FAR struct tcb_s *tcb);
  239. #else
  240. # define sched_note_cpu_start(t,c)
  241. # define sched_note_cpu_started(t)
  242. # define sched_note_cpu_pause(t,c)
  243. # define sched_note_cpu_paused(t)
  244. # define sched_note_cpu_resume(t,c)
  245. # define sched_note_cpu_resumed(t)
  246. #endif
  247. #ifdef CONFIG_SCHED_INSTRUMENTATION_PREEMPTION
  248. void sched_note_premption(FAR struct tcb_s *tcb, bool locked);
  249. #else
  250. # define sched_note_premption(t,l)
  251. #endif
  252. #ifdef CONFIG_SCHED_INSTRUMENTATION_CSECTION
  253. void sched_note_csection(FAR struct tcb_s *tcb, bool enter);
  254. #else
  255. # define sched_note_csection(t,e)
  256. #endif
  257. #ifdef CONFIG_SCHED_INSTRUMENTATION_SPINLOCKS
  258. void sched_note_spinlock(FAR struct tcb_s *tcb,
  259. FAR volatile void *spinlock);
  260. void sched_note_spinlocked(FAR struct tcb_s *tcb,
  261. FAR volatile void *spinlock);
  262. void sched_note_spinunlock(FAR struct tcb_s *tcb,
  263. FAR volatile void *spinlock);
  264. void sched_note_spinabort(FAR struct tcb_s *tcb,
  265. FAR volatile void *spinlock);
  266. #else
  267. # define sched_note_spinlock(t,s)
  268. # define sched_note_spinlocked(t,s)
  269. # define sched_note_spinunlock(t,s)
  270. # define sched_note_spinabort(t,s)
  271. #endif
  272. #ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
  273. void sched_note_syscall_enter(int nr, int argc, ...);
  274. void sched_note_syscall_leave(int nr, uintptr_t result);
  275. #else
  276. # define sched_note_syscall_enter(n,a...)
  277. # define sched_note_syscall_leave(n,r)
  278. #endif
  279. #ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
  280. void sched_note_irqhandler(int irq, FAR void *handler, bool enter);
  281. #else
  282. # define sched_note_irqhandler(i,h,e)
  283. #endif
  284. /****************************************************************************
  285. * Name: note_add
  286. *
  287. * Description:
  288. * Add the variable length note to the transport layer
  289. *
  290. * Input Parameters:
  291. * note - The note buffer
  292. * notelen - The buffer length
  293. *
  294. * Returned Value:
  295. * None
  296. *
  297. * Assumptions:
  298. * We are within a critical section.
  299. *
  300. ****************************************************************************/
  301. void note_add(FAR const uint8_t *note, uint8_t notelen);
  302. #else /* CONFIG_SCHED_INSTRUMENTATION */
  303. # define sched_note_start(t)
  304. # define sched_note_stop(t)
  305. # define sched_note_suspend(t)
  306. # define sched_note_resume(t)
  307. # define sched_note_cpu_start(t,c)
  308. # define sched_note_cpu_started(t)
  309. # define sched_note_cpu_pause(t,c)
  310. # define sched_note_cpu_paused(t)
  311. # define sched_note_cpu_resume(t,c)
  312. # define sched_note_cpu_resumed(t)
  313. # define sched_note_premption(t,l)
  314. # define sched_note_csection(t,e)
  315. # define sched_note_spinlock(t,s)
  316. # define sched_note_spinlocked(t,s)
  317. # define sched_note_spinunlock(t,s)
  318. # define sched_note_spinabort(t,s)
  319. # define sched_note_syscall_enter(n,a...)
  320. # define sched_note_syscall_leave(n,r)
  321. # define sched_note_irqhandler(i,h,e)
  322. #endif /* CONFIG_SCHED_INSTRUMENTATION */
  323. #endif /* __INCLUDE_NUTTX_SCHED_NOTE_H */