sched_debug.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. /*
  2. * kernel/time/sched_debug.c
  3. *
  4. * Print the CFS rbtree
  5. *
  6. * Copyright(C) 2007, Red Hat, Inc., Ingo Molnar
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/proc_fs.h>
  13. #include <linux/sched.h>
  14. #include <linux/seq_file.h>
  15. #include <linux/kallsyms.h>
  16. #include <linux/utsname.h>
  17. /*
  18. * This allows printing both to /proc/sched_debug and
  19. * to the console
  20. */
  21. #define SEQ_printf(m, x...) \
  22. do { \
  23. if (m) \
  24. seq_printf(m, x); \
  25. else \
  26. printk(x); \
  27. } while (0)
  28. /*
  29. * Ease the printing of nsec fields:
  30. */
  31. static long long nsec_high(unsigned long long nsec)
  32. {
  33. if ((long long)nsec < 0) {
  34. nsec = -nsec;
  35. do_div(nsec, 1000000);
  36. return -nsec;
  37. }
  38. do_div(nsec, 1000000);
  39. return nsec;
  40. }
  41. static unsigned long nsec_low(unsigned long long nsec)
  42. {
  43. if ((long long)nsec < 0)
  44. nsec = -nsec;
  45. return do_div(nsec, 1000000);
  46. }
  47. #define SPLIT_NS(x) nsec_high(x), nsec_low(x)
  48. #ifdef CONFIG_FAIR_GROUP_SCHED
  49. static void print_cfs_group_stats(struct seq_file *m, int cpu, struct task_group *tg)
  50. {
  51. struct sched_entity *se = tg->se[cpu];
  52. if (!se)
  53. return;
  54. #define P(F) \
  55. SEQ_printf(m, " .%-30s: %lld\n", #F, (long long)F)
  56. #define PN(F) \
  57. SEQ_printf(m, " .%-30s: %lld.%06ld\n", #F, SPLIT_NS((long long)F))
  58. PN(se->exec_start);
  59. PN(se->vruntime);
  60. PN(se->sum_exec_runtime);
  61. #ifdef CONFIG_SCHEDSTATS
  62. PN(se->statistics.wait_start);
  63. PN(se->statistics.sleep_start);
  64. PN(se->statistics.block_start);
  65. PN(se->statistics.sleep_max);
  66. PN(se->statistics.block_max);
  67. PN(se->statistics.exec_max);
  68. PN(se->statistics.slice_max);
  69. PN(se->statistics.wait_max);
  70. PN(se->statistics.wait_sum);
  71. P(se->statistics.wait_count);
  72. #endif
  73. P(se->load.weight);
  74. #undef PN
  75. #undef P
  76. }
  77. #endif
  78. static void
  79. print_task(struct seq_file *m, struct rq *rq, struct task_struct *p)
  80. {
  81. if (rq->curr == p)
  82. SEQ_printf(m, "R");
  83. else
  84. SEQ_printf(m, " ");
  85. SEQ_printf(m, "%15s %5d %9Ld.%06ld %9Ld %5d ",
  86. p->comm, p->pid,
  87. SPLIT_NS(p->se.vruntime),
  88. (long long)(p->nvcsw + p->nivcsw),
  89. p->prio);
  90. #ifdef CONFIG_SCHEDSTATS
  91. SEQ_printf(m, "%9Ld.%06ld %9Ld.%06ld %9Ld.%06ld",
  92. SPLIT_NS(p->se.vruntime),
  93. SPLIT_NS(p->se.sum_exec_runtime),
  94. SPLIT_NS(p->se.statistics.sum_sleep_runtime));
  95. #else
  96. SEQ_printf(m, "%15Ld %15Ld %15Ld.%06ld %15Ld.%06ld %15Ld.%06ld",
  97. 0LL, 0LL, 0LL, 0L, 0LL, 0L, 0LL, 0L);
  98. #endif
  99. SEQ_printf(m, "\n");
  100. }
  101. static void print_rq(struct seq_file *m, struct rq *rq, int rq_cpu)
  102. {
  103. struct task_struct *g, *p;
  104. unsigned long flags;
  105. SEQ_printf(m,
  106. "\nrunnable tasks:\n"
  107. " task PID tree-key switches prio"
  108. " exec-runtime sum-exec sum-sleep\n"
  109. "------------------------------------------------------"
  110. "----------------------------------------------------\n");
  111. read_lock_irqsave(&tasklist_lock, flags);
  112. do_each_thread(g, p) {
  113. if (!p->se.on_rq || task_cpu(p) != rq_cpu)
  114. continue;
  115. print_task(m, rq, p);
  116. } while_each_thread(g, p);
  117. read_unlock_irqrestore(&tasklist_lock, flags);
  118. }
  119. void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq)
  120. {
  121. s64 MIN_vruntime = -1, min_vruntime, max_vruntime = -1,
  122. spread, rq0_min_vruntime, spread0;
  123. struct rq *rq = cpu_rq(cpu);
  124. struct sched_entity *last;
  125. unsigned long flags;
  126. SEQ_printf(m, "\ncfs_rq[%d]:\n", cpu);
  127. SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "exec_clock",
  128. SPLIT_NS(cfs_rq->exec_clock));
  129. raw_spin_lock_irqsave(&rq->lock, flags);
  130. if (cfs_rq->rb_leftmost)
  131. MIN_vruntime = (__pick_next_entity(cfs_rq))->vruntime;
  132. last = __pick_last_entity(cfs_rq);
  133. if (last)
  134. max_vruntime = last->vruntime;
  135. min_vruntime = cfs_rq->min_vruntime;
  136. rq0_min_vruntime = cpu_rq(0)->cfs.min_vruntime;
  137. raw_spin_unlock_irqrestore(&rq->lock, flags);
  138. SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "MIN_vruntime",
  139. SPLIT_NS(MIN_vruntime));
  140. SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "min_vruntime",
  141. SPLIT_NS(min_vruntime));
  142. SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "max_vruntime",
  143. SPLIT_NS(max_vruntime));
  144. spread = max_vruntime - MIN_vruntime;
  145. SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "spread",
  146. SPLIT_NS(spread));
  147. spread0 = min_vruntime - rq0_min_vruntime;
  148. SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "spread0",
  149. SPLIT_NS(spread0));
  150. SEQ_printf(m, " .%-30s: %d\n", "nr_spread_over",
  151. cfs_rq->nr_spread_over);
  152. SEQ_printf(m, " .%-30s: %ld\n", "nr_running", cfs_rq->nr_running);
  153. SEQ_printf(m, " .%-30s: %ld\n", "load", cfs_rq->load.weight);
  154. #ifdef CONFIG_FAIR_GROUP_SCHED
  155. #ifdef CONFIG_SMP
  156. SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "load_avg",
  157. SPLIT_NS(cfs_rq->load_avg));
  158. SEQ_printf(m, " .%-30s: %Ld.%06ld\n", "load_period",
  159. SPLIT_NS(cfs_rq->load_period));
  160. SEQ_printf(m, " .%-30s: %ld\n", "load_contrib",
  161. cfs_rq->load_contribution);
  162. SEQ_printf(m, " .%-30s: %d\n", "load_tg",
  163. atomic_read(&cfs_rq->tg->load_weight));
  164. #endif
  165. print_cfs_group_stats(m, cpu, cfs_rq->tg);
  166. #endif
  167. }
  168. void print_rt_rq(struct seq_file *m, int cpu, struct rt_rq *rt_rq)
  169. {
  170. SEQ_printf(m, "\nrt_rq[%d]:\n", cpu);
  171. #define P(x) \
  172. SEQ_printf(m, " .%-30s: %Ld\n", #x, (long long)(rt_rq->x))
  173. #define PN(x) \
  174. SEQ_printf(m, " .%-30s: %Ld.%06ld\n", #x, SPLIT_NS(rt_rq->x))
  175. P(rt_nr_running);
  176. P(rt_throttled);
  177. PN(rt_time);
  178. PN(rt_runtime);
  179. #undef PN
  180. #undef P
  181. }
  182. extern __read_mostly int sched_clock_running;
  183. static void print_cpu(struct seq_file *m, int cpu)
  184. {
  185. struct rq *rq = cpu_rq(cpu);
  186. #ifdef CONFIG_X86
  187. {
  188. unsigned int freq = cpu_khz ? : 1;
  189. SEQ_printf(m, "\ncpu#%d, %u.%03u MHz\n",
  190. cpu, freq / 1000, (freq % 1000));
  191. }
  192. #else
  193. SEQ_printf(m, "\ncpu#%d\n", cpu);
  194. #endif
  195. #define P(x) \
  196. SEQ_printf(m, " .%-30s: %Ld\n", #x, (long long)(rq->x))
  197. #define PN(x) \
  198. SEQ_printf(m, " .%-30s: %Ld.%06ld\n", #x, SPLIT_NS(rq->x))
  199. P(nr_running);
  200. SEQ_printf(m, " .%-30s: %lu\n", "load",
  201. rq->load.weight);
  202. P(nr_switches);
  203. P(nr_load_updates);
  204. P(nr_uninterruptible);
  205. PN(next_balance);
  206. P(curr->pid);
  207. PN(clock);
  208. P(cpu_load[0]);
  209. P(cpu_load[1]);
  210. P(cpu_load[2]);
  211. P(cpu_load[3]);
  212. P(cpu_load[4]);
  213. #undef P
  214. #undef PN
  215. #ifdef CONFIG_SCHEDSTATS
  216. #define P(n) SEQ_printf(m, " .%-30s: %d\n", #n, rq->n);
  217. #define P64(n) SEQ_printf(m, " .%-30s: %Ld\n", #n, rq->n);
  218. P(yld_count);
  219. P(sched_switch);
  220. P(sched_count);
  221. P(sched_goidle);
  222. #ifdef CONFIG_SMP
  223. P64(avg_idle);
  224. #endif
  225. P(ttwu_count);
  226. P(ttwu_local);
  227. P(bkl_count);
  228. #undef P
  229. #endif
  230. print_cfs_stats(m, cpu);
  231. print_rt_stats(m, cpu);
  232. print_rq(m, rq, cpu);
  233. }
  234. static const char *sched_tunable_scaling_names[] = {
  235. "none",
  236. "logaritmic",
  237. "linear"
  238. };
  239. static int sched_debug_show(struct seq_file *m, void *v)
  240. {
  241. u64 ktime, sched_clk, cpu_clk;
  242. unsigned long flags;
  243. int cpu;
  244. local_irq_save(flags);
  245. ktime = ktime_to_ns(ktime_get());
  246. sched_clk = sched_clock();
  247. cpu_clk = local_clock();
  248. local_irq_restore(flags);
  249. SEQ_printf(m, "Sched Debug Version: v0.10, %s %.*s\n",
  250. init_utsname()->release,
  251. (int)strcspn(init_utsname()->version, " "),
  252. init_utsname()->version);
  253. #define P(x) \
  254. SEQ_printf(m, "%-40s: %Ld\n", #x, (long long)(x))
  255. #define PN(x) \
  256. SEQ_printf(m, "%-40s: %Ld.%06ld\n", #x, SPLIT_NS(x))
  257. PN(ktime);
  258. PN(sched_clk);
  259. PN(cpu_clk);
  260. P(jiffies);
  261. #ifdef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
  262. P(sched_clock_stable);
  263. #endif
  264. #undef PN
  265. #undef P
  266. SEQ_printf(m, "\n");
  267. SEQ_printf(m, "sysctl_sched\n");
  268. #define P(x) \
  269. SEQ_printf(m, " .%-40s: %Ld\n", #x, (long long)(x))
  270. #define PN(x) \
  271. SEQ_printf(m, " .%-40s: %Ld.%06ld\n", #x, SPLIT_NS(x))
  272. PN(sysctl_sched_latency);
  273. PN(sysctl_sched_min_granularity);
  274. PN(sysctl_sched_wakeup_granularity);
  275. P(sysctl_sched_child_runs_first);
  276. P(sysctl_sched_features);
  277. #undef PN
  278. #undef P
  279. SEQ_printf(m, " .%-40s: %d (%s)\n", "sysctl_sched_tunable_scaling",
  280. sysctl_sched_tunable_scaling,
  281. sched_tunable_scaling_names[sysctl_sched_tunable_scaling]);
  282. for_each_online_cpu(cpu)
  283. print_cpu(m, cpu);
  284. SEQ_printf(m, "\n");
  285. return 0;
  286. }
  287. static void sysrq_sched_debug_show(void)
  288. {
  289. sched_debug_show(NULL, NULL);
  290. }
  291. static int sched_debug_open(struct inode *inode, struct file *filp)
  292. {
  293. return single_open(filp, sched_debug_show, NULL);
  294. }
  295. static const struct file_operations sched_debug_fops = {
  296. .open = sched_debug_open,
  297. .read = seq_read,
  298. .llseek = seq_lseek,
  299. .release = single_release,
  300. };
  301. static int __init init_sched_debug_procfs(void)
  302. {
  303. struct proc_dir_entry *pe;
  304. pe = proc_create("sched_debug", 0444, NULL, &sched_debug_fops);
  305. if (!pe)
  306. return -ENOMEM;
  307. return 0;
  308. }
  309. __initcall(init_sched_debug_procfs);
  310. void proc_sched_show_task(struct task_struct *p, struct seq_file *m)
  311. {
  312. unsigned long nr_switches;
  313. SEQ_printf(m, "%s (%d, #threads: %d)\n", p->comm, p->pid,
  314. get_nr_threads(p));
  315. SEQ_printf(m,
  316. "---------------------------------------------------------\n");
  317. #define __P(F) \
  318. SEQ_printf(m, "%-35s:%21Ld\n", #F, (long long)F)
  319. #define P(F) \
  320. SEQ_printf(m, "%-35s:%21Ld\n", #F, (long long)p->F)
  321. #define __PN(F) \
  322. SEQ_printf(m, "%-35s:%14Ld.%06ld\n", #F, SPLIT_NS((long long)F))
  323. #define PN(F) \
  324. SEQ_printf(m, "%-35s:%14Ld.%06ld\n", #F, SPLIT_NS((long long)p->F))
  325. PN(se.exec_start);
  326. PN(se.vruntime);
  327. PN(se.sum_exec_runtime);
  328. nr_switches = p->nvcsw + p->nivcsw;
  329. #ifdef CONFIG_SCHEDSTATS
  330. PN(se.statistics.wait_start);
  331. PN(se.statistics.sleep_start);
  332. PN(se.statistics.block_start);
  333. PN(se.statistics.sleep_max);
  334. PN(se.statistics.block_max);
  335. PN(se.statistics.exec_max);
  336. PN(se.statistics.slice_max);
  337. PN(se.statistics.wait_max);
  338. PN(se.statistics.wait_sum);
  339. P(se.statistics.wait_count);
  340. PN(se.statistics.iowait_sum);
  341. P(se.statistics.iowait_count);
  342. P(sched_info.bkl_count);
  343. P(se.nr_migrations);
  344. P(se.statistics.nr_migrations_cold);
  345. P(se.statistics.nr_failed_migrations_affine);
  346. P(se.statistics.nr_failed_migrations_running);
  347. P(se.statistics.nr_failed_migrations_hot);
  348. P(se.statistics.nr_forced_migrations);
  349. P(se.statistics.nr_wakeups);
  350. P(se.statistics.nr_wakeups_sync);
  351. P(se.statistics.nr_wakeups_migrate);
  352. P(se.statistics.nr_wakeups_local);
  353. P(se.statistics.nr_wakeups_remote);
  354. P(se.statistics.nr_wakeups_affine);
  355. P(se.statistics.nr_wakeups_affine_attempts);
  356. P(se.statistics.nr_wakeups_passive);
  357. P(se.statistics.nr_wakeups_idle);
  358. {
  359. u64 avg_atom, avg_per_cpu;
  360. avg_atom = p->se.sum_exec_runtime;
  361. if (nr_switches)
  362. do_div(avg_atom, nr_switches);
  363. else
  364. avg_atom = -1LL;
  365. avg_per_cpu = p->se.sum_exec_runtime;
  366. if (p->se.nr_migrations) {
  367. avg_per_cpu = div64_u64(avg_per_cpu,
  368. p->se.nr_migrations);
  369. } else {
  370. avg_per_cpu = -1LL;
  371. }
  372. __PN(avg_atom);
  373. __PN(avg_per_cpu);
  374. }
  375. #endif
  376. __P(nr_switches);
  377. SEQ_printf(m, "%-35s:%21Ld\n",
  378. "nr_voluntary_switches", (long long)p->nvcsw);
  379. SEQ_printf(m, "%-35s:%21Ld\n",
  380. "nr_involuntary_switches", (long long)p->nivcsw);
  381. P(se.load.weight);
  382. P(policy);
  383. P(prio);
  384. #undef PN
  385. #undef __PN
  386. #undef P
  387. #undef __P
  388. {
  389. unsigned int this_cpu = raw_smp_processor_id();
  390. u64 t0, t1;
  391. t0 = cpu_clock(this_cpu);
  392. t1 = cpu_clock(this_cpu);
  393. SEQ_printf(m, "%-35s:%21Ld\n",
  394. "clock-delta", (long long)(t1-t0));
  395. }
  396. }
  397. void proc_sched_set_task(struct task_struct *p)
  398. {
  399. #ifdef CONFIG_SCHEDSTATS
  400. memset(&p->se.statistics, 0, sizeof(p->se.statistics));
  401. #endif
  402. }