rcu/sync: kill rcu_sync_type/gp_type
Subsystems (3)
PATCH 1/1 rcu/sync: kill rcu_sync_type/gp_type
Now that the RCU flavors were consolidated rcu_sync_type makes no sense, all internal update functions except .held() doesn't depend on gp_type.
The patch adds RCU_LOCKDEP_WARN(!rcu_read_lock_sched_held()) into rcu_sync_is_idle() because this matches its current user, but probably we should simply remove this check or introduce rcu_read_lock_any_held().
--- include/linux/percpu-rwsem.h | 2 +- include/linux/rcu_sync.h | 32 ++++++------------------- kernel/locking/percpu-rwsem.c | 2 +- kernel/rcu/sync.c | 55 ++++--------------------------------------- 4 files changed, 14 insertions(+), 77 deletions(-)
include/linux/percpu-rwsem.h +1 -1
@@ -20,7 +20,7 @@ struct percpu_rw_semaphore {#define DEFINE_STATIC_PERCPU_RWSEM (name) \ static DEFINE_PER_CPU(unsigned int, __percpu_rwsem_rc_##name); \ static struct percpu_rw_semaphore name = { \ - .rss = __RCU_SYNC_INITIALIZER(name.rss, RCU_SCHED_SYNC), \ + .rss = __RCU_SYNC_INITIALIZER(name.rss), \ .read_count = &__percpu_rwsem_rc_##name, \ .rw_sem = __RWSEM_INITIALIZER(name.rw_sem), \ .writer = __RCUWAIT_INITIALIZER(name.writer), \
include/linux/rcu_sync.h +7 -25
@@ -13,8 +13,6 @@#include <linux/wait.h> #include <linux/rcupdate.h> -enum rcu_sync_type {RCU_SYNC ,RCU_SCHED_SYNC ,RCU_BH_SYNC }; -/* Structure to mediate between updaters and fastpath-using readers. */ struct rcu_sync {int gp_state;
@@ -23,52 +21,36 @@ struct rcu_sync {int cb_state; struct rcu_head cb_head; - - enum rcu_sync_type gp_type; }; -extern void rcu_sync_lockdep_assert (struct rcu_sync *); -/** * rcu_sync_is_idle() - Are readers permitted to use their fastpaths? * @rsp: Pointer to rcu_sync structure to use for synchronization * * Returns true if readers are permitted to use their fastpaths. -* Must be invoked within an RCU read-side critical section whose -* flavor matches that of the rcu_sync struture. +* Must be invoked within an RCU-sched read-side critical section. */ static inline bool rcu_sync_is_idle (struct rcu_sync *rsp) { -#ifdef CONFIG_PROVE_RCU -rcu_sync_lockdep_assert (rsp); -#endif +RCU_LOCKDEP_WARN (!rcu_read_lock_sched_held (), +"suspicious rcu_sync_is_idle() usage" );return !rsp->gp_state;/* GP_IDLE */ } -extern void rcu_sync_init (struct rcu_sync *,enum rcu_sync_type ); +extern void rcu_sync_init (struct rcu_sync *);extern void rcu_sync_enter_start (struct rcu_sync *);extern void rcu_sync_enter (struct rcu_sync *);extern void rcu_sync_exit (struct rcu_sync *);extern void rcu_sync_dtor (struct rcu_sync *); -#define __RCU_SYNC_INITIALIZER (name, type) { \ +#define __RCU_SYNC_INITIALIZER (name) { \ .gp_state = 0, \ .gp_count = 0, \ .gp_wait = __WAIT_QUEUE_HEAD_INITIALIZER(name.gp_wait), \ .cb_state = 0, \ - .gp_type = type, \ } -#define __DEFINE_RCU_SYNC (name, type) \ - struct rcu_sync_struct name = __RCU_SYNC_INITIALIZER(name, type) - -#define DEFINE_RCU_SYNC (name) \ - __DEFINE_RCU_SYNC(name, RCU_SYNC) - -#define DEFINE_RCU_SCHED_SYNC (name) \ - __DEFINE_RCU_SYNC(name, RCU_SCHED_SYNC) - -#define DEFINE_RCU_BH_SYNC (name) \ - __DEFINE_RCU_SYNC(name, RCU_BH_SYNC) +#define DEFINE_RCU_SYNC (name) \ + struct rcu_sync name = __RCU_SYNC_INITIALIZER(name)#endif /* _LINUX_RCU_SYNC_H_ */
kernel/locking/percpu-rwsem.c +1 -1
@@ -15,7 +15,7 @@ int __percpu_init_rwsem(struct percpu_rw_semaphore *sem,return -ENOMEM ;/* ->rw_sem represents the whole percpu_rw_semaphore for lockdep */ -rcu_sync_init (&sem->rss,RCU_SCHED_SYNC ); +rcu_sync_init (&sem->rss);__init_rwsem (&sem->rw_sem, name, rwsem_key);rcuwait_init (&sem->writer); sem->readers_block =0 ;
kernel/rcu/sync.c +5 -50
98 lines not on this page · raw message
Signature · 1 line
2.5.0
Quoted 8 lines · Oleg Nesterov
Now that the RCU flavors were consolidated
rcu_sync_typemakes no sense, all internal update functions except .held() doesn't depend ongp_type.The patch adds RCU_LOCKDEP_WARN(!rcu_read_lock_sched_held()) into
rcu_sync_is_idle()because this matches its current user, but probably we should simply remove this check or introducercu_read_lock_any_held().Signed-off-by Oleg Nesterov <[email protected]>
Nice simplification! Queued for testing and review, thank you!
I wordsmithed the commit log and merged in the RCU-bh and RCU checks to rcu_sync_is_idle(), with the result shown below. Does that work OK, or did I mess something up?
Thanx, Paul
------------------------------------------------------------------------
commit cdf54c0ad9951b1f9de63fce5e53a947105b17db
Author: Oleg Nesterov <[email protected]> Date: Tue Apr 23 14:07:24 2019 +0200
rcu/sync: Kill rcu_sync_type/gp_type
Now that the RCU flavors have been consolidated, rcu_sync_type makes no sense because none of internal update functions aside from .held() depend on gp_type. This commit therefore removes this field and consolidates the relevant code.
include/linux/percpu-rwsem.h +1 -1
@@ -20,7 +20,7 @@ struct percpu_rw_semaphore {#define DEFINE_STATIC_PERCPU_RWSEM (name) \ static DEFINE_PER_CPU(unsigned int, __percpu_rwsem_rc_##name); \ static struct percpu_rw_semaphore name = { \ - .rss = __RCU_SYNC_INITIALIZER(name.rss, RCU_SCHED_SYNC), \ + .rss = __RCU_SYNC_INITIALIZER(name.rss), \ .read_count = &__percpu_rwsem_rc_##name, \ .rw_sem = __RWSEM_INITIALIZER(name.rw_sem), \ .writer = __RCUWAIT_INITIALIZER(name.writer), \
include/linux/rcu_sync.h +9 -25
@@ -13,8 +13,6 @@#include <linux/wait.h> #include <linux/rcupdate.h> -enum rcu_sync_type {RCU_SYNC ,RCU_SCHED_SYNC ,RCU_BH_SYNC }; -/* Structure to mediate between updaters and fastpath-using readers. */ struct rcu_sync {int gp_state;
@@ -23,52 +21,38 @@ struct rcu_sync {int cb_state; struct rcu_head cb_head; - - enum rcu_sync_type gp_type; }; -extern void rcu_sync_lockdep_assert (struct rcu_sync *); -/** * rcu_sync_is_idle() - Are readers permitted to use their fastpaths? * @rsp: Pointer to rcu_sync structure to use for synchronization * * Returns true if readers are permitted to use their fastpaths. -* Must be invoked within an RCU read-side critical section whose -* flavor matches that of the rcu_sync struture. +* Must be invoked within an RCU-sched read-side critical section. */ static inline bool rcu_sync_is_idle (struct rcu_sync *rsp) { -#ifdef CONFIG_PROVE_RCU -rcu_sync_lockdep_assert (rsp); -#endif +RCU_LOCKDEP_WARN (!rcu_read_lock_held () && + !rcu_read_lock_bh_held () && + !rcu_read_lock_sched_held (), +"suspicious rcu_sync_is_idle() usage" );return !rsp->gp_state;/* GP_IDLE */ } -extern void rcu_sync_init (struct rcu_sync *,enum rcu_sync_type ); +extern void rcu_sync_init (struct rcu_sync *);extern void rcu_sync_enter_start (struct rcu_sync *);extern void rcu_sync_enter (struct rcu_sync *);extern void rcu_sync_exit (struct rcu_sync *);extern void rcu_sync_dtor (struct rcu_sync *); -#define __RCU_SYNC_INITIALIZER (name, type) { \ +#define __RCU_SYNC_INITIALIZER (name) { \ .gp_state = 0, \ .gp_count = 0, \ .gp_wait = __WAIT_QUEUE_HEAD_INITIALIZER(name.gp_wait), \ .cb_state = 0, \ - .gp_type = type, \ } -#define __DEFINE_RCU_SYNC (name, type) \ - struct rcu_sync_struct name = __RCU_SYNC_INITIALIZER(name, type) - -#define DEFINE_RCU_SYNC (name) \ - __DEFINE_RCU_SYNC(name, RCU_SYNC) - -#define DEFINE_RCU_SCHED_SYNC (name) \ - __DEFINE_RCU_SYNC(name, RCU_SCHED_SYNC) - -#define DEFINE_RCU_BH_SYNC (name) \ - __DEFINE_RCU_SYNC(name, RCU_BH_SYNC) +#define DEFINE_RCU_SYNC (name) \ + struct rcu_sync name = __RCU_SYNC_INITIALIZER(name)#endif /* _LINUX_RCU_SYNC_H_ */
kernel/locking/percpu-rwsem.c +1 -1
@@ -15,7 +15,7 @@ int __percpu_init_rwsem(struct percpu_rw_semaphore *sem,return -ENOMEM ;/* ->rw_sem represents the whole percpu_rw_semaphore for lockdep */ -rcu_sync_init (&sem->rss,RCU_SCHED_SYNC ); +rcu_sync_init (&sem->rss);__init_rwsem (&sem->rw_sem, name, rwsem_key);rcuwait_init (&sem->writer); sem->readers_block =0 ;
kernel/rcu/sync.c +5 -50
98 lines not on this page · raw message
Quoted 4 lines · Paul E. McKenney
I wordsmithed the commit log and merged in the RCU-bh and RCU checks to
rcu_sync_is_idle(), with the result shown below. Does that work OK, or did I mess something up?
Yes, thanks!
the additional RCU-bh and RCU checks matches the "or introduce rcu_read_lock_any_held()" note from the changelog, perhaps it makes some sense...
Just one nit below,
Quoted 3 lines
- * Must be invoked within an RCU read-side critical section whose
- * flavor matches that of thercu_syncstruture.
+ * Must be invoked within an RCU-sched read-side critical section.
^^^^^^^^^
Given that the actual code:
include/linux/rcu_sync.h struct rcu_sync { · line 38
Quoted 9 lines
static inline bool
rcu_sync_is_idle(struct rcu_sync *rsp){include/linux/rcu_sync.h +4
-3-#ifdef CONFIG_PROVE_RCU -rcu_sync_lockdep_assert (rsp); -#endif +RCU_LOCKDEP_WARN (!rcu_read_lock_held () && + !rcu_read_lock_bh_held () && + !rcu_read_lock_sched_held (), +"suspicious rcu_sync_is_idle() usage" );
does RCU_LOCKDEP_WARN(!rcu_read_lock_any()) the comment should say
Must be invoked within an RCU read-side critical section of any flavor
?
Oleg.
Quoted 32 lines · Oleg Nesterov
Quoted 4 lines · Paul E. McKenney
I wordsmithed the commit log and merged in the RCU-bh and RCU checks to
rcu_sync_is_idle(), with the result shown below. Does that work OK, or did I mess something up?Yes, thanks!
the additional RCU-bh and RCU checks matches the "or introduce
rcu_read_lock_any_held()" note from the changelog, perhaps it makes some sense...Just one nit below,
Quoted 3 lines
- * Must be invoked within an RCU read-side critical section whose
- * flavor matches that of thercu_syncstruture.
+ * Must be invoked within an RCU-sched read-side critical section.^^^^^^^^^Given that the actual code:
include/linux/rcu_sync.h struct rcu_sync { · line 38
Quoted 9 lines
static inline bool
rcu_sync_is_idle(struct rcu_sync *rsp){include/linux/rcu_sync.h +4
-3-#ifdef CONFIG_PROVE_RCU -rcu_sync_lockdep_assert (rsp); -#endif +RCU_LOCKDEP_WARN (!rcu_read_lock_held () && + !rcu_read_lock_bh_held () && + !rcu_read_lock_sched_held (), +"suspicious rcu_sync_is_idle() usage" );does RCU_LOCKDEP_WARN(!rcu_read_lock_any()) the comment should say
Quoted 2 lines
Must be invoked within an RCU read-side critical section of any flavor
Good catch, thank you! I went with this:
* Must be invoked within some flavor of RCU read-side critical section.
Does that work for you?
Thanx, Paul
Quoted 4 lines · Paul E. McKenney
* Must be invoked within some flavor of RCU read-side critical section.
Does that work for you?
Thanks!
Oleg.