rcutree_trace.c 9.7 KB

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