service.cpp 5.2 KB

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