Poor Dhrystone performance

Here is a quick patch.

    --- software/dhrystone/dhry_stubs.c.org 2017-01-02 10:57:54.843417150 +0900
    +++ software/dhrystone/dhry_stubs.c     2017-01-02 14:50:10.592062860 +0900
    @@ -8,7 +8,7 @@
     {
       long t;
       asm volatile ("csrr %0, mcycle" : "=r" (t));
    -  return t / (get_cpu_freq() / 1000);
    +  return t / get_cpu_freq();
     }
     
     // set the number of dhrystone iterations

get_cpu_freq() is defined in bsp/env/freedom-e300-hifive1/init.c and it returns a value calculated with a relatively short loop using RTC in E31 core. I think using RTC as follows is straightforward and more accurate. (Actually it gives very stable dhrystone results.)

    uint32_t mtime_lo(void);  // defined in bsp/env/init.c

    // return the cycle counter as though it were the current time
    long time(void)
    {
      return mtime_lo() / 32768;
    }

Here is the result.

Dhrystones per Second:                      714285.6 

714285.6 / 1757 = 406.5 VAX MIPS (DMIPS)
714285.6 / 1757 / 261 = 1.56 DMIPS/MHz

This matches with Andrew’s measurement.


FYI, here is the result with the C extension (rv32imac).

Dhrystones per Second:                      681818.1 
681818.1/ 1757 / 261 = 1.49 DMIPS/MHz