rcutree_trace.c 14 KB

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