rcupreempt.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * Read-Copy Update mechanism for mutual exclusion (RT 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 (C) IBM Corporation, 2006
  19. *
  20. * Author: Paul McKenney <paulmck@us.ibm.com>
  21. *
  22. * Based on the original work by Paul McKenney <paul.mckenney@us.ibm.com>
  23. * and inputs from Rusty Russell, Andrea Arcangeli and Andi Kleen.
  24. * Papers:
  25. * http://www.rdrop.com/users/paulmck/paper/rclockpdcsproof.pdf
  26. * http://lse.sourceforge.net/locking/rclock_OLS.2001.05.01c.sc.pdf (OLS2001)
  27. *
  28. * For detailed explanation of Read-Copy Update mechanism see -
  29. * Documentation/RCU
  30. *
  31. */
  32. #ifndef __LINUX_RCUPREEMPT_H
  33. #define __LINUX_RCUPREEMPT_H
  34. #include <linux/cache.h>
  35. #include <linux/spinlock.h>
  36. #include <linux/threads.h>
  37. #include <linux/percpu.h>
  38. #include <linux/cpumask.h>
  39. #include <linux/seqlock.h>
  40. struct rcu_dyntick_sched {
  41. int dynticks;
  42. int dynticks_snap;
  43. int sched_qs;
  44. int sched_qs_snap;
  45. int sched_dynticks_snap;
  46. };
  47. DECLARE_PER_CPU(struct rcu_dyntick_sched, rcu_dyntick_sched);
  48. static inline void rcu_qsctr_inc(int cpu)
  49. {
  50. struct rcu_dyntick_sched *rdssp = &per_cpu(rcu_dyntick_sched, cpu);
  51. rdssp->sched_qs++;
  52. }
  53. #define rcu_bh_qsctr_inc(cpu)
  54. /*
  55. * Someone might want to pass call_rcu_bh as a function pointer.
  56. * So this needs to just be a rename and not a macro function.
  57. * (no parentheses)
  58. */
  59. #define call_rcu_bh call_rcu
  60. /**
  61. * call_rcu_sched - Queue RCU callback for invocation after sched grace period.
  62. * @head: structure to be used for queueing the RCU updates.
  63. * @func: actual update function to be invoked after the grace period
  64. *
  65. * The update function will be invoked some time after a full
  66. * synchronize_sched()-style grace period elapses, in other words after
  67. * all currently executing preempt-disabled sections of code (including
  68. * hardirq handlers, NMI handlers, and local_irq_save() blocks) have
  69. * completed.
  70. */
  71. extern void call_rcu_sched(struct rcu_head *head,
  72. void (*func)(struct rcu_head *head));
  73. extern void __rcu_read_lock(void) __acquires(RCU);
  74. extern void __rcu_read_unlock(void) __releases(RCU);
  75. extern int rcu_pending(int cpu);
  76. extern int rcu_needs_cpu(int cpu);
  77. #define __rcu_read_lock_bh() { rcu_read_lock(); local_bh_disable(); }
  78. #define __rcu_read_unlock_bh() { local_bh_enable(); rcu_read_unlock(); }
  79. extern void __synchronize_sched(void);
  80. extern void __rcu_init(void);
  81. extern void rcu_init_sched(void);
  82. extern void rcu_check_callbacks(int cpu, int user);
  83. extern void rcu_restart_cpu(int cpu);
  84. extern long rcu_batches_completed(void);
  85. /*
  86. * Return the number of RCU batches processed thus far. Useful for debug
  87. * and statistic. The _bh variant is identifcal to straight RCU
  88. */
  89. static inline long rcu_batches_completed_bh(void)
  90. {
  91. return rcu_batches_completed();
  92. }
  93. #ifdef CONFIG_RCU_TRACE
  94. struct rcupreempt_trace;
  95. extern long *rcupreempt_flipctr(int cpu);
  96. extern long rcupreempt_data_completed(void);
  97. extern int rcupreempt_flip_flag(int cpu);
  98. extern int rcupreempt_mb_flag(int cpu);
  99. extern char *rcupreempt_try_flip_state_name(void);
  100. extern struct rcupreempt_trace *rcupreempt_trace_cpu(int cpu);
  101. #endif
  102. struct softirq_action;
  103. #ifdef CONFIG_NO_HZ
  104. static inline void rcu_enter_nohz(void)
  105. {
  106. static DEFINE_RATELIMIT_STATE(rs, 10 * HZ, 1);
  107. smp_mb(); /* CPUs seeing ++ must see prior RCU read-side crit sects */
  108. __get_cpu_var(rcu_dyntick_sched).dynticks++;
  109. WARN_ON_RATELIMIT(__get_cpu_var(rcu_dyntick_sched).dynticks & 0x1, &rs);
  110. }
  111. static inline void rcu_exit_nohz(void)
  112. {
  113. static DEFINE_RATELIMIT_STATE(rs, 10 * HZ, 1);
  114. __get_cpu_var(rcu_dyntick_sched).dynticks++;
  115. smp_mb(); /* CPUs seeing ++ must see later RCU read-side crit sects */
  116. WARN_ON_RATELIMIT(!(__get_cpu_var(rcu_dyntick_sched).dynticks & 0x1),
  117. &rs);
  118. }
  119. #else /* CONFIG_NO_HZ */
  120. #define rcu_enter_nohz() do { } while (0)
  121. #define rcu_exit_nohz() do { } while (0)
  122. #endif /* CONFIG_NO_HZ */
  123. /*
  124. * A context switch is a grace period for rcupreempt synchronize_rcu()
  125. * only during early boot, before the scheduler has been initialized.
  126. * So, how the heck do we get a context switch? Well, if the caller
  127. * invokes synchronize_rcu(), they are willing to accept a context
  128. * switch, so we simply pretend that one happened.
  129. *
  130. * After boot, there might be a blocked or preempted task in an RCU
  131. * read-side critical section, so we cannot then take the fastpath.
  132. */
  133. static inline int rcu_blocking_is_gp(void)
  134. {
  135. return num_online_cpus() == 1 && !rcu_scheduler_active;
  136. }
  137. #endif /* __LINUX_RCUPREEMPT_H */