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
24 #ifndef _LINUX_SRCU_TINY_H
25 #define _LINUX_SRCU_TINY_H
27 #include <linux/swait.h>
30 int srcu_lock_nesting[2]; /* srcu_read_lock() nesting depth. */
31 struct swait_queue_head srcu_wq;
32 /* Last srcu_read_unlock() wakes GP. */
33 unsigned long srcu_gp_seq; /* GP seq # for callback tagging. */
34 struct rcu_segcblist srcu_cblist;
35 /* Pending SRCU callbacks. */
36 int srcu_idx; /* Current reader array element. */
37 bool srcu_gp_running; /* GP workqueue running? */
38 bool srcu_gp_waiting; /* GP waiting for readers? */
39 struct work_struct srcu_work; /* For driving grace periods. */
40 #ifdef CONFIG_DEBUG_LOCK_ALLOC
41 struct lockdep_map dep_map;
42 #endif /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
45 void srcu_drive_gp(struct work_struct *wp);
47 #define __SRCU_STRUCT_INIT(name) \
49 .srcu_wq = __SWAIT_QUEUE_HEAD_INITIALIZER(name.srcu_wq), \
50 .srcu_cblist = RCU_SEGCBLIST_INITIALIZER(name.srcu_cblist), \
51 .srcu_work = __WORK_INITIALIZER(name.srcu_work, srcu_drive_gp), \
52 __SRCU_DEP_MAP_INIT(name) \
56 * This odd _STATIC_ arrangement is needed for API compatibility with
57 * Tree SRCU, which needs some per-CPU data.
59 #define DEFINE_SRCU(name) \
60 struct srcu_struct name = __SRCU_STRUCT_INIT(name)
61 #define DEFINE_STATIC_SRCU(name) \
62 static struct srcu_struct name = __SRCU_STRUCT_INIT(name)
64 void synchronize_srcu(struct srcu_struct *sp);
66 static inline void synchronize_srcu_expedited(struct srcu_struct *sp)
71 static inline void srcu_barrier(struct srcu_struct *sp)
76 static inline unsigned long srcu_batches_completed(struct srcu_struct *sp)
81 static inline void srcutorture_get_gp_data(enum rcutorture_type test_type,
82 struct srcu_struct *sp, int *flags,
84 unsigned long *completed)
86 if (test_type != SRCU_FLAVOR)
89 *completed = sp->srcu_gp_seq;