From bc6f11b730a8a4dfc46b547bdfbf6dd872c99dcd Mon Sep 17 00:00:00 2001 From: Wayne Ren Date: Thu, 21 May 2020 10:30:18 +0800 Subject: [PATCH] drivers: arcv2_timer0: minor fix and optimization for SMP case * still need to clear IP bit in timer irq handler * last_time should be aligned to ticks, old code will miss some cycles which are about (curret_time - last_time) % CYC_PER_TICK * in timeout set, shorten the delay needed when tick is 0, this will improve the response of timer irq Signed-off-by: Wayne Ren --- drivers/timer/arcv2_timer0.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/timer/arcv2_timer0.c b/drivers/timer/arcv2_timer0.c index d63f70be808..21325280ef7 100644 --- a/drivers/timer/arcv2_timer0.c +++ b/drivers/timer/arcv2_timer0.c @@ -228,12 +228,16 @@ static void timer_int_handler(void *unused) u64_t curr_time; k_spinlock_key_t key; + /* clear the IP bit of the control register */ + timer0_control_register_set(_ARC_V2_TMR_CTRL_NH | + _ARC_V2_TMR_CTRL_IE); key = k_spin_lock(&lock); /* gfrc is the wall clock */ curr_time = z_arc_connect_gfrc_read(); dticks = (curr_time - last_time) / CYC_PER_TICK; - last_time = curr_time; + /* last_time should be aligned to ticks */ + last_time += dticks * CYC_PER_TICK; k_spin_unlock(&lock, key); @@ -335,8 +339,12 @@ void z_clock_set_timeout(s32_t ticks, bool idle) ticks = MIN(MAX_TICKS, ticks); - /* Desired delay in the future */ - delay = MAX(CYC_PER_TICK, ticks * CYC_PER_TICK); + /* Desired delay in the future + * use MIN_DEALY here can trigger the timer + * irq more soon, no need to go to CYC_PER_TICK + * later. + */ + delay = MAX(ticks * CYC_PER_TICK, MIN_DELAY); key = arch_irq_lock();