diff --git a/en/device-dev/kernel/Readme-EN.md b/en/device-dev/kernel/Readme-EN.md index 90a193350373b0cce1373609398f2c2f3534eeba..86c4084c5fa70b97c2d9998ee822fad69700f144 100644 --- a/en/device-dev/kernel/Readme-EN.md +++ b/en/device-dev/kernel/Readme-EN.md @@ -69,7 +69,7 @@ - [Interrupt and Exception Handling](kernel-small-basic-interrupt.md) - [Process Management](kernel-small-basic-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) - [Memory Management](kernel-small-basic-memory.md) - [Heap Memory Management](kernel-small-basic-memory-heap.md) diff --git a/en/device-dev/kernel/figure/kernel-architecture.png b/en/device-dev/kernel/figure/kernel-architecture.png index 1e120a02344a848cc8b87b58f6c86a5f97e560c1..22880de59d064ae9ce1451c0475dd950280ea087 100644 Binary files a/en/device-dev/kernel/figure/kernel-architecture.png and b/en/device-dev/kernel/figure/kernel-architecture.png differ diff --git a/en/device-dev/kernel/figure/kernel-startup-process.png b/en/device-dev/kernel/figure/kernel-startup-process.png index e20abdc4493bc503efab410f444135c48d0ec250..17c4e0e82bcd5d2dc8bf327dc2ccb36477f857ea 100644 Binary files a/en/device-dev/kernel/figure/kernel-startup-process.png and b/en/device-dev/kernel/figure/kernel-startup-process.png differ diff --git a/en/device-dev/kernel/kernel-mini-appx-code.md b/en/device-dev/kernel/kernel-mini-appx-code.md index 7892f4823b55a50d68bdeb9cf931ed66b1012de3..b1d1ebad2784d4c658ed303618923d77eff2577c 100644 --- a/en/device-dev/kernel/kernel-mini-appx-code.md +++ b/en/device-dev/kernel/kernel-mini-appx-code.md @@ -156,13 +156,14 @@ Example: 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 (;). -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) { Foo(); // There is only one statement in a line. Bar(); } else { // The right brace, else, and the subsequent left brace are in the same line. ... - } // The right brace occupies one line exclusively. + } // The right brace occupies one line exclusively. ... } ``` diff --git a/en/device-dev/kernel/kernel-mini-memory-debug-mes.md b/en/device-dev/kernel/kernel-mini-memory-debug-mes.md index dfb48d549593e5ac47e50361e045ae6e7553fc94..9ada391f6a65ff8d6e8007a7368fe114b8eeb9e2 100644 --- a/en/device-dev/kernel/kernel-mini-memory-debug-mes.md +++ b/en/device-dev/kernel/kernel-mini-memory-debug-mes.md @@ -56,7 +56,7 @@ typedef struct { 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. diff --git a/en/device-dev/kernel/kernel-mini-overview.md b/en/device-dev/kernel/kernel-mini-overview.md index b0b7cb8328f7f47bee0d39d06a4ab3ad2cd8338a..e727b225c1998e4a54df754987d8f3440b818d7b 100644 --- a/en/device-dev/kernel/kernel-mini-overview.md +++ b/en/device-dev/kernel/kernel-mini-overview.md @@ -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 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. -- **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. +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. **Figure 1** Kernel architecture ![](figure/kernel-architecture.png "kernel-architecture") diff --git a/en/device-dev/kernel/kernel-small-basic-process-thread.md b/en/device-dev/kernel/kernel-small-basic-process-thread.md index 4f255f922e8f9096b0d005dd29ef555bf15bf996..0abb01044877f893074498f53e918fb067c61d18 100644 --- a/en/device-dev/kernel/kernel-small-basic-process-thread.md +++ b/en/device-dev/kernel/kernel-small-basic-process-thread.md @@ -1,4 +1,4 @@ -# Thread +# Task - [Basic Concepts](#section138411646175417) - [Working Principles](#section1381918945512) @@ -10,64 +10,64 @@ ## Basic Concepts -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. -**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. -- Running: The thread 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\). -- Exit: The thread stops running and waits for the parent thread to reclaim its control block resources. +- Ready: The task is in the Ready queue and waits for being scheduled by the CPU. +- Running: The task is running. +- 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 task stops running and waits for the parent task to reclaim its control block resources. -**Figure 1** Thread state transition -![](figure/thread-state-transition.png "thread-state-transition") +**Figure 1** Task state transition +![](figure/task-state-transition.png "task-state-transition") -**Thread State Transition:** +**Task State Transition:** - 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: - 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: - 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: - 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: - 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: - 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: - 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 -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 @@ -82,115 +82,115 @@ When a thread is created, the system initializes the thread stack and presets th -

Thread creation and deletion

+

Task creation and deletion

LOS_TaskCreateOnly

-

Creates a thread and places the thread in the Init state but not be scheduled.

+

Creates a task and places the task in the Init state but not be scheduled.

LOS_TaskCreate

-

Creates a thread and places the thread in the Init state and be scheduled.

+

Creates a task and places the task in the Init state and be scheduled.

LOS_TaskDelete

-

Deletes the specified thread.

+

Deletes the specified task.

-

Thread status control

+

Task status control

LOS_TaskResume

-

Resumes a suspended thread.

+

Resumes a suspended task.

LOS_TaskSuspend

-

Suspends the specified thread.

+

Suspends the specified task.

LOS_TaskDelay

-

Delays a thread.

+

Delays a task.

LOS_TaskYield

-

Adjusts the scheduling sequence of threads that call the thread priority.

+

Adjusts the scheduling sequence of tasks that call the task priority.

-

Thread scheduling control

+

Task scheduling control

LOS_TaskLock

-

Locks thread scheduling.

+

Locks task scheduling.

LOS_TaskUnlock

-

Unlocks thread scheduling.

+

Unlocks task scheduling.

-

Thread priority control

+

Task priority control

LOS_CurTaskPriSet

-

Sets the priority for the current thread.

+

Sets the priority for the current task.

LOS_TaskPriSet

-

Sets the priority of the specified thread.

+

Sets the priority of the specified task.

LOS_TaskPriGet

-

Obtains the priority of the specified thread.

+

Obtains the priority of the specified task.

-

Obtaining thread information

+

Obtaining task information

LOS_CurTaskIDGet

-

Obtains the ID of the current thread.

+

Obtains the ID of the current task.

LOS_TaskInfoGet

-

Obtains information about the specific thread.

+

Obtains information about the specific task.

-

Binding threads to CPU cores

+

Binding tasks to CPU cores

LOS_TaskCpuAffiSet

-

Binds a specified thread to a specified CPU. It is used only in multi-core scenarios.

+

Binds a specified task to a specified CPU. It is used only in multi-core scenarios.

LOS_TaskCpuAffiGet

-

Obtains the core binding information of a specified thread. It is used only in multi-core scenarios.

+

Obtains the core binding information of a specified task. It is used only in multi-core scenarios.

-

Thread scheduling parameter control

+

Task scheduling parameter control

LOS_GetTaskScheduler

-

Obtains the scheduling policy of the specified thread.

+

Obtains the scheduling policy of the specified task.

LOS_SetTaskScheduler

-

Sets the scheduling parameters, including the priority and scheduling policy, for the specified thread.

+

Sets the scheduling parameters, including the priority and scheduling policy, for the specified task.

-

Maximum number of threads supported

+

Maximum number of tasks supported

LOS_GetSystemTaskMaximum

-

Obtains the maximum number of threads supported by the system.

+

Obtains the maximum number of tasks supported by the system.

@@ -198,23 +198,23 @@ When a thread is created, the system initializes the thread stack and presets th ### How to Develop -The typical thread development process is as follows: +The typical task development process is as follows: -1. Call **LOS\_TaskCreate** to create a thread. - - Specify the execution entry function for the thread. +1. Call **LOS\_TaskCreate** to create a task. + - Specify the execution entry function for the task. - - Specify the thread name. - - Specify the thread stack size. - - Specify the priority of the thread. - - Specify the thread 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 name. + - Specify the task stack size. + - Specify the priority of the task. + - Specify the task attribute, that is, whether to support the **LOS\_TASK\_STATUS\_DETACHED** attribute. + - Specify the task-core binding attribute for multi-core environment. -2. Run the service code to implement thread 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. +2. Run the service code to implement task scheduling. +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:** ->- The kernel space has the highest permission and can operate threads 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 kernel space has the highest permission and can operate tasks in any process. +>- The task created by calling a user-space process in the kernel space is a KProcess, not a user-space process. ### Development Example @@ -229,7 +229,7 @@ UINT32 ExampleTaskHi(VOID) { UINT32 ret; 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); if (ret != LOS_OK) { PRINTK("Delay Task Failed.\n"); @@ -252,7 +252,7 @@ UINT32 ExampleTaskLo(VOID) { UINT32 ret; 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); if (ret != LOS_OK) { PRINTK("Delay TaskLo Failed.\n"); diff --git a/en/device-dev/kernel/kernel-small-debug-memory-info.md b/en/device-dev/kernel/kernel-small-debug-memory-info.md index f2be31a222f612da4f6afb30d339b20ffdacbaf7..d87652c782de7f205d4cd5d9eda743b396656daf 100644 --- a/en/device-dev/kernel/kernel-small-debug-memory-info.md +++ b/en/device-dev/kernel/kernel-small-debug-memory-info.md @@ -54,7 +54,7 @@ typedef struct { 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. 3. Calculates the memory usage and fragmentation rate. diff --git a/en/device-dev/kernel/kernel-small-overview.md b/en/device-dev/kernel/kernel-small-overview.md index a4590c1e88c1f99497dad219c0cb7e98bb1574eb..7afd67fb1596b3b11226adee89f61be744271a2f 100644 --- a/en/device-dev/kernel/kernel-small-overview.md +++ b/en/device-dev/kernel/kernel-small-overview.md @@ -44,7 +44,7 @@ The lightweight kernel consists of the basic kernel, extension components, HDF, 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. - 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. diff --git a/en/device-dev/kernel/kernel-small-start-kernel.md b/en/device-dev/kernel/kernel-small-start-kernel.md index e097647772e780ff29d9d502f0fda6b98ad9e4d9..65381837b98ef3be9b91d875dbb9f148f8c93c73 100644 --- a/en/device-dev/kernel/kernel-small-start-kernel.md +++ b/en/device-dev/kernel/kernel-small-start-kernel.md @@ -86,7 +86,7 @@ The kernel startup process consists of the assembly startup and C language start

LOS_INIT_LEVEL_KMOD_TASK

Kernel task creation

-

Create kernel tasks (kernel thread and software timer tasks).

+

Create kernel tasks (kernel tasks and software timer tasks).

Example: creation of the resident resource reclaiming task, SystemInit task, and CPU usage statistics task.

diff --git a/zh-cn/device-dev/kernel/Readme-CN.md b/zh-cn/device-dev/kernel/Readme-CN.md index 8322ca1667314d6016f60fbcd026a53d14c60b0e..aa638608df45256d04b2ac62a818278081180210 100755 --- a/zh-cn/device-dev/kernel/Readme-CN.md +++ b/zh-cn/device-dev/kernel/Readme-CN.md @@ -67,7 +67,7 @@ - [中断及异常处理](kernel-small-basic-interrupt.md) - [进程管理](kernel-small-basic-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-memory.md) - [堆内存管理](kernel-small-basic-memory-heap.md) diff --git a/zh-cn/device-dev/kernel/figure/zh-cn_image_0000001191018697.png b/zh-cn/device-dev/kernel/figure/zh-cn_image_0000001191018697.png index 9330ebba7e4fd0de3f88a0abda65beceb65a18ac..d5693bd916ea4f009687af8233054baedf06ddf3 100644 Binary files a/zh-cn/device-dev/kernel/figure/zh-cn_image_0000001191018697.png and b/zh-cn/device-dev/kernel/figure/zh-cn_image_0000001191018697.png differ diff --git "a/zh-cn/device-dev/kernel/figure/\345\206\205\346\240\270\345\220\257\345\212\250\346\265\201\347\250\213.png" "b/zh-cn/device-dev/kernel/figure/\345\206\205\346\240\270\345\220\257\345\212\250\346\265\201\347\250\213.png" index 6c211cb88534ae6a28e6dbdaed8bd1b2717d7366..ab769d0228a005f3332d86e1443712e157c7f32d 100644 Binary files "a/zh-cn/device-dev/kernel/figure/\345\206\205\346\240\270\345\220\257\345\212\250\346\265\201\347\250\213.png" and "b/zh-cn/device-dev/kernel/figure/\345\206\205\346\240\270\345\220\257\345\212\250\346\265\201\347\250\213.png" differ diff --git "a/zh-cn/device-dev/kernel/figure/\345\206\205\346\240\270\346\236\266\346\236\204\345\233\276.png" "b/zh-cn/device-dev/kernel/figure/\345\206\205\346\240\270\346\236\266\346\236\204\345\233\276.png" index 63a10e4e899d2bff697158fff9c869eb278bca59..aab178cde608403d259af3cd10c11188e213de08 100644 Binary files "a/zh-cn/device-dev/kernel/figure/\345\206\205\346\240\270\346\236\266\346\236\204\345\233\276.png" and "b/zh-cn/device-dev/kernel/figure/\345\206\205\346\240\270\346\236\266\346\236\204\345\233\276.png" differ diff --git a/zh-cn/device-dev/kernel/kernel-mini-extend.md b/zh-cn/device-dev/kernel/kernel-mini-extend.md index f257a85a1cb30a1c691bf86cba024d1d8c483106..2c171e7ce636249dda71961412c9f4862046effb 100644 --- a/zh-cn/device-dev/kernel/kernel-mini-extend.md +++ b/zh-cn/device-dev/kernel/kernel-mini-extend.md @@ -4,7 +4,7 @@ - **[CPU占用率](kernel-mini-extend-cpup.md)** -- **[](kernel-mini-extend-dynamic-loading.md)** +- **[动态加载](kernel-mini-extend-dynamic-loading.md)** - **[文件系统](kernel-mini-extend-file.md)** diff --git a/zh-cn/device-dev/kernel/kernel-mini-memory-debug-mes.md b/zh-cn/device-dev/kernel/kernel-mini-memory-debug-mes.md index 4115b8c99d9a3399ffd1cc0b508d7a394c1cffd3..6f58e1b0777c1a3d0d36450c68d0f5af3633b7e4 100644 --- a/zh-cn/device-dev/kernel/kernel-mini-memory-debug-mes.md +++ b/zh-cn/device-dev/kernel/kernel-mini-memory-debug-mes.md @@ -50,7 +50,7 @@ typedef struct { 本实例实现如下功能: -1.创建一个监控线程,用于获取内存池的信息; +1.创建一个监控任务,用于获取内存池的信息; 2.调用LOS\_MemInfoGet接口,获取内存池的基础信息; diff --git a/zh-cn/device-dev/kernel/kernel-mini-overview.md b/zh-cn/device-dev/kernel/kernel-mini-overview.md index 8454dad63d713a591a9fdc2e72c6f4c2d3cf3321..0966779d95cab06335077285e069b53793abbbc1 100644 --- a/zh-cn/device-dev/kernel/kernel-mini-overview.md +++ b/zh-cn/device-dev/kernel/kernel-mini-overview.md @@ -7,7 +7,7 @@ ## 内核简介 -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** 内核架构图 ![](figure/内核架构图.png "内核架构图") diff --git a/zh-cn/device-dev/kernel/kernel-small-basic-process-thread.md b/zh-cn/device-dev/kernel/kernel-small-basic-process-thread.md index 0bb10cbfae91c353c956e8ec98e0c642543fb84e..8d7a436a8ba22c711a3957df8c6875952eaf6764 100644 --- a/zh-cn/device-dev/kernel/kernel-small-basic-process-thread.md +++ b/zh-cn/device-dev/kernel/kernel-small-basic-process-thread.md @@ -1,4 +1,4 @@ -# 线程 +# 任务 - [基本概念](#section138411646175417) - [运行机制](#section1381918945512) @@ -10,64 +10,66 @@ ## 基本概念 -从系统的角度看,线程是竞争系统资源的最小运行单元。线程可以使用或等待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调度。 -- 运行(Running):线程正在运行。 -- 阻塞(Blocked):线程被阻塞挂起。Blocked状态包括:pending\(因为锁、事件、信号量等阻塞\)、suspended(主动pend)、delay\(延时阻塞\)、pendtime\(因为锁、事件、信号量时间等超时等待\)。 -- 退出(Exit):线程运行结束,等待父线程回收其控制块资源。 +- 初始化(Init):任务正在被创建。 -**图 1** 线程状态迁移示意图 -![](figure/线程状态迁移示意图.png "线程状态迁移示意图") +- 就绪(Ready):任务在就绪列表中,等待CPU调度。 +- 运行(Running):任务正在运行。 +- 阻塞(Blocked):任务被阻塞挂起。Blocked状态包括:pending\(因为锁、事件、信号量等阻塞\)、suspended(主动pend)、delay\(延时阻塞\)、pendtime\(因为锁、事件、信号量时间等超时等待\)。 +- 退出(Exit):任务运行结束,等待父任务回收其控制块资源。 -**线程状态迁移说明:** +**图 1** 任务状态迁移示意图 +![](figure/任务状态迁移示意图.png "任务状态迁移示意图") + +**任务状态迁移说明:** - Init→Ready: - 线程创建拿到控制块后为初始化阶段\(Init状态\),当线程初始化完成将线程插入调度队列,此时线程进入就绪状态。 + 任务创建拿到控制块后为初始化阶段\(Init状态\),当任务初始化完成将任务插入调度队列,此时任务进入就绪状态。 - Ready→Running: - 线程创建后进入就绪态,发生线程切换时,就绪列表中最高优先级的线程被执行,从而进入运行态,此刻该线程从就绪列表中删除。 + 任务创建后进入就绪态,发生任务切换时,就绪列表中最高优先级的任务被执行,从而进入运行态,此刻该任务从就绪列表中删除。 - Running→Blocked: - 正在运行的线程发生阻塞(挂起、延时、读信号量等)时,线程状态由运行态变成阻塞态,然后发生线程切换,运行就绪列表中剩余最高优先级线程。 + 正在运行的任务发生阻塞(挂起、延时、读信号量等)时,任务状态由运行态变成阻塞态,然后发生任务切换,运行就绪列表中剩余最高优先级任务。 - Blocked→Ready : - 阻塞的线程被恢复后(线程恢复、延时时间超时、读信号量超时或读到信号量等),此时被恢复的线程会被加入就绪列表,从而由阻塞态变成就绪态。 + 阻塞的任务被恢复后(任务恢复、延时时间超时、读信号量超时或读到信号量等),此时被恢复的任务会被加入就绪列表,从而由阻塞态变成就绪态。 - Ready→Blocked: - 线程也有可能在就绪态时被阻塞(挂起),此时线程状态会由就绪态转变为阻塞态,该线程从就绪列表中删除,不会参与线程调度,直到该线程被恢复。 + 任务也有可能在就绪态时被阻塞(挂起),此时任务状态会由就绪态转变为阻塞态,该任务从就绪列表中删除,不会参与任务调度,直到该任务被恢复。 - Running→Ready: - 有更高优先级线程创建或者恢复后,会发生线程调度,此刻就绪列表中最高优先级线程变为运行态,那么原先运行的线程由运行态变为就绪态,并加入就绪列表中。 + 有更高优先级任务创建或者恢复后,会发生任务调度,此刻就绪列表中最高优先级任务变为运行态,那么原先运行的任务由运行态变为就绪态,并加入就绪列表中。 - Running→Exit: - 运行中的线程运行结束,线程状态由运行态变为退出态。若为设置了分离属性(LOS\_TASK\_STATUS\_DETACHED)的线程,运行结束后将直接销毁。 + 运行中的任务运行结束,任务状态由运行态变为退出态。若为设置了分离属性(LOS\_TASK\_STATUS\_DETACHED)的任务,运行结束后将直接销毁。 ## 运行机制 -OpenHarmony 线程管理模块提供线程创建、线程延时、线程挂起和线程恢复、锁线程调度和解锁线程调度、根据ID查询线程控制块信息功能。 +OpenHarmony 任务管理模块提供任务创建、任务延时、任务挂起和任务恢复、锁任务调度和解锁任务调度、根据ID查询任务控制块信息功能。 -用户创建线程时,系统会将线程栈进行初始化,预置上下文。此外,系统还会将“线程入口函数”地址放在相应位置。这样在线程第一次启动进入运行态时,将会执行线程入口函数。 +用户创建任务时,系统会将任务栈进行初始化,预置上下文。此外,系统还会将“任务入口函数”地址放在相应位置。这样在任务第一次启动进入运行态时,将会执行任务入口函数。 ## 开发指导 @@ -82,115 +84,115 @@ OpenHarmony 线程管理模块提供线程创建、线程延时、线程挂起 -

线程的创建和删除

+

任务的创建和删除

LOS_TaskCreateOnly

-

创建线程,并使该线程进入Init状态,不执行线程调度

+

创建任务,并使该任务进入Init状态,不执行任务调度

LOS_TaskCreate

-

创建线程,并使该线程进入Ready状态,并调度

+

创建任务,并使该任务进入Ready状态,并调度

LOS_TaskDelete

-

删除指定的线程

+

删除指定的任务

-

线程状态控制

+

任务状态控制

LOS_TaskResume

-

恢复挂起的线程

+

恢复挂起的任务

LOS_TaskSuspend

-

挂起指定的线程

+

挂起指定的任务

LOS_TaskDelay

-

线程延时等待

+

任务延时等待

LOS_TaskYield

-

显式放权,调整调用线程优先级的线程调度顺序

+

显式放权,调整调用任务优先级的任务调度顺序

-

线程调度的控制

+

任务调度的控制

LOS_TaskLock

-

锁线程调度

+

锁任务调度

LOS_TaskUnlock

-

解锁线程调度

+

解锁任务调度

-

线程优先级的控制

+

任务优先级的控制

LOS_CurTaskPriSet

-

设置当前线程的优先级

+

设置当前任务的优先级

LOS_TaskPriSet

-

设置指定线程的优先级

+

设置指定任务的优先级

LOS_TaskPriGet

-

获取指定线程的优先级

+

获取指定任务的优先级

-

线程信息获取

+

任务信息获取

LOS_CurTaskIDGet

-

获取当前线程的ID

+

获取当前任务的ID

LOS_TaskInfoGet

-

获取指定线程的信息

+

获取指定任务的信息

-

线程绑核操作

+

任务绑核操作

LOS_TaskCpuAffiSet

-

绑定指定线程到指定cpu上运行,仅在多核下使用

+

绑定指定任务到指定cpu上运行,仅在多核下使用

LOS_TaskCpuAffiGet

-

获取指定线程的绑核信息,仅在多核下使用

+

获取指定任务的绑核信息,仅在多核下使用

-

线程调度参数的控制

+

任务调度参数的控制

LOS_GetTaskScheduler

-

获取指定线程的调度策略

+

获取指定任务的调度策略

LOS_SetTaskScheduler

-

设置指定线程的调度参数,包括优先级和调度策略

+

设置指定任务的调度参数,包括优先级和调度策略

-

系统支持的最大线程数

+

系统支持的最大任务数

LOS_GetSystemTaskMaximum

-

获取系统支持的最大线程数目

+

获取系统支持的最大任务数目

@@ -198,23 +200,23 @@ OpenHarmony 线程管理模块提供线程创建、线程延时、线程挂起 ### 开发流程 -线程的典型开发流程: +任务的典型开发流程: -1. 通过LOS\_TaskCreate创建一个线程。 - - 指定线程的执行入口函数 +1. 通过LOS\_TaskCreate创建一个任务。 + - 指定任务的执行入口函数 - - 指定线程名 - - 指定线程的栈大小 - - 指定线程的优先级 - - 指定线程的属性,是否支持LOS\_TASK\_STATUS\_DETACHED属性 - - 多核运行时,可以选择设置线程的绑核属性 + - 指定任务名 + - 指定任务的栈大小 + - 指定任务的优先级 + - 指定任务的属性,是否支持LOS\_TASK\_STATUS\_DETACHED属性 + - 多核运行时,可以选择设置任务的绑核属性 -2. 线程参与调度运行,执行用户指定的业务代码。 -3. 线程执行结束,如果线程设置了LOS\_TASK\_STATUS\_DETACHED属性,则线程运行结束后自动回收线程资源,如果未设置LOS\_TASK\_STATUS\_DETACHED属性,则需要调用LOS\_TaskDelete接口回收线程资源。 +2. 任务参与调度运行,执行用户指定的业务代码。 +3. 任务执行结束,如果任务设置了LOS\_TASK\_STATUS\_DETACHED属性,则任务运行结束后自动回收任务资源,如果未设置LOS\_TASK\_STATUS\_DETACHED属性,则需要调用LOS\_TaskDelete接口回收任务资源。 >![](../public_sys-resources/icon-note.gif) **说明:** ->- 内核态具有最高权限,可以操作任意进程内的线程。 ->- 用户态进程通过系统调用进入内核态后创建的线程属于KProcess, 不属于当前用户态进程。 +>- 内核态具有最高权限,可以操作任意进程内的任务。 +>- 用户态进程通过系统调用进入内核态后创建的任务属于KProcess, 不属于当前用户态进程。 ### 编程实例 diff --git a/zh-cn/device-dev/kernel/kernel-small-debug-memory-info.md b/zh-cn/device-dev/kernel/kernel-small-debug-memory-info.md index 74ba36bc295e6e4855eefce41d57204c4bc4df18..25ce9e07f8c8daf92df2e3e88f54b43ea08ae9d1 100644 --- a/zh-cn/device-dev/kernel/kernel-small-debug-memory-info.md +++ b/zh-cn/device-dev/kernel/kernel-small-debug-memory-info.md @@ -48,7 +48,7 @@ typedef struct { 本实例实现如下功能: -1. 创建一个监控线程,用于获取内存池的信息; +1. 创建一个监控任务,用于获取内存池的信息; 2. 调用LOS\_MemInfoGet接口,获取内存池的基础信息; 3. 利用公式算出使用率及碎片率。 diff --git a/zh-cn/device-dev/kernel/kernel-small-overview.md b/zh-cn/device-dev/kernel/kernel-small-overview.md index 703cf6241c3aa10ad15908cb30bdb5085595ad84..8852458ea0591ef331d8a499cde11f7dd15689f8 100644 --- a/zh-cn/device-dev/kernel/kernel-small-overview.md +++ b/zh-cn/device-dev/kernel/kernel-small-overview.md @@ -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 - 动态链接:支持标准ELF链接执行、加载地址随机化 - 进程通信:支持轻量级LiteIPC,同时也支持标准的Mqueue、Pipe、Fifo、Signal等机制 -- 系统调用:支持170+系统调用 ,同时有支持VDSO机制 +- 系统调用:支持170+系统调用,同时有支持VDSO机制 - 权限管理:支持进程粒度的特权划分和管控,UGO三种权限配置 diff --git a/zh-cn/device-dev/kernel/kernel-small-start-kernel.md b/zh-cn/device-dev/kernel/kernel-small-start-kernel.md index 7fb58fa0b65aed49254a6aa3ac51931bdd8deeb5..484ecce12ecd68e3714e4f24edd533b15568ca27 100644 --- a/zh-cn/device-dev/kernel/kernel-small-start-kernel.md +++ b/zh-cn/device-dev/kernel/kernel-small-start-kernel.md @@ -86,7 +86,7 @@

LOS_INIT_LEVEL_KMOD_TASK

内核任务创建

-

说明:进行内核任务的创建(内核线程,软件定时器任务)

+

说明:进行内核任务的创建(内核任务,软件定时器任务)

例如:资源回收系统常驻任务的创建、SystemInit任务创建、CPU占用率统计任务创建