rcutree_trace.c 14 KB

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