• Home
Name Date Size #Lines LOC

..--

cgroup_sched/12-May-2024-4,5183,341

figures/12-May-2024-

ressched/12-May-2024-7,8075,078

soc_perf/12-May-2024-3,4422,600

.gitignoreD12-May-202414 21

LICENSED12-May-202410.1 KiB177150

OAT.xmlD12-May-20245.6 KiB8534

README.mdD12-May-202411.1 KiB209168

README_ZH.mdD12-May-202412.7 KiB231182

Resource_Schedule_Service进程管理规范.mdD12-May-202416.1 KiB311150

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    ├── configs                     # socperf config file
74    ├── include
75    |       ├── client              # socperf client header files
76    |       ├── server              # socperf server header files
77    |       └── server              # socperf core code header files
78    ├── src
79    |    ├── client                 # socperf Client interfaces
80    |    ├── server                 # socperf Server codes
81    |    └── server                 # core code, arbitrate and take effects
82    └── sa_profile                  # System ability xml
83
84```
85## How to write a plugin<a name="section1312121216216"></a>
86
87### Available APIs<a name="section114564657874"></a>
88
89| API                                                                           | Description                      |
90|-------------------------------------------------------------------------------|----------------------------------|
91| function OnPluginInit(std::string& libName): bool;                            | plugin init                      |
92| function OnPluginDisable(): void;                                             | plugin disable                   |
93| function OnDispatchResource(const std::shared_ptr\<ResData\>& data):void;       | dispatch resource event          |
94
95### Usage Guidelines<a name="section129654513264"></a>
96
97When 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,
98
99At 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.
100
101#### Restrictions on Using Transient Tasks<a name="section1551164914237"></a>
102
1031. The plugin can be implemented with C/C++.
104
1052. The event processing of the plugin must be completed quickly. If it exceeds 1ms, warning will be printed.
106If it exceeds 10ms, the framework thinks the plugin is abnormal and reports an error.
107
108## Cgroup Schedule Policy
109
110### Basic Policy
111
112| Scene  | Schedule policy  |
113|----------|-------|
114| Currently focused oreground application and processes with same uid  | top_app  |
115| Foreground visible processes, include unfocused window process in split mode, float window process, foundation process  | foreground  |
116| system level daemon processes. Assign system schedule policy to them when started,   | system  |
117| Background application and processes with same uid | background |
118| kernel processes, most native processes and others have not mensioned | root |
119
120### Policy Configuration
121
122Each schedule policy is configured in a json file, and is bound to different cgroup.
123```
124  "Cgroups": [
125    {
126      "controller": "cpu",
127      "path": "/dev/cpuctl",
128      "sched_policy": {
129        "sp_default": "",
130        "sp_background": "background",
131        "sp_foreground": "foreground",
132        "sp_system_background": "system-background",
133        "sp_top_app": "top-app"
134      }
135    },
136    {
137      "controller": "cpuset",
138      "path": "/dev/cpuset",
139      "sched_policy": {
140        "sp_default": "",
141        "sp_background": "background",
142        "sp_foreground": "foreground",
143        "sp_system_background": "system-background",
144        "sp_top_app": "top-app"
145      }
146    }
147  ]
148```
149
150### Restrictions
151
152Configuration file: cgroup_action_config.json
153Every schedule policy defined should be configured.
154
155Introduction to each config item:
156
157| Item | Description |
158|--------|--------|
159|controller|cgroup controller: cpuset, cpuctl, blkio etc.|
160|path|Absolute path of current cgroup|
161|sched_policy|Binding between each schedule policy and cgroup|
162|sp_xx|Different kinds of schedule policy|
163
164## SocPerf
165
166### Interfaces
167
168Supported SocPerf interfaces description
169
170| Interface  | Description  |
171|----------|-------|
172| PerfRequest(int32_t cmdId, const std::string& msg) | Used for Performace boost freq |
173| PerfRequestEx(int32_t cmdId, bool onOffTag, const std::string& msg) | Used for Performace boost freq and support ON/OFF |
174| PowerLimitBoost(bool onOffTag, const std::string& msg) | Used for Power limit freq which cannot be boosted |
175| ThermalLimitBoost(bool onOffTag, const std::string& msg) | Used for Thermal limit freq which cannot be boosted |
176| 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 |
177
178All interfaces are based on the key parameter cmdID, cmdID connects scenes and configs, which is used to boost freq or limit freq.
179Interface with parameter onOffTag means it support ON/OFF event. Normally, these interfaces are used for long-term event,
180which needs user to turn on or turn off manually.
181Parameter msg is used for extra information, like client's pid and tid.
182
183### Configs
184
185Config files description
186
187| File  | Description  |
188|----------|-------|
189| socperf_resource_config.xml | Define resource which can be modify,such as CPU/GPU/DDR/NPU |
190| socperf_boost_config.xml | Config file used for Performace boost |
191
192All xml files are different for particular products.
193For specific product, all resources which could be modify are defined in socperf_resource_config.xml. Each resource has its own resID.
194The cmdID in the socperf_boost_config.xml/socperf_resource_config.xml/socperf_thermal_config.xml must be different.
195
196## callback event receive
197Now support audio frameWork event、 telephony event、camera event callback
198
199audio frameWork contains renserState change、 ringMode change、 volumeKey change
200
201telphony change
202
203camera change
204
205## Repositories Involved<a name="section1371113476307"></a>
206- [windowmanager](https://gitee.com/openharmony/windowmanager)
207- [communication_ipc](https://gitee.com/openharmony/communication_ipc)
208- [hiviewdfx_hilog](https://gitee.com/openharmony/hiviewdfx_hilog)
209

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    ├── configs                     # 调频配置文件
74    ├── include
75    |       ├── client              # SocPerf客户端头文件
76    |       ├── server              # SocPerf服务端头文件
77    |       └── server              # SocPerf核心逻辑代码头文件
78    ├── src
79    |    ├── client                 # SocPerf客户端代码,给调用者使用的接口
80    |    ├── server                 # SocPerf服务器代码,用于接受客户端发送的调频请求
81    |    └── server                 # SocPerf核心业务逻辑代码,仲裁并生效最终的调频结果
82    └── sa_profile                  # 系统元能力配置
83
84```
85## 如何编写一个插件<a name="section1312121216216"></a>
86
87### 接口说明<a name="section114564657874"></a>
88
89| 接口名                                                                        | 接口描述                         |
90|-------------------------------------------------------------------------------|----------------------------------|
91| function OnPluginInit(std::string& libName): bool;                            | 插件初始化                       |
92| function OnPluginDisable(): void;                                             | 插件退出                         |
93| function OnDispatchResource(const std::shared_ptr\<ResData\>& data):void;       | 获取分发的事件                   |
94
95### 使用说明<a name="section129654513264"></a>
96
97插件初始化的时候,指定需要注册监听的事件。在这些事件发生的时候,框架会依次分发给各个插件,
98此时插件需要快速处理消息接收进行资源调度(需要有耗时任务则需另起线程处理),处理完成后返回。
99
100#### 插件事件处理约束<a name="section1551164914237"></a>
101
1021、插件可以用C/C++实现。
103
1042、插件的事件处理,必须快速完成,超过1ms会打印相关告警,超过10ms,框架认为插件异常而进行插件退出操作。
105
106## 分组策略
107
108### 基础分组策略
109
110| 场景描述  | 分组策略  |
111|----------|-------|
112| 前台焦点应用,UID相同的进程  | top_app  |
113| 前台可见的,包括分屏场景下的非焦点应用进程、悬浮窗对应的进程、foundation进程等  | foreground  |
114| 一些系统级后台常驻进程,不由分组计算主动设置。在rc/cfg文件中写定,直接写入system分组   | system  |
115| 退到后台的前一个应用,及其相关的进程  | background |
116| OS内核和其他native进程,以及上面没有涉及到的一些进程 | root |
117
118### 策略配置
119
120通过JSON配置文件,对每个分组策略,绑定指定的CGROUP分组。
121```
122  "Cgroups": [
123    {
124      "controller": "cpu",
125      "path": "/dev/cpuctl",
126      "sched_policy": {
127        "sp_default": "",
128        "sp_background": "background",
129        "sp_foreground": "foreground",
130        "sp_system_background": "system-background",
131        "sp_top_app": "top-app"
132      }
133    },
134    {
135      "controller": "cpuset",
136      "path": "/dev/cpuset",
137      "sched_policy": {
138        "sp_default": "",
139        "sp_background": "background",
140        "sp_foreground": "foreground",
141        "sp_system_background": "system-background",
142        "sp_top_app": "top-app"
143      }
144    }
145  ]
146```
147
148### 配置约束
149
150策略配置路径:cgroup_action_config.json文件; 每个sp_xxx策略都需要配置
151
152配置参数说明:
153
154| 配置项 | 说明 |
155|--------|--------|
156|controller|当前配置项对应的cgroup分组控制器|
157|path|cgroup分组对应的路径|
158|sched_policy|不同分组调度策略对应到的具体分组|
159|sp_xx|不同分组调度策略标识|
160
161## 统一调频
162
163### 调频接口说明
164
165当前可支持的调频接口说明
166
167| 接口  | 说明  |
168|----------|-------|
169| PerfRequest(int32_t cmdId, const std::string& msg) | 用于性能提频使用 |
170| PerfRequestEx(int32_t cmdId, bool onOffTag, const std::string& msg) | 用于性能提频使用且支持ON/OFF事件 |
171| PowerLimitBoost(bool onOffTag, const std::string& msg) | 用于限制boost无法突破功耗限频 |
172| ThermalLimitBoost(bool onOffTag, const std::string& msg) | 用于限制boost无法突破热限频 |
173| LimitRequest(int32_t clientId, const std::vector<int32_t>& tags, const std::vector<int64_t>& configs, const std::string& msg) | 用于热或功耗模块的限频且支持多项值一同设置 |
174
175如表格所示,所有的调频接口都以cmdID为核心,将调频场景和调频参数互相关联,实现提频或者限频的功能。
176带onOffTag参数的接口表示该接口支持ON/OFF的开关调频模式,一般用于生效时间不固定的长期调频事件,需要调用者手动开启或者关闭。
177msg参数为拓展字符串信息,可承载例如调用客户端pid/tid等信息。
178
179### 调频配置说明
180
181当前configs目录下的配置文件
182
183| 配置文件  | 说明  |
184|----------|-------|
185| socperf_resource_config.xml | 定义产品可支持的资源配置,例如CPU/GPU/DDR/NPU等 |
186| socperf_boost_config.xml | 用于性能提频的配置文件 |
187
188各个xml配置文件都需要按产品定制,不同产品的配置不相同。
189对于指定的某产品,所有可支持配置的资源都定义在socperf_resource_config.xml内,支持单路径/多路径配置,任何资源都有唯一的resID。
190socperf_boost_config.xml使用的cmdID不能重复。
191
192### 调频使用举例
193
194以点击提频事件为例。
195
196点击场景提频为固定生效时间,无需使用ON/OFF手动开启或关闭,故使用PerfRequest接口即可。因此需要在合适的地方调用soc_perf提供的IPC接口PerfRequest实现提频请求。
197
198资源调度服务对所有事件的采集有统一的入口,即资源调度框架对订阅事件的插件进行分发的机制,调频服务也依赖该机制实现对于各个需要调频的场景的感知。
199
200调频服务已实现为一个单独的调频插件socperf_plugin,定义在/ressched/plugins/socperf_plugin目录下。
201要实现点击场景的提频,分为点击事件插桩、事件上报给资源调度框架、框架给插件分发事件、生效调频服务四个步骤。
202
203第一步,
204ACE子系统仓内实现了对资源调度框架提供的可动态加载接口ReportData的封装,路径为/framework/base/ressched/ressched_report.h
205并在/framework/core/gestures/click_recognizer.cpp增加了打点作为手势识别中对点击事件的判定
206
207第二步,
208通过动态加载libressched_client.z.so,调用资源调度框架提供的接口ReportData,ACE子系统将点击事件上报给全局资源调度子系统
209
210第三步,
211在资源调度框架里,点击事件类型定义在/ressched/interfaces/innerkits/ressched_client/include/res_type.h内,为RES_TYPE_CLICK_RECOGNIZE
212由于调频插件socperf_plugin在初始化过程中已完成了对该点击事件的订阅,因此框架会在接受到事件通知时将点击事件分发给调频插件
213
214第四步,
215调频插件socperf_plugin对于点击事件分配了cmdID:PERF_REQUEST_CMD_ID_EVENT_CLICK,路径在/ressched/plugins/socperf_plugin/src/socperf_plugin.cpp216通过调用调频服务提供的IPC接口PerfRequest,插件会给调频服务发送请求,实现点击提频功能。
217
218## 监听事件采集
219目前支持音频框架相关事件、电话子系统相关事件、相机相关事件监听回调,
220
221监听音频框架中音频流状态变化、声音模式变化和整机声音变化
222
223监听电话状态变化
224
225监听相机状态变化
226
227## 相关仓<a name="section1371113476307"></a>
228- [windowmanager](https://gitee.com/openharmony/windowmanager)
229- [communication_ipc](https://gitee.com/openharmony/communication_ipc)
230- [hiviewdfx_hilog](https://gitee.com/openharmony/hiviewdfx_hilog)
231