Work on issue #62065889: Assess thresholds and criteria for killing...
...background processes (CPU, etc)
Add full configuration params for adjusting these settings (some were
already there).
Also... as long as we are doing this...
- Get rid of all of the wakelock stuff. That is completely pointless
now that we aren't even allowing cached processes to hold wake locks.
- This greatly simplifies the code, since we don't need to deal with
two different policies for how we do checks. Instead, we just regularly
check for CPU and the CPU check interval.
- And make the CPU check more aggressive and have much more flexibility
for tuning: there are now 4 different maximum CPU use levels, depending
on how long the process has been in the cached state. This allows us to
be more strict on CPU use the longer it is sitting in the background.
Note that CPU use tracking only happens while the device is not
plugged in to power... I'll leave this for now, but I think in the
future we should think about applying these limits even when plugged
in, because in either case cached apps should really not be doing
much.
Test: manual
Change-Id: I68f4ab68be5f7d5fc4822005107fb60ef07a374d
diff --git a/core/java/android/os/BatteryStats.java b/core/java/android/os/BatteryStats.java
index b178d81..cf4fd99 100644
--- a/core/java/android/os/BatteryStats.java
+++ b/core/java/android/os/BatteryStats.java
@@ -5160,9 +5160,7 @@
Uid.Proc.ExcessivePower ew = ps.getExcessivePower(e);
if (ew != null) {
pw.print(prefix); pw.print(" * Killed for ");
- if (ew.type == Uid.Proc.ExcessivePower.TYPE_WAKE) {
- pw.print("wake lock");
- } else if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) {
+ if (ew.type == Uid.Proc.ExcessivePower.TYPE_CPU) {
pw.print("cpu");
} else {
pw.print("unknown");
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index e563360..3b6a11d 100755
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -9161,9 +9161,11 @@
* gc_min_interval (long)
* full_pss_min_interval (long)
* full_pss_lowered_interval (long)
- * power_check_delay (long)
- * wake_lock_min_check_duration (long)
- * cpu_min_check_duration (long)
+ * power_check_interval (long)
+ * power_check_max_cpu_1 (int)
+ * power_check_max_cpu_2 (int)
+ * power_check_max_cpu_3 (int)
+ * power_check_max_cpu_4 (int)
* service_usage_interaction_time (long)
* usage_stats_interaction_interval (long)
* service_restart_duration (long)
diff --git a/core/java/com/android/internal/app/procstats/ProcessState.java b/core/java/com/android/internal/app/procstats/ProcessState.java
index 9470668..e0a4053 100644
--- a/core/java/com/android/internal/app/procstats/ProcessState.java
+++ b/core/java/com/android/internal/app/procstats/ProcessState.java
@@ -196,7 +196,6 @@
ProcessState pnew = new ProcessState(this, mPackage, mUid, mVersion, mName, now);
pnew.mDurations.addDurations(mDurations);
pnew.mPssTable.copyFrom(mPssTable, PSS_COUNT);
- pnew.mNumExcessiveWake = mNumExcessiveWake;
pnew.mNumExcessiveCpu = mNumExcessiveCpu;
pnew.mNumCachedKill = mNumCachedKill;
pnew.mMinCachedKillPss = mMinCachedKillPss;
@@ -250,7 +249,6 @@
public void add(ProcessState other) {
mDurations.addDurations(other.mDurations);
mPssTable.mergeStats(other.mPssTable);
- mNumExcessiveWake += other.mNumExcessiveWake;
mNumExcessiveCpu += other.mNumExcessiveCpu;
if (other.mNumCachedKill > 0) {
addCachedKill(other.mNumCachedKill, other.mMinCachedKillPss,
@@ -264,7 +262,6 @@
mStartTime = now;
mLastPssState = STATE_NOTHING;
mLastPssTime = 0;
- mNumExcessiveWake = 0;
mNumExcessiveCpu = 0;
mNumCachedKill = 0;
mMinCachedKillPss = mAvgCachedKillPss = mMaxCachedKillPss = 0;
@@ -286,7 +283,7 @@
out.writeInt(mMultiPackage ? 1 : 0);
mDurations.writeToParcel(out);
mPssTable.writeToParcel(out);
- out.writeInt(mNumExcessiveWake);
+ out.writeInt(0); // was mNumExcessiveWake
out.writeInt(mNumExcessiveCpu);
out.writeInt(mNumCachedKill);
if (mNumCachedKill > 0) {
@@ -309,7 +306,7 @@
if (!mPssTable.readFromParcel(in)) {
return false;
}
- mNumExcessiveWake = in.readInt();
+ in.readInt(); // was mNumExcessiveWake
mNumExcessiveCpu = in.readInt();
mNumCachedKill = in.readInt();
if (mNumCachedKill > 0) {
@@ -493,18 +490,6 @@
}
}
- public void reportExcessiveWake(ArrayMap<String, ProcessStateHolder> pkgList) {
- ensureNotDead();
- mCommonProcess.mNumExcessiveWake++;
- if (!mCommonProcess.mMultiPackage) {
- return;
- }
-
- for (int ip=pkgList.size()-1; ip>=0; ip--) {
- pullFixedProc(pkgList, ip).mNumExcessiveWake++;
- }
- }
-
public void reportExcessiveCpu(ArrayMap<String, ProcessStateHolder> pkgList) {
ensureNotDead();
mCommonProcess.mNumExcessiveCpu++;
@@ -895,10 +880,6 @@
}
}
}
- if (mNumExcessiveWake != 0) {
- pw.print(prefix); pw.print("Killed for excessive wake locks: ");
- pw.print(mNumExcessiveWake); pw.println(" times");
- }
if (mNumExcessiveCpu != 0) {
pw.print(prefix); pw.print("Killed for excessive CPU use: ");
pw.print(mNumExcessiveCpu); pw.println(" times");
@@ -1072,7 +1053,7 @@
dumpAllPssCheckin(pw);
pw.println();
}
- if (mNumExcessiveWake > 0 || mNumExcessiveCpu > 0 || mNumCachedKill > 0) {
+ if (mNumExcessiveCpu > 0 || mNumCachedKill > 0) {
pw.print("pkgkills,");
pw.print(pkgName);
pw.print(",");
@@ -1082,7 +1063,7 @@
pw.print(",");
pw.print(DumpUtils.collapseString(pkgName, itemName));
pw.print(",");
- pw.print(mNumExcessiveWake);
+ pw.print("0"); // was mNumExcessiveWake
pw.print(",");
pw.print(mNumExcessiveCpu);
pw.print(",");
@@ -1114,13 +1095,13 @@
dumpAllPssCheckin(pw);
pw.println();
}
- if (mNumExcessiveWake > 0 || mNumExcessiveCpu > 0 || mNumCachedKill > 0) {
+ if (mNumExcessiveCpu > 0 || mNumCachedKill > 0) {
pw.print("kills,");
pw.print(procName);
pw.print(",");
pw.print(uid);
pw.print(",");
- pw.print(mNumExcessiveWake);
+ pw.print("0"); // was mNumExcessiveWake
pw.print(",");
pw.print(mNumExcessiveCpu);
pw.print(",");
diff --git a/core/java/com/android/internal/os/BatteryStatsImpl.java b/core/java/com/android/internal/os/BatteryStatsImpl.java
index 696dbda..cb00c5e 100644
--- a/core/java/com/android/internal/os/BatteryStatsImpl.java
+++ b/core/java/com/android/internal/os/BatteryStatsImpl.java
@@ -3987,14 +3987,6 @@
return 0;
}
- public void reportExcessiveWakeLocked(int uid, String proc, long overTime, long usedTime) {
- uid = mapUid(uid);
- Uid u = mUidStats.get(uid);
- if (u != null) {
- u.reportExcessiveWakeLocked(proc, overTime, usedTime);
- }
- }
-
public void reportExcessiveCpuLocked(int uid, String proc, long overTime, long usedTime) {
uid = mapUid(uid);
Uid u = mUidStats.get(uid);
@@ -7745,17 +7737,6 @@
return null;
}
- public void addExcessiveWake(long overTime, long usedTime) {
- if (mExcessivePower == null) {
- mExcessivePower = new ArrayList<ExcessivePower>();
- }
- ExcessivePower ew = new ExcessivePower();
- ew.type = ExcessivePower.TYPE_WAKE;
- ew.overTime = overTime;
- ew.usedTime = usedTime;
- mExcessivePower.add(ew);
- }
-
public void addExcessiveCpu(long overTime, long usedTime) {
if (mExcessivePower == null) {
mExcessivePower = new ArrayList<ExcessivePower>();
@@ -8570,13 +8551,6 @@
}
}
- public void reportExcessiveWakeLocked(String proc, long overTime, long usedTime) {
- Proc p = getProcessStatsLocked(proc);
- if (p != null) {
- p.addExcessiveWake(overTime, usedTime);
- }
- }
-
public void reportExcessiveCpuLocked(String proc, long overTime, long usedTime) {
Proc p = getProcessStatsLocked(proc);
if (p != null) {