diff --git a/hw/i8259.c b/hw/i8259.c index 7532d5c672962b6fa94177fdacb75afd0c931ca6..62e11f0efe7ce656246c1490cd62cc6b6d9e051e 100644 --- a/hw/i8259.c +++ b/hw/i8259.c @@ -27,6 +27,7 @@ //#define DEBUG_PIC //#define DEBUG_IRQ_LATENCY +//#define DEBUG_IRQ_COUNT typedef struct PicState { uint8_t last_irr; /* edge detection */ @@ -50,6 +51,13 @@ typedef struct PicState { /* 0 is master pic, 1 is slave pic */ static PicState pics[2]; +#if defined(DEBUG_PIC) || defined (DEBUG_IRQ_COUNT) +static int irq_level[16]; +#endif +#ifdef DEBUG_IRQ_COUNT +static uint64_t irq_count[16]; +#endif + /* set irq level. If an edge is detected, then the IRR is set to 1 */ static inline void pic_set_irq1(PicState *s, int irq, int level) { @@ -147,16 +155,19 @@ static void pic_update_irq(void) #ifdef DEBUG_IRQ_LATENCY int64_t irq_time[16]; #endif -#if defined(DEBUG_PIC) -int irq_level[16]; -#endif void pic_set_irq(int irq, int level) { -#if defined(DEBUG_PIC) +#if defined(DEBUG_PIC) || defined(DEBUG_IRQ_COUNT) if (level != irq_level[irq]) { +#if defined(DEBUG_PIC) printf("pic_set_irq: irq=%d level=%d\n", irq, level); +#endif irq_level[irq] = level; +#ifdef DEBUG_IRQ_COUNT + if (level == 1) + irq_count[irq]++; +#endif } #endif #ifdef DEBUG_IRQ_LATENCY @@ -463,6 +474,22 @@ void pic_info(void) } } +void irq_info(void) +{ +#ifndef DEBUG_IRQ_COUNT + term_printf("irq statistic code not compiled.\n"); +#else + int i; + int64_t count; + + term_printf("IRQ statistics:\n"); + for (i = 0; i < 16; i++) { + count = irq_count[i]; + if (count > 0) + term_printf("%2d: %lld\n", i, count); + } +#endif +} void pic_init(void) { diff --git a/monitor.c b/monitor.c index 2dc94b44a7086e2e0bcb261ea711531fa5f605a2..f5ab04336b96e4689b84da6d7fe5a05af43b5481 100644 --- a/monitor.c +++ b/monitor.c @@ -523,6 +523,8 @@ static term_cmd_t info_cmds[] = { "", "show the cpu registers" }, { "history", "", do_info_history, "", "show the command line history", }, + { "irq", "", irq_info, + "", "show the interrupts statistics (if available)", }, { "pic", "", pic_info, "", "show i8259 (PIC) state", }, { "pci", "", pci_info, diff --git a/vl.h b/vl.h index ace401fbb01599dceb96c72fa63966f4d27a0f1e..8026dec656358df3bf0eed13e1709d48323d159b 100644 --- a/vl.h +++ b/vl.h @@ -544,6 +544,7 @@ void pic_set_irq(int irq, int level); void pic_init(void); uint32_t pic_intack_read(CPUState *env); void pic_info(void); +void irq_info(void); /* i8254.c */