From b0c3245423c49570491ce1368fd351bcdabda588 Mon Sep 17 00:00:00 2001 From: Lephe Date: Sun, 19 Jul 2020 22:55:58 +0200 Subject: [PATCH] add an interrupt stress test --- include/gintctl/perf.h | 3 ++ include/gintctl/prof-contexts.h | 1 + src/gintctl.c | 1 + src/perf/interrupt.c | 89 +++++++++++++++++++++++++++++++++ 4 files changed, 94 insertions(+) create mode 100644 src/perf/interrupt.c diff --git a/include/gintctl/perf.h b/include/gintctl/perf.h index 51b9b53..2138632 100644 --- a/include/gintctl/perf.h +++ b/include/gintctl/perf.h @@ -8,6 +8,9 @@ /* gintctl_perf_libprof(): Basic libprof tests using timers */ void gintctl_perf_libprof(void); +/* gintctl_perf_interrupts(): Interrupt handling */ +void gintctl_perf_interrupts(void); + /* gintctl_perf_render(): Profile the display primitives */ void gintctl_perf_render(void); diff --git a/include/gintctl/prof-contexts.h b/include/gintctl/prof-contexts.h index 06f76bd..61e4c29 100644 --- a/include/gintctl/prof-contexts.h +++ b/include/gintctl/prof-contexts.h @@ -12,6 +12,7 @@ enum { PROFCTX_BASICS = 0, PROFCTX_EMPTY, PROFCTX_RENDER, + PROFCTX_INTSTRESS, /* Last element and bound checker */ PROFCTX_COUNT, diff --git a/src/gintctl.c b/src/gintctl.c index cbaf6ce..6bd9840 100644 --- a/src/gintctl.c +++ b/src/gintctl.c @@ -61,6 +61,7 @@ struct menu menu_perf = { _("Performance", "Performance benchmarks"), .entries = { { "libprof basics", gintctl_perf_libprof }, + { "Interrupt stress", gintctl_perf_interrupts }, { "Rendering functions", gintctl_perf_render }, /* TODO: Comparison with MonochromeLib */ diff --git a/src/perf/interrupt.c b/src/perf/interrupt.c new file mode 100644 index 0000000..264b814 --- /dev/null +++ b/src/perf/interrupt.c @@ -0,0 +1,89 @@ +#include +#include +#include + +#include +#include +#include + +#include + +#define STRESS_LIMIT 1000 + +int stress_callback(int *counter) +{ + (*counter)++; + if(*counter >= STRESS_LIMIT) return TIMER_STOP; + return TIMER_CONTINUE; +} + +uint32_t stress_interrupts(void) +{ + int counter = 0; + int timer = timer_setup(TIMER_ANY, 1, stress_callback, &counter); + + if(timer >= 0) + { + prof_clear(PROFCTX_INTSTRESS); + prof_enter(PROFCTX_INTSTRESS); + + timer_start(timer); + timer_wait(timer); + + prof_leave(PROFCTX_INTSTRESS); + return prof_time(PROFCTX_INTSTRESS); + } + + return 0; +} + +/* gintctl_perf_interrupts(): Interrupt handling */ +void gintctl_perf_interrupts(void) +{ + uint32_t time_spent = stress_interrupts(); + int rate = 0; + int key = 0; + + if(time_spent > 0) + { + rate = 1000000ull * STRESS_LIMIT / time_spent; + } + + while(key != KEY_EXIT) + { + dclear(C_WHITE); + + #ifdef FX9860G + row_title("Interrupt stress"); + + if(time_spent == 0) + { + row_print(3, 1, "Not tested"); + } + else + { + row_print(3, 1, "Count: %d", STRESS_LIMIT); + row_print(4, 1, "Time: %d us", time_spent); + row_print(5, 1, "Rate: %d int/s", rate); + } + #endif + + #ifdef FXCG50 + row_title("Interrupt handling stress test"); + + if(time_spent == 0) + { + row_print(1, 1, "Not tested"); + } + else + { + row_print(1, 1, "%d interrupts handled in %d us", + STRESS_LIMIT, time_spent); + row_print(2, 1, "Rate is %d int/s", rate); + } + #endif + + dupdate(); + key = getkey().key; + } +}