/* * Interrupt latency test module * * (C) 2007 Jaswinder Singh * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public Licence Version * 2 as published by the Free Software Foundation. * */ #include #include #include #include //#define DBG_IRQ_LAT /* debug interrupt latency test */ /* getting global time from 8254 */ #define READ_CNT0(var) do {var = inb(0x40); var |= (inb(0x40) << 8);} while (0) #ifdef DBG_IRQ_LAT #define TEST_CNT 1000 static long lat_val[TEST_CNT + 1]; static long lat_val_num; #endif static volatile long count_c0; static long lat_max = 0; static long lat_min = 100000000; static unsigned long irq_cnt = 0; static unsigned long lat_avg = 0; static void irq_lat_hdr(void) { READ_CNT0(count_c0); count_c0 = (LATCH - count_c0); if (count_c0 > lat_max) lat_max = count_c0; if (count_c0 < lat_min) lat_min = count_c0; lat_avg = lat_avg + count_c0; irq_cnt++; #ifdef DBG_IRQ_LAT if (irq_cnt <= TEST_CNT) { lat_val[irq_cnt] = count_c0; } #endif } static int __init irq_lat_init(void) { printk("*************************************\n"); printk("* Interrupt Latency module loaded *\n"); printk("* When you remove this module you *\n"); printk("* will get interrupt latency result *\n"); printk("*************************************\n"); irq_lat_ptr = irq_lat_hdr; /* Install interrupt handler */ return 0; } static void __exit irq_lat_exit(void) { unsigned long nanosecs = 1000000000; irq_lat_ptr = NULL; /* Uninstall interrupt handler */ nanosecs = (nanosecs/CLOCK_TICK_RATE); printk("Interrupt Latency result\n"); printk("------------------------\n"); if (lat_avg) lat_avg = lat_avg/irq_cnt; else { printk("Interrupt Latency test Failed\n"); printk("send info to \n"); return; } #ifdef DBG_IRQ_LAT if (irq_cnt < TEST_CNT) lat_val_num = irq_cnt; else lat_val_num = TEST_CNT; for (count_c0 = 1; count_c0 <= lat_val_num; count_c0++) { printk("%4lu: %6lu ", count_c0, lat_val[count_c0]); if ((count_c0 % 5) == 0) printk("\n"); } printk("\nCLOCK_TICK_RATE: %d TICK: %lu LATCH: %d\n", CLOCK_TICK_RATE, nanosecs, LATCH); printk("MAX latency : %lu ticks\n", lat_max); printk("MIN latency : %lu ticks\n", lat_min); printk("AVG latency : %lu ticks\n", lat_avg); #endif printk("MAX latency : %5lu.%03lu micro-seconds\n", (nanosecs * lat_max)/1000, (nanosecs * lat_max) % 1000); printk("MIN latency : %5lu.%03lu micro-seconds\n", (nanosecs * lat_min)/1000, (nanosecs * lat_min) % 1000); printk("AVG latency : %5lu.%03lu micro-seconds\n", (nanosecs * lat_avg)/1000, (nanosecs * lat_avg) % 1000); printk("Total Samples : %lu\n", irq_cnt); } module_init(irq_lat_init); module_exit(irq_lat_exit); MODULE_LICENSE("GPL");