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 <sys/prctl.h> | 8 #include <sys/prctl.h> |
9 #include <sys/resource.h> | 9 #include <sys/resource.h> |
10 #include <sys/types.h> | 10 #include <sys/types.h> |
11 #include <unistd.h> | 11 #include <unistd.h> |
12 | 12 |
13 #include "base/android/jni_android.h" | 13 #include "base/android/jni_android.h" |
14 #include "base/android/thread_utils.h" | 14 #include "base/android/thread_utils.h" |
15 #include "base/lazy_instance.h" | 15 #include "base/lazy_instance.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/threading/platform_thread_internal_posix.h" | 17 #include "base/threading/platform_thread_internal_posix.h" |
18 #include "base/threading/thread_id_name_manager.h" | 18 #include "base/threading/thread_id_name_manager.h" |
19 #include "base/tracked_objects.h" | 19 #include "base/tracked_objects.h" |
20 #include "jni/ThreadUtils_jni.h" | 20 #include "jni/ThreadUtils_jni.h" |
21 | 21 |
22 namespace base { | 22 namespace base { |
23 | 23 |
24 namespace internal { | 24 namespace internal { |
25 | 25 |
26 // These nice values are taken from Android, which uses nice values like linux, | 26 // - BACKGROUND is 9 due to it being the nicest value we can use that's still |
danakj
2015/07/06 23:24:22
Thanks this comment is awesome.
| |
27 // but defines some preset nice values. | 27 // above an Android system threshold that enables heavy throttling starting at |
28 // Process.THREAD_PRIORITY_AUDIO = -16 | 28 // 10; we want to be lower-priority than Chrome's other threads without |
29 // Process.THREAD_PRIORITY_BACKGROUND = 10 | 29 // incurring this behavior. |
30 // Process.THREAD_PRIORITY_DEFAULT = 0; | 30 // - DISPLAY is -6 due to being midway between Android's DISPLAY (-4) and |
31 // Process.THREAD_PRIORITY_DISPLAY = -4; | 31 // URGENT_DISPLAY (-8). |
32 // Process.THREAD_PRIORITY_FOREGROUND = -2; | 32 // - REALTIME_AUDIO corresponds to Android's THREAD_PRIORITY_AUDIO = -16 value. |
33 // Process.THREAD_PRIORITY_LESS_FAVORABLE = 1; | |
34 // Process.THREAD_PRIORITY_LOWEST = 19; | |
35 // Process.THREAD_PRIORITY_MORE_FAVORABLE = -1; | |
36 // Process.THREAD_PRIORITY_URGENT_AUDIO = -19; | |
37 // Process.THREAD_PRIORITY_URGENT_DISPLAY = -8; | |
38 // We use -6 for display, but we may want to split this into urgent (-8) and | |
39 // non-urgent (-4). | |
40 const ThreadPriorityToNiceValuePair kThreadPriorityToNiceValueMap[4] = { | 33 const ThreadPriorityToNiceValuePair kThreadPriorityToNiceValueMap[4] = { |
41 {ThreadPriority::BACKGROUND, 10}, | 34 {ThreadPriority::BACKGROUND, 9}, |
42 {ThreadPriority::NORMAL, 0}, | 35 {ThreadPriority::NORMAL, 0}, |
43 {ThreadPriority::DISPLAY, -6}, | 36 {ThreadPriority::DISPLAY, -6}, |
44 {ThreadPriority::REALTIME_AUDIO, -16}, | 37 {ThreadPriority::REALTIME_AUDIO, -16}, |
45 }; | 38 }; |
46 | 39 |
47 bool SetThreadPriorityForPlatform(PlatformThreadHandle handle, | 40 bool SetThreadPriorityForPlatform(PlatformThreadHandle handle, |
48 ThreadPriority priority) { | 41 ThreadPriority priority) { |
49 // On Android, we set the Audio priority through JNI as Audio priority | 42 // On Android, we set the Audio priority through JNI as Audio priority |
50 // will also allow the process to run while it is backgrounded. | 43 // will also allow the process to run while it is backgrounded. |
51 if (priority == ThreadPriority::REALTIME_AUDIO) { | 44 if (priority == ThreadPriority::REALTIME_AUDIO) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 // 1Mb is not enough for some tests (see http://crbug.com/263749 for example). | 97 // 1Mb is not enough for some tests (see http://crbug.com/263749 for example). |
105 return 2 * (1 << 20); // 2Mb | 98 return 2 * (1 << 20); // 2Mb |
106 #endif | 99 #endif |
107 } | 100 } |
108 | 101 |
109 bool RegisterThreadUtils(JNIEnv* env) { | 102 bool RegisterThreadUtils(JNIEnv* env) { |
110 return RegisterNativesImpl(env); | 103 return RegisterNativesImpl(env); |
111 } | 104 } |
112 | 105 |
113 } // namespace base | 106 } // namespace base |
OLD | NEW |