Merge "Fix system service power calculation when measured energy is available" into sc-dev am: 16d1188b7d am: c22cb8480d am: 9dec696e82
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14726213 Change-Id: I40265d4c4552474b989dd16fc061952dbcb0211b
This commit is contained in:
@@ -201,7 +201,10 @@ public class CpuPowerCalculator extends PowerCalculator {
|
||||
result.packageWithHighestDrain = packageWithHighestDrain;
|
||||
}
|
||||
|
||||
private double calculateUidModeledPowerMah(BatteryStats.Uid u, int statsType) {
|
||||
/**
|
||||
* Calculates CPU power consumed by the specified app, using the PowerProfile model.
|
||||
*/
|
||||
public double calculateUidModeledPowerMah(BatteryStats.Uid u, int statsType) {
|
||||
// Constant battery drain when CPU is active
|
||||
double powerMah = calculateActiveCpuPowerMah(u.getCpuActiveTime());
|
||||
|
||||
|
||||
@@ -40,8 +40,10 @@ public class SystemServicePowerCalculator extends PowerCalculator {
|
||||
// to this layout:
|
||||
// {cluster1-speed1, cluster1-speed2, ..., cluster2-speed1, cluster2-speed2, ...}
|
||||
private final UsageBasedPowerEstimator[] mPowerEstimators;
|
||||
private final CpuPowerCalculator mCpuPowerCalculator;
|
||||
|
||||
public SystemServicePowerCalculator(PowerProfile powerProfile) {
|
||||
mCpuPowerCalculator = new CpuPowerCalculator(powerProfile);
|
||||
int numFreqs = 0;
|
||||
final int numCpuClusters = powerProfile.getNumCpuClusters();
|
||||
for (int cluster = 0; cluster < numCpuClusters; cluster++) {
|
||||
@@ -62,7 +64,22 @@ public class SystemServicePowerCalculator extends PowerCalculator {
|
||||
@Override
|
||||
public void calculate(BatteryUsageStats.Builder builder, BatteryStats batteryStats,
|
||||
long rawRealtimeUs, long rawUptimeUs, BatteryUsageStatsQuery query) {
|
||||
double systemServicePowerMah = calculateSystemServicePower(batteryStats);
|
||||
final BatteryStats.Uid systemUid = batteryStats.getUidStats().get(Process.SYSTEM_UID);
|
||||
if (systemUid == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final long consumptionUC = systemUid.getCpuMeasuredBatteryConsumptionUC();
|
||||
final int powerModel = getPowerModel(consumptionUC, query);
|
||||
|
||||
double systemServicePowerMah;
|
||||
if (powerModel == BatteryConsumer.POWER_MODEL_MEASURED_ENERGY) {
|
||||
systemServicePowerMah = calculatePowerUsingMeasuredConsumption(batteryStats,
|
||||
systemUid, consumptionUC);
|
||||
} else {
|
||||
systemServicePowerMah = calculatePowerUsingPowerProfile(batteryStats);
|
||||
}
|
||||
|
||||
final SparseArray<UidBatteryConsumer.Builder> uidBatteryConsumerBuilders =
|
||||
builder.getUidBatteryConsumerBuilders();
|
||||
final UidBatteryConsumer.Builder systemServerConsumer = uidBatteryConsumerBuilders.get(
|
||||
@@ -76,7 +93,7 @@ public class SystemServicePowerCalculator extends PowerCalculator {
|
||||
// distributed to applications
|
||||
systemServerConsumer.setConsumedPower(
|
||||
BatteryConsumer.POWER_COMPONENT_REATTRIBUTED_TO_OTHER_CONSUMERS,
|
||||
-systemServicePowerMah);
|
||||
-systemServicePowerMah, powerModel);
|
||||
}
|
||||
|
||||
for (int i = uidBatteryConsumerBuilders.size() - 1; i >= 0; i--) {
|
||||
@@ -84,7 +101,8 @@ public class SystemServicePowerCalculator extends PowerCalculator {
|
||||
if (app != systemServerConsumer) {
|
||||
final BatteryStats.Uid uid = app.getBatteryStatsUid();
|
||||
app.setConsumedPower(BatteryConsumer.POWER_COMPONENT_SYSTEM_SERVICES,
|
||||
systemServicePowerMah * uid.getProportionalSystemServiceUsage());
|
||||
systemServicePowerMah * uid.getProportionalSystemServiceUsage(),
|
||||
powerModel);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +120,20 @@ public class SystemServicePowerCalculator extends PowerCalculator {
|
||||
public void calculate(List<BatterySipper> sippers, BatteryStats batteryStats,
|
||||
long rawRealtimeUs, long rawUptimeUs, int statsType,
|
||||
SparseArray<UserHandle> asUsers) {
|
||||
double systemServicePowerMah = calculateSystemServicePower(batteryStats);
|
||||
final BatteryStats.Uid systemUid = batteryStats.getUidStats().get(Process.SYSTEM_UID);
|
||||
if (systemUid == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final long consumptionUC = systemUid.getCpuMeasuredBatteryConsumptionUC();
|
||||
double systemServicePowerMah;
|
||||
if (getPowerModel(consumptionUC) == BatteryConsumer.POWER_MODEL_MEASURED_ENERGY) {
|
||||
systemServicePowerMah = calculatePowerUsingMeasuredConsumption(batteryStats,
|
||||
systemUid, consumptionUC);
|
||||
} else {
|
||||
systemServicePowerMah = calculatePowerUsingPowerProfile(batteryStats);
|
||||
}
|
||||
|
||||
BatterySipper systemServerSipper = null;
|
||||
for (int i = sippers.size() - 1; i >= 0; i--) {
|
||||
final BatterySipper app = sippers.get(i);
|
||||
@@ -134,7 +165,21 @@ public class SystemServicePowerCalculator extends PowerCalculator {
|
||||
}
|
||||
}
|
||||
|
||||
private double calculateSystemServicePower(BatteryStats batteryStats) {
|
||||
private double calculatePowerUsingMeasuredConsumption(BatteryStats batteryStats,
|
||||
BatteryStats.Uid systemUid, long consumptionUC) {
|
||||
// Use the PowerProfile based model to estimate the ratio between the power consumed
|
||||
// while handling incoming binder calls and the entire System UID power consumption.
|
||||
// Apply that ratio to the _measured_ system UID power consumption to get a more
|
||||
// accurate estimate of the power consumed by incoming binder calls.
|
||||
final double systemServiceModeledPowerMah = calculatePowerUsingPowerProfile(batteryStats);
|
||||
final double systemUidModeledPowerMah = mCpuPowerCalculator.calculateUidModeledPowerMah(
|
||||
systemUid, BatteryStats.STATS_SINCE_CHARGED);
|
||||
|
||||
return uCtoMah(consumptionUC) * systemServiceModeledPowerMah
|
||||
/ systemUidModeledPowerMah;
|
||||
}
|
||||
|
||||
private double calculatePowerUsingPowerProfile(BatteryStats batteryStats) {
|
||||
final long[] systemServiceTimeAtCpuSpeeds = batteryStats.getSystemServiceTimeAtCpuSpeeds();
|
||||
if (systemServiceTimeAtCpuSpeeds == null) {
|
||||
return 0;
|
||||
@@ -145,13 +190,12 @@ public class SystemServicePowerCalculator extends PowerCalculator {
|
||||
double powerMah = 0;
|
||||
final int size = Math.min(mPowerEstimators.length, systemServiceTimeAtCpuSpeeds.length);
|
||||
for (int i = 0; i < size; i++) {
|
||||
powerMah += mPowerEstimators[i].calculatePower(systemServiceTimeAtCpuSpeeds[i]);
|
||||
powerMah += mPowerEstimators[i].calculatePower(systemServiceTimeAtCpuSpeeds[i] / 1000);
|
||||
}
|
||||
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "System service power:" + powerMah);
|
||||
}
|
||||
|
||||
return powerMah;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user