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 <sched.h> | 8 #include <sched.h> |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 | 10 |
11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "base/threading/platform_thread_internal_posix.h" | 15 #include "base/threading/platform_thread_internal_posix.h" |
16 #include "base/threading/thread_id_name_manager.h" | 16 #include "base/threading/thread_id_name_manager.h" |
17 #include "base/tracked_objects.h" | 17 #include "base/tracked_objects.h" |
18 #include "build/build_config.h" | 18 #include "build/build_config.h" |
19 | 19 |
20 #if !defined(OS_NACL) | 20 #if !defined(OS_NACL) && !defined(OS_AIX) |
21 #include <pthread.h> | 21 #include <pthread.h> |
22 #include <sys/prctl.h> | 22 #include <sys/prctl.h> |
23 #include <sys/resource.h> | 23 #include <sys/resource.h> |
24 #include <sys/time.h> | 24 #include <sys/time.h> |
25 #include <sys/types.h> | 25 #include <sys/types.h> |
26 #include <unistd.h> | 26 #include <unistd.h> |
27 #endif | 27 #endif |
28 | 28 |
29 namespace base { | 29 namespace base { |
30 namespace { | 30 namespace { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 return false; | 123 return false; |
124 } | 124 } |
125 | 125 |
126 } // namespace internal | 126 } // namespace internal |
127 | 127 |
128 // static | 128 // static |
129 void PlatformThread::SetName(const std::string& name) { | 129 void PlatformThread::SetName(const std::string& name) { |
130 ThreadIdNameManager::GetInstance()->SetName(CurrentId(), name); | 130 ThreadIdNameManager::GetInstance()->SetName(CurrentId(), name); |
131 tracked_objects::ThreadData::InitializeThreadContext(name); | 131 tracked_objects::ThreadData::InitializeThreadContext(name); |
132 | 132 |
133 #if !defined(OS_NACL) | 133 #if !defined(OS_NACL) && !defined(OS_AIX) |
134 // On linux we can get the thread names to show up in the debugger by setting | 134 // On linux we can get the thread names to show up in the debugger by setting |
135 // the process name for the LWP. We don't want to do this for the main | 135 // the process name for the LWP. We don't want to do this for the main |
136 // thread because that would rename the process, causing tools like killall | 136 // thread because that would rename the process, causing tools like killall |
137 // to stop working. | 137 // to stop working. |
138 if (PlatformThread::CurrentId() == getpid()) | 138 if (PlatformThread::CurrentId() == getpid()) |
139 return; | 139 return; |
140 | 140 |
141 // http://0pointer.de/blog/projects/name-your-threads.html | 141 // http://0pointer.de/blog/projects/name-your-threads.html |
142 // Set the name for the LWP (which gets truncated to 15 characters). | 142 // Set the name for the LWP (which gets truncated to 15 characters). |
143 // Note that glibc also has a 'pthread_setname_np' api, but it may not be | 143 // Note that glibc also has a 'pthread_setname_np' api, but it may not be |
144 // available everywhere and it's only benefit over using prctl directly is | 144 // available everywhere and it's only benefit over using prctl directly is |
145 // that it can set the name of threads other than the current thread. | 145 // that it can set the name of threads other than the current thread. |
146 int err = prctl(PR_SET_NAME, name.c_str()); | 146 int err = prctl(PR_SET_NAME, name.c_str()); |
147 // We expect EPERM failures in sandboxed processes, just ignore those. | 147 // We expect EPERM failures in sandboxed processes, just ignore those. |
148 if (err < 0 && errno != EPERM) | 148 if (err < 0 && errno != EPERM) |
149 DPLOG(ERROR) << "prctl(PR_SET_NAME)"; | 149 DPLOG(ERROR) << "prctl(PR_SET_NAME)"; |
150 #endif // !defined(OS_NACL) | 150 #endif // !defined(OS_NACL) && !defined(OS_AIX) |
151 } | 151 } |
152 | 152 |
153 #if !defined(OS_NACL) | 153 #if !defined(OS_NACL) && !defined(OS_AIX) |
154 // static | 154 // static |
155 void PlatformThread::SetThreadPriority(PlatformThreadId thread_id, | 155 void PlatformThread::SetThreadPriority(PlatformThreadId thread_id, |
156 ThreadPriority priority) { | 156 ThreadPriority priority) { |
157 // Changing current main threads' priority is not permitted in favor of | 157 // Changing current main threads' priority is not permitted in favor of |
158 // security, this interface is restricted to change only non-main thread | 158 // security, this interface is restricted to change only non-main thread |
159 // priority. | 159 // priority. |
160 CHECK_NE(thread_id, getpid()); | 160 CHECK_NE(thread_id, getpid()); |
161 | 161 |
162 SetThreadCgroupsForThreadPriority(thread_id, priority); | 162 SetThreadCgroupsForThreadPriority(thread_id, priority); |
163 | 163 |
164 const int nice_setting = internal::ThreadPriorityToNiceValue(priority); | 164 const int nice_setting = internal::ThreadPriorityToNiceValue(priority); |
165 if (setpriority(PRIO_PROCESS, thread_id, nice_setting)) { | 165 if (setpriority(PRIO_PROCESS, thread_id, nice_setting)) { |
166 DVPLOG(1) << "Failed to set nice value of thread (" << thread_id << ") to " | 166 DVPLOG(1) << "Failed to set nice value of thread (" << thread_id << ") to " |
167 << nice_setting; | 167 << nice_setting; |
168 } | 168 } |
169 } | 169 } |
170 #endif // !defined(OS_NACL) | 170 #endif // !defined(OS_NACL) && !defined(OS_AIX) |
171 | 171 |
172 void InitThreading() {} | 172 void InitThreading() {} |
173 | 173 |
174 void TerminateOnThread() {} | 174 void TerminateOnThread() {} |
175 | 175 |
176 size_t GetDefaultThreadStackSize(const pthread_attr_t& attributes) { | 176 size_t GetDefaultThreadStackSize(const pthread_attr_t& attributes) { |
177 #if !defined(THREAD_SANITIZER) | 177 #if !defined(THREAD_SANITIZER) |
178 return 0; | 178 return 0; |
179 #else | 179 #else |
180 // ThreadSanitizer bloats the stack heavily. Evidence has been that the | 180 // ThreadSanitizer bloats the stack heavily. Evidence has been that the |
181 // default stack size isn't enough for some browser tests. | 181 // default stack size isn't enough for some browser tests. |
182 return 2 * (1 << 23); // 2 times 8192K (the default stack size on Linux). | 182 return 2 * (1 << 23); // 2 times 8192K (the default stack size on Linux). |
183 #endif | 183 #endif |
184 } | 184 } |
185 | 185 |
186 } // namespace base | 186 } // namespace base |
OLD | NEW |