Skip to contentSkip to conversation

ARM: local timers: Unmask interrupt before new TVAL is set

PATCH In review Rohit Vaswani 2 participants 3 messages Aug 10, 2012 – Aug 14, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 ARM: local timers: Unmask interrupt before new TVAL is set

Level triggered interrupt is deasserted when a new TVAL is written only when the interrupt is unmasked. Make sure that the interrupt is unmasked in CTL register before TVAL is written.
If this order is not followed, there are chances that on some hardware you would not receive any timer interrupts.

---
 arch/arm/kernel/arch_timer.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/arm/kernel/arch_timer.c +1 -1
index dd58035..1d0d9df 100644
@@ -126,8 +126,8 @@ static int arch_timer_set_next_event(unsigned long evt,
 	ctrl |= ARCH_TIMER_CTRL_ENABLE;
 	ctrl &= ~ARCH_TIMER_CTRL_IT_MASK;
 
-	arch_timer_reg_write(ARCH_TIMER_REG_TVAL, evt);
 	arch_timer_reg_write(ARCH_TIMER_REG_CTRL, ctrl);
+	arch_timer_reg_write(ARCH_TIMER_REG_TVAL, evt);
 
 	return 0;
 }
Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center,Inc
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
#1 lore raw

arch/arm/kernel/arch_timer.c static int arch_timer_set_next_event(unsigned long

Quoted 16 lines · Rohit Vaswani

Level triggered interrupt is deasserted when a new TVAL is written only when the interrupt is unmasked. Make sure that the interrupt is unmasked in CTL register before TVAL is written.
If this order is not followed, there are chances that on some hardware you would not receive any timer interrupts.

---
 arch/arm/kernel/arch_timer.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/arm/kernel/arch_timer.c +0 -0
index dd58035..1d0d9df 100644
@@ -126,8 +126,8 @@ static int arch_timer_set_next_event(unsigned long

evt,

arch/arm/kernel/arch_timer.c static int arch_timer_set_next_event(unsigned long evt, · line 130

Quoted 6 lines
arch/arm/kernel/arch_timer.c +1 -1
 	ctrl |= ARCH_TIMER_CTRL_ENABLE;
 	ctrl &= ~ARCH_TIMER_CTRL_IT_MASK;
 
-	arch_timer_reg_write(ARCH_TIMER_REG_TVAL, evt);
 	arch_timer_reg_write(ARCH_TIMER_REG_CTRL, ctrl);
+	arch_timer_reg_write(ARCH_TIMER_REG_TVAL, evt);

But by doing so, you're opening a window where TVAL can be negative (from a previous timer trigger) and the interrupt unmasked, which would lead to an immediate trigger, before TVAL is updated with the new value.

Does your hardware deassert the interrupt even when the enable bit is not set? If so, would the following sequence work?

        ctrl &= ~(ARCH_TIMER_CTRL_ENABLE | ARCH_TIMER_CTRL_IT_MASK);
        arch_timer_reg_write(ARCH_TIMER_REG_CTRL, ctrl);

	arch_timer_reg_write(ARCH_TIMER_REG_TVAL, evt);

        ctrl |= ARCH_TIMER_CTRL_ENABLE;
        arch_timer_reg_write(ARCH_TIMER_REG_CTRL, ctrl);

Thanks,

        M.
Signature · 1 line
Fast, cheap, reliable. Pick two.
#2 lore raw
Quoted 41 lines · Marc Zyngier

arch/arm/kernel/arch_timer.c static int arch_timer_set_next_event(unsigned long

Quoted 16 lines · Rohit Vaswani

Level triggered interrupt is deasserted when a new TVAL is written only when the interrupt is unmasked. Make sure that the interrupt is unmasked in CTL register before TVAL is written.
If this order is not followed, there are chances that on some hardware you would not receive any timer interrupts.

---
  arch/arm/kernel/arch_timer.c |    2 +-
  1 files changed, 1 insertions(+), 1 deletions(-)
arch/arm/kernel/arch_timer.c +0 -0
index dd58035..1d0d9df 100644
@@ -126,8 +126,8 @@ static int arch_timer_set_next_event(unsigned long

evt,

arch/arm/kernel/arch_timer.c static int arch_timer_set_next_event(unsigned long evt, · line 130

Quoted 6 lines
arch/arm/kernel/arch_timer.c +1 -1
  	ctrl |= ARCH_TIMER_CTRL_ENABLE;
  	ctrl &= ~ARCH_TIMER_CTRL_IT_MASK;
 
-	arch_timer_reg_write(ARCH_TIMER_REG_TVAL, evt);
  	arch_timer_reg_write(ARCH_TIMER_REG_CTRL, ctrl);
+	arch_timer_reg_write(ARCH_TIMER_REG_TVAL, evt);

But by doing so, you're opening a window where TVAL can be negative (from a previous timer trigger) and the interrupt unmasked, which would lead to an immediate trigger, before TVAL is updated with the new value.

Does your hardware deassert the interrupt even when the enable bit is not set? If so, would the following sequence work?

         ctrl &= ~(ARCH_TIMER_CTRL_ENABLE | ARCH_TIMER_CTRL_IT_MASK);
         arch_timer_reg_write(ARCH_TIMER_REG_CTRL, ctrl);

	arch_timer_reg_write(ARCH_TIMER_REG_TVAL, evt);

         ctrl |= ARCH_TIMER_CTRL_ENABLE;
         arch_timer_reg_write(ARCH_TIMER_REG_CTRL, ctrl);
Quoted 3 lines

Thanks,

         M.

Thanks Marc, this works. I will re-send the patch with these changes.

Thanks,
Rohit Vaswani

Signature · 2 lines
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.