From: Lai Jiangshan <laijs@cn.fujitsu.com>
To: linux-kernel@vger.kernel.org,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Cc: Lai Jiangshan <laijs@cn.fujitsu.com>
Subject: [PATCH 3/4] srcu: add DEFINE_SRCU()
Date: Sat, 13 Oct 2012 01:14:16 +0800 [thread overview]
Message-ID: <1350062057-2439-4-git-send-email-laijs@cn.fujitsu.com> (raw)
In-Reply-To: <1350062057-2439-1-git-send-email-laijs@cn.fujitsu.com>
In old days, we have two different API sets for dynamic-allocated per_cpu data
and DEFINE_PER_CPU()-defined per_cpu data, and since we used
dynamic-allocated per_cpu data, we can't use DEFINE_PER_CPU()-defined
per_cpu data(otherwise we will introduce a lot of duplicated code.
In new days, we have only one API sets for both type of per_cpu data,
so we can use DEFINE_PER_CPU() for DEFINE_SRCU() which allows us
define and init srcu struct in build time and allows us use srcu APIs
in very early boot time.
We also provide DEFINE_STATIC_SRCU() which defines an internal srcu struct
inside a single *.c.
Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
---
include/linux/srcu.h | 30 ++++++++++++++++++++++++++++++
1 files changed, 30 insertions(+), 0 deletions(-)
diff --git a/include/linux/srcu.h b/include/linux/srcu.h
index 5cce128..f986df1 100644
--- a/include/linux/srcu.h
+++ b/include/linux/srcu.h
@@ -42,6 +42,8 @@ struct rcu_batch {
struct rcu_head *head, **tail;
};
+#define RCU_BATCH_INIT(name) { NULL, &(name.head) }
+
struct srcu_struct {
unsigned completed;
struct srcu_struct_array __percpu *per_cpu_ref;
@@ -72,14 +74,42 @@ int __init_srcu_struct(struct srcu_struct *sp, const char *name,
__init_srcu_struct((sp), #sp, &__srcu_key); \
})
+#define __SRCU_DEP_MAP_INIT(srcu_name) .dep_map = { .name = #srcu_name },
#else /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
int init_srcu_struct(struct srcu_struct *sp);
+#define __SRCU_DEP_MAP_INIT(srcu_name)
#endif /* #else #ifdef CONFIG_DEBUG_LOCK_ALLOC */
void process_srcu(struct work_struct *work);
+#define __SRCU_STRUCT_INIT(name) \
+ { \
+ .completed = -300, \
+ .per_cpu_ref = &name##_srcu_array, \
+ .queue_lock = __SPIN_LOCK_UNLOCKED(name.queue_lock), \
+ .running = false, \
+ .batch_queue = RCU_BATCH_INIT(name.batch_queue), \
+ .batch_check0 = RCU_BATCH_INIT(name.batch_check0), \
+ .batch_check1 = RCU_BATCH_INIT(name.batch_check1), \
+ .batch_done = RCU_BATCH_INIT(name.batch_done), \
+ .work = __DELAYED_WORK_INITIALIZER(name.work, process_srcu),\
+ __SRCU_DEP_MAP_INIT(name) \
+ }
+
+/*
+ * define and init a srcu struct at build time.
+ * dont't call init_srcu_struct() nor cleanup_srcu_struct() on it.
+ */
+#define DEFINE_SRCU(name) \
+ static DEFINE_PER_CPU(struct srcu_struct_array, name##_srcu_array);\
+ struct srcu_struct name = __SRCU_STRUCT_INIT(name);
+
+#define DEFINE_STATIC_SRCU(name) \
+ static DEFINE_PER_CPU(struct srcu_struct_array, name##_srcu_array);\
+ static struct srcu_struct name = __SRCU_STRUCT_INIT(name);
+
/**
* call_srcu() - Queue a callback for invocation after an SRCU grace period
* @sp: srcu_struct in queue the callback
--
1.7.7.6
next prev parent reply other threads:[~2012-10-12 17:12 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-12 17:14 [PATCH 0/4] srcu: Add DEFINE_SRCU() Lai Jiangshan
2012-10-12 17:14 ` [PATCH 1/4] srcu: add my name Lai Jiangshan
2012-10-12 17:14 ` [PATCH 2/4] srcu: export process_srcu() Lai Jiangshan
2012-10-12 17:14 ` Lai Jiangshan [this message]
2012-10-15 21:56 ` [PATCH 3/4] srcu: add DEFINE_SRCU() Paul E. McKenney
2012-10-15 22:40 ` Paul E. McKenney
2012-10-12 17:14 ` [PATCH 4/4] rcutorture: use DEFINE_STATIC_SRCU() Lai Jiangshan
2012-10-12 19:06 ` Josh Triplett
2012-10-15 23:38 ` [PATCH 0/4] srcu: Add DEFINE_SRCU() Paul E. McKenney
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1350062057-2439-4-git-send-email-laijs@cn.fujitsu.com \
--to=laijs@cn.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=paulmck@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®