Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/process.h" | 5 #include "base/process.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <sys/resource.h> | 8 #include <sys/resource.h> |
| 9 | 9 |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
| 13 | 13 |
| 14 #if defined(OS_CHROMEOS) | 14 #if defined(OS_CHROMEOS) |
| 15 static bool use_cgroups = false; | 15 static bool use_cgroups = false; |
|
Mark Mentovai
2011/11/09 21:13:45
All of these should just go and live in Process::S
| |
| 16 static bool cgroups_inited = false; | 16 static bool cgroups_inited = false; |
| 17 static const char kForegroundTasks[] = | 17 static const char kForegroundTasks[] = |
|
Mark Mentovai
2011/11/09 21:13:45
And these two won’t need to be static. Or you can
| |
| 18 "/tmp/cgroup/cpu/chrome_renderers/foreground/tasks"; | 18 "/tmp/cgroup/cpu/chrome_renderers/foreground/tasks"; |
| 19 static const char kBackgroundTasks[] = | 19 static const char kBackgroundTasks[] = |
| 20 "/tmp/cgroup/cpu/chrome_renderers/background/tasks"; | 20 "/tmp/cgroup/cpu/chrome_renderers/background/tasks"; |
| 21 static FilePath foreground_tasks; | |
| 22 static FilePath background_tasks; | |
| 23 #endif | 21 #endif |
| 24 | 22 |
| 25 namespace base { | 23 namespace base { |
| 26 | 24 |
| 27 #if defined(OS_CHROMEOS) | 25 #if defined(OS_CHROMEOS) |
| 28 // We are more aggressive in our lowering of background process priority | 26 // We are more aggressive in our lowering of background process priority |
| 29 // for chromeos as we have much more control over other processes running | 27 // for chromeos as we have much more control over other processes running |
| 30 // on the machine. | 28 // on the machine. |
| 31 const int kPriorityAdjustment = 19; | 29 const int kPriorityAdjustment = 19; |
| 32 #else | 30 #else |
| 33 const int kPriorityAdjustment = 5; | 31 const int kPriorityAdjustment = 5; |
| 34 #endif | 32 #endif |
| 35 | 33 |
| 36 bool Process::IsProcessBackgrounded() const { | 34 bool Process::IsProcessBackgrounded() const { |
| 37 DCHECK(process_); | 35 DCHECK(process_); |
| 38 return saved_priority_ == kUnsetProcessPriority; | 36 return saved_priority_ == kUnsetProcessPriority; |
| 39 } | 37 } |
| 40 | 38 |
| 41 bool Process::SetProcessBackgrounded(bool background) { | 39 bool Process::SetProcessBackgrounded(bool background) { |
| 42 DCHECK(process_); | 40 DCHECK(process_); |
| 43 | 41 |
| 44 #if defined(OS_CHROMEOS) | 42 #if defined(OS_CHROMEOS) |
| 45 // Check for cgroups files. ChromeOS supports these by default. It creates | 43 // Check for cgroups files. ChromeOS supports these by default. It creates |
| 46 // a cgroup mount in /tmp/cgroup and then configures two cpu task groups, | 44 // a cgroup mount in /tmp/cgroup and then configures two cpu task groups, |
| 47 // one contains at most a single foreground renderer and the other contains | 45 // one contains at most a single foreground renderer and the other contains |
| 48 // all background renderers. This allows us to limit the impact of background | 46 // all background renderers. This allows us to limit the impact of background |
| 49 // renderers on foreground ones to a greater level than simple renicing. | 47 // renderers on foreground ones to a greater level than simple renicing. |
| 48 FilePath foreground_tasks(kForegroundTasks); | |
| 49 FilePath background_tasks(kBackgroundTasks); | |
| 50 if (!cgroups_inited) { | 50 if (!cgroups_inited) { |
| 51 cgroups_inited = true; | 51 cgroups_inited = true; |
| 52 foreground_tasks = FilePath(kForegroundTasks); | |
| 53 background_tasks = FilePath(kBackgroundTasks); | |
| 54 file_util::FileSystemType foreground_type; | 52 file_util::FileSystemType foreground_type; |
| 55 file_util::FileSystemType background_type; | 53 file_util::FileSystemType background_type; |
| 56 use_cgroups = | 54 use_cgroups = |
| 57 file_util::GetFileSystemType(foreground_tasks, &foreground_type) && | 55 file_util::GetFileSystemType(foreground_tasks, &foreground_type) && |
| 58 file_util::GetFileSystemType(background_tasks, &background_type) && | 56 file_util::GetFileSystemType(background_tasks, &background_type) && |
| 59 foreground_type == file_util::FILE_SYSTEM_CGROUP && | 57 foreground_type == file_util::FILE_SYSTEM_CGROUP && |
| 60 background_type == file_util::FILE_SYSTEM_CGROUP; | 58 background_type == file_util::FILE_SYSTEM_CGROUP; |
| 61 } | 59 } |
| 62 | 60 |
| 63 if (use_cgroups) { | 61 if (use_cgroups) { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 } | 123 } |
| 126 int result = setpriority(PRIO_PROCESS, process_, saved_priority_); | 124 int result = setpriority(PRIO_PROCESS, process_, saved_priority_); |
| 127 // If we can't restore something has gone terribly wrong. | 125 // If we can't restore something has gone terribly wrong. |
| 128 DPCHECK(result == 0); | 126 DPCHECK(result == 0); |
| 129 saved_priority_ = kUnsetProcessPriority; | 127 saved_priority_ = kUnsetProcessPriority; |
| 130 return true; | 128 return true; |
| 131 } | 129 } |
| 132 } | 130 } |
| 133 | 131 |
| 134 } // namespace base | 132 } // namespace base |
| OLD | NEW |