mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: John Kacur <jkacur@redhat.com>
To: Thomas Gleixner <tglx@linutronix.de>,
	lkml <linux-kernel@vger.kernel.org>, Ingo Molnar <mingo@elte.hu>
Cc: Clark Williams <williams@redhat.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	John Kacur <jkacur@redhat.com>
Subject: [PATCH 02/26] seqlock: Create raw_seqlock
Date: Mon, 11 Jan 2010 22:26:32 +0100	[thread overview]
Message-ID: <1263245216-14754-3-git-send-email-jkacur@redhat.com> (raw)
In-Reply-To: <1263245216-14754-2-git-send-email-jkacur@redhat.com>

From: Thomas Gleixner <tglx@linutronix.de>

raw_seqlock_t will be used to annotate seqlocks which can not be
converted to sleeping locks in preempt-rt

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

The original patch 09e46c7a86b2e81f97bd93f588b62c2d36cff58e used atomic_locks
I converted this patch to raw_locks.

Signed-off-by: John Kacur <jkacur@redhat.com>
---
 include/linux/seqlock.h |   86 ++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 82 insertions(+), 4 deletions(-)

diff --git a/include/linux/seqlock.h b/include/linux/seqlock.h
index 632205c..6f2685c 100644
--- a/include/linux/seqlock.h
+++ b/include/linux/seqlock.h
@@ -31,6 +31,11 @@
 
 typedef struct {
 	unsigned sequence;
+	raw_spinlock_t lock;
+} raw_seqlock_t;
+
+typedef struct {
+	unsigned sequence;
 	spinlock_t lock;
 } seqlock_t;
 
