Android 11(R) Power HAL AIDL简析 -- 基本接口
Android 11(R) Power HAL AIDL简析 -- Service功能实现
Android 11(R) Power HAL AIDL简析 -- 应用实例
Android 11 引入了在 Android 中使用 AIDL 实现 HAL 的功能。这样就可以在不使用 HIDL 的情况下实现 Android 的部分代码。Power HAL模块即可以采用AIDL方式来实现。在Android 11中已经引入这个Power AIDL Interface,源码位于:
/hardware/interfaces/power/aidl/
在学习这部分之前,推荐阅读AIDL的相关知识,特别是Android 10之后引入的对稳定的 Android 接口定义语言 (AIDL) 的支持(stable AIDL),这里放上几篇官网链接:
1. 在Androi源码目录/hardware/interfaces/power/aidl/android/hardware/power/下定义了三个aidl文件,分别为:
IPower.aidl
定义 power hal接口
Mode.aidl
定义各种 power mode
Boost.aidl
定义Boost type
2. aidl_api目录:对于Stable AIDL,从 Android 11 开始,versions
冻结在 aidl_api/name
下,和AIDL接口版本相关。
3. default目录:功能实现的一个示例代码,实现了一个android.hardware.power-service.example 这个aidl service
4. vts目录:vts测试用例
先看看IPower源码是如何定义的,interface IPower的源码定义如下:
点击查看IPower代码
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.hardware.power;
import android.hardware.power.Boost;
import android.hardware.power.Mode;
@VintfStability
interface IPower {
/**
* setMode() is called to enable/disable specific hint mode, which
* may result in adjustment of power/performance parameters of the
* cpufreq governor and other controls on device side.
*
* A particular platform may choose to ignore any mode hint.
*
* @param type Mode which is to be enable/disable.
* @param enabled true to enable, false to disable the mode.
*/
oneway void setMode(in Mode type, in boolean enabled);
/**
* isModeSupported() is called to query if the given mode hint is
* supported by vendor.
*
* @return true if the hint passed is supported on this platform.
* If false, setting the mode will have no effect.
* @param type Mode to be queried
*/
boolean isModeSupported(in Mode type);
/**
* setBoost() indicates the device may need to boost some resources, as the
* the load is likely to increase before the kernel governors can react.
* Depending on the boost, it may be appropriate to raise the frequencies of
* CPU, GPU, memory subsystem, or stop CPU from going into deep sleep state.
* A particular platform may choose to ignore this hint.
*
* @param type Boost type which is to be set with a timeout.
* @param durationMs The expected duration of the user's interaction, if
* known, or 0 if the expected duration is unknown.
* a negative value indicates canceling previous boost.
* A given platform can choose to boost some time based on durationMs,
* and may also pick an appropriate timeout for 0 case.
*/
oneway void setBoost(in Boost type, in int durationMs);
/**
* isBoostSupported() is called to query if the given boost hint is
* supported by vendor. When returns false, set the boost will have
* no effect on the platform.
*
* @return true if the hint passed is supported on this platform.
* If false, setting the boost will have no effect.
* @param type Boost to be queried
*/
boolean isBoostSupported(in Boost type);
}
从源码中可以看到,IPower的定义还是比较简单的,只提供了4个接口,从源码注释也很容易理解其作用,下面我们简单总结一下:
接口名称
参数
返回值
作用
setMode
Mode type:开启或关闭的Power Mode
boolean enabled:true表示开启,false表示关闭
无
调用这个接口可以启用/禁用特定Power Mode,这可能导致cpufreq调控器或设备端其他控件的power/performance参数调整。
isModeSupported
Mode type:要查询的Power Mode
true:支持
fasle:不支持
查询给定的Power Mode是否支持
setBoost
Boost type:需要设置的type
int durationMs:已知情况下的用户交互的预期时间。值为0表示未知预期时间,负值表示取消上一次的boost
无
表示设备可能需要增加一些资源,因为在内核调控器做出反应之前,负载可能会增加。根据增压情况,可能适合提高CPU、GPU、内存子系统的频率或停止CPU进入深度睡眠状态.
isBoostSupported
Boost type:要查询的Boost type
true:支持
fasle:不支持
查询给定的Boost type是否支持
先看一下AIDL文件中的定义
点击查看PowerMode源码
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.hardware.power;
@VintfStability
@Backing(type="int")
enum Mode {
/**
* This mode indicates that the device is to allow wake up when the
* screen is tapped twice.
*/
DOUBLE_TAP_TO_WAKE,
/**
* This mode indicates Low power mode is activated or not. Low power
* mode is intended to save battery at the cost of performance.
*/
LOW_POWER,
/**
* This mode indicates Sustained Performance mode is activated or not.
* Sustained performance mode is intended to provide a consistent level of
* performance for a prolonged amount of time.
*/
SUSTAINED_PERFORMANCE,
/**
* Sets the device to a fixed performance level which can be sustained under
* normal indoor conditions for at least 10 minutes.
*
* This is similar to sustained performance mode, except that whereas
* sustained performance mode puts an upper bound on performance in the
* interest of long-term stability, fixed performance mode puts both upper
* and lower bounds on performance such that any workload run while in a
* fixed performance mode should complete in a repeatable amount of time
* (except if the device is under thermal throttling).
*
* This mode is not intended for general purpose use, but rather to enable
* games and other performance-sensitive applications to reduce the number
* of variables during profiling and performance debugging. As such, while
* it is valid to set the device to minimum clocks for all subsystems in
* this mode, it is preferable to attempt to make the relative performance
* of the CPU, GPU, and other subsystems match typical usage, even if the
* frequencies have to be reduced to provide sustainability.
*
* To calibrate this mode, follow these steps:
*
* 1) Build and push the HWUI macrobench as described in
* //frameworks/base/libs/hwui/tests/macrobench/how_to_run.txt
* 2) Run the macrobench as follows:
* while true; do \
* adb shell /data/benchmarktest/hwuimacro/hwuimacro shadowgrid2 -c 200 -r 10; \
* done
* 3) Determine a fixed set of device clocks such that the loop in (2) can
* run for at least 10 minutes, starting from an idle device on a desk
* at room temperature (roughly 22 Celsius), without hitting thermal
* throttling.
* 4) After setting those clocks, set the system property
* ro.power.fixed_performance_scale_factor to a value N, where N is the
* number of times the loop from (2) runs during the 10 minute test
* cycle. It is expected that in FIXED_PERFORMANCE mode, unless there is
* thermal throttling, the loop will run N to N+1 times (inclusive).
*
* After calibrating this, while in FIXED_PERFORMANCE mode, the macrobench
* results obtained while running the loop in (2) should be consistent both
* within a given run and from the first run in the 10 minute window through
* the last run in the window.
*/
FIXED_PERFORMANCE,
/**
* This mode indicates VR Mode is activated or not. VR mode is intended
* to provide minimum guarantee for performance for the amount of time the
* device can sustain it.
*/
VR,
/**
* This mode indicates that an application has been launched.
*/
LAUNCH,
/**
* This mode indicates that the device is about to enter a period of
* expensive rendering.
*/
EXPENSIVE_RENDERING,
/**
* This mode indicates that the device is about entering/leaving
* interactive state. (that is, the system is awake and ready for
* interaction, often with UI devices such as display and touchscreen
* enabled) or non-interactive state (the
* system appears asleep, display usually turned off). The
* non-interactive state may be entered after a period of
* inactivity in order to conserve battery power during
* such inactive periods.
*
* Typical actions are to turn on or off devices and adjust
* cpufreq parameters. This function may also call the
* appropriate interfaces to allow the kernel to suspend the
* system to low-power sleep state when entering non-interactive
* state, and to disallow low-power suspend when the system is in
* interactive state. When low-power suspend state is allowed, the
* kernel may suspend the system whenever no wakelocks are held.
*/
INTERACTIVE,
/**
* This mode indicates the device is in device idle, externally known as doze.
* More details on:
* https://developer.android.com/training/monitoring-device-state/doze-standby
*/
DEVICE_IDLE,
/**
* This mode indicates that display is either off or still on but is optimized
* for low-power.
*/
DISPLAY_INACTIVE,
/**
* Below hints are currently not sent in Android framework but OEM might choose to
* implement for power/perf optimizations.
*/
/**
* This mode indicates that low latency audio is active.
*/
AUDIO_STREAMING_LOW_LATENCY,
/**
* This hint indicates that camera secure stream is being started.
*/
CAMERA_STREAMING_SECURE,
/**
* This hint indicates that camera low resolution stream is being started.
*/
CAMERA_STREAMING_LOW,
/**
* This hint indicates that camera mid resolution stream is being started.
*/
CAMERA_STREAMING_MID,
/**
* This hint indicates that camera high resolution stream is being started.
*/
CAMERA_STREAMING_HIGH,
}
简单介绍各个Mode:
以下提示选项目前未在加入 Android 框架,但 OEM 可能会选择实施电源/性能优化。
首先看一下AIDL的源码:
点击查看Boost代码
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.hardware.power;
@VintfStability
@Backing(type="int")
enum Boost {
/**
* This boost is set when user interacting with the device, for example,
* touchscreen events are incoming. CPU and GPU load may be expected soon,
* and it may be appropriate to raise speeds of CPU, memory bus etc.
* Note that this is different from INTERACTIVE mode, which only indicates
* that such interaction *may* occur, not that it is actively occurring.
*/
INTERACTION,
/**
* This boost indicates that the framework is likely to provide a new
* display frame soon. This implies that the device should ensure that the
* display processing path is powered up and ready to receive that update.
*/
DISPLAY_UPDATE_IMMINENT,
/**
* Below hints are currently not sent in Android framework but OEM might choose to
* implement for power/perf optimizations.
*/
/**
* This boost indicates that the device is interacting with ML accelerator.
*/
ML_ACC,
/**
* This boost indicates that the device is setting up audio stream.
*/
AUDIO_LAUNCH,
/**
* This boost indicates that camera is being launched.
*/
CAMERA_LAUNCH,
/**
* This boost indicates that camera shot is being taken.
*/
CAMERA_SHOT,
}
几个枚举常量的大概解释如下:
通过上面的介绍,应该对power hal aidl有了一个直观的认识,清楚了有哪些接口/哪些模式,下一篇中我们会在此基础上通过一个示例讲解如何实现这个aidl serivice功能。
手机扫一扫
移动阅读更方便
你可能感兴趣的文章