Skip to content

Commit 6e083c0

Browse files
jan-kiszkabonzini
authored andcommitted
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 <[email protected]> Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Message-Id: <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 86f13ef commit 6e083c0

File tree

4 files changed

+23
-20
lines changed

4 files changed

+23
-20
lines changed

hw/intc/apic.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -615,24 +615,6 @@ int apic_accept_pic_intr(DeviceState *dev)
615615
return 0;
616616
}
617617

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-
636618
static void apic_timer_update(APICCommonState *s, int64_t current_time)
637619
{
638620
if (apic_next_timer(s, current_time)) {

hw/intc/apic_common.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,25 @@ bool apic_next_timer(APICCommonState *s, int64_t current_time)
189189
return true;
190190
}
191191

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+
192211
void apic_init_reset(DeviceState *dev)
193212
{
194213
APICCommonState *s;

include/hw/i386/apic_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ void vapic_report_tpr_access(DeviceState *dev, CPUState *cpu, target_ulong ip,
211211
TPRAccess access);
212212

213213
int apic_get_ppr(APICCommonState *s);
214+
uint32_t apic_get_current_count(APICCommonState *s);
214215

215216
static inline void apic_set_bit(uint32_t *tab, int index)
216217
{

target/i386/helper.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,11 @@ void x86_cpu_dump_local_apic_state(CPUState *cs, int flags)
370370
dump_apic_lvt("LVTTHMR", lvt[APIC_LVT_THERMAL], false);
371371
dump_apic_lvt("LVTT", lvt[APIC_LVT_TIMER], true);
372372

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",
374375
s->divide_conf & APIC_DCR_MASK,
375376
divider_conf(s->divide_conf),
376-
s->initial_count);
377+
s->initial_count, apic_get_current_count(s));
377378

378379
qemu_printf("SPIV\t 0x%08x APIC %s, focus=%s, spurious vec %u\n",
379380
s->spurious_vec,

0 commit comments

Comments
 (0)