[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 11/11] hpet: avoid timer storms on periodic timers
From: |
Paolo Bonzini |
Subject: |
[PULL 11/11] hpet: avoid timer storms on periodic timers |
Date: |
Tue, 23 Jul 2024 16:15:29 +0200 |
If the period is set to a value that is too low, there could be no
time left to run the rest of QEMU. Do not trigger interrupts faster
than 1 MHz.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/timer/hpet.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/hw/timer/hpet.c b/hw/timer/hpet.c
index 1654b7cb8b8..471950adef1 100644
--- a/hw/timer/hpet.c
+++ b/hw/timer/hpet.c
@@ -59,6 +59,7 @@ typedef struct HPETTimer { /* timers */
uint8_t wrap_flag; /* timer pop will indicate wrap for one-shot 32-bit
* mode. Next pop will be actual timer expiration.
*/
+ uint64_t last; /* last value armed, to avoid timer storms */
} HPETTimer;
struct HPETState {
@@ -266,6 +267,7 @@ static int hpet_post_load(void *opaque, int version_id)
for (i = 0; i < s->num_timers; i++) {
HPETTimer *t = &s->timer[i];
t->cmp64 = hpet_calculate_cmp64(t, s->hpet_counter, t->cmp);
+ t->last = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) -
NANOSECONDS_PER_SECOND;
}
/* Recalculate the offset between the main counter and guest time */
if (!s->hpet_offset_saved) {
@@ -364,8 +366,15 @@ static const VMStateDescription vmstate_hpet = {
static void hpet_arm(HPETTimer *t, uint64_t tick)
{
- /* FIXME: Clamp period to reasonable min value? */
- timer_mod(t->qemu_timer, hpet_get_ns(t->state, tick));
+ uint64_t ns = hpet_get_ns(t->state, tick);
+
+ /* Clamp period to reasonable min value (1 us) */
+ if (timer_is_periodic(t) && ns - t->last < 1000) {
+ ns = t->last + 1000;
+ }
+
+ t->last = ns;
+ timer_mod(t->qemu_timer, ns);
}
/*
--
2.45.2
- [PULL 00/11] target/i386, HPET changes for QEMU 9.1 soft freeze, Paolo Bonzini, 2024/07/23
- [PULL 01/11] target/i386: do not crash if microvm guest uses SGX CPUID leaves, Paolo Bonzini, 2024/07/23
- [PULL 02/11] qio: add support for SO_PEERCRED for socket channel, Paolo Bonzini, 2024/07/23
- [PULL 03/11] tools: build qemu-vmsr-helper, Paolo Bonzini, 2024/07/23
- [PULL 05/11] hpet: fix and cleanup persistence of interrupt status, Paolo Bonzini, 2024/07/23
- [PULL 04/11] Add support for RAPL MSRs in KVM/Qemu, Paolo Bonzini, 2024/07/23
- [PULL 07/11] hpet: remove unnecessary variable "index", Paolo Bonzini, 2024/07/23
- [PULL 08/11] hpet: place read-only bits directly in "new_val", Paolo Bonzini, 2024/07/23
- [PULL 06/11] hpet: ignore high bits of comparator in 32-bit mode, Paolo Bonzini, 2024/07/23
- [PULL 11/11] hpet: avoid timer storms on periodic timers,
Paolo Bonzini <=
- [PULL 09/11] hpet: accept 64-bit reads and writes, Paolo Bonzini, 2024/07/23
- [PULL 10/11] hpet: store full 64-bit target value of the counter, Paolo Bonzini, 2024/07/23
- Re: [PULL 00/11] target/i386, HPET changes for QEMU 9.1 soft freeze, Richard Henderson, 2024/07/23