diff options
author | Raphael Herouart <rherouart@google.com> | 2023-07-25 14:46:57 +0000 |
---|---|---|
committer | Raphaël Hérouart <rherouart@google.com> | 2023-12-01 05:12:21 +0000 |
commit | f4ab22408946529221691978d0bcfc6ee4bd4109 (patch) | |
tree | 74bad38f86e9b2b1d24a64b7182778d628c0607f | |
parent | 43bd94934f4f4270c081bdc8a7cc8ff3556c3365 (diff) | |
download | trusty-f4ab22408946529221691978d0bcfc6ee4bd4109.tar.gz |
include/shared/lk: benchmark cleanup
- "get_extended_test_name" is renamed to "get_extended_bench_name"
- An error is displayed in main console (rather than UART/verbose) for tests whose min runtime is less than 5 time max "get_time" overhead
Bug: None
Change-Id: I121cc5f744c47d4ecf7cecf0734e612c43d3df0a
-rw-r--r-- | include/shared/lk/trusty_benchmark.h | 213 |
1 files changed, 107 insertions, 106 deletions
diff --git a/include/shared/lk/trusty_benchmark.h b/include/shared/lk/trusty_benchmark.h index 8b26e6a..8e13fcf 100644 --- a/include/shared/lk/trusty_benchmark.h +++ b/include/shared/lk/trusty_benchmark.h @@ -434,7 +434,7 @@ static int64_t trusty_bench_get_overhead(void) { } /** - * get_extended_test_name - Print Status of Currently Running Bench. + * get_extended_bench_name - Print Status of Currently Running Bench. * * @test_name_in: Name of the Current Unparameterized Test. * @test_name_out: Name of the Current Unparameterized Test. @@ -444,8 +444,8 @@ static int64_t trusty_bench_get_overhead(void) { * If test_name_out allocation/print failed returns asprintf * return code */ -static inline int get_extended_test_name(const char* test_name_in, - char** test_name_out) { +static inline int get_extended_bench_name(const char* test_name_in, + char** test_name_out) { int res = snprintf(NULL, 0, "%s_%zu", test_name_in, bench_state.cur_param_idx); *test_name_out = NULL; @@ -474,109 +474,110 @@ static inline int get_extended_test_name(const char* test_name_in, * @params: An array T array_name[nb_params] of parameter * @metric_list: List of metric nodes to update */ -#define BENCH_CORE(suite_name, bench_name, nb_runs, nb_params, params, \ - metric_list) \ - reset_vertical_print_widths(); \ - trusty_bench_print_title(STRINGIFY(suite_name), STRINGIFY(bench_name), \ - STRINGIFY(params)); \ - static trusty_bench_print_callback_t trusty_bench_print_cb = \ - &BENCHMARK_PRINT_CB; \ - trusty_cur_bench_nb_params = nb_params; \ - for (size_t idx_param = 0; idx_param < (nb_params * trusty_bench_nb_cpu); \ - ++idx_param) { \ - bench_state.cur_param_idx = idx_param; \ - char* extended_test_name = NULL; \ - int res_alloc = get_extended_test_name( \ - STRINGIFY(bench_name##_##params), &extended_test_name); \ - if (res_alloc < 0) { \ - TLOGE("ERROR %d expanding test name\n", res_alloc); \ - _test_context.all_ok = false; \ - _test_context.tests_failed++; \ - continue; \ - } \ - TEST_BEGIN_FUNC(STRINGIFY(suite_name), extended_test_name); \ - \ - int rc = trusty_bench_multi_cpus_setup(); \ - if (rc != NO_ERROR) { \ - _test_context.skipped = true; \ - _test_context.tests_skipped++; \ - } else { \ - rc = suite_name##_setup(); \ - } \ - \ - if (_test_context.skipped) { \ - trusty_unittest_print_status(" SKIPPED"); \ - continue; \ - } else if (rc != NO_ERROR) { \ - TLOGE("ERROR %d during benchmark setup\n", rc); \ - _test_context.all_ok = false; \ - _test_context.tests_failed++; \ - continue; \ - } \ - int64_t overhead = trusty_bench_get_overhead(); \ - \ - /* Cold Run */ \ - int64_t start_time; \ - int64_t end_time; \ - start_time = get_current_time_ns(); \ - int64_t res = suite_name##_##bench_name##_inner_##params(); \ - end_time = get_current_time_ns(); \ - \ - if (res != NO_ERROR) { \ - TLOGE("ERROR During Cold Run%" PRId64 "\n", res); \ - _test_context.all_ok = false; \ - _test_context.tests_failed++; \ - continue; \ - } \ - \ - bench_state.last_bench_body_duration = end_time - start_time; \ - if (overhead >= bench_state.last_bench_body_duration) { \ - TLOGE("Benchmark internal function is too fast %" PRId64 \ - "ns, while the benchmark overhead is %" PRId64 "ns.\n", \ - overhead, bench_state.last_bench_body_duration); \ - } \ - \ - bench_state.last_bench_body_duration -= overhead; \ - \ - if (!_test_context.hard_fail && _test_context.all_ok) { \ - trusty_bench_run_metrics(&metric_list, idx_param, true); \ - } \ - \ - for (size_t idx_run = 0; idx_run < nb_runs; ++idx_run) { \ - if (!_test_context.hard_fail && _test_context.all_ok) { \ - start_time = get_current_time_ns(); \ - res = suite_name##_##bench_name##_inner_##params(); \ - end_time = get_current_time_ns(); \ - bench_state.last_bench_body_duration = end_time - start_time; \ - if (overhead >= bench_state.last_bench_body_duration) { \ - TLOGE("Benchmark internal function is too fast %" PRId64 \ - "ns, while the benchmark overhead is %" PRId64 \ - "ns.", \ - overhead, bench_state.last_bench_body_duration); \ - } \ - \ - bench_state.last_bench_body_duration -= overhead; \ - if (res != NO_ERROR) { \ - TLOGE("ERROR %" PRId64 "\n", res); \ - } \ - } \ - if (!_test_context.hard_fail && _test_context.all_ok) { \ - trusty_bench_run_metrics(&metric_list, idx_param, false); \ - } \ - } \ - suite_name##_teardown(); \ - rc = trusty_bench_multi_cpus_teardown(); \ - if (rc != NO_ERROR) { \ - TLOGW("failed to reset CPU affinity: %d\n", rc); \ - } \ - TEST_END_FUNC(); \ - free(extended_test_name); \ - extended_test_name = NULL; \ - } \ - trusty_bench_print_cb(&metric_list, (nb_params * trusty_bench_nb_cpu), \ - STRINGIFY(suite_name), \ - STRINGIFY(bench_name##_##params)); \ - trusty_bench_get_param_name_cb = NULL; \ +#define BENCH_CORE(suite_name, bench_name, nb_runs, nb_params, params, \ + metric_list) \ + reset_vertical_print_widths(); \ + trusty_bench_print_title(STRINGIFY(suite_name), STRINGIFY(bench_name), \ + STRINGIFY(params)); \ + static trusty_bench_print_callback_t trusty_bench_print_cb = \ + &BENCHMARK_PRINT_CB; \ + trusty_cur_bench_nb_params = nb_params; \ + for (size_t idx_param = 0; idx_param < (nb_params * trusty_bench_nb_cpu); \ + ++idx_param) { \ + bench_state.cur_param_idx = idx_param; \ + char* extended_test_name = NULL; \ + int res_alloc = get_extended_bench_name( \ + STRINGIFY(bench_name##_##params), &extended_test_name); \ + if (res_alloc < 0) { \ + TLOGE("ERROR %d expanding test name\n", res_alloc); \ + _test_context.all_ok = false; \ + _test_context.tests_failed++; \ + continue; \ + } \ + TEST_BEGIN_FUNC(STRINGIFY(suite_name), extended_test_name); \ + \ + int rc = trusty_bench_multi_cpus_setup(); \ + if (rc != NO_ERROR) { \ + _test_context.skipped = true; \ + _test_context.tests_skipped++; \ + } else { \ + rc = suite_name##_setup(); \ + } \ + \ + if (_test_context.skipped) { \ + trusty_unittest_print_status(" SKIPPED"); \ + continue; \ + } else if (rc != NO_ERROR) { \ + TLOGE("ERROR %d during benchmark setup\n", rc); \ + _test_context.all_ok = false; \ + _test_context.tests_failed++; \ + continue; \ + } \ + int64_t overhead = trusty_bench_get_overhead(); \ + \ + /* Cold Run */ \ + int64_t start_time; \ + int64_t end_time; \ + start_time = get_current_time_ns(); \ + int64_t res = suite_name##_##bench_name##_inner_##params(); \ + end_time = get_current_time_ns(); \ + \ + if (res != NO_ERROR) { \ + TLOGE("ERROR During Cold Run%" PRId64 "\n", res); \ + _test_context.all_ok = false; \ + _test_context.tests_failed++; \ + continue; \ + } \ + \ + bench_state.last_bench_body_duration = end_time - start_time; \ + if (5 * overhead >= bench_state.last_bench_body_duration) { \ + trusty_unittest_printf( \ + "WARNING: Benchmark internal function is too fast %" PRId64 \ + "ns, while the benchmark overhead is %" PRId64 "ns.", \ + overhead, bench_state.last_bench_body_duration); \ + } \ + \ + bench_state.last_bench_body_duration -= overhead; \ + \ + if (!_test_context.hard_fail && _test_context.all_ok) { \ + trusty_bench_run_metrics(&metric_list, idx_param, true); \ + } \ + \ + for (size_t idx_run = 0; idx_run < nb_runs; ++idx_run) { \ + if (!_test_context.hard_fail && _test_context.all_ok) { \ + start_time = get_current_time_ns(); \ + res = suite_name##_##bench_name##_inner_##params(); \ + end_time = get_current_time_ns(); \ + bench_state.last_bench_body_duration = end_time - start_time; \ + if (overhead >= bench_state.last_bench_body_duration) { \ + TLOGE("Benchmark internal function is too fast %" PRId64 \ + "ns, while the benchmark overhead is %" PRId64 \ + "ns.", \ + overhead, bench_state.last_bench_body_duration); \ + } \ + \ + bench_state.last_bench_body_duration -= overhead; \ + if (res != NO_ERROR) { \ + TLOGE("ERROR %" PRId64 "\n", res); \ + } \ + } \ + if (!_test_context.hard_fail && _test_context.all_ok) { \ + trusty_bench_run_metrics(&metric_list, idx_param, false); \ + } \ + } \ + suite_name##_teardown(); \ + rc = trusty_bench_multi_cpus_teardown(); \ + if (rc != NO_ERROR) { \ + TLOGW("failed to reset CPU affinity: %d\n", rc); \ + } \ + TEST_END_FUNC(); \ + free(extended_test_name); \ + extended_test_name = NULL; \ + } \ + trusty_bench_print_cb(&metric_list, (nb_params * trusty_bench_nb_cpu), \ + STRINGIFY(suite_name), \ + STRINGIFY(bench_name##_##params)); \ + trusty_bench_get_param_name_cb = NULL; \ trusty_bench_get_formatted_value_cb = NULL /** |