Blame view
include/linux/srcu.h
6.38 KB
621934ee7 [PATCH] srcu-3: R... |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
/* * Sleepable Read-Copy Update mechanism for mutual exclusion * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License |
87de1cfdc rcu: Stop trackin... |
15 16 |
* along with this program; if not, you can access it online at * http://www.gnu.org/licenses/gpl-2.0.html. |
621934ee7 [PATCH] srcu-3: R... |
17 18 |
* * Copyright (C) IBM Corporation, 2006 |
4e87b2d7e srcu: Credit Lai ... |
19 |
* Copyright (C) Fujitsu, 2012 |
621934ee7 [PATCH] srcu-3: R... |
20 21 |
* * Author: Paul McKenney <paulmck@us.ibm.com> |
4e87b2d7e srcu: Credit Lai ... |
22 |
* Lai Jiangshan <laijs@cn.fujitsu.com> |
621934ee7 [PATCH] srcu-3: R... |
23 24 |
* * For detailed explanation of Read-Copy Update mechanism see - |
8660b7d8a srcu: Use rcu_seg... |
25 |
* Documentation/RCU/ *.txt |
621934ee7 [PATCH] srcu-3: R... |
26 27 |
* */ |
eabc06940 [PATCH] Add SRCU-... |
28 29 |
#ifndef _LINUX_SRCU_H #define _LINUX_SRCU_H |
d14aada8e rcu: make SRCU us... |
30 |
#include <linux/mutex.h> |
ff195cb69 rcu: Warn when sr... |
31 |
#include <linux/rcupdate.h> |
931ea9d1a rcu: Implement pe... |
32 |
#include <linux/workqueue.h> |
8660b7d8a srcu: Use rcu_seg... |
33 |
#include <linux/rcu_segcblist.h> |
d14aada8e rcu: make SRCU us... |
34 |
|
d8be81735 srcu: Create a ti... |
35 |
struct srcu_struct; |
c2a8ec077 srcu: Move to sta... |
36 |
|
632ee2001 rcu: Introduce lo... |
37 38 39 40 41 42 43 44 45 46 47 |
#ifdef CONFIG_DEBUG_LOCK_ALLOC int __init_srcu_struct(struct srcu_struct *sp, const char *name, struct lock_class_key *key); #define init_srcu_struct(sp) \ ({ \ static struct lock_class_key __srcu_key; \ \ __init_srcu_struct((sp), #sp, &__srcu_key); \ }) |
55c6659af srcu: Add DEFINE_... |
48 |
#define __SRCU_DEP_MAP_INIT(srcu_name) .dep_map = { .name = #srcu_name }, |
632ee2001 rcu: Introduce lo... |
49 |
#else /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */ |
e6a92013b [PATCH] SRCU: rep... |
50 |
int init_srcu_struct(struct srcu_struct *sp); |
632ee2001 rcu: Introduce lo... |
51 |
|
55c6659af srcu: Add DEFINE_... |
52 |
#define __SRCU_DEP_MAP_INIT(srcu_name) |
632ee2001 rcu: Introduce lo... |
53 |
#endif /* #else #ifdef CONFIG_DEBUG_LOCK_ALLOC */ |
d8be81735 srcu: Create a ti... |
54 55 56 57 |
#ifdef CONFIG_TINY_SRCU #include <linux/srcutiny.h> #elif defined(CONFIG_TREE_SRCU) #include <linux/srcutree.h> |
07f6e64bf srcu: Make SRCU b... |
58 |
#elif defined(CONFIG_SRCU) |
d8be81735 srcu: Create a ti... |
59 |
#error "Unknown SRCU implementation specified to kernel configuration" |
07f6e64bf srcu: Make SRCU b... |
60 |
#else |
07f6e64bf srcu: Make SRCU b... |
61 62 |
/* Dummy definition for things like notifiers. Actual use gets link error. */ struct srcu_struct { }; |
d8be81735 srcu: Create a ti... |
63 |
#endif |
55c6659af srcu: Add DEFINE_... |
64 |
|
931ea9d1a rcu: Implement pe... |
65 66 |
void call_srcu(struct srcu_struct *sp, struct rcu_head *head, void (*func)(struct rcu_head *head)); |
621934ee7 [PATCH] srcu-3: R... |
67 |
void cleanup_srcu_struct(struct srcu_struct *sp); |
632ee2001 rcu: Introduce lo... |
68 69 |
int __srcu_read_lock(struct srcu_struct *sp) __acquires(sp); void __srcu_read_unlock(struct srcu_struct *sp, int idx) __releases(sp); |
621934ee7 [PATCH] srcu-3: R... |
70 |
void synchronize_srcu(struct srcu_struct *sp); |
eabc06940 [PATCH] Add SRCU-... |
71 |
|
632ee2001 rcu: Introduce lo... |
72 73 74 75 |
#ifdef CONFIG_DEBUG_LOCK_ALLOC /** * srcu_read_lock_held - might we be in SRCU read-side critical section? |
27fdb35fe doc: Fix various ... |
76 |
* @sp: The srcu_struct structure to check |
632ee2001 rcu: Introduce lo... |
77 |
* |
d20200b59 rcu: Fix bogus CO... |
78 79 |
* If CONFIG_DEBUG_LOCK_ALLOC is selected, returns nonzero iff in an SRCU * read-side critical section. In absence of CONFIG_DEBUG_LOCK_ALLOC, |
632ee2001 rcu: Introduce lo... |
80 81 |
* this assumes we are in an SRCU read-side critical section unless it can * prove otherwise. |
ff195cb69 rcu: Warn when sr... |
82 |
* |
867f236bd rcu: Make srcu_re... |
83 84 85 |
* Checks debug_lockdep_rcu_enabled() to prevent false positives during boot * and while lockdep is disabled. * |
511a0868b srcu: Remove chec... |
86 87 88 |
* Note that SRCU is based on its own statemachine and it doesn't * relies on normal RCU, it can be called from the CPU which * is in the idle loop from an RCU point of view or offline. |
632ee2001 rcu: Introduce lo... |
89 90 91 |
*/ static inline int srcu_read_lock_held(struct srcu_struct *sp) { |
867f236bd rcu: Make srcu_re... |
92 |
if (!debug_lockdep_rcu_enabled()) |
ff195cb69 rcu: Warn when sr... |
93 |
return 1; |
ff195cb69 rcu: Warn when sr... |
94 |
return lock_is_held(&sp->dep_map); |
632ee2001 rcu: Introduce lo... |
95 96 97 98 99 100 101 102 103 104 105 106 |
} #else /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */ static inline int srcu_read_lock_held(struct srcu_struct *sp) { return 1; } #endif /* #else #ifdef CONFIG_DEBUG_LOCK_ALLOC */ /** |
ca5ecddfa rcu: define __rcu... |
107 108 109 110 111 |
* srcu_dereference_check - fetch SRCU-protected pointer for later dereferencing * @p: the pointer to fetch and protect for later dereferencing * @sp: pointer to the srcu_struct, which is used to check that we * really are in an SRCU read-side critical section. * @c: condition to check for update-side use |
c26d34a58 rcu: Add lockdep-... |
112 |
* |
ca5ecddfa rcu: define __rcu... |
113 114 115 116 |
* If PROVE_RCU is enabled, invoking this outside of an RCU read-side * critical section will result in an RCU-lockdep splat, unless @c evaluates * to 1. The @c argument will normally be a logical expression containing * lockdep_is_held() calls. |
c26d34a58 rcu: Add lockdep-... |
117 |
*/ |
ca5ecddfa rcu: define __rcu... |
118 |
#define srcu_dereference_check(p, sp, c) \ |
b826565aa rcu: Reverse rcu_... |
119 |
__rcu_dereference_check((p), (c) || srcu_read_lock_held(sp), __rcu) |
ca5ecddfa rcu: define __rcu... |
120 121 122 123 124 125 126 127 128 129 130 131 |
/** * srcu_dereference - fetch SRCU-protected pointer for later dereferencing * @p: the pointer to fetch and protect for later dereferencing * @sp: pointer to the srcu_struct, which is used to check that we * really are in an SRCU read-side critical section. * * Makes rcu_dereference_check() do the dirty work. If PROVE_RCU * is enabled, invoking this outside of an RCU read-side critical * section will result in an RCU-lockdep splat. */ #define srcu_dereference(p, sp) srcu_dereference_check((p), (sp), 0) |
c26d34a58 rcu: Add lockdep-... |
132 133 |
/** |
632ee2001 rcu: Introduce lo... |
134 135 136 137 |
* srcu_read_lock - register a new reader for an SRCU-protected structure. * @sp: srcu_struct in which to register the new reader. * * Enter an SRCU read-side critical section. Note that SRCU read-side |
73d4da4d3 rcu: Upgrade srcu... |
138 139 140 141 142 143 |
* critical sections may be nested. However, it is illegal to * call anything that waits on an SRCU grace period for the same * srcu_struct, whether directly or indirectly. Please note that * one way to indirectly wait on an SRCU grace period is to acquire * a mutex that is held elsewhere while calling synchronize_srcu() or * synchronize_srcu_expedited(). |
3842a0832 rcu: Document sam... |
144 145 146 147 148 |
* * Note that srcu_read_lock() and the matching srcu_read_unlock() must * occur in the same context, for example, it is illegal to invoke * srcu_read_unlock() in an irq handler if the matching srcu_read_lock() * was invoked in process context. |
632ee2001 rcu: Introduce lo... |
149 150 151 |
*/ static inline int srcu_read_lock(struct srcu_struct *sp) __acquires(sp) { |
49f5903b4 rcu: Move preempt... |
152 |
int retval; |
632ee2001 rcu: Introduce lo... |
153 |
|
49f5903b4 rcu: Move preempt... |
154 |
retval = __srcu_read_lock(sp); |
ff195cb69 rcu: Warn when sr... |
155 |
rcu_lock_acquire(&(sp)->dep_map); |
632ee2001 rcu: Introduce lo... |
156 157 158 159 160 161 162 163 164 165 166 167 168 |
return retval; } /** * srcu_read_unlock - unregister a old reader from an SRCU-protected structure. * @sp: srcu_struct in which to unregister the old reader. * @idx: return value from corresponding srcu_read_lock(). * * Exit an SRCU read-side critical section. */ static inline void srcu_read_unlock(struct srcu_struct *sp, int idx) __releases(sp) { |
ff195cb69 rcu: Warn when sr... |
169 |
rcu_lock_release(&(sp)->dep_map); |
632ee2001 rcu: Introduce lo... |
170 171 |
__srcu_read_unlock(sp, idx); } |
ce332f662 srcu: API for bar... |
172 173 174 175 176 177 178 179 180 181 182 183 184 |
/** * smp_mb__after_srcu_read_unlock - ensure full ordering after srcu_read_unlock * * Converts the preceding srcu_read_unlock into a two-way memory barrier. * * Call this after srcu_read_unlock, to guarantee that all memory operations * that occur after smp_mb__after_srcu_read_unlock will appear to happen after * the preceding srcu_read_unlock. */ static inline void smp_mb__after_srcu_read_unlock(void) { /* __srcu_read_unlock has smp_mb() internally so nothing to do here. */ } |
eabc06940 [PATCH] Add SRCU-... |
185 |
#endif |