tiny_plugin.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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, you can access it online at
  18. * http://www.gnu.org/licenses/gpl-2.0.html.
  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/init.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(const 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. #include <linux/kernel_stat.h>
  52. int rcu_scheduler_active __read_mostly;
  53. EXPORT_SYMBOL_GPL(rcu_scheduler_active);
  54. /*
  55. * During boot, we forgive RCU lockdep issues. After this function is
  56. * invoked, we start taking RCU lockdep issues seriously. Note that unlike
  57. * Tree RCU, Tiny RCU transitions directly from RCU_SCHEDULER_INACTIVE
  58. * to RCU_SCHEDULER_RUNNING, skipping the RCU_SCHEDULER_INIT stage.
  59. * The reason for this is that Tiny RCU does not need kthreads, so does
  60. * not have to care about the fact that the scheduler is half-initialized
  61. * at a certain phase of the boot process.
  62. */
  63. void __init rcu_scheduler_starting(void)
  64. {
  65. WARN_ON(nr_context_switches() > 0);
  66. rcu_scheduler_active = RCU_SCHEDULER_RUNNING;
  67. }
  68. #endif /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
  69. #ifdef CONFIG_RCU_TRACE
  70. static void rcu_trace_sub_qlen(struct rcu_ctrlblk *rcp, int n)
  71. {
  72. unsigned long flags;
  73. local_irq_save(flags);
  74. rcp->qlen -= n;
  75. local_irq_restore(flags);
  76. }
  77. /*
  78. * Dump statistics for TINY_RCU, such as they are.
  79. */
  80. static int show_tiny_stats(struct seq_file *m, void *unused)
  81. {
  82. seq_printf(m, "rcu_sched: qlen: %ld\n", rcu_sched_ctrlblk.qlen);
  83. seq_printf(m, "rcu_bh: qlen: %ld\n", rcu_bh_ctrlblk.qlen);
  84. return 0;
  85. }
  86. static int show_tiny_stats_open(struct inode *inode, struct file *file)
  87. {
  88. return single_open(file, show_tiny_stats, NULL);
  89. }
  90. static const struct file_operations show_tiny_stats_fops = {
  91. .owner = THIS_MODULE,
  92. .open = show_tiny_stats_open,
  93. .read = seq_read,
  94. .llseek = seq_lseek,
  95. .release = single_release,
  96. };
  97. static struct dentry *rcudir;
  98. static int __init rcutiny_trace_init(void)
  99. {
  100. struct dentry *retval;
  101. rcudir = debugfs_create_dir("rcu", NULL);
  102. if (!rcudir)
  103. goto free_out;
  104. retval = debugfs_create_file("rcudata", 0444, rcudir,
  105. NULL, &show_tiny_stats_fops);
  106. if (!retval)
  107. goto free_out;
  108. return 0;
  109. free_out:
  110. debugfs_remove_recursive(rcudir);
  111. return 1;
  112. }
  113. device_initcall(rcutiny_trace_init);
  114. static void check_cpu_stall(struct rcu_ctrlblk *rcp)
  115. {
  116. unsigned long j;
  117. unsigned long js;
  118. if (rcu_cpu_stall_suppress)
  119. return;
  120. rcp->ticks_this_gp++;
  121. j = jiffies;
  122. js = READ_ONCE(rcp->jiffies_stall);
  123. if (rcp->rcucblist && ULONG_CMP_GE(j, js)) {
  124. pr_err("INFO: %s stall on CPU (%lu ticks this GP) idle=%llx (t=%lu jiffies q=%ld)\n",
  125. rcp->name, rcp->ticks_this_gp, DYNTICK_TASK_EXIT_IDLE,
  126. jiffies - rcp->gp_start, rcp->qlen);
  127. dump_stack();
  128. WRITE_ONCE(rcp->jiffies_stall,
  129. jiffies + 3 * rcu_jiffies_till_stall_check() + 3);
  130. } else if (ULONG_CMP_GE(j, js)) {
  131. WRITE_ONCE(rcp->jiffies_stall,
  132. jiffies + rcu_jiffies_till_stall_check());
  133. }
  134. }
  135. static void reset_cpu_stall_ticks(struct rcu_ctrlblk *rcp)
  136. {
  137. rcp->ticks_this_gp = 0;
  138. rcp->gp_start = jiffies;
  139. WRITE_ONCE(rcp->jiffies_stall,
  140. jiffies + rcu_jiffies_till_stall_check());
  141. }
  142. static void check_cpu_stalls(void)
  143. {
  144. RCU_TRACE(check_cpu_stall(&rcu_bh_ctrlblk));
  145. RCU_TRACE(check_cpu_stall(&rcu_sched_ctrlblk));
  146. }
  147. #endif /* #ifdef CONFIG_RCU_TRACE */