From 377833583ee4d3ee471212a882679a2cf253003b Mon Sep 17 00:00:00 2001 From: Igor Opaniuk Date: Tue, 16 Jan 2024 16:53:37 +0100 Subject: [PATCH] core: pta: drop benchmark Drop Benchmark PTA 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 --- core/arch/arm/kernel/secure_partition.c | 5 - core/arch/arm/kernel/spmc_sp_handler.c | 1 - core/include/bench.h | 60 ------- core/pta/benchmark.c | 215 ------------------------ core/pta/sub.mk | 1 - core/tee/entry_std.c | 5 - lib/libutee/include/pta_benchmark.h | 26 --- 7 files changed, 313 deletions(-) delete mode 100644 core/include/bench.h delete mode 100644 core/pta/benchmark.c delete mode 100644 lib/libutee/include/pta_benchmark.h diff --git a/core/arch/arm/kernel/secure_partition.c b/core/arch/arm/kernel/secure_partition.c index 7691cadbb16..6fd9fd7f6c2 100644 --- a/core/arch/arm/kernel/secure_partition.c +++ b/core/arch/arm/kernel/secure_partition.c @@ -2,7 +2,6 @@ /* * Copyright (c) 2020-2024, Arm Limited. */ -#include #include #include #include @@ -1616,8 +1615,6 @@ static TEE_Result sp_enter_invoke_cmd(struct ts_session *s, uint32_t panicked = false; uint32_t panic_code = 0; - bm_timestamp(); - sp_regs = &ctx->sp_regs; ts_push_current_session(s); @@ -1661,8 +1658,6 @@ static TEE_Result sp_enter_invoke_cmd(struct ts_session *s, sess = ts_pop_current_session(); assert(sess == s); - bm_timestamp(); - return res; } diff --git a/core/arch/arm/kernel/spmc_sp_handler.c b/core/arch/arm/kernel/spmc_sp_handler.c index 65e0a82cbd3..7506cb71a9e 100644 --- a/core/arch/arm/kernel/spmc_sp_handler.c +++ b/core/arch/arm/kernel/spmc_sp_handler.c @@ -3,7 +3,6 @@ * Copyright (c) 2021-2024, Arm Limited */ #include -#include #include #include #include diff --git a/core/include/bench.h b/core/include/bench.h deleted file mode 100644 index d9f3cdd3f22..00000000000 --- a/core/include/bench.h +++ /dev/null @@ -1,60 +0,0 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ -/* - * Copyright (c) 2017, Linaro Limited - */ - -#ifndef __BENCH_H -#define __BENCH_H - -#include -#include -#include -#include - -/* - * Cycle count divider is enabled (in PMCR), - * CCNT value is incremented every 64th clock cycle - */ -#define TEE_BENCH_DIVIDER U(64) - -/* Max amount of timestamps per buffer */ -#define TEE_BENCH_MAX_STAMPS U(32) -#define TEE_BENCH_MAX_MASK (TEE_BENCH_MAX_STAMPS - 1) - -#define OPTEE_MSG_RPC_CMD_BENCH_REG_NEW U(0) -#define OPTEE_MSG_RPC_CMD_BENCH_REG_DEL U(1) - -/* OP-TEE susbsystems ids */ -#define TEE_BENCH_CLIENT U(0x10000000) -#define TEE_BENCH_KMOD U(0x20000000) -#define TEE_BENCH_CORE U(0x30000000) -#define TEE_BENCH_UTEE U(0x40000000) -#define TEE_BENCH_DUMB_TA U(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[]; -}; - -#ifdef CFG_TEE_BENCHMARK -void bm_timestamp(void); -#else -static inline void bm_timestamp(void) {} -#endif /* CFG_TEE_BENCHMARK */ - -#endif /* __BENCH_H */ diff --git a/core/pta/benchmark.c b/core/pta/benchmark.c deleted file mode 100644 index bfaa42696c9..00000000000 --- a/core/pta/benchmark.c +++ /dev/null @@ -1,215 +0,0 @@ -// SPDX-License-Identifier: BSD-2-Clause -/* - * Copyright (c) 2017, Linaro Limited - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define TA_NAME "benchmark.ta" -#define TA_PRINT_PREFIX "Benchmark: " - -static struct tee_ts_global *bench_ts_global; -static size_t bench_ts_size; - -static struct mutex bench_reg_mu = MUTEX_INITIALIZER; -static struct mobj *bench_mobj; - -static TEE_Result rpc_reg_global_buf(uint64_t type, paddr_t phta, size_t size) -{ - struct thread_param tpm = THREAD_PARAM_VALUE(IN, type, phta, size); - - return thread_rpc_cmd(OPTEE_RPC_CMD_BENCH_REG, 1, &tpm); -} - -static TEE_Result alloc_benchmark_buffer(uint32_t type, - TEE_Param p[TEE_NUM_PARAMS]) -{ - TEE_Result res; - - if ((TEE_PARAM_TYPE_GET(type, 0) != TEE_PARAM_TYPE_VALUE_INOUT) || - (TEE_PARAM_TYPE_GET(type, 1) != TEE_PARAM_TYPE_VALUE_INPUT) || - (TEE_PARAM_TYPE_GET(type, 2) != TEE_PARAM_TYPE_NONE) || - (TEE_PARAM_TYPE_GET(type, 3) != TEE_PARAM_TYPE_NONE)) { - return TEE_ERROR_BAD_PARAMETERS; - } - - mutex_lock(&bench_reg_mu); - - /* Check if we have already registered buffer */ - if (bench_ts_global) { - EMSG(TA_PRINT_PREFIX - "timestamp buffer was already registered"); - mutex_unlock(&bench_reg_mu); - return TEE_ERROR_BAD_STATE; - } - - bench_ts_size = sizeof(struct tee_ts_global) + - p[1].value.a * sizeof(struct tee_ts_cpu_buf); - if (!bench_ts_size) { - EMSG(TA_PRINT_PREFIX - "invalid timestamp buffer size"); - mutex_unlock(&bench_reg_mu); - return TEE_ERROR_BAD_STATE; - } - - bench_mobj = thread_rpc_alloc_global_payload(bench_ts_size); - if (!bench_mobj) { - EMSG(TA_PRINT_PREFIX - "can't create mobj for timestamp buffer"); - mutex_unlock(&bench_reg_mu); - return TEE_ERROR_OUT_OF_MEMORY; - } - - bench_ts_global = (struct tee_ts_global *)mobj_get_va(bench_mobj, 0, - bench_ts_size); - if (!bench_ts_global) { - thread_rpc_free_global_payload(bench_mobj); - bench_mobj = NULL; - - mutex_unlock(&bench_reg_mu); - return TEE_ERROR_BAD_STATE; - } - - memset((void *)bench_ts_global, 0, bench_ts_size); - bench_ts_global->cores = p[1].value.a; - - DMSG(TA_PRINT_PREFIX - "allocated timestamp buffer, addr = %p", - (void *)bench_ts_global); - - mutex_unlock(&bench_reg_mu); - - /* Send back to the optee linux kernel module */ - res = rpc_reg_global_buf(OPTEE_MSG_RPC_CMD_BENCH_REG_NEW, - virt_to_phys((void *)bench_ts_global), - bench_ts_size); - - p[0].value.a = virt_to_phys((void *)bench_ts_global); - p[0].value.b = bench_ts_size; - - return res; -} - -static TEE_Result get_benchmark_memref(uint32_t type, - TEE_Param p[TEE_NUM_PARAMS]) -{ - if ((TEE_PARAM_TYPE_GET(type, 0) != TEE_PARAM_TYPE_VALUE_OUTPUT) || - (TEE_PARAM_TYPE_GET(type, 1) != TEE_PARAM_TYPE_NONE) || - (TEE_PARAM_TYPE_GET(type, 2) != TEE_PARAM_TYPE_NONE) || - (TEE_PARAM_TYPE_GET(type, 3) != TEE_PARAM_TYPE_NONE)) { - return TEE_ERROR_BAD_PARAMETERS; - } - - mutex_lock(&bench_reg_mu); - - DMSG(TA_PRINT_PREFIX "Sending back timestamp buffer paddr = %p", - (void *)virt_to_phys((void *)bench_ts_global)); - - if (bench_ts_global) { - p[0].value.a = virt_to_phys((void *)bench_ts_global); - p[0].value.b = bench_ts_size; - } else { - p[0].value.a = 0; - p[0].value.b = 0; - } - - mutex_unlock(&bench_reg_mu); - - return TEE_SUCCESS; -} - -static TEE_Result unregister_benchmark(uint32_t type, - TEE_Param p[TEE_NUM_PARAMS] __unused) -{ - TEE_Result res; - - if ((TEE_PARAM_TYPE_GET(type, 0) != TEE_PARAM_TYPE_NONE) || - (TEE_PARAM_TYPE_GET(type, 1) != TEE_PARAM_TYPE_NONE) || - (TEE_PARAM_TYPE_GET(type, 2) != TEE_PARAM_TYPE_NONE) || - (TEE_PARAM_TYPE_GET(type, 3) != TEE_PARAM_TYPE_NONE)) { - return TEE_ERROR_BAD_PARAMETERS; - } - mutex_lock(&bench_reg_mu); - - DMSG(TA_PRINT_PREFIX "Unregister benchmark ts buffer paddr = %p", - (void *)virt_to_phys((void *)bench_ts_global)); - bench_ts_global = NULL; - - mutex_unlock(&bench_reg_mu); - - res = rpc_reg_global_buf(OPTEE_MSG_RPC_CMD_BENCH_REG_DEL, 0, 0); - - thread_rpc_free_global_payload(bench_mobj); - bench_mobj = NULL; - - return res; -} - -static TEE_Result invoke_command(void *session_ctx __unused, - uint32_t cmd_id, uint32_t param_types, - TEE_Param params[TEE_NUM_PARAMS]) -{ - switch (cmd_id) { - case BENCHMARK_CMD_ALLOCATE_BUF: - return alloc_benchmark_buffer(param_types, params); - case BENCHMARK_CMD_GET_MEMREF: - return get_benchmark_memref(param_types, params); - case BENCHMARK_CMD_UNREGISTER: - return unregister_benchmark(param_types, params); - default: - break; - } - - return TEE_ERROR_BAD_PARAMETERS; -} - -pseudo_ta_register(.uuid = BENCHMARK_UUID, .name = TA_NAME, - .flags = PTA_DEFAULT_FLAGS, - .invoke_command_entry_point = invoke_command); - -void bm_timestamp(void) -{ - struct tee_ts_cpu_buf *cpu_buf; - struct tee_time_st ts_data; - uint64_t ts_i; - void *ret_addr; - uint32_t cur_cpu; - uint32_t exceptions; - - if (!bench_ts_global) - return; - - exceptions = thread_mask_exceptions(THREAD_EXCP_ALL); - cur_cpu = get_core_pos(); - - if (cur_cpu >= bench_ts_global->cores) { - thread_unmask_exceptions(exceptions); - return; - } - - ret_addr = __builtin_return_address(0); - - cpu_buf = &bench_ts_global->cpu_buf[cur_cpu]; - ts_i = cpu_buf->head++; - ts_data.cnt = read_pmccntr() * TEE_BENCH_DIVIDER; - ts_data.addr = (uintptr_t)ret_addr; - ts_data.src = TEE_BENCH_CORE; - cpu_buf->stamps[ts_i & TEE_BENCH_MAX_MASK] = ts_data; - - thread_unmask_exceptions(exceptions); -} diff --git a/core/pta/sub.mk b/core/pta/sub.mk index cf8e86298db..bb024d6e504 100644 --- a/core/pta/sub.mk +++ b/core/pta/sub.mk @@ -1,7 +1,6 @@ subdirs-$(CFG_TEE_CORE_EMBED_INTERNAL_TESTS) += tests srcs-$(CFG_ATTESTATION_PTA) += attestation.c -srcs-$(CFG_TEE_BENCHMARK) += benchmark.c srcs-$(CFG_DEVICE_ENUM_PTA) += device.c srcs-$(CFG_TA_GPROF_SUPPORT) += gprof.c ifeq ($(CFG_WITH_USER_TA),y) diff --git a/core/tee/entry_std.c b/core/tee/entry_std.c index d3ae6248624..607ebd4b545 100644 --- a/core/tee/entry_std.c +++ b/core/tee/entry_std.c @@ -5,7 +5,6 @@ */ #include -#include #include #include #include @@ -425,8 +424,6 @@ static void entry_invoke_command(struct optee_msg_arg *arg, uint32_t num_params) struct tee_ta_param param = { 0 }; uint64_t saved_attr[TEE_NUM_PARAMS] = { 0 }; - bm_timestamp(); - res = copy_in_params(arg->params, num_params, ¶m, saved_attr); if (res != TEE_SUCCESS) goto out; @@ -440,8 +437,6 @@ static void entry_invoke_command(struct optee_msg_arg *arg, uint32_t num_params) res = tee_ta_invoke_command(&err_orig, s, NSAPP_IDENTITY, TEE_TIMEOUT_INFINITE, arg->func, ¶m); - bm_timestamp(); - tee_ta_put_session(s); copy_out_param(¶m, num_params, arg->params, saved_attr); diff --git a/lib/libutee/include/pta_benchmark.h b/lib/libutee/include/pta_benchmark.h deleted file mode 100644 index 2b6f1573f3f..00000000000 --- a/lib/libutee/include/pta_benchmark.h +++ /dev/null @@ -1,26 +0,0 @@ -/* SPDX-License-Identifier: BSD-2-Clause */ -/* - * Copyright (c) 2017, Linaro Limited - */ - -#ifndef __PTA_BENCHMARK_H -#define __PTA_BENCHMARK_H - -/* - * Interface to the benchmark pseudo-TA, which is used for registering - * timestamp buffers - */ - -#define BENCHMARK_UUID \ - { 0x0b9a63b0, 0xb4c6, 0x4c85, \ - { 0xa2, 0x84, 0xa2, 0x28, 0xef, 0x54, 0x7b, 0x4e } } - -/* - * Benchmark PTA supported commands - */ -#define BENCHMARK_CMD(id) (0xFA190000 | ((id) & 0xFFFF)) -#define BENCHMARK_CMD_ALLOCATE_BUF BENCHMARK_CMD(1) -#define BENCHMARK_CMD_GET_MEMREF BENCHMARK_CMD(2) -#define BENCHMARK_CMD_UNREGISTER BENCHMARK_CMD(3) - -#endif /* __PTA_BENCHMARK_H */