blob: e24b859e3e6acee106ccbdfb2ba3966e58f09867 [file] [log] [blame]
David Wangbcb8b142022-02-17 17:31:40 +08001/*
2 * Copyright (c) 2021-2022, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8#ifndef __PROF_IF_S_H__
9#define __PROF_IF_S_H__
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
19extern "C" {
20#endif
21
22/*
23 * Topic based timing logging
24 */
Summer Qin521677e2023-07-19 14:01:47 +080025#define PROF_TIMING_LOG(cp_id, topic_id) \
David Wangbcb8b142022-02-17 17:31:40 +080026 prof_timing_cp( \
27 PROF_MAKE_TIMING_TAG((cp_id), (topic_id), PROF_CALI_IDX_S, \
28 PROF_TYPE_TIMING_LOG))
29
30/*
31 * Get the timing value for further calibration
32 * The difference with checkpoint is that the calibration item doesn't increase
33 * the index in database. So, the calibration item can be overwritten by other
34 * items. The reason of keeping writing calibration data into database is that
35 * we want to make a full cycle of saving an item into the database to more
36 * accurately reflect the latency.
37 */
38#define PROF_TIMING_CALIBRATE() prof_timing_cp( \
39 PROF_MAKE_TIMING_TAG(0, 0, 0, PROF_TYPE_TIMING_CALI))
40
41/*
42 * Secure side can call this macro to do/redo calibration
43 * Suggest to do/redo calibration before running the profiling. It's because the
44 * latency introduced by the profiler may be changed in the system lifecycle.
45 * For example, enable caches, change CPU frequency, etc.
46 * 'rounds' sets how many rounds executed for the calibration. In theory, "more
47 * rounds" is more accurate.
48 * Set `rounds` to `0` to reset the calibration value to 0.
49 */
50#define PROF_DO_CALIBRATE(rounds) prof_calibrate( \
51 PROF_CALI_IDX_S, rounds, 0)
52
53/*
54 * Get the calibration value from the tag.
55 * The calibrated counter is
56 * "current_counter" - "previous_counter" - "current_cali_value"
57 * "current_cali_value" = PROF_GET_CALI_VALUE_FROM_TAG(current_tag)
58 */
Summer Qin07e8f212023-07-05 17:05:07 +080059#define PROF_GET_CALI_VALUE_FROM_TAG(tag) prof_get_cali_value( \
David Wangbcb8b142022-02-17 17:31:40 +080060 PROF_GET_CALI_IDX_FROM_TAG(tag))
61
62/* Get data */
63#define PROF_FETCH_DATA_START(tag, data, tag_pattern, tag_mask) \
64 prof_get_data_start(tag, data, tag_pattern, tag_mask)
65
66#define PROF_FETCH_DATA_CONTINUE(tag, data, tag_pattern, tag_mask) \
67 prof_get_data_continue(tag, data, tag_pattern, tag_mask)
68
69#define PROF_FETCH_DATA_BY_TOPIC_START(tag, data, topic) \
70 prof_get_data_start(tag, data, \
71 PROF_MAKE_TIMING_TAG(0, topic, 0, 0), PROF_MASK_TOPIC)
72
73#define PROF_FETCH_DATA_BY_TOPIC_CONTINUE(tag, data, topic) \
74 prof_get_data_continue(tag, data, \
75 PROF_MAKE_TIMING_TAG(0, topic, 0, 0), PROF_MASK_TOPIC)
76
Summer Qin521677e2023-07-19 14:01:47 +080077#define PROF_FETCH_DATA_BY_CP_START(tag, data, cp, topic) \
David Wangbcb8b142022-02-17 17:31:40 +080078 prof_get_data_start(tag, data, \
79 PROF_MAKE_TIMING_TAG(cp, topic, 0, 0), PROF_MASK_TOPIC_CP)
80
Summer Qin521677e2023-07-19 14:01:47 +080081#define PROF_FETCH_DATA_BY_CP_CONTINUE(tag, data, cp, topic) \
David Wangbcb8b142022-02-17 17:31:40 +080082 prof_get_data_continue(tag, data, \
83 PROF_MAKE_TIMING_TAG(cp, topic, 0, 0), PROF_MASK_TOPIC_CP)
84
Summer Qin07e8f212023-07-05 17:05:07 +080085/* Data analysis with calibration */
86#define PROF_DATA_DIFF(cp_a, topic_a, cp_b, topic_b) \
87 prof_data_diff(PROF_MAKE_TIMING_TAG((cp_a), (topic_a), \
88 PROF_CALI_IDX_S, \
89 PROF_TYPE_TIMING_LOG), \
90 PROF_MAKE_TIMING_TAG((cp_b), (topic_b), \
91 PROF_CALI_IDX_S, \
92 PROF_TYPE_TIMING_LOG))
93
94#define PROF_DATA_DIFF_MIN(cp_a, topic_a, cp_b, topic_b) \
95 prof_data_diff_min(PROF_MAKE_TIMING_TAG((cp_a), (topic_a), \
96 PROF_CALI_IDX_S, \
97 PROF_TYPE_TIMING_LOG), \
98 PROF_MAKE_TIMING_TAG((cp_b), (topic_b), \
99 PROF_CALI_IDX_S, \
100 PROF_TYPE_TIMING_LOG))
101
102#define PROF_DATA_DIFF_MAX(cp_a, topic_a, cp_b, topic_b) \
103 prof_data_diff_max(PROF_MAKE_TIMING_TAG((cp_a), (topic_a), \
104 PROF_CALI_IDX_S, \
105 PROF_TYPE_TIMING_LOG), \
106 PROF_MAKE_TIMING_TAG((cp_b), (topic_b), \
107 PROF_CALI_IDX_S, \
108 PROF_TYPE_TIMING_LOG))
109
110#define PROF_DATA_DIFF_AVG(cp_a, topic_a, cp_b, topic_b) \
111 prof_data_diff_avg(PROF_MAKE_TIMING_TAG((cp_a), (topic_a), \
112 PROF_CALI_IDX_S, \
113 PROF_TYPE_TIMING_LOG), \
114 PROF_MAKE_TIMING_TAG((cp_b), (topic_b), \
115 PROF_CALI_IDX_S, \
116 PROF_TYPE_TIMING_LOG))
117
David Wangbcb8b142022-02-17 17:31:40 +0800118#ifdef __cplusplus
119}
120#endif
121
122#endif /* __PROF_IF_S_H__ */