aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/arm/mali/mali_kbase_gpu_metrics.h
blob: adc8816a18dc96feebf8c84fe026800893c982c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
/*
 *
 * (C) COPYRIGHT 2023 ARM Limited. All rights reserved.
 *
 * This program is free software and is provided to you under the terms of the
 * GNU General Public License version 2 as published by the Free Software
 * Foundation, and any use by you of this program is subject to the terms
 * of such GNU license.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you can access it online at
 * http://www.gnu.org/licenses/gpl-2.0.html.
 *
 */

/**
 * DOC: GPU metrics frontend APIs
 */

#ifndef _KBASE_GPU_METRICS_H_
#define _KBASE_GPU_METRICS_H_

#if IS_ENABLED(CONFIG_MALI_TRACE_POWER_GPU_WORK_PERIOD)
#include <mali_kbase.h>

/**
 * kbase_gpu_metrics_get_emit_interval() - Return the trace point emission interval.
 *
 * Return: The time interval in nanosecond for GPU metrics trace point emission.
 */
unsigned long kbase_gpu_metrics_get_emit_interval(void);

/**
 * kbase_gpu_metrics_ctx_put() - Decrement the Kbase context count for the GPU metrics
 *                               context and free it if the count becomes 0.
 *
 * @kbdev:           Pointer to the GPU device.
 * @gpu_metrics_ctx: Pointer to the GPU metrics context.
 *
 * This function must be called when a Kbase context is destroyed.
 * The function would decrement the Kbase context count for the GPU metrics context and
 * free the memory if the count becomes 0.
 * The function would emit a power/gpu_work_period tracepoint for the GPU metrics context
 * if there was some GPU activity done for it since the last tracepoint was emitted.
 *
 * Note: The caller must appropriately serialize the call to this function with the
 *       call to other GPU metrics functions declared in this file.
 */
void kbase_gpu_metrics_ctx_put(struct kbase_device *kbdev,
			       struct kbase_gpu_metrics_ctx *gpu_metrics_ctx);

/**
 * kbase_gpu_metrics_ctx_get() - Increment the Kbase context count for the GPU metrics
 *                               context if it exists.
 *
 * @kbdev: Pointer to the GPU device.
 * @aid:   Unique identifier of the Application that is creating the Kbase context.
 *
 * This function must be called when a Kbase context is created.
 * The function would increment the Kbase context count for the GPU metrics context,
 * corresponding to the @aid, if it exists.
 *
 * Return: Pointer to the GPU metrics context corresponding to the @aid if it already
 * exists otherwise NULL.
 *
 * Note: The caller must appropriately serialize the call to this function with the
 *       call to other GPU metrics functions declared in this file.
 *       The caller shall allocate memory for GPU metrics context structure if the
 *       function returns NULL.
 */
struct kbase_gpu_metrics_ctx *kbase_gpu_metrics_ctx_get(struct kbase_device *kbdev, u32 aid);

/**
 * kbase_gpu_metrics_ctx_init() - Initialise the GPU metrics context
 *
 * @kbdev:           Pointer to the GPU device.
 * @gpu_metrics_ctx: Pointer to the GPU metrics context.
 * @aid:             Unique identifier of the Application for which GPU metrics
 *                   context needs to be initialized.
 *
 * This function must be called when a Kbase context is created, after the call to
 * kbase_gpu_metrics_ctx_get() returned NULL and memory for the GPU metrics context
 * structure was allocated.
 *
 * Note: The caller must appropriately serialize the call to this function with the
 *       call to other GPU metrics functions declared in this file.
 */
void kbase_gpu_metrics_ctx_init(struct kbase_device *kbdev,
				struct kbase_gpu_metrics_ctx *gpu_metrics_ctx, u32 aid);

/**
 * kbase_gpu_metrics_ctx_start_activity() - Report the start of some GPU activity
 *                                          for GPU metrics context.
 *
 * @kctx:         Pointer to the Kbase context contributing data to the GPU metrics context.
 * @timestamp_ns: CPU timestamp at which the GPU activity started.
 *
 * The provided timestamp would be later used as the "start_time_ns" for the
 * power/gpu_work_period tracepoint if this is the first GPU activity for the GPU
 * metrics context in the current work period.
 *
 * Note: The caller must appropriately serialize the call to this function with the
 *       call to other GPU metrics functions declared in this file.
 */
void kbase_gpu_metrics_ctx_start_activity(struct kbase_context *kctx, u64 timestamp_ns);

/**
 * kbase_gpu_metrics_ctx_end_activity() - Report the end of some GPU activity
 *                                        for GPU metrics context.
 *
 * @kctx:         Pointer to the Kbase context contributing data to the GPU metrics context.
 * @timestamp_ns: CPU timestamp at which the GPU activity ended.
 *
 * The provided timestamp would be later used as the "end_time_ns" for the
 * power/gpu_work_period tracepoint if this is the last GPU activity for the GPU
 * metrics context in the current work period.
 *
 * Note: The caller must appropriately serialize the call to this function with the
 *       call to other GPU metrics functions declared in this file.
 */
void kbase_gpu_metrics_ctx_end_activity(struct kbase_context *kctx, u64 timestamp_ns);

/**
 * kbase_gpu_metrics_emit_tracepoint() - Emit power/gpu_work_period tracepoint
 *                                       for active GPU metrics contexts.
 *
 * @kbdev: Pointer to the GPU device.
 * @ts:    Timestamp at which the tracepoint is being emitted.
 *
 * This function would loop through all the active GPU metrics contexts and emit a
 * power/gpu_work_period tracepoint for them.
 * The GPU metrics context that is found to be inactive since the last tracepoint
 * was emitted would be moved to the inactive list.
 * The current work period would be considered as over and a new work period would
 * begin whenever any application does the GPU activity.
 *
 * Note: The caller must appropriately serialize the call to this function with the
 *       call to other GPU metrics functions declared in this file.
 */
void kbase_gpu_metrics_emit_tracepoint(struct kbase_device *kbdev, u64 ts);

/**
 * kbase_gpu_metrics_init() - Initialise a gpu_metrics instance for a GPU
 *
 * @kbdev: Pointer to the GPU device.
 *
 * This function is called once for each @kbdev.
 *
 * Return: 0 on success, or negative on failure.
 */
int kbase_gpu_metrics_init(struct kbase_device *kbdev);

/**
 * kbase_gpu_metrics_term() - Terminate a gpu_metrics instance
 *
 * @kbdev: Pointer to the GPU device.
 */
void kbase_gpu_metrics_term(struct kbase_device *kbdev);

#endif
#endif  /* _KBASE_GPU_METRICS_H_ */