rcutree_trace.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /*
  2. * Read-Copy Update tracing for classic implementation
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. *
  18. * Copyright IBM Corporation, 2008
  19. *
  20. * Papers: http://www.rdrop.com/users/paulmck/RCU
  21. *
  22. * For detailed explanation of Read-Copy Update mechanism see -
  23. * Documentation/RCU
  24. *
  25. */
  26. #include <linux/types.h>
  27. #include <linux/kernel.h>
  28. #include <linux/init.h>
  29. #include <linux/spinlock.h>
  30. #include <linux/smp.h>
  31. #include <linux/rcupdate.h>
  32. #include <linux/interrupt.h>
  33. #include <linux/sched.h>
  34. #include <asm/atomic.h>
  35. #include <linux/bitops.h>
  36. #include <linux/module.h>
  37. #include <linux/completion.h>
  38. #include <linux/moduleparam.h>
  39. #include <linux/percpu.h>
  40. #include <linux/notifier.h>
  41. #include <linux/cpu.h>
  42. #include <linux/mutex.h>
  43. #include <linux/debugfs.h>
  44. #include <linux/seq_file.h>
  45. #include "rcutree.h"
  46. static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
  47. {
  48. if (!rdp->beenonline)
  49. return;
  50. seq_printf(m, "%3d%cc=%ld g=%ld pq=%d pqc=%ld qp=%d rpfq=%ld rp=%x",
  51. rdp->cpu,
  52. cpu_is_offline(rdp->cpu) ? '!' : ' ',
  53. rdp->completed, rdp->gpnum,
  54. rdp->passed_quiesc, rdp->passed_quiesc_completed,
  55. rdp->qs_pending,
  56. rdp->n_rcu_pending_force_qs - rdp->n_rcu_pending,
  57. (int)(rdp->n_rcu_pending & 0xffff));
  58. #ifdef CONFIG_NO_HZ
  59. seq_printf(m, " dt=%d/%d dn=%d df=%lu",
  60. rdp->dynticks->dynticks,
  61. rdp->dynticks->dynticks_nesting,
  62. rdp->dynticks->dynticks_nmi,
  63. rdp->dynticks_fqs);
  64. #endif /* #ifdef CONFIG_NO_HZ */
  65. seq_printf(m, " of=%lu ri=%lu", rdp->offline_fqs, rdp->resched_ipi);
  66. seq_printf(m, " ql=%ld b=%ld\n", rdp->qlen, rdp->blimit);
  67. }
  68. #define PRINT_RCU_DATA(name, func, m) \
  69. do { \
  70. int _p_r_d_i; \
  71. \
  72. for_each_possible_cpu(_p_r_d_i) \
  73. func(m, &per_cpu(name, _p_r_d_i)); \
  74. } while (0)
  75. static int show_rcudata(struct seq_file *m, void *unused)
  76. {
  77. seq_puts(m, "rcu:\n");
  78. PRINT_RCU_DATA(rcu_data, print_one_rcu_data, m);
  79. seq_puts(m, "rcu_bh:\n");
  80. PRINT_RCU_DATA(rcu_bh_data, print_one_rcu_data, m);
  81. return 0;
  82. }
  83. static int rcudata_open(struct inode *inode, struct file *file)
  84. {
  85. return single_open(file, show_rcudata, NULL);
  86. }
  87. static struct file_operations rcudata_fops = {
  88. .owner = THIS_MODULE,
  89. .open = rcudata_open,
  90. .read = seq_read,
  91. .llseek = seq_lseek,
  92. .release = single_release,
  93. };
  94. static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
  95. {
  96. if (!rdp->beenonline)
  97. return;
  98. seq_printf(m, "%d,%s,%ld,%ld,%d,%ld,%d,%ld,%ld",
  99. rdp->cpu,
  100. cpu_is_offline(rdp->cpu) ? "\"Y\"" : "\"N\"",
  101. rdp->completed, rdp->gpnum,
  102. rdp->passed_quiesc, rdp->passed_quiesc_completed,
  103. rdp->qs_pending,
  104. rdp->n_rcu_pending_force_qs - rdp->n_rcu_pending,
  105. rdp->n_rcu_pending);
  106. #ifdef CONFIG_NO_HZ
  107. seq_printf(m, ",%d,%d,%d,%lu",
  108. rdp->dynticks->dynticks,
  109. rdp->dynticks->dynticks_nesting,
  110. rdp->dynticks->dynticks_nmi,
  111. rdp->dynticks_fqs);
  112. #endif /* #ifdef CONFIG_NO_HZ */
  113. seq_printf(m, ",%lu,%lu", rdp->offline_fqs, rdp->resched_ipi);
  114. seq_printf(m, ",%ld,%ld\n", rdp->qlen, rdp->blimit);
  115. }
  116. static int show_rcudata_csv(struct seq_file *m, void *unused)
  117. {
  118. seq_puts(m, "\"CPU\",\"Online?\",\"c\",\"g\",\"pq\",\"pqc\",\"pq\",\"rpfq\",\"rp\",");
  119. #ifdef CONFIG_NO_HZ
  120. seq_puts(m, "\"dt\",\"dt nesting\",\"dn\",\"df\",");
  121. #endif /* #ifdef CONFIG_NO_HZ */
  122. seq_puts(m, "\"of\",\"ri\",\"ql\",\"b\"\n");
  123. seq_puts(m, "\"rcu:\"\n");
  124. PRINT_RCU_DATA(rcu_data, print_one_rcu_data_csv, m);
  125. seq_puts(m, "\"rcu_bh:\"\n");
  126. PRINT_RCU_DATA(rcu_bh_data, print_one_rcu_data_csv, m);
  127. return 0;
  128. }
  129. static int rcudata_csv_open(struct inode *inode, struct file *file)
  130. {
  131. return single_open(file, show_rcudata_csv, NULL);
  132. }
  133. static struct file_operations rcudata_csv_fops = {
  134. .owner = THIS_MODULE,
  135. .open = rcudata_csv_open,
  136. .read = seq_read,
  137. .llseek = seq_lseek,
  138. .release = single_release,
  139. };
  140. static void print_one_rcu_state(struct seq_file *m, struct rcu_state *rsp)
  141. {
  142. int level = 0;
  143. struct rcu_node *rnp;
  144. seq_printf(m, "c=%ld g=%ld s=%d jfq=%ld j=%x "
  145. "nfqs=%lu/nfqsng=%lu(%lu) fqlh=%lu\n",
  146. rsp->completed, rsp->gpnum, rsp->signaled,
  147. (long)(rsp->jiffies_force_qs - jiffies),
  148. (int)(jiffies & 0xffff),
  149. rsp->n_force_qs, rsp->n_force_qs_ngp,
  150. rsp->n_force_qs - rsp->n_force_qs_ngp,
  151. rsp->n_force_qs_lh);
  152. for (rnp = &rsp->node[0]; rnp - &rsp->node[0] < NUM_RCU_NODES; rnp++) {
  153. if (rnp->level != level) {
  154. seq_puts(m, "\n");
  155. level = rnp->level;
  156. }
  157. seq_printf(m, "%lx/%lx %d:%d ^%d ",
  158. rnp->qsmask, rnp->qsmaskinit,
  159. rnp->grplo, rnp->grphi, rnp->grpnum);
  160. }
  161. seq_puts(m, "\n");
  162. }
  163. static int show_rcuhier(struct seq_file *m, void *unused)
  164. {
  165. seq_puts(m, "rcu:\n");
  166. print_one_rcu_state(m, &rcu_state);
  167. seq_puts(m, "rcu_bh:\n");
  168. print_one_rcu_state(m, &rcu_bh_state);
  169. return 0;
  170. }
  171. static int rcuhier_open(struct inode *inode, struct file *file)
  172. {
  173. return single_open(file, show_rcuhier, NULL);
  174. }
  175. static struct file_operations rcuhier_fops = {
  176. .owner = THIS_MODULE,
  177. .open = rcuhier_open,
  178. .read = seq_read,
  179. .llseek = seq_lseek,
  180. .release = single_release,
  181. };
  182. static int show_rcugp(struct seq_file *m, void *unused)
  183. {
  184. seq_printf(m, "rcu: completed=%ld gpnum=%ld\n",
  185. rcu_state.completed, rcu_state.gpnum);
  186. seq_printf(m, "rcu_bh: completed=%ld gpnum=%ld\n",
  187. rcu_bh_state.completed, rcu_bh_state.gpnum);
  188. return 0;
  189. }
  190. static int rcugp_open(struct inode *inode, struct file *file)
  191. {
  192. return single_open(file, show_rcugp, NULL);
  193. }
  194. static struct file_operations rcugp_fops = {
  195. .owner = THIS_MODULE,
  196. .open = rcugp_open,
  197. .read = seq_read,
  198. .llseek = seq_lseek,
  199. .release = single_release,
  200. };
  201. static struct dentry *rcudir, *datadir, *datadir_csv, *hierdir, *gpdir;
  202. static int __init rcuclassic_trace_init(void)
  203. {
  204. rcudir = debugfs_create_dir("rcu", NULL);
  205. if (!rcudir)
  206. goto out;
  207. datadir = debugfs_create_file("rcudata", 0444, rcudir,
  208. NULL, &rcudata_fops);
  209. if (!datadir)
  210. goto free_out;
  211. datadir_csv = debugfs_create_file("rcudata.csv", 0444, rcudir,
  212. NULL, &rcudata_csv_fops);
  213. if (!datadir_csv)
  214. goto free_out;
  215. gpdir = debugfs_create_file("rcugp", 0444, rcudir, NULL, &rcugp_fops);
  216. if (!gpdir)
  217. goto free_out;
  218. hierdir = debugfs_create_file("rcuhier", 0444, rcudir,
  219. NULL, &rcuhier_fops);
  220. if (!hierdir)
  221. goto free_out;
  222. return 0;
  223. free_out:
  224. if (datadir)
  225. debugfs_remove(datadir);
  226. if (datadir_csv)
  227. debugfs_remove(datadir_csv);
  228. if (gpdir)
  229. debugfs_remove(gpdir);
  230. debugfs_remove(rcudir);
  231. out:
  232. return 1;
  233. }
  234. static void __exit rcuclassic_trace_cleanup(void)
  235. {
  236. debugfs_remove(datadir);
  237. debugfs_remove(datadir_csv);
  238. debugfs_remove(gpdir);
  239. debugfs_remove(hierdir);
  240. debugfs_remove(rcudir);
  241. }
  242. module_init(rcuclassic_trace_init);
  243. module_exit(rcuclassic_trace_cleanup);
  244. MODULE_AUTHOR("Paul E. McKenney");
  245. MODULE_DESCRIPTION("Read-Copy Update tracing for hierarchical implementation");
  246. MODULE_LICENSE("GPL");