Merge "init: try converting writepid used with cgroups into task_profiles command" am: 8330095807
am: 34cc1ffb19
am: c47ece62d4
Original change: https://android-review.googlesource.com/c/platform/system/core/+/1740144 Change-Id: I833e1c01d189bd755be4f9f079c34302db337802 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
b1ab56b30e
2 changed files with 50 additions and 1 deletions
|
@ -27,6 +27,7 @@
|
|||
#include <android-base/parseint.h>
|
||||
#include <android-base/strings.h>
|
||||
#include <hidl-util/FQName.h>
|
||||
#include <processgroup/processgroup.h>
|
||||
#include <system/thread_defs.h>
|
||||
|
||||
#include "lmkd_service.h"
|
||||
|
@ -395,7 +396,15 @@ Result<void> ServiceParser::ParseShutdown(std::vector<std::string>&& args) {
|
|||
|
||||
Result<void> ServiceParser::ParseTaskProfiles(std::vector<std::string>&& args) {
|
||||
args.erase(args.begin());
|
||||
service_->task_profiles_ = std::move(args);
|
||||
if (service_->task_profiles_.empty()) {
|
||||
service_->task_profiles_ = std::move(args);
|
||||
} else {
|
||||
// Some task profiles might have been added during writepid conversions
|
||||
service_->task_profiles_.insert(service_->task_profiles_.end(),
|
||||
std::make_move_iterator(args.begin()),
|
||||
std::make_move_iterator(args.end()));
|
||||
args.clear();
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -521,8 +530,37 @@ Result<void> ServiceParser::ParseUser(std::vector<std::string>&& args) {
|
|||
return {};
|
||||
}
|
||||
|
||||
// Convert legacy paths used to migrate processes between cgroups using writepid command.
|
||||
// We can't get these paths from TaskProfiles because profile definitions are changing
|
||||
// when we migrate to cgroups v2 while these hardcoded paths stay the same.
|
||||
static std::optional<const std::string> ConvertTaskFileToProfile(const std::string& file) {
|
||||
static const std::map<const std::string, const std::string> map = {
|
||||
{"/dev/stune/top-app/tasks", "MaxPerformance"},
|
||||
{"/dev/stune/foreground/tasks", "HighPerformance"},
|
||||
{"/dev/cpuset/camera-daemon/tasks", "CameraServiceCapacity"},
|
||||
{"/dev/cpuset/foreground/tasks", "ProcessCapacityHigh"},
|
||||
{"/dev/cpuset/system-background/tasks", "ServiceCapacityLow"},
|
||||
{"/dev/stune/nnapi-hal/tasks", "NNApiHALPerformance"},
|
||||
{"/dev/blkio/background/tasks", "LowIoPriority"},
|
||||
};
|
||||
auto iter = map.find(file);
|
||||
return iter == map.end() ? std::nullopt : std::make_optional<const std::string>(iter->second);
|
||||
}
|
||||
|
||||
Result<void> ServiceParser::ParseWritepid(std::vector<std::string>&& args) {
|
||||
args.erase(args.begin());
|
||||
// Convert any cgroup writes into appropriate task_profiles
|
||||
for (auto iter = args.begin(); iter != args.end();) {
|
||||
auto task_profile = ConvertTaskFileToProfile(*iter);
|
||||
if (task_profile) {
|
||||
LOG(WARNING) << "'writepid " << *iter << "' is converted into 'task_profiles "
|
||||
<< task_profile.value() << "' for service " << service_->name();
|
||||
service_->task_profiles_.push_back(task_profile.value());
|
||||
iter = args.erase(iter);
|
||||
} else {
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
service_->writepid_files_ = std::move(args);
|
||||
return {};
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
#include <fcntl.h>
|
||||
#include <grp.h>
|
||||
#include <map>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/prctl.h>
|
||||
#include <sys/wait.h>
|
||||
|
@ -305,6 +306,16 @@ Result<void> WritePidToFiles(std::vector<std::string>* files) {
|
|||
} else {
|
||||
LOG(ERROR) << "cpuset cgroup controller is not mounted!";
|
||||
}
|
||||
|
||||
// Issue a warning whenever writepid is being used with a cgroup. This can't be done during
|
||||
// command parsing because cgroups might not be configured at the time or parsing.
|
||||
for (const auto& file : *files) {
|
||||
if (CgroupGetControllerFromPath(file, nullptr)) {
|
||||
LOG(WARNING) << "writepid usage with cgroups path '" << file
|
||||
<< "' is obsolete, please use task_profiles!";
|
||||
}
|
||||
}
|
||||
|
||||
std::string pid_str = std::to_string(getpid());
|
||||
for (const auto& file : *files) {
|
||||
if (!WriteStringToFile(pid_str, file)) {
|
||||
|
|
Loading…
Reference in a new issue