Skip to contentSkip to conversation

arm_mptimer fixes

Qemu-devel New Dmitry Osipenko 3 participants 30 messages Jul 2, 2015 – Jul 6, 2015

lore
Share & tools
lore
#0 lore raw

Hello, this series fixes 3 arm_mptimer issues. All 3 patches were successfully tested on ARM Cortex-A9 QEMU machine booting Linux kernel and behavior was compared to real hw by running couple handcrafted mptimer tests.

arm_mptimer: Fix timer shutdown
arm_mptimer: Fix ONE-SHOT -> PERIODIC mode change
arm_mptimer: Respect IT bit state

#1 lore raw

PATCH v3 1/3 arm_mptimer: Fix timer shutdown

Timer, running in periodic mode, can't be stopped or coming one-shot tick won't be canceled because timer control code just doesn't handle timer disabling. Fix it by deleting timer if enable bit isn't set.

---

v2: Avoid calling timer_del() if the timer was already disabled as per
Peter Maydell suggestion.

v3: Do not change "reload the timer" logic as it is separate bug.

 hw/timer/arm_mptimer.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
hw/timer/arm_mptimer.c +7 -1
index 8b93b3c..e230063 100644
@@ -122,11 +122,17 @@ static void timerblock_write(void *opaque, hwaddr addr,
     case 8: /* Control.  */
         old = tb->control;
         tb->control = value;
-        if (((old & 1) == 0) && (value & 1)) {
+        if ((old & 1) == (value & 1)) {
+            break;
+        }
+        if (value & 1) {
             if (tb->count == 0 && (tb->control & 2)) {
                 tb->count = tb->load;
             }
             timerblock_reload(tb, 1);
+        } else {
+            /* Shutdown timer.  */
+            timer_del(tb->timer);
         }
         break;
     case 12: /* Interrupt status.  */
Signature · 1 line
2.4.4
#2 lore raw

PATCH 2/3 arm_mptimer: Fix ONE-SHOT -> PERIODIC mode change

In reply to Dmitry Osipenko

Timer won't start periodic ticking if ONE-SHOT -> PERIODIC mode change happened after one-shot tick was completed. Fix it by starting ticking only if timer was disabled previously and isn't ticking right now.

---
 hw/timer/arm_mptimer.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
hw/timer/arm_mptimer.c +7 -2
index e230063..58e17c4 100644
@@ -122,11 +122,16 @@ static void timerblock_write(void *opaque, hwaddr addr,
     case 8: /* Control.  */
         old = tb->control;
         tb->control = value;
-        if ((old & 1) == (value & 1)) {
+        /* Don't do anything if timer already disabled.  */
+        if (((old & 1) == 0) && ((value & 1) == 0)) {
             break;
         }
         if (value & 1) {
-            if (tb->count == 0 && (tb->control & 2)) {
+            /* Don't do anything if timer already ticking.  */
+            if (((old & 1) != 0) && (tb->count != 0)) {
+                break;
+            }
+            if (tb->control & 2) {
                 tb->count = tb->load;
             }
             timerblock_reload(tb, 1);
Signature · 1 line
2.4.4
#3 lore raw

Re: [Qemu-devel] [PATCH 2/3] arm_mptimer: Fix ONE-SHOT -> PERIODIC mode change

Quoted 14 lines · Dmitry Osipenko

Timer won't start periodic ticking if ONE-SHOT -> PERIODIC mode change happened after one-shot tick was completed. Fix it by starting ticking only if timer was disabled previously and isn't ticking right now.

---
 hw/timer/arm_mptimer.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
hw/timer/arm_mptimer.c +0 -0
index e230063..58e17c4 100644

hw/timer/arm_mptimer.c static void timerblock_write(void *opaque, hwaddr addr, · line 126

Quoted 6 lines
hw/timer/arm_mptimer.c +2 -1
@@ -122,11 +122,16 @@ static void timerblock_write(void *opaque, hwaddr addr,
     case 8: /* Control.  */
         old = tb->control;
         tb->control = value;
-        if ((old & 1) == (value & 1)) {
+        /* Don't do anything if timer already disabled.  */
+        if (((old & 1) == 0) && ((value & 1) == 0)) {

Your do-nothing code paths are now inconsistent between the 0 and 1 cases. I think this if can be consolidated with:

if (value & 1) {
    if ((old & 1) && (tb->count != 0)) {
        break;
    }
    if (tb->control & 2) {
        ...
    }
    tb_reload();
} else if (old & 1) {
    timer_del();
}

break;

I think it's ok to squash patches 1 and 2. and just make a note in the commit message of the multiple issues. It's hard to split this without churning.

hw/timer/arm_mptimer.c static void timerblock_write(void *opaque, hwaddr addr, · line 134

Quoted 9 lines
hw/timer/arm_mptimer.c +5 -1
             break;
         }
         if (value & 1) {
-            if (tb->count == 0 && (tb->control & 2)) {
+            /* Don't do anything if timer already ticking.  */
+            if (((old & 1) != 0) && (tb->count != 0)) {
+                break;
+            }
+            if (tb->control & 2) {

You have dropped the tb->count == 0 which looks like another bugfix again. It looks like you are making sure the load value is loaded regardless of timer run-state. If this is correct it just needs a note in commit message.

Regards,
Peter

Quoted 7 lines
hw/timer/arm_mptimer.c +0 -1
                 tb->count = tb->load;
             }
             timerblock_reload(tb, 1);
--

2.4.4

#4 lore raw

Re: [Qemu-devel] [PATCH 2/3] arm_mptimer: Fix ONE-SHOT -> PERIODIC mode change

04.07.2015 22:36, Peter Crosthwaite пишет:

Quoted 15 lines

Your do-nothing code paths are now inconsistent between the 0 and 1 cases. I think this if can be consolidated with:

if (value & 1) {
     if ((old & 1) && (tb->count != 0)) {
         break;
     }
     if (tb->control & 2) {
         ...
     }
     tb_reload();
} else if (old & 1) {
     timer_del();
}
Quoted 2 lines

break;

Code, you are suggesting, is logically equal to my patch. Your variant looks cleaner, I'll switch to it. Thanks.

Quoted 5 lines

You have dropped the tb->count == 0 which looks like another bugfix again. It looks like you are making sure the load value is loaded regardless of timer run-state. If this is correct it just needs a note in commit message.

Sorry, I don't see where tb->count == 0 got dropped. I think you missed that timerblock_reload() checks for tb->count == 0.

To clarify:

Timer is stopped in two cases:
1) timer was shutdown; (old & 1) == 0, tb->count may be unequal to 0 (if timer was shutdown while it was ticking).
2) one-shot was completed; (old & 1) == 1, tb->count = 0

On timer enabling we don't need to do anything if either one-shot or periodic count is currently in fly, because timerblock_tick() would correctly handle mode change, otherwise we re-load tb->count in case of periodic mode or starting with whatever(left after periodic shutdown or after loading 'count' via load register) tb->count in case of one-shot.

BTW, timer pausing is not implemented and timer can be in two states only: running and stopped. This leads to opportunity to convert arm_mptimer to use ptimer, I'd like to do it after fixing current issues.

Quoted 4 lines

I think it's ok to squash patches 1 and 2. and just make a note in the commit message of the multiple issues. It's hard to split this without churning.

Well... yeah, it may worth squashing them. I'll do it.

Thanks for review.

Signature · 1 line
Dmitry
#5 lore raw

PATCH 3/3 arm_mptimer: Respect IT bit state

In reply to Dmitry Osipenko

Timer fires interrupt regardless of current IT(interrupt enable) bit state. Fix it by making timer to respect IT state.

---
 hw/timer/arm_mptimer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/timer/arm_mptimer.c +1 -1
index 58e17c4..82c4462 100644
@@ -38,7 +38,7 @@ static inline int get_current_cpu(ARMMPTimerState *s)
 
 static inline void timerblock_update_irq(TimerBlock *tb)
 {
-    qemu_set_irq(tb->irq, tb->status);
+    qemu_set_irq(tb->irq, tb->status && (tb->control & 4));
 }
 
 /* Return conversion factor from mpcore timer ticks to qemu timer ticks.  */
Signature · 1 line
2.4.4
#6 lore raw

Re: [Qemu-devel] [PATCH 3/3] arm_mptimer: Respect IT bit state

Quoted 13 lines · Dmitry Osipenko

Timer fires interrupt regardless of current IT(interrupt enable) bit state. Fix it by making timer to respect IT state.

---
 hw/timer/arm_mptimer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/timer/arm_mptimer.c +0 -0
index 58e17c4..82c4462 100644

hw/timer/arm_mptimer.c static inline int get_current_cpu(ARMMPTimerState *s) · line 41

Quoted 5 lines
hw/timer/arm_mptimer.c +1 -1
@@ -38,7 +38,7 @@ static inline int get_current_cpu(ARMMPTimerState *s)
 
 static inline void timerblock_update_irq(TimerBlock *tb)
 {
-    qemu_set_irq(tb->irq, tb->status);
+    qemu_set_irq(tb->irq, tb->status && (tb->control & 4));

You also need to trigger timerblock_update_irq on change of state for the control bit itself. "case 8: /* Control. */" in the _write handler needs to call this fn.

Regards,
Peter

Quoted 7 lines
hw/timer/arm_mptimer.c +0 -1
 }
 
 /* Return conversion factor from mpcore timer ticks to qemu timer ticks.  */
--

2.4.4

#7 lore raw

Re: [Qemu-devel] [PATCH 3/3] arm_mptimer: Respect IT bit state

Hello Peter,

04.07.2015 22:39, Peter Crosthwaite пишет:

Quoted 5 lines

You also need to trigger timerblock_update_irq on change of state for the control bit itself. "case 8: /* Control. */" in the _write handler needs to call this fn.

Right, as it will mask/unmask interrupt line. Good catch, thanks.

Signature · 1 line
Dmitry
#8 lore raw

PATCH v2 1/1 arm_mptimer fixes

In reply to Dmitry Osipenko

Hello, this is V2 of arm_mptimer patch series. Comments and suggestion from V1 has been addressed and the series was re-tested, including new test for IT bit masking/unmasking.

[PATCH 1/2] arm_mptimer: Fix timer shutdown and mode change [PATCH v2 2/2] arm_mptimer: Respect IT bit state

#9 lore raw

PATCH v3 1/2 arm_mptimer: Fix timer shutdown and mode change

Timer, running in periodic mode, can't be stopped or coming one-shot tick won't be canceled because timer control code just doesn't handle timer disabling. Fix it by deleting the timer if enable bit isn't set.

Timer won't start periodic ticking if ONE-SHOT -> PERIODIC mode change happened after one-shot tick was completed. Fix it by starting ticking only if the timer isn't ticking right now.

To avoid code churning, these two fixes are squashed in one commit.

---

Commits are squashed as per Peter Crosthwaite suggestion.

 hw/timer/arm_mptimer.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
hw/timer/arm_mptimer.c +9 -2
index 8b93b3c..0e132b1 100644
@@ -122,11 +122,18 @@ static void timerblock_write(void *opaque, hwaddr addr,
     case 8: /* Control.  */
         old = tb->control;
         tb->control = value;
-        if (((old & 1) == 0) && (value & 1)) {
-            if (tb->count == 0 && (tb->control & 2)) {
+        if (value & 1) {
+            if ((old & 1) && (tb->count != 0)) {
+                /* Do nothing if timer is ticking right now.  */
+                break;
+            }
+            if (tb->control & 2) {
                 tb->count = tb->load;
             }
             timerblock_reload(tb, 1);
+        } else if (old & 1) {
+            /* Shutdown the timer.  */
+            timer_del(tb->timer);
         }
         break;
     case 12: /* Interrupt status.  */
Signature · 1 line
2.4.4
#10 lore raw

Re: [Qemu-devel] [PATCH 1/2] arm_mptimer: Fix timer shutdown and mode change

Quoted 24 lines · Dmitry Osipenko

Timer, running in periodic mode, can't be stopped or coming one-shot tick won't be canceled because timer control code just doesn't handle timer disabling. Fix it by deleting the timer if enable bit isn't set.

Timer won't start periodic ticking if ONE-SHOT -> PERIODIC mode change happened after one-shot tick was completed. Fix it by starting ticking only if the timer isn't ticking right now.

To avoid code churning, these two fixes are squashed in one commit.

---

Commits are squashed as per Peter Crosthwaite suggestion.

 hw/timer/arm_mptimer.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
hw/timer/arm_mptimer.c +0 -0
index 8b93b3c..0e132b1 100644
@@ -122,11 +122,18 @@ static void timerblock_write(void *opaque, hwaddr addr,
     case 8: /* Control.  */

hw/timer/arm_mptimer.c static void timerblock_write(void *opaque, hwaddr addr, · line 130

Quoted 10 lines
hw/timer/arm_mptimer.c +6 -2
         old = tb->control;
         tb->control = value;
-        if (((old & 1) == 0) && (value & 1)) {
-            if (tb->count == 0 && (tb->control & 2)) {
+        if (value & 1) {
+            if ((old & 1) && (tb->count != 0)) {
+                /* Do nothing if timer is ticking right now.  */
+                break;
+            }
+            if (tb->control & 2) {

So when the timer was previously disabled (!(old & 1)) and the count is non-zero this will cause a spurious auto-reload. I don't this causes a bug today because the code as-is doesn't support arbitrary count values, but it is a developer trap should the assumption that tb->count equals either 0 or the reload value not hold true.

hw/timer/arm_mptimer.c static void timerblock_write(void *opaque, hwaddr addr, · line 136

Quoted 6 lines
hw/timer/arm_mptimer.c +3 -0
                 tb->count = tb->load;
             }
             timerblock_reload(tb, 1);
+        } else if (old & 1) {
+            /* Shutdown the timer.  */
+            timer_del(tb->timer);

In general, this seems to now dup the code paths for control and load/counter writes. Both now have a del and reload call for various changes-of state. I had a go to see if I can consolidate. Turns out, doing so should implement timer pause and resumption while fixing both of your bugs, I'll send some patches.

Regards,
Peter

Quoted 7 lines
hw/timer/arm_mptimer.c +0 -1
         }
         break;
     case 12: /* Interrupt status.  */
--

2.4.4

#11 lore raw

Re: [Qemu-devel] [PATCH 1/2] arm_mptimer: Fix timer shutdown and mode change

05.07.2015 22:07, Peter Crosthwaite пишет:

Quoted 9 lines

hw/timer/arm_mptimer.c static void timerblock_write(void *opaque, hwaddr addr, · line 130

Quoted 8 lines
hw/timer/arm_mptimer.c +6 -2
-        if (((old & 1) == 0) && (value & 1)) {
-            if (tb->count == 0 && (tb->control & 2)) {
+        if (value & 1) {
+            if ((old & 1) && (tb->count != 0)) {
+                /* Do nothing if timer is ticking right now.  */
+                break;
+            }
+            if (tb->control & 2) {
Quoted 6 lines

So when the timer was previously disabled (!(old & 1)) and the count is non-zero this will cause a spurious auto-reload. I don't this causes a bug today because the code as-is doesn't support arbitrary count values, but it is a developer trap should the assumption that tb->count equals either 0 or the reload value not hold true.

tb->count can be either 0 or tb->load, so it shouldn't hurt to re-load it here.

Quoted 7 lines

hw/timer/arm_mptimer.c static void timerblock_write(void *opaque, hwaddr addr, · line 136

Quoted 6 lines
                  tb->count = tb->load;
              }
              timerblock_reload(tb, 1);
hw/timer/arm_mptimer.c +3 -0
+        } else if (old & 1) {
+            /* Shutdown the timer.  */
+            timer_del(tb->timer);
Quoted 5 lines

In general, this seems to now dup the code paths for control and load/counter writes. Both now have a del and reload call for various changes-of state. I had a go to see if I can consolidate. Turns out, doing so should implement timer pause and resumption while fixing both of your bugs, I'll send some patches.

Yeah, still there is some room for optimizations.

Well, I think it would be more reasonable to implement pausing with a conversion to ptimer use, since it should result in a cleaner and simpler code.

Signature · 1 line
Dmitry
Reviewed-by on v3 1/2
#12 lore raw

Re: [Qemu-devel] [PATCH 1/2] arm_mptimer: Fix timer shutdown and mode change

In reply to Dmitry Osipenko
Quoted 4 lines · Dmitry Osipenko

Timer, running in periodic mode, can't be stopped or coming one-shot tick won't be canceled because timer control code just doesn't handle timer disabling. Fix it by deleting the timer if enable bit isn't set.

You don't need to itemize one-shot and periodic separately, disabling the running timer just doesn't work universally.

Quoted 4 lines

Timer won't start periodic ticking if ONE-SHOT -> PERIODIC mode change happened after one-shot tick was completed. Fix it by starting ticking only if the timer isn't ticking right now.

Needs some grammar work. Try:

The running timer can't be stopped because timer control code just doesn't handle disabling the timer. Fix it by deleting the timer if the enable bit is cleared.

The timer won't start periodic ticking if a ONE-SHOT -> PERIODIC mode change happens after a one-shot tick was completed. Fix it by re-starting ticking if the timer isn't ticking right now.

Quoted 3 lines

To avoid code churning, these two fixes are squashed in one commit.

Otherwise:

Regards,
Peter

Quoted 36 lines

---

Commits are squashed as per Peter Crosthwaite suggestion.

 hw/timer/arm_mptimer.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
hw/timer/arm_mptimer.c +9 -3
index 8b93b3c..0e132b1 100644
@@ -122,11 +122,18 @@ static void timerblock_write(void *opaque, hwaddr addr,
     case 8: /* Control.  */
         old = tb->control;
         tb->control = value;
-        if (((old & 1) == 0) && (value & 1)) {
-            if (tb->count == 0 && (tb->control & 2)) {
+        if (value & 1) {
+            if ((old & 1) && (tb->count != 0)) {
+                /* Do nothing if timer is ticking right now.  */
+                break;
+            }
+            if (tb->control & 2) {
                 tb->count = tb->load;
             }
             timerblock_reload(tb, 1);
+        } else if (old & 1) {
+            /* Shutdown the timer.  */
+            timer_del(tb->timer);
         }
         break;
     case 12: /* Interrupt status.  */
--

2.4.4

#13 lore raw

Re: [Qemu-devel] [PATCH 1/2] arm_mptimer: Fix timer shutdown and mode change

06.07.2015 00:19, Peter Crosthwaite пишет:

Quoted 8 lines · Dmitry Osipenko
Quoted 4 lines

Timer, running in periodic mode, can't be stopped or coming one-shot tick won't be canceled because timer control code just doesn't handle timer disabling. Fix it by deleting the timer if enable bit isn't set.

You don't need to itemize one-shot and periodic separately, disabling the running timer just doesn't work universally.

Fair enough.

Quoted 15 lines
Quoted 4 lines

Timer won't start periodic ticking if ONE-SHOT -> PERIODIC mode change happened after one-shot tick was completed. Fix it by starting ticking only if the timer isn't ticking right now.

Needs some grammar work. Try:

The running timer can't be stopped because timer control code just doesn't handle disabling the timer. Fix it by deleting the timer if the enable bit is cleared.

The timer won't start periodic ticking if a ONE-SHOT -> PERIODIC mode change happens after a one-shot tick was completed. Fix it by re-starting ticking if the timer isn't ticking right now.

Quoted 7 lines

Otherwise:

Regards,
Peter

Sounds good, I'll pick it. Thanks.

Signature · 1 line
Dmitry
#14 lore raw

PATCH v2 2/2 arm_mptimer: Respect IT bit state

In reply to Dmitry Osipenko

Timer should fire interrupt only if IT(interrupt enable) bit state of control register is enabled and timer should update IRQ status on IT bit change as it would mask/unmask the interrupt line.

---

v2: Added missed IRQ status update on control register write as per
Peter Crosthwaite comment.

 hw/timer/arm_mptimer.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
hw/timer/arm_mptimer.c +4 -1
index 0e132b1..22fa46e 100644
@@ -38,7 +38,7 @@ static inline int get_current_cpu(ARMMPTimerState *s)
 
 static inline void timerblock_update_irq(TimerBlock *tb)
 {
-    qemu_set_irq(tb->irq, tb->status);
+    qemu_set_irq(tb->irq, tb->status && (tb->control & 4));
 }
 
 /* Return conversion factor from mpcore timer ticks to qemu timer ticks.  */
@@ -122,6 +122,9 @@ static void timerblock_write(void *opaque, hwaddr addr,
     case 8: /* Control.  */
         old = tb->control;
         tb->control = value;
+        if ((old & 4) != (value & 4)) {
+            timerblock_update_irq(tb);
+        }
         if (value & 1) {
             if ((old & 1) && (tb->count != 0)) {
                 /* Do nothing if timer is ticking right now.  */
Signature · 1 line
2.4.4
Reviewed-by on v2 2/2
#15 lore raw

Re: [Qemu-devel] [PATCH v2 2/2] arm_mptimer: Respect IT bit state

Quoted 5 lines · Dmitry Osipenko

Timer should fire interrupt only if IT(interrupt enable) bit state of control register is enabled and timer should update IRQ status on IT bit change as it would mask/unmask the interrupt line.

Quoted 35 lines

---

v2: Added missed IRQ status update on control register write as per
Peter Crosthwaite comment.

 hw/timer/arm_mptimer.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
hw/timer/arm_mptimer.c +4 -2
index 0e132b1..22fa46e 100644
@@ -38,7 +38,7 @@ static inline int get_current_cpu(ARMMPTimerState *s)
 
 static inline void timerblock_update_irq(TimerBlock *tb)
 {
-    qemu_set_irq(tb->irq, tb->status);
+    qemu_set_irq(tb->irq, tb->status && (tb->control & 4));
 }
 
 /* Return conversion factor from mpcore timer ticks to qemu timer ticks.  */
@@ -122,6 +122,9 @@ static void timerblock_write(void *opaque, hwaddr addr,
     case 8: /* Control.  */
         old = tb->control;
         tb->control = value;
+        if ((old & 4) != (value & 4)) {
+            timerblock_update_irq(tb);
+        }
         if (value & 1) {
             if ((old & 1) && (tb->count != 0)) {
                 /* Do nothing if timer is ticking right now.  */
--

2.4.4

#16 lore raw
In reply to Dmitry Osipenko
Quoted 7 lines · Dmitry Osipenko

Hello, this is V2 of arm_mptimer patch series. Comments and suggestion from V1 has been addressed and the series was re-tested, including new test for IT bit masking/unmasking.

[PATCH 1/2] arm_mptimer: Fix timer shutdown and mode change [PATCH v2 2/2] arm_mptimer: Respect IT bit state

This looks like an ad-hoc cover letter. Use git to generate patch series covers.

git format-patch HEAD~N --thread --cover-letter -vX

For N patches version X of the series.

Edit the 0000-cover-letter file with your cover mail contents and send all the generated patches along with cover.

This series doesn't show up in the patch tracking system due to irregular cover.

Regards,
Peter

#17 lore raw

05.07.2015 22:52, Peter Crosthwaite пишет:

Quoted 15 lines · Dmitry Osipenko
Quoted 7 lines

Hello, this is V2 of arm_mptimer patch series. Comments and suggestion from V1 has been addressed and the series was re-tested, including new test for IT bit masking/unmasking.

[PATCH 1/2] arm_mptimer: Fix timer shutdown and mode change [PATCH v2 2/2] arm_mptimer: Respect IT bit state

This looks like an ad-hoc cover letter. Use git to generate patch series covers.

git format-patch HEAD~N --thread --cover-letter -vX

For N patches version X of the series.

Quoted 8 lines

Edit the 0000-cover-letter file with your cover mail contents and send all the generated patches along with cover.

This series doesn't show up in the patch tracking system due to irregular cover.

Regards,
Peter

Thanks for advice, I used --compose --no-chain-reply-to. Please let me know if I should re-sent and sorry for the mess.

Signature · 1 line
Dmitry
#18 lore raw
In reply to Peter Crosthwaite

05.07.2015 22:52, Peter Crosthwaite пишет:

Quoted 1 line

This series doesn't show up in the patch tracking system due to irregular cover.

BTW, doesn't QEMU use patchwork for tracking? I see both patches there.

Signature · 1 line
Dmitry
#19 lore raw

v3 cover arm_mptimer fixes

In reply to Dmitry Osipenko

Hello, this is V3 of arm_mptimer patch series. No code changes here, just grammar fixes for "shutdown and mode change" patch and general re-send, as V2 was screwed for patchtracker.

Dmitry Osipenko (2):
arm_mptimer: Fix timer shutdown and mode change
arm_mptimer: Respect IT bit state

 hw/timer/arm_mptimer.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
Signature · 1 line
2.4.4
#20 lore raw

PATCH v2 1/2 arm_mptimer: Fix timer shutdown and mode change

The running timer can't be stopped because timer control code just doesn't handle disabling the timer. Fix it by deleting the timer if the enable bit is cleared.

The timer won't start periodic ticking if a ONE-SHOT -> PERIODIC mode change happens after a one-shot tick was completed. Fix it by re-starting ticking if the timer isn't ticking right now.

To avoid code churning, these two fixes are squashed in one commit.

---

v1: Commits are squashed as per Peter Crosthwaite suggestion.

v2: Grammar fixes of commit message as per Peter Crosthwaite suggestion.

 hw/timer/arm_mptimer.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
hw/timer/arm_mptimer.c +9 -2
index 8b93b3c..0e132b1 100644
@@ -122,11 +122,18 @@ static void timerblock_write(void *opaque, hwaddr addr,
     case 8: /* Control.  */
         old = tb->control;
         tb->control = value;
-        if (((old & 1) == 0) && (value & 1)) {
-            if (tb->count == 0 && (tb->control & 2)) {
+        if (value & 1) {
+            if ((old & 1) && (tb->count != 0)) {
+                /* Do nothing if timer is ticking right now.  */
+                break;
+            }
+            if (tb->control & 2) {
                 tb->count = tb->load;
             }
             timerblock_reload(tb, 1);
+        } else if (old & 1) {
+            /* Shutdown the timer.  */
+            timer_del(tb->timer);
         }
         break;
     case 12: /* Interrupt status.  */
Signature · 1 line
2.4.4
#21 lore raw

PATCH v3 2/2 arm_mptimer: Respect IT bit state

In reply to Dmitry Osipenko

The timer should fire interrupt only if IT(interrupt enable) bit state of control register is enabled and the timer should update IRQ status on IT bit change as it would mask/unmask the interrupt line.

---

v2: Added missed IRQ status update on control register write as per
Peter Crosthwaite comment.

v3: No code change, just re-send.

 hw/timer/arm_mptimer.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
hw/timer/arm_mptimer.c +4 -1
index 0e132b1..22fa46e 100644
@@ -38,7 +38,7 @@ static inline int get_current_cpu(ARMMPTimerState *s)
 
 static inline void timerblock_update_irq(TimerBlock *tb)
 {
-    qemu_set_irq(tb->irq, tb->status);
+    qemu_set_irq(tb->irq, tb->status && (tb->control & 4));
 }
 
 /* Return conversion factor from mpcore timer ticks to qemu timer ticks.  */
@@ -122,6 +122,9 @@ static void timerblock_write(void *opaque, hwaddr addr,
     case 8: /* Control.  */
         old = tb->control;
         tb->control = value;
+        if ((old & 4) != (value & 4)) {
+            timerblock_update_irq(tb);
+        }
         if (value & 1) {
             if ((old & 1) && (tb->count != 0)) {
                 /* Do nothing if timer is ticking right now.  */
Signature · 1 line
2.4.4
#22 lore raw

Re: [Qemu-devel] [PATCH v3 2/2] arm_mptimer: Respect IT bit state

Quoted 2 lines

v2: Added missed IRQ status update on control register write as per
Peter Crosthwaite comment.

Oh, no! Turned out, that is wrong. I wasn't testing that case properly on HW, V1 is correct. Quote from ARM doc "If the timer interrupt is enabled, Interrupt ID 29 is set as Pending in the Interrupt Distributor after the event flag is set."

Signature · 1 line
Dmitry
#23 lore raw

PATCH v4 1/1 arm_mptimer: Respect IT bit state

The timer should fire the interrupt only if the IT (interrupt enable) bit state of the control register is enabled.

---

v2: Added missed IRQ status update on control register write as per
Peter Crosthwaite comment.

v3: No code change, just re-send.

v4: Revert to v1, as it was correct, with a slightly change commit message.

 hw/timer/arm_mptimer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/timer/arm_mptimer.c +1 -1
index 0e132b1..3e59c2a 100644
@@ -38,7 +38,7 @@ static inline int get_current_cpu(ARMMPTimerState *s)
 
 static inline void timerblock_update_irq(TimerBlock *tb)
 {
-    qemu_set_irq(tb->irq, tb->status);
+    qemu_set_irq(tb->irq, tb->status && (tb->control & 4));
 }
 
 /* Return conversion factor from mpcore timer ticks to qemu timer ticks.  */
Signature · 1 line
2.4.4
#24 lore raw

Re: [Qemu-devel] [PATCH v4] arm_mptimer: Respect IT bit state

Quoted 5 lines · Dmitry Osipenko

The timer should fire the interrupt only if the IT (interrupt enable) bit state of the control register is enabled.

If you need to update a patch, please resend the whole series, not just one patch from it. (This is one of the things we talk about on http://wiki.qemu.org/Contribute/SubmitAPatch -- the v2/3/4 etc version number applies to a series, not a single patch). Otherwise it gets very confusing because it's hard to see if you're really looking at the most recent version of the patchset, and as Peter C says, some patch handling tools don't cope with the failure to thread a series properly.

I'll pick these up manually since there are only two patches here, but for future submissions it would be really helpful if you could fix this. We generally recommend using git format-patch/send-email to put together the series and its cover letter with the right references headers.

thanks
-- PMM

#25 lore raw

Re: [Qemu-devel] [PATCH v4] arm_mptimer: Respect IT bit state

06.07.2015 12:23, Peter Maydell пишет:

Quoted 4 lines

If you need to update a patch, please resend the whole series, not just one patch from it. (This is one of the things we talk about on http://wiki.qemu.org/Contribute/SubmitAPatch -- the v2/3/4 etc version number applies to a series, not a single

I made a quick glance at "SubmitAPatch" before posting. Now, reading more closely, I see that it all mentioned there and I feel sorry for that.

Quoted 5 lines

patch). Otherwise it gets very confusing because it's hard to see if you're really looking at the most recent version of the patchset, and as Peter C says, some patch handling tools don't cope with the failure to thread a series properly.

Probably, I should go and try those tools myself to have better sense of what I should and shouldn't be doing.

Quoted 6 lines

I'll pick these up manually since there are only two patches here, but for future submissions it would be really helpful if you could fix this. We generally recommend using git format-patch/send-email to put together the series and its cover letter with the right references headers.

Thanks a lot! I very appreciate any help and advices.

Signature · 1 line
Dmitry
#26 lore raw

Re: [Qemu-devel] [PATCH v4] arm_mptimer: Respect IT bit state

Quoted 2 lines · Dmitry Osipenko

I made a quick glance at "SubmitAPatch" before posting. Now, reading more closely, I see that it all mentioned there and I feel sorry for that.

No problem -- it's a pretty big page and it mentions a lot of different things. (I keep meaning to try cleaning it up by putting in different subsections for 'before sending your initial patch', 'dealing with review', and so on.)

Quoted 8 lines
Quoted 5 lines

patch). Otherwise it gets very confusing because it's hard to see if you're really looking at the most recent version of the patchset, and as Peter C says, some patch handling tools don't cope with the failure to thread a series properly.

Probably, I should go and try those tools myself to have better sense of what I should and shouldn't be doing.

The particular one I find useful is Anthony Liguori's "patches"
tool: https://github.com/aliguori/patches
But it's really intended to help maintainers and submaintainers:
as somebody who's only submitting patches to the list you probably don't have any need to use it.

thanks
-- PMM

#27 lore raw

Re: [Qemu-devel] [PATCH v4] arm_mptimer: Respect IT bit state

06.07.2015 16:16, Peter Maydell пишет:

Quoted 5 lines
Quoted 2 lines

Probably, I should go and try those tools myself to have better sense of what I should and shouldn't be doing.

The particular one I find useful is Anthony Liguori's "patches"
tool: https://github.com/aliguori/patches

Thanks! I'll take a look at it.

Quoted 4 lines

But it's really intended to help maintainers and submaintainers:
as somebody who's only submitting patches to the list you probably don't have any need to use it.

Sure, nevertheless, it won't hurt to know what's going on behind the scene.

Signature · 1 line
Dmitry
#28 lore raw

Re: [Qemu-devel] [PATCH v4] arm_mptimer: Respect IT bit state

Quoted 6 lines · Dmitry Osipenko

06.07.2015 16:16, Peter Maydell пишет:

Quoted 5 lines
Quoted 3 lines

Probably, I should go and try those tools myself to have better sense of what I should and shouldn't be doing.

Quoted 10 lines
Quoted 2 lines

The particular one I find useful is Anthony Liguori's "patches"
tool: https://github.com/aliguori/patches

Thanks! I'll take a look at it.

Quoted 4 lines

But it's really intended to help maintainers and submaintainers:
as somebody who's only submitting patches to the list you probably don't have any need to use it.

As someone who doesn't send PULLs, I still find patches very useful. It sanity checks your email sends. A while back, I drafted a paragraph on how to use patches to verify receipt of your series if we want to add it to "submit a patch".

Regards,
Peter

Quoted 6 lines

Sure, nevertheless, it won't hurt to know what's going on behind the scene.

--
Dmitry

#29 lore raw

Re: [Qemu-devel] [PATCH v4] arm_mptimer: Respect IT bit state

06.07.2015 19:45, Peter Crosthwaite пишет:

Quoted 5 lines

As someone who doesn't send PULLs, I still find patches very useful. It sanity checks your email sends. A while back, I drafted a paragraph on how to use patches to verify receipt of your series if we want to add it to "submit a patch".

Sounds useful. However, I think, it would make sense to do only if the whole preparing/sending process description is split-up in distinguished sections, like Peter proposed, otherwise it tends to bloat text and stay unnoticed.

Signature · 1 line
Dmitry