Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
10 years ago

Why my Nios II run slowly ?

Dear all,

I have do experiment on the Cyclone V SOC. [Helio evaluation board]

And I put one nios/e and onchip-ram into the FPGA fabric.

Currently, I could read/write the data in/out from Onchip RAM.

Now, I am measuring the time duration for my source code.

I discover that each instruction runs slowly.

Below is my simple source code.

I don't understand that the one line[*pdata = i++;] I comment , it needs to take 1us.

It should not be correct performance.

Or should I choose the better version of Nios II ?

Anyone could suggest or hint me why and what to do?

Attached file is my zip file of QSYS.

# include <stdio.h># include "system.h"# include "altera_avalon_pio_regs.h"

unsigned int LED_TOGGLE = 0;

unsigned char *pData = ONCHIP_MEMORY2_1_BASE;

int main()

{

int i = 0;

printf("Hello from Nios II!\n");

while(1)

{

IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE,LED_TOGGLE);

LED_TOGGLE = ~LED_TOGGLE;

//*pdata = i++;

}

return 0;

}

9 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Use NIOS /f and compile without debug information and with optimizations

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi, I use scope[logic analysis] and connect the LED output.

    And comment / dis-comment the line of [write data]. check time difference between comment and dis-comment.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    According to my QSYS,

    All components[including NiosII] are connected to clk and it is default for 50Mhz.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Count the instructions in the loop:

    1) Read of LED_TOGGLE for the io_write

    2) Write of LED_TOGGLE to the hardware

    3) Read of LED_TOGGLE for the invert

    4) the invert inself

    5) Write back of LED_TOGGLE

    6) Unconditional branch

    IIRC a nios/e takes 5 clocks per instruction - so that is at least 30 clocks.

    The constant LED_PIO_DATA_BASE might also be created each loop iteration.

    Add in any extra clocks for the avalon write caused by your slave itself.

    Make LED_TOGGLE a local variable (so it can be assigned to a register).

    Compile with -O2 so that the compiler moves some calculations outside the loop.

    That should get you to a three instruction loop.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thanks for all suggestion.

    Because my Quartus II/NiosEDS is web edition, some option does not appear like optimization and version of Nios.

    I select subscription edition of Quartus, choose Nios/F and select opt to O2 or O3.

    It seems to get better performance.

    Thanks a lot for everyone.