gintctl/src/perf/libprof.c

89 lines
1.8 KiB
C
Raw Permalink Normal View History

2019-07-17 18:59:17 +02:00
#include <gint/keyboard.h>
#include <gint/display.h>
#include <gint/timer.h>
2019-07-17 18:59:17 +02:00
#include <gintctl/util.h>
#include <gintctl/perf.h>
#include <libprof.h>
2019-07-18 23:53:54 +02:00
/* Waits some time and returns the libprof output in microseconds */
static uint32_t run_sleep(int us)
2019-07-17 18:59:17 +02:00
{
/* We can't use sleep_us() as we want a TMU */
volatile int flag = 0;
2021-04-27 14:57:27 +02:00
int timer = timer_configure(TIMER_TMU, us, GINT_CALL_SET_STOP(&flag));
if(timer < 0) return 0;
return prof_exec({
timer_start(timer);
timer_wait(timer);
});
2019-07-18 23:53:54 +02:00
}
/* Measure overhead of an empty context */
static uint32_t run_empty(void)
{
return prof_exec();
2019-07-17 18:59:17 +02:00
}
/* gintctl_perf_libprof(): Test the libprof implementation */
void gintctl_perf_libprof(void)
{
2019-07-18 23:53:54 +02:00
int key=0, test=0, delay=10000;
uint32_t sleep_delay = 0;
uint32_t empty = 0;
2019-07-17 18:59:17 +02:00
while(key != KEY_EXIT)
{
dclear(C_WHITE);
#ifdef FX9860G
2019-07-18 23:53:54 +02:00
row_print(1, 1, "Measures time for");
row_print(2, 1, "10ms sleep +1us each");
row_print(3, 1, "time, and empty code.");
2019-07-17 18:59:17 +02:00
2019-07-18 23:53:54 +02:00
if(test)
{
row_print(5, 1, "Sleep: %.3D ms", sleep_delay);
2019-07-18 23:53:54 +02:00
row_print(6, 1, "Empty: %d us", empty);
}
2019-07-17 18:59:17 +02:00
extern bopti_image_t img_opt_perf_libprof;
dimage(0, 56, &img_opt_perf_libprof);
2019-07-18 23:53:54 +02:00
#endif /* FX9860G */
2019-07-17 18:59:17 +02:00
#ifdef FXCG50
2019-07-18 23:53:54 +02:00
row_title("libprof basics");
2019-07-17 18:59:17 +02:00
row_print(1, 1, "This program shows the execution time "
"measured");
2019-08-04 14:07:56 +02:00
row_print(2, 1, "by libprof for a 100 ms sleep, with 1 us "
2019-07-17 18:59:17 +02:00
"added");
row_print(3, 1, "each time.");
row_print(5, 1, "Press F1 to start the test.");
2019-07-18 23:53:54 +02:00
if(test)
{
row_print(7, 1, "Sleep: %.3D ms", sleep_delay);
2019-07-18 23:53:54 +02:00
row_print(8, 1, "Empty: %d us", empty);
row_print(9, 1, "Tests: %d", test);
}
2019-07-17 18:59:17 +02:00
fkey_button(1, "START");
2019-07-18 23:53:54 +02:00
#endif /* FXCG50 */
2019-07-17 18:59:17 +02:00
dupdate();
key = getkey().key;
2019-07-18 23:53:54 +02:00
if(key == KEY_F1)
{
sleep_delay = run_sleep(delay);
empty = run_empty();
delay++;
test++;
}
2019-07-17 18:59:17 +02:00
}
}