Merge "Power: Implement PowerHal 1.2"

This commit is contained in:
Wei Wang
2017-12-06 00:13:17 +00:00
committed by Android (Google) Code Review
16 changed files with 198 additions and 44 deletions

View File

@@ -170,7 +170,7 @@ PRODUCT_COPY_FILES += \
# power HAL
PRODUCT_PACKAGES += \
android.hardware.power@1.1-service.wahoo
android.hardware.power@1.2-service.wahoo
PRODUCT_COPY_FILES += \
$(LOCAL_PATH)/powerhint.xml:$(TARGET_COPY_OUT_VENDOR)/etc/powerhint.xml
@@ -616,7 +616,7 @@ PRODUCT_PROPERTY_OVERRIDES += \
# Enable CameraHAL perfd usage
PRODUCT_PROPERTY_OVERRIDES += \
persist.camera.perfd.enable=true
persist.camera.perfd.enable=false
# Enable Gcam FD Ensemble
PRODUCT_PROPERTY_OVERRIDES += \

View File

@@ -228,7 +228,7 @@
<hal format="hidl">
<name>android.hardware.power</name>
<transport>hwbinder</transport>
<version>1.1</version>
<version>1.2</version>
<interface>
<name>IPower</name>
<instance>default</instance>

View File

@@ -21,8 +21,8 @@ LOCAL_PROPRIETARY_MODULE := true
LOCAL_MODULE_OWNER := qcom
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := android.hardware.power@1.1-service.wahoo
LOCAL_INIT_RC := android.hardware.power@1.1-service.wahoo.rc
LOCAL_MODULE := android.hardware.power@1.2-service.wahoo
LOCAL_INIT_RC := android.hardware.power@1.2-service.wahoo.rc
LOCAL_SRC_FILES := service.cpp \
Power.cpp \
InteractionHandler.cpp \
@@ -53,6 +53,6 @@ LOCAL_SHARED_LIBRARIES := \
libhidltransport \
libhardware \
libutils \
android.hardware.power@1.1 \
android.hardware.power@1.2 \
include $(BUILD_EXECUTABLE)

View File

