summaryrefslogtreecommitdiff
path: root/driver/product/kernel/drivers/gpu/arm/midgard/mali_kbase_trace_timeline.h
blob: 619072f3215cea9e5dd0d87b58f314ffecddb2ab (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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
/*
 *
 * (C) COPYRIGHT 2012-2016 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 licence.
 *
 * A copy of the licence is included with the program, and can also be obtained
 * from Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301, USA.
 *
 */





#if !defined(_KBASE_TRACE_TIMELINE_H)
#define _KBASE_TRACE_TIMELINE_H

#ifdef CONFIG_MALI_TRACE_TIMELINE

enum kbase_trace_timeline_code {
	#define KBASE_TIMELINE_TRACE_CODE(enum_val, desc, format, format_desc) enum_val
	#include "mali_kbase_trace_timeline_defs.h"
	#undef KBASE_TIMELINE_TRACE_CODE
};

#ifdef CONFIG_DEBUG_FS

/** Initialize Timeline DebugFS entries */
void kbasep_trace_timeline_debugfs_init(struct kbase_device *kbdev);

#else /* CONFIG_DEBUG_FS */

#define kbasep_trace_timeline_debugfs_init CSTD_NOP

#endif /* CONFIG_DEBUG_FS */

/* mali_timeline.h defines kernel tracepoints used by the KBASE_TIMELINE
 * functions.
 * Output is timestamped by either sched_clock() (default), local_clock(), or
 * cpu_clock(), depending on /sys/kernel/debug/tracing/trace_clock */
#include "mali_timeline.h"

/* Trace number of atoms in flight for kctx (atoms either not completed, or in
   process of being returned to user */
#define KBASE_TIMELINE_ATOMS_IN_FLIGHT(kctx, count)                          \
	do {                                                                 \
		struct timespec ts;                                          \
		getrawmonotonic(&ts);                                        \
		trace_mali_timeline_atoms_in_flight(ts.tv_sec, ts.tv_nsec,   \
				(int)kctx->timeline.owner_tgid,              \
				count);                                      \
	} while (0)

/* Trace atom_id being Ready to Run */
#define KBASE_TIMELINE_ATOM_READY(kctx, atom_id)                             \
	do {                                                                 \
		struct timespec ts;                                          \
		getrawmonotonic(&ts);                                        \
		trace_mali_timeline_atom(ts.tv_sec, ts.tv_nsec,              \
				CTX_FLOW_ATOM_READY,                         \
				(int)kctx->timeline.owner_tgid,              \
				atom_id);                                    \
	} while (0)

/* Trace number of atoms submitted to job slot js
 *
 * NOTE: This uses a different tracepoint to the head/next/soft-stop actions,
 * so that those actions can be filtered out separately from this
 *
 * This is because this is more useful, as we can use it to calculate general
 * utilization easily and accurately */
#define KBASE_TIMELINE_ATOMS_SUBMITTED(kctx, js, count)                      \
	do {                                                                 \
		struct timespec ts;                                          \
		getrawmonotonic(&ts);                                        \
		trace_mali_timeline_gpu_slot_active(ts.tv_sec, ts.tv_nsec,   \
				SW_SET_GPU_SLOT_ACTIVE,                      \
				(int)kctx->timeline.owner_tgid,              \
				js, count);                                  \
	} while (0)


/* Trace atoms present in JS_NEXT */
#define KBASE_TIMELINE_JOB_START_NEXT(kctx, js, count)                       \
	do {                                                                 \
		struct timespec ts;                                          \
		getrawmonotonic(&ts);                                        \
		trace_mali_timeline_gpu_slot_action(ts.tv_sec, ts.tv_nsec,   \
				SW_SET_GPU_SLOT_NEXT,                        \
				(int)kctx->timeline.owner_tgid,              \
				js, count);                                  \
	} while (0)

/* Trace atoms present in JS_HEAD */
#define KBASE_TIMELINE_JOB_START_HEAD(kctx, js, count)                       \
	do {                                                                 \
		struct timespec ts;                                          \
		getrawmonotonic(&ts);                                        \
		trace_mali_timeline_gpu_slot_action(ts.tv_sec, ts.tv_nsec,   \
				SW_SET_GPU_SLOT_HEAD,                        \
				(int)kctx->timeline.owner_tgid,              \
				js, count);                                  \
	} while (0)

/* Trace that a soft stop/evict from next is being attempted on a slot */
#define KBASE_TIMELINE_TRY_SOFT_STOP(kctx, js, count) \
	do {                                                                 \
		struct timespec ts;                                          \
		getrawmonotonic(&ts);                                        \
		trace_mali_timeline_gpu_slot_action(ts.tv_sec, ts.tv_nsec,   \
				SW_SET_GPU_SLOT_STOPPING,                    \
				(kctx) ? (int)kctx->timeline.owner_tgid : 0, \
				js, count);                                  \
	} while (0)



/* Trace state of overall GPU power */
#define KBASE_TIMELINE_GPU_POWER(kbdev, active)                              \
	do {                                                                 \
		struct timespec ts;                                          \
		getrawmonotonic(&ts);                                        \
		trace_mali_timeline_gpu_power_active(ts.tv_sec, ts.tv_nsec,  \
				SW_SET_GPU_POWER_ACTIVE, active);            \
	} while (0)

/* Trace state of tiler power */
#define KBASE_TIMELINE_POWER_TILER(kbdev, bitmap)                            \
	do {                                                                 \
		struct timespec ts;                                          \
		getrawmonotonic(&ts);                                        \
		trace_mali_timeline_gpu_power_active(ts.tv_sec, ts.tv_nsec,  \
				SW_SET_GPU_POWER_TILER_ACTIVE,               \
				hweight64(bitmap));                          \
	} while (0)

/* Trace number of shaders currently powered */
#define KBASE_TIMELINE_POWER_SHADER(kbdev, bitmap)                           \
	do {                                                                 \
		struct timespec ts;                                          \
		getrawmonotonic(&ts);                                        \
		trace_mali_timeline_gpu_power_active(ts.tv_sec, ts.tv_nsec,  \
				SW_SET_GPU_POWER_SHADER_ACTIVE,              \
				hweight64(bitmap));                          \
	} while (0)

/* Trace state of L2 power */
#define KBASE_TIMELINE_POWER_L2(kbdev, bitmap)                               \
	do {                                                                 \
		struct timespec ts;                                          \
		getrawmonotonic(&ts);                                        \
		trace_mali_timeline_gpu_power_active(ts.tv_sec, ts.tv_nsec,  \
				SW_SET_GPU_POWER_L2_ACTIVE,                  \
				hweight64(bitmap));                          \
	} while (0)

/* Trace state of L2 cache*/
#define KBASE_TIMELINE_POWERING_L2(kbdev)                                    \
	do {                                                                 \
		struct timespec ts;                                          \
		getrawmonotonic(&ts);                                        \
		trace_mali_timeline_l2_power_active(ts.tv_sec, ts.tv_nsec,   \
				SW_FLOW_GPU_POWER_L2_POWERING,               \
				1);                                          \
	} while (0)

#define KBASE_TIMELINE_POWERED_L2(kbdev)                                     \
	do {                                                                 \
		struct timespec ts;                                          \
		getrawmonotonic(&ts);                                        \
		trace_mali_timeline_l2_power_active(ts.tv_sec, ts.tv_nsec,   \
				SW_FLOW_GPU_POWER_L2_ACTIVE,                 \
				1);                                          \
	} while (0)

/* Trace kbase_pm_send_event message send */
#define KBASE_TIMELINE_PM_SEND_EVENT(kbdev, event_type, pm_event_id)         \
	do {                                                                 \
		struct timespec ts;                                          \
		getrawmonotonic(&ts);                                        \
		trace_mali_timeline_pm_event(ts.tv_sec, ts.tv_nsec,          \
				SW_FLOW_PM_SEND_EVENT,                       \
				event_type, pm_event_id);                    \
	} while (0)

/* Trace kbase_pm_worker message receive */
#define KBASE_TIMELINE_PM_HANDLE_EVENT(kbdev, event_type, pm_event_id)       \
	do {                                                                 \
		struct timespec ts;                                          \
		getrawmonotonic(&ts);                                        \
		trace_mali_timeline_pm_event(ts.tv_sec, ts.tv_nsec,          \
				SW_FLOW_PM_HANDLE_EVENT,                     \
				event_type, pm_event_id);                    \
	} while (0)


/* Trace atom_id starting in JS_HEAD */
#define KBASE_TIMELINE_JOB_START(kctx, js, _consumerof_atom_number)          \
	do {                                                                 \
		struct timespec ts;                                          \
		getrawmonotonic(&ts);                                        \
		trace_mali_timeline_slot_atom(ts.tv_sec, ts.tv_nsec,         \
				HW_START_GPU_JOB_CHAIN_SW_APPROX,            \
				(int)kctx->timeline.owner_tgid,              \
				js, _consumerof_atom_number);                \
	} while (0)

/* Trace atom_id stopping on JS_HEAD */
#define KBASE_TIMELINE_JOB_STOP(kctx, js, _producerof_atom_number_completed) \
	do {                                                                 \
		struct timespec ts;                                          \
		getrawmonotonic(&ts);                                        \
		trace_mali_timeline_slot_atom(ts.tv_sec, ts.tv_nsec,         \
				HW_STOP_GPU_JOB_CHAIN_SW_APPROX,             \
				(int)kctx->timeline.owner_tgid,              \
				js, _producerof_atom_number_completed);      \
	} while (0)

/** Trace beginning/end of a call to kbase_pm_check_transitions_nolock from a
 * certin caller */
#define KBASE_TIMELINE_PM_CHECKTRANS(kbdev, trace_code)                      \
	do {                                                                 \
		struct timespec ts;                                          \
		getrawmonotonic(&ts);                                        \
		trace_mali_timeline_pm_checktrans(ts.tv_sec, ts.tv_nsec,     \
				trace_code, 1);                              \
	} while (0)

/* Trace number of contexts active */
#define KBASE_TIMELINE_CONTEXT_ACTIVE(kbdev, count)                          \
	do {                                                                 \
		struct timespec ts;                                          \
		getrawmonotonic(&ts);                                        \
		trace_mali_timeline_context_active(ts.tv_sec, ts.tv_nsec,    \
				count);                                      \
	} while (0)

/* NOTE: kbase_timeline_pm_cores_func() is in mali_kbase_pm_policy.c */

/**
 * Trace that an atom is starting on a job slot
 *
 * The caller must be holding hwaccess_lock
 */
void kbase_timeline_job_slot_submit(struct kbase_device *kbdev, struct kbase_context *kctx,
		struct kbase_jd_atom *katom, int js);

/**
 * Trace that an atom has done on a job slot
 *
 * 'Done' in this sense can occur either because:
 * - the atom in JS_HEAD finished
 * - the atom in JS_NEXT was evicted
 *
 * Whether the atom finished or was evicted is passed in @a done_code
 *
 * It is assumed that the atom has already been removed from the submit slot,
 * with either:
 * - kbasep_jm_dequeue_submit_slot()
 * - kbasep_jm_dequeue_tail_submit_slot()
 *
 * The caller must be holding hwaccess_lock
 */
void kbase_timeline_job_slot_done(struct kbase_device *kbdev, struct kbase_context *kctx,
		struct kbase_jd_atom *katom, int js,
		kbasep_js_atom_done_code done_code);


/** Trace a pm event starting */
void kbase_timeline_pm_send_event(struct kbase_device *kbdev,
		enum kbase_timeline_pm_event event_sent);

/** Trace a pm event finishing */
void kbase_timeline_pm_check_handle_event(struct kbase_device *kbdev, enum kbase_timeline_pm_event event);

/** Check whether a pm event was present, and if so trace finishing it */
void kbase_timeline_pm_handle_event(struct kbase_device *kbdev, enum kbase_timeline_pm_event event);

/** Trace L2 power-up start */
void kbase_timeline_pm_l2_transition_start(struct kbase_device *kbdev);

/** Trace L2 power-up done */
void kbase_timeline_pm_l2_transition_done(struct kbase_device *kbdev);

#else

#define KBASE_TIMELINE_ATOMS_IN_FLIGHT(kctx, count) CSTD_NOP()

#define KBASE_TIMELINE_ATOM_READY(kctx, atom_id) CSTD_NOP()

#define KBASE_TIMELINE_ATOMS_SUBMITTED(kctx, js, count) CSTD_NOP()

#define KBASE_TIMELINE_JOB_START_NEXT(kctx, js, count) CSTD_NOP()

#define KBASE_TIMELINE_JOB_START_HEAD(kctx, js, count) CSTD_NOP()

#define KBASE_TIMELINE_TRY_SOFT_STOP(kctx, js, count) CSTD_NOP()

#define KBASE_TIMELINE_GPU_POWER(kbdev, active) CSTD_NOP()

#define KBASE_TIMELINE_POWER_TILER(kbdev, bitmap) CSTD_NOP()

#define KBASE_TIMELINE_POWER_SHADER(kbdev, bitmap) CSTD_NOP()

#define KBASE_TIMELINE_POWER_L2(kbdev, active) CSTD_NOP()

#define KBASE_TIMELINE_POWERING_L2(kbdev) CSTD_NOP()

#define KBASE_TIMELINE_POWERED_L2(kbdev)  CSTD_NOP()

#define KBASE_TIMELINE_PM_SEND_EVENT(kbdev, event_type, pm_event_id) CSTD_NOP()

#define KBASE_TIMELINE_PM_HANDLE_EVENT(kbdev, event_type, pm_event_id) CSTD_NOP()

#define KBASE_TIMELINE_JOB_START(kctx, js, _consumerof_atom_number) CSTD_NOP()

#define KBASE_TIMELINE_JOB_STOP(kctx, js, _producerof_atom_number_completed) CSTD_NOP()

#define KBASE_TIMELINE_PM_CHECKTRANS(kbdev, trace_code) CSTD_NOP()

#define KBASE_TIMELINE_CONTEXT_ACTIVE(kbdev, count) CSTD_NOP()

static inline void kbase_timeline_job_slot_submit(struct kbase_device *kbdev, struct kbase_context *kctx,
		struct kbase_jd_atom *katom, int js)
{
	lockdep_assert_held(&kbdev->hwaccess_lock);
}

static inline void kbase_timeline_job_slot_done(struct kbase_device *kbdev, struct kbase_context *kctx,
		struct kbase_jd_atom *katom, int js,
		kbasep_js_atom_done_code done_code)
{
	lockdep_assert_held(&kbdev->hwaccess_lock);
}

static inline void kbase_timeline_pm_send_event(struct kbase_device *kbdev, enum kbase_timeline_pm_event event_sent)
{
}

static inline void kbase_timeline_pm_check_handle_event(struct kbase_device *kbdev, enum kbase_timeline_pm_event event)
{
}

static inline void kbase_timeline_pm_handle_event(struct kbase_device *kbdev, enum kbase_timeline_pm_event event)
{
}

static inline void kbase_timeline_pm_l2_transition_start(struct kbase_device *kbdev)
{
}

static inline void kbase_timeline_pm_l2_transition_done(struct kbase_device *kbdev)
{
}
#endif				/* CONFIG_MALI_TRACE_TIMELINE */

#endif				/* _KBASE_TRACE_TIMELINE_H */