未验证 提交 f1fff312 编写于 作者: O openharmony_ci 提交者: Gitee

!2870 #I4XP51完成,请审批

Merge pull request !2870 from Annie_wang/PR1996+
......@@ -177,4 +177,6 @@
- [Enhanced Kernel Features](kernel-standard-enhanced-features.md)
- [Memory Management](kernel-standard-mm.md)
- [Enhanced SWAP](kernel-standard-mm-eswap.md)
\ No newline at end of file
- [Task Scheduling](kernel-standard-sched.md)
- [Related Thread Group](kernel-standard-sched-rtg.md)
- [Lightweight CPU Isolation](kernel-standard-sched-cpuisolation.md)
\ No newline at end of file
# Lightweight CPU Isolation
## Basic Concepts
Lightweight CPU isolation enables dynamic CPU isolation based on the system load and user configuration. The kernel migrates the tasks and interrupts from the isolated CPU to other CPUs for execution. The isolated CPU enters the idle state, which reduces the power consumption. In addition, user-mode configuration and query APIs are provided for better system optimization.
## Configuration
### Enabling Lightweight CPU Isolation
Enable related configuration items and dependencies.
To enable lightweight CPU isolation, you need to enable the corresponding configuration items and dependencies during kernel compilation. The related configuration items are as follows:
```
CONFIG_CPU_ISOLATION_OPT=y
CONFIG_SCHED_CORE_CTRL=y
```
Enable the following dependencies:
```
CONFIG_SMP=y
CONFIG_SCHED_WALT=y
```
## Available APIs
APIs are provided to set the number of isolated CPU cores and record the current status. Configurations can be performed based on CPU clusters. These APIs are located in the first CPU device directory of each CPU cluster, for example, `/sys/devices/system/cpu/cpu0/core_ctl`.
| Category| API | Description |
| ---- | ------------ | ---------------------------------------- |
| Control API| enable | Enables or disables the lightweight CPU isolation. The value **1** means enable, and **0** means disable. |
| | min_cpus | Sets the minimum number of active (not isolated) CPUs. |
| | max_cpus | Sets the maximum number of active (not isolated) CPUs. The maximum value is the number of CPUs in a CPU cluster.|
| Status API| active_cpus | Obtains the number of active (not isolated) CPUs. |
| | need_cpus | Obtains the number of CPUs to de-isolate. |
| | global_state | Records the status of all CPU clusters in the system, including the CPU isolation status, online status, and load information.|
# Related Thread Group
## Basic Concepts
The Related Thread Group (RTG) provides optimized scheduling of a group of important threads. The load of an RTG can be collected and predicted separately and the preferred CPU cluster can be set to allow the important threads to run on the optimal CPU and the kernel to select a proper CPU frequency based on the group loads.
## Configuration
### Enabling RTG
To enable RTG, you need to enable the related configuration items and dependencies during kernel compilation. The related configuration items are as follows:
```
CONFIG_SCHED_RTG=y
CONFIG_SCHED_RTG_DEBUG=y
CONFIG_SCHED_RTG_FRAME=y
CONFIG_SCHED_RTG_RT_THREAD_LIMIT=y
```
Enable the following dependencies:
```
CONFIG_SCHED_WALT=y
```
### Adding a Process or Thread to an RTG
By default, 20 RTGs are created in the kernel. The group with ID of 1 is reserved and cannot be added with any process or thread.
```Bash
// Add a process to an RTG.
echo 2 > /proc/<pid>/sched_group_id
// Remove a process from an RTG. The group with ID of 0 is not an RTG.
echo 0 > /proc/<pid>/sched_group_id
```
### Obtaining RTG Information
The RTG information includes group ID, preferred CPU cluster ID, and thread information.
```Bash
cat /proc/sched_rtg_debug
// The following information is displayed:
RTG_ID : 2 // RTG ID.
RTG_INTERVAL : UPDATE:8ms\#INVALID:4294ms // CPU frequency modulation interval and valid load duration.
RTG_CLUSTER : -1 // CPU cluster ID. The value **-1** means that the preferred cluster is not set.
RTG_THREADS: 0/1 // Total number of threads in the group.
STATE COMM PID PRIO CPU // Thread information, including the status, name, PID, priority, and CPU ID.
---------------------------------------------------------
S bash 436 120 1(0-3)
```
## Available APIs
The RTG provides the device node and ioctl APIs for querying and configuring group information. The device node is in `/dev/sched_rtg_ctrl`.
| Device Node | request | Description |
| ------------------- | ------------------- | ------------------- |
| /dev/sched_rtg_ctrl | CMD_ID_SET_RTG | Creates an RTG, and adds, updates, or deletes threads in the group. |
| | CMD_ID_SET_CONFIG | Configures global group attributes, for example, the maximum number of real-time RTGs.|
| | CMD_ID_SET_RTG_ATTR | Configures specified group attributes, for example, the thread priority. |
| | CMD_ID_SET_MIN_UTIL | Sets the minimum utilization of an RTG. |
# Task Scheduling
- **[Related Thread Group](kernel-standard-sched-rtg.md)**
- **[Lightweight CPU Isolation](kernel-standard-sched-cpuisolation.md)**
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册