From 0caf630148c3b52a2430d90ec2d7df3ae88e2033 Mon Sep 17 00:00:00 2001 From: Jesse Chan Date: Tue, 30 Jun 2020 22:22:42 +0800 Subject: [PATCH] power-libperfmgr: implement Lineage perf profiles Change-Id: Ia247ee65a668689168be009a59355d97ce4f2cca --- hidl/power-libperfmgr/Android.bp | 1 + hidl/power-libperfmgr/Power.cpp | 89 +++++++++++++++++++++++++++++++- hidl/power-libperfmgr/Power.h | 24 ++++++++- 3 files changed, 112 insertions(+), 2 deletions(-) diff --git a/hidl/power-libperfmgr/Android.bp b/hidl/power-libperfmgr/Android.bp index e3d80467..5b010e2c 100644 --- a/hidl/power-libperfmgr/Android.bp +++ b/hidl/power-libperfmgr/Android.bp @@ -41,6 +41,7 @@ cc_binary { "android.hardware.power@1.2", "android.hardware.power@1.3", "libperfmgr", + "vendor.lineage.power@1.0", ], proprietary: true, } diff --git a/hidl/power-libperfmgr/Power.cpp b/hidl/power-libperfmgr/Power.cpp index 942ef94c..a7d8842c 100644 --- a/hidl/power-libperfmgr/Power.cpp +++ b/hidl/power-libperfmgr/Power.cpp @@ -46,6 +46,8 @@ constexpr char kPowerHalStateProp[] = "vendor.powerhal.state"; constexpr char kPowerHalAudioProp[] = "vendor.powerhal.audio"; constexpr char kPowerHalInitProp[] = "vendor.powerhal.init"; constexpr char kPowerHalRenderingProp[] = "vendor.powerhal.rendering"; +constexpr char kPowerHalProfileNumProp[] = "vendor.powerhal.perf_profiles"; +constexpr char kPowerHalProfileProp[] = "vendor.powerhal.perf_profile"; constexpr char kPowerHalConfigPath[] = "/vendor/etc/powerhint.json"; Power::Power() @@ -54,7 +56,9 @@ Power::Power() mVRModeOn(false), mSustainedPerfModeOn(false), mCameraStreamingMode(false), - mReady(false) { + mReady(false), + mNumPerfProfiles(0), + mCurrentPerfProfile(PowerProfile::BALANCED) { mInitThread = std::thread([this]() { android::base::WaitForProperty(kPowerHalInitProp, "1"); mHintManager = HintManager::GetFromJSON(kPowerHalConfigPath); @@ -96,10 +100,30 @@ Power::Power() ALOGI("Initialize with EXPENSIVE_RENDERING on"); mHintManager->DoHint("EXPENSIVE_RENDERING"); } + + state = android::base::GetProperty(kPowerHalProfileProp, ""); + if (state == "POWER_SAVE") { + ALOGI("Initialize with POWER_SAVE profile"); + setProfile(PowerProfile::POWER_SAVE); + mCurrentPerfProfile = PowerProfile::POWER_SAVE; + } else if (state == "BIAS_POWER_SAVE") { + ALOGI("Initialize with BIAS_POWER_SAVE profile"); + setProfile(PowerProfile::BIAS_POWER_SAVE); + mCurrentPerfProfile = PowerProfile::BIAS_POWER_SAVE; + } else if (state == "BIAS_PERFORMANCE") { + ALOGI("Initialize with BIAS_PERFORMANCE profile"); + setProfile(PowerProfile::BIAS_PERFORMANCE); + mCurrentPerfProfile = PowerProfile::BIAS_PERFORMANCE; + } else if (state == "HIGH_PERFORMANCE") { + ALOGI("Initialize with HIGH_PERFORMANCE profile"); + setProfile(PowerProfile::HIGH_PERFORMANCE); + mCurrentPerfProfile = PowerProfile::HIGH_PERFORMANCE; + } // Now start to take powerhint mReady.store(true); ALOGI("PowerHAL ready to process hints"); }); + mNumPerfProfiles = android::base::GetIntProperty(kPowerHalProfileNumProp, 0); mInitThread.detach(); } @@ -115,6 +139,50 @@ Return Power::updateHint(const char *hint, bool enable) { return Void(); } +Return Power::setProfile(PowerProfile profile) { + if (mCurrentPerfProfile == profile) { + return Void(); + } + + // End previous perf profile hints + switch (mCurrentPerfProfile) { + case PowerProfile::POWER_SAVE: + mHintManager->EndHint("PROFILE_POWER_SAVE"); + break; + case PowerProfile::BIAS_POWER_SAVE: + mHintManager->EndHint("PROFILE_BIAS_POWER_SAVE"); + break; + case PowerProfile::BIAS_PERFORMANCE: + mHintManager->EndHint("PROFILE_BIAS_PERFORMANCE"); + break; + case PowerProfile::HIGH_PERFORMANCE: + mHintManager->EndHint("PROFILE_HIGH_PERFORMANCE"); + break; + default: + break; + } + + // Apply perf profile hints + switch (profile) { + case PowerProfile::POWER_SAVE: + mHintManager->DoHint("PROFILE_POWER_SAVE"); + break; + case PowerProfile::BIAS_POWER_SAVE: + mHintManager->DoHint("PROFILE_BIAS_POWER_SAVE"); + break; + case PowerProfile::BIAS_PERFORMANCE: + mHintManager->DoHint("PROFILE_BIAS_PERFORMANCE"); + break; + case PowerProfile::HIGH_PERFORMANCE: + mHintManager->DoHint("PROFILE_HIGH_PERFORMANCE"); + break; + default: + break; + } + + return Void(); +} + // Methods from ::android::hardware::power::V1_0::IPower follow. Return Power::setInteractive(bool interactive) { return updateHint("NOT_INTERACTIVE", !interactive); @@ -297,6 +365,15 @@ Return Power::powerHintAsync_1_3(PowerHint_1_3 hint, int32_t data) { return Void(); } + switch (static_cast(hint)) { + case LineagePowerHint::SET_PROFILE: + setProfile(static_cast(data)); + mCurrentPerfProfile = static_cast(data); + return Void(); + default: + break; + } + if (hint == PowerHint_1_3::EXPENSIVE_RENDERING) { ATRACE_INT(android::hardware::power::V1_3::toString(hint).c_str(), data); if (mVRModeOn || mSustainedPerfModeOn) { @@ -314,6 +391,16 @@ Return Power::powerHintAsync_1_3(PowerHint_1_3 hint, int32_t data) { return Void(); } +// Methods from ::vendor::lineage::power::V1_0::ILineagePower follow. +Return Power::getFeature(LineageFeature feature) { + switch (feature) { + case LineageFeature::SUPPORTED_PROFILES: + return mNumPerfProfiles; + default: + return -1; + } +} + constexpr const char *boolToString(bool b) { return b ? "true" : "false"; } diff --git a/hidl/power-libperfmgr/Power.h b/hidl/power-libperfmgr/Power.h index 0e511dc6..81687b2c 100644 --- a/hidl/power-libperfmgr/Power.h +++ b/hidl/power-libperfmgr/Power.h @@ -28,6 +28,8 @@ #include "InteractionHandler.h" +#include + namespace android { namespace hardware { namespace power { @@ -44,7 +46,20 @@ using PowerHint_1_2 = ::android::hardware::power::V1_2::PowerHint; using PowerHint_1_3 = ::android::hardware::power::V1_3::PowerHint; using ::android::perfmgr::HintManager; -class Power : public IPower { +using ::vendor::lineage::power::V1_0::ILineagePower; +using ::vendor::lineage::power::V1_0::LineageFeature; +using ::vendor::lineage::power::V1_0::LineagePowerHint; + +enum PowerProfile { + POWER_SAVE = 0, + BALANCED, + HIGH_PERFORMANCE, + BIAS_POWER_SAVE, + BIAS_PERFORMANCE, + MAX +}; + +class Power : public IPower, public ILineagePower { public: // Methods from ::android::hardware::power::V1_0::IPower follow. @@ -65,6 +80,9 @@ class Power : public IPower { // Methods from ::android::hardware::power::V1_3::IPower follow. Return powerHintAsync_1_3(PowerHint_1_3 hint, int32_t data) override; + // Methods from ::vendor::lineage::power::V1_0::ILineagePower follow. + Return getFeature(LineageFeature feature) override; + // Methods from ::android::hidl::base::V1_0::IBase follow. Return debug(const hidl_handle &fd, const hidl_vec &args) override; @@ -77,7 +95,11 @@ class Power : public IPower { std::atomic mReady; std::thread mInitThread; + int32_t mNumPerfProfiles; + std::atomic mCurrentPerfProfile; + Return updateHint(const char *hint, bool enable); + Return setProfile(PowerProfile profile); }; } // namespace implementation