sched.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  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 task enqueue/dequeue:
  40. */
  41. TRACE_EVENT(sched_enq_deq_task,
  42. TP_PROTO(struct task_struct *p, int enqueue),
  43. TP_ARGS(p, enqueue),
  44. TP_STRUCT__entry(
  45. __array( char, comm, TASK_COMM_LEN )
  46. __field( pid_t, pid )
  47. __field( int, prio )
  48. __field( int, cpu )
  49. __field( int, enqueue )
  50. __field(unsigned int, nr_running )
  51. __field(unsigned long, cpu_load )
  52. __field(unsigned int, rt_nr_running )
  53. ),
  54. TP_fast_assign(
  55. memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
  56. __entry->pid = p->pid;
  57. __entry->prio = p->prio;
  58. __entry->cpu = task_cpu(p);
  59. __entry->enqueue = enqueue;
  60. __entry->nr_running = task_rq(p)->nr_running;
  61. __entry->cpu_load = task_rq(p)->cpu_load[0];
  62. __entry->rt_nr_running = task_rq(p)->rt.rt_nr_running;
  63. ),
  64. TP_printk("cpu=%d %s comm=%s pid=%d prio=%d nr_running=%u cpu_load=%lu rt_nr_running=%u",
  65. __entry->cpu, __entry->enqueue ? "enqueue" : "dequeue",
  66. __entry->comm, __entry->pid,
  67. __entry->prio, __entry->nr_running,
  68. __entry->cpu_load, __entry->rt_nr_running)
  69. );
  70. /*
  71. * Tracepoint for waking up a task:
  72. */
  73. DECLARE_EVENT_CLASS(sched_wakeup_template,
  74. TP_PROTO(struct task_struct *p, int success),
  75. TP_ARGS(p, success),
  76. TP_STRUCT__entry(
  77. __array( char, comm, TASK_COMM_LEN )
  78. __field( pid_t, pid )
  79. __field( int, prio )
  80. __field( int, success )
  81. __field( int, target_cpu )
  82. ),
  83. TP_fast_assign(
  84. memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
  85. __entry->pid = p->pid;
  86. __entry->prio = p->prio;
  87. __entry->success = success;
  88. __entry->target_cpu = task_cpu(p);
  89. )
  90. TP_perf_assign(
  91. __perf_task(p);
  92. ),
  93. TP_printk("comm=%s pid=%d prio=%d success=%d target_cpu=%03d",
  94. __entry->comm, __entry->pid, __entry->prio,
  95. __entry->success, __entry->target_cpu)
  96. );
  97. DEFINE_EVENT(sched_wakeup_template, sched_wakeup,
  98. TP_PROTO(struct task_struct *p, int success),
  99. TP_ARGS(p, success));
  100. /*
  101. * Tracepoint for waking up a new task:
  102. */
  103. DEFINE_EVENT(sched_wakeup_template, sched_wakeup_new,
  104. TP_PROTO(struct task_struct *p, int success),
  105. TP_ARGS(p, success));
  106. #ifdef CREATE_TRACE_POINTS
  107. static inline long __trace_sched_switch_state(struct task_struct *p)
  108. {
  109. long state = p->state;
  110. #ifdef CONFIG_PREEMPT
  111. /*
  112. * For all intents and purposes a preempted task is a running task.
  113. */
  114. if (task_thread_info(p)->preempt_count & PREEMPT_ACTIVE)
  115. state = TASK_RUNNING | TASK_STATE_MAX;
  116. #endif
  117. return state;
  118. }
  119. #endif
  120. /*
  121. * Tracepoint for task switches, performed by the scheduler:
  122. */
  123. TRACE_EVENT(sched_switch,
  124. TP_PROTO(struct task_struct *prev,
  125. struct task_struct *next),
  126. TP_ARGS(prev, next),
  127. TP_STRUCT__entry(
  128. __array( char, prev_comm, TASK_COMM_LEN )
  129. __field( pid_t, prev_pid )
  130. __field( int, prev_prio )
  131. __field( long, prev_state )
  132. __array( char, next_comm, TASK_COMM_LEN )
  133. __field( pid_t, next_pid )
  134. __field( int, next_prio )
  135. ),
  136. TP_fast_assign(
  137. memcpy(__entry->next_comm, next->comm, TASK_COMM_LEN);
  138. __entry->prev_pid = prev->pid;
  139. __entry->prev_prio = prev->prio;
  140. __entry->prev_state = __trace_sched_switch_state(prev);
  141. memcpy(__entry->prev_comm, prev->comm, TASK_COMM_LEN);
  142. __entry->next_pid = next->pid;
  143. __entry->next_prio = next->prio;
  144. ),
  145. TP_printk("prev_comm=%s prev_pid=%d prev_prio=%d prev_state=%s%s ==> next_comm=%s next_pid=%d next_prio=%d",
  146. __entry->prev_comm, __entry->prev_pid, __entry->prev_prio,
  147. __entry->prev_state & (TASK_STATE_MAX-1) ?
  148. __print_flags(__entry->prev_state & (TASK_STATE_MAX-1), "|",
  149. { 1, "S"} , { 2, "D" }, { 4, "T" }, { 8, "t" },
  150. { 16, "Z" }, { 32, "X" }, { 64, "x" },
  151. { 128, "W" }) : "R",
  152. __entry->prev_state & TASK_STATE_MAX ? "+" : "",
  153. __entry->next_comm, __entry->next_pid, __entry->next_prio)
  154. );
  155. /*
  156. * Tracepoint for a task being migrated:
  157. */
  158. TRACE_EVENT(sched_migrate_task,
  159. TP_PROTO(struct task_struct *p, int dest_cpu),
  160. TP_ARGS(p, dest_cpu),
  161. TP_STRUCT__entry(
  162. __array( char, comm, TASK_COMM_LEN )
  163. __field( pid_t, pid )
  164. __field( int, prio )
  165. __field( int, orig_cpu )
  166. __field( int, dest_cpu )
  167. ),
  168. TP_fast_assign(
  169. memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
  170. __entry->pid = p->pid;
  171. __entry->prio = p->prio;
  172. __entry->orig_cpu = task_cpu(p);
  173. __entry->dest_cpu = dest_cpu;
  174. ),
  175. TP_printk("comm=%s pid=%d prio=%d orig_cpu=%d dest_cpu=%d",
  176. __entry->comm, __entry->pid, __entry->prio,
  177. __entry->orig_cpu, __entry->dest_cpu)
  178. );
  179. /*
  180. * Tracepoint for a CPU going offline/online:
  181. */
  182. TRACE_EVENT(sched_cpu_hotplug,
  183. TP_PROTO(int affected_cpu, int error, int status),
  184. TP_ARGS(affected_cpu, error, status),
  185. TP_STRUCT__entry(
  186. __field( int, affected_cpu )
  187. __field( int, error )
  188. __field( int, status )
  189. ),
  190. TP_fast_assign(
  191. __entry->affected_cpu = affected_cpu;
  192. __entry->error = error;
  193. __entry->status = status;
  194. ),
  195. TP_printk("cpu %d %s error=%d", __entry->affected_cpu,
  196. __entry->status ? "online" : "offline", __entry->error)
  197. );
  198. /*
  199. * Tracepoint for load balancing:
  200. */
  201. #if NR_CPUS > 32
  202. #error "Unsupported NR_CPUS for lb tracepoint."
  203. #endif
  204. TRACE_EVENT(sched_load_balance,
  205. TP_PROTO(int cpu, enum cpu_idle_type idle, int balance,
  206. unsigned long group_mask, int busiest_nr_running,
  207. unsigned long imbalance, unsigned int env_flags, int ld_moved,
  208. unsigned int balance_interval),
  209. TP_ARGS(cpu, idle, balance, group_mask, busiest_nr_running,
  210. imbalance, env_flags, ld_moved, balance_interval),
  211. TP_STRUCT__entry(
  212. __field( int, cpu)
  213. __field( enum cpu_idle_type, idle)
  214. __field( int, balance)
  215. __field( unsigned long, group_mask)
  216. __field( int, busiest_nr_running)
  217. __field( unsigned long, imbalance)
  218. __field( unsigned int, env_flags)
  219. __field( int, ld_moved)
  220. __field( unsigned int, balance_interval)
  221. ),
  222. TP_fast_assign(
  223. __entry->cpu = cpu;
  224. __entry->idle = idle;
  225. __entry->balance = balance;
  226. __entry->group_mask = group_mask;
  227. __entry->busiest_nr_running = busiest_nr_running;
  228. __entry->imbalance = imbalance;
  229. __entry->env_flags = env_flags;
  230. __entry->ld_moved = ld_moved;
  231. __entry->balance_interval = balance_interval;
  232. ),
  233. TP_printk("cpu=%d state=%s balance=%d group=%#lx busy_nr=%d imbalance=%ld flags=%#x ld_moved=%d bal_int=%d",
  234. __entry->cpu,
  235. __entry->idle == CPU_IDLE ? "idle" :
  236. (__entry->idle == CPU_NEWLY_IDLE ? "newly_idle" : "busy"),
  237. __entry->balance,
  238. __entry->group_mask, __entry->busiest_nr_running,
  239. __entry->imbalance, __entry->env_flags, __entry->ld_moved,
  240. __entry->balance_interval)
  241. );
  242. DECLARE_EVENT_CLASS(sched_process_template,
  243. TP_PROTO(struct task_struct *p),
  244. TP_ARGS(p),
  245. TP_STRUCT__entry(
  246. __array( char, comm, TASK_COMM_LEN )
  247. __field( pid_t, pid )
  248. __field( int, prio )
  249. ),
  250. TP_fast_assign(
  251. memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
  252. __entry->pid = p->pid;
  253. __entry->prio = p->prio;
  254. ),
  255. TP_printk("comm=%s pid=%d prio=%d",
  256. __entry->comm, __entry->pid, __entry->prio)
  257. );
  258. /*
  259. * Tracepoint for freeing a task:
  260. */
  261. DEFINE_EVENT(sched_process_template, sched_process_free,
  262. TP_PROTO(struct task_struct *p),
  263. TP_ARGS(p));
  264. /*
  265. * Tracepoint for a task exiting:
  266. */
  267. DEFINE_EVENT(sched_process_template, sched_process_exit,
  268. TP_PROTO(struct task_struct *p),
  269. TP_ARGS(p));
  270. /*
  271. * Tracepoint for waiting on task to unschedule:
  272. */
  273. DEFINE_EVENT(sched_process_template, sched_wait_task,
  274. TP_PROTO(struct task_struct *p),
  275. TP_ARGS(p));
  276. /*
  277. * Tracepoint for a waiting task:
  278. */
  279. TRACE_EVENT(sched_process_wait,
  280. TP_PROTO(struct pid *pid),
  281. TP_ARGS(pid),
  282. TP_STRUCT__entry(
  283. __array( char, comm, TASK_COMM_LEN )
  284. __field( pid_t, pid )
  285. __field( int, prio )
  286. ),
  287. TP_fast_assign(
  288. memcpy(__entry->comm, current->comm, TASK_COMM_LEN);
  289. __entry->pid = pid_nr(pid);
  290. __entry->prio = current->prio;
  291. ),
  292. TP_printk("comm=%s pid=%d prio=%d",
  293. __entry->comm, __entry->pid, __entry->prio)
  294. );
  295. /*
  296. * Tracepoint for do_fork:
  297. */
  298. TRACE_EVENT(sched_process_fork,
  299. TP_PROTO(struct task_struct *parent, struct task_struct *child),
  300. TP_ARGS(parent, child),
  301. TP_STRUCT__entry(
  302. __array( char, parent_comm, TASK_COMM_LEN )
  303. __field( pid_t, parent_pid )
  304. __array( char, child_comm, TASK_COMM_LEN )
  305. __field( pid_t, child_pid )
  306. ),
  307. TP_fast_assign(
  308. memcpy(__entry->parent_comm, parent->comm, TASK_COMM_LEN);
  309. __entry->parent_pid = parent->pid;
  310. memcpy(__entry->child_comm, child->comm, TASK_COMM_LEN);
  311. __entry->child_pid = child->pid;
  312. ),
  313. TP_printk("comm=%s pid=%d child_comm=%s child_pid=%d",
  314. __entry->parent_comm, __entry->parent_pid,
  315. __entry->child_comm, __entry->child_pid)
  316. );
  317. /*
  318. * Tracepoint for exec:
  319. */
  320. TRACE_EVENT(sched_process_exec,
  321. TP_PROTO(struct task_struct *p, pid_t old_pid,
  322. struct linux_binprm *bprm),
  323. TP_ARGS(p, old_pid, bprm),
  324. TP_STRUCT__entry(
  325. __string( filename, bprm->filename )
  326. __field( pid_t, pid )
  327. __field( pid_t, old_pid )
  328. ),
  329. TP_fast_assign(
  330. __assign_str(filename, bprm->filename);
  331. __entry->pid = p->pid;
  332. __entry->old_pid = old_pid;
  333. ),
  334. TP_printk("filename=%s pid=%d old_pid=%d", __get_str(filename),
  335. __entry->pid, __entry->old_pid)
  336. );
  337. /*
  338. * XXX the below sched_stat tracepoints only apply to SCHED_OTHER/BATCH/IDLE
  339. * adding sched_stat support to SCHED_FIFO/RR would be welcome.
  340. */
  341. DECLARE_EVENT_CLASS(sched_stat_template,
  342. TP_PROTO(struct task_struct *tsk, u64 delay),
  343. TP_ARGS(tsk, delay),
  344. TP_STRUCT__entry(
  345. __array( char, comm, TASK_COMM_LEN )
  346. __field( pid_t, pid )
  347. __field( u64, delay )
  348. ),
  349. TP_fast_assign(
  350. memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
  351. __entry->pid = tsk->pid;
  352. __entry->delay = delay;
  353. )
  354. TP_perf_assign(
  355. __perf_count(delay);
  356. __perf_task(tsk);
  357. ),
  358. TP_printk("comm=%s pid=%d delay=%Lu [ns]",
  359. __entry->comm, __entry->pid,
  360. (unsigned long long)__entry->delay)
  361. );
  362. /*
  363. * Tracepoint for accounting wait time (time the task is runnable
  364. * but not actually running due to scheduler contention).
  365. */
  366. DEFINE_EVENT(sched_stat_template, sched_stat_wait,
  367. TP_PROTO(struct task_struct *tsk, u64 delay),
  368. TP_ARGS(tsk, delay));
  369. /*
  370. * Tracepoint for accounting sleep time (time the task is not runnable,
  371. * including iowait, see below).
  372. */
  373. DEFINE_EVENT(sched_stat_template, sched_stat_sleep,
  374. TP_PROTO(struct task_struct *tsk, u64 delay),
  375. TP_ARGS(tsk, delay));
  376. /*
  377. * Tracepoint for accounting iowait time (time the task is not runnable
  378. * due to waiting on IO to complete).
  379. */
  380. DEFINE_EVENT(sched_stat_template, sched_stat_iowait,
  381. TP_PROTO(struct task_struct *tsk, u64 delay),
  382. TP_ARGS(tsk, delay));
  383. /*
  384. * Tracepoint for accounting blocked time (time the task is in uninterruptible).
  385. */
  386. DEFINE_EVENT(sched_stat_template, sched_stat_blocked,
  387. TP_PROTO(struct task_struct *tsk, u64 delay),
  388. TP_ARGS(tsk, delay));
  389. /*
  390. * Tracepoint for accounting runtime (time the task is executing
  391. * on a CPU).
  392. */
  393. TRACE_EVENT(sched_stat_runtime,
  394. TP_PROTO(struct task_struct *tsk, u64 runtime, u64 vruntime),
  395. TP_ARGS(tsk, runtime, vruntime),
  396. TP_STRUCT__entry(
  397. __array( char, comm, TASK_COMM_LEN )
  398. __field( pid_t, pid )
  399. __field( u64, runtime )
  400. __field( u64, vruntime )
  401. ),
  402. TP_fast_assign(
  403. memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
  404. __entry->pid = tsk->pid;
  405. __entry->runtime = runtime;
  406. __entry->vruntime = vruntime;
  407. )
  408. TP_perf_assign(
  409. __perf_count(runtime);
  410. ),
  411. TP_printk("comm=%s pid=%d runtime=%Lu [ns] vruntime=%Lu [ns]",
  412. __entry->comm, __entry->pid,
  413. (unsigned long long)__entry->runtime,
  414. (unsigned long long)__entry->vruntime)
  415. );
  416. /*
  417. * Tracepoint for showing priority inheritance modifying a tasks
  418. * priority.
  419. */
  420. TRACE_EVENT(sched_pi_setprio,
  421. TP_PROTO(struct task_struct *tsk, int newprio),
  422. TP_ARGS(tsk, newprio),
  423. TP_STRUCT__entry(
  424. __array( char, comm, TASK_COMM_LEN )
  425. __field( pid_t, pid )
  426. __field( int, oldprio )
  427. __field( int, newprio )
  428. ),
  429. TP_fast_assign(
  430. memcpy(__entry->comm, tsk->comm, TASK_COMM_LEN);
  431. __entry->pid = tsk->pid;
  432. __entry->oldprio = tsk->prio;
  433. __entry->newprio = newprio;
  434. ),
  435. TP_printk("comm=%s pid=%d oldprio=%d newprio=%d",
  436. __entry->comm, __entry->pid,
  437. __entry->oldprio, __entry->newprio)
  438. );
  439. #endif /* _TRACE_SCHED_H */
  440. /* This part must be outside protection */
  441. #include <trace/define_trace.h>