In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
In this issue, the editor will bring you about how to look at the RT-Thread kernel data structure from rtthread_startup. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
The following does not analyze the implementation of task scheduling and task management in RT-Thread, but only takes the linked list in RT-Thread as a clue to sort out the important data structure and correlation of the whole RT-Thread, so that readers have a general understanding when analyzing the kernel, and you are welcome to correct mistakes.
Let's take a look at rtthread_startup:
Before starting the analysis, do a few instructions, RT-Thread is the most used two-way circular linked list, and plug-in linked list, such a linked list only acts as a link, itself does not carry data, so it can be inserted into a variety of custom structures, these different structures can also be flexibly connected. This is also a personal favorite place, compared with the bloated design of a structure and a linked list of ucos, the design of RT-Thread is too convenient, the linked list has a unified operation, and the code is much more comfortable to read. One of the most important macro definitions for this linked list is # define rt_list_entry (node, type, member)\
((type *) ((char *) (node)-(unsigned long) (& ((type *) 0)-> member)
Forums and online analysis of this understanding, and then understand the linked list operation is not difficult.
Let's focus on the following:
Rt_system_object_init ()
This function is now empty, and the corresponding functions are as follows:
Struct rt_object_information rt_object_ container[RT _ Object_Class_Unknown]
This structure manages all the registered components in the RT-Thread system. From this structure, we can get almost all the information we want in the system. Finsh, such as list_xxx, extract the corresponding information from this structure.
The schematic diagram is as follows:
Rt_system_timer_init ()
The function corresponding to this function is actually to initialize the rt_timer_list linked list and manage the timer that exists in the whole system.
Here is no specific analysis of the source code implementation, only to show the intention:
For threads with fewer than 32 tasks, all ready tasks are marked with the array rt_list_t rt_thread_priority_ table [RT _ THREAD_PRIORITY_MAX]. Using the rt_thread structure
The embedded linked list structure forms a circular linked list with the same priority thread. Different priority threads each occupy an array element.
Notice that a variable rt_current_thread = RT_NULL; will see it later.
Rt_application_init ()
Our application is set up in this, do not explain this process, just look at the rt_thread_create function to complete the correlation of which data structures.
Rt_thread_create
-> rt_object_allocate
-- > information = & rt_object_ container [type]
Rt_list_insert_after (& (information- > object_list), & (object- > list)); up to this thread appears in the kernel's field of vision
-- > _ rt_thread_init
-- > rt_object_init ((rt_object_t) timer, RT_Object_Class_Timer, name); add rt_object_container to the built-in timer structure of the thread
_ rt_timer_init (timer, timeout, parameter, time, flag)
-- > rt_list_init (& (timer- > row [I])); timer is added to the rt_timer_list list.
Rt_thread_idle_init ()
In the application, we can set rt_thread_idle_hook, complete CPU utilization statistics, CPU into low-power mode and other functions.
Another global variable rt_thread_defunct is involved in rt_thread_idle_excute. When a task is deleted, the deleted task control block will be connected to the linked list. Complete the recovery of resources in idle tasks to improve system performance.
Rt_system_scheduler_start ()
From this function, the system is officially running, first getting the highest priority task that is ready, then assigning a value to rt_current_thread, and finally triggering a soft interrupt to switch to the corresponding task stack to execute the task.
To_thread = rt_list_entry (rt_thread_priority_ table [highest _ ready_priority] .next
Struct rt_thread
Tlist)
Rt_current_thread = to_thread
Rt_hw_context_switch_to ((rt_uint32_t) & to_thread- > sp)
There are two rt_list_t type elements in each rt_thread, where list in rt_object parent is used to organize kernel objects. Tlist is used as a link to the rt_timer_list waiting list, it can also be added to the idle processing chain rt_thread_defunct after deleting the task, or it can be linked to the suspend list in IPC.
The above is the editor for you to share how to look at the RT-Thread kernel data structure from rtthread_startup, if you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.