All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: linux-kernel@vger.kernel.org
Cc: mingo@elte.hu, laijs@cn.fujitsu.com, dipankar@in.ibm.com,
	akpm@linux-foundation.org, mathieu.desnoyers@polymtl.ca,
	josh@joshtriplett.org, dvhltc@us.ibm.com, niv@us.ibm.com,
	tglx@linutronix.de, peterz@infradead.org, rostedt@goodmis.org,
	Valdis.Kletnieks@vt.edu, dhowells@redhat.com,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Subject: [PATCH RFC tip/core/rcu 16/18] rcu: make lockdep aware of SRCU read-side critical sections.
Date: Tue, 15 Dec 2009 15:02:39 -0800	[thread overview]
Message-ID: <1260918161657-git-send-email-> (raw)
In-Reply-To: <20091215230213.GA9093@linux.vnet.ibm.com>

From: Paul E. McKenney <paulmck@linux.vnet.ibm.com>

Proposed for 2.6.34, not for inclusion.

This patch adds lockdep classes and code to make lockdep aware of
SRCU read-side critical sections.

Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
---
 include/linux/srcu.h |   44 ++++++++++++++++++++++++++++++++++++++++++--
 kernel/srcu.c        |   26 +++++++++++++-------------
 2 files changed, 55 insertions(+), 15 deletions(-)

