1*d57664e9SAndroid Build Coastguard Worker /*
2*d57664e9SAndroid Build Coastguard Worker * Copyright (C) 2024 The Android Open Source Project
3*d57664e9SAndroid Build Coastguard Worker *
4*d57664e9SAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*d57664e9SAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*d57664e9SAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*d57664e9SAndroid Build Coastguard Worker *
8*d57664e9SAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*d57664e9SAndroid Build Coastguard Worker *
10*d57664e9SAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*d57664e9SAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*d57664e9SAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*d57664e9SAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*d57664e9SAndroid Build Coastguard Worker * limitations under the License.
15*d57664e9SAndroid Build Coastguard Worker */
16*d57664e9SAndroid Build Coastguard Worker
17*d57664e9SAndroid Build Coastguard Worker #include <aidl/android/hardware/power/CpuHeadroomParams.h>
18*d57664e9SAndroid Build Coastguard Worker #include <aidl/android/hardware/power/GpuHeadroomParams.h>
19*d57664e9SAndroid Build Coastguard Worker #include <aidl/android/os/CpuHeadroomParamsInternal.h>
20*d57664e9SAndroid Build Coastguard Worker #include <aidl/android/os/GpuHeadroomParamsInternal.h>
21*d57664e9SAndroid Build Coastguard Worker #include <aidl/android/os/IHintManager.h>
22*d57664e9SAndroid Build Coastguard Worker #include <android/binder_manager.h>
23*d57664e9SAndroid Build Coastguard Worker #include <android/system_health.h>
24*d57664e9SAndroid Build Coastguard Worker #include <binder/IServiceManager.h>
25*d57664e9SAndroid Build Coastguard Worker #include <binder/Status.h>
26*d57664e9SAndroid Build Coastguard Worker
27*d57664e9SAndroid Build Coastguard Worker using namespace android;
28*d57664e9SAndroid Build Coastguard Worker using namespace aidl::android::os;
29*d57664e9SAndroid Build Coastguard Worker namespace hal = aidl::android::hardware::power;
30*d57664e9SAndroid Build Coastguard Worker
31*d57664e9SAndroid Build Coastguard Worker struct ACpuHeadroomParams : public CpuHeadroomParamsInternal {};
32*d57664e9SAndroid Build Coastguard Worker struct AGpuHeadroomParams : public GpuHeadroomParamsInternal {};
33*d57664e9SAndroid Build Coastguard Worker
34*d57664e9SAndroid Build Coastguard Worker const int CPU_HEADROOM_CALCULATION_WINDOW_MILLIS_MIN = 50;
35*d57664e9SAndroid Build Coastguard Worker const int CPU_HEADROOM_CALCULATION_WINDOW_MILLIS_MAX = 10000;
36*d57664e9SAndroid Build Coastguard Worker const int GPU_HEADROOM_CALCULATION_WINDOW_MILLIS_MIN = 50;
37*d57664e9SAndroid Build Coastguard Worker const int GPU_HEADROOM_CALCULATION_WINDOW_MILLIS_MAX = 10000;
38*d57664e9SAndroid Build Coastguard Worker const int CPU_HEADROOM_MAX_TID_COUNT = 5;
39*d57664e9SAndroid Build Coastguard Worker
40*d57664e9SAndroid Build Coastguard Worker struct ASystemHealthManager {
41*d57664e9SAndroid Build Coastguard Worker public:
42*d57664e9SAndroid Build Coastguard Worker static ASystemHealthManager* getInstance();
43*d57664e9SAndroid Build Coastguard Worker ASystemHealthManager(std::shared_ptr<IHintManager>& hintManager);
44*d57664e9SAndroid Build Coastguard Worker ASystemHealthManager() = delete;
45*d57664e9SAndroid Build Coastguard Worker ~ASystemHealthManager();
46*d57664e9SAndroid Build Coastguard Worker int getCpuHeadroom(const ACpuHeadroomParams* params, float* outHeadroom);
47*d57664e9SAndroid Build Coastguard Worker int getGpuHeadroom(const AGpuHeadroomParams* params, float* outHeadroom);
48*d57664e9SAndroid Build Coastguard Worker int getCpuHeadroomMinIntervalMillis(int64_t* outMinIntervalMillis);
49*d57664e9SAndroid Build Coastguard Worker int getGpuHeadroomMinIntervalMillis(int64_t* outMinIntervalMillis);
50*d57664e9SAndroid Build Coastguard Worker
51*d57664e9SAndroid Build Coastguard Worker private:
52*d57664e9SAndroid Build Coastguard Worker static ASystemHealthManager* create(std::shared_ptr<IHintManager> hintManager);
53*d57664e9SAndroid Build Coastguard Worker std::shared_ptr<IHintManager> mHintManager;
54*d57664e9SAndroid Build Coastguard Worker };
55*d57664e9SAndroid Build Coastguard Worker
getInstance()56*d57664e9SAndroid Build Coastguard Worker ASystemHealthManager* ASystemHealthManager::getInstance() {
57*d57664e9SAndroid Build Coastguard Worker static std::once_flag creationFlag;
58*d57664e9SAndroid Build Coastguard Worker static ASystemHealthManager* instance = nullptr;
59*d57664e9SAndroid Build Coastguard Worker std::call_once(creationFlag, []() { instance = create(nullptr); });
60*d57664e9SAndroid Build Coastguard Worker return instance;
61*d57664e9SAndroid Build Coastguard Worker }
62*d57664e9SAndroid Build Coastguard Worker
ASystemHealthManager(std::shared_ptr<IHintManager> & hintManager)63*d57664e9SAndroid Build Coastguard Worker ASystemHealthManager::ASystemHealthManager(std::shared_ptr<IHintManager>& hintManager)
64*d57664e9SAndroid Build Coastguard Worker : mHintManager(std::move(hintManager)) {}
65*d57664e9SAndroid Build Coastguard Worker
~ASystemHealthManager()66*d57664e9SAndroid Build Coastguard Worker ASystemHealthManager::~ASystemHealthManager() {}
67*d57664e9SAndroid Build Coastguard Worker
create(std::shared_ptr<IHintManager> hintManager)68*d57664e9SAndroid Build Coastguard Worker ASystemHealthManager* ASystemHealthManager::create(std::shared_ptr<IHintManager> hintManager) {
69*d57664e9SAndroid Build Coastguard Worker if (!hintManager) {
70*d57664e9SAndroid Build Coastguard Worker hintManager = IHintManager::fromBinder(
71*d57664e9SAndroid Build Coastguard Worker ndk::SpAIBinder(AServiceManager_waitForService("performance_hint")));
72*d57664e9SAndroid Build Coastguard Worker }
73*d57664e9SAndroid Build Coastguard Worker if (hintManager == nullptr) {
74*d57664e9SAndroid Build Coastguard Worker ALOGE("%s: PerformanceHint service is not ready ", __FUNCTION__);
75*d57664e9SAndroid Build Coastguard Worker return nullptr;
76*d57664e9SAndroid Build Coastguard Worker }
77*d57664e9SAndroid Build Coastguard Worker return new ASystemHealthManager(hintManager);
78*d57664e9SAndroid Build Coastguard Worker }
79*d57664e9SAndroid Build Coastguard Worker
ASystemHealth_acquireManager()80*d57664e9SAndroid Build Coastguard Worker ASystemHealthManager* ASystemHealth_acquireManager() {
81*d57664e9SAndroid Build Coastguard Worker return ASystemHealthManager::getInstance();
82*d57664e9SAndroid Build Coastguard Worker }
83*d57664e9SAndroid Build Coastguard Worker
getCpuHeadroom(const ACpuHeadroomParams * params,float * outHeadroom)84*d57664e9SAndroid Build Coastguard Worker int ASystemHealthManager::getCpuHeadroom(const ACpuHeadroomParams* params, float* outHeadroom) {
85*d57664e9SAndroid Build Coastguard Worker std::optional<hal::CpuHeadroomResult> res;
86*d57664e9SAndroid Build Coastguard Worker ::ndk::ScopedAStatus ret;
87*d57664e9SAndroid Build Coastguard Worker CpuHeadroomParamsInternal internalParams;
88*d57664e9SAndroid Build Coastguard Worker if (!params) {
89*d57664e9SAndroid Build Coastguard Worker ret = mHintManager->getCpuHeadroom(internalParams, &res);
90*d57664e9SAndroid Build Coastguard Worker } else {
91*d57664e9SAndroid Build Coastguard Worker ret = mHintManager->getCpuHeadroom(*params, &res);
92*d57664e9SAndroid Build Coastguard Worker }
93*d57664e9SAndroid Build Coastguard Worker if (!ret.isOk()) {
94*d57664e9SAndroid Build Coastguard Worker LOG_ALWAYS_FATAL_IF(ret.getExceptionCode() == EX_ILLEGAL_ARGUMENT,
95*d57664e9SAndroid Build Coastguard Worker "Invalid ACpuHeadroomParams: %s", ret.getMessage());
96*d57664e9SAndroid Build Coastguard Worker ALOGE("ASystemHealth_getCpuHeadroom fails: %s", ret.getMessage());
97*d57664e9SAndroid Build Coastguard Worker if (ret.getExceptionCode() == EX_UNSUPPORTED_OPERATION) {
98*d57664e9SAndroid Build Coastguard Worker return ENOTSUP;
99*d57664e9SAndroid Build Coastguard Worker } else if (ret.getExceptionCode() == EX_SECURITY) {
100*d57664e9SAndroid Build Coastguard Worker return EPERM;
101*d57664e9SAndroid Build Coastguard Worker }
102*d57664e9SAndroid Build Coastguard Worker return EPIPE;
103*d57664e9SAndroid Build Coastguard Worker }
104*d57664e9SAndroid Build Coastguard Worker *outHeadroom = res->get<hal::CpuHeadroomResult::Tag::globalHeadroom>();
105*d57664e9SAndroid Build Coastguard Worker return OK;
106*d57664e9SAndroid Build Coastguard Worker }
107*d57664e9SAndroid Build Coastguard Worker
getGpuHeadroom(const AGpuHeadroomParams * params,float * outHeadroom)108*d57664e9SAndroid Build Coastguard Worker int ASystemHealthManager::getGpuHeadroom(const AGpuHeadroomParams* params, float* outHeadroom) {
109*d57664e9SAndroid Build Coastguard Worker std::optional<hal::GpuHeadroomResult> res;
110*d57664e9SAndroid Build Coastguard Worker ::ndk::ScopedAStatus ret;
111*d57664e9SAndroid Build Coastguard Worker GpuHeadroomParamsInternal internalParams;
112*d57664e9SAndroid Build Coastguard Worker if (!params) {
113*d57664e9SAndroid Build Coastguard Worker ret = mHintManager->getGpuHeadroom(internalParams, &res);
114*d57664e9SAndroid Build Coastguard Worker } else {
115*d57664e9SAndroid Build Coastguard Worker ret = mHintManager->getGpuHeadroom(*params, &res);
116*d57664e9SAndroid Build Coastguard Worker }
117*d57664e9SAndroid Build Coastguard Worker if (!ret.isOk()) {
118*d57664e9SAndroid Build Coastguard Worker LOG_ALWAYS_FATAL_IF(ret.getExceptionCode() == EX_ILLEGAL_ARGUMENT,
119*d57664e9SAndroid Build Coastguard Worker "Invalid AGpuHeadroomParams: %s", ret.getMessage());
120*d57664e9SAndroid Build Coastguard Worker ALOGE("ASystemHealth_getGpuHeadroom fails: %s", ret.getMessage());
121*d57664e9SAndroid Build Coastguard Worker if (ret.getExceptionCode() == EX_UNSUPPORTED_OPERATION) {
122*d57664e9SAndroid Build Coastguard Worker return ENOTSUP;
123*d57664e9SAndroid Build Coastguard Worker }
124*d57664e9SAndroid Build Coastguard Worker return EPIPE;
125*d57664e9SAndroid Build Coastguard Worker }
126*d57664e9SAndroid Build Coastguard Worker *outHeadroom = res->get<hal::GpuHeadroomResult::Tag::globalHeadroom>();
127*d57664e9SAndroid Build Coastguard Worker return OK;
128*d57664e9SAndroid Build Coastguard Worker }
129*d57664e9SAndroid Build Coastguard Worker
getCpuHeadroomMinIntervalMillis(int64_t * outMinIntervalMillis)130*d57664e9SAndroid Build Coastguard Worker int ASystemHealthManager::getCpuHeadroomMinIntervalMillis(int64_t* outMinIntervalMillis) {
131*d57664e9SAndroid Build Coastguard Worker int64_t minIntervalMillis = 0;
132*d57664e9SAndroid Build Coastguard Worker ::ndk::ScopedAStatus ret = mHintManager->getCpuHeadroomMinIntervalMillis(&minIntervalMillis);
133*d57664e9SAndroid Build Coastguard Worker if (!ret.isOk()) {
134*d57664e9SAndroid Build Coastguard Worker ALOGE("ASystemHealth_getCpuHeadroomMinIntervalMillis fails: %s", ret.getMessage());
135*d57664e9SAndroid Build Coastguard Worker if (ret.getExceptionCode() == EX_UNSUPPORTED_OPERATION) {
136*d57664e9SAndroid Build Coastguard Worker return ENOTSUP;
137*d57664e9SAndroid Build Coastguard Worker }
138*d57664e9SAndroid Build Coastguard Worker return EPIPE;
139*d57664e9SAndroid Build Coastguard Worker }
140*d57664e9SAndroid Build Coastguard Worker *outMinIntervalMillis = minIntervalMillis;
141*d57664e9SAndroid Build Coastguard Worker return OK;
142*d57664e9SAndroid Build Coastguard Worker }
143*d57664e9SAndroid Build Coastguard Worker
getGpuHeadroomMinIntervalMillis(int64_t * outMinIntervalMillis)144*d57664e9SAndroid Build Coastguard Worker int ASystemHealthManager::getGpuHeadroomMinIntervalMillis(int64_t* outMinIntervalMillis) {
145*d57664e9SAndroid Build Coastguard Worker int64_t minIntervalMillis = 0;
146*d57664e9SAndroid Build Coastguard Worker ::ndk::ScopedAStatus ret = mHintManager->getGpuHeadroomMinIntervalMillis(&minIntervalMillis);
147*d57664e9SAndroid Build Coastguard Worker if (!ret.isOk()) {
148*d57664e9SAndroid Build Coastguard Worker ALOGE("ASystemHealth_getGpuHeadroomMinIntervalMillis fails: %s", ret.getMessage());
149*d57664e9SAndroid Build Coastguard Worker if (ret.getExceptionCode() == EX_UNSUPPORTED_OPERATION) {
150*d57664e9SAndroid Build Coastguard Worker return ENOTSUP;
151*d57664e9SAndroid Build Coastguard Worker }
152*d57664e9SAndroid Build Coastguard Worker return EPIPE;
153*d57664e9SAndroid Build Coastguard Worker }
154*d57664e9SAndroid Build Coastguard Worker *outMinIntervalMillis = minIntervalMillis;
155*d57664e9SAndroid Build Coastguard Worker return OK;
156*d57664e9SAndroid Build Coastguard Worker }
157*d57664e9SAndroid Build Coastguard Worker
ASystemHealth_getCpuHeadroom(const ACpuHeadroomParams * _Nullable params,float * _Nonnull outHeadroom)158*d57664e9SAndroid Build Coastguard Worker int ASystemHealth_getCpuHeadroom(const ACpuHeadroomParams* _Nullable params,
159*d57664e9SAndroid Build Coastguard Worker float* _Nonnull outHeadroom) {
160*d57664e9SAndroid Build Coastguard Worker LOG_ALWAYS_FATAL_IF(outHeadroom == nullptr, "%s: outHeadroom should not be null", __FUNCTION__);
161*d57664e9SAndroid Build Coastguard Worker auto manager = ASystemHealthManager::getInstance();
162*d57664e9SAndroid Build Coastguard Worker if (manager == nullptr) return ENOTSUP;
163*d57664e9SAndroid Build Coastguard Worker return manager->getCpuHeadroom(params, outHeadroom);
164*d57664e9SAndroid Build Coastguard Worker }
165*d57664e9SAndroid Build Coastguard Worker
ASystemHealth_getGpuHeadroom(const AGpuHeadroomParams * _Nullable params,float * _Nonnull outHeadroom)166*d57664e9SAndroid Build Coastguard Worker int ASystemHealth_getGpuHeadroom(const AGpuHeadroomParams* _Nullable params,
167*d57664e9SAndroid Build Coastguard Worker float* _Nonnull outHeadroom) {
168*d57664e9SAndroid Build Coastguard Worker LOG_ALWAYS_FATAL_IF(outHeadroom == nullptr, "%s: outHeadroom should not be null", __FUNCTION__);
169*d57664e9SAndroid Build Coastguard Worker auto manager = ASystemHealthManager::getInstance();
170*d57664e9SAndroid Build Coastguard Worker if (manager == nullptr) return ENOTSUP;
171*d57664e9SAndroid Build Coastguard Worker return manager->getGpuHeadroom(params, outHeadroom);
172*d57664e9SAndroid Build Coastguard Worker }
173*d57664e9SAndroid Build Coastguard Worker
ASystemHealth_getCpuHeadroomMinIntervalMillis(int64_t * _Nonnull outMinIntervalMillis)174*d57664e9SAndroid Build Coastguard Worker int ASystemHealth_getCpuHeadroomMinIntervalMillis(int64_t* _Nonnull outMinIntervalMillis) {
175*d57664e9SAndroid Build Coastguard Worker LOG_ALWAYS_FATAL_IF(outMinIntervalMillis == nullptr,
176*d57664e9SAndroid Build Coastguard Worker "%s: outMinIntervalMillis should not be null", __FUNCTION__);
177*d57664e9SAndroid Build Coastguard Worker auto manager = ASystemHealthManager::getInstance();
178*d57664e9SAndroid Build Coastguard Worker if (manager == nullptr) return ENOTSUP;
179*d57664e9SAndroid Build Coastguard Worker return manager->getCpuHeadroomMinIntervalMillis(outMinIntervalMillis);
180*d57664e9SAndroid Build Coastguard Worker }
181*d57664e9SAndroid Build Coastguard Worker
ASystemHealth_getGpuHeadroomMinIntervalMillis(int64_t * _Nonnull outMinIntervalMillis)182*d57664e9SAndroid Build Coastguard Worker int ASystemHealth_getGpuHeadroomMinIntervalMillis(int64_t* _Nonnull outMinIntervalMillis) {
183*d57664e9SAndroid Build Coastguard Worker LOG_ALWAYS_FATAL_IF(outMinIntervalMillis == nullptr,
184*d57664e9SAndroid Build Coastguard Worker "%s: outMinIntervalMillis should not be null", __FUNCTION__);
185*d57664e9SAndroid Build Coastguard Worker auto manager = ASystemHealthManager::getInstance();
186*d57664e9SAndroid Build Coastguard Worker if (manager == nullptr) return ENOTSUP;
187*d57664e9SAndroid Build Coastguard Worker return manager->getGpuHeadroomMinIntervalMillis(outMinIntervalMillis);
188*d57664e9SAndroid Build Coastguard Worker }
189*d57664e9SAndroid Build Coastguard Worker
ACpuHeadroomParams_setCalculationWindowMillis(ACpuHeadroomParams * _Nonnull params,int windowMillis)190*d57664e9SAndroid Build Coastguard Worker void ACpuHeadroomParams_setCalculationWindowMillis(ACpuHeadroomParams* _Nonnull params,
191*d57664e9SAndroid Build Coastguard Worker int windowMillis) {
192*d57664e9SAndroid Build Coastguard Worker LOG_ALWAYS_FATAL_IF(windowMillis < CPU_HEADROOM_CALCULATION_WINDOW_MILLIS_MIN ||
193*d57664e9SAndroid Build Coastguard Worker windowMillis > CPU_HEADROOM_CALCULATION_WINDOW_MILLIS_MAX,
194*d57664e9SAndroid Build Coastguard Worker "%s: windowMillis should be in range [50, 10000] but got %d", __FUNCTION__,
195*d57664e9SAndroid Build Coastguard Worker windowMillis);
196*d57664e9SAndroid Build Coastguard Worker params->calculationWindowMillis = windowMillis;
197*d57664e9SAndroid Build Coastguard Worker }
198*d57664e9SAndroid Build Coastguard Worker
AGpuHeadroomParams_setCalculationWindowMillis(AGpuHeadroomParams * _Nonnull params,int windowMillis)199*d57664e9SAndroid Build Coastguard Worker void AGpuHeadroomParams_setCalculationWindowMillis(AGpuHeadroomParams* _Nonnull params,
200*d57664e9SAndroid Build Coastguard Worker int windowMillis) {
201*d57664e9SAndroid Build Coastguard Worker LOG_ALWAYS_FATAL_IF(windowMillis < GPU_HEADROOM_CALCULATION_WINDOW_MILLIS_MIN ||
202*d57664e9SAndroid Build Coastguard Worker windowMillis > GPU_HEADROOM_CALCULATION_WINDOW_MILLIS_MAX,
203*d57664e9SAndroid Build Coastguard Worker "%s: windowMillis should be in range [50, 10000] but got %d", __FUNCTION__,
204*d57664e9SAndroid Build Coastguard Worker windowMillis);
205*d57664e9SAndroid Build Coastguard Worker params->calculationWindowMillis = windowMillis;
206*d57664e9SAndroid Build Coastguard Worker }
207*d57664e9SAndroid Build Coastguard Worker
ACpuHeadroomParams_getCalculationWindowMillis(ACpuHeadroomParams * _Nonnull params)208*d57664e9SAndroid Build Coastguard Worker int ACpuHeadroomParams_getCalculationWindowMillis(ACpuHeadroomParams* _Nonnull params) {
209*d57664e9SAndroid Build Coastguard Worker return params->calculationWindowMillis;
210*d57664e9SAndroid Build Coastguard Worker }
211*d57664e9SAndroid Build Coastguard Worker
AGpuHeadroomParams_getCalculationWindowMillis(AGpuHeadroomParams * _Nonnull params)212*d57664e9SAndroid Build Coastguard Worker int AGpuHeadroomParams_getCalculationWindowMillis(AGpuHeadroomParams* _Nonnull params) {
213*d57664e9SAndroid Build Coastguard Worker return params->calculationWindowMillis;
214*d57664e9SAndroid Build Coastguard Worker }
215*d57664e9SAndroid Build Coastguard Worker
ACpuHeadroomParams_setTids(ACpuHeadroomParams * _Nonnull params,const int * _Nonnull tids,int tidsSize)216*d57664e9SAndroid Build Coastguard Worker void ACpuHeadroomParams_setTids(ACpuHeadroomParams* _Nonnull params, const int* _Nonnull tids,
217*d57664e9SAndroid Build Coastguard Worker int tidsSize) {
218*d57664e9SAndroid Build Coastguard Worker LOG_ALWAYS_FATAL_IF(tids == nullptr, "%s: tids should not be null", __FUNCTION__);
219*d57664e9SAndroid Build Coastguard Worker LOG_ALWAYS_FATAL_IF(tidsSize > CPU_HEADROOM_MAX_TID_COUNT, "%s: tids size should not exceed 5",
220*d57664e9SAndroid Build Coastguard Worker __FUNCTION__);
221*d57664e9SAndroid Build Coastguard Worker params->tids.resize(tidsSize);
222*d57664e9SAndroid Build Coastguard Worker params->tids.clear();
223*d57664e9SAndroid Build Coastguard Worker for (int i = 0; i < tidsSize; ++i) {
224*d57664e9SAndroid Build Coastguard Worker LOG_ALWAYS_FATAL_IF(tids[i] <= 0, "ACpuHeadroomParams_setTids: Invalid non-positive tid %d",
225*d57664e9SAndroid Build Coastguard Worker tids[i]);
226*d57664e9SAndroid Build Coastguard Worker params->tids[i] = tids[i];
227*d57664e9SAndroid Build Coastguard Worker }
228*d57664e9SAndroid Build Coastguard Worker }
229*d57664e9SAndroid Build Coastguard Worker
ACpuHeadroomParams_setCalculationType(ACpuHeadroomParams * _Nonnull params,ACpuHeadroomCalculationType calculationType)230*d57664e9SAndroid Build Coastguard Worker void ACpuHeadroomParams_setCalculationType(ACpuHeadroomParams* _Nonnull params,
231*d57664e9SAndroid Build Coastguard Worker ACpuHeadroomCalculationType calculationType) {
232*d57664e9SAndroid Build Coastguard Worker LOG_ALWAYS_FATAL_IF(calculationType < ACpuHeadroomCalculationType::
233*d57664e9SAndroid Build Coastguard Worker ACPU_HEADROOM_CALCULATION_TYPE_MIN ||
234*d57664e9SAndroid Build Coastguard Worker calculationType > ACpuHeadroomCalculationType::
235*d57664e9SAndroid Build Coastguard Worker ACPU_HEADROOM_CALCULATION_TYPE_AVERAGE,
236*d57664e9SAndroid Build Coastguard Worker "%s: calculationType should be one of ACpuHeadroomCalculationType values "
237*d57664e9SAndroid Build Coastguard Worker "but got %d",
238*d57664e9SAndroid Build Coastguard Worker __FUNCTION__, calculationType);
239*d57664e9SAndroid Build Coastguard Worker params->calculationType = static_cast<hal::CpuHeadroomParams::CalculationType>(calculationType);
240*d57664e9SAndroid Build Coastguard Worker }
241*d57664e9SAndroid Build Coastguard Worker
ACpuHeadroomParams_getCalculationType(ACpuHeadroomParams * _Nonnull params)242*d57664e9SAndroid Build Coastguard Worker ACpuHeadroomCalculationType ACpuHeadroomParams_getCalculationType(
243*d57664e9SAndroid Build Coastguard Worker ACpuHeadroomParams* _Nonnull params) {
244*d57664e9SAndroid Build Coastguard Worker return static_cast<ACpuHeadroomCalculationType>(params->calculationType);
245*d57664e9SAndroid Build Coastguard Worker }
246*d57664e9SAndroid Build Coastguard Worker
AGpuHeadroomParams_setCalculationType(AGpuHeadroomParams * _Nonnull params,AGpuHeadroomCalculationType calculationType)247*d57664e9SAndroid Build Coastguard Worker void AGpuHeadroomParams_setCalculationType(AGpuHeadroomParams* _Nonnull params,
248*d57664e9SAndroid Build Coastguard Worker AGpuHeadroomCalculationType calculationType) {
249*d57664e9SAndroid Build Coastguard Worker LOG_ALWAYS_FATAL_IF(calculationType < AGpuHeadroomCalculationType::
250*d57664e9SAndroid Build Coastguard Worker AGPU_HEADROOM_CALCULATION_TYPE_MIN ||
251*d57664e9SAndroid Build Coastguard Worker calculationType > AGpuHeadroomCalculationType::
252*d57664e9SAndroid Build Coastguard Worker AGPU_HEADROOM_CALCULATION_TYPE_AVERAGE,
253*d57664e9SAndroid Build Coastguard Worker "%s: calculationType should be one of AGpuHeadroomCalculationType values "
254*d57664e9SAndroid Build Coastguard Worker "but got %d",
255*d57664e9SAndroid Build Coastguard Worker __FUNCTION__, calculationType);
256*d57664e9SAndroid Build Coastguard Worker params->calculationType = static_cast<hal::GpuHeadroomParams::CalculationType>(calculationType);
257*d57664e9SAndroid Build Coastguard Worker }
258*d57664e9SAndroid Build Coastguard Worker
AGpuHeadroomParams_getCalculationType(AGpuHeadroomParams * _Nonnull params)259*d57664e9SAndroid Build Coastguard Worker AGpuHeadroomCalculationType AGpuHeadroomParams_getCalculationType(
260*d57664e9SAndroid Build Coastguard Worker AGpuHeadroomParams* _Nonnull params) {
261*d57664e9SAndroid Build Coastguard Worker return static_cast<AGpuHeadroomCalculationType>(params->calculationType);
262*d57664e9SAndroid Build Coastguard Worker }
263*d57664e9SAndroid Build Coastguard Worker
ACpuHeadroomParams_create()264*d57664e9SAndroid Build Coastguard Worker ACpuHeadroomParams* _Nonnull ACpuHeadroomParams_create() {
265*d57664e9SAndroid Build Coastguard Worker return new ACpuHeadroomParams();
266*d57664e9SAndroid Build Coastguard Worker }
267*d57664e9SAndroid Build Coastguard Worker
AGpuHeadroomParams_create()268*d57664e9SAndroid Build Coastguard Worker AGpuHeadroomParams* _Nonnull AGpuHeadroomParams_create() {
269*d57664e9SAndroid Build Coastguard Worker return new AGpuHeadroomParams();
270*d57664e9SAndroid Build Coastguard Worker }
271*d57664e9SAndroid Build Coastguard Worker
ACpuHeadroomParams_destroy(ACpuHeadroomParams * _Nonnull params)272*d57664e9SAndroid Build Coastguard Worker void ACpuHeadroomParams_destroy(ACpuHeadroomParams* _Nonnull params) {
273*d57664e9SAndroid Build Coastguard Worker delete params;
274*d57664e9SAndroid Build Coastguard Worker }
275*d57664e9SAndroid Build Coastguard Worker
AGpuHeadroomParams_destroy(AGpuHeadroomParams * _Nonnull params)276*d57664e9SAndroid Build Coastguard Worker void AGpuHeadroomParams_destroy(AGpuHeadroomParams* _Nonnull params) {
277*d57664e9SAndroid Build Coastguard Worker delete params;
278*d57664e9SAndroid Build Coastguard Worker }
279