diff options
author | 2024-05-20 17:25:55 -0700 | |
---|---|---|
committer | 2024-05-22 15:25:52 +0000 | |
commit | 1495449f61fc77749b004b1400107d8027b3c4f5 (patch) | |
tree | dbbbf4676f99d1b215f7b6f655da7b3626ab8637 | |
parent | db0551d164783866acf0cdcf9a7741ee6f21f0f2 (diff) |
JIT thread priority adjustments
1) Raise the priority of exiting JIT pool threads so that the zygote
does not have to wait long for them.
2) Slightly lower the priority of the BootImagePollingThread, so that
it can benefit from a longer suspend timeout in SuspendAll.
Bug: 337585993
Bug: 310106506
Test: mainly Treehuuger
Change-Id: Id5067a81b0b20084b1120422eb8515d4547ccee9
-rw-r--r-- | runtime/jit/jit.cc | 8 | ||||
-rw-r--r-- | runtime/thread_pool.cc | 18 |
2 files changed, 23 insertions, 3 deletions
diff --git a/runtime/jit/jit.cc b/runtime/jit/jit.cc index cb80b4151d..4d395c8528 100644 --- a/runtime/jit/jit.cc +++ b/runtime/jit/jit.cc @@ -17,6 +17,7 @@ #include "jit.h" #include <dlfcn.h> +#include <sys/resource.h> #include "art_method-inl.h" #include "base/file_utils.h" @@ -1487,6 +1488,13 @@ static void* RunPollingThread(void* arg) { /* create_peer= */ false); CHECK(thread_attached); + if (getpriority(PRIO_PROCESS, 0 /* this thread */) == 0) { + // Slightly reduce thread priority, mostly so the suspend logic notices that we're + // not a high priority thread, and can time out more slowly. May fail on host. + (void)setpriority(PRIO_PROCESS, 0 /* this thread */, 1); + } else { + PLOG(ERROR) << "Unexpected BootImagePollingThread priority: " << getpriority(PRIO_PROCESS, 0); + } { // Prevent other threads from running while we are remapping the boot image // ArtMethod's. Native threads might still be running, but they cannot diff --git a/runtime/thread_pool.cc b/runtime/thread_pool.cc index f0ea078cdc..a7c2cd1286 100644 --- a/runtime/thread_pool.cc +++ b/runtime/thread_pool.cc @@ -86,14 +86,22 @@ ThreadPoolWorker::~ThreadPoolWorker() { CHECK_PTHREAD_CALL(pthread_join, (pthread_, nullptr), "thread pool worker shutdown"); } -void ThreadPoolWorker::SetPthreadPriority(int priority) { +// Set the "nice" priority for tid (0 means self). +static void SetPriorityForTid(pid_t tid, int priority) { CHECK_GE(priority, PRIO_MIN); CHECK_LE(priority, PRIO_MAX); -#if defined(ART_TARGET_ANDROID) - int result = setpriority(PRIO_PROCESS, pthread_gettid_np(pthread_), priority); + int result = setpriority(PRIO_PROCESS, tid, priority); if (result != 0) { +#if defined(ART_TARGET_ANDROID) PLOG(ERROR) << "Failed to setpriority to :" << priority; +#endif + // Setpriority may fail on host due to ulimit issues. } +} + +void ThreadPoolWorker::SetPthreadPriority(int priority) { +#if defined(ART_TARGET_ANDROID) + SetPriorityForTid(pthread_gettid_np(pthread_), priority); #else UNUSED(priority); #endif @@ -144,6 +152,10 @@ void* ThreadPoolWorker::Callback(void* arg) { // Do work until its time to shut down. worker->Run(); runtime->DetachCurrentThread(/* should_run_callbacks= */ false); + // On zygote fork, we wait for this thread to exit completely. Set to highest Java priority + // to speed that up. + constexpr int kJavaMaxPrioNiceness = -8; + SetPriorityForTid(0 /* this thread */, kJavaMaxPrioNiceness); return nullptr; } |