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_NS_H__ |
| 9 | #define __PROF_INTF_NS_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 non-secure side */ |
| 12 | |
| 13 | #include <stdint.h> |
| 14 | #include <stddef.h> |
| 15 | #include "prof_common.h" |
| 16 | |
| 17 | #ifdef __cplusplus |
| 18 | extern "C" { |
| 19 | #endif |
| 20 | |
| 21 | /* |
| 22 | * Topic based timing logging |
| 23 | */ |
Summer Qin | 521677e | 2023-07-19 14:01:47 +0800 | [diff] [blame] | 24 | #define PROF_TIMING_LOG(cp_id, topic_id) \ |
David Wang | bcb8b14 | 2022-02-17 17:31:40 +0800 | [diff] [blame] | 25 | prof_timing_cp_veneer( \ |
| 26 | PROF_MAKE_TIMING_TAG((cp_id), (topic_id), PROF_CALI_IDX_NS, \ |
| 27 | PROF_TYPE_TIMING_LOG)) |
| 28 | |
| 29 | /* |
David Wang | bcb8b14 | 2022-02-17 17:31:40 +0800 | [diff] [blame] | 30 | * Non-secure side can call this macro to do/redo calibration |
| 31 | * Suggest to do/redo calibration before running the profiling. It's because the |
| 32 | * latency introduced by the profiler may be changed in the system lifecycle. |
| 33 | * For example, enable caches, change CPU frequency, etc. |
| 34 | * 'rounds' sets how many rounds executed for the calibration. In theory, "more |
| 35 | * rounds" is more accurate. |
| 36 | * Set `rounds` to `0` to reset the calibration value to 0. |
| 37 | */ |
| 38 | #define PROF_DO_CALIBRATE(rounds) prof_calibrate_ns(rounds) |
| 39 | |
Kevin Peng | dc06d4b | 2023-07-13 15:31:15 +0800 | [diff] [blame] | 40 | |
| 41 | /* Get the calibration value from the tag. */ |
David Wang | bcb8b14 | 2022-02-17 17:31:40 +0800 | [diff] [blame] | 42 | #define PROF_GET_CALI_VALUE_FROM_TAG(tag) prof_get_cali_value_veneer( \ |
| 43 | PROF_GET_CALI_IDX_FROM_TAG(tag)) |
| 44 | |
Kevin Peng | dc06d4b | 2023-07-13 15:31:15 +0800 | [diff] [blame] | 45 | /* |
| 46 | * Get data, not calibrated. |
| 47 | * The calibrated counter (diff) is |
| 48 | * "current_counter" - "previous_counter" - "current_cali_value" |
| 49 | * "current_cali_value" = PROF_GET_CALI_VALUE_FROM_TAG(current_tag) |
| 50 | * |
| 51 | * "tag" and "data" are outputs which should be pointers. |
| 52 | * "tag" is used to get calibration data. |
| 53 | */ |
| 54 | #define PROF_FETCH_DATA_START(tag, data, cp, topic) \ |
| 55 | prof_get_data_start_veneer(tag, data, \ |
| 56 | PROF_MAKE_TIMING_TAG(cp, topic, 0, 0), PROF_MASK_TOPIC_CP) |
David Wang | bcb8b14 | 2022-02-17 17:31:40 +0800 | [diff] [blame] | 57 | |
Kevin Peng | dc06d4b | 2023-07-13 15:31:15 +0800 | [diff] [blame] | 58 | #define PROF_FETCH_DATA_CONTINUE(tag, data, cp, topic) \ |
| 59 | prof_get_data_continue_veneer(tag, data, \ |
| 60 | PROF_MAKE_TIMING_TAG(cp, topic, 0, 0), PROF_MASK_TOPIC_CP) |
David Wang | bcb8b14 | 2022-02-17 17:31:40 +0800 | [diff] [blame] | 61 | |
| 62 | #define PROF_FETCH_DATA_BY_TOPIC_START(tag, data, topic) \ |
| 63 | prof_get_data_start_veneer(tag, data, \ |
| 64 | PROF_MAKE_TIMING_TAG(0, topic, 0, 0), PROF_MASK_TOPIC) |
| 65 | |
| 66 | #define PROF_FETCH_DATA_BY_TOPIC_CONTINUE(tag, data, topic) \ |
| 67 | prof_get_data_continue_veneer(tag, data, \ |
| 68 | PROF_MAKE_TIMING_TAG(0, topic, 0, 0), PROF_MASK_TOPIC) |
| 69 | |
David Wang | bcb8b14 | 2022-02-17 17:31:40 +0800 | [diff] [blame] | 70 | void prof_calibrate_ns(uint32_t rounds); |
| 71 | |
Summer Qin | 07e8f21 | 2023-07-05 17:05:07 +0800 | [diff] [blame] | 72 | /* Data analysis with calibration */ |
| 73 | #define PROF_DATA_DIFF(cp_a, topic_a, cp_b, topic_b) \ |
| 74 | prof_data_diff_veneer(PROF_MAKE_TIMING_TAG((cp_a), (topic_a), \ |
| 75 | PROF_CALI_IDX_NS, \ |
| 76 | PROF_TYPE_TIMING_LOG), \ |
| 77 | PROF_MAKE_TIMING_TAG((cp_b), (topic_b), \ |
| 78 | PROF_CALI_IDX_NS, \ |
| 79 | PROF_TYPE_TIMING_LOG)) |
| 80 | |
| 81 | #define PROF_DATA_DIFF_MIN(cp_a, topic_a, cp_b, topic_b) \ |
| 82 | prof_data_diff_min_veneer(PROF_MAKE_TIMING_TAG((cp_a), (topic_a), \ |
| 83 | PROF_CALI_IDX_NS, \ |
| 84 | PROF_TYPE_TIMING_LOG), \ |
| 85 | PROF_MAKE_TIMING_TAG((cp_b), (topic_b), \ |
| 86 | PROF_CALI_IDX_NS, \ |
| 87 | PROF_TYPE_TIMING_LOG)) |
| 88 | |
| 89 | #define PROF_DATA_DIFF_MAX(cp_a, topic_a, cp_b, topic_b) \ |
| 90 | prof_data_diff_max_veneer(PROF_MAKE_TIMING_TAG((cp_a), (topic_a), \ |
| 91 | PROF_CALI_IDX_NS, \ |
| 92 | PROF_TYPE_TIMING_LOG), \ |
| 93 | PROF_MAKE_TIMING_TAG((cp_b), (topic_b), \ |
| 94 | PROF_CALI_IDX_NS, \ |
| 95 | PROF_TYPE_TIMING_LOG)) |
| 96 | |
| 97 | #define PROF_DATA_DIFF_AVG(cp_a, topic_a, cp_b, topic_b) \ |
| 98 | prof_data_diff_avg_veneer(PROF_MAKE_TIMING_TAG((cp_a), (topic_a), \ |
| 99 | PROF_CALI_IDX_NS, \ |
| 100 | PROF_TYPE_TIMING_LOG), \ |
| 101 | PROF_MAKE_TIMING_TAG((cp_b), (topic_b), \ |
| 102 | PROF_CALI_IDX_NS, \ |
| 103 | PROF_TYPE_TIMING_LOG)) |
| 104 | |
David Wang | bcb8b14 | 2022-02-17 17:31:40 +0800 | [diff] [blame] | 105 | #ifdef __cplusplus |
| 106 | } |
| 107 | #endif |
| 108 | |
Jianliang Shen | e898f5c | 2023-08-10 15:20:33 +0800 | [diff] [blame] | 109 | #endif /* __PROF_INTF_NS_H__ */ |