summaryrefslogtreecommitdiffstats
path: root/kernel/rcu/sync.c
diff options
context:
space:
mode:
authorOleg Nesterov <oleg@redhat.com>2015-08-21 19:42:47 +0200
committerPaul E. McKenney <paulmck@linux.vnet.ibm.com>2015-10-06 11:25:10 -0700
commit82e8c565be8a72957570d7da8dd9b441db7bb648 (patch)
tree340d7f93cecbb93a2f6517e369b675195282ba7f /kernel/rcu/sync.c
parentcc44ca848f5e517aeca9f5eabbe13609a3f71450 (diff)
downloadlinux-82e8c565be8a72957570d7da8dd9b441db7bb648.tar.bz2
rcu_sync: Simplify rcu_sync using new rcu_sync_ops structure
This commit adds the new struct rcu_sync_ops which holds sync/call methods, and turns the function pointers in rcu_sync_struct into an array of struct rcu_sync_ops. This simplifies the "init" helpers by collapsing a switch statement and explicit multiple definitions into a simple assignment and a helper macro, respectively. Signed-off-by: Oleg Nesterov <oleg@redhat.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Reviewed-by: Josh Triplett <josh@joshtriplett.org>
Diffstat (limited to 'kernel/rcu/sync.c')
-rw-r--r--kernel/rcu/sync.c42
1 files changed, 22 insertions, 20 deletions
diff --git a/kernel/rcu/sync.c b/kernel/rcu/sync.c
index 0a11df43be23..5a9aa4c394f1 100644
--- a/kernel/rcu/sync.c
+++ b/kernel/rcu/sync.c
@@ -23,6 +23,24 @@
#include <linux/rcu_sync.h>
#include <linux/sched.h>
+static const struct {
+ void (*sync)(void);
+ void (*call)(struct rcu_head *, void (*)(struct rcu_head *));
+} gp_ops[] = {
+ [RCU_SYNC] = {
+ .sync = synchronize_rcu,
+ .call = call_rcu,
+ },
+ [RCU_SCHED_SYNC] = {
+ .sync = synchronize_sched,
+ .call = call_rcu_sched,
+ },
+ [RCU_BH_SYNC] = {
+ .sync = synchronize_rcu_bh,
+ .call = call_rcu_bh,
+ },
+};
+
enum { GP_IDLE = 0, GP_PENDING, GP_PASSED };
enum { CB_IDLE = 0, CB_PENDING, CB_REPLAY };
@@ -37,23 +55,7 @@ void rcu_sync_init(struct rcu_sync *rsp, enum rcu_sync_type type)
{
memset(rsp, 0, sizeof(*rsp));
init_waitqueue_head(&rsp->gp_wait);
-
- switch (type) {
- case RCU_SYNC:
- rsp->sync = synchronize_rcu;
- rsp->call = call_rcu;
- break;
-
- case RCU_SCHED_SYNC:
- rsp->sync = synchronize_sched;
- rsp->call = call_rcu_sched;
- break;
-
- case RCU_BH_SYNC:
- rsp->sync = synchronize_rcu_bh;
- rsp->call = call_rcu_bh;
- break;
- }
+ rsp->gp_type = type;
}
/**
@@ -85,7 +87,7 @@ void rcu_sync_enter(struct rcu_sync *rsp)
BUG_ON(need_wait && need_sync);
if (need_sync) {
- rsp->sync();
+ gp_ops[rsp->gp_type].sync();
rsp->gp_state = GP_PASSED;
wake_up_all(&rsp->gp_wait);
} else if (need_wait) {
@@ -138,7 +140,7 @@ static void rcu_sync_func(struct rcu_head *rcu)
* to catch a later GP.
*/
rsp->cb_state = CB_PENDING;
- rsp->call(&rsp->cb_head, rcu_sync_func);
+ gp_ops[rsp->gp_type].call(&rsp->cb_head, rcu_sync_func);
} else {
/*
* We're at least a GP after rcu_sync_exit(); eveybody will now
@@ -166,7 +168,7 @@ void rcu_sync_exit(struct rcu_sync *rsp)
if (!--rsp->gp_count) {
if (rsp->cb_state == CB_IDLE) {
rsp->cb_state = CB_PENDING;
- rsp->call(&rsp->cb_head, rcu_sync_func);
+ gp_ops[rsp->gp_type].call(&rsp->cb_head, rcu_sync_func);
} else if (rsp->cb_state == CB_PENDING) {
rsp->cb_state = CB_REPLAY;
}