int pipeget(kpipe_t pipe, K_PIPE_OPTION option, int size, int count, unsigned int* time) { int i; unsigned int t; int sizexferd_total = 0; int size2xfer_total = size * count; /* sync with the sender */ task_sem_take_wait(SEM0); t = BENCH_START(); for (i = 0; _1_TO_N == option || (i < count); i++) { int sizexferd = 0; int size2xfer = min(size, size2xfer_total - sizexferd_total); int ret; ret = task_pipe_get_wait(pipe, data_recv, size2xfer, &sizexferd, option); if (RC_OK != ret) { return 1; } if (_ALL_N == option && sizexferd != size2xfer) { return 1; } sizexferd_total += sizexferd; if (size2xfer_total == sizexferd_total) { break; } if (size2xfer_total < sizexferd_total) { return 1; } } t = TIME_STAMP_DELTA_GET(t); *time = SYS_CLOCK_HW_CYCLES_TO_NS_AVG(t, count); if (bench_test_end() < 0) { if (high_timer_overflow()) { PRINT_STRING("| Timer overflow. Results are invalid ", output_file); } else { PRINT_STRING("| Tick occured. Results may be inaccurate ", output_file); } PRINT_STRING(" |\n", output_file); } return 0; }
static void bench_mutex() { pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t rmutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; /* pthread_mutex lock/unlock */ BENCH_START(); BENCH_LOOP() { pthread_mutex_lock( &mutex ); pthread_mutex_unlock( &mutex ); } BENCH_STOP(); printf( "mutex lock/unlock -> %8.2f k/sec\n", BENCH_RESULT() ); /* pthread_mutex lock/unlock */ BENCH_START(); BENCH_LOOP() { pthread_mutex_lock( &rmutex ); pthread_mutex_unlock( &rmutex ); } BENCH_STOP(); printf( "mutex lock/unlock (recursive) -> %8.2f k/sec\n", BENCH_RESULT() ); pthread_mutex_destroy( &mutex ); pthread_mutex_destroy( &rmutex ); printf( "\n" ); }
/** * * @brief Mutex lock/unlock test * * @return N/A */ void mutex_test(void) { u32_t et; /* elapsed time */ int i; PRINT_STRING(dashline, output_file); et = BENCH_START(); for (i = 0; i < NR_OF_MUTEX_RUNS; i++) { k_mutex_lock(&DEMO_MUTEX, K_FOREVER); k_mutex_unlock(&DEMO_MUTEX); } et = TIME_STAMP_DELTA_GET(et); check_result(); PRINT_F(output_file, FORMAT, "average lock and unlock mutex", SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, (2 * NR_OF_MUTEX_RUNS))); }
void Program::term(void) { BENCH_START(); delete mp_UnitManager; mp_UnitManager = nullptr; delete mp_InputManager; mp_InputManager = nullptr; delete mp_DataManager; mp_DataManager = nullptr; destroyWindow(); BENCH_PRINT("Program::term"); }
static void bench_shmpool( bool debug ) { DirectResult ret; void *mem[256]; const int sizes[8] = { 12, 36, 200, 120, 39, 3082, 8, 1040 }; FusionSHMPoolShared *pool; ret = fusion_shm_pool_create( world, "Benchmark Pool", 524288, debug, &pool ); if (ret) { DirectFBError( "fusion_shm_pool_create() failed", ret ); return; } BENCH_START(); BENCH_LOOP() { int i; for (i=0; i<128; i++) mem[i] = SHMALLOC( pool, sizes[i&7] ); for (i=0; i<64; i++) SHFREE( pool, mem[i] ); for (i=128; i<192; i++) mem[i] = SHMALLOC( pool, sizes[i&7] ); for (i=64; i<128; i++) SHFREE( pool, mem[i] ); for (i=192; i<256; i++) mem[i] = SHMALLOC( pool, sizes[i&7] ); for (i=128; i<256; i++) SHFREE( pool, mem[i] ); } BENCH_STOP(); printf( "shm pool alloc/free %s -> %8.2f k/sec\n", debug ? "(debug)" : " ", BENCH_RESULT_BY(256) ); fusion_shm_pool_destroy( world, pool ); }
/** * * @brief Write the number of data chunks into the mailbox * * @param size The size of the data chunk. * @param count Number of data chunks. * @param time The total time. * * @return N/A */ void mailbox_put(u32_t size, int count, u32_t *time) { int i; unsigned int t; Message.rx_source_thread = K_ANY; Message.tx_target_thread = K_ANY; /* first sync with the receiver */ k_sem_give(&SEM0); t = BENCH_START(); for (i = 0; i < count; i++) { k_mbox_put(&MAILB1, &Message, K_FOREVER); } t = TIME_STAMP_DELTA_GET(t); *time = SYS_CLOCK_HW_CYCLES_TO_NS_AVG(t, count); check_result(); }
void Program::createWindow(void) { BENCH_START(); mp_Window = SDL_CreateWindow( "Dinner Rush - A Pathing AI Test", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1024, 768, SDL_WINDOW_SHOWN ); if (!mp_Window) { die("Failed to create window"); } mp_Renderer = SDL_CreateRenderer(mp_Window, -1, SDL_RENDERER_ACCELERATED); BENCH_PRINT("Program::createWindow"); }
Program::Program(void) : m_TargetFPS(), m_CurrentFPS(), m_UpdateInterval(), mp_DataManager(nullptr), mp_InputManager(nullptr), mp_UnitManager(nullptr), mp_Window(nullptr), mp_Renderer(nullptr) { BENCH_START(); if (SDL_Init(SDL_INIT_VIDEO)) { die("Failed to initialize SDL"); } if (TTF_Init()) { die("Failed to initialize SDL TTF"); } BENCH_PRINT("Program::ctor"); }
void Program::init(void) { BENCH_START(); createWindow(); setTargetFPS(60.0); mp_DataManager = New DataManager(); mp_DataManager->loadData("GameData.bin"); mp_DataManager->saveData("GameData.out.txt"); mp_DataManager->saveData("GameData.out.bin"); mp_InputManager = New InputManager(); mp_UnitManager = New UnitManager(); Unit *pTestUnit = New Unit(); mp_UnitManager->addUnit(pTestUnit); mp_UnitManager->addTag("test", pTestUnit); BENCH_PRINT("Program::init"); }
static void bench_skirmish_threaded() { int i; DirectResult ret; FusionSkirmish skirmish; ret = fusion_skirmish_init( &skirmish, "Threaded Benchmark", world ); if (ret) { fprintf( stderr, "Fusion Error %d\n", ret ); return; } /* skirmish prevail/dismiss (2-5 threads) */ for (i=2; i<=5; i++) { int t; pthread_t threads[i]; BENCH_START(); for (t=0; t<i; t++) pthread_create( &threads[t], NULL, prevail_dismiss_loop, &skirmish ); for (t=0; t<i; t++) pthread_join( threads[t], NULL ); BENCH_STOP(); printf( "skirmish prevail/dismiss (%d threads) -> %8.2f k/sec\n", i, BENCH_RESULT() ); } fusion_skirmish_destroy( &skirmish ); printf( "\n" ); }
/** * * @brief The main test entry * * @return 1 if success and 0 on failure */ int lifo_test(void) { uint32_t t; int i = 0; int return_value = 0; int element[2]; int j; nano_fifo_init(&nanoFifo_sync); /* test get wait & put fiber functions */ fprintf(output_file, sz_test_case_fmt, "LIFO #1"); fprintf(output_file, sz_description, "\n\tnano_lifo_init" "\n\tnano_fiber_lifo_get(TICKS_UNLIMITED)" "\n\tnano_fiber_lifo_put"); printf(sz_test_start_fmt); lifo_test_init(); t = BENCH_START(); task_fiber_start(fiber_stack1, STACK_SIZE, lifo_fiber1, 0, NUMBER_OF_LOOPS, 3, 0); task_fiber_start(fiber_stack2, STACK_SIZE, lifo_fiber2, (int) &i, NUMBER_OF_LOOPS, 3, 0); t = TIME_STAMP_DELTA_GET(t); return_value += check_result(i, t); /* fibers have done their job, they can stop now safely: */ for (j = 0; j < 2; j++) { nano_task_fifo_put(&nanoFifo_sync, (void *) element); } /* test get/yield & put fiber functions */ fprintf(output_file, sz_test_case_fmt, "LIFO #2"); fprintf(output_file, sz_description, "\n\tnano_lifo_init" "\n\tnano_fiber_lifo_get(TICKS_UNLIMITED)" "\n\tnano_fiber_lifo_get(TICKS_NONE)" "\n\tnano_fiber_lifo_put" "\n\tfiber_yield"); printf(sz_test_start_fmt); lifo_test_init(); t = BENCH_START(); i = 0; task_fiber_start(fiber_stack1, STACK_SIZE, lifo_fiber1, 0, NUMBER_OF_LOOPS, 3, 0); task_fiber_start(fiber_stack2, STACK_SIZE, lifo_fiber3, (int) &i, NUMBER_OF_LOOPS, 3, 0); t = TIME_STAMP_DELTA_GET(t); return_value += check_result(i, t); /* fibers have done their job, they can stop now safely: */ for (j = 0; j < 2; j++) { nano_task_fifo_put(&nanoFifo_sync, (void *) element); } /* test get wait & put fiber/task functions */ fprintf(output_file, sz_test_case_fmt, "LIFO #3"); fprintf(output_file, sz_description, "\n\tnano_lifo_init" "\n\tnano_fiber_lifo_get(TICKS_UNLIMITED)" "\n\tnano_fiber_lifo_put" "\n\tnano_task_lifo_get(TICKS_UNLIMITED)" "\n\tnano_task_lifo_put"); printf(sz_test_start_fmt); lifo_test_init(); t = BENCH_START(); task_fiber_start(fiber_stack1, STACK_SIZE, lifo_fiber1, 0, NUMBER_OF_LOOPS, 3, 0); for (i = 0; i < NUMBER_OF_LOOPS / 2; i++) { int element[2]; int *pelement; element[1] = 2 * i; nano_task_lifo_put(&nanoLifo1, element); element[1] = 2 * i + 1; nano_task_lifo_put(&nanoLifo1, element); pelement = (int *)nano_task_lifo_get(&nanoLifo2, TICKS_UNLIMITED); if (pelement[1] != 2 * i + 1) { break; } pelement = (int *)nano_task_lifo_get(&nanoLifo2, TICKS_UNLIMITED); if (pelement[1] != 2 * i) { break; } } t = TIME_STAMP_DELTA_GET(t); return_value += check_result(i * 2, t); /* fibers have done their job, they can stop now safely: */ for (j = 0; j < 2; j++) { nano_task_fifo_put(&nanoFifo_sync, (void *) element); } return return_value; }
int stack_test(void) { uint32_t t; int i = 0; int return_value = 0; /* test get wait & put fiber functions */ fprintf(output_file, sz_test_case_fmt, "Stack #1"); fprintf(output_file, sz_description, "\n\tnano_stack_init" "\n\tnano_fiber_stack_pop_wait" "\n\tnano_fiber_stack_push"); printf(sz_test_start_fmt); stack_test_init(); t = BENCH_START(); task_fiber_start(fiber_stack1, STACK_SIZE, stack_fiber1, 0, NUMBER_OF_LOOPS, 3, 0); task_fiber_start(fiber_stack2, STACK_SIZE, stack_fiber2, (int) &i, NUMBER_OF_LOOPS, 3, 0); t = TIME_STAMP_DELTA_GET(t); return_value += check_result(i, t); /* test get/yield & put fiber functions */ fprintf(output_file, sz_test_case_fmt, "Stack #2"); fprintf(output_file, sz_description, "\n\tnano_stack_init" "\n\tnano_fiber_stack_pop_wait" "\n\tnano_fiber_stack_pop" "\n\tnano_fiber_stack_push" "\n\tfiber_yield"); printf(sz_test_start_fmt); stack_test_init(); t = BENCH_START(); i = 0; task_fiber_start(fiber_stack1, STACK_SIZE, stack_fiber1, 0, NUMBER_OF_LOOPS, 3, 0); task_fiber_start(fiber_stack2, STACK_SIZE, stack_fiber3, (int) &i, NUMBER_OF_LOOPS, 3, 0); t = TIME_STAMP_DELTA_GET(t); return_value += check_result(i, t); /* test get wait & put fiber/task functions */ fprintf(output_file, sz_test_case_fmt, "Stack #3"); fprintf(output_file, sz_description, "\n\tnano_stack_init" "\n\tnano_fiber_stack_pop_wait" "\n\tnano_fiber_stack_push" "\n\tnano_task_stack_pop_wait" "\n\tnano_task_stack_push"); printf(sz_test_start_fmt); stack_test_init(); t = BENCH_START(); task_fiber_start(fiber_stack1, STACK_SIZE, stack_fiber1, 0, NUMBER_OF_LOOPS, 3, 0); for (i = 0; i < NUMBER_OF_LOOPS / 2; i++) { uint32_t data; data = 2 * i; nano_task_stack_push(&nano_stack_1, data); data = 2 * i + 1; nano_task_stack_push(&nano_stack_1, data); data = nano_task_stack_pop_wait(&nano_stack_2); if (data != 2 * i + 1) { break; } data = nano_task_stack_pop_wait(&nano_stack_2); if (data != 2 * i) { break; } } t = TIME_STAMP_DELTA_GET(t); return_value += check_result(i * 2, t); return return_value; }
static void bench_reactor() { FusionReactor *reactor; Reaction reaction; Reaction reaction2; GlobalReaction global_reaction; reactor = fusion_reactor_new( 16, "Benchmark", world ); if (!reactor) { fprintf( stderr, "Fusion Error\n" ); return; } /* reactor attach/detach */ BENCH_START(); BENCH_LOOP() { fusion_reactor_attach( reactor, reaction_callback, NULL, &reaction ); fusion_reactor_detach( reactor, &reaction ); } BENCH_STOP(); printf( "reactor attach/detach -> %8.2f k/sec\n", BENCH_RESULT() ); /* reactor attach/detach (2nd) */ fusion_reactor_attach( reactor, reaction_callback, NULL, &reaction ); BENCH_START(); BENCH_LOOP() { fusion_reactor_attach( reactor, reaction_callback, NULL, &reaction2 ); fusion_reactor_detach( reactor, &reaction2 ); } BENCH_STOP(); fusion_reactor_detach( reactor, &reaction ); printf( "reactor attach/detach (2nd) -> %8.2f k/sec\n", BENCH_RESULT() ); /* reactor attach/detach (global) */ fusion_reactor_attach( reactor, reaction_callback, NULL, &reaction ); BENCH_START(); BENCH_LOOP() { fusion_reactor_attach_global( reactor, 0, NULL, &global_reaction ); fusion_reactor_detach_global( reactor, &global_reaction ); } BENCH_STOP(); fusion_reactor_detach( reactor, &reaction ); printf( "reactor attach/detach (global) -> %8.2f k/sec\n", BENCH_RESULT() ); /* reactor dispatch */ fusion_reactor_attach( reactor, reaction_callback, NULL, &reaction ); BENCH_START(); BENCH_LOOP() { char msg[16]; fusion_reactor_dispatch( reactor, msg, true, NULL ); } BENCH_STOP(); printf( "reactor dispatch -> %8.2f k/sec\n", BENCH_RESULT() ); fusion_reactor_detach( reactor, &reaction ); fusion_reactor_free( reactor ); printf( "\n" ); }
/** * * @brief Semaphore signal speed test * * @return N/A */ void sema_test(void) { uint32_t et; /* elapsed Time */ int i; PRINT_STRING(dashline, output_file); et = BENCH_START(); for (i = 0; i < NR_OF_SEMA_RUNS; i++) { task_sem_give(SEM0); } et = TIME_STAMP_DELTA_GET(et); check_result(); PRINT_F(output_file, FORMAT, "signal semaphore", SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS)); task_sem_reset(SEM1); task_sem_give(STARTRCV); et = BENCH_START(); for (i = 0; i < NR_OF_SEMA_RUNS; i++) { task_sem_give(SEM1); } et = TIME_STAMP_DELTA_GET(et); check_result(); PRINT_F(output_file, FORMAT, "signal to waiting high pri task", SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS)); et = BENCH_START(); for (i = 0; i < NR_OF_SEMA_RUNS; i++) { task_sem_give(SEM1); } et = TIME_STAMP_DELTA_GET(et); check_result(); PRINT_F(output_file, FORMAT, "signal to waiting high pri task, with timeout", SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS)); et = BENCH_START(); for (i = 0; i < NR_OF_SEMA_RUNS; i++) { task_sem_give(SEM2); } et = TIME_STAMP_DELTA_GET(et); check_result(); PRINT_F(output_file, FORMAT, "signal to waitm (2)", SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS)); et = BENCH_START(); for (i = 0; i < NR_OF_SEMA_RUNS; i++) { task_sem_give(SEM2); } et = TIME_STAMP_DELTA_GET(et); check_result(); PRINT_F(output_file, FORMAT, "signal to waitm (2), with timeout", SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS)); et = BENCH_START(); for (i = 0; i < NR_OF_SEMA_RUNS; i++) { task_sem_give(SEM3); } et = TIME_STAMP_DELTA_GET(et); check_result(); PRINT_F(output_file, FORMAT, "signal to waitm (3)", SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS)); et = BENCH_START(); for (i = 0; i < NR_OF_SEMA_RUNS; i++) { task_sem_give(SEM3); } et = TIME_STAMP_DELTA_GET(et); check_result(); PRINT_F(output_file, FORMAT, "signal to waitm (3), with timeout", SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS)); et = BENCH_START(); for (i = 0; i < NR_OF_SEMA_RUNS; i++) { task_sem_give(SEM4); } et = TIME_STAMP_DELTA_GET(et); check_result(); PRINT_F(output_file, FORMAT, "signal to waitm (4)", SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS)); et = BENCH_START(); for (i = 0; i < NR_OF_SEMA_RUNS; i++) { task_sem_give(SEM4); } et = TIME_STAMP_DELTA_GET(et); check_result(); PRINT_F(output_file, FORMAT, "signal to waitm (4), with timeout", SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS)); }