diff options
-rw-r--r-- | pixelstats/SysfsCollector.cpp | 123 | ||||
-rw-r--r-- | pixelstats/include/pixelstats/SysfsCollector.h | 5 | ||||
-rw-r--r-- | pixelstats/pixelatoms.proto | 32 |
3 files changed, 159 insertions, 1 deletions
diff --git a/pixelstats/SysfsCollector.cpp b/pixelstats/SysfsCollector.cpp index 69e345b..f9dc7ab 100644 --- a/pixelstats/SysfsCollector.cpp +++ b/pixelstats/SysfsCollector.cpp @@ -32,6 +32,10 @@ #include <cinttypes> #include <string> +#ifndef ARRAY_SIZE +#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) +#endif + namespace android { namespace hardware { namespace google { @@ -49,6 +53,7 @@ using android::hardware::google::pixel::PixelAtoms::F2fsCompressionInfo; using android::hardware::google::pixel::PixelAtoms::F2fsGcSegmentInfo; using android::hardware::google::pixel::PixelAtoms::F2fsSmartIdleMaintEnabledStateChanged; using android::hardware::google::pixel::PixelAtoms::F2fsStatsInfo; +using android::hardware::google::pixel::PixelAtoms::PcieLinkStatsReported; using android::hardware::google::pixel::PixelAtoms::StorageUfsHealth; using android::hardware::google::pixel::PixelAtoms::StorageUfsResetCount; using android::hardware::google::pixel::PixelAtoms::ThermalDfsStats; @@ -95,7 +100,9 @@ SysfsCollector::SysfsCollector(const struct SysfsPaths &sysfs_paths) kCCARatePath(sysfs_paths.CCARatePath), kTempResidencyPath(sysfs_paths.TempResidencyPath), kLongIRQMetricsPath(sysfs_paths.LongIRQMetricsPath), - kResumeLatencyMetricsPath(sysfs_paths.ResumeLatencyMetricsPath) {} + kResumeLatencyMetricsPath(sysfs_paths.ResumeLatencyMetricsPath), + kModemPcieLinkStatsPath(sysfs_paths.ModemPcieLinkStatsPath), + kWifiPcieLinkStatsPath(sysfs_paths.WifiPcieLinkStatsPath) {} bool SysfsCollector::ReadFileToInt(const std::string &path, int *val) { return ReadFileToInt(path.c_str(), val); @@ -1284,6 +1291,119 @@ void SysfsCollector::logVendorLongIRQStatsReported(const std::shared_ptr<IStats> ALOGE("Unable to report kVendorLongIRQStatsReported to Stats service"); } +void SysfsCollector::logPcieLinkStats(const std::shared_ptr<IStats> &stats_client) { + struct sysfs_map { + const char *sysfs_path; + bool is_counter; + int modem_val; + int wifi_val; + int modem_msg_field_number; + int wifi_msg_field_number; + }; + + int i; + bool reportPcieLinkStats = false; + + /* Map sysfs data to PcieLinkStatsReported message elements */ + struct sysfs_map datamap[] = { + {"link_down_irqs", true, 0, 0, + PcieLinkStatsReported::kModemPcieLinkdownsFieldNumber, + PcieLinkStatsReported::kWifiPcieLinkdownsFieldNumber}, + + {"complete_timeout_irqs", true, 0, 0, + PcieLinkStatsReported::kModemPcieCompletionTimeoutsFieldNumber, + PcieLinkStatsReported::kWifiPcieCompletionTimeoutsFieldNumber}, + + {"link_up_failures", true, 0, 0, + PcieLinkStatsReported::kModemPcieLinkupFailuresFieldNumber, + PcieLinkStatsReported::kWifiPcieLinkupFailuresFieldNumber}, + + {"pll_lock_average", false, 0, 0, + PcieLinkStatsReported::kModemPciePllLockAvgFieldNumber, + PcieLinkStatsReported::kWifiPciePllLockAvgFieldNumber}, + + {"link_up_average", false, 0, 0, + PcieLinkStatsReported::kWifiPcieLinkUpAvgFieldNumber, + PcieLinkStatsReported::kWifiPcieLinkUpAvgFieldNumber }, + }; + + + if (kModemPcieLinkStatsPath == nullptr) { + ALOGD("Modem PCIe stats path not specified"); + } else { + for (i=0; i < ARRAY_SIZE(datamap); i++) { + std::string modempath = std::string (kModemPcieLinkStatsPath) + \ + "/" + datamap[i].sysfs_path; + + if (ReadFileToInt(modempath, &(datamap[i].modem_val))) { + reportPcieLinkStats = true; + ALOGD("Modem %s = %d", datamap[i].sysfs_path, + datamap[i].modem_val); + if (datamap[i].is_counter) { + std::string value = std::to_string(datamap[i].modem_val); + /* Writing the value back clears the counter */ + if (!WriteStringToFile(value, modempath)) { + ALOGE("Unable to clear modem PCIe statistics file: %s - %s", + modempath.c_str(), strerror(errno)); + } + } + } + } + } + + if (kWifiPcieLinkStatsPath == nullptr) { + ALOGD("Wifi PCIe stats path not specified"); + } else { + for (i=0; i < ARRAY_SIZE(datamap); i++) { + std::string wifipath = std::string (kWifiPcieLinkStatsPath) + \ + "/" + datamap[i].sysfs_path; + + if (ReadFileToInt(wifipath, &(datamap[i].wifi_val))) { + reportPcieLinkStats = true; + ALOGD("Wifi %s = %d", datamap[i].sysfs_path, + datamap[i].wifi_val); + if (datamap[i].is_counter) { + std::string value = std::to_string(datamap[i].wifi_val); + /* Writing the value back clears the counter */ + if (!WriteStringToFile(value, wifipath)) { + ALOGE("Unable to clear wifi PCIe statistics file: %s - %s", + wifipath.c_str(), strerror(errno)); + } + } + } + } + } + + if (!reportPcieLinkStats) { + ALOGD("No PCIe link stats to report"); + return; + } + + // Load values array + std::vector<VendorAtomValue> values(2 * ARRAY_SIZE(datamap)); + VendorAtomValue tmp; + for (i=0; i < ARRAY_SIZE(datamap); i++) { + if (datamap[i].modem_val > 0) { + tmp.set<VendorAtomValue::intValue>(datamap[i].modem_val); + values[datamap[i].modem_msg_field_number - kVendorAtomOffset] = tmp; + } + if (datamap[i].wifi_val > 0) { + tmp.set<VendorAtomValue::intValue>(datamap[i].wifi_val); + values[datamap[i].wifi_msg_field_number - kVendorAtomOffset] = tmp; + } + } + + // Send vendor atom to IStats HAL + VendorAtom event = {.reverseDomainName = "", + .atomId = PixelAtoms::Atom::kPcieLinkStats, + .values = std::move(values)}; + + const ndk::ScopedAStatus ret = stats_client->reportVendorAtom(event); + if (!ret.isOk()) { + ALOGE("Unable to report PCIe link statistics to stats service"); + } +} + void SysfsCollector::logPerDay() { const std::shared_ptr<IStats> stats_client = getStatsService(); if (!stats_client) { @@ -1318,6 +1438,7 @@ void SysfsCollector::logPerDay() { logTempResidencyStats(stats_client); logVendorLongIRQStatsReported(stats_client); logVendorResumeLatencyStats(stats_client); + logPcieLinkStats(stats_client); } void SysfsCollector::aggregatePer5Min() { diff --git a/pixelstats/include/pixelstats/SysfsCollector.h b/pixelstats/include/pixelstats/SysfsCollector.h index df4a331..80ec1a2 100644 --- a/pixelstats/include/pixelstats/SysfsCollector.h +++ b/pixelstats/include/pixelstats/SysfsCollector.h @@ -69,6 +69,8 @@ class SysfsCollector { const char *const TempResidencyPath; const char *const LongIRQMetricsPath; const char *const ResumeLatencyMetricsPath; + const char *const ModemPcieLinkStatsPath; + const char *const WifiPcieLinkStatsPath; }; SysfsCollector(const struct SysfsPaths &paths); @@ -111,6 +113,7 @@ class SysfsCollector { void logVendorAudioHardwareStats(const std::shared_ptr<IStats> &stats_client); void logVendorLongIRQStatsReported(const std::shared_ptr<IStats> &stats_client); void logVendorResumeLatencyStats(const std::shared_ptr<IStats> &stats_client); + void logPcieLinkStats(const std::shared_ptr<IStats> &stats_client); const char *const kSlowioReadCntPath; const char *const kSlowioWriteCntPath; @@ -142,6 +145,8 @@ class SysfsCollector { const char *const kTempResidencyPath; const char *const kLongIRQMetricsPath; const char *const kResumeLatencyMetricsPath; + const char *const kModemPcieLinkStatsPath; + const char *const kWifiPcieLinkStatsPath; BatteryEEPROMReporter battery_EEPROM_reporter_; MmMetricsReporter mm_metrics_reporter_; diff --git a/pixelstats/pixelatoms.proto b/pixelstats/pixelatoms.proto index 433768a..16db5b4 100644 --- a/pixelstats/pixelatoms.proto +++ b/pixelstats/pixelatoms.proto @@ -87,6 +87,8 @@ message Atom { VendorLongIRQStatsReported vendor_long_irq_stats_reported = 105043; VendorResumeLatencyStats vendor_resume_latency_stats = 105044; VendorTempResidencyStats vendor_temp_residency_stats = 105045; + + PcieLinkStatsReported pcie_link_stats = 105047; } // AOSP atom ID range ends at 109999 } @@ -1411,3 +1413,33 @@ message VendorResumeLatencyStats { optional int64 resume_count_bucket_35 = 38; optional int64 resume_count_bucket_36 = 39; } + +/* + * PCIe Link Statistics + */ +message PcieLinkStatsReported { + /* Vendor reverse domain name (expecting "com.google.pixel"). */ + optional string reverse_domain_name = 1; + + /* Count of new PCIe Link Down events on the modem interface */ + optional int32 modem_pcie_linkdowns = 2; + /* Count of new PCIe Completion Timeout events on the modem interface */ + optional int32 modem_pcie_completion_timeouts = 3; + /* Count of new PCIe Link Up Failure events on the modem interface */ + optional int32 modem_pcie_linkup_failures = 4; + /* Average pll lock time (uS) during PCIe Link Up on modem interface */ + optional int32 modem_pcie_pll_lock_avg = 5; + /* Average time (uS) for successful PCIe Link Up on modem interface */ + optional int32 modem_pcie_link_up_avg = 6; + + /* Count of new PCIe Link Down events on the wifi interface */ + optional int32 wifi_pcie_linkdowns = 7; + /* Count of new PCIe Completion Timeout events on the wifi interface */ + optional int32 wifi_pcie_completion_timeouts = 8; + /* Count of new PCIe Link Up Failure events on the wifi interface */ + optional int32 wifi_pcie_linkup_failures = 9; + /* Average pll lock time (uS) during PCIe Link Up on wifi interface */ + optional int32 wifi_pcie_pll_lock_avg = 10; + /* Average time (uS) for successful PCIe Link Up on wifi interface */ + optional int32 wifi_pcie_link_up_avg = 11; +} |