This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AM2634: Instructions and clock calculation

Part Number: AM2634


Tool/software:

Dear Team,

I want to calculate program execution time to define the state machine cycles for our project.

I want to know how to  calculate program execution time in CCS

SDK - mcu_plus_sdk_am263x_09_02_00_56

 

lets take a example:

void initializeStringArray() {

 

  char stringArray[10][100];

  char buff[100] = { 0 };

 

  // Initialize the string array

  for (int i = 0; i < 10; ++i) {

    for (int j = 0; j < 100; j++) {

      stringArray[i][j] = j;

    }

    stringArray[i][99] = '\0';

  }

we have to calculatre the time taken to execute the above code.

  • Here's how to get the number of execution cycles: AM263x MCU+ SDK: Cycle Counter (ti.com)

  • thanks for your support & answer

  • Dear Kier,

    I have 2 observations

    1. WIthout Optimization:- 

    CycleCounterP_reset();

    cycleCountBefore = CycleCounterP_getCount32();
    initializeStringArray();                                                    // User functon
    cycleCountAfter = CycleCounterP_getCount32();

    void initializeStringArray() {

    char stringArray[10][100];
    char buff[100] = { 0 };

    // Initialize the string array
    for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 100; j++) {
    stringArray[i][j] = j;
    }
    stringArray[i][99] = '\0';
    }
    }

    without optimzation its showing 23154 clocks that is irrelevant, how its possible to take that much of clock 

    2. With Optimizatoin:-

    and with optimization its showing 9 clock only that's also irrelevant

    So kindly let me know how to test task execution time 

    /------------------------- Unoptimized code assemble --------------------------/

     47 void initializeStringArray() {
    initializeStringArray():
    70051ed0: B580 push {r7, r14}
    70051ed2: F5AD6D8B sub.w r13, r13, #0x458
    70051ed6: A803 add r0, r13, #0xc
    70051ed8: 2164 movs r1, #0x64
    50 char buff[100] = { 0 };
    70051eda: F001EB36 blx __aeabi_memclr
    70051ede: 2000 movs r0, #0
    54 for (int i = 0; i < 10; ++i) {
    70051ee0: 9002 str r0, [r13, #8]
    70051ee2: E7FF b #0x70051ee4
    70051ee4: 9802 ldr r0, [r13, #8]
    70051ee6: 2809 cmp r0, #9
    70051ee8: DC20 bgt #0x70051f2c
    70051eea: E7FF b #0x70051eec
    70051eec: 2000 movs r0, #0
    55 for (int j = 0; j < 100; j++) {
    70051eee: 9001 str r0, [r13, #4]
    70051ef0: E7FF b #0x70051ef2
    70051ef2: 9801 ldr r0, [r13, #4]
    70051ef4: 2863 cmp r0, #0x63
    70051ef6: DC0C bgt #0x70051f12
    70051ef8: E7FF b #0x70051efa
    56 stringArray[i][j] = j;
    70051efa: 9801 ldr r0, [r13, #4]
    70051efc: 9902 ldr r1, [r13, #8]
    70051efe: AB1C add r3, r13, #0x70
    70051f00: 2264 movs r2, #0x64
    70051f02: FB013102 mla r1, r1, r2, r3
    70051f06: 5408 strb r0, [r1, r0]
    57 }
    70051f08: E7FF b #0x70051f0a
    55 for (int j = 0; j < 100; j++) {
    70051f0a: 9801 ldr r0, [r13, #4]
    70051f0c: 3001 adds r0, #1
    70051f0e: 9001 str r0, [r13, #4]
    70051f10: E7EF b #0x70051ef2
    58 stringArray[i][99] = '\0';
    70051f12: 9802 ldr r0, [r13, #8]
    70051f14: AA1C add r2, r13, #0x70
    70051f16: 2164 movs r1, #0x64
    70051f18: FB002101 mla r1, r0, r1, r2
    70051f1c: 2000 movs r0, #0
    70051f1e: F8810063 strb.w r0, [r1, #0x63]
    59 }
    70051f22: E7FF b #0x70051f24
    54 for (int i = 0; i < 10; ++i) {
    70051f24: 9802 ldr r0, [r13, #8]
    70051f26: 3001 adds r0, #1
    70051f28: 9002 str r0, [r13, #8]
    70051f2a: E7DB b #0x70051ee4
    60 }
    70051f2c: F50D6D8B add.w r13, r13, #0x458
    70051f30: BD80 pop {r7, pc}
    145 }

    /-------------------------------------------------------------------------------------------/ 

  • Hi Vikas, 

    As you have tried in your code, the usage of Cycle counter is correct.

    uint32_t start, end, overhead;
    
        /* Calculate overhead */
        CycleCounterP_reset();
    
        start = CycleCounterP_getCount32();
        end = CycleCounterP_getCount32();
        overhead = end - start;
    
        DebugP_log("Total Overhead: %d Cycles\r\n", overhead);


    As it's a 32 bit counter, you can handle overflow like:

    uint32_t cycleCountBefore, cycleCountAfter, cpuCycles; /* enable and reset CPU cycle coutner */ CycleCounterP_reset(); cycleCountBefore = CycleCounterP_getCount32(); /* call functions to profile */ cycleCountAfter = CycleCounterP_getCount32(); /* Check for overflow and wrap around. * * This logic will only work for one overflow. * If multiple overflows happen during the profile period, * then CPU cycles count will be wrong. */ if (cycleCountAfter > cycleCountBefore) { cpuCycles = cycleCountAfter - cycleCountBefore; } else { cpuCycles = (0xFFFFFFFFU - cycleCountBefore) + cycleCountAfter; }

    If measurement of longer durations is needed, it is recommended to use the ClockP_getTimeUsec() API from the Clock module.

    You can also use the CCS in-built profiling options; Please refer to the following links for more information:

    Regards,
    Akshit