diff options
| author | 2016-03-01 23:30:10 +0000 | |
|---|---|---|
| committer | 2016-03-01 23:30:10 +0000 | |
| commit | bbc300c4c59ebf9541f04c67bdff0c257c43805d (patch) | |
| tree | 8389e1b870715b97e0ddab370c6afd9b6cc874f7 | |
| parent | 31b743106d8654bcdf39e4f638f4591eb5d7fb78 (diff) | |
| parent | 9e927f57415372591bab2a5c7af2520204902ca4 (diff) | |
Merge "Lower JIT thread priority"
| -rw-r--r-- | runtime/jit/jit_instrumentation.cc | 4 | ||||
| -rw-r--r-- | runtime/thread_pool.cc | 24 | ||||
| -rw-r--r-- | runtime/thread_pool.h | 6 |
3 files changed, 34 insertions, 0 deletions
diff --git a/runtime/jit/jit_instrumentation.cc b/runtime/jit/jit_instrumentation.cc index a4e40ad3fd..46c362ac62 100644 --- a/runtime/jit/jit_instrumentation.cc +++ b/runtime/jit/jit_instrumentation.cc @@ -25,6 +25,9 @@ namespace art { namespace jit { +// At what priority to schedule jit threads. 9 is the lowest foreground priority on device. +static constexpr int kJitPoolThreadPthreadPriority = 9; + class JitCompileTask FINAL : public Task { public: enum TaskKind { @@ -92,6 +95,7 @@ void JitInstrumentationCache::CreateThreadPool() { // There is a DCHECK in the 'AddSamples' method to ensure the tread pool // is not null when we instrument. thread_pool_.reset(new ThreadPool("Jit thread pool", 1)); + thread_pool_->SetPthreadPriority(kJitPoolThreadPthreadPriority); thread_pool_->StartWorkers(Thread::Current()); { // Add Jit interpreter instrumentation, tells the interpreter when diff --git a/runtime/thread_pool.cc b/runtime/thread_pool.cc index 5a4dfb8cfd..2fba805fa2 100644 --- a/runtime/thread_pool.cc +++ b/runtime/thread_pool.cc @@ -16,6 +16,11 @@ #include "thread_pool.h" +#include <pthread.h> + +#include <sys/time.h> +#include <sys/resource.h> + #include "base/bit_utils.h" #include "base/casts.h" #include "base/logging.h" @@ -53,6 +58,19 @@ ThreadPoolWorker::~ThreadPoolWorker() { CHECK_PTHREAD_CALL(pthread_join, (pthread_, nullptr), "thread pool worker shutdown"); } +void ThreadPoolWorker::SetPthreadPriority(int priority) { + CHECK_GE(priority, PRIO_MIN); + CHECK_LE(priority, PRIO_MAX); +#if defined(__ANDROID__) + int result = setpriority(PRIO_PROCESS, pthread_gettid_np(pthread_), priority); + if (result != 0) { + PLOG(ERROR) << "Failed to setpriority to :" << priority; + } +#else + UNUSED(priority); +#endif +} + void ThreadPoolWorker::Run() { Thread* self = Thread::Current(); Task* task = nullptr; @@ -214,4 +232,10 @@ size_t ThreadPool::GetTaskCount(Thread* self) { return tasks_.size(); } +void ThreadPool::SetPthreadPriority(int priority) { + for (ThreadPoolWorker* worker : threads_) { + worker->SetPthreadPriority(priority); + } +} + } // namespace art diff --git a/runtime/thread_pool.h b/runtime/thread_pool.h index 6cd4ad3cdc..b6c6f02db8 100644 --- a/runtime/thread_pool.h +++ b/runtime/thread_pool.h @@ -59,6 +59,9 @@ class ThreadPoolWorker { virtual ~ThreadPoolWorker(); + // Set the "nice" priorty for this worker. + void SetPthreadPriority(int priority); + protected: ThreadPoolWorker(ThreadPool* thread_pool, const std::string& name, size_t stack_size); static void* Callback(void* arg) REQUIRES(!Locks::mutator_lock_); @@ -111,6 +114,9 @@ class ThreadPool { // thread count of the thread pool. void SetMaxActiveWorkers(size_t threads) REQUIRES(!task_queue_lock_); + // Set the "nice" priorty for threads in the pool. + void SetPthreadPriority(int priority); + protected: // get a task to run, blocks if there are no tasks left virtual Task* GetTask(Thread* self) REQUIRES(!task_queue_lock_); |