简体   繁体   中英

Is time.h clock() broken on my hardware?

I try to measure the clock cyles needed to execute a piece of code on the TMS32064x+ DSP that comes with the OMAP ZOOM 3430 MDK. I look at the "Programmer's Guide" of the DSP chip and it says that the DSP supports the clock() function.

What I do is really simple, I just do

start = clock();
for (i=0;i<100;i++){
    /* do something here */
}
stop = clock();
total = stop - start;

and then put the values of "start","stop" and "total" to a previously allocated shared memory with the ARM processor. Then I simply print it to the screen at the ARM side.

The problem is, in my first executes, I always get the same "total" value, and then in my next runs I always get 0! The "start" and "stop" values go along with the "total" value.

The strangest thing is that they seem to follow a bit pattern! I put the output below:

# ./sampleapp
Total = 63744
Start clock() value = 0x000000f9
Stop  clock() value = 0x0000f9f9
# ./sampleapp 
Total = 4177526784
Start clock() value = 0x00f9f9f9
Stop  clock() value = 0xf9f9f9f9
# ./sampleapp
Total clock cyles = 0
Start clock() value = 0xf9f9f9f9
Stop  clock() value = 0xf9f9f9f9

Apparantly, clock() is not functioning well, but I'm not sure if this is because of something I do wrong or because this type of thing is not supported with the hardware I have. Any ideas why this might be happening?

从目前为止的阅读问题来看,我认为原始海报对此问题的了解远远超过目前的贡献者,并且怀疑时钟()被破坏(或不支持,并返回未定义的结果) DSP似乎很有可能。

Curiously, Why do you require a previously allocated shared memory . Why don't you try with a normal stack variable? Is there anything that I am missing?

也许你需要先初始化时钟。

How are you printing it out? maybe the issue is actually with displaying the result?

on most platforms clock_t is a long long. If you're using printf with %d you might get variable results which is what you're seeing.

Assuming the start and end variable are of type 'clock_t', and your shared memory assumes the same on the other end's interpretation of the numbers passed, then your problem is not with the call to clock, and your handleing of the difference between the start end end times.

I believe your problem is in the shared memory between the two. Can you please post code to show how you're sharing memory between two separate processors?

Perhaps you could use some inline assembly to access the CPU's counter registers directly.

The TMS320C64x+ has a 64-bit timestamp register in TSCL, TSCH. The counter is not enabled on reset, you must first write to the register to start the counter (maybe this is the problem with clock ?). Reading from the register is not quite trivial as each half must be read with a separate instruction (and you can get interrupts...).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM