David Wang | bcb8b14 | 2022-02-17 17:31:40 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2021-2022, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | * |
| 6 | */ |
| 7 | |
Jianliang Shen | e898f5c | 2023-08-10 15:20:33 +0800 | [diff] [blame] | 8 | #ifndef __PROF_INTF_S_H__ |
| 9 | #define __PROF_INTF_S_H__ |
David Wang | bcb8b14 | 2022-02-17 17:31:40 +0800 | [diff] [blame] | 10 | |
| 11 | /* This file defines all API that should be called by secure side */ |
| 12 | |
| 13 | #include <stdint.h> |
| 14 | #include <stddef.h> |
| 15 | #include <stdbool.h> |
| 16 | #include "prof_common.h" |
| 17 | |
| 18 | #ifdef __cplusplus |
| 19 | extern "C" { |
| 20 | #endif |
| 21 | |
| 22 | /* |
| 23 | * Topic based timing logging |
| 24 | */ |
Summer Qin | 521677e | 2023-07-19 14:01:47 +0800 | [diff] [blame] | 25 | #define PROF_TIMING_LOG(cp_id, topic_id) \ |
David Wang | bcb8b14 | 2022-02-17 17:31:40 +0800 | [diff] [blame] | 26 | prof_timing_cp( \ |
| 27 | PROF_MAKE_TIMING_TAG((cp_id), (topic_id), PROF_CALI_IDX_S, \ |
| 28 | PROF_TYPE_TIMING_LOG)) |
| 29 | |
| 30 | /* |
David Wang | bcb8b14 | 2022-02-17 17:31:40 +0800 | [diff] [blame] | 31 | * Secure side can call this macro to do/redo calibration |
| 32 | * Suggest to do/redo calibration before running the profiling. It's because the |
| 33 | * latency introduced by the profiler may be changed in the system lifecycle. |
| 34 | * For example, enable caches, change CPU frequency, etc. |
| 35 | * 'rounds' sets how many rounds executed for the calibration. In theory, "more |
| 36 | * rounds" is more accurate. |
| 37 | * Set `rounds` to `0` to reset the calibration value to 0. |
| 38 | */ |
| 39 | #define PROF_DO_CALIBRATE(rounds) prof_calibrate( \ |
| 40 | PROF_CALI_IDX_S, rounds, 0) |
| 41 | |
Jianliang Shen | 0b49b00 | 2023-08-18 14:07:05 +0800 | [diff] [blame] | 42 | /* |
| 43 | * Init profiling on secure side. |
| 44 | */ |
| 45 | #define PROFILING_INIT() prof_init() |
| 46 | |
Kevin Peng | dc06d4b | 2023-07-13 15:31:15 +0800 | [diff] [blame] | 47 | /* Get the calibration value from the tag. */ |
Summer Qin | 07e8f21 | 2023-07-05 17:05:07 +0800 | [diff] [blame] | 48 | #define PROF_GET_CALI_VALUE_FROM_TAG(tag) prof_get_cali_value( \ |
David Wang | bcb8b14 | 2022-02-17 17:31:40 +0800 | [diff] [blame] | 49 | PROF_GET_CALI_IDX_FROM_TAG(tag)) |
| 50 | |
Kevin Peng | dc06d4b | 2023-07-13 15:31:15 +0800 | [diff] [blame] | 51 | /* |
| 52 | * Get data, not calibrated. |
| 53 | * The calibrated counter (diff) is |
| 54 | * "current_counter" - "previous_counter" - "current_cali_value" |
| 55 | * "current_cali_value" = PROF_GET_CALI_VALUE_FROM_TAG(current_tag) |
| 56 | * |
| 57 | * "tag" and "data" are outputs which should be pointers. |
| 58 | * "tag" is used to get calibration data. |
| 59 | */ |
| 60 | #define PROF_FETCH_DATA_START(tag, data, cp, topic) \ |
| 61 | prof_get_data_start(tag, data, \ |
| 62 | PROF_MAKE_TIMING_TAG(cp, topic, 0, 0), PROF_MASK_TOPIC_CP) |
David Wang | bcb8b14 | 2022-02-17 17:31:40 +0800 | [diff] [blame] | 63 | |
Kevin Peng | dc06d4b | 2023-07-13 15:31:15 +0800 | [diff] [blame] | 64 | #define PROF_FETCH_DATA_CONTINUE(tag, data, cp, topic) \ |
| 65 | prof_get_data_continue(tag, data, \ |
| 66 | PROF_MAKE_TIMING_TAG(cp, topic, 0, 0), PROF_MASK_TOPIC_CP) |
David Wang | bcb8b14 | 2022-02-17 17:31:40 +0800 | [diff] [blame] | 67 | |
| 68 | #define PROF_FETCH_DATA_BY_TOPIC_START(tag, data, topic) \ |
| 69 | prof_get_data_start(tag, data, \ |
| 70 | PROF_MAKE_TIMING_TAG(0, topic, 0, 0), PROF_MASK_TOPIC) |
| 71 | |
| 72 | #define PROF_FETCH_DATA_BY_TOPIC_CONTINUE(tag, data, topic) \ |
| 73 | prof_get_data_continue(tag, data, \ |
| 74 | PROF_MAKE_TIMING_TAG(0, topic, 0, 0), PROF_MASK_TOPIC) |
| 75 | |
Summer Qin | 07e8f21 | 2023-07-05 17:05:07 +0800 | [diff] [blame] | 76 | /* Data analysis with calibration */ |
| 77 | #define PROF_DATA_DIFF(cp_a, topic_a, cp_b, topic_b) \ |
| 78 | prof_data_diff(PROF_MAKE_TIMING_TAG((cp_a), (topic_a), \ |
| 79 | PROF_CALI_IDX_S, \ |
| 80 | PROF_TYPE_TIMING_LOG), \ |
| 81 | PROF_MAKE_TIMING_TAG((cp_b), (topic_b), \ |
| 82 | PROF_CALI_IDX_S, \ |
| 83 | PROF_TYPE_TIMING_LOG)) |
| 84 | |
| 85 | #define PROF_DATA_DIFF_MIN(cp_a, topic_a, cp_b, topic_b) \ |
| 86 | prof_data_diff_min(PROF_MAKE_TIMING_TAG((cp_a), (topic_a), \ |
| 87 | PROF_CALI_IDX_S, \ |
| 88 | PROF_TYPE_TIMING_LOG), \ |
| 89 | PROF_MAKE_TIMING_TAG((cp_b), (topic_b), \ |
| 90 | PROF_CALI_IDX_S, \ |
| 91 | PROF_TYPE_TIMING_LOG)) |
| 92 | |
| 93 | #define PROF_DATA_DIFF_MAX(cp_a, topic_a, cp_b, topic_b) \ |
| 94 | prof_data_diff_max(PROF_MAKE_TIMING_TAG((cp_a), (topic_a), \ |
| 95 | PROF_CALI_IDX_S, \ |
| 96 | PROF_TYPE_TIMING_LOG), \ |
| 97 | PROF_MAKE_TIMING_TAG((cp_b), (topic_b), \ |
| 98 | PROF_CALI_IDX_S, \ |
| 99 | PROF_TYPE_TIMING_LOG)) |
| 100 | |
| 101 | #define PROF_DATA_DIFF_AVG(cp_a, topic_a, cp_b, topic_b) \ |
| 102 | prof_data_diff_avg(PROF_MAKE_TIMING_TAG((cp_a), (topic_a), \ |
| 103 | PROF_CALI_IDX_S, \ |
| 104 | PROF_TYPE_TIMING_LOG), \ |
| 105 | PROF_MAKE_TIMING_TAG((cp_b), (topic_b), \ |
| 106 | PROF_CALI_IDX_S, \ |
| 107 | PROF_TYPE_TIMING_LOG)) |
| 108 | |
David Wang | bcb8b14 | 2022-02-17 17:31:40 +0800 | [diff] [blame] | 109 | #ifdef __cplusplus |
| 110 | } |
| 111 | #endif |
| 112 | |
Jianliang Shen | e898f5c | 2023-08-10 15:20:33 +0800 | [diff] [blame] | 113 | #endif /* __PROF_INTF_S_H__ */ |