diff --git a/include/linux/srcu.h b/include/linux/srcu.h
index 4765d97..5a07b90 100644
--- a/include/linux/srcu.h
+++ b/include/linux/srcu.h
@@ -45,10 +45,50 @@ struct srcu_struct {
 
 int init_srcu_struct(struct srcu_struct *sp);
 void cleanup_srcu_struct(struct srcu_struct *sp);
-int srcu_read_lock(struct srcu_struct *sp) __acquires(sp);
-void srcu_read_unlock(struct srcu_struct *sp, int idx) __releases(sp);
+int __srcu_read_lock(struct srcu_struct *sp) __acquires(sp);
+void __srcu_read_unlock(struct srcu_struct *sp, int idx) __releases(sp);
 void synchronize_srcu(struct srcu_struct *sp);
 void synchronize_srcu_expedited(struct srcu_struct *sp);
 long srcu_batches_completed(struct srcu_struct *sp);
 
+#ifdef CONFIG_DEBUG_LOCK_ALLOC
+extern struct lockdep_map srcu_lock_map;
+# define srcu_read_acquire() \
+		lock_acquire(&srcu_lock_map, 0, 0, 2, 1, NULL, _THIS_IP_)
+# define srcu_read_release() \
+		lock_release(&srcu_lock_map, 1, _THIS_IP_)
+#else /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
+# define srcu_read_acquire()	do { } while (0)
+# define srcu_read_release()	do { } while (0)
+#endif /* #else #ifdef CONFIG_DEBUG_LOCK_ALLOC */
+
+/**
+ * srcu_read_lock - register a new reader for an SRCU-protected structure.
+ * @sp: srcu_struct in which to register the new reader.
+ *
+ * Enter an SRCU read-side critical section.  Note that SRCU read-side
+ * critical sections may be nested.
+ */
+static inline int srcu_read_lock(struct srcu_struct *sp) __acquires(sp)
+{
+	int retval = __srcu_read_lock(sp);
+
+	srcu_read_acquire();
+	return retval;
+}
+
+/**
+ * srcu_read_unlock - unregister a old reader from an SRCU-protected structure.
+ * @sp: srcu_struct in which to unregister the old reader.
+ * @idx: return value from corresponding srcu_read_lock().
+ *
+ * Exit an SRCU read-side critical section.
+ */
+static inline void srcu_read_unlock(struct srcu_struct *sp, int idx)
+	__releases(sp)
+{
+	srcu_read_release();
+	__srcu_read_unlock(sp, idx);
+}
+
 #endif
diff --git a/kernel/srcu.c b/kernel/srcu.c
index 818d7d9..4575f63 100644
--- a/kernel/srcu.c
+++ b/kernel/srcu.c
@@ -34,6 +34,13 @@
 #include <linux/smp.h>
 #include <linux/srcu.h>
 
+#ifdef CONFIG_DEBUG_LOCK_ALLOC
+static struct lock_class_key srcu_lock_key;
+struct lockdep_map srcu_lock_map =
+	STATIC_LOCKDEP_MAP_INIT("srcu_read_lock", &srcu_lock_key);
+EXPORT_SYMBOL_GPL(srcu_lock_map);
+#endif /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
+
 /**
  * init_srcu_struct - initialize a sleep-RCU structure
  * @sp: structure to initialize.
@@ -100,15 +107,12 @@ void cleanup_srcu_struct(struct srcu_struct *sp)
 }
 EXPORT_SYMBOL_GPL(cleanup_srcu_struct);
 
-/**
- * srcu_read_lock - register a new reader for an SRCU-protected structure.
- * @sp: srcu_struct in which to register the new reader.
- *
+/*
  * Counts the new reader in the appropriate per-CPU element of the
  * srcu_struct.  Must be called from process context.
  * Returns an index that must be passed to the matching srcu_read_unlock().
  */
-int srcu_read_lock(struct srcu_struct *sp)
+int __srcu_read_lock(struct srcu_struct *sp)
 {
 	int idx;
 
@@ -120,26 +124,22 @@ int srcu_read_lock(struct srcu_struct *sp)
 	preempt_enable();
 	return idx;
 }
-EXPORT_SYMBOL_GPL(srcu_read_lock);
+EXPORT_SYMBOL_GPL(__srcu_read_lock);
 
-/**
- * srcu_read_unlock - unregister a old reader from an SRCU-protected structure.
- * @sp: srcu_struct in which to unregister the old reader.
- * @idx: return value from corresponding srcu_read_lock().
- *
+/*
  * Removes the count for the old reader from the appropriate per-CPU
  * element of the srcu_struct.  Note that this may well be a different
  * CPU than that which was incremented by the corresponding srcu_read_lock().
  * Must be called from process context.
  */
-void srcu_read_unlock(struct srcu_struct *sp, int idx)
+void __srcu_read_unlock(struct srcu_struct *sp, int idx)
 {
 	preempt_disable();
 	srcu_barrier();  /* ensure compiler won't misorder critical section. */
 	per_cpu_ptr(sp->per_cpu_ref, smp_processor_id())->c[idx]--;
 	preempt_enable();
 }
-EXPORT_SYMBOL_GPL(srcu_read_unlock);
+EXPORT_SYMBOL_GPL(__srcu_read_unlock);
 
 /*
  * Helper function for synchronize_srcu() and synchronize_srcu_expedited().
-- 
1.5.2.5


  parent reply	other threads:[~2009-12-15 23:13 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-15 23:02 [PATCH RFC tip/core/rcu 0/18] rcu: simplify race conditions, add checking Paul E. McKenney
2009-12-15 23:02 ` [PATCH RFC tip/core/rcu 01/18] rcu: adjust force_quiescent_state() locking, step 1 Paul E. McKenney
2009-12-15 23:02 ` [PATCH RFC tip/core/rcu 02/18] rcu: adjust force_quiescent_state() locking, step 2 Paul E. McKenney
2009-12-15 23:02 ` [PATCH RFC tip/core/rcu 03/18] rcu: prohibit starting new grace periods while forcing quiescent states Paul E. McKenney
2009-12-15 23:02 ` [PATCH RFC tip/core/rcu 04/18] rcu: eliminate local variable signaled from force_quiescent_state() Paul E. McKenney
2009-12-15 23:02 ` [PATCH RFC tip/core/rcu 05/18] rcu: eliminate local variable lastcomp " Paul E. McKenney
2009-12-15 23:02 ` [PATCH RFC tip/core/rcu 06/18] rcu: eliminate second argument of rcu_process_dyntick() Paul E. McKenney
2009-12-15 23:02 ` [PATCH RFC tip/core/rcu 07/18] rcu: eliminate rcu_process_dyntick() return value Paul E. McKenney
2009-12-15 23:02 ` [PATCH RFC tip/core/rcu 08/18] rcu: remove leg of force_quiescent_state() switch statement Paul E. McKenney
2009-12-15 23:02 ` [PATCH RFC tip/core/rcu 09/18] rcu: remove redundant grace-period check Paul E. McKenney
2009-12-15 23:02 ` [PATCH RFC tip/core/rcu 10/18] rcu: make force_quiescent_state() start grace period if needed Paul E. McKenney
2009-12-15 23:02 ` [PATCH RFC tip/core/rcu 11/18] rcu: add force_quiescent_state() testing to rcutorture Paul E. McKenney
2009-12-15 23:02 ` [PATCH RFC tip/core/rcu 12/18] rcu: make MAINTAINERS file match new RCU reality Paul E. McKenney
2009-12-16  0:53   ` Josh Triplett
2009-12-15 23:02 ` [PATCH RFC tip/core/rcu 13/18] rcu: add debug check for too many rcu_read_unlock() Paul E. McKenney
2009-12-15 23:02 ` [PATCH RFC tip/core/rcu 14/18] rcu: lockdep check for exiting to user space as RCU reader Paul E. McKenney
2009-12-16 10:24   ` Peter Zijlstra
2009-12-16 15:11     ` Paul E. McKenney
2009-12-15 23:02 ` [PATCH RFC tip/core/rcu 15/18] rcu: give different levels of the rcu_node hierarchy distinct lockdep names Paul E. McKenney
2009-12-16  0:59   ` Josh Triplett
2009-12-16  1:59     ` Paul E. McKenney
2009-12-16 10:26   ` Peter Zijlstra
2009-12-16 10:33     ` Peter Zijlstra
2009-12-16 15:13     ` Paul E. McKenney
2009-12-15 23:02 ` Paul E. McKenney [this message]
2009-12-15 23:02 ` [PATCH RFC tip/core/rcu 17/18] rcu: Provide different lockdep classes for each flavor of RCU Paul E. McKenney
2009-12-15 23:02 ` [PATCH RFC tip/core/rcu 18/18] rcu: add primitives to check for RCU read-side critical sections Paul E. McKenney
2009-12-16  1:04   ` Josh Triplett
2009-12-16  2:08     ` Paul E. McKenney
2009-12-16 10:31   ` Peter Zijlstra
2009-12-16 15:18     ` 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=1260918161657-git-send-email- \
    --to=paulmck@linux.vnet.ibm.com \
    --cc=Valdis.Kletnieks@vt.edu \
    --cc=akpm@linux-foundation.org \
    --cc=dhowells@redhat.com \
    --cc=dipankar@in.ibm.com \
    --cc=dvhltc@us.ibm.com \
    --cc=josh@joshtriplett.org \
    --cc=laijs@cn.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@polymtl.ca \
    --cc=mingo@elte.hu \
    --cc=niv@us.ibm.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.