blob: 17fbb25a5a76f5729ecbeb8ff752f4ff6189ae73 [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_NS_H__
9#define __PROF_IF_NS_H__
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
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/*
30 * Get the timing value for further calibration
31 * The difference with checkpoint is that the calibration item doesn't increase
32 * the index in database. So, the calibration item can be overwritten by other
33 * items. The reason of keeping writing calibration data into database is that
34 * we want to make a full cycle of saving an item into the database to more
35 * accurately reflect the latency.
36 */
37#define PROF_TIMING_CALIBRATE() prof_timing_cp_veneer( \
38 PROF_MAKE_TIMING_TAG(0, 0, 0, \
39 PROF_TYPE_TIMING_CALI))
40
41/*
42 * Non-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_ns(rounds)
51
52/*
53 * Get the calibration value from the tag.
54 * The calibrated counter is
55 * "current_counter" - "previous_counter" - "current_cali_value"
56 * "current_cali_value" = PROF_GET_CALI_VALUE_FROM_TAG(current_tag)
57 */
58#define PROF_GET_CALI_VALUE_FROM_TAG(tag) prof_get_cali_value_veneer( \
59 PROF_GET_CALI_IDX_FROM_TAG(tag))
60
61/* Get data */
62#define PROF_FETCH_DATA_START(tag, data, tag_pattern, tag_mask) \
63 prof_get_data_start_veneer(tag, data, tag_pattern, tag_mask)
64
65#define PROF_FETCH_DATA_CONTINUE(tag, data, tag_pattern, tag_mask) \
66 prof_get_data_continue_veneer(tag, data, tag_pattern, tag_mask)
67
68#define PROF_FETCH_DATA_BY_TOPIC_START(tag, data, topic) \
69 prof_get_data_start_veneer(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_veneer(tag, data, \
74 PROF_MAKE_TIMING_TAG(0, topic, 0, 0), PROF_MASK_TOPIC)
75
Summer Qin521677e2023-07-19 14:01:47 +080076#define PROF_FETCH_DATA_BY_CP_START(tag, data, cp, topic) \
David Wangbcb8b142022-02-17 17:31:40 +080077 prof_get_data_start_veneer(tag, data, \
78 PROF_MAKE_TIMING_TAG(cp, topic, 0, 0), PROF_MASK_TOPIC_CP)
79
Summer Qin521677e2023-07-19 14:01:47 +080080#define PROF_FETCH_DATA_BY_CP_CONTINUE(tag, data, cp, topic) \
David Wangbcb8b142022-02-17 17:31:40 +080081 prof_get_data_continue_veneer(tag, data, \
82 PROF_MAKE_TIMING_TAG(cp, topic, 0, 0), PROF_MASK_TOPIC_CP)
83
84void prof_calibrate_ns(uint32_t rounds);
85
86#ifdef __cplusplus
87}
88#endif
89
90#endif /* __PROF_IF_NS_H__ */