Counting number of cycles

Dear all,

How can I count de exact number of cycles spent by processor during a very small code execution?

I'm using an EDB9315A with ARM920T processor running Linux 2.6

Thanks in advance,

Reply to
Ricardo Menotti
Loading thread data ...

It would depend on how small the code is. If it is small enough then you can count it by hand, using the ARM reference manual to get the number of cycles per instruction. If the code is longer then you could run it in a simulator and have the simulator count the instructions for you.

--
Regards,
Richard.

+ http://www.FreeRTOS.org
Designed for Microcontrollers.  More than 7000 downloads per month.

+ http://www.SafeRTOS.com
Certified by TÜV as meeting the requirements for safety related systems
Reply to
FreeRTOS info

ou

a

Additionally some processors have cycles counters that can be used for things like this, if they aren't already being used. Keep in mind that any context switches will through off both the measurement, and perhaps the point of even taking a measurement. And once you get into the possibility of cache hits/misses, etc... you are talking more average numbers than specific ones.

Reply to
Chris Stratton

...assuming interrupts are disabled, otherwise you are not actually measuring the subject code itself.

--
Regards,
Richard.

+ http://www.FreeRTOS.org
Designed for Microcontrollers.  More than 7000 downloads per month.

+ http://www.SafeRTOS.com
Certified by TÜV as meeting the requirements for safety related systems
Reply to
FreeRTOS info

a

ou

of

a

I do believe I said something about the effect of context switches on both the measurement and the utility of taking a measurement...

Reply to
Chris Stratton

Yes - you mentioned ensureing no context switches occurred, I was thinking you meant task switches, not interrupts, so I was just adding in that interrupts should be disabled too. Seems like I just misunderstood you.

- Regards, Richard.

  • formatting link
    Designed for Microcontrollers. More than 7000 downloads per month.
  • formatting link
    Certified by TÜV as meeting the requirements for safety related systems
Reply to
FreeRTOS info

Many (all?) compilers thesedays have options to 1. generate an assembly listing output and 2. within that listing generate a column that has the number of cycles to execute each instruction. You still want to read through the processor reference manual, as the listing may contain things such as 1/2 for a branch instruction, which may mean it takes 1 cycle if the branch not taken and 2 cycles if the branch is taken. Read through the manual carefully about the CPU operation as there may be things such as invalidated caches that add cycles to execution time.

Reply to
Ben Bradley

With a modern processor, it is generally impossible to count the number cycles taken by a piece of code without a simulator as it depends on too many factors and it is going to be different from one time to another. The state of the pipeline, the branch prediction, the cache, the state of the TLB, the state of the SDRAM, the DMA interferrence - all affects the time of the execution dramatically.

Vladimir Vassilevsky DSP and Mixed Signal Design Consultant

formatting link

Reply to
Vladimir Vassilevsky

If this is an embedded board and you have a spare port bit, you can profile code in real time by by setting the port bit at start of section and clear it again on exit. Then just use a scope to measure the pulse width. You need to factor in the time taken to set and clear the bit, but this is usually minimal on modern processors.

If you have interrupts going on as well you can see the min/max times in the jitter...

Regards,

Chris

Reply to
ChrisQ

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.