sched.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  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. #include <linux/binfmts.h>
  8. /*
  9. * Tracepoint for calling kthread_stop, performed to end a kthread:
  10. */
  11. TRACE_EVENT(sched_kthread_stop,
  12. TP_PROTO(struct task_struct *t),
  13. TP_ARGS(t),
  14. TP_STRUCT__entry(
  15. __array( char, comm, TASK_COMM_LEN )
  16. __field( pid_t, pid )
  17. ),
  18. TP_fast_assign(
  19. memcpy(__entry->comm, t->comm, TASK_COMM_LEN);
  20. __entry->pid = t->pid;
  21. ),
  22. TP_printk("comm=%s pid=%d", __entry->comm, __entry->pid)
  23. );
  24. /*
  25. * Tracepoint for the return value of the kthread stopping:
  26. */
  27. TRACE_EVENT(sched_kthread_stop_ret,
  28. TP_PROTO(int ret),
  29. TP_ARGS(ret),
  30. TP_STRUCT__entry(
  31. __field( int, ret )
  32. ),
  33. TP_fast_assign(
  34. __entry->ret = ret;
  35. ),
  36. TP_printk("ret=%d", __entry->ret)
  37. );
  38. /*
  39. * Tracepoint for waking up a task:
  40. */
  41. DECLARE_EVENT_CLASS(sched_wakeup_template,
  42. TP_PROTO(struct task_struct *p, int success),
  43. TP_ARGS(p, success),
  44. TP_STRUCT__entry(
  45. __array( char, comm, TASK_COMM_LEN )
  46. __field( pid_t, pid )
  47. __field( int, prio )
  48. __field( int, success )
  49. __field( int, target_cpu )
  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. __entry->success = success;
  56. __entry->target_cpu = task_cpu(p);
  57. )
  58. TP_perf_assign(
  59. __perf_task(p);
  60. ),
  61. TP_printk("comm=%s pid=%d prio=%d success=%d target_cpu=%03d",
  62. __entry->comm, __entry->pid, __entry->prio,
  63. __entry->success, __entry->target_cpu)
  64. );
  65. DEFINE_EVENT(sched_wakeup_template, sched_wakeup,
  66. TP_PROTO(struct task_struct *p, int success),
  67. TP_ARGS(p, success));
  68. /*
  69. * Tracepoint for waking up a new task:
  70. */
  71. DEFINE_EVENT(sched_wakeup_template, sched_wakeup_new,
  72. TP_PROTO(struct task_struct *p, int success),
  73. TP_ARGS(p, success));
  74. #ifdef CREATE_TRACE_POINTS
  75. static inline long __trace_sched_switch_state(struct task_struct *p)
  76. {
  77. long state = p->state;
  78. #ifdef CONFIG_PREEMPT
  79. /*
  80. * For all intents and purposes a preempted task is a running task.
  81. */
  82. if (task_thread_info(p)->preempt_count & PREEMPT_ACTIVE)
  83. state = TASK_RUNNING | TASK_STATE_MAX;
  84. #endif
  85. return state;
  86. }
  87. #endif
  88. /*
  89. * Tracepoint for task switches, performed by the scheduler:
  90. */
  91. TRACE_EVENT(sched_switch,
  92. TP_PROTO(struct task_struct *prev,
  93. struct task_struct *next),
  94. TP_ARGS(prev, next),
  95. TP_STRUCT__entry(
  96. __array( char, prev_comm, TASK_COMM_LEN )
  97. __field( pid_t, prev_pid )
  98. __field( int, prev_prio )
  99. __field( long, prev_state )
  100. __array( char, next_comm, TASK_COMM_LEN )
  101. __field( pid_t, next_pid )
  102. __field( int, next_prio )
  103. ),
  104. TP_fast_assign(
  105. memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN);
  106. __entry->prev_pid = prev->pid;
  107. __entry->prev_prio = prev->prio;
  108. __entry->prev_state = __trace_sched_switch_state(prev);
  109. memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN);
  110. __entry->next_pid = next->pid;
  111. __entry->next_prio = next->prio;
  112. ),
  113. TP_printk("prev_comm=%s prev_pid=%d prev_prio=%d prev_state=%s%s ==> next_comm=%s next_pid=%d next_prio=%d",
  114. __entry->prev_comm, __entry->prev_pid, __entry->prev_prio,
  115. __entry->prev_state & (TASK_STATE_MAX-1) ?
  116. __print_flags(__entry->prev_state & (TASK_STATE_MAX-1), "|",
  117. { 1, "S"} , { 2, "D" }, { 4, "T" }, { 8, "t" },
  118. { 16, "Z" }, { 32, "X" }, { 64, "x" },
  119. { 128, "W" }) : "R",
  120. __entry->prev_state & TASK_STATE_MAX ? "+" : "",
  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 waiting on task to unschedule:
  177. */
  178. DEFINE_EVENT(sched_process_template, sched_wait_task,
  179. TP_PROTO(struct task_struct *p),
  180. TP_ARGS(p));
  181. /*
  182. * Tracepoint for a waiting task:
  183. */
  184. TRACE_EVENT(sched_process_wait,
  185. TP_PROTO(struct pid *pid),
  186. TP_ARGS(pid),
  187. TP_STRUCT__entry(
  188. __array( char, comm, TASK_COMM_LEN )
  189. __field( pid_t, pid )
  190. __field( int, prio )
  191. ),
  192. TP_fast_assign(
  193. memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
  194. __entry->pid = pid_nr(pid);
  195. __entry->prio = current->prio;
  196. ),
  197. TP_printk("comm=%s pid=%d prio=%d",
  198. __entry->comm, __entry->pid, __entry->prio)
  199. );
  200. /*
  201. * Tracepoint for do_fork:
  202. */
  203. TRACE_EVENT(sched_process_fork,
  204. TP_PROTO(struct task_struct *parent, struct task_struct *child),
  205. TP_ARGS(parent, child),
  206. TP_STRUCT__entry(
  207. __array( char, parent_comm, TASK_COMM_LEN )
  208. __field( pid_t, parent_pid )
  209. __array( char, child_comm, TASK_COMM_LEN )
  210. __field( pid_t, child_pid )
  211. ),
  212. TP_fast_assign(
  213. memcpy(__entry->parent_comm, parent->comm, TASK_COMM_LEN);
  214. __entry->parent_pid = parent->pid;
  215. memcpy(__entry->child_comm, child->comm, TASK_COMM_LEN);
  216. __entry->child_pid = child->pid;
  217. ),
  218. TP_printk("comm=%s pid=%d child_comm=%s child_pid=%d",
  219. __entry->parent_comm, __entry->parent_pid,
  220. __entry->child_comm, __entry->child_pid)
  221. );
  222. /*
  223. * Tracepoint for exec:
  224. */
  225. TRACE_EVENT(sched_process_exec,
  226. TP_PROTO(struct task_struct *p, pid_t old_pid,
  227. struct linux_binprm *bprm),
  228. TP_ARGS(p, old_pid, bprm),
  229. TP_STRUCT__entry(
  230. __string( filename, bprm->filename )
  231. __field( pid_t, pid )
  232. __field( pid_t, old_pid )
  233. ),
  234. TP_fast_assign(
  235. __assign_str(filename, bprm->filename);
  236. __entry->pid = p->pid;
  237. __entry->old_pid = old_pid;
  238. ),
  239. TP_printk("filename=%s pid=%d old_pid=%d", __get_str(filename),
  240. __entry->pid, __entry->old_pid)
  241. );
  242. /*
  243. * XXX the below sched_stat tracepoints only apply to SCHED_OTHER/BATCH/IDLE
  244. * adding sched_stat support to SCHED_FIFO/RR would be welcome.
  245. */
  246. DECLARE_EVENT_CLASS(sched_stat_template,
  247. TP_PROTO(struct task_struct *tsk, u64 delay),
  248. TP_ARGS(tsk, delay),
  249. TP_STRUCT__entry(
  250. __array( char, comm, TASK_COMM_LEN )
  251. __field( pid_t, pid )
  252. __field( u64, delay )
  253. ),
  254. TP_fast_assign(
  255. memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
  256. __entry->pid = tsk->pid;
  257. __entry->delay = delay;
  258. )
  259. TP_perf_assign(
  260. __perf_count(delay);
  261. __perf_task(tsk);
  262. ),
  263. TP_printk("comm=%s pid=%d delay=%Lu [ns]",
  264. __entry->comm, __entry->pid,
  265. (unsigned long long)__entry->delay)
  266. );
  267. /*
  268. * Tracepoint for accounting wait time (time the task is runnable
  269. * but not actually running due to scheduler contention).
  270. */
  271. DEFINE_EVENT(sched_stat_template, sched_stat_wait,
  272. TP_PROTO(struct task_struct *tsk, u64 delay),
  273. TP_ARGS(tsk, delay));
  274. /*
  275. * Tracepoint for accounting sleep time (time the task is not runnable,
  276. * including iowait, see below).
  277. */
  278. DEFINE_EVENT(sched_stat_template, sched_stat_sleep,
  279. TP_PROTO(struct task_struct *tsk, u64 delay),
  280. TP_ARGS(tsk, delay));
  281. /*
  282. * Tracepoint for accounting iowait time (time the task is not runnable
  283. * due to waiting on IO to complete).
  284. */
  285. DEFINE_EVENT(sched_stat_template, sched_stat_iowait,
  286. TP_PROTO(struct task_struct *tsk, u64 delay),
  287. TP_ARGS(tsk, delay));
  288. /*
  289. * Tracepoint for accounting blocked time (time the task is in uninterruptible).
  290. */
  291. DEFINE_EVENT(sched_stat_template, sched_stat_blocked,
  292. TP_PROTO(struct task_struct *tsk, u64 delay),
  293. TP_ARGS(tsk, delay));
  294. /*
  295. * Tracepoint for accounting runtime (time the task is executing
  296. * on a CPU).
  297. */
  298. TRACE_EVENT(sched_stat_runtime,
  299. TP_PROTO(struct task_struct *tsk, u64 runtime, u64 vruntime),
  300. TP_ARGS(tsk, runtime, vruntime),
  301. TP_STRUCT__entry(
  302. __array( char, comm, TASK_COMM_LEN )
  303. __field( pid_t, pid )
  304. __field( u64, runtime )
  305. __field( u64, vruntime )
  306. ),
  307. TP_fast_assign(
  308. memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
  309. __entry->pid = tsk->pid;
  310. __entry->runtime = runtime;
  311. __entry->vruntime = vruntime;
  312. )
  313. TP_perf_assign(
  314. __perf_count(runtime);
  315. ),
  316. TP_printk("comm=%s pid=%d runtime=%Lu [ns] vruntime=%Lu [ns]",
  317. __entry->comm, __entry->pid,
  318. (unsigned long long)__entry->runtime,
  319. (unsigned long long)__entry->vruntime)
  320. );
  321. /*
  322. * Tracepoint for showing priority inheritance modifying a tasks
  323. * priority.
  324. */
  325. TRACE_EVENT(sched_pi_setprio,
  326. TP_PROTO(struct task_struct *tsk, int newprio),
  327. TP_ARGS(tsk, newprio),
  328. TP_STRUCT__entry(
  329. __array( char, comm, TASK_COMM_LEN )
  330. __field( pid_t, pid )
  331. __field( int, oldprio )
  332. __field( int, newprio )
  333. ),
  334. TP_fast_assign(
  335. memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
  336. __entry->pid = tsk->pid;
  337. __entry->oldprio = tsk->prio;
  338. __entry->newprio = newprio;
  339. ),
  340. TP_printk("comm=%s pid=%d oldprio=%d newprio=%d",
  341. __entry->comm, __entry->pid,
  342. __entry->oldprio, __entry->newprio)
  343. );
  344. #endif /* _TRACE_SCHED_H */
  345. /* This part must be outside protection */
  346. #include <trace/define_trace.h>