From: Kirill Tkhai <tkhai@yandex.ru>
To: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>,
Ingo Molnar <mingo@redhat.com>,
Peter Zijlstra <peterz@infradead.org>
Subject: [PATCH] sched: schedule_raw_spin_unlock() and schedule_spin_unlock()
Date: Fri, 14 Jun 2013 18:40:51 +0400 [thread overview]
Message-ID: <353211371220851@web23d.yandex.ru> (raw)
Helpers for replacement repeating patterns:
1)raw_spin_unlock_irq(lock);
schedule();
2)raw_spin_unlock_irqrestore(lock, flags);
schedule();
(The same for spinlock_t)
They allow to prevent excess preempt_schedule(), which can happen on preemptible kernel.
Signed-off-by: Kirill Tkhai <tkhai@yandex.ru>
CC: Steven Rostedt <rostedt@goodmis.org>
CC: Ingo Molnar <mingo@redhat.com>
CC: Peter Zijlstra <peterz@infradead.org>
---
include/linux/sched.h | 20 ++++++++++++++++++++
kernel/sched/core.c | 24 ++++++++++++++++++++++++
2 files changed, 44 insertions(+), 0 deletions(-)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 8b10339..0ae79f3 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -310,6 +310,26 @@ extern signed long schedule_timeout_uninterruptible(signed long timeout);
asmlinkage void schedule(void);
extern void schedule_preempt_disabled(void);
+#ifdef CONFIG_PREEMPT
+extern void schedule_raw_spin_unlock(raw_spinlock_t *lock);
+/* See comment for schedule_raw_spin_unlock() */
+static inline void schedule_spin_unlock(spinlock_t *lock)
+{
+ schedule_raw_spin_unlock(&lock->rlock);
+}
+#else
+static inline void schedule_raw_spin_unlock(raw_spinlock_t *lock)
+{
+ raw_spin_unlock_irq(lock);
+ schedule();
+}
+static inline void schedule_spin_unlock(spinlock_t *lock)
+{
+ spin_unlock_irq(lock);
+ schedule();
+}
+#endif
+
struct nsproxy;
struct user_namespace;
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 58453b8..381e493 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -3125,6 +3125,30 @@ asmlinkage void __sched preempt_schedule_irq(void)
exception_exit(prev_state);
}
+/*
+ * schedule_raw_spin_unlock - unlock raw_spinlock and call schedule()
+ *
+ * Should be used instead of the constructions
+ * 1) raw_spin_unlock_irq(lock);
+ * schedule();
+ * or
+ * 2) raw_spin_unlock_irqrestore(lock, flags);
+ * schedule();
+ * where they have to be.
+ *
+ * It helps to prevent excess preempt_schedule() during the unlocking,
+ * which can be called on preemptible kernel.
+ * Returns with irqs enabled.
+ */
+void __sched schedule_raw_spin_unlock(raw_spinlock_t *lock)
+{
+ preempt_disable();
+ raw_spin_unlock_irq(lock);
+ sched_preempt_enable_no_resched();
+ schedule();
+}
+EXPORT_SYMBOL(schedule_raw_spin_unlock);
+
#endif /* CONFIG_PREEMPT */
int default_wake_function(wait_queue_t *curr, unsigned mode, int wake_flags,
next reply other threads:[~2013-06-14 14:40 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-14 14:40 Kirill Tkhai [this message]
2013-06-17 14:29 ` Steven Rostedt
2013-06-17 16:12 ` Kirill Tkhai
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=353211371220851@web23d.yandex.ru \
--to=tkhai@yandex.ru \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
/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®