| Paul E. McKenney | 01c1c66 | 2008-01-25 21:08:24 +0100 | [diff] [blame] | 1 | /* | 
|  | 2 | * Read-Copy Update mechanism for mutual exclusion (classic version) | 
|  | 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, 2001 | 
|  | 19 | * | 
|  | 20 | * Author: Dipankar Sarma <dipankar@in.ibm.com> | 
|  | 21 | * | 
|  | 22 | * Based on the original work by Paul McKenney <paulmck@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 |  | 
|  | 33 | #ifndef __LINUX_RCUCLASSIC_H | 
|  | 34 | #define __LINUX_RCUCLASSIC_H | 
|  | 35 |  | 
| Paul E. McKenney | 01c1c66 | 2008-01-25 21:08:24 +0100 | [diff] [blame] | 36 | #include <linux/cache.h> | 
|  | 37 | #include <linux/spinlock.h> | 
|  | 38 | #include <linux/threads.h> | 
|  | 39 | #include <linux/percpu.h> | 
|  | 40 | #include <linux/cpumask.h> | 
|  | 41 | #include <linux/seqlock.h> | 
|  | 42 |  | 
| Paul E. McKenney | 2133b5d | 2008-10-02 16:06:39 -0700 | [diff] [blame] | 43 | #ifdef CONFIG_RCU_CPU_STALL_DETECTOR | 
| Paul E. McKenney | 29cbda7 | 2008-11-03 09:16:39 -0800 | [diff] [blame] | 44 | #define RCU_SECONDS_TILL_STALL_CHECK	(10 * HZ) /* for rcp->jiffies_stall */ | 
| Paul E. McKenney | 2133b5d | 2008-10-02 16:06:39 -0700 | [diff] [blame] | 45 | #define RCU_SECONDS_TILL_STALL_RECHECK	(30 * HZ) /* for rcp->jiffies_stall */ | 
|  | 46 | #endif /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */ | 
| Paul E. McKenney | 01c1c66 | 2008-01-25 21:08:24 +0100 | [diff] [blame] | 47 |  | 
|  | 48 | /* Global control variables for rcupdate callback mechanism. */ | 
|  | 49 | struct rcu_ctrlblk { | 
|  | 50 | long	cur;		/* Current batch number.                      */ | 
|  | 51 | long	completed;	/* Number of the last completed batch         */ | 
| Lai Jiangshan | 3cac97c | 2008-07-06 17:23:55 +0800 | [diff] [blame] | 52 | long	pending;	/* Number of the last pending batch           */ | 
| Paul E. McKenney | 2133b5d | 2008-10-02 16:06:39 -0700 | [diff] [blame] | 53 | #ifdef CONFIG_RCU_CPU_STALL_DETECTOR | 
|  | 54 | unsigned long gp_start;	/* Time at which GP started in jiffies. */ | 
|  | 55 | unsigned long jiffies_stall; | 
|  | 56 | /* Time at which to check for CPU stalls. */ | 
|  | 57 | #endif /* #ifdef CONFIG_RCU_CPU_STALL_DETECTOR */ | 
| Paul E. McKenney | 01c1c66 | 2008-01-25 21:08:24 +0100 | [diff] [blame] | 58 |  | 
|  | 59 | int	signaled; | 
|  | 60 |  | 
|  | 61 | spinlock_t	lock	____cacheline_internodealigned_in_smp; | 
| Rusty Russell | bd232f9 | 2009-01-01 10:12:26 +1030 | [diff] [blame] | 62 | DECLARE_BITMAP(cpumask, NR_CPUS); /* CPUs that need to switch for */ | 
|  | 63 | /* current batch to proceed.     */ | 
| Paul E. McKenney | 01c1c66 | 2008-01-25 21:08:24 +0100 | [diff] [blame] | 64 | } ____cacheline_internodealigned_in_smp; | 
|  | 65 |  | 
|  | 66 | /* Is batch a before batch b ? */ | 
|  | 67 | static inline int rcu_batch_before(long a, long b) | 
|  | 68 | { | 
|  | 69 | return (a - b) < 0; | 
|  | 70 | } | 
|  | 71 |  | 
|  | 72 | /* Is batch a after batch b ? */ | 
|  | 73 | static inline int rcu_batch_after(long a, long b) | 
|  | 74 | { | 
|  | 75 | return (a - b) > 0; | 
|  | 76 | } | 
|  | 77 |  | 
| Lai Jiangshan | 5127bed | 2008-07-06 17:23:59 +0800 | [diff] [blame] | 78 | /* Per-CPU data for Read-Copy UPdate. */ | 
| Paul E. McKenney | 01c1c66 | 2008-01-25 21:08:24 +0100 | [diff] [blame] | 79 | struct rcu_data { | 
|  | 80 | /* 1) quiescent state handling : */ | 
|  | 81 | long		quiescbatch;     /* Batch # for grace period */ | 
|  | 82 | int		passed_quiesc;	 /* User-mode/idle loop etc. */ | 
|  | 83 | int		qs_pending;	 /* core waits for quiesc state */ | 
|  | 84 |  | 
|  | 85 | /* 2) batch handling */ | 
| Lai Jiangshan | 5127bed | 2008-07-06 17:23:59 +0800 | [diff] [blame] | 86 | /* | 
|  | 87 | * if nxtlist is not NULL, then: | 
|  | 88 | * batch: | 
|  | 89 | *	The batch # for the last entry of nxtlist | 
|  | 90 | * [*nxttail[1], NULL = *nxttail[2]): | 
|  | 91 | *	Entries that batch # <= batch | 
|  | 92 | * [*nxttail[0], *nxttail[1]): | 
|  | 93 | *	Entries that batch # <= batch - 1 | 
|  | 94 | * [nxtlist, *nxttail[0]): | 
|  | 95 | *	Entries that batch # <= batch - 2 | 
|  | 96 | *	The grace period for these entries has completed, and | 
|  | 97 | *	the other grace-period-completed entries may be moved | 
|  | 98 | *	here temporarily in rcu_process_callbacks(). | 
|  | 99 | */ | 
|  | 100 | long  	       	batch; | 
| Paul E. McKenney | 01c1c66 | 2008-01-25 21:08:24 +0100 | [diff] [blame] | 101 | struct rcu_head *nxtlist; | 
| Lai Jiangshan | 5127bed | 2008-07-06 17:23:59 +0800 | [diff] [blame] | 102 | struct rcu_head **nxttail[3]; | 
| Paul E. McKenney | 01c1c66 | 2008-01-25 21:08:24 +0100 | [diff] [blame] | 103 | long            qlen; 	 	 /* # of queued callbacks */ | 
| Paul E. McKenney | 01c1c66 | 2008-01-25 21:08:24 +0100 | [diff] [blame] | 104 | struct rcu_head *donelist; | 
|  | 105 | struct rcu_head **donetail; | 
|  | 106 | long		blimit;		 /* Upper limit on a processed batch */ | 
|  | 107 | int cpu; | 
|  | 108 | struct rcu_head barrier; | 
|  | 109 | }; | 
|  | 110 |  | 
| Paul E. McKenney | 01c1c66 | 2008-01-25 21:08:24 +0100 | [diff] [blame] | 111 | /* | 
|  | 112 | * Increment the quiescent state counter. | 
|  | 113 | * The counter is a bit degenerated: We do not need to know | 
|  | 114 | * how many quiescent states passed, just if there was at least | 
|  | 115 | * one since the start of the grace period. Thus just a flag. | 
|  | 116 | */ | 
| Ingo Molnar | b1f77b0 | 2009-03-13 03:20:49 +0100 | [diff] [blame^] | 117 | extern void rcu_qsctr_inc(int cpu); | 
|  | 118 | extern void rcu_bh_qsctr_inc(int cpu); | 
| Paul E. McKenney | 01c1c66 | 2008-01-25 21:08:24 +0100 | [diff] [blame] | 119 |  | 
|  | 120 | extern int rcu_pending(int cpu); | 
|  | 121 | extern int rcu_needs_cpu(int cpu); | 
|  | 122 |  | 
|  | 123 | #ifdef CONFIG_DEBUG_LOCK_ALLOC | 
|  | 124 | extern struct lockdep_map rcu_lock_map; | 
|  | 125 | # define rcu_read_acquire()	\ | 
| Peter Zijlstra | 7531e2f | 2008-08-11 09:30:24 +0200 | [diff] [blame] | 126 | lock_acquire(&rcu_lock_map, 0, 0, 2, 1, NULL, _THIS_IP_) | 
| Paul E. McKenney | 01c1c66 | 2008-01-25 21:08:24 +0100 | [diff] [blame] | 127 | # define rcu_read_release()	lock_release(&rcu_lock_map, 1, _THIS_IP_) | 
|  | 128 | #else | 
|  | 129 | # define rcu_read_acquire()	do { } while (0) | 
|  | 130 | # define rcu_read_release()	do { } while (0) | 
|  | 131 | #endif | 
|  | 132 |  | 
|  | 133 | #define __rcu_read_lock() \ | 
|  | 134 | do { \ | 
|  | 135 | preempt_disable(); \ | 
|  | 136 | __acquire(RCU); \ | 
|  | 137 | rcu_read_acquire(); \ | 
|  | 138 | } while (0) | 
|  | 139 | #define __rcu_read_unlock() \ | 
|  | 140 | do { \ | 
|  | 141 | rcu_read_release(); \ | 
|  | 142 | __release(RCU); \ | 
|  | 143 | preempt_enable(); \ | 
|  | 144 | } while (0) | 
|  | 145 | #define __rcu_read_lock_bh() \ | 
|  | 146 | do { \ | 
|  | 147 | local_bh_disable(); \ | 
|  | 148 | __acquire(RCU_BH); \ | 
|  | 149 | rcu_read_acquire(); \ | 
|  | 150 | } while (0) | 
|  | 151 | #define __rcu_read_unlock_bh() \ | 
|  | 152 | do { \ | 
|  | 153 | rcu_read_release(); \ | 
|  | 154 | __release(RCU_BH); \ | 
|  | 155 | local_bh_enable(); \ | 
|  | 156 | } while (0) | 
|  | 157 |  | 
|  | 158 | #define __synchronize_sched() synchronize_rcu() | 
|  | 159 |  | 
| Paul E. McKenney | 4446a36 | 2008-05-12 21:21:05 +0200 | [diff] [blame] | 160 | #define call_rcu_sched(head, func) call_rcu(head, func) | 
|  | 161 |  | 
| Paul E. McKenney | 01c1c66 | 2008-01-25 21:08:24 +0100 | [diff] [blame] | 162 | extern void __rcu_init(void); | 
| Paul E. McKenney | 4446a36 | 2008-05-12 21:21:05 +0200 | [diff] [blame] | 163 | #define rcu_init_sched()	do { } while (0) | 
| Paul E. McKenney | 01c1c66 | 2008-01-25 21:08:24 +0100 | [diff] [blame] | 164 | extern void rcu_check_callbacks(int cpu, int user); | 
|  | 165 | extern void rcu_restart_cpu(int cpu); | 
|  | 166 |  | 
| Paul E. McKenney | e260be6 | 2008-01-25 21:08:24 +0100 | [diff] [blame] | 167 | extern long rcu_batches_completed(void); | 
|  | 168 | extern long rcu_batches_completed_bh(void); | 
|  | 169 |  | 
| Steven Rostedt | 2232c2d | 2008-02-29 18:46:50 +0100 | [diff] [blame] | 170 | #define rcu_enter_nohz()	do { } while (0) | 
|  | 171 | #define rcu_exit_nohz()		do { } while (0) | 
|  | 172 |  | 
| Paul E. McKenney | a682604 | 2009-02-25 18:03:42 -0800 | [diff] [blame] | 173 | /* A context switch is a grace period for rcuclassic. */ | 
|  | 174 | static inline int rcu_blocking_is_gp(void) | 
|  | 175 | { | 
|  | 176 | return num_online_cpus() == 1; | 
|  | 177 | } | 
|  | 178 |  | 
| Paul E. McKenney | 01c1c66 | 2008-01-25 21:08:24 +0100 | [diff] [blame] | 179 | #endif /* __LINUX_RCUCLASSIC_H */ |