rcutree_trace.c 8.6 KB

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