• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/core


Commit MetaInfo

Révisionfd285d2b70537fd3ef239ae3843c30ccf07ac161 (tree)
l'heure2019-05-18 08:18:29
AuteurSuren Baghdasaryan <surenb@goog...>
CommiterSuren Baghdasaryan

Message de Log

libprocessgroup: add flags to indicate when a controller failed to mount

Controllers listed in cgroups.json file might fail to mount if kernel is
not configured to support them. We need a way to indicate whether a
controller was successfully mounted and is usable to avoid logging errors
and warnings when a controller that failed to mount is being used. Add
flags bitmask to cgrouprc controller descriptor and use a bit to indicate
that controller is successfully mounted. Modify cpusets_enabled() and
schedboost_enabled() functions to use this bit and report the actual
availability of the controller.

Bug: 124080437
Test: libcutils_test with cpuset and schedtune controllers disabled
Change-Id: I770cc39fe50465146e3205aacf77dc3c56923c5d
Signed-off-by: Suren Baghdasaryan <surenb@google.com>

Change Summary

Modification

--- a/libprocessgroup/cgroup_map.cpp
+++ b/libprocessgroup/cgroup_map.cpp
@@ -67,6 +67,13 @@ bool CgroupController::HasValue() const {
6767 return controller_ != nullptr;
6868 }
6969
70+bool CgroupController::IsUsable() const {
71+ if (!HasValue()) return false;
72+
73+ uint32_t flags = ACgroupController_getFlags(controller_);
74+ return (flags & CGROUPRC_CONTROLLER_FLAG_MOUNTED) != 0;
75+}
76+
7077 std::string CgroupController::GetTasksFilePath(const std::string& rel_path) const {
7178 std::string tasks_path = path();
7279
@@ -153,6 +160,7 @@ void CgroupMap::Print() const {
153160 const ACgroupController* controller = ACgroupFile_getController(i);
154161 LOG(INFO) << "\t" << ACgroupController_getName(controller) << " ver "
155162 << ACgroupController_getVersion(controller) << " path "
163+ << ACgroupController_getFlags(controller) << " flags "
156164 << ACgroupController_getPath(controller);
157165 }
158166 }
--- a/libprocessgroup/cgroup_map.h
+++ b/libprocessgroup/cgroup_map.h
@@ -38,6 +38,7 @@ class CgroupController {
3838 const char* path() const;
3939
4040 bool HasValue() const;
41+ bool IsUsable() const;
4142
4243 std::string GetTasksFilePath(const std::string& path) const;
4344 std::string GetProcsFilePath(const std::string& path, uid_t uid, pid_t pid) const;
--- a/libprocessgroup/cgrouprc/Android.bp
+++ b/libprocessgroup/cgrouprc/Android.bp
@@ -42,19 +42,19 @@ cc_library {
4242 "libcgrouprc_format",
4343 ],
4444 stubs: {
45- symbol_file: "libcgrouprc.map.txt",
45+ symbol_file: "libcgrouprc.llndk.txt",
4646 versions: ["29"],
4747 },
4848 target: {
4949 linux: {
50- version_script: "libcgrouprc.map.txt",
50+ version_script: "libcgrouprc.llndk.txt",
5151 },
5252 },
5353 }
5454
5555 llndk_library {
5656 name: "libcgrouprc",
57- symbol_file: "libcgrouprc.map.txt",
57+ symbol_file: "libcgrouprc.llndk.txt",
5858 export_include_dirs: [
5959 "include",
6060 ],
--- a/libprocessgroup/cgrouprc/cgroup_controller.cpp
+++ b/libprocessgroup/cgrouprc/cgroup_controller.cpp
@@ -27,6 +27,11 @@ uint32_t ACgroupController_getVersion(const ACgroupController* controller) {
2727 return controller->version();
2828 }
2929
30+uint32_t ACgroupController_getFlags(const ACgroupController* controller) {
31+ CHECK(controller != nullptr);
32+ return controller->flags();
33+}
34+
3035 const char* ACgroupController_getName(const ACgroupController* controller) {
3136 CHECK(controller != nullptr);
3237 return controller->name();
--- a/libprocessgroup/cgrouprc/include/android/cgrouprc.h
+++ b/libprocessgroup/cgrouprc/include/android/cgrouprc.h
@@ -66,6 +66,18 @@ __attribute__((warn_unused_result)) uint32_t ACgroupController_getVersion(const
6666 __INTRODUCED_IN(29);
6767
6868 /**
69+ * Flag bitmask used in ACgroupController_getFlags
70+ */
71+#define CGROUPRC_CONTROLLER_FLAG_MOUNTED 0x1
72+
73+/**
74+ * Returns the flags bitmask of the given controller.
75+ * If the given controller is null, return 0.
76+ */
77+__attribute__((warn_unused_result)) uint32_t ACgroupController_getFlags(const ACgroupController*)
78+ __INTRODUCED_IN(29);
79+
80+/**
6981 * Returns the name of the given controller.
7082 * If the given controller is null, return nullptr.
7183 */
--- a/libprocessgroup/cgrouprc/libcgrouprc.map.txt
+++ b/libprocessgroup/cgrouprc/libcgrouprc.llndk.txt
@@ -4,6 +4,7 @@ LIBCGROUPRC { # introduced=29
44 ACgroupFile_getControllerCount;
55 ACgroupFile_getController;
66 ACgroupController_getVersion;
7+ ACgroupController_getFlags;
78 ACgroupController_getName;
89 ACgroupController_getPath;
910 local:
--- a/libprocessgroup/cgrouprc_format/cgroup_controller.cpp
+++ b/libprocessgroup/cgrouprc_format/cgroup_controller.cpp
@@ -20,12 +20,19 @@ namespace android {
2020 namespace cgrouprc {
2121 namespace format {
2222
23-CgroupController::CgroupController(uint32_t version, const std::string& name,
24- const std::string& path) {
23+CgroupController::CgroupController() : version_(0), flags_(0) {
24+ memset(name_, 0, sizeof(name_));
25+ memset(path_, 0, sizeof(path_));
26+}
27+
28+CgroupController::CgroupController(uint32_t version, uint32_t flags, const std::string& name,
29+ const std::string& path)
30+ : CgroupController() {
2531 // strlcpy isn't available on host. Although there is an implementation
2632 // in licutils, libcutils itself depends on libcgrouprc_format, causing
2733 // a circular dependency.
2834 version_ = version;
35+ flags_ = flags;
2936 strncpy(name_, name.c_str(), sizeof(name_) - 1);
3037 name_[sizeof(name_) - 1] = '\0';
3138 strncpy(path_, path.c_str(), sizeof(path_) - 1);
@@ -36,6 +43,10 @@ uint32_t CgroupController::version() const {
3643 return version_;
3744 }
3845
46+uint32_t CgroupController::flags() const {
47+ return flags_;
48+}
49+
3950 const char* CgroupController::name() const {
4051 return name_;
4152 }
@@ -44,6 +55,10 @@ const char* CgroupController::path() const {
4455 return path_;
4556 }
4657
58+void CgroupController::set_flags(uint32_t flags) {
59+ flags_ = flags;
60+}
61+
4762 } // namespace format
4863 } // namespace cgrouprc
4964 } // namespace android
--- a/libprocessgroup/cgrouprc_format/include/processgroup/format/cgroup_controller.h
+++ b/libprocessgroup/cgrouprc_format/include/processgroup/format/cgroup_controller.h
@@ -26,18 +26,23 @@ namespace format {
2626 // Minimal controller description to be mmapped into process address space
2727 struct CgroupController {
2828 public:
29- CgroupController() {}
30- CgroupController(uint32_t version, const std::string& name, const std::string& path);
29+ CgroupController();
30+ CgroupController(uint32_t version, uint32_t flags, const std::string& name,
31+ const std::string& path);
3132
3233 uint32_t version() const;
34+ uint32_t flags() const;
3335 const char* name() const;
3436 const char* path() const;
3537
38+ void set_flags(uint32_t flags);
39+
3640 private:
3741 static constexpr size_t CGROUP_NAME_BUF_SZ = 16;
3842 static constexpr size_t CGROUP_PATH_BUF_SZ = 32;
3943
4044 uint32_t version_;
45+ uint32_t flags_;
4146 char name_[CGROUP_NAME_BUF_SZ];
4247 char path_[CGROUP_PATH_BUF_SZ];
4348 };
--- a/libprocessgroup/processgroup.cpp
+++ b/libprocessgroup/processgroup.cpp
@@ -106,8 +106,7 @@ bool UsePerAppMemcg() {
106106 }
107107
108108 static bool isMemoryCgroupSupported() {
109- std::string cgroup_name;
110- static bool memcg_supported = CgroupMap::GetInstance().FindController("memory").HasValue();
109+ static bool memcg_supported = CgroupMap::GetInstance().FindController("memory").IsUsable();
111110
112111 return memcg_supported;
113112 }
--- a/libprocessgroup/sched_policy.cpp
+++ b/libprocessgroup/sched_policy.cpp
@@ -151,19 +151,19 @@ int set_sched_policy(int tid, SchedPolicy policy) {
151151 }
152152
153153 bool cpusets_enabled() {
154- static bool enabled = (CgroupMap::GetInstance().FindController("cpuset").HasValue());
154+ static bool enabled = (CgroupMap::GetInstance().FindController("cpuset").IsUsable());
155155 return enabled;
156156 }
157157
158158 bool schedboost_enabled() {
159- static bool enabled = (CgroupMap::GetInstance().FindController("schedtune").HasValue());
159+ static bool enabled = (CgroupMap::GetInstance().FindController("schedtune").IsUsable());
160160 return enabled;
161161 }
162162
163163 static int getCGroupSubsys(int tid, const char* subsys, std::string& subgroup) {
164164 auto controller = CgroupMap::GetInstance().FindController(subsys);
165165
166- if (!controller.HasValue()) return -1;
166+ if (!controller.IsUsable()) return -1;
167167
168168 if (!controller.GetTaskGroup(tid, &subgroup)) {
169169 LOG(ERROR) << "Failed to find cgroup for tid " << tid;
--- a/libprocessgroup/setup/cgroup_descriptor.h
+++ b/libprocessgroup/setup/cgroup_descriptor.h
@@ -32,6 +32,8 @@ class CgroupDescriptor {
3232 std::string uid() const { return uid_; }
3333 std::string gid() const { return gid_; }
3434
35+ void set_mounted(bool mounted);
36+
3537 private:
3638 format::CgroupController controller_;
3739 mode_t mode_ = 0;
--- a/libprocessgroup/setup/cgroup_map_write.cpp
+++ b/libprocessgroup/setup/cgroup_map_write.cpp
@@ -35,6 +35,7 @@
3535 #include <android-base/properties.h>
3636 #include <android-base/stringprintf.h>
3737 #include <android-base/unique_fd.h>
38+#include <android/cgrouprc.h>
3839 #include <json/reader.h>
3940 #include <json/value.h>
4041 #include <processgroup/format/cgroup_file.h>
@@ -267,7 +268,17 @@ static bool WriteRcFile(const std::map<std::string, CgroupDescriptor>& descripto
267268 CgroupDescriptor::CgroupDescriptor(uint32_t version, const std::string& name,
268269 const std::string& path, mode_t mode, const std::string& uid,
269270 const std::string& gid)
270- : controller_(version, name, path), mode_(mode), uid_(uid), gid_(gid) {}
271+ : controller_(version, 0, name, path), mode_(mode), uid_(uid), gid_(gid) {}
272+
273+void CgroupDescriptor::set_mounted(bool mounted) {
274+ uint32_t flags = controller_.flags();
275+ if (mounted) {
276+ flags |= CGROUPRC_CONTROLLER_FLAG_MOUNTED;
277+ } else {
278+ flags &= ~CGROUPRC_CONTROLLER_FLAG_MOUNTED;
279+ }
280+ controller_.set_flags(flags);
281+}
271282
272283 } // namespace cgrouprc
273284 } // namespace android
@@ -296,10 +307,11 @@ bool CgroupSetup() {
296307 }
297308
298309 // setup cgroups
299- for (const auto& [name, descriptor] : descriptors) {
300- if (!SetupCgroup(descriptor)) {
310+ for (auto& [name, descriptor] : descriptors) {
311+ if (SetupCgroup(descriptor)) {
312+ descriptor.set_mounted(true);
313+ } else {
301314 // issue a warning and proceed with the next cgroup
302- // TODO: mark the descriptor as invalid and skip it in WriteRcFile()
303315 LOG(WARNING) << "Failed to setup " << name << " cgroup";
304316 }
305317 }