rcutiny_plugin.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /*
  2. * Read-Copy Update mechanism for mutual exclusion, the Bloatwatch edition
  3. * Internal non-public definitions that provide either classic
  4. * or preemptible semantics.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. *
  20. * Copyright (c) 2010 Linaro
  21. *
  22. * Author: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
  23. */
  24. #include <linux/kthread.h>
  25. #include <linux/module.h>
  26. #include <linux/debugfs.h>
  27. #include <linux/seq_file.h>
  28. /* Global control variables for rcupdate callback mechanism. */
  29. struct rcu_ctrlblk {
  30. struct rcu_head *rcucblist; /* List of pending callbacks (CBs). */
  31. struct rcu_head **donetail; /* ->next pointer of last "done" CB. */
  32. struct rcu_head **curtail; /* ->next pointer of last CB. */
  33. RCU_TRACE(long qlen); /* Number of pending CBs. */
  34. RCU_TRACE(unsigned long gp_start); /* Start time for stalls. */
  35. RCU_TRACE(unsigned long ticks_this_gp); /* Statistic for stalls. */
  36. RCU_TRACE(unsigned long jiffies_stall); /* Jiffies at next stall. */
  37. RCU_TRACE(char *name); /* Name of RCU type. */
  38. };
  39. /* Definition for rcupdate control block. */
  40. static struct rcu_ctrlblk rcu_sched_ctrlblk = {
  41. .donetail = &rcu_sched_ctrlblk.rcucblist,
  42. .curtail = &rcu_sched_ctrlblk.rcucblist,
  43. RCU_TRACE(.name = "rcu_sched")
  44. };
  45. static struct rcu_ctrlblk rcu_bh_ctrlblk = {
  46. .donetail = &rcu_bh_ctrlblk.rcucblist,
  47. .curtail = &rcu_bh_ctrlblk.rcucblist,
  48. RCU_TRACE(.name = "rcu_bh")
  49. };
  50. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  51. int rcu_scheduler_active __read_mostly;
  52. EXPORT_SYMBOL_GPL(rcu_scheduler_active);
  53. #endif /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
  54. #ifdef CONFIG_RCU_TRACE
  55. static void check_cpu_stall(struct rcu_ctrlblk *rcp)
  56. {
  57. unsigned long j;
  58. unsigned long js;
  59. if (rcu_cpu_stall_suppress)
  60. return;
  61. rcp->ticks_this_gp++;
  62. j = jiffies;
  63. js = rcp->jiffies_stall;
  64. if (*rcp->curtail && ULONG_CMP_GE(j, js)) {
  65. pr_err("INFO: %s stall on CPU (%lu ticks this GP) idle=%llx (t=%lu jiffies q=%ld)\n",
  66. rcp->name, rcp->ticks_this_gp, rcu_dynticks_nesting,
  67. jiffies - rcp->gp_start, rcp->qlen);
  68. dump_stack();
  69. }
  70. if (*rcp->curtail && ULONG_CMP_GE(j, js))
  71. rcp->jiffies_stall = jiffies +
  72. 3 * rcu_jiffies_till_stall_check() + 3;
  73. else if (ULONG_CMP_GE(j, js))
  74. rcp->jiffies_stall = jiffies + rcu_jiffies_till_stall_check();
  75. }
  76. static void check_cpu_stall_preempt(void);
  77. #endif /* #ifdef CONFIG_RCU_TRACE */
  78. static void reset_cpu_stall_ticks(struct rcu_ctrlblk *rcp)
  79. {
  80. #ifdef CONFIG_RCU_TRACE
  81. rcp->ticks_this_gp = 0;
  82. rcp->gp_start = jiffies;
  83. rcp->jiffies_stall = jiffies + rcu_jiffies_till_stall_check();
  84. #endif /* #ifdef CONFIG_RCU_TRACE */
  85. }
  86. static void check_cpu_stalls(void)
  87. {
  88. RCU_TRACE(check_cpu_stall(&rcu_bh_ctrlblk));
  89. RCU_TRACE(check_cpu_stall(&rcu_sched_ctrlblk));
  90. RCU_TRACE(check_cpu_stall_preempt());
  91. }
  92. #ifdef CONFIG_RCU_TRACE
  93. /*
  94. * Because preemptible RCU does not exist, it is not necessary to
  95. * dump out its statistics.
  96. */
  97. static void show_tiny_preempt_stats(struct seq_file *m)
  98. {
  99. }
  100. #endif /* #ifdef CONFIG_RCU_TRACE */
  101. /*
  102. * Because preemptible RCU does not exist, it never has any callbacks
  103. * to check.
  104. */
  105. static void rcu_preempt_check_callbacks(void)
  106. {
  107. }
  108. /*
  109. * Because preemptible RCU does not exist, it never has any callbacks
  110. * to remove.
  111. */
  112. static void rcu_preempt_remove_callbacks(struct rcu_ctrlblk *rcp)
  113. {
  114. }
  115. /*
  116. * Because preemptible RCU does not exist, it never has any callbacks
  117. * to process.
  118. */
  119. static void rcu_preempt_process_callbacks(void)
  120. {
  121. }
  122. /* Hold off callback invocation until early_initcall() time. */
  123. static int rcu_scheduler_fully_active __read_mostly;
  124. /*
  125. * Start up softirq processing of callbacks.
  126. */
  127. void invoke_rcu_callbacks(void)
  128. {
  129. if (rcu_scheduler_fully_active)
  130. raise_softirq(RCU_SOFTIRQ);
  131. }
  132. #ifdef CONFIG_RCU_TRACE
  133. /*
  134. * There is no callback kthread, so this thread is never it.
  135. */
  136. static bool rcu_is_callbacks_kthread(void)
  137. {
  138. return false;
  139. }
  140. #endif /* #ifdef CONFIG_RCU_TRACE */
  141. static int __init rcu_scheduler_really_started(void)
  142. {
  143. rcu_scheduler_fully_active = 1;
  144. open_softirq(RCU_SOFTIRQ, rcu_process_callbacks);
  145. raise_softirq(RCU_SOFTIRQ); /* Invoke any callbacks from early boot. */
  146. return 0;
  147. }
  148. early_initcall(rcu_scheduler_really_started);
  149. #ifdef CONFIG_DEBUG_LOCK_ALLOC
  150. #include <linux/kernel_stat.h>
  151. /*
  152. * During boot, we forgive RCU lockdep issues. After this function is
  153. * invoked, we start taking RCU lockdep issues seriously.
  154. */
  155. void __init rcu_scheduler_starting(void)
  156. {
  157. WARN_ON(nr_context_switches() > 0);
  158. rcu_scheduler_active = 1;
  159. }
  160. #endif /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
  161. #ifdef CONFIG_RCU_TRACE
  162. static void rcu_trace_sub_qlen(struct rcu_ctrlblk *rcp, int n)
  163. {
  164. unsigned long flags;
  165. local_irq_save(flags);
  166. rcp->qlen -= n;
  167. local_irq_restore(flags);
  168. }
  169. /*
  170. * Dump statistics for TINY_RCU, such as they are.
  171. */
  172. static int show_tiny_stats(struct seq_file *m, void *unused)
  173. {
  174. show_tiny_preempt_stats(m);
  175. seq_printf(m, "rcu_sched: qlen: %ld\n", rcu_sched_ctrlblk.qlen);
  176. seq_printf(m, "rcu_bh: qlen: %ld\n", rcu_bh_ctrlblk.qlen);
  177. return 0;
  178. }
  179. static int show_tiny_stats_open(struct inode *inode, struct file *file)
  180. {
  181. return single_open(file, show_tiny_stats, NULL);
  182. }
  183. static const struct file_operations show_tiny_stats_fops = {
  184. .owner = THIS_MODULE,
  185. .open = show_tiny_stats_open,
  186. .read = seq_read,
  187. .llseek = seq_lseek,
  188. .release = single_release,
  189. };
  190. static struct dentry *rcudir;
  191. static int __init rcutiny_trace_init(void)
  192. {
  193. struct dentry *retval;
  194. rcudir = debugfs_create_dir("rcu", NULL);
  195. if (!rcudir)
  196. goto free_out;
  197. retval = debugfs_create_file("rcudata", 0444, rcudir,
  198. NULL, &show_tiny_stats_fops);
  199. if (!retval)
  200. goto free_out;
  201. return 0;
  202. free_out:
  203. debugfs_remove_recursive(rcudir);
  204. return 1;
  205. }
  206. static void __exit rcutiny_trace_cleanup(void)
  207. {
  208. debugfs_remove_recursive(rcudir);
  209. }
  210. module_init(rcutiny_trace_init);
  211. module_exit(rcutiny_trace_cleanup);
  212. MODULE_AUTHOR("Paul E. McKenney");
  213. MODULE_DESCRIPTION("Read-Copy Update tracing for tiny implementation");
  214. MODULE_LICENSE("GPL");
  215. static void check_cpu_stall_preempt(void)
  216. {
  217. }
  218. #endif /* #ifdef CONFIG_RCU_TRACE */