source: svn/newcon3bcm2_21bu/magnum/portinginterface/xvd/7552/bxvd_decoder_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.1 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2003-2011, 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: bxvd_decoder_timer.c $
11 * $brcm_Revision: Hydra_Software_Devel/4 $
12 * $brcm_Date: 7/20/11 3:07p $
13 *
14 * [File Description:]
15 *
16 * Revision History:
17 *
18 * $brcm_Log: /magnum/portinginterface/xvd/7401/bxvd_decoder_timer.c $
19 *
20 * Hydra_Software_Devel/4   7/20/11 3:07p davidp
21 * SW7420-2001: Reorder header-file includes.
22 *
23 * Hydra_Software_Devel/3   6/28/10 2:48p btosi
24 * SW7405-4365: added support to selectively compile the function timing
25 * code.
26 *
27 * Hydra_Software_Devel/2   6/16/10 11:37a btosi
28 * SW7405-4365: added include of bxvd_decoder_timer.h
29 *
30 * Hydra_Software_Devel/1   6/16/10 11:16a btosi
31 * SW7405-4365: initial checkin
32 *
33 ***************************************************************************/
34
35#include "bstd.h"
36#include "bkni.h"
37#include "bdbg.h"
38
39#include "bxvd_platform.h"
40#include "bxvd_priv.h"
41#include "bxvd_decoder.h"
42#include "bxvd_decoder_timer.h"
43
44#include "bxvd_vdec_info.h"
45
46
47BDBG_MODULE(BXVD_DECODERTMR);
48
49#if BDBG_DEBUG_BUILD
50
51/*
52 * Result will be printed every BXVD_DECODER_TIMER_S_VSYNCS_PER_PRINT vsync's
53 * For a value of '0', results are printed once per second.
54 */
55#define BXVD_DECODER_TIMER_S_VSYNCS_PER_PRINT  0
56
57
58/*
59 * Only compile the local functions if timing data is being collected.
60 */
61
62#if BXVD_DECODER_TIMER_S_ENABLE_FUNCTION_TIMING
63
64
65static const char* sFunctionNameLUT[BXVD_DecoderTimer_P_eFuncMax] =
66{
67   "DRIsr",
68   "UQVet",
69   "UQDQT",
70   "UQVal",
71   "UQAdd",
72
73   "\n\tGetCnt",
74   "Peek",
75   "GetPic",
76   "RelPic"
77
78};
79
80#endif
81
82#if ( BXVD_DECODER_TIMER_S_ENABLE_FUNCTION_TIMING || BXVD_DECODER_TIMER_S_ENABLE_CALLBACK_TIMING )
83
84/*
85 * Local functions
86 */
87void BXVD_DecoderTimer_S_GetTime(
88   BXVD_ChannelHandle hXvdCh,
89   uint32_t * pTimeUsec
90   )
91{
92   if( NULL != hXvdCh->pXvd->hTimer )
93   {
94      BTMR_ReadTimer_isr( hXvdCh->pXvd->hTimer, pTimeUsec );
95   }
96   else 
97   {
98      *pTimeUsec = 0;
99   }
100   
101   return;
102}
103
104void BXVD_DecoderTimer_S_SnapshotEndTimeAndUpdateElapse(
105   BXVD_ChannelHandle hXvdCh,
106   BXVD_DecoderTimer_P_Sample * pTimerSample
107   )
108{
109   BDBG_ENTER(BXVD_DecoderTimer_S_SnapshotEndTimeAndUpdateElapse);
110
111   BXVD_DecoderTimer_S_GetTime( hXvdCh, &(pTimerSample->uiEndTimeUsecs) );
112
113   /* Calculate the elapse time. */
114   pTimerSample->uiElapseTimeUsecs = ( pTimerSample->uiEndTimeUsecs - pTimerSample->uiStartTimeUsecs );
115
116   /* Check if the time is a new max elapse time. */
117   if ( pTimerSample->uiElapseTimeUsecs > pTimerSample->uiMaxTimeUsecs )
118   {
119      pTimerSample->uiMaxTimeUsecs = pTimerSample->uiElapseTimeUsecs;
120   }
121
122   /* Check if the time is a new min elapse time. */
123   if ( 0 == pTimerSample->uiMinTimeUsecs )
124   {
125      pTimerSample->uiMinTimeUsecs = pTimerSample->uiElapseTimeUsecs;
126   }
127   else if ( pTimerSample->uiElapseTimeUsecs < pTimerSample->uiMinTimeUsecs )
128   {
129      pTimerSample->uiMinTimeUsecs = pTimerSample->uiElapseTimeUsecs;
130   }
131
132   /* Add the elapse time for this callback to the total. */
133   pTimerSample->uiTotalTimeUsecs += pTimerSample->uiElapseTimeUsecs;
134
135   pTimerSample->uiNumSamples++;
136
137   BDBG_LEAVE(BXVD_DecoderTimer_S_SnapshotEndTimeAndUpdateElapse);
138
139   return;
140}
141
142void BXVD_DecoderTimer_S_CookResults(
143   BXVD_ChannelHandle hXvdCh
144   )
145{
146   BXVD_DecoderTimer_P_Data * pTimerData = &(hXvdCh->stDecoderContext.stLogData.stTimerData);
147
148   uint32_t i;
149   
150   BDBG_ENTER(BXVD_DecoderTimer_S_CookResults);
151
152#if BXVD_DECODER_TIMER_S_ENABLE_FUNCTION_TIMING
153
154   for ( i = 0; i < BXVD_DecoderTimer_P_eFuncMax; 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 < BXVD_DecoderTimer_P_eCbMax; 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(BXVD_DecoderTimer_S_CookResults);
174
175   return;
176}
177
178void BXVD_DecoderTimer_S_ResetTimerData(
179   BXVD_DecoderTimer_P_Data * pTimerData
180   )
181{
182   BDBG_ENTER(BXVD_DecoderTimer_S_ResetTimerData);
183
184   BKNI_Memset_isr( pTimerData, 0, sizeof( BXVD_DecoderTimer_P_Data ) );
185
186   BDBG_LEAVE(BXVD_DecoderTimer_S_ResetTimerData);
187   return;
188}
189
190#endif
191
192/*
193 * Public functions for measuring the elapse time of functions.
194 * Conditionally compiled out to reduce overhead during normal play.
195 */
196
197void BXVD_DecoderTimer_P_SnapshotFunctionStartTime(
198   BXVD_ChannelHandle hXvdCh,
199   BXVD_DecoderTimer_P_eFunc eFunctionIndex
200   )
201{
202   BDBG_ENTER(BXVD_DecoderTimer_P_SnapshotFunctionStartTime);
203
204#if BXVD_DECODER_TIMER_S_ENABLE_FUNCTION_TIMING
205
206   BXVD_DecoderTimer_S_GetTime( 
207         hXvdCh,
208         &(hXvdCh->stDecoderContext.stLogData.stTimerData.astFunctions[ eFunctionIndex ].uiStartTimeUsecs)
209         );
210
211#else
212   BSTD_UNUSED( hXvdCh );
213   BSTD_UNUSED( eFunctionIndex );
214#endif
215
216   BDBG_LEAVE(BXVD_DecoderTimer_P_SnapshotFunctionStartTime);
217
218   return;
219}
220
221void BXVD_DecoderTimer_P_SnapshotFunctionEndTime(
222   BXVD_ChannelHandle hXvdCh,
223   BXVD_DecoderTimer_P_eFunc eFunctionIndex
224   )
225{
226   BDBG_ENTER(BXVD_DecoderTimer_P_SnapshotFunctionEndTime);
227
228#if BXVD_DECODER_TIMER_S_ENABLE_FUNCTION_TIMING
229
230   BXVD_DecoderTimer_S_SnapshotEndTimeAndUpdateElapse(
231         hXvdCh,
232         &(hXvdCh->stDecoderContext.stLogData.stTimerData.astFunctions[ eFunctionIndex ])
233         );
234
235#else
236   BSTD_UNUSED( hXvdCh );
237   BSTD_UNUSED( eFunctionIndex );
238#endif
239
240   BDBG_LEAVE(BXVD_DecoderTimer_P_SnapshotFunctionEndTime);
241
242   return;
243}
244
245/*
246 * Public functions for measuring the elapse time of callbacks.
247 */
248
249void BXVD_DecoderTimer_P_SnapshotCallbackStartTime(
250   BXVD_ChannelHandle hXvdCh,
251   BXVD_DecoderTimer_P_eCallbacks eCallbackIndex
252   )
253{
254   BDBG_ENTER(BXVD_DecoderTimer_P_SnapshotCallbackStartTime);
255
256#if BXVD_DECODER_TIMER_S_ENABLE_CALLBACK_TIMING
257
258   BXVD_DecoderTimer_S_GetTime( 
259         hXvdCh,
260         &(hXvdCh->stDecoderContext.stLogData.stTimerData.astCallbacks[ eCallbackIndex ].uiStartTimeUsecs)
261         );
262
263#else
264   BSTD_UNUSED( hXvdCh );
265   BSTD_UNUSED( eCallbackIndex );
266#endif
267
268
269   BDBG_LEAVE(BXVD_DecoderTimer_P_SnapshotCallbackStartTime);
270
271   return;
272}
273
274void BXVD_DecoderTimer_P_SnapshotCallbackEndTime(
275   BXVD_ChannelHandle hXvdCh,
276   BXVD_DecoderTimer_P_eCallbacks eCallbackIndex
277   )
278{
279   BDBG_ENTER(BXVD_DecoderTimer_P_SnapshotCallbackEndTime);
280
281#if BXVD_DECODER_TIMER_S_ENABLE_CALLBACK_TIMING
282
283   BXVD_DecoderTimer_S_SnapshotEndTimeAndUpdateElapse(
284         hXvdCh,
285         &(hXvdCh->stDecoderContext.stLogData.stTimerData.astCallbacks[ eCallbackIndex ])
286         );
287
288#else
289   BSTD_UNUSED( hXvdCh );
290   BSTD_UNUSED( eCallbackIndex );
291#endif
292
293
294   BDBG_LEAVE(BXVD_DecoderTimer_P_SnapshotCallbackEndTime);
295
296   return;
297}
298
299/*
300 * Public function for printing the results.
301 */
302
303void BXVD_DecoderTimer_P_PrintResults(
304   BXVD_ChannelHandle hXvdCh
305   )
306{
307   uint32_t                   uiVsyncThreshold;
308   BXVD_DecoderTimer_P_Data * pTimerData;
309
310#if BXVD_DECODER_TIMER_S_ENABLE_FUNCTION_TIMING
311   char           szTemp[BXVD_DECODER_TIMER_P_MAX_STR_LEN];
312   uint32_t       uiOffset=0;
313   uint32_t       i;
314   bool           bPrintFunctionTimes = false;
315#endif
316
317   
318   BDBG_ENTER(BXVD_DecoderTimer_P_PrintResults);
319
320   /*
321    * Only compile in the body of this function if timing data is being collected.
322    */
323
324#if ( BXVD_DECODER_TIMER_S_ENABLE_FUNCTION_TIMING || BXVD_DECODER_TIMER_S_ENABLE_CALLBACK_TIMING )
325
326   uiVsyncThreshold = BXVD_DECODER_TIMER_S_VSYNCS_PER_PRINT;
327
328   if ( 0 == uiVsyncThreshold )
329   {
330      uiVsyncThreshold = hXvdCh->stDecoderContext.stLogData.uiVsyncsPerSecond;
331   }
332
333   pTimerData = &(hXvdCh->stDecoderContext.stLogData.stTimerData);
334
335   if ( hXvdCh->stDecoderContext.stLogData.uiCallbackCount >= uiVsyncThreshold )
336   {
337      BXVD_DecoderTimer_S_CookResults( hXvdCh );
338
339#if BXVD_DECODER_TIMER_S_ENABLE_FUNCTION_TIMING
340
341      for ( i = 0; i < BXVD_DecoderTimer_P_eFuncMax; i++ )
342      {
343         if ( 0 != pTimerData->astFunctions[i].uiNumSamples )
344         {
345            uiOffset += BKNI_Snprintf(
346                           szTemp + uiOffset,
347                           BXVD_DECODER_TIMER_P_MAX_STR_LEN - uiOffset,
348                           "%s: %u/%u/%u(%d) ",
349                           sFunctionNameLUT[i],
350                           pTimerData->astFunctions[i].uiAverageTimeUsecs,
351                           pTimerData->astFunctions[i].uiMinTimeUsecs,
352                           pTimerData->astFunctions[i].uiMaxTimeUsecs,
353                           pTimerData->astFunctions[i].uiNumSamples
354                           );
355
356            bPrintFunctionTimes = true;
357         }
358      }
359
360      if ( true == bPrintFunctionTimes )
361      {
362         BDBG_MSG(("%s", szTemp));
363      }
364
365#endif
366
367      /* BKNI_Snprintf is very slow.  Since there are only two callback functions
368       * to time, use discrete print statements instead of building up a string.
369       */
370
371      if ( 0 != pTimerData->astCallbacks[ BXVD_DecoderTimer_P_eCbUserData ].uiAverageTimeUsecs
372           && 0 == pTimerData->astCallbacks[ BXVD_DecoderTimer_P_eCbPPBReceived ].uiAverageTimeUsecs
373         )
374
375      {
376         /* only the userdata callback has been executed. */
377         BDBG_MSG(("UserData %u/%u/%u(%d) ",
378                     pTimerData->astCallbacks[ BXVD_DecoderTimer_P_eCbUserData ].uiAverageTimeUsecs,
379                     pTimerData->astCallbacks[ BXVD_DecoderTimer_P_eCbUserData ].uiMinTimeUsecs,
380                     pTimerData->astCallbacks[ BXVD_DecoderTimer_P_eCbUserData ].uiMaxTimeUsecs,
381                     pTimerData->astCallbacks[ BXVD_DecoderTimer_P_eCbUserData ].uiNumSamples
382                     ));
383      }
384      else if ( 0 == pTimerData->astCallbacks[ BXVD_DecoderTimer_P_eCbUserData ].uiAverageTimeUsecs
385           && 0 != pTimerData->astCallbacks[ BXVD_DecoderTimer_P_eCbPPBReceived ].uiAverageTimeUsecs
386         )
387
388      {
389         /* only the PPB received callback has been executed. */
390         BDBG_MSG(("PPBRec %u/%u/%u(%d) ",
391                     pTimerData->astCallbacks[ BXVD_DecoderTimer_P_eCbPPBReceived ].uiAverageTimeUsecs,
392                     pTimerData->astCallbacks[ BXVD_DecoderTimer_P_eCbPPBReceived ].uiMinTimeUsecs,
393                     pTimerData->astCallbacks[ BXVD_DecoderTimer_P_eCbPPBReceived ].uiMaxTimeUsecs,
394                     pTimerData->astCallbacks[ BXVD_DecoderTimer_P_eCbPPBReceived ].uiNumSamples
395                     ));
396      }
397      else if ( 0 != pTimerData->astCallbacks[ BXVD_DecoderTimer_P_eCbUserData ].uiAverageTimeUsecs
398           && 0 != pTimerData->astCallbacks[ BXVD_DecoderTimer_P_eCbPPBReceived ].uiAverageTimeUsecs
399         )
400
401      {
402         /* both callbacks have been executed. */
403         BDBG_MSG(("UserData %u/%u/%u(%d) PPBRec %u/%u/%u(%d) ",
404                     pTimerData->astCallbacks[ BXVD_DecoderTimer_P_eCbUserData ].uiAverageTimeUsecs,
405                     pTimerData->astCallbacks[ BXVD_DecoderTimer_P_eCbUserData ].uiMinTimeUsecs,
406                     pTimerData->astCallbacks[ BXVD_DecoderTimer_P_eCbUserData ].uiMaxTimeUsecs,
407                     pTimerData->astCallbacks[ BXVD_DecoderTimer_P_eCbUserData ].uiNumSamples,
408                     pTimerData->astCallbacks[ BXVD_DecoderTimer_P_eCbPPBReceived ].uiAverageTimeUsecs,
409                     pTimerData->astCallbacks[ BXVD_DecoderTimer_P_eCbPPBReceived ].uiMinTimeUsecs,
410                     pTimerData->astCallbacks[ BXVD_DecoderTimer_P_eCbPPBReceived ].uiMaxTimeUsecs,
411                     pTimerData->astCallbacks[ BXVD_DecoderTimer_P_eCbPPBReceived ].uiNumSamples
412                     ));
413      }
414
415      BXVD_DecoderTimer_S_ResetTimerData( &(hXvdCh->stDecoderContext.stLogData.stTimerData) );
416   }
417
418#else
419
420   BSTD_UNUSED( hXvdCh );
421   BSTD_UNUSED( uiVsyncThreshold );
422   BSTD_UNUSED( pTimerData );
423
424#endif
425
426   BDBG_LEAVE(BXVD_DecoderTimer_P_PrintResults);
427
428   return;
429}
430
431#endif   /* if debug build */
432
Note: See TracBrowser for help on using the repository browser.