summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRaphael Herouart <rherouart@google.com>2024-02-16 03:53:29 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2024-02-16 03:53:29 +0000
commit1f317348c79cfda362f85dd8951933a87b149c67 (patch)
tree05db321e5de56aad4085a72311b3665d330fcbfa
parentffca5d093965d985a6416d18c5e3246bd5c0cd07 (diff)
parent5f990236ab3e86e8a94e08154f802ca3860ae3c8 (diff)
downloadtrusty-1f317348c79cfda362f85dd8951933a87b149c67.tar.gz
app/memorylatencybench: Find AMAT for different cache sizes am: 5f990236ab
Original change: https://android-review.googlesource.com/c/trusty/lk/trusty/+/2624450 Change-Id: I73e238c12b4568cffa347d9567a2206b5bc46092 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--app/memorylatencybench/main.c128
-rw-r--r--include/shared/lk/trusty_bench_print_tables.h6
2 files changed, 119 insertions, 15 deletions
diff --git a/app/memorylatencybench/main.c b/app/memorylatencybench/main.c
index 937e629..7139896 100644
--- a/app/memorylatencybench/main.c
+++ b/app/memorylatencybench/main.c
@@ -22,42 +22,144 @@
#include <stdlib.h>
#include <string.h>
+#include <arch/defines.h>
#include <trusty_benchmark.h>
#include <uapi/err.h>
-#define BUF_SIZE 16384
+#define BLOCK_SIZE_BYTES (CACHE_LINE * 4)
+#define STRUCT_NPAD (BLOCK_SIZE_BYTES) / sizeof(uintptr_t)
+#define MAX_WORKING_SET_SZ 16777216
-typedef struct {
- uint8_t buf[BUF_SIZE];
+static const uint64_t working_set_sizes[] = {
+ BLOCK_SIZE_BYTES,
+ 512,
+ 1024,
+ 2048,
+ 4096,
+ 8192,
+ 16384,
+ 32768,
+ 65536,
+ 131072,
+ 262144,
+ 524288,
+ 1048576,
+ 2097152,
+ 4194304,
+ 8388608,
+ MAX_WORKING_SET_SZ,
+};
+
+typedef union memlatency_state_t {
+ union memlatency_state_t* next;
+ uintptr_t pad[STRUCT_NPAD];
} memlatency_state_t;
-static memlatency_state_t* memlatency_state;
+static memlatency_state_t* memlatency_state_start;
+
+static size_t nb_blocks = MAX_WORKING_SET_SZ / sizeof(memlatency_state_t);
+
+static void get_param_name_cb_fixed(char* buf,
+ size_t buf_size,
+ size_t param_idx) {
+ snprintf(buf, buf_size,
+ "%" PRIu64 " Bytes working size in blocks of %zu Bytes",
+ working_set_sizes[param_idx], sizeof(memlatency_state_t));
+}
+
+static void get_formatted_value_cb(char* buf,
+ size_t buf_size,
+ int64_t value,
+ const char* metric_name) {
+ if (strcmp("time_micro_seconds", metric_name) == 0) {
+ int64_t mic_sec = value / 1000;
+ int64_t n_sec = value % 1000;
+
+ snprintf(buf, buf_size, "%" PRId64 ".%03" PRId64 "", mic_sec, n_sec);
+ } else {
+ snprintf(buf, buf_size, "%" PRId64, value);
+ }
+}
BENCH_SETUP(memlatency) {
- memlatency_state = calloc(1, sizeof(memlatency_state_t));
- if (memlatency_state == NULL) {
+ trusty_bench_get_param_name_cb = &get_param_name_cb_fixed;
+ trusty_bench_get_formatted_value_cb = &get_formatted_value_cb;
+ memlatency_state_start =
+ memalign(CACHE_LINE, nb_blocks * sizeof(memlatency_state_t));
+
+ if (memlatency_state_start == NULL) {
TLOGE("Failed to Allocate memory for memlatency_state!");
return ERR_NO_MEMORY;
}
+ memset((uint8_t*)memlatency_state_start, 0,
+ nb_blocks * sizeof(memlatency_state_t));
+
+ for (size_t idx = 0; idx < nb_blocks - 1; ++idx) {
+ memlatency_state_start[idx].next = &memlatency_state_start[idx + 1];
+ }
+
+ static_assert(sizeof(memlatency_state_t) == BLOCK_SIZE_BYTES);
+
return NO_ERROR;
}
BENCH_TEARDOWN(memlatency) {
- free(memlatency_state);
- memlatency_state = NULL;
+ free(memlatency_state_start);
+ memlatency_state_start = NULL;
}
-BENCH(memlatency, latency, 20) {
- int rc = NO_ERROR;
+BENCH(memlatency, latency_read, 20, working_set_sizes) {
+ uint64_t sz = working_set_sizes[bench_get_param_idx()];
+ uint64_t nb_blocks = sz / BLOCK_SIZE_BYTES;
+ uint64_t loops = 10 * (MAX_WORKING_SET_SZ / sz);
+
+ ASSERT_GT(nb_blocks, 0);
- ASSERT_EQ(NO_ERROR, rc);
+ while (loops > 0) {
+ --loops;
+ volatile union memlatency_state_t* block = memlatency_state_start;
+ for (size_t idx = 0; idx < nb_blocks; idx++) {
+ /* To make sure we are not overwriting next block Address */
+ static_assert(sizeof(uintptr_t) == __SIZEOF_POINTER__);
+ block = block->next;
+ }
+ }
+
+ return NO_ERROR;
+test_abort:
+ return ERR_GENERIC;
+}
+
+BENCH(memlatency, latency_write, 20, working_set_sizes) {
+ uint64_t sz = working_set_sizes[bench_get_param_idx()];
+ uint64_t nb_blocks = sz / BLOCK_SIZE_BYTES;
+ uint64_t loops = 10 * (MAX_WORKING_SET_SZ / sz);
+
+ ASSERT_GT(nb_blocks, 0);
+
+ while (loops > 0) {
+ --loops;
+ union memlatency_state_t* block = memlatency_state_start;
+
+ for (size_t idx = 0; idx < nb_blocks; idx++) {
+ /* To make sure we are not overwriting next block Address */
+ static_assert(sizeof(uintptr_t) == __SIZEOF_POINTER__);
+ (block + idx)->pad[1] = idx + sz;
+ }
+ }
+
+ return NO_ERROR;
test_abort:
- return rc;
+ return ERR_GENERIC;
+}
+
+BENCH_RESULT(memlatency, latency_read, time_micro_seconds) {
+ return bench_get_duration_ns();
}
-BENCH_RESULT(memlatency, latency, time_micro_seconds) {
+BENCH_RESULT(memlatency, latency_write, time_micro_seconds) {
return bench_get_duration_ns();
}
diff --git a/include/shared/lk/trusty_bench_print_tables.h b/include/shared/lk/trusty_bench_print_tables.h
index 4a02655..95a247c 100644
--- a/include/shared/lk/trusty_bench_print_tables.h
+++ b/include/shared/lk/trusty_bench_print_tables.h
@@ -29,10 +29,12 @@
static size_t trusty_bench_max_column_width;
/* Max Width ever needed for a metric cell in the table */
-static size_t trusty_bench_max_metric_name_width;
+static size_t trusty_bench_max_metric_name_width =
+ 6 /* strlen("Metric") is the minimum needed*/;
/* Max Width ever needed for a Param cell in the table */
-static size_t trusty_bench_max_param_name_width;
+static size_t trusty_bench_max_param_name_width =
+ 5 /* strlen("Param") is the minimum needed*/;
/* Max Width ever needed for a Metric Value cell in the table */
static size_t trusty_bench_max_metric_digit_width;