@@ -14,10 +14,10 @@
* limitations under the License.
*/
#define LOG_TAG "android.hardware.power@1.1-service.wahoo"
#define LOG_TAG "android.hardware.power@1.2-service.wahoo"
#include <android/log.h>
#include <android-base/file.h>
#include <android-base/logging.h>
#include <android-base/properties.h>
#include <android-base/strings.h>
#include <utils/Log.h>
@@ -33,14 +33,14 @@ extern struct stat_pair rpm_stat_map[];
namespace android {
namespace hardware {
namespace power {
namespace V1_1 {
namespace V1_2 {
namespace implementation {
using ::android::hardware::power::V1_0::Feature;
using ::android::hardware::power::V1_0::PowerHint;
using ::android::hardware::power::V1_0::PowerStatePlatformSleepState;
using ::android::hardware::power::V1_0::Status;
using ::android::hardware::power::V1_1::PowerStateSubsystem;
using ::android::hardware::power::V1_1::PowerStateSubsystemSleepState;
using ::android::hardware::hidl_vec;
using ::android::hardware::Return;
using ::android::hardware::Void;
@@ -59,9 +59,9 @@ Return<void> Power::setInteractive(bool interactive) {
return Void();
}
Return<void> Power::powerHint(PowerHint hint, int32_t data) {
Return<void> Power::powerHint(PowerHint_1_0 hint, int32_t data) {
if (android::base::GetProperty("init.svc.vendor.perfd", "") != "running") {
ALOGW("perfd is not started");
LOG(WARNING) << "perfd is not started";
return Void();
}
@@ -192,18 +192,42 @@ bool Power::isSupportedGovernor() {
if (buf == SCHEDUTIL_GOVERNOR || buf == SCHED_GOVERNOR || buf == INTERACTIVE_GOVERNOR) {
return true;
} else {
ALOGE("Governor not supported by powerHAL, skipping");
LOG(ERROR) << "Governor not supported by powerHAL, skipping";
return false;
}
}
Return<void> Power::powerHintAsync(PowerHint hint, int32_t data) {
Return<void> Power::powerHintAsync(PowerHint_1_0 hint, int32_t data) {
// just call the normal power hint in this oneway function
return powerHint(hint, data);
}
// Methods from ::android::hardware::power::V1_2::IPower follow.
Return<void> Power::powerHintAsync_1_2(PowerHint_1_2 hint, int32_t data) {
switch(hint) {
case PowerHint_1_2::AUDIO_LOW_LATENCY:
process_audio_low_latency_hint(data);
break;
case PowerHint_1_2::AUDIO_STREAMING:
process_audio_streaming_hint(data);
break;
case PowerHint_1_2::CAMERA_LAUNCH:
process_camera_launch_hint(data);
break;
case PowerHint_1_2::CAMERA_STREAMING:
process_camera_streaming_hint(data);
break;
case PowerHint_1_2::CAMERA_SHOT:
process_camera_shot_hint(data);
break;
default:
return powerHint(static_cast<PowerHint_1_0>(hint), data);
}
return Void();
}
} // namespace implementation
} // namespace V1_1
} // namespace V1_2
} // namespace power
} // namespace hardware
} // namespace android

View File

@@ -14,10 +14,10 @@
* limitations under the License.
*/
#ifndef ANDROID_HARDWARE_POWER_V1_1_POWER_H
#define ANDROID_HARDWARE_POWER_V1_1_POWER_H
#ifndef ANDROID_HARDWARE_POWER_V1_2_POWER_H
#define ANDROID_HARDWARE_POWER_V1_2_POWER_H
#include <android/hardware/power/1.1/IPower.h>
#include <android/hardware/power/1.2/IPower.h>
#include <hidl/MQDescriptor.h>
#include <hidl/Status.h>
#include <hardware/power.h>
@@ -27,15 +27,16 @@
namespace android {
namespace hardware {
namespace power {
namespace V1_1 {
namespace V1_2 {
namespace implementation {
using ::android::hardware::power::V1_0::Feature;
using ::android::hardware::power::V1_0::PowerHint;
using ::android::hardware::power::V1_1::IPower;
using ::android::hardware::power::V1_2::IPower;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::InteractionHandler;
using PowerHint_1_0 = ::android::hardware::power::V1_0::PowerHint;
using PowerHint_1_2 = ::android::hardware::power::V1_2::PowerHint;
struct Power : public IPower {
// Methods from ::android::hardware::power::V1_0::IPower follow.
@@ -43,13 +44,16 @@ struct Power : public IPower {
Power();
Return<void> setInteractive(bool interactive) override;
Return<void> powerHint(PowerHint hint, int32_t data) override;
Return<void> powerHint(PowerHint_1_0 hint, int32_t data) override;
Return<void> setFeature(Feature feature, bool activate) override;
Return<void> getPlatformLowPowerStats(getPlatformLowPowerStats_cb _hidl_cb) override;
// Methods from ::android::hardware::power::V1_1::IPower follow.
Return<void> getSubsystemLowPowerStats(getSubsystemLowPowerStats_cb _hidl_cb) override;
Return<void> powerHintAsync(PowerHint hint, int32_t data) override;
Return<void> powerHintAsync(PowerHint_1_0 hint, int32_t data) override;
// Methods from ::android::hardware::power::V1_2::IPower follow.
Return<void> powerHintAsync_1_2(PowerHint_1_2 hint, int32_t data) override;
// Methods from ::android::hidl::base::V1_0::IBase follow.
@@ -59,9 +63,9 @@ struct Power : public IPower {
};
} // namespace implementation
} // namespace V1_1
} // namespace V1_2
} // namespace power
} // namespace hardware
} // namespace android
#endif // ANDROID_HARDWARE_POWER_V1_1_POWER_H
#endif // ANDROID_HARDWARE_POWER_V1_2_POWER_H

View File

@@ -1,4 +0,0 @@
service vendor.power-hal-1-1 /vendor/bin/hw/android.hardware.power@1.1-service.wahoo
class hal
user system
group system

View File

@@ -0,0 +1,4 @@
service vendor.power-hal-1-2 /vendor/bin/hw/android.hardware.power@1.2-service.wahoo
class hal
user system
group system

View File

@@ -39,6 +39,12 @@
#define INTERACTION_HINT_ID (0x1A00)
#define BOOST_HINT_ID (0x1B00)
#define CAMERA_LAUNCH_HINT_ID (0x0B0A)
#define CAMERA_STREAMING_HINT_ID (0x0C0A)
#define CAMERA_SHOT_HINT_ID (0x0D0A)
#define AUDIO_STREAMING_HINT_ID (0x0E0A)
#define AUDIO_LOW_LATENCY_HINT_ID (0x0F0A)
struct hint_data {
unsigned long hint_id; /* This is our key. */
unsigned long perflock_handle;

View File

@@ -180,18 +180,18 @@ static int process_vr_mode_hint(void *data)
return HINT_HANDLED;
}
static int process_boost(int boost_handle, int duration)
static int process_boost(int hint_id, int boost_handle, int duration)
{
int *resource_values;
int resources;
resource_values = getPowerhint(BOOST_HINT_ID, &resources);
resource_values = getPowerhint(hint_id, &resources);
if (resource_values != NULL) {
boost_handle = interaction_with_handle(
boost_handle, duration, resources, resource_values);
if (!CHECK_HANDLE(boost_handle)) {
ALOGE("Failed interaction_with_handle for boost_handle");
ALOGE("Failed interaction_with_handle for hint_id %d", hint_id);
}
}
@@ -205,7 +205,7 @@ static int process_video_encode_hint(void *data)
if (data) {
// TODO: remove the launch boost based on camera launch time
int duration = 2000; // boosts 2s for starting encoding
boost_handle = process_boost(boost_handle, duration);
boost_handle = process_boost(BOOST_HINT_ID, boost_handle, duration);
ALOGD("LAUNCH ENCODER-ON: %d MS", duration);
int *resource_values = NULL;
int resources = 0;
@@ -222,6 +222,95 @@ static int process_video_encode_hint(void *data)
return HINT_NONE;
}
int process_camera_launch_hint(int32_t duration)
{
static int cam_launch_handle = -1;
if (duration > 0) {
cam_launch_handle = process_boost(CAMERA_LAUNCH_HINT_ID, cam_launch_handle, duration);
ALOGD("CAMERA LAUNCH ON: %d MS", duration);
return HINT_HANDLED;
} else if (duration == 0) {
release_request(cam_launch_handle);
ALOGD("CAMERA LAUNCH OFF");
return HINT_HANDLED;
} else {
ALOGE("CAMERA LAUNCH INVALID DATA: %d", duration);
}
return HINT_NONE;
}
int process_camera_streaming_hint(int32_t duration)
{
static int cam_streaming_handle = -1;
if (duration > 0) {
cam_streaming_handle = process_boost(CAMERA_STREAMING_HINT_ID, cam_streaming_handle, duration);
ALOGD("CAMERA STREAMING ON: %d MS", duration);
return HINT_HANDLED;
} else if (duration == 0) {
release_request(cam_streaming_handle);
ALOGD("CAMERA STREAMING OFF");
return HINT_HANDLED;
} else {
ALOGE("CAMERA STREAMING INVALID DATA: %d", duration);
}
return HINT_NONE;
}
int process_camera_shot_hint(int32_t duration)
{
static int cam_shot_handle = -1;
if (duration > 0) {
cam_shot_handle = process_boost(CAMERA_SHOT_HINT_ID, cam_shot_handle, duration);
ALOGD("CAMERA SHOT ON: %d MS", duration);
return HINT_HANDLED;
} else if (duration == 0) {
release_request(cam_shot_handle);
ALOGD("CAMERA SHOT OFF");
return HINT_HANDLED;
} else {
ALOGE("CAMERA SHOT INVALID DATA: %d", duration);
}
return HINT_NONE;
}
int process_audio_streaming_hint(int32_t duration)
{
static int audio_streaming_handle = -1;
if (duration > 0) {
// set max duration 2s for starting audio
audio_streaming_handle = process_boost(AUDIO_STREAMING_HINT_ID, audio_streaming_handle, 2000);
ALOGD("AUDIO STREAMING ON");
return HINT_HANDLED;
} else if (duration == 0) {
release_request(audio_streaming_handle);
ALOGD("AUDIO STREAMING OFF");
return HINT_HANDLED;
} else {
ALOGE("AUDIO STREAMING INVALID DATA: %d", duration);
}
return HINT_NONE;
}
int process_audio_low_latency_hint(int32_t data)
{
static int audio_low_latency_handle = -1;
if (data) {
// Hint until canceled
audio_low_latency_handle = process_boost(AUDIO_LOW_LATENCY_HINT_ID, audio_low_latency_handle, 0);
ALOGD("AUDIO LOW LATENCY ON");
} else {
release_request(audio_low_latency_handle);
ALOGD("AUDIO LOW LATENCY OFF");
return HINT_HANDLED;
}
return HINT_HANDLED;
}
static int process_activity_launch_hint(void *data)
{
// boost will timeout in 1.25s
@@ -236,7 +325,7 @@ static int process_activity_launch_hint(void *data)
// restart the launch hint if the framework has not yet released
// this shouldn't happen, but we've seen bugs where it could
if (data) {
launch_handle = process_boost(launch_handle, duration);
launch_handle = process_boost(BOOST_HINT_ID, launch_handle, duration);
if (launch_handle > 0) {
launch_mode = 1;
ALOGD("Activity launch hint handled");

View File

@@ -102,6 +102,12 @@ int extract_wlan_stats(uint64_t *list);
int is_perf_hint_active(int hint);
int process_camera_launch_hint(int32_t duration);
int process_camera_streaming_hint(int32_t duration);
int process_camera_shot_hint(int32_t duration);
int process_audio_streaming_hint(int32_t duration);
int process_audio_low_latency_hint(int32_t data);
#ifdef __cplusplus
}
#endif

View File

@@ -31,7 +31,7 @@
#define __POWERHINTPARSER__
#define POWERHINT_XML "/vendor/etc/powerhint.xml"
#define MAX_HINT 8
#define MAX_HINT 16
#define MAX_PARAM 30
typedef struct perflock_param_t {

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
#define LOG_TAG "android.hardware.power@1.1-service.wahoo"
#define LOG_TAG "android.hardware.power@1.2-service.wahoo"
#include <android/log.h>
#include <hidl/HidlTransportSupport.h>
@@ -30,15 +30,15 @@ using android::hardware::configureRpcThreadpool;
using android::hardware::joinRpcThreadpool;
// Generated HIDL files
using android::hardware::power::V1_1::IPower;
using android::hardware::power::V1_1::implementation::Power;
using android::hardware::power::V1_2::IPower;
using android::hardware::power::V1_2::implementation::Power;
int main() {
status_t status;
android::sp<IPower> service = nullptr;
ALOGI("Power HAL Service 1.1 for Wahoo is starting.");
ALOGI("Power HAL Service 1.2 for Wahoo is starting.");
service = new Power();
if (service == nullptr) {

View File

@@ -74,4 +74,29 @@
<Resource opcode="0x40400000" value="0x1"/> <!-- POWER_COLLAPSE -->
<Resource opcode="0x41800000" value="0x8C"/> <!-- CPUBW min freq 1804 MHz -->
</Hint>
<Hint type="0x0B0A"> <!--CAMERA LAUNCH-->
<Resource opcode="0x40800000" value="0xFFF"/> <!-- B CPU - Cluster min freq ~ max -->
<Resource opcode="0x40800100" value="0xFFF"/> <!-- L CPU - Cluster min freq ~ max -->
<Resource opcode="0x40400000" value="0x1"/> <!-- POWER_COLLAPSE -->
</Hint>
<Hint type="0x0C0A"> <!--CAMERA STREAMING-->
<Resource opcode="0x40800000" value="0xFFF"/> <!-- B CPU - Cluster min freq ~ max -->
<Resource opcode="0x40800100" value="0xFFF"/> <!-- L CPU - Cluster min freq ~ max -->
<Resource opcode="0x40400000" value="0x1"/> <!-- POWER_COLLAPSE -->
</Hint>
<Hint type="0x0D0A"> <!--CAMERA SHOT-->
<Resource opcode="0x40800000" value="0xFFF"/> <!-- B CPU - Cluster min freq ~ max -->
<Resource opcode="0x40800100" value="0xFFF"/> <!-- L CPU - Cluster min freq ~ max -->
<Resource opcode="0x40400000" value="0x1"/> <!-- POWER_COLLAPSE -->
<Resource opcode="0x4180C000" value="0x0"/> <!-- CPUBW disable hysteresis -->
<Resource opcode="0x41800000" value="0x8C"/> <!-- CPUBW min freq 1804 MHz -->
</Hint>
<Hint type="0x0E0A"> <!--AUDIO STREAMING-->
<Resource opcode="0x40400000" value="0x1"/> <!-- POWER_COLLAPSE -->
<Resource opcode="0x40800000" value="0x579"/> <!-- B CPU - Cluster min freq ~1.4 Ghz -->
</Hint>
<Hint type="0x0F0A"> <!--AUDIO_LOW_LATENCY-->
<Resource opcode="0x40400000" value="0x1"/> <!-- POWER_COLLAPSE -->
</Hint>
</Powerhint>

View File

@@ -1,6 +1,4 @@
binder_call(audioserver, bootanim)
allow audioserver perfd_socket:sock_file write;
allow audioserver sysfs_soc:file r_file_perms;
allow audioserver sysfs_soc:dir search;

View File

@@ -168,7 +168,7 @@
/vendor/bin/oemlock_provision u:object_r:hal_bootctl_default_exec:s0
/vendor/bin/oemlock-bridge u:object_r:hal_bootctl_default_exec:s0
/vendor/bin/hw/android\.hardware\.usb@1\.1-service.wahoo u:object_r:hal_usb_default_exec:s0
/vendor/bin/hw/android\.hardware\.power@1\.1-service.wahoo u:object_r:hal_power_default_exec:s0
/vendor/bin/hw/android\.hardware\.power@1\.2-service.wahoo u:object_r:hal_power_default_exec:s0
/vendor/bin/hw/android\.hardware\.thermal@1\.0-service.wahoo u:object_r:hal_thermal_default_exec:s0
/vendor/bin/chre u:object_r:chre_exec:s0
/vendor/bin/time_daemon u:object_r:time_daemon_exec:s0

View File

@@ -3,8 +3,10 @@ r_dir_file(hal_audio_default, sysfs_soc)
allow hal_audio_default audio_vendor_data_file:dir rw_dir_perms;
allow hal_audio_default audio_vendor_data_file:file create_file_perms;
allow hal_audio_default perfd:unix_stream_socket connectto;
allow hal_audio_default perfd_socket:sock_file write;
dontaudit hal_audio_default perfd:unix_stream_socket connectto;
dontaudit hal_audio_default perfd_socket:sock_file write;
hal_client_domain(hal_audio_default, hal_power)
userdebug_or_eng(`
allow hal_audio diag_device:chr_file rw_file_perms;