sched.h 14 KB

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