Merge "libprocessgroup: add flags to indicate when a controller failed to mount" into qt-dev
This commit is contained in:
commit
9b77c0ba32
12 changed files with 76 additions and 16 deletions
|
|
@ -67,6 +67,13 @@ bool CgroupController::HasValue() const {
|
||||||
return controller_ != nullptr;
|
return controller_ != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CgroupController::IsUsable() const {
|
||||||
|
if (!HasValue()) return false;
|
||||||
|
|
||||||
|
uint32_t flags = ACgroupController_getFlags(controller_);
|
||||||
|
return (flags & CGROUPRC_CONTROLLER_FLAG_MOUNTED) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
std::string CgroupController::GetTasksFilePath(const std::string& rel_path) const {
|
std::string CgroupController::GetTasksFilePath(const std::string& rel_path) const {
|
||||||
std::string tasks_path = path();
|
std::string tasks_path = path();
|
||||||
|
|
||||||
|
|
@ -153,6 +160,7 @@ void CgroupMap::Print() const {
|
||||||
const ACgroupController* controller = ACgroupFile_getController(i);
|
const ACgroupController* controller = ACgroupFile_getController(i);
|
||||||
LOG(INFO) << "\t" << ACgroupController_getName(controller) << " ver "
|
LOG(INFO) << "\t" << ACgroupController_getName(controller) << " ver "
|
||||||
<< ACgroupController_getVersion(controller) << " path "
|
<< ACgroupController_getVersion(controller) << " path "
|
||||||
|
<< ACgroupController_getFlags(controller) << " flags "
|
||||||
<< ACgroupController_getPath(controller);
|
<< ACgroupController_getPath(controller);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ class CgroupController {
|
||||||
const char* path() const;
|
const char* path() const;
|
||||||
|
|
||||||
bool HasValue() const;
|
bool HasValue() const;
|
||||||
|
bool IsUsable() const;
|
||||||
|
|
||||||
std::string GetTasksFilePath(const std::string& path) const;
|
std::string GetTasksFilePath(const std::string& path) const;
|
||||||
std::string GetProcsFilePath(const std::string& path, uid_t uid, pid_t pid) const;
|
std::string GetProcsFilePath(const std::string& path, uid_t uid, pid_t pid) const;
|
||||||
|
|
|
||||||
|
|
@ -42,19 +42,19 @@ cc_library {
|
||||||
"libcgrouprc_format",
|
"libcgrouprc_format",
|
||||||
],
|
],
|
||||||
stubs: {
|
stubs: {
|
||||||
symbol_file: "libcgrouprc.map.txt",
|
symbol_file: "libcgrouprc.llndk.txt",
|
||||||
versions: ["29"],
|
versions: ["29"],
|
||||||
},
|
},
|
||||||
target: {
|
target: {
|
||||||
linux: {
|
linux: {
|
||||||
version_script: "libcgrouprc.map.txt",
|
version_script: "libcgrouprc.llndk.txt",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
llndk_library {
|
llndk_library {
|
||||||
name: "libcgrouprc",
|
name: "libcgrouprc",
|
||||||
symbol_file: "libcgrouprc.map.txt",
|
symbol_file: "libcgrouprc.llndk.txt",
|
||||||
export_include_dirs: [
|
export_include_dirs: [
|
||||||
"include",
|
"include",
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,11 @@ uint32_t ACgroupController_getVersion(const ACgroupController* controller) {
|
||||||
return controller->version();
|
return controller->version();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t ACgroupController_getFlags(const ACgroupController* controller) {
|
||||||
|
CHECK(controller != nullptr);
|
||||||
|
return controller->flags();
|
||||||
|
}
|
||||||
|
|
||||||
const char* ACgroupController_getName(const ACgroupController* controller) {
|
const char* ACgroupController_getName(const ACgroupController* controller) {
|
||||||
CHECK(controller != nullptr);
|
CHECK(controller != nullptr);
|
||||||
return controller->name();
|
return controller->name();
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,18 @@ __attribute__((warn_unused_result)) const ACgroupController* ACgroupFile_getCont
|
||||||
__attribute__((warn_unused_result)) uint32_t ACgroupController_getVersion(const ACgroupController*)
|
__attribute__((warn_unused_result)) uint32_t ACgroupController_getVersion(const ACgroupController*)
|
||||||
__INTRODUCED_IN(29);
|
__INTRODUCED_IN(29);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flag bitmask used in ACgroupController_getFlags
|
||||||
|
*/
|
||||||
|
#define CGROUPRC_CONTROLLER_FLAG_MOUNTED 0x1
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the flags bitmask of the given controller.
|
||||||
|
* If the given controller is null, return 0.
|
||||||
|
*/
|
||||||
|
__attribute__((warn_unused_result)) uint32_t ACgroupController_getFlags(const ACgroupController*)
|
||||||
|
__INTRODUCED_IN(29);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the name of the given controller.
|
* Returns the name of the given controller.
|
||||||
* If the given controller is null, return nullptr.
|
* If the given controller is null, return nullptr.
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ LIBCGROUPRC { # introduced=29
|
||||||
ACgroupFile_getControllerCount;
|
ACgroupFile_getControllerCount;
|
||||||
ACgroupFile_getController;
|
ACgroupFile_getController;
|
||||||
ACgroupController_getVersion;
|
ACgroupController_getVersion;
|
||||||
|
ACgroupController_getFlags;
|
||||||
ACgroupController_getName;
|
ACgroupController_getName;
|
||||||
ACgroupController_getPath;
|
ACgroupController_getPath;
|
||||||
local:
|
local:
|
||||||
|
|
@ -20,12 +20,19 @@ namespace android {
|
||||||
namespace cgrouprc {
|
namespace cgrouprc {
|
||||||
namespace format {
|
namespace format {
|
||||||
|
|
||||||
CgroupController::CgroupController(uint32_t version, const std::string& name,
|
CgroupController::CgroupController() : version_(0), flags_(0) {
|
||||||
const std::string& path) {
|
memset(name_, 0, sizeof(name_));
|
||||||
|
memset(path_, 0, sizeof(path_));
|
||||||
|
}
|
||||||
|
|
||||||
|
CgroupController::CgroupController(uint32_t version, uint32_t flags, const std::string& name,
|
||||||
|
const std::string& path)
|
||||||
|
: CgroupController() {
|
||||||
// strlcpy isn't available on host. Although there is an implementation
|
// strlcpy isn't available on host. Although there is an implementation
|
||||||
// in licutils, libcutils itself depends on libcgrouprc_format, causing
|
// in licutils, libcutils itself depends on libcgrouprc_format, causing
|
||||||
// a circular dependency.
|
// a circular dependency.
|
||||||
version_ = version;
|
version_ = version;
|
||||||
|
flags_ = flags;
|
||||||
strncpy(name_, name.c_str(), sizeof(name_) - 1);
|
strncpy(name_, name.c_str(), sizeof(name_) - 1);
|
||||||
name_[sizeof(name_) - 1] = '\0';
|
name_[sizeof(name_) - 1] = '\0';
|
||||||
strncpy(path_, path.c_str(), sizeof(path_) - 1);
|
strncpy(path_, path.c_str(), sizeof(path_) - 1);
|
||||||
|
|
@ -36,6 +43,10 @@ uint32_t CgroupController::version() const {
|
||||||
return version_;
|
return version_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t CgroupController::flags() const {
|
||||||
|
return flags_;
|
||||||
|
}
|
||||||
|
|
||||||
const char* CgroupController::name() const {
|
const char* CgroupController::name() const {
|
||||||
return name_;
|
return name_;
|
||||||
}
|
}
|
||||||
|
|
@ -44,6 +55,10 @@ const char* CgroupController::path() const {
|
||||||
return path_;
|
return path_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CgroupController::set_flags(uint32_t flags) {
|
||||||
|
flags_ = flags;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace format
|
} // namespace format
|
||||||
} // namespace cgrouprc
|
} // namespace cgrouprc
|
||||||
} // namespace android
|
} // namespace android
|
||||||
|
|
|
||||||
|
|
@ -26,18 +26,23 @@ namespace format {
|
||||||
// Minimal controller description to be mmapped into process address space
|
// Minimal controller description to be mmapped into process address space
|
||||||
struct CgroupController {
|
struct CgroupController {
|
||||||
public:
|
public:
|
||||||
CgroupController() {}
|
CgroupController();
|
||||||
CgroupController(uint32_t version, const std::string& name, const std::string& path);
|
CgroupController(uint32_t version, uint32_t flags, const std::string& name,
|
||||||
|
const std::string& path);
|
||||||
|
|
||||||
uint32_t version() const;
|
uint32_t version() const;
|
||||||
|
uint32_t flags() const;
|
||||||
const char* name() const;
|
const char* name() const;
|
||||||
const char* path() const;
|
const char* path() const;
|
||||||
|
|
||||||
|
void set_flags(uint32_t flags);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static constexpr size_t CGROUP_NAME_BUF_SZ = 16;
|
static constexpr size_t CGROUP_NAME_BUF_SZ = 16;
|
||||||
static constexpr size_t CGROUP_PATH_BUF_SZ = 32;
|
static constexpr size_t CGROUP_PATH_BUF_SZ = 32;
|
||||||
|
|
||||||
uint32_t version_;
|
uint32_t version_;
|
||||||
|
uint32_t flags_;
|
||||||
char name_[CGROUP_NAME_BUF_SZ];
|
char name_[CGROUP_NAME_BUF_SZ];
|
||||||
char path_[CGROUP_PATH_BUF_SZ];
|
char path_[CGROUP_PATH_BUF_SZ];
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -106,8 +106,7 @@ bool UsePerAppMemcg() {
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool isMemoryCgroupSupported() {
|
static bool isMemoryCgroupSupported() {
|
||||||
std::string cgroup_name;
|
static bool memcg_supported = CgroupMap::GetInstance().FindController("memory").IsUsable();
|
||||||
static bool memcg_supported = CgroupMap::GetInstance().FindController("memory").HasValue();
|
|
||||||
|
|
||||||
return memcg_supported;
|
return memcg_supported;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -151,19 +151,19 @@ int set_sched_policy(int tid, SchedPolicy policy) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cpusets_enabled() {
|
bool cpusets_enabled() {
|
||||||
static bool enabled = (CgroupMap::GetInstance().FindController("cpuset").HasValue());
|
static bool enabled = (CgroupMap::GetInstance().FindController("cpuset").IsUsable());
|
||||||
return enabled;
|
return enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool schedboost_enabled() {
|
bool schedboost_enabled() {
|
||||||
static bool enabled = (CgroupMap::GetInstance().FindController("schedtune").HasValue());
|
static bool enabled = (CgroupMap::GetInstance().FindController("schedtune").IsUsable());
|
||||||
return enabled;
|
return enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int getCGroupSubsys(int tid, const char* subsys, std::string& subgroup) {
|
static int getCGroupSubsys(int tid, const char* subsys, std::string& subgroup) {
|
||||||
auto controller = CgroupMap::GetInstance().FindController(subsys);
|
auto controller = CgroupMap::GetInstance().FindController(subsys);
|
||||||
|
|
||||||
if (!controller.HasValue()) return -1;
|
if (!controller.IsUsable()) return -1;
|
||||||
|
|
||||||
if (!controller.GetTaskGroup(tid, &subgroup)) {
|
if (!controller.GetTaskGroup(tid, &subgroup)) {
|
||||||
LOG(ERROR) << "Failed to find cgroup for tid " << tid;
|
LOG(ERROR) << "Failed to find cgroup for tid " << tid;
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,8 @@ class CgroupDescriptor {
|
||||||
std::string uid() const { return uid_; }
|
std::string uid() const { return uid_; }
|
||||||
std::string gid() const { return gid_; }
|
std::string gid() const { return gid_; }
|
||||||
|
|
||||||
|
void set_mounted(bool mounted);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
format::CgroupController controller_;
|
format::CgroupController controller_;
|
||||||
mode_t mode_ = 0;
|
mode_t mode_ = 0;
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@
|
||||||
#include <android-base/properties.h>
|
#include <android-base/properties.h>
|
||||||
#include <android-base/stringprintf.h>
|
#include <android-base/stringprintf.h>
|
||||||
#include <android-base/unique_fd.h>
|
#include <android-base/unique_fd.h>
|
||||||
|
#include <android/cgrouprc.h>
|
||||||
#include <json/reader.h>
|
#include <json/reader.h>
|
||||||
#include <json/value.h>
|
#include <json/value.h>
|
||||||
#include <processgroup/format/cgroup_file.h>
|
#include <processgroup/format/cgroup_file.h>
|
||||||
|
|
@ -267,7 +268,17 @@ static bool WriteRcFile(const std::map<std::string, CgroupDescriptor>& descripto
|
||||||
CgroupDescriptor::CgroupDescriptor(uint32_t version, const std::string& name,
|
CgroupDescriptor::CgroupDescriptor(uint32_t version, const std::string& name,
|
||||||
const std::string& path, mode_t mode, const std::string& uid,
|
const std::string& path, mode_t mode, const std::string& uid,
|
||||||
const std::string& gid)
|
const std::string& gid)
|
||||||
: controller_(version, name, path), mode_(mode), uid_(uid), gid_(gid) {}
|
: controller_(version, 0, name, path), mode_(mode), uid_(uid), gid_(gid) {}
|
||||||
|
|
||||||
|
void CgroupDescriptor::set_mounted(bool mounted) {
|
||||||
|
uint32_t flags = controller_.flags();
|
||||||
|
if (mounted) {
|
||||||
|
flags |= CGROUPRC_CONTROLLER_FLAG_MOUNTED;
|
||||||
|
} else {
|
||||||
|
flags &= ~CGROUPRC_CONTROLLER_FLAG_MOUNTED;
|
||||||
|
}
|
||||||
|
controller_.set_flags(flags);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace cgrouprc
|
} // namespace cgrouprc
|
||||||
} // namespace android
|
} // namespace android
|
||||||
|
|
@ -296,10 +307,11 @@ bool CgroupSetup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup cgroups
|
// setup cgroups
|
||||||
for (const auto& [name, descriptor] : descriptors) {
|
for (auto& [name, descriptor] : descriptors) {
|
||||||
if (!SetupCgroup(descriptor)) {
|
if (SetupCgroup(descriptor)) {
|
||||||
|
descriptor.set_mounted(true);
|
||||||
|
} else {
|
||||||
// issue a warning and proceed with the next cgroup
|
// issue a warning and proceed with the next cgroup
|
||||||
// TODO: mark the descriptor as invalid and skip it in WriteRcFile()
|
|
||||||
LOG(WARNING) << "Failed to setup " << name << " cgroup";
|
LOG(WARNING) << "Failed to setup " << name << " cgroup";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue