Skip to content

Commit

Permalink
posix-cpu-timers: Consolidate timer base accessor
Browse files Browse the repository at this point in the history
Remove the ad-hoc timer base accessors and provide a consolidated one.

Signed-off-by: Frederic Weisbecker <[email protected]>
Signed-off-by: Thomas Gleixner <[email protected]>
Acked-by: Peter Zijlstra (Intel) <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
  • Loading branch information
Frederic Weisbecker authored and KAGA-KOKO committed Aug 10, 2021
1 parent d9c1b2a commit 5c8f23e
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions kernel/time/posix-cpu-timers.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,17 @@ static int posix_cpu_timer_create(struct k_itimer *new_timer)
return 0;
}

static struct posix_cputimer_base *timer_base(struct k_itimer *timer,
struct task_struct *tsk)
{
int clkidx = CPUCLOCK_WHICH(timer->it_clock);

if (CPUCLOCK_PERTHREAD(timer->it_clock))
return tsk->posix_cputimers.bases + clkidx;
else
return tsk->signal->posix_cputimers.bases + clkidx;
}

/*
* Dequeue the timer and reset the base if it was its earliest expiration.
* It makes sure the next tick recalculates the base next expiration so we
Expand All @@ -421,18 +432,11 @@ static void disarm_timer(struct k_itimer *timer, struct task_struct *p)
{
struct cpu_timer *ctmr = &timer->it.cpu;
struct posix_cputimer_base *base;
int clkidx;

if (!cpu_timer_dequeue(ctmr))
return;

clkidx = CPUCLOCK_WHICH(timer->it_clock);

if (CPUCLOCK_PERTHREAD(timer->it_clock))
base = p->posix_cputimers.bases + clkidx;
else
base = p->signal->posix_cputimers.bases + clkidx;

base = timer_base(timer, p);
if (cpu_timer_getexpires(ctmr) == base->nextevt)
base->nextevt = 0;
}
Expand Down Expand Up @@ -531,15 +535,9 @@ void posix_cpu_timers_exit_group(struct task_struct *tsk)
*/
static void arm_timer(struct k_itimer *timer, struct task_struct *p)
{
int clkidx = CPUCLOCK_WHICH(timer->it_clock);
struct posix_cputimer_base *base = timer_base(timer, p);
struct cpu_timer *ctmr = &timer->it.cpu;
u64 newexp = cpu_timer_getexpires(ctmr);
struct posix_cputimer_base *base;

if (CPUCLOCK_PERTHREAD(timer->it_clock))
base = p->posix_cputimers.bases + clkidx;
else
base = p->signal->posix_cputimers.bases + clkidx;

if (!cpu_timer_enqueue(&base->tqhead, ctmr))
return;
Expand Down

0 comments on commit 5c8f23e

Please sign in to comment.