/** * * @brief Memory pool get/free test * * @return N/A */ void mempool_test(void) { u32_t et; /* elapsed time */ int i; s32_t return_value = 0; struct k_mem_block block; PRINT_STRING(dashline, output_file); et = BENCH_START(); for (i = 0; i < NR_OF_POOL_RUNS; i++) { return_value |= k_mem_pool_alloc(&DEMOPOOL, &block, 16, K_FOREVER); k_mem_pool_free(&block); } et = TIME_STAMP_DELTA_GET(et); check_result(); if (return_value != 0) { k_panic(); } PRINT_F(output_file, FORMAT, "average alloc and dealloc memory pool block", SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, (2 * NR_OF_POOL_RUNS))); }
/** * * @brief Test ISR used to measure best case interrupt latency * * The interrupt handler gets the second timestamp. * * @return N/A */ static void latency_test_isr(void *unused) { ARG_UNUSED(unused); k_alert_send(&EVENT0); timestamp = TIME_STAMP_DELTA_GET(0); }
/** * * @brief Test ISR used to measure best case interrupt latency * * The interrupt handler gets the second timestamp. * * @return N/A */ static void latencyTestIsr(void *unused) { ARG_UNUSED(unused); nano_isr_sem_give(&testSema); timestamp = TIME_STAMP_DELTA_GET(0); }
/** * * @brief Test ISR used to measure best case interrupt latency * * The interrupt handler gets the second timestamp. * * @return N/A */ static void latencyTestIsr(void *unused) { ARG_UNUSED(unused); flagVar = 1; timestamp = TIME_STAMP_DELTA_GET(0); }
/** * * @brief Interrupt preparation fiber * * Fiber makes all the test preparations: registers the interrupt handler, * gets the first timestamp and invokes the software interrupt. * * @return N/A */ static void fiberInt(void) { flagVar = 0; irq_offload(latencyTestIsr, NULL); if (flagVar != 1) { PRINT_FORMAT(" Flag variable has not changed. FAILED"); } else { timestamp = TIME_STAMP_DELTA_GET(timestamp); } }
/** * * @brief The test main function * * @return 0 on success */ int int_to_thread_evt(void) { PRINT_FORMAT(" 2 - Measure time from ISR to executing a different thread" " (rescheduled)"); TICK_SYNCH(); k_sem_give(&INTSEMA); k_alert_recv(&EVENT0, K_FOREVER); timestamp = TIME_STAMP_DELTA_GET(timestamp); PRINT_FORMAT(" switch time is %u tcs = %u nsec", timestamp, SYS_CLOCK_HW_CYCLES_TO_NS(timestamp)); return 0; }
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; }
/** * * @brief The test main function * * @return 0 on success */ int nanoIntLockUnlock(void) { int i; unsigned int mask; PRINT_FORMAT(" 5- Measure average time to lock then unlock interrupts"); bench_test_start(); timestamp = TIME_STAMP_DELTA_GET(0); for (i = 0; i < NTESTS; i++) { mask = irq_lock(); irq_unlock(mask); } timestamp = TIME_STAMP_DELTA_GET(timestamp); if (bench_test_end() == 0) { PRINT_FORMAT(" Average time for lock then unlock " "is %lu tcs = %lu nsec", timestamp / NTESTS, SYS_CLOCK_HW_CYCLES_TO_NS_AVG(timestamp, NTESTS)); } else { errorCount++; PRINT_OVERFLOW_ERROR(); } return 0; }
/** * * @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))); }
/** * * @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(); }
/** * * @brief Interrupt preparation fiber * * Fiber makes all the test preparations: registers the interrupt handler, * gets the first timestamp and invokes the software interrupt. * * @return N/A */ static void fiberInt(void) { timestamp = TIME_STAMP_DELTA_GET(0); irq_offload(latencyTestIsr, NULL); }
/** * * @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; }
/** * * @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)); }
/** * * @brief Check the time when it gets executed after the semaphore * * Fiber starts, waits on semaphore. When the interrupt handler releases * the semaphore, fiber measures the time. * * @return N/A */ static void fiberWaiter(void) { nano_fiber_sem_take(&testSema, TICKS_UNLIMITED); timestamp = TIME_STAMP_DELTA_GET(timestamp); }