Browse Source

health: Rate-limit LearnedCapacity backup

Only check values on every 8th call, saving some read/writes.

(One call is every minute on AC, every 10min on battery)
For reference: https://android.googlesource.com/platform/hardware/interfaces/+/refs/tags/android-9.0.0_r38/health/2.0/default/healthd_common.cpp#40
master
Felix 6 months ago
parent
commit
57b301ae68
2 changed files with 12 additions and 3 deletions
  1. +11
    -3
      hardware/health/LearnedCapacityBackupRestore.cpp
  2. +1
    -0
      hardware/health/LearnedCapacityBackupRestore.h

+ 11
- 3
hardware/health/LearnedCapacityBackupRestore.cpp View File

@@ -26,12 +26,16 @@ namespace device {
namespace sony {
namespace health {

static constexpr int kLCBackupTrigger = 8;

static constexpr int kBuffSize = 256;
/* Battery capacity is given in microampere hours */
/* Divide by 1000 to get milliampere hours("mAh") */
static constexpr int kCapConversionFactor = 1000;

LearnedCapacityBackupRestore::LearnedCapacityBackupRestore() {}
LearnedCapacityBackupRestore::LearnedCapacityBackupRestore() {
cap_inc_ = 0;
}

void LearnedCapacityBackupRestore::Restore() {
ReadFromPersistStorage();
@@ -40,8 +44,12 @@ void LearnedCapacityBackupRestore::Restore() {
}

void LearnedCapacityBackupRestore::Backup() {
ReadFromSRAM();
UpdateAndSave();
if (++cap_inc_ >= kLCBackupTrigger) {
LOG(VERBOSE) << "LC: Triggered ReadFromSRAM() and UpdateAndSave() !";
ReadFromSRAM();
UpdateAndSave();
cap_inc_ = 0;
}
}

void LearnedCapacityBackupRestore::ReadFromPersistStorage() {

+ 1
- 0
hardware/health/LearnedCapacityBackupRestore.h View File

@@ -40,6 +40,7 @@ class LearnedCapacityBackupRestore {
private:
int sw_cap_;
int hw_cap_;
int cap_inc_;

void ReadFromPersistStorage();
void SaveToPersistStorage();

Loading…
Cancel
Save