2 * Sleepable Read-Copy Update mechanism for mutual exclusion,
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, you can access it online at
17 * http://www.gnu.org/licenses/gpl-2.0.html.
19 * Copyright (C) IBM Corporation, 2017
21 * Author: Paul McKenney <paulmck@us.ibm.com>
24 #ifndef _LINUX_SRCU_TREE_H
25 #define _LINUX_SRCU_TREE_H
28 unsigned long lock_count
[2];
29 unsigned long unlock_count
[2];
33 unsigned long completed
;
34 unsigned long srcu_gp_seq
;
35 atomic_t srcu_exp_cnt
;
36 struct srcu_array __percpu
*per_cpu_ref
;
37 spinlock_t queue_lock
; /* protect ->srcu_cblist */
38 struct rcu_segcblist srcu_cblist
;
39 struct delayed_work work
;
40 #ifdef CONFIG_DEBUG_LOCK_ALLOC
41 struct lockdep_map dep_map
;
42 #endif /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
45 /* Values for -> state variable. */
46 #define SRCU_STATE_IDLE 0
47 #define SRCU_STATE_SCAN1 1
48 #define SRCU_STATE_SCAN2 2
50 void process_srcu(struct work_struct
*work
);
52 #define __SRCU_STRUCT_INIT(name) \
55 .per_cpu_ref = &name##_srcu_array, \
56 .queue_lock = __SPIN_LOCK_UNLOCKED(name.queue_lock), \
57 .srcu_cblist = RCU_SEGCBLIST_INITIALIZER(name.srcu_cblist),\
58 .work = __DELAYED_WORK_INITIALIZER(name.work, process_srcu, 0),\
59 __SRCU_DEP_MAP_INIT(name) \
63 * Define and initialize a srcu struct at build time.
64 * Do -not- call init_srcu_struct() nor cleanup_srcu_struct() on it.
66 * Note that although DEFINE_STATIC_SRCU() hides the name from other
67 * files, the per-CPU variable rules nevertheless require that the
68 * chosen name be globally unique. These rules also prohibit use of
69 * DEFINE_STATIC_SRCU() within a function. If these rules are too
70 * restrictive, declare the srcu_struct manually. For example, in
73 * static struct srcu_struct my_srcu;
75 * Then, before the first use of each my_srcu, manually initialize it:
77 * init_srcu_struct(&my_srcu);
79 * See include/linux/percpu-defs.h for the rules on per-CPU variables.
81 #define __DEFINE_SRCU(name, is_static) \
82 static DEFINE_PER_CPU(struct srcu_array, name##_srcu_array);\
83 is_static struct srcu_struct name = __SRCU_STRUCT_INIT(name)
84 #define DEFINE_SRCU(name) __DEFINE_SRCU(name, /* not static */)
85 #define DEFINE_STATIC_SRCU(name) __DEFINE_SRCU(name, static)
87 void synchronize_srcu_expedited(struct srcu_struct
*sp
);
88 void srcu_barrier(struct srcu_struct
*sp
);
89 unsigned long srcu_batches_completed(struct srcu_struct
*sp
);