summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Lee <geolee@google.com>2023-11-22 01:48:50 +0000
committersamou <samou@google.com>2023-11-22 06:42:18 +0000
commitb54eb838051ecb7e6abca8c6e43d5597ee1770c4 (patch)
tree8831fc33036200278fdb5d6a84b179e433228a28
parent60889ed67732375bccb53b12f68d15aae9b71d93 (diff)
downloadpixel-b54eb838051ecb7e6abca8c6e43d5597ee1770c4.tar.gz
bm: Add Battery SOC and enhance data writing speed
- Add Battery SOC to lastmeal generation. - Enhance brownout stats writing speed. - Remove floating point in lastmeal.csv. Bug: 299700579 Test: - Confirm lastmeal contains battery soc. - Confirm that lastmeal.txt have 3~5 dumps after a brownout. Change-Id: I0feda6755470d34e74143fd4d5af30327cdf6219 Signed-off-by: George Lee <geolee@google.com>
-rw-r--r--battery_mitigation/BatteryMitigationService.cpp149
-rw-r--r--battery_mitigation/include/battery_mitigation/BatteryMitigationService.h7
-rw-r--r--battery_mitigation/include/battery_mitigation/MitigationConfig.h2
3 files changed, 72 insertions, 86 deletions
diff --git a/battery_mitigation/BatteryMitigationService.cpp b/battery_mitigation/BatteryMitigationService.cpp
index db749763..a3c3c527 100644
--- a/battery_mitigation/BatteryMitigationService.cpp
+++ b/battery_mitigation/BatteryMitigationService.cpp
@@ -23,30 +23,32 @@ namespace pixel {
using android::base::ReadFileToString;
using android::base::StartsWith;
+using android::hardware::google::pixel::MitigationConfig;
const struct BrownoutStatsCSVFields brownoutStatsCSVFields = {
- .triggered_time = "triggered_timestamp",
- .triggered_idx = "triggered_irq",
- .battery_temp = "battery_temp",
- .battery_cycle = "battery_cycle",
- .voltage_now = "voltage_now",
- .current_now = "current_now",
- .cpu0_freq = "dvfs_channel1",
- .cpu1_freq = "dvfs_channel2",
- .cpu2_freq = "dvfs_channel3",
- .gpu_freq = "dvfs_channel4",
- .tpu_freq = "dvfs_channel5",
- .aur_freq = "dvfs_channel6",
- .odpm_prefix = "odpm_channel_",
+ .triggered_time = "triggered_timestamp",
+ .triggered_idx = "triggered_irq",
+ .battery_soc = "battery_soc",
+ .battery_temp = "battery_temp",
+ .battery_cycle = "battery_cycle",
+ .voltage_now = "voltage_now",
+ .current_now = "current_now",
+ .cpu0_freq = "dvfs_channel1",
+ .cpu1_freq = "dvfs_channel2",
+ .cpu2_freq = "dvfs_channel3",
+ .gpu_freq = "dvfs_channel4",
+ .tpu_freq = "dvfs_channel5",
+ .aur_freq = "dvfs_channel6",
+ .odpm_prefix = "odpm_channel_",
};
BatteryMitigationService::BatteryMitigationService(
const struct MitigationConfig::EventThreadConfig &eventThreadCfg,
int platformNum)
:cfg(eventThreadCfg), platformNum(platformNum) {
+ platformIdx = platformNum - MIN_SUPPORTED_PLATFORM;
initTotalNumericSysfsPaths();
initPmicRelated();
- platformIdx = platformNum - MIN_SUPPORTED_PLATFORM;
}
BatteryMitigationService::~BatteryMitigationService() {
@@ -114,13 +116,11 @@ int getFilesInDir(const char *directory, std::vector<std::string> *files) {
return 0;
}
-void BatteryMitigationService::initTotalNumericSysfsPaths() {
+void addNumericSysfsStatPathinDirs(
+ std::vector<MitigationConfig::numericSysfs> numericSysfsStatDirs,
+ std::vector<MitigationConfig::numericSysfs> totalNumericSysfsStatPaths) {
std::vector<std::string> files;
-
- totalNumericSysfsStatPaths.assign(cfg.NumericSysfsStatPaths.begin(),
- cfg.NumericSysfsStatPaths.end());
-
- for (const auto &sysfsStat : cfg.NumericSysfsStatDirs) {
+ for (const auto &sysfsStat : numericSysfsStatDirs) {
if (getFilesInDir(sysfsStat.path.c_str(), &files) < 0) {
continue;
}
@@ -131,6 +131,19 @@ void BatteryMitigationService::initTotalNumericSysfsPaths() {
}
}
+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);
+}
+
int BatteryMitigationService::readNumericStats(struct BrownoutStatsExtend *brownoutStatsExtend) {
int i = 0;
@@ -195,21 +208,6 @@ int getMmapAddr(int &fd, const char *const path, size_t memSize, char **addr) {
return 0;
}
-int BatteryMitigationService::initThisMeal() {
- int ret;
- size_t memSize = sizeof(struct BrownoutStatsExtend) * DUMP_TIMES * \
- BROWNOUT_EVENT_BUF_SIZE;
-
- ret = getMmapAddr(storingFd, cfg.StoringPath, memSize, &storingAddr);
- if (ret != 0) {
- LOG(DEBUG) << "can't generate " << cfg.StoringPath;
- return ret;
- }
- memset(storingAddr, 0, memSize);
-
- return 0;
-}
-
int BatteryMitigationService::initTrigFd() {
int ret;
struct epoll_event trigEvent[MAX_EVENT];
@@ -330,6 +328,11 @@ int BatteryMitigationService::initFd() {
return brownoutStatsFd;
}
+ storingFd = open(cfg.StoringPath, O_RDWR | O_CREAT | O_TRUNC, (mode_t) 0644);
+ if (storingFd < 0) {
+ return storingFd;
+ }
+
triggeredIdxFd = open(cfg.TriggeredIdxPath, O_RDONLY);
if (triggeredIdxFd < 0) {
return triggeredIdxFd;
@@ -371,32 +374,25 @@ void BatteryMitigationService::BrownoutEventThread() {
struct timeval eventReceivedTime;
struct timeval statStoredTime;
struct epoll_event events[EPOLL_MAXEVENTS];
- struct BrownoutStatsExtend *brownoutStatsExtendHead;
+ struct BrownoutStatsExtend brownoutStatsExtend;
size_t brownoutStatsSize = sizeof(struct brownout_stats);
+ size_t brownoutStatsExtendSize = sizeof(struct BrownoutStatsExtend);
bool stopByEvent = false;
/* BrownoutEventThread store multiple brownout event (BROWNOUT_EVENT_BUF_SIZE)
* and each event contains several dumps (DUMP_TIMES).
*/
int brownoutEventCounter = 0;
- if (initThisMeal() != 0) {
- LOG(DEBUG) << "failed to init thismeal.bin";
- tearDownBrownoutEventThread();
- return;
- }
if (initFd() != 0) {
LOG(DEBUG) << "failed to init FD";
tearDownBrownoutEventThread();
return;
}
- brownoutStatsExtendHead = (struct BrownoutStatsExtend *)storingAddr;
/* allow epoll_wait sleep in the first loop */
read(triggeredIdxFd, buf, BUF_SIZE);
while (!threadStop.load()) {
- struct BrownoutStatsExtend *brownoutStatsExtendEventHead = brownoutStatsExtendHead + \
- (brownoutEventCounter * DUMP_TIMES);
requestedFd = epoll_wait(triggeredIdxEpollFd, events, EPOLL_MAXEVENTS, -1);
if (requestedFd <= 0) {
/* ensure epoll_wait can sleep in the next loop */
@@ -418,7 +414,6 @@ void BatteryMitigationService::BrownoutEventThread() {
/* record brownout event idx and received time */
gettimeofday(&eventReceivedTime, NULL);
- brownoutStatsExtendEventHead->eventReceivedTime = eventReceivedTime;
lseek(triggeredIdxFd, 0, SEEK_SET);
if (read(triggeredIdxFd, buf, BUF_SIZE) == -1) {
continue;
@@ -427,31 +422,32 @@ void BatteryMitigationService::BrownoutEventThread() {
if (triggeredIdx >= TRIGGERED_SOURCE_MAX || triggeredIdx < 0) {
continue;
}
- brownoutStatsExtendEventHead->eventIdx = triggeredIdx;
/* dump brownout related stats */
std::string stats;
for (int i = 0; i < DUMP_TIMES; i++) {
- struct BrownoutStatsExtend *brownoutStatsExtend = brownoutStatsExtendEventHead + i;
-
- /* kernel needs time to prepare brownoutstats for userland to do mmap */
- std::this_thread::sleep_for(std::chrono::milliseconds(STATS_PREPARATION_MS));
+ memset(&brownoutStatsExtend, 0 , brownoutStatsExtendSize);
/* storing by string due the stats msg too complicate */
if (ReadFileToString(cfg.FvpStatsPath, &stats)) {
- snprintf(brownoutStatsExtend->fvpStats, FVP_STATS_SIZE, "%s", stats.c_str());
+ snprintf(brownoutStatsExtend.fvpStats, FVP_STATS_SIZE, "%s", stats.c_str());
}
/* storing numericStats */
- readNumericStats(brownoutStatsExtend);
+ readNumericStats(&brownoutStatsExtend);
/* storing brownoutStats */
lseek(brownoutStatsFd, 0, SEEK_SET);
- read(brownoutStatsFd, &brownoutStatsExtend->brownoutStats, brownoutStatsSize);
+ read(brownoutStatsFd, &brownoutStatsExtend.brownoutStats, brownoutStatsSize);
gettimeofday(&statStoredTime, NULL);
- brownoutStatsExtend->dumpTime = statStoredTime;
- brownoutStatsExtend->eventReceivedTime = eventReceivedTime;
- brownoutStatsExtend->eventIdx = triggeredIdx;
+ brownoutStatsExtend.dumpTime = statStoredTime;
+ brownoutStatsExtend.eventReceivedTime = eventReceivedTime;
+ brownoutStatsExtend.eventIdx = triggeredIdx;
+
+ /* write to file */
+ lseek(storingFd,
+ brownoutStatsExtendSize * (brownoutEventCounter * DUMP_TIMES + i), SEEK_SET);
+ write(storingFd, &brownoutStatsExtend, brownoutStatsExtendSize);
fsync(storingFd);
}
@@ -524,10 +520,6 @@ void BatteryMitigationService::tearDownBrownoutEventThread() {
close(triggeredIdxEpollFd);
close(wakeupEventFd);
close(storingFd);
- if (storingAddr != nullptr) {
- munmap(storingAddr, sizeof(struct BrownoutStatsExtend) * DUMP_TIMES * \
- BROWNOUT_EVENT_BUF_SIZE);
- }
threadStop.store(true);
freeLpfChannelNames(mainLpfChannelNames);
freeLpfChannelNames(subLpfChannelNames);
@@ -877,6 +869,7 @@ void setMinNumericStat(const char *statName, int *minValue,
void initBrownoutStatsCSVRow(struct BrownoutStatsCSVRow *row) {
memset(row, 0, sizeof(struct BrownoutStatsCSVRow));
+ row->min_battery_soc = INT_MAX;
row->min_battery_cycle = INT_MAX;
row->min_voltage_now = INT_MAX;
row->min_cpu0_freq = INT_MAX;
@@ -895,14 +888,7 @@ bool readBrownoutStatsExtend(const char *storingPath,
return false;
}
- size_t memSize = sizeof(struct BrownoutStatsExtend) * DUMP_TIMES * BROWNOUT_EVENT_BUF_SIZE;
size_t logFileSize = lseek(fd, 0, SEEK_END);
- if (memSize != logFileSize) {
- LOG(DEBUG) << storingPath << " size not match";
- close(fd);
- return false;
- }
-
char *logFileAddr = (char *) mmap(NULL, logFileSize, PROT_READ, MAP_PRIVATE, fd, 0);
close(fd);
@@ -942,6 +928,10 @@ void BatteryMitigationService::getBrownoutStatsCSVRow(
}
}
}
+ /* min_battery_soc */
+ setMinNumericStat("battery_soc",
+ &row->min_battery_soc,
+ brownoutStatsExtendPerEvent[i].numericStats);
/* max_battery_temp */
setMaxNumericStat("battery_temp",
&row->max_battery_temp,
@@ -1016,19 +1006,13 @@ bool BatteryMitigationService::genLastmealCSV(const char *parsedMealCSVPath) {
return false;
/* print csv fields */
- fprintf(fp, "%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,",
- brownoutStatsCSVFields.triggered_time,
- brownoutStatsCSVFields.triggered_idx,
- brownoutStatsCSVFields.battery_temp,
- brownoutStatsCSVFields.battery_cycle,
- brownoutStatsCSVFields.voltage_now,
- brownoutStatsCSVFields.current_now,
- brownoutStatsCSVFields.cpu0_freq,
- brownoutStatsCSVFields.cpu1_freq,
- brownoutStatsCSVFields.cpu2_freq,
- brownoutStatsCSVFields.gpu_freq,
- brownoutStatsCSVFields.tpu_freq,
- brownoutStatsCSVFields.aur_freq);
+ fprintf(fp, "%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,", brownoutStatsCSVFields.triggered_time,
+ brownoutStatsCSVFields.triggered_idx, brownoutStatsCSVFields.battery_soc,
+ brownoutStatsCSVFields.battery_temp, brownoutStatsCSVFields.battery_cycle,
+ brownoutStatsCSVFields.voltage_now, brownoutStatsCSVFields.current_now,
+ brownoutStatsCSVFields.cpu0_freq, brownoutStatsCSVFields.cpu1_freq,
+ brownoutStatsCSVFields.cpu2_freq, brownoutStatsCSVFields.gpu_freq,
+ brownoutStatsCSVFields.tpu_freq, brownoutStatsCSVFields.aur_freq);
for (int c = 1; c <= METER_CHANNEL_MAX; c++) {
fprintf(fp, "%s%02d,", brownoutStatsCSVFields.odpm_prefix, c);
}
@@ -1042,6 +1026,7 @@ bool BatteryMitigationService::genLastmealCSV(const char *parsedMealCSVPath) {
printUTC(fp, row->triggered_time, "");
fprintf(fp, ",");
fprintf(fp, "%d,", row->triggered_idx);
+ fprintf(fp, "%d,", row->min_battery_soc);
fprintf(fp, "%d,", row->max_battery_temp);
fprintf(fp, "%d,", row->min_battery_cycle);
fprintf(fp, "%d,", row->min_voltage_now);
@@ -1053,10 +1038,10 @@ bool BatteryMitigationService::genLastmealCSV(const char *parsedMealCSVPath) {
fprintf(fp, "%d,", row->min_tpu_freq);
fprintf(fp, "%d,", row->min_aur_freq);
for (int c = 0; c < METER_CHANNEL_MAX; c++) {
- fprintf(fp, "%.2f,", row->max_main_odpm_instant_power[c]);
+ fprintf(fp, "%d,", int(row->max_main_odpm_instant_power[c]));
}
for (int c = 0; c < METER_CHANNEL_MAX; c++) {
- fprintf(fp, "%.2f,", row->max_sub_odpm_instant_power[c]);
+ fprintf(fp, "%d,", int(row->max_sub_odpm_instant_power[c]));
}
fprintf(fp, "\n");
}
diff --git a/battery_mitigation/include/battery_mitigation/BatteryMitigationService.h b/battery_mitigation/include/battery_mitigation/BatteryMitigationService.h
index 153bbe8b..7eaf3c68 100644
--- a/battery_mitigation/include/battery_mitigation/BatteryMitigationService.h
+++ b/battery_mitigation/include/battery_mitigation/BatteryMitigationService.h
@@ -49,8 +49,7 @@
#define FVP_STATS_SIZE 4096
#define STAT_NAME_SIZE 48
#define STATS_MAX_SIZE 64
-#define PMIC_NUM 2
-#define STATS_PREPARATION_MS 3
+#define PMIC_NUM 2
#define LOOP_TRIG_STATS(idx) for (int idx = 0; idx < MAX_EVENT; idx++)
namespace android {
@@ -74,6 +73,7 @@ struct OdpmInstantPower {
struct BrownoutStatsCSVFields {
const char *const triggered_time;
const char *const triggered_idx;
+ const char *const battery_soc;
const char *const battery_temp;
const char *const battery_cycle;
const char *const voltage_now;
@@ -90,6 +90,7 @@ struct BrownoutStatsCSVFields {
struct BrownoutStatsCSVRow {
struct timespec triggered_time;
int triggered_idx;
+ int min_battery_soc;
int max_battery_temp;
int min_battery_cycle;
int min_voltage_now;
@@ -146,7 +147,6 @@ class BatteryMitigationService : public RefBase {
std::thread brownoutEventThread;
std::atomic_bool threadStop{false};
- char *storingAddr;
int mainPmicID;
int subPmicID;
double mainLpfBitResolutions[METER_CHANNEL_MAX];
@@ -159,7 +159,6 @@ class BatteryMitigationService : public RefBase {
void TriggerEventThread();
void initTotalNumericSysfsPaths();
void initPmicRelated();
- int initThisMeal();
int initFd();
int initTrigFd();
void tearDownBrownoutEventThread();
diff --git a/battery_mitigation/include/battery_mitigation/MitigationConfig.h b/battery_mitigation/include/battery_mitigation/MitigationConfig.h
index bcf0f69b..3fea3233 100644
--- a/battery_mitigation/include/battery_mitigation/MitigationConfig.h
+++ b/battery_mitigation/include/battery_mitigation/MitigationConfig.h
@@ -53,6 +53,8 @@ class MitigationConfig {
std::string SubPmicName;
std::string PcieModemPath;
std::string PcieWifiPath;
+ const std::vector<numericSysfs> NumericSysfsStatPaths;
+ const std::vector<numericSysfs> NumericSysfsStatDirs;
};
struct pmicCommon {