This commit creates a DEFINE_SRCU_FAST() that is similar to DEFINE_SRCU(),
but which creates an srcu_struct that is usable only by readers initiated
by srcu_read_lock_fast() and friends.  Note that DEFINE_SRCU_FAST() is
usable only by built-in code, not from loadable modules.

Signed-off-by: Paul E. McKenney <paul...@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoy...@efficios.com>
Cc: Steven Rostedt <rost...@goodmis.org>
Cc: Sebastian Andrzej Siewior <bige...@linutronix.de>
Cc: <b...@vger.kernel.org>
---
 include/linux/srcutiny.h |  1 +
 include/linux/srcutree.h | 20 +++++++++++++++-----
 2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/include/linux/srcutiny.h b/include/linux/srcutiny.h
index 51ce25f07930ee..00e5f05288d5e7 100644
--- a/include/linux/srcutiny.h
+++ b/include/linux/srcutiny.h
@@ -45,6 +45,7 @@ void srcu_drive_gp(struct work_struct *wp);
  */
 #define DEFINE_SRCU(name) \
        struct srcu_struct name = __SRCU_STRUCT_INIT(name, name, name)
+#define DEFINE_SRCU_FAST(name) DEFINE_SRCU(name)
 #define DEFINE_STATIC_SRCU(name) \
        static struct srcu_struct name = __SRCU_STRUCT_INIT(name, name, name)
 
diff --git a/include/linux/srcutree.h b/include/linux/srcutree.h
index 42098e0fa0b7dd..1adc58d2ab6425 100644
--- a/include/linux/srcutree.h
+++ b/include/linux/srcutree.h
@@ -189,23 +189,33 @@ struct srcu_struct {
  *     init_srcu_struct(&my_srcu);
  *
  * See include/linux/percpu-defs.h for the rules on per-CPU variables.
+ *
+ * DEFINE_SRCU_FAST() creates an srcu_struct and associated structures
+ * whose readers must be of the SRCU-fast variety.  DEFINE_SRCU_FAST()
+ * cannot be used within modules due to there being no place to
+ * put the desired ->srcu_reader_flavor value.  If in-module use of
+ * DEFINE_SRCU_FAST() becomes necessary, the srcu_struct structure will
+ * need to grow in order to store this value.
  */
 #ifdef MODULE
-# define __DEFINE_SRCU(name, is_static)                                        
                        \
+# define __DEFINE_SRCU(name, fast, is_static)                                  
                \
        static struct srcu_usage name##_srcu_usage = 
__SRCU_USAGE_INIT(name##_srcu_usage);      \
        is_static struct srcu_struct name = __SRCU_STRUCT_INIT_MODULE(name, 
name##_srcu_usage); \
        extern struct srcu_struct * const __srcu_struct_##name;                 
                \
        struct srcu_struct * const __srcu_struct_##name                         
                \
                __section("___srcu_struct_ptrs") = &name
 #else
-# define __DEFINE_SRCU(name, is_static)                                        
                        \
-       static DEFINE_PER_CPU(struct srcu_data, name##_srcu_data);              
                \
+# define __DEFINE_SRCU(name, fast, is_static)                                  
                \
+       static DEFINE_PER_CPU(struct srcu_data, name##_srcu_data) = {           
                \
+               .srcu_reader_flavor = fast,                                     
                \
+       };                                                                      
                \
        static struct srcu_usage name##_srcu_usage = 
__SRCU_USAGE_INIT(name##_srcu_usage);      \
        is_static struct srcu_struct name =                                     
                \
                __SRCU_STRUCT_INIT(name, name##_srcu_usage, name##_srcu_data)
+#define DEFINE_SRCU_FAST(name)         __DEFINE_SRCU(name, 
SRCU_READ_FLAVOR_FAST, /* not static */)
 #endif
-#define DEFINE_SRCU(name)              __DEFINE_SRCU(name, /* not static */)
-#define DEFINE_STATIC_SRCU(name)       __DEFINE_SRCU(name, static)
+#define DEFINE_SRCU(name)              __DEFINE_SRCU(name, 0, /* not static */)
+#define DEFINE_STATIC_SRCU(name)       __DEFINE_SRCU(name, 0, static)
 
 int __srcu_read_lock(struct srcu_struct *ssp) __acquires(ssp);
 void synchronize_srcu_expedited(struct srcu_struct *ssp);
-- 
2.40.1


Reply via email to