sched.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  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),
  43. TP_ARGS(__perf_task(p)),
  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 = 1; /* rudiment, kill when possible */
  56. __entry->target_cpu = task_cpu(p);
  57. ),
  58. TP_printk("comm=%s pid=%d prio=%d target_cpu=%03d",
  59. __entry->comm, __entry->pid, __entry->prio,
  60. __entry->target_cpu)
  61. );
  62. /*
  63. * Tracepoint called when waking a task; this tracepoint is guaranteed to be
  64. * called from the waking context.
  65. */
  66. DEFINE_EVENT(sched_wakeup_template, sched_waking,
  67. TP_PROTO(struct task_struct *p),
  68. TP_ARGS(p));
  69. /*
  70. * Tracepoint called when the task is actually woken; p->state == TASK_RUNNNG.
  71. * It it not always called from the waking context.
  72. */
  73. DEFINE_EVENT(sched_wakeup_template, sched_wakeup,
  74. TP_PROTO(struct task_struct *p),
  75. TP_ARGS(p));
  76. /*
  77. * Tracepoint for waking up a new task:
  78. */
  79. DEFINE_EVENT(sched_wakeup_template, sched_wakeup_new,
  80. TP_PROTO(struct task_struct *p),
  81. TP_ARGS(p));
  82. #ifdef CREATE_TRACE_POINTS
  83. static inline long __trace_sched_switch_state(bool preempt, struct task_struct *p)
  84. {
  85. #ifdef CONFIG_SCHED_DEBUG
  86. BUG_ON(p != current);
  87. #endif /* CONFIG_SCHED_DEBUG */
  88. /*
  89. * Preemption ignores task state, therefore preempted tasks are always
  90. * RUNNING (we will not have dequeued if state != RUNNING).
  91. */
  92. return preempt ? TASK_RUNNING | TASK_STATE_MAX : p->state;
  93. }
  94. #endif /* CREATE_TRACE_POINTS */
  95. /*
  96. * Tracepoint for task switches, performed by the scheduler:
  97. */
  98. TRACE_EVENT(sched_switch,
  99. TP_PROTO(bool preempt,
  100. struct task_struct *prev,
  101. struct task_struct *next),
  102. TP_ARGS(preempt, prev, next),
  103. TP_STRUCT__entry(
  104. __array( char, prev_comm, TASK_COMM_LEN )
  105. __field( pid_t, prev_pid )
  106. __field( int, prev_prio )
  107. __field( long, prev_state )
  108. __array( char, next_comm, TASK_COMM_LEN )
  109. __field( pid_t, next_pid )
  110. __field( int, next_prio )
  111. ),
  112. TP_fast_assign(
  113. memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN);
  114. __entry->prev_pid = prev->pid;
  115. __entry->prev_prio = prev->prio;
  116. __entry->prev_state = __trace_sched_switch_state(preempt, prev);
  117. memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN);
  118. __entry->next_pid = next->pid;
  119. __entry->next_prio = next->prio;
  120. ),
  121. TP_printk("prev_comm=%s prev_pid=%d prev_prio=%d prev_state=%s%s ==> next_comm=%s next_pid=%d next_prio=%d",
  122. __entry->prev_comm, __entry->prev_pid, __entry->prev_prio,
  123. __entry->prev_state & (TASK_STATE_MAX-1) ?
  124. __print_flags(__entry->prev_state & (TASK_STATE_MAX-1), "|",
  125. { 1, "S"} , { 2, "D" }, { 4, "T" }, { 8, "t" },
  126. { 16, "Z" }, { 32, "X" }, { 64, "x" },
  127. { 128, "K" }, { 256, "W" }, { 512, "P" },
  128. { 1024, "N" }) : "R",
  129. __entry->prev_state & TASK_STATE_MAX ? "+" : "",
  130. __entry->next_comm, __entry->next_pid, __entry->next_prio)
  131. );
  132. /*
  133. * Tracepoint for a task being migrated:
  134. */
  135. TRACE_EVENT(sched_migrate_task,
  136. TP_PROTO(struct task_struct *p, int dest_cpu),
  137. TP_ARGS(p, dest_cpu),
  138. TP_STRUCT__entry(
  139. __array( char, comm, TASK_COMM_LEN )
  140. __field( pid_t, pid )
  141. __field( int, prio )
  142. __field( int, orig_cpu )
  143. __field( int, dest_cpu )
  144. ),
  145. TP_fast_assign(
  146. memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
  147. __entry->pid = p->pid;
  148. __entry->prio = p->prio;
  149. __entry->orig_cpu = task_cpu(p);
  150. __entry->dest_cpu = dest_cpu;
  151. ),
  152. TP_printk("comm=%s pid=%d prio=%d orig_cpu=%d dest_cpu=%d",
  153. __entry->comm, __entry->pid, __entry->prio,
  154. __entry->orig_cpu, __entry->dest_cpu)
  155. );
  156. DECLARE_EVENT_CLASS(sched_process_template,
  157. TP_PROTO(struct task_struct *p),
  158. TP_ARGS(p),
  159. TP_STRUCT__entry(
  160. __array( char, comm, TASK_COMM_LEN )
  161. __field( pid_t, pid )
  162. __field( int, prio )
  163. ),
  164. TP_fast_assign(
  165. memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
  166. __entry->pid = p->pid;
  167. __entry->prio = p->prio;
  168. ),
  169. TP_printk("comm=%s pid=%d prio=%d",
  170. __entry->comm, __entry->pid, __entry->prio)
  171. );
  172. /*
  173. * Tracepoint for freeing a task:
  174. */
  175. DEFINE_EVENT(sched_process_template, sched_process_free,
  176. TP_PROTO(struct task_struct *p),
  177. TP_ARGS(p));
  178. /*
  179. * Tracepoint for a task exiting:
  180. */
  181. DEFINE_EVENT(sched_process_template, sched_process_exit,
  182. TP_PROTO(struct task_struct *p),
  183. TP_ARGS(p));
  184. /*
  185. * Tracepoint for waiting on task to unschedule:
  186. */
  187. DEFINE_EVENT(sched_process_template, sched_wait_task,
  188. TP_PROTO(struct task_struct *p),
  189. TP_ARGS(p));
  190. /*
  191. * Tracepoint for a waiting task:
  192. */
  193. TRACE_EVENT(sched_process_wait,
  194. TP_PROTO(struct pid *pid),
  195. TP_ARGS(pid),
  196. TP_STRUCT__entry(
  197. __array( char, comm, TASK_COMM_LEN )
  198. __field( pid_t, pid )
  199. __field( int, prio )
  200. ),
  201. TP_fast_assign(
  202. memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
  203. __entry->pid = pid_nr(pid);
  204. __entry->prio = current->prio;
  205. ),
  206. TP_printk("comm=%s pid=%d prio=%d",
  207. __entry->comm, __entry->pid, __entry->prio)
  208. );
  209. /*
  210. * Tracepoint for do_fork:
  211. */
  212. TRACE_EVENT(sched_process_fork,
  213. TP_PROTO(struct task_struct *parent, struct task_struct *child),
  214. TP_ARGS(parent, child),
  215. TP_STRUCT__entry(
  216. __array( char, parent_comm, TASK_COMM_LEN )
  217. __field( pid_t, parent_pid )
  218. __array( char, child_comm, TASK_COMM_LEN )
  219. __field( pid_t, child_pid )
  220. ),
  221. TP_fast_assign(
  222. memcpy(__entry->parent_comm, parent->comm, TASK_COMM_LEN);
  223. __entry->parent_pid = parent->pid;
  224. memcpy(__entry->child_comm, child->comm, TASK_COMM_LEN);
  225. __entry->child_pid = child->pid;
  226. ),
  227. TP_printk("comm=%s pid=%d child_comm=%s child_pid=%d",
  228. __entry->parent_comm, __entry->parent_pid,
  229. __entry->child_comm, __entry->child_pid)
  230. );
  231. /*
  232. * Tracepoint for exec:
  233. */
  234. TRACE_EVENT(sched_process_exec,
  235. TP_PROTO(struct task_struct *p, pid_t old_pid,
  236. struct linux_binprm *bprm),
  237. TP_ARGS(p, old_pid, bprm),
  238. TP_STRUCT__entry(
  239. __string( filename, bprm->filename )
  240. __field( pid_t, pid )
  241. __field( pid_t, old_pid )
  242. ),
  243. TP_fast_assign(
  244. __assign_str(filename, bprm->filename);
  245. __entry->pid = p->pid;
  246. __entry->old_pid = old_pid;
  247. ),
  248. TP_printk("filename=%s pid=%d old_pid=%d", __get_str(filename),
  249. __entry->pid, __entry->old_pid)
  250. );
  251. /*
  252. * XXX the below sched_stat tracepoints only apply to SCHED_OTHER/BATCH/IDLE
  253. * adding sched_stat support to SCHED_FIFO/RR would be welcome.
  254. */
  255. DECLARE_EVENT_CLASS(sched_stat_template,
  256. TP_PROTO(struct task_struct *tsk, u64 delay),
  257. TP_ARGS(__perf_task(tsk), __perf_count(delay)),
  258. TP_STRUCT__entry(
  259. __array( char, comm, TASK_COMM_LEN )
  260. __field( pid_t, pid )
  261. __field( u64, delay )
  262. ),
  263. TP_fast_assign(
  264. memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
  265. __entry->pid = tsk->pid;
  266. __entry->delay = delay;
  267. ),
  268. TP_printk("comm=%s pid=%d delay=%Lu [ns]",
  269. __entry->comm, __entry->pid,
  270. (unsigned long long)__entry->delay)
  271. );
  272. /*
  273. * Tracepoint for accounting wait time (time the task is runnable
  274. * but not actually running due to scheduler contention).
  275. */
  276. DEFINE_EVENT(sched_stat_template, sched_stat_wait,
  277. TP_PROTO(struct task_struct *tsk, u64 delay),
  278. TP_ARGS(tsk, delay));
  279. /*
  280. * Tracepoint for accounting sleep time (time the task is not runnable,
  281. * including iowait, see below).
  282. */
  283. DEFINE_EVENT(sched_stat_template, sched_stat_sleep,
  284. TP_PROTO(struct task_struct *tsk, u64 delay),
  285. TP_ARGS(tsk, delay));
  286. /*
  287. * Tracepoint for accounting iowait time (time the task is not runnable
  288. * due to waiting on IO to complete).
  289. */
  290. DEFINE_EVENT(sched_stat_template, sched_stat_iowait,
  291. TP_PROTO(struct task_struct *tsk, u64 delay),
  292. TP_ARGS(tsk, delay));
  293. /*
  294. * Tracepoint for accounting blocked time (time the task is in uninterruptible).
  295. */
  296. DEFINE_EVENT(sched_stat_template, sched_stat_blocked,
  297. TP_PROTO(struct task_struct *tsk, u64 delay),
  298. TP_ARGS(tsk, delay));
  299. /*
  300. * Tracepoint for accounting runtime (time the task is executing
  301. * on a CPU).
  302. */
  303. DECLARE_EVENT_CLASS(sched_stat_runtime,
  304. TP_PROTO(struct task_struct *tsk, u64 runtime, u64 vruntime),
  305. TP_ARGS(tsk, __perf_count(runtime), vruntime),
  306. TP_STRUCT__entry(
  307. __array( char, comm, TASK_COMM_LEN )
  308. __field( pid_t, pid )
  309. __field( u64, runtime )
  310. __field( u64, vruntime )
  311. ),
  312. TP_fast_assign(
  313. memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
  314. __entry->pid = tsk->pid;
  315. __entry->runtime = runtime;
  316. __entry->vruntime = vruntime;
  317. ),
  318. TP_printk("comm=%s pid=%d runtime=%Lu [ns] vruntime=%Lu [ns]",
  319. __entry->comm, __entry->pid,
  320. (unsigned long long)__entry->runtime,
  321. (unsigned long long)__entry->vruntime)
  322. );
  323. DEFINE_EVENT(sched_stat_runtime, sched_stat_runtime,
  324. TP_PROTO(struct task_struct *tsk, u64 runtime, u64 vruntime),
  325. TP_ARGS(tsk, runtime, vruntime));
  326. /*
  327. * Tracepoint for showing priority inheritance modifying a tasks
  328. * priority.
  329. */
  330. TRACE_EVENT(sched_pi_setprio,
  331. TP_PROTO(struct task_struct *tsk, int newprio),
  332. TP_ARGS(tsk, newprio),
  333. TP_STRUCT__entry(
  334. __array( char, comm, TASK_COMM_LEN )
  335. __field( pid_t, pid )
  336. __field( int, oldprio )
  337. __field( int, newprio )
  338. ),
  339. TP_fast_assign(
  340. memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
  341. __entry->pid = tsk->pid;
  342. __entry->oldprio = tsk->prio;
  343. __entry->newprio = newprio;
  344. ),
  345. TP_printk("comm=%s pid=%d oldprio=%d newprio=%d",
  346. __entry->comm, __entry->pid,
  347. __entry->oldprio, __entry->newprio)
  348. );
  349. #ifdef CONFIG_DETECT_HUNG_TASK
  350. TRACE_EVENT(sched_process_hang,
  351. TP_PROTO(struct task_struct *tsk),
  352. TP_ARGS(tsk),
  353. TP_STRUCT__entry(
  354. __array( char, comm, TASK_COMM_LEN )
  355. __field( pid_t, pid )
  356. ),
  357. TP_fast_assign(
  358. memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
  359. __entry->pid = tsk->pid;
  360. ),
  361. TP_printk("comm=%s pid=%d", __entry->comm, __entry->pid)
  362. );
  363. #endif /* CONFIG_DETECT_HUNG_TASK */
  364. DECLARE_EVENT_CLASS(sched_move_task_template,
  365. TP_PROTO(struct task_struct *tsk, int src_cpu, int dst_cpu),
  366. TP_ARGS(tsk, src_cpu, dst_cpu),
  367. TP_STRUCT__entry(
  368. __field( pid_t, pid )
  369. __field( pid_t, tgid )
  370. __field( pid_t, ngid )
  371. __field( int, src_cpu )
  372. __field( int, src_nid )
  373. __field( int, dst_cpu )
  374. __field( int, dst_nid )
  375. ),
  376. TP_fast_assign(
  377. __entry->pid = task_pid_nr(tsk);
  378. __entry->tgid = task_tgid_nr(tsk);
  379. __entry->ngid = task_numa_group_id(tsk);
  380. __entry->src_cpu = src_cpu;
  381. __entry->src_nid = cpu_to_node(src_cpu);
  382. __entry->dst_cpu = dst_cpu;
  383. __entry->dst_nid = cpu_to_node(dst_cpu);
  384. ),
  385. TP_printk("pid=%d tgid=%d ngid=%d src_cpu=%d src_nid=%d dst_cpu=%d dst_nid=%d",
  386. __entry->pid, __entry->tgid, __entry->ngid,
  387. __entry->src_cpu, __entry->src_nid,
  388. __entry->dst_cpu, __entry->dst_nid)
  389. );
  390. /*
  391. * Tracks migration of tasks from one runqueue to another. Can be used to
  392. * detect if automatic NUMA balancing is bouncing between nodes
  393. */
  394. DEFINE_EVENT(sched_move_task_template, sched_move_numa,
  395. TP_PROTO(struct task_struct *tsk, int src_cpu, int dst_cpu),
  396. TP_ARGS(tsk, src_cpu, dst_cpu)
  397. );
  398. DEFINE_EVENT(sched_move_task_template, sched_stick_numa,
  399. TP_PROTO(struct task_struct *tsk, int src_cpu, int dst_cpu),
  400. TP_ARGS(tsk, src_cpu, dst_cpu)
  401. );
  402. TRACE_EVENT(sched_swap_numa,
  403. TP_PROTO(struct task_struct *src_tsk, int src_cpu,
  404. struct task_struct *dst_tsk, int dst_cpu),
  405. TP_ARGS(src_tsk, src_cpu, dst_tsk, dst_cpu),
  406. TP_STRUCT__entry(
  407. __field( pid_t, src_pid )
  408. __field( pid_t, src_tgid )
  409. __field( pid_t, src_ngid )
  410. __field( int, src_cpu )
  411. __field( int, src_nid )
  412. __field( pid_t, dst_pid )
  413. __field( pid_t, dst_tgid )
  414. __field( pid_t, dst_ngid )
  415. __field( int, dst_cpu )
  416. __field( int, dst_nid )
  417. ),
  418. TP_fast_assign(
  419. __entry->src_pid = task_pid_nr(src_tsk);
  420. __entry->src_tgid = task_tgid_nr(src_tsk);
  421. __entry->src_ngid = task_numa_group_id(src_tsk);
  422. __entry->src_cpu = src_cpu;
  423. __entry->src_nid = cpu_to_node(src_cpu);
  424. __entry->dst_pid = task_pid_nr(dst_tsk);
  425. __entry->dst_tgid = task_tgid_nr(dst_tsk);
  426. __entry->dst_ngid = task_numa_group_id(dst_tsk);
  427. __entry->dst_cpu = dst_cpu;
  428. __entry->dst_nid = cpu_to_node(dst_cpu);
  429. ),
  430. 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",
  431. __entry->src_pid, __entry->src_tgid, __entry->src_ngid,
  432. __entry->src_cpu, __entry->src_nid,
  433. __entry->dst_pid, __entry->dst_tgid, __entry->dst_ngid,
  434. __entry->dst_cpu, __entry->dst_nid)
  435. );
  436. /*
  437. * Tracepoint for waking a polling cpu without an IPI.
  438. */
  439. TRACE_EVENT(sched_wake_idle_without_ipi,
  440. TP_PROTO(int cpu),
  441. TP_ARGS(cpu),
  442. TP_STRUCT__entry(
  443. __field( int, cpu )
  444. ),
  445. TP_fast_assign(
  446. __entry->cpu = cpu;
  447. ),
  448. TP_printk("cpu=%d", __entry->cpu)
  449. );
  450. #endif /* _TRACE_SCHED_H */
  451. /* This part must be outside protection */
  452. #include <trace/define_trace.h>