tree_trace.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494
  1. /*
  2. * Read-Copy Update tracing for hierarchical 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. * Author: Paul E. McKenney
  20. *
  21. * Papers: http://www.rdrop.com/users/paulmck/RCU
  22. *
  23. * For detailed explanation of Read-Copy Update mechanism see -
  24. * Documentation/RCU
  25. *
  26. */
  27. #include <linux/types.h>
  28. #include <linux/kernel.h>
  29. #include <linux/init.h>
  30. #include <linux/spinlock.h>
  31. #include <linux/smp.h>
  32. #include <linux/rcupdate.h>
  33. #include <linux/interrupt.h>
  34. #include <linux/sched.h>
  35. #include <linux/atomic.h>
  36. #include <linux/bitops.h>
  37. #include <linux/completion.h>
  38. #include <linux/percpu.h>
  39. #include <linux/notifier.h>
  40. #include <linux/cpu.h>
  41. #include <linux/mutex.h>
  42. #include <linux/debugfs.h>
  43. #include <linux/seq_file.h>
  44. #define RCU_TREE_NONCORE
  45. #include "tree.h"
  46. DECLARE_PER_CPU_SHARED_ALIGNED(unsigned long, rcu_qs_ctr);
  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 *v)
  74. {
  75. struct rcu_state *rsp = (struct rcu_state *)m->private;
  76. seq_printf(m, "bcc: %d bseq: %lu\n",
  77. atomic_read(&rsp->barrier_cpu_count),
  78. rsp->barrier_sequence);
  79. return 0;
  80. }
  81. static int rcubarrier_open(struct inode *inode, struct file *file)
  82. {
  83. return single_open(file, show_rcubarrier, inode->i_private);
  84. }
  85. static const struct file_operations rcubarrier_fops = {
  86. .owner = THIS_MODULE,
  87. .open = rcubarrier_open,
  88. .read = seq_read,
  89. .llseek = no_llseek,
  90. .release = single_release,
  91. };
  92. #ifdef CONFIG_RCU_BOOST
  93. static char convert_kthread_status(unsigned int kthread_status)
  94. {
  95. if (kthread_status > RCU_KTHREAD_MAX)
  96. return '?';
  97. return "SRWOY"[kthread_status];
  98. }
  99. #endif /* #ifdef CONFIG_RCU_BOOST */
  100. static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
  101. {
  102. long ql, qll;
  103. if (!rdp->beenonline)
  104. return;
  105. seq_printf(m, "%3d%cc=%ld g=%ld cnq=%d/%d:%d",
  106. rdp->cpu,
  107. cpu_is_offline(rdp->cpu) ? '!' : ' ',
  108. ulong2long(rdp->completed), ulong2long(rdp->gpnum),
  109. rdp->cpu_no_qs.b.norm,
  110. rdp->rcu_qs_ctr_snap == per_cpu(rcu_qs_ctr, rdp->cpu),
  111. rdp->core_needs_qs);
  112. seq_printf(m, " dt=%d/%llx/%d df=%lu",
  113. atomic_read(&rdp->dynticks->dynticks),
  114. rdp->dynticks->dynticks_nesting,
  115. rdp->dynticks->dynticks_nmi_nesting,
  116. rdp->dynticks_fqs);
  117. seq_printf(m, " of=%lu", rdp->offline_fqs);
  118. rcu_nocb_q_lengths(rdp, &ql, &qll);
  119. qll += rdp->qlen_lazy;
  120. ql += rdp->qlen;
  121. seq_printf(m, " ql=%ld/%ld qs=%c%c%c%c",
  122. qll, ql,
  123. ".N"[rdp->nxttail[RCU_NEXT_READY_TAIL] !=
  124. rdp->nxttail[RCU_NEXT_TAIL]],
  125. ".R"[rdp->nxttail[RCU_WAIT_TAIL] !=
  126. rdp->nxttail[RCU_NEXT_READY_TAIL]],
  127. ".W"[rdp->nxttail[RCU_DONE_TAIL] !=
  128. rdp->nxttail[RCU_WAIT_TAIL]],
  129. ".D"[&rdp->nxtlist != rdp->nxttail[RCU_DONE_TAIL]]);
  130. #ifdef CONFIG_RCU_BOOST
  131. seq_printf(m, " kt=%d/%c ktl=%x",
  132. per_cpu(rcu_cpu_has_work, rdp->cpu),
  133. convert_kthread_status(per_cpu(rcu_cpu_kthread_status,
  134. rdp->cpu)),
  135. per_cpu(rcu_cpu_kthread_loops, rdp->cpu) & 0xffff);
  136. #endif /* #ifdef CONFIG_RCU_BOOST */
  137. seq_printf(m, " b=%ld", rdp->blimit);
  138. seq_printf(m, " ci=%lu nci=%lu co=%lu ca=%lu\n",
  139. rdp->n_cbs_invoked, rdp->n_nocbs_invoked,
  140. rdp->n_cbs_orphaned, rdp->n_cbs_adopted);
  141. }
  142. static int show_rcudata(struct seq_file *m, void *v)
  143. {
  144. print_one_rcu_data(m, (struct rcu_data *)v);
  145. return 0;
  146. }
  147. static const struct seq_operations rcudate_op = {
  148. .start = r_start,
  149. .next = r_next,
  150. .stop = r_stop,
  151. .show = show_rcudata,
  152. };
  153. static int rcudata_open(struct inode *inode, struct file *file)
  154. {
  155. return r_open(inode, file, &rcudate_op);
  156. }
  157. static const struct file_operations rcudata_fops = {
  158. .owner = THIS_MODULE,
  159. .open = rcudata_open,
  160. .read = seq_read,
  161. .llseek = no_llseek,
  162. .release = seq_release,
  163. };
  164. static int show_rcuexp(struct seq_file *m, void *v)
  165. {
  166. int cpu;
  167. struct rcu_state *rsp = (struct rcu_state *)m->private;
  168. struct rcu_data *rdp;
  169. unsigned long s1 = 0, s2 = 0, s3 = 0;
  170. for_each_possible_cpu(cpu) {
  171. rdp = per_cpu_ptr(rsp->rda, cpu);
  172. s1 += atomic_long_read(&rdp->exp_workdone1);
  173. s2 += atomic_long_read(&rdp->exp_workdone2);
  174. s3 += atomic_long_read(&rdp->exp_workdone3);
  175. }
  176. seq_printf(m, "s=%lu wd1=%lu wd2=%lu wd3=%lu n=%lu enq=%d sc=%lu\n",
  177. rsp->expedited_sequence, s1, s2, s3,
  178. atomic_long_read(&rsp->expedited_normal),
  179. atomic_read(&rsp->expedited_need_qs),
  180. rsp->expedited_sequence / 2);
  181. return 0;
  182. }
  183. static int rcuexp_open(struct inode *inode, struct file *file)
  184. {
  185. return single_open(file, show_rcuexp, inode->i_private);
  186. }
  187. static const struct file_operations rcuexp_fops = {
  188. .owner = THIS_MODULE,
  189. .open = rcuexp_open,
  190. .read = seq_read,
  191. .llseek = no_llseek,
  192. .release = single_release,
  193. };
  194. #ifdef CONFIG_RCU_BOOST
  195. static void print_one_rcu_node_boost(struct seq_file *m, struct rcu_node *rnp)
  196. {
  197. seq_printf(m, "%d:%d tasks=%c%c%c%c kt=%c ntb=%lu neb=%lu nnb=%lu ",
  198. rnp->grplo, rnp->grphi,
  199. "T."[list_empty(&rnp->blkd_tasks)],
  200. "N."[!rnp->gp_tasks],
  201. "E."[!rnp->exp_tasks],
  202. "B."[!rnp->boost_tasks],
  203. convert_kthread_status(rnp->boost_kthread_status),
  204. rnp->n_tasks_boosted, rnp->n_exp_boosts,
  205. rnp->n_normal_boosts);
  206. seq_printf(m, "j=%04x bt=%04x\n",
  207. (int)(jiffies & 0xffff),
  208. (int)(rnp->boost_time & 0xffff));
  209. seq_printf(m, " balk: nt=%lu egt=%lu bt=%lu nb=%lu ny=%lu nos=%lu\n",
  210. rnp->n_balk_blkd_tasks,
  211. rnp->n_balk_exp_gp_tasks,
  212. rnp->n_balk_boost_tasks,
  213. rnp->n_balk_notblocked,
  214. rnp->n_balk_notyet,
  215. rnp->n_balk_nos);
  216. }
  217. static int show_rcu_node_boost(struct seq_file *m, void *unused)
  218. {
  219. struct rcu_node *rnp;
  220. rcu_for_each_leaf_node(&rcu_preempt_state, rnp)
  221. print_one_rcu_node_boost(m, rnp);
  222. return 0;
  223. }
  224. static int rcu_node_boost_open(struct inode *inode, struct file *file)
  225. {
  226. return single_open(file, show_rcu_node_boost, NULL);
  227. }
  228. static const struct file_operations rcu_node_boost_fops = {
  229. .owner = THIS_MODULE,
  230. .open = rcu_node_boost_open,
  231. .read = seq_read,
  232. .llseek = no_llseek,
  233. .release = single_release,
  234. };
  235. #endif /* #ifdef CONFIG_RCU_BOOST */
  236. static void print_one_rcu_state(struct seq_file *m, struct rcu_state *rsp)
  237. {
  238. unsigned long gpnum;
  239. int level = 0;
  240. struct rcu_node *rnp;
  241. gpnum = rsp->gpnum;
  242. seq_printf(m, "c=%ld g=%ld s=%d jfq=%ld j=%x ",
  243. ulong2long(rsp->completed), ulong2long(gpnum),
  244. rsp->gp_state,
  245. (long)(rsp->jiffies_force_qs - jiffies),
  246. (int)(jiffies & 0xffff));
  247. seq_printf(m, "nfqs=%lu/nfqsng=%lu(%lu) fqlh=%lu oqlen=%ld/%ld\n",
  248. rsp->n_force_qs, rsp->n_force_qs_ngp,
  249. rsp->n_force_qs - rsp->n_force_qs_ngp,
  250. READ_ONCE(rsp->n_force_qs_lh), rsp->qlen_lazy, rsp->qlen);
  251. for (rnp = &rsp->node[0]; rnp - &rsp->node[0] < rcu_num_nodes; rnp++) {
  252. if (rnp->level != level) {
  253. seq_puts(m, "\n");
  254. level = rnp->level;
  255. }
  256. seq_printf(m, "%lx/%lx->%lx %c%c>%c %d:%d ^%d ",
  257. rnp->qsmask, rnp->qsmaskinit, rnp->qsmaskinitnext,
  258. ".G"[rnp->gp_tasks != NULL],
  259. ".E"[rnp->exp_tasks != NULL],
  260. ".T"[!list_empty(&rnp->blkd_tasks)],
  261. rnp->grplo, rnp->grphi, rnp->grpnum);
  262. }
  263. seq_puts(m, "\n");
  264. }
  265. static int show_rcuhier(struct seq_file *m, void *v)
  266. {
  267. struct rcu_state *rsp = (struct rcu_state *)m->private;
  268. print_one_rcu_state(m, rsp);
  269. return 0;
  270. }
  271. static int rcuhier_open(struct inode *inode, struct file *file)
  272. {
  273. return single_open(file, show_rcuhier, inode->i_private);
  274. }
  275. static const struct file_operations rcuhier_fops = {
  276. .owner = THIS_MODULE,
  277. .open = rcuhier_open,
  278. .read = seq_read,
  279. .llseek = no_llseek,
  280. .release = single_release,
  281. };
  282. static void show_one_rcugp(struct seq_file *m, struct rcu_state *rsp)
  283. {
  284. unsigned long flags;
  285. unsigned long completed;
  286. unsigned long gpnum;
  287. unsigned long gpage;
  288. unsigned long gpmax;
  289. struct rcu_node *rnp = &rsp->node[0];
  290. raw_spin_lock_irqsave_rcu_node(rnp, flags);
  291. completed = READ_ONCE(rsp->completed);
  292. gpnum = READ_ONCE(rsp->gpnum);
  293. if (completed == gpnum)
  294. gpage = 0;
  295. else
  296. gpage = jiffies - rsp->gp_start;
  297. gpmax = rsp->gp_max;
  298. raw_spin_unlock_irqrestore(&rnp->lock, flags);
  299. seq_printf(m, "completed=%ld gpnum=%ld age=%ld max=%ld\n",
  300. ulong2long(completed), ulong2long(gpnum), gpage, gpmax);
  301. }
  302. static int show_rcugp(struct seq_file *m, void *v)
  303. {
  304. struct rcu_state *rsp = (struct rcu_state *)m->private;
  305. show_one_rcugp(m, rsp);
  306. return 0;
  307. }
  308. static int rcugp_open(struct inode *inode, struct file *file)
  309. {
  310. return single_open(file, show_rcugp, inode->i_private);
  311. }
  312. static const struct file_operations rcugp_fops = {
  313. .owner = THIS_MODULE,
  314. .open = rcugp_open,
  315. .read = seq_read,
  316. .llseek = no_llseek,
  317. .release = single_release,
  318. };
  319. static void print_one_rcu_pending(struct seq_file *m, struct rcu_data *rdp)
  320. {
  321. if (!rdp->beenonline)
  322. return;
  323. seq_printf(m, "%3d%cnp=%ld ",
  324. rdp->cpu,
  325. cpu_is_offline(rdp->cpu) ? '!' : ' ',
  326. rdp->n_rcu_pending);
  327. seq_printf(m, "qsp=%ld rpq=%ld cbr=%ld cng=%ld ",
  328. rdp->n_rp_core_needs_qs,
  329. rdp->n_rp_report_qs,
  330. rdp->n_rp_cb_ready,
  331. rdp->n_rp_cpu_needs_gp);
  332. seq_printf(m, "gpc=%ld gps=%ld nn=%ld ndw%ld\n",
  333. rdp->n_rp_gp_completed,
  334. rdp->n_rp_gp_started,
  335. rdp->n_rp_nocb_defer_wakeup,
  336. rdp->n_rp_need_nothing);
  337. }
  338. static int show_rcu_pending(struct seq_file *m, void *v)
  339. {
  340. print_one_rcu_pending(m, (struct rcu_data *)v);
  341. return 0;
  342. }
  343. static const struct seq_operations rcu_pending_op = {
  344. .start = r_start,
  345. .next = r_next,
  346. .stop = r_stop,
  347. .show = show_rcu_pending,
  348. };
  349. static int rcu_pending_open(struct inode *inode, struct file *file)
  350. {
  351. return r_open(inode, file, &rcu_pending_op);
  352. }
  353. static const struct file_operations rcu_pending_fops = {
  354. .owner = THIS_MODULE,
  355. .open = rcu_pending_open,
  356. .read = seq_read,
  357. .llseek = no_llseek,
  358. .release = seq_release,
  359. };
  360. static int show_rcutorture(struct seq_file *m, void *unused)
  361. {
  362. seq_printf(m, "rcutorture test sequence: %lu %s\n",
  363. rcutorture_testseq >> 1,
  364. (rcutorture_testseq & 0x1) ? "(test in progress)" : "");
  365. seq_printf(m, "rcutorture update version number: %lu\n",
  366. rcutorture_vernum);
  367. return 0;
  368. }
  369. static int rcutorture_open(struct inode *inode, struct file *file)
  370. {
  371. return single_open(file, show_rcutorture, NULL);
  372. }
  373. static const struct file_operations rcutorture_fops = {
  374. .owner = THIS_MODULE,
  375. .open = rcutorture_open,
  376. .read = seq_read,
  377. .llseek = seq_lseek,
  378. .release = single_release,
  379. };
  380. static struct dentry *rcudir;
  381. static int __init rcutree_trace_init(void)
  382. {
  383. struct rcu_state *rsp;
  384. struct dentry *retval;
  385. struct dentry *rspdir;
  386. rcudir = debugfs_create_dir("rcu", NULL);
  387. if (!rcudir)
  388. goto free_out;
  389. for_each_rcu_flavor(rsp) {
  390. rspdir = debugfs_create_dir(rsp->name, rcudir);
  391. if (!rspdir)
  392. goto free_out;
  393. retval = debugfs_create_file("rcudata", 0444,
  394. rspdir, rsp, &rcudata_fops);
  395. if (!retval)
  396. goto free_out;
  397. retval = debugfs_create_file("rcuexp", 0444,
  398. rspdir, rsp, &rcuexp_fops);
  399. if (!retval)
  400. goto free_out;
  401. retval = debugfs_create_file("rcu_pending", 0444,
  402. rspdir, rsp, &rcu_pending_fops);
  403. if (!retval)
  404. goto free_out;
  405. retval = debugfs_create_file("rcubarrier", 0444,
  406. rspdir, rsp, &rcubarrier_fops);
  407. if (!retval)
  408. goto free_out;
  409. #ifdef CONFIG_RCU_BOOST
  410. if (rsp == &rcu_preempt_state) {
  411. retval = debugfs_create_file("rcuboost", 0444,
  412. rspdir, NULL, &rcu_node_boost_fops);
  413. if (!retval)
  414. goto free_out;
  415. }
  416. #endif
  417. retval = debugfs_create_file("rcugp", 0444,
  418. rspdir, rsp, &rcugp_fops);
  419. if (!retval)
  420. goto free_out;
  421. retval = debugfs_create_file("rcuhier", 0444,
  422. rspdir, rsp, &rcuhier_fops);
  423. if (!retval)
  424. goto free_out;
  425. }
  426. retval = debugfs_create_file("rcutorture", 0444, rcudir,
  427. NULL, &rcutorture_fops);
  428. if (!retval)
  429. goto free_out;
  430. return 0;
  431. free_out:
  432. debugfs_remove_recursive(rcudir);
  433. return 1;
  434. }
  435. device_initcall(rcutree_trace_init);