notelog_driver.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. /****************************************************************************
  2. * drivers/note/notelog_driver.c
  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. /****************************************************************************
  21. * Included Files
  22. ****************************************************************************/
  23. #include <nuttx/config.h>
  24. #include <stdarg.h>
  25. #include <stdio.h>
  26. #include <syscall.h>
  27. #include <syslog.h>
  28. #include <nuttx/sched.h>
  29. #include <nuttx/sched_note.h>
  30. /****************************************************************************
  31. * Public Functions
  32. ****************************************************************************/
  33. /****************************************************************************
  34. * Name: sched_note_start, sched_note_stop, sched_note_switch,
  35. * sched_note_premption
  36. *
  37. * Description:
  38. * Hooks to scheduler monitor
  39. *
  40. * Input Parameters:
  41. * Varies
  42. *
  43. * Returned Value:
  44. * None
  45. *
  46. ****************************************************************************/
  47. void sched_note_start(FAR struct tcb_s *tcb)
  48. {
  49. #ifdef CONFIG_SMP
  50. #if CONFIG_TASK_NAME_SIZE > 0
  51. syslog(LOG_INFO, "CPU%d: Start %s, TCB@%p, state=%d\n",
  52. tcb->cpu, tcb->name, tcb, tcb->task_state);
  53. #else
  54. syslog(LOG_INFO, "CPU%d: Start TCB@%p, state=%d\n"
  55. tcb->cpu, tcb, tcb->task_state);
  56. #endif
  57. #else
  58. #if CONFIG_TASK_NAME_SIZE > 0
  59. syslog(LOG_INFO, "Start %s, TCB@%p, state=%d\n",
  60. tcb->name, tcb, tcb->task_state);
  61. #else
  62. syslog(LOG_INFO, "Start TCB@%p, state=%d\n",
  63. tcb, tcb->task_state);
  64. #endif
  65. #endif
  66. }
  67. void sched_note_stop(FAR struct tcb_s *tcb)
  68. {
  69. #ifdef CONFIG_SMP
  70. #if CONFIG_TASK_NAME_SIZE > 0
  71. syslog(LOG_INFO, "CPU%d: Stop %s, TCB@%p, state=%d\n",
  72. tcb->cpu, tcb->name, tcb, tcb->task_state);
  73. #else
  74. syslog(LOG_INFO, "CPU%d: Stop TCB@%p, state=%d\n",
  75. tcb->cpu, tcb, tcb->task_state);
  76. #endif
  77. #else
  78. #if CONFIG_TASK_NAME_SIZE > 0
  79. syslog(LOG_INFO, "Stop %s, TCB@%p, state=%d\n",
  80. tcb->name, tcb, tcb->task_state);
  81. #else
  82. syslog(LOG_INFO, "Stop TCB@%p, state=%d\n",
  83. tcb, tcb->task_state);
  84. #endif
  85. #endif
  86. }
  87. void sched_note_suspend(FAR struct tcb_s *tcb)
  88. {
  89. #ifdef CONFIG_SMP
  90. #if CONFIG_TASK_NAME_SIZE > 0
  91. syslog(LOG_INFO, "CPU%d: Suspend %s, TCB@%p, state=%d\n",
  92. tcb->cpu, tcb->name, tcb, tcb->task_state);
  93. #else
  94. syslog(LOG_INFO, "CPU%d: Suspend TCB@%p, state=%d\n",
  95. tcb->cpu, tcb, tcb->task_state);
  96. #endif
  97. #else
  98. #if CONFIG_TASK_NAME_SIZE > 0
  99. syslog(LOG_INFO, "Suspend %s, TCB@%p, state=%d\n",
  100. tcb->name, tcb, tcb->task_state);
  101. #else
  102. syslog(LOG_INFO, "Suspend TCB@%p, state=%d\n",
  103. tcb, tcb->task_state);
  104. #endif
  105. #endif
  106. }
  107. void sched_note_resume(FAR struct tcb_s *tcb)
  108. {
  109. #ifdef CONFIG_SMP
  110. #if CONFIG_TASK_NAME_SIZE > 0
  111. syslog(LOG_INFO, "CPU%d: Resume %s, TCB@%p, state=%d\n",
  112. tcb->cpu, tcb->name, tcb, tcb->task_state);
  113. #else
  114. syslog(LOG_INFO, "CPU%d: Resume TCB@%p, state=%d\n",
  115. tcb->cpu, tcb, tcb->task_state);
  116. #endif
  117. #else
  118. #if CONFIG_TASK_NAME_SIZE > 0
  119. syslog(LOG_INFO, "Resume %s, TCB@%p, state=%d\n",
  120. tcb->name, tcb, tcb->task_state);
  121. #else
  122. syslog(LOG_INFO, "Resume TCB@%p, state=%d\n",
  123. tcb, tcb->task_state);
  124. #endif
  125. #endif
  126. }
  127. #ifdef CONFIG_SMP
  128. void sched_note_cpu_start(FAR struct tcb_s *tcb, int cpu)
  129. {
  130. #if CONFIG_TASK_NAME_SIZE > 0
  131. syslog(LOG_INFO, "CPU%d: Task %s TCB@%p CPU%d START\n",
  132. tcb->cpu, tcb->name, tcb, cpu);
  133. #else
  134. syslog(LOG_INFO, "CPU%d: TCB@%p CPU%d START\n",
  135. tcb->cpu, tcb, cpu);
  136. #endif
  137. }
  138. void sched_note_cpu_started(FAR struct tcb_s *tcb)
  139. {
  140. #if CONFIG_TASK_NAME_SIZE > 0
  141. syslog(LOG_INFO, "CPU%d: Task %s TCB@%p CPU%d STARTED\n",
  142. tcb->cpu, tcb->name, tcb, tcb->cpu);
  143. #else
  144. syslog(LOG_INFO, "CPU%d: TCB@%p CPU%d STARTED\n",
  145. tcb->cpu, tcb, tcb->cpu);
  146. #endif
  147. }
  148. void sched_note_cpu_pause(FAR struct tcb_s *tcb, int cpu)
  149. {
  150. #if CONFIG_TASK_NAME_SIZE > 0
  151. syslog(LOG_INFO, "CPU%d: Task %s TCB@%p CPU%d PAUSE\n",
  152. tcb->cpu, tcb->name, tcb, cpu);
  153. #else
  154. syslog(LOG_INFO, "CPU%d: TCB@%p CPU%d PAUSE\n",
  155. tcb->cpu, tcb, cpu);
  156. #endif
  157. }
  158. void sched_note_cpu_paused(FAR struct tcb_s *tcb)
  159. {
  160. #if CONFIG_TASK_NAME_SIZE > 0
  161. syslog(LOG_INFO, "CPU%d: Task %s TCB@%p CPU%d PAUSED\n",
  162. tcb->cpu, tcb->name, tcb, tcb->cpu);
  163. #else
  164. syslog(LOG_INFO, "CPU%d: TCB@%p CPU%d PAUSED\n",
  165. tcb->cpu, tcb, tcb->cpu);
  166. #endif
  167. }
  168. void sched_note_cpu_resume(FAR struct tcb_s *tcb, int cpu)
  169. {
  170. #if CONFIG_TASK_NAME_SIZE > 0
  171. syslog(LOG_INFO, "CPU%d: Task %s TCB@%p CPU%d RESUME\n",
  172. tcb->cpu, tcb->name, tcb, cpu);
  173. #else
  174. syslog(LOG_INFO, "CPU%d: TCB@%p CPU%d RESUME\n",
  175. tcb->cpu, tcb, cpu);
  176. #endif
  177. }
  178. void sched_note_cpu_resumed(FAR struct tcb_s *tcb)
  179. {
  180. #if CONFIG_TASK_NAME_SIZE > 0
  181. syslog(LOG_INFO, "CPU%d: Task %s TCB@%p CPU%d RESUMED\n",
  182. tcb->cpu, tcb->name, tcb, tcb->cpu);
  183. #else
  184. syslog(LOG_INFO, "CPU%d: TCB@%p CPU%d RESUMED\n",
  185. tcb->cpu, tcb, tcb->cpu);
  186. #endif
  187. }
  188. #endif
  189. #ifdef CONFIG_SCHED_INSTRUMENTATION_PREEMPTION
  190. /* This does not work well... it interferes with the operation of the
  191. * simulated /dev/console device which, of course, does disable preemption
  192. * and does use critical sections.
  193. */
  194. #warning CONFIG_SCHED_INSTRUMENTATION_PREEMPTION is a bad idea
  195. void sched_note_premption(FAR struct tcb_s *tcb, bool locked)
  196. {
  197. #ifdef CONFIG_SMP
  198. #if CONFIG_TASK_NAME_SIZE > 0
  199. syslog(LOG_INFO, "CPU%d: Task %s TCB@%p preemption %s\n",
  200. tcb->cpu, tcb->name, tcb, locked ? "LOCKED" : "UNLOCKED");
  201. #else
  202. syslog(LOG_INFO, "CPU%d: TCB@%p preemption %s\n",
  203. tcb->cpu, tcb, locked ? "LOCKED" : "UNLOCKED");
  204. #endif
  205. #else
  206. #if CONFIG_TASK_NAME_SIZE > 0
  207. syslog(LOG_INFO, "Task %s, TCB@%p preemption %s\n",
  208. tcb->name, tcb, locked ? "LOCKED" : "UNLOCKED");
  209. #else
  210. syslog(LOG_INFO, "TCB@%p preemption %s\n",
  211. tcb, locked ? "LOCKED" : "UNLOCKED");
  212. #endif
  213. #endif
  214. }
  215. #endif
  216. #ifdef CONFIG_SCHED_INSTRUMENTATION_CSECTION
  217. /* This does not work well... it interferes with the operation of the
  218. * simulated /dev/console device which, of course, does disable preemption
  219. * and does use critical sections.
  220. */
  221. #warning CONFIG_SCHED_INSTRUMENTATION_CSECTION is a bad idea
  222. void sched_note_csection(FAR struct tcb_s *tcb, bool enter)
  223. {
  224. #ifdef CONFIG_SMP
  225. #if CONFIG_TASK_NAME_SIZE > 0
  226. syslog(LOG_INFO, "CPU%d: Task %s TCB@%p critical section %s\n",
  227. tcb->cpu, tcb->name, tcb, enter ? "ENTER" : "LEAVE");
  228. #else
  229. syslog(LOG_INFO, "CPU%d: TCB@%p critical section %s\n",
  230. tcb->cpu, tcb, enter ? "ENTER" : "LEAVE");
  231. #endif
  232. #else
  233. #if CONFIG_TASK_NAME_SIZE > 0
  234. syslog(LOG_INFO, "Task %s, TCB@%p critical section %s\n",
  235. tcb->name, tcb, enter ? "ENTER" : "LEAVE");
  236. #else
  237. syslog(LOG_INFO, "TCB@%p critical section %s\n",
  238. tcb, enter ? "ENTER" : "LEAVE");
  239. #endif
  240. #endif
  241. }
  242. #endif
  243. #ifdef CONFIG_SCHED_INSTRUMENTATION_SPINLOCKS
  244. void sched_note_spinlock(FAR struct tcb_s *tcb,
  245. FAR volatile void *spinlock)
  246. {
  247. #ifdef CONFIG_SMP
  248. #if CONFIG_TASK_NAME_SIZE > 0
  249. syslog(LOG_INFO, "CPU%d: Task %s TCB@%p spinlock@%p LOCK\n",
  250. tcb->cpu, tcb->name, tcb, spinlock);
  251. #else
  252. syslog(LOG_INFO, "CPU%d: TCB@%p spinlock@%p LOCK\n",
  253. tcb->cpu, tcb, spinlock);
  254. #endif
  255. #else
  256. #if CONFIG_TASK_NAME_SIZE > 0
  257. syslog(LOG_INFO, "Task %s TCB@%p spinlock@%p LOCK\n",
  258. tcb->name, tcb, spinlock);
  259. #else
  260. syslog(LOG_INFO, "TCB@%p spinlock@%p LOCK\n",
  261. tcb, spinlock);
  262. #endif
  263. #endif
  264. }
  265. void sched_note_spinlocked(FAR struct tcb_s *tcb,
  266. FAR volatile void *spinlock)
  267. {
  268. #ifdef CONFIG_SMP
  269. #if CONFIG_TASK_NAME_SIZE > 0
  270. syslog(LOG_INFO, "CPU%d: Task %s TCB@%p spinlock@%p LOCKED\n",
  271. tcb->cpu, tcb->name, tcb, spinlock);
  272. #else
  273. syslog(LOG_INFO, "CPU%d: TCB@%p spinlock@%p LOCKED\n",
  274. tcb->cpu, tcb, spinlock);
  275. #endif
  276. #else
  277. #if CONFIG_TASK_NAME_SIZE > 0
  278. syslog(LOG_INFO, "Task %s TCB@%p spinlock@%p LOCKED\n",
  279. tcb->name, tcb, spinlock);
  280. #else
  281. syslog(LOG_INFO, "TCB@%p spinlock@%p LOCKED\n",
  282. tcb, spinlock);
  283. #endif
  284. #endif
  285. }
  286. void sched_note_spinunlock(FAR struct tcb_s *tcb,
  287. FAR volatile void *spinlock)
  288. {
  289. #ifdef CONFIG_SMP
  290. #if CONFIG_TASK_NAME_SIZE > 0
  291. syslog(LOG_INFO, "CPU%d: Task %s TCB@%p spinlock@%p UNLOCK\n",
  292. tcb->cpu, tcb->name, tcb, spinlock);
  293. #else
  294. syslog(LOG_INFO, "CPU%d: TCB@%p spinlock@%p UNLOCK\n",
  295. tcb->cpu, tcb, spinlock);
  296. #endif
  297. #else
  298. #if CONFIG_TASK_NAME_SIZE > 0
  299. syslog(LOG_INFO, "Task %s TCB@%p spinlock@%p UNLOCK\n",
  300. tcb->name, tcb, spinlock);
  301. #else
  302. syslog(LOG_INFO, "TCB@%p spinlock@%p UNLOCK\n",
  303. tcb, spinlock);
  304. #endif
  305. #endif
  306. }
  307. void sched_note_spinabort(FAR struct tcb_s *tcb,
  308. FAR volatile void *spinlock)
  309. {
  310. #ifdef CONFIG_SMP
  311. #if CONFIG_TASK_NAME_SIZE > 0
  312. syslog(LOG_INFO, "CPU%d: Task %s TCB@%p spinlock@%p ABORT\n",
  313. tcb->cpu, tcb->name, tcb, spinlock);
  314. #else
  315. syslog(LOG_INFO, "CPU%d: TCB@%p spinlock@%p ABORT\n",
  316. tcb->cpu, tcb, spinlock);
  317. #endif
  318. #else
  319. #if CONFIG_TASK_NAME_SIZE > 0
  320. syslog(LOG_INFO, "Task %s TCB@%p spinlock@%p ABORT\n",
  321. tcb->name, tcb, spinlock);
  322. #else
  323. syslog(LOG_INFO, "TCB@%p spinlock@%p ABORT\n",
  324. tcb, spinlock);
  325. #endif
  326. #endif
  327. }
  328. #endif
  329. #ifdef CONFIG_SCHED_INSTRUMENTATION_SYSCALL
  330. void sched_note_syscall_enter(int nr, int argc, ...)
  331. {
  332. char buf[128];
  333. FAR char *p = buf;
  334. va_list ap;
  335. va_start(ap, argc);
  336. while (argc-- > 0)
  337. {
  338. if (argc)
  339. {
  340. p += sprintf(p, "%#"PRIxPTR", ", va_arg(ap, uintptr_t));
  341. }
  342. else
  343. {
  344. p += sprintf(p, "%#"PRIxPTR, va_arg(ap, uintptr_t));
  345. }
  346. }
  347. va_end(ap);
  348. syslog(LOG_INFO, "%s@%d ENTER %s\n", g_funcnames[nr], nr, buf);
  349. }
  350. void sched_note_syscall_leave(int nr, uintptr_t result)
  351. {
  352. syslog(LOG_INFO, "%s@%d LEAVE %"PRIdPTR"\n", g_funcnames[nr], nr, result);
  353. }
  354. #endif
  355. #ifdef CONFIG_SCHED_INSTRUMENTATION_IRQHANDLER
  356. void sched_note_irqhandler(int irq, FAR void *handler, bool enter)
  357. {
  358. syslog(LOG_INFO, "IRQ%d handler@%p %s\n",
  359. irq, handler, enter ? "ENTER" : "LEAVE");
  360. }
  361. #endif