sched.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  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_printk("comm=%s pid=%d prio=%d success=%d target_cpu=%03d",
  59. __entry->comm, __entry->pid, __entry->prio,
  60. __entry->success, __entry->target_cpu)
  61. );
  62. DEFINE_EVENT(sched_wakeup_template, sched_wakeup,
  63. TP_PROTO(struct task_struct *p, int success),
  64. TP_ARGS(p, success));
  65. /*
  66. * Tracepoint for waking up a new task:
  67. */
  68. DEFINE_EVENT(sched_wakeup_template, sched_wakeup_new,
  69. TP_PROTO(struct task_struct *p, int success),
  70. TP_ARGS(p, success));
  71. #ifdef CREATE_TRACE_POINTS
  72. static inline long __trace_sched_switch_state(struct task_struct *p)
  73. {
  74. long state = p->state;
  75. #ifdef CONFIG_PREEMPT
  76. /*
  77. * For all intents and purposes a preempted task is a running task.
  78. */
  79. if (task_thread_info(p)->preempt_count & PREEMPT_ACTIVE)
  80. state = TASK_RUNNING | TASK_STATE_MAX;
  81. #endif
  82. return state;
  83. }
  84. #endif
  85. /*
  86. * Tracepoint for task switches, performed by the scheduler:
  87. */
  88. TRACE_EVENT(sched_switch,
  89. TP_PROTO(struct task_struct *prev,
  90. struct task_struct *next),
  91. TP_ARGS(prev, next),
  92. TP_STRUCT__entry(
  93. __array( char, prev_comm, TASK_COMM_LEN )
  94. __field( pid_t, prev_pid )
  95. __field( int, prev_prio )
  96. __field( long, prev_state )
  97. __array( char, next_comm, TASK_COMM_LEN )
  98. __field( pid_t, next_pid )
  99. __field( int, next_prio )
  100. ),
  101. TP_fast_assign(
  102. memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN);
  103. __entry->prev_pid = prev->pid;
  104. __entry->prev_prio = prev->prio;
  105. __entry->prev_state = __trace_sched_switch_state(prev);
  106. memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN);
  107. __entry->next_pid = next->pid;
  108. __entry->next_prio = next->prio;
  109. ),
  110. TP_printk("prev_comm=%s prev_pid=%d prev_prio=%d prev_state=%s%s ==> next_comm=%s next_pid=%d next_prio=%d",
  111. __entry->prev_comm, __entry->prev_pid, __entry->prev_prio,
  112. __entry->prev_state & (TASK_STATE_MAX-1) ?
  113. __print_flags(__entry->prev_state & (TASK_STATE_MAX-1), "|",
  114. { 1, "S"} , { 2, "D" }, { 4, "T" }, { 8, "t" },
  115. { 16, "Z" }, { 32, "X" }, { 64, "x" },
  116. { 128, "W" }) : "R",
  117. __entry->prev_state & TASK_STATE_MAX ? "+" : "",
  118. __entry->next_comm, __entry->next_pid, __entry->next_prio)
  119. );
  120. /*
  121. * Tracepoint for a task being migrated:
  122. */
  123. TRACE_EVENT(sched_migrate_task,
  124. TP_PROTO(struct task_struct *p, int dest_cpu),
  125. TP_ARGS(p, dest_cpu),
  126. TP_STRUCT__entry(
  127. __array( char, comm, TASK_COMM_LEN )
  128. __field( pid_t, pid )
  129. __field( int, prio )
  130. __field( int, orig_cpu )
  131. __field( int, dest_cpu )
  132. ),
  133. TP_fast_assign(
  134. memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
  135. __entry->pid = p->pid;
  136. __entry->prio = p->prio;
  137. __entry->orig_cpu = task_cpu(p);
  138. __entry->dest_cpu = dest_cpu;
  139. ),
  140. TP_printk("comm=%s pid=%d prio=%d orig_cpu=%d dest_cpu=%d",
  141. __entry->comm, __entry->pid, __entry->prio,
  142. __entry->orig_cpu, __entry->dest_cpu)
  143. );
  144. DECLARE_EVENT_CLASS(sched_process_template,
  145. TP_PROTO(struct task_struct *p),
  146. TP_ARGS(p),
  147. TP_STRUCT__entry(
  148. __array( char, comm, TASK_COMM_LEN )
  149. __field( pid_t, pid )
  150. __field( int, prio )
  151. ),
  152. TP_fast_assign(
  153. memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
  154. __entry->pid = p->pid;
  155. __entry->prio = p->prio;
  156. ),
  157. TP_printk("comm=%s pid=%d prio=%d",
  158. __entry->comm, __entry->pid, __entry->prio)
  159. );
  160. /*
  161. * Tracepoint for freeing a task:
  162. */
  163. DEFINE_EVENT(sched_process_template, sched_process_free,
  164. TP_PROTO(struct task_struct *p),
  165. TP_ARGS(p));
  166. /*
  167. * Tracepoint for a task exiting:
  168. */
  169. DEFINE_EVENT(sched_process_template, sched_process_exit,
  170. TP_PROTO(struct task_struct *p),
  171. TP_ARGS(p));
  172. /*
  173. * Tracepoint for waiting on task to unschedule:
  174. */
  175. DEFINE_EVENT(sched_process_template, sched_wait_task,
  176. TP_PROTO(struct task_struct *p),
  177. TP_ARGS(p));
  178. /*
  179. * Tracepoint for a waiting task:
  180. */
  181. TRACE_EVENT(sched_process_wait,
  182. TP_PROTO(struct pid *pid),
  183. TP_ARGS(pid),
  184. TP_STRUCT__entry(
  185. __array( char, comm, TASK_COMM_LEN )
  186. __field( pid_t, pid )
  187. __field( int, prio )
  188. ),
  189. TP_fast_assign(
  190. memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
  191. __entry->pid = pid_nr(pid);
  192. __entry->prio = current->prio;
  193. ),
  194. TP_printk("comm=%s pid=%d prio=%d",
  195. __entry->comm, __entry->pid, __entry->prio)
  196. );
  197. /*
  198. * Tracepoint for do_fork:
  199. */
  200. TRACE_EVENT(sched_process_fork,
  201. TP_PROTO(struct task_struct *parent, struct task_struct *child),
  202. TP_ARGS(parent, child),
  203. TP_STRUCT__entry(
  204. __array( char, parent_comm, TASK_COMM_LEN )
  205. __field( pid_t, parent_pid )
  206. __array( char, child_comm, TASK_COMM_LEN )
  207. __field( pid_t, child_pid )
  208. ),
  209. TP_fast_assign(
  210. memcpy(__entry->parent_comm, parent->comm, TASK_COMM_LEN);
  211. __entry->parent_pid = parent->pid;
  212. memcpy(__entry->child_comm, child->comm, TASK_COMM_LEN);
  213. __entry->child_pid = child->pid;
  214. ),
  215. TP_printk("comm=%s pid=%d child_comm=%s child_pid=%d",
  216. __entry->parent_comm, __entry->parent_pid,
  217. __entry->child_comm, __entry->child_pid)
  218. );
  219. /*
  220. * Tracepoint for exec:
  221. */
  222. TRACE_EVENT(sched_process_exec,
  223. TP_PROTO(struct task_struct *p, pid_t old_pid,
  224. struct linux_binprm *bprm),
  225. TP_ARGS(p, old_pid, bprm),
  226. TP_STRUCT__entry(
  227. __string( filename, bprm->filename )
  228. __field( pid_t, pid )
  229. __field( pid_t, old_pid )
  230. ),
  231. TP_fast_assign(
  232. __assign_str(filename, bprm->filename);
  233. __entry->pid = p->pid;
  234. __entry->old_pid = p->pid;
  235. ),
  236. TP_printk("filename=%s pid=%d old_pid=%d", __get_str(filename),
  237. __entry->pid, __entry->old_pid)
  238. );
  239. /*
  240. * XXX the below sched_stat tracepoints only apply to SCHED_OTHER/BATCH/IDLE
  241. * adding sched_stat support to SCHED_FIFO/RR would be welcome.
  242. */
  243. DECLARE_EVENT_CLASS(sched_stat_template,
  244. TP_PROTO(struct task_struct *tsk, u64 delay),
  245. TP_ARGS(tsk, delay),
  246. TP_STRUCT__entry(
  247. __array( char, comm, TASK_COMM_LEN )
  248. __field( pid_t, pid )
  249. __field( u64, delay )
  250. ),
  251. TP_fast_assign(
  252. memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
  253. __entry->pid = tsk->pid;
  254. __entry->delay = delay;
  255. )
  256. TP_perf_assign(
  257. __perf_count(delay);
  258. ),
  259. TP_printk("comm=%s pid=%d delay=%Lu [ns]",
  260. __entry->comm, __entry->pid,
  261. (unsigned long long)__entry->delay)
  262. );
  263. /*
  264. * Tracepoint for accounting wait time (time the task is runnable
  265. * but not actually running due to scheduler contention).
  266. */
  267. DEFINE_EVENT(sched_stat_template, sched_stat_wait,
  268. TP_PROTO(struct task_struct *tsk, u64 delay),
  269. TP_ARGS(tsk, delay));
  270. /*
  271. * Tracepoint for accounting sleep time (time the task is not runnable,
  272. * including iowait, see below).
  273. */
  274. DEFINE_EVENT(sched_stat_template, sched_stat_sleep,
  275. TP_PROTO(struct task_struct *tsk, u64 delay),
  276. TP_ARGS(tsk, delay));
  277. /*
  278. * Tracepoint for accounting iowait time (time the task is not runnable
  279. * due to waiting on IO to complete).
  280. */
  281. DEFINE_EVENT(sched_stat_template, sched_stat_iowait,
  282. TP_PROTO(struct task_struct *tsk, u64 delay),
  283. TP_ARGS(tsk, delay));
  284. /*
  285. * Tracepoint for accounting blocked time (time the task is in uninterruptible).
  286. */
  287. DEFINE_EVENT(sched_stat_template, sched_stat_blocked,
  288. TP_PROTO(struct task_struct *tsk, u64 delay),
  289. TP_ARGS(tsk, delay));
  290. /*
  291. * Tracepoint for accounting runtime (time the task is executing
  292. * on a CPU).
  293. */
  294. TRACE_EVENT(sched_stat_runtime,
  295. TP_PROTO(struct task_struct *tsk, u64 runtime, u64 vruntime),
  296. TP_ARGS(tsk, runtime, vruntime),
  297. TP_STRUCT__entry(
  298. __array( char, comm, TASK_COMM_LEN )
  299. __field( pid_t, pid )
  300. __field( u64, runtime )
  301. __field( u64, vruntime )
  302. ),
  303. TP_fast_assign(
  304. memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
  305. __entry->pid = tsk->pid;
  306. __entry->runtime = runtime;
  307. __entry->vruntime = vruntime;
  308. )
  309. TP_perf_assign(
  310. __perf_count(runtime);
  311. ),
  312. TP_printk("comm=%s pid=%d runtime=%Lu [ns] vruntime=%Lu [ns]",
  313. __entry->comm, __entry->pid,
  314. (unsigned long long)__entry->runtime,
  315. (unsigned long long)__entry->vruntime)
  316. );
  317. /*
  318. * Tracepoint for showing priority inheritance modifying a tasks
  319. * priority.
  320. */
  321. TRACE_EVENT(sched_pi_setprio,
  322. TP_PROTO(struct task_struct *tsk, int newprio),
  323. TP_ARGS(tsk, newprio),
  324. TP_STRUCT__entry(
  325. __array( char, comm, TASK_COMM_LEN )
  326. __field( pid_t, pid )
  327. __field( int, oldprio )
  328. __field( int, newprio )
  329. ),
  330. TP_fast_assign(
  331. memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
  332. __entry->pid = tsk->pid;
  333. __entry->oldprio = tsk->prio;
  334. __entry->newprio = newprio;
  335. ),
  336. TP_printk("comm=%s pid=%d oldprio=%d newprio=%d",
  337. __entry->comm, __entry->pid,
  338. __entry->oldprio, __entry->newprio)
  339. );
  340. #endif /* _TRACE_SCHED_H */
  341. /* This part must be outside protection */
  342. #include <trace/define_trace.h>