I need to benchmark some C++ code on the FVP_MPS2_Cortex-M4 simulator.
I considered using CMSIS function osKernelGetTickCount() to provide timestamps but the resolution of the tick timer seems to be 1ms, which is too coarse.
What would be a suitable clock counter to use for the timings?
Would ARM_CM_DWT_CYCCNT be suitable and, if so, how would I access it?Best regards
David
Hi David,
Yes, the FVP supports this register. You can access it in your code (in Thread mode) using something like the below.
#define CM_DEMCR (*((volatile unsigned int*)0xE000EDFC)) #define CM_TRCENA_BIT (1UL<<24) #define CM_DWT_CONTROL (*((volatile unsigned int*)0xE0001000)) #define CM_DWT_CYCCNTENA_BIT (1UL<<0) #define CM_DWT_CYCCNT (*((volatile unsigned int*)0xE0001004)) void start_cyccnt() { CM_DEMCR |= CM_TRCENA_BIT; CM_DWT_CONTROL |= CM_DWT_CYCCNTENA_BIT; CM_DWT_CYCCNT = 0; } unsigned int stop_cyccnt() { CM_DWT_CONTROL &= ~CM_DWT_CYCCNTENA_BIT; return CM_DWT_CYCCNT; }
Note that the FVP is not fully cycle accurate (especially regarding memory access timing),but useful for relative comparison, See Cortex-M4 processor documentation for description of the registers.
There are CMSIS functions available too, though these are for Arm architecture v8.1M (such as Cortex-M55), Cortex-M4 is v7-M processor, and so only supports a subset of the functionality.https://arm-software.github.io/CMSIS_5/Core/html/group__pmu8__functions.html
Regards
Ronan
Hi Ronan
Thanks for your answer. My reason for wanting the counter is to provide a clock source for the C++ std::chrono library. I will investigate whether they will work together. BTW what do you mean by 'thread mode'?
Best regards