1 /*************************************************************************/ /*!
3 @Title PVR GPU Trace module Linux implementation
4 @Copyright Copyright (c) Imagination Technologies Ltd. All Rights Reserved
5 @License Dual MIT/GPLv2
7 The contents of this file are subject to the MIT license as set out below.
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
19 Alternatively, the contents of this file may be used under the terms of
20 the GNU General Public License Version 2 ("GPL") in which case the provisions
21 of GPL are applicable instead of those above.
23 If you wish to allow use of your version of this file only under the terms of
24 GPL, and not to allow others to use your version of this file under the terms
25 of the MIT license, indicate your decision by deleting the provisions above
26 and replace them with the notice and other provisions required by GPL as set
27 out in the file called "GPL-COPYING" included in this distribution. If you do
28 not delete the provisions above, a recipient may use your version of this file
29 under the terms of either the MIT license or GPL.
31 This License is also included in this distribution in the file called
34 EXCEPT AS OTHERWISE STATED IN A NEGOTIATED AGREEMENT: (A) THE SOFTWARE IS
35 PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
36 BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
37 PURPOSE AND NONINFRINGEMENT; AND (B) IN NO EVENT SHALL THE AUTHORS OR
38 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
39 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
40 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41 */ /**************************************************************************/
43 #include "pvrsrv_error.h"
45 #include "pvr_debug.h"
46 #include "pvr_debugfs.h"
47 #include "pvr_uaccess.h"
49 #include "pvr_gputrace.h"
50 #include "rgxhwperf.h"
52 #include "trace_events.h"
53 #define CREATE_TRACE_POINTS
54 #include <trace/events/gpu.h>
55 #include "rogue_trace_events.h"
59 /******************************************************************************
60 Module internal implementation
61 ******************************************************************************/
63 /* DebugFS entry for the feature's on/off file */
64 static PVR_DEBUGFS_ENTRY_DATA *gpsPVRDebugFSGpuTracingOnEntry = NULL;
66 /* This variable is set when the gpu tracing is enabled but the HWPerf
67 * resources have not been initialised yet. This may most likely happen
68 * if the driver was built with SUPPORT_KERNEL_SRVINIT=1.
69 * If this variable is IMG_TRUE it means that the gpu tracing was enabled
70 * but the full initialisation is yet to be done. */
71 static IMG_BOOL gbFTraceGPUEventsPreEnabled = IMG_FALSE;
72 /* When this variable is IMG_TRUE it means that the gpu tracing has been fully
73 * initialised and enabled. */
74 static IMG_BOOL gbFTraceGPUEventsEnabled = IMG_FALSE;
77 If SUPPORT_GPUTRACE_EVENTS is defined the drive is built with support
78 to route RGX HWPerf packets to the Linux FTrace mechanism. To allow
79 this routing feature to be switched on and off at run-time the following
80 debugfs entry is created:
81 /sys/kernel/debug/pvr/gpu_tracing_on
82 To enable GPU events in the FTrace log type the following on the target:
83 echo Y > /sys/kernel/debug/pvr/gpu_tracing_on
85 echo N > /sys/kernel/debug/pvr/gpu_tracing_on
87 It is also possible to enable this feature at driver load by setting the
88 default application hint "EnableFTraceGPU=1" in /etc/powervr.ini.
91 static void *GpuTracingSeqStart(struct seq_file *psSeqFile, loff_t *puiPosition)
93 if (*puiPosition == 0)
95 /* We want only one entry in the sequence, one call to show() */
103 static void GpuTracingSeqStop(struct seq_file *psSeqFile, void *pvData)
105 PVR_UNREFERENCED_PARAMETER(psSeqFile);
109 static void *GpuTracingSeqNext(struct seq_file *psSeqFile, void *pvData, loff_t *puiPosition)
111 PVR_UNREFERENCED_PARAMETER(psSeqFile);
116 static int GpuTracingSeqShow(struct seq_file *psSeqFile, void *pvData)
118 const IMG_CHAR *pszInit = "N\n";
120 if (gbFTraceGPUEventsEnabled)
123 else if (gbFTraceGPUEventsPreEnabled)
124 // partially initialised (probably HWPerf not initialised yet)
127 PVR_UNREFERENCED_PARAMETER(pvData);
129 seq_puts(psSeqFile, pszInit);
134 static struct seq_operations gsGpuTracingReadOps =
136 .start = GpuTracingSeqStart,
137 .stop = GpuTracingSeqStop,
138 .next = GpuTracingSeqNext,
139 .show = GpuTracingSeqShow,
143 static IMG_INT GpuTracingSet(const IMG_CHAR *buffer, size_t count, loff_t uiPosition, void *data)
147 PVR_UNREFERENCED_PARAMETER(uiPosition);
148 PVR_UNREFERENCED_PARAMETER(data);
155 if (pvr_copy_from_user(&cFirstChar, buffer, 1))
166 PVRGpuTraceEnabledSet(IMG_FALSE);
167 PVR_TRACE(("DISABLED GPU FTrace"));
174 if (PVRGpuTraceEnabledSet(IMG_TRUE) == PVRSRV_OK)
176 PVR_TRACE(("ENABLED GPU FTrace"));
180 PVR_TRACE(("FAILED to enable GPU FTrace"));
190 /******************************************************************************
192 ******************************************************************************/
195 void PVRGpuTraceClientWork(
196 const IMG_UINT32 ui32CtxId,
197 const IMG_UINT32 ui32JobId,
198 const IMG_CHAR* pszKickType)
200 PVR_ASSERT(pszKickType);
202 PVR_DPF((PVR_DBG_VERBOSE, "PVRGpuTraceClientKick(%s): contextId %u, "
203 "jobId %u", pszKickType, ui32CtxId, ui32JobId));
205 if (PVRGpuTraceEnabled())
207 trace_gpu_job_enqueue(ui32CtxId, ui32JobId, pszKickType);
212 void PVRGpuTraceWorkSwitch(
213 IMG_UINT64 ui64HWTimestampInOSTime,
214 const IMG_UINT32 ui32CtxId,
215 const IMG_UINT32 ui32CtxPriority,
216 const IMG_UINT32 ui32JobId,
217 const IMG_CHAR* pszWorkType,
218 PVR_GPUTRACE_SWITCH_TYPE eSwType)
220 PVR_ASSERT(pszWorkType);
222 /* Invert the priority cause this is what systrace expects. Lower values
223 * convey a higher priority to systrace. */
224 trace_gpu_sched_switch(pszWorkType, ui64HWTimestampInOSTime,
225 eSwType == PVR_GPUTRACE_SWITCH_TYPE_END ? 0 : ui32CtxId,
226 2-ui32CtxPriority, ui32JobId);
230 IMG_UINT64 ui64OSTimestamp,
231 const RGX_HWPERF_UFO_EV eEvType,
232 const IMG_UINT32 ui32ExtJobRef,
233 const IMG_UINT32 ui32CtxId,
234 const IMG_UINT32 ui32JobId,
235 const IMG_UINT32 ui32UFOCount,
236 const RGX_HWPERF_UFO_DATA_ELEMENT *puData)
239 case RGX_HWPERF_UFO_EV_UPDATE:
240 trace_rogue_ufo_updates(ui64OSTimestamp, ui32CtxId,
241 ui32JobId, ui32UFOCount, puData);
243 case RGX_HWPERF_UFO_EV_CHECK_SUCCESS:
244 trace_rogue_ufo_checks_success(ui64OSTimestamp, ui32CtxId,
245 ui32JobId, IMG_FALSE, ui32UFOCount, puData);
247 case RGX_HWPERF_UFO_EV_PRCHECK_SUCCESS:
248 trace_rogue_ufo_checks_success(ui64OSTimestamp, ui32CtxId,
249 ui32JobId, IMG_TRUE, ui32UFOCount, puData);
251 case RGX_HWPERF_UFO_EV_CHECK_FAIL:
252 trace_rogue_ufo_checks_fail(ui64OSTimestamp, ui32CtxId,
253 ui32JobId, IMG_FALSE, ui32UFOCount, puData);
255 case RGX_HWPERF_UFO_EV_PRCHECK_FAIL:
256 trace_rogue_ufo_checks_fail(ui64OSTimestamp, ui32CtxId,
257 ui32JobId, IMG_TRUE, ui32UFOCount, puData);
264 void PVRGpuTraceFirmware(
265 IMG_UINT64 ui64HWTimestampInOSTime,
266 const IMG_CHAR* pszWorkType,
267 PVR_GPUTRACE_SWITCH_TYPE eSwType)
269 trace_rogue_firmware_activity(ui64HWTimestampInOSTime, pszWorkType, eSwType);
272 void PVRGpuTraceEventsLost(
273 const RGX_HWPERF_STREAM_ID eStreamId,
274 const IMG_UINT32 ui32LastOrdinal,
275 const IMG_UINT32 ui32CurrOrdinal)
277 trace_rogue_events_lost(eStreamId, ui32LastOrdinal, ui32CurrOrdinal);
280 PVRSRV_ERROR PVRGpuTraceInit(PVRSRV_DEVICE_NODE *psDeviceNode)
284 eError = RGXHWPerfFTraceGPUInit(psDeviceNode);
285 if (eError != PVRSRV_OK)
288 eError = PVRDebugFSCreateEntry("gpu_tracing_on", NULL, &gsGpuTracingReadOps,
289 (PVRSRV_ENTRY_WRITE_FUNC *)GpuTracingSet,
291 &gpsPVRDebugFSGpuTracingOnEntry);
292 if (eError != PVRSRV_OK)
294 RGXHWPerfFTraceGPUDeInit(psDeviceNode);
301 void PVRGpuTraceDeInit(PVRSRV_DEVICE_NODE *psDeviceNode)
303 /* gbFTraceGPUEventsEnabled and gbFTraceGPUEventsPreEnabled are cleared
304 * in this function. */
305 PVRGpuTraceEnabledSet(IMG_FALSE);
307 RGXHWPerfFTraceGPUDeInit(psDeviceNode);
309 /* Can be NULL if driver startup failed */
310 if (gpsPVRDebugFSGpuTracingOnEntry)
312 PVRDebugFSRemoveEntry(&gpsPVRDebugFSGpuTracingOnEntry);
316 IMG_BOOL PVRGpuTraceEnabled(void)
318 return gbFTraceGPUEventsEnabled;
321 void PVRGpuTraceSetEnabled(IMG_BOOL bEnabled)
323 gbFTraceGPUEventsEnabled = bEnabled;
326 IMG_BOOL PVRGpuTracePreEnabled(void)
328 return gbFTraceGPUEventsPreEnabled;
331 void PVRGpuTraceSetPreEnabled(IMG_BOOL bEnabled)
333 gbFTraceGPUEventsPreEnabled = bEnabled;
336 /******************************************************************************
337 End of file (pvr_gputrace.c)
338 ******************************************************************************/