| From 3f09905a6a65ed4fcf8e664abf044c91b2ce7b27 Mon Sep 17 00:00:00 2001 |
| From: Sebastian Andrzej Siewior <bigeasy@linutronix.de> |
| Date: Tue, 19 Mar 2013 14:44:30 +0100 |
| Subject: [PATCH 2/2] kernel/SRCU: provide a static initializer |
| |
| There are macros for static initializer for the three out of four |
| possible notifier types, that are: |
| ATOMIC_NOTIFIER_HEAD() |
| BLOCKING_NOTIFIER_HEAD() |
| RAW_NOTIFIER_HEAD() |
| |
| This patch provides a static initilizer for the forth type to make it |
| complete. |
| |
| Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> |
| --- |
| include/linux/notifier.h | 26 +++++++++++++++++++++----- |
| include/linux/srcu.h | 6 +++--- |
| 2 files changed, 24 insertions(+), 8 deletions(-) |
| |
| --- a/include/linux/notifier.h |
| +++ b/include/linux/notifier.h |
| @@ -42,9 +42,7 @@ |
| * in srcu_notifier_call_chain(): no cache bounces and no memory barriers. |
| * As compensation, srcu_notifier_chain_unregister() is rather expensive. |
| * SRCU notifier chains should be used when the chain will be called very |
| - * often but notifier_blocks will seldom be removed. Also, SRCU notifier |
| - * chains are slightly more difficult to use because they require special |
| - * runtime initialization. |
| + * often but notifier_blocks will seldom be removed. |
| */ |
| |
| struct notifier_block { |
| @@ -85,7 +83,7 @@ struct srcu_notifier_head { |
| (name)->head = NULL; \ |
| } while (0) |
| |
| -/* srcu_notifier_heads must be initialized and cleaned up dynamically */ |
| +/* srcu_notifier_heads must be cleaned up dynamically */ |
| extern void srcu_init_notifier_head(struct srcu_notifier_head *nh); |
| #define srcu_cleanup_notifier_head(name) \ |
| cleanup_srcu_struct(&(name)->srcu); |
| @@ -98,7 +96,13 @@ extern void srcu_init_notifier_head(stru |
| .head = NULL } |
| #define RAW_NOTIFIER_INIT(name) { \ |
| .head = NULL } |
| -/* srcu_notifier_heads cannot be initialized statically */ |
| + |
| +#define SRCU_NOTIFIER_INIT(name, pcpu) \ |
| + { \ |
| + .mutex = __MUTEX_INITIALIZER(name.mutex), \ |
| + .head = NULL, \ |
| + .srcu = __SRCU_STRUCT_INIT(name.srcu, pcpu), \ |
| + } |
| |
| #define ATOMIC_NOTIFIER_HEAD(name) \ |
| struct atomic_notifier_head name = \ |
| @@ -110,6 +114,18 @@ extern void srcu_init_notifier_head(stru |
| struct raw_notifier_head name = \ |
| RAW_NOTIFIER_INIT(name) |
| |
| +#define _SRCU_NOTIFIER_HEAD(name, mod) \ |
| + static DEFINE_PER_CPU(struct srcu_struct_array, \ |
| + name##_head_srcu_array); \ |
| + mod struct srcu_notifier_head name = \ |
| + SRCU_NOTIFIER_INIT(name, name##_head_srcu_array) |
| + |
| +#define SRCU_NOTIFIER_HEAD(name) \ |
| + _SRCU_NOTIFIER_HEAD(name, ) |
| + |
| +#define SRCU_NOTIFIER_HEAD_STATIC(name) \ |
| + _SRCU_NOTIFIER_HEAD(name, static) |
| + |
| #ifdef __KERNEL__ |
| |
| extern int atomic_notifier_chain_register(struct atomic_notifier_head *nh, |
| --- a/include/linux/srcu.h |
| +++ b/include/linux/srcu.h |
| @@ -84,10 +84,10 @@ int init_srcu_struct(struct srcu_struct |
| |
| void process_srcu(struct work_struct *work); |
| |
| -#define __SRCU_STRUCT_INIT(name) \ |
| +#define __SRCU_STRUCT_INIT(name, pcpu_name) \ |
| { \ |
| .completed = -300, \ |
| - .per_cpu_ref = &name##_srcu_array, \ |
| + .per_cpu_ref = &pcpu_name, \ |
| .queue_lock = __SPIN_LOCK_UNLOCKED(name.queue_lock), \ |
| .running = false, \ |
| .batch_queue = RCU_BATCH_INIT(name.batch_queue), \ |
| @@ -105,7 +105,7 @@ void process_srcu(struct work_struct *wo |
| #define _DEFINE_SRCU(name, mod) \ |
| static DEFINE_PER_CPU(struct srcu_struct_array, name##_srcu_array);\ |
| mod struct srcu_struct name = \ |
| - __SRCU_STRUCT_INIT(name); |
| + __SRCU_STRUCT_INIT(name, name##_srcu_array); |
| |
| #define DEFINE_SRCU(name) _DEFINE_SRCU(name, ) |
| #define DEFINE_STATIC_SRCU(name) _DEFINE_SRCU(name, static) |