[patch V2 0/5] posix-cpu-timers: Move expiry into task work context

Thomas Gleixner
2020-07-16T20:22:13Z

This is the second attempt of moving the posix CPU timer heavy lifting out
of interrupt context. The initial version can be found here:

https://lore.kernel.org/r/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.

- Long running timer interrupts caused by a large amount of expiring
timers which can be created and armed by unpriviledged user space.

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.

This version is more or less a resend of the posix CPU timer bits of
V1. The back then observed issue that KVM does not handle pending task work
before going into guest mode has been solved differently. The related
patches have been posted here:

https://lore.kernel.org/r/20200716182208.180916541@linutronix.de

This patch series has no code dependency on the entry/KVM work, but the
functional dependency vs. KVM exists.

It applies on mainline and passes all tests - except when KVM is active and
timers are armed on the KVM threads. This particular issue is solved when
the entry/KVM series is applied as well.

The entry/KVM changes are available from:

git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git x86/entry

and the whole lot (entry/kvm + posix CPU timers) is available from:

git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git timers/posixtimer

Thanks,

tglx

----
b/arch/x86/Kconfig | 1
include/linux/posix-timers.h | 33 ++++--
include/linux/sched/cputime.h | 2
kernel/time/Kconfig | 5
kernel/time/posix-cpu-timers.c | 213 ++++++++++++++++++++++++++++++-----------
5 files changed, 192 insertions(+), 62 deletions(-)