stats.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #include <linux/slab.h>
  2. #include <linux/fs.h>
  3. #include <linux/seq_file.h>
  4. #include <linux/proc_fs.h>
  5. #include "sched.h"
  6. /*
  7. * bump this up when changing the output format or the meaning of an existing
  8. * format, so that tools can adapt (or abort)
  9. */
  10. #define SCHEDSTAT_VERSION 15
  11. static int show_schedstat(struct seq_file *seq, void *v)
  12. {
  13. int cpu;
  14. if (v == (void *)1) {
  15. seq_printf(seq, "version %d\n", SCHEDSTAT_VERSION);
  16. seq_printf(seq, "timestamp %lu\n", jiffies);
  17. } else {
  18. struct rq *rq;
  19. #ifdef CONFIG_SMP
  20. struct sched_domain *sd;
  21. int dcount = 0;
  22. #endif
  23. cpu = (unsigned long)(v - 2);
  24. rq = cpu_rq(cpu);
  25. /* runqueue-specific stats */
  26. seq_printf(seq,
  27. "cpu%d %u 0 %u %u %u %u %llu %llu %lu",
  28. cpu, rq->yld_count,
  29. rq->sched_count, rq->sched_goidle,
  30. rq->ttwu_count, rq->ttwu_local,
  31. rq->rq_cpu_time,
  32. rq->rq_sched_info.run_delay, rq->rq_sched_info.pcount);
  33. seq_printf(seq, "\n");
  34. #ifdef CONFIG_SMP
  35. /* domain-specific stats */
  36. rcu_read_lock();
  37. for_each_domain(cpu, sd) {
  38. enum cpu_idle_type itype;
  39. seq_printf(seq, "domain%d %*pb", dcount++,
  40. cpumask_pr_args(sched_domain_span(sd)));
  41. for (itype = CPU_IDLE; itype < CPU_MAX_IDLE_TYPES;
  42. itype++) {
  43. seq_printf(seq, " %u %u %u %u %u %u %u %u",
  44. sd->lb_count[itype],
  45. sd->lb_balanced[itype],
  46. sd->lb_failed[itype],
  47. sd->lb_imbalance[itype],
  48. sd->lb_gained[itype],
  49. sd->lb_hot_gained[itype],
  50. sd->lb_nobusyq[itype],
  51. sd->lb_nobusyg[itype]);
  52. }
  53. seq_printf(seq,
  54. " %u %u %u %u %u %u %u %u %u %u %u %u\n",
  55. sd->alb_count, sd->alb_failed, sd->alb_pushed,
  56. sd->sbe_count, sd->sbe_balanced, sd->sbe_pushed,
  57. sd->sbf_count, sd->sbf_balanced, sd->sbf_pushed,
  58. sd->ttwu_wake_remote, sd->ttwu_move_affine,
  59. sd->ttwu_move_balance);
  60. }
  61. rcu_read_unlock();
  62. #endif
  63. }
  64. return 0;
  65. }
  66. /*
  67. * This itererator needs some explanation.
  68. * It returns 1 for the header position.
  69. * This means 2 is cpu 0.
  70. * In a hotplugged system some cpus, including cpu 0, may be missing so we have
  71. * to use cpumask_* to iterate over the cpus.
  72. */
  73. static void *schedstat_start(struct seq_file *file, loff_t *offset)
  74. {
  75. unsigned long n = *offset;
  76. if (n == 0)
  77. return (void *) 1;
  78. n--;
  79. if (n > 0)
  80. n = cpumask_next(n - 1, cpu_online_mask);
  81. else
  82. n = cpumask_first(cpu_online_mask);
  83. *offset = n + 1;
  84. if (n < nr_cpu_ids)
  85. return (void *)(unsigned long)(n + 2);
  86. return NULL;
  87. }
  88. static void *schedstat_next(struct seq_file *file, void *data, loff_t *offset)
  89. {
  90. (*offset)++;
  91. return schedstat_start(file, offset);
  92. }
  93. static void schedstat_stop(struct seq_file *file, void *data)
  94. {
  95. }
  96. static const struct seq_operations schedstat_sops = {
  97. .start = schedstat_start,
  98. .next = schedstat_next,
  99. .stop = schedstat_stop,
  100. .show = show_schedstat,
  101. };
  102. static int schedstat_open(struct inode *inode, struct file *file)
  103. {
  104. return seq_open(file, &schedstat_sops);
  105. }
  106. static const struct file_operations proc_schedstat_operations = {
  107. .open = schedstat_open,
  108. .read = seq_read,
  109. .llseek = seq_lseek,
  110. .release = seq_release,
  111. };
  112. static int __init proc_schedstat_init(void)
  113. {
  114. proc_create("schedstat", 0, NULL, &proc_schedstat_operations);
  115. return 0;
  116. }
  117. subsys_initcall(proc_schedstat_init);