diff options
author | Wei Wang <wvw@google.com> | 2020-03-20 12:21:12 -0700 |
---|---|---|
committer | Wei Wang <wvw@google.com> | 2020-03-20 15:02:24 -0700 |
commit | 46780732d4816e1ccf65c1ff6c3ab72fced34382 (patch) | |
tree | f966a9221f25065be3d44f697e3c1e87e3e6fbcf /power-libperfmgr | |
parent | 2a1910fadb367d37f8f386b1056dd4c26a6ab506 (diff) | |
download | pixel-46780732d4816e1ccf65c1ff6c3ab72fced34382.tar.gz |
Power: add aidl extension server
Bug: 151896829
Test: boot flame
Change-Id: Ie951008cabe2a5680fbc546a21bdc9a428864ef9
Diffstat (limited to 'power-libperfmgr')
-rw-r--r-- | power-libperfmgr/Android.bp | 2 | ||||
-rw-r--r-- | power-libperfmgr/aidl/Power.cpp | 86 | ||||
-rw-r--r-- | power-libperfmgr/aidl/Power.h | 9 | ||||
-rw-r--r-- | power-libperfmgr/aidl/PowerExt.cpp | 101 | ||||
-rw-r--r-- | power-libperfmgr/aidl/PowerExt.h | 57 | ||||
-rw-r--r-- | power-libperfmgr/aidl/service.cpp | 40 |
6 files changed, 239 insertions, 56 deletions
diff --git a/power-libperfmgr/Android.bp b/power-libperfmgr/Android.bp index fd5dee0e..f829a729 100644 --- a/power-libperfmgr/Android.bp +++ b/power-libperfmgr/Android.bp @@ -76,9 +76,11 @@ cc_binary { "libbinder_ndk", "libdisppower-pixel", "libperfmgr", + "pixel-power-ext-ndk_platform", ], srcs: [ "aidl/service.cpp", "aidl/Power.cpp", + "aidl/PowerExt.cpp", ], } diff --git a/power-libperfmgr/aidl/Power.cpp b/power-libperfmgr/aidl/Power.cpp index 688a49c9..d409a571 100644 --- a/power-libperfmgr/aidl/Power.cpp +++ b/power-libperfmgr/aidl/Power.cpp @@ -41,63 +41,45 @@ namespace pixel { 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 kPowerHalConfigPath[] = "/vendor/etc/powerhint.json"; -Power::Power() - : mHintManager(nullptr), - mInteractionHandler(nullptr), - mVRModeOn(false), - mSustainedPerfModeOn(false), - mReady(false) { - // Parse config but do not start the looper - mHintManager = HintManager::GetFromJSON(kPowerHalConfigPath, false); - if (!mHintManager) { - LOG(FATAL) << "Invalid config: " << kPowerHalConfigPath; - } - - std::thread initThread([this]() { - ::android::base::WaitForProperty(kPowerHalInitProp, "1"); - mHintManager->Start(); - mInteractionHandler = std::make_unique<InteractionHandler>(mHintManager); - mInteractionHandler->Init(); +void Power::setReady() { + mInteractionHandler = std::make_unique<InteractionHandler>(mHintManager); + mInteractionHandler->Init(); - std::string state = ::android::base::GetProperty(kPowerHalStateProp, ""); - if (state == "SUSTAINED_PERFORMANCE") { - ALOGI("Initialize with SUSTAINED_PERFORMANCE on"); - mHintManager->DoHint("SUSTAINED_PERFORMANCE"); - mSustainedPerfModeOn = true; - } else if (state == "VR") { - ALOGI("Initialize with VR on"); - mHintManager->DoHint(state); - mVRModeOn = true; - } else if (state == "VR_SUSTAINED_PERFORMANCE") { - ALOGI("Initialize with SUSTAINED_PERFORMANCE and VR on"); - mHintManager->DoHint("VR_SUSTAINED_PERFORMANCE"); - mSustainedPerfModeOn = true; - mVRModeOn = true; - } else { - ALOGI("Initialize PowerHAL"); - } + std::string state = ::android::base::GetProperty(kPowerHalStateProp, ""); + if (state == "SUSTAINED_PERFORMANCE") { + ALOGI("Initialize with SUSTAINED_PERFORMANCE on"); + mHintManager->DoHint("SUSTAINED_PERFORMANCE"); + mSustainedPerfModeOn = true; + } else if (state == "VR") { + ALOGI("Initialize with VR on"); + mHintManager->DoHint(state); + mVRModeOn = true; + } else if (state == "VR_SUSTAINED_PERFORMANCE") { + ALOGI("Initialize with SUSTAINED_PERFORMANCE and VR on"); + mHintManager->DoHint("VR_SUSTAINED_PERFORMANCE"); + mSustainedPerfModeOn = true; + mVRModeOn = true; + } else { + ALOGI("Initialize PowerHAL"); + } - state = ::android::base::GetProperty(kPowerHalAudioProp, ""); - if (state == "AUDIO_STREAMING_LOW_LATENCY") { - ALOGI("Initialize with AUDIO_LOW_LATENCY on"); - mHintManager->DoHint(state); - } + state = ::android::base::GetProperty(kPowerHalAudioProp, ""); + if (state == "AUDIO_STREAMING_LOW_LATENCY") { + ALOGI("Initialize with AUDIO_LOW_LATENCY on"); + mHintManager->DoHint(state); + } - state = ::android::base::GetProperty(kPowerHalRenderingProp, ""); - if (state == "EXPENSIVE_RENDERING") { - ALOGI("Initialize with EXPENSIVE_RENDERING on"); - mHintManager->DoHint("EXPENSIVE_RENDERING"); - } + state = ::android::base::GetProperty(kPowerHalRenderingProp, ""); + if (state == "EXPENSIVE_RENDERING") { + ALOGI("Initialize with EXPENSIVE_RENDERING on"); + mHintManager->DoHint("EXPENSIVE_RENDERING"); + } - // Now start to take powerhint - mReady.store(true); - ALOGI("PowerHAL ready to process hints"); - }); - initThread.detach(); + // Now start to take powerhint + mReady.store(true); + ALOGI("PowerHAL ready to process hints"); } ndk::ScopedAStatus Power::setMode(Mode type, bool enabled) { @@ -246,7 +228,7 @@ ndk::ScopedAStatus Power::setBoost(Boost type, int32_t durationMs) { ndk::ScopedAStatus Power::isBoostSupported(Boost type, bool *_aidl_return) { bool supported = mHintManager->IsHintSupported(toString(type)); - LOG(INFO) << "Power mode " << toString(type) << " isBoostSupported: " << supported; + LOG(INFO) << "Power boost " << toString(type) << " isBoostSupported: " << supported; *_aidl_return = supported; return ndk::ScopedAStatus::ok(); } diff --git a/power-libperfmgr/aidl/Power.h b/power-libperfmgr/aidl/Power.h index 460ca94d..cb16b4a2 100644 --- a/power-libperfmgr/aidl/Power.h +++ b/power-libperfmgr/aidl/Power.h @@ -37,12 +37,19 @@ using ::android::perfmgr::HintManager; class Power : public BnPower { public: - Power(); + Power(std::shared_ptr<HintManager> hm) + : mHintManager(hm), + mInteractionHandler(nullptr), + mVRModeOn(false), + mSustainedPerfModeOn(false), + mReady(false) {} + ndk::ScopedAStatus setMode(Mode type, bool enabled) override; ndk::ScopedAStatus isModeSupported(Mode type, bool *_aidl_return) override; ndk::ScopedAStatus setBoost(Boost type, int32_t durationMs) override; ndk::ScopedAStatus isBoostSupported(Boost type, bool *_aidl_return) override; binder_status_t dump(int fd, const char **args, uint32_t numArgs) override; + void setReady(); private: std::shared_ptr<HintManager> mHintManager; diff --git a/power-libperfmgr/aidl/PowerExt.cpp b/power-libperfmgr/aidl/PowerExt.cpp new file mode 100644 index 00000000..1610d774 --- /dev/null +++ b/power-libperfmgr/aidl/PowerExt.cpp @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define ATRACE_TAG (ATRACE_TAG_POWER | ATRACE_TAG_HAL) +#define LOG_TAG "android.hardware.power-service.pixel.ext-libperfmgr" + +#include "PowerExt.h" + +#include <mutex> + +#include <android-base/file.h> +#include <android-base/logging.h> +#include <android-base/properties.h> +#include <android-base/stringprintf.h> +#include <android-base/strings.h> + +#include <utils/Log.h> +#include <utils/Trace.h> + +namespace aidl { +namespace android { +namespace hardware { +namespace pixel { +namespace extension { +namespace power { +namespace impl { + +void PowerExt::setReady() { + // Now start to take powerhint + mReady.store(true); + ALOGI("PowerHAL extension ready to process hints"); +} + +ndk::ScopedAStatus PowerExt::setMode(const std::string &mode, bool enabled) { + if (!mReady) { + return ndk::ScopedAStatus::ok(); + } + LOG(DEBUG) << "PowerExt setMode: " << mode << " to: " << enabled; + ATRACE_INT(mode.c_str(), enabled); + + if (enabled) { + mHintManager->DoHint(mode); + } else { + mHintManager->EndHint(mode); + } + + return ndk::ScopedAStatus::ok(); +} + +ndk::ScopedAStatus PowerExt::isModeSupported(const std::string &mode, bool *_aidl_return) { + bool supported = mHintManager->IsHintSupported(mode); + LOG(INFO) << "PowerExt mode " << mode << " isModeSupported: " << supported; + *_aidl_return = supported; + return ndk::ScopedAStatus::ok(); +} + +ndk::ScopedAStatus PowerExt::setBoost(const std::string &boost, int32_t durationMs) { + if (!mReady) { + return ndk::ScopedAStatus::ok(); + } + LOG(DEBUG) << "PowerExt setBoost: " << boost << " duration: " << durationMs; + ATRACE_INT(boost.c_str(), durationMs); + + if (durationMs > 0) { + mHintManager->DoHint(boost, std::chrono::milliseconds(durationMs)); + } else if (durationMs == 0) { + mHintManager->DoHint(boost); + } else { + mHintManager->EndHint(boost); + } + + return ndk::ScopedAStatus::ok(); +} + +ndk::ScopedAStatus PowerExt::isBoostSupported(const std::string &boost, bool *_aidl_return) { + bool supported = mHintManager->IsHintSupported(boost); + LOG(INFO) << "PowerExt boost " << boost << " isBoostSupported: " << supported; + *_aidl_return = supported; + return ndk::ScopedAStatus::ok(); +} + +} // namespace impl +} // namespace power +} // namespace extension +} // namespace pixel +} // namespace hardware +} // namespace android +} // namespace aidl diff --git a/power-libperfmgr/aidl/PowerExt.h b/power-libperfmgr/aidl/PowerExt.h new file mode 100644 index 00000000..b9fc95d5 --- /dev/null +++ b/power-libperfmgr/aidl/PowerExt.h @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2020 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include <atomic> +#include <memory> +#include <thread> + +#include <aidl/android/hardware/pixel/extension/power/BnPowerExt.h> +#include <perfmgr/HintManager.h> + +namespace aidl { +namespace android { +namespace hardware { +namespace pixel { +namespace extension { +namespace power { +namespace impl { + +using ::android::perfmgr::HintManager; + +class PowerExt : public BnPowerExt { + public: + PowerExt(std::shared_ptr<HintManager> hm) : mHintManager(hm), mReady(false) {} + + ndk::ScopedAStatus setMode(const std::string &mode, bool enabled) override; + ndk::ScopedAStatus isModeSupported(const std::string &mode, bool *_aidl_return) override; + ndk::ScopedAStatus setBoost(const std::string &boost, int32_t durationMs) override; + ndk::ScopedAStatus isBoostSupported(const std::string &boost, bool *_aidl_return) override; + void setReady(); + + private: + std::shared_ptr<HintManager> mHintManager; + std::atomic<bool> mReady; +}; + +} // namespace impl +} // namespace power +} // namespace extension +} // namespace pixel +} // namespace hardware +} // namespace android +} // namespace aidl diff --git a/power-libperfmgr/aidl/service.cpp b/power-libperfmgr/aidl/service.cpp index add78bdf..bfd2c70a 100644 --- a/power-libperfmgr/aidl/service.cpp +++ b/power-libperfmgr/aidl/service.cpp @@ -16,23 +16,57 @@ #define LOG_TAG "android.hardware.power-service.pixel-libperfmgr" -#include "Power.h" +#include <thread> #include <android-base/logging.h> +#include <android-base/properties.h> #include <android/binder_manager.h> #include <android/binder_process.h> +#include "Power.h" +#include "PowerExt.h" + +using aidl::android::hardware::pixel::extension::power::impl::PowerExt; using aidl::android::hardware::power::impl::pixel::Power; +using ::android::perfmgr::HintManager; + +constexpr char kPowerHalConfigPath[] = "/vendor/etc/powerhint.json"; +constexpr char kPowerHalInitProp[] = "vendor.powerhal.init"; int main() { LOG(INFO) << "Power HAL AIDL Service for Pixel is starting."; + + // Parse config but do not start the looper + std::shared_ptr<HintManager> hm = HintManager::GetFromJSON(kPowerHalConfigPath, false); + if (!hm) { + LOG(FATAL) << "Invalid config: " << kPowerHalConfigPath; + } + + // single thread ABinderProcess_setThreadPoolMaxThreadCount(0); - std::shared_ptr<Power> pw = ndk::SharedRefBase::make<Power>(); + + // power hal core service + std::shared_ptr<Power> pw = ndk::SharedRefBase::make<Power>(hm); + ndk::SpAIBinder pwBinder = pw->asBinder(); + + // making the extension service + std::shared_ptr<PowerExt> pwExt = ndk::SharedRefBase::make<PowerExt>(hm); + + // need to attach the extension to the same binder we will be registering + CHECK(STATUS_OK == AIBinder_setExtension(pwBinder.get(), pwExt->asBinder().get())); const std::string instance = std::string() + Power::descriptor + "/default"; binder_status_t status = AServiceManager_addService(pw->asBinder().get(), instance.c_str()); CHECK(status == STATUS_OK); - LOG(INFO) << "Power HAL AIDL Service for Pixel is started."; + LOG(INFO) << "Pixel Power HAL AIDL Service with Extension is started."; + + std::thread initThread([&]() { + ::android::base::WaitForProperty(kPowerHalInitProp, "1"); + hm->Start(); + pw->setReady(); + pwExt->setReady(); + }); + initThread.detach(); ABinderProcess_joinThreadPool(); LOG(ERROR) << "Power HAL AIDL Service for Pixel died."; |