Messages in this thread Patch in this message | | | From | Thomas Gleixner <> | Subject | [patch 14/45] posix-timers: Consolidate interval retrieval | Date | Tue, 6 Jun 2023 16:37:40 +0200 (CEST) |
| |
There is no point to collect the current interval in the posix clock specific settime() and gettime() callbacks. Just do it right in the common code.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de> --- kernel/time/posix-cpu-timers.c | 26 ++++++++------------------ kernel/time/posix-timers.c | 18 +++++++++--------- 2 files changed, 17 insertions(+), 27 deletions(-)
--- a/kernel/time/posix-cpu-timers.c +++ b/kernel/time/posix-cpu-timers.c @@ -622,8 +622,8 @@ static int posix_cpu_timer_set(struct k_ { bool sigev_none = timer->it_sigev_notify == SIGEV_NONE; clockid_t clkid = CPUCLOCK_WHICH(timer->it_clock); - u64 old_expires, new_expires, old_incr, now; struct cpu_timer *ctmr = &timer->it.cpu; + u64 old_expires, new_expires, now; struct sighand_struct *sighand; struct task_struct *p; unsigned long flags; @@ -660,10 +660,7 @@ static int posix_cpu_timer_set(struct k_ return -ESRCH; } - /* - * Disarm any old timer after extracting its expiry time. - */ - old_incr = timer->it_interval; + /* Retrieve the current expiry time before disarming the timer */ old_expires = cpu_timer_getexpires(ctmr); if (unlikely(timer->it.cpu.firing)) { @@ -737,9 +734,6 @@ static int posix_cpu_timer_set(struct k_ cpu_timer_fire(timer); out: rcu_read_unlock(); - if (old) - old->it_interval = ns_to_timespec64(old_incr); - return ret; } @@ -785,17 +779,13 @@ static void posix_cpu_timer_get(struct k rcu_read_lock(); p = cpu_timer_task_rcu(timer); - if (p) { - itp->it_interval = ktime_to_timespec64(timer->it_interval); - - if (cpu_timer_getexpires(ctmr)) { - if (CPUCLOCK_PERTHREAD(timer->it_clock)) - now = cpu_clock_sample(clkid, p); - else - now = cpu_clock_sample_group(clkid, p, false); + if (p && cpu_timer_getexpires(ctmr)) { + if (CPUCLOCK_PERTHREAD(timer->it_clock)) + now = cpu_clock_sample(clkid, p); + else + now = cpu_clock_sample_group(clkid, p, false); - __posix_cpu_timer_get(timer, itp, now); - } + __posix_cpu_timer_get(timer, itp, now); } rcu_read_unlock(); } --- a/kernel/time/posix-timers.c +++ b/kernel/time/posix-timers.c @@ -636,17 +636,12 @@ static s64 common_hrtimer_forward(struct */ void common_timer_get(struct k_itimer *timr, struct itimerspec64 *cur_setting) { + bool sig_none = timr->it_sigev_notify == SIGEV_NONE; const struct k_clock *kc = timr->kclock; - ktime_t now, remaining, iv; - bool sig_none; + bool iv = !!timr->it_interval; + ktime_t now, remaining; - sig_none = timr->it_sigev_notify == SIGEV_NONE; - iv = timr->it_interval; - - /* interval timer ? */ - if (iv) { - cur_setting->it_interval = ktime_to_timespec64(iv); - } else if (!timr->it_active) { + if (!iv && !timr->it_active) { /* * SIGEV_NONE oneshot timers are never queued and therefore * timr->it_active is always false. The check below @@ -705,6 +700,8 @@ static int do_timer_gettime(timer_t time return -EINVAL; memset(setting, 0, sizeof(*setting)); + setting->it_interval = ktime_to_timespec64(timr->it_interval); + kc = timr->kclock; if (WARN_ON_ONCE(!kc || !kc->timer_get)) ret = -EINVAL; @@ -918,6 +915,9 @@ static int do_timer_settime(timer_t time if (!timr) return -EINVAL; + if (old_spec64) + old_spec64->it_interval = ktime_to_timespec64(timr->it_interval); + kc = timr->kclock; if (WARN_ON_ONCE(!kc || !kc->timer_set)) error = -EINVAL;
| |