summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Vitalii Tomkiv <vitalit@google.com> 2016-05-18 17:43:02 -0700
committer Andreas Gampe <agampe@google.com> 2016-12-16 09:06:28 -0800
commit1e52ce48a6f2d98485d18585eb3452cab050ffb7 (patch)
treececc95066a04a4fa7542e8120bbe5fdee087661e
parent8175f0955aed5bd7a3aa80ac6348bdecb46db915 (diff)
Make sure Zygote is running at process priority 0 after VM has started.
Boosting up zygote priority before VM startup, saves ~450ms of boot time for N9, 180ms for Nexus 5X. (cherry picked from commit 5d551a5ac3d13706f62a86842ff6851e1d25213b) Bug: 28866384 Test: m Test: Device boots Change-Id: Ic85892b408e15bbc1de7ce706f113f23974fe478
-rw-r--r--core/jni/com_android_internal_os_Zygote.cpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/core/jni/com_android_internal_os_Zygote.cpp b/core/jni/com_android_internal_os_Zygote.cpp
index 9c74d9a15e99..fec8f4e39efb 100644
--- a/core/jni/com_android_internal_os_Zygote.cpp
+++ b/core/jni/com_android_internal_os_Zygote.cpp
@@ -37,6 +37,7 @@
#include <sys/prctl.h>
#include <sys/resource.h>
#include <sys/stat.h>
+#include <sys/time.h>
#include <sys/types.h>
#include <sys/utsname.h>
#include <sys/wait.h>
@@ -153,6 +154,24 @@ static void SetSigChldHandler() {
}
}
+// Resets nice priority for zygote process. Zygote priority can be set
+// to high value during boot phase to speed it up. We want to ensure
+// zygote is running at normal priority before childs are forked from it.
+//
+// This ends up being called repeatedly before each fork(), but there's
+// no real harm in that.
+static void ResetNicePriority(JNIEnv* env) {
+ errno = 0;
+ int prio = getpriority(PRIO_PROCESS, 0);
+ if (prio == -1 && errno != 0) {
+ ALOGW("getpriority failed: %s\n", strerror(errno));
+ }
+ if (prio != 0 && setpriority(PRIO_PROCESS, 0, 0) != 0) {
+ ALOGE("setpriority(%d, 0, 0) failed: %s", PRIO_PROCESS, strerror(errno));
+ RuntimeAbort(env, __LINE__, "setpriority failed");
+ }
+}
+
// Sets the SIGCHLD handler back to default behavior in zygote children.
static void UnsetSigChldHandler() {
struct sigaction sa;
@@ -447,6 +466,8 @@ static pid_t ForkAndSpecializeCommon(JNIEnv* env, uid_t uid, gid_t gid, jintArra
RuntimeAbort(env, __LINE__, "Unable to restat file descriptor table.");
}
+ ResetNicePriority(env);
+
pid_t pid = fork();
if (pid == 0) {
@@ -719,4 +740,3 @@ int register_com_android_internal_os_Zygote(JNIEnv* env) {
return RegisterMethodsOrDie(env, "com/android/internal/os/Zygote", gMethods, NELEM(gMethods));
}
} // namespace android
-