sched.h 8.7 KB

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