sched_debug.c 6.0 KB

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