• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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.stats-service.pixel"
18 
19 #include <dataproviders/DisplayStateResidencyDataProvider.h>
20 #include <dataproviders/PowerStatsEnergyConsumer.h>
21 #include <DevfreqStateResidencyDataProvider.h>
22 #include <Gs201CommonDataProviders.h>
23 #include <PowerStatsAidl.h>
24 
25 #include <android-base/logging.h>
26 #include <android-base/properties.h>
27 #include <android/binder_manager.h>
28 #include <android/binder_process.h>
29 #include <log/log.h>
30 
31 using aidl::android::hardware::power::stats::DevfreqStateResidencyDataProvider;
32 using aidl::android::hardware::power::stats::DisplayStateResidencyDataProvider;
33 using aidl::android::hardware::power::stats::EnergyConsumerType;
34 using aidl::android::hardware::power::stats::PowerStatsEnergyConsumer;
35 
addDisplay(std::shared_ptr<PowerStats> p)36 void addDisplay(std::shared_ptr<PowerStats> p) {
37     // Add display residency stats
38     std::vector<std::string> states = {
39         "Off",
40         "LP: 1080x2400@30",
41         "On: 1080x2400@60",
42         "On: 1080x2400@90",
43         "HBM: 1080x2400@60",
44         "HBM: 1080x2400@90"};
45 
46     p->addStateResidencyDataProvider(std::make_unique<DisplayStateResidencyDataProvider>("Display",
47             "/sys/class/backlight/panel0-backlight/state",
48             states));
49 
50     // Add display energy consumer
51     p->addEnergyConsumer(PowerStatsEnergyConsumer::createMeterAndEntityConsumer(p,
52             EnergyConsumerType::DISPLAY, "display", {"VSYS_PWR_DISPLAY"}, "Display",
53             {{"LP: 1080x2400@30", 1},
54              {"On: 1080x2400@60", 2},
55              {"On: 1080x2400@90", 3}}));
56 }
57 
addGPUGs202(std::shared_ptr<PowerStats> p)58 void addGPUGs202(std::shared_ptr<PowerStats> p) {
59     std::map<std::string, int32_t> stateCoeffs;
60 
61     // Add GPU state residency
62     p->addStateResidencyDataProvider(std::make_unique<DevfreqStateResidencyDataProvider>(
63             "GPU",
64             "/sys/devices/platform/28000000.mali"));
65 
66     // Add GPU energy consumer
67     stateCoeffs = {
68         {"202000",  890},
69         {"251000", 1102},
70         {"302000", 1308},
71         {"351000", 1522},
72         {"400000", 1772},
73         {"434000", 1931},
74         {"471000", 2105},
75         {"510000", 2292},
76         {"572000", 2528},
77         {"633000", 2811},
78         {"701000", 3127},
79         {"762000", 3452},
80         {"848000", 4044}};
81 
82     p->addEnergyConsumer(PowerStatsEnergyConsumer::createMeterAndAttrConsumer(
83             p,
84             EnergyConsumerType::OTHER,
85             "GPU",
86             {"S2S_VDD_G3D", "S8S_VDD_G3D_L2"},
87             {{UID_TIME_IN_STATE, "/sys/devices/platform/28000000.mali/uid_time_in_state"}},
88             stateCoeffs));
89 }
90 
main()91 int main() {
92     LOG(INFO) << "Pixel PowerStats HAL AIDL Service is starting.";
93 
94     // single thread
95     ABinderProcess_setThreadPoolMaxThreadCount(0);
96 
97     std::shared_ptr<PowerStats> p = ndk::SharedRefBase::make<PowerStats>();
98 
99     setEnergyMeter(p);
100     addAoC(p);
101     addCPUclusters(p);
102     addDisplay(p);
103     addSoC(p);
104     addGNSS(p);
105     addMobileRadio(p);
106     addPCIe(p);
107     addWlan(p);
108     addTPU(p);
109     addUfs(p);
110     addNFC(p, "/sys/devices/platform/10970000.hsi2c/i2c-4/i2c-st21nfc/power_stats");
111     addPowerDomains(p);
112     addDevfreq(p);
113     addGPUGs202(p);
114     addDvfsStats(p);
115 
116     const std::string instance = std::string() + PowerStats::descriptor + "/default";
117     binder_status_t status = AServiceManager_addService(p->asBinder().get(), instance.c_str());
118     LOG_ALWAYS_FATAL_IF(status != STATUS_OK);
119 
120     ABinderProcess_joinThreadPool();
121     return EXIT_FAILURE;  // should not reach
122 }
123