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 - [Repositories Involved<a name="section1371113476307"></a>](#repositories-involved)
15
16## Introduction<a name="section11660541593"></a>
17
18In the resourceschedule subsystem, it provides the awareness and distribution of system events, such as application start, exit, screen on and off, etc.
19If 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.
20
21In 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.
22
23## Directory Structure<a name="section161941989596"></a>
24
25```
26├── cgroup_sched
27| ├── common
28| │ └── include # common header files
29| ├── framework
30| │ ├── process_group # utils to set cgroup by pid
31| │ ├── sched_controller # cgroup schedule
32| │ └── utils # adaption interface to forwarding data
33| │ ├── include
34| │ │ └── ressched_utils.h
35| │ └── ressched_utils.cpp
36| ├── interfaces # Init/Denit/Query interface for rss
37| │ └── innerkits
38| └── profiles
39└── ressched
40 ├── common # Common header file
41 ├── interfaces
42 │ └── innerkits # Interface APIs
43 │ └── ressched_client # Report data in process
44 ├── plugins # Plugin code
45 ├── profile # Plugin switch xml and plugin private xml
46 ├── sa_profile # System ability xml
47 └── services
48 ├── resschedmgr
49 │ ├── pluginbase # Plugin struct definition
50 │ └── resschedfwk # Resource schedule framework
51 └── resschedservice # Resource schedule service
52
53```
54## How to write a plugin<a name="section1312121216216"></a>
55
56### Available APIs<a name="section114564657874"></a>
57
58| API | Description |
59|-------------------------------------------------------------------------------|----------------------------------|
60| function OnPluginInit(std::string& libName): bool; | plugin init |
61| function OnPluginDisable(): void; | plugin disable |
62| function OnDispatchResource(const std::shared_ptr<ResData>& data):void; | dispatch resource event |
63
64### Usage Guidelines<a name="section129654513264"></a>
65
66When 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,
67
68At 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.
69
70#### Restrictions on Using Transient Tasks<a name="section1551164914237"></a>
71
721. The plugin can be implemented with C/C++.
73
742. The event processing of the plugin must be completed quickly. If it exceeds 1ms, warning will be printed.
75If it exceeds 10ms, the framework thinks the plugin is abnormal and reports an error.
76
77## Cgroup Schedule Policy
78
79### Basic Policy
80
81| Scene | Schedule policy |
82|----------|-------|
83| Currently focused oreground application and processes with same uid | top_app |
84| Foreground visible processes, include unfocused window process in split mode, float window process, foundation process | foreground |
85| system level daemon processes. Assign system schedule policy to them when started, | system |
86| Background application and processes with same uid | background |
87| kernel processes, most native processes and others have not mensioned | root |
88
89### Policy Configuration
90
91Each schedule policy is configured in a json file, and is bound to different cgroup.
92```
93 "Cgroups": [
94 {
95 "controller": "cpuctl",
96 "path": "/dev/cpuctl",
97 "sched_policy": {
98 "sp_default": "",
99 "sp_background": "background",
100 "sp_foreground": "foreground",
101 "sp_system": "system",
102 "sp_top_app": "top-app"
103 }
104 }
105 ]
106```
107
108### Restrictions
109
110Configuration file: cgroup_action_config.json
111Every schedule policy defined should be configured.
112
113Introduction to each config item:
114
115| Item | Description |
116|--------|--------|
117|controller|cgroup controller: cpuset, cpuctl, blkio etc.|
118|path|Absolute path of current cgroup|
119|sched_policy|Binding between each schedule policy and cgroup|
120|sp_xx|Different kinds of schedule policy|
121
122## Repositories Involved<a name="section1371113476307"></a>
123
124- [aafwk_standard](https://gitee.com/openharmony/aafwk_standard)
125- [windowmanager](https://gitee.com/openharmony/windowmanager)
126- [communication_ipc](https://gitee.com/openharmony/communication_ipc)
127- [hiviewdfx_hilog](https://gitee.com/openharmony/hiviewdfx_hilog)
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 - [相关仓<a name="section1371113476307"></a>](#相关仓)
15
16## 简介<a name="section11660541593"></a>
17
18在资源调度子系统中,提供系统事件的感知以及分发,例如应用启动、退出、亮灭屏等。如果需要获取系统事件,并且进行相关资源调度,那么可以选择以插件形式加入资源调度服务中。
19
20作为资源调度子系统的子模块,智能分组模块通过系统内应用前后台切换、用户焦点输入、后台任务的执行状态,决策进程的分组调度策略,并支持通过配置将调度策略映射到不同的CGROUP分组,为系统的性能、功耗均衡调度提供决策依据。同时该模块向资源调度框架转发应用状态、焦点状态、后台任务状态等系统事件,供插件订阅。
21
22## 目录<a name="section161941989596"></a>
23
24```
25├── cgroup_sched
26| ├── common
27| │ └── include # 公共头文件
28| ├── framework # 主体代码
29| │ ├── process_group # 分组设置接口
30| │ ├── sched_controller # 分组计算
31| │ └── utils # RMS数据转发适配接口
32| │ ├── include
33| │ │ └── ressched_utils.h
34| │ └── ressched_utils.cpp
35| ├── interfaces # 供RSS初始化、查询分组接口
36| │ └── innerkits
37| └── profiles
38└── ressched
39 ├── common # 公共头文件
40 ├── interfaces
41 │ └── innerkits # 对外接口目录
42 │ └── ressched_client # 外部同步事件通知接口
43 ├── plugins # 插件代码实现
44 ├── profile # 插件开关以及私有配置
45 ├── sa_profile # 系统元能力配置
46 └── services
47 ├── resschedmgr
48 │ ├── pluginbase # 插件结构定义
49 │ └── resschedfwk # 资源调度服务框架实现
50 └── resschedservice # 资源调度服务层
51
52```
53## 如何编写一个插件<a name="section1312121216216"></a>
54
55### 接口说明<a name="section114564657874"></a>
56
57| 接口名 | 接口描述 |
58|-------------------------------------------------------------------------------|----------------------------------|
59| function OnPluginInit(std::string& libName): bool; | 插件初始化 |
60| function OnPluginDisable(): void; | 插件退出 |
61| function OnDispatchResource(const std::shared_ptr<ResData>& data):void; | 获取分发的事件 |
62
63### 使用说明<a name="section129654513264"></a>
64
65插件初始化的时候,指定需要注册监听的事件。在这些事件发生的时候,框架会依次分发给各个插件,
66此时插件需要快速处理消息接收进行资源调度(需要有耗时任务则需另起线程处理),处理完成后返回。
67
68#### 插件事件处理约束<a name="section1551164914237"></a>
69
701、插件可以用C/C++实现。
71
722、插件的事件处理,必须快速完成,超过1ms会打印相关告警,超过10ms,框架认为插件异常而进行插件退出操作。
73
74## 分组策略
75
76### 基础分组策略
77
78| 场景描述 | 分组策略 |
79|----------|-------|
80| 前台焦点应用,UID相同的进程 | top_app |
81| 前台可见的,包括分屏场景下的非焦点应用进程、悬浮窗对应的进程、foundation进程等 | foreground |
82| 一些系统级后台常驻进程,不由分组计算主动设置。在rc/cfg文件中写定,直接写入system分组 | system |
83| 退到后台的前一个应用,及其相关的进程 | background |
84| OS内核和其他native进程,以及上面没有涉及到的一些进程 | root |
85
86### 策略配置
87
88通过JSON配置文件,对每个分组策略,绑定指定的CGROUP分组。
89```
90 "Cgroups": [
91 {
92 "controller": "cpuctl",
93 "path": "/dev/cpuctl",
94 "sched_policy": {
95 "sp_default": "",
96 "sp_background": "background",
97 "sp_foreground": "foreground",
98 "sp_system": "system",
99 "sp_top_app": "top-app"
100 }
101 }
102 ]
103```
104
105### 配置约束
106
107策略配置路径:cgroup_action_config.json文件; 每个sp_xxx策略都需要配置
108
109配置参数说明:
110
111| 配置项 | 说明 |
112|--------|--------|
113|controller|当前配置项对应的cgroup分组控制器|
114|path|cgroup分组对应的路径|
115|sched_policy|不同分组调度策略对应到的具体分组|
116|sp_xx|不同分组调度策略标识|
117
118## 相关仓<a name="section1371113476307"></a>
119- [aafwk_standard](https://gitee.com/openharmony/aafwk_standard)
120- [windowmanager](https://gitee.com/openharmony/windowmanager)
121- [communication_ipc](https://gitee.com/openharmony/communication_ipc)
122- [hiviewdfx_hilog](https://gitee.com/openharmony/hiviewdfx_hilog)