sched_debug.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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. static void
  29. print_task(struct seq_file *m, struct rq *rq, struct task_struct *p)
  30. {
  31. if (rq->curr == p)
  32. SEQ_printf(m, "R");
  33. else
  34. SEQ_printf(m, " ");
  35. SEQ_printf(m, "%15s %5d %15Ld %13Ld %13Ld %9Ld %5d ",
  36. p->comm, p->pid,
  37. (long long)p->se.fair_key,
  38. (long long)(p->se.fair_key - rq->cfs.fair_clock),
  39. (long long)p->se.wait_runtime,
  40. (long long)(p->nvcsw + p->nivcsw),
  41. p->prio);
  42. #ifdef CONFIG_SCHEDSTATS
  43. SEQ_printf(m, "%15Ld %15Ld %15Ld %15Ld %15Ld\n",
  44. (long long)p->se.sum_exec_runtime,
  45. (long long)p->se.sum_wait_runtime,
  46. (long long)p->se.sum_sleep_runtime,
  47. (long long)p->se.wait_runtime_overruns,
  48. (long long)p->se.wait_runtime_underruns);
  49. #else
  50. SEQ_printf(m, "%15Ld %15Ld %15Ld %15Ld %15Ld\n",
  51. 0LL, 0LL, 0LL, 0LL, 0LL);
  52. #endif
  53. }
  54. static void print_rq(struct seq_file *m, struct rq *rq, int rq_cpu)
  55. {
  56. struct task_struct *g, *p;
  57. SEQ_printf(m,
  58. "\nrunnable tasks:\n"
  59. " task PID tree-key delta waiting"
  60. " switches prio"
  61. " sum-exec sum-wait sum-sleep"
  62. " wait-overrun wait-underrun\n"
  63. "------------------------------------------------------------------"
  64. "----------------"
  65. "------------------------------------------------"
  66. "--------------------------------\n");
  67. read_lock_irq(&tasklist_lock);
  68. do_each_thread(g, p) {
  69. if (!p->se.on_rq || task_cpu(p) != rq_cpu)
  70. continue;
  71. print_task(m, rq, p);
  72. } while_each_thread(g, p);
  73. read_unlock_irq(&tasklist_lock);
  74. }
  75. static void
  76. print_cfs_rq_runtime_sum(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq)
  77. {
  78. s64 wait_runtime_rq_sum = 0;
  79. struct task_struct *p;
  80. struct rb_node *curr;
  81. unsigned long flags;
  82. struct rq *rq = &per_cpu(runqueues, cpu);
  83. spin_lock_irqsave(&rq->lock, flags);
  84. curr = first_fair(cfs_rq);
  85. while (curr) {
  86. p = rb_entry(curr, struct task_struct, se.run_node);
  87. wait_runtime_rq_sum += p->se.wait_runtime;
  88. curr = rb_next(curr);
  89. }
  90. spin_unlock_irqrestore(&rq->lock, flags);
  91. SEQ_printf(m, " .%-30s: %Ld\n", "wait_runtime_rq_sum",
  92. (long long)wait_runtime_rq_sum);
  93. }
  94. void print_cfs_rq(struct seq_file *m, int cpu, struct cfs_rq *cfs_rq)
  95. {
  96. SEQ_printf(m, "\ncfs_rq\n");
  97. #define P(x) \
  98. SEQ_printf(m, " .%-30s: %Ld\n", #x, (long long)(cfs_rq->x))
  99. P(fair_clock);
  100. P(exec_clock);
  101. P(wait_runtime);
  102. P(wait_runtime_overruns);
  103. P(wait_runtime_underruns);
  104. P(sleeper_bonus);
  105. #undef P
  106. print_cfs_rq_runtime_sum(m, cpu, cfs_rq);
  107. }
  108. static void print_cpu(struct seq_file *m, int cpu)
  109. {
  110. struct rq *rq = &per_cpu(runqueues, cpu);
  111. #ifdef CONFIG_X86
  112. {
  113. unsigned int freq = cpu_khz ? : 1;
  114. SEQ_printf(m, "\ncpu#%d, %u.%03u MHz\n",
  115. cpu, freq / 1000, (freq % 1000));
  116. }
  117. #else
  118. SEQ_printf(m, "\ncpu#%d\n", cpu);
  119. #endif
  120. #define P(x) \
  121. SEQ_printf(m, " .%-30s: %Ld\n", #x, (long long)(rq->x))
  122. P(nr_running);
  123. SEQ_printf(m, " .%-30s: %lu\n", "load",
  124. rq->ls.load.weight);
  125. P(ls.delta_fair);
  126. P(ls.delta_exec);
  127. P(nr_switches);
  128. P(nr_load_updates);
  129. P(nr_uninterruptible);
  130. SEQ_printf(m, " .%-30s: %lu\n", "jiffies", jiffies);
  131. P(next_balance);
  132. P(curr->pid);
  133. P(clock);
  134. P(idle_clock);
  135. P(prev_clock_raw);
  136. P(clock_warps);
  137. P(clock_overflows);
  138. P(clock_deep_idle_events);
  139. P(clock_max_delta);
  140. P(cpu_load[0]);
  141. P(cpu_load[1]);
  142. P(cpu_load[2]);
  143. P(cpu_load[3]);
  144. P(cpu_load[4]);
  145. #undef P
  146. print_cfs_stats(m, cpu);
  147. print_rq(m, rq, cpu);
  148. }
  149. static int sched_debug_show(struct seq_file *m, void *v)
  150. {
  151. u64 now = ktime_to_ns(ktime_get());
  152. int cpu;
  153. SEQ_printf(m, "Sched Debug Version: v0.05-v20, %s %.*s\n",
  154. init_utsname()->release,
  155. (int)strcspn(init_utsname()->version, " "),
  156. init_utsname()->version);
  157. SEQ_printf(m, "now at %Lu nsecs\n", (unsigned long long)now);
  158. for_each_online_cpu(cpu)
  159. print_cpu(m, cpu);
  160. SEQ_printf(m, "\n");
  161. return 0;
  162. }
  163. static void sysrq_sched_debug_show(void)
  164. {
  165. sched_debug_show(NULL, NULL);
  166. }
  167. static int sched_debug_open(struct inode *inode, struct file *filp)
  168. {
  169. return single_open(filp, sched_debug_show, NULL);
  170. }
  171. static struct file_operations sched_debug_fops = {
  172. .open = sched_debug_open,
  173. .read = seq_read,
  174. .llseek = seq_lseek,
  175. .release = single_release,
  176. };
  177. static int __init init_sched_debug_procfs(void)
  178. {
  179. struct proc_dir_entry *pe;
  180. pe = create_proc_entry("sched_debug", 0644, NULL);
  181. if (!pe)
  182. return -ENOMEM;
  183. pe->proc_fops = &sched_debug_fops;
  184. return 0;
  185. }
  186. __initcall(init_sched_debug_procfs);
  187. void proc_sched_show_task(struct task_struct *p, struct seq_file *m)
  188. {
  189. unsigned long flags;
  190. int num_threads = 1;
  191. rcu_read_lock();
  192. if (lock_task_sighand(p, &flags)) {
  193. num_threads = atomic_read(&p->signal->count);
  194. unlock_task_sighand(p, &flags);
  195. }
  196. rcu_read_unlock();
  197. SEQ_printf(m, "%s (%d, #threads: %d)\n", p->comm, p->pid, num_threads);
  198. SEQ_printf(m, "----------------------------------------------\n");
  199. #define P(F) \
  200. SEQ_printf(m, "%-25s:%20Ld\n", #F, (long long)p->F)
  201. P(se.wait_runtime);
  202. P(se.wait_start_fair);
  203. P(se.exec_start);
  204. P(se.sleep_start_fair);
  205. P(se.sum_exec_runtime);
  206. #ifdef CONFIG_SCHEDSTATS
  207. P(se.wait_start);
  208. P(se.sleep_start);
  209. P(se.block_start);
  210. P(se.sleep_max);
  211. P(se.block_max);
  212. P(se.exec_max);
  213. P(se.wait_max);
  214. P(se.wait_runtime_overruns);
  215. P(se.wait_runtime_underruns);
  216. P(se.sum_wait_runtime);
  217. #endif
  218. SEQ_printf(m, "%-25s:%20Ld\n",
  219. "nr_switches", (long long)(p->nvcsw + p->nivcsw));
  220. P(se.load.weight);
  221. P(policy);
  222. P(prio);
  223. #undef P
  224. {
  225. u64 t0, t1;
  226. t0 = sched_clock();
  227. t1 = sched_clock();
  228. SEQ_printf(m, "%-25s:%20Ld\n",
  229. "clock-delta", (long long)(t1-t0));
  230. }
  231. }
  232. void proc_sched_set_task(struct task_struct *p)
  233. {
  234. #ifdef CONFIG_SCHEDSTATS
  235. p->se.sleep_max = p->se.block_max = p->se.exec_max = p->se.wait_max = 0;
  236. p->se.wait_runtime_overruns = p->se.wait_runtime_underruns = 0;
  237. #endif
  238. p->se.sum_exec_runtime = 0;
  239. p->se.prev_sum_exec_runtime = 0;
  240. }