|
| 1 | +/* |
| 2 | + * Sleepable Read-Copy Update mechanism for mutual exclusion, |
| 3 | + * tree variant. |
| 4 | + * |
| 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. |
| 9 | + * |
| 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. |
| 14 | + * |
| 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. |
| 18 | + * |
| 19 | + * Copyright (C) IBM Corporation, 2017 |
| 20 | + * |
| 21 | + * Author: Paul McKenney <paulmck@us.ibm.com> |
| 22 | + */ |
| 23 | + |
| 24 | +#ifndef _LINUX_SRCU_TREE_H |
| 25 | +#define _LINUX_SRCU_TREE_H |
| 26 | + |
| 27 | +struct srcu_array { |
| 28 | + unsigned long lock_count[2]; |
| 29 | + unsigned long unlock_count[2]; |
| 30 | +}; |
| 31 | + |
| 32 | +struct srcu_struct { |
| 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 */ |
| 43 | +}; |
| 44 | + |
| 45 | +/* Values for -> state variable. */ |
| 46 | +#define SRCU_STATE_IDLE 0 |
| 47 | +#define SRCU_STATE_SCAN1 1 |
| 48 | +#define SRCU_STATE_SCAN2 2 |
| 49 | + |
| 50 | +void process_srcu(struct work_struct *work); |
| 51 | + |
| 52 | +#define __SRCU_STRUCT_INIT(name) \ |
| 53 | + { \ |
| 54 | + .completed = -300, \ |
| 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) \ |
| 60 | + } |
| 61 | + |
| 62 | +/* |
| 63 | + * Define and initialize a srcu struct at build time. |
| 64 | + * Do -not- call init_srcu_struct() nor cleanup_srcu_struct() on it. |
| 65 | + * |
| 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 |
| 71 | + * each file: |
| 72 | + * |
| 73 | + * static struct srcu_struct my_srcu; |
| 74 | + * |
| 75 | + * Then, before the first use of each my_srcu, manually initialize it: |
| 76 | + * |
| 77 | + * init_srcu_struct(&my_srcu); |
| 78 | + * |
| 79 | + * See include/linux/percpu-defs.h for the rules on per-CPU variables. |
| 80 | + */ |
| 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) |
| 86 | + |
| 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); |
| 90 | + |
| 91 | +#endif |
0 commit comments