tiny_plugin.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. /* Global control variables for rcupdate callback mechanism. */
  27. struct rcu_ctrlblk {
  28. struct rcu_head *rcucblist; /* List of pending callbacks (CBs). */
  29. struct rcu_head **donetail; /* ->next pointer of last "done" CB. */
  30. struct rcu_head **curtail; /* ->next pointer of last CB. */
  31. RCU_TRACE(long qlen); /* Number of pending CBs. */
  32. RCU_TRACE(unsigned long gp_start); /* Start time for stalls. */
  33. RCU_TRACE(unsigned long ticks_this_gp); /* Statistic for stalls. */
  34. RCU_TRACE(unsigned long jiffies_stall); /* Jiffies at next stall. */
  35. RCU_TRACE(const char *name); /* Name of RCU type. */
  36. };
  37. /* Definition for rcupdate control block. */
  38. static struct rcu_ctrlblk rcu_sched_ctrlblk = {
  39. .donetail = &rcu_sched_ctrlblk.rcucblist,
  40. .curtail = &rcu_sched_ctrlblk.rcucblist,
  41. RCU_TRACE(.name = "rcu_sched")
  42. };
  43. static struct rcu_ctrlblk rcu_bh_ctrlblk = {
  44. .donetail = &rcu_bh_ctrlblk.rcucblist,
  45. .curtail = &rcu_bh_ctrlblk.rcucblist,
  46. RCU_TRACE(.name = "rcu_bh")
  47. };
  48. #if defined(CONFIG_DEBUG_LOCK_ALLOC) || defined(CONFIG_SRCU)
  49. #include <linux/kernel_stat.h>
  50. int rcu_scheduler_active __read_mostly;
  51. EXPORT_SYMBOL_GPL(rcu_scheduler_active);
  52. /*
  53. * During boot, we forgive RCU lockdep issues. After this function is
  54. * invoked, we start taking RCU lockdep issues seriously. Note that unlike
  55. * Tree RCU, Tiny RCU transitions directly from RCU_SCHEDULER_INACTIVE
  56. * to RCU_SCHEDULER_RUNNING, skipping the RCU_SCHEDULER_INIT stage.
  57. * The reason for this is that Tiny RCU does not need kthreads, so does
  58. * not have to care about the fact that the scheduler is half-initialized
  59. * at a certain phase of the boot process. Unless SRCU is in the mix.
  60. */
  61. void __init rcu_scheduler_starting(void)
  62. {
  63. WARN_ON(nr_context_switches() > 0);
  64. rcu_scheduler_active = IS_ENABLED(CONFIG_SRCU)
  65. ? RCU_SCHEDULER_INIT : RCU_SCHEDULER_RUNNING;
  66. }
  67. #endif /* #if defined(CONFIG_DEBUG_LOCK_ALLOC) || defined(CONFIG_SRCU) */
  68. #ifdef CONFIG_RCU_TRACE
  69. static void rcu_trace_sub_qlen(struct rcu_ctrlblk *rcp, int n)
  70. {
  71. unsigned long flags;
  72. local_irq_save(flags);
  73. rcp->qlen -= n;
  74. local_irq_restore(flags);
  75. }
  76. static void check_cpu_stall(struct rcu_ctrlblk *rcp)
  77. {
  78. unsigned long j;
  79. unsigned long js;
  80. if (rcu_cpu_stall_suppress)
  81. return;
  82. rcp->ticks_this_gp++;
  83. j = jiffies;
  84. js = READ_ONCE(rcp->jiffies_stall);
  85. if (rcp->rcucblist && ULONG_CMP_GE(j, js)) {
  86. pr_err("INFO: %s stall on CPU (%lu ticks this GP) idle=%llx (t=%lu jiffies q=%ld)\n",
  87. rcp->name, rcp->ticks_this_gp, DYNTICK_TASK_EXIT_IDLE,
  88. jiffies - rcp->gp_start, rcp->qlen);
  89. dump_stack();
  90. WRITE_ONCE(rcp->jiffies_stall,
  91. jiffies + 3 * rcu_jiffies_till_stall_check() + 3);
  92. } else if (ULONG_CMP_GE(j, js)) {
  93. WRITE_ONCE(rcp->jiffies_stall,
  94. jiffies + rcu_jiffies_till_stall_check());
  95. }
  96. }
  97. static void reset_cpu_stall_ticks(struct rcu_ctrlblk *rcp)
  98. {
  99. rcp->ticks_this_gp = 0;
  100. rcp->gp_start = jiffies;
  101. WRITE_ONCE(rcp->jiffies_stall,
  102. jiffies + rcu_jiffies_till_stall_check());
  103. }
  104. static void check_cpu_stalls(void)
  105. {
  106. RCU_TRACE(check_cpu_stall(&rcu_bh_ctrlblk);)
  107. RCU_TRACE(check_cpu_stall(&rcu_sched_ctrlblk);)
  108. }
  109. #endif /* #ifdef CONFIG_RCU_TRACE */