Skip to content

benchmark: fix build error on Cortex-M0 #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions benchmark/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@
mbedtls_printf( "FAILED: -0x%04x\r\n", -ret );
#endif

#if defined(CoreDebug_DEMCR_TRCENA_Msk) && defined(DWT_CTRL_CYCCNTENA_Msk)
/* DWT cycle counter is available (Cortex-M3, Cortex-M4) */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't use different ways of measuring time. Using the same implementation will let us compare results across different platforms/MCUs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code always prints kB/s. I only changed the additional printing of cycles/byte, which aren't meaningful across platforms. The only fully portable alternative is not to have a cycle count at all, AFAICT. So this is the best I know how to do at the moment, but I'm open to suggestions.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest we remove the usage of the cycle counter and use only one way of measuring time (which is supported across platforms).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#79 removes the cycle counter altogether.

static unsigned long mbedtls_timing_hardclock( void )
{
static int dwt_started = 0;
Expand All @@ -191,6 +193,26 @@ static unsigned long mbedtls_timing_hardclock( void )

return( DWT->CYCCNT );
}
#define mbedtls_timing_before() (mbedtls_timing_hardclock())
#define mbedtls_timing_after() (mbedtls_timing_hardclock())
#define MBEDTLS_TIMING_UNIT "cycles"

#else /* No cycle counter, default to mbed microsecond timer */

static Timer timer;
static unsigned long mbedtls_timing_before( void )
{
timer.reset( );
timer.start( );
return( 0 );
}
static unsigned long mbedtls_timing_after( void )
{
timer.stop( );
return( timer.read_us() );
}
#define MBEDTLS_TIMING_UNIT "usec"
#endif

static volatile int alarmed;
static void alarm() { alarmed = 1; }
Expand All @@ -207,15 +229,15 @@ do { \
CODE; \
} \
\
tsc = mbedtls_timing_hardclock(); \
tsc = mbedtls_timing_before(); \
for( j = 0; j < 1024; j++ ) \
{ \
CODE; \
} \
\
mbedtls_printf( "%9lu Kb/s, %9lu cycles/byte\r\n", \
mbedtls_printf( "%9lu Kb/s, %9lu " MBEDTLS_TIMING_UNIT "/byte\r\n", \
i * BUFSIZE / 1024, \
( mbedtls_timing_hardclock() - tsc ) / ( j * BUFSIZE ) ); \
( mbedtls_timing_after() - tsc ) / ( j * BUFSIZE ) ); \
} while( 0 )

#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && defined(MBEDTLS_MEMORY_DEBUG)
Expand Down