Small JS code cleanup.

1. `cat /proc/<pid>/cpuset` returns "background" for EJs, which implies
   they'll run on little cores
2. Added some annotations
3. Removed specialized method in favor of generic method.

Bug: 141645789
Bug: 171305774
Test: Android builds
Change-Id: I4b6a5776eddbcec1bc28ebbd0ba38577ba3a93c3
This commit is contained in:
Kweku Adams
2021-03-04 11:10:28 -08:00
parent 1fd830ffe4
commit 0ce0c5e4cb
2 changed files with 18 additions and 18 deletions

View File

@@ -25,6 +25,7 @@ import android.app.ActivityManager;
import android.app.ActivityManagerInternal;
import android.app.UserSwitchObserver;
import android.app.job.JobInfo;
import android.app.job.JobParameters;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -469,7 +470,7 @@ class JobConcurrencyManager {
// Update the priorities of jobs that aren't running, and also count the pending work types.
// Do this before the following loop to hopefully reduce the cost of
// shouldStopRunningJobLocked().
updateNonRunningPriorities(pendingJobs, true);
updateNonRunningPrioritiesLocked(pendingJobs, true);
for (int i = 0; i < MAX_JOB_CONTEXTS_COUNT; i++) {
final JobServiceContext js = activeServices.get(i);
@@ -585,7 +586,8 @@ class JobConcurrencyManager {
+ activeServices.get(i).getRunningJobLocked());
}
// preferredUid will be set to uid of currently running job.
activeServices.get(i).preemptExecutingJobLocked(preemptReasonForContext[i]);
activeServices.get(i).cancelExecutingJobLocked(
JobParameters.REASON_PREEMPT, preemptReasonForContext[i]);
preservePreferredUid = true;
} else {
final JobStatus pendingJob = contextIdToJobMap[i];
@@ -610,7 +612,8 @@ class JobConcurrencyManager {
mWorkCountTracker.getRunningJobCount(WORK_TYPE_TOP));
}
private void updateNonRunningPriorities(@NonNull final List<JobStatus> pendingJobs,
@GuardedBy("mLock")
private void updateNonRunningPrioritiesLocked(@NonNull final List<JobStatus> pendingJobs,
boolean updateCounter) {
for (int i = 0; i < pendingJobs.size(); i++) {
final JobStatus pending = pendingJobs.get(i);
@@ -628,6 +631,7 @@ class JobConcurrencyManager {
}
}
@GuardedBy("mLock")
private void startJobLocked(@NonNull JobServiceContext worker, @NonNull JobStatus jobStatus,
@WorkType final int workType) {
final List<StateController> controllers = mService.mControllers;
@@ -647,6 +651,7 @@ class JobConcurrencyManager {
}
}
@GuardedBy("mLock")
void onJobCompletedLocked(@NonNull JobServiceContext worker, @NonNull JobStatus jobStatus,
@WorkType final int workType) {
mWorkCountTracker.onJobFinished(workType);
@@ -655,7 +660,7 @@ class JobConcurrencyManager {
if (worker.getPreferredUid() != JobServiceContext.NO_PREFERRED_UID) {
updateCounterConfigLocked();
// Preemption case needs special care.
updateNonRunningPriorities(pendingJobs, false);
updateNonRunningPrioritiesLocked(pendingJobs, false);
JobStatus highestPriorityJob = null;
int highPriWorkType = workType;
@@ -726,7 +731,7 @@ class JobConcurrencyManager {
}
} else if (pendingJobs.size() > 0) {
updateCounterConfigLocked();
updateNonRunningPriorities(pendingJobs, false);
updateNonRunningPrioritiesLocked(pendingJobs, false);
// This slot is now free and we have pending jobs. Start the highest priority job we
// find.
@@ -775,6 +780,7 @@ class JobConcurrencyManager {
* another job to run, or if system state suggests the job should stop.
*/
@Nullable
@GuardedBy("mLock")
String shouldStopRunningJobLocked(@NonNull JobServiceContext context) {
final JobStatus js = context.getRunningJobLocked();
if (js == null) {
@@ -881,6 +887,7 @@ class JobConcurrencyManager {
return s.toString();
}
@GuardedBy("mLock")
void updateConfigLocked() {
DeviceConfig.Properties properties =
DeviceConfig.getProperties(DeviceConfig.NAMESPACE_JOB_SCHEDULER);

View File

@@ -269,8 +269,6 @@ public final class JobServiceContext implements ServiceConnection {
try {
final int bindFlags;
if (job.shouldTreatAsExpeditedJob()) {
// TODO(171305774): The job should run on the little cores. We'll probably need
// another binding flag for that.
bindFlags = Context.BIND_AUTO_CREATE | Context.BIND_NOT_FOREGROUND
| Context.BIND_ALMOST_PERCEPTIBLE
| Context.BIND_ALLOW_NETWORK_ACCESS;
@@ -353,15 +351,10 @@ public final class JobServiceContext implements ServiceConnection {
/** Called externally when a job that was scheduled for execution should be cancelled. */
@GuardedBy("mLock")
void cancelExecutingJobLocked(int reason, String debugReason) {
void cancelExecutingJobLocked(int reason, @NonNull String debugReason) {
doCancelLocked(reason, debugReason);
}
@GuardedBy("mLock")
void preemptExecutingJobLocked(@NonNull String reason) {
doCancelLocked(JobParameters.REASON_PREEMPT, reason);
}
int getPreferredUid() {
return mPreferredUid;
}
@@ -618,7 +611,7 @@ public final class JobServiceContext implements ServiceConnection {
}
@GuardedBy("mLock")
private void doCancelLocked(int stopReasonCode, String debugReason) {
private void doCancelLocked(int stopReasonCode, @Nullable String debugReason) {
if (mVerb == VERB_FINISHED) {
if (DEBUG) {
Slog.d(TAG,
@@ -731,7 +724,7 @@ public final class JobServiceContext implements ServiceConnection {
* _ENDING -> No point in doing anything here, so we ignore.
*/
@GuardedBy("mLock")
private void handleCancelLocked(String reason) {
private void handleCancelLocked(@Nullable String reason) {
if (JobSchedulerService.DEBUG) {
Slog.d(TAG, "Handling cancel for: " + mRunningJob.getJobId() + " "
+ VERB_STRINGS[mVerb]);
@@ -815,7 +808,7 @@ public final class JobServiceContext implements ServiceConnection {
* VERB_STOPPING.
*/
@GuardedBy("mLock")
private void sendStopMessageLocked(String reason) {
private void sendStopMessageLocked(@Nullable String reason) {
removeOpTimeOutLocked();
if (mVerb != VERB_EXECUTING) {
Slog.e(TAG, "Sending onStopJob for a job that isn't started. " + mRunningJob);
@@ -841,7 +834,7 @@ public final class JobServiceContext implements ServiceConnection {
* we want to clean up internally.
*/
@GuardedBy("mLock")
private void closeAndCleanupJobLocked(boolean reschedule, String reason) {
private void closeAndCleanupJobLocked(boolean reschedule, @Nullable String reason) {
final JobStatus completedJob;
if (mVerb == VERB_FINISHED) {
return;
@@ -886,7 +879,7 @@ public final class JobServiceContext implements ServiceConnection {
mJobConcurrencyManager.onJobCompletedLocked(this, completedJob, workType);
}
private void applyStoppedReasonLocked(String reason) {
private void applyStoppedReasonLocked(@Nullable String reason) {
if (reason != null && mStoppedReason == null) {
mStoppedReason = reason;
mStoppedTime = sElapsedRealtimeClock.millis();