[processor-sdk/pdk.git] / packages / ti / drv / udma / unit_test / udma_ut / src / utils_prf_baremetal.c
1 /* =============================================================================
2 * Copyright (c) Texas Instruments Incorporated 2012-2017
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the
14 * distribution.
15 *
16 * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
33 /**
34 * \file utils_prf_baremetal.c
35 *
36 * \brief Profiling API utility file for baremetal.
37 *
38 */
40 /* ========================================================================== */
41 /* Include Files */
42 /* ========================================================================== */
44 #include <string.h>
45 #include <ti/osal/osal.h>
46 #include "udma_test.h"
48 /* ========================================================================== */
49 /* Macros & Typedefs */
50 /* ========================================================================== */
51 /* None */
53 /* ========================================================================== */
54 /* Structure Declarations */
55 /* ========================================================================== */
57 typedef struct
58 {
59 Bool isAlloc;
60 Char name[32];
61 TaskP_Handle pTsk;
62 UInt64 totalTskThreadTime;
63 } Utils_PrfLoadObj;
65 typedef struct
66 {
67 Utils_PrfTsHndl tsObj[UTILS_PRF_MAX_HNDL];
68 Utils_PrfLoadObj loadObj[UTILS_PRF_MAX_HNDL];
69 } Utils_PrfObj;
71 typedef struct
72 {
73 UInt64 totalSwiThreadTime;
74 UInt64 totalHwiThreadTime;
75 UInt64 totalTime;
76 UInt64 totalIdlTskTime;
77 } Utils_AccPrfLoadObj;
79 /* ========================================================================== */
80 /* Function Declarations */
81 /* ========================================================================== */
83 /* None */
85 /* ========================================================================== */
86 /* Global Variables */
87 /* ========================================================================== */
89 static Utils_PrfObj gUtils_prfObj;
90 static Utils_AccPrfLoadObj gUtils_accPrfLoadObj;
92 /* ========================================================================== */
93 /* Function Definitions */
94 /* ========================================================================== */
96 Int32 Utils_prfInit(void)
97 {
98 memset(&gUtils_prfObj, 0, sizeof (gUtils_prfObj));
99 memset(&gUtils_accPrfLoadObj, 0, sizeof (Utils_AccPrfLoadObj));
101 return (0);
102 }
104 Int32 Utils_prfDeInit(void)
105 {
106 return (0);
107 }
109 Utils_PrfTsHndl *Utils_prfTsCreate(const Char *name)
110 {
111 UInt32 hndlId;
112 UInt32 cookie;
113 Utils_PrfTsHndl *pHndl = NULL;
115 cookie = HwiP_disable();
117 for (hndlId = 0; hndlId < UTILS_PRF_MAX_HNDL; hndlId++)
118 {
119 pHndl = &gUtils_prfObj.tsObj[hndlId];
121 if (FALSE == pHndl->isAlloc)
122 {
123 /* One less for NULL character */
124 strncpy(pHndl->name, name, ((UInt32) sizeof (pHndl->name) - 1U));
125 pHndl->name[sizeof (pHndl->name) - 1U] = (UInt8) '\0';
126 pHndl->isAlloc = (Bool) TRUE;
127 Utils_prfTsReset(pHndl);
128 break;
129 }
130 }
132 HwiP_restore(cookie);
134 return (pHndl);
135 }
137 Int32 Utils_prfTsDelete(Utils_PrfTsHndl *pHndl)
138 {
139 pHndl->isAlloc = (Bool) FALSE;
140 return (0);
141 }
143 UInt64 Utils_prfTsBegin(Utils_PrfTsHndl *pHndl)
144 {
145 pHndl->startTs = Utils_prfTsGet64();
147 return (pHndl->startTs);
148 }
150 UInt64 Utils_prfTsEnd(Utils_PrfTsHndl *pHndl, UInt32 numFrames)
151 {
152 return (Utils_prfTsDelta(pHndl, pHndl->startTs, numFrames));
153 }
155 UInt64 Utils_prfTsDelta(Utils_PrfTsHndl *pHndl,
156 UInt64 startTime,
157 UInt32 numFrames)
158 {
159 UInt64 endTs;
160 UInt32 cookie;
162 endTs = Utils_prfTsGet64();
164 cookie = HwiP_disable();
166 pHndl->totalTs += (endTs - pHndl->startTs);
167 pHndl->count++;
168 pHndl->numFrames += numFrames;
170 HwiP_restore(cookie);
172 return (endTs);
173 }
175 Int32 Utils_prfTsReset(Utils_PrfTsHndl *pHndl)
176 {
177 UInt32 cookie;
179 cookie = HwiP_disable();
181 pHndl->totalTs = 0;
182 pHndl->count = 0;
183 pHndl->numFrames = 0;
185 HwiP_restore(cookie);
187 return (0);
188 }
190 UInt64 Utils_prfTsGet64(void)
191 {
192 UInt64 curTs = (UInt64) 0U;
193 return (curTs);
194 }
196 Int32 Utils_prfTsPrint(Utils_PrfTsHndl *pHndl, uint32_t resetAfterPrint, uint32_t trace)
197 {
198 UInt32 cpuKhz;
199 UInt32 timeMs, fps, fpc;
200 cpuKhz = 24000U;
203 timeMs = pHndl->totalTs / cpuKhz;
205 if(0U == timeMs)
206 {
207 fps = 0U;
208 }
209 else
210 {
211 fps = (pHndl->numFrames * (UInt32) 1000U) / timeMs;
212 }
213 if(0U == pHndl->count)
214 {
215 fpc = 0U;
216 }
217 else
218 {
219 fpc = pHndl->numFrames / pHndl->count;
220 }
222 GT_7trace(
223 trace, GT_INFO,
224 " %d: PRF : %s : t: %d ms, count: %d, frames: %d, fps: %d, fpc: %d \r\n",
225 AppUtils_getCurTimeInMsec(),
226 pHndl->name,
227 timeMs, /* in msecs */
228 pHndl->count,
229 pHndl->numFrames,
230 fps, /* frames per second */
231 fpc /* frames per count */
232 );
234 if (resetAfterPrint)
235 {
236 Utils_prfTsReset(pHndl);
237 }
239 return (0);
240 }
242 Int32 Utils_prfTsPrintAll(uint32_t resetAfterPrint, uint32_t trace)
243 {
244 UInt32 hndlId;
245 Utils_PrfTsHndl *pHndl;
247 GT_0trace(trace, GT_INFO, "\r\n");
249 for (hndlId = 0; hndlId < UTILS_PRF_MAX_HNDL; hndlId++)
250 {
251 pHndl = &gUtils_prfObj.tsObj[hndlId];
253 if (TRUE == pHndl->isAlloc)
254 {
255 Utils_prfTsPrint(pHndl, resetAfterPrint, trace);
256 }
257 }
259 GT_0trace(trace, GT_INFO, "\r\n");
261 return (0);
262 }
264 Int32 Utils_prfLoadRegister(TaskP_Handle pTsk, const Char *name)
265 {
266 UInt32 hndlId;
267 UInt32 cookie;
268 Int32 status = CSL_EFAIL;
269 Utils_PrfLoadObj *pHndl;
271 cookie = HwiP_disable();
273 for (hndlId = 0; hndlId < UTILS_PRF_MAX_HNDL; hndlId++)
274 {
275 pHndl = &gUtils_prfObj.loadObj[hndlId];
277 if (FALSE == pHndl->isAlloc)
278 {
279 pHndl->isAlloc = (Bool) TRUE;
280 pHndl->pTsk = pTsk;
281 /* One less for NULL character */
282 strncpy(pHndl->name, name, ((UInt32) sizeof (pHndl->name) - 1U));
283 pHndl->name[sizeof (pHndl->name) - 1U] = (UInt8) '\0';
284 status = CSL_SOK;
285 break;
286 }
287 }
289 HwiP_restore(cookie);
291 return (status);
292 }
294 Int32 Utils_prfLoadUnRegister(TaskP_Handle pTsk)
295 {
296 UInt32 hndlId;
297 UInt32 cookie;
298 Int32 status = CSL_EFAIL;
299 Utils_PrfLoadObj *pHndl;
301 cookie = HwiP_disable();
303 for (hndlId = 0; hndlId < UTILS_PRF_MAX_HNDL; hndlId++)
304 {
305 pHndl = &gUtils_prfObj.loadObj[hndlId];
307 if ((TRUE == pHndl->isAlloc) && (pHndl->pTsk == pTsk))
308 {
309 pHndl->isAlloc = (Bool) FALSE;
310 status = CSL_SOK;
311 break;
312 }
313 }
315 HwiP_restore(cookie);
317 return (status);
318 }
320 Int32 Utils_prfLoadPrintAll(uint32_t printTskLoad, uint32_t trace)
321 {
322 UInt32 hwiLoad, swiLoad, tskLoad, hndlId, cpuLoad;
323 Utils_PrfLoadObj *pHndl;
325 hwiLoad = (UInt32) ((gUtils_accPrfLoadObj.totalHwiThreadTime *
326 (UInt64) 100U) / gUtils_accPrfLoadObj.totalTime);
327 swiLoad = (UInt32) ((gUtils_accPrfLoadObj.totalSwiThreadTime *
328 (UInt64) 100U) / gUtils_accPrfLoadObj.totalTime);
329 cpuLoad = (UInt32) 100U -
330 (UInt32) ((gUtils_accPrfLoadObj.totalIdlTskTime *
331 (UInt64) 100U) /
332 gUtils_accPrfLoadObj.totalTime);
334 GT_0trace(trace, GT_INFO, "\r\n");
335 GT_4trace(trace, GT_INFO,
336 " %d: LOAD: CPU: %d%%, HWI: %d%%, SWI:%d%% \r\n",
337 AppUtils_getCurTimeInMsec(),
338 cpuLoad,
339 hwiLoad,
340 swiLoad);
342 if (((Bool) TRUE) == printTskLoad)
343 {
344 for (hndlId = 0; hndlId < UTILS_PRF_MAX_HNDL; hndlId++)
345 {
346 pHndl = &gUtils_prfObj.loadObj[hndlId];
348 if (TRUE == pHndl->isAlloc)
349 {
350 tskLoad = (UInt32) ((pHndl->totalTskThreadTime *
351 (UInt64) 100U) /
352 gUtils_accPrfLoadObj.totalTime);
354 GT_3trace(trace, GT_INFO,
355 " %d: LOAD: TSK: %s: %d%% \r\n",
356 AppUtils_getCurTimeInMsec(),
357 pHndl->name,
358 tskLoad);
359 }
360 }
361 }
363 GT_0trace(trace, GT_INFO, "\r\n");
365 return (0);
366 }
368 void Utils_prfLoadCalcStart(void)
369 {
370 return;
371 }
373 void Utils_prfLoadCalcStop(void)
374 {
375 return;
376 }
378 void Utils_prfLoadCalcReset(void)
379 {
380 UInt32 hndlId;
381 Utils_PrfLoadObj *pHndl;
383 gUtils_accPrfLoadObj.totalHwiThreadTime = 0;
384 gUtils_accPrfLoadObj.totalSwiThreadTime = 0;
385 gUtils_accPrfLoadObj.totalTime = 0;
386 gUtils_accPrfLoadObj.totalIdlTskTime = 0;
388 /* Reset the performace loads accumulator */
389 for (hndlId = 0; hndlId < UTILS_PRF_MAX_HNDL; hndlId++)
390 {
391 pHndl = &gUtils_prfObj.loadObj[hndlId];
393 if (((Bool) TRUE == pHndl->isAlloc) &&
394 (pHndl->pTsk != NULL))
395 {
396 pHndl->totalTskThreadTime = 0;
397 }
398 }
400 return;
401 }
403 /* Function called by Loadupdate for each update cycle */
404 void Utils_prfLoadUpdate(void)
405 {
406 return;
407 }