Skip to content

Commit 9c80172

Browse files
Sebastian Andrzej Siewiorrafaeljw
authored andcommitted
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 <[email protected]> Tested-by: Paul E. McKenney <[email protected]> Reviewed-by: Paul E. McKenney <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent c7d1f11 commit 9c80172

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

include/linux/notifier.h

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@
4343
* in srcu_notifier_call_chain(): no cache bounces and no memory barriers.
4444
* As compensation, srcu_notifier_chain_unregister() is rather expensive.
4545
* SRCU notifier chains should be used when the chain will be called very
46-
* often but notifier_blocks will seldom be removed. Also, SRCU notifier
47-
* chains are slightly more difficult to use because they require special
48-
* runtime initialization.
46+
* often but notifier_blocks will seldom be removed.
4947
*/
5048

5149
struct notifier_block;
@@ -91,7 +89,7 @@ struct srcu_notifier_head {
9189
(name)->head = NULL; \
9290
} while (0)
9391

94-
/* srcu_notifier_heads must be initialized and cleaned up dynamically */
92+
/* srcu_notifier_heads must be cleaned up dynamically */
9593
extern void srcu_init_notifier_head(struct srcu_notifier_head *nh);
9694
#define srcu_cleanup_notifier_head(name) \
9795
cleanup_srcu_struct(&(name)->srcu);
@@ -104,7 +102,13 @@ extern void srcu_init_notifier_head(struct srcu_notifier_head *nh);
104102
.head = NULL }
105103
#define RAW_NOTIFIER_INIT(name) { \
106104
.head = NULL }
107-
/* srcu_notifier_heads cannot be initialized statically */
105+
106+
#define SRCU_NOTIFIER_INIT(name, pcpu) \
107+
{ \
108+
.mutex = __MUTEX_INITIALIZER(name.mutex), \
109+
.head = NULL, \
110+
.srcu = __SRCU_STRUCT_INIT(name.srcu, pcpu), \
111+
}
108112

109113
#define ATOMIC_NOTIFIER_HEAD(name) \
110114
struct atomic_notifier_head name = \
@@ -116,6 +120,26 @@ extern void srcu_init_notifier_head(struct srcu_notifier_head *nh);
116120
struct raw_notifier_head name = \
117121
RAW_NOTIFIER_INIT(name)
118122

123+
#ifdef CONFIG_TREE_SRCU
124+
#define _SRCU_NOTIFIER_HEAD(name, mod) \
125+
static DEFINE_PER_CPU(struct srcu_data, \
126+
name##_head_srcu_data); \
127+
mod struct srcu_notifier_head name = \
128+
SRCU_NOTIFIER_INIT(name, name##_head_srcu_data)
129+
130+
#else
131+
#define _SRCU_NOTIFIER_HEAD(name, mod) \
132+
mod struct srcu_notifier_head name = \
133+
SRCU_NOTIFIER_INIT(name, name)
134+
135+
#endif
136+
137+
#define SRCU_NOTIFIER_HEAD(name) \
138+
_SRCU_NOTIFIER_HEAD(name, /* not static */)
139+
140+
#define SRCU_NOTIFIER_HEAD_STATIC(name) \
141+
_SRCU_NOTIFIER_HEAD(name, static)
142+
119143
#ifdef __KERNEL__
120144

121145
extern int atomic_notifier_chain_register(struct atomic_notifier_head *nh,

include/linux/srcutiny.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ struct srcu_struct {
4343

4444
void srcu_drive_gp(struct work_struct *wp);
4545

46-
#define __SRCU_STRUCT_INIT(name) \
46+
#define __SRCU_STRUCT_INIT(name, __ignored) \
4747
{ \
4848
.srcu_wq = __SWAIT_QUEUE_HEAD_INITIALIZER(name.srcu_wq), \
4949
.srcu_cb_tail = &name.srcu_cb_head, \
@@ -56,9 +56,9 @@ void srcu_drive_gp(struct work_struct *wp);
5656
* Tree SRCU, which needs some per-CPU data.
5757
*/
5858
#define DEFINE_SRCU(name) \
59-
struct srcu_struct name = __SRCU_STRUCT_INIT(name)
59+
struct srcu_struct name = __SRCU_STRUCT_INIT(name, name)
6060
#define DEFINE_STATIC_SRCU(name) \
61-
static struct srcu_struct name = __SRCU_STRUCT_INIT(name)
61+
static struct srcu_struct name = __SRCU_STRUCT_INIT(name, name)
6262

6363
void synchronize_srcu(struct srcu_struct *sp);
6464

include/linux/srcutree.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ struct srcu_struct {
104104
#define SRCU_STATE_SCAN1 1
105105
#define SRCU_STATE_SCAN2 2
106106

107-
#define __SRCU_STRUCT_INIT(name) \
107+
#define __SRCU_STRUCT_INIT(name, pcpu_name) \
108108
{ \
109-
.sda = &name##_srcu_data, \
109+
.sda = &pcpu_name, \
110110
.lock = __SPIN_LOCK_UNLOCKED(name.lock), \
111111
.srcu_gp_seq_needed = 0 - 1, \
112112
__SRCU_DEP_MAP_INIT(name) \
@@ -133,7 +133,7 @@ struct srcu_struct {
133133
*/
134134
#define __DEFINE_SRCU(name, is_static) \
135135
static DEFINE_PER_CPU(struct srcu_data, name##_srcu_data);\
136-
is_static struct srcu_struct name = __SRCU_STRUCT_INIT(name)
136+
is_static struct srcu_struct name = __SRCU_STRUCT_INIT(name, name##_srcu_data)
137137
#define DEFINE_SRCU(name) __DEFINE_SRCU(name, /* not static */)
138138
#define DEFINE_STATIC_SRCU(name) __DEFINE_SRCU(name, static)
139139

0 commit comments

Comments
 (0)