From fadfe563a0ce0529c57af684221555378024b255 Mon Sep 17 00:00:00 2001 From: Tim Zimmermann Date: Fri, 10 May 2024 21:22:45 +0200 Subject: [PATCH] aidl: Drop power-libperfmgr * Nobody ever bothered to update it past R * It has no meaningful changes that are needed anymore, everyone can just use pixel power HAL directly now Change-Id: I6fa490759ffe09c1401165a84b4a6df724cd501c --- aidl/power-libperfmgr/Android.bp | 38 -- aidl/power-libperfmgr/InteractionHandler.cpp | 285 ----------- aidl/power-libperfmgr/InteractionHandler.h | 76 --- aidl/power-libperfmgr/Power.cpp | 262 ----------- aidl/power-libperfmgr/Power.h | 60 --- aidl/power-libperfmgr/PowerExt.cpp | 87 ---- aidl/power-libperfmgr/PowerExt.h | 53 --- ...rdware.power-service.samsung-libperfmgr.rc | 28 -- ...android.hardware.power-service.samsung.xml | 6 - aidl/power-libperfmgr/powerhint.json.template | 441 ------------------ aidl/power-libperfmgr/service.cpp | 79 ---- 11 files changed, 1415 deletions(-) delete mode 100644 aidl/power-libperfmgr/Android.bp delete mode 100644 aidl/power-libperfmgr/InteractionHandler.cpp delete mode 100644 aidl/power-libperfmgr/InteractionHandler.h delete mode 100644 aidl/power-libperfmgr/Power.cpp delete mode 100644 aidl/power-libperfmgr/Power.h delete mode 100644 aidl/power-libperfmgr/PowerExt.cpp delete mode 100644 aidl/power-libperfmgr/PowerExt.h delete mode 100644 aidl/power-libperfmgr/android.hardware.power-service.samsung-libperfmgr.rc delete mode 100644 aidl/power-libperfmgr/android.hardware.power-service.samsung.xml delete mode 100644 aidl/power-libperfmgr/powerhint.json.template delete mode 100644 aidl/power-libperfmgr/service.cpp diff --git a/aidl/power-libperfmgr/Android.bp b/aidl/power-libperfmgr/Android.bp deleted file mode 100644 index 258a2d1..0000000 --- a/aidl/power-libperfmgr/Android.bp +++ /dev/null @@ -1,38 +0,0 @@ -// -// Copyright (C) 2018 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. - -cc_binary { - name: "android.hardware.power-service.samsung-libperfmgr", - relative_install_path: "hw", - init_rc: ["android.hardware.power-service.samsung-libperfmgr.rc"], - vintf_fragments: ["android.hardware.power-service.samsung.xml"], - vendor: true, - shared_libs: [ - "android.hardware.power-V1-ndk", - "libbase", - "libcutils", - "liblog", - "libutils", - "libbinder_ndk", - "libperfmgr", - "pixel-power-ext-V1-ndk", - ], - srcs: [ - "service.cpp", - "Power.cpp", - "PowerExt.cpp", - "InteractionHandler.cpp", - ], -} diff --git a/aidl/power-libperfmgr/InteractionHandler.cpp b/aidl/power-libperfmgr/InteractionHandler.cpp deleted file mode 100644 index 256c602..0000000 --- a/aidl/power-libperfmgr/InteractionHandler.cpp +++ /dev/null @@ -1,285 +0,0 @@ -/* - * Copyright (C) 2018 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 LOG_TAG "android.hardware.power@-service.samsung-libperfmgr" -#define ATRACE_TAG (ATRACE_TAG_POWER | ATRACE_TAG_HAL) - -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "InteractionHandler.h" - -#define MAX_LENGTH 64 - -#define MSINSEC 1000L -#define NSINMS 1000000L - -namespace aidl { -namespace google { -namespace hardware { -namespace power { -namespace impl { -namespace pixel { - -namespace { - -static const bool kDisplayIdleSupport = - ::android::base::GetBoolProperty("vendor.powerhal.disp.idle_support", true); -static const std::array kDispIdlePath = {"/sys/class/drm/card0/device/idle_state", - "/sys/class/graphics/fb0/idle_state"}; -static const uint32_t kWaitMs = - ::android::base::GetUintProperty("vendor.powerhal.disp.idle_wait", /*default*/ 100U); -static const uint32_t kMinDurationMs = - ::android::base::GetUintProperty("vendor.powerhal.interaction.min", /*default*/ 1400U); -static const uint32_t kMaxDurationMs = - ::android::base::GetUintProperty("vendor.powerhal.interaction.max", /*default*/ 5650U); -static const uint32_t kDurationOffsetMs = - ::android::base::GetUintProperty("vendor.powerhal.interaction.offset", /*default*/ 650U); - -static size_t CalcTimespecDiffMs(struct timespec start, struct timespec end) { - size_t diff_in_ms = 0; - diff_in_ms += (end.tv_sec - start.tv_sec) * MSINSEC; - diff_in_ms += (end.tv_nsec - start.tv_nsec) / NSINMS; - return diff_in_ms; -} - -static int FbIdleOpen(void) { - int fd; - for (const auto &path : kDispIdlePath) { - fd = open(path, O_RDONLY); - if (fd >= 0) - return fd; - } - ALOGE("Unable to open fb idle state path (%d)", errno); - return -1; -} - -} // namespace - -InteractionHandler::InteractionHandler(std::shared_ptr const &hint_manager) - : mState(INTERACTION_STATE_UNINITIALIZED), - mDurationMs(0), - mHintManager(hint_manager) {} - -InteractionHandler::~InteractionHandler() { - Exit(); -} - -bool InteractionHandler::Init() { - std::lock_guard lk(mLock); - - if (mState != INTERACTION_STATE_UNINITIALIZED) - return true; - - int fd = FbIdleOpen(); - if (fd < 0) - return false; - mIdleFd = fd; - - mEventFd = eventfd(0, EFD_NONBLOCK); - if (mEventFd < 0) { - ALOGE("Unable to create event fd (%d)", errno); - close(mIdleFd); - return false; - } - - mState = INTERACTION_STATE_IDLE; - mThread = std::unique_ptr(new std::thread(&InteractionHandler::Routine, this)); - - return true; -} - -void InteractionHandler::Exit() { - std::unique_lock lk(mLock); - if (mState == INTERACTION_STATE_UNINITIALIZED) - return; - - AbortWaitLocked(); - mState = INTERACTION_STATE_UNINITIALIZED; - lk.unlock(); - - mCond.notify_all(); - mThread->join(); - - close(mEventFd); - close(mIdleFd); -} - -void InteractionHandler::PerfLock() { - ALOGV("%s: acquiring perf lock", __func__); - if (!mHintManager->DoHint("INTERACTION")) { - ALOGE("%s: do hint INTERACTION failed", __func__); - } - ATRACE_INT("interaction_lock", 1); -} - -void InteractionHandler::PerfRel() { - ALOGV("%s: releasing perf lock", __func__); - if (!mHintManager->EndHint("INTERACTION")) { - ALOGE("%s: end hint INTERACTION failed", __func__); - } - ATRACE_INT("interaction_lock", 0); -} - -void InteractionHandler::Acquire(int32_t duration) { - ATRACE_CALL(); - - std::lock_guard lk(mLock); - - int inputDuration = duration + kDurationOffsetMs; - int finalDuration; - if (inputDuration > kMaxDurationMs) - finalDuration = kMaxDurationMs; - else if (inputDuration > kMinDurationMs) - finalDuration = inputDuration; - else - finalDuration = kMinDurationMs; - - // Fallback to do boost directly - // 1) override property is set OR - // 2) InteractionHandler not initialized - if (!kDisplayIdleSupport || mState == INTERACTION_STATE_UNINITIALIZED) { - mHintManager->DoHint("INTERACTION", std::chrono::milliseconds(finalDuration)); - return; - } - - struct timespec cur_timespec; - clock_gettime(CLOCK_MONOTONIC, &cur_timespec); - if (mState != INTERACTION_STATE_IDLE && finalDuration <= mDurationMs) { - size_t elapsed_time = CalcTimespecDiffMs(mLastTimespec, cur_timespec); - // don't hint if previous hint's duration covers this hint's duration - if (elapsed_time <= (mDurationMs - finalDuration)) { - ALOGV("%s: Previous duration (%d) cover this (%d) elapsed: %lld", __func__, - static_cast(mDurationMs), static_cast(finalDuration), - static_cast(elapsed_time)); - return; - } - } - mLastTimespec = cur_timespec; - mDurationMs = finalDuration; - - ALOGV("%s: input: %d final duration: %d", __func__, duration, finalDuration); - - if (mState == INTERACTION_STATE_WAITING) - AbortWaitLocked(); - else if (mState == INTERACTION_STATE_IDLE) - PerfLock(); - - mState = INTERACTION_STATE_INTERACTION; - mCond.notify_one(); -} - -void InteractionHandler::Release() { - std::lock_guard lk(mLock); - if (mState == INTERACTION_STATE_WAITING) { - ATRACE_CALL(); - PerfRel(); - mState = INTERACTION_STATE_IDLE; - } else { - // clear any wait aborts pending in event fd - uint64_t val; - ssize_t ret = read(mEventFd, &val, sizeof(val)); - - ALOGW_IF(ret < 0, "%s: failed to clear eventfd (%zd, %d)", __func__, ret, errno); - } -} - -// should be called while locked -void InteractionHandler::AbortWaitLocked() { - uint64_t val = 1; - ssize_t ret = write(mEventFd, &val, sizeof(val)); - if (ret != sizeof(val)) - ALOGW("Unable to write to event fd (%zd)", ret); -} - -void InteractionHandler::WaitForIdle(int32_t wait_ms, int32_t timeout_ms) { - char data[MAX_LENGTH]; - ssize_t ret; - struct pollfd pfd[2]; - - ATRACE_CALL(); - - ALOGV("%s: wait:%d timeout:%d", __func__, wait_ms, timeout_ms); - - pfd[0].fd = mEventFd; - pfd[0].events = POLLIN; - pfd[1].fd = mIdleFd; - pfd[1].events = POLLPRI | POLLERR; - - ret = poll(pfd, 1, wait_ms); - if (ret > 0) { - ALOGV("%s: wait aborted", __func__); - return; - } else if (ret < 0) { - ALOGE("%s: error in poll while waiting", __func__); - return; - } - - ret = pread(mIdleFd, data, sizeof(data), 0); - if (!ret) { - ALOGE("%s: Unexpected EOF!", __func__); - return; - } - - if (!strncmp(data, "idle", 4)) { - ALOGV("%s: already idle", __func__); - return; - } - - ret = poll(pfd, 2, timeout_ms); - if (ret < 0) - ALOGE("%s: Error on waiting for idle (%zd)", __func__, ret); - else if (ret == 0) - ALOGV("%s: timed out waiting for idle", __func__); - else if (pfd[0].revents) - ALOGV("%s: wait for idle aborted", __func__); - else if (pfd[1].revents) - ALOGV("%s: idle detected", __func__); -} - -void InteractionHandler::Routine() { - pthread_setname_np(pthread_self(), "DispIdle"); - std::unique_lock lk(mLock, std::defer_lock); - - while (true) { - lk.lock(); - mCond.wait(lk, [&] { return mState != INTERACTION_STATE_IDLE; }); - if (mState == INTERACTION_STATE_UNINITIALIZED) - return; - mState = INTERACTION_STATE_WAITING; - lk.unlock(); - - WaitForIdle(kWaitMs, mDurationMs); - Release(); - } -} - -} // namespace pixel -} // namespace impl -} // namespace power -} // namespace hardware -} // namespace google -} // namespace aidl diff --git a/aidl/power-libperfmgr/InteractionHandler.h b/aidl/power-libperfmgr/InteractionHandler.h deleted file mode 100644 index 77ade88..0000000 --- a/aidl/power-libperfmgr/InteractionHandler.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) 2018 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 -#include -#include -#include -#include - -#include - -namespace aidl { -namespace google { -namespace hardware { -namespace power { -namespace impl { -namespace pixel { - -using ::android::perfmgr::HintManager; - -enum InteractionState { - INTERACTION_STATE_UNINITIALIZED, - INTERACTION_STATE_IDLE, - INTERACTION_STATE_INTERACTION, - INTERACTION_STATE_WAITING, -}; - -class InteractionHandler { - public: - InteractionHandler(std::shared_ptr const &hint_manager); - ~InteractionHandler(); - bool Init(); - void Exit(); - void Acquire(int32_t duration); - - private: - void Release(); - void WaitForIdle(int32_t wait_ms, int32_t timeout_ms); - void AbortWaitLocked(); - void Routine(); - - void PerfLock(); - void PerfRel(); - - enum InteractionState mState; - int mIdleFd; - int mEventFd; - int32_t mDurationMs; - struct timespec mLastTimespec; - std::unique_ptr mThread; - std::mutex mLock; - std::condition_variable mCond; - std::shared_ptr mHintManager; -}; - -} // namespace pixel -} // namespace impl -} // namespace power -} // namespace hardware -} // namespace google -} // namespace aidl diff --git a/aidl/power-libperfmgr/Power.cpp b/aidl/power-libperfmgr/Power.cpp deleted file mode 100644 index b7a51d9..0000000 --- a/aidl/power-libperfmgr/Power.cpp +++ /dev/null @@ -1,262 +0,0 @@ -/* - * 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.samsung-libperfmgr" - -#include "Power.h" - -#include - -#include -#include -#include -#include -#include - -#include -#include - -namespace aidl { -namespace google { -namespace hardware { -namespace power { -namespace impl { -namespace pixel { - -constexpr char kPowerHalStateProp[] = "vendor.powerhal.state"; -constexpr char kPowerHalAudioProp[] = "vendor.powerhal.audio"; -constexpr char kPowerHalRenderingProp[] = "vendor.powerhal.rendering"; - -Power::Power(std::shared_ptr hm) - : mHintManager(hm), - mInteractionHandler(nullptr), - mVRModeOn(false), - mSustainedPerfModeOn(false) { - mInteractionHandler = std::make_unique(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"); - } - - 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"); - } - - // Now start to take powerhint - ALOGI("PowerHAL ready to process hints"); -} - -ndk::ScopedAStatus Power::setMode(Mode type, bool enabled) { - LOG(DEBUG) << "Power setMode: " << toString(type) << " to: " << enabled; - ATRACE_INT(toString(type).c_str(), enabled); - switch (type) { - case Mode::LOW_POWER: - if (enabled) { - mHintManager->DoHint(toString(type)); - } else { - mHintManager->EndHint(toString(type)); - } - break; - case Mode::SUSTAINED_PERFORMANCE: - if (enabled && !mSustainedPerfModeOn) { - if (!mVRModeOn) { // Sustained mode only. - mHintManager->DoHint("SUSTAINED_PERFORMANCE"); - } else { // Sustained + VR mode. - mHintManager->EndHint("VR"); - mHintManager->DoHint("VR_SUSTAINED_PERFORMANCE"); - } - mSustainedPerfModeOn = true; - } else if (!enabled && mSustainedPerfModeOn) { - mHintManager->EndHint("VR_SUSTAINED_PERFORMANCE"); - mHintManager->EndHint("SUSTAINED_PERFORMANCE"); - if (mVRModeOn) { // Switch back to VR Mode. - mHintManager->DoHint("VR"); - } - mSustainedPerfModeOn = false; - } - break; - case Mode::VR: - if (enabled && !mVRModeOn) { - if (!mSustainedPerfModeOn) { // VR mode only. - mHintManager->DoHint("VR"); - } else { // Sustained + VR mode. - mHintManager->EndHint("SUSTAINED_PERFORMANCE"); - mHintManager->DoHint("VR_SUSTAINED_PERFORMANCE"); - } - mVRModeOn = true; - } else if (!enabled && mVRModeOn) { - mHintManager->EndHint("VR_SUSTAINED_PERFORMANCE"); - mHintManager->EndHint("VR"); - if (mSustainedPerfModeOn) { // Switch back to sustained Mode. - mHintManager->DoHint("SUSTAINED_PERFORMANCE"); - } - mVRModeOn = false; - } - break; - case Mode::LAUNCH: - if (mVRModeOn || mSustainedPerfModeOn) { - break; - } - [[fallthrough]]; - case Mode::DOUBLE_TAP_TO_WAKE: - [[fallthrough]]; - case Mode::FIXED_PERFORMANCE: - [[fallthrough]]; - case Mode::EXPENSIVE_RENDERING: - [[fallthrough]]; - case Mode::INTERACTIVE: - [[fallthrough]]; - case Mode::DEVICE_IDLE: - [[fallthrough]]; - case Mode::DISPLAY_INACTIVE: - [[fallthrough]]; - case Mode::AUDIO_STREAMING_LOW_LATENCY: - [[fallthrough]]; - case Mode::CAMERA_STREAMING_SECURE: - [[fallthrough]]; - case Mode::CAMERA_STREAMING_LOW: - [[fallthrough]]; - case Mode::CAMERA_STREAMING_MID: - [[fallthrough]]; - case Mode::CAMERA_STREAMING_HIGH: - [[fallthrough]]; - default: - if (enabled) { - mHintManager->DoHint(toString(type)); - } else { - mHintManager->EndHint(toString(type)); - } - break; - } - - return ndk::ScopedAStatus::ok(); -} - -ndk::ScopedAStatus Power::isModeSupported(Mode type, bool *_aidl_return) { - bool supported = mHintManager->IsHintSupported(toString(type)); - switch (type) { - case Mode::LOW_POWER: // LOW_POWER handled insides PowerHAL specifically - supported = true; - break; - case Mode::DOUBLE_TAP_TO_WAKE: - supported = true; - break; - case Mode::INTERACTIVE: - supported = true; - break; - default: - break; - } - - LOG(INFO) << "Power mode " << toString(type) << " isModeSupported: " << supported; - *_aidl_return = supported; - return ndk::ScopedAStatus::ok(); -} - -ndk::ScopedAStatus Power::setBoost(Boost type, int32_t durationMs) { - LOG(DEBUG) << "Power setBoost: " << toString(type) << " duration: " << durationMs; - ATRACE_INT(toString(type).c_str(), durationMs); - switch (type) { - case Boost::INTERACTION: - if (mVRModeOn || mSustainedPerfModeOn) { - break; - } - mInteractionHandler->Acquire(durationMs); - break; - case Boost::DISPLAY_UPDATE_IMMINENT: - [[fallthrough]]; - case Boost::ML_ACC: - [[fallthrough]]; - case Boost::AUDIO_LAUNCH: - [[fallthrough]]; - case Boost::CAMERA_LAUNCH: - [[fallthrough]]; - case Boost::CAMERA_SHOT: - [[fallthrough]]; - default: - if (mVRModeOn || mSustainedPerfModeOn) { - break; - } - if (durationMs > 0) { - mHintManager->DoHint(toString(type), std::chrono::milliseconds(durationMs)); - } else if (durationMs == 0) { - mHintManager->DoHint(toString(type)); - } else { - mHintManager->EndHint(toString(type)); - } - break; - } - - return ndk::ScopedAStatus::ok(); -} - -ndk::ScopedAStatus Power::isBoostSupported(Boost type, bool *_aidl_return) { - bool supported = mHintManager->IsHintSupported(toString(type)); - LOG(INFO) << "Power boost " << toString(type) << " isBoostSupported: " << supported; - *_aidl_return = supported; - return ndk::ScopedAStatus::ok(); -} - -constexpr const char *boolToString(bool b) { - return b ? "true" : "false"; -} - -binder_status_t Power::dump(int fd, const char **, uint32_t) { - std::string buf(::android::base::StringPrintf( - "HintManager Running: %s\n" - "VRMode: %s\n" - "SustainedPerformanceMode: %s\n", - boolToString(mHintManager->IsRunning()), boolToString(mVRModeOn), - boolToString(mSustainedPerfModeOn))); - // Dump nodes through libperfmgr - mHintManager->DumpToFd(fd); - if (!::android::base::WriteStringToFd(buf, fd)) { - PLOG(ERROR) << "Failed to dump state to fd"; - } - fsync(fd); - return STATUS_OK; -} - -} // namespace pixel -} // namespace impl -} // namespace power -} // namespace hardware -} // namespace google -} // namespace aidl diff --git a/aidl/power-libperfmgr/Power.h b/aidl/power-libperfmgr/Power.h deleted file mode 100644 index 932c76a..0000000 --- a/aidl/power-libperfmgr/Power.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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 -#include -#include - -#include -#include - -#include "InteractionHandler.h" - -namespace aidl { -namespace google { -namespace hardware { -namespace power { -namespace impl { -namespace pixel { - -using ::aidl::android::hardware::power::Boost; -using ::aidl::android::hardware::power::Mode; -using ::android::perfmgr::HintManager; - -class Power : public ::aidl::android::hardware::power::BnPower { - public: - Power(std::shared_ptr hm); - 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; - - private: - std::shared_ptr mHintManager; - std::unique_ptr mInteractionHandler; - std::atomic mVRModeOn; - std::atomic mSustainedPerfModeOn; -}; - -} // namespace pixel -} // namespace impl -} // namespace power -} // namespace hardware -} // namespace google -} // namespace aidl diff --git a/aidl/power-libperfmgr/PowerExt.cpp b/aidl/power-libperfmgr/PowerExt.cpp deleted file mode 100644 index 6f854b0..0000000 --- a/aidl/power-libperfmgr/PowerExt.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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.samsung.ext-libperfmgr" - -#include "PowerExt.h" - -#include - -#include -#include -#include -#include -#include - -#include -#include - -namespace aidl { -namespace google { -namespace hardware { -namespace power { -namespace impl { -namespace pixel { - -ndk::ScopedAStatus PowerExt::setMode(const std::string &mode, bool enabled) { - 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) { - 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 pixel -} // namespace impl -} // namespace power -} // namespace hardware -} // namespace google -} // namespace aidl diff --git a/aidl/power-libperfmgr/PowerExt.h b/aidl/power-libperfmgr/PowerExt.h deleted file mode 100644 index c24d650..0000000 --- a/aidl/power-libperfmgr/PowerExt.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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 -#include -#include - -#include -#include - -namespace aidl { -namespace google { -namespace hardware { -namespace power { -namespace impl { -namespace pixel { - -using ::android::perfmgr::HintManager; - -class PowerExt : public ::aidl::google::hardware::power::extension::pixel::BnPowerExt { - public: - PowerExt(std::shared_ptr hm) - : mHintManager(hm) {} - 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; - - private: - std::shared_ptr mHintManager; -}; - -} // namespace pixel -} // namespace impl -} // namespace power -} // namespace hardware -} // namespace google -} // namespace aidl diff --git a/aidl/power-libperfmgr/android.hardware.power-service.samsung-libperfmgr.rc b/aidl/power-libperfmgr/android.hardware.power-service.samsung-libperfmgr.rc deleted file mode 100644 index 93497c9..0000000 --- a/aidl/power-libperfmgr/android.hardware.power-service.samsung-libperfmgr.rc +++ /dev/null @@ -1,28 +0,0 @@ -service vendor.power-hal-aidl /vendor/bin/hw/android.hardware.power-service.samsung-libperfmgr - class hal - user root - group system radio - priority -20 - -on late-fs - start vendor.power-hal-aidl - -# restart powerHAL when framework died -on property:init.svc.zygote=restarting && property:vendor.powerhal.state=* - setprop vendor.powerhal.state "" - setprop vendor.powerhal.audio "" - setprop vendor.powerhal.rendering "" - restart vendor.power-hal-aidl - -# Clean up after b/163539793 resolved -on property:vendor.powerhal.dalvik.vm.dex2oat-threads=* - setprop dalvik.vm.dex2oat-threads ${vendor.powerhal.dalvik.vm.dex2oat-threads} - setprop dalvik.vm.restore-dex2oat-threads ${vendor.powerhal.dalvik.vm.dex2oat-threads} - -on property:vendor.powerhal.dalvik.vm.dex2oat-cpu-set=* - setprop dalvik.vm.dex2oat-cpu-set ${vendor.powerhal.dalvik.vm.dex2oat-cpu-set} - setprop dalvik.vm.restore-dex2oat-cpu-set ${vendor.powerhal.dalvik.vm.dex2oat-cpu-set} - -# initialize powerHAL when boot is completed -on property:sys.boot_completed=1 - setprop vendor.powerhal.init 1 diff --git a/aidl/power-libperfmgr/android.hardware.power-service.samsung.xml b/aidl/power-libperfmgr/android.hardware.power-service.samsung.xml deleted file mode 100644 index 1efa5f1..0000000 --- a/aidl/power-libperfmgr/android.hardware.power-service.samsung.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - android.hardware.power - IPower/default - - diff --git a/aidl/power-libperfmgr/powerhint.json.template b/aidl/power-libperfmgr/powerhint.json.template deleted file mode 100644 index 1ffafd6..0000000 --- a/aidl/power-libperfmgr/powerhint.json.template +++ /dev/null @@ -1,441 +0,0 @@ -{ - "Nodes": [ - { - "Name": "CPULittleClusterMaxFreq", - "Path": "/sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq", - "Values": [ - "9999999", - "1113600" - ], - "DefaultIndex": 0, - "ResetOnInit": true - }, - { - "Name": "CPULittleClusterMinFreq", - "Path": "/sys/devices/system/cpu/cpu0/cpufreq/scaling_min_freq", - "Values": [ - "9999999", - "1113600", - "576000" - ], - "ResetOnInit": true - }, - { - "Name": "CPUBigClusterMaxFreq", - "Path": "/sys/devices/system/cpu/cpu4/cpufreq/scaling_max_freq", - "Values": [ - "9999999", - "2016000", - "1497600", - "1401600" - ], - "DefaultIndex": 0, - "ResetOnInit": true - }, - { - "Name": "CPUBigClusterMinFreq", - "Path": "/sys/devices/system/cpu/cpu4/cpufreq/scaling_min_freq", - "Values": [ - "9999999", - "1497600", - "1401600", - "1286400", - "0" - ], - "ResetOnInit": true - }, - { - "Name": "CPUBigPlusClusterMaxFreq", - "Path": "/sys/devices/system/cpu/cpu7/cpufreq/scaling_max_freq", - "Values": [ - "9999999", - "2016000", - "1497600", - "1401600" - ], - "DefaultIndex": 0, - "ResetOnInit": true - }, - { - "Name": "CPUBigPlusClusterMinFreq", - "Path": "/sys/devices/system/cpu/cpu7/cpufreq/scaling_min_freq", - "Values": [ - "9999999", - "1497600", - "1401600", - "1286400", - "0" - ], - "ResetOnInit": true - }, - { - "Name": "GPUMaxFreq", - "Path": "/sys/class/kgsl/kgsl-3d0/devfreq/max_freq", - "Values": [ - "585000000", - "427000000" - ], - "DefaultIndex": 0, - "ResetOnInit": true - }, - { - "Name": "GPUMinFreq", - "Path": "/sys/class/kgsl/kgsl-3d0/devfreq/min_freq", - "Values": [ - "585000000", - "427000000", - "345000000", - "257000000" - ], - "ResetOnInit": true - }, - { - "Name": "TASchedtuneBoost", - "Path": "/dev/stune/top-app/schedtune.boost", - "Values": [ - "30", - "10" - ], - "ResetOnInit": true - }, - { - "Name": "PMQoSCpuDmaLatency", - "Path": "/dev/cpu_dma_latency", - "Values": [ - "44", - "100" - ], - "HoldFd": true - }, - { - "Name": "TouchscreenEnable", - "Path": "/sys/class/input/input3/enabled", - "Values": [ - "1", - "0" - ], - "ResetOnInit": true - }, - { - "Name": "DoubleTapToWakeEnable", - "Path": "/sys/class/sec/tsp/cmd", - "Values": [ - "aot_enable,0", - "aot_enable,1" - ], - "DefaultIndex": 0 - }, - { - "Name": "PowerHALMainState", - "Path": "vendor.powerhal.state", - "Values": [ - "SUSTAINED_PERFORMANCE", - "VR_MODE", - "VR_SUSTAINED_PERFORMANCE", - "" - ], - "Type": "Property" - }, - { - "Name": "PowerHALAudioState", - "Path": "vendor.powerhal.audio", - "Values": [ - "AUDIO_STREAMING_LOW_LATENCY", - "" - ], - "Type": "Property" - }, - { - "Name": "PowerHALRenderingState", - "Path": "vendor.powerhal.rendering", - "Values": [ - "EXPENSIVE_RENDERING", - "" - ], - "Type": "Property" - }, - { - "Name": "PowerHALPerfProfileState", - "Path": "vendor.powerhal.perf_profile", - "Values": [ - "POWER_SAVE", - "BIAS_POWER_SAVE", - "BIAS_PERFORMANCE", - "HIGH_PERFORMANCE" - ], - "Type": "Property" - } - ], - "Actions": [ - { - "PowerHint": "INTERACTION", - "Node": "CPUBigClusterMinFreq", - "Duration": 0, - "Value": "1286400" - }, - { - "PowerHint": "INTERACTION", - "Node": "CPUBigPlusClusterMinFreq", - "Duration": 0, - "Value": "1286400" - }, - { - "PowerHint": "INTERACTION", - "Node": "CPULittleClusterMinFreq", - "Duration": 0, - "Value": "1113600" - }, - { - "PowerHint": "INTERACTION", - "Node": "TASchedtuneBoost", - "Duration": 0, - "Value": "30" - }, - { - "PowerHint": "LAUNCH", - "Node": "CPUBigClusterMaxFreq", - "Duration": 5000, - "Value": "9999999" - }, - { - "PowerHint": "LAUNCH", - "Node": "CPUBigPlusClusterMaxFreq", - "Duration": 5000, - "Value": "9999999" - }, - { - "PowerHint": "LAUNCH", - "Node": "CPUBigClusterMinFreq", - "Duration": 5000, - "Value": "9999999" - }, - { - "PowerHint": "LAUNCH", - "Node": "CPUBigPlusClusterMinFreq", - "Duration": 5000, - "Value": "9999999" - }, - { - "PowerHint": "LAUNCH", - "Node": "CPULittleClusterMinFreq", - "Duration": 5000, - "Value": "9999999" - }, - { - "PowerHint": "LAUNCH", - "Node": "PMQoSCpuDmaLatency", - "Duration": 5000, - "Value": "44" - }, - { - "PowerHint": "CAMERA_LAUNCH", - "Node": "CPUBigClusterMaxFreq", - "Duration": 1000, - "Value": "9999999" - }, - { - "PowerHint": "CAMERA_LAUNCH", - "Node": "CPUBigPlusClusterMaxFreq", - "Duration": 1000, - "Value": "9999999" - }, - { - "PowerHint": "CAMERA_LAUNCH", - "Node": "CPUBigClusterMinFreq", - "Duration": 1000, - "Value": "9999999" - }, - { - "PowerHint": "CAMERA_LAUNCH", - "Node": "CPUBigPlusClusterMinFreq", - "Duration": 1000, - "Value": "9999999" - }, - { - "PowerHint": "CAMERA_LAUNCH", - "Node": "CPULittleClusterMaxFreq", - "Duration": 1000, - "Value": "9999999" - }, - { - "PowerHint": "CAMERA_LAUNCH", - "Node": "CPULittleClusterMinFreq", - "Duration": 1000, - "Value": "9999999" - }, - { - "PowerHint": "CAMERA_LAUNCH", - "Node": "PMQoSCpuDmaLatency", - "Duration": 1000, - "Value": "44" - }, - { - "PowerHint": "CAMERA_STREAMING_MID", - "Node": "CPUBigClusterMaxFreq", - "Duration": 0, - "Value": "2016000" - }, - { - "PowerHint": "CAMERA_STREAMING_MID", - "Node": "CPUBigPlusClusterMaxFreq", - "Duration": 0, - "Value": "2016000" - }, - { - "PowerHint": "CAMERA_SHOT", - "Node": "CPUBigClusterMaxFreq", - "Duration": 1000, - "Value": "9999999" - }, - { - "PowerHint": "CAMERA_SHOT", - "Node": "CPUBigPlusClusterMaxFreq", - "Duration": 1000, - "Value": "9999999" - }, - { - "PowerHint": "CAMERA_SHOT", - "Node": "CPUBigClusterMinFreq", - "Duration": 1000, - "Value": "9999999" - }, - { - "PowerHint": "CAMERA_SHOT", - "Node": "CPUBigPlusClusterMinFreq", - "Duration": 1000, - "Value": "9999999" - }, - { - "PowerHint": "CAMERA_SHOT", - "Node": "CPULittleClusterMaxFreq", - "Duration": 1000, - "Value": "9999999" - }, - { - "PowerHint": "CAMERA_SHOT", - "Node": "CPULittleClusterMinFreq", - "Duration": 1000, - "Value": "9999999" - }, - { - "PowerHint": "CAMERA_SHOT", - "Node": "PMQoSCpuDmaLatency", - "Duration": 1000, - "Value": "44" - }, - { - "PowerHint": "AUDIO_LAUNCH", - "Node": "PMQoSCpuDmaLatency", - "Duration": 2000, - "Value": "44" - }, - { - "PowerHint": "AUDIO_STREAMING_LOW_LATENCY", - "Node": "PowerHALAudioState", - "Duration": 0, - "Value": "AUDIO_STREAMING_LOW_LATENCY" - }, - { - "PowerHint": "AUDIO_STREAMING_LOW_LATENCY", - "Node": "PMQoSCpuDmaLatency", - "Duration": 0, - "Value": "44" - }, - { - "PowerHint": "SUSTAINED_PERFORMANCE", - "Node": "PowerHALMainState", - "Duration": 0, - "Value": "SUSTAINED_PERFORMANCE" - }, - { - "PowerHint": "SUSTAINED_PERFORMANCE", - "Node": "CPUBigClusterMaxFreq", - "Duration": 0, - "Value": "1401600" - }, - { - "PowerHint": "SUSTAINED_PERFORMANCE", - "Node": "CPUBigPlusClusterMaxFreq", - "Duration": 0, - "Value": "1401600" - }, - { - "PowerHint": "SUSTAINED_PERFORMANCE", - "Node": "CPULittleClusterMaxFreq", - "Duration": 0, - "Value": "1113600" - }, - { - "PowerHint": "SUSTAINED_PERFORMANCE", - "Node": "GPUMaxFreq", - "Duration": 0, - "Value": "427000000" - }, - { - "PowerHint": "VR_MODE", - "Node": "PowerHALMainState", - "Duration": 0, - "Value": "VR_MODE" - }, - { - "PowerHint": "VR_SUSTAINED_PERFORMANCE", - "Node": "PowerHALMainState", - "Duration": 0, - "Value": "VR_SUSTAINED_PERFORMANCE" - }, - { - "PowerHint": "EXPENSIVE_RENDERING", - "Node": "PowerHALRenderingState", - "Duration": 0, - "Value": "EXPENSIVE_RENDERING" - }, - { - "PowerHint": "EXPENSIVE_RENDERING", - "Node": "GPUMinFreq", - "Duration": 0, - "Value": "427000000" - }, - { - "PowerHint": "EXPENSIVE_RENDERING", - "Node": "GPUMaxFreq", - "Duration": 0, - "Value": "585000000" - }, - { - "PowerHint": "INTERACTIVE", - "Node": "TouchscreenEnable", - "Duration": 0, - "Value": "1" - }, - { - "PowerHint": "DOUBLE_TAP_TO_WAKE", - "Node": "DoubleTapToWakeEnable", - "Duration": 0, - "Value": "aot_enable,1" - }, - { - "PowerHint": "PROFILE_POWER_SAVE", - "Node": "PowerHALPerfProfileState", - "Duration": 0, - "Value": "POWER_SAVE" - }, - { - "PowerHint": "PROFILE_BIAS_POWER_SAVE", - "Node": "PowerHALPerfProfileState", - "Duration": 0, - "Value": "BIAS_POWER_SAVE" - }, - { - "PowerHint": "PROFILE_BIAS_PERFORMANCE", - "Node": "PowerHALPerfProfileState", - "Duration": 0, - "Value": "BIAS_PERFORMANCE" - }, - { - "PowerHint": "PROFILE_HIGH_PERFORMANCE", - "Node": "PowerHALPerfProfileState", - "Duration": 0, - "Value": "HIGH_PERFORMANCE" - } - ] -} diff --git a/aidl/power-libperfmgr/service.cpp b/aidl/power-libperfmgr/service.cpp deleted file mode 100644 index 54e9388..0000000 --- a/aidl/power-libperfmgr/service.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* - * 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 LOG_TAG "android.hardware.power-service.samsung-libperfmgr" - -#include - -#include -#include -#include -#include - -#include "Power.h" -#include "PowerExt.h" - -using aidl::google::hardware::power::impl::pixel::Power; -using aidl::google::hardware::power::impl::pixel::PowerExt; -using ::android::perfmgr::HintManager; - -constexpr std::string_view kPowerHalInitProp("vendor.powerhal.init"); -constexpr std::string_view kConfigProperty("vendor.powerhal.config"); -constexpr std::string_view kConfigDefaultFileName("powerhint.json"); - -int main() { - const std::string config_path = - "/vendor/etc/" + - android::base::GetProperty(kConfigProperty.data(), kConfigDefaultFileName.data()); - LOG(INFO) << "Pixel Power HAL AIDL Service with Extension is starting with config: " - << config_path; - - // Parse config but do not start the looper - std::shared_ptr hm = HintManager::GetFromJSON(config_path, false); - if (!hm) { - LOG(FATAL) << "Invalid config: " << config_path; - } - - // single thread - ABinderProcess_setThreadPoolMaxThreadCount(0); - - // core service - std::shared_ptr pw = ndk::SharedRefBase::make(hm); - ndk::SpAIBinder pwBinder = pw->asBinder(); - - // extension service - std::shared_ptr pwExt = ndk::SharedRefBase::make(hm); - - // 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) << "Pixel Power HAL AIDL Service with Extension is started."; - - std::thread initThread([&]() { - ::android::base::WaitForProperty(kPowerHalInitProp.data(), "1"); - hm->Start(); - }); - initThread.detach(); - - ABinderProcess_joinThreadPool(); - - // should not reach - LOG(ERROR) << "Pixel Power HAL AIDL Service with Extension just died."; - return EXIT_FAILURE; -} -- 2.20.1