TI C64x系列DSP時間計量

http://hi.baidu.com/myyb/blog/item/e1071dce1878d032b700c8c7.html

 

TI C64x 可以有兩種方法來得到程序的運行 cycle, 一個是Enable clock後調用 clock()( 這個在 VC 下是得到以 ms 爲單位的時間,這裏得到的是 cycle), 另一個就是 CSL Chip Support Library )提供的 timer

下面給出兩種方法的程序段

 

/**************************************************************/

/*                                                                                                                        */

/*      Auth:wb0330                                                                                              */

/*     Dest: used to measure cycle counts for TI C64x DSP                                    */

/*      Support by: http://hi.baidu.com/videocodec                                                   */

/*     or QQ group: 24960630, 10714050, 11216191                                            */

/*                                                                                                                        */

/**************************************************************/

#include < stdio .h>

 

 

#include < time .h> /* need time.h in order to call clock()*/

 

int main ()

{

        unsigned int start , stop , overhead,cycles ;

 

 

/*––––––––––––––––––––––––––*/

/* The following example demonstrates how to include                            */

/* the clock() function in your C code.                                                          */

        /*––––––––––––––––––––––– – –*/

 

        start = clock (); /* Calculate overhead of calling clock*/

        stop = clock (); /* and subtract this value from The results*/

        overhead = stop - start ;

        start = clock ();

        /* ––––––––––––––––––––––––––*/

        /* Call a function here.                                                               */

        /* ––––––––––––––––––––––––––*/

        stop = clock ();

       cycles = stop - start - overhead;

        printf ( “cycles: %d   / n ” , cycles );

       printf ( "times: %.2f   s with cpu 600MHz, /n" ,(( float ) cycles /( float )600000000));

// clock()   end

return 0;

}

 

 

 

這裏給出CSL_Timer 部分的

 

/**************************************************************/

/*                                                                                                                        */

/*      Auth:wb0330                                                                                              */

/*     Dest: used to measure cycle counts for TI C64x DSP                                    */

/*      Support by: http://hi.baidu.com/videocodec                                                    */

/*     or QQ group:24960630, 10714050, 11216191                                            */

/*                                                                                                                         */

/**************************************************************/

#include < stdio .h>

#include "csl.h"

#include "csl_timer.h"

int main ()

{

        TIMER_Handle hTimer ;

        unsigned int start , stop , overhead diff,cycles;

 

/*––––––––––––––––––––––––––––––––––*/

/* The following sample code shows how to set up the timer       */

/* and measure cycle counts with Chip Support Library (CSL)    */

        /*––––––––––––––––––––––––––––––––––*/

       

hTimer = TIMER_open (TIMER_DEVANY,0); /* open a timer */

        /*––––––––––––––––––––––––––––––––––*/

        /* Configure the timer. count corresponds to 8 CPU cycles in C64 */

        /*––––––––––––––––––––––––––––––––––*/

        /* control period initial value */

        TIMER_configArgs ( hTimer , 0x000002C0, 0xFFFFFFFF, 0x00000000);

        /* ––––––––––––––––––––––––––––––––––*/

        /* Compute the overhead of calling the timer. */

        /* ––––––––––––––––––––––––––––––––––*/

        start = TIMER_getCount ( hTimer ); /* to remove L1P miss overhead */

        start = TIMER_getCount ( hTimer );

        stop = TIMER_getCount ( hTimer );

        overhead = stop - start ;

        start = TIMER_getCount ( hTimer );

        /* ––––––––––––––––––––––––––––––––––*/

        /* Call a function here.                                        */

        /* ––––––––––––––––––––––––––––––––––*/

        diff = ( TIMER_getCount ( hTimer ) - start ) - overhead ;

        TIMER_close ( hTimer );

          cycles = diff*8;

        printf ( “cycles %d   / n”, cycles);      

printf ( "times: %.2f   s with cpu 600MHz, /n" ,(( float ) cycles /( float )600000000));

     // The maximum resolution of the timer is 8 CPU cycles, since the input clock to

     // the timer is fixed   to the CPU clock divided by eight

     // CSL_timer   end

 

return 0;

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章