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 29, 2021
1 parent 2552fe6 commit ca0df6d
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

using namespace std;

static string opt_demos_cg_name = "demos";
static const string CGROUP_NAME_PREFIX = "demos-";

static string pluralize(unsigned long count, const string &noun)
{
Expand Down Expand Up @@ -77,7 +77,7 @@ static void print_help()
// TODO: list supported policies and short descriptions, probably in a separate function
" -p <POWER_POLICY> 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 <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 WINDOW_MESSAGE to stdout at the beginning of each window;\n"
" this may be useful for external synchronization with scheduler windows\n"
Expand All @@ -99,6 +99,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) {
Expand All @@ -112,7 +115,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;
Expand Down Expand Up @@ -170,7 +173,7 @@ int main(int argc, char *argv[])
// === ROOT CGROUP SETUP ===================================================================
Cgroup unified_root, freezer_root, cpuset_root;
if (!cgroup_setup::create_toplevel_cgroups(
unified_root, freezer_root, cpuset_root, opt_demos_cg_name)) {
unified_root, freezer_root, cpuset_root, root_cgroup_name)) {
// cgroup creation failed
return 1;
}
Expand Down

0 comments on commit ca0df6d

Please sign in to comment.