1e41f4b71Sopenharmony_ci# Related Thread Group
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci
4e41f4b71Sopenharmony_ci## Basic Concepts
5e41f4b71Sopenharmony_ci
6e41f4b71Sopenharmony_ciThe 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.
7e41f4b71Sopenharmony_ci
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci## Configuration
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci### Enabling RTG
12e41f4b71Sopenharmony_ciTo enable RTG, you need to enable the related configuration items and dependencies during kernel compilation. The related configuration items are as follows:
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci```
15e41f4b71Sopenharmony_ciCONFIG_SCHED_RTG=y
16e41f4b71Sopenharmony_ciCONFIG_SCHED_RTG_DEBUG=y
17e41f4b71Sopenharmony_ciCONFIG_SCHED_RTG_FRAME=y
18e41f4b71Sopenharmony_ciCONFIG_SCHED_RTG_RT_THREAD_LIMIT=y
19e41f4b71Sopenharmony_ci```
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ciEnable the following dependencies:
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_ci```
24e41f4b71Sopenharmony_ciCONFIG_SCHED_WALT=y
25e41f4b71Sopenharmony_ci```
26e41f4b71Sopenharmony_ci### Adding a Process or Thread to an RTG
27e41f4b71Sopenharmony_ci
28e41f4b71Sopenharmony_ciBy 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.
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ci```Bash
31e41f4b71Sopenharmony_ci// Add a process to an RTG.
32e41f4b71Sopenharmony_ciecho 2 > /proc/<pid>/sched_group_id
33e41f4b71Sopenharmony_ci// Remove a process from an RTG. The group with ID of 0 is not an RTG.
34e41f4b71Sopenharmony_ciecho 0 > /proc/<pid>/sched_group_id
35e41f4b71Sopenharmony_ci```
36e41f4b71Sopenharmony_ci### Obtaining RTG Information
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ciThe RTG information includes group ID, preferred CPU cluster ID, and thread information.
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci  ```Bash
41e41f4b71Sopenharmony_cicat /proc/sched_rtg_debug
42e41f4b71Sopenharmony_ci// The following information is displayed:
43e41f4b71Sopenharmony_ciRTG_ID          : 2                          // RTG ID.
44e41f4b71Sopenharmony_ciRTG_INTERVAL    : UPDATE:8ms\#INVALID:4294ms // CPU frequency modulation interval and valid load duration.
45e41f4b71Sopenharmony_ciRTG_CLUSTER     : -1                        // CPU cluster ID. The value **-1** means that the preferred cluster is not set.
46e41f4b71Sopenharmony_ciRTG_THREADS: 0/1                          // Total number of threads in the group.
47e41f4b71Sopenharmony_ciSTATE           COMM       PID  PRIO    CPU  // Thread information, including the status, name, PID, priority, and CPU ID.
48e41f4b71Sopenharmony_ci---------------------------------------------------------
49e41f4b71Sopenharmony_ci    S            bash   436   120     1(0-3)
50e41f4b71Sopenharmony_ci  ```
51