[patch 08/11] signal: Move itimer rearming into itimer code

From: Thomas Gleixner
Date: Thu Sep 23 2021 - 12:05:12 EST


Move the itimer rearming functionality into itimer.c which cleans up the
ifdeffery in the signal code.

While at it replace the open coded hrtimer_forward() invocation with
hrtimer_forward_now() which is equivalent.

Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Cc: "Eric W. Biederman" <ebiederm@xxxxxxxxxxxx>
---
include/linux/posix-timers.h | 3 +++
kernel/signal.c | 14 ++------------
kernel/time/itimer.c | 13 +++++++++++++
3 files changed, 18 insertions(+), 12 deletions(-)

--- a/include/linux/posix-timers.h
+++ b/include/linux/posix-timers.h
@@ -174,6 +174,8 @@ static inline void posix_cputimers_rt_wa
.posix_cputimers = { \
.bases = INIT_CPU_TIMERBASES(s.posix_cputimers.bases), \
},
+
+void itimer_restart(void);
#else
struct posix_cputimers { };
struct cpu_timer { };
@@ -181,6 +183,7 @@ struct cpu_timer { };
static inline void posix_cputimers_init(struct posix_cputimers *pct) { }
static inline void posix_cputimers_group_init(struct posix_cputimers *pct,
u64 cpu_limit) { }
+static inline void itimer_restart(void) { }
#endif

#ifdef CONFIG_POSIX_CPU_TIMERS_TASK_WORK
--- a/kernel/signal.c
+++ b/kernel/signal.c
@@ -651,7 +651,6 @@ int dequeue_signal(struct task_struct *t
if (!signr) {
signr = __dequeue_signal(&tsk->signal->shared_pending,
mask, info, &resched_timer);
-#ifdef CONFIG_POSIX_TIMERS
/*
* itimer signal ?
*
@@ -665,17 +664,8 @@ int dequeue_signal(struct task_struct *t
* reducing the timer noise on heavy loaded !highres
* systems too.
*/
- if (unlikely(signr == SIGALRM)) {
- struct hrtimer *tmr = &tsk->signal->real_timer;
-
- if (!hrtimer_is_queued(tmr) &&
- tsk->signal->it_real_incr != 0) {
- hrtimer_forward(tmr, tmr->base->get_time(),
- tsk->signal->it_real_incr);
- hrtimer_restart(tmr);
- }
- }
-#endif
+ if (unlikely(signr == SIGALRM))
+ itimer_restart();
}

recalc_sigpending();
--- a/kernel/time/itimer.c
+++ b/kernel/time/itimer.c
@@ -150,6 +150,19 @@ COMPAT_SYSCALL_DEFINE2(getitimer, int, w
}
#endif

+void itimer_restart(void)
+{
+ struct task_struct *tsk = current;
+ struct hrtimer *tmr = &tsk->signal->real_timer;
+
+ lockdep_assert_task_sighand_held(current);
+
+ if (!hrtimer_is_queued(tmr) && tsk->signal->it_real_incr != 0) {
+ hrtimer_forward_now(tmr, tsk->signal->it_real_incr);
+ hrtimer_restart(tmr);
+ }
+}
+
/*
* The timer is automagically restarted, when interval != 0
*/