sched.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  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(__perf_task(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. #ifdef CONFIG_SCHED_DEBUG
  77. BUG_ON(p != current);
  78. #endif /* CONFIG_SCHED_DEBUG */
  79. /*
  80. * For all intents and purposes a preempted task is a running task.
  81. */
  82. if (preempt_count() & PREEMPT_ACTIVE)
  83. state = TASK_RUNNING | TASK_STATE_MAX;
  84. #endif /* CONFIG_PREEMPT */
  85. return state;
  86. }
  87. #endif /* CREATE_TRACE_POINTS */
  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, "K" }, { 256, "W" }, { 512, "P" }) : "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(__perf_task(tsk), __perf_count(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_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. DECLARE_EVENT_CLASS(sched_stat_runtime,
  295. TP_PROTO(struct task_struct *tsk, u64 runtime, u64 vruntime),
  296. TP_ARGS(tsk, __perf_count(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_printk("comm=%s pid=%d runtime=%Lu [ns] vruntime=%Lu [ns]",
  310. __entry->comm, __entry->pid,
  311. (unsigned long long)__entry->runtime,
  312. (unsigned long long)__entry->vruntime)
  313. );
  314. DEFINE_EVENT(sched_stat_runtime, sched_stat_runtime,
  315. TP_PROTO(struct task_struct *tsk, u64 runtime, u64 vruntime),
  316. TP_ARGS(tsk, runtime, vruntime));
  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. #ifdef CONFIG_DETECT_HUNG_TASK
  341. TRACE_EVENT(sched_process_hang,
  342. TP_PROTO(struct task_struct *tsk),
  343. TP_ARGS(tsk),
  344. TP_STRUCT__entry(
  345. __array( char, comm, TASK_COMM_LEN )
  346. __field( pid_t, pid )
  347. ),
  348. TP_fast_assign(
  349. memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
  350. __entry->pid = tsk->pid;
  351. ),
  352. TP_printk("comm=%s pid=%d", __entry->comm, __entry->pid)
  353. );
  354. #endif /* CONFIG_DETECT_HUNG_TASK */
  355. DECLARE_EVENT_CLASS(sched_move_task_template,
  356. TP_PROTO(struct task_struct *tsk, int src_cpu, int dst_cpu),
  357. TP_ARGS(tsk, src_cpu, dst_cpu),
  358. TP_STRUCT__entry(
  359. __field( pid_t, pid )
  360. __field( pid_t, tgid )
  361. __field( pid_t, ngid )
  362. __field( int, src_cpu )
  363. __field( int, src_nid )
  364. __field( int, dst_cpu )
  365. __field( int, dst_nid )
  366. ),
  367. TP_fast_assign(
  368. __entry->pid = task_pid_nr(tsk);
  369. __entry->tgid = task_tgid_nr(tsk);
  370. __entry->ngid = task_numa_group_id(tsk);
  371. __entry->src_cpu = src_cpu;
  372. __entry->src_nid = cpu_to_node(src_cpu);
  373. __entry->dst_cpu = dst_cpu;
  374. __entry->dst_nid = cpu_to_node(dst_cpu);
  375. ),
  376. TP_printk("pid=%d tgid=%d ngid=%d src_cpu=%d src_nid=%d dst_cpu=%d dst_nid=%d",
  377. __entry->pid, __entry->tgid, __entry->ngid,
  378. __entry->src_cpu, __entry->src_nid,
  379. __entry->dst_cpu, __entry->dst_nid)
  380. );
  381. /*
  382. * Tracks migration of tasks from one runqueue to another. Can be used to
  383. * detect if automatic NUMA balancing is bouncing between nodes
  384. */
  385. DEFINE_EVENT(sched_move_task_template, sched_move_numa,
  386. TP_PROTO(struct task_struct *tsk, int src_cpu, int dst_cpu),
  387. TP_ARGS(tsk, src_cpu, dst_cpu)
  388. );
  389. DEFINE_EVENT(sched_move_task_template, sched_stick_numa,
  390. TP_PROTO(struct task_struct *tsk, int src_cpu, int dst_cpu),
  391. TP_ARGS(tsk, src_cpu, dst_cpu)
  392. );
  393. TRACE_EVENT(sched_swap_numa,
  394. TP_PROTO(struct task_struct *src_tsk, int src_cpu,
  395. struct task_struct *dst_tsk, int dst_cpu),
  396. TP_ARGS(src_tsk, src_cpu, dst_tsk, dst_cpu),
  397. TP_STRUCT__entry(
  398. __field( pid_t, src_pid )
  399. __field( pid_t, src_tgid )
  400. __field( pid_t, src_ngid )
  401. __field( int, src_cpu )
  402. __field( int, src_nid )
  403. __field( pid_t, dst_pid )
  404. __field( pid_t, dst_tgid )
  405. __field( pid_t, dst_ngid )
  406. __field( int, dst_cpu )
  407. __field( int, dst_nid )
  408. ),
  409. TP_fast_assign(
  410. __entry->src_pid = task_pid_nr(src_tsk);
  411. __entry->src_tgid = task_tgid_nr(src_tsk);
  412. __entry->src_ngid = task_numa_group_id(src_tsk);
  413. __entry->src_cpu = src_cpu;
  414. __entry->src_nid = cpu_to_node(src_cpu);
  415. __entry->dst_pid = task_pid_nr(dst_tsk);
  416. __entry->dst_tgid = task_tgid_nr(dst_tsk);
  417. __entry->dst_ngid = task_numa_group_id(dst_tsk);
  418. __entry->dst_cpu = dst_cpu;
  419. __entry->dst_nid = cpu_to_node(dst_cpu);
  420. ),
  421. TP_printk("src_pid=%d src_tgid=%d src_ngid=%d src_cpu=%d src_nid=%d dst_pid=%d dst_tgid=%d dst_ngid=%d dst_cpu=%d dst_nid=%d",
  422. __entry->src_pid, __entry->src_tgid, __entry->src_ngid,
  423. __entry->src_cpu, __entry->src_nid,
  424. __entry->dst_pid, __entry->dst_tgid, __entry->dst_ngid,
  425. __entry->dst_cpu, __entry->dst_nid)
  426. );
  427. /*
  428. * Tracepoint for waking a polling cpu without an IPI.
  429. */
  430. TRACE_EVENT(sched_wake_idle_without_ipi,
  431. TP_PROTO(int cpu),
  432. TP_ARGS(cpu),
  433. TP_STRUCT__entry(
  434. __field( int, cpu )
  435. ),
  436. TP_fast_assign(
  437. __entry->cpu = cpu;
  438. ),
  439. TP_printk("cpu=%d", __entry->cpu)
  440. );
  441. #endif /* _TRACE_SCHED_H */
  442. /* This part must be outside protection */
  443. #include <trace/define_trace.h>