From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org,
linux-rt-users <linux-rt-users@vger.kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>,
Carsten Emde <C.Emde@osadl.org>, John Kacur <jkacur@redhat.com>,
stable-rt@vger.kernel.org
Subject: [PATCH RT 16/25][RFC 3.0.23-rt39-rc1] seqlock: Prevent rt starvation
Date: Tue, 06 Mar 2012 11:16:52 -0500 [thread overview]
Message-ID: <20120306161950.357072870@goodmis.org> (raw)
In-Reply-To: 20120306161636.491172179@goodmis.org
[-- Attachment #1: 0016-seqlock-Prevent-rt-starvation.patch --]
[-- Type: text/plain, Size: 1998 bytes --]
From: Thomas Gleixner <tglx@linutronix.de>
If a low prio writer gets preempted while holding the seqlock write
locked, a high prio reader spins forever on RT.
To prevent this let the reader grab the spinlock, so it blocks and
eventually boosts the writer. This way the writer can proceed and
endless spinning is prevented.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: stable-rt@vger.kernel.org
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
include/linux/seqlock.h | 23 +++++++++++++++++++++++
include/net/neighbour.h | 2 +-
2 files changed, 24 insertions(+), 1 deletions(-)
diff --git a/include/linux/seqlock.h b/include/linux/seqlock.h
index b44048d..29ffd4f 100644
--- a/include/linux/seqlock.h
+++ b/include/linux/seqlock.h
@@ -177,10 +177,33 @@ typedef struct {
/*
* Read side functions for starting and finalizing a read side section.
*/
+#ifndef CONFIG_PREEMPT_RT_FULL
static inline unsigned read_seqbegin(const seqlock_t *sl)
{
return read_seqcount_begin(&sl->seqcount);
}
+#else
+/*
+ * Starvation safe read side for RT
+ */
+static inline unsigned read_seqbegin(seqlock_t *sl)
+{
+ unsigned ret;
+
+repeat:
+ ret = sl->seqcount.sequence;
+ if (unlikely(ret & 1)) {
+ /*
+ * Take the lock and let the writer proceed (i.e. evtl
+ * boost it), otherwise we could loop here forever.
+ */
+ spin_lock(&sl->lock);
+ spin_unlock(&sl->lock);
+ goto repeat;
+ }
+ return ret;
+}
+#endif
static inline unsigned read_seqretry(const seqlock_t *sl, unsigned start)
{
diff --git a/include/net/neighbour.h b/include/net/neighbour.h
index 4014b62..9c1cb97 100644
--- a/include/net/neighbour.h
+++ b/include/net/neighbour.h
@@ -377,7 +377,7 @@ struct neighbour_cb {
#define NEIGH_CB(skb) ((struct neighbour_cb *)(skb)->cb)
-static inline void neigh_ha_snapshot(char *dst, const struct neighbour *n,
+static inline void neigh_ha_snapshot(char *dst, struct neighbour *n,
const struct net_device *dev)
{
unsigned int seq;
--
1.7.8.3
next prev parent reply other threads:[~2012-03-06 16:16 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-06 16:16 [PATCH RT 00/25][RFC 3.0.23-rt39-rc1] [ANNOUNCE] 3.0.23-rt39-rc1 release cycle Steven Rostedt
2012-03-06 16:16 ` [PATCH RT 01/25][RFC 3.0.23-rt39-rc1] revert-convert-xtime_lock-to-raw_seqlock Steven Rostedt
2012-03-06 16:16 ` [PATCH RT 02/25][RFC 3.0.23-rt39-rc1] revert-seqlock-create-raw_seqlock Steven Rostedt
2012-03-06 16:16 ` [PATCH RT 03/25][RFC 3.0.23-rt39-rc1] revert-seqlock-use-seqcount Steven Rostedt
2012-03-06 16:16 ` [PATCH RT 04/25][RFC 3.0.23-rt39-rc1] revert-seqlock-remove-unused-functions Steven Rostedt
2012-03-06 22:39 ` John Kacur
2012-03-06 22:42 ` Thomas Gleixner
2012-03-06 16:16 ` [PATCH RT 05/25][RFC 3.0.23-rt39-rc1] x86-64-remove-vsyscall-number-3 Steven Rostedt
2012-03-06 16:16 ` [PATCH RT 06/25][RFC 3.0.23-rt39-rc1] x86-64-emulate-legacy-vsyscalls Steven Rostedt
2012-03-06 16:16 ` [PATCH RT 07/25][RFC 3.0.23-rt39-rc1] x86: vdso: Remove bogus locking in update_vsyscall_tz() Steven Rostedt
2012-03-06 16:16 ` [PATCH RT 08/25][RFC 3.0.23-rt39-rc1] x86: vdso: Use seqcount instead of seqlock Steven Rostedt
2012-03-06 16:16 ` [PATCH RT 09/25][RFC 3.0.23-rt39-rc1] ia64: vsyscall: " Steven Rostedt
2012-03-06 16:16 ` [PATCH RT 10/25][RFC 3.0.23-rt39-rc1] seqlock: Remove unused functions Steven Rostedt
2012-03-06 16:16 ` [PATCH RT 11/25][RFC 3.0.23-rt39-rc1] seqlock: Use seqcount Steven Rostedt
2012-03-06 16:16 ` [PATCH RT 12/25][RFC 3.0.23-rt39-rc1] seqlock: Provide seq_spin_* functions Steven Rostedt
2012-03-06 16:16 ` [PATCH RT 13/25][RFC 3.0.23-rt39-rc1] fs: fs_struct use seqlock Steven Rostedt
2012-03-06 16:16 ` [PATCH RT 14/25][RFC 3.0.23-rt39-rc1] fs: dentry " Steven Rostedt
2012-03-06 16:16 ` [PATCH RT 15/25][RFC 3.0.23-rt39-rc1] timekeeping: Split xtime_lock Steven Rostedt
2012-03-06 16:16 ` Steven Rostedt [this message]
2012-03-06 16:16 ` [PATCH RT 17/25][RFC 3.0.23-rt39-rc1] fs: Protect open coded isize seqcount Steven Rostedt
2012-03-06 16:16 ` [PATCH RT 18/25][RFC 3.0.23-rt39-rc1] net: u64_stat: Protect seqcount Steven Rostedt
2012-03-06 16:16 ` [PATCH RT 19/25][RFC 3.0.23-rt39-rc1] timer: Fix hotplug for -rt Steven Rostedt
2012-03-06 16:16 ` [PATCH RT 20/25][RFC 3.0.23-rt39-rc1] futex/rt: Fix possible lockup when taking pi_lock in proxy handler Steven Rostedt
2012-03-06 16:16 ` [PATCH RT 21/25][RFC 3.0.23-rt39-rc1] ring-buffer/rt: Check for irqs disabled before grabbing reader lock Steven Rostedt
2012-03-06 16:16 ` [PATCH RT 22/25][RFC 3.0.23-rt39-rc1] sched/rt: Fix wait_task_interactive() to test rt_spin_lock state Steven Rostedt
2012-03-06 16:16 ` [PATCH RT 23/25][RFC 3.0.23-rt39-rc1] lglock/rt: Use non-rt for_each_cpu() in -rt code Steven Rostedt
2012-03-06 16:17 ` [PATCH RT 24/25][RFC 3.0.23-rt39-rc1] cpu: Make hotplug.lock a "sleeping" spinlock on RT Steven Rostedt
2012-03-06 16:17 ` [PATCH RT 25/25][RFC 3.0.23-rt39-rc1] Linux 3.0.23-rt39-rc1 Steven Rostedt
2012-03-06 22:20 ` [PATCH RT 00/25][RFC 3.0.23-rt39-rc1] [ANNOUNCE] 3.0.23-rt39-rc1 release cycle Steven Rostedt
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=20120306161950.357072870@goodmis.org \
--to=rostedt@goodmis.org \
--cc=C.Emde@osadl.org \
--cc=jkacur@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-users@vger.kernel.org \
--cc=stable-rt@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).