• Home
Name Date Size #Lines LOC

..--

cgroup_sched/12-May-2024-5,0733,752

figures/12-May-2024-

ressched/12-May-2024-9,7206,458

soc_perf/12-May-2024-4,6443,318

.gitignoreD12-May-202414 21

CODEOWNERSD12-May-2024979 1715

LICENSED12-May-202410.1 KiB177150

OAT.xmlD12-May-20245.6 KiB8534

README.mdD12-May-202411.1 KiB208167

README_ZH.mdD12-May-202412.7 KiB229181

Resource_Schedule_Service_Process_Management_Specifications_ZH.mdD12-May-202418.2 KiB319160

bundle.jsonD12-May-20245.6 KiB141140

README.md

1# Resource Schedule Service
2
3- [Resource Schedule Service](#resource-schedule-service)
4  - [Introduction<a name="section11660541593"></a>](#introduction)
5  - [Directory Structure<a name="section161941989596"></a>](#directory-structure)
6  - [How to write a plugin<a name="section1312121216216"></a>](#how-to-write-a-plugin)
7    - [Available APIs<a name="section114564657874"></a>](#available-apis)
8    - [Usage Guidelines<a name="section129654513264"></a>](#usage-guidelines)
9      - [Restrictions on Using Transient Tasks<a name="section1551164914237"></a>](#restrictions-on-using-transient-tasks)
10  - [Cgroup Schedule Policy](#cgroup-schedule-policy)
11    - [Basic Policy](#basic-policy)
12    - [Policy Configuration](#policy-configuration)
13    - [Restrictions](#restrictions)
14  - [SocPerf](#socperf)
15    - [Interfaces](#interfaces)
16    - [Configs](#configs)
17  - [Repositories Involved<a name="section1371113476307"></a>](#repositories-involved)
18
19## Introduction<a name="section11660541593"></a>
20
21In the resourceschedule subsystem, it provides the awareness and distribution of system events, such as application start, exit, screen on and off, etc.
22If you need to obtain system events and perform related resource schedule, you can choose to join the resource schedule service in the form of a plugin.
23
24In resource schedule subsystem, the module of cgroup schedule decides the group schedule policy of each process by analyzing application state, window status and background task status. And with proper configuration, it can bind each process to certain cgroup node. These schedule policies can be used to gain better performance. And this module forward different kinds of events to plugin manager and then be distributed to subscribers.
25
26Resource_schedule_service is an engine that receives events, decides schedule policies and executes schedule mechanisms. It's architecture is shown as follows:
27 ![img](figures/resource_schedule_service_architecture.png)
28It consists of the following important parts:
291. Event manager, which includes the function of using external interfaces to sense system events, as well as the function of using listening forms to sense system events.
302. Application intelligent grouping, which receives the event of application life cycle change and decides the priority of application grouping, is the fundamental basis for global resource schedule.
313. Plugin manager, which is responsible for loading the resource schedule plugin corresponding to the product, receiving system and application events, and distributing events to the plugin according to the plugin subscription.
324. Soc_perf service, which receives frequency modulation events from the related plugin, arbitration the frequency value, and finally uses the kernel interface to set the CPU frequency.
33
34Resource_schedule_service policy is mainly used to extend and schedule the system's global resources with related plugins. Plugins run in the form of dynamic-link, and different users can choose different plugin combinations. At present, the existing plugins include: intelligent perception schedule plugin, device's status management plugin, and soc_perf plugin.The soc_perf plugin is implemented in resource_schedule_service code repository, while the other two plugins are implemented in other code repositories. However, system events are used as the basis for setting schedule policies to the system kernel.
35
36## Directory Structure<a name="section161941989596"></a>
37
38```
39</foundation/resourceschedule/resource_schedule_service>
40├── cgroup_sched
41|   ├── common
42|   │   └── include                   # common header files
43|   ├── framework
44|   │   ├── process_group             # utils to set cgroup by pid
45|   │   ├── sched_controller          # cgroup schedule
46|   │   └── utils                     # adaption interface to forwarding data
47|   │       ├── include
48|   │       │   └── ressched_utils.h  # event report header files
49|   │       └── ressched_utils.cpp    # event report interface
50|   ├── interfaces                    # Init/Denit/Query interface for rss
51|   │   └── innerkits                 # Interface APIs
52|   └── profiles                      # config files
53└── ressched
54|   ├── common                        # Common header file
55|   ├── interfaces
56|   │   └── innerkits                 # Interface APIs
57|   │       └── ressched_client       # Report data in process
58|   ├── plugins                       # Plugin code
59|   ├── profile                       # Plugin switch xml and plugin private xml
60|   ├── sa_profile                    # System ability xml
61|   ├── sched_controller              # event receive
62|   |   ├── common_event              # event receive common interface
63|   |   └── observer                  # callback event receive
64|   |       ├── audio_observer        # audio framework event callback
65|   |       ├── camera_observer       # camera event callback
66|   |       └── telephony_observer    # telephony event callback
67|   └── services
68|       ├── resschedmgr
69|       │   ├── pluginbase            # Plugin struct definition
70|       │   └── resschedfwk           # Resource schedule framework
71|       └── resschedservice           # Resource schedule service
72└── soc_perf
73    ├── common                        # Common header file
74    ├── interfaces                    #
75    │   └── inner_api                 # Interface APIs
76    │       └── socperf_client        # SocPerf Client interfaces
77    ├── profile                       # SocPerf config file
78    ├── sa_profile                    # System ability xml
79    ├── services
80        ├── core                      # SocPerf core code, arbitrate and take effects
81        └── server                    # SocPerf server codes
82
83```
84## How to write a plugin<a name="section1312121216216"></a>
85
86### Available APIs<a name="section114564657874"></a>
87
88| API                                                                           | Description                      |
89|-------------------------------------------------------------------------------|----------------------------------|
90| function OnPluginInit(std::string& libName): bool;                            | plugin init                      |
91| function OnPluginDisable(): void;                                             | plugin disable                   |
92| function OnDispatchResource(const std::shared_ptr\<ResData\>& data):void;       | dispatch resource event          |
93
94### Usage Guidelines<a name="section129654513264"></a>
95
96When the plugin is initialized, specify the events that need to be registered for monitoring. When these events occur, the framework will be distributed to each plugin in turn,
97
98At this point, the plugin needs to quickly process message reception for resource schedule (if time-consuming tasks need to be processed by another thread), and the processing is completed, return.
99
100#### Restrictions on Using Transient Tasks<a name="section1551164914237"></a>
101
1021. The plugin can be implemented with C/C++.
103
1042. The event processing of the plugin must be completed quickly. If it exceeds 1ms, warning will be printed.
105If it exceeds 10ms, the framework thinks the plugin is abnormal and reports an error.
106
107## Cgroup Schedule Policy
108
109### Basic Policy
110
111| Scene  | Schedule policy  |
112|----------|-------|
113| Currently focused oreground application and processes with same uid  | top_app  |
114| Foreground visible processes, include unfocused window process in split mode, float window process, foundation process  | foreground  |
115| system level daemon processes. Assign system schedule policy to them when started,   | system  |
116| Background application and processes with same uid | background |
117| kernel processes, most native processes and others have not mensioned | root |
118
119### Policy Configuration
120
121Each schedule policy is configured in a json file, and is bound to different cgroup.
122```
123  "Cgroups": [
124    {
125      "controller": "cpu",
126      "path": "/dev/cpuctl",
127      "sched_policy": {
128        "sp_default": "",
129        "sp_background": "background",
130        "sp_foreground": "foreground",
131        "sp_system_background": "system-background",
132        "sp_top_app": "top-app"
133      }
134    },
135    {
136      "controller": "cpuset",
137      "path": "/dev/cpuset",
138      "sched_policy": {
139        "sp_default": "",
140        "sp_background": "background",
141        "sp_foreground": "foreground",
142        "sp_system_background": "system-background",
143        "sp_top_app": "top-app"
144      }
145    }
146  ]
147```
148
149### Restrictions
150
151Configuration file: cgroup_action_config.json
152Every schedule policy defined should be configured.
153
154Introduction to each config item:
155
156| Item | Description |
157|--------|--------|
158|controller|cgroup controller: cpuset, cpuctl, blkio etc.|
159|path|Absolute path of current cgroup|
160|sched_policy|Binding between each schedule policy and cgroup|
161|sp_xx|Different kinds of schedule policy|
162
163## SocPerf
164
165### Interfaces
166
167Supported SocPerf interfaces description
168
169| Interface  | Description  |
170|----------|-------|
171| PerfRequest(int32_t cmdId, const std::string& msg) | Used for Performace boost freq |
172| PerfRequestEx(int32_t cmdId, bool onOffTag, const std::string& msg) | Used for Performace boost freq and support ON/OFF |
173| PowerLimitBoost(bool onOffTag, const std::string& msg) | Used for Power limit freq which cannot be boosted |
174| ThermalLimitBoost(bool onOffTag, const std::string& msg) | Used for Thermal limit freq which cannot be boosted |
175| LimitRequest(int32_t clientId, const std::vector<int32_t>& tags, const std::vector<int64_t>& configs, const std::string& msg) | Used for Power or Thermal limit freq and multiple freq items can be set together |
176
177All interfaces are based on the key parameter cmdID, cmdID connects scenes and configs, which is used to boost freq or limit freq.
178Interface with parameter onOffTag means it support ON/OFF event. Normally, these interfaces are used for long-term event,
179which needs user to turn on or turn off manually.
180Parameter msg is used for extra information, like client's pid and tid.
181
182### Configs
183
184Config files description
185
186| File  | Description  |
187|----------|-------|
188| socperf_resource_config.xml | Define resource which can be modify,such as CPU/GPU/DDR/NPU |
189| socperf_boost_config.xml | Config file used for Performace boost |
190
191All xml files are different for particular products.
192For specific product, all resources which could be modify are defined in socperf_resource_config.xml. Each resource has its own resID.
193The cmdID in the socperf_boost_config.xml/socperf_resource_config.xml/socperf_thermal_config.xml must be different.
194
195## callback event receive
196Now support audio frameWork event、 telephony event、camera event callback
197
198audio frameWork contains renserState change、 ringMode change、 volumeKey change
199
200telphony change
201
202camera change
203
204## Repositories Involved<a name="section1371113476307"></a>
205- [windowmanager](https://gitee.com/openharmony/windowmanager)
206- [communication_ipc](https://gitee.com/openharmony/communication_ipc)
207- [hiviewdfx_hilog](https://gitee.com/openharmony/hiviewdfx_hilog)
208

README_ZH.md

1# 资源调度服务
2
3- [资源调度服务](#资源调度服务)
4  - [简介<a name="section11660541593"></a>](#简介)
5  - [目录<a name="section161941989596"></a>](#目录)
6  - [如何编写一个插件<a name="section1312121216216"></a>](#如何编写一个插件)
7    - [接口说明<a name="section114564657874"></a>](#接口说明)
8    - [使用说明<a name="section129654513264"></a>](#使用说明)
9      - [插件事件处理约束<a name="section1551164914237"></a>](#插件事件处理约束)
10  - [分组策略](#分组策略)
11    - [基础分组策略](#基础分组策略)
12    - [策略配置](#策略配置)
13    - [配置约束](#配置约束)
14  - [统一调频](#统一调频)
15    - [调频接口说明](#调频接口说明)
16    - [调频配置说明](#调频配置说明)
17    - [调频使用举例](#调频使用举例)
18  - [相关仓<a name="section1371113476307"></a>](#相关仓)
19
20## 简介<a name="section11660541593"></a>
21
22在资源调度子系统中,提供系统事件的感知以及分发,例如应用启动、退出、亮灭屏等。如果需要获取系统事件,并且进行相关资源调度,那么可以选择以插件形式加入资源调度服务中。
23
24作为资源调度子系统的子模块,智能分组模块通过系统内应用前后台切换、用户焦点输入、后台任务的执行状态,决策进程的分组调度策略,并支持通过配置将调度策略映射到不同的CGROUP分组,为系统的性能、功耗均衡调度提供决策依据。同时该模块向资源调度框架转发应用状态、焦点状态、后台任务状态等系统事件,供插件订阅。
25
26resource_schedule_service是接收事件,决策调度策略和执行调度机制的引擎,其架构图示如下:
27 ![img](figures/resource_schedule_service_architecture_ZH.png)
28其中包括以下几个重要组成部分:
291、事件管理器,包含了使用对外接口直接感知系统事件,以及使用监听形式感知系统事件功能。
302、应用智能分组,该组件接收应用生命周期变更的事件,决策应用的分组优先级,是全局资源调度的根本依据。
313、插件管理器,负责产品对应资源调度插件的加载,接收系统和应用的事件,并根据插件的订阅情况将事件分发给插件。
324、SOC统一调频服务,该服务主要是从SOC统一调频插件中接收调频事件,进行相关的调频仲裁,最终使用内核接口设置CPU频率策略。
33
34resource_schedule_service主要通过插件的形式进行扩展和实现系统全局资源的调度功能,插件以动态链接的形式运行,不同产品可以选择不同的插件进行加载。目前已知的插件有智能感知调度插件、设备状态管理插件、SOC统一调频插件。其中SOC统一调频插件的服务包含在resource_schedule_service中,而另外两个插件的服务包含在其它仓内,最终都是根据系统事件设置调度策略到内核中进行实施。
35
36## 目录<a name="section161941989596"></a>
37
38```
39/foundation/resourceschedule/resource_schedule_service
40├── cgroup_sched
41|   ├── common
42|   │   └── include                   # 公共头文件
43|   ├── framework                     # 主体代码
44|   │   ├── process_group             # 分组设置接口
45|   │   ├── sched_controller          # 分组计算
46|   │   └── utils                     # RSS数据转发适配接口
47|   │       ├── include
48|   │       │   └── ressched_utils.h  # 事件上报头文件
49|   │       └── ressched_utils.cpp    # 事件上报接口
50|   ├── interfaces                    # 供RSS初始化、查询分组接口
51|   │   └── innerkits                 # 对外接口目录
52|   └── profiles                      # 配置文件
53└── ressched
54|   ├── common                        # 公共头文件
55|   ├── interfaces
56|   │   └── innerkits                 # 对外接口目录
57|   │       └── ressched_client       # 外部同步事件通知接口
58|   ├── plugins                       # 插件代码实现
59|   ├── profile                       # 插件开关以及私有配置
60|   ├── sa_profile                    # 系统元能力配置
61|   ├── sched_controller              # 事件采集
62|   |   ├── common_event              # 事件采集公共接口
63|   |   └── observer                  # 监听事件采集
64|   |       ├── audio_observer        # 音频事件监听回调
65|   |       ├── camera_observer       # 相机事件监听回调
66|   |       └── telephony_observer    # 电话状态监听回调
67|   └── services
68|       ├── resschedmgr
69|       │   ├── pluginbase            # 插件结构定义
70|       │   └── resschedfwk           # 资源调度服务框架实现
71|       └── resschedservice           # 资源调度服务层
72└── soc_perf
73    ├── common                        # 公共头文件
74    ├── interfaces
75    │   └── inner_api                 # 对外接口目录
76    │       └── socperf_client        # SocPerf客户端代码,给调用者使用的接口
77    ├── profile                       # 调频配置文件
78    ├── sa_profile                    # 系统元能力配置
79    ├── services
80        ├── core                      # SocPerf核心业务逻辑代码,仲裁并生效最终的调频结果
81        └── server                    # SocPerf服务端代码,用于接受客户端发送的调频请求
82```
83## 如何编写一个插件<a name="section1312121216216"></a>
84
85### 接口说明<a name="section114564657874"></a>
86
87| 接口名                                                                        | 接口描述                         |
88|-------------------------------------------------------------------------------|----------------------------------|
89| function OnPluginInit(std::string& libName): bool;                            | 插件初始化                       |
90| function OnPluginDisable(): void;                                             | 插件退出                         |
91| function OnDispatchResource(const std::shared_ptr\<ResData\>& data):void;       | 获取分发的事件                   |
92
93### 使用说明<a name="section129654513264"></a>
94
95插件初始化的时候,指定需要注册监听的事件。在这些事件发生的时候,框架会依次分发给各个插件,
96此时插件需要快速处理消息接收进行资源调度(需要有耗时任务则需另起线程处理),处理完成后返回。
97
98#### 插件事件处理约束<a name="section1551164914237"></a>
99
1001、插件可以用C/C++实现。
101
1022、插件的事件处理,必须快速完成,超过1ms会打印相关告警,超过10ms,框架认为插件异常而进行插件退出操作。
103
104## 分组策略
105
106### 基础分组策略
107
108| 场景描述  | 分组策略  |
109|----------|-------|
110| 前台焦点应用,UID相同的进程  | top_app  |
111| 前台可见的,包括分屏场景下的非焦点应用进程、悬浮窗对应的进程、foundation进程等  | foreground  |
112| 一些系统级后台常驻进程,不由分组计算主动设置。在rc/cfg文件中写定,直接写入system分组   | system  |
113| 退到后台的前一个应用,及其相关的进程  | background |
114| OS内核和其他native进程,以及上面没有涉及到的一些进程 | root |
115
116### 策略配置
117
118通过JSON配置文件,对每个分组策略,绑定指定的CGROUP分组。
119```
120  "Cgroups": [
121    {
122      "controller": "cpu",
123      "path": "/dev/cpuctl",
124      "sched_policy": {
125        "sp_default": "",
126        "sp_background": "background",
127        "sp_foreground": "foreground",
128        "sp_system_background": "system-background",
129        "sp_top_app": "top-app"
130      }
131    },
132    {
133      "controller": "cpuset",
134      "path": "/dev/cpuset",
135      "sched_policy": {
136        "sp_default": "",
137        "sp_background": "background",
138        "sp_foreground": "foreground",
139        "sp_system_background": "system-background",
140        "sp_top_app": "top-app"
141      }
142    }
143  ]
144```
145
146### 配置约束
147
148策略配置路径:cgroup_action_config.json文件; 每个sp_xxx策略都需要配置
149
150配置参数说明:
151
152| 配置项 | 说明 |
153|--------|--------|
154|controller|当前配置项对应的cgroup分组控制器|
155|path|cgroup分组对应的路径|
156|sched_policy|不同分组调度策略对应到的具体分组|
157|sp_xx|不同分组调度策略标识|
158
159## 统一调频
160
161### 调频接口说明
162
163当前可支持的调频接口说明
164
165| 接口  | 说明  |
166|----------|-------|
167| PerfRequest(int32_t cmdId, const std::string& msg) | 用于性能提频使用 |
168| PerfRequestEx(int32_t cmdId, bool onOffTag, const std::string& msg) | 用于性能提频使用且支持ON/OFF事件 |
169| PowerLimitBoost(bool onOffTag, const std::string& msg) | 用于限制boost无法突破功耗限频 |
170| ThermalLimitBoost(bool onOffTag, const std::string& msg) | 用于限制boost无法突破热限频 |
171| LimitRequest(int32_t clientId, const std::vector<int32_t>& tags, const std::vector<int64_t>& configs, const std::string& msg) | 用于热或功耗模块的限频且支持多项值一同设置 |
172
173如表格所示,所有的调频接口都以cmdID为核心,将调频场景和调频参数互相关联,实现提频或者限频的功能。
174带onOffTag参数的接口表示该接口支持ON/OFF的开关调频模式,一般用于生效时间不固定的长期调频事件,需要调用者手动开启或者关闭。
175msg参数为拓展字符串信息,可承载例如调用客户端pid/tid等信息。
176
177### 调频配置说明
178
179当前configs目录下的配置文件
180
181| 配置文件  | 说明  |
182|----------|-------|
183| socperf_resource_config.xml | 定义产品可支持的资源配置,例如CPU/GPU/DDR/NPU等 |
184| socperf_boost_config.xml | 用于性能提频的配置文件 |
185
186各个xml配置文件都需要按产品定制,不同产品的配置不相同。
187对于指定的某产品,所有可支持配置的资源都定义在socperf_resource_config.xml内,支持单路径/多路径配置,任何资源都有唯一的resID。
188socperf_boost_config.xml使用的cmdID不能重复。
189
190### 调频使用举例
191
192以点击提频事件为例。
193
194点击场景提频为固定生效时间,无需使用ON/OFF手动开启或关闭,故使用PerfRequest接口即可。因此需要在合适的地方调用soc_perf提供的IPC接口PerfRequest实现提频请求。
195
196资源调度服务对所有事件的采集有统一的入口,即资源调度框架对订阅事件的插件进行分发的机制,调频服务也依赖该机制实现对于各个需要调频的场景的感知。
197
198调频服务已实现为一个单独的调频插件socperf_plugin,定义在/ressched/plugins/socperf_plugin目录下。
199要实现点击场景的提频,分为点击事件插桩、事件上报给资源调度框架、框架给插件分发事件、生效调频服务四个步骤。
200
201第一步,
202ACE子系统仓内实现了对资源调度框架提供的可动态加载接口ReportData的封装,路径为/framework/base/ressched/ressched_report.h
203并在/framework/core/gestures/click_recognizer.cpp增加了打点作为手势识别中对点击事件的判定
204
205第二步,
206通过动态加载libressched_client.z.so,调用资源调度框架提供的接口ReportData,ACE子系统将点击事件上报给全局资源调度子系统
207
208第三步,
209在资源调度框架里,点击事件类型定义在/ressched/interfaces/innerkits/ressched_client/include/res_type.h内,为RES_TYPE_CLICK_RECOGNIZE
210由于调频插件socperf_plugin在初始化过程中已完成了对该点击事件的订阅,因此框架会在接受到事件通知时将点击事件分发给调频插件
211
212第四步,
213调频插件socperf_plugin对于点击事件分配了cmdID:PERF_REQUEST_CMD_ID_EVENT_CLICK,路径在/ressched/plugins/socperf_plugin/src/socperf_plugin.cpp214通过调用调频服务提供的IPC接口PerfRequest,插件会给调频服务发送请求,实现点击提频功能。
215
216## 监听事件采集
217目前支持音频框架相关事件、电话子系统相关事件、相机相关事件监听回调,
218
219监听音频框架中音频流状态变化、声音模式变化和整机声音变化
220
221监听电话状态变化
222
223监听相机状态变化
224
225## 相关仓<a name="section1371113476307"></a>
226- [windowmanager](https://gitee.com/openharmony/windowmanager)
227- [communication_ipc](https://gitee.com/openharmony/communication_ipc)
228- [hiviewdfx_hilog](https://gitee.com/openharmony/hiviewdfx_hilog)
229