From: Peter Zijlstra <peterz@infradead.org>
To: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: mingo@redhat.com, linux-kernel@vger.kernel.org,
tglx <tglx@linutronix.de>
Subject: Re: [RFC] seqlock,lockdep: Add lock primitives to read_seqbegin().
Date: Tue, 29 Mar 2011 15:11:11 +0200 [thread overview]
Message-ID: <1301404271.2250.381.camel@laptop> (raw)
In-Reply-To: <201103261312.AEJ01293.OVFJFSLtHOFOMQ@I-love.SAKURA.ne.jp>
On Sat, 2011-03-26 at 13:12 +0900, Tetsuo Handa wrote:
> @@ -86,6 +86,11 @@ static inline int write_tryseqlock(seqlo
> static __always_inline unsigned read_seqbegin(const seqlock_t *sl)
> {
> unsigned ret;
> +#ifdef CONFIG_PROVE_LOCKING
> + unsigned long flags;
> + spin_lock_irqsave(&((seqlock_t *) sl)->lock, flags);
> + spin_unlock_irqrestore(&((seqlock_t *) sl)->lock, flags);
> +#endif
>
> repeat:
> ret = sl->sequence;
That isn't the right way, something like the below would do, however
there's a reason this isn't done, we use these primitives from the VDSO
which means they're not permitted to write to any kernel memory at all.
We could sort that by creating a raw_ variant that doesn't get the
annotation, something I think is already done for -rt anyway.
---
include/linux/seqlock.h | 13 ++++++++++++-
1 files changed, 12 insertions(+), 1 deletions(-)
diff --git a/include/linux/seqlock.h b/include/linux/seqlock.h
index e98cd2e..f2bc19c 100644
--- a/include/linux/seqlock.h
+++ b/include/linux/seqlock.h
@@ -94,6 +94,7 @@ static __always_inline unsigned read_seqbegin(const seqlock_t *sl)
cpu_relax();
goto repeat;
}
+ rwlock_acquire_read(&sl->lock->dep_map, 0, 0, _RET_IP_);
return ret;
}
@@ -107,6 +108,8 @@ static __always_inline int read_seqretry(const seqlock_t *sl, unsigned start)
{
smp_rmb();
+ rwlock_release(&sl->lock->dep_map, 1, _RET_IP_);
+
return unlikely(sl->sequence != start);
}
@@ -120,6 +123,9 @@ static __always_inline int read_seqretry(const seqlock_t *sl, unsigned start)
typedef struct seqcount {
unsigned sequence;
+#ifdef CONFIG_DEBUG_LOCK_ALLOC
+ struct lockdep_map dep_map;
+#endif
} seqcount_t;
#define SEQCNT_ZERO { 0 }
@@ -148,6 +154,7 @@ static inline unsigned __read_seqcount_begin(const seqcount_t *s)
cpu_relax();
goto repeat;
}
+ rwlock_acquire_read(&sl->dep_map, 0, 0, _RET_IP_);
return ret;
}
@@ -183,7 +190,9 @@ static inline unsigned read_seqcount_begin(const seqcount_t *s)
*/
static inline int __read_seqcount_retry(const seqcount_t *s, unsigned start)
{
- return unlikely(s->sequence != start);
+ int ret = unlikely(s->sequence != start);
+ rwlock_release(&sl->dep_map, 1, _RET_IP_);
+ return ret;
}
/**
@@ -210,6 +219,7 @@ static inline int read_seqcount_retry(const seqcount_t *s, unsigned start)
*/
static inline void write_seqcount_begin(seqcount_t *s)
{
+ rwlock_acquire(&sl->dep_map, 0, 0, _RET_IP_);
s->sequence++;
smp_wmb();
}
@@ -218,6 +228,7 @@ static inline void write_seqcount_end(seqcount_t *s)
{
smp_wmb();
s->sequence++;
+ rwlock_release(&sl->dep_map, 1, _RET_IP_);
}
/**
next prev parent reply other threads:[~2011-03-29 13:09 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-26 4:12 [RFC] seqlock,lockdep: Add lock primitives to read_seqbegin() Tetsuo Handa
2011-03-28 17:12 ` Steven Rostedt
2011-03-28 21:57 ` Tetsuo Handa
2011-03-29 4:30 ` Tetsuo Handa
2011-03-29 12:49 ` Steven Rostedt
2011-03-29 13:39 ` Peter Zijlstra
2011-03-29 17:50 ` Peter Zijlstra
2011-03-30 8:12 ` Tetsuo Handa
2011-03-30 9:50 ` Peter Zijlstra
2011-03-30 12:17 ` Tetsuo Handa
2011-03-31 13:59 ` Peter Zijlstra
2011-03-29 13:11 ` Peter Zijlstra [this message]
2011-03-29 13:14 ` Peter Zijlstra
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=1301404271.2250.381.camel@laptop \
--to=peterz@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=penguin-kernel@I-love.SAKURA.ne.jp \
--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.