From 0828676dff618c8ecc9852cb319543570b3a2e72 Mon Sep 17 00:00:00 2001 From: Alex Vakulenko Date: Tue, 3 May 2016 12:00:00 -0700 Subject: [PATCH] Add 'ro.cpuset.default' system property for default cpusets. Normally 'writepid' is used to add a process to a particular cpuset. However certain systems with big/small cores might need to specify a default cpuset for system processes which do not explicitly specify one. Add an option to use 'ro.cpuset.default' system property to specify default cpuset for system processes which do not explicitly write to /dev/cpuset/... with 'writepid' option. The cpuset name specified in ro.cpuset.default is just the cpuset name, e.g. '/system-background', '/foreground', or simply '/' for the "root" cpuset. Bug: 28550814 Test: `m -j32` succeeds for aosp_sailfish-eng. Phone boots successfully. Also tested manually with debug trace messages on emulator with different combinations of values for 'ro.cpuset.default'. Change-Id: I501727fa5ee3f4bb7a938fa104b81a404b616633 --- init/README.md | 4 +++- init/service.cpp | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/init/README.md b/init/README.md index d3dd73a56..99522b95e 100644 --- a/init/README.md +++ b/init/README.md @@ -203,7 +203,9 @@ runs the service. `writepid ` > Write the child's pid to the given files when it forks. Meant for - cgroup/cpuset usage. + cgroup/cpuset usage. If no files under /dev/cpuset/ are specified, but the + system property 'ro.cpuset.default' is set to a non-empty cpuset name (e.g. + '/foreground'), then the pid is written to file /dev/cpuset/_cpuset\_name_/tasks. `priority ` > Scheduling priority of the service process. This value has to be in range diff --git a/init/service.cpp b/init/service.cpp index ba901fdce..35aaa563a 100644 --- a/init/service.cpp +++ b/init/service.cpp @@ -630,6 +630,28 @@ bool Service::Start() { std::for_each(descriptors_.begin(), descriptors_.end(), std::bind(&DescriptorInfo::CreateAndPublish, std::placeholders::_1, scon)); + // See if there were "writepid" instructions to write to files under /dev/cpuset/. + auto cpuset_predicate = [](const std::string& path) { + return android::base::StartsWith(path, "/dev/cpuset/"); + }; + auto iter = std::find_if(writepid_files_.begin(), writepid_files_.end(), cpuset_predicate); + if (iter == writepid_files_.end()) { + // There were no "writepid" instructions for cpusets, check if the system default + // cpuset is specified to be used for the process. + std::string default_cpuset = property_get("ro.cpuset.default"); + if (!default_cpuset.empty()) { + // Make sure the cpuset name starts and ends with '/'. + // A single '/' means the 'root' cpuset. + if (default_cpuset.front() != '/') { + default_cpuset.insert(0, 1, '/'); + } + if (default_cpuset.back() != '/') { + default_cpuset.push_back('/'); + } + writepid_files_.push_back( + StringPrintf("/dev/cpuset%stasks", default_cpuset.c_str())); + } + } std::string pid_str = StringPrintf("%d", getpid()); for (const auto& file : writepid_files_) { if (!WriteStringToFile(pid_str, file)) {