summaryrefslogtreecommitdiff
path: root/services/java
diff options
context:
space:
mode:
author Jared Duke <jdduke@google.com> 2025-02-05 23:32:46 +0000
committer Jared Duke <jdduke@google.com> 2025-02-08 23:51:48 +0000
commitd3cff499871ae6e90037b1592d1ea73efa22c96d (patch)
treec3490221f9938c5c196ecb0d6e8939e38e0f2ed6 /services/java
parent62bf135d822cac371f089ba0b5c5c896c71caf3c (diff)
Start SystemConfig parsing before loading libandroid_servers
SystemConfig parsing can be expensive (>100ms), and is currently queued to a worker thread to avoid blocking the main system server thread during init. However, it's often needed before parsing is finished, so the main thread bottlenecks anyway. Move the async parsing trigger to *before* the native library loading of libandroid_servers. This should be safe as SystemConfig relies on only basic APIs that shouldn't need the system server native lib to complete. On low-end devices, this can reduce boot times by ~500ms. On more recent flagship devices, this can reduce boot times by ~100ms. Bug: 383869534 Test: presubmit + boot Flag: android.server.early_systemconfig_init Change-Id: Iaf8a09316715a0b31512fdcffca11db1e232beea
Diffstat (limited to 'services/java')
-rw-r--r--services/java/com/android/server/SystemServer.java32
1 files changed, 24 insertions, 8 deletions
diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java
index 7972d9c6fba3..e4ab7685d787 100644
--- a/services/java/com/android/server/SystemServer.java
+++ b/services/java/com/android/server/SystemServer.java
@@ -875,6 +875,17 @@ public final class SystemServer implements Dumpable {
SystemServiceRegistry.sEnableServiceNotFoundWtf = true;
+ // Prepare the thread pool for init tasks that can be parallelized
+ SystemServerInitThreadPool tp = SystemServerInitThreadPool.start();
+ mDumper.addDumpable(tp);
+
+ if (android.server.Flags.earlySystemConfigInit()) {
+ // SystemConfig init is expensive, so enqueue the work as early as possible to allow
+ // concurrent execution before it's needed (typically by ActivityManagerService).
+ // As native library loading is also expensive, this is a good place to start.
+ startSystemConfigInit(t);
+ }
+
// Initialize native services.
System.loadLibrary("android_servers");
@@ -907,9 +918,6 @@ public final class SystemServer implements Dumpable {
mDumper.addDumpable(mSystemServiceManager);
LocalServices.addService(SystemServiceManager.class, mSystemServiceManager);
- // Prepare the thread pool for init tasks that can be parallelized
- SystemServerInitThreadPool tp = SystemServerInitThreadPool.start();
- mDumper.addDumpable(tp);
// Lazily load the pre-installed system font map in SystemServer only if we're not doing
// the optimized font loading in the FontManagerService.
@@ -1057,6 +1065,14 @@ public final class SystemServer implements Dumpable {
}
}
+ private void startSystemConfigInit(TimingsTraceAndSlog t) {
+ Slog.i(TAG, "Reading configuration...");
+ final String tagSystemConfig = "ReadingSystemConfig";
+ t.traceBegin(tagSystemConfig);
+ SystemServerInitThreadPool.submit(SystemConfig::getInstance, tagSystemConfig);
+ t.traceEnd();
+ }
+
private void createSystemContext() {
ActivityThread activityThread = ActivityThread.systemMain();
mSystemContext = activityThread.getSystemContext();
@@ -1095,11 +1111,11 @@ public final class SystemServer implements Dumpable {
mDumper.addDumpable(watchdog);
t.traceEnd();
- Slog.i(TAG, "Reading configuration...");
- final String TAG_SYSTEM_CONFIG = "ReadingSystemConfig";
- t.traceBegin(TAG_SYSTEM_CONFIG);
- SystemServerInitThreadPool.submit(SystemConfig::getInstance, TAG_SYSTEM_CONFIG);
- t.traceEnd();
+ // Legacy entry point for starting SystemConfig init, only needed if the early init flag is
+ // disabled and we haven't already triggered init before bootstrap services.
+ if (!android.server.Flags.earlySystemConfigInit()) {
+ startSystemConfigInit(t);
+ }
// Orchestrates some ProtoLogging functionality.
if (android.tracing.Flags.clientSideProtoLogging()) {