power-libperfmgr: implement Lineage perf profiles
authorJesse Chan <jc@lineageos.org>
Tue, 30 Jun 2020 14:22:42 +0000 (22:22 +0800)
committerAndreas Schneider <asn@cryptomilk.org>
Thu, 2 Jul 2020 07:22:55 +0000 (09:22 +0200)
Change-Id: Ia247ee65a668689168be009a59355d97ce4f2cca

hidl/power-libperfmgr/Android.bp
hidl/power-libperfmgr/Power.cpp
hidl/power-libperfmgr/Power.h

index e3d80467104b8437faa2b57b500bec1d6e7d0fd4..5b010e2cf3b7613a4202c377a7123cf8048f6c38 100644 (file)
@@ -41,6 +41,7 @@ cc_binary {
         "android.hardware.power@1.2",
         "android.hardware.power@1.3",
         "libperfmgr",
+        "vendor.lineage.power@1.0",
     ],
     proprietary: true,
 }
index 942ef94c0a70833f0ffb79f94bb166d3b6c83850..a7d8842c7e0621701c69a72acd311cb2badcb835 100644 (file)
@@ -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";
 }
index 0e511dc69b9168691c7767b294dc141c8271432d..81687b2c9e21816260f461fca160e665f1da94dd 100644 (file)
@@ -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