Login

Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

ARM websites use two types of cookie: (1) those that enable the site to function and perform as required; and (2) analytical cookies which anonymously track visitors only while using the site. If you are not happy with this use of these cookies please review our Privacy Policy to learn how they can be disabled. By disabling cookies some features of the site will not work.

ARM Community: Cycle count in cortex m3 - ARM Community

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Cycle count in cortex m3 Rate Topic: -----

#1 User is offline   Krish 

  • Member
  • Pip
  • Group: Members
  • Posts: 8
  • Joined: 10-December 09

Posted 10 December 2009 - 09:00 AM

Hi all,
I am new to cortex m3...
For my application I need to calculate the number of cycles for a particular function....
I set the debug options as high optimization level and optimize for time....

How can I calculate the MIPS/cycles manually for a particular function.
Please suggest me a solution...

Thanks in advance.
Krish.
0

#2 User is offline   isogen74 

  • Super Contributor
  • PipPipPipPip
  • Group: Members
  • Posts: 1097
  • Joined: 20-March 07

Posted 10 December 2009 - 09:50 AM

The low tech solution:

Run it in a loop a _lot_ of times.
Use a stop watch.
((Seconds * MHz) / Loops) = cycles per loop.
When optimizing software, consider that the quickest code to run is the bit you removed from the call path.
0

#3 User is offline   Krish 

  • Member
  • Pip
  • Group: Members
  • Posts: 8
  • Joined: 10-December 09

Posted 10 December 2009 - 11:58 AM

Thanks for the reply....
does armulator serve my purpose?
If so how to start with realview debugger?(any settings).

View Postisogen74, on Dec 10 2009, 10:50 AM, said:

The low tech solution:

Run it in a loop a _lot_ of times.
Use a stop watch.
((Seconds * MHz) / Loops) = cycles per loop.

0

#4 User is offline   mharnisch 

  • Contributor
  • PipPip
  • Group: Members
  • Posts: 80
  • Joined: 11-April 08

Posted 10 December 2009 - 03:08 PM

View PostKrish, on Dec 10 2009, 01:58 PM, said:

If so how to start with realview debugger?(any settings).

The ISSM for Cortex-M3 is semi-accurate. It models an ideal memory sub-system. Not sure about the pipeline accuracy, but I guess CM3 is simple enough.

If you are really concerned about accuracy, get a cheap eval board and read the cycle count register in the DWT unit.

Regards
Marcus
0

#5 User is offline   Krish 

  • Member
  • Pip
  • Group: Members
  • Posts: 8
  • Joined: 10-December 09

Posted 11 December 2009 - 08:36 AM

Thanks Marcus,

so we can access the DWT only by connecting the board?
I tried like this but did not work....

int count = 0;
int *DWT_CPICNT = (int *)0xE0001008; //address of the register
*DWT_CPICNT = 0; // reset the counter
.......
......
count = *DWT_CPICNT;

can you please suggest me how to access the DWT unit without the board?

Thanks & regards,
Krish.
0

#6 User is offline   mharnisch 

  • Contributor
  • PipPip
  • Group: Members
  • Posts: 80
  • Joined: 11-April 08

Posted 11 December 2009 - 01:19 PM

View PostKrish, on Dec 11 2009, 10:36 AM, said:

so we can access the DWT only by connecting the board?
I tried like this but did not work....

Not sure if this part of DWT is modelled in ISSM. Did you follow the initialisation procedure in the Cortex-M3 TRM?

Regards
Marcus
0

#7 Guest_Joseph Yiu_*

  • Group: Guests

Posted 11 December 2009 - 06:29 PM

Hi Krish,

I few things you need to do:
1. Define the registers as "volatile", and "unsigned"

2. Enable TRCENA bit in DEMCR (0xE000EDFC, bit 24) before using DWT

3. You should use DWT's Cycle Count Register (0xE0001004) for timing measurement.
The CPI counter is only 8-bit, and need to have trace support to detect the number of time it overflow.
While the DWT Cycle Count Register is 32-bit.

4. You need to enable the Cycle Count counter.

So based on the code you have prepared, it can be modified to:
int count = 0;
volatile unsigned int *DWT_CYCCNT = (int *)0xE0001004; //address of the register
volatile unsigned int *DWT_CONTROL = (int *)0xE0001000; //address of the register
volatile unsigned int *SCB_DEMCR = (int *)0xE000EDFC; //address of the register

*SCB_DEMCR = *SCB_DEMCR | 0x01000000;
*DWT_CYCCNT = 0; // reset the counter
*DWT_CONTROL = *DWT_CONTROL | 1 ; // enable the counter
.......
......
count = *DWT_CYCCNT;

I haven't test this code in hardware but it should work.... :-)
The ISSM might not have the detail model of debug components, so it is best to do the timing measurement on actual hardware, either on actual microcontroller or on our FPGA prototyping system.

Note that if the debugger you are using is trying to use this counter at the same time (e.g. if you have got some sort of profiling feature turn on in your debug environment), you might find incorrect profiling result by doing this.

regards,
Joseph
0

#8 User is offline   Krish 

  • Member
  • Pip
  • Group: Members
  • Posts: 8
  • Joined: 10-December 09

Posted 12 December 2009 - 07:21 AM

Thank you very much.....

I am really very happy for the support from you all.....

Thanks Marcus and Joseph.....

I'll try it and get back to you.......

Thanks....
Krish
0

#9 User is offline   BillNeifert 

  • Member
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 26-January 10

Posted 26 January 2010 - 07:36 PM

The best way to get accurate results for this is to use accurate models. Carbon Design Systems has models of the M3 (as well as all the other processors and peripherals) which are compiled directly from ARM's RTL and are 100% implementation accurate. These models can work in pretty much any virtual or RTL environment and also feature debugger integrations to enable you to debug your software as well.

<disclaimer> I work for Carbon
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic