From 194edaf7db0acf5b2c605e1ffb5b944552ba3911 Mon Sep 17 00:00:00 2001 From: Benjamin Schwartz Date: Wed, 24 Feb 2021 17:23:09 -0800 Subject: [PATCH] powerstats: Add NFC, PCIE, WIFI stats Bug: 179277258 Test: adb shell dumpsys android.hardware.power.stats.IPowerStats/default Change-Id: I64d84f82eafe34c12caeaa73f24ed79a60db3604 --- powerstats/serviceaidl.cpp | 112 ++++++++++++++++++++++++++++++++++++- 1 file changed, 110 insertions(+), 2 deletions(-) diff --git a/powerstats/serviceaidl.cpp b/powerstats/serviceaidl.cpp index 3a26065c..8c15775c 100644 --- a/powerstats/serviceaidl.cpp +++ b/powerstats/serviceaidl.cpp @@ -285,8 +285,7 @@ void addDisplay(std::shared_ptr p) { p->addEnergyConsumer(displayConsumer); } -void addCPUclusters(std::shared_ptr p) -{ +void addCPUclusters(std::shared_ptr p) { p->addEnergyConsumer(PowerStatsEnergyConsumer::createMeterConsumer(p, EnergyConsumerType::CPU_CLUSTER, "CPUCL0", {"S4M_VDD_CPUCL0"})); p->addEnergyConsumer(PowerStatsEnergyConsumer::createMeterConsumer(p, @@ -370,6 +369,112 @@ void addGNSS(std::shared_ptr p) p->addEnergyConsumer(PowerStatsEnergyConsumer::createMeterConsumer(p, EnergyConsumerType::GNSS, "GPS", {"L9S_GNSS_CORE"})); } + +void addNFC(std::shared_ptr p) { + const GenericStateResidencyDataProvider::StateResidencyConfig nfcStateConfig = { + .entryCountSupported = true, + .entryCountPrefix = "Cumulative count:", + .totalTimeSupported = true, + .totalTimePrefix = "Cumulative duration msec:", + .lastEntrySupported = true, + .lastEntryPrefix = "Last entry timestamp msec:", + }; + const std::vector> nfcStateHeaders = { + std::make_pair("IDLE", "Idle mode:"), + std::make_pair("ACTIVE", "Active mode:"), + std::make_pair("ACTIVE-RW", "Active Reader/Writer mode:"), + }; + + std::vector cfgs; + cfgs.emplace_back(generateGenericStateResidencyConfigs(nfcStateConfig, nfcStateHeaders), + "NFC", "NFC subsystem"); + + auto nfcSdp = std::make_shared( + "/sys/devices/platform/10960000.hsi2c/i2c-3/3-0008/power_stats", cfgs); + + p->addStateResidencyDataProvider(nfcSdp); +} + +void addPCIe(std::shared_ptr p) { + // Add PCIe power entities for Modem and WiFi + const GenericStateResidencyDataProvider::StateResidencyConfig pcieStateConfig = { + .entryCountSupported = true, + .entryCountPrefix = "Cumulative count:", + .totalTimeSupported = true, + .totalTimePrefix = "Cumulative duration msec:", + .lastEntrySupported = true, + .lastEntryPrefix = "Last entry timestamp msec:", + }; + const std::vector> pcieStateHeaders = { + std::make_pair("UP", "Link up:"), + std::make_pair("DOWN", "Link down:"), + }; + + // Add PCIe - Modem + const std::vector pcieModemCfgs = { + {generateGenericStateResidencyConfigs(pcieStateConfig, pcieStateHeaders), "PCIe-Modem", + "Version: 1"} + }; + auto pcieModemSdp = std::make_shared( + "/sys/devices/platform/11920000.pcie/power_stats", pcieModemCfgs); + p->addStateResidencyDataProvider(pcieModemSdp); + + // Add PCIe - WiFi + const std::vector pcieWifiCfgs = { + {generateGenericStateResidencyConfigs(pcieStateConfig, pcieStateHeaders), + "PCIe-WiFi", "Version: 1"} + }; + auto pcieWifiSdp = std::make_shared( + "/sys/devices/platform/14520000.pcie/power_stats", pcieWifiCfgs); + p->addStateResidencyDataProvider(pcieWifiSdp); +} + +void addWifi(std::shared_ptr p) { + // The transform function converts microseconds to milliseconds. + std::function usecToMs = [](uint64_t a) { return a / 1000; }; + const GenericStateResidencyDataProvider::StateResidencyConfig stateConfig = { + .entryCountSupported = true, + .entryCountPrefix = "count:", + .totalTimeSupported = true, + .totalTimePrefix = "duration_usec:", + .totalTimeTransform = usecToMs, + .lastEntrySupported = true, + .lastEntryPrefix = "last_entry_timestamp_usec:", + .lastEntryTransform = usecToMs, + }; + const GenericStateResidencyDataProvider::StateResidencyConfig pcieStateConfig = { + .entryCountSupported = true, + .entryCountPrefix = "count:", + .totalTimeSupported = true, + .totalTimePrefix = "duration_usec:", + .totalTimeTransform = usecToMs, + .lastEntrySupported = false, + }; + + const std::vector> stateHeaders = { + std::make_pair("AWAKE", "AWAKE:"), + std::make_pair("ASLEEP", "ASLEEP:"), + + }; + const std::vector> pcieStateHeaders = { + std::make_pair("L0", "L0:"), + std::make_pair("L1", "L1:"), + std::make_pair("L1_1", "L1_1:"), + std::make_pair("L1_2", "L1_2:"), + std::make_pair("L2", "L2:"), + }; + + const std::vector cfgs = { + {generateGenericStateResidencyConfigs(stateConfig, stateHeaders), "WIFI", "WIFI"}, + {generateGenericStateResidencyConfigs(pcieStateConfig, pcieStateHeaders), "WIFI-PCIE", + "WIFI-PCIE"} + }; + + auto wifiSdp = std::make_shared("/sys/wifi/power_stats", + cfgs); + p->addStateResidencyDataProvider(wifiSdp); +} + /** * Unlike other data providers, which source power entity state residency data from the kernel, * this data provider acts as a general-purpose channel for state residency data providers @@ -405,6 +510,9 @@ int main() { addGPU(p); addMobileRadio(p); addGNSS(p); + addNFC(p); + addPCIe(p); + addWifi(p); const std::string instance = std::string() + PowerStats::descriptor + "/default"; binder_status_t status = AServiceManager_addService(p->asBinder().get(), instance.c_str());