付费版 BPF自定义线程
这篇按付费版当前真实 bin/cpu/<拓扑>.json 与解析代码支持的字段来解释。
1. 当前主结构
付费版当前线程专项主线仍然是:
maingfxrenderworkerotherextra:[pattern]
2. 当前真实示例
json
{
"version": 3,
"apps": [
{
"friendly": "示例游戏",
"packages": ["com.demo.game"],
"main": { "match": ["UnityMain"], "cpus": "6-7", "fifo": 1 },
"gfx": { "match": ["UnityGfx*", "GfxDevice*"], "cpus": "4-5", "rr": 10 },
"render": { "match": ["*rthread*"], "cpus": "6-7", "rr": 1 },
"worker": { "match": ["*thread*"], "limit": 2, "cpus": "4-5", "rr": 10 },
"extra:[binder:*]": { "limit": 8, "cpus": "0-5" },
"other": { "cpus": "1-4" }
}
]
}3. 顶层字段逐个解释
version
- 当前线程 JSON 版本号
- 现有主线为
3
apps
- 应用级线程规则数组
4. apps[] 里当前支持的字段
friendly
- 规则显示名
packages
- 这组规则命中的包名或常驻进程名
scope
- 可选字段
- 现有值主要是:
foregroundpersistent
persistent用于surfaceflinger这类常驻进程
features
- 付费版线程应用规则支持的功能开关对象
- 当前解析代码支持:
features.dynamic_tuningfeatures.fasfeatures.custom_threadfeatures.dynamic_thread_scheduler
这些字段是"该应用命中后是否允许该功能继续生效"的应用级覆写,不是线程动作本身。
其中线程相关的两个开关现在要分开理解:
features.custom_thread- 控制静态线程规则是否继续生效
- 包括
main / gfx / render / worker / other / extra:[pattern] / default_action
features.dynamic_thread_scheduler- 控制线程学习、守护、动态重打这条运行时链
- 关掉后仍可保留静态线程规则
session
- 付费版线程应用规则支持会话参数
- 当前解析代码支持:
session.learning_duration_mssession.guard_interval_ms
default_action
- 应用级默认线程动作
- 当线程没有命中更具体的角色规则时,可回落到这里
- 当前紧凑写法里
other仍然是更常见主写法
main / gfx / render / worker / other
- 当前真实角色键
- 都属于
BPF自定义线程主规则链
extra:[pattern]
- 手写补充线程规则
pattern就直接写在 key 里
5. 角色对象和 extra:[pattern] 里支持什么字段
当前主线常见字段是:
matchlimitcpusclustersnicerrfifo
match
- 线程名匹配规则
- 当前解析支持:
- 普通包含:
"GameThread" - 通配:
"UnityGfx*"、"*worker*" - 精确:
"=renderengine" - 带排名:
"Thread-*@1"、"Thread-*@1-2"
- 普通包含:
limit
- 最多命中几个线程
cpus
- 直接指定 CPU 范围或列表
- 例如:
"7""6-7""1-4""2,4,5-6"
clusters
- 直接指定目标簇
- 当前预置常见:
bigmiddletop
nice
- 普通优先级调整
rr
SCHED_RR实时优先级
fifo
SCHED_FIFO实时优先级
6. main 的真实语义
main 的意思不是"所有同名线程全部吃进主线程规则"。
正确理解是:
main只占主规则名额- 同名线程出现多条时,不会全部被吞进
main - 剩余线程可以继续流向
extra:[pattern]或other
7. 当前优先级顺序
建议按下面顺序理解:
main / gfx / render / workerextra:[pattern]otherdefault_action
也就是说:
- 主角色最优先
extra用来补专项other负责当前紧凑结构里的主要兜底default_action属于额外兼容入口
8. 付费版和免费版这里的差别
线程角色结构表面相似,但付费版额外支持:
- 应用级
features - 应用级
session - 更完整的
default_action覆盖链 - 与
fas.json、模式级dynamic_tuning的联动 - 线程能力拆成
custom_thread + dynamic_thread_scheduler两层
所以线程文档不能只讲 main / gfx / worker,还要把这些可选字段写清楚。
9. 一句话理解
付费版 BPF自定义线程 可以直接记成:
先用
custom_thread决定静态线程规则能不能生效,再由dynamic_thread_scheduler决定要不要继续走线程学习、守护和动态重打。
