sched.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  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" },
  120. { 1024, "N" }) : "R",
  121. __entry->prev_state & TASK_STATE_MAX ? "+" : "",
  122. __entry->next_comm, __entry->next_pid, __entry->next_prio)
  123. );
  124. /*
  125. * Tracepoint for a task being migrated:
  126. */
  127. TRACE_EVENT(sched_migrate_task,
  128. TP_PROTO(struct task_struct *p, int dest_cpu),
  129. TP_ARGS(p, dest_cpu),
  130. TP_STRUCT__entry(
  131. __array( char, comm, TASK_COMM_LEN )
  132. __field( pid_t, pid )
  133. __field( int, prio )
  134. __field( int, orig_cpu )
  135. __field( int, dest_cpu )
  136. ),
  137. TP_fast_assign(
  138. memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
  139. __entry->pid = p->pid;
  140. __entry->prio = p->prio;
  141. __entry->orig_cpu = task_cpu(p);
  142. __entry->dest_cpu = dest_cpu;
  143. ),
  144. TP_printk("comm=%s pid=%d prio=%d orig_cpu=%d dest_cpu=%d",
  145. __entry->comm, __entry->pid, __entry->prio,
  146. __entry->orig_cpu, __entry->dest_cpu)
  147. );
  148. DECLARE_EVENT_CLASS(sched_process_template,
  149. TP_PROTO(struct task_struct *p),
  150. TP_ARGS(p),
  151. TP_STRUCT__entry(
  152. __array( char, comm, TASK_COMM_LEN )
  153. __field( pid_t, pid )
  154. __field( int, prio )
  155. ),
  156. TP_fast_assign(
  157. memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
  158. __entry->pid = p->pid;
  159. __entry->prio = p->prio;
  160. ),
  161. TP_printk("comm=%s pid=%d prio=%d",
  162. __entry->comm, __entry->pid, __entry->prio)
  163. );
  164. /*
  165. * Tracepoint for freeing a task:
  166. */
  167. DEFINE_EVENT(sched_process_template, sched_process_free,
  168. TP_PROTO(struct task_struct *p),
  169. TP_ARGS(p));
  170. /*
  171. * Tracepoint for a task exiting:
  172. */
  173. DEFINE_EVENT(sched_process_template, sched_process_exit,
  174. TP_PROTO(struct task_struct *p),
  175. TP_ARGS(p));
  176. /*
  177. * Tracepoint for waiting on task to unschedule:
  178. */
  179. DEFINE_EVENT(sched_process_template, sched_wait_task,
  180. TP_PROTO(struct task_struct *p),
  181. TP_ARGS(p));
  182. /*
  183. * Tracepoint for a waiting task:
  184. */
  185. TRACE_EVENT(sched_process_wait,
  186. TP_PROTO(struct pid *pid),
  187. TP_ARGS(pid),
  188. TP_STRUCT__entry(
  189. __array( char, comm, TASK_COMM_LEN )
  190. __field( pid_t, pid )
  191. __field( int, prio )
  192. ),
  193. TP_fast_assign(
  194. memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
  195. __entry->pid = pid_nr(pid);
  196. __entry->prio = current->prio;
  197. ),
  198. TP_printk("comm=%s pid=%d prio=%d",
  199. __entry->comm, __entry->pid, __entry->prio)
  200. );
  201. /*
  202. * Tracepoint for do_fork:
  203. */
  204. TRACE_EVENT(sched_process_fork,
  205. TP_PROTO(struct task_struct *parent, struct task_struct *child),
  206. TP_ARGS(parent, child),
  207. TP_STRUCT__entry(
  208. __array( char, parent_comm, TASK_COMM_LEN )
  209. __field( pid_t, parent_pid )
  210. __array( char, child_comm, TASK_COMM_LEN )
  211. __field( pid_t, child_pid )
  212. ),
  213. TP_fast_assign(
  214. memcpy(__entry->parent_comm, parent->comm, TASK_COMM_LEN);
  215. __entry->parent_pid = parent->pid;
  216. memcpy(__entry->child_comm, child->comm, TASK_COMM_LEN);
  217. __entry->child_pid = child->pid;
  218. ),
  219. TP_printk("comm=%s pid=%d child_comm=%s child_pid=%d",
  220. __entry->parent_comm, __entry->parent_pid,
  221. __entry->child_comm, __entry->child_pid)
  222. );
  223. /*
  224. * Tracepoint for exec:
  225. */
  226. TRACE_EVENT(sched_process_exec,
  227. TP_PROTO(struct task_struct *p, pid_t old_pid,
  228. struct linux_binprm *bprm),
  229. TP_ARGS(p, old_pid, bprm),
  230. TP_STRUCT__entry(
  231. __string( filename, bprm->filename )
  232. __field( pid_t, pid )
  233. __field( pid_t, old_pid )
  234. ),
  235. TP_fast_assign(
  236. __assign_str(filename, bprm->filename);
  237. __entry->pid = p->pid;
  238. __entry->old_pid = old_pid;
  239. ),
  240. TP_printk("filename=%s pid=%d old_pid=%d", __get_str(filename),
  241. __entry->pid, __entry->old_pid)
  242. );
  243. /*
  244. * XXX the below sched_stat tracepoints only apply to SCHED_OTHER/BATCH/IDLE
  245. * adding sched_stat support to SCHED_FIFO/RR would be welcome.
  246. */
  247. DECLARE_EVENT_CLASS(sched_stat_template,
  248. TP_PROTO(struct task_struct *tsk, u64 delay),
  249. TP_ARGS(__perf_task(tsk), __perf_count(delay)),
  250. TP_STRUCT__entry(
  251. __array( char, comm, TASK_COMM_LEN )
  252. __field( pid_t, pid )
  253. __field( u64, delay )
  254. ),
  255. TP_fast_assign(
  256. memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
  257. __entry->pid = tsk->pid;
  258. __entry->delay = delay;
  259. ),
  260. TP_printk("comm=%s pid=%d delay=%Lu [ns]",
  261. __entry->comm, __entry->pid,
  262. (unsigned long long)__entry->delay)
  263. );
  264. /*
  265. * Tracepoint for accounting wait time (time the task is runnable
  266. * but not actually running due to scheduler contention).
  267. */
  268. DEFINE_EVENT(sched_stat_template, sched_stat_wait,
  269. TP_PROTO(struct task_struct *tsk, u64 delay),
  270. TP_ARGS(tsk, delay));
  271. /*
  272. * Tracepoint for accounting sleep time (time the task is not runnable,
  273. * including iowait, see below).
  274. */
  275. DEFINE_EVENT(sched_stat_template, sched_stat_sleep,
  276. TP_PROTO(struct task_struct *tsk, u64 delay),
  277. TP_ARGS(tsk, delay));
  278. /*
  279. * Tracepoint for accounting iowait time (time the task is not runnable
  280. * due to waiting on IO to complete).
  281. */
  282. DEFINE_EVENT(sched_stat_template, sched_stat_iowait,
  283. TP_PROTO(struct task_struct *tsk, u64 delay),
  284. TP_ARGS(tsk, delay));
  285. /*
  286. * Tracepoint for accounting blocked time (time the task is in uninterruptible).
  287. */
  288. DEFINE_EVENT(sched_stat_template, sched_stat_blocked,
  289. TP_PROTO(struct task_struct *tsk, u64 delay),
  290. TP_ARGS(tsk, delay));
  291. /*
  292. * Tracepoint for accounting runtime (time the task is executing
  293. * on a CPU).
  294. */
  295. DECLARE_EVENT_CLASS(sched_stat_runtime,
  296. TP_PROTO(struct task_struct *tsk, u64 runtime, u64 vruntime),
  297. TP_ARGS(tsk, __perf_count(runtime), vruntime),
  298. TP_STRUCT__entry(
  299. __array( char, comm, TASK_COMM_LEN )
  300. __field( pid_t, pid )
  301. __field( u64, runtime )
  302. __field( u64, vruntime )
  303. ),
  304. TP_fast_assign(
  305. memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
  306. __entry->pid = tsk->pid;
  307. __entry->runtime = runtime;
  308. __entry->vruntime = vruntime;
  309. ),
  310. TP_printk("comm=%s pid=%d runtime=%Lu [ns] vruntime=%Lu [ns]",
  311. __entry->comm, __entry->pid,
  312. (unsigned long long)__entry->runtime,
  313. (unsigned long long)__entry->vruntime)
  314. );
  315. DEFINE_EVENT(sched_stat_runtime, sched_stat_runtime,
  316. TP_PROTO(struct task_struct *tsk, u64 runtime, u64 vruntime),
  317. TP_ARGS(tsk, runtime, vruntime));
  318. /*
  319. * Tracepoint for showing priority inheritance modifying a tasks
  320. * priority.
  321. */
  322. TRACE_EVENT(sched_pi_setprio,
  323. TP_PROTO(struct task_struct *tsk, int newprio),
  324. TP_ARGS(tsk, newprio),
  325. TP_STRUCT__entry(
  326. __array( char, comm, TASK_COMM_LEN )
  327. __field( pid_t, pid )
  328. __field( int, oldprio )
  329. __field( int, newprio )
  330. ),
  331. TP_fast_assign(
  332. memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
  333. __entry->pid = tsk->pid;
  334. __entry->oldprio = tsk->prio;
  335. __entry->newprio = newprio;
  336. ),
  337. TP_printk("comm=%s pid=%d oldprio=%d newprio=%d",
  338. __entry->comm, __entry->pid,
  339. __entry->oldprio, __entry->newprio)
  340. );
  341. #ifdef CONFIG_DETECT_HUNG_TASK
  342. TRACE_EVENT(sched_process_hang,
  343. TP_PROTO(struct task_struct *tsk),
  344. TP_ARGS(tsk),
  345. TP_STRUCT__entry(
  346. __array( char, comm, TASK_COMM_LEN )
  347. __field( pid_t, pid )
  348. ),
  349. TP_fast_assign(
  350. memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
  351. __entry->pid = tsk->pid;
  352. ),
  353. TP_printk("comm=%s pid=%d", __entry->comm, __entry->pid)
  354. );
  355. #endif /* CONFIG_DETECT_HUNG_TASK */
  356. DECLARE_EVENT_CLASS(sched_move_task_template,
  357. TP_PROTO(struct task_struct *tsk, int src_cpu, int dst_cpu),
  358. TP_ARGS(tsk, src_cpu, dst_cpu),
  359. TP_STRUCT__entry(
  360. __field( pid_t, pid )
  361. __field( pid_t, tgid )
  362. __field( pid_t, ngid )
  363. __field( int, src_cpu )
  364. __field( int, src_nid )
  365. __field( int, dst_cpu )
  366. __field( int, dst_nid )
  367. ),
  368. TP_fast_assign(
  369. __entry->pid = task_pid_nr(tsk);
  370. __entry->tgid = task_tgid_nr(tsk);
  371. __entry->ngid = task_numa_group_id(tsk);
  372. __entry->src_cpu = src_cpu;
  373. __entry->src_nid = cpu_to_node(src_cpu);
  374. __entry->dst_cpu = dst_cpu;
  375. __entry->dst_nid = cpu_to_node(dst_cpu);
  376. ),
  377. TP_printk("pid=%d tgid=%d ngid=%d src_cpu=%d src_nid=%d dst_cpu=%d dst_nid=%d",
  378. __entry->pid, __entry->tgid, __entry->ngid,
  379. __entry->src_cpu, __entry->src_nid,
  380. __entry->dst_cpu, __entry->dst_nid)
  381. );
  382. /*
  383. * Tracks migration of tasks from one runqueue to another. Can be used to
  384. * detect if automatic NUMA balancing is bouncing between nodes
  385. */
  386. DEFINE_EVENT(sched_move_task_template, sched_move_numa,
  387. TP_PROTO(struct task_struct *tsk, int src_cpu, int dst_cpu),
  388. TP_ARGS(tsk, src_cpu, dst_cpu)
  389. );
  390. DEFINE_EVENT(sched_move_task_template, sched_stick_numa,
  391. TP_PROTO(struct task_struct *tsk, int src_cpu, int dst_cpu),
  392. TP_ARGS(tsk, src_cpu, dst_cpu)
  393. );
  394. TRACE_EVENT(sched_swap_numa,
  395. TP_PROTO(struct task_struct *src_tsk, int src_cpu,
  396. struct task_struct *dst_tsk, int dst_cpu),
  397. TP_ARGS(src_tsk, src_cpu, dst_tsk, dst_cpu),
  398. TP_STRUCT__entry(
  399. __field( pid_t, src_pid )
  400. __field( pid_t, src_tgid )
  401. __field( pid_t, src_ngid )
  402. __field( int, src_cpu )
  403. __field( int, src_nid )
  404. __field( pid_t, dst_pid )
  405. __field( pid_t, dst_tgid )
  406. __field( pid_t, dst_ngid )
  407. __field( int, dst_cpu )
  408. __field( int, dst_nid )
  409. ),
  410. TP_fast_assign(
  411. __entry->src_pid = task_pid_nr(src_tsk);
  412. __entry->src_tgid = task_tgid_nr(src_tsk);
  413. __entry->src_ngid = task_numa_group_id(src_tsk);
  414. __entry->src_cpu = src_cpu;
  415. __entry->src_nid = cpu_to_node(src_cpu);
  416. __entry->dst_pid = task_pid_nr(dst_tsk);
  417. __entry->dst_tgid = task_tgid_nr(dst_tsk);
  418. __entry->dst_ngid = task_numa_group_id(dst_tsk);
  419. __entry->dst_cpu = dst_cpu;
  420. __entry->dst_nid = cpu_to_node(dst_cpu);
  421. ),
  422. 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",
  423. __entry->src_pid, __entry->src_tgid, __entry->src_ngid,
  424. __entry->src_cpu, __entry->src_nid,
  425. __entry->dst_pid, __entry->dst_tgid, __entry->dst_ngid,
  426. __entry->dst_cpu, __entry->dst_nid)
  427. );
  428. /*
  429. * Tracepoint for waking a polling cpu without an IPI.
  430. */
  431. TRACE_EVENT(sched_wake_idle_without_ipi,
  432. TP_PROTO(int cpu),
  433. TP_ARGS(cpu),
  434. TP_STRUCT__entry(
  435. __field( int, cpu )
  436. ),
  437. TP_fast_assign(
  438. __entry->cpu = cpu;
  439. ),
  440. TP_printk("cpu=%d", __entry->cpu)
  441. );
  442. #endif /* _TRACE_SCHED_H */
  443. /* This part must be outside protection */
  444. #include <trace/define_trace.h>