rcutree_trace.c 14 KB

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