Merge "Reserve contexts for user-initiated jobs."

This commit is contained in:
TreeHugger Robot
2023-01-18 21:04:01 +00:00
committed by Android (Google) Code Review
4 changed files with 102 additions and 70 deletions

View File

@@ -158,33 +158,37 @@ class JobConcurrencyManager {
* state (excluding {@link ActivityManager#PROCESS_STATE_TOP} for a currently active user.
*/
static final int WORK_TYPE_FGS = 1 << 1;
/** The job is allowed to run as a user-initiated job for a currently active user. */
static final int WORK_TYPE_UI = 1 << 2;
/** The job is allowed to run as an expedited job for a currently active user. */
static final int WORK_TYPE_EJ = 1 << 2;
static final int WORK_TYPE_EJ = 1 << 3;
/**
* The job does not satisfy any of the conditions for {@link #WORK_TYPE_TOP},
* {@link #WORK_TYPE_FGS}, or {@link #WORK_TYPE_EJ}, but is for a currently active user, so
* can run as a background job.
*/
static final int WORK_TYPE_BG = 1 << 3;
static final int WORK_TYPE_BG = 1 << 4;
/**
* The job is for an app in a {@link ActivityManager#PROCESS_STATE_FOREGROUND_SERVICE} or higher
* state, or is allowed to run as an expedited job, but is for a completely background user.
* state, or is allowed to run as an expedited or user-initiated job,
* but is for a completely background user.
*/
static final int WORK_TYPE_BGUSER_IMPORTANT = 1 << 4;
static final int WORK_TYPE_BGUSER_IMPORTANT = 1 << 5;
/**
* The job does not satisfy any of the conditions for {@link #WORK_TYPE_TOP},
* {@link #WORK_TYPE_FGS}, or {@link #WORK_TYPE_EJ}, but is for a completely background user,
* so can run as a background user job.
*/
static final int WORK_TYPE_BGUSER = 1 << 5;
static final int WORK_TYPE_BGUSER = 1 << 6;
@VisibleForTesting
static final int NUM_WORK_TYPES = 6;
static final int NUM_WORK_TYPES = 7;
private static final int ALL_WORK_TYPES = (1 << NUM_WORK_TYPES) - 1;
@IntDef(prefix = {"WORK_TYPE_"}, flag = true, value = {
WORK_TYPE_NONE,
WORK_TYPE_TOP,
WORK_TYPE_FGS,
WORK_TYPE_UI,
WORK_TYPE_EJ,
WORK_TYPE_BG,
WORK_TYPE_BGUSER_IMPORTANT,
@@ -203,6 +207,8 @@ class JobConcurrencyManager {
return "TOP";
case WORK_TYPE_FGS:
return "FGS";
case WORK_TYPE_UI:
return "UI";
case WORK_TYPE_EJ:
return "EJ";
case WORK_TYPE_BG:
@@ -238,8 +244,9 @@ class JobConcurrencyManager {
// defaultMin
List.of(Pair.create(WORK_TYPE_TOP, .4f),
Pair.create(WORK_TYPE_FGS, .2f),
Pair.create(WORK_TYPE_EJ, .2f), Pair.create(WORK_TYPE_BG, .1f),
Pair.create(WORK_TYPE_BGUSER_IMPORTANT, .1f)),
Pair.create(WORK_TYPE_UI, .1f),
Pair.create(WORK_TYPE_EJ, .1f), Pair.create(WORK_TYPE_BG, .05f),
Pair.create(WORK_TYPE_BGUSER_IMPORTANT, .05f)),
// defaultMax
List.of(Pair.create(WORK_TYPE_BG, .5f),
Pair.create(WORK_TYPE_BGUSER_IMPORTANT, .25f),
@@ -250,6 +257,7 @@ class JobConcurrencyManager {
// defaultMin
List.of(Pair.create(WORK_TYPE_TOP, .4f),
Pair.create(WORK_TYPE_FGS, .1f),
Pair.create(WORK_TYPE_UI, .1f),
Pair.create(WORK_TYPE_EJ, .1f), Pair.create(WORK_TYPE_BG, .1f),
Pair.create(WORK_TYPE_BGUSER_IMPORTANT, .1f)),
// defaultMax
@@ -260,8 +268,9 @@ class JobConcurrencyManager {
new WorkTypeConfig("screen_on_low", DEFAULT_CONCURRENCY_LIMIT,
/* defaultMaxTotal */ DEFAULT_CONCURRENCY_LIMIT * 4 / 10,
// defaultMin
List.of(Pair.create(WORK_TYPE_TOP, 2.0f / 3),
List.of(Pair.create(WORK_TYPE_TOP, .6f),
Pair.create(WORK_TYPE_FGS, .1f),
Pair.create(WORK_TYPE_UI, .1f),
Pair.create(WORK_TYPE_EJ, .1f)),
// defaultMax
List.of(Pair.create(WORK_TYPE_BG, 1.0f / 3),
@@ -271,9 +280,10 @@ class JobConcurrencyManager {
new WorkTypeConfig("screen_on_critical", DEFAULT_CONCURRENCY_LIMIT,
/* defaultMaxTotal */ DEFAULT_CONCURRENCY_LIMIT * 4 / 10,
// defaultMin
List.of(Pair.create(WORK_TYPE_TOP, 2.0f / 3),
List.of(Pair.create(WORK_TYPE_TOP, .7f),
Pair.create(WORK_TYPE_FGS, .1f),
Pair.create(WORK_TYPE_EJ, .1f)),
Pair.create(WORK_TYPE_UI, .1f),
Pair.create(WORK_TYPE_EJ, .05f)),
// defaultMax
List.of(Pair.create(WORK_TYPE_BG, 1.0f / 6),
Pair.create(WORK_TYPE_BGUSER_IMPORTANT, 1.0f / 6),
@@ -287,8 +297,9 @@ class JobConcurrencyManager {
// defaultMin
List.of(Pair.create(WORK_TYPE_TOP, .3f),
Pair.create(WORK_TYPE_FGS, .2f),
Pair.create(WORK_TYPE_EJ, .3f), Pair.create(WORK_TYPE_BG, .2f),
Pair.create(WORK_TYPE_BGUSER_IMPORTANT, .1f)),
Pair.create(WORK_TYPE_UI, .2f),
Pair.create(WORK_TYPE_EJ, .15f), Pair.create(WORK_TYPE_BG, .1f),
Pair.create(WORK_TYPE_BGUSER_IMPORTANT, .05f)),
// defaultMax
List.of(Pair.create(WORK_TYPE_BG, .6f),
Pair.create(WORK_TYPE_BGUSER_IMPORTANT, .2f),
@@ -299,8 +310,9 @@ class JobConcurrencyManager {
// defaultMin
List.of(Pair.create(WORK_TYPE_TOP, .3f),
Pair.create(WORK_TYPE_FGS, .2f),
Pair.create(WORK_TYPE_EJ, .3f), Pair.create(WORK_TYPE_BG, .2f),
Pair.create(WORK_TYPE_BGUSER_IMPORTANT, .1f)),
Pair.create(WORK_TYPE_UI, .2f),
Pair.create(WORK_TYPE_EJ, .15f), Pair.create(WORK_TYPE_BG, .1f),
Pair.create(WORK_TYPE_BGUSER_IMPORTANT, .05f)),
// defaultMax
List.of(Pair.create(WORK_TYPE_BG, .5f),
Pair.create(WORK_TYPE_BGUSER_IMPORTANT, .1f),
@@ -309,9 +321,11 @@ class JobConcurrencyManager {
new WorkTypeConfig("screen_off_low", DEFAULT_CONCURRENCY_LIMIT,
/* defaultMaxTotal */ DEFAULT_CONCURRENCY_LIMIT * 6 / 10,
// defaultMin
List.of(Pair.create(WORK_TYPE_TOP, .4f),
Pair.create(WORK_TYPE_FGS, .1f),
Pair.create(WORK_TYPE_EJ, .2f), Pair.create(WORK_TYPE_BG, .1f)),
List.of(Pair.create(WORK_TYPE_TOP, .3f),
Pair.create(WORK_TYPE_FGS, .15f),
Pair.create(WORK_TYPE_UI, .15f),
Pair.create(WORK_TYPE_EJ, .1f), Pair.create(WORK_TYPE_BG, .05f),
Pair.create(WORK_TYPE_BGUSER_IMPORTANT, .05f)),
// defaultMax
List.of(Pair.create(WORK_TYPE_BG, .25f),
Pair.create(WORK_TYPE_BGUSER_IMPORTANT, .1f),
@@ -320,9 +334,10 @@ class JobConcurrencyManager {
new WorkTypeConfig("screen_off_critical", DEFAULT_CONCURRENCY_LIMIT,
/* defaultMaxTotal */ DEFAULT_CONCURRENCY_LIMIT * 4 / 10,
// defaultMin
List.of(Pair.create(WORK_TYPE_TOP, .5f),
List.of(Pair.create(WORK_TYPE_TOP, .3f),
Pair.create(WORK_TYPE_FGS, .1f),
Pair.create(WORK_TYPE_EJ, .1f)),
Pair.create(WORK_TYPE_UI, .1f),
Pair.create(WORK_TYPE_EJ, .05f)),
// defaultMax
List.of(Pair.create(WORK_TYPE_BG, .1f),
Pair.create(WORK_TYPE_BGUSER_IMPORTANT, .1f),
@@ -2097,10 +2112,12 @@ class JobConcurrencyManager {
if (js.shouldTreatAsExpeditedJob()) {
classification |= WORK_TYPE_EJ;
} else if (js.shouldTreatAsUserInitiatedJob()) {
classification |= WORK_TYPE_UI;
}
} else {
if (js.lastEvaluatedBias >= JobInfo.BIAS_FOREGROUND_SERVICE
|| js.shouldTreatAsExpeditedJob()) {
|| js.shouldTreatAsExpeditedJob() || js.shouldTreatAsUserInitiatedJob()) {
classification |= WORK_TYPE_BGUSER_IMPORTANT;
}
// BGUSER_IMPORTANT jobs can also run as BGUSER jobs, so not an 'else' here.
@@ -2120,6 +2137,7 @@ class JobConcurrencyManager {
static final String KEY_PREFIX_MAX_RATIO = KEY_PREFIX_MAX + "ratio_";
private static final String KEY_PREFIX_MAX_RATIO_TOP = KEY_PREFIX_MAX_RATIO + "top_";
private static final String KEY_PREFIX_MAX_RATIO_FGS = KEY_PREFIX_MAX_RATIO + "fgs_";
private static final String KEY_PREFIX_MAX_RATIO_UI = KEY_PREFIX_MAX_RATIO + "ui_";
private static final String KEY_PREFIX_MAX_RATIO_EJ = KEY_PREFIX_MAX_RATIO + "ej_";
private static final String KEY_PREFIX_MAX_RATIO_BG = KEY_PREFIX_MAX_RATIO + "bg_";
private static final String KEY_PREFIX_MAX_RATIO_BGUSER = KEY_PREFIX_MAX_RATIO + "bguser_";
@@ -2129,6 +2147,7 @@ class JobConcurrencyManager {
static final String KEY_PREFIX_MIN_RATIO = KEY_PREFIX_MIN + "ratio_";
private static final String KEY_PREFIX_MIN_RATIO_TOP = KEY_PREFIX_MIN_RATIO + "top_";
private static final String KEY_PREFIX_MIN_RATIO_FGS = KEY_PREFIX_MIN_RATIO + "fgs_";
private static final String KEY_PREFIX_MIN_RATIO_UI = KEY_PREFIX_MIN_RATIO + "ui_";
private static final String KEY_PREFIX_MIN_RATIO_EJ = KEY_PREFIX_MIN_RATIO + "ej_";
private static final String KEY_PREFIX_MIN_RATIO_BG = KEY_PREFIX_MIN_RATIO + "bg_";
private static final String KEY_PREFIX_MIN_RATIO_BGUSER = KEY_PREFIX_MIN_RATIO + "bguser_";
@@ -2209,6 +2228,9 @@ class JobConcurrencyManager {
final int maxFgs = getMaxValue(properties,
KEY_PREFIX_MAX_RATIO_FGS + mConfigIdentifier, WORK_TYPE_FGS, oneIntBits);
mMaxAllowedSlots.put(WORK_TYPE_FGS, maxFgs);
final int maxUi = getMaxValue(properties,
KEY_PREFIX_MAX_RATIO_UI + mConfigIdentifier, WORK_TYPE_UI, oneIntBits);
mMaxAllowedSlots.put(WORK_TYPE_UI, maxUi);
final int maxEj = getMaxValue(properties,
KEY_PREFIX_MAX_RATIO_EJ + mConfigIdentifier, WORK_TYPE_EJ, oneIntBits);
mMaxAllowedSlots.put(WORK_TYPE_EJ, maxEj);
@@ -2237,6 +2259,12 @@ class JobConcurrencyManager {
0, Math.min(maxFgs, remaining));
mMinReservedSlots.put(WORK_TYPE_FGS, minFgs);
remaining -= minFgs;
// Ensure ui is in the range [0, min(maxUi, remaining)]
final int minUi = getMinValue(properties,
KEY_PREFIX_MIN_RATIO_UI + mConfigIdentifier, WORK_TYPE_UI,
0, Math.min(maxUi, remaining));
mMinReservedSlots.put(WORK_TYPE_UI, minUi);
remaining -= minUi;
// Ensure ej is in the range [0, min(maxEj, remaining)]
final int minEj = getMinValue(properties,
KEY_PREFIX_MIN_RATIO_EJ + mConfigIdentifier, WORK_TYPE_EJ,
@@ -2313,6 +2341,12 @@ class JobConcurrencyManager {
pw.print(KEY_PREFIX_MAX_RATIO_FGS + mConfigIdentifier,
mMaxAllowedSlots.get(WORK_TYPE_FGS))
.println();
pw.print(KEY_PREFIX_MIN_RATIO_UI + mConfigIdentifier,
mMinReservedSlots.get(WORK_TYPE_UI))
.println();
pw.print(KEY_PREFIX_MAX_RATIO_UI + mConfigIdentifier,
mMaxAllowedSlots.get(WORK_TYPE_UI))
.println();
pw.print(KEY_PREFIX_MIN_RATIO_EJ + mConfigIdentifier,
mMinReservedSlots.get(WORK_TYPE_EJ))
.println();

View File

@@ -30,6 +30,7 @@ import static com.android.server.job.JobConcurrencyManager.WORK_TYPE_EJ;
import static com.android.server.job.JobConcurrencyManager.WORK_TYPE_FGS;
import static com.android.server.job.JobConcurrencyManager.WORK_TYPE_NONE;
import static com.android.server.job.JobConcurrencyManager.WORK_TYPE_TOP;
import static com.android.server.job.JobConcurrencyManager.WORK_TYPE_UI;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
@@ -855,6 +856,9 @@ public final class JobConcurrencyManagerTest {
case WORK_TYPE_FGS:
workTypeString = "fgs";
break;
case WORK_TYPE_UI:
workTypeString = "ui";
break;
case WORK_TYPE_EJ:
workTypeString = "ej";
break;

View File

@@ -22,7 +22,6 @@ import static com.android.server.job.JobConcurrencyManager.WORK_TYPE_BG;
import static com.android.server.job.JobConcurrencyManager.WORK_TYPE_BGUSER;
import static com.android.server.job.JobConcurrencyManager.WORK_TYPE_BGUSER_IMPORTANT;
import static com.android.server.job.JobConcurrencyManager.WORK_TYPE_EJ;
import static com.android.server.job.JobConcurrencyManager.WORK_TYPE_FGS;
import static com.android.server.job.JobConcurrencyManager.WORK_TYPE_NONE;
import static com.android.server.job.JobConcurrencyManager.WORK_TYPE_TOP;
import static com.android.server.job.JobConcurrencyManager.workTypeToString;
@@ -59,7 +58,8 @@ public class WorkCountTrackerTest {
private static final double[] EQUAL_PROBABILITY_CDF =
buildWorkTypeCdf(1.0 / NUM_WORK_TYPES, 1.0 / NUM_WORK_TYPES, 1.0 / NUM_WORK_TYPES,
1.0 / NUM_WORK_TYPES, 1.0 / NUM_WORK_TYPES, 1.0 / NUM_WORK_TYPES);
1.0 / NUM_WORK_TYPES, 1.0 / NUM_WORK_TYPES, 1.0 / NUM_WORK_TYPES,
1.0 / NUM_WORK_TYPES);
private Random mRandom;
private WorkCountTracker mWorkCountTracker;
@@ -72,8 +72,9 @@ public class WorkCountTrackerTest {
@NonNull
private static double[] buildWorkTypeCdf(
double pTop, double pFgs, double pEj, double pBg, double pBgUserImp, double pBgUser) {
return buildCdf(pTop, pFgs, pEj, pBg, pBgUserImp, pBgUser);
double pTop, double pFgs, double pUi, double pEj, double pBg,
double pBgUserImp, double pBgUser) {
return buildCdf(pTop, pFgs, pUi, pEj, pBg, pBgUserImp, pBgUser);
}
@NonNull
@@ -108,23 +109,9 @@ public class WorkCountTrackerTest {
@JobConcurrencyManager.WorkType
static int getRandomWorkType(double[] cdf, double rand) {
assertThat(cdf.length).isEqualTo(NUM_WORK_TYPES);
final int index = getRandomIndex(cdf, rand);
switch (index) {
case 0:
return WORK_TYPE_TOP;
case 1:
return WORK_TYPE_FGS;
case 2:
return WORK_TYPE_EJ;
case 3:
return WORK_TYPE_BG;
case 4:
return WORK_TYPE_BGUSER_IMPORTANT;
case 5:
return WORK_TYPE_BGUSER;
default:
throw new IllegalStateException("Unknown work type");
}
return 1 << index;
}
/**
@@ -326,7 +313,7 @@ public class WorkCountTrackerTest {
final List<Pair<Integer, Float>> maxLimitRatios =
List.of(Pair.create(WORK_TYPE_BG, 1f), Pair.create(WORK_TYPE_BGUSER, .5f));
final double probStop = 0.5;
final double[] cdf = buildWorkTypeCdf(0.5, 0, 0, 0.5, 0, 0);
final double[] cdf = buildWorkTypeCdf(0.5, 0, 0, 0, 0.5, 0, 0);
final double[] numTypesCdf = buildCdf(.5, .3, .15, .05);
final double probStart = 0.5;
@@ -344,7 +331,7 @@ public class WorkCountTrackerTest {
final List<Pair<Integer, Float>> maxLimitRatios =
List.of(Pair.create(WORK_TYPE_BG, 1f), Pair.create(WORK_TYPE_BGUSER, .5f));
final double probStop = 0.5;
final double[] cdf = buildWorkTypeCdf(1.0 / 3, 0, 0, 1.0 / 3, 0, 1.0 / 3);
final double[] cdf = buildWorkTypeCdf(1.0 / 3, 0, 0, 0, 1.0 / 3, 0, 1.0 / 3);
final double[] numTypesCdf = buildCdf(.75, .2, .05);
final double probStart = 0.5;
@@ -362,7 +349,7 @@ public class WorkCountTrackerTest {
final List<Pair<Integer, Float>> maxLimitRatios =
List.of(Pair.create(WORK_TYPE_BG, .2f), Pair.create(WORK_TYPE_BGUSER, .1f));
final double probStop = 0.5;
final double[] cdf = buildWorkTypeCdf(1.0 / 3, 0, 0, 1.0 / 3, 0, 1.0 / 3);
final double[] cdf = buildWorkTypeCdf(1.0 / 3, 0, 0, 0, 1.0 / 3, 0, 1.0 / 3);
final double[] numTypesCdf = buildCdf(.05, .95);
final double probStart = 0.5;
@@ -382,7 +369,7 @@ public class WorkCountTrackerTest {
List.of(Pair.create(WORK_TYPE_BG, 2.0f / 3),
Pair.create(WORK_TYPE_BGUSER, 2.0f / 3));
final double probStop = 0.5;
final double[] cdf = buildWorkTypeCdf(0.1, 0, 0, 0.8, 0.02, .08);
final double[] cdf = buildWorkTypeCdf(0.1, 0, 0, 0, 0.8, 0.02, .08);
final double[] numTypesCdf = buildCdf(.5, .3, .15, .05);
final double probStart = 0.5;
@@ -402,7 +389,7 @@ public class WorkCountTrackerTest {
List.of(Pair.create(WORK_TYPE_BG, 2.0f / 3),
Pair.create(WORK_TYPE_BGUSER, 1.0f / 3));
final double probStop = 0.5;
final double[] cdf = buildWorkTypeCdf(0.85, 0.05, 0, 0.1, 0, 0);
final double[] cdf = buildWorkTypeCdf(0.8, 0.05, 0.05, 0, 0.1, 0, 0);
final double[] numTypesCdf = buildCdf(1);
final double probStart = 0.5;
@@ -422,7 +409,7 @@ public class WorkCountTrackerTest {
List.of(Pair.create(WORK_TYPE_BG, 2.0f / 3),
Pair.create(WORK_TYPE_BGUSER, 1.0f / 3));
final double probStop = 0.4;
final double[] cdf = buildWorkTypeCdf(0.1, 0, 0, 0.1, 0.05, .75);
final double[] cdf = buildWorkTypeCdf(0.1, 0, 0, 0, 0.1, 0.05, .75);
final double[] numTypesCdf = buildCdf(0.5, 0.5);
final double probStart = 0.5;
@@ -443,7 +430,7 @@ public class WorkCountTrackerTest {
List.of(Pair.create(WORK_TYPE_BG, 2.0f / 3),
Pair.create(WORK_TYPE_BGUSER, 1.0f / 3));
final double probStop = 0.4;
final double[] cdf = buildWorkTypeCdf(0.8, 0.1, 0, 0.05, 0, 0.05);
final double[] cdf = buildWorkTypeCdf(0.8, 0.1, 0, 0, 0.05, 0, 0.05);
final double[] numTypesCdf = buildCdf(1);
final double probStart = 0.5;
@@ -464,7 +451,7 @@ public class WorkCountTrackerTest {
List.of(Pair.create(WORK_TYPE_BG, 2.0f / 3),
Pair.create(WORK_TYPE_BGUSER, 1.0f / 3));
final double probStop = 0.5;
final double[] cdf = buildWorkTypeCdf(0, 0, 0, 0.5, 0, 0.5);
final double[] cdf = buildWorkTypeCdf(0, 0, 0, 0, 0.5, 0, 0.5);
final double[] numTypesCdf = buildCdf(1);
final double probStart = 0.5;
@@ -485,7 +472,7 @@ public class WorkCountTrackerTest {
List.of(Pair.create(WORK_TYPE_BG, 2.0f / 3),
Pair.create(WORK_TYPE_BGUSER, 1.0f / 3));
final double probStop = 0.5;
final double[] cdf = buildWorkTypeCdf(0, 0, 0, 0.1, 0, 0.9);
final double[] cdf = buildWorkTypeCdf(0, 0, 0, 0, 0.1, 0, 0.9);
final double[] numTypesCdf = buildCdf(0.9, 0.1);
final double probStart = 0.5;
@@ -506,7 +493,7 @@ public class WorkCountTrackerTest {
List.of(Pair.create(WORK_TYPE_BG, 2.0f / 3),
Pair.create(WORK_TYPE_BGUSER, 1.0f / 3));
final double probStop = 0.5;
final double[] cdf = buildWorkTypeCdf(0, 0, 0, 0.9, 0, 0.1);
final double[] cdf = buildWorkTypeCdf(0, 0, .4, 0, 0.5, 0, 0.1);
final double[] numTypesCdf = buildCdf(1);
final double probStart = 0.5;
@@ -525,7 +512,7 @@ public class WorkCountTrackerTest {
final List<Pair<Integer, Float>> maxLimitRatios =
List.of(Pair.create(WORK_TYPE_BG, 2.0f / 3));
final double probStop = 0.4;
final double[] cdf = buildWorkTypeCdf(0.5, 0, 0.5, 0, 0, 0);
final double[] cdf = buildWorkTypeCdf(0.5, 0, 0.25, 0.25, 0, 0, 0);
final double[] numTypesCdf = buildCdf(0.1, 0.7, 0.2);
final double probStart = 0.5;
@@ -566,7 +553,7 @@ public class WorkCountTrackerTest {
final List<Pair<Integer, Float>> maxLimitRatios =
List.of(Pair.create(WORK_TYPE_EJ, 5.0f / 6), Pair.create(WORK_TYPE_BG, 2.0f / 3));
final double probStop = 0.4;
final double[] cdf = buildWorkTypeCdf(.1, 0, 0.5, 0.35, 0, 0.05);
final double[] cdf = buildWorkTypeCdf(.1, 0, 0.05, 0.45, 0.35, 0, 0.05);
final double[] numTypesCdf = buildCdf(1);
final double probStart = 0.5;
@@ -586,7 +573,7 @@ public class WorkCountTrackerTest {
List.of(Pair.create(WORK_TYPE_EJ, 5.0f / 6), Pair.create(WORK_TYPE_BG, 2.0f / 3),
Pair.create(WORK_TYPE_BGUSER, 1.0f / 6));
final double probStop = 0.4;
final double[] cdf = buildWorkTypeCdf(0.01, 0.09, 0.4, 0.1, 0, 0.4);
final double[] cdf = buildWorkTypeCdf(0.01, 0.09, 0.2, 0.2, 0.1, 0, 0.4);
final double[] numTypesCdf = buildCdf(0.7, 0.3);
final double probStart = 0.5;
@@ -607,7 +594,7 @@ public class WorkCountTrackerTest {
Pair.create(WORK_TYPE_BGUSER_IMPORTANT, 1.0f / 7),
Pair.create(WORK_TYPE_BGUSER, 1.0f / 7));
final double probStop = 0.4;
final double[] cdf = buildWorkTypeCdf(0.01, 0.09, 0.25, 0.05, 0.3, 0.3);
final double[] cdf = buildWorkTypeCdf(0.01, 0.02, 0.09, 0.25, 0.05, 0.3, 0.3);
final double[] numTypesCdf = buildCdf(0.7, 0.3);
final double probStart = 0.5;

View File

@@ -21,6 +21,7 @@ import static com.android.server.job.JobConcurrencyManager.WORK_TYPE_BGUSER_IMPO
import static com.android.server.job.JobConcurrencyManager.WORK_TYPE_EJ;
import static com.android.server.job.JobConcurrencyManager.WORK_TYPE_FGS;
import static com.android.server.job.JobConcurrencyManager.WORK_TYPE_TOP;
import static com.android.server.job.JobConcurrencyManager.WORK_TYPE_UI;
import static com.android.server.job.JobConcurrencyManager.workTypeToString;
import static org.junit.Assert.assertEquals;
@@ -47,6 +48,7 @@ public class WorkTypeConfigTest {
private static final String KEY_MAX_TOTAL = "concurrency_max_total_test";
private static final String KEY_MAX_RATIO_TOP = "concurrency_max_ratio_top_test";
private static final String KEY_MAX_RATIO_FGS = "concurrency_max_ratio_fgs_test";
private static final String KEY_MAX_RATIO_UI = "concurrency_max_ratio_ui_test";
private static final String KEY_MAX_RATIO_EJ = "concurrency_max_ratio_ej_test";
private static final String KEY_MAX_RATIO_BG = "concurrency_max_ratio_bg_test";
private static final String KEY_MAX_RATIO_BGUSER_IMPORTANT =
@@ -54,6 +56,7 @@ public class WorkTypeConfigTest {
private static final String KEY_MAX_RATIO_BGUSER = "concurrency_max_ratio_bguser_test";
private static final String KEY_MIN_RATIO_TOP = "concurrency_min_ratio_top_test";
private static final String KEY_MIN_RATIO_FGS = "concurrency_min_ratio_fgs_test";
private static final String KEY_MIN_RATIO_UI = "concurrency_min_ratio_ui_test";
private static final String KEY_MIN_RATIO_EJ = "concurrency_min_ratio_ej_test";
private static final String KEY_MIN_RATIO_BG = "concurrency_min_ratio_bg_test";
private static final String KEY_MIN_RATIO_BGUSER_IMPORTANT =
@@ -326,31 +329,35 @@ public class WorkTypeConfigTest {
/* max */ List.of(Pair.create(WORK_TYPE_TOP, 16), Pair.create(WORK_TYPE_BG, 16)));
check(new DeviceConfig.Properties.Builder(DeviceConfig.NAMESPACE_JOB_SCHEDULER)
.setInt(KEY_MAX_TOTAL, 16)
.setInt(KEY_MAX_TOTAL, 32)
.setFloat(KEY_MAX_RATIO_TOP, 1f)
.setFloat(KEY_MIN_RATIO_TOP, 1.0f / 16)
.setFloat(KEY_MAX_RATIO_FGS, 15.0f / 16)
.setFloat(KEY_MIN_RATIO_FGS, 2.0f / 16)
.setFloat(KEY_MAX_RATIO_EJ, 14.0f / 16)
.setFloat(KEY_MIN_RATIO_EJ, 3.0f / 16)
.setFloat(KEY_MAX_RATIO_BG, 13.0f / 16)
.setFloat(KEY_MIN_RATIO_BG, 3.0f / 16)
.setFloat(KEY_MAX_RATIO_BGUSER_IMPORTANT, 12.0f / 16)
.setFloat(KEY_MIN_RATIO_BGUSER_IMPORTANT, 2.0f / 16)
.setFloat(KEY_MAX_RATIO_BGUSER, 11.0f / 16)
.setFloat(KEY_MIN_RATIO_BGUSER, 2.0f / 16)
.setFloat(KEY_MIN_RATIO_TOP, 1.0f / 32)
.setFloat(KEY_MAX_RATIO_FGS, 15.0f / 32)
.setFloat(KEY_MIN_RATIO_FGS, 2.0f / 32)
.setFloat(KEY_MAX_RATIO_UI, 10.0f / 32)
.setFloat(KEY_MIN_RATIO_UI, 4.0f / 32)
.setFloat(KEY_MAX_RATIO_EJ, 14.0f / 32)
.setFloat(KEY_MIN_RATIO_EJ, 3.0f / 32)
.setFloat(KEY_MAX_RATIO_BG, 13.0f / 32)
.setFloat(KEY_MIN_RATIO_BG, 3.0f / 32)
.setFloat(KEY_MAX_RATIO_BGUSER_IMPORTANT, 12.0f / 32)
.setFloat(KEY_MIN_RATIO_BGUSER_IMPORTANT, 2.0f / 32)
.setFloat(KEY_MAX_RATIO_BGUSER, 11.0f / 32)
.setFloat(KEY_MIN_RATIO_BGUSER, 2.0f / 32)
.build(),
/* limit */ 16,
/* limit */ 32,
/*default*/ 9,
/* min */ List.of(Pair.create(WORK_TYPE_BG, .99f)),
/* max */ List.of(Pair.create(WORK_TYPE_BG, 1f)),
/*expected*/ true, 16,
/*expected*/ true, 32,
/* min */ List.of(Pair.create(WORK_TYPE_TOP, 1), Pair.create(WORK_TYPE_FGS, 2),
Pair.create(WORK_TYPE_UI, 4),
Pair.create(WORK_TYPE_EJ, 3), Pair.create(WORK_TYPE_BG, 3),
Pair.create(WORK_TYPE_BGUSER_IMPORTANT, 2),
Pair.create(WORK_TYPE_BGUSER, 2)),
/* max */
List.of(Pair.create(WORK_TYPE_TOP, 16), Pair.create(WORK_TYPE_FGS, 15),
List.of(Pair.create(WORK_TYPE_TOP, 32), Pair.create(WORK_TYPE_FGS, 15),
Pair.create(WORK_TYPE_UI, 10),
Pair.create(WORK_TYPE_EJ, 14), Pair.create(WORK_TYPE_BG, 13),
Pair.create(WORK_TYPE_BGUSER_IMPORTANT, 12),
Pair.create(WORK_TYPE_BGUSER, 11)));