service.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. struct stat buffer;
  35. if (!stat("/sys/class/drm/card0/device/primary-panel/time_in_state", &buffer)) {
  36. // time_in_state exists
  37. addDisplayMrr(p);
  38. } else {
  39. // time_in_state doesn't exist
  40. std::vector<std::string> states = {
  41. "Off",
  42. "LP: 1080x2400@30",
  43. "On: 1080x2400@60",
  44. "On: 1080x2400@90",
  45. "HBM: 1080x2400@60",
  46. "HBM: 1080x2400@90"};
  47. p->addStateResidencyDataProvider(std::make_unique<DisplayStateResidencyDataProvider>("Display",
  48. "/sys/class/backlight/panel0-backlight/state",
  49. states));
  50. }
  51. // Add display energy consumer
  52. p->addEnergyConsumer(PowerStatsEnergyConsumer::createMeterAndEntityConsumer(p,
  53. EnergyConsumerType::DISPLAY, "display", {"VSYS_PWR_DISPLAY"}, "Display",
  54. {{"LP: 1080x2400@30", 1},
  55. {"On: 1080x2400@60", 2},
  56. {"On: 1080x2400@90", 3}}));
  57. }
  58. void addGPUGs202(std::shared_ptr<PowerStats> p) {
  59. std::map<std::string, int32_t> stateCoeffs;
  60. // Add GPU state residency
  61. p->addStateResidencyDataProvider(std::make_unique<DevfreqStateResidencyDataProvider>(
  62. "GPU",
  63. "/sys/devices/platform/28000000.mali"));
  64. // Add GPU energy consumer
  65. stateCoeffs = {
  66. {"202000", 890},
  67. {"251000", 1102},
  68. {"302000", 1308},
  69. {"351000", 1522},
  70. {"400000", 1772},
  71. {"434000", 1931},
  72. {"471000", 2105},
  73. {"510000", 2292},
  74. {"572000", 2528},
  75. {"633000", 2811},
  76. {"701000", 3127},
  77. {"762000", 3452},
  78. {"848000", 4044}};
  79. p->addEnergyConsumer(PowerStatsEnergyConsumer::createMeterAndAttrConsumer(
  80. p,
  81. EnergyConsumerType::OTHER,
  82. "GPU",
  83. {"S2S_VDD_G3D", "S8S_VDD_G3D_L2"},
  84. {{UID_TIME_IN_STATE, "/sys/devices/platform/28000000.mali/uid_time_in_state"}},
  85. stateCoeffs));
  86. }
  87. int main() {
  88. struct stat buffer;
  89. LOG(INFO) << "Pixel PowerStats HAL AIDL Service is starting.";
  90. // single thread
  91. ABinderProcess_setThreadPoolMaxThreadCount(0);
  92. std::shared_ptr<PowerStats> p = ndk::SharedRefBase::make<PowerStats>();
  93. setEnergyMeter(p);
  94. addAoC(p);
  95. addCPUclusters(p);
  96. addDisplay(p);
  97. addSoC(p);
  98. addGNSS(p);
  99. addMobileRadio(p);
  100. addPCIe(p);
  101. addWlan(p);
  102. addTPU(p);
  103. addUfs(p);
  104. if (!stat("/sys/devices/platform/10970000.hsi2c/i2c-8/8-0008/power_stats", &buffer)) {
  105. addNFC(p, "/sys/devices/platform/10970000.hsi2c/i2c-8/8-0008/power_stats");
  106. }
  107. addPowerDomains(p);
  108. addDevfreq(p);
  109. addGPUGs202(p);
  110. addDvfsStats(p);
  111. const std::string instance = std::string() + PowerStats::descriptor + "/default";
  112. binder_status_t status = AServiceManager_addService(p->asBinder().get(), instance.c_str());
  113. LOG_ALWAYS_FATAL_IF(status != STATUS_OK);
  114. ABinderProcess_joinThreadPool();
  115. return EXIT_FAILURE; // should not reach
  116. }