• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #define LOG_TAG "powerhal-libperfmgr"
18 
19 #include <android-base/logging.h>
20 #include <android-base/properties.h>
21 #include <android/binder_ibinder_platform.h>
22 #include <android/binder_manager.h>
23 #include <android/binder_process.h>
24 #include <perfmgr/HintManager.h>
25 
26 #include <thread>
27 
28 #include "Power.h"
29 #include "PowerExt.h"
30 #include "PowerSessionManager.h"
31 #include "adaptivecpu/AdaptiveCpu.h"
32 #include "disp-power/DisplayLowPower.h"
33 
34 using aidl::google::hardware::power::impl::pixel::AdaptiveCpu;
35 using aidl::google::hardware::power::impl::pixel::DisplayLowPower;
36 using aidl::google::hardware::power::impl::pixel::Power;
37 using aidl::google::hardware::power::impl::pixel::PowerExt;
38 using aidl::google::hardware::power::impl::pixel::PowerHintMonitor;
39 using aidl::google::hardware::power::impl::pixel::PowerSessionManager;
40 using ::android::perfmgr::HintManager;
41 
42 constexpr std::string_view kPowerHalInitProp("vendor.powerhal.init");
43 
main()44 int main() {
45     // Parse config but do not start the looper
46     std::shared_ptr<HintManager> hm = HintManager::GetInstance();
47     if (!hm) {
48         LOG(FATAL) << "HintManager Init failed";
49     }
50 
51     std::shared_ptr<DisplayLowPower> dlpw = std::make_shared<DisplayLowPower>();
52 
53     // single thread
54     ABinderProcess_setThreadPoolMaxThreadCount(0);
55 
56     std::shared_ptr<AdaptiveCpu> adaptiveCpu = std::make_shared<AdaptiveCpu>();
57 
58     // core service
59     std::shared_ptr<Power> pw = ndk::SharedRefBase::make<Power>(dlpw, adaptiveCpu);
60     ndk::SpAIBinder pwBinder = pw->asBinder();
61     AIBinder_setMinSchedulerPolicy(pwBinder.get(), SCHED_NORMAL, -20);
62 
63     // extension service
64     std::shared_ptr<PowerExt> pwExt = ndk::SharedRefBase::make<PowerExt>(dlpw, adaptiveCpu);
65     auto pwExtBinder = pwExt->asBinder();
66     AIBinder_setMinSchedulerPolicy(pwExtBinder.get(), SCHED_NORMAL, -20);
67 
68     // attach the extension to the same binder we will be registering
69     CHECK(STATUS_OK == AIBinder_setExtension(pwBinder.get(), pwExt->asBinder().get()));
70 
71     const std::string instance = std::string() + Power::descriptor + "/default";
72     binder_status_t status = AServiceManager_addService(pw->asBinder().get(), instance.c_str());
73     CHECK(status == STATUS_OK);
74     LOG(INFO) << "Pixel Power HAL AIDL Service with Extension is started.";
75 
76     if (HintManager::GetInstance()->GetAdpfProfile()) {
77         PowerHintMonitor::getInstance()->start();
78     }
79 
80     std::thread initThread([&]() {
81         ::android::base::WaitForProperty(kPowerHalInitProp.data(), "1");
82         HintManager::GetInstance()->Start();
83         dlpw->Init();
84     });
85     initThread.detach();
86 
87     ABinderProcess_joinThreadPool();
88 
89     // should not reach
90     LOG(ERROR) << "Pixel Power HAL AIDL Service with Extension just died.";
91     return EXIT_FAILURE;
92 }
93