source: svn/newcon3bcm2_21bu/magnum/commonutils/xdm/bxdm_pp_timer.c

Last change on this file was 76, checked in by megakiss, 10 years ago

1W 대기전력을 만족시키기 위하여 POWEROFF시 튜너를 Standby 상태로 함

  • Property svn:executable set to *
File size: 12.6 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2003-2010, Broadcom Corporation
3 *     All Rights Reserved
4 *     Confidential Property of Broadcom Corporation
5 *
6 *  THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE
7 *  AGREEMENT  BETWEEN THE USER AND BROADCOM.  YOU HAVE NO RIGHT TO USE OR
8 *  EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
9 *
10 * $brcm_Workfile: bxdm_pp_timer.c $
11 * $brcm_Revision: Hydra_Software_Devel/5 $
12 * $brcm_Date: 8/12/10 4:28p $
13 *
14 * [File Description:]
15 *
16 * Revision History:
17 *
18 * $brcm_Log: /magnum/commonutils/xdm/bxdm_pp_timer.c $
19 *
20 * Hydra_Software_Devel/5   8/12/10 4:28p btosi
21 * SW7405-4736: moved location of BXDM_PPTMR_lutVsyncsPersSecond
22 *
23 * Hydra_Software_Devel/4   8/12/10 9:38a btosi
24 * SW7405-4736: modified QM debug messages
25 *
26 * Hydra_Software_Devel/3   6/29/10 11:25a btosi
27 * SW7405-4365: revamped the timer code to selectively enable the function
28 * and callback timing
29 *
30 * Hydra_Software_Devel/2   3/1/10 5:10p nilesh
31 * SW7405-2993: Fixed coverity warnings
32 *
33 * Hydra_Software_Devel/1   2/16/10 10:51a nilesh
34 * SW7405-2993: Initial XDM version
35 *
36 ***************************************************************************/
37
38#include "bstd.h"
39#include "bkni.h"
40#include "bdbg.h"
41
42#include "bxdm_pp.h"
43#include "bxdm_pp_priv.h"
44#include "bxdm_pp_timer.h"
45
46BDBG_MODULE(BXDM_PPTMR);
47
48const char BXDM_PP_P_DISPMGR_TIMER_NODE[]="DMDBG:\t""$brcm_Revision: Hydra_Software_Devel/5 $";
49
50const uint32_t BXDM_PPTMR_lutVsyncsPersSecond[BXDM_PictureProvider_MonitorRefreshRate_eMax]=
51{
52   60,   /* BXDM_PictureProvider_MonitorRefreshRate_eUnknown */
53   24,   /* BXDM_PictureProvider_MonitorRefreshRate_e23_97 */
54   24,   /* BXDM_PictureProvider_MonitorRefreshRate_e24 */
55   25,   /* BXDM_PictureProvider_MonitorRefreshRate_e25 */
56   30,   /* BXDM_PictureProvider_MonitorRefreshRate_e29_97 */
57   30,   /* BXDM_PictureProvider_MonitorRefreshRate_e30 */
58   50,   /* BXDM_PictureProvider_MonitorRefreshRate_e50 */
59   60,   /* BXDM_PictureProvider_MonitorRefreshRate_e59_94 */
60   60,   /* BXDM_PictureProvider_MonitorRefreshRate_e60 */
61   48    /* BXDM_PictureProvider_MonitorRefreshRate_e48 */
62
63}; /* end of BXDM_PPTMR_lutVsyncsPersSecond */
64
65#if BDBG_DEBUG_BUILD
66
67#if ( BXDM_PPTMR_P_ENABLE_FUNCTION_TIMING || BXDM_PPTMR_P_ENABLE_CALLBACK_TIMING )
68
69/*
70 * Result will be printed every BXDM_PPTMR_S_VSYNCS_PER_PRINT vsync's
71 * For a value of '0', results are printed once per second.
72 */
73#define BXDM_PPTMR_S_VSYNCS_PER_PRINT  0
74
75/*
76 * Local function prototypes
77 */
78void BXDM_PPTMR_S_CookResults( BXDM_PictureProvider_Handle hXdmPP );
79void BXDM_PPTMR_S_ResetTimerData( BXDM_PPTIMER_P_Data * pTimerData );
80
81/*
82 * Private functions
83 */
84
85void BXDM_PPTMR_S_GetTime(
86   BXDM_PictureProvider_Handle hXdmPP,
87   uint32_t * pTimeUsec
88   )
89{
90   if( NULL != hXdmPP->hTimer )
91   {
92      BTMR_ReadTimer_isr( hXdmPP->hTimer, pTimeUsec );
93   }
94   else 
95   {
96      *pTimeUsec = 0;
97   }
98   
99   return;
100}
101
102
103void BXDM_PPTMR_S_SnapshotEndTimeAndUpdateElapse(
104   BXDM_PictureProvider_Handle hXdmPP,
105   BXDM_PPTIMER_P_Sample * pTimerSample
106   )
107{
108   BDBG_ENTER(BXDM_PPTMR_S_SnapshotEndTimeAndUpdateElapse);
109
110   BXDM_PPTMR_S_GetTime( hXdmPP, &(pTimerSample->uiEndTimeUsecs) );
111
112   /* Calculate the elapse time. */
113   pTimerSample->uiElapseTimeUsecs = ( pTimerSample->uiEndTimeUsecs - pTimerSample->uiStartTimeUsecs );
114
115   /* Check if the time is a new max elapse time. */
116   if ( pTimerSample->uiElapseTimeUsecs > pTimerSample->uiMaxTimeUsecs )
117   {
118      pTimerSample->uiMaxTimeUsecs = pTimerSample->uiElapseTimeUsecs;
119   }
120
121   /* Check if the time is a new min elapse time. */
122   if ( 0 == pTimerSample->uiMinTimeUsecs )
123   {
124      pTimerSample->uiMinTimeUsecs = pTimerSample->uiElapseTimeUsecs;
125   }
126   else if ( pTimerSample->uiElapseTimeUsecs < pTimerSample->uiMinTimeUsecs )
127   {
128      pTimerSample->uiMinTimeUsecs = pTimerSample->uiElapseTimeUsecs;
129   }
130
131   /* Add the elapse time for this callback to the total. */
132   pTimerSample->uiTotalTimeUsecs += pTimerSample->uiElapseTimeUsecs;
133
134   pTimerSample->uiNumSamples++;
135
136   BDBG_LEAVE(BXDM_PPTMR_S_SnapshotEndTimeAndUpdateElapse);
137
138   return;
139}
140
141
142void BXDM_PPTMR_S_CookResults(
143   BXDM_PictureProvider_Handle hXdmPP
144   )
145{
146   BXDM_PPTIMER_P_Data * pTimerData = &(hXdmPP->stDMState.stDecode.stTimerData);
147
148   uint32_t i;
149   
150   BDBG_ENTER(BXDM_PPTMR_S_CookResults);
151
152#if BXDM_PPTMR_P_ENABLE_FUNCTION_TIMING
153
154   for ( i = 0; i < BXDM_PPTIMER_P_Function_eMax; i++ )
155   {
156      if ( 0 != pTimerData->astFunctions[ i ].uiNumSamples )
157      {
158         pTimerData->astFunctions[ i ].uiAverageTimeUsecs = pTimerData->astFunctions[ i ].uiTotalTimeUsecs / pTimerData->astFunctions[ i ].uiNumSamples;
159      }
160   }
161
162#endif
163
164   for ( i=0; i < BXDM_PictureProvider_Callback_eMax; i++ )
165   {
166      if ( 0 != pTimerData->astCallbacks[ i ].uiNumSamples )
167      {
168         pTimerData->astCallbacks[ i ].uiAverageTimeUsecs = pTimerData->astCallbacks[ i ].uiTotalTimeUsecs / pTimerData->astCallbacks[ i ].uiNumSamples;
169      }
170
171   }
172
173   BDBG_LEAVE(BXDM_PPTMR_S_CookResults);
174
175   return;
176}
177
178#endif
179
180/*
181 * Public functions for measuring the elapse time of functions.
182 * Conditionally compiled out to reduce overhead during normal play.
183 */
184void BXDM_PPTMR_P_SnapshotFunctionStartTime(
185   BXDM_PictureProvider_Handle hXdmPP,
186   BXDM_PPTIMER_P_Function eFunctionIndex
187   )
188{
189   BDBG_ENTER(BXDM_PPTMR_P_SnapshotFunctionStartTime);
190
191#if BXDM_PPTMR_P_ENABLE_FUNCTION_TIMING
192
193   BXDM_PPTMR_S_GetTime( 
194         hXdmPP,
195         &(hXdmPP->stDMState.stDecode.stTimerData.astFunctions[ eFunctionIndex ].uiStartTimeUsecs)
196         );
197
198#else
199   BSTD_UNUSED( hXdmPP );
200   BSTD_UNUSED( eFunctionIndex );
201#endif
202
203   BDBG_LEAVE(BXDM_PPTMR_P_SnapshotFunctionStartTime);
204
205   return;
206}
207
208void BXDM_PPTMR_P_SnapshotFunctionEndTime(
209   BXDM_PictureProvider_Handle hXdmPP,
210   BXDM_PPTIMER_P_Function eFunctionIndex
211   )
212{
213   BDBG_ENTER(BXDM_PPTMR_P_SnapshotFunctionEndTime);
214
215#if BXDM_PPTMR_P_ENABLE_FUNCTION_TIMING
216
217   BXDM_PPTMR_S_SnapshotEndTimeAndUpdateElapse(
218         hXdmPP,
219         &(hXdmPP->stDMState.stDecode.stTimerData.astFunctions[ eFunctionIndex ])
220         );
221
222#else
223   BSTD_UNUSED( hXdmPP );
224   BSTD_UNUSED( eFunctionIndex );
225#endif
226
227   BDBG_LEAVE(BXDM_PPTMR_P_SnapshotFunctionEndTime);
228
229   return;
230}
231
232/*
233 * Public functions for measuring the elapse time of callbacks.
234 */
235
236void BXDM_PPTMR_P_SnapshotCallbackStartTime(
237   BXDM_PictureProvider_Handle hXdmPP,
238   BXDM_PictureProvider_Callback eCallbackIndex
239   )
240{
241   BDBG_ENTER(BXDM_PPTMR_P_SnapshotCallbackStartTime);
242
243#if BXDM_PPTMR_P_ENABLE_CALLBACK_TIMING
244
245   BXDM_PPTMR_S_GetTime( 
246         hXdmPP,
247         &(hXdmPP->stDMState.stDecode.stTimerData.astCallbacks[ eCallbackIndex ].uiStartTimeUsecs)
248         );
249
250#else
251   BSTD_UNUSED( hXdmPP );
252   BSTD_UNUSED( eCallbackIndex );
253#endif
254
255
256   BDBG_LEAVE(BXDM_PPTMR_P_SnapshotCallbackStartTime);
257
258   return;
259}
260
261void BXDM_PPTMR_P_SnapshotCallbackEndTime(
262   BXDM_PictureProvider_Handle hXdmPP,
263   BXDM_PictureProvider_Callback eCallbackIndex
264   )
265{
266   BDBG_ENTER(BXDM_PPTMR_P_SnapshotCallbackEndTime);
267
268#if BXDM_PPTMR_P_ENABLE_CALLBACK_TIMING
269
270   BXDM_PPTMR_S_SnapshotEndTimeAndUpdateElapse(
271         hXdmPP,
272         &(hXdmPP->stDMState.stDecode.stTimerData.astCallbacks[ eCallbackIndex ])
273         );
274
275#else
276   BSTD_UNUSED( hXdmPP );
277   BSTD_UNUSED( eCallbackIndex );
278#endif
279
280
281   BDBG_LEAVE(BXDM_PPTMR_P_SnapshotCallbackEndTime);
282
283   return;
284}
285
286/*
287 * Public function for printing the results.
288 */
289#if BXDM_PPTMR_P_ENABLE_FUNCTION_TIMING
290
291static const char* sFunctionNameLUT[BXDM_PPTIMER_P_Function_eMax] =
292{
293   "Main",
294   "Init",
295   "DecIsr",
296   "Select",
297   "Pic1",
298   "Pic2",
299   "Pic3",
300   "ValPCHead",
301   "ValPCTail",
302   "Eval",
303   "VDC",
304   "Update",
305   "CallBck",
306   "Post",
307   "GetCnt",
308   "PeekPic",
309   "GetPic",
310   "RelPic",
311   "DrP",
312   "DrR",
313};
314
315#endif
316
317#if BXDM_PPTMR_P_ENABLE_CALLBACK_TIMING
318
319static const char* sCallbackNameLUT[BXDM_PictureProvider_Callback_eMax] =
320{
321   "StcPtsOff",   /* BXDM_PictureProvider_Callback_eStcPtsOffset */
322   "FirstPic",    /* BXDM_PictureProvider_Callback_eFirstPTSReady */
323   "PTSCoded",    /* BXDM_PictureProvider_Callback_eFirstCodedPTSReady */
324   "PTSPass",     /* BXDM_PictureProvider_Callback_eFirstPTSPassed */
325   "PTSError",    /* BXDM_PictureProvider_Callback_ePTSError */
326   "IFrame",      /* BXDM_PictureProvider_Callback_eIFrame */
327   "PicParms",    /* BXDM_PictureProvider_Callback_ePictureParameters */
328   "ASTM",        /* BXDM_PictureProvider_Callback_eTSMPassInASTMMode */
329   "ClpStr",      /* BXDM_PictureProvider_Callback_eClipStart */
330   "ClpStp",      /* BXDM_PictureProvider_Callback_eClipStop */
331   "Marker",      /* BXDM_PictureProvider_Callback_ePictureMarker */
332   "ReqStc",      /* BXDM_PictureProvider_Callback_eRequestSTC */
333   "PPBParms",    /* BXDM_PictureProvider_Callback_ePictureUnderEvaluation */
334   "TSM",         /* BXDM_PictureProvider_Callback_eTSMResult */
335   "ExtData",     /* BXDM_PictureProvider_Callback_ePictureExtensionData */
336   "DecErr",      /* BXDM_PictureProvider_Callback_eDecodeError */
337};
338
339#endif
340
341void BXDM_PPTMR_P_PrintResults(
342   BXDM_PictureProvider_Handle hXdmPP
343   )
344{
345   char           szTemp[BXDM_PP_TIMER_P_MAX_STR_LEN];
346   uint32_t       uiOffset=0;
347   uint32_t       i;
348   uint32_t       uiVsyncThreshold;
349
350   BXDM_PPTIMER_P_Data *         pTimerData;
351   BXDM_PictureProvider_MonitorRefreshRate  eMonitorRefreshRate;
352   
353#if BXDM_PPTMR_P_ENABLE_FUNCTION_TIMING
354   bool           bPrintFunctionTimes = false;
355#endif
356
357   BDBG_ENTER(BXDM_PPTMR_P_PrintResults);
358
359#if ( BXDM_PPTMR_P_ENABLE_FUNCTION_TIMING || BXDM_PPTMR_P_ENABLE_CALLBACK_TIMING )
360
361   pTimerData = &(hXdmPP->stDMState.stDecode.stTimerData);
362
363   /* Bump the vsync count to know when to print the results. */
364
365   pTimerData->uiVsyncCnt++;
366
367   /* Calculate the "print" threshold.  */
368
369   uiVsyncThreshold = BXDM_PPTMR_S_VSYNCS_PER_PRINT;
370
371   if ( 0 == uiVsyncThreshold )
372   {
373
374      if ( hXdmPP->stDMConfig.eMonitorRefreshRate >= BXDM_PictureProvider_MonitorRefreshRate_eMax )
375      {
376         eMonitorRefreshRate = BXDM_PictureProvider_MonitorRefreshRate_e60Hz;
377      }
378      else
379      {
380         eMonitorRefreshRate = hXdmPP->stDMConfig.eMonitorRefreshRate;
381      }
382
383      uiVsyncThreshold = BXDM_PPTMR_lutVsyncsPersSecond[ eMonitorRefreshRate ];
384   }
385
386
387   if ( pTimerData->uiVsyncCnt >= uiVsyncThreshold )
388   {
389      BXDM_PPTMR_S_CookResults( hXdmPP );
390
391#if BXDM_PPTMR_P_ENABLE_FUNCTION_TIMING
392
393      for ( i = 0; i < BXDM_PPTIMER_P_Function_eMax; i++ )
394      {
395         if ( 0 != pTimerData->astFunctions[i].uiNumSamples )
396         {
397            uiOffset += BKNI_Snprintf(
398                           szTemp + uiOffset,
399                           BXDM_PP_TIMER_P_MAX_STR_LEN - uiOffset,
400                           "%s: %u/%u/%u(%d) ",
401                           sFunctionNameLUT[i],
402                           pTimerData->astFunctions[i].uiAverageTimeUsecs,
403                           pTimerData->astFunctions[i].uiMinTimeUsecs,
404                           pTimerData->astFunctions[i].uiMaxTimeUsecs,
405                           pTimerData->astFunctions[i].uiNumSamples
406                           );
407
408            bPrintFunctionTimes = true;
409         }
410      }
411
412      if ( true == bPrintFunctionTimes )
413      {
414         BDBG_MSG(("%s", szTemp));
415         uiOffset = 0;
416      }
417
418#endif
419
420#if BXDM_PPTMR_P_ENABLE_CALLBACK_TIMING
421
422      for ( i=0; i < BXDM_PictureProvider_Callback_eMax; i++ )
423      {
424         if ( 0 != pTimerData->astCallbacks[ i ].uiAverageTimeUsecs )
425         {
426            uiOffset += BKNI_Snprintf(
427                           szTemp + uiOffset,
428                           BXDM_PP_TIMER_P_MAX_STR_LEN - uiOffset,
429                           "%s: %u/%u/%u(%d) ",
430                           sCallbackNameLUT[i],
431                           pTimerData->astCallbacks[i].uiAverageTimeUsecs,
432                           pTimerData->astCallbacks[i].uiMinTimeUsecs,
433                           pTimerData->astCallbacks[i].uiMaxTimeUsecs,
434                           pTimerData->astCallbacks[i].uiNumSamples
435                           );
436         }
437      }
438
439      BDBG_MSG(("%s", szTemp));
440
441#endif
442
443      BXDM_PPTMR_S_ResetTimerData( &(hXdmPP->stDMState.stDecode.stTimerData) );
444   }
445
446#else
447
448   BSTD_UNUSED( szTemp );
449   BSTD_UNUSED( uiOffset );
450   BSTD_UNUSED( i );
451   BSTD_UNUSED( uiVsyncThreshold );
452   BSTD_UNUSED( pTimerData );
453   BSTD_UNUSED( eMonitorRefreshRate );
454   BSTD_UNUSED( hXdmPP );
455
456#endif
457
458   BDBG_LEAVE(BXDM_PPTMR_P_PrintResults);
459
460   return;
461}
462
463void BXDM_PPTMR_S_ResetTimerData(
464   BXDM_PPTIMER_P_Data * pTimerData
465   )
466{
467   BDBG_ENTER(BXDM_PPTMR_S_ResetTimerData);
468
469   BKNI_Memset_isr( pTimerData, 0, sizeof( BXDM_PPTIMER_P_Data ) );
470
471   BDBG_LEAVE(BXDM_PPTMR_S_ResetTimerData);
472   return;
473}
474
475#endif   /* if debug build */
476
Note: See TracBrowser for help on using the repository browser.