1 /*
2  * Copyright (C) 2022 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 ATRACE_TAG (ATRACE_TAG_POWER | ATRACE_TAG_HAL)
18 #define LOG_TAG "libperfmgr"
19 
20 #include "perfmgr/AdpfConfig.h"
21 
22 #include <android-base/file.h>
23 #include <android-base/logging.h>
24 
25 #include <sstream>
26 
27 namespace android {
28 namespace perfmgr {
29 
getPidIInitDivI()30 int64_t AdpfConfig::getPidIInitDivI() {
31     return (mPidI == 0) ? 0 : static_cast<int64_t>(mPidIInit / mPidI);
32 }
getPidIHighDivI()33 int64_t AdpfConfig::getPidIHighDivI() {
34     return (mPidI == 0) ? 0 : static_cast<int64_t>(mPidIHigh / mPidI);
35 }
getPidILowDivI()36 int64_t AdpfConfig::getPidILowDivI() {
37     return (mPidI == 0) ? 0 : static_cast<int64_t>(mPidILow / mPidI);
38 }
39 
dumpToFd(int fd)40 void AdpfConfig::dumpToFd(int fd) {
41     std::ostringstream dump_buf;
42     dump_buf << "Name: " << mName << "\n";
43     dump_buf << "PID_On: " << mPidOn << "\n";
44     dump_buf << "PID_Po: " << mPidPo << "\n";
45     dump_buf << "PID_Pu: " << mPidPu << "\n";
46     dump_buf << "PID_I: " << mPidI << "\n";
47     dump_buf << "PID_I_Init: " << mPidIInit << "\n";
48     dump_buf << "PID_I_High: " << mPidIHigh << "\n";
49     dump_buf << "PID_I_Low: " << mPidILow << "\n";
50     dump_buf << "PID_Do: " << mPidDo << "\n";
51     dump_buf << "PID_Du: " << mPidDu << "\n";
52     dump_buf << "SamplingWindow_P: " << mSamplingWindowP << "\n";
53     dump_buf << "SamplingWindow_I: " << mSamplingWindowI << "\n";
54     dump_buf << "SamplingWindow_D: " << mSamplingWindowD << "\n";
55     dump_buf << "UclampMin_On: " << mUclampMinOn << "\n";
56     dump_buf << "UclampMin_Init: " << mUclampMinInit << "\n";
57     dump_buf << "UclampMin_LoadUp: " << mUclampMinLoadUp << "\n";
58     dump_buf << "UclampMin_LoadReset: " << mUclampMinLoadReset << "\n";
59     dump_buf << "UclampMin_High: " << mUclampMinHigh << "\n";
60     dump_buf << "UclampMin_Low: " << mUclampMinLow << "\n";
61     dump_buf << "ReportingRateLimitNs: " << mReportingRateLimitNs << "\n";
62     dump_buf << "TargetTimeFactor: " << mTargetTimeFactor << "\n";
63     dump_buf << "StaleTimeFactor: " << mStaleTimeFactor << "\n";
64     dump_buf << "GpuBoostOn: " << mGpuBoostOn.value_or(false) << "\n";
65     dump_buf << "GpuBoostCapacityMax: " << mGpuBoostCapacityMax.value_or(0) << "\n";
66     dump_buf << "mGpuCapacityLoadUpHeadroom: " << mGpuCapacityLoadUpHeadroom << "\n";
67     if (mHeuristicBoostOn.has_value()) {
68         dump_buf << "HeuristicBoost_On: " << mHeuristicBoostOn.value() << "\n";
69         dump_buf << "HBoostOnMissedCycles: " << mHBoostOnMissedCycles.value() << "\n";
70         dump_buf << "HBoostOffMaxAvgRatio: " << mHBoostOffMaxAvgRatio.value() << "\n";
71         dump_buf << "HBoostOffMissedCycles: " << mHBoostOffMissedCycles.value() << "\n";
72         dump_buf << "HBoostPidPuFactor: " << mHBoostPidPuFactor.value() << "\n";
73         dump_buf << "HBoostUclampMin: " << mHBoostUclampMin.value() << "\n";
74         dump_buf << "JankCheckTimeFactor: " << mJankCheckTimeFactor.value() << "\n";
75         dump_buf << "LowFrameRateThreshold: " << mLowFrameRateThreshold.value() << "\n";
76         dump_buf << "MaxRecordsNum: " << mMaxRecordsNum.value() << "\n";
77     }
78     if (mUclampMaxEfficientBase.has_value()) {
79         dump_buf << "UclampMax_EfficientBase: " << *mUclampMaxEfficientBase << "\n";
80         dump_buf << "UclampMax_EfficientOffset: " << *mUclampMaxEfficientOffset << "\n";
81     }
82     if (!android::base::WriteStringToFd(dump_buf.str(), fd)) {
83         LOG(ERROR) << "Failed to dump ADPF profile to fd: " << fd;
84     }
85 }
86 
87 }  // namespace perfmgr
88 }  // namespace android
89