Skip to content

smp execution_profile function's error #541

@qualityguo

Description

@qualityguo

Describe the bug
Error occurred while obtaining the execution time of the kernel

information
Please also mention any information which could help others to understand
the problem you're facing:
device: zynq7010(Cortex-A9),ThreadX-Verison:6.4.1
toolchain:gnu-gcc(Xilinx-Vitis-toolchain)

code
I use a task to monitor my CPU usage,example code:

EXECUTION_TIME ThreadTime_S1[TX_THREAD_SMP_MAX_CORES];
EXECUTION_TIME IdleTime_S1[TX_THREAD_SMP_MAX_CORES];
EXECUTION_TIME IsrTime_S1[TX_THREAD_SMP_MAX_CORES];
_tx_execution_thread_total_time_get(&ThreadTime_S1[0]);
_tx_execution_isr_time_get(&IsrTime_S1[0]);
_tx_execution_idle_time_get(&IdleTime_S1[0]);
for(UINT i = 0; i < TX_THREAD_SMP_MAX_CORES; i++)
  {
  	App_Printf("Core %u 利用率 = %5.2f%%\r\n", i, OSCPUUsage[i]);
  	App_Printf("Core %u 任务执行时间 = %.9fs\r\n", i, (double)ThreadTime_S1[i]/GTC_CLK_FREQ_HZ);
  	App_Printf("Core %u 空闲执行时间 = %.9fs\r\n", i, (double)IdleTime_S1[i]/GTC_CLK_FREQ_HZ);
  	App_Printf("Core %u 中断执行时间 = %.9fs\r\n", i, (double)IsrTime_S1[i]/GTC_CLK_FREQ_HZ);
  	App_Printf("Core %u 系统总执行时间 = %.9fs\r\n", i, (double)(ThreadTime_S1[i] + IdleTime_S1[i] + \
  										 	 	 	IsrTime_S1[i])/GTC_CLK_FREQ_HZ);
  }

log

Logs befor code modification:
[Core0] ===============================================================
[Core0] Core 0 利用率 =  0.05%
[Core0] Core 0 任务执行时间 = 0.006152898s
[Core0] Core 0 空闲执行时间 = 10.243573122s
[Core0] Core 0 中断执行时间 = 0.000000990s
[Core0] Core 0 系统总执行时间 = 10.249727010s
[Core0] Core 1 利用率 = -0.03%
[Core0] Core 1 任务执行时间 = 0.000000000s
[Core0] Core 1 空闲执行时间 = 14462580.399226261s
[Core0] Core 1 中断执行时间 = 16553078.438070176s
[Core0] Core 1 系统总执行时间 = 31015658.837296437s
[Core0] ===============================================================
[Core0]  任务优先级 任务栈大小 当前使用栈  最大栈使用   任务名
[Core0]    Prio     StackSize   CurStack    MaxStack   Taskname
[Core0]     2         4092        511         631      App Task Start
[Core0]    20         4092        583        1103      App Task LED
[Core0]    21         4092        335         415      App Task KEY
[Core0]     0         1020        307         411      System Timer Thread
Log after code modification:
[Core0] Core 0 利用率 =  0.06%
[Core0] Core 0 任务执行时间 = 0.231750803s
[Core0] Core 0 空闲执行时间 = 9.975616784s
[Core0] Core 0 中断执行时间 = 0.002151840s
[Core0] Core 0 系统总执行时间 = 10.209519427s
[Core0] Core 1 利用率 =  0.05%
[Core0] Core 1 任务执行时间 = 0.006162105s
[Core0] Core 1 空闲执行时间 = 10.203567718s
[Core0] Core 1 中断执行时间 = 0.000000987s
[Core0] Core 1 系统总执行时间 = 10.209730810s
[Core0] ===============================================================
[Core0]  任务优先级 任务栈大小 当前使用栈  最大栈使用   任务名
[Core0]    Prio     StackSize   CurStack    MaxStack   Taskname
[Core0]     2         4092        511         631      App Task Start
[Core0]    20         4092        583        1091      App Task LED
[Core0]    21         4092        335         415      App Task KEY
[Core0]     0         1020        307         411      System Timer Thread

modify
Code modification location:
file:
threadx/utility/execution_profile_kit/smp_version/tx_execution_profile.c
function:
_tx_execution_thread_total_time_get
_tx_execution_isr_time_get
_tx_execution_idle_time_get
code:(Three places need to be modified)
- *total_time = _tx_execution_idle_time_total[core];
+ total_time[core] = _tx_execution_idle_time_total[core];

In the original code, the time of core 0 is set to the time of core 1, and the time of core 1 is a random value.

Another question
Why is the SCU timer chosen as the time reference for performance measurement? It is a decrementing counter, and it is thought that an incrementing counter would be better, that is, the GTC timer.

In file threadx/ports_smp/cortex_a9_smp/gnu/src/tx_thread_smp_time_get.S, I think not LDR r0, [r0, #0x604]
should LDR r0, [r0, #0x200]
The following code can prove this point.

/* Pickup the current time.  */
        current_time =  TX_EXECUTION_TIME_SOURCE;

        /* Pickup the last start time.  */
        last_start_time =  thread_ptr -> tx_thread_execution_time_last_start;

        /* Determine if there is an actual start time.  */
        if (last_start_time)
        {

            /* Clear the last start time.  */
            thread_ptr -> tx_thread_execution_time_last_start =  0;
      
            /* Determine how to calculate the difference.  */
            if (current_time >= last_start_time)
            {
        
                /* Simply subtract.  */
                delta_time =  (EXECUTION_TIME) (current_time - last_start_time);
            }        
            else
            {
        
                /* Timer wrapped, compute the delta assuming incrementing time counter.  */
                delta_time =  (EXECUTION_TIME) (current_time + (((EXECUTION_TIME_SOURCE_TYPE) TX_EXECUTION_MAX_TIME_SOURCE) - last_start_time));
            }
...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghardwareNew hardware or architecture support request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions