Loading init/service_parser.cpp +39 −1 Original line number Original line Diff line number Diff line Loading @@ -27,6 +27,7 @@ #include <android-base/parseint.h> #include <android-base/parseint.h> #include <android-base/strings.h> #include <android-base/strings.h> #include <hidl-util/FQName.h> #include <hidl-util/FQName.h> #include <processgroup/processgroup.h> #include <system/thread_defs.h> #include <system/thread_defs.h> #include "lmkd_service.h" #include "lmkd_service.h" Loading Loading @@ -395,7 +396,15 @@ Result<void> ServiceParser::ParseShutdown(std::vector<std::string>&& args) { Result<void> ServiceParser::ParseTaskProfiles(std::vector<std::string>&& args) { Result<void> ServiceParser::ParseTaskProfiles(std::vector<std::string>&& args) { args.erase(args.begin()); args.erase(args.begin()); if (service_->task_profiles_.empty()) { service_->task_profiles_ = std::move(args); 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 {}; return {}; } } Loading Loading @@ -521,8 +530,37 @@ Result<void> ServiceParser::ParseUser(std::vector<std::string>&& args) { return {}; 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) { Result<void> ServiceParser::ParseWritepid(std::vector<std::string>&& args) { args.erase(args.begin()); 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); service_->writepid_files_ = std::move(args); return {}; return {}; } } Loading init/service_utils.cpp +11 −0 Original line number Original line Diff line number Diff line Loading @@ -18,6 +18,7 @@ #include <fcntl.h> #include <fcntl.h> #include <grp.h> #include <grp.h> #include <map> #include <sys/mount.h> #include <sys/mount.h> #include <sys/prctl.h> #include <sys/prctl.h> #include <sys/wait.h> #include <sys/wait.h> Loading Loading @@ -305,6 +306,16 @@ Result<void> WritePidToFiles(std::vector<std::string>* files) { } else { } else { LOG(ERROR) << "cpuset cgroup controller is not mounted!"; 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()); std::string pid_str = std::to_string(getpid()); for (const auto& file : *files) { for (const auto& file : *files) { if (!WriteStringToFile(pid_str, file)) { if (!WriteStringToFile(pid_str, file)) { Loading Loading
init/service_parser.cpp +39 −1 Original line number Original line Diff line number Diff line Loading @@ -27,6 +27,7 @@ #include <android-base/parseint.h> #include <android-base/parseint.h> #include <android-base/strings.h> #include <android-base/strings.h> #include <hidl-util/FQName.h> #include <hidl-util/FQName.h> #include <processgroup/processgroup.h> #include <system/thread_defs.h> #include <system/thread_defs.h> #include "lmkd_service.h" #include "lmkd_service.h" Loading Loading @@ -395,7 +396,15 @@ Result<void> ServiceParser::ParseShutdown(std::vector<std::string>&& args) { Result<void> ServiceParser::ParseTaskProfiles(std::vector<std::string>&& args) { Result<void> ServiceParser::ParseTaskProfiles(std::vector<std::string>&& args) { args.erase(args.begin()); args.erase(args.begin()); if (service_->task_profiles_.empty()) { service_->task_profiles_ = std::move(args); 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 {}; return {}; } } Loading Loading @@ -521,8 +530,37 @@ Result<void> ServiceParser::ParseUser(std::vector<std::string>&& args) { return {}; 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) { Result<void> ServiceParser::ParseWritepid(std::vector<std::string>&& args) { args.erase(args.begin()); 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); service_->writepid_files_ = std::move(args); return {}; return {}; } } Loading
init/service_utils.cpp +11 −0 Original line number Original line Diff line number Diff line Loading @@ -18,6 +18,7 @@ #include <fcntl.h> #include <fcntl.h> #include <grp.h> #include <grp.h> #include <map> #include <sys/mount.h> #include <sys/mount.h> #include <sys/prctl.h> #include <sys/prctl.h> #include <sys/wait.h> #include <sys/wait.h> Loading Loading @@ -305,6 +306,16 @@ Result<void> WritePidToFiles(std::vector<std::string>* files) { } else { } else { LOG(ERROR) << "cpuset cgroup controller is not mounted!"; 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()); std::string pid_str = std::to_string(getpid()); for (const auto& file : *files) { for (const auto& file : *files) { if (!WriteStringToFile(pid_str, file)) { if (!WriteStringToFile(pid_str, file)) { Loading