Skip to content

Commit

Permalink
Power: Implement PowerHal 1.2
Browse files Browse the repository at this point in the history
Convert all perfd hints into PowerHAL hints

Test: do camera/audio powerhint
Bug: 62041945
Change-Id: I82c8ca99b76d70d716eabedb617a126446646b7d
  • Loading branch information
weivincewang committed Dec 4, 2017
1 parent 7839585 commit 8ce5e19
Show file tree
Hide file tree
Showing 16 changed files with 198 additions and 44 deletions.
4 changes: 2 additions & 2 deletions device.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -611,7 +611,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 += \
Expand Down
2 changes: 1 addition & 1 deletion manifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,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>
Expand Down
6 changes: 3 additions & 3 deletions power/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -53,6 +53,6 @@ LOCAL_SHARED_LIBRARIES := \
libhidltransport \
libhardware \
libutils \
android.hardware.power@1.1 \
android.hardware.power@1.2 \

include $(BUILD_EXECUTABLE)
42 changes: 33 additions & 9 deletions power/Power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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;
Expand All @@ -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();
}

Expand Down Expand Up @@ -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
24 changes: 14 additions & 10 deletions power/Power.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -27,29 +27,33 @@
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.

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.

Expand All @@ -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
4 changes: 0 additions & 4 deletions power/[email protected]

This file was deleted.

4 changes: 4 additions & 0 deletions power/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
service vendor.power-hal-1-2 /vendor/bin/hw/[email protected]
class hal
user system
group system
6 changes: 6 additions & 0 deletions power/hint-data.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
99 changes: 94 additions & 5 deletions power/power-8998.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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");
Expand Down
6 changes: 6 additions & 0 deletions power/power-helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion power/powerhintparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit 8ce5e19

Please sign in to comment.