rcutree_trace.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  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 <linux/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 int show_rcubarrier(struct seq_file *m, void *unused)
  48. {
  49. struct rcu_state *rsp;
  50. for_each_rcu_flavor(rsp)
  51. seq_printf(m, "%s: bcc: %d nbd: %lu\n",
  52. rsp->name,
  53. atomic_read(&rsp->barrier_cpu_count),
  54. rsp->n_barrier_done);
  55. return 0;
  56. }
  57. static int rcubarrier_open(struct inode *inode, struct file *file)
  58. {
  59. return single_open(file, show_rcubarrier, NULL);
  60. }
  61. static const struct file_operations rcubarrier_fops = {
  62. .owner = THIS_MODULE,
  63. .open = rcubarrier_open,
  64. .read = seq_read,
  65. .llseek = seq_lseek,
  66. .release = single_release,
  67. };
  68. #ifdef CONFIG_RCU_BOOST
  69. static char convert_kthread_status(unsigned int kthread_status)
  70. {
  71. if (kthread_status > RCU_KTHREAD_MAX)
  72. return '?';
  73. return "SRWOY"[kthread_status];
  74. }
  75. #endif /* #ifdef CONFIG_RCU_BOOST */
  76. static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
  77. {
  78. if (!rdp->beenonline)
  79. return;
  80. seq_printf(m, "%3d%cc=%lu g=%lu pq=%d qp=%d",
  81. rdp->cpu,
  82. cpu_is_offline(rdp->cpu) ? '!' : ' ',
  83. rdp->completed, rdp->gpnum,
  84. rdp->passed_quiesce, rdp->qs_pending);
  85. seq_printf(m, " dt=%d/%llx/%d df=%lu",
  86. atomic_read(&rdp->dynticks->dynticks),
  87. rdp->dynticks->dynticks_nesting,
  88. rdp->dynticks->dynticks_nmi_nesting,
  89. rdp->dynticks_fqs);
  90. seq_printf(m, " of=%lu", rdp->offline_fqs);
  91. seq_printf(m, " ql=%ld/%ld qs=%c%c%c%c",
  92. rdp->qlen_lazy, rdp->qlen,
  93. ".N"[rdp->nxttail[RCU_NEXT_READY_TAIL] !=
  94. rdp->nxttail[RCU_NEXT_TAIL]],
  95. ".R"[rdp->nxttail[RCU_WAIT_TAIL] !=
  96. rdp->nxttail[RCU_NEXT_READY_TAIL]],
  97. ".W"[rdp->nxttail[RCU_DONE_TAIL] !=
  98. rdp->nxttail[RCU_WAIT_TAIL]],
  99. ".D"[&rdp->nxtlist != rdp->nxttail[RCU_DONE_TAIL]]);
  100. #ifdef CONFIG_RCU_BOOST
  101. seq_printf(m, " kt=%d/%c ktl=%x",
  102. per_cpu(rcu_cpu_has_work, rdp->cpu),
  103. convert_kthread_status(per_cpu(rcu_cpu_kthread_status,
  104. rdp->cpu)),
  105. per_cpu(rcu_cpu_kthread_loops, rdp->cpu) & 0xffff);
  106. #endif /* #ifdef CONFIG_RCU_BOOST */
  107. seq_printf(m, " b=%ld", rdp->blimit);
  108. seq_printf(m, " ci=%lu co=%lu ca=%lu\n",
  109. rdp->n_cbs_invoked, rdp->n_cbs_orphaned, rdp->n_cbs_adopted);
  110. }
  111. static int show_rcudata(struct seq_file *m, void *unused)
  112. {
  113. int cpu;
  114. struct rcu_state *rsp;
  115. for_each_rcu_flavor(rsp) {
  116. seq_printf(m, "%s:\n", rsp->name);
  117. for_each_possible_cpu(cpu)
  118. print_one_rcu_data(m, per_cpu_ptr(rsp->rda, cpu));
  119. }
  120. return 0;
  121. }
  122. static int rcudata_open(struct inode *inode, struct file *file)
  123. {
  124. return single_open(file, show_rcudata, NULL);
  125. }
  126. static const struct file_operations rcudata_fops = {
  127. .owner = THIS_MODULE,
  128. .open = rcudata_open,
  129. .read = seq_read,
  130. .llseek = seq_lseek,
  131. .release = single_release,
  132. };
  133. static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
  134. {
  135. if (!rdp->beenonline)
  136. return;
  137. seq_printf(m, "%d,%s,%lu,%lu,%d,%d",
  138. rdp->cpu,
  139. cpu_is_offline(rdp->cpu) ? "\"N\"" : "\"Y\"",
  140. rdp->completed, rdp->gpnum,
  141. rdp->passed_quiesce, rdp->qs_pending);
  142. seq_printf(m, ",%d,%llx,%d,%lu",
  143. atomic_read(&rdp->dynticks->dynticks),
  144. rdp->dynticks->dynticks_nesting,
  145. rdp->dynticks->dynticks_nmi_nesting,
  146. rdp->dynticks_fqs);
  147. seq_printf(m, ",%lu", rdp->offline_fqs);
  148. seq_printf(m, ",%ld,%ld,\"%c%c%c%c\"", rdp->qlen_lazy, rdp->qlen,
  149. ".N"[rdp->nxttail[RCU_NEXT_READY_TAIL] !=
  150. rdp->nxttail[RCU_NEXT_TAIL]],
  151. ".R"[rdp->nxttail[RCU_WAIT_TAIL] !=
  152. rdp->nxttail[RCU_NEXT_READY_TAIL]],
  153. ".W"[rdp->nxttail[RCU_DONE_TAIL] !=
  154. rdp->nxttail[RCU_WAIT_TAIL]],
  155. ".D"[&rdp->nxtlist != rdp->nxttail[RCU_DONE_TAIL]]);
  156. #ifdef CONFIG_RCU_BOOST
  157. seq_printf(m, ",%d,\"%c\"",
  158. per_cpu(rcu_cpu_has_work, rdp->cpu),
  159. convert_kthread_status(per_cpu(rcu_cpu_kthread_status,
  160. rdp->cpu)));
  161. #endif /* #ifdef CONFIG_RCU_BOOST */
  162. seq_printf(m, ",%ld", rdp->blimit);
  163. seq_printf(m, ",%lu,%lu,%lu\n",
  164. rdp->n_cbs_invoked, rdp->n_cbs_orphaned, rdp->n_cbs_adopted);
  165. }
  166. static int show_rcudata_csv(struct seq_file *m, void *unused)
  167. {
  168. int cpu;
  169. struct rcu_state *rsp;
  170. seq_puts(m, "\"CPU\",\"Online?\",\"c\",\"g\",\"pq\",\"pq\",");
  171. seq_puts(m, "\"dt\",\"dt nesting\",\"dt NMI nesting\",\"df\",");
  172. seq_puts(m, "\"of\",\"qll\",\"ql\",\"qs\"");
  173. #ifdef CONFIG_RCU_BOOST
  174. seq_puts(m, "\"kt\",\"ktl\"");
  175. #endif /* #ifdef CONFIG_RCU_BOOST */
  176. seq_puts(m, ",\"b\",\"ci\",\"co\",\"ca\"\n");
  177. for_each_rcu_flavor(rsp) {
  178. seq_printf(m, "\"%s:\"\n", rsp->name);
  179. for_each_possible_cpu(cpu)
  180. print_one_rcu_data_csv(m, per_cpu_ptr(rsp->rda, cpu));
  181. }
  182. return 0;
  183. }
  184. static int rcudata_csv_open(struct inode *inode, struct file *file)
  185. {
  186. return single_open(file, show_rcudata_csv, NULL);
  187. }
  188. static const struct file_operations rcudata_csv_fops = {
  189. .owner = THIS_MODULE,
  190. .open = rcudata_csv_open,
  191. .read = seq_read,
  192. .llseek = seq_lseek,
  193. .release = single_release,
  194. };
  195. #ifdef CONFIG_RCU_BOOST
  196. static void print_one_rcu_node_boost(struct seq_file *m, struct rcu_node *rnp)
  197. {
  198. seq_printf(m, "%d:%d tasks=%c%c%c%c kt=%c ntb=%lu neb=%lu nnb=%lu ",
  199. rnp->grplo, rnp->grphi,
  200. "T."[list_empty(&rnp->blkd_tasks)],
  201. "N."[!rnp->gp_tasks],
  202. "E."[!rnp->exp_tasks],
  203. "B."[!rnp->boost_tasks],
  204. convert_kthread_status(rnp->boost_kthread_status),
  205. rnp->n_tasks_boosted, rnp->n_exp_boosts,
  206. rnp->n_normal_boosts);
  207. seq_printf(m, "j=%04x bt=%04x\n",
  208. (int)(jiffies & 0xffff),
  209. (int)(rnp->boost_time & 0xffff));
  210. seq_printf(m, " balk: nt=%lu egt=%lu bt=%lu nb=%lu ny=%lu nos=%lu\n",
  211. rnp->n_balk_blkd_tasks,
  212. rnp->n_balk_exp_gp_tasks,
  213. rnp->n_balk_boost_tasks,
  214. rnp->n_balk_notblocked,
  215. rnp->n_balk_notyet,
  216. rnp->n_balk_nos);
  217. }
  218. static int show_rcu_node_boost(struct seq_file *m, void *unused)
  219. {
  220. struct rcu_node *rnp;
  221. rcu_for_each_leaf_node(&rcu_preempt_state, rnp)
  222. print_one_rcu_node_boost(m, rnp);
  223. return 0;
  224. }
  225. static int rcu_node_boost_open(struct inode *inode, struct file *file)
  226. {
  227. return single_open(file, show_rcu_node_boost, NULL);
  228. }
  229. static const struct file_operations rcu_node_boost_fops = {
  230. .owner = THIS_MODULE,
  231. .open = rcu_node_boost_open,
  232. .read = seq_read,
  233. .llseek = seq_lseek,
  234. .release = single_release,
  235. };
  236. /*
  237. * Create the rcuboost debugfs entry. Standard error return.
  238. */
  239. static int rcu_boost_trace_create_file(struct dentry *rcudir)
  240. {
  241. return !debugfs_create_file("rcuboost", 0444, rcudir, NULL,
  242. &rcu_node_boost_fops);
  243. }
  244. #else /* #ifdef CONFIG_RCU_BOOST */
  245. static int rcu_boost_trace_create_file(struct dentry *rcudir)
  246. {
  247. return 0; /* There cannot be an error if we didn't create it! */
  248. }
  249. #endif /* #else #ifdef CONFIG_RCU_BOOST */
  250. static void print_one_rcu_state(struct seq_file *m, struct rcu_state *rsp)
  251. {
  252. unsigned long gpnum;
  253. int level = 0;
  254. struct rcu_node *rnp;
  255. gpnum = rsp->gpnum;
  256. seq_printf(m, "%s: c=%lu g=%lu s=%d jfq=%ld j=%x ",
  257. rsp->name, rsp->completed, gpnum, rsp->fqs_state,
  258. (long)(rsp->jiffies_force_qs - jiffies),
  259. (int)(jiffies & 0xffff));
  260. seq_printf(m, "nfqs=%lu/nfqsng=%lu(%lu) fqlh=%lu oqlen=%ld/%ld\n",
  261. rsp->n_force_qs, rsp->n_force_qs_ngp,
  262. rsp->n_force_qs - rsp->n_force_qs_ngp,
  263. rsp->n_force_qs_lh, rsp->qlen_lazy, rsp->qlen);
  264. for (rnp = &rsp->node[0]; rnp - &rsp->node[0] < rcu_num_nodes; rnp++) {
  265. if (rnp->level != level) {
  266. seq_puts(m, "\n");
  267. level = rnp->level;
  268. }
  269. seq_printf(m, "%lx/%lx %c%c>%c %d:%d ^%d ",
  270. rnp->qsmask, rnp->qsmaskinit,
  271. ".G"[rnp->gp_tasks != NULL],
  272. ".E"[rnp->exp_tasks != NULL],
  273. ".T"[!list_empty(&rnp->blkd_tasks)],
  274. rnp->grplo, rnp->grphi, rnp->grpnum);
  275. }
  276. seq_puts(m, "\n");
  277. }
  278. static int show_rcuhier(struct seq_file *m, void *unused)
  279. {
  280. struct rcu_state *rsp;
  281. for_each_rcu_flavor(rsp)
  282. print_one_rcu_state(m, rsp);
  283. return 0;
  284. }
  285. static int rcuhier_open(struct inode *inode, struct file *file)
  286. {
  287. return single_open(file, show_rcuhier, NULL);
  288. }
  289. static const struct file_operations rcuhier_fops = {
  290. .owner = THIS_MODULE,
  291. .open = rcuhier_open,
  292. .read = seq_read,
  293. .llseek = seq_lseek,
  294. .release = single_release,
  295. };
  296. static void show_one_rcugp(struct seq_file *m, struct rcu_state *rsp)
  297. {
  298. unsigned long flags;
  299. unsigned long completed;
  300. unsigned long gpnum;
  301. unsigned long gpage;
  302. unsigned long gpmax;
  303. struct rcu_node *rnp = &rsp->node[0];
  304. raw_spin_lock_irqsave(&rnp->lock, flags);
  305. completed = rsp->completed;
  306. gpnum = rsp->gpnum;
  307. if (rsp->completed == rsp->gpnum)
  308. gpage = 0;
  309. else
  310. gpage = jiffies - rsp->gp_start;
  311. gpmax = rsp->gp_max;
  312. raw_spin_unlock_irqrestore(&rnp->lock, flags);
  313. seq_printf(m, "%s: completed=%ld gpnum=%lu age=%ld max=%ld\n",
  314. rsp->name, completed, gpnum, gpage, gpmax);
  315. }
  316. static int show_rcugp(struct seq_file *m, void *unused)
  317. {
  318. struct rcu_state *rsp;
  319. for_each_rcu_flavor(rsp)
  320. show_one_rcugp(m, rsp);
  321. return 0;
  322. }
  323. static int rcugp_open(struct inode *inode, struct file *file)
  324. {
  325. return single_open(file, show_rcugp, NULL);
  326. }
  327. static const struct file_operations rcugp_fops = {
  328. .owner = THIS_MODULE,
  329. .open = rcugp_open,
  330. .read = seq_read,
  331. .llseek = seq_lseek,
  332. .release = single_release,
  333. };
  334. static void print_one_rcu_pending(struct seq_file *m, struct rcu_data *rdp)
  335. {
  336. seq_printf(m, "%3d%cnp=%ld ",
  337. rdp->cpu,
  338. cpu_is_offline(rdp->cpu) ? '!' : ' ',
  339. rdp->n_rcu_pending);
  340. seq_printf(m, "qsp=%ld rpq=%ld cbr=%ld cng=%ld ",
  341. rdp->n_rp_qs_pending,
  342. rdp->n_rp_report_qs,
  343. rdp->n_rp_cb_ready,
  344. rdp->n_rp_cpu_needs_gp);
  345. seq_printf(m, "gpc=%ld gps=%ld nn=%ld\n",
  346. rdp->n_rp_gp_completed,
  347. rdp->n_rp_gp_started,
  348. rdp->n_rp_need_nothing);
  349. }
  350. static int show_rcu_pending(struct seq_file *m, void *unused)
  351. {
  352. int cpu;
  353. struct rcu_data *rdp;
  354. struct rcu_state *rsp;
  355. for_each_rcu_flavor(rsp) {
  356. seq_printf(m, "%s:\n", rsp->name);
  357. for_each_possible_cpu(cpu) {
  358. rdp = per_cpu_ptr(rsp->rda, cpu);
  359. if (rdp->beenonline)
  360. print_one_rcu_pending(m, rdp);
  361. }
  362. }
  363. return 0;
  364. }
  365. static int rcu_pending_open(struct inode *inode, struct file *file)
  366. {
  367. return single_open(file, show_rcu_pending, NULL);
  368. }
  369. static const struct file_operations rcu_pending_fops = {
  370. .owner = THIS_MODULE,
  371. .open = rcu_pending_open,
  372. .read = seq_read,
  373. .llseek = seq_lseek,
  374. .release = single_release,
  375. };
  376. static int show_rcutorture(struct seq_file *m, void *unused)
  377. {
  378. seq_printf(m, "rcutorture test sequence: %lu %s\n",
  379. rcutorture_testseq >> 1,
  380. (rcutorture_testseq & 0x1) ? "(test in progress)" : "");
  381. seq_printf(m, "rcutorture update version number: %lu\n",
  382. rcutorture_vernum);
  383. return 0;
  384. }
  385. static int rcutorture_open(struct inode *inode, struct file *file)
  386. {
  387. return single_open(file, show_rcutorture, NULL);
  388. }
  389. static const struct file_operations rcutorture_fops = {
  390. .owner = THIS_MODULE,
  391. .open = rcutorture_open,
  392. .read = seq_read,
  393. .llseek = seq_lseek,
  394. .release = single_release,
  395. };
  396. static struct dentry *rcudir;
  397. static int __init rcutree_trace_init(void)
  398. {
  399. struct dentry *retval;
  400. rcudir = debugfs_create_dir("rcu", NULL);
  401. if (!rcudir)
  402. goto free_out;
  403. retval = debugfs_create_file("rcubarrier", 0444, rcudir,
  404. NULL, &rcubarrier_fops);
  405. if (!retval)
  406. goto free_out;
  407. retval = debugfs_create_file("rcudata", 0444, rcudir,
  408. NULL, &rcudata_fops);
  409. if (!retval)
  410. goto free_out;
  411. retval = debugfs_create_file("rcudata.csv", 0444, rcudir,
  412. NULL, &rcudata_csv_fops);
  413. if (!retval)
  414. goto free_out;
  415. if (rcu_boost_trace_create_file(rcudir))
  416. goto free_out;
  417. retval = debugfs_create_file("rcugp", 0444, rcudir, NULL, &rcugp_fops);
  418. if (!retval)
  419. goto free_out;
  420. retval = debugfs_create_file("rcuhier", 0444, rcudir,
  421. NULL, &rcuhier_fops);
  422. if (!retval)
  423. goto free_out;
  424. retval = debugfs_create_file("rcu_pending", 0444, rcudir,
  425. NULL, &rcu_pending_fops);
  426. if (!retval)
  427. goto free_out;
  428. retval = debugfs_create_file("rcutorture", 0444, rcudir,
  429. NULL, &rcutorture_fops);
  430. if (!retval)
  431. goto free_out;
  432. return 0;
  433. free_out:
  434. debugfs_remove_recursive(rcudir);
  435. return 1;
  436. }
  437. static void __exit rcutree_trace_cleanup(void)
  438. {
  439. debugfs_remove_recursive(rcudir);
  440. }
  441. module_init(rcutree_trace_init);
  442. module_exit(rcutree_trace_cleanup);
  443. MODULE_AUTHOR("Paul E. McKenney");
  444. MODULE_DESCRIPTION("Read-Copy Update tracing for hierarchical implementation");
  445. MODULE_LICENSE("GPL");