rcutree_trace.c 14 KB

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