Profiler: Add NS profiling case in NSPE
Signed-off-by: Jianliang Shen <jianliang.shen@arm.com>
Change-Id: I8d6fd4130f98f30903c267a74f25c329ca2ff048
diff --git a/profiling/profiling_cases/prof_psa_client_api/cases/non_secure/CMakeLists.txt b/profiling/profiling_cases/prof_psa_client_api/cases/non_secure/CMakeLists.txt
new file mode 100644
index 0000000..a4793cf
--- /dev/null
+++ b/profiling/profiling_cases/prof_psa_client_api/cases/non_secure/CMakeLists.txt
@@ -0,0 +1,35 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2023, Arm Limited. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+cmake_policy(SET CMP0079 NEW)
+
+add_library(non_secure_prof_psa_client_api INTERFACE)
+
+target_sources(non_secure_prof_psa_client_api
+ INTERFACE
+ non_secure_prof_psa_client_api.c
+ ${TFM_PROF_PATH}/export/ns/prof_intf_ns.c
+)
+
+target_include_directories(non_secure_prof_psa_client_api
+ INTERFACE
+ ${PROF_PSA_CLIENT_API_CASE_PATH}/non_secure
+ ${PROF_PSA_CLIENT_API_CASE_PATH}/
+ ${TFM_PROF_PATH}/profiler
+ ${TFM_PROF_PATH}/export/ns
+ ${TFM_PROF_PATH}/export
+)
+
+target_link_libraries(non_secure_prof_psa_client_api
+ INTERFACE
+ tfm_log
+)
+
+target_compile_definitions(non_secure_prof_psa_client_api
+ INTERFACE
+ CONFIG_TFM_ENALBE_PROFILING
+)
diff --git a/profiling/profiling_cases/prof_psa_client_api/cases/non_secure/non_secure_prof_psa_client_api.c b/profiling/profiling_cases/prof_psa_client_api/cases/non_secure/non_secure_prof_psa_client_api.c
new file mode 100644
index 0000000..2da3f4b
--- /dev/null
+++ b/profiling/profiling_cases/prof_psa_client_api/cases/non_secure/non_secure_prof_psa_client_api.c
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2023, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include "non_secure_prof_psa_client_api.h"
+#include "tfm_log.h"
+#include "prof_intf_ns.h"
+
+#define PROFILING_AVERAGE_DIFF(psa_api_name, cp_start, cp_end) \
+ LOG_MSG("non-secure %s average is %d CPU cycles\r\n", psa_api_name, \
+ PROF_DATA_DIFF_AVG(cp_start, PSA_API_TOPIC, cp_end, PSA_API_TOPIC))
+
+void non_secure_prof_psa_client_api()
+{
+ psa_handle_t handle;
+ psa_status_t status;
+ uint16_t i = 0;
+
+ for (i = 0; i < TEST_LOOP_CNT; i++) {
+ PROF_TIMING_LOG(CONNECT_CP_START, PSA_API_TOPIC);
+ handle = psa_connect(PROFILING_SERVICE_SID, PROFILING_SERVICE_VERSION);
+ PROF_TIMING_LOG(CONNECT_CP_END, PSA_API_TOPIC);
+
+ if (!PSA_HANDLE_IS_VALID(handle)) {
+ LOG_MSG("PSA connect fail!");
+ return;
+ }
+
+ PROF_TIMING_LOG(CALL_CP_START, PSA_API_TOPIC);
+ status = psa_call(handle, PSA_IPC_CALL, NULL, 0, NULL, 0);
+ PROF_TIMING_LOG(CALL_CP_END, PSA_API_TOPIC);
+
+ if (status != PSA_SUCCESS) {
+ LOG_MSG("PSA call fail!");
+ return;
+ }
+
+ PROF_TIMING_LOG(CLOSE_CP_START, PSA_API_TOPIC);
+ psa_close(handle);
+ PROF_TIMING_LOG(CLOSE_CP_END, PSA_API_TOPIC);
+
+ /* Test stateless PSA call interface. */
+ PROF_TIMING_LOG(STATELESS_CALL_CP_START, PSA_API_TOPIC);
+ status = psa_call(PROFILING_STATELESS_SERVICE_HANDLE, PSA_IPC_CALL, NULL, 0, NULL, 0);
+ PROF_TIMING_LOG(STATELESS_CALL_CP_END, PSA_API_TOPIC);
+
+ if (status != PSA_SUCCESS) {
+ LOG_MSG("PSA stateless call fail!");
+ return;
+ }
+ }
+
+ PROFILING_AVERAGE_DIFF("psa_connect", CONNECT_CP_START, CONNECT_CP_END);
+ PROFILING_AVERAGE_DIFF("psa_call", CALL_CP_START, CALL_CP_END);
+ PROFILING_AVERAGE_DIFF("psa_close", CLOSE_CP_START, CLOSE_CP_END);
+ PROFILING_AVERAGE_DIFF("psa_call stateless", STATELESS_CALL_CP_START, STATELESS_CALL_CP_END);
+}
diff --git a/profiling/profiling_cases/prof_psa_client_api/cases/non_secure/non_secure_prof_psa_client_api.h b/profiling/profiling_cases/prof_psa_client_api/cases/non_secure/non_secure_prof_psa_client_api.h
new file mode 100644
index 0000000..cd8be00
--- /dev/null
+++ b/profiling/profiling_cases/prof_psa_client_api/cases/non_secure/non_secure_prof_psa_client_api.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2023, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+
+#ifndef __NON_SECURE_PROF_PSA_CLIENT_API_H__
+#define __NON_SECURE_PROF_PSA_CLIENT_API_H__
+
+#include "prof_psa_client_api_common.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void non_secure_prof_psa_client_api();
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __NON_SECURE_PROF_PSA_CLIENT_API_H__ */