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>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
John Kacur <jkacur@redhat.com>, <stable-rt@vger.kernel.org>
Subject: [PATCH RT 10/16] rt,ntp: Move call to schedule_delayed_work() to helper thread
Date: Mon, 09 Sep 2013 08:45:41 -0400 [thread overview]
Message-ID: <20130909124557.494305433@goodmis.org> (raw)
In-Reply-To: 20130909124531.445392664@goodmis.org
[-- Attachment #1: 0010-rt-ntp-Move-call-to-schedule_delayed_work-to-helper-.patch --]
[-- Type: text/plain, Size: 2578 bytes --]
From: Steven Rostedt <rostedt@goodmis.org>
The ntp code for notify_cmos_timer() is called from a hard interrupt
context. schedule_delayed_work() under PREEMPT_RT_FULL calls spinlocks
that have been converted to mutexes, thus calling schedule_delayed_work()
from interrupt is not safe.
Add a helper thread that does the call to schedule_delayed_work and wake
up that thread instead of calling schedule_delayed_work() directly.
This is only for CONFIG_PREEMPT_RT_FULL, otherwise the code still calls
schedule_delayed_work() directly in irq context.
Note: There's a few places in the kernel that do this. Perhaps the RT
code should have a dedicated thread that does the checks. Just register
a notifier on boot up for your check and wake up the thread when
needed. This will be a todo.
Cc: stable-rt@vger.kernel.org
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
kernel/time/ntp.c | 40 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
diff --git a/kernel/time/ntp.c b/kernel/time/ntp.c
index 96db12f..dfe74f1 100644
--- a/kernel/time/ntp.c
+++ b/kernel/time/ntp.c
@@ -10,6 +10,7 @@
#include <linux/workqueue.h>
#include <linux/hrtimer.h>
#include <linux/jiffies.h>
+#include <linux/kthread.h>
#include <linux/math64.h>
#include <linux/timex.h>
#include <linux/time.h>
@@ -531,10 +532,49 @@ static void sync_cmos_clock(struct work_struct *work)
schedule_delayed_work(&sync_cmos_work, timespec_to_jiffies(&next));
}
+#ifdef CONFIG_PREEMPT_RT_FULL
+/*
+ * RT can not call schedule_delayed_work from real interrupt context.
+ * Need to make a thread to do the real work.
+ */
+static struct task_struct *cmos_delay_thread;
+static bool do_cmos_delay;
+
+static int run_cmos_delay(void *ignore)
+{
+ while (!kthread_should_stop()) {
+ set_current_state(TASK_INTERRUPTIBLE);
+ if (do_cmos_delay) {
+ do_cmos_delay = false;
+ schedule_delayed_work(&sync_cmos_work, 0);
+ }
+ schedule();
+ }
+ __set_current_state(TASK_RUNNING);
+ return 0;
+}
+
+static void notify_cmos_timer(void)
+{
+ do_cmos_delay = true;
+ /* Make visible before waking up process */
+ smp_wmb();
+ wake_up_process(cmos_delay_thread);
+}
+
+static __init int create_cmos_delay_thread(void)
+{
+ cmos_delay_thread = kthread_run(run_cmos_delay, NULL, "kcmosdelayd");
+ BUG_ON(!cmos_delay_thread);
+ return 0;
+}
+early_initcall(create_cmos_delay_thread);
+#else
static void notify_cmos_timer(void)
{
schedule_delayed_work(&sync_cmos_work, 0);
}
+#endif /* CONFIG_PREEMPT_RT_FULL */
#else
static inline void notify_cmos_timer(void) { }
--
1.7.10.4
next prev parent reply other threads:[~2013-09-09 12:45 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-09 12:45 [PATCH RT 00/16] 3.4.57-rt73-rc1 stable review Steven Rostedt
2013-09-09 12:45 ` [PATCH RT 01/16] sched/workqueue: Only wake up idle workers if not blocked on sleeping spin lock Steven Rostedt
2013-09-09 12:45 ` [PATCH RT 02/16] x86/mce: fix mce timer interval Steven Rostedt
2013-09-09 12:45 ` [PATCH RT 03/16] genirq: Set irq thread to RT priority on creation Steven Rostedt
2013-09-09 12:45 ` [PATCH RT 04/16] list_bl.h: make list head locking RT safe Steven Rostedt
2013-09-09 12:45 ` [PATCH RT 05/16] list_bl.h: fix it for for !SMP && !DEBUG_SPINLOCK Steven Rostedt
2013-09-09 12:45 ` [PATCH RT 06/16] timers: prepare for full preemption improve Steven Rostedt
2013-09-09 12:45 ` [PATCH RT 07/16] kernel/cpu: fix cpu down problem if kthreads cpu is going down Steven Rostedt
2013-09-09 12:45 ` [PATCH RT 08/16] kernel/hotplug: restore original cpu mask oncpu/down Steven Rostedt
2013-09-09 12:45 ` [PATCH RT 09/16] drm/i915: drop trace_i915_gem_ring_dispatch on rt Steven Rostedt
2013-09-09 12:45 ` Steven Rostedt [this message]
2013-09-09 12:45 ` [PATCH RT 11/16] hwlat-detector: Update hwlat_detector to add outer loop detection Steven Rostedt
2013-09-09 12:45 ` [PATCH RT 12/16] hwlat-detect/trace: Export trace_clock_local for hwlat-detector Steven Rostedt
2013-09-09 12:45 ` [PATCH RT 13/16] hwlat-detector: Use trace_clock_local if available Steven Rostedt
2013-09-09 12:45 ` [PATCH RT 14/16] hwlat-detector: Use thread instead of stop machine Steven Rostedt
2013-09-09 12:45 ` [PATCH RT 15/16] genirq: do not invoke the affinity callback via a workqueue Steven Rostedt
2013-09-09 12:45 ` [PATCH RT 16/16] Linux 3.4.57-rt73-rc1 Steven Rostedt
-- strict thread matches above, loose matches on Subject: below --
2013-09-09 12:47 [PATCH RT 00/16] 3.2.50-rt71-rc1 stable review Steven Rostedt
2013-09-09 12:47 ` [PATCH RT 10/16] rt,ntp: Move call to schedule_delayed_work() to helper thread Steven Rostedt
2013-09-09 14:35 [PATCH RT 00/16] 3.0.89-rt118-rc1 stable review Steven Rostedt
2013-09-09 14:35 ` [PATCH RT 10/16] rt,ntp: Move call to schedule_delayed_work() to helper thread 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=20130909124557.494305433@goodmis.org \
--to=rostedt@goodmis.org \
--cc=C.Emde@osadl.org \
--cc=bigeasy@linutronix.de \
--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).