rcutree_trace.c 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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. #define RCU_TREE_NONCORE
  46. #include "rcutree.h"
  47. static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
  48. {
  49. if (!rdp->beenonline)
  50. return;
  51. seq_printf(m, "%3d%cc=%ld g=%ld pq=%d pqc=%ld qp=%d",
  52. rdp->cpu,
  53. cpu_is_offline(rdp->cpu) ? '!' : ' ',
  54. rdp->completed, rdp->gpnum,
  55. rdp->passed_quiesc, rdp->passed_quiesc_completed,
  56. rdp->qs_pending);
  57. #ifdef CONFIG_NO_HZ
  58. seq_printf(m, " dt=%d/%d dn=%d df=%lu",
  59. rdp->dynticks->dynticks,
  60. rdp->dynticks->dynticks_nesting,
  61. rdp->dynticks->dynticks_nmi,
  62. rdp->dynticks_fqs);
  63. #endif /* #ifdef CONFIG_NO_HZ */
  64. seq_printf(m, " of=%lu ri=%lu", rdp->offline_fqs, rdp->resched_ipi);
  65. seq_printf(m, " ql=%ld b=%ld\n", rdp->qlen, rdp->blimit);
  66. }
  67. #define PRINT_RCU_DATA(name, func, m) \
  68. do { \
  69. int _p_r_d_i; \
  70. \
  71. for_each_possible_cpu(_p_r_d_i) \
  72. func(m, &per_cpu(name, _p_r_d_i)); \
  73. } while (0)
  74. static int show_rcudata(struct seq_file *m, void *unused)
  75. {
  76. seq_puts(m, "rcu_sched:\n");
  77. PRINT_RCU_DATA(rcu_sched_data, print_one_rcu_data, m);
  78. seq_puts(m, "rcu_bh:\n");
  79. PRINT_RCU_DATA(rcu_bh_data, print_one_rcu_data, m);
  80. return 0;
  81. }
  82. static int rcudata_open(struct inode *inode, struct file *file)
  83. {
  84. return single_open(file, show_rcudata, NULL);
  85. }
  86. static struct file_operations rcudata_fops = {
  87. .owner = THIS_MODULE,
  88. .open = rcudata_open,
  89. .read = seq_read,
  90. .llseek = seq_lseek,
  91. .release = single_release,
  92. };
  93. static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
  94. {
  95. if (!rdp->beenonline)
  96. return;
  97. seq_printf(m, "%d,%s,%ld,%ld,%d,%ld,%d",
  98. rdp->cpu,
  99. cpu_is_offline(rdp->cpu) ? "\"Y\"" : "\"N\"",
  100. rdp->completed, rdp->gpnum,
  101. rdp->passed_quiesc, rdp->passed_quiesc_completed,
  102. rdp->qs_pending);
  103. #ifdef CONFIG_NO_HZ
  104. seq_printf(m, ",%d,%d,%d,%lu",
  105. rdp->dynticks->dynticks,
  106. rdp->dynticks->dynticks_nesting,
  107. rdp->dynticks->dynticks_nmi,
  108. rdp->dynticks_fqs);
  109. #endif /* #ifdef CONFIG_NO_HZ */
  110. seq_printf(m, ",%lu,%lu", rdp->offline_fqs, rdp->resched_ipi);
  111. seq_printf(m, ",%ld,%ld\n", rdp->qlen, rdp->blimit);
  112. }
  113. static int show_rcudata_csv(struct seq_file *m, void *unused)
  114. {
  115. seq_puts(m, "\"CPU\",\"Online?\",\"c\",\"g\",\"pq\",\"pqc\",\"pq\",");
  116. #ifdef CONFIG_NO_HZ
  117. seq_puts(m, "\"dt\",\"dt nesting\",\"dn\",\"df\",");
  118. #endif /* #ifdef CONFIG_NO_HZ */
  119. seq_puts(m, "\"of\",\"ri\",\"ql\",\"b\"\n");
  120. seq_puts(m, "\"rcu_sched:\"\n");
  121. PRINT_RCU_DATA(rcu_sched_data, print_one_rcu_data_csv, m);
  122. seq_puts(m, "\"rcu_bh:\"\n");
  123. PRINT_RCU_DATA(rcu_bh_data, print_one_rcu_data_csv, m);
  124. return 0;
  125. }
  126. static int rcudata_csv_open(struct inode *inode, struct file *file)
  127. {
  128. return single_open(file, show_rcudata_csv, NULL);
  129. }
  130. static struct file_operations rcudata_csv_fops = {
  131. .owner = THIS_MODULE,
  132. .open = rcudata_csv_open,
  133. .read = seq_read,
  134. .llseek = seq_lseek,
  135. .release = single_release,
  136. };
  137. static void print_one_rcu_state(struct seq_file *m, struct rcu_state *rsp)
  138. {
  139. int level = 0;
  140. struct rcu_node *rnp;
  141. seq_printf(m, "c=%ld g=%ld s=%d jfq=%ld j=%x "
  142. "nfqs=%lu/nfqsng=%lu(%lu) fqlh=%lu\n",
  143. rsp->completed, rsp->gpnum, rsp->signaled,
  144. (long)(rsp->jiffies_force_qs - jiffies),
  145. (int)(jiffies & 0xffff),
  146. rsp->n_force_qs, rsp->n_force_qs_ngp,
  147. rsp->n_force_qs - rsp->n_force_qs_ngp,
  148. rsp->n_force_qs_lh);
  149. for (rnp = &rsp->node[0]; rnp - &rsp->node[0] < NUM_RCU_NODES; rnp++) {
  150. if (rnp->level != level) {
  151. seq_puts(m, "\n");
  152. level = rnp->level;
  153. }
  154. seq_printf(m, "%lx/%lx %d:%d ^%d ",
  155. rnp->qsmask, rnp->qsmaskinit,
  156. rnp->grplo, rnp->grphi, rnp->grpnum);
  157. }
  158. seq_puts(m, "\n");
  159. }
  160. static int show_rcuhier(struct seq_file *m, void *unused)
  161. {
  162. seq_puts(m, "rcu_sched:\n");
  163. print_one_rcu_state(m, &rcu_sched_state);
  164. seq_puts(m, "rcu_bh:\n");
  165. print_one_rcu_state(m, &rcu_bh_state);
  166. return 0;
  167. }
  168. static int rcuhier_open(struct inode *inode, struct file *file)
  169. {
  170. return single_open(file, show_rcuhier, NULL);
  171. }
  172. static struct file_operations rcuhier_fops = {
  173. .owner = THIS_MODULE,
  174. .open = rcuhier_open,
  175. .read = seq_read,
  176. .llseek = seq_lseek,
  177. .release = single_release,
  178. };
  179. static int show_rcugp(struct seq_file *m, void *unused)
  180. {
  181. seq_printf(m, "rcu_sched: completed=%ld gpnum=%ld\n",
  182. rcu_sched_state.completed, rcu_sched_state.gpnum);
  183. seq_printf(m, "rcu_bh: completed=%ld gpnum=%ld\n",
  184. rcu_bh_state.completed, rcu_bh_state.gpnum);
  185. return 0;
  186. }
  187. static int rcugp_open(struct inode *inode, struct file *file)
  188. {
  189. return single_open(file, show_rcugp, NULL);
  190. }
  191. static struct file_operations rcugp_fops = {
  192. .owner = THIS_MODULE,
  193. .open = rcugp_open,
  194. .read = seq_read,
  195. .llseek = seq_lseek,
  196. .release = single_release,
  197. };
  198. static void print_one_rcu_pending(struct seq_file *m, struct rcu_data *rdp)
  199. {
  200. seq_printf(m, "%3d%cnp=%ld "
  201. "qsp=%ld cbr=%ld cng=%ld gpc=%ld gps=%ld nf=%ld nn=%ld\n",
  202. rdp->cpu,
  203. cpu_is_offline(rdp->cpu) ? '!' : ' ',
  204. rdp->n_rcu_pending,
  205. rdp->n_rp_qs_pending,
  206. rdp->n_rp_cb_ready,
  207. rdp->n_rp_cpu_needs_gp,
  208. rdp->n_rp_gp_completed,
  209. rdp->n_rp_gp_started,
  210. rdp->n_rp_need_fqs,
  211. rdp->n_rp_need_nothing);
  212. }
  213. static void print_rcu_pendings(struct seq_file *m, struct rcu_state *rsp)
  214. {
  215. int cpu;
  216. struct rcu_data *rdp;
  217. for_each_possible_cpu(cpu) {
  218. rdp = rsp->rda[cpu];
  219. if (rdp->beenonline)
  220. print_one_rcu_pending(m, rdp);
  221. }
  222. }
  223. static int show_rcu_pending(struct seq_file *m, void *unused)
  224. {
  225. seq_puts(m, "rcu_sched:\n");
  226. print_rcu_pendings(m, &rcu_sched_state);
  227. seq_puts(m, "rcu_bh:\n");
  228. print_rcu_pendings(m, &rcu_bh_state);
  229. return 0;
  230. }
  231. static int rcu_pending_open(struct inode *inode, struct file *file)
  232. {
  233. return single_open(file, show_rcu_pending, NULL);
  234. }
  235. static struct file_operations rcu_pending_fops = {
  236. .owner = THIS_MODULE,
  237. .open = rcu_pending_open,
  238. .read = seq_read,
  239. .llseek = seq_lseek,
  240. .release = single_release,
  241. };
  242. static struct dentry *rcudir;
  243. static struct dentry *datadir;
  244. static struct dentry *datadir_csv;
  245. static struct dentry *gpdir;
  246. static struct dentry *hierdir;
  247. static struct dentry *rcu_pendingdir;
  248. static int __init rcuclassic_trace_init(void)
  249. {
  250. rcudir = debugfs_create_dir("rcu", NULL);
  251. if (!rcudir)
  252. goto out;
  253. datadir = debugfs_create_file("rcudata", 0444, rcudir,
  254. NULL, &rcudata_fops);
  255. if (!datadir)
  256. goto free_out;
  257. datadir_csv = debugfs_create_file("rcudata.csv", 0444, rcudir,
  258. NULL, &rcudata_csv_fops);
  259. if (!datadir_csv)
  260. goto free_out;
  261. gpdir = debugfs_create_file("rcugp", 0444, rcudir, NULL, &rcugp_fops);
  262. if (!gpdir)
  263. goto free_out;
  264. hierdir = debugfs_create_file("rcuhier", 0444, rcudir,
  265. NULL, &rcuhier_fops);
  266. if (!hierdir)
  267. goto free_out;
  268. rcu_pendingdir = debugfs_create_file("rcu_pending", 0444, rcudir,
  269. NULL, &rcu_pending_fops);
  270. if (!rcu_pendingdir)
  271. goto free_out;
  272. return 0;
  273. free_out:
  274. if (datadir)
  275. debugfs_remove(datadir);
  276. if (datadir_csv)
  277. debugfs_remove(datadir_csv);
  278. if (gpdir)
  279. debugfs_remove(gpdir);
  280. debugfs_remove(rcudir);
  281. out:
  282. return 1;
  283. }
  284. static void __exit rcuclassic_trace_cleanup(void)
  285. {
  286. debugfs_remove(datadir);
  287. debugfs_remove(datadir_csv);
  288. debugfs_remove(gpdir);
  289. debugfs_remove(hierdir);
  290. debugfs_remove(rcu_pendingdir);
  291. debugfs_remove(rcudir);
  292. }
  293. module_init(rcuclassic_trace_init);
  294. module_exit(rcuclassic_trace_cleanup);
  295. MODULE_AUTHOR("Paul E. McKenney");
  296. MODULE_DESCRIPTION("Read-Copy Update tracing for hierarchical implementation");
  297. MODULE_LICENSE("GPL");