sched.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. #undef TRACE_SYSTEM
  2. #define TRACE_SYSTEM sched
  3. #if !defined(_TRACE_SCHED_H) || defined(TRACE_HEADER_MULTI_READ)
  4. #define _TRACE_SCHED_H
  5. #include <linux/sched.h>
  6. #include <linux/tracepoint.h>
  7. /*
  8. * Tracepoint for calling kthread_stop, performed to end a kthread:
  9. */
  10. TRACE_EVENT(sched_kthread_stop,
  11. TP_PROTO(struct task_struct *t),
  12. TP_ARGS(t),
  13. TP_STRUCT__entry(
  14. __array( char, comm, TASK_COMM_LEN )
  15. __field( pid_t, pid )
  16. ),
  17. TP_fast_assign(
  18. memcpy(__entry->comm, t->comm, TASK_COMM_LEN);
  19. __entry->pid = t->pid;
  20. ),
  21. TP_printk("comm=%s pid=%d", __entry->comm, __entry->pid)
  22. );
  23. /*
  24. * Tracepoint for the return value of the kthread stopping:
  25. */
  26. TRACE_EVENT(sched_kthread_stop_ret,
  27. TP_PROTO(int ret),
  28. TP_ARGS(ret),
  29. TP_STRUCT__entry(
  30. __field( int, ret )
  31. ),
  32. TP_fast_assign(
  33. __entry->ret = ret;
  34. ),
  35. TP_printk("ret=%d", __entry->ret)
  36. );
  37. /*
  38. * Tracepoint for waiting on task to unschedule:
  39. */
  40. TRACE_EVENT(sched_wait_task,
  41. TP_PROTO(struct task_struct *p),
  42. TP_ARGS(p),
  43. TP_STRUCT__entry(
  44. __array( char, comm, TASK_COMM_LEN )
  45. __field( pid_t, pid )
  46. __field( int, prio )
  47. ),
  48. TP_fast_assign(
  49. memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
  50. __entry->pid = p->pid;
  51. __entry->prio = p->prio;
  52. ),
  53. TP_printk("comm=%s pid=%d prio=%d",
  54. __entry->comm, __entry->pid, __entry->prio)
  55. );
  56. /*
  57. * Tracepoint for waking up a task:
  58. */
  59. DECLARE_EVENT_CLASS(sched_wakeup_template,
  60. TP_PROTO(struct task_struct *p, int success),
  61. TP_ARGS(p, success),
  62. TP_STRUCT__entry(
  63. __array( char, comm, TASK_COMM_LEN )
  64. __field( pid_t, pid )
  65. __field( int, prio )
  66. __field( int, success )
  67. __field( int, target_cpu )
  68. ),
  69. TP_fast_assign(
  70. memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
  71. __entry->pid = p->pid;
  72. __entry->prio = p->prio;
  73. __entry->success = success;
  74. __entry->target_cpu = task_cpu(p);
  75. ),
  76. TP_printk("comm=%s pid=%d prio=%d success=%d target_cpu=%03d",
  77. __entry->comm, __entry->pid, __entry->prio,
  78. __entry->success, __entry->target_cpu)
  79. );
  80. DEFINE_EVENT(sched_wakeup_template, sched_wakeup,
  81. TP_PROTO(struct task_struct *p, int success),
  82. TP_ARGS(p, success));
  83. /*
  84. * Tracepoint for waking up a new task:
  85. */
  86. DEFINE_EVENT(sched_wakeup_template, sched_wakeup_new,
  87. TP_PROTO(struct task_struct *p, int success),
  88. TP_ARGS(p, success));
  89. /*
  90. * Tracepoint for task switches, performed by the scheduler:
  91. */
  92. TRACE_EVENT(sched_switch,
  93. TP_PROTO(struct task_struct *prev,
  94. struct task_struct *next),
  95. TP_ARGS(prev, next),
  96. TP_STRUCT__entry(
  97. __array( char, prev_comm, TASK_COMM_LEN )
  98. __field( pid_t, prev_pid )
  99. __field( int, prev_prio )
  100. __field( long, prev_state )
  101. __array( char, next_comm, TASK_COMM_LEN )
  102. __field( pid_t, next_pid )
  103. __field( int, next_prio )
  104. ),
  105. TP_fast_assign(
  106. memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN);
  107. __entry->prev_pid = prev->pid;
  108. __entry->prev_prio = prev->prio;
  109. __entry->prev_state = prev->state;
  110. memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN);
  111. __entry->next_pid = next->pid;
  112. __entry->next_prio = next->prio;
  113. ),
  114. TP_printk("prev_comm=%s prev_pid=%d prev_prio=%d prev_state=%s ==> next_comm=%s next_pid=%d next_prio=%d",
  115. __entry->prev_comm, __entry->prev_pid, __entry->prev_prio,
  116. __entry->prev_state ?
  117. __print_flags(__entry->prev_state, "|",
  118. { 1, "S"} , { 2, "D" }, { 4, "T" }, { 8, "t" },
  119. { 16, "Z" }, { 32, "X" }, { 64, "x" },
  120. { 128, "W" }) : "R",
  121. __entry->next_comm, __entry->next_pid, __entry->next_prio)
  122. );
  123. /*
  124. * Tracepoint for a task being migrated:
  125. */
  126. TRACE_EVENT(sched_migrate_task,
  127. TP_PROTO(struct task_struct *p, int dest_cpu),
  128. TP_ARGS(p, dest_cpu),
  129. TP_STRUCT__entry(
  130. __array( char, comm, TASK_COMM_LEN )
  131. __field( pid_t, pid )
  132. __field( int, prio )
  133. __field( int, orig_cpu )
  134. __field( int, dest_cpu )
  135. ),
  136. TP_fast_assign(
  137. memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
  138. __entry->pid = p->pid;
  139. __entry->prio = p->prio;
  140. __entry->orig_cpu = task_cpu(p);
  141. __entry->dest_cpu = dest_cpu;
  142. ),
  143. TP_printk("comm=%s pid=%d prio=%d orig_cpu=%d dest_cpu=%d",
  144. __entry->comm, __entry->pid, __entry->prio,
  145. __entry->orig_cpu, __entry->dest_cpu)
  146. );
  147. DECLARE_EVENT_CLASS(sched_process_template,
  148. TP_PROTO(struct task_struct *p),
  149. TP_ARGS(p),
  150. TP_STRUCT__entry(
  151. __array( char, comm, TASK_COMM_LEN )
  152. __field( pid_t, pid )
  153. __field( int, prio )
  154. ),
  155. TP_fast_assign(
  156. memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
  157. __entry->pid = p->pid;
  158. __entry->prio = p->prio;
  159. ),
  160. TP_printk("comm=%s pid=%d prio=%d",
  161. __entry->comm, __entry->pid, __entry->prio)
  162. );
  163. /*
  164. * Tracepoint for freeing a task:
  165. */
  166. DEFINE_EVENT(sched_process_template, sched_process_free,
  167. TP_PROTO(struct task_struct *p),
  168. TP_ARGS(p));
  169. /*
  170. * Tracepoint for a task exiting:
  171. */
  172. DEFINE_EVENT(sched_process_template, sched_process_exit,
  173. TP_PROTO(struct task_struct *p),
  174. TP_ARGS(p));
  175. /*
  176. * Tracepoint for a waiting task:
  177. */
  178. TRACE_EVENT(sched_process_wait,
  179. TP_PROTO(struct pid *pid),
  180. TP_ARGS(pid),
  181. TP_STRUCT__entry(
  182. __array( char, comm, TASK_COMM_LEN )
  183. __field( pid_t, pid )
  184. __field( int, prio )
  185. ),
  186. TP_fast_assign(
  187. memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
  188. __entry->pid = pid_nr(pid);
  189. __entry->prio = current->prio;
  190. ),
  191. TP_printk("comm=%s pid=%d prio=%d",
  192. __entry->comm, __entry->pid, __entry->prio)
  193. );
  194. /*
  195. * Tracepoint for do_fork:
  196. */
  197. TRACE_EVENT(sched_process_fork,
  198. TP_PROTO(struct task_struct *parent, struct task_struct *child),
  199. TP_ARGS(parent, child),
  200. TP_STRUCT__entry(
  201. __array( char, parent_comm, TASK_COMM_LEN )
  202. __field( pid_t, parent_pid )
  203. __array( char, child_comm, TASK_COMM_LEN )
  204. __field( pid_t, child_pid )
  205. ),
  206. TP_fast_assign(
  207. memcpy(__entry->parent_comm, parent->comm, TASK_COMM_LEN);
  208. __entry->parent_pid = parent->pid;
  209. memcpy(__entry->child_comm, child->comm, TASK_COMM_LEN);
  210. __entry->child_pid = child->pid;
  211. ),
  212. TP_printk("comm=%s pid=%d child_comm=%s child_pid=%d",
  213. __entry->parent_comm, __entry->parent_pid,
  214. __entry->child_comm, __entry->child_pid)
  215. );
  216. /*
  217. * XXX the below sched_stat tracepoints only apply to SCHED_OTHER/BATCH/IDLE
  218. * adding sched_stat support to SCHED_FIFO/RR would be welcome.
  219. */
  220. DECLARE_EVENT_CLASS(sched_stat_template,
  221. TP_PROTO(struct task_struct *tsk, u64 delay),
  222. TP_ARGS(tsk, delay),
  223. TP_STRUCT__entry(
  224. __array( char, comm, TASK_COMM_LEN )
  225. __field( pid_t, pid )
  226. __field( u64, delay )
  227. ),
  228. TP_fast_assign(
  229. memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
  230. __entry->pid = tsk->pid;
  231. __entry->delay = delay;
  232. )
  233. TP_perf_assign(
  234. __perf_count(delay);
  235. ),
  236. TP_printk("comm=%s pid=%d delay=%Lu [ns]",
  237. __entry->comm, __entry->pid,
  238. (unsigned long long)__entry->delay)
  239. );
  240. /*
  241. * Tracepoint for accounting wait time (time the task is runnable
  242. * but not actually running due to scheduler contention).
  243. */
  244. DEFINE_EVENT(sched_stat_template, sched_stat_wait,
  245. TP_PROTO(struct task_struct *tsk, u64 delay),
  246. TP_ARGS(tsk, delay));
  247. /*
  248. * Tracepoint for accounting sleep time (time the task is not runnable,
  249. * including iowait, see below).
  250. */
  251. DEFINE_EVENT(sched_stat_template, sched_stat_sleep,
  252. TP_PROTO(struct task_struct *tsk, u64 delay),
  253. TP_ARGS(tsk, delay));
  254. /*
  255. * Tracepoint for accounting iowait time (time the task is not runnable
  256. * due to waiting on IO to complete).
  257. */
  258. DEFINE_EVENT(sched_stat_template, sched_stat_iowait,
  259. TP_PROTO(struct task_struct *tsk, u64 delay),
  260. TP_ARGS(tsk, delay));
  261. /*
  262. * Tracepoint for accounting runtime (time the task is executing
  263. * on a CPU).
  264. */
  265. TRACE_EVENT(sched_stat_runtime,
  266. TP_PROTO(struct task_struct *tsk, u64 runtime, u64 vruntime),
  267. TP_ARGS(tsk, runtime, vruntime),
  268. TP_STRUCT__entry(
  269. __array( char, comm, TASK_COMM_LEN )
  270. __field( pid_t, pid )
  271. __field( u64, runtime )
  272. __field( u64, vruntime )
  273. ),
  274. TP_fast_assign(
  275. memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
  276. __entry->pid = tsk->pid;
  277. __entry->runtime = runtime;
  278. __entry->vruntime = vruntime;
  279. )
  280. TP_perf_assign(
  281. __perf_count(runtime);
  282. ),
  283. TP_printk("comm=%s pid=%d runtime=%Lu [ns] vruntime=%Lu [ns]",
  284. __entry->comm, __entry->pid,
  285. (unsigned long long)__entry->runtime,
  286. (unsigned long long)__entry->vruntime)
  287. );
  288. #endif /* _TRACE_SCHED_H */
  289. /* This part must be outside protection */
  290. #include <trace/define_trace.h>