Skip to content

Commit

Permalink
#31 Suffix cgroup names with DEmOS process PID to allow running multi…
Browse files Browse the repository at this point in the history
…ple instances in parallel

TODO: cleanup_crash.sh
  • Loading branch information
MatejKafka committed Apr 26, 2021
1 parent 6e63922 commit b0e6dc2
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,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,
Expand Down Expand Up @@ -207,7 +207,8 @@ static void print_help()
cout << "Usage: demos-sched -c <CONFIG_FILE> [-h] [-g <CGROUP_NAME>]\n"
" -c <CONFIG_FILE> path to configuration file\n"
" -C <CONFIG> inline configuration in YAML format\n"
" -g <CGROUP_NAME> name of root cgroups, default \"" << opt_demos_cg_name << "\"\n"
" -g <CGROUP_NAME> name of root cgroups, default \"" << CGROUP_NAME_PREFIX << "<process_pid>\"\n"
" NOTE: this name must be unique for each running instance of DEmOS\n"
" -m <WINDOW_MESSAGE> print the passed message to stdout at the beginning of each window;\n"
" this may be useful for external synchronization with scheduler windows\n"
" -s rerun itself via systemd-run to get access to unified cgroup hierarchy\n"
Expand All @@ -227,11 +228,14 @@ int main(int argc, char *argv[])
string config_file, config_str, window_sync_message;
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, "dhgm:c:C:s")) != -1) {
switch (opt) {
case 'g': // custom root cgroup name
opt_demos_cg_name = optarg;
root_cgroup_name = optarg;
break;
case 'c': // config file path
config_file = optarg;
Expand Down Expand Up @@ -293,7 +297,7 @@ int main(int argc, char *argv[])

// set up demos container cgroups
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");

// select power policy
Expand Down

0 comments on commit b0e6dc2

Please sign in to comment.