summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsamou <samou@google.com>2023-12-03 15:07:56 +0000
committersamou <samou@google.com>2023-12-03 15:46:32 +0000
commitdfe6c6ac98499019abb7706ef8729d3acc93ea1a (patch)
tree0b6bafbc4df6caeb68ee539d981546f22d05b3b4
parentdbf49625da7290b6c0d2d4976efa8b6771fbc43f (diff)
downloadpixel-dfe6c6ac98499019abb7706ef8729d3acc93ea1a.tar.gz
bm: Handling sysfs variance at runtime
- Check PlatformSpecific sysfs access. - Identify PMIC ID by comparing the PMIC version. Bug: 313692190 Change-Id: I3e401e48584a7a1c6a622d153be6e1236526eaae Signed-off-by: samou <samou@google.com>
-rw-r--r--battery_mitigation/BatteryMitigationService.cpp78
-rw-r--r--battery_mitigation/include/battery_mitigation/BatteryMitigationService.h5
-rw-r--r--battery_mitigation/include/battery_mitigation/MitigationConfig.h15
3 files changed, 53 insertions, 45 deletions
diff --git a/battery_mitigation/BatteryMitigationService.cpp b/battery_mitigation/BatteryMitigationService.cpp
index b5731452..3357fdfa 100644
--- a/battery_mitigation/BatteryMitigationService.cpp
+++ b/battery_mitigation/BatteryMitigationService.cpp
@@ -43,10 +43,8 @@ const struct BrownoutStatsCSVFields brownoutStatsCSVFields = {
};
BatteryMitigationService::BatteryMitigationService(
- const struct MitigationConfig::EventThreadConfig &eventThreadCfg,
- int platformNum)
- :cfg(eventThreadCfg), platformNum(platformNum) {
- platformIdx = platformNum - MIN_SUPPORTED_PLATFORM;
+ const struct MitigationConfig::EventThreadConfig &eventThreadCfg)
+ :cfg(eventThreadCfg) {
initTotalNumericSysfsPaths();
initPmicRelated();
}
@@ -66,14 +64,6 @@ bool BatteryMitigationService::isBrownoutStatsBinarySupported() {
return false;
}
-bool BatteryMitigationService::isPlatformSupported() {
- if (platformNum >= MIN_SUPPORTED_PLATFORM &&
- platformNum <= MAX_SUPPORTED_PLATFORM) {
- return true;
- }
- return false;
-}
-
bool readSysfsToInt(const std::string &path, int *val) {
std::string file_contents;
@@ -116,32 +106,43 @@ int getFilesInDir(const char *directory, std::vector<std::string> *files) {
return 0;
}
-void addNumericSysfsStatPathinDirs(
- std::vector<MitigationConfig::numericSysfs> numericSysfsStatDirs,
+void addNumericSysfsStatPathinDir(
+ std::string numericSysfsStatDir,
std::vector<MitigationConfig::numericSysfs> totalNumericSysfsStatPaths) {
std::vector<std::string> files;
- for (const auto &sysfsStat : numericSysfsStatDirs) {
- if (getFilesInDir(sysfsStat.path.c_str(), &files) < 0) {
- continue;
- }
- for (auto &file : files) {
- std::string fullPath = sysfsStat.path + file;
- totalNumericSysfsStatPaths.push_back({file, fullPath});
- }
+ if (getFilesInDir(numericSysfsStatDir.c_str(), &files) < 0) {
+ return;
+ }
+ for (auto &file : files) {
+ std::string fullPath = numericSysfsStatDir + file;
+ totalNumericSysfsStatPaths.push_back({file, fullPath});
}
}
void BatteryMitigationService::initTotalNumericSysfsPaths() {
totalNumericSysfsStatPaths.assign(cfg.NumericSysfsStatPaths.begin(),
cfg.NumericSysfsStatPaths.end());
- addNumericSysfsStatPathinDirs(cfg.NumericSysfsStatDirs, totalNumericSysfsStatPaths);
-
- /* add NumericSysfsStatPaths from PlatformSpecific */
- totalNumericSysfsStatPaths.insert(totalNumericSysfsStatPaths.end(),
- cfg.PlatformSpecific[platformIdx].NumericSysfsStatPaths.begin(),
- cfg.PlatformSpecific[platformIdx].NumericSysfsStatPaths.end());
- addNumericSysfsStatPathinDirs(cfg.PlatformSpecific[platformIdx].NumericSysfsStatDirs,
- totalNumericSysfsStatPaths);
+ for (const auto &sysfsStat : cfg.NumericSysfsStatDirs) {
+ addNumericSysfsStatPathinDir(sysfsStat.path.c_str(), totalNumericSysfsStatPaths);
+ }
+
+ /* Append first available path in PlatformSpecific */
+ for (const auto &sysfsStatList : cfg.PlatformSpecific.NumericSysfsStatPaths) {
+ for (const auto &sysfsStatPath : sysfsStatList.paths) {
+ if (access(sysfsStatPath.c_str(), F_OK) == 0) {
+ totalNumericSysfsStatPaths.push_back({sysfsStatList.name, sysfsStatPath});
+ break;
+ }
+ }
+ }
+ for (const auto &sysfsStatList : cfg.PlatformSpecific.NumericSysfsStatDirs) {
+ for (const auto &sysfsStatPath : sysfsStatList.paths) {
+ if (access(sysfsStatPath.c_str(), F_OK) == 0) {
+ addNumericSysfsStatPathinDir(sysfsStatPath, totalNumericSysfsStatPaths);
+ break;
+ }
+ }
+ }
}
int BatteryMitigationService::readNumericStats(struct BrownoutStatsExtend *brownoutStatsExtend) {
@@ -168,7 +169,7 @@ int BatteryMitigationService::readNumericStats(struct BrownoutStatsExtend *brown
void BatteryMitigationService::startBrownoutEventThread() {
- if (isPlatformSupported() && isBrownoutStatsBinarySupported()) {
+ if (isBrownoutStatsBinarySupported()) {
brownoutEventThread = std::thread(&BatteryMitigationService::BrownoutEventThread, this);
eventThread = std::thread(&BatteryMitigationService::TriggerEventThread, this);
}
@@ -492,16 +493,25 @@ void readLPFChannelNames(const char *odpmEnabledRailsPath, char **lpfChannelName
free(line);
}
-int getMainPmicID(const std::string &mainPmicNamePath, const std::string &mainPmicName) {
+int getMainPmicID(const std::string &mainPmicNamePath, const std::string &subPmicNamePath) {
std::string content;
int ret = 0;
+ int mainPmicVer, subPmicVer;
if (!ReadFileToString(mainPmicNamePath, &content)) {
LOG(DEBUG) << "Failed to open " << mainPmicNamePath << " set device0 as main pmic";
return ret;
}
+ /* ODPM pmic name: s2mpgXX-odpm */
+ mainPmicVer = atoi(content.substr(5, 2).c_str());
+
+ if (!ReadFileToString(subPmicNamePath, &content)) {
+ LOG(DEBUG) << "Failed to open " << subPmicNamePath << " set device0 as main pmic";
+ return ret;
+ }
+ subPmicVer = atoi(content.substr(5, 2).c_str());
- if (content.compare(mainPmicName) != 0) {
+ if (mainPmicVer > subPmicVer) {
ret = 1;
}
@@ -529,7 +539,7 @@ void BatteryMitigationService::tearDownBrownoutEventThread() {
void BatteryMitigationService::initPmicRelated() {
mainPmicID = 0;
mainPmicID = getMainPmicID(cfg.PmicCommon[mainPmicID].PmicNamePath,
- cfg.PlatformSpecific[platformIdx].MainPmicName);
+ cfg.PmicCommon[subPmicID].PmicNamePath);
subPmicID = !mainPmicID;
/* read odpm resolutions and channel names */
diff --git a/battery_mitigation/include/battery_mitigation/BatteryMitigationService.h b/battery_mitigation/include/battery_mitigation/BatteryMitigationService.h
index 7eaf3c68..9c697140 100644
--- a/battery_mitigation/include/battery_mitigation/BatteryMitigationService.h
+++ b/battery_mitigation/include/battery_mitigation/BatteryMitigationService.h
@@ -117,8 +117,7 @@ struct BrownoutStatsExtend {
class BatteryMitigationService : public RefBase {
public:
- BatteryMitigationService(const struct MitigationConfig::EventThreadConfig &eventThreadCfg,
- int platformNum);
+ BatteryMitigationService(const struct MitigationConfig::EventThreadConfig &eventThreadCfg);
~BatteryMitigationService();
void startBrownoutEventThread();
@@ -131,8 +130,6 @@ class BatteryMitigationService : public RefBase {
bool genLastmealCSV(const char*);
private:
struct MitigationConfig::EventThreadConfig cfg;
- int platformNum;
- int platformIdx;
int storingFd;
int triggeredStateFd[MAX_EVENT];
diff --git a/battery_mitigation/include/battery_mitigation/MitigationConfig.h b/battery_mitigation/include/battery_mitigation/MitigationConfig.h
index 3fea3233..2062d29d 100644
--- a/battery_mitigation/include/battery_mitigation/MitigationConfig.h
+++ b/battery_mitigation/include/battery_mitigation/MitigationConfig.h
@@ -48,13 +48,14 @@ class MitigationConfig {
std::string path;
};
+ struct numericSysfsList {
+ std::string name;
+ std::vector<std::string> paths;
+ };
+
struct platformSpecific {
- std::string MainPmicName;
- std::string SubPmicName;
- std::string PcieModemPath;
- std::string PcieWifiPath;
- const std::vector<numericSysfs> NumericSysfsStatPaths;
- const std::vector<numericSysfs> NumericSysfsStatDirs;
+ const std::vector<numericSysfsList> NumericSysfsStatPaths;
+ const std::vector<numericSysfsList> NumericSysfsStatDirs;
};
struct pmicCommon {
@@ -75,7 +76,7 @@ class MitigationConfig {
const char *const ParsedLastmealCSVPath;
const char *const FvpStatsPath;
const std::vector<pmicCommon> PmicCommon;
- const std::vector<platformSpecific> PlatformSpecific;
+ const platformSpecific PlatformSpecific;
};
MitigationConfig(const struct Config &cfg);