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.

RM57L843: bias when Using PMU to determine program execution duration

Part Number: RM57L843

Environment:   RM57 + IAR 7.40.5 For ARM  + JTAG emulator

in our project, we're using PMU cycle counter API to determine some function duration.   Reading PMU cycle counter API is like this:

_pmuGetCycleCount_

    mrc p15, #0, r0, c9, c13, #0
    bx lr

Test Codes: ( they are actually same codes only in different function names)

uint32 DelayMs(void)
{
volatile uint32 i = 0u;
uint32 u32T0 = 0u;
uint32 u32T1 = 0u;
u32T0 = _pmuGetCycleCount_();

for(i = 0u; i<30400u; i++);

u32T1 = _pmuGetCycleCount_();
return u32T1 - u32T0; /* test the duration of for loop */

}

 

uint32 DelayMs1(void)
{
volatile uint32 i = 0u;
uint32 u32T0 = 0u;
uint32 u32T1 = 0u;
u32T0 = _pmuGetCycleCount_();

for(i = 0u; i<30400u; i++);

u32T1 = _pmuGetCycleCount_();
return u32T1 - u32T0; /* test the duration of for loop */

}

uint32 DelayMs2(void)
{
volatile uint32 i = 0u;
uint32 u32T0 = 0u;
uint32 u32T1 = 0u;
u32T0 = _pmuGetCycleCount_();

for(i = 0u; i<30400u; i++);

u32T1 = _pmuGetCycleCount_();
return u32T1 - u32T0; /* test the duration of for loop */

}

void main()

{

...DelayMs();  DelayMs1(); DelayMs(); DelayMs2();....

}

These codes are running in single-task environment, and we've been disabled IRQ.

What's really confusing is that  we get different output from DelayMs(), DelayMs1() and DelayMs2().  Sometimes there can be up to 10% bias. Like DelayMs() returns 1500000, DelayMs1() returns 1600000.

Plus, we can invoke these funtions multiple times in any order, for instance:

DelayMs();

DelayMs2();

DelayMs2();

DelayMs1();

DelayMs()......

all DelayMs() returns same result, and so do all DelayMs1().  So I infer this has nothing to do with IRQ...

Any thoughts what might cause this  bias?

  • So each function call/function name is returning the same PMU results on a consistent basis? Am I reading that correctly? Have you had a look at the disassembly window to be certain each is being compiled to the same object code and that they are the same instruction for instruction in the disassembly window? This could be a case of some optimization or lack of optimization is impacting seemingly the same code in different ways. This too would be an issue, but a different issue requiring a different set of eyes and expertise to figure out.
  • Thanks for reply. Yes you're right, each function is returning same PMU results. Like all DelayMs() returns 1500000, all DelayMs1() returns 1600000. And I've already checked assembly code in disassembly window, DelayMs() code and DelayMs1() code are exactly the same.
  • 2818.testPMU.zipupdate my IAR project, which can run on RM57L843