From 82b8c8913d6f542ae24b88564158ab7289379092 Mon Sep 17 00:00:00 2001 From: Matt Yang Date: Fri, 20 May 2022 17:44:58 +0800 Subject: [PATCH] DEV 22.05.20 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 开放配置文件自定义 - 改进 CPU重负载调频稳定性 - 改进 任务放置 - 改进 顶层APP获取开销,感谢@nakixii - 修复 perapp切换崩溃 - 修复 部分潜在崩溃代码 - 修复 CPU频率写入器失效 - ...合计97个commit Signed-off-by: Matt Yang --- changelog.md | 10 + config/README.md | 378 +++++++++++++++++++++++++++++++ config/template.json | 393 +++++++++++++++++++++++++++++++++ magisk/module.prop | 4 +- magisk/script/initsvc.sh | 2 + magisk/script/powercfg.json | 2 +- magisk/script/powercfg_once.sh | 42 +++- magisk/script/setup.sh | 2 +- version.json | 6 +- 9 files changed, 822 insertions(+), 17 deletions(-) create mode 100644 config/README.md create mode 100644 config/template.json diff --git a/changelog.md b/changelog.md index bff6333..f737bbb 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,15 @@ # 更新日志 +## DEV 22.05.20 + +- 新增 开放配置文件自定义 +- 改进 CPU重负载调频稳定性 +- 改进 任务放置 +- 改进 顶层APP获取开销,感谢@nakixii +- 修复 perapp切换崩溃 +- 修复 部分潜在崩溃代码 +- 修复 CPU频率写入器失效 + ## DEV 22.05.09 - 回退 混合CPU调频 diff --git a/config/README.md b/config/README.md new file mode 100644 index 0000000..0ebeda2 --- /dev/null +++ b/config/README.md @@ -0,0 +1,378 @@ +# Uperf v3 配置文件说明 + +Uperf v3 使用插件化的软件结构设计,每个功能模块均可拥有独立的配置参数空间。 + +## meta/元信息 + +| 字段 | 类型 | 描述 | +| ------ | ------ | ------------------ | +| name | string | 配置文件的名称 | +| author | string | 配置文件的作者信息 | + +## modules/模块定义 + +功能模块的静态参数段,仅在模块实例化时读取一次,用于开关功能、定义模型参数等。 + +### switcher/动态配置切换器 + +根据关联的 native 层信号,跳转对应的 hint 状态切换,应用对应的动态参数,并持续指定时长。用户可定义多个性能配置,每个性能配置有各个 hint 的动态参数。动态参数的默认值定义在`/initials`,动态参数的动态值定义在`/presets`。如果在写入`/presets`定义了`powersave`和`balance`两个性能配置,那么`switchInode`文件允许写入`auto`、`powersave`和`balance`,其中`auto`表示启用`内置分APP性能配置切换器`。 + +注:由于是基础模块,此模块**不可关闭**。 + +内置分 APP 性能配置切换器的规则样例如下,包名按大小写敏感的全字匹配。行首为`*`表示默认规则,行首为`-`表示熄屏规则,**必须包含默认和熄屏规则**。 + +``` +# 分应用性能模式配置 +# Per-app dynamic power mode rule +# '-' means offscreen rule +# '*' means default rule + +com.miHoYo.Yuanshen fast +- balance +* balance +``` + +| 字段 | 类型 | 描述 | +| ------------ | ------ | ------------------------------ | +| switchInode | string | 监听手动切换性能模式的文件节点 | +| perapp | string | 内置分 APP 性能配置文件路径 | +| hintDuration | object | 每个 hint 的最长持续时间 | + +#### hintDuration/hint 最长持续时间 + +各个 hint 使用状态机完成跳转,状态转移图如下: + +```mermaid +stateDiagram-v2 + +[*] --> idle +idle --> touch: pressed touch / pressed button +idle --> switch: woke up screen +touch --> trigger: released touch / started scrolling +touch --> gesture: detected fullscreen gesture +touch --> switch: detected window animation +touch --> junk: detected junk +gesture --> switch: detected window animation +gesture --> junk: detected junk +switch --> swjunk: detected junk +junk --> touch: timeout / finished junk +swjunk --> switch: timeout / finished junk +trigger --> touch: timeout / not rendering +gesture --> touch: timeout / not rendering +switch --> touch: timeout / not rendering +touch --> idle: timeout / not rendering +``` + +| 字段 | 类型 | 描述 | +| ------- | ----- | -------------------------------------------------- | +| idle | float | (单位:秒)默认 | +| touch | float | (单位:秒)触摸屏幕/按下按键 | +| trigger | float | (单位:秒)点击操作离开屏幕/滑动操作起始 | +| gesture | float | (单位:秒)全面屏手势 | +| switch | float | (单位:秒)应用切换动画/点亮屏幕 | +| junk | float | (单位:秒)touch/gesture 中 sfanalysis 检测到掉帧 | +| swjunk | float | (单位:秒)switch 中 sfanalysis 检测到掉帧 | + +### atrace/数据打点 + +用于 uperf 程序调试。 + +| 字段 | 类型 | 描述 | +| ------ | ---- | ------------ | +| enable | bool | 启用数据打点 | + +### log/日志级别 + +用于 uperf 配置文件调试。 + +| 字段 | 类型 | 描述 | +| ----- | ------ | ----------------------------------------------------- | +| level | string | 日志级别,可用`err`、`warn`、`info`、`debug`、`trace` | + +### input/用户输入监听 + +监听用户触摸屏触摸操作、按键操作、鼠标操作。支持输入设备热插拔。 + +| 字段 | 类型 | 描述 | +| ---------------- | ----- | ------------------------------------------------ | +| enable | bool | 启用用户输入监听 | +| swipeThd | float | 单次触摸轨迹百分比长度超过该阈值,判定为滑动操作 | +| gestureThdX | float | 全面屏手势起始 X 轴百分比位置 | +| gestureThdY | float | 全面屏手势起始 Y 轴百分比位置 | +| gestureDelayTime | float | 暂不使用 | +| holdEnterTime | float | 暂不使用 | + +### sfanalysis/SurfaceFlinger 信号分析 + +接收 sfanalysis 模块在 SurfaceFlinger 内部的信号分析结果。检测到掉帧触发 hint,渲染结束提前结束 hint。 + +| 字段 | 类型 | 描述 | +| ------------------- | ----- | ------------------------------------------------ | +| enable | bool | 启用 SurfaceFlinger 信号分析 | +| renderIdleSlackTime | float | (单位:秒)渲染结束保持一段时间,判定为渲染结束 | + +### cpu/用户态 CPU 调频 + +基于能耗模型的用户态 CPU 调频器,使能 HMP/EAS 全平台统一体验。根据功耗模型计算每个频点的每瓦性能,选择最佳的频率限制。 + +| 字段 | 类型 | 描述 | +| ---------- | ------ | ------------------- | +| enable | bool | 启用用户态 CPU 调频 | +| powerModel | object | CPU 能耗模型 | + +#### powerModel/能耗模型 + +仅需一组实测数据即可完成标定。经验模型结合实测数据,保持模型精度并显著减少平台适配工作量。类型为对象列表,与 CPU 集群顺序一致。 + +| 字段 | 类型 | 描述 | +| ------------ | ----- | --------------------------------------------- | +| efficiency | int | 单核相对同频性能(以Cortex-A53@1.0Ghz为 100) | +| nr | int | 集群内核心数量 | +| typicalPower | float | (单位:瓦)单核典型功耗 | +| typicalFreq | float | (单位:千兆赫)单核典型频点 | +| sweetFreq | float | (单位:千兆赫)单核甜点交界频点 | +| plainFreq | float | (单位:千兆赫)单核线性交界频点 | +| freeFreq | float | (单位:千兆赫)单核最低功耗频点 | + +### sysfs/内核节点写入器 + +用户态性能控制器的核心功能,为不同场景设置不同的内核参数。此模块高度优化,写入目标值开销极低。 + +| 字段 | 类型 | 描述 | +| ------ | ------ | ------------------ | +| enable | bool | 启用内核节点写入器 | +| knob | object | 内核节点定义 | + +#### knob/内核节点定义 + +按键值对定义: + +- 键:内核节点名称 +- 值:内核节点文件路径 + +例子: + +```json +"cpusetTa": "/dev/cpuset/top-app/cpus" +``` + +### sched/识别上下文的任务调度器 + +在相同的能耗下,改进 QoS 提升用户感知的流畅度。正则匹配进程名和线程名,绑定到指定的 CPU 核心,并设置指定的调度优先级。此模块高度优化,进程扫描和动态规则应用开销极低。 + +识别上下文的任务调度器定义有如下场景: + +- `bg`:进程处于后台 +- `fg`:进程处于前台 +- `idle`:进程处于顶层可见,默认场景 +- `touch`:进程处于顶层可见,交互场景 +- `boost`:进程处于顶层可见,重负载场景 + +| 字段 | 类型 | 描述 | +| -------- | ------ | -------------------------- | +| enable | bool | 启用识别上下文的任务调度器 | +| cpumask | object | CPU 组定义 | +| affinity | object | CPU 亲和性类别定义 | +| prio | object | 调度优先级类别定义 | +| rules | object | 进程规则 | + +#### cpumask/CPU 组定义 + +按键值对定义: + +- 键:CPU 组名称 +- 值:此 CPU 组包含的 CPU 核心 id 列表 + +例子: + +```json +"perf": [4, 5, 6, 7] +``` + +#### affinity/CPU 亲和性类别定义 + +按键值对定义: + +- 键:CPU 亲和性类别名称 +- 值:每个场景绑定到的`cpumask` + +例子: + +```json +"coop": { + "bg": "eff", + "fg": "eff", + "idle": "norm", + "touch": "norm", + "boost": "norm" +} +``` + +#### prio/调度优先级类别定义 + +按键值对定义: + +- 键:调度优先级类别名称 +- 值:每个场景应用的调度优先级,值定义如下 + +| 数值 | 描述 | +| ------- | ------------------------------------------------------ | +| 0 | 跳过 SCHED 类别设置 | +| 1~98 | 设置线程调度类别为`SCHED_FIFO`,数值为实时静态优先级 | +| 100~139 | 设置线程调度类别为`SCHED_NORMAL`,数值为实时静态优先级 | +| -1 | 设置线程调度类别为`SCHED_NORMAL` | +| -2 | 设置线程调度类别为`SCHED_BATCH` | +| -3 | 设置线程调度类别为`SCHED_IDLE` | + +例子: + +```json +"high": { + "bg": -3, + "fg": 110, + "idle": 104, + "touch": 102, + "boost": 100 +} +``` + +#### rules/进程规则 + +类型为对象列表,与匹配优先级顺序一致。 + +注:正则匹配规则`/HOME_PACKAGE/`在内部会自动替换为当前系统启动器的包名。 + +| 字段 | 类型 | 描述 | +| ------ | ------ | -------------------------------------------- | +| name | string | 进程规则名 | +| regex | string | 进程名正则匹配规则,注意不要与 json 语法冲突 | +| pinned | bool | 始终作为`处于顶层可见的进程`应用规则 | +| rules | object | 此进程的线程规则 | + +##### rules/线程规则 + +类型为对象列表,与匹配优先级顺序一致。 + +注:正则匹配规则`/MAIN_THREAD/`在内部会自动替换为主线程线程名。 + +| 字段 | 类型 | 描述 | +| ---- | ------ | ----------------------------------------------------------------------- | +| k | string | 线程名正则匹配规则,注意不要与 json 语法冲突(abbr: keyword) | +| ac | string | 线程的 CPU 亲和性类别,需要在`affinity`预先定义(abbr: affinity class) | +| pc | string | 线程的调度优先级类别,需要在`prio`预先定义(abbr: priority class) | + +## initials/初始值 + +功能模块的动态参数段,模块初始化完成后可动态切换,用于调整阈值、模块行为倾向性等。在此段定义的值为该模块参数的默认值。 + +### cpu/用户态 CPU 调频 + +基于能耗模型的用户态 CPU 调频器工作流程如下,提供多个可调节参数: + +1. 从内核周期性采样 CPU 每个核心的负载 + - CPU 整体存在一定负载时,以`baseSampleTime`周期采样 CPU 频率,提高响应速度 + - CPU 整体进入空载时,以`baseSlackTime`周期采样 CPU 频率,减少轮询开销 +2. 计算每个集群的性能负载和性能需求 + - 如果 CPU 集群最大负载增加量大于`predictThd`,则性能需求计算使用预测的负载值 + - 根据性能负载计算性能需求,`demand = load + (1 - load) * (margin + burst)` + - `burst`与`margin`不同,即使当前负载较低也能计算到较大的性能需求 +3. 计算性能需求对应的工作频点 + - CPU 整体如果存在多个集群,它们共享整个`latencyTime`,表示从性能最低的集群的最低频到性能最高的集群的最高频率的最小延迟 + - 由于离散采样周期的存在,实测 CPU 整体升频最小延迟一般会大于设定的`latencyTime` + - 能耗代价越大的频点,升频到它的延迟也越大,且低于`sweetFreq`的频点没有额外的升频延迟 +4. 限制 CPU 整体的功耗 + - 类似于 Intel 处理器的 PL1 和 PL2 功耗限制,兼顾短期爆发性能需求和长期能效需求 + - 根据能耗模型和每个核心的负载,估计当前周期 CPU 整体的能耗值 + - 如果当前能耗大于`slowLimitPower`,能耗缓冲池余量减少 + - 如果当前能耗小于`slowLimitPower`,能耗缓冲池余量增加,并按照`fastLimitRecoverScale`缩放因子恢复,总量不超过`fastLimitCapacity` + - 限制 CPU 功耗根据能耗模型选择最优频率限制,在限定功耗下提供最佳整体性能 +5. 引导任务调度器放置任务 + - 启用`guideCap`后,根据能耗模型调节集群性能容量,引导 EAS 任务调度器把任务放置到能效最佳的集群 + - 启用`limitEfficiency`后,低性能集群最大频点能效值不高于高性能集群当前频点的能效值 +6. 写入目标 CPU 频率到内核 + - 高效的 CPU 频率写入器,用户态 CPU 调频整体周期运行耗时大约为 0.0005 秒 + +| 字段 | 类型 | 描述 | +| --------------------- | ----- | -------------------------------------------------------------------------------------------- | +| baseSampleTime | float | (单位:秒)(0.01~0.5)基础采样周期 | +| baseSlackTime | float | (单位:秒)(0.01~0.5)闲置采样周期,CPU 整体进入空载时生效 | +| latencyTime | float | (单位:秒)(0.0~10.0)CPU 整体升频最小延迟 | +| slowLimitPower | float | (单位:瓦)(0.05~999.0)CPU 长期功耗限制 | +| fastLimitPower | float | (单位:瓦)(0.05~999.0)CPU 短期功耗限制,能耗缓冲池消耗完毕后进入长期功耗限制 | +| fastLimitCapacity | float | (单位:瓦秒)(0.0~999.0)CPU 短期功耗限制容量 | +| fastLimitRecoverScale | float | (0.1~10.0)CPU 短期功耗限制容量恢复缩放因子 | +| predictThd | float | (0.1~1.0)CPU 集群最大负载增加量大于该阈值,则集群调频使用预测的负载值,并忽略`latencyTime` | +| margin | float | (0.0~1.0)调频提供的性能余量 | +| burst | float | (0.0~1.0)调频提供的额外性能余量,非零时忽略`latencyTime` | +| guideCap | bool | 启用引导 EAS 任务调度负载转移 | +| limitEfficiency | bool | 启用 CPU 整体能效限制 | + +### sysfs/内核节点写入器 + +按键值对定义: + +- 键:内核节点名称 +- 值:内核节点文件写入值,支持`string`和`int`类型 + +例子: + +```json +"cpusetTa": "0-7" +``` + +### sched/识别上下文的任务调度器 + +| 字段 | 类型 | 描述 | +| ----- | ------ | -------------------------------------------------------- | +| scene | string | 进程处于顶层可见的场景,合法值有`idle`, `touch`, `boost` | + +## presets/参数预设 + +功能模块的参数预设段,在这里定义不同的性能模式,如均衡模式、节能模式。 + +每组参数预设必须包含`*`, `idle`, `touch`, `trigger`, `gesture`, `junk`, `switch`, `swjunk`,如下样例所示。参数预设中子配置名称定义同[动态配置切换器](#switcher/动态配置切换器),在状态跳转后应用对应模式的动态参数。其中`*`中的参数为该组参数预设的动态参数默认值。 + +```json +"balance": { + "*": { + }, + "idle": { + }, + "touch": { + }, + "trigger": { + }, + "gesture": { + }, + "junk": { + }, + "switch": { + }, + "swjunk": { + } +} +``` + +为了提高参数预设的可读性,参数值采用`层叠样式表`的设计方式。以下示例展示参数值`cpu.baseSampleTime`的覆盖关系: + +1. 在`/initial/cpu`中定义`baseSampleTime`全局默认值为`0.01` +2. 在`/presets/balance/*`中定义`baseSampleTime`在该参数预设默认值为`0.02`,覆盖全局默认值`0.01` +3. 在`/presets/balance/idle`中定义`baseSampleTime`在`idle`场景值为`0.04`,覆盖该参数预设默认值`0.02` + +``` +"initials": { + "cpu": { + "baseSampleTime": 0.01, + } +}, +"presets": { + "balance": { + "*": { + "cpu.baseSampleTime": 0.02 + }, + "idle": { + "cpu.baseSampleTime": 0.04 + } + } +} +``` diff --git a/config/template.json b/config/template.json new file mode 100644 index 0000000..962ea3e --- /dev/null +++ b/config/template.json @@ -0,0 +1,393 @@ +{ + "meta": { + "name": "platform[yy.mm.dd]", + "author": "author@community" + }, + "modules": { + "switcher": { + "switchInode": "/sdcard/Android/yc/uperf/cur_powermode.txt", + "perapp": "/sdcard/Android/yc/uperf/perapp_powermode.txt", + "hintDuration": { + "idle": 0.0, + "touch": 4.0, + "trigger": 0.02, + "gesture": 0.1, + "switch": 0.3, + "junk": 0.04, + "swjunk": 0.04 + } + }, + "atrace": { + "enable": false + }, + "log": { + "level": "info" + }, + "input": { + "enable": true, + "swipeThd": 0.005, + "gestureThdX": 0.03, + "gestureThdY": 0.03, + "gestureDelayTime": 2.0, + "holdEnterTime": 1.0 + }, + "sfanalysis": { + "enable": true, + "renderIdleSlackTime": 0.2 + }, + "cpu": { + "enable": true, + "powerModel": [] + }, + "sysfs": { + "enable": true, + "knob": { + "cpusetTa": "/dev/cpuset/top-app/cpus", + "cpusetFg": "/dev/cpuset/foreground/cpus", + "cpusetBg": "/dev/cpuset/background/cpus", + "cpusetSysBg": "/dev/cpuset/system-background/cpus", + "cpusetRe": "/dev/cpuset/restricted/cpus" + } + }, + "sched": { + "enable": true, + "cpumask": { + "all": [0, 1, 2, 3, 4, 5, 6, 7], + "norm": [0, 1, 2, 3, 4, 5, 6], + "perf": [4, 5, 6, 7], + "eff": [0, 1, 2, 3], + "bal": [4, 5, 6], + "max": [7], + "gtcoop": [4, 5, 6], + "gtmain": [7] + }, + "affinity": { + "norm": { "bg": "", "fg": "norm", "idle": "all", "touch": "all", "boost": "all" }, + "bg": { "bg": "eff", "fg": "eff", "idle": "eff", "touch": "eff", "boost": "" }, + "coop": { "bg": "eff", "fg": "eff", "idle": "norm", "touch": "norm", "boost": "" }, + "trig": { "bg": "", "fg": "eff", "idle": "eff", "touch": "bal", "boost": "bal" }, + "crit": { "bg": "", "fg": "norm", "idle": "", "touch": "bal", "boost": "bal" }, + "mix": { "bg": "", "fg": "norm", "idle": "all", "touch": "bal", "boost": "bal" }, + "main": { "bg": "", "fg": "norm", "idle": "", "touch": "bal", "boost": "norm" }, + "binder": { "bg": "", "fg": "norm", "idle": "norm", "touch": "bal", "boost": "perf" }, + "gtcoop": { "bg": "", "fg": "norm", "idle": "perf", "touch": "gtcoop", "boost": "gtcoop" }, + "gtmain": { "bg": "", "fg": "norm", "idle": "perf", "touch": "gtmain", "boost": "gtmain" }, + "auto": { "bg": "", "fg": "", "idle": "", "touch": "", "boost": "" } + }, + "prio": { + "rtsys": { "bg": 97, "fg": 97, "idle": 97, "touch": 97, "boost": 96 }, + "rtusr": { "bg": 98, "fg": 98, "idle": 98, "touch": 98, "boost": 97 }, + "ux": { "bg": -3, "fg": 122, "idle": 104, "touch": 104, "boost": 100 }, + "bg": { "bg": -3, "fg": -3, "idle": -3, "touch": -3, "boost": -3 }, + "norm": { "bg": -3, "fg": -1, "idle": -1, "touch": -1, "boost": -3 }, + "auto": { "bg": 0, "fg": 0, "idle": 0, "touch": 0, "boost": 0 } + }, + "rules": [ + { + "name": "Launcher", + "regex": "/HOME_PACKAGE/", + "pinned": true, + "rules": [ + { "k": "/MAIN_THREAD/", "ac": "crit", "pc": "rtusr" }, + { "k": "^(RenderThread|GLThread)", "ac": "crit", "pc": "rtusr" }, + { "k": "^(GPU completion|HWC release|hwui|FramePolicy|ScrollPolicy|ged-swd)", "ac": "bg", "pc": "rtusr" }, + { "k": ".", "ac": "auto", "pc": "auto" } + ] + }, + { + "name": "SurfaceFlinger", + "regex": "/system/bin/surfaceflinger", + "pinned": true, + "rules": [ + { "k": "/MAIN_THREAD/", "ac": "trig", "pc": "rtsys" }, + { "k": "^RenderEngine", "ac": "crit", "pc": "rtsys" }, + { "k": "^Binder:", "ac": "binder", "pc": "auto" }, + { "k": "^app", "ac": "trig", "pc": "rtsys" }, + { "k": "^[Ss]f|Timer|Idle", "ac": "bg", "pc": "rtsys" }, + { "k": ".", "ac": "bg", "pc": "rtsys" } + ] + }, + { + "name": "SystemServer", + "regex": "system_server", + "pinned": true, + "rules": [ + { "k": "^(android.anim|android.display|android.bg)", "ac": "crit", "pc": "rtusr" }, + { "k": "^Binder:", "ac": "binder", "pc": "auto" }, + { "k": "^[Ii]nput", "ac": "trig", "pc": "ux" }, + { "k": "^(Jit thread pool|HeapTaskDaemon|FinalizerDaemon|ReferenceQueueD)", "ac": "binder", "pc": "bg" }, + { "k": "^(TaskSnapshot|Greezer|CachedApp|SystemPressure|SensorService)|[Mm]emory", "ac": "bg", "pc": "auto" }, + { "k": ".", "ac": "coop", "pc": "auto" } + ] + }, + { + "name": "Phone", + "regex": "com.android.phone", + "pinned": true, + "rules": [{ "k": ".", "ac": "coop", "pc": "auto" }] + }, + { + "name": "MediaProvider", + "regex": "^com.android.providers.media", + "pinned": true, + "rules": [{ "k": ".", "ac": "auto", "pc": "bg" }] + }, + { + "name": "Memory reclaim", + "regex": "^(kswapd0|kcompactd0)", + "pinned": true, + "rules": [{ "k": ".", "ac": "auto", "pc": "bg" }] + }, + { + "name": "Uperf", + "regex": "uperf", + "pinned": true, + "rules": [ + { "k": "HeavyWorker", "ac": "bg", "pc": "auto" }, + { "k": ".", "ac": "auto", "pc": "auto" } + ] + }, + { + "name": "SystemUI", + "regex": "com.android.systemui", + "pinned": false, + "rules": [{ "k": "^(Jit thread pool|HeapTaskDaemon|FinalizerDaemon|ReferenceQueueD)", "ac": "bg", "pc": "norm" }] + }, + { + "name": "Other system processes", + "regex": "^(/system|/vendor|magiskd|zygiskd)|@|-service$", + "pinned": false, + "rules": [{ "k": ".", "ac": "auto", "pc": "auto" }] + }, + { + "name": "App co-process", + "regex": "[.].+:", + "pinned": false, + "rules": [ + { "k": "^Binder:", "ac": "norm", "pc": "norm" }, + { "k": "^(Jit thread pool|HeapTaskDaemon|FinalizerDaemon|ReferenceQueueD)", "ac": "bg", "pc": "norm" } + ] + }, + { + "name": "Default rule", + "regex": ".", + "pinned": false, + "rules": [ + { "k": "/MAIN_THREAD/", "ac": "main", "pc": "ux" }, + { "k": "[.]ui$", "ac": "main", "pc": "ux" }, + { "k": "^(UnityMain|RenderThread |GameThread)", "ac": "gtmain", "pc": "ux" }, + { "k": "^(Unity|Worker Thread|TaskGraph|RHIThread)", "ac": "gtcoop", "pc": "ux" }, + { "k": "^(NativeThread|Timer-)", "ac": "bg", "pc": "norm" }, + { "k": "^(Chrome_InProc|CrRendererMain|CrGpuMain|CompositorTile)", "ac": "coop", "pc": "norm" }, + { "k": "^(Viz|Chrome_|Compositor)", "ac": "coop", "pc": "ux" }, + { "k": "^(JS|libweexjsb|WeexJsBridge|mqt_native|mqt_js|JavaScriptTh)", "ac": "coop", "pc": "bg" }, + { "k": "^Thread-", "ac": "mix", "pc": "norm" }, + { "k": "[Aa]sync", "ac": "norm", "pc": "bg" }, + { "k": "[Vv]sync|mali-", "ac": "coop", "pc": "ux" }, + { "k": "^(pool-|glide-|launcher-)", "ac": "coop", "pc": "bg" }, + { "k": "^(OkHttp|Ysa|Xqa|Rx|Fresco|TVKDL|APM|tp-|cgi-|ODCP-|Bugly|xlog_)", "ac": "bg", "pc": "norm" }, + { "k": "^(xg_vip_service|Profile|SearchDaemon|default_matrix|FrameDecoder|FrameSeq)", "ac": "bg", "pc": "norm" }, + { "k": "^([Dd]ownload|ThreadPoolForeg|launcher-idle-|fe_single_pool)", "ac": "bg", "pc": "norm" }, + { "k": "[Ss]chedule|[.][.][.]$|[.]so$", "ac": "bg", "pc": "norm" }, + { "k": "[Ww]ork|[Pp]ool", "ac": "coop", "pc": "norm" }, + { "k": "^(GPU completion|HWC release|hwui|FramePolicy|ScrollPolicy|ged-swd)", "ac": "bg", "pc": "rtusr" }, + { "k": "^(RenderThread|GLThread|JNISurfaceText|IJK_External_Re)", "ac": "main", "pc": "ux" }, + { "k": "[.]raster$", "ac": "crit", "pc": "ux" }, + { "k": "[Aa]nim", "ac": "crit", "pc": "ux" }, + { "k": "^Binder:", "ac": "trig", "pc": "auto" }, + { "k": ".", "ac": "norm", "pc": "norm" } + ] + } + ] + } + }, + "initials": { + "cpu": { + "baseSampleTime": 0.01, + "baseSlackTime": 0.01, + "latencyTime": 0.5, + "slowLimitPower": 3.0, + "fastLimitPower": 6.0, + "fastLimitCapacity": 10.0, + "fastLimitRecoverScale": 0.6, + "predictThd": 0.1, + "margin": 0.25, + "burst": 0.0, + "guideCap": true, + "limitEfficiency": false + }, + "sysfs": { + "cpusetTa": "0-7", + "cpusetFg": "0-6", + "cpusetBg": "0-3", + "cpusetSysBg": "0-3", + "cpusetRe": "0-6" + }, + "sched": { + "scene": "idle" + } + }, + "presets": { + "balance": { + "*": { + "cpu.latencyTime": 0.2, + "cpu.slowLimitPower": 2.5, + "cpu.fastLimitPower": 5.0, + "cpu.fastLimitCapacity": 1.0, + "cpu.margin": 0.2 + }, + "idle": { + "cpu.baseSampleTime": 0.04, + "cpu.baseSlackTime": 0.08, + "cpu.limitEfficiency": true, + "sched.scene": "idle" + }, + "touch": { + "sched.scene": "touch" + }, + "trigger": { + "cpu.margin": 0.7, + "sched.scene": "touch" + }, + "gesture": { + "cpu.margin": 0.7, + "sched.scene": "touch" + }, + "junk": { + "cpu.burst": 0.55, + "sched.scene": "touch" + }, + "switch": { + "cpu.slowLimitPower": 5.0, + "cpu.guideCap": false, + "cpu.margin": 0.3, + "sched.scene": "boost" + }, + "swjunk": { + "cpu.slowLimitPower": 5.0, + "cpu.guideCap": false, + "cpu.margin": 0.3, + "cpu.burst": 0.55, + "sched.scene": "boost" + } + }, + "powersave": { + "*": { + "cpu.latencyTime": 0.5, + "cpu.slowLimitPower": 1.5, + "cpu.fastLimitPower": 3.0, + "cpu.fastLimitCapacity": 0.5, + "cpu.margin": 0.1 + }, + "idle": { + "cpu.baseSampleTime": 0.04, + "cpu.baseSlackTime": 0.08, + "cpu.predictThd": 1.0, + "cpu.limitEfficiency": true, + "sched.scene": "idle" + }, + "touch": { + "sched.scene": "touch" + }, + "trigger": { + "cpu.margin": 0.4, + "sched.scene": "touch" + }, + "gesture": { + "cpu.margin": 0.4, + "sched.scene": "touch" + }, + "junk": { + "cpu.burst": 0.45, + "sched.scene": "touch" + }, + "switch": { + "cpu.slowLimitPower": 3.0, + "cpu.guideCap": false, + "cpu.margin": 0.2, + "sched.scene": "boost" + }, + "swjunk": { + "cpu.slowLimitPower": 3.0, + "cpu.guideCap": false, + "cpu.margin": 0.2, + "cpu.burst": 0.45, + "sched.scene": "boost" + } + }, + "performance": { + "*": { + "cpu.latencyTime": 0.0, + "cpu.slowLimitPower": 5.0, + "cpu.fastLimitPower": 10.0, + "cpu.fastLimitCapacity": 300.0, + "cpu.margin": 0.4 + }, + "idle": { + "cpu.baseSampleTime": 0.01, + "cpu.baseSlackTime": 0.04, + "sched.scene": "idle" + }, + "touch": { + "sched.scene": "touch" + }, + "trigger": { + "cpu.margin": 0.8, + "sched.scene": "touch" + }, + "gesture": { + "cpu.margin": 0.8, + "sched.scene": "touch" + }, + "junk": { + "cpu.burst": 0.55, + "sched.scene": "touch" + }, + "switch": { + "cpu.burst": 0.2, + "sched.scene": "boost" + }, + "swjunk": { + "cpu.burst": 0.55, + "sched.scene": "boost" + } + }, + "fast": { + "*": { + "cpu.latencyTime": 0.0, + "cpu.slowLimitPower": 3.0, + "cpu.fastLimitPower": 3.0, + "cpu.fastLimitCapacity": 0.0, + "cpu.margin": 0.4 + }, + "idle": { + "cpu.baseSampleTime": 0.01, + "cpu.baseSlackTime": 0.04, + "sched.scene": "idle" + }, + "touch": { + "sched.scene": "touch" + }, + "trigger": { + "cpu.margin": 0.8, + "sched.scene": "touch" + }, + "gesture": { + "cpu.margin": 0.8, + "sched.scene": "touch" + }, + "junk": { + "cpu.burst": 0.55, + "sched.scene": "touch" + }, + "switch": { + "cpu.burst": 0.2, + "sched.scene": "boost" + }, + "swjunk": { + "cpu.burst": 0.55, + "sched.scene": "boost" + } + } + } +} diff --git a/magisk/module.prop b/magisk/module.prop index 17d1acc..8095f98 100644 --- a/magisk/module.prop +++ b/magisk/module.prop @@ -1,7 +1,7 @@ id=uperf name=Uperf -version=v3(22.05.09) -versionCode=3 +version=v3(22.05.20) +versionCode=220520 author=Matt Yang description=Userspace performance controller for android. Repo: https://github.com/yc9559/uperf/ updateJson=https://github.com/yc9559/uperf/raw/master/version.json diff --git a/magisk/script/initsvc.sh b/magisk/script/initsvc.sh index 06c23ba..e86cb05 100644 --- a/magisk/script/initsvc.sh +++ b/magisk/script/initsvc.sh @@ -40,4 +40,6 @@ lock_val "1048576" /proc/sys/fs/inotify/max_user_watches lock_val "1024" /proc/sys/fs/inotify/max_user_instances mv $USER_PATH/uperf_log.txt $USER_PATH/uperf_log.txt.bak +ASAN_LIB="$(ls $BIN_PATH/libclang_rt.asan-*-android.so)" +export LD_PRELOAD="$ASAN_LIB $BIN_PATH/libc++_shared.so" $BIN_PATH/uperf $USER_PATH/uperf.json -o $USER_PATH/uperf_log.txt diff --git a/magisk/script/powercfg.json b/magisk/script/powercfg.json index c9f57c5..97a7c28 100644 --- a/magisk/script/powercfg.json +++ b/magisk/script/powercfg.json @@ -1,7 +1,7 @@ { "name": "Uperf", "author": "Matt Yang", - "version": "22.05.09", + "version": "22.05.20", "versionCode": 3, "features": { "strict": true, diff --git a/magisk/script/powercfg_once.sh b/magisk/script/powercfg_once.sh index 3d8df62..4578af2 100644 --- a/magisk/script/powercfg_once.sh +++ b/magisk/script/powercfg_once.sh @@ -35,21 +35,26 @@ unify_cgroup() { rmdir /dev/cpuset/foreground/boost # work with uperf/ContextScheduler - change_task_cgroup "surfaceflinger" "foreground" "cpuset" - change_thread_cgroup "surfaceflinger" "^Binder" "" "cpuset" - change_task_cgroup "system_server" "foreground" "cpuset" - change_thread_cgroup "system_server" "^android.bg" "" "cpuset" - change_task_cgroup "composer|allocator" "foreground" "cpuset" - change_task_cgroup "netd" "foreground" "cpuset" - change_task_cgroup "android.hardware.media" "background" "cpuset" - change_task_cgroup "vendor.mediatek.hardware" "background" "cpuset" + change_task_cgroup "surfaceflinger|system_server" "" "cpuset" + change_task_cgroup "netd|allocator|kswapd0|kcompactd0" "foreground" "cpuset" + change_task_cgroup "android.hardware.media|vendor.mediatek.hardware" "background" "cpuset" change_task_cgroup "aal_sof|kfps|dsp_send_thread|vdec_ipi_recv|mtk_drm_disp_id|hif_thread|main_thread|ged_" "background" "cpuset" change_task_cgroup "pp_event|crtc_" "background" "cpuset" } unify_sched() { + # clear stune & uclamp + for d in /dev/stune/*/; do + lock_val "0" $d/schedtune.boost + done + for d in /dev/cpuctl/*/; do + lock_val "0" $d/cpu.uclamp.min + done + for d in kernel walt; do lock_val "0" /proc/sys/$d/sched_force_lb_enable + lock_val "255" /proc/sys/$d/sched_busy_hysteresis_enable_cpus + lock_val "2000000" /proc/sys/$d/sched_busy_hyst_ns done } @@ -66,6 +71,13 @@ unify_devfreq() { done } +unify_lpm() { + # Qualcomm enter C-state level 3 took ~500us + lock_val "0" /sys/module/lpm_levels/parameters/lpm_ipi_prediction + lock_val "0" /sys/module/lpm_levels/parameters/lpm_prediction + lock_val "2" /sys/module/lpm_levels/parameters/bias_hyst +} + disable_hotplug() { # Exynos hotplug mutate "0" /sys/power/cpuhotplug/enabled @@ -100,6 +112,10 @@ disable_kernel_boost() { lock_val "0" "/sys/kernel/msm_performance/parameters/*" lock_val "0" "/proc/sys/walt/input_boost/*" + # no msm_performance limit + set_cpufreq_min "0:0 1:0 2:0 3:0 4:0 5:0 6:0 7:0" + set_cpufreq_max "0:9999000 1:9999000 2:9999000 3:9999000 4:9999000 5:9999000 6:9999000 7:9999000" + # MediaTek # policy_status # [0] PPM_POLICY_PTPOD: Meature PMIC buck currents @@ -164,7 +180,10 @@ disable_userspace_boost() { lock_val "0" "/sys/module/fbt_cpu/parameters/boost_affinity*" lock_val "0" /sys/kernel/fpsgo/fbt/switch_idleprefer lock_val "1" /proc/perfmgr/syslimiter/syslimiter_force_disable - # lock_val "1" /sys/module/mtk_core_ctl/parameters/policy_enable + lock_val "1" /sys/module/mtk_core_ctl/parameters/policy_enable + lock_val "90" /sys/kernel/fpsgo/fbt/thrm_temp_th + lock_val "-1" /sys/kernel/fpsgo/fbt/thrm_limit_cpu + lock_val "-1" /sys/kernel/fpsgo/fbt/thrm_sub_cpu # Qualcomm&MTK perfhal perfhal_stop @@ -194,7 +213,8 @@ disable_userspace_thermal() { killall mi_thermald # prohibit mi_thermald use cpu thermal interface for i in 0 2 4 6 7; do - lock_val "cpu$i 9999000" /sys/devices/virtual/thermal/thermal_message/cpu_limits + local maxfreq="$(cat /sys/devices/system/cpu/cpu$i/cpufreq/cpuinfo_max_freq)" + [ "$maxfreq" -gt "0" ] && lock_val "cpu$i $maxfreq" /sys/devices/virtual/thermal/thermal_message/cpu_limits done } @@ -214,6 +234,7 @@ disable_kernel_boost disable_hotplug unify_sched unify_devfreq +unify_lpm disable_userspace_thermal restart_userspace_thermal @@ -225,6 +246,7 @@ disable_kernel_boost disable_hotplug unify_sched unify_devfreq +unify_lpm # make sure that all the related cpu is online rebuild_process_scan_cache diff --git a/magisk/script/setup.sh b/magisk/script/setup.sh index 4e4adb1..139e6ea 100644 --- a/magisk/script/setup.sh +++ b/magisk/script/setup.sh @@ -74,7 +74,7 @@ install_uperf() { echo "" echo "* Uperf https://github.com/yc9559/uperf/" echo "* Author: Matt Yang" -echo "* Version: v3(22.05.09)" +echo "* Version: v3(22.05.20)" echo "" echo "- Installing uperf" diff --git a/version.json b/version.json index 35ab898..c5e3cdf 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { - "versionCode": 3, - "version": "v3(22.05.09)", - "zipUrl": "https://github.com/yc9559/uperf/releases/download/dev-22.05.09/uperf-dev-22.05.09.zip", + "versionCode": 220520, + "version": "v3", + "zipUrl": "https://github.com/yc9559/uperf/releases/download/dev-22.05.20/uperf-dev-22.05.20.zip", "changelog": "https://github.com/yc9559/uperf/raw/master/changelog.md" }