qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

apic: Report current_count via 'info lapic'

This is helpful when debugging stuck guest timers.

As we need apic_get_current_count for that, and it is really not
emulation specific, move it to apic_common.c and export it. Fix its
style at this chance as well.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-Id: <e00e2896-ca5b-a929-de7a-8e5762f0c1c2@siemens.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

authored by

Jan Kiszka and committed by
Paolo Bonzini
6e083c0d 86f13ef3

+23 -20
-18
hw/intc/apic.c
··· 615 615 return 0; 616 616 } 617 617 618 - static uint32_t apic_get_current_count(APICCommonState *s) 619 - { 620 - int64_t d; 621 - uint32_t val; 622 - d = (qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) - s->initial_count_load_time) >> 623 - s->count_shift; 624 - if (s->lvt[APIC_LVT_TIMER] & APIC_LVT_TIMER_PERIODIC) { 625 - /* periodic */ 626 - val = s->initial_count - (d % ((uint64_t)s->initial_count + 1)); 627 - } else { 628 - if (d >= s->initial_count) 629 - val = 0; 630 - else 631 - val = s->initial_count - d; 632 - } 633 - return val; 634 - } 635 - 636 618 static void apic_timer_update(APICCommonState *s, int64_t current_time) 637 619 { 638 620 if (apic_next_timer(s, current_time)) {
+19
hw/intc/apic_common.c
··· 189 189 return true; 190 190 } 191 191 192 + uint32_t apic_get_current_count(APICCommonState *s) 193 + { 194 + int64_t d; 195 + uint32_t val; 196 + d = (qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) - s->initial_count_load_time) >> 197 + s->count_shift; 198 + if (s->lvt[APIC_LVT_TIMER] & APIC_LVT_TIMER_PERIODIC) { 199 + /* periodic */ 200 + val = s->initial_count - (d % ((uint64_t)s->initial_count + 1)); 201 + } else { 202 + if (d >= s->initial_count) { 203 + val = 0; 204 + } else { 205 + val = s->initial_count - d; 206 + } 207 + } 208 + return val; 209 + } 210 + 192 211 void apic_init_reset(DeviceState *dev) 193 212 { 194 213 APICCommonState *s;
+1
include/hw/i386/apic_internal.h
··· 211 211 TPRAccess access); 212 212 213 213 int apic_get_ppr(APICCommonState *s); 214 + uint32_t apic_get_current_count(APICCommonState *s); 214 215 215 216 static inline void apic_set_bit(uint32_t *tab, int index) 216 217 {
+3 -2
target/i386/helper.c
··· 370 370 dump_apic_lvt("LVTTHMR", lvt[APIC_LVT_THERMAL], false); 371 371 dump_apic_lvt("LVTT", lvt[APIC_LVT_TIMER], true); 372 372 373 - qemu_printf("Timer\t DCR=0x%x (divide by %u) initial_count = %u\n", 373 + qemu_printf("Timer\t DCR=0x%x (divide by %u) initial_count = %u" 374 + " current_count = %u\n", 374 375 s->divide_conf & APIC_DCR_MASK, 375 376 divider_conf(s->divide_conf), 376 - s->initial_count); 377 + s->initial_count, apic_get_current_count(s)); 377 378 378 379 qemu_printf("SPIV\t 0x%08x APIC %s, focus=%s, spurious vec %u\n", 379 380 s->spurious_vec,