sched.h 14 KB

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