From bfe37714c20c46512e70fad961f1a81a7ab05a8b Mon Sep 17 00:00:00 2001 From: Igor Opaniuk Date: Tue, 16 Jan 2024 17:15:11 +0100 Subject: [PATCH] libteec: drop benchmark framework support Drop Benchmark Framework as current implementation is non-function and obsolete, and it's not supported anymore. Acked-by: Jens Wiklander Acked-by: Etienne Carriere Signed-off-by: Igor Opaniuk --- Android.mk | 4 - Makefile | 2 +- libteec/CMakeLists.txt | 13 --- libteec/Makefile | 7 -- libteec/include/tee_bench.h | 77 ------------ libteec/src/tee_client_api.c | 6 - libteec/src/teec_benchmark.c | 221 ----------------------------------- libteec/src/teec_benchmark.h | 37 ------ 8 files changed, 1 insertion(+), 366 deletions(-) delete mode 100644 libteec/include/tee_bench.h delete mode 100644 libteec/src/teec_benchmark.c delete mode 100644 libteec/src/teec_benchmark.h diff --git a/Android.mk b/Android.mk index a59bc9e2..78466d87 100644 --- a/Android.mk +++ b/Android.mk @@ -43,10 +43,6 @@ LOCAL_CFLAGS += -DBINARY_PREFIX=\"TEEC\" LOCAL_SRC_FILES := libteec/src/tee_client_api.c \ libteec/src/teec_trace.c -ifeq ($(CFG_TEE_BENCHMARK),y) -LOCAL_CFLAGS += -DCFG_TEE_BENCHMARK -LOCAL_SRC_FILES += teec_benchmark.c -endif LOCAL_C_INCLUDES := $(LOCAL_PATH)/libteec/include diff --git a/Makefile b/Makefile index 0d5a500a..8a1a86af 100644 --- a/Makefile +++ b/Makefile @@ -34,7 +34,7 @@ all: build install build-libteec: @echo "Building libteec.so" @$(MAKE) --directory=libteec --no-print-directory --no-builtin-variables \ - CFG_TEE_BENCHMARK=$(CFG_TEE_BENCHMARK) CFG_TEE_CLIENT_LOG_LEVEL=$(CFG_TEE_CLIENT_LOG_LEVEL) + CFG_TEE_CLIENT_LOG_LEVEL=$(CFG_TEE_CLIENT_LOG_LEVEL) build-tee-supplicant: build-libteec @echo "Building tee-supplicant" diff --git a/libteec/CMakeLists.txt b/libteec/CMakeLists.txt index 0c73ebae..e7b56c3d 100644 --- a/libteec/CMakeLists.txt +++ b/libteec/CMakeLists.txt @@ -13,8 +13,6 @@ endif() ################################################################################ # Configuration flags always included ################################################################################ -option(CFG_TEE_BENCHMARK "Build with benchmark support" OFF) - set(CFG_TEE_CLIENT_LOG_LEVEL "1" CACHE STRING "libteec log level") set(CFG_TEE_CLIENT_LOG_FILE "/data/tee/teec.log" CACHE STRING "Location of libteec log") @@ -26,10 +24,6 @@ set(SRC src/teec_trace.c ) -if(CFG_TEE_BENCHMARK) - set(SRC ${SRC} src/teec_benchmark.c) -endif() - ################################################################################ # Built library ################################################################################ @@ -53,13 +47,6 @@ target_compile_definitions(teec PRIVATE -DBINARY_PREFIX="LT" ) -################################################################################ -# Optional flags -################################################################################ -if(CFG_TEE_BENCHMARK) - target_compile_definitions(teec PRIVATE -DCFG_TEE_BENCHMARK) -endif() - ################################################################################ # Public and private header and library dependencies ################################################################################ diff --git a/libteec/Makefile b/libteec/Makefile index 41a21bb6..3c584068 100644 --- a/libteec/Makefile +++ b/libteec/Makefile @@ -19,9 +19,6 @@ LIB_MAJ_MIN_P := $(LIB_NAME).$(MAJOR_VERSION).$(MINOR_VERSION).$(PATCH_VERSION) TEEC_SRCS := tee_client_api.c \ teec_trace.c -ifeq ($(CFG_TEE_BENCHMARK),y) -TEEC_SRCS += teec_benchmark.c -endif TEEC_SRC_DIR := src TEEC_OBJ_DIR := $(OUT_DIR) @@ -34,10 +31,6 @@ TEEC_CFLAGS := $(addprefix -I, $(TEEC_INCLUDES)) $(CFLAGS) -D_GNU_SOURCE \ -DDEBUGLEVEL_$(CFG_TEE_CLIENT_LOG_LEVEL) \ -DBINARY_PREFIX=\"TEEC\" -ifeq ($(CFG_TEE_BENCHMARK),y) -TEEC_CFLAGS += -DCFG_TEE_BENCHMARK -endif - TEEC_LFLAGS := $(LDFLAGS) -lpthread TEEC_LIBRARY := $(OUT_DIR)/$(LIB_MAJ_MIN_P) diff --git a/libteec/include/tee_bench.h b/libteec/include/tee_bench.h deleted file mode 100644 index 600407f3..00000000 --- a/libteec/include/tee_bench.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (c) 2017, Linaro Limited - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef TEE_BENCH_H -#define TEE_BENCH_H - -#include - -#define PTA_BENCHMARK_UUID \ - { 0x0b9a63b0, 0xb4c6, 0x4c85, \ - { 0xa2, 0x84, 0xa2, 0x28, 0xef, 0x54, 0x7b, 0x4e } } - -#define BENCHMARK_CMD(id) (0xFA190000 | ((id) & 0xFFFF)) -#define BENCHMARK_CMD_REGISTER_MEMREF BENCHMARK_CMD(1) -#define BENCHMARK_CMD_GET_MEMREF BENCHMARK_CMD(2) -#define BENCHMARK_CMD_UNREGISTER BENCHMARK_CMD(3) - -/* - * Cycle count divider is enabled (in PMCR), - * CCNT value is incremented every 64th clock cycle - */ -#define TEE_BENCH_DIVIDER 64 -/* max amount of timestamps per buffer */ -#define TEE_BENCH_MAX_STAMPS 32 -#define TEE_BENCH_MAX_MASK (TEE_BENCH_MAX_STAMPS - 1) - -/* OP-TEE susbsystems ids */ -#define TEE_BENCH_CLIENT 0x10000000 -#define TEE_BENCH_KMOD 0x20000000 -#define TEE_BENCH_CORE 0x30000000 -#define TEE_BENCH_UTEE 0x40000000 -#define TEE_BENCH_DUMB_TA 0xF0000001 - -/* storing timestamp */ -struct tee_time_st { - uint64_t cnt; /* stores value from CNTPCT register */ - uint64_t addr; /* stores value from program counter register */ - uint64_t src; /* OP-TEE subsystem id */ -}; - -/* per-cpu circular buffer for timestamps */ -struct tee_ts_cpu_buf { - uint64_t head; - uint64_t tail; - struct tee_time_st stamps[TEE_BENCH_MAX_STAMPS]; -}; - -/* memory layout for shared memory, where timestamps will be stored */ -struct tee_ts_global { - uint64_t cores; - struct tee_ts_cpu_buf cpu_buf[]; -}; -#endif /* TEE_BENCH_H */ diff --git a/libteec/src/tee_client_api.c b/libteec/src/tee_client_api.c index b7507452..7e628121 100644 --- a/libteec/src/tee_client_api.c +++ b/libteec/src/tee_client_api.c @@ -46,8 +46,6 @@ #endif #include -#include "teec_benchmark.h" - #define MIN(x, y) (((x) < (y)) ? (x) : (y)) /* How many device sequence numbers will be tried before giving up */ @@ -705,8 +703,6 @@ TEEC_Result TEEC_InvokeCommand(TEEC_Session *session, uint32_t cmd_id, goto out; } - bm_timestamp(); - buf_data.buf_ptr = (uintptr_t)&buf; buf_data.buf_len = sizeof(buf); @@ -741,8 +737,6 @@ TEEC_Result TEEC_InvokeCommand(TEEC_Session *session, uint32_t cmd_id, eorig = arg->ret_origin; teec_post_process_operation(operation, params, shm); - bm_timestamp(); - out_free_temp_refs: teec_free_temp_refs(operation, shm); out: diff --git a/libteec/src/teec_benchmark.c b/libteec/src/teec_benchmark.c deleted file mode 100644 index 0d04c196..00000000 --- a/libteec/src/teec_benchmark.c +++ /dev/null @@ -1,221 +0,0 @@ -/* - * Copyright (c) 2017, Linaro Limited - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "teec_benchmark.h" - -struct tee_ts_global *bench_ts_global; -static const TEEC_UUID pta_benchmark_uuid = PTA_BENCHMARK_UUID; - -static TEEC_Context bench_ctx; -static TEEC_Session bench_sess; - -static pthread_mutex_t teec_bench_mu = PTHREAD_MUTEX_INITIALIZER; - -/* Cycle counter */ -static inline uint64_t read_ccounter(void) -{ - uint64_t ccounter = 0; -#ifdef __aarch64__ - asm volatile("mrs %0, PMCCNTR_EL0" : "=r"(ccounter)); -#else - asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r"(ccounter)); -#endif - return ccounter * TEE_BENCH_DIVIDER; -} - -static TEEC_Result benchmark_pta_open(void) -{ - TEEC_Result res = TEEC_ERROR_GENERIC; - uint32_t ret_orig = 0; - - res = TEEC_InitializeContext(NULL, &bench_ctx); - if (res != TEEC_SUCCESS) - return res; - - res = TEEC_OpenSession(&bench_ctx, &bench_sess, - &pta_benchmark_uuid, - TEEC_LOGIN_PUBLIC, NULL, NULL, &ret_orig); - if (res != TEEC_SUCCESS) { - TEEC_FinalizeContext(&bench_ctx); - return res; - } - - return res; -} - -static void benchmark_pta_close(void) -{ - TEEC_CloseSession(&bench_sess); - TEEC_FinalizeContext(&bench_ctx); -} - -static TEEC_Result benchmark_get_bench_buf_paddr(uint64_t *paddr_ts_buf, - uint64_t *size) -{ - TEEC_Result res = TEEC_ERROR_GENERIC; - uint32_t ret_orig = 0; - TEEC_Operation op; - - memset(&op, 0, sizeof(op)); - - res = benchmark_pta_open(); - if (res != TEEC_SUCCESS) - return res; - - op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT, TEEC_NONE, - TEEC_NONE, TEEC_NONE); - - res = TEEC_InvokeCommand(&bench_sess, BENCHMARK_CMD_GET_MEMREF, - &op, &ret_orig); - if (res != TEEC_SUCCESS) - return res; - - *paddr_ts_buf = op.params[0].value.a; - *size = op.params[0].value.b; - - benchmark_pta_close(); - - return res; -} - -static void *mmap_paddr(intptr_t paddr, uint64_t size) -{ - int devmem = 0; - off_t offset = 0; - off_t page_addr = 0; - intptr_t *hw_addr = NULL; - - devmem = open("/dev/mem", O_RDWR); - if (!devmem) - return NULL; - - offset = (off_t)paddr % getpagesize(); - page_addr = (off_t)(paddr - offset); - - hw_addr = (intptr_t *)mmap(0, size + offset, PROT_READ|PROT_WRITE, - MAP_SHARED, devmem, page_addr); - if (hw_addr == MAP_FAILED) { - close(devmem); - return NULL; - } - - close(devmem); - return (hw_addr + offset); -} - -/* check if we are in benchmark mode */ -static bool benchmark_check_mode(void) -{ - uint64_t ts_buf_raw = 0; - uint64_t ts_buf_size = 0; - bool res = true; - - if (!bench_ts_global) { - /* receive buffer from Benchmark PTA and register it */ - benchmark_get_bench_buf_paddr(&ts_buf_raw, &ts_buf_size); - if (ts_buf_raw && ts_buf_size) { - bench_ts_global = mmap_paddr(ts_buf_raw, ts_buf_size); - res = (bench_ts_global) ? true : false; - } else { - res = false; - } - } - - return res; -} - -/* Adding timestamp to buffer */ -void bm_timestamp(void) -{ - struct tee_ts_cpu_buf *cpu_buf = NULL; - uint64_t ts_i = 0; - void *ret_addr = NULL; - uint32_t cur_cpu = 0; - int ret = 0; - cpu_set_t cpu_set_old; - cpu_set_t cpu_set_tmp; - struct tee_time_st ts_data; - - memset(&cpu_set_old, 0, sizeof(cpu_set_old)); - memset(&cpu_set_tmp, 0, sizeof(cpu_set_tmp)); - memset(&ts_data, 0, sizeof(ts_data)); - - if (pthread_mutex_trylock(&teec_bench_mu)) - return; - - if (!benchmark_check_mode()) - goto error; - - CPU_ZERO(&cpu_set_old); - ret = sched_getaffinity(0, sizeof(cpu_set_old), &cpu_set_old); - if (ret) - goto error; - - /* stick to the same core while putting timestamp */ - cur_cpu = sched_getcpu(); - CPU_ZERO(&cpu_set_tmp); - CPU_SET(cur_cpu, &cpu_set_tmp); - ret = sched_setaffinity(0, sizeof(cpu_set_tmp), &cpu_set_tmp); - if (ret) - goto error; - - /* fill timestamp data */ - if (cur_cpu >= bench_ts_global->cores) { - ret = sched_setaffinity(0, sizeof(cpu_set_old), &cpu_set_old); - goto error; - } - - ret_addr = __builtin_return_address(0); - - cpu_buf = &bench_ts_global->cpu_buf[cur_cpu]; - ts_i = __sync_fetch_and_add(&cpu_buf->head, 1); - ts_data.cnt = read_ccounter(); - ts_data.addr = (uintptr_t)ret_addr; - ts_data.src = TEE_BENCH_CLIENT; - cpu_buf->stamps[ts_i & TEE_BENCH_MAX_MASK] = ts_data; - - /* set back affinity mask */ - sched_setaffinity(0, sizeof(cpu_set_old), &cpu_set_old); - -error: - pthread_mutex_unlock(&teec_bench_mu); -} - diff --git a/libteec/src/teec_benchmark.h b/libteec/src/teec_benchmark.h deleted file mode 100644 index 17d99ac7..00000000 --- a/libteec/src/teec_benchmark.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2017, Linaro Limited - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __TEEC_BENCHMARK_H -#define __TEEC_BENCHMARK_H - -#ifdef CFG_TEE_BENCHMARK -void bm_timestamp(void); -#else -static inline void bm_timestamp(void) {} -#endif - -#endif /* __TEEC_BENCHMARK_H */