Skip to contentSkip to conversation

arm_timer: reload timer when enabled

PATCH Applied Rabin Vincent 2 participants 5 messages May 2, 2010 – May 21, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 arm_timer: reload timer when enabled

Reload the timer when TimerControl is written, if the timer is to be enabled. Otherwise, if an earlier write to TimerLoad was done while periodic mode was not set, s->delta may incorrectly still have the value of the maximum limit instead of the value written to TimerLoad.

This problem is evident on versatileap on current linux-next, which enables TIMER_CTRL_32BIT before writing to TimerLoad and then enabling periodic mode and starting the timer. This causes the first periodic tick to be scheduled to occur after 0xffffffff periods, leading to a perceived hang while the kernel waits for the first timer tick.

---
 hw/arm_timer.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
hw/arm_timer.c +1 -1
index 9fef191..5b6947a 100644
@@ -113,7 +113,7 @@ static void arm_timer_write(void *opaque, target_phys_addr_t offset,
         case 1: freq >>= 4; break;
         case 2: freq >>= 8; break;
         }
-        arm_timer_recalibrate(s, 0);
+        arm_timer_recalibrate(s, s->control & TIMER_CTRL_ENABLE);
         ptimer_set_freq(s->timer, freq);
         if (s->control & TIMER_CTRL_ENABLE) {
             /* Restart the timer if still enabled.  */
Signature · 1 line
1.7.0.4
#1 lore raw

PATCH 2/2 arm_timer: fix oneshot mode

In oneshot mode, the delta needs to come from the TimerLoad register, not the maximum limit.

---
 hw/arm_timer.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
hw/arm_timer.c +1 -1
index 5b6947a..9073ffc 100644
@@ -71,7 +71,7 @@ static void arm_timer_recalibrate(arm_timer_state *s, int reload)
 {
     uint32_t limit;
 
-    if ((s->control & TIMER_CTRL_PERIODIC) == 0) {
+    if ((s->control & (TIMER_CTRL_PERIODIC | TIMER_CTRL_ONESHOT)) == 0) {
         /* Free running.  */
         if (s->control & TIMER_CTRL_32BIT)
             limit = 0xffffffff;
Signature · 1 line
1.7.0.4
#2 lore raw

Re: [Qemu-devel] [PATCH 2/2] arm_timer: fix oneshot mode

Quoted 4 lines · Rabin Vincent

In oneshot mode, the delta needs to come from the TimerLoad register, not the maximum limit.

Thanks, applied.

Quoted 23 lines
---
 hw/arm_timer.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
hw/arm_timer.c +1 -1
index 5b6947a..9073ffc 100644
@@ -71,7 +71,7 @@ static void arm_timer_recalibrate(arm_timer_state *s, int reload)
 {
     uint32_t limit;
 
-    if ((s->control & TIMER_CTRL_PERIODIC) == 0) {
+    if ((s->control & (TIMER_CTRL_PERIODIC | TIMER_CTRL_ONESHOT)) == 0) {
         /* Free running.  */
         if (s->control & TIMER_CTRL_32BIT)
             limit = 0xffffffff;
Signature · 1 line
1.7.0.4
Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#3 lore raw
In reply to Rabin Vincent
Quoted 5 lines · Rabin Vincent

Reload the timer when TimerControl is written, if the timer is to be enabled. Otherwise, if an earlier write to TimerLoad was done while periodic mode was not set, s->delta may incorrectly still have the value of the maximum limit instead of the value written to TimerLoad.

Quoted 7 lines

This problem is evident on versatileap on current linux-next, which enables TIMER_CTRL_32BIT before writing to TimerLoad and then enabling periodic mode and starting the timer. This causes the first periodic tick to be scheduled to occur after 0xffffffff periods, leading to a perceived hang while the kernel waits for the first timer tick.

Could these patches please be applied? What was then linux-next is now current Linux mainline, and it doesn't boot without this patch.

Rabin

#4 lore raw
In reply to Rabin Vincent
Quoted 5 lines · Rabin Vincent

Reload the timer when TimerControl is written, if the timer is to be enabled. Otherwise, if an earlier write to TimerLoad was done while periodic mode was not set, s->delta may incorrectly still have the value of the maximum limit instead of the value written to TimerLoad.

Quoted 7 lines

This problem is evident on versatileap on current linux-next, which enables TIMER_CTRL_32BIT before writing to TimerLoad and then enabling periodic mode and starting the timer. This causes the first periodic tick to be scheduled to occur after 0xffffffff periods, leading to a perceived hang while the kernel waits for the first timer tick.

Thanks, applied.

Quoted 23 lines
---
 hw/arm_timer.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
hw/arm_timer.c +1 -1
index 9fef191..5b6947a 100644
@@ -113,7 +113,7 @@ static void arm_timer_write(void *opaque, target_phys_addr_t offset,
         case 1: freq >>= 4; break;
         case 2: freq >>= 8; break;
         }
-        arm_timer_recalibrate(s, 0);
+        arm_timer_recalibrate(s, s->control & TIMER_CTRL_ENABLE);
         ptimer_set_freq(s->timer, freq);
         if (s->control & TIMER_CTRL_ENABLE) {
             /* Restart the timer if still enabled.  */
Signature · 1 line
1.7.0.4
Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net