DSP 运行时间计算函数--_itoll(TSCH,TSCL);

时间:2023-03-09 06:27:14
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