From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: linux-rt-users@vger.kernel.org
Cc: linux-kernel@vger.kernel.org,
Gratian Crisan <gratian.crisan@ni.com>,
Piotr Gregor <piotrgregor@rsyncme.org>,
tglx@linutronix.de, Peter Zijlstra <peterz@infradead.org>,
Steven Rostedt <rostedt@goodmis.org>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Subject: [PATCH RT] time/hrtimer: Use softirq based wakeups for non-RT threads
Date: Wed, 4 Oct 2017 18:08:20 +0200 [thread overview]
Message-ID: <20171004160820.27754-1-bigeasy@linutronix.de> (raw)
Normal wake ups (like clock_nanosleep()) which are performed by normal
users can easily lead to 2ms latency spikes if (enough) hrtimer wakeups
are synchronized.
This patch moves all hrtimers wakeups to the softirq queue unless the
caller has a RT priority.
Reported-by: Gratian Crisan <gratian.crisan@ni.com>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
kernel/time/hrtimer.c | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
index 3aa823fcab70..8ea2825a50af 100644
--- a/kernel/time/hrtimer.c
+++ b/kernel/time/hrtimer.c
@@ -1622,14 +1622,31 @@ static enum hrtimer_restart hrtimer_wakeup(struct hrtimer *timer)
return HRTIMER_NORESTART;
}
+#ifdef CONFIG_PREEMPT_RT_FULL
+static bool task_is_elevated(struct task_struct *tsk)
+{
+ int policy = tsk->policy;
+
+ if (policy == SCHED_FIFO || policy == SCHED_RR)
+ return true;
+ if (policy == SCHED_DEADLINE)
+ return true;
+ return false;
+}
+#endif
+
static void __hrtimer_init_sleeper(struct hrtimer_sleeper *sl,
clockid_t clock_id,
enum hrtimer_mode mode,
struct task_struct *task)
{
#ifdef CONFIG_PREEMPT_RT_FULL
- if (!(clock_id & HRTIMER_BASE_SOFT_MASK))
- clock_id |= HRTIMER_BASE_HARD_MASK;
+ if (!(clock_id & (HRTIMER_BASE_HARD_MASK | HRTIMER_BASE_SOFT_MASK))) {
+ if (task_is_elevated(current) || system_state != SYSTEM_RUNNING)
+ clock_id |= HRTIMER_BASE_HARD_MASK;
+ else
+ clock_id |= HRTIMER_BASE_SOFT_MASK;
+ }
#endif
__hrtimer_init(&sl->timer, clock_id, mode);
sl->timer.function = hrtimer_wakeup;
--
2.14.2
next reply other threads:[~2017-10-04 16:08 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-04 16:08 Sebastian Andrzej Siewior [this message]
2017-10-05 21:14 ` Gratian Crisan
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=20171004160820.27754-1-bigeasy@linutronix.de \
--to=bigeasy@linutronix.de \
--cc=gratian.crisan@ni.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rt-users@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=piotrgregor@rsyncme.org \
--cc=rostedt@goodmis.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
all inboxes | Powered by JetHome®