硬汉嵌入式论坛

 找回密码
 立即注册
查看: 1421|回复: 5
收起左侧

[ThreadX全家桶] 开始研究下ThreadX内核源码,制作RTOS Trace功能

[复制链接]

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
115863
QQ
发表于 2022-9-12 10:03:21 | 显示全部楼层 |阅读模式

uCOS-III的关键信息检索,基本都已经完成,不需要目标板额外做任何代码,实时检测RTOS任务执行情况。

下面开始ThreadX的Trace功能支持。

image.png

ThreadX 的TCB链表:
[C] 纯文本查看 复制代码
/* ThreadX thread control block structure follows.  Additional fields
   can be added providing they are added after the information that is
   referenced in the port-specific assembly code.  */

typedef struct TX_THREAD_STRUCT
{
    /* The first section of the control block contains critical
       information that is referenced by the port-specific 
       assembly language code.  Any changes in this section could
       necessitate changes in the assembly language.  */

    ULONG               tx_thread_id;                   /* Control block ID         */
    ULONG               tx_thread_run_count;            /* Thread's run counter     */
    VOID                *tx_thread_stack_ptr;           /* Thread's stack pointer   */
    VOID                *tx_thread_stack_start;         /* Stack starting address   */
    VOID                *tx_thread_stack_end;           /* Stack ending address     */
    ULONG               tx_thread_stack_size;           /* Stack size               */
    ULONG               tx_thread_time_slice;           /* Current time-slice       */
    ULONG               tx_thread_new_time_slice;       /* New time-slice           */

    /* Define pointers to the next and previous ready threads.  */
    struct TX_THREAD_STRUCT
                        *tx_thread_ready_next,
                        *tx_thread_ready_previous;

    /***************************************************************/

    /* Define the first port extension in the thread control block. This 
       is typically defined to whitespace or a pointer type in tx_port.h.  */
    TX_THREAD_EXTENSION_0
         
    CHAR                *tx_thread_name;                /* Pointer to thread's name     */
    UINT                tx_thread_priority;             /* Priority of thread (0-1023)  */
    UINT                tx_thread_state;                /* Thread's execution state     */
    UINT                tx_thread_delayed_suspend;      /* Delayed suspend flag         */
    UINT                tx_thread_suspending;           /* Thread suspending flag       */
    UINT                tx_thread_preempt_threshold;    /* Preemption threshold         */
    
    /* Define the thread schedule hook. The usage of this is port/application specific, 
       but when used, the function pointer designated is called whenever the thread is
       scheduled and unscheduled.  */
    VOID                (*tx_thread_schedule_hook)(struct TX_THREAD_STRUCT *thread_ptr, ULONG id);

    /* Nothing after this point is referenced by the target-specific
       assembly language.  Hence, information after this point can 
       be added to the control block providing the complete system 
       is recompiled.  */

    /* Define the thread's entry point and input parameter.  */
    VOID                (*tx_thread_entry)(ULONG id);
    ULONG               tx_thread_entry_parameter;

    /* Define the thread's timer block.   This is used for thread 
       sleep and timeout requests.  */
    TX_TIMER_INTERNAL   tx_thread_timer;

    /* Define the thread's cleanup function and associated data.  This
       is used to cleanup various data structures when a thread 
       suspension is lifted or terminated either by the user or 
       a timeout.  */
    VOID                (*tx_thread_suspend_cleanup)(struct TX_THREAD_STRUCT *thread_ptr, ULONG suspension_sequence);
    VOID                *tx_thread_suspend_control_block;
    struct TX_THREAD_STRUCT
                        *tx_thread_suspended_next,
                        *tx_thread_suspended_previous;
    ULONG               tx_thread_suspend_info;
    VOID                *tx_thread_additional_suspend_info;
    UINT                tx_thread_suspend_option;
    UINT                tx_thread_suspend_status;

    /* Define the second port extension in the thread control block. This 
       is typically defined to whitespace or a pointer type in tx_port.h.  */
    TX_THREAD_EXTENSION_1

    /* Define pointers to the next and previous threads in the 
       created list.  */
    struct TX_THREAD_STRUCT
                        *tx_thread_created_next,
                        *tx_thread_created_previous;

    /* Define the third port extension in the thread control block. This 
       is typically defined to whitespace in tx_port.h.  */
    TX_THREAD_EXTENSION_2

    /* Define a pointer type for FileX extensions.  */
#ifndef TX_NO_FILEX_POINTER
    VOID                *tx_thread_filex_ptr;
#endif
    
    /* Define the priority inheritance variables. These will be used
       to manage priority inheritance changes applied to this thread 
       as a result of mutex get operations.  */
    UINT                tx_thread_user_priority;
    UINT                tx_thread_user_preempt_threshold;
    UINT                tx_thread_inherit_priority;
    
    /* Define the owned mutex count and list head pointer.  */
    UINT                tx_thread_owned_mutex_count;
    struct TX_MUTEX_STRUCT
                        *tx_thread_owned_mutex_list;

#ifdef TX_THREAD_ENABLE_PERFORMANCE_INFO

    /* Define the number of times this thread is resumed.  */
    ULONG               tx_thread_performance_resume_count;

    /* Define the number of times this thread suspends.  */
    ULONG               tx_thread_performance_suspend_count;

    /* Define the number of times this thread is preempted by calling 
       a ThreadX API service.  */
    ULONG               tx_thread_performance_solicited_preemption_count;

    /* Define the number of times this thread is preempted by an
       ISR calling a ThreadX API service.  */
    ULONG               tx_thread_performance_interrupt_preemption_count;

    /* Define the number of priority inversions for this thread.  */
    ULONG               tx_thread_performance_priority_inversion_count;

    /* Define the last thread pointer to preempt this thread.  */
    struct TX_THREAD_STRUCT
                        *tx_thread_performance_last_preempting_thread;

    /* Define the total number of times this thread was time-sliced.  */
    ULONG               tx_thread_performance_time_slice_count;

    /* Define the total number of times this thread relinquishes.  */
    ULONG               tx_thread_performance_relinquish_count;

    /* Define the total number of times this thread had a timeout.  */
    ULONG               tx_thread_performance_timeout_count;

    /* Define the total number of times this thread had suspension lifted
       because of the tx_thread_wait_abort service.  */
    ULONG               tx_thread_performance_wait_abort_count;
#endif

    /* Define the highest stack pointer variable.  */
    VOID                *tx_thread_stack_highest_ptr;   /* Stack highest usage pointer  */


#ifndef TX_DISABLE_NOTIFY_CALLBACKS

    /* Define the application callback routine used to notify the application when 
       the thread is entered or exits.  */
    VOID                (*tx_thread_entry_exit_notify)(struct TX_THREAD_STRUCT *thread_ptr, UINT type);
#endif

    /* Define the fourth port extension in the thread control block. This 
       is typically defined to whitespace in tx_port.h.  */
    TX_THREAD_EXTENSION_3


    /* Define variables for supporting execution profile. */
    /* Note that in ThreadX 5.x, user would define TX_ENABLE_EXECUTION_CHANGE_NOTIFY and use TX_THREAD_EXTENSION_3
       to define the following two variables.  
       For Azure RTOS 6, user shall use TX_EXECUTION_PROFILE_ENABLE instead of TX_ENABLE_EXECUTION_CHANGE_NOTIFY,
       and SHALL NOT add variables to TX_THREAD_EXTENSION_3. */
#if (defined(TX_EXECUTION_PROFILE_ENABLE) && !defined(TX_ENABLE_EXECUTION_CHANGE_NOTIFY))
    unsigned long long  tx_thread_execution_time_total;  
    unsigned long long  tx_thread_execution_time_last_start; 
#endif

    /* Define suspension sequence number.  This is used to ensure suspension is still valid when 
       cleanup routine executes.  */
    ULONG               tx_thread_suspension_sequence;

    /* Define the user extension field.  This typically is defined 
       to white space, but some ports of ThreadX may need to have 
       additional fields in the thread control block.  This is 
       defined in the file tx_port.h.  */
    TX_THREAD_USER_EXTENSION

} TX_THREAD;



回复

使用道具 举报

48

主题

376

回帖

520

积分

金牌会员

积分
520
发表于 2022-9-12 10:18:25 | 显示全部楼层
这个牛,功能等价甚至超过IAR的ThreadX debug插件
回复

使用道具 举报

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
115863
QQ
 楼主| 发表于 2022-9-12 11:13:22 | 显示全部楼层
wanglehui_12 发表于 2022-9-12 10:18
这个牛,功能等价甚至超过IAR的ThreadX debug插件

IAR需要调试状态暂停才能查看,这个不用,可以实时更新查看。
回复

使用道具 举报

0

主题

102

回帖

102

积分

初级会员

积分
102
发表于 2022-9-12 13:12:32 | 显示全部楼层
准备 抗 segger的节奏
回复

使用道具 举报

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
115863
QQ
 楼主| 发表于 2022-9-12 15:59:30 | 显示全部楼层
tigerdill 发表于 2022-9-12 13:12
准备 抗 segger的节奏

做点实用好使的功能。
回复

使用道具 举报

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
115863
QQ
 楼主| 发表于 2022-10-9 01:20:14 | 显示全部楼层
ThreadX内核效果:


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2025-5-24 00:55 , Processed in 0.281892 second(s), 27 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表