Clock cycles/time

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Clock cycles/time

Jump to solution
899 Views
Futte
Contributor II

Hi

 

How can i see the executing time for a statement? 

Both time and clock cycles?

 

I thought maybe that i could see it in a register so i looked at Clock Module Register but nothing is happening here. Is it the wrong register i am looking at?

 

cheers

 

Rasmus

Labels (1)
0 Kudos
1 Solution
353 Views
TomE
Specialist II

What CPU are you using? The simple ones are different to the more complex ones. As a first approximation for the CF3 series you can expect "one simple assembly instruction per clock plus two clocks for a read from memory". Multiplies are (usually) 4 clocks and divides are 35. Mispredicted branches take 5 clocks.


> How can i see the executing time for a statement?

"Statement" in what language?

For Assembly statements you read the "Instruction Execution Timing" chapter in the Reference Manual for your CPU.

For "C", see if you can get the compiler to give you a listing of your code with both the source and assembly and then add up the assembly instructions for the statements of interest using the manual. Or you can get the toolchain to disassemble your code. I'm using gcc and "objdump -S" does that.

> i looked at Clock Module Register

The Clock Module is programmed to generate the appropriate CPU and peripheral clocks from the crystal connected to the CPU. It does not provide what you want.

If you're running Linux then you should be able to use "prof" to measure the execution time of your code. I assume you're not doing this.

Your Debugger might provide the ability to measure execution times. If you have a cheap debugger it may not be able to.

If you aren't using anything that does this work for you then you have to do it yourself. This is called "instrumenting your code". Program a hardware counter running at a known frequency and read it before and after a block of code you want to measure. Then subtract the counter values to get the execution time. Edit, compile, load, run, measure, repeat.

If you were using a PPC you'd use the "Timebase" (TBL and TBU) registers for this. On ARM there's usually the CNTPCT register. The ColdFire chips don't have a standard timer, but there are plenty of general purpose timers that can be programmed to serve this purpose. I usually start a 32-bit DMA Timer running at 1MHz, and then add statements to the code I'm measuring to read that register either side and then subtract. I'm using an MCF5329 running at 240MHz so the 1MHz timer is a little coarse for instructions, but appropriate for complex functions.  I also usually write a "real time profiling" system that interrupts the code at IPL7 at a high rate from a timer and records an "execution histogram". I dump that and combine with the symbol table to get a table of where the CPU has been spending its time.

Tom

View solution in original post

0 Kudos
1 Reply
354 Views
TomE
Specialist II

What CPU are you using? The simple ones are different to the more complex ones. As a first approximation for the CF3 series you can expect "one simple assembly instruction per clock plus two clocks for a read from memory". Multiplies are (usually) 4 clocks and divides are 35. Mispredicted branches take 5 clocks.


> How can i see the executing time for a statement?

"Statement" in what language?

For Assembly statements you read the "Instruction Execution Timing" chapter in the Reference Manual for your CPU.

For "C", see if you can get the compiler to give you a listing of your code with both the source and assembly and then add up the assembly instructions for the statements of interest using the manual. Or you can get the toolchain to disassemble your code. I'm using gcc and "objdump -S" does that.

> i looked at Clock Module Register

The Clock Module is programmed to generate the appropriate CPU and peripheral clocks from the crystal connected to the CPU. It does not provide what you want.

If you're running Linux then you should be able to use "prof" to measure the execution time of your code. I assume you're not doing this.

Your Debugger might provide the ability to measure execution times. If you have a cheap debugger it may not be able to.

If you aren't using anything that does this work for you then you have to do it yourself. This is called "instrumenting your code". Program a hardware counter running at a known frequency and read it before and after a block of code you want to measure. Then subtract the counter values to get the execution time. Edit, compile, load, run, measure, repeat.

If you were using a PPC you'd use the "Timebase" (TBL and TBU) registers for this. On ARM there's usually the CNTPCT register. The ColdFire chips don't have a standard timer, but there are plenty of general purpose timers that can be programmed to serve this purpose. I usually start a 32-bit DMA Timer running at 1MHz, and then add statements to the code I'm measuring to read that register either side and then subtract. I'm using an MCF5329 running at 240MHz so the 1MHz timer is a little coarse for instructions, but appropriate for complex functions.  I also usually write a "real time profiling" system that interrupts the code at IPL7 at a high rate from a timer and records an "execution histogram". I dump that and combine with the symbol table to get a table of where the CPU has been spending its time.

Tom

0 Kudos