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) | |
15 static bool use_cgroups = false; | |
16 static bool cgroups_inited = false; | |
17 static const char kForegroundTasks[] = | |
18 "/tmp/cgroup/cpu/chrome_renderers/foreground/tasks"; | |
19 static const char kBackgroundTasks[] = | |
20 "/tmp/cgroup/cpu/chrome_renderers/background/tasks"; | |
21 static FilePath foreground_tasks; | |
22 static FilePath background_tasks; | |
23 #endif | |
24 | |
25 namespace base { | 14 namespace base { |
26 | 15 |
27 #if defined(OS_CHROMEOS) | 16 #if defined(OS_CHROMEOS) |
28 // We are more aggressive in our lowering of background process priority | 17 // We are more aggressive in our lowering of background process priority |
29 // for chromeos as we have much more control over other processes running | 18 // for chromeos as we have much more control over other processes running |
30 // on the machine. | 19 // on the machine. |
31 const int kPriorityAdjustment = 19; | 20 const int kPriorityAdjustment = 19; |
32 #else | 21 #else |
33 const int kPriorityAdjustment = 5; | 22 const int kPriorityAdjustment = 5; |
34 #endif | 23 #endif |
35 | 24 |
36 bool Process::IsProcessBackgrounded() const { | 25 bool Process::IsProcessBackgrounded() const { |
37 DCHECK(process_); | 26 DCHECK(process_); |
38 return saved_priority_ == kUnsetProcessPriority; | 27 return saved_priority_ == kUnsetProcessPriority; |
39 } | 28 } |
40 | 29 |
41 bool Process::SetProcessBackgrounded(bool background) { | 30 bool Process::SetProcessBackgrounded(bool background) { |
42 DCHECK(process_); | 31 DCHECK(process_); |
43 | 32 |
44 #if defined(OS_CHROMEOS) | 33 #if defined(OS_CHROMEOS) |
| 34 static bool cgroups_inited = false; |
| 35 static bool use_cgroups = false; |
| 36 |
45 // Check for cgroups files. ChromeOS supports these by default. It creates | 37 // 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, | 38 // 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 | 39 // 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 | 40 // all background renderers. This allows us to limit the impact of background |
49 // renderers on foreground ones to a greater level than simple renicing. | 41 // renderers on foreground ones to a greater level than simple renicing. |
| 42 FilePath foreground_tasks( |
| 43 "/tmp/cgroup/cpu/chrome_renderers/foreground/tasks"); |
| 44 FilePath background_tasks( |
| 45 "/tmp/cgroup/cpu/chrome_renderers/background/tasks"); |
50 if (!cgroups_inited) { | 46 if (!cgroups_inited) { |
51 cgroups_inited = true; | 47 cgroups_inited = true; |
52 foreground_tasks = FilePath(kForegroundTasks); | |
53 background_tasks = FilePath(kBackgroundTasks); | |
54 file_util::FileSystemType foreground_type; | 48 file_util::FileSystemType foreground_type; |
55 file_util::FileSystemType background_type; | 49 file_util::FileSystemType background_type; |
56 use_cgroups = | 50 use_cgroups = |
57 file_util::GetFileSystemType(foreground_tasks, &foreground_type) && | 51 file_util::GetFileSystemType(foreground_tasks, &foreground_type) && |
58 file_util::GetFileSystemType(background_tasks, &background_type) && | 52 file_util::GetFileSystemType(background_tasks, &background_type) && |
59 foreground_type == file_util::FILE_SYSTEM_CGROUP && | 53 foreground_type == file_util::FILE_SYSTEM_CGROUP && |
60 background_type == file_util::FILE_SYSTEM_CGROUP; | 54 background_type == file_util::FILE_SYSTEM_CGROUP; |
61 } | 55 } |
62 | 56 |
63 if (use_cgroups) { | 57 if (use_cgroups) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 } | 119 } |
126 int result = setpriority(PRIO_PROCESS, process_, saved_priority_); | 120 int result = setpriority(PRIO_PROCESS, process_, saved_priority_); |
127 // If we can't restore something has gone terribly wrong. | 121 // If we can't restore something has gone terribly wrong. |
128 DPCHECK(result == 0); | 122 DPCHECK(result == 0); |
129 saved_priority_ = kUnsetProcessPriority; | 123 saved_priority_ = kUnsetProcessPriority; |
130 return true; | 124 return true; |
131 } | 125 } |
132 } | 126 } |
133 | 127 |
134 } // namespace base | 128 } // namespace base |
OLD | NEW |