FAQ: How do I benchmark or count system cycles of a segemnt of code on the ADSP-CM41x (2 Methods) ?

Document created by John_M Employee on Feb 16, 2016Last modified by John_M Employee on Feb 16, 2016
Version 4Show Document
  • View in full screen mode

Method 1:

/ This example uses the ADSP-CM41X Enablement Software, available as a free download


/*=============  D A T A  =============*/


volatile Uint32_t data_a, data_b, data_c, data_d, data_e, data_f;   // Data variables


/*=============  C O D E  =============*/


CYCLES_INIT                                  // Initialize and enable system tick counter
CYCLES_CLR                                  // Clear system tick counter
data_a  = CYCLES_GET;                   // Get counter value
data_b  =    CYCLES_GET;                 // Get counter value
// Code of interest
. . .
. . .
// End of code of interest
data_c =    CYCLES_GET;                // Get counter value
data_d = data_b - data_a;                 // Calculate over head of read routines
data_e = data_c - data_b - data_d;   // Calculate system ticks or cycles to execute code of interest
// data_e is the number of cycles to execute code of interest


Method 2:


You can use the Systick Timer available with the cortex M4 core to benchmark a section of the code as below:



long long sys_count=0,dd=0,final=0;

long long count1=0,count2=0;


void main()



//code to be benchmarked




void start_cnt()


*pREG_SCS0_STRVR=0xFFFFFF;  //Initial 24-bit count(decrements from here)

*pREG_SCS0_STCVR=0;         //Current value of countdown

*pREG_SCS0_STCSR=7;         //interrupt and timer enable



void stop_cnt()



final=(sys_count*0xffffff)+dd;   //holds the final cycle count



  void SysTick_Handler ()


sys_count++;    //keep track of number of timer overflows