blob: 1fe9d5f89a55d3b6992a8b48492503e1ba1dd3f1 [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_NS_H__
9#define __PROF_INTF_NS_H__
David Wangbcb8b142022-02-17 17:31:40 +080010
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
18extern "C" {
19#endif
20
21/*
22 * Topic based timing logging
23 */
Summer Qin521677e2023-07-19 14:01:47 +080024#define PROF_TIMING_LOG(cp_id, topic_id) \
David Wangbcb8b142022-02-17 17:31:40 +080025 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 Wangbcb8b142022-02-17 17:31:40 +080030 * 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 Pengdc06d4b2023-07-13 15:31:15 +080040
41/* Get the calibration value from the tag. */
David Wangbcb8b142022-02-17 17:31:40 +080042#define PROF_GET_CALI_VALUE_FROM_TAG(tag) prof_get_cali_value_veneer( \
43 PROF_GET_CALI_IDX_FROM_TAG(tag))
44
Kevin Pengdc06d4b2023-07-13 15:31:15 +080045/*
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 Wangbcb8b142022-02-17 17:31:40 +080057
Kevin Pengdc06d4b2023-07-13 15:31:15 +080058#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 Wangbcb8b142022-02-17 17:31:40 +080061
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 Wangbcb8b142022-02-17 17:31:40 +080070void prof_calibrate_ns(uint32_t rounds);
71
Summer Qin07e8f212023-07-05 17:05:07 +080072/* 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 Wangbcb8b142022-02-17 17:31:40 +0800105#ifdef __cplusplus
106}
107#endif
108
Jianliang Shene898f5c2023-08-10 15:20:33 +0800109#endif /* __PROF_INTF_NS_H__ */