Populate active apexes cache in a background thread

* Split populateActivePackagesCacheIfNeeded into populateApexFilesCache
  and parseApexFiles.
* populateApexFilesCache does an IPC to apexd , while parseApexFiles
  does the heavy lifting of parsing apex files and extracting signature;
* Split is required because during PackageManagerService boot-sequence
  we need to know list of apex packages, and in order to get that
  information we don't need to parse apex files.
* Both populateApexFilesCache and parseApexFiles are enquened to run in
  ApexManagers own HandlerThread so that they don't block other tasks in
  system servers boot sequence.
* Changed ApexManager to use CountDownLatches instead of locks to
  synchronize between thread, as they are more modern and easier to use.

Also did some perf testing on blueline by running
atest google/perf/boottime/boottime-test:

Without https://googleplex-android-review.git.corp.google.com/q/Ic7e5e14ed2d02d3685fd39bb70bc9423ae78f18e:
SystemServerTiming_StartPackageManagerService_avg: 2767.2

With what is currently in qt-dev:
SystemServerTiming_StartPackageManagerService_avg: 3728.4444444444443

Without splitting into populateApexFilesCache and parseApexFiles:
SystemServerTiming_StartPackageManagerService_avg: 3247.5

This change:
SystemServerTiming_StartPackageManagerService_avg: 2894.7

Test: device boots
Test: atest CtsStagedInstallHostTestCases
Bug: 131611765
Change-Id: I980700cd785c22d7f1ace294bb5456056d68baaa
This commit is contained in:
Nikita Ioffe
2019-04-29 21:14:06 +01:00
parent ca9056eb66
commit 97fc6d9c29
3 changed files with 118 additions and 57 deletions

View File

@@ -115,6 +115,7 @@ import com.android.server.om.OverlayManagerService;
import com.android.server.os.BugreportManagerService;
import com.android.server.os.DeviceIdentifiersPolicyService;
import com.android.server.os.SchedulingPolicyService;
import com.android.server.pm.ApexManager;
import com.android.server.pm.BackgroundDexOptService;
import com.android.server.pm.CrossProfileAppsService;
import com.android.server.pm.DynamicCodeLoggingService;
@@ -627,6 +628,12 @@ public final class SystemServer {
watchdog.start();
traceEnd();
// Start ApexManager as early as we can to give it enough time to call apexd and populate
// cache of known apex packages. Note that calling apexd will happen asynchronously.
traceBeginAndSlog("StartApexManager");
mSystemServiceManager.startService(ApexManager.class);
traceEnd();
Slog.i(TAG, "Reading configuration...");
final String TAG_SYSTEM_CONFIG = "ReadingSystemConfig";
traceBeginAndSlog(TAG_SYSTEM_CONFIG);