Skip to content

Commit bd29d77

Browse files
KAGA-KOKOFrederic Weisbecker
authored andcommitted
posix-cpu-timers: Do not arm SIGEV_NONE timers
There is no point in arming SIGEV_NONE timers as they never deliver a signal. timer_gettime() is handling the expiry time correctly and that's all SIGEV_NONE timers care about. Prevent arming them and remove the expiry handler code which just disarms them. Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: Frederic Weisbecker <[email protected]> Reviewed-by: Anna-Maria Behnsen <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]>
1 parent d471ff3 commit bd29d77

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

kernel/time/posix-cpu-timers.c

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -584,12 +584,7 @@ static void cpu_timer_fire(struct k_itimer *timer)
584584
{
585585
struct cpu_timer *ctmr = &timer->it.cpu;
586586

587-
if ((timer->it_sigev_notify & ~SIGEV_THREAD_ID) == SIGEV_NONE) {
588-
/*
589-
* User don't want any signal.
590-
*/
591-
cpu_timer_setexpires(ctmr, 0);
592-
} else if (unlikely(timer->sigq == NULL)) {
587+
if (unlikely(timer->sigq == NULL)) {
593588
/*
594589
* This a special case for clock_nanosleep,
595590
* not a normal timer from sys_timer_create.
@@ -625,6 +620,7 @@ static void __posix_cpu_timer_get(struct k_itimer *timer, struct itimerspec64 *i
625620
static int posix_cpu_timer_set(struct k_itimer *timer, int timer_flags,
626621
struct itimerspec64 *new, struct itimerspec64 *old)
627622
{
623+
bool sigev_none = timer->it_sigev_notify == SIGEV_NONE;
628624
clockid_t clkid = CPUCLOCK_WHICH(timer->it_clock);
629625
u64 old_expires, new_expires, old_incr, val;
630626
struct cpu_timer *ctmr = &timer->it.cpu;
@@ -688,7 +684,7 @@ static int posix_cpu_timer_set(struct k_itimer *timer, int timer_flags,
688684
if (CPUCLOCK_PERTHREAD(timer->it_clock))
689685
val = cpu_clock_sample(clkid, p);
690686
else
691-
val = cpu_clock_sample_group(clkid, p, true);
687+
val = cpu_clock_sample_group(clkid, p, !sigev_none);
692688

693689
/* Retrieve the previous expiry value if requested. */
694690
if (old) {
@@ -708,19 +704,20 @@ static int posix_cpu_timer_set(struct k_itimer *timer, int timer_flags,
708704
goto out;
709705
}
710706

711-
if (new_expires != 0 && !(timer_flags & TIMER_ABSTIME)) {
707+
/* Convert relative expiry time to absolute */
708+
if (new_expires && !(timer_flags & TIMER_ABSTIME))
712709
new_expires += val;
713-
}
710+
711+
/* Set the new expiry time (might be 0) */
712+
cpu_timer_setexpires(ctmr, new_expires);
714713

715714
/*
716-
* Install the new expiry time (or zero).
717-
* For a timer with no notification action, we don't actually
718-
* arm the timer (we'll just fake it for timer_gettime).
715+
* Arm the timer if it is not disabled, the new expiry value has
716+
* not yet expired and the timer requires signal delivery.
717+
* SIGEV_NONE timers are never armed.
719718
*/
720-
cpu_timer_setexpires(ctmr, new_expires);
721-
if (new_expires != 0 && val < new_expires) {
719+
if (!sigev_none && new_expires && val < new_expires)
722720
arm_timer(timer, p);
723-
}
724721

725722
unlock_task_sighand(p, &flags);
726723
/*
@@ -739,7 +736,7 @@ static int posix_cpu_timer_set(struct k_itimer *timer, int timer_flags,
739736
timer->it_overrun_last = 0;
740737
timer->it_overrun = -1;
741738

742-
if (val >= new_expires) {
739+
if (!sigev_none && val >= new_expires) {
743740
if (new_expires != 0) {
744741
/*
745742
* The designated time already passed, so we notify

0 commit comments

Comments
 (0)