Add a bool property `vendor.powerhal.config.debug`. Power HAL would use `/data/vendor/etc/powerhint.json` when vendor.powerhal.config.debug = true. Bug: 218872105 Bug: 206061061 Test: adb wait-for-device root; adb shell mkdir -p /data/vendor/etc/; adb push powerhint_mod.json /data/vendor/etc/powerhint.json Test: adb shell setprop vendor.powerhal.config.debug true && \ adb shell getprop vendor.powerhal.config.debug && \ adb shell stop vendor.power-hal-aidl && \ adb shell start vendor.power-hal-aidl && adb shell stop && adb shell start Test: adb pull /data/local.prop ; vim local.prop + vendor.powerhal.config.debug=true Test: adb wait-for-device root && adb shell perfetto -o \ /data/misc/perfetto-traces/trace_file.perfetto-trace -t 20s sched freq \ idle am wm gfx view power hal && \ adb pull /data/misc/perfetto-traces/trace_file.perfetto-trace trace_profile_debug.pftrace Change-Id: Ibaf5df280b989a8268efce1e3ab9a3f1e5510800
95 lines
3.8 KiB
C++
95 lines
3.8 KiB
C++
/*
|
|
* 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 "powerhal-libperfmgr"
|
|
|
|
#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"
|
|
#include "PowerSessionManager.h"
|
|
|
|
using aidl::google::hardware::power::impl::pixel::Power;
|
|
using aidl::google::hardware::power::impl::pixel::PowerExt;
|
|
using aidl::google::hardware::power::impl::pixel::PowerHintMonitor;
|
|
using aidl::google::hardware::power::impl::pixel::PowerSessionManager;
|
|
using ::android::perfmgr::HintManager;
|
|
|
|
constexpr std::string_view kPowerHalInitProp("vendor.powerhal.init");
|
|
constexpr std::string_view kConfigDebugPathProperty("vendor.powerhal.config.debug");
|
|
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) << "Power HAL AIDL Service for moto_sm6375 with Extension is starting with config: "
|
|
<< config_path;
|
|
|
|
// Parse config but do not start the looper
|
|
std::shared_ptr<HintManager> hm = HintManager::GetFromJSON(config_path, false);
|
|
if (!hm) {
|
|
LOG(FATAL) << "Invalid config: " << config_path;
|
|
}
|
|
|
|
// single thread
|
|
ABinderProcess_setThreadPoolMaxThreadCount(0);
|
|
|
|
// core service
|
|
std::shared_ptr<Power> pw = ndk::SharedRefBase::make<Power>(hm);
|
|
ndk::SpAIBinder pwBinder = pw->asBinder();
|
|
|
|
// extension service
|
|
std::shared_ptr<PowerExt> pwExt = ndk::SharedRefBase::make<PowerExt>(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) << "Power HAL AIDL Service for moto_sm6375 is started.";
|
|
|
|
std::thread initThread([&]() {
|
|
::android::base::WaitForProperty(kPowerHalInitProp.data(), "1");
|
|
hm->Start();
|
|
|
|
// use debug config for ADPF tuning.
|
|
if (android::base::GetBoolProperty(kConfigDebugPathProperty.data(), false)) {
|
|
const std::string debug_config_path =
|
|
"/data/vendor/etc/" + android::base::GetProperty(kConfigProperty.data(),
|
|
kConfigDefaultFileName.data());
|
|
hm = HintManager::GetFromJSON(debug_config_path, false);
|
|
LOG(WARNING) << "Xiaomi Power HAL AIDL Service with Extension is reloading with config: "
|
|
<< debug_config_path;
|
|
}
|
|
if (::android::base::GetIntProperty("vendor.powerhal.adpf.rate", -1) != -1) {
|
|
PowerHintMonitor::getInstance()->start();
|
|
PowerSessionManager::getInstance()->setHintManager(hm);
|
|
}
|
|
});
|
|
initThread.detach();
|
|
|
|
ABinderProcess_joinThreadPool();
|
|
LOG(ERROR) << "Power HAL AIDL Service for moto_sm6375 with Extension just died.";
|
|
return EXIT_FAILURE; // should not reach
|
|
}
|