diff options
author | Raphael Herouart <rherouart@google.com> | 2024-03-18 10:22:07 +0000 |
---|---|---|
committer | Raphael Herouart <rherouart@google.com> | 2024-03-18 10:22:07 +0000 |
commit | 12c4733a78e187828675a52f74c6442c507bec44 (patch) | |
tree | 3fb7aec3c1f30dd569377335bd134f8ca2cfa93a | |
parent | 6b48d4e44f5dabe31ba6c657e02ceb0b78b0e9c6 (diff) | |
download | trusty-12c4733a78e187828675a52f74c6442c507bec44.tar.gz |
include/shared/lk: adjust param_idx for callbacks
If BENCH_ALL_CPU() is used with parameters, the trusty_bench_get_param_name_cb will be called with param_idx values that exceed the number of parameters in the benchmark.
Bug: 330059594
Test: dc_adb shell trusty-ut-ctrl "com.android.trusty.syscall.msg.bench"
Change-Id: Ifde1fa883bd0d52361950ed4d75985889ff79375
-rw-r--r-- | include/shared/lk/trusty_bench_common.h | 1 | ||||
-rw-r--r-- | include/shared/lk/trusty_bench_json_print.h | 10 | ||||
-rw-r--r-- | include/shared/lk/trusty_bench_print_tables.h | 29 | ||||
-rw-r--r-- | include/shared/lk/trusty_benchmark.h | 2 |
4 files changed, 27 insertions, 15 deletions
diff --git a/include/shared/lk/trusty_bench_common.h b/include/shared/lk/trusty_bench_common.h index a7cadb9..629392e 100644 --- a/include/shared/lk/trusty_bench_common.h +++ b/include/shared/lk/trusty_bench_common.h @@ -89,6 +89,7 @@ struct bench_metric_list_node { struct bench_metric_node metric; const char* name; size_t param_idx; + size_t nb_params; size_t col_sz; int64_t (*bench_result)(void); trusty_bench_get_formatted_value_callback_t formatted_value_cb; diff --git a/include/shared/lk/trusty_bench_json_print.h b/include/shared/lk/trusty_bench_json_print.h index d3d4f1d..e2636ba 100644 --- a/include/shared/lk/trusty_bench_json_print.h +++ b/include/shared/lk/trusty_bench_json_print.h @@ -66,13 +66,15 @@ static inline void trusty_bench_print_json_metric_list( trusty_unittest_printf("{"); trusty_unittest_printf("\"metric_name\": \"%s\", ", entry->name); if (nb_params > 1 || trusty_bench_nb_cpu > 1) { - trusty_unittest_printf("\"param_id\": %zu, ", entry->param_idx); + trusty_unittest_printf("\"param_id\": %zu, ", + entry->param_idx % entry->nb_params); if (entry->param_name_cb) { - entry->param_name_cb(buf, sizeof(buf), entry->param_idx); + entry->param_name_cb(buf, sizeof(buf), + entry->param_idx % entry->nb_params); trusty_unittest_printf("\"param_name\": \"%s\", ", buf); } else if (trusty_bench_get_param_name_cb) { - trusty_bench_get_param_name_cb(buf, sizeof(buf), - entry->param_idx); + trusty_bench_get_param_name_cb( + buf, sizeof(buf), entry->param_idx % entry->nb_params); trusty_unittest_printf("\"param_name\": \"%s\", ", buf); } } diff --git a/include/shared/lk/trusty_bench_print_tables.h b/include/shared/lk/trusty_bench_print_tables.h index 1eb76e9..0c6c944 100644 --- a/include/shared/lk/trusty_bench_print_tables.h +++ b/include/shared/lk/trusty_bench_print_tables.h @@ -181,12 +181,14 @@ static inline void trusty_bench_compute_widths(struct list_node* metric_list, if (nb_params > 1 || trusty_bench_nb_cpu > 1) { if (entry->param_name_cb) { - entry->param_name_cb(buf, sizeof(buf), entry->param_idx); + entry->param_name_cb(buf, sizeof(buf), + entry->param_idx % entry->nb_params); } else if (trusty_bench_get_param_name_cb) { - trusty_bench_get_param_name_cb(buf, sizeof(buf), - entry->param_idx); + trusty_bench_get_param_name_cb( + buf, sizeof(buf), entry->param_idx % entry->nb_params); } else { - snprintf(buf, sizeof(buf), "%zu", entry->param_idx); + snprintf(buf, sizeof(buf), "%zu", + entry->param_idx % entry->nb_params); } size_t param_name_width = strnlen(buf, sizeof(buf)); @@ -253,11 +255,14 @@ static inline void trusty_bench_print_params(struct list_node* metric_list) { char buf[BENCH_MAX_COL_SIZE]; if (entry->param_name_cb) { - entry->param_name_cb(buf, sizeof(buf), entry->param_idx); + entry->param_name_cb(buf, sizeof(buf), + entry->param_idx % entry->nb_params); } else if (trusty_bench_get_param_name_cb) { - trusty_bench_get_param_name_cb(buf, sizeof(buf), entry->param_idx); + trusty_bench_get_param_name_cb(buf, sizeof(buf), + entry->param_idx % entry->nb_params); } else { - snprintf(buf, sizeof(buf), "%zu", entry->param_idx); + snprintf(buf, sizeof(buf), "%zu", + entry->param_idx % entry->nb_params); } trusty_bench_print_col_header(entry->col_sz, buf, true); } @@ -411,12 +416,14 @@ static inline void trusty_bench_print_vertical_metric_list( char buf[BENCH_MAX_COL_SIZE]; if (entry->param_name_cb) { - entry->param_name_cb(buf, sizeof(buf), entry->param_idx); + entry->param_name_cb(buf, sizeof(buf), + entry->param_idx % entry->nb_params); } else if (trusty_bench_get_param_name_cb) { - trusty_bench_get_param_name_cb(buf, sizeof(buf), - entry->param_idx); + trusty_bench_get_param_name_cb( + buf, sizeof(buf), entry->param_idx % entry->nb_params); } else { - snprintf(buf, sizeof(buf), "%zu", entry->param_idx); + snprintf(buf, sizeof(buf), "%zu", + entry->param_idx % entry->nb_params); } trusty_bench_print_col_header(trusty_bench_max_param_name_width, buf, false); diff --git a/include/shared/lk/trusty_benchmark.h b/include/shared/lk/trusty_benchmark.h index d0c3bf8..1bb4728 100644 --- a/include/shared/lk/trusty_benchmark.h +++ b/include/shared/lk/trusty_benchmark.h @@ -359,6 +359,7 @@ static inline void trusty_bench_reset_metrics(struct list_node* metric_list, .metric = {0, 0, 0, {INT32_MAX, 0, 0}}, \ .name = STRINGIFY(metric_name), \ .param_idx = 0, \ + .nb_params = 0, \ .bench_result = \ update_##suite_name##_##bench_name##_##metric_name, \ .formatted_value_cb = formatted_value_cb_, \ @@ -475,6 +476,7 @@ static inline struct bench_metric_list_node* set_param_metric( list_pool[idx].metric = tmp_metric; list_pool[idx].name = entry->name; list_pool[idx].param_idx = idx_param; + list_pool[idx].nb_params = nb_params; list_pool[idx].bench_result = entry->bench_result; list_pool[idx].formatted_value_cb = entry->formatted_value_cb; list_pool[idx].param_name_cb = entry->param_name_cb; |