#include "c6x.h"
unsigned int a,b;
TSCL = 0; //初始化
a = TSCL;
...
...
b=TSCL;
cycle = 0xFFFFFFFF-a+b-1; //防止翻转
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
要计算函数的准确执行时间,可以用内部寄存器TSCL, TSCH,用法见下面的帖子。
https://www.deyisupport.com/question_answer/dsp_arm/c6000_multicore/f/53/t/5708.aspx
TSCL, TSCH寄存器的介绍见下面的CPU user guide。
2.9.13 Time Stamp Counter Registers (TSCL and TSCH)
http://www.ti.com/lit/ug/sprugh7/sprugh7.pdf
您好,
我看了C66x 有TSCL 和TSCH 寄存器,我想知道,这个计数器数值的增长是基于CPU的频率吗?
DSP go main() 函数之后,如果需要用该计数器,是否需要做一些相关的初始化工作?
还是直接像下文中所说,直接用就OK,非常感谢!
在C66x中存在计时寄存器TSC,所以可以通过在测试程序前后读取该寄存器的方式获得程序的运行时间。使用参考如下:
TSCL=0; //初始化为任意值使能TSC时钟计时
start = TSCL;
FUNC();
end = TSCL;
cycle = end - start;
BRS,
Meng
Hello Shine,
谢谢您的回复。
因为C6655的主频,是1.25Ghz,,也就是说,每秒钟定时器计数的增长值为1.25*(10^9) = 1250000000,这样的话,32为计数器,就会很快溢出。
比较复杂的程序,很难用TSCL来统计,必须用TSCH一块来统计计数值,如果这样的话,我参考您的代码修改如下,您看一下是否合适?
#include "c6x.h"
unsigned long long a,b;
TSCL = 0; //初始化
TSCH = 0;
a = (TSCH<<32) | TSCL;
...
...
b=(TSCH<<32) | TSCL;
//cycle = 0xFFFFFFFF-a+b-1; //防止翻转
cycle = b-a+1; //64 位的,不可能翻转。
我这个写法是否正确?
如果TSCH 与 TSCL组合成64位计数器使用的话,需要额外的设置吗?
非常感谢!
BRS,
Meng
要64bit TSCH, TSCL的话,可以用编译器里的_itoll内联函数读取64bit的值。
例如:
void main() {
unsigned long long t1, t2;
...
TSCL = 0; // Initiate CPU timer by writing any val to TSCL
...
t1 = _itoll( TSCH, TSCL ); // benchmark snapshot of free-running ctr
my_code_to_benchmark();
t2 = _itoll( TSCH, TSCL ); // benchmark snapshot of free-running ctr
printf("# cycles == %ld\n", (t2-t1));
}