arm64: timer: Speed up gic-timer-state check
PATCH 1/1 arm64: timer: Speed up gic-timer-state check
Let's bail out of the wait loop if we see the expected state to save about seven seconds of run time. Make sure we wait a bit before reading the registers, though, to somewhat mitigate the chance of the expected state being stale.
--- arm/timer.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
arm/timer.c +10 -7
@@ -183,7 +183,8 @@ static bool timer_pending(struct timer_info *info) (info->read_ctl () &ARCH_TIMER_CTL_ISTATUS ); } -static enum gic_state gic_timer_state (struct timer_info *info) +static bool gic_timer_check_state (struct timer_info *info, +enum gic_state expected_state) {enum gic_state state =GIC_STATE_INACTIVE ;int i;
@@ -191,6 +192,7 @@ static enum gic_state gic_timer_state(struct timer_info *info)/* Wait for up to 1s for the GIC to sample the interrupt. */ for (i =0 ; i <10 ; i++) { +mdelay (100 ); pending =readl (gic_ispendr) & (1 <<PPI (info->irq)); active =readl (gic_isactiver) & (1 <<PPI (info->irq));if (!active && !pending)
@@ -201,10 +203,11 @@ static enum gic_state gic_timer_state(struct timer_info *info) state =GIC_STATE_ACTIVE ;if (active && pending) state =GIC_STATE_ACTIVE_PENDING ; -mdelay (100 ); +if (state == expected_state) +return true; } -return state; +return false; }static bool test_cval_10msec (struct timer_info *info)
@@ -253,11 +256,11 @@ static void test_timer(struct timer_info *info)/* Enable the timer, but schedule it for much later */ info->write_cval (later); info->write_ctl (ARCH_TIMER_CTL_ENABLE ); -report (!timer_pending (info) &&gic_timer_state (info) ==GIC_STATE_INACTIVE , +report (!timer_pending (info) &&gic_timer_check_state (info,GIC_STATE_INACTIVE ),"not pending before" ); info->write_cval (now -1 ); -report (timer_pending (info) &&gic_timer_state (info) ==GIC_STATE_PENDING , +report (timer_pending (info) &&gic_timer_check_state (info,GIC_STATE_PENDING ),"interrupt signal pending" );/* Disable the timer again and prepare to take interrupts */
@@ -265,12 +268,12 @@ static void test_timer(struct timer_info *info) info->irq_received = false;set_timer_irq_enabled (info, true);report (!info->irq_received,"no interrupt when timer is disabled" ); -report (!timer_pending (info) &&gic_timer_state (info) ==GIC_STATE_INACTIVE , +report (!timer_pending (info) &&gic_timer_check_state (info,GIC_STATE_INACTIVE ),"interrupt signal no longer pending" ); info->write_cval (now -1 ); info->write_ctl (ARCH_TIMER_CTL_ENABLE |ARCH_TIMER_CTL_IMASK ); -report (timer_pending (info) &&gic_timer_state (info) ==GIC_STATE_INACTIVE , +report (timer_pending (info) &&gic_timer_check_state (info,GIC_STATE_INACTIVE ),"interrupt signal not pending" );report (test_cval_10msec (info),"latency within 10 ms" );
Signature · 1 line
2.21.1
Hi,
Quoted 34 lines · Andrew Jones
Let's bail out of the wait loop if we see the expected state to save about seven seconds of run time. Make sure we wait a bit before reading the registers, though, to somewhat mitigate the chance of the expected state being stale.
Signed-off-by Andrew Jones <[email protected]>--- arm/timer.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)arm/timer.c +3
-1@@ -183,7 +183,8 @@ static bool timer_pending(struct timer_info *info) (info->read_ctl () &ARCH_TIMER_CTL_ISTATUS ); } -static enum gic_state gic_timer_state (struct timer_info *info) +static bool gic_timer_check_state (struct timer_info *info, +enum gic_state expected_state) {enum gic_state state =GIC_STATE_INACTIVE ;int i;@@ -191,6 +192,7 @@ static enum gic_state gic_timer_state(struct timer_info *info)/* Wait for up to 1s for the GIC to sample the interrupt. */ for (i =0 ; i <10 ; i++) { +mdelay (100 ); pending =readl (gic_ispendr) & (1 <<PPI (info->irq)); active =readl (gic_isactiver) & (1 <<PPI (info->irq));if (!active && !pending)@@ -201,10 +203,11 @@ static enum gic_state gic_timer_state(struct timer_info *info) state =GIC_STATE_ACTIVE ;
arm/timer.c static enum gic_state gic_timer_state(struct timer_info *info) · line 211
Quoted 10 lines
arm/timer.c +3
-2if (active && pending) state =GIC_STATE_ACTIVE_PENDING ; -mdelay (100 ); +if (state == expected_state) +return true; } -return state; +return false; }
The first version I wrote looked similar. However I decided to wait the entire 1s because I could imagine a situation where the interrupt was pending, but if I were to wait a bit longer, it would have become active and pending, which is not what we would want. Same thing with inactive.
How about after the state matches what we expect, we wait for an extra 100ms and check that the state hasn't changed?
Also, you probably also want to lower the timeout in arm/unittests.cfg.
Thanks,
Alex
Quoted 31 lines
arm/timer.c +4
-4static bool test_cval_10msec (struct timer_info *info)@@ -253,11 +256,11 @@ static void test_timer(struct timer_info *info)/* Enable the timer, but schedule it for much later */ info->write_cval (later); info->write_ctl (ARCH_TIMER_CTL_ENABLE ); -report (!timer_pending (info) &&gic_timer_state (info) ==GIC_STATE_INACTIVE , +report (!timer_pending (info) &&gic_timer_check_state (info,GIC_STATE_INACTIVE ),"not pending before" ); info->write_cval (now -1 ); -report (timer_pending (info) &&gic_timer_state (info) ==GIC_STATE_PENDING , +report (timer_pending (info) &&gic_timer_check_state (info,GIC_STATE_PENDING ),"interrupt signal pending" );/* Disable the timer again and prepare to take interrupts */ @@ -265,12 +268,12 @@ static void test_timer(struct timer_info *info) info->irq_received = false;set_timer_irq_enabled (info, true);report (!info->irq_received,"no interrupt when timer is disabled" ); -report (!timer_pending (info) &&gic_timer_state (info) ==GIC_STATE_INACTIVE , +report (!timer_pending (info) &&gic_timer_check_state (info,GIC_STATE_INACTIVE ),"interrupt signal no longer pending" ); info->write_cval (now -1 ); info->write_ctl (ARCH_TIMER_CTL_ENABLE |ARCH_TIMER_CTL_IMASK ); -report (timer_pending (info) &&gic_timer_state (info) ==GIC_STATE_INACTIVE , +report (timer_pending (info) &&gic_timer_check_state (info,GIC_STATE_INACTIVE ),"interrupt signal not pending" );report (test_cval_10msec (info),"latency within 10 ms" );
Quoted 53 lines · Alexandru Elisei
Hi,
Quoted 34 lines · Andrew Jones
Let's bail out of the wait loop if we see the expected state to save about seven seconds of run time. Make sure we wait a bit before reading the registers, though, to somewhat mitigate the chance of the expected state being stale.
Signed-off-by Andrew Jones <[email protected]>--- arm/timer.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)arm/timer.c +3
-1@@ -183,7 +183,8 @@ static bool timer_pending(struct timer_info *info) (info->read_ctl () &ARCH_TIMER_CTL_ISTATUS ); } -static enum gic_state gic_timer_state (struct timer_info *info) +static bool gic_timer_check_state (struct timer_info *info, +enum gic_state expected_state) {enum gic_state state =GIC_STATE_INACTIVE ;int i;@@ -191,6 +192,7 @@ static enum gic_state gic_timer_state(struct timer_info *info)/* Wait for up to 1s for the GIC to sample the interrupt. */ for (i =0 ; i <10 ; i++) { +mdelay (100 ); pending =readl (gic_ispendr) & (1 <<PPI (info->irq)); active =readl (gic_isactiver) & (1 <<PPI (info->irq));if (!active && !pending)@@ -201,10 +203,11 @@ static enum gic_state gic_timer_state(struct timer_info *info) state =GIC_STATE_ACTIVE ;arm/timer.c static enum gic_state gic_timer_state(struct timer_info *info) · line 211
Quoted 10 lines
arm/timer.c +3
-2if (active && pending) state =GIC_STATE_ACTIVE_PENDING ; -mdelay (100 ); +if (state == expected_state) +return true; } -return state; +return false; }The first version I wrote looked similar. However I decided to wait the entire 1s because I could imagine a situation where the interrupt was pending, but if I were to wait a bit longer, it would have become active and pending, which is not what we would want. Same thing with inactive.
Quoted 2 lines
How about after the state matches what we expect, we wait for an extra 100ms and check that the state hasn't changed?
That sounds good. I'll send a v2 with that.
Quoted 2 lines
Also, you probably also want to lower the timeout in arm/unittests.cfg.
The timeout is fine, because if we need to loop the worst-case scenario amount of time then we want the timeout high enough. It's not really a goal to make the timeout just barely long enough to cover the test anyway. If the timeout is too long, and we need it to fire, then it just means test runners will have to wait longer for it.
Thanks,
drew
Quoted 35 lines
Thanks,
AlexQuoted 31 lines
arm/timer.c +4
-4static bool test_cval_10msec (struct timer_info *info)@@ -253,11 +256,11 @@ static void test_timer(struct timer_info *info)/* Enable the timer, but schedule it for much later */ info->write_cval (later); info->write_ctl (ARCH_TIMER_CTL_ENABLE ); -report (!timer_pending (info) &&gic_timer_state (info) ==GIC_STATE_INACTIVE , +report (!timer_pending (info) &&gic_timer_check_state (info,GIC_STATE_INACTIVE ),"not pending before" ); info->write_cval (now -1 ); -report (timer_pending (info) &&gic_timer_state (info) ==GIC_STATE_PENDING , +report (timer_pending (info) &&gic_timer_check_state (info,GIC_STATE_PENDING ),"interrupt signal pending" );/* Disable the timer again and prepare to take interrupts */ @@ -265,12 +268,12 @@ static void test_timer(struct timer_info *info) info->irq_received = false;set_timer_irq_enabled (info, true);report (!info->irq_received,"no interrupt when timer is disabled" ); -report (!timer_pending (info) &&gic_timer_state (info) ==GIC_STATE_INACTIVE , +report (!timer_pending (info) &&gic_timer_check_state (info,GIC_STATE_INACTIVE ),"interrupt signal no longer pending" ); info->write_cval (now -1 ); info->write_ctl (ARCH_TIMER_CTL_ENABLE |ARCH_TIMER_CTL_IMASK ); -report (timer_pending (info) &&gic_timer_state (info) ==GIC_STATE_INACTIVE , +report (timer_pending (info) &&gic_timer_check_state (info,GIC_STATE_INACTIVE ),"interrupt signal not pending" );report (test_cval_10msec (info),"latency within 10 ms" );