blob: 6dd445e6f5f9d25565e5c9617c0a9493b47b4fb9 [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
Jianliang Shene898f5c2023-08-10 15:20:33 +08008#ifndef __PROF_INTF_S_H__
9#define __PROF_INTF_S_H__
David Wangbcb8b142022-02-17 17:31:40 +080010
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/*
David Wangbcb8b142022-02-17 17:31:40 +080031 * 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 Shen0b49b002023-08-18 14:07:05 +080042/*
43 * Init profiling on secure side.
44 */
45#define PROFILING_INIT() prof_init()
46
Kevin Pengdc06d4b2023-07-13 15:31:15 +080047/* Get the calibration value from the tag. */
Summer Qin07e8f212023-07-05 17:05:07 +080048#define PROF_GET_CALI_VALUE_FROM_TAG(tag) prof_get_cali_value( \
David Wangbcb8b142022-02-17 17:31:40 +080049 PROF_GET_CALI_IDX_FROM_TAG(tag))
50
Kevin Pengdc06d4b2023-07-13 15:31:15 +080051/*
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 Wangbcb8b142022-02-17 17:31:40 +080063
Kevin Pengdc06d4b2023-07-13 15:31:15 +080064#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 Wangbcb8b142022-02-17 17:31:40 +080067
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 Qin07e8f212023-07-05 17:05:07 +080076/* 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 Wangbcb8b142022-02-17 17:31:40 +0800109#ifdef __cplusplus
110}
111#endif
112
Jianliang Shene898f5c2023-08-10 15:20:33 +0800113#endif /* __PROF_INTF_S_H__ */