本文介绍高通PerfLock的使用。
PerfLock 架构
Perflock的API封装在libqti-perfd-client.so库里面(源码在android/vendor/qcom/proprietary/commonsys-intf/android-perf/mp-ctl/client.cpp
),主要包含三个方法:
int perf_lock_acq(int handle, int duration, int list[], int numArgs)
int perf_lock_rel(int handle)
int perf_hint(int hint, const char *pkg, int duration, int type)
Perflock的使用
可以通过perf_lock_acq和perf_lock_rel来提频操作。
handle参数
调用perf_lock_acq或perf_hint会返回一个handle,该Handle可以存起来后面继续使用。
第一次调用perf_lock_acq或perf_hint方法时,handle为0,perflock会创建一个新的handle
示例:
mHandle = (m_pPerfLockOps->perfLockAcquire(mHandle,
timer,
m_pPerflockInfo->perfLockParams,
m_pPerflockInfo->perfLockParamsCount));
duration
表示要让Perf engine LOCK住多久,单位是ms。
如果设置为0,则表示无限时间。
list[] 和 numArgs
list[]
是要传递给Perf Engine的参数,每2个参数为一组[resource, value]
,numArgs为参数个数。
list[] 和 numArgs示例:
{ // PERF_LOCK_OPEN_CAMERA
perfLockParamsOpenCamera,
sizeof(perfLockParamsOpenCamera) / sizeof(INT32)
},
perfLockParamsOpenCamera定义为:
static INT32 perfLockParamsOpenCamera[] =
{
// Disable power collapse and set CPU clocks to turbo
MPCTLV3_ALL_CPUS_PWR_CLPS_DIS, 0x1,
MPCTLV3_SCHED_BOOST, 0x1,
MPCTLV3_MAX_FREQ_CLUSTER_BIG_CORE_0, 0xFFF,
MPCTLV3_MIN_FREQ_CLUSTER_BIG_CORE_0, 0xFFF,
MPCTLV3_MAX_FREQ_CLUSTER_LITTLE_CORE_0, 0xFFF,
MPCTLV3_MIN_FREQ_CLUSTER_LITTLE_CORE_0, 0xFFF,
MPCTLV3_MIN_FREQ_CLUSTER_PLUS_CORE_0, 0xFFF,
MPCTLV3_MAX_FREQ_CLUSTER_PLUS_CORE_0, 0xFFF
};
可以看出来Open Camera时是
- 关闭power collapse
- 使能SCHED_BOOST
- 大核、小核、超大核都切成turbo模式
perf_lock_rel
释放持有的perfLock,具体是哪个perflock由参数handle决定。
如果perf_lock_acq有设置duration,则不需要调用perf_lock_rel。
示例
在一个Native进程中使用PerfLock来调出两个核。
Makefile
LOCAL_SHARED_LIBRARIES := liblog libcutils libdl libqti-perfd-client
LOCAL_C_INCLUDES := device/qcom/common/power
源代码
#include <dlfcn.h>
#include “performance.h”
static void *qcopt_handle;
static int (*perf_lock_acq)(int handle, int duration, int list[], int numArgs);
static int (*perf_lock_rel)(int handle);
static int perf_lock_handle;
char opt_lib_path[PATH_MAX] = {0};
if (property_get("ro.vendor.extension_library", opt_lib_path, NULL) != 0) {
if((qcopt_handle = dlopen(opt_lib_path, RTLD_NOW)) == NULL) {
error_out();
} else {
perf_lock_acq = (int(*)(int, int, int*,int))dlsym(qcopt_handle, "perf_lock_acq");
perf_lock_rel = (int(*)(int))dlsym(qcopt_handle, "perf_lock_rel");
}
}
int perf_lock_opts[1] = {CPUS_ONLINE_MIN_2};
perf_lock_handle = perf_lock_acq(perf_lock_handle, 0, perf_lock_opts, 1);
// Critical section requiring PerfLock
perf_lock_rel(perf_lock_handle);
具体可参考代码:vendor/qcom/proprietary/android-perf/tests/ModuleTests/mp-ctl/perflock_native_test.cpp
PowerHint的使用
使用PowerHint需要先在powerhint.xml里面定义一个HintID,然后再调用perf_hint
让其生效。
PowerHint XML位置: vendor/qcom/opensource/power/config/bengal/powerhint.xml
,系统中,该文件存放在/vendor/etc/powerhint.xml"
其他XML文件位置定义如下:
#define PERF_MAPPING_XML "/vendor/etc/perf/perfmapping.xml"
#define PERF_BOOSTS_CONFIGS_XML "/vendor/etc/perf/perfboostsconfig.xml"
#define POWER_CONFIGS_XML "/vendor/etc/powerhint.xml"
#define COMMONRESOURCE_CONFIGS_XML "/vendor/etc/perf/commonresourceconfigs.xml"
#define TARGETRESOURCE_CONFIGS_XML "/vendor/etc/perf/targetresourceconfigs.xml"
语法:
int perf_hint(int hint, const char *pkg, int duration, int type)
参数:
- hint- 识别每个Hit的ID。
- Pkg- 谁触发这个Hint。
- Duration- Duration of the hint perflock.
- Type- To differentiate between similar action, like horizontal scroll/vertical scroll,一般可以传-1。
常用Resource ID
Resource ID | Resource Name | Description | Description |
---|---|---|---|
0x40400000 | MPCTLV3_TOGGLE_POWER_COLLAPSE | 是否允许CPU进入深度低功耗模式 | /dev/cpu_dma_latency,默认空,不允许则设置为1 |
0x40C00000 | MPCTLV3_SCHED_BOOST 1 (Fullthrottle), 2(Conservative),3(Restrained) |
SCHED加速类型 | /proc/sys/kernel/sched_boost |
0x40800100 | MPCTLV3_MIN_FREQ_CLUSTERLITTLE CORE_0 | 设置小核最小频率,十六进制 | /sys/module/msm_performance/p arameters/cpu_min_freq |
0x40804100 | MPCTLV3_MAX_FREQ_CLUSTERLITTLE CORE_0 | 设置小核最大频率,十六进制 | /sys/module/msm_performance/p arameters/cpu_max_freq |
0x40800000 | MPCTLV3_MIN_FREQ_CLUSTER_BIG_CO RE_0 | 设置大核最小频率,十六进制 | /sys/module/msm_performance/p arameters/cpu_min_freq |
0x40804000 | MPCTLV3_MAX_FREQ_CLUSTER_BIG_CO RE_0 | 设置大核最大频率,十六进制 | /sys/module/msm_performance/p arameters/cpu_max_freq |
0X42804000 | MPCTLV3_GPU_MIN_POWER_LEVEL | 设置GPU最小PowerLevel,十六进制 | /sys/class/kgsl/kgsl3d0/min_pwrlevel |
0X42808000 | MPCTLV3_GPU_MAX_POWER_LEVEL | 设置GPU最大PowerLevel,十六进制 | /sys/class/kgsl/kgsl3d0/max_pwrlevel |
0x41000000 | MPCTLV3_MIN_ONLINE_CPUCLUSTER BIG | 最小几个大核Online | /sys/devices/system/cpu/cpu*/cor e_ctl/min_cpus |
0x41004000 | MPCTLV3_MAX_ONLINE_CPUCLUSTER BIG | 最多几个大核Online | /sys/devices/system/cpu/cpu*/cor e_ctl/max_cpus |
0x41000100 | MPCTLV3_MIN_ONLINE_CPUCLUSTER LITTLE | 最小几个小核Online | /sys/devices/system/cpu/cpu*/cor e_ctl/min_cpus |
0x41004100 | MPCTLV3_MAX_ONLINE_CPUCLUSTER LITTLE | 最多几个小核Online | /sys/devices/system/cpu/cpu*/cor e_ctl/max_cpus |
0x41000200 | MPCTLV3_MIN_ONLINE_CPUCLUSTER PRIME | 最小几个超大核Online | /sys/devices/system/cpu/cpu*/cor e_ctl/min_cpus |
0x41800000 | MPCTLV3_CPUBW_HWMON_MIN_FREQ | CPU请求的最小DDR频率 | /sys/class/devfreq/soc:qcom,cpub w/min_freq |
0x41818000 | MPCTLV3_CPUBW_HWMON_MAX_FREQ | CPU请求的最大DDR频率 | /sys/class/devfreq/soc:qcom,cpub w/max_freq |
OpenCamera过程中,将所有CPU都拉满
static INT32 perfLockParamsOpenCamera[] =
{
// Disable power collapse and set CPU clocks to turbo
MPCTLV3_ALL_CPUS_PWR_CLPS_DIS, 0x1,
MPCTLV3_SCHED_BOOST, 0x1,
MPCTLV3_MAX_FREQ_CLUSTER_BIG_CORE_0, 0xFFF,
MPCTLV3_MIN_FREQ_CLUSTER_BIG_CORE_0, 0xFFF,
MPCTLV3_MAX_FREQ_CLUSTER_LITTLE_CORE_0, 0xFFF,
MPCTLV3_MIN_FREQ_CLUSTER_LITTLE_CORE_0, 0xFFF,
MPCTLV3_MIN_FREQ_CLUSTER_PLUS_CORE_0, 0xFFF,
MPCTLV3_MAX_FREQ_CLUSTER_PLUS_CORE_0, 0xFFF
};
PerfLock in Camera
CamX
CamX中有一个类:CamxPerfLockManager,封装了对perflock的使用,代码路径为:vendor/qcom/proprietary/camx/src/osutils/camxperf.cpp
CHI
CHI也有一个类:PerfLockManager,封装了对perflock的使用,代码路径为:vendor/qcom/proprietary/chi-cdk/core/chiutils/chxperf.cpp
Perflock 调试
Log
adb root
adb remount(disable verity if needed)
adb shell "echo vendor.debug.trace.perf=1 >> /system/build.prop"
adb reboot
然后从Log里面能看到如下打印:
07-10 16:07:27.575 13212 13212 E ANDR-PERF-MPCTL: perf_lock_acq: client_pid=1007, client_tid=1095, inupt handle=0, duration=80 ms,
num_args=18, list=0x43000000 0x19 0x40800000 0x3E8 0x40800100 0x3E8 0x40800200 0x3E8 0x40C00000 0x2 0x43400000 0x1F40 0x40C74000 0xFF
0x40408000 0x63 0x41000000 0x3
07-10 16:07:27.575 13212 13212 E ANDR-PERF-MPCTL: perf_lock_acq: output handle=1
07-10 16:07:27.576 13212 13212 E ANDR-PERF-MPCTL: perf_lock_acq: client_pid=1007, client_tid=1095, inupt handle=0, duration=0 ms, num_args=18,
list=0x43000000 0x11 0x40800000 0x3E8 0x40800100 0x3E8 0x40800200 0x3E8 0x40C00000 0x2 0x43400000 0x1F40 0x40C74000 0xFF 0x40408000 0x63
0x41000000 0x3
07-10 16:07:27.576 13212 13212 E ANDR-PERF-MPCTL: perf_lock_acq: output handle=2
07-10 16:07:27.649 13212 13213 E ANDR-PERF-MPCTL: perf_lock_rel: input handle=2
07-10 16:07:27.660 13212 13213 E ANDR-PERF-MPCTL: perf_lock_rel: input handle=1
如果需要更多Log,可以打开QC_DEBUG
:
在vendor/qcom/proprietary/android-perf/mp-ctl/
, 在makefile中打开 QC_DEBUG flag
Dump
可以执行
dumpsys vendor.perfservice
来dump 处于active状态的 request list。
实验验证CPU/GPU/DDR最高频
关闭perflock和thermal
adb shell su -c setenforce 0
adb shell stop thermal-engine
adb shell stop perf-hal-1-0
adb shell stop perfd
perf-hal的版本要注意不一定是1.0,具体的perf hal版本可以参考:vendor/qcom/proprietary/android-perf/perf-hal/xxxx.rc
关闭 low power model
adb shell "echo Y > /sys/module/lpm_levels/parameters/sleep_disabled“
online 所有 cpus
adb shell "echo 4 > /sys/devices/system/cpu/cpu0/core_ctl/min_cpus“
adb shell "echo 4 > /sys/devices/system/cpu/cpu0/core_ctl/max_cpus“
adb shell "echo 4 > /sys/devices/system/cpu/cpu4/core_ctl/min_cpus"
adb shell "echo 4 > /sys/devices/system/cpu/cpu4/core_ctl/max_cpus"
adb shell "echo 1 > /sys/devices/system/cpu/cpu0/online"
adb shell "echo 1 > /sys/devices/system/cpu/cpu1/online"
adb shell "echo 1 > /sys/devices/system/cpu/cpu2/online"
adb shell "echo 1 > /sys/devices/system/cpu/cpu3/online"
adb shell "echo 1 > /sys/devices/system/cpu/cpu4/online"
adb shell "echo 1 > /sys/devices/system/cpu/cpu5/online"
adb shell "echo 1 > /sys/devices/system/cpu/cpu6/online"
adb shell "echo 1 > /sys/devices/system/cpu/cpu7/online"
cpufreq performance
adb shell "echo performance > /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor"
或
adb shell "echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor"
adb shell "echo performance > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor"
adb shell "echo performance > /sys/devices/system/cpu/cpu2/cpufreq/scaling_governor"
adb shell "echo performance > /sys/devices/system/cpu/cpu3/cpufreq/scaling_governor"
adb shell "echo performance > /sys/devices/system/cpu/cpu4/cpufreq/scaling_governor"
adb shell "echo performance > /sys/devices/system/cpu/cpu5/cpufreq/scaling_governor"
adb shell "echo performance > /sys/devices/system/cpu/cpu6/cpufreq/scaling_governor"
adb shell "echo performance > /sys/devices/system/cpu/cpu7/cpufreq/scaling_governor"
gpu performance
adb shell stop mpdecision
adb shell "echo 0 > /sys/class/kgsl/kgsl-3d0/min_pwrlevel"
adb shell "echo 0 > /sys/class/kgsl/kgsl-3d0/max_pwrlevel"
adb shell "echo 1 > /sys/class/kgsl/kgsl-3d0/force_rail_on"
adb shell "echo 1 > /sys/class/kgsl/kgsl-3d0/force_clk_on"
adb shell "echo 1 > /sys/class/kgsl/kgsl-3d0/force_bus_on"
adb shell "echo 10000000 > /sys/class/kgsl/kgsl-3d0/idle_timer"
adb shell "echo performance > /sys/class/kgsl/kgsl-3d0/devfreq/governor"
ddr performance
adb shell "echo performance >/sys/class/devfreq/*/governor”