diff mbox series

[kvm-unit-tests,v2,3/3] tscdeadline_latency: Stop timer when reach max loop

Message ID 20190712022825.1366-4-peterx@redhat.com (mailing list archive)
State New, archived
Headers show
Series tscdeadline_latency: Some fixes of hangs | expand

Commit Message

Peter Xu July 12, 2019, 2:28 a.m. UTC
This fixes another possible hang of this test when delay is configured
too small (e.g., 2000) so that the IRQ handler will trigger forever.

Let's stop the timer if we've collected enough data so that the
program can quit always.

Signed-off-by: Peter Xu <peterx@redhat.com>
---
 x86/tscdeadline_latency.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/x86/tscdeadline_latency.c b/x86/tscdeadline_latency.c
index 0a3532d..a63f98b 100644
--- a/x86/tscdeadline_latency.c
+++ b/x86/tscdeadline_latency.c
@@ -50,18 +50,24 @@  int breakmax = 0;
 
 static void tsc_deadline_timer_isr(isr_regs_t *regs)
 {
-    u64 now = rdtsc();
+    u64 now = rdtsc(), delay;
     ++tdt_count;
 
-    if (table_idx < TABLE_SIZE && tdt_count > 1)
-        table[table_idx++] = now - exptime;
+    if (tdt_count == 1)
+        /* Skip the 1st IRQ */
+        goto setup_next;
 
-    if (breakmax && tdt_count > 1 && (now - exptime) > breakmax) {
-        hitmax = 1;
+    table[table_idx++] = delay = now - exptime;
+
+    /* Stop if either we finished collection or hit max */
+    if ((breakmax && delay > breakmax) || table_idx >= TABLE_SIZE) {
+        if (breakmax)
+            hitmax = 1;
         apic_write(APIC_EOI, 0);
         return;
     }
 
+setup_next:
     exptime = now+delta;
     wrmsr(MSR_IA32_TSCDEADLINE, now+delta);
     apic_write(APIC_EOI, 0);