sched.h 8.5 KB

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