diff options
author | Kweku Adams <kwekua@google.com> | 2023-11-29 20:56:29 +0000 |
---|---|---|
committer | Kweku Adams <kwekua@google.com> | 2023-11-29 20:56:29 +0000 |
commit | 2d0db1b3ba957b6c0ffecee7ec4fdeac6edbf1c5 (patch) | |
tree | 1c9e6c5d865b27e93d3d68439d6505c4de51536f /apex | |
parent | 418c3175124fabeb9479b1911a65391657aff3a2 (diff) | |
download | base-2d0db1b3ba957b6c0ffecee7ec4fdeac6edbf1c5.tar.gz |
Avoid doubly penalizing rescheduled periodic jobs for flex.
Periodic jobs that were completed successfully and rescheduled sometimes
have adjusted start times to avoid running them back to back. When this
happens, make sure the flex logic takes the adjustment into account and
doesn't delay the constraint drops too significantly.
Bug: 236261941
Test: atest FrameworksMockingServicesTests:FlexibilityControllerTest
Change-Id: I039f86a409754089c7592719e0fd3355d6883cfb
Diffstat (limited to 'apex')
-rw-r--r-- | apex/jobscheduler/service/java/com/android/server/job/controllers/FlexibilityController.java | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/apex/jobscheduler/service/java/com/android/server/job/controllers/FlexibilityController.java b/apex/jobscheduler/service/java/com/android/server/job/controllers/FlexibilityController.java index fed3c42ab87f..a900d162ab96 100644 --- a/apex/jobscheduler/service/java/com/android/server/job/controllers/FlexibilityController.java +++ b/apex/jobscheduler/service/java/com/android/server/job/controllers/FlexibilityController.java @@ -369,8 +369,23 @@ public final class FlexibilityController extends StateController { @VisibleForTesting @GuardedBy("mLock") long getLifeCycleBeginningElapsedLocked(JobStatus js) { + long earliestRuntime = js.getEarliestRunTime() == JobStatus.NO_EARLIEST_RUNTIME + ? js.enqueueTime : js.getEarliestRunTime(); + if (js.getJob().isPeriodic() && js.getNumPreviousAttempts() == 0) { + // Rescheduling periodic jobs (after a successful execution) may result in the job's + // start time being a little after the "true" periodic start time (to avoid jobs + // running back to back). See JobSchedulerService#getRescheduleJobForPeriodic for more + // details. Since rescheduled periodic jobs may already be delayed slightly by this + // policy, don't penalize them further by then enforcing the full set of applied + // flex constraints at the beginning of the newly determined start time. Let the flex + // constraint requirement start closer to the true periodic start time. + final long truePeriodicStartTimeElapsed = + js.getLatestRunTimeElapsed() - js.getJob().getFlexMillis(); + // For now, treat the lifecycle beginning as the midpoint between the true periodic + // start time and the adjusted start time. + earliestRuntime = (earliestRuntime + truePeriodicStartTimeElapsed) / 2; + } if (js.getJob().isPrefetch()) { - final long earliestRuntime = Math.max(js.enqueueTime, js.getEarliestRunTime()); final long estimatedLaunchTime = mPrefetchController.getNextEstimatedLaunchTimeLocked(js); long prefetchWindowStart = mPrefetchLifeCycleStart.getOrDefault( @@ -381,8 +396,7 @@ public final class FlexibilityController extends StateController { } return Math.max(prefetchWindowStart, earliestRuntime); } - return js.getEarliestRunTime() == JobStatus.NO_EARLIEST_RUNTIME - ? js.enqueueTime : js.getEarliestRunTime(); + return earliestRuntime; } @VisibleForTesting |