sched.h 8.8 KB

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