From dcea2fc0ea424911bbbb41ee7bb7d9f10abfcb71 Mon Sep 17 00:00:00 2001 From: Matej Kafka Date: Sat, 24 Apr 2021 21:08:00 +0200 Subject: [PATCH] #31 Suffix cgroup names with DEmOS process PID to allow running multiple instances in parallel TODO: cleanup_crash.sh --- src/main.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index cdee422f..48b5152d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,7 +13,7 @@ using namespace std; -static string opt_demos_cg_name = "demos"; +static const string CGROUP_NAME_PREFIX = "demos-"; static void handle_cgroup_exc(stringstream &commands, stringstream &mount_cmds, @@ -226,7 +226,7 @@ static void print_help() // TODO: list supported policies and short descriptions, probably in a separate function " -p name of selected power management policy; if multiple instances of DEmOS\n" " are running in parallel, this parameter must not be passed to more than a single one\n" - " -g name of root cgroups, default \"" << opt_demos_cg_name << "\"\n" + " -g name of root cgroups, default \"" << CGROUP_NAME_PREFIX << "\"\n" " NOTE: this name must be unique for each running instance of DEmOS\n" " -m print WINDOW_MESSAGE to stdout at the beginning of each window;\n" " this may be useful for external synchronization with scheduler windows\n" @@ -248,6 +248,9 @@ int main(int argc, char *argv[]) string config_file, config_str, window_sync_message, mf_sync_message, power_policy_name; bool dump_config = false; bool systemd_run = false; + // to support multiple instances of DEmOS running at once (primarily for testing), + // default root cgroup name includes the scheduler process PID + string root_cgroup_name = CGROUP_NAME_PREFIX + to_string(getpid()); while ((opt = getopt(argc, argv, "c:C:p:g:m:M:sdh")) != -1) { switch (opt) { @@ -261,7 +264,7 @@ int main(int argc, char *argv[]) power_policy_name = optarg; break; case 'g': // custom root cgroup name - opt_demos_cg_name = optarg; + root_cgroup_name = optarg; break; case 'm': // window start sync message window_sync_message = optarg; @@ -318,7 +321,7 @@ int main(int argc, char *argv[]) // === ROOT CGROUP SETUP =================================================================== Cgroup unified_root, freezer_root, cpuset_root; - create_toplevel_cgroups(unified_root, freezer_root, cpuset_root, opt_demos_cg_name); + create_toplevel_cgroups(unified_root, freezer_root, cpuset_root, root_cgroup_name); logger->debug("Top level cgroups created");