Index: base/threading/platform_thread_linux.cc |
diff --git a/base/threading/platform_thread_linux.cc b/base/threading/platform_thread_linux.cc |
index 95ed32418ff49bdce1cfc91b846374000f62a4e3..f1c91c7aae7614991d5158ce7ba7f3ee62db4bdd 100644 |
--- a/base/threading/platform_thread_linux.cc |
+++ b/base/threading/platform_thread_linux.cc |
@@ -8,8 +8,10 @@ |
#include <sched.h> |
#include <stddef.h> |
+#include "base/files/file_util.h" |
#include "base/lazy_instance.h" |
#include "base/logging.h" |
+#include "base/strings/string_number_conversions.h" |
#include "base/threading/platform_thread_internal_posix.h" |
#include "base/threading/thread_id_name_manager.h" |
#include "base/tracked_objects.h" |
@@ -65,6 +67,13 @@ bool GetCurrentThreadPriorityForPlatform(ThreadPriority* priority) { |
} // namespace internal |
+namespace { |
+#if !defined(OS_NACL) |
+const FilePath::CharType kCpusetDirectory[] = |
+ FILE_PATH_LITERAL("/sys/fs/cgroup/cpuset/chrome"); |
Dmitry Torokhov
2016/09/12 16:18:09
I wonder if, instead of having static cpuset place
reveman
2016/09/16 22:16:11
sgtm.
dtor, can you take care of starting chrome
|
+#endif |
+} // namespace |
+ |
// static |
void PlatformThread::SetName(const std::string& name) { |
ThreadIdNameManager::GetInstance()->SetName(CurrentId(), name); |
@@ -90,6 +99,38 @@ void PlatformThread::SetName(const std::string& name) { |
#endif // !defined(OS_NACL) |
} |
+#if !defined(OS_NACL) |
+// static |
+void PlatformThread::SetThreadAffinity(PlatformThreadId id, |
+ ThreadPriority priority) { |
+ // Move thread into the appropriate cpuset when chrome cpuset directory |
+ // exists. Threads with BACKGROUND priority are move to the "non-urgent" |
+ // cpuset and threads with DISPLAY and REALTIME_AUDIO priority are moved |
+ // to "urgent" cpuset. |
+ FilePath cpuset_filepath(kCpusetDirectory); |
+ switch (priority) { |
+ case ThreadPriority::NORMAL: |
+ break; |
+ case ThreadPriority::BACKGROUND: |
+ cpuset_filepath = cpuset_filepath.Append(FILE_PATH_LITERAL("non-urgent")); |
+ break; |
+ case ThreadPriority::DISPLAY: |
+ case ThreadPriority::REALTIME_AUDIO: |
+ cpuset_filepath = cpuset_filepath.Append(FILE_PATH_LITERAL("urgent")); |
+ break; |
+ } |
+ if (DirectoryExists(cpuset_filepath)) { |
+ FilePath tasks_filepath = |
+ cpuset_filepath.Append(FILE_PATH_LITERAL("tasks")); |
+ std::string tid = IntToString(id); |
+ int bytes_written = WriteFile(tasks_filepath, tid.c_str(), tid.size()); |
+ if (bytes_written != static_cast<int>(tid.size())) { |
+ DVLOG(1) << "Failed to add " << tid << " to " << tasks_filepath.value(); |
+ } |
+ } |
+} |
+#endif // !defined(OS_NACL) |
+ |
void InitThreading() {} |
void TerminateOnThread() {} |