DSP 運行時間計算函數--_itoll(TSCH,TSCL);


DSP OMAP 程序耗時測定 CPU周期 兩種方法

 

利用TSCL和TSCH來計算時鍾周期,這兩天看了一下如何他們

DSP開發,測量某個函數或某段代碼的cycles消耗是經常要做的 事情,常用的profiling和clock()一般在simulation下使用,真正到了板子上做emulation時,因為要考慮到數據和被測 code在板子上的存放位置和讀取時間,用這種方法測結果就不那么可靠了。其實在c64x+ core上有兩個計數寄存器TSCL/TSCH,它們與CPU同頻,共同表示一個64-bit數,CPU運行一個cycle,該寄存器就加1,因此可以用 它們來准確的測量cpu在某個執行段中消耗的cycles。一般我們只會用到TSCL這個寄存器,594MHz下,32-bit可以測試到7s,而 TSCH是高32位,除非測試整個工程,一般用不到它。

使用方法:長時間寬范圍時鍾測定

unsigned long long t1,t2;

t1=_itoll(TSCH,TSCL);

code_wait_test;

t2=_itoll(TSCH,TSCL);

printf(“#cycle=%d”,t2-t1);

短時間(7秒)窄范圍時鍾測定:

T1=TSCL;

…process code …

T2=TSCL;

Printf(“#cycle=%d”,t2-t1);

方法二,也可以采用biosAPI方式

LgUns time1=CLK_gethtime();

…process code …

LgUns time2=CLK_gethtime();

Cpucycles=(time2-time1)*CLK_cpucyclePerhtime;

Prinf(“#cycle=%d”,Cpucycle);

關於測量CPU時鍾周期中我們用的變量類型和函數我們都可以在C6000DSP/bios的API文檔和BIOS提供的源碼找到,可以詳細去查閱。

#include "c6x.h"


void YourFunc (void)
{
unsigned long long start;
unsigned long long end;

start = _itoll (TSCH, TSCL);

/* put your code here */

end = _itoll (TSCH, TSCL);

printf ("Hi mate, I just wasted %d DSP-cycles in your punny code.
Optimize me!\n", end-start);
}

inline long long read_time(void)
{
extern cregister volatile unsigned int TSCL;
extern cregister volatile unsigned int TSCH;
long long l = (TSCH << 32) | TSCL;
return l;
}
在使用TSCL和TSCH時首先需要向TSCL中寫入數據,使能TSC寄存器。
在DSP手冊中說明:
The counter is enabled by writing to TSCL. The value written is ignored.

 

轉載自:http://blog.chinaunix.net/uid-24517893-id-3235121.html

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM