Code execution too slow

Hello,

 

We have found out that processing is too slow on our Renesas RZ A1M target, but we can't figure out what is wrong. For benchmarking purposes the following code is written:

 

#define CPU_FREQUENCY_KHZ 390000
#define NUMBER_OF_INSTRUCTIONS 14

static void Wait1ms(void)
{
  uint32_t count = CPU_FREQUENCY_KHZ/NUMBER_OF_INSTRUCTIONS;
  while ( count > 0 )
  {
    asm( "NOP");
    count--;
  }
}

void main(void)
{
  while ( true )
  {
    TestPinHigh();

    Wait1ms();

    TestPinLow();
  }
}

 

 

The while-loop inside Wait1ms contains around 14 instructions (number of instructions cannot exactly be determined). The counter is set to a value so that the expected duration is around 1ms. The measured duration is, however, more than 7ms. Does anyone have an idea about what our problem is?

  • Hello,

    How do you estimate the number of the instructions inside the while-loop? Also are you sure that you run your MCU at the 390MHz frequency?
  • In reply to Sergey Sokol:

    We viewed the disassembly and calculated the total number of cycles for the instructions executed, given the number of cycles per instruction (http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ddi0388e/Babghcej.html). Although this cannot be calculated exactly, we expected that the total number has less than 50% error.

    We have solved the speed problem; caching was not configured correctly. This, however, introduced another problem: when transmitting strings with DMA, the same string is printed over and over again, while this was not the case without configuring the cache. We have configured one page, in which the buffer to transmit is placed, with the following cache settings:

     

    @ setting for Outer and inner Non-cacheable, and Non-secure Normal memory
    @                                             ------------1------------------- NS
    @                                             -----------------100------------ TEX[2:0]
    @                                             ---------------------------0---- XN
    @                                             ----------------------------0--- C
    @                                             -----------------------------0-- B
    .EQU TTB_PARA_NORMAL_NOT_CACHE_NS, 0x84DE2 @2_00000000000010000100110111100010

     

    Do you have any idea what we are doing wrong?

  • In reply to nils:

    nils,

    If you have now enabled cache, you must declare your port variables "volatile" or they will send and or receive the cached values.

    I hope this helps

    Mike Clements
    RenesasRulz Moderator

  • This thread will be archived due to inactivity.

    Mike Clements
    RenesasRulz Moderator