summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Michael Wachenschwanz <mwachens@google.com> 2021-02-12 10:30:35 -0800
committer Michael Wachenschwanz <mwachens@google.com> 2021-02-17 11:38:40 -0800
commitaf23d81ff289a83fc4cbed7a250d9cfc7ad37abb (patch)
tree88370aeeddc11e7f775e3368309bc3b127985821
parent580d86680d7c50846e61ce07e0423943b296b56f (diff)
Make CpuPowerCalculator's Estimators available to com.android.internal
BatteryStats needs the power_profile Cpu constants to smear the measured CPU Cluster energies across UIDs. Using the CpuPowerProfileCalculator to get the calculation decreases the chance of someone accidentally diverging estimated and measured CPU power calculations. Bug: 180079165 Test: tbd Change-Id: I474cd019d177bd07f2ae48a47b83a82e4074ed4f
-rw-r--r--core/java/com/android/internal/os/CpuPowerCalculator.java45
1 files changed, 40 insertions, 5 deletions
diff --git a/core/java/com/android/internal/os/CpuPowerCalculator.java b/core/java/com/android/internal/os/CpuPowerCalculator.java
index 45d81280af4a..97f727ba72c5 100644
--- a/core/java/com/android/internal/os/CpuPowerCalculator.java
+++ b/core/java/com/android/internal/os/CpuPowerCalculator.java
@@ -124,15 +124,15 @@ public class CpuPowerCalculator extends PowerCalculator {
long durationMs = (u.getUserCpuTimeUs(statsType) + u.getSystemCpuTimeUs(statsType)) / 1000;
// Constant battery drain when CPU is active
- double powerMah = mCpuActivePowerEstimator.calculatePower(u.getCpuActiveTime());
+ double powerMah = calculateActiveCpuPowerMah(u.getCpuActiveTime());
// Additional per-cluster battery drain
long[] cpuClusterTimes = u.getCpuClusterTimes();
if (cpuClusterTimes != null) {
if (cpuClusterTimes.length == mNumCpuClusters) {
for (int cluster = 0; cluster < mNumCpuClusters; cluster++) {
- double power = mPerClusterPowerEstimators[cluster]
- .calculatePower(cpuClusterTimes[cluster]);
+ double power = calculatePerCpuClusterPowerMah(cluster,
+ cpuClusterTimes[cluster]);
powerMah += power;
if (DEBUG) {
Log.d(TAG, "UID " + u.getUid() + ": CPU cluster #" + cluster
@@ -151,8 +151,8 @@ public class CpuPowerCalculator extends PowerCalculator {
final int speedsForCluster = mPerCpuFreqPowerEstimators[cluster].length;
for (int speed = 0; speed < speedsForCluster; speed++) {
final long timeUs = u.getTimeAtCpuSpeed(cluster, speed, statsType);
- final double power =
- mPerCpuFreqPowerEstimators[cluster][speed].calculatePower(timeUs / 1000);
+ final double power = calculatePerCpuFreqPowerMah(cluster, speed,
+ timeUs / 1000);
if (DEBUG) {
Log.d(TAG, "UID " + u.getUid() + ": CPU cluster #" + cluster + " step #"
+ speed + " timeUs=" + timeUs + " power="
@@ -207,4 +207,39 @@ public class CpuPowerCalculator extends PowerCalculator {
result.powerMah = powerMah;
result.packageWithHighestDrain = packageWithHighestDrain;
}
+
+ /**
+ * Calculates active CPU power consumption.
+ *
+ * @param durationsMs duration of CPU usage.
+ * @return a double in milliamp-hours of estimated active CPU power consumption.
+ */
+ public double calculateActiveCpuPowerMah(long durationsMs) {
+ return mCpuActivePowerEstimator.calculatePower(durationsMs);
+ }
+
+ /**
+ * Calculates CPU cluster power consumption.
+ *
+ * @param cluster CPU cluster used.
+ * @param clusterDurationMs duration of CPU cluster usage.
+ * @return a double in milliamp-hours of estimated CPU cluster power consumption.
+ */
+ public double calculatePerCpuClusterPowerMah(int cluster, long clusterDurationMs) {
+ return mPerClusterPowerEstimators[cluster].calculatePower(clusterDurationMs);
+ }
+
+ /**
+ * Calculates CPU cluster power consumption at a specific speedstep.
+ *
+ * @param cluster CPU cluster used.
+ * @param speedStep which speedstep used.
+ * @param clusterSpeedDurationsMs duration of CPU cluster usage at the specified speed step.
+ * @return a double in milliamp-hours of estimated CPU cluster-speed power consumption.
+ */
+ public double calculatePerCpuFreqPowerMah(int cluster, int speedStep,
+ long clusterSpeedDurationsMs) {
+ return mPerCpuFreqPowerEstimators[cluster][speedStep].calculatePower(
+ clusterSpeedDurationsMs);
+ }
}