From: Thomas Gleixner <tglx@linutronix.de>
To: LKML <linux-kernel@vger.kernel.org>
Cc: x86@kernel.org, Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@kernel.org>,
Sebastian Siewior <bigeasy@linutronix.de>,
Anna-Maria Gleixner <anna-maria@linutronix.de>,
Steven Rostedt <rostedt@goodmis.org>,
Julia Cartwright <julia@ni.com>,
Paul McKenney <paulmck@linux.vnet.ibm.com>,
Frederic Weisbecker <fweisbec@gmail.com>,
John Stultz <john.stultz@linaro.org>,
Andy Lutomirski <luto@kernel.org>,
"Paul E. McKenney" <paulmck@linux.ibm.com>,
Oleg Nesterov <oleg@redhat.com>,
kvm@vger.kernel.org, Radim Krcmar <rkrcmar@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>
Subject: [patch 4/5] posix-cpu-timers: Defer timer handling to task_work
Date: Thu, 01 Aug 2019 16:32:54 +0200 [thread overview]
Message-ID: <20190801143658.074833024@linutronix.de> (raw)
In-Reply-To: 20190801143250.370326052@linutronix.de
Running posix cpu timers in hard interrupt context has a few downsides:
- For PREEMPT_RT it cannot work as the expiry code needs to take sighand
lock, which is a 'sleeping spinlock' in RT
- For fine grained accounting it's just wrong to run this in context of
the timer interrupt because that way a process specific cpu time is
accounted to the timer interrupt.
There is no real hard requirement to run the expiry code in hard interrupt
context. The posix CPU timers are an approximation anyway, so having them
expired and evaluated in task work context does not really make them worse.
Make it conditional on a selectable config switch as this requires that
task work is handled in KVM.
The available tests pass and no problematic difference has been observed.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: "Paul E. McKenney" <paulmck@linux.ibm.com>
---
include/linux/sched.h | 3 +++
kernel/time/Kconfig | 5 +++++
kernel/time/posix-cpu-timers.c | 26 +++++++++++++++++++++++++-
3 files changed, 33 insertions(+), 1 deletion(-)
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -880,6 +880,9 @@ struct task_struct {
struct task_cputime cputime_expires;
struct list_head cpu_timers[3];
#endif
+#ifdef CONFIG_POSIX_CPU_TIMERS_TASK_WORK
+ struct callback_head cpu_timer_work;
+#endif
/* Process credentials: */
--- a/kernel/time/Kconfig
+++ b/kernel/time/Kconfig
@@ -52,6 +52,11 @@ config GENERIC_CLOCKEVENTS_MIN_ADJUST
config GENERIC_CMOS_UPDATE
bool
+# Select to handle posix CPU timers from task_work
+# and not from the timer interrupt context
+config POSIX_CPU_TIMERS_TASK_WORK
+ bool
+
if GENERIC_CLOCKEVENTS
menu "Timers subsystem"
--- a/kernel/time/posix-cpu-timers.c
+++ b/kernel/time/posix-cpu-timers.c
@@ -14,6 +14,7 @@
#include <linux/tick.h>
#include <linux/workqueue.h>
#include <linux/compat.h>
+#include <linux/task_work.h>
#include <linux/sched/deadline.h>
#include "posix-timers.h"
@@ -1127,7 +1128,7 @@ static inline int fastpath_timer_check(s
return 0;
}
-static void __run_posix_cpu_timers(struct task_struct *tsk)
+static void handle_posix_cpu_timers(struct task_struct *tsk)
{
struct k_itimer *timer, *next;
unsigned long flags;
@@ -1178,6 +1179,29 @@ static void __run_posix_cpu_timers(struc
}
}
+#ifdef CONFIG_POSIX_CPU_TIMERS_TASK_WORK
+
+static void posix_cpu_timers_work(struct callback_head *work)
+{
+ handle_posix_cpu_timers(current);
+}
+
+static void __run_posix_cpu_timers(struct task_struct *tsk)
+{
+ /* FIXME: Init it proper in fork or such */
+ init_task_work(&tsk->cpu_timer_work, posix_cpu_timers_work);
+ task_work_add(tsk, &tsk->cpu_timer_work, true);
+}
+
+#else
+
+static void __run_posix_cpu_timers(struct task_struct *tsk)
+{
+ handle_posix_cpu_timers(tsk);
+}
+
+#endif
+
/*
* This is called from the timer interrupt handler. The irq handler has
* already updated our counts. We need to check if any timers fire now.
next prev parent reply other threads:[~2019-08-01 14:38 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-01 14:32 [patch 0/5] posix-cpu-timers: Move expiry into task work context Thomas Gleixner
2019-08-01 14:32 ` [patch 1/5] tracehook: Provide TIF_NOTIFY_RESUME handling for KVM Thomas Gleixner
2019-08-01 14:48 ` Peter Zijlstra
2019-08-01 15:10 ` Thomas Gleixner
2019-08-01 17:02 ` Andy Lutomirski
2019-08-01 14:32 ` [patch 2/5] x86/kvm: Handle task_work on VMENTER/EXIT Thomas Gleixner
2019-08-01 16:24 ` Oleg Nesterov
2019-08-01 18:34 ` Thomas Gleixner
2019-08-01 21:35 ` Sean Christopherson
2019-08-01 21:44 ` Peter Zijlstra
2019-08-01 21:44 ` Thomas Gleixner
2019-08-01 21:47 ` Thomas Gleixner
2019-08-02 21:35 ` Paolo Bonzini
2019-08-02 22:22 ` Thomas Gleixner
2019-08-02 22:39 ` Andy Lutomirski
2019-08-02 12:04 ` Oleg Nesterov
2019-08-01 14:32 ` [patch 3/5] posix-cpu-timers: Split run_posix_cpu_timers() Thomas Gleixner
2019-08-01 14:32 ` Thomas Gleixner [this message]
2019-08-01 14:51 ` [patch 4/5] posix-cpu-timers: Defer timer handling to task_work Peter Zijlstra
2019-08-01 15:10 ` Thomas Gleixner
2019-08-01 15:39 ` Oleg Nesterov
2019-08-01 18:41 ` Thomas Gleixner
2019-08-01 14:32 ` [patch 5/5] x86: Select POSIX_CPU_TIMERS_TASK_WORK Thomas Gleixner
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=20190801143658.074833024@linutronix.de \
--to=tglx@linutronix.de \
--cc=anna-maria@linutronix.de \
--cc=bigeasy@linutronix.de \
--cc=fweisbec@gmail.com \
--cc=john.stultz@linaro.org \
--cc=julia@ni.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@kernel.org \
--cc=oleg@redhat.com \
--cc=paulmck@linux.ibm.com \
--cc=paulmck@linux.vnet.ibm.com \
--cc=pbonzini@redhat.com \
--cc=peterz@infradead.org \
--cc=rkrcmar@redhat.com \
--cc=rostedt@goodmis.org \
--cc=x86@kernel.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