tree_trace.c 13 KB

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