service.cpp 4.0 KB

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