/** * * @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 Checks number of tests and calculate average time * * @return 1 if success and 0 on failure * * @param i Number of tests. * @param t Time in ticks for the whole test. */ int check_result(int i, uint32_t t) { /* * bench_test_end checks tCheck static variable. * bench_test_start modifies it */ if (bench_test_end() != 0) { fprintf(output_file, sz_case_result_fmt, sz_fail); fprintf(output_file, sz_case_details_fmt, "timer tick happened. Results are inaccurate"); fprintf(output_file, sz_case_end_fmt); return 0; } if (i != NUMBER_OF_LOOPS) { fprintf(output_file, sz_case_result_fmt, sz_fail); fprintf(output_file, sz_case_details_fmt, "loop counter = "); fprintf(output_file, "%i !!!", i); fprintf(output_file, sz_case_end_fmt); return 0; } fprintf(output_file, sz_case_result_fmt, sz_success); fprintf(output_file, sz_case_details_fmt, "Average time for 1 iteration: "); fprintf(output_file, sz_case_timing_fmt, SYS_CLOCK_HW_CYCLES_TO_NS_AVG(t, NUMBER_OF_LOOPS)); fprintf(output_file, sz_case_end_fmt); return 1; }
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 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 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 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)); }