resolve merge conflicts of ed81cc26aa to qt-r1-dev-plus-aosp

Bug: None
Test: I solemnly swear I tested this conflict resolution.
Change-Id: I9cc45ecad961f3aee1753679636a1919c797d7fc
This commit is contained in:
Suren Baghdasaryan 2019-05-21 14:32:46 -07:00
commit 0f6a85322d
12 changed files with 76 additions and 16 deletions

View file

@ -67,6 +67,13 @@ bool CgroupController::HasValue() const {
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 tasks_path = path();
@ -153,6 +160,7 @@ void CgroupMap::Print() const {
const ACgroupController* controller = ACgroupFile_getController(i);
LOG(INFO) << "\t" << ACgroupController_getName(controller) << " ver "
<< ACgroupController_getVersion(controller) << " path "
<< ACgroupController_getFlags(controller) << " flags "
<< ACgroupController_getPath(controller);
}
}

View file

@ -38,6 +38,7 @@ class CgroupController {
const char* path() const;
bool HasValue() const;
bool IsUsable() const;
std::string GetTasksFilePath(const std::string& path) const;
std::string GetProcsFilePath(const std::string& path, uid_t uid, pid_t pid) const;

View file

@ -43,19 +43,19 @@ cc_library {
"libcgrouprc_format",
],
stubs: {
symbol_file: "libcgrouprc.map.txt",
symbol_file: "libcgrouprc.llndk.txt",
versions: ["29"],
},
target: {
linux: {
version_script: "libcgrouprc.map.txt",
version_script: "libcgrouprc.llndk.txt",
},
},
}
llndk_library {
name: "libcgrouprc",
symbol_file: "libcgrouprc.map.txt",
symbol_file: "libcgrouprc.llndk.txt",
native_bridge_supported: true,
export_include_dirs: [
"include",

View file

@ -27,6 +27,11 @@ uint32_t ACgroupController_getVersion(const ACgroupController* controller) {
return controller->version();
}
uint32_t ACgroupController_getFlags(const ACgroupController* controller) {
CHECK(controller != nullptr);
return controller->flags();
}
const char* ACgroupController_getName(const ACgroupController* controller) {
CHECK(controller != nullptr);
return controller->name();

View file

@ -65,6 +65,18 @@ __attribute__((warn_unused_result)) const ACgroupController* ACgroupFile_getCont
__attribute__((warn_unused_result)) uint32_t ACgroupController_getVersion(const ACgroupController*)
__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.
* If the given controller is null, return nullptr.

View file

@ -4,6 +4,7 @@ LIBCGROUPRC { # introduced=29
ACgroupFile_getControllerCount;
ACgroupFile_getController;
ACgroupController_getVersion;
ACgroupController_getFlags;
ACgroupController_getName;
ACgroupController_getPath;
local:

View file

@ -20,12 +20,19 @@ namespace android {
namespace cgrouprc {
namespace format {
CgroupController::CgroupController(uint32_t version, const std::string& name,
const std::string& path) {
CgroupController::CgroupController() : version_(0), flags_(0) {
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
// in licutils, libcutils itself depends on libcgrouprc_format, causing
// a circular dependency.
version_ = version;
flags_ = flags;
strncpy(name_, name.c_str(), sizeof(name_) - 1);
name_[sizeof(name_) - 1] = '\0';
strncpy(path_, path.c_str(), sizeof(path_) - 1);
@ -36,6 +43,10 @@ uint32_t CgroupController::version() const {
return version_;
}
uint32_t CgroupController::flags() const {
return flags_;
}
const char* CgroupController::name() const {
return name_;
}
@ -44,6 +55,10 @@ const char* CgroupController::path() const {
return path_;
}
void CgroupController::set_flags(uint32_t flags) {
flags_ = flags;
}
} // namespace format
} // namespace cgrouprc
} // namespace android

View file

@ -26,18 +26,23 @@ namespace format {
// Minimal controller description to be mmapped into process address space
struct CgroupController {
public:
CgroupController() {}
CgroupController(uint32_t version, const std::string& name, const std::string& path);
CgroupController();
CgroupController(uint32_t version, uint32_t flags, const std::string& name,
const std::string& path);
uint32_t version() const;
uint32_t flags() const;
const char* name() const;
const char* path() const;
void set_flags(uint32_t flags);
private:
static constexpr size_t CGROUP_NAME_BUF_SZ = 16;
static constexpr size_t CGROUP_PATH_BUF_SZ = 32;
uint32_t version_;
uint32_t flags_;
char name_[CGROUP_NAME_BUF_SZ];
char path_[CGROUP_PATH_BUF_SZ];
};

View file

@ -106,8 +106,7 @@ bool UsePerAppMemcg() {
}
static bool isMemoryCgroupSupported() {
std::string cgroup_name;
static bool memcg_supported = CgroupMap::GetInstance().FindController("memory").HasValue();
static bool memcg_supported = CgroupMap::GetInstance().FindController("memory").IsUsable();
return memcg_supported;
}

View file

@ -151,19 +151,19 @@ int set_sched_policy(int tid, SchedPolicy policy) {
}
bool cpusets_enabled() {
static bool enabled = (CgroupMap::GetInstance().FindController("cpuset").HasValue());
static bool enabled = (CgroupMap::GetInstance().FindController("cpuset").IsUsable());
return enabled;
}
bool schedboost_enabled() {
static bool enabled = (CgroupMap::GetInstance().FindController("schedtune").HasValue());
static bool enabled = (CgroupMap::GetInstance().FindController("schedtune").IsUsable());
return enabled;
}
static int getCGroupSubsys(int tid, const char* subsys, std::string& subgroup) {
auto controller = CgroupMap::GetInstance().FindController(subsys);
if (!controller.HasValue()) return -1;
if (!controller.IsUsable()) return -1;
if (!controller.GetTaskGroup(tid, &subgroup)) {
LOG(ERROR) << "Failed to find cgroup for tid " << tid;

View file

@ -32,6 +32,8 @@ class CgroupDescriptor {
std::string uid() const { return uid_; }
std::string gid() const { return gid_; }
void set_mounted(bool mounted);
private:
format::CgroupController controller_;
mode_t mode_ = 0;

View file

@ -35,6 +35,7 @@
#include <android-base/properties.h>
#include <android-base/stringprintf.h>
#include <android-base/unique_fd.h>
#include <android/cgrouprc.h>
#include <json/reader.h>
#include <json/value.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,
const std::string& path, mode_t mode, const std::string& uid,
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 android
@ -296,10 +307,11 @@ bool CgroupSetup() {
}
// setup cgroups
for (const auto& [name, descriptor] : descriptors) {
if (!SetupCgroup(descriptor)) {
for (auto& [name, descriptor] : descriptors) {
if (SetupCgroup(descriptor)) {
descriptor.set_mounted(true);
} else {
// 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";
}
}