提交 06ad310b 编写于 作者: K kenneth

内核开发指南文档根据外部意见优化

1、更新M核架构图与文字描述;
2、M核启动流程图格式挑战
3、A核中术语调整:线程改为任务
4、A核扩展组件中漏了动态加载标题
5、A核架构图中“系统调用”文字方向修正
6、中文部分标题同步更新英文
Signed-off-by: Nkenneth <zhushangyuan@huawei.com>
上级 cb021254
...@@ -69,7 +69,7 @@ ...@@ -69,7 +69,7 @@
- [Interrupt and Exception Handling](kernel-small-basic-interrupt.md) - [Interrupt and Exception Handling](kernel-small-basic-interrupt.md)
- [Process Management](kernel-small-basic-process.md) - [Process Management](kernel-small-basic-process.md)
- [Process](kernel-small-basic-process-process.md) - [Process](kernel-small-basic-process-process.md)
- [Thread](kernel-small-basic-process-thread.md) - [Task](kernel-small-basic-process-thread.md)
- [Scheduler](kernel-small-basic-process-scheduler.md) - [Scheduler](kernel-small-basic-process-scheduler.md)
- [Memory Management](kernel-small-basic-memory.md) - [Memory Management](kernel-small-basic-memory.md)
- [Heap Memory Management](kernel-small-basic-memory-heap.md) - [Heap Memory Management](kernel-small-basic-memory-heap.md)
......
...@@ -156,7 +156,8 @@ Example: ...@@ -156,7 +156,8 @@ Example:
struct MyType { // Add a comment here, and leave a space between the comment sign (//) and the comment. struct MyType { // Add a comment here, and leave a space between the comment sign (//) and the comment.
... ...
}; // The right brace is followed by a semicolon (;). }; // The right brace is followed by a semicolon (;).
int Foo(int a) {// The left brace of the function is placed at the beginning of a line and occupies one line. int Foo(int a)
{ // The left brace of the function is placed at the beginning of a line and occupies one line.
if (a > 0) { if (a > 0) {
Foo(); // There is only one statement in a line. Foo(); // There is only one statement in a line.
Bar(); Bar();
......
...@@ -56,7 +56,7 @@ typedef struct { ...@@ -56,7 +56,7 @@ typedef struct {
This example implements the following: This example implements the following:
1. Creates a monitoring thread to obtain information about the memory pool. 1. Creates a monitoring task to obtain information about the memory pool.
2. Calls **LOS\_MemInfoGet** to obtain the basic information about the memory pool. 2. Calls **LOS\_MemInfoGet** to obtain the basic information about the memory pool.
......
...@@ -9,10 +9,9 @@ ...@@ -9,10 +9,9 @@
The OpenHarmony LiteOS-M kernel is a lightweight operating system \(OS\) kernel designed for the IoT field. It features small size, low power consumption, and high performance. The LiteOS-M kernel has simple code structure, including the minimum function set, kernel abstraction layer, optional components, and project directory. The OpenHarmony LiteOS-M kernel is a lightweight operating system \(OS\) kernel designed for the IoT field. It features small size, low power consumption, and high performance. The LiteOS-M kernel has simple code structure, including the minimum function set, kernel abstraction layer, optional components, and project directory.
The OpenHarmony LiteOS-M kernel architecture consists of the hardware-related layer and the hardware-irrelevant layer, as shown in [Figure 1](#fig17231457191415). The OpenHarmony LiteOS-M kernel architecture consists of the hardware layer and the hardware-irrelevant layers, as shown in [Figure Kernel architecture](#fig17231457191415).
- The **Kernel arch** module belongs to the hardware-related layer. This module provides unified hardware abstraction layer \(HAL\) interfaces based on the compilation toolchain and chip architecture, improving hardware adaptability and meeting the expansion requirements of diversified AIoT hardware and compilation toolchains. The hardware layer is classified based on the compilation toolchain and chip architecture, and provides a unified Hardware Abstraction Layer \(HAL\) interface to improve hardware adaptation and facilitate the expansion of various types of &IoT hardware and compilation toolchains. The basic kernel provides basic kernel capabilities. The extended modules provide capabilities of components, such as network and file systems, as well as exception handling and debug tools. The Kernel Abstraction Layer \(**KAL**\) provides unified standard APIs.
- **Components** and other modules belong to the hardware-irrelevant layer. Kernel modules, such as the task, provide basic capabilities. **Components** provide component capabilities, such as network and file system capabilities. **Utils** provides error handling and debugging capabilities. The Kernel Abstraction Layer \(**KAL**\) provides unified standard interfaces.
**Figure 1** Kernel architecture<a name="fig17231457191415"></a> **Figure 1** Kernel architecture<a name="fig17231457191415"></a>
![](figure/kernel-architecture.png "kernel-architecture") ![](figure/kernel-architecture.png "kernel-architecture")
......
# Thread<a name="EN-US_TOPIC_0000001078641280"></a> # Task<a name="EN-US_TOPIC_0000001078641280"></a>
- [Basic Concepts](#section138411646175417) - [Basic Concepts](#section138411646175417)
- [Working Principles](#section1381918945512) - [Working Principles](#section1381918945512)
...@@ -10,64 +10,64 @@ ...@@ -10,64 +10,64 @@
## Basic Concepts<a name="section138411646175417"></a> ## Basic Concepts<a name="section138411646175417"></a>
Threads are the minimum running units that compete for system resources. They can use or wait to use CPUs and use system resources such as memory. They run independently from one another. Tasks are the minimum running units that compete for system resources. They can use or wait to use CPUs and use system resources such as memory. They run independently from one another.
Threads in the processes of the same priority in the OpenHarmony kernel are scheduled and run in a unified manner. A task represents a thread in the OpenHarmony kernel, and tasks in the processes of the same priority are scheduled and run in a unified manner.
Threads in the OpenHarmony kernel use the preemptive scheduling mechanism, either round-robin \(RR\) scheduling or First In First Out \(FIFO\) scheduling. Tasks in the OpenHarmony kernel use the preemptive scheduling mechanism, either round-robin \(RR\) scheduling or First In First Out \(FIFO\) scheduling.
Threads in the OpenHarmony kernel are assigned 32 priorities, ranging from **0** \(highest\) to **31** \(lowest\). Tasks in the OpenHarmony kernel are assigned 32 priorities, ranging from **0** \(highest\) to **31** \(lowest\).
In the same process, a higher-priority process can preempt resources of a lower-priority process. The lower-priority process can be scheduled only after the higher-priority process is blocked or terminated. In the same process, a higher-priority process can preempt resources of a lower-priority process. The lower-priority process can be scheduled only after the higher-priority process is blocked or terminated.
**Thread States:** **Task States:**
- Init: The thread is being created. - Init: The task is being created.
- Ready: The thread is in the Ready queue and waits for being scheduled by the CPU. - Ready: The task is in the Ready queue and waits for being scheduled by the CPU.
- Running: The thread is running. - Running: The task is running.
- Blocked: The thread is blocked and suspended. The Blocked states include pending \(blocked due to lock, event, or semaphore issues\), suspended \(active pending\), delay \(blocked due to delays\), and pendtime \(blocked by waiting timeout of locks, events, or semaphores\). - Blocked: The task is blocked and suspended. The Blocked states include pending \(blocked due to lock, event, or semaphore issues\), suspended \(active pending\), delay \(blocked due to delays\), and pendtime \(blocked by waiting timeout of locks, events, or semaphores\).
- Exit: The thread stops running and waits for the parent thread to reclaim its control block resources. - Exit: The task stops running and waits for the parent task to reclaim its control block resources.
**Figure 1** Thread state transition<a name="fig5251243193113"></a> **Figure 1** Task state transition<a name="fig5251243193113"></a>
![](figure/thread-state-transition.png "thread-state-transition") ![](figure/task-state-transition.png "task-state-transition")
**Thread State Transition:** **Task State Transition:**
- Init→Ready: - Init→Ready:
When a thread is created, the thread obtains the control block and enters the Init state \(initialization\). After the initialization is complete, the thread is inserted into the scheduling queue and enters the Ready state. When a task is created, the task obtains the control block and enters the Init state \(initialization\). After the initialization is complete, the task is inserted into the scheduling queue and enters the Ready state.
- Ready→Running: - Ready→Running:
When a thread switching is triggered, the thread with the highest priority in the Ready queue is executed and enters the Running state. Then, this thread is deleted from the Ready queue. When a task switching is triggered, the task with the highest priority in the Ready queue is executed and enters the Running state. Then, this task is deleted from the Ready queue.
- Running→Blocked: - Running→Blocked:
When a running thread is blocked \(for example, is pended, delayed, or reading semaphores\), its state changes from Running to Blocked. Then, a thread switching is triggered to run the thread with the highest priority in the Ready queue. When a running task is blocked \(for example, is pended, delayed, or reading semaphores\), its state changes from Running to Blocked. Then, a task switching is triggered to run the task with the highest priority in the Ready queue.
- Blocked→Ready: - Blocked→Ready:
After the blocked thread is restored \(the thread is restored, the delay times out, the semaphore reading times out, or the semaphore is read\), the thread is added to the Ready queue and changes from the Blocked state to the Ready state. After the blocked task is restored \(the task is restored, the delay times out, the semaphore reading times out, or the semaphore is read\), the task is added to the Ready queue and changes from the Blocked state to the Ready state.
- Ready→Blocked: - Ready→Blocked:
A thread may also be blocked \(suspended\) in the Ready state. The blocked thread will change from the Ready state to the Blocked state and is deleted from the Ready queue. The thread will not be scheduled until it is restored. A task may also be blocked \(suspended\) in the Ready state. The blocked task will change from the Ready state to the Blocked state and is deleted from the Ready queue. The task will not be scheduled until it is restored.
- Running→Ready: - Running→Ready:
After a thread with a higher priority is created or restored, threads will be scheduled. The thread with the highest priority in the Ready queue will change to the Running state. The originally running thread will change from the Running state to the Ready state and be added to the Ready queue. After a task with a higher priority is created or restored, tasks will be scheduled. The task with the highest priority in the Ready queue will change to the Running state. The originally running task will change from the Running state to the Ready state and be added to the Ready queue.
- Running→Exit: - Running→Exit:
When a running thread is terminated, its state changes from Running to Exit. If the thread is set with a detach attribute \(**LOS\_TASK\_STATUS\_DETACHED**\), it will be directly destroyed after the running is complete. When a running task is terminated, its state changes from Running to Exit. If the task is set with a detach attribute \(**LOS\_TASK\_STATUS\_DETACHED**\), it will be directly destroyed after the running is complete.
## Working Principles<a name="section1381918945512"></a> ## Working Principles<a name="section1381918945512"></a>
The OpenHarmony thread management module provides the following functions: creating, delaying, suspending, and restoring threads, locking and unlocking thread scheduling, and querying thread control block information by ID. The OpenHarmony task management module provides the following functions: creating, delaying, suspending, and restoring tasks, locking and unlocking task scheduling, and querying task control block information by ID.
When a thread is created, the system initializes the thread stack and presets the context. The system places the thread entry function in the corresponding position so that the function will be executed when the thread enters the Running state for the first time. When a task is created, the system initializes the task stack and presets the context. The system places the task entry function in the corresponding position so that the function will be executed when the task enters the Running state for the first time.
## Development Guidelines<a name="section10649727135519"></a> ## Development Guidelines<a name="section10649727135519"></a>
...@@ -82,115 +82,115 @@ When a thread is created, the system initializes the thread stack and presets th ...@@ -82,115 +82,115 @@ When a thread is created, the system initializes the thread stack and presets th
</th> </th>
</tr> </tr>
</thead> </thead>
<tbody><tr id="row713032973813"><td class="cellrowborder" rowspan="3" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.1 "><p id="p0130429133818"><a name="p0130429133818"></a><a name="p0130429133818"></a>Thread creation and deletion</p> <tbody><tr id="row713032973813"><td class="cellrowborder" rowspan="3" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.1 "><p id="p0130429133818"><a name="p0130429133818"></a><a name="p0130429133818"></a>Task creation and deletion</p>
</td> </td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.2 "><p id="p6130102911384"><a name="p6130102911384"></a><a name="p6130102911384"></a>LOS_TaskCreateOnly</p> <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.2 "><p id="p6130102911384"><a name="p6130102911384"></a><a name="p6130102911384"></a>LOS_TaskCreateOnly</p>
</td> </td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.3 "><p id="p181303297387"><a name="p181303297387"></a><a name="p181303297387"></a>Creates a thread and places the thread in the Init state but not be scheduled.</p> <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.3 "><p id="p181303297387"><a name="p181303297387"></a><a name="p181303297387"></a>Creates a task and places the task in the Init state but not be scheduled.</p>
</td> </td>
</tr> </tr>
<tr id="row51301329123813"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p41301293386"><a name="p41301293386"></a><a name="p41301293386"></a>LOS_TaskCreate</p> <tr id="row51301329123813"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p41301293386"><a name="p41301293386"></a><a name="p41301293386"></a>LOS_TaskCreate</p>
</td> </td>
<td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p513092983812"><a name="p513092983812"></a><a name="p513092983812"></a>Creates a thread and places the thread in the Init state and be scheduled.</p> <td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p513092983812"><a name="p513092983812"></a><a name="p513092983812"></a>Creates a task and places the task in the Init state and be scheduled.</p>
</td> </td>
</tr> </tr>
<tr id="row14130729193816"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p7130152993810"><a name="p7130152993810"></a><a name="p7130152993810"></a>LOS_TaskDelete</p> <tr id="row14130729193816"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p7130152993810"><a name="p7130152993810"></a><a name="p7130152993810"></a>LOS_TaskDelete</p>
</td> </td>
<td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p11130122910387"><a name="p11130122910387"></a><a name="p11130122910387"></a>Deletes the specified thread.</p> <td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p11130122910387"><a name="p11130122910387"></a><a name="p11130122910387"></a>Deletes the specified task.</p>
</td> </td>
</tr> </tr>
<tr id="row1513118292383"><td class="cellrowborder" rowspan="4" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.1 "><p id="p1813114299384"><a name="p1813114299384"></a><a name="p1813114299384"></a>Thread status control</p> <tr id="row1513118292383"><td class="cellrowborder" rowspan="4" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.1 "><p id="p1813114299384"><a name="p1813114299384"></a><a name="p1813114299384"></a>Task status control</p>
</td> </td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.2 "><p id="p1713113291382"><a name="p1713113291382"></a><a name="p1713113291382"></a>LOS_TaskResume</p> <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.2 "><p id="p1713113291382"><a name="p1713113291382"></a><a name="p1713113291382"></a>LOS_TaskResume</p>
</td> </td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.3 "><p id="p16131229173819"><a name="p16131229173819"></a><a name="p16131229173819"></a>Resumes a suspended thread.</p> <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.3 "><p id="p16131229173819"><a name="p16131229173819"></a><a name="p16131229173819"></a>Resumes a suspended task.</p>
</td> </td>
</tr> </tr>
<tr id="row9131729173817"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p131311929123810"><a name="p131311929123810"></a><a name="p131311929123810"></a>LOS_TaskSuspend</p> <tr id="row9131729173817"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p131311929123810"><a name="p131311929123810"></a><a name="p131311929123810"></a>LOS_TaskSuspend</p>
</td> </td>
<td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p1813192919384"><a name="p1813192919384"></a><a name="p1813192919384"></a>Suspends the specified thread.</p> <td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p1813192919384"><a name="p1813192919384"></a><a name="p1813192919384"></a>Suspends the specified task.</p>
</td> </td>
</tr> </tr>
<tr id="row151311929193818"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p213114299387"><a name="p213114299387"></a><a name="p213114299387"></a>LOS_TaskDelay</p> <tr id="row151311929193818"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p213114299387"><a name="p213114299387"></a><a name="p213114299387"></a>LOS_TaskDelay</p>
</td> </td>
<td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p141311729183817"><a name="p141311729183817"></a><a name="p141311729183817"></a>Delays a thread.</p> <td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p141311729183817"><a name="p141311729183817"></a><a name="p141311729183817"></a>Delays a task.</p>
</td> </td>
</tr> </tr>
<tr id="row18131182910384"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p15131122923810"><a name="p15131122923810"></a><a name="p15131122923810"></a>LOS_TaskYield</p> <tr id="row18131182910384"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p15131122923810"><a name="p15131122923810"></a><a name="p15131122923810"></a>LOS_TaskYield</p>
</td> </td>
<td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p1713122953816"><a name="p1713122953816"></a><a name="p1713122953816"></a>Adjusts the scheduling sequence of threads that call the thread priority.</p> <td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p1713122953816"><a name="p1713122953816"></a><a name="p1713122953816"></a>Adjusts the scheduling sequence of tasks that call the task priority.</p>
</td> </td>
</tr> </tr>
<tr id="row9131829123812"><td class="cellrowborder" rowspan="2" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.1 "><p id="p1313115299387"><a name="p1313115299387"></a><a name="p1313115299387"></a>Thread scheduling control</p> <tr id="row9131829123812"><td class="cellrowborder" rowspan="2" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.1 "><p id="p1313115299387"><a name="p1313115299387"></a><a name="p1313115299387"></a>Task scheduling control</p>
</td> </td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.2 "><p id="p101312029113815"><a name="p101312029113815"></a><a name="p101312029113815"></a>LOS_TaskLock</p> <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.2 "><p id="p101312029113815"><a name="p101312029113815"></a><a name="p101312029113815"></a>LOS_TaskLock</p>
</td> </td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.3 "><p id="p0131629183812"><a name="p0131629183812"></a><a name="p0131629183812"></a>Locks thread scheduling.</p> <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.3 "><p id="p0131629183812"><a name="p0131629183812"></a><a name="p0131629183812"></a>Locks task scheduling.</p>
</td> </td>
</tr> </tr>
<tr id="row5131829193813"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p1313182910388"><a name="p1313182910388"></a><a name="p1313182910388"></a>LOS_TaskUnlock</p> <tr id="row5131829193813"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p1313182910388"><a name="p1313182910388"></a><a name="p1313182910388"></a>LOS_TaskUnlock</p>
</td> </td>
<td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p1131122913812"><a name="p1131122913812"></a><a name="p1131122913812"></a>Unlocks thread scheduling.</p> <td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p1131122913812"><a name="p1131122913812"></a><a name="p1131122913812"></a>Unlocks task scheduling.</p>
</td> </td>
</tr> </tr>
<tr id="row213115292389"><td class="cellrowborder" rowspan="3" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.1 "><p id="p41312295381"><a name="p41312295381"></a><a name="p41312295381"></a>Thread priority control</p> <tr id="row213115292389"><td class="cellrowborder" rowspan="3" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.1 "><p id="p41312295381"><a name="p41312295381"></a><a name="p41312295381"></a>Task priority control</p>
</td> </td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.2 "><p id="p1131829103815"><a name="p1131829103815"></a><a name="p1131829103815"></a>LOS_CurTaskPriSet</p> <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.2 "><p id="p1131829103815"><a name="p1131829103815"></a><a name="p1131829103815"></a>LOS_CurTaskPriSet</p>
</td> </td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.3 "><p id="p6131729163810"><a name="p6131729163810"></a><a name="p6131729163810"></a>Sets the priority for the current thread.</p> <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.3 "><p id="p6131729163810"><a name="p6131729163810"></a><a name="p6131729163810"></a>Sets the priority for the current task.</p>
</td> </td>
</tr> </tr>
<tr id="row913142917389"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p10131172913819"><a name="p10131172913819"></a><a name="p10131172913819"></a>LOS_TaskPriSet</p> <tr id="row913142917389"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p10131172913819"><a name="p10131172913819"></a><a name="p10131172913819"></a>LOS_TaskPriSet</p>
</td> </td>
<td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p113162912387"><a name="p113162912387"></a><a name="p113162912387"></a>Sets the priority of the specified thread.</p> <td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p113162912387"><a name="p113162912387"></a><a name="p113162912387"></a>Sets the priority of the specified task.</p>
</td> </td>
</tr> </tr>
<tr id="row7131192913812"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p713142923817"><a name="p713142923817"></a><a name="p713142923817"></a>LOS_TaskPriGet</p> <tr id="row7131192913812"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p713142923817"><a name="p713142923817"></a><a name="p713142923817"></a>LOS_TaskPriGet</p>
</td> </td>
<td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p14131162923818"><a name="p14131162923818"></a><a name="p14131162923818"></a>Obtains the priority of the specified thread.</p> <td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p14131162923818"><a name="p14131162923818"></a><a name="p14131162923818"></a>Obtains the priority of the specified task.</p>
</td> </td>
</tr> </tr>
<tr id="row14132329133817"><td class="cellrowborder" rowspan="2" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.1 "><p id="p81323295380"><a name="p81323295380"></a><a name="p81323295380"></a>Obtaining thread information</p> <tr id="row14132329133817"><td class="cellrowborder" rowspan="2" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.1 "><p id="p81323295380"><a name="p81323295380"></a><a name="p81323295380"></a>Obtaining task information</p>
</td> </td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.2 "><p id="p31324294389"><a name="p31324294389"></a><a name="p31324294389"></a>LOS_CurTaskIDGet</p> <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.2 "><p id="p31324294389"><a name="p31324294389"></a><a name="p31324294389"></a>LOS_CurTaskIDGet</p>
</td> </td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.3 "><p id="p14132929193814"><a name="p14132929193814"></a><a name="p14132929193814"></a>Obtains the ID of the current thread.</p> <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.3 "><p id="p14132929193814"><a name="p14132929193814"></a><a name="p14132929193814"></a>Obtains the ID of the current task.</p>
</td> </td>
</tr> </tr>
<tr id="row4132182920383"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p15133172923815"><a name="p15133172923815"></a><a name="p15133172923815"></a>LOS_TaskInfoGet</p> <tr id="row4132182920383"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p15133172923815"><a name="p15133172923815"></a><a name="p15133172923815"></a>LOS_TaskInfoGet</p>
</td> </td>
<td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p5133329123814"><a name="p5133329123814"></a><a name="p5133329123814"></a>Obtains information about the specific thread.</p> <td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p5133329123814"><a name="p5133329123814"></a><a name="p5133329123814"></a>Obtains information about the specific task.</p>
</td> </td>
</tr> </tr>
<tr id="row855810357401"><td class="cellrowborder" rowspan="2" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.1 "><p id="p9682331164117"><a name="p9682331164117"></a><a name="p9682331164117"></a>Binding threads to CPU cores</p> <tr id="row855810357401"><td class="cellrowborder" rowspan="2" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.1 "><p id="p9682331164117"><a name="p9682331164117"></a><a name="p9682331164117"></a>Binding tasks to CPU cores</p>
</td> </td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.2 "><p id="p205581835144010"><a name="p205581835144010"></a><a name="p205581835144010"></a>LOS_TaskCpuAffiSet</p> <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.2 "><p id="p205581835144010"><a name="p205581835144010"></a><a name="p205581835144010"></a>LOS_TaskCpuAffiSet</p>
</td> </td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.3 "><p id="p115582035154014"><a name="p115582035154014"></a><a name="p115582035154014"></a>Binds a specified thread to a specified CPU. It is used only in multi-core scenarios.</p> <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.3 "><p id="p115582035154014"><a name="p115582035154014"></a><a name="p115582035154014"></a>Binds a specified task to a specified CPU. It is used only in multi-core scenarios.</p>
</td> </td>
</tr> </tr>
<tr id="row5866193714018"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p8867133744011"><a name="p8867133744011"></a><a name="p8867133744011"></a>LOS_TaskCpuAffiGet</p> <tr id="row5866193714018"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p8867133744011"><a name="p8867133744011"></a><a name="p8867133744011"></a>LOS_TaskCpuAffiGet</p>
</td> </td>
<td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p10867173718404"><a name="p10867173718404"></a><a name="p10867173718404"></a>Obtains the core binding information of a specified thread. It is used only in multi-core scenarios.</p> <td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p10867173718404"><a name="p10867173718404"></a><a name="p10867173718404"></a>Obtains the core binding information of a specified task. It is used only in multi-core scenarios.</p>
</td> </td>
</tr> </tr>
<tr id="row197312218434"><td class="cellrowborder" rowspan="2" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.1 "><p id="p20362114474318"><a name="p20362114474318"></a><a name="p20362114474318"></a>Thread scheduling parameter control</p> <tr id="row197312218434"><td class="cellrowborder" rowspan="2" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.1 "><p id="p20362114474318"><a name="p20362114474318"></a><a name="p20362114474318"></a>Task scheduling parameter control</p>
</td> </td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.2 "><p id="p5974192215434"><a name="p5974192215434"></a><a name="p5974192215434"></a>LOS_GetTaskScheduler</p> <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.2 "><p id="p5974192215434"><a name="p5974192215434"></a><a name="p5974192215434"></a>LOS_GetTaskScheduler</p>
</td> </td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.3 "><p id="p2974922164317"><a name="p2974922164317"></a><a name="p2974922164317"></a>Obtains the scheduling policy of the specified thread.</p> <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.3 "><p id="p2974922164317"><a name="p2974922164317"></a><a name="p2974922164317"></a>Obtains the scheduling policy of the specified task.</p>
</td> </td>
</tr> </tr>
<tr id="row141414214436"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p9141202144319"><a name="p9141202144319"></a><a name="p9141202144319"></a>LOS_SetTaskScheduler</p> <tr id="row141414214436"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p9141202144319"><a name="p9141202144319"></a><a name="p9141202144319"></a>LOS_SetTaskScheduler</p>
</td> </td>
<td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p3141221154319"><a name="p3141221154319"></a><a name="p3141221154319"></a>Sets the scheduling parameters, including the priority and scheduling policy, for the specified thread.</p> <td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p3141221154319"><a name="p3141221154319"></a><a name="p3141221154319"></a>Sets the scheduling parameters, including the priority and scheduling policy, for the specified task.</p>
</td> </td>
</tr> </tr>
<tr id="row617914918441"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.1 "><p id="p17180184911445"><a name="p17180184911445"></a><a name="p17180184911445"></a>Maximum number of threads supported</p> <tr id="row617914918441"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.1 "><p id="p17180184911445"><a name="p17180184911445"></a><a name="p17180184911445"></a>Maximum number of tasks supported</p>
</td> </td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.2 "><p id="p151807498449"><a name="p151807498449"></a><a name="p151807498449"></a>LOS_GetSystemTaskMaximum</p> <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.2 "><p id="p151807498449"><a name="p151807498449"></a><a name="p151807498449"></a>LOS_GetSystemTaskMaximum</p>
</td> </td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.3 "><p id="p81801249124417"><a name="p81801249124417"></a><a name="p81801249124417"></a>Obtains the maximum number of threads supported by the system.</p> <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.3 "><p id="p81801249124417"><a name="p81801249124417"></a><a name="p81801249124417"></a>Obtains the maximum number of tasks supported by the system.</p>
</td> </td>
</tr> </tr>
</tbody> </tbody>
...@@ -198,23 +198,23 @@ When a thread is created, the system initializes the thread stack and presets th ...@@ -198,23 +198,23 @@ When a thread is created, the system initializes the thread stack and presets th
### How to Develop<a name="section16229657115514"></a> ### How to Develop<a name="section16229657115514"></a>
The typical thread development process is as follows: The typical task development process is as follows:
1. Call **LOS\_TaskCreate** to create a thread. 1. Call **LOS\_TaskCreate** to create a task.
- Specify the execution entry function for the thread. - Specify the execution entry function for the task.
- Specify the thread name. - Specify the task name.
- Specify the thread stack size. - Specify the task stack size.
- Specify the priority of the thread. - Specify the priority of the task.
- Specify the thread attribute, that is, whether to support the **LOS\_TASK\_STATUS\_DETACHED** attribute. - Specify the task attribute, that is, whether to support the **LOS\_TASK\_STATUS\_DETACHED** attribute.
- Specify the thread-core binding attribute for multi-core environment. - Specify the task-core binding attribute for multi-core environment.
2. Run the service code to implement thread scheduling. 2. Run the service code to implement task scheduling.
3. After the thread execution is complete, the thread resources are automatically reclaimed if the **LOS\_TASK\_STATUS\_DETACHED** attribute is set. If the **LOS\_TASK\_STATUS\_DETACHED** attribute is not set, call the **LOS\_TaskDelete** API to reclaim the thread resources. 3. After the task execution is complete, the task resources are automatically reclaimed if the **LOS\_TASK\_STATUS\_DETACHED** attribute is set. If the **LOS\_TASK\_STATUS\_DETACHED** attribute is not set, call the **LOS\_TaskDelete** API to reclaim the task resources.
>![](../public_sys-resources/icon-note.gif) **NOTE:** >![](../public_sys-resources/icon-note.gif) **NOTE:**
>- The kernel space has the highest permission and can operate threads in any process. >- The kernel space has the highest permission and can operate tasks in any process.
>- The thread created by calling a user-space process in the kernel space is a KProcess, not a user-space process. >- The task created by calling a user-space process in the kernel space is a KProcess, not a user-space process.
### Development Example<a name="section2809723165612"></a> ### Development Example<a name="section2809723165612"></a>
...@@ -229,7 +229,7 @@ UINT32 ExampleTaskHi(VOID) ...@@ -229,7 +229,7 @@ UINT32 ExampleTaskHi(VOID)
{ {
UINT32 ret; UINT32 ret;
PRINTK("Enter TaskHi Handler.\n"); PRINTK("Enter TaskHi Handler.\n");
/* Delay the thread for 2 ticks. The task is then suspended, and the remaining task with the highest priority (g_taskLoID) will be executed.*/ /* Delay the task for 2 ticks. The task is then suspended, and the remaining task with the highest priority (g_taskLoID) will be executed.*/
ret = LOS_TaskDelay(2); ret = LOS_TaskDelay(2);
if (ret != LOS_OK) { if (ret != LOS_OK) {
PRINTK("Delay Task Failed.\n"); PRINTK("Delay Task Failed.\n");
...@@ -252,7 +252,7 @@ UINT32 ExampleTaskLo(VOID) ...@@ -252,7 +252,7 @@ UINT32 ExampleTaskLo(VOID)
{ {
UINT32 ret; UINT32 ret;
PRINTK("Enter TaskLo Handler.\n"); PRINTK("Enter TaskLo Handler.\n");
/* Delay the thread for 2 ticks. The task is then suspended, and the remaining task with the highest priority (background task) will be executed.*/ /* Delay the task for 2 ticks. The task is then suspended, and the remaining task with the highest priority (background task) will be executed.*/
ret = LOS_TaskDelay(2); ret = LOS_TaskDelay(2);
if (ret != LOS_OK) { if (ret != LOS_OK) {
PRINTK("Delay TaskLo Failed.\n"); PRINTK("Delay TaskLo Failed.\n");
......
...@@ -54,7 +54,7 @@ typedef struct { ...@@ -54,7 +54,7 @@ typedef struct {
This example implements the following: This example implements the following:
1. Creates a monitoring thread to obtain information about the memory pool. 1. Creates a monitoring task to obtain information about the memory pool.
2. Calls **LOS\_MemInfoGet** to obtain the basic information about the memory pool. 2. Calls **LOS\_MemInfoGet** to obtain the basic information about the memory pool.
3. Calculates the memory usage and fragmentation rate. 3. Calculates the memory usage and fragmentation rate.
......
...@@ -44,7 +44,7 @@ The lightweight kernel consists of the basic kernel, extension components, HDF, ...@@ -44,7 +44,7 @@ The lightweight kernel consists of the basic kernel, extension components, HDF,
The basic kernel implements the following mechanisms: The basic kernel implements the following mechanisms:
- Process management: supports processes and threads and task-based process implementation. Processes have independent 4 GB address space. - Process management: supports processes and threads and task-based process implementation. Processes have independent 4 GiB address space.
- Multi-core scheduling: supports task and affinity-based interrupt-core binding settings. - Multi-core scheduling: supports task and affinity-based interrupt-core binding settings.
- Real-time scheduling: Tasks are scheduled based on priorities. The tasks of the same priority are scheduled by using the time slice round-robin. - Real-time scheduling: Tasks are scheduled based on priorities. The tasks of the same priority are scheduled by using the time slice round-robin.
- Virtual memory: supports page fault. The kernel space is statically mapped to 0-1 GiB addresses, and the user space is mapped to 1-4 GiB addresses. - Virtual memory: supports page fault. The kernel space is statically mapped to 0-1 GiB addresses, and the user space is mapped to 1-4 GiB addresses.
......
...@@ -86,7 +86,7 @@ The kernel startup process consists of the assembly startup and C language start ...@@ -86,7 +86,7 @@ The kernel startup process consists of the assembly startup and C language start
<tr id="row357517134414"><td class="cellrowborder" valign="top" width="35.58%" headers="mcps1.2.3.1.1 "><p id="p12575676449"><a name="p12575676449"></a><a name="p12575676449"></a>LOS_INIT_LEVEL_KMOD_TASK</p> <tr id="row357517134414"><td class="cellrowborder" valign="top" width="35.58%" headers="mcps1.2.3.1.1 "><p id="p12575676449"><a name="p12575676449"></a><a name="p12575676449"></a>LOS_INIT_LEVEL_KMOD_TASK</p>
</td> </td>
<td class="cellrowborder" valign="top" width="64.42%" headers="mcps1.2.3.1.2 "><p id="p7128122619143"><a name="p7128122619143"></a><a name="p7128122619143"></a>Kernel task creation</p> <td class="cellrowborder" valign="top" width="64.42%" headers="mcps1.2.3.1.2 "><p id="p7128122619143"><a name="p7128122619143"></a><a name="p7128122619143"></a>Kernel task creation</p>
<p id="p1657587184419"><a name="p1657587184419"></a><a name="p1657587184419"></a>Create kernel tasks (kernel thread and software timer tasks).</p> <p id="p1657587184419"><a name="p1657587184419"></a><a name="p1657587184419"></a>Create kernel tasks (kernel tasks and software timer tasks).</p>
<p id="p55485297219"><a name="p55485297219"></a><a name="p55485297219"></a>Example: creation of the resident resource reclaiming task, SystemInit task, and CPU usage statistics task.</p> <p id="p55485297219"><a name="p55485297219"></a><a name="p55485297219"></a>Example: creation of the resident resource reclaiming task, SystemInit task, and CPU usage statistics task.</p>
</td> </td>
</tr> </tr>
......
...@@ -67,7 +67,7 @@ ...@@ -67,7 +67,7 @@
- [中断及异常处理](kernel-small-basic-interrupt.md) - [中断及异常处理](kernel-small-basic-interrupt.md)
- [进程管理](kernel-small-basic-process.md) - [进程管理](kernel-small-basic-process.md)
- [进程](kernel-small-basic-process-process.md) - [进程](kernel-small-basic-process-process.md)
- [线程](kernel-small-basic-process-thread.md) - [任务](kernel-small-basic-process-thread.md)
- [调度器](kernel-small-basic-process-scheduler.md) - [调度器](kernel-small-basic-process-scheduler.md)
- [内存管理](kernel-small-basic-memory.md) - [内存管理](kernel-small-basic-memory.md)
- [堆内存管理](kernel-small-basic-memory-heap.md) - [堆内存管理](kernel-small-basic-memory-heap.md)
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
- **[CPU占用率](kernel-mini-extend-cpup.md)** - **[CPU占用率](kernel-mini-extend-cpup.md)**
- **[](kernel-mini-extend-dynamic-loading.md)** - **[动态加载](kernel-mini-extend-dynamic-loading.md)**
- **[文件系统](kernel-mini-extend-file.md)** - **[文件系统](kernel-mini-extend-file.md)**
......
...@@ -50,7 +50,7 @@ typedef struct { ...@@ -50,7 +50,7 @@ typedef struct {
本实例实现如下功能: 本实例实现如下功能:
1.创建一个监控线程,用于获取内存池的信息; 1.创建一个监控任务,用于获取内存池的信息;
2.调用LOS\_MemInfoGet接口,获取内存池的基础信息; 2.调用LOS\_MemInfoGet接口,获取内存池的基础信息;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
## 内核简介<a name="section1429342661510"></a> ## 内核简介<a name="section1429342661510"></a>
OpenHarmony LiteOS-M内核是面向IoT领域构建的轻量级物联网操作系统内核,具有小体积、低功耗、高性能的特点。其代码结构简单,主要包括内核最小功能集、内核抽象层、可选组件以及工程目录等。OpenHarmony LiteOS-M内核架构包含硬件相关层以及硬件无关层,如下图所示,其中Kernel Arch模块属于硬件相关层,该模块按不同编译工具链、芯片架构分类,提供统一的HAL(Hardware Abstraction Layer)接口,提升了硬件易适配性,满足AIoT类型丰富的硬件和编译工具链的拓展;Components等其他模块属于硬件无关层,其中Kernel Task等内核模块提供基础能力,Components模块提供网络、文件系统等组件能力,Utils模块提供错误处理、调测等能力,KAL(Kernel Abstraction Layer)模块提供统一的标准接口。 OpenHarmony LiteOS-M内核是面向IoT领域构建的轻量级物联网操作系统内核,具有小体积、低功耗、高性能的特点。其代码结构简单,主要包括内核最小功能集、内核抽象层、可选组件以及工程目录等。OpenHarmony LiteOS-M内核架构包含硬件相关层以及硬件无关层,如下图所示,其中硬件相关层按不同编译工具链、芯片架构分类,提供统一的HAL(Hardware Abstraction Layer)接口,提升了硬件易适配性,满足AIoT类型丰富的硬件和编译工具链的拓展;其他模块属于硬件无关层,其中基础内核模块提供基础能力,扩展模块提供网络、文件系统等组件能力,还提供错误处理、调测等能力;KAL(Kernel Abstraction Layer)模块提供统一的标准接口。
**图 1** 内核架构图<a name="fig17231457191415"></a> **图 1** 内核架构图<a name="fig17231457191415"></a>
![](figure/内核架构图.png "内核架构图") ![](figure/内核架构图.png "内核架构图")
......
# 线程<a name="ZH-CN_TOPIC_0000001078641280"></a> # 任务<a name="ZH-CN_TOPIC_0000001078641280"></a>
- [基本概念](#section138411646175417) - [基本概念](#section138411646175417)
- [运行机制](#section1381918945512) - [运行机制](#section1381918945512)
...@@ -10,64 +10,66 @@ ...@@ -10,64 +10,66 @@
## 基本概念<a name="section138411646175417"></a> ## 基本概念<a name="section138411646175417"></a>
从系统的角度看,线程是竞争系统资源的最小运行单元。线程可以使用或等待CPU、使用内存空间等系统资源,并独立于其它线程运行。 从系统的角度看,任务Task是竞争系统资源的最小运行单元。任务可以使用或等待CPU、使用内存空间等系统资源,并独立于其它任务运行。
OpenHarmony 内核中同优先级进程内的线程统一调度、运行 OpenHarmony 内核中使用一个任务表示一个线程
OpenHarmony 内核中的线程采用抢占式调度机制,同时支持时间片轮转调度和FIFO调度方式 OpenHarmony 内核中同优先级进程内的任务统一调度、运行
OpenHarmony 内核的线程一共有32个优先级\(0-31\),最高优先级为0,最低优先级为31 OpenHarmony 内核中的任务采用抢占式调度机制,同时支持时间片轮转调度和FIFO调度方式
当前进程内, 高优先级的线程可抢占低优先级线程,低优先级线程必须在高优先级线程阻塞或结束后才能得到调度 OpenHarmony 内核的任务一共有32个优先级\(0-31\),最高优先级为0,最低优先级为31
**线程状态说明** 当前进程内, 高优先级的任务可抢占低优先级任务,低优先级任务必须在高优先级任务阻塞或结束后才能得到调度。
- 初始化(Init):线程正在被创建。 **任务状态说明**
- 就绪(Ready):线程在就绪列表中,等待CPU调度。 - 初始化(Init):任务正在被创建。
- 运行(Running):线程正在运行。
- 阻塞(Blocked):线程被阻塞挂起。Blocked状态包括:pending\(因为锁、事件、信号量等阻塞\)、suspended(主动pend)、delay\(延时阻塞\)、pendtime\(因为锁、事件、信号量时间等超时等待\)
- 退出(Exit):线程运行结束,等待父线程回收其控制块资源。
**图 1** 线程状态迁移示意图<a name="fig5251243193113"></a> - 就绪(Ready):任务在就绪列表中,等待CPU调度。
![](figure/线程状态迁移示意图.png "线程状态迁移示意图") - 运行(Running):任务正在运行。
- 阻塞(Blocked):任务被阻塞挂起。Blocked状态包括:pending\(因为锁、事件、信号量等阻塞\)、suspended(主动pend)、delay\(延时阻塞\)、pendtime\(因为锁、事件、信号量时间等超时等待\)
- 退出(Exit):任务运行结束,等待父任务回收其控制块资源。
**线程状态迁移说明:** **图 1** 任务状态迁移示意图<a name="fig5251243193113"></a>
![](figure/任务状态迁移示意图.png "任务状态迁移示意图")
**任务状态迁移说明:**
- Init→Ready: - Init→Ready:
线程创建拿到控制块后为初始化阶段\(Init状态\),当线程初始化完成将线程插入调度队列,此时线程进入就绪状态。 任务创建拿到控制块后为初始化阶段\(Init状态\),当任务初始化完成将任务插入调度队列,此时任务进入就绪状态。
- Ready→Running: - Ready→Running:
线程创建后进入就绪态,发生线程切换时,就绪列表中最高优先级的线程被执行,从而进入运行态,此刻该线程从就绪列表中删除。 任务创建后进入就绪态,发生任务切换时,就绪列表中最高优先级的任务被执行,从而进入运行态,此刻该任务从就绪列表中删除。
- Running→Blocked: - Running→Blocked:
正在运行的线程发生阻塞(挂起、延时、读信号量等)时,线程状态由运行态变成阻塞态,然后发生线程切换,运行就绪列表中剩余最高优先级线程 正在运行的任务发生阻塞(挂起、延时、读信号量等)时,任务状态由运行态变成阻塞态,然后发生任务切换,运行就绪列表中剩余最高优先级任务
- Blocked→Ready : - Blocked→Ready :
阻塞的线程被恢复后(线程恢复、延时时间超时、读信号量超时或读到信号量等),此时被恢复的线程会被加入就绪列表,从而由阻塞态变成就绪态。 阻塞的任务被恢复后(任务恢复、延时时间超时、读信号量超时或读到信号量等),此时被恢复的任务会被加入就绪列表,从而由阻塞态变成就绪态。
- Ready→Blocked: - Ready→Blocked:
线程也有可能在就绪态时被阻塞(挂起),此时线程状态会由就绪态转变为阻塞态,该线程从就绪列表中删除,不会参与线程调度,直到该线程被恢复。 任务也有可能在就绪态时被阻塞(挂起),此时任务状态会由就绪态转变为阻塞态,该任务从就绪列表中删除,不会参与任务调度,直到该任务被恢复。
- Running→Ready: - Running→Ready:
有更高优先级线程创建或者恢复后,会发生线程调度,此刻就绪列表中最高优先级线程变为运行态,那么原先运行的线程由运行态变为就绪态,并加入就绪列表中。 有更高优先级任务创建或者恢复后,会发生任务调度,此刻就绪列表中最高优先级任务变为运行态,那么原先运行的任务由运行态变为就绪态,并加入就绪列表中。
- Running→Exit: - Running→Exit:
运行中的线程运行结束,线程状态由运行态变为退出态。若为设置了分离属性(LOS\_TASK\_STATUS\_DETACHED)的线程,运行结束后将直接销毁。 运行中的任务运行结束,任务状态由运行态变为退出态。若为设置了分离属性(LOS\_TASK\_STATUS\_DETACHED)的任务,运行结束后将直接销毁。
## 运行机制<a name="section1381918945512"></a> ## 运行机制<a name="section1381918945512"></a>
OpenHarmony 线程管理模块提供线程创建、线程延时、线程挂起和线程恢复、锁线程调度和解锁线程调度、根据ID查询线程控制块信息功能。 OpenHarmony 任务管理模块提供任务创建、任务延时、任务挂起和任务恢复、锁任务调度和解锁任务调度、根据ID查询任务控制块信息功能。
用户创建线程时,系统会将线程栈进行初始化,预置上下文。此外,系统还会将“线程入口函数”地址放在相应位置。这样在线程第一次启动进入运行态时,将会执行线程入口函数。 用户创建任务时,系统会将任务栈进行初始化,预置上下文。此外,系统还会将“任务入口函数”地址放在相应位置。这样在任务第一次启动进入运行态时,将会执行任务入口函数。
## 开发指导<a name="section10649727135519"></a> ## 开发指导<a name="section10649727135519"></a>
...@@ -82,115 +84,115 @@ OpenHarmony 线程管理模块提供线程创建、线程延时、线程挂起 ...@@ -82,115 +84,115 @@ OpenHarmony 线程管理模块提供线程创建、线程延时、线程挂起
</th> </th>
</tr> </tr>
</thead> </thead>
<tbody><tr id="row713032973813"><td class="cellrowborder" rowspan="3" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.1 "><p id="p0130429133818"><a name="p0130429133818"></a><a name="p0130429133818"></a>线程的创建和删除</p> <tbody><tr id="row713032973813"><td class="cellrowborder" rowspan="3" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.1 "><p id="p0130429133818"><a name="p0130429133818"></a><a name="p0130429133818"></a>任务的创建和删除</p>
</td> </td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.2 "><p id="p6130102911384"><a name="p6130102911384"></a><a name="p6130102911384"></a>LOS_TaskCreateOnly</p> <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.2 "><p id="p6130102911384"><a name="p6130102911384"></a><a name="p6130102911384"></a>LOS_TaskCreateOnly</p>
</td> </td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.3 "><p id="p181303297387"><a name="p181303297387"></a><a name="p181303297387"></a>创建线程,并使该线程进入Init状态,不执行线程调度</p> <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.3 "><p id="p181303297387"><a name="p181303297387"></a><a name="p181303297387"></a>创建任务,并使该任务进入Init状态,不执行任务调度</p>
</td> </td>
</tr> </tr>
<tr id="row51301329123813"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p41301293386"><a name="p41301293386"></a><a name="p41301293386"></a>LOS_TaskCreate</p> <tr id="row51301329123813"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p41301293386"><a name="p41301293386"></a><a name="p41301293386"></a>LOS_TaskCreate</p>
</td> </td>
<td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p513092983812"><a name="p513092983812"></a><a name="p513092983812"></a>创建线程,并使该线程进入Ready状态,并调度</p> <td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p513092983812"><a name="p513092983812"></a><a name="p513092983812"></a>创建任务,并使该任务进入Ready状态,并调度</p>
</td> </td>
</tr> </tr>
<tr id="row14130729193816"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p7130152993810"><a name="p7130152993810"></a><a name="p7130152993810"></a>LOS_TaskDelete</p> <tr id="row14130729193816"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p7130152993810"><a name="p7130152993810"></a><a name="p7130152993810"></a>LOS_TaskDelete</p>
</td> </td>
<td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p11130122910387"><a name="p11130122910387"></a><a name="p11130122910387"></a>删除指定的线程</p> <td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p11130122910387"><a name="p11130122910387"></a><a name="p11130122910387"></a>删除指定的任务</p>
</td> </td>
</tr> </tr>
<tr id="row1513118292383"><td class="cellrowborder" rowspan="4" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.1 "><p id="p1813114299384"><a name="p1813114299384"></a><a name="p1813114299384"></a>线程状态控制</p> <tr id="row1513118292383"><td class="cellrowborder" rowspan="4" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.1 "><p id="p1813114299384"><a name="p1813114299384"></a><a name="p1813114299384"></a>任务状态控制</p>
</td> </td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.2 "><p id="p1713113291382"><a name="p1713113291382"></a><a name="p1713113291382"></a>LOS_TaskResume</p> <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.2 "><p id="p1713113291382"><a name="p1713113291382"></a><a name="p1713113291382"></a>LOS_TaskResume</p>
</td> </td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.3 "><p id="p16131229173819"><a name="p16131229173819"></a><a name="p16131229173819"></a>恢复挂起的线程</p> <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.3 "><p id="p16131229173819"><a name="p16131229173819"></a><a name="p16131229173819"></a>恢复挂起的任务</p>
</td> </td>
</tr> </tr>
<tr id="row9131729173817"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p131311929123810"><a name="p131311929123810"></a><a name="p131311929123810"></a>LOS_TaskSuspend</p> <tr id="row9131729173817"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p131311929123810"><a name="p131311929123810"></a><a name="p131311929123810"></a>LOS_TaskSuspend</p>
</td> </td>
<td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p1813192919384"><a name="p1813192919384"></a><a name="p1813192919384"></a>挂起指定的线程</p> <td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p1813192919384"><a name="p1813192919384"></a><a name="p1813192919384"></a>挂起指定的任务</p>
</td> </td>
</tr> </tr>
<tr id="row151311929193818"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p213114299387"><a name="p213114299387"></a><a name="p213114299387"></a>LOS_TaskDelay</p> <tr id="row151311929193818"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p213114299387"><a name="p213114299387"></a><a name="p213114299387"></a>LOS_TaskDelay</p>
</td> </td>
<td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p141311729183817"><a name="p141311729183817"></a><a name="p141311729183817"></a>线程延时等待</p> <td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p141311729183817"><a name="p141311729183817"></a><a name="p141311729183817"></a>任务延时等待</p>
</td> </td>
</tr> </tr>
<tr id="row18131182910384"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p15131122923810"><a name="p15131122923810"></a><a name="p15131122923810"></a>LOS_TaskYield</p> <tr id="row18131182910384"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p15131122923810"><a name="p15131122923810"></a><a name="p15131122923810"></a>LOS_TaskYield</p>
</td> </td>
<td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p1713122953816"><a name="p1713122953816"></a><a name="p1713122953816"></a>显式放权,调整调用线程优先级的线程调度顺序</p> <td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p1713122953816"><a name="p1713122953816"></a><a name="p1713122953816"></a>显式放权,调整调用任务优先级的任务调度顺序</p>
</td> </td>
</tr> </tr>
<tr id="row9131829123812"><td class="cellrowborder" rowspan="2" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.1 "><p id="p1313115299387"><a name="p1313115299387"></a><a name="p1313115299387"></a>线程调度的控制</p> <tr id="row9131829123812"><td class="cellrowborder" rowspan="2" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.1 "><p id="p1313115299387"><a name="p1313115299387"></a><a name="p1313115299387"></a>任务调度的控制</p>
</td> </td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.2 "><p id="p101312029113815"><a name="p101312029113815"></a><a name="p101312029113815"></a>LOS_TaskLock</p> <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.2 "><p id="p101312029113815"><a name="p101312029113815"></a><a name="p101312029113815"></a>LOS_TaskLock</p>
</td> </td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.3 "><p id="p0131629183812"><a name="p0131629183812"></a><a name="p0131629183812"></a>线程调度</p> <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.3 "><p id="p0131629183812"><a name="p0131629183812"></a><a name="p0131629183812"></a>任务调度</p>
</td> </td>
</tr> </tr>
<tr id="row5131829193813"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p1313182910388"><a name="p1313182910388"></a><a name="p1313182910388"></a>LOS_TaskUnlock</p> <tr id="row5131829193813"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p1313182910388"><a name="p1313182910388"></a><a name="p1313182910388"></a>LOS_TaskUnlock</p>
</td> </td>
<td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p1131122913812"><a name="p1131122913812"></a><a name="p1131122913812"></a>解锁线程调度</p> <td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p1131122913812"><a name="p1131122913812"></a><a name="p1131122913812"></a>解锁任务调度</p>
</td> </td>
</tr> </tr>
<tr id="row213115292389"><td class="cellrowborder" rowspan="3" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.1 "><p id="p41312295381"><a name="p41312295381"></a><a name="p41312295381"></a>线程优先级的控制</p> <tr id="row213115292389"><td class="cellrowborder" rowspan="3" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.1 "><p id="p41312295381"><a name="p41312295381"></a><a name="p41312295381"></a>任务优先级的控制</p>
</td> </td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.2 "><p id="p1131829103815"><a name="p1131829103815"></a><a name="p1131829103815"></a>LOS_CurTaskPriSet</p> <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.2 "><p id="p1131829103815"><a name="p1131829103815"></a><a name="p1131829103815"></a>LOS_CurTaskPriSet</p>
</td> </td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.3 "><p id="p6131729163810"><a name="p6131729163810"></a><a name="p6131729163810"></a>设置当前线程的优先级</p> <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.3 "><p id="p6131729163810"><a name="p6131729163810"></a><a name="p6131729163810"></a>设置当前任务的优先级</p>
</td> </td>
</tr> </tr>
<tr id="row913142917389"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p10131172913819"><a name="p10131172913819"></a><a name="p10131172913819"></a>LOS_TaskPriSet</p> <tr id="row913142917389"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p10131172913819"><a name="p10131172913819"></a><a name="p10131172913819"></a>LOS_TaskPriSet</p>
</td> </td>
<td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p113162912387"><a name="p113162912387"></a><a name="p113162912387"></a>设置指定线程的优先级</p> <td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p113162912387"><a name="p113162912387"></a><a name="p113162912387"></a>设置指定任务的优先级</p>
</td> </td>
</tr> </tr>
<tr id="row7131192913812"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p713142923817"><a name="p713142923817"></a><a name="p713142923817"></a>LOS_TaskPriGet</p> <tr id="row7131192913812"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p713142923817"><a name="p713142923817"></a><a name="p713142923817"></a>LOS_TaskPriGet</p>
</td> </td>
<td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p14131162923818"><a name="p14131162923818"></a><a name="p14131162923818"></a>获取指定线程的优先级</p> <td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p14131162923818"><a name="p14131162923818"></a><a name="p14131162923818"></a>获取指定任务的优先级</p>
</td> </td>
</tr> </tr>
<tr id="row14132329133817"><td class="cellrowborder" rowspan="2" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.1 "><p id="p81323295380"><a name="p81323295380"></a><a name="p81323295380"></a>线程信息获取</p> <tr id="row14132329133817"><td class="cellrowborder" rowspan="2" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.1 "><p id="p81323295380"><a name="p81323295380"></a><a name="p81323295380"></a>任务信息获取</p>
</td> </td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.2 "><p id="p31324294389"><a name="p31324294389"></a><a name="p31324294389"></a>LOS_CurTaskIDGet</p> <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.2 "><p id="p31324294389"><a name="p31324294389"></a><a name="p31324294389"></a>LOS_CurTaskIDGet</p>
</td> </td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.3 "><p id="p14132929193814"><a name="p14132929193814"></a><a name="p14132929193814"></a>获取当前线程的ID</p> <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.3 "><p id="p14132929193814"><a name="p14132929193814"></a><a name="p14132929193814"></a>获取当前任务的ID</p>
</td> </td>
</tr> </tr>
<tr id="row4132182920383"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p15133172923815"><a name="p15133172923815"></a><a name="p15133172923815"></a>LOS_TaskInfoGet</p> <tr id="row4132182920383"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p15133172923815"><a name="p15133172923815"></a><a name="p15133172923815"></a>LOS_TaskInfoGet</p>
</td> </td>
<td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p5133329123814"><a name="p5133329123814"></a><a name="p5133329123814"></a>获取指定线程的信息</p> <td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p5133329123814"><a name="p5133329123814"></a><a name="p5133329123814"></a>获取指定任务的信息</p>
</td> </td>
</tr> </tr>
<tr id="row855810357401"><td class="cellrowborder" rowspan="2" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.1 "><p id="p9682331164117"><a name="p9682331164117"></a><a name="p9682331164117"></a>线程绑核操作</p> <tr id="row855810357401"><td class="cellrowborder" rowspan="2" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.1 "><p id="p9682331164117"><a name="p9682331164117"></a><a name="p9682331164117"></a>任务绑核操作</p>
</td> </td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.2 "><p id="p205581835144010"><a name="p205581835144010"></a><a name="p205581835144010"></a>LOS_TaskCpuAffiSet</p> <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.2 "><p id="p205581835144010"><a name="p205581835144010"></a><a name="p205581835144010"></a>LOS_TaskCpuAffiSet</p>
</td> </td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.3 "><p id="p115582035154014"><a name="p115582035154014"></a><a name="p115582035154014"></a>绑定指定线程到指定cpu上运行,仅在多核下使用</p> <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.3 "><p id="p115582035154014"><a name="p115582035154014"></a><a name="p115582035154014"></a>绑定指定任务到指定cpu上运行,仅在多核下使用</p>
</td> </td>
</tr> </tr>
<tr id="row5866193714018"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p8867133744011"><a name="p8867133744011"></a><a name="p8867133744011"></a>LOS_TaskCpuAffiGet</p> <tr id="row5866193714018"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p8867133744011"><a name="p8867133744011"></a><a name="p8867133744011"></a>LOS_TaskCpuAffiGet</p>
</td> </td>
<td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p10867173718404"><a name="p10867173718404"></a><a name="p10867173718404"></a>获取指定线程的绑核信息,仅在多核下使用</p> <td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p10867173718404"><a name="p10867173718404"></a><a name="p10867173718404"></a>获取指定任务的绑核信息,仅在多核下使用</p>
</td> </td>
</tr> </tr>
<tr id="row197312218434"><td class="cellrowborder" rowspan="2" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.1 "><p id="p20362114474318"><a name="p20362114474318"></a><a name="p20362114474318"></a>线程调度参数的控制</p> <tr id="row197312218434"><td class="cellrowborder" rowspan="2" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.1 "><p id="p20362114474318"><a name="p20362114474318"></a><a name="p20362114474318"></a>任务调度参数的控制</p>
</td> </td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.2 "><p id="p5974192215434"><a name="p5974192215434"></a><a name="p5974192215434"></a>LOS_GetTaskScheduler</p> <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.2 "><p id="p5974192215434"><a name="p5974192215434"></a><a name="p5974192215434"></a>LOS_GetTaskScheduler</p>
</td> </td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.3 "><p id="p2974922164317"><a name="p2974922164317"></a><a name="p2974922164317"></a>获取指定线程的调度策略</p> <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.3 "><p id="p2974922164317"><a name="p2974922164317"></a><a name="p2974922164317"></a>获取指定任务的调度策略</p>
</td> </td>
</tr> </tr>
<tr id="row141414214436"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p9141202144319"><a name="p9141202144319"></a><a name="p9141202144319"></a>LOS_SetTaskScheduler</p> <tr id="row141414214436"><td class="cellrowborder" valign="top" headers="mcps1.1.4.1.1 "><p id="p9141202144319"><a name="p9141202144319"></a><a name="p9141202144319"></a>LOS_SetTaskScheduler</p>
</td> </td>
<td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p3141221154319"><a name="p3141221154319"></a><a name="p3141221154319"></a>设置指定线程的调度参数,包括优先级和调度策略</p> <td class="cellrowborder" valign="top" headers="mcps1.1.4.1.2 "><p id="p3141221154319"><a name="p3141221154319"></a><a name="p3141221154319"></a>设置指定任务的调度参数,包括优先级和调度策略</p>
</td> </td>
</tr> </tr>
<tr id="row617914918441"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.1 "><p id="p17180184911445"><a name="p17180184911445"></a><a name="p17180184911445"></a>系统支持的最大线程</p> <tr id="row617914918441"><td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.1 "><p id="p17180184911445"><a name="p17180184911445"></a><a name="p17180184911445"></a>系统支持的最大任务</p>
</td> </td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.2 "><p id="p151807498449"><a name="p151807498449"></a><a name="p151807498449"></a>LOS_GetSystemTaskMaximum</p> <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.2 "><p id="p151807498449"><a name="p151807498449"></a><a name="p151807498449"></a>LOS_GetSystemTaskMaximum</p>
</td> </td>
<td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.3 "><p id="p81801249124417"><a name="p81801249124417"></a><a name="p81801249124417"></a>获取系统支持的最大线程数目</p> <td class="cellrowborder" valign="top" width="33.33333333333333%" headers="mcps1.1.4.1.3 "><p id="p81801249124417"><a name="p81801249124417"></a><a name="p81801249124417"></a>获取系统支持的最大任务数目</p>
</td> </td>
</tr> </tr>
</tbody> </tbody>
...@@ -198,23 +200,23 @@ OpenHarmony 线程管理模块提供线程创建、线程延时、线程挂起 ...@@ -198,23 +200,23 @@ OpenHarmony 线程管理模块提供线程创建、线程延时、线程挂起
### 开发流程<a name="section16229657115514"></a> ### 开发流程<a name="section16229657115514"></a>
线程的典型开发流程: 任务的典型开发流程:
1. 通过LOS\_TaskCreate创建一个线程 1. 通过LOS\_TaskCreate创建一个任务
- 指定线程的执行入口函数 - 指定任务的执行入口函数
- 指定线程 - 指定任务
- 指定线程的栈大小 - 指定任务的栈大小
- 指定线程的优先级 - 指定任务的优先级
- 指定线程的属性,是否支持LOS\_TASK\_STATUS\_DETACHED属性 - 指定任务的属性,是否支持LOS\_TASK\_STATUS\_DETACHED属性
- 多核运行时,可以选择设置线程的绑核属性 - 多核运行时,可以选择设置任务的绑核属性
2. 线程参与调度运行,执行用户指定的业务代码。 2. 任务参与调度运行,执行用户指定的业务代码。
3. 线程执行结束,如果线程设置了LOS\_TASK\_STATUS\_DETACHED属性,则线程运行结束后自动回收线程资源,如果未设置LOS\_TASK\_STATUS\_DETACHED属性,则需要调用LOS\_TaskDelete接口回收线程资源。 3. 任务执行结束,如果任务设置了LOS\_TASK\_STATUS\_DETACHED属性,则任务运行结束后自动回收任务资源,如果未设置LOS\_TASK\_STATUS\_DETACHED属性,则需要调用LOS\_TaskDelete接口回收任务资源。
>![](../public_sys-resources/icon-note.gif) **说明:** >![](../public_sys-resources/icon-note.gif) **说明:**
>- 内核态具有最高权限,可以操作任意进程内的线程 >- 内核态具有最高权限,可以操作任意进程内的任务
>- 用户态进程通过系统调用进入内核态后创建的线程属于KProcess, 不属于当前用户态进程。 >- 用户态进程通过系统调用进入内核态后创建的任务属于KProcess, 不属于当前用户态进程。
### 编程实例<a name="section2809723165612"></a> ### 编程实例<a name="section2809723165612"></a>
......
...@@ -48,7 +48,7 @@ typedef struct { ...@@ -48,7 +48,7 @@ typedef struct {
本实例实现如下功能: 本实例实现如下功能:
1. 创建一个监控线程,用于获取内存池的信息; 1. 创建一个监控任务,用于获取内存池的信息;
2. 调用LOS\_MemInfoGet接口,获取内存池的基础信息; 2. 调用LOS\_MemInfoGet接口,获取内存池的基础信息;
3. 利用公式算出使用率及碎片率。 3. 利用公式算出使用率及碎片率。
......
...@@ -44,16 +44,16 @@ OpenHarmony 轻量级内核是基于IoT领域轻量级物联网操作系统Huawe ...@@ -44,16 +44,16 @@ OpenHarmony 轻量级内核是基于IoT领域轻量级物联网操作系统Huawe
基础内核组件实现精简,主要包括内核的基础机制,如调度、内存管理、中断异常、内核通信等; 基础内核组件实现精简,主要包括内核的基础机制,如调度、内存管理、中断异常、内核通信等;
- 进程管理:支持进程和线程,基于Task实现进程,进程独立4GB地址空间 - 进程管理:支持进程和线程,基于Task实现进程,进程独立4GiB地址空间
- 多核调度:支持任务和中断亲核性设置,支持绑核运行 - 多核调度:支持任务和中断亲核性设置,支持绑核运行
- 实时调度:支持高优先级抢占,同优先级时间片轮转 - 实时调度:支持高优先级抢占,同优先级时间片轮转
- 虚拟内存:支持缺页异常,内核空间静态映射到0-1G地址,用户空间映射到1-4G地址 - 虚拟内存:支持缺页异常,内核空间静态映射到0-1GiB地址,用户空间映射到1-4GiB地址
- 内核通信:事件、信号量、互斥锁、队列 - 内核通信:事件、信号量、互斥锁、队列
- 时间管理:软件定时器、系统时钟 - 时间管理:软件定时器、系统时钟
**文件系统** **文件系统**
轻量级内核支持FAT,JFFS2,NFS,ramfs,procfs等众多文件系统,并对外提供完整的POSIX标准的操作接口,功能非常强大;内部使用VFS层作为统一的适配层框架,方便移植新的文件系统,各个文件系统也能自动利用VFS层提供的丰富的功能。 轻量级内核支持FAT,JFFS2,NFS,ramfs,procfs等众多文件系统,并对外提供完整的POSIX标准的操作接口;内部使用VFS层作为统一的适配层框架,方便移植新的文件系统,各个文件系统也能自动利用VFS层提供的丰富的功能。
主要特性有: 主要特性有:
...@@ -92,6 +92,6 @@ OpenHarmony 轻量级内核是基于IoT领域轻量级物联网操作系统Huawe ...@@ -92,6 +92,6 @@ OpenHarmony 轻量级内核是基于IoT领域轻量级物联网操作系统Huawe
- 动态链接:支持标准ELF链接执行、加载地址随机化 - 动态链接:支持标准ELF链接执行、加载地址随机化
- 进程通信:支持轻量级LiteIPC,同时也支持标准的Mqueue、Pipe、Fifo、Signal等机制 - 进程通信:支持轻量级LiteIPC,同时也支持标准的Mqueue、Pipe、Fifo、Signal等机制
- 系统调用:支持170+系统调用 ,同时有支持VDSO机制 - 系统调用:支持170+系统调用,同时有支持VDSO机制
- 权限管理:支持进程粒度的特权划分和管控,UGO三种权限配置 - 权限管理:支持进程粒度的特权划分和管控,UGO三种权限配置
...@@ -86,7 +86,7 @@ ...@@ -86,7 +86,7 @@
<tr id="row357517134414"><td class="cellrowborder" valign="top" width="35.58%" headers="mcps1.2.3.1.1 "><p id="p12575676449"><a name="p12575676449"></a><a name="p12575676449"></a>LOS_INIT_LEVEL_KMOD_TASK</p> <tr id="row357517134414"><td class="cellrowborder" valign="top" width="35.58%" headers="mcps1.2.3.1.1 "><p id="p12575676449"><a name="p12575676449"></a><a name="p12575676449"></a>LOS_INIT_LEVEL_KMOD_TASK</p>
</td> </td>
<td class="cellrowborder" valign="top" width="64.42%" headers="mcps1.2.3.1.2 "><p id="p7128122619143"><a name="p7128122619143"></a><a name="p7128122619143"></a>内核任务创建</p> <td class="cellrowborder" valign="top" width="64.42%" headers="mcps1.2.3.1.2 "><p id="p7128122619143"><a name="p7128122619143"></a><a name="p7128122619143"></a>内核任务创建</p>
<p id="p1657587184419"><a name="p1657587184419"></a><a name="p1657587184419"></a>说明:进行内核任务的创建(内核线程,软件定时器任务)</p> <p id="p1657587184419"><a name="p1657587184419"></a><a name="p1657587184419"></a>说明:进行内核任务的创建(内核任务,软件定时器任务)</p>
<p id="p55485297219"><a name="p55485297219"></a><a name="p55485297219"></a>例如:资源回收系统常驻任务的创建、SystemInit任务创建、CPU占用率统计任务创建</p> <p id="p55485297219"><a name="p55485297219"></a><a name="p55485297219"></a>例如:资源回收系统常驻任务的创建、SystemInit任务创建、CPU占用率统计任务创建</p>
</td> </td>
</tr> </tr>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册