From 2383977c2a36906c28cb1e60229d840be59ccb2b Mon Sep 17 00:00:00 2001 From: JackWindows Date: Tue, 14 Mar 2017 17:20:20 -0400 Subject: [PATCH 1/2] Fix code deficiency that will always cause at least one missed IRQ variable test_data.gpio_time will be accessed without initialization in the current code, which result in a fake missed IRQ --- gpio-test/src/gpio-irq-latency-test.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gpio-test/src/gpio-irq-latency-test.c b/gpio-test/src/gpio-irq-latency-test.c index 4de33ea..e319e14 100644 --- a/gpio-test/src/gpio-irq-latency-test.c +++ b/gpio-test/src/gpio-irq-latency-test.c @@ -161,6 +161,9 @@ int __init test_irq_latency_init_module(void) { test_data.timer.function = test_irq_latency_timer_handler; add_timer(&test_data.timer); + getnstimeofday(&test_data.gpio_time); + gpio_set_value(test_data.gpio_pin, 0); + printk(KERN_INFO DRV_NAME " : beginning GPIO IRQ latency test (%u passes in %d seconds).\n", NUM_TESTS, (NUM_TESTS * TEST_INTERVAL) / HZ); From 48980da31dda5f590850817733417e54270cc15d Mon Sep 17 00:00:00 2001 From: JackWindows Date: Tue, 14 Mar 2017 17:28:04 -0400 Subject: [PATCH 2/2] Fix wrong method of calculating average latency --- gpio-test/src/gpio-irq-latency-test.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/gpio-test/src/gpio-irq-latency-test.c b/gpio-test/src/gpio-irq-latency-test.c index e319e14..40e2eb6 100644 --- a/gpio-test/src/gpio-irq-latency-test.c +++ b/gpio-test/src/gpio-irq-latency-test.c @@ -68,10 +68,7 @@ static void test_irq_latency_timer_handler(unsigned long ptr) { " : GPIO IRQ triggered after > 1 sec, something is fishy.\n"); data->missed_irqs++; } else { - data->avg_nsecs = data->avg_nsecs ? - (unsigned long)(((unsigned long long)delta.tv_nsec + - (unsigned long long)data->avg_nsecs) >> 1) : - delta.tv_nsec; + data->avg_nsecs = (data->avg_nsecs * data->test_count + delta.tv_nsec) / (data->test_count + 1); test_ok = 1; }