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