power-libperfmgr: implement Lineage perf profiles

Change-Id: Ia247ee65a668689168be009a59355d97ce4f2cca
tirimbino
Jesse Chan 4 years ago committed by Andreas Schneider
parent ac485bae7a
commit 0caf630148
  1. 1
      hidl/power-libperfmgr/Android.bp
  2. 89
      hidl/power-libperfmgr/Power.cpp
  3. 24
      hidl/power-libperfmgr/Power.h

@ -41,6 +41,7 @@ cc_binary {
"android.hardware.power@1.2",
"android.hardware.power@1.3",
"libperfmgr",
"vendor.lineage.power@1.0",
],
proprietary: true,
}

@ -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<void> Power::updateHint(const char *hint, bool enable) {
return Void();
}
Return<void> 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<void> Power::setInteractive(bool interactive) {
return updateHint("NOT_INTERACTIVE", !interactive);
@ -297,6 +365,15 @@ Return<void> Power::powerHintAsync_1_3(PowerHint_1_3 hint, int32_t data) {
return Void();
}
switch (static_cast<LineagePowerHint>(hint)) {
case LineagePowerHint::SET_PROFILE:
setProfile(static_cast<PowerProfile>(data));
mCurrentPerfProfile = static_cast<PowerProfile>(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<void> Power::powerHintAsync_1_3(PowerHint_1_3 hint, int32_t data) {
return Void();
}
// Methods from ::vendor::lineage::power::V1_0::ILineagePower follow.
Return<int32_t> 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";
}

@ -28,6 +28,8 @@
#include "InteractionHandler.h"
#include <vendor/lineage/power/1.0/ILineagePower.h>
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<void> powerHintAsync_1_3(PowerHint_1_3 hint, int32_t data) override;
// Methods from ::vendor::lineage::power::V1_0::ILineagePower follow.
Return<int32_t> getFeature(LineageFeature feature) override;
// Methods from ::android::hidl::base::V1_0::IBase follow.
Return<void> debug(const hidl_handle &fd, const hidl_vec<hidl_string> &args) override;
@ -77,7 +95,11 @@ class Power : public IPower {
std::atomic<bool> mReady;
std::thread mInitThread;
int32_t mNumPerfProfiles;
std::atomic<PowerProfile> mCurrentPerfProfile;
Return<void> updateHint(const char *hint, bool enable);
Return<void> setProfile(PowerProfile profile);
};
} // namespace implementation

Loading…
Cancel
Save