From d661367aeb7cdf870d044df47d315f85f0cc6a14 Mon Sep 17 00:00:00 2001 From: Darren Hsu Date: Wed, 6 Sep 2023 17:44:32 +0800 Subject: [PATCH] powerstats: introduce GPS state residency External GNSS power stats are controlled by GPS chip side. The power stats would not update while GPS chip is down. This means that GPS OFF state residency won't reflect the elapsed off time. So only GPS ON state residency is present. Bug: 289764363 Test: dumpsys android.hardware.power.stats.IPowerStats/default Change-Id: Ic51ebef14ca131914a6a5b4ea681c739e9920d63 Signed-off-by: Darren Hsu --- powerstats/akita/service.cpp | 40 +++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/powerstats/akita/service.cpp b/powerstats/akita/service.cpp index 673167e..743a84b 100644 --- a/powerstats/akita/service.cpp +++ b/powerstats/akita/service.cpp @@ -17,6 +17,7 @@ #define LOG_TAG "android.hardware.power.stats-service.pixel" #include +#include #include #include #include @@ -29,6 +30,7 @@ using aidl::android::hardware::power::stats::DisplayStateResidencyDataProvider; using aidl::android::hardware::power::stats::EnergyConsumerType; +using aidl::android::hardware::power::stats::GenericStateResidencyDataProvider; using aidl::android::hardware::power::stats::PowerStatsEnergyConsumer; void addDisplay(std::shared_ptr p) { @@ -56,6 +58,42 @@ void addDisplay(std::shared_ptr p) { {"HBM: 1080x2400@120", 5}})); } +void addGPS(std::shared_ptr p) +{ + // A constant to represent the number of microseconds in one millisecond. + const int US_TO_MS = 1000; + + // gnss power_stats are reported in microseconds. The transform function + // converts microseconds to milliseconds. + std::function gnssUsToMs = [](uint64_t a) { return a / US_TO_MS; }; + + const GenericStateResidencyDataProvider::StateResidencyConfig gnssStateConfig = { + .entryCountSupported = true, + .entryCountPrefix = "count:", + .totalTimeSupported = true, + .totalTimePrefix = "duration_usec:", + .totalTimeTransform = gnssUsToMs, + .lastEntrySupported = true, + .lastEntryPrefix = "last_entry_timestamp_usec:", + .lastEntryTransform = gnssUsToMs, + }; + + // External GNSS power stats are controlled by GPS chip side. The power stats + // would not update while GPS chip is down. This means that GPS OFF state + // residency won't reflect the elapsed off time. So only GPS ON state + // residency is present. + const std::vector> gnssStateHeaders = { + std::make_pair("ON", "GPS_ON:"), + }; + + std::vector cfgs; + cfgs.emplace_back(generateGenericStateResidencyConfigs(gnssStateConfig, gnssStateHeaders), + "GPS", ""); + + p->addStateResidencyDataProvider(std::make_unique( + "/data/vendor/gps/power_stats", cfgs)); +} + int main() { LOG(INFO) << "Pixel PowerStats HAL AIDL Service is starting."; @@ -69,7 +107,7 @@ int main() { addPixelStateResidencyDataProvider(p); addCPUclusters(p); addSoC(p); - // TODO(b/289764363): add GNSS power stats back when the sysfs is ready + addGPS(p); addMobileRadio(p); addNFC(p); addPCIe(p);