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 "android.hardware.power-service.pixel.ext-libperfmgr"
18
19 #include "PowerExt.h"
20
21 #include <android-base/file.h>
22 #include <android-base/logging.h>
23 #include <android-base/properties.h>
24 #include <android-base/stringprintf.h>
25 #include <android-base/strings.h>
26 #include <perfmgr/HintManager.h>
27 #include <utils/Log.h>
28
29 #include <mutex>
30
31 #include "PowerSessionManager.h"
32
33 namespace aidl {
34 namespace google {
35 namespace hardware {
36 namespace power {
37 namespace impl {
38 namespace pixel {
39
40 using ::android::perfmgr::HintManager;
41
setMode(const std::string & mode,bool enabled)42 ndk::ScopedAStatus PowerExt::setMode(const std::string &mode, bool enabled) {
43 LOG(DEBUG) << "PowerExt setMode: " << mode << " to: " << enabled;
44
45 if (enabled) {
46 HintManager::GetInstance()->DoHint(mode);
47 } else {
48 HintManager::GetInstance()->EndHint(mode);
49 }
50 if (HintManager::GetInstance()->GetAdpfProfile() &&
51 HintManager::GetInstance()->GetAdpfProfile()->mReportingRateLimitNs > 0) {
52 PowerSessionManager::getInstance()->updateHintMode(mode, enabled);
53 }
54
55 if (mode == AdaptiveCpu::HINT_NAME) {
56 LOG(DEBUG) << "AdaptiveCpu intercepted hint";
57 mAdaptiveCpu->HintReceived(enabled);
58 }
59
60 return ndk::ScopedAStatus::ok();
61 }
62
isModeSupported(const std::string & mode,bool * _aidl_return)63 ndk::ScopedAStatus PowerExt::isModeSupported(const std::string &mode, bool *_aidl_return) {
64 bool supported = HintManager::GetInstance()->IsHintSupported(mode);
65 LOG(INFO) << "PowerExt mode " << mode << " isModeSupported: " << supported;
66 *_aidl_return = supported;
67 return ndk::ScopedAStatus::ok();
68 }
69
setBoost(const std::string & boost,int32_t durationMs)70 ndk::ScopedAStatus PowerExt::setBoost(const std::string &boost, int32_t durationMs) {
71 LOG(DEBUG) << "PowerExt setBoost: " << boost << " duration: " << durationMs;
72 if (HintManager::GetInstance()->GetAdpfProfile() &&
73 HintManager::GetInstance()->GetAdpfProfile()->mReportingRateLimitNs > 0) {
74 PowerSessionManager::getInstance()->updateHintBoost(boost, durationMs);
75 }
76
77 if (durationMs > 0) {
78 HintManager::GetInstance()->DoHint(boost, std::chrono::milliseconds(durationMs));
79 } else if (durationMs == 0) {
80 HintManager::GetInstance()->DoHint(boost);
81 } else {
82 HintManager::GetInstance()->EndHint(boost);
83 }
84
85 return ndk::ScopedAStatus::ok();
86 }
87
isBoostSupported(const std::string & boost,bool * _aidl_return)88 ndk::ScopedAStatus PowerExt::isBoostSupported(const std::string &boost, bool *_aidl_return) {
89 bool supported = HintManager::GetInstance()->IsHintSupported(boost);
90 LOG(INFO) << "PowerExt boost " << boost << " isBoostSupported: " << supported;
91 *_aidl_return = supported;
92 return ndk::ScopedAStatus::ok();
93 }
94
95 } // namespace pixel
96 } // namespace impl
97 } // namespace power
98 } // namespace hardware
99 } // namespace google
100 } // namespace aidl
101