@@ -38,11 +43,23 @@ typedef struct {
  * These macros triggered gcc-3.x compile-time problems.  We think these are
  * OK now.  Be cautious.
  */
+#define __RAW_SEQLOCK_UNLOCKED(lockname) \
+	{ 0, __RAW_SPIN_LOCK_UNLOCKED(lockname) }
+
+#define seqlock_raw_init(x)				\
+	do {						\
+		(x)->sequence = 0;			\
+		raw_spin_lock_init(&(x)->lock);	\
+	} while (0)
+
+#define DEFINE_RAW_SEQLOCK(x) \
+	raw_seqlock_t x = __RAW_SEQLOCK_UNLOCKED(x)
+
 #define __SEQLOCK_UNLOCKED(lockname) \
-		 { 0, __SPIN_LOCK_UNLOCKED(lockname) }
+	{ 0, __SPIN_LOCK_UNLOCKED(lockname) }
 
 #define SEQLOCK_UNLOCKED \
-		 __SEQLOCK_UNLOCKED(old_style_seqlock_init)
+	__SEQLOCK_UNLOCKED(old_style_seqlock_init)
 
 #define seqlock_init(x)					\
 	do {						\
@@ -51,12 +68,19 @@ typedef struct {
 	} while (0)
 
 #define DEFINE_SEQLOCK(x) \
-		seqlock_t x = __SEQLOCK_UNLOCKED(x)
+	seqlock_t x = __SEQLOCK_UNLOCKED(x)
 
 /* Lock out other writers and update the count.
  * Acts like a normal spin_lock/unlock.
  * Don't need preempt_disable() because that is in the spin_lock already.
  */
+static inline void write_raw_seqlock(raw_seqlock_t *sl)
+{
+	raw_spin_lock(&sl->lock);
+	++sl->sequence;
+	smp_wmb();
+}
+
 static inline void write_seqlock(seqlock_t *sl)
 {
 	spin_lock(&sl->lock);
@@ -64,6 +88,13 @@ static inline void write_seqlock(seqlock_t *sl)
 	smp_wmb();
 }
 
+static inline void write_raw_sequnlock(raw_seqlock_t *sl)
+{
+	smp_wmb();
+	sl->sequence++;
+	raw_spin_unlock(&sl->lock);
+}
+
 static inline void write_sequnlock(seqlock_t *sl)
 {
 	smp_wmb();
@@ -83,6 +114,21 @@ static inline int write_tryseqlock(seqlock_t *sl)
 }
 
 /* Start of read calculation -- fetch last complete writer token */
+static __always_inline unsigned read_raw_seqbegin(const raw_seqlock_t *sl)
+{
+	unsigned ret;
+
+repeat:
+	ret = sl->sequence;
+	smp_rmb();
+	if (unlikely(ret & 1)) {
+		cpu_relax();
+		goto repeat;
+	}
+
+	return ret;
+}
+
 static __always_inline unsigned read_seqbegin(const seqlock_t *sl)
 {
 	unsigned ret;
@@ -103,6 +149,14 @@ repeat:
  *
  * If sequence value changed then writer changed data while in section.
  */
+static __always_inline int
+read_raw_seqretry(const raw_seqlock_t *sl, unsigned start)
+{
+	smp_rmb();
+
+	return (sl->sequence != start);
+}
+
 static __always_inline int read_seqretry(const seqlock_t *sl, unsigned start)
 {
 	smp_rmb();
@@ -170,12 +224,36 @@ static inline void write_seqcount_end(seqcount_t *s)
 /*
  * Possible sw/hw IRQ protected versions of the interfaces.
  */
+#define write_raw_seqlock_irqsave(lock, flags)			\
+	do { local_irq_save(flags); write_raw_seqlock(lock); } while (0)
+#define write_raw_seqlock_irq(lock)					\
+	do { local_irq_disable();   write_raw_seqlock(lock); } while (0)
+#define write_raw_seqlock_bh(lock)					\
+	do { local_bh_disable();    write_raw_seqlock(lock); } while (0)
+
+#define write_raw_sequnlock_irqrestore(lock, flags)			\
+	do { write_raw_sequnlock(lock); local_irq_restore(flags); } while(0)
+#define write_raw_sequnlock_irq(lock)				\
+	do { write_raw_sequnlock(lock); local_irq_enable(); } while(0)
+#define write_raw_sequnlock_bh(lock)					\
+	do { write_raw_sequnlock(lock); local_bh_enable(); } while(0)
+
+#define read_raw_seqbegin_irqsave(lock, flags)			\
+	({ local_irq_save(flags);   read_raw_seqbegin(lock); })
+
+#define read_raw_seqretry_irqrestore(lock, iv, flags)		\
+	({								\
+		int ret = read_raw_seqretry(lock, iv);		\
+		local_irq_restore(flags);				\
+		ret;							\
+	})
+
 #define write_seqlock_irqsave(lock, flags)				\
 	do { local_irq_save(flags); write_seqlock(lock); } while (0)
 #define write_seqlock_irq(lock)						\
 	do { local_irq_disable();   write_seqlock(lock); } while (0)
 #define write_seqlock_bh(lock)						\
-        do { local_bh_disable();    write_seqlock(lock); } while (0)
+	do { local_bh_disable();    write_seqlock(lock); } while (0)
 
 #define write_sequnlock_irqrestore(lock, flags)				\
 	do { write_sequnlock(lock); local_irq_restore(flags); } while(0)
-- 
1.6.5.2


  reply	other threads:[~2010-01-11 21:27 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-11 21:26 [PATCH 00/26] Convert locks that can't sleep in -rt to raw_spinlock John Kacur
2010-01-11 21:26 ` [PATCH 01/26] xtime_lock: Convert atomic_seqlock to raw_seqlock, fix up all users John Kacur
2010-01-11 21:26   ` John Kacur [this message]
2010-01-11 21:26     ` [PATCH 03/26] x86: Convert tlbstate_lock to raw_spinlock John Kacur
2010-01-11 21:26       ` [PATCH 04/26] sched: Convert thread_group_cputimer lock " John Kacur
2010-01-11 21:26         ` [PATCH 05/26] x86: Convert ioapic_lock and vector_lock to raw_spinlocks John Kacur
2010-01-11 21:26           ` [PATCH 06/26] x86: Convert i8259A_lock to raw_spinlock John Kacur
2010-01-11 21:26             ` [PATCH 07/26] x86: Convert pci_config_lock " John Kacur
2010-01-11 21:26               ` [PATCH 08/26] i8253: Convert i8253_lock " John Kacur
2010-01-11 21:26                 ` [PATCH 09/26] x86: Convert set_atomicity_lock " John Kacur
2010-01-11 21:26                   ` [PATCH 10/26] ACPI: Convert c3_lock " John Kacur
2010-01-11 21:26                     ` [PATCH 11/26] rtmutex: Convert wait_lock and pi_lock " John Kacur
2010-01-11 21:26                       ` [PATCH 12/26] printk: Convert lock " John Kacur
2010-01-11 21:26                         ` [PATCH 13/26] genirq: Convert locks to raw_spinlocks John Kacur
2010-01-11 21:26                           ` [PATCH 14/26] trace: Convert various locks to raw_spinlock John Kacur
2010-01-11 21:26                             ` [PATCH 15/26] clocksource: Convert watchdog_lock " John Kacur
2010-01-11 21:26                               ` [PATCH 16/26] timer_stats: Convert to raw_spinlocks John Kacur
2010-01-11 21:26                                 ` [PATCH 17/26] x86: kvm: Convert i8254/i8259 locks to raw_spinlock John Kacur
2010-01-11 21:26                                   ` [PATCH 18/26] x86 - nmi: Convert nmi_lock " John Kacur
2010-01-11 21:26                                     ` [PATCH 19/26] cgroups: Convert cgroups release_list_lock " John Kacur
2010-01-11 21:26                                       ` [PATCH 20/26] proportions: Convert spinlocks to raw_spinlocks John Kacur
2010-01-11 21:26                                         ` [PATCH 21/26] percpu_counter: Convert to raw_spinlock John Kacur
2010-01-11 21:26                                           ` [PATCH 22/26] oprofile: " John Kacur
2010-01-11 21:26                                             ` [PATCH 23/26] vgacon: Convert vga console lock " John Kacur
2010-01-11 21:26                                               ` [PATCH 24/26] pci-access: Convert pci_lock " John Kacur
2010-01-11 21:26                                                 ` [PATCH 25/26] kprobes: Convert to raw_spinlocks John Kacur
2010-01-11 21:26                                                   ` [PATCH 26/26] softlockup: " John Kacur
2010-01-12  3:54                                                   ` [PATCH 25/26] kprobes: " Frederic Weisbecker
2010-01-11 21:50                                       ` [PATCH 19/26] cgroups: Convert cgroups release_list_lock to raw_spinlock Paul Menage
2010-01-11 22:11                                         ` John Kacur
2010-01-12  3:39                             ` [PATCH 14/26] trace: Convert various locks " Frederic Weisbecker
2010-01-13 15:28                               ` Steven Rostedt
2010-01-13 15:36                                 ` John Kacur
2010-01-13 15:41                                   ` Steven Rostedt
2010-01-13 18:09                                     ` John Kacur
2010-01-17 13:00                                       ` Frederic Weisbecker
2010-01-12  3:24 ` [PATCH 00/26] Convert locks that can't sleep in -rt " Frederic Weisbecker
2010-01-12  3:49   ` Frederic Weisbecker

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=1263245216-14754-3-git-send-email-jkacur@redhat.com \
    --to=jkacur@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=tglx@linutronix.de \
    --cc=williams@redhat.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

Powered by JetHome