sched_debug.c 6.1 KB

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