Software should see timer counter wraparound only after IRQ being triggered.
This fixes regression introduced by the commit
5a50307 ("hw/ptimer: Perform
counter wrap around if timer already expired"), resulting in monotonic timer
jumping backwards on SPARC emulated machine running NetBSD guest OS, as
reported by Mark Cave-Ayland.
Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
Message-id:
20160708132206.2080-1-digetx@gmail.com
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
bool oneshot = (s->enabled == 2);
/* Figure out the current counter value. */
- if (s->period == 0 || (expired && (oneshot || use_icount))) {
+ if (expired) {
/* Prevent timer underflowing if it should already have
triggered. */
counter = 0;
backwards.
*/
- rem = expired ? now - next : next - now;
+ rem = next - now;
div = period;
clz1 = clz64(rem);
div += 1;
}
counter = rem / div;
-
- if (expired && counter != 0) {
- /* Wrap around periodic counter. */
- counter = s->limit - (counter - 1) % s->limit;
- }
}
} else {
counter = s->delta;