| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/threading/platform_thread.h" | 5 #include "base/threading/platform_thread.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <sys/prctl.h> | 9 #include <sys/prctl.h> |
| 10 #include <sys/resource.h> | 10 #include <sys/resource.h> |
| 11 #include <sys/types.h> | 11 #include <sys/types.h> |
| 12 #include <unistd.h> | 12 #include <unistd.h> |
| 13 | 13 |
| 14 #include "base/android/jni_android.h" | 14 #include "base/android/jni_android.h" |
| 15 #include "base/android/thread_utils.h" | 15 #include "base/android/thread_utils.h" |
| 16 #include "base/lazy_instance.h" | 16 #include "base/lazy_instance.h" |
| 17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/threading/platform_thread_internal_posix.h" | 18 #include "base/threading/platform_thread_internal_posix.h" |
| 19 #include "base/threading/thread_id_name_manager.h" | 19 #include "base/threading/thread_id_name_manager.h" |
| 20 #include "base/tracked_objects.h" | 20 #include "base/tracked_objects.h" |
| 21 #include "jni/ThreadUtils_jni.h" | 21 #include "jni/ThreadUtils_jni.h" |
| 22 | 22 |
| 23 namespace base { | 23 namespace base { |
| 24 | 24 |
| 25 namespace internal { | 25 namespace internal { |
| 26 | 26 |
| 27 // - BACKGROUND is 9 due to it being the nicest value we can use that's still | 27 // - BACKGROUND corresponds to Android's PRIORITY_BACKGROUND = 10 value and can |
| 28 // above an Android system threshold that enables heavy throttling starting at | 28 // result in heavy throttling and force the thread onto a little core on |
| 29 // 10; we want to be lower-priority than Chrome's other threads without | 29 // big.LITTLE devices. |
| 30 // incurring this behavior. | |
| 31 // - DISPLAY corresponds to Android's PRIORITY_DISPLAY = -4 value. | 30 // - DISPLAY corresponds to Android's PRIORITY_DISPLAY = -4 value. |
| 32 // - REALTIME_AUDIO corresponds to Android's THREAD_PRIORITY_AUDIO = -16 value. | 31 // - REALTIME_AUDIO corresponds to Android's PRIORITY_AUDIO = -16 value. |
| 33 const ThreadPriorityToNiceValuePair kThreadPriorityToNiceValueMap[4] = { | 32 const ThreadPriorityToNiceValuePair kThreadPriorityToNiceValueMap[4] = { |
| 34 {ThreadPriority::BACKGROUND, 9}, | 33 {ThreadPriority::BACKGROUND, 10}, |
| 35 {ThreadPriority::NORMAL, 0}, | 34 {ThreadPriority::NORMAL, 0}, |
| 36 {ThreadPriority::DISPLAY, -4}, | 35 {ThreadPriority::DISPLAY, -4}, |
| 37 {ThreadPriority::REALTIME_AUDIO, -16}, | 36 {ThreadPriority::REALTIME_AUDIO, -16}, |
| 38 }; | 37 }; |
| 39 | 38 |
| 40 bool SetCurrentThreadPriorityForPlatform(ThreadPriority priority) { | 39 bool SetCurrentThreadPriorityForPlatform(ThreadPriority priority) { |
| 41 // On Android, we set the Audio priority through JNI as Audio priority | 40 // On Android, we set the Audio priority through JNI as Audio priority |
| 42 // will also allow the process to run while it is backgrounded. | 41 // will also allow the process to run while it is backgrounded. |
| 43 if (priority == ThreadPriority::REALTIME_AUDIO) { | 42 if (priority == ThreadPriority::REALTIME_AUDIO) { |
| 44 JNIEnv* env = base::android::AttachCurrentThread(); | 43 JNIEnv* env = base::android::AttachCurrentThread(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 // 1Mb is not enough for some tests (see http://crbug.com/263749 for example). | 94 // 1Mb is not enough for some tests (see http://crbug.com/263749 for example). |
| 96 return 2 * (1 << 20); // 2Mb | 95 return 2 * (1 << 20); // 2Mb |
| 97 #endif | 96 #endif |
| 98 } | 97 } |
| 99 | 98 |
| 100 bool RegisterThreadUtils(JNIEnv* env) { | 99 bool RegisterThreadUtils(JNIEnv* env) { |
| 101 return RegisterNativesImpl(env); | 100 return RegisterNativesImpl(env); |
| 102 } | 101 } |
| 103 | 102 |
| 104 } // namespace base | 103 } // namespace base |
| OLD | NEW |