sched.h 14 KB

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