cgroup: set cpu period as well

This commit is contained in:
Robert Swiecki 2018-02-04 04:23:45 +01:00
parent 3ee825c4aa
commit 30e84f7add
2 changed files with 13 additions and 4 deletions

View File

@ -169,7 +169,7 @@ static bool cgroupInitNsFromParentCpu(struct nsjconf_t* nsjconf, pid_t pid) {
char fname[PATH_MAX];
char cpu_ms_per_sec_str[512];
snprintf(cpu_ms_per_sec_str, sizeof(cpu_ms_per_sec_str), "0x%x",
snprintf(cpu_ms_per_sec_str, sizeof(cpu_ms_per_sec_str), "%u",
nsjconf->cgroup_cpu_ms_per_sec * 1000U);
snprintf(fname, sizeof(fname), "%s/cpu.cfs_quota_us", cpu_cgroup_path);
LOG_D("Setting '%s' to '%s'", fname, cpu_ms_per_sec_str);
@ -179,6 +179,15 @@ static bool cgroupInitNsFromParentCpu(struct nsjconf_t* nsjconf, pid_t pid) {
return false;
}
const char cpu_period_us[] = "1000000";
snprintf(fname, sizeof(fname), "%s/cpu.cfs_period_us", cpu_cgroup_path);
LOG_D("Setting '%s' to '%s'", fname, cpu_period_us);
if (!utilWriteBufToFile(
fname, cpu_period_us, strlen(cpu_period_us), O_WRONLY | O_CLOEXEC)) {
LOG_E("Could not update cpu period");
return false;
}
char pid_str[512];
snprintf(pid_str, sizeof(pid_str), "%d", (int)pid);
snprintf(fname, sizeof(fname), "%s/tasks", cpu_cgroup_path);

View File

@ -363,13 +363,13 @@ bool cmdlineParse(int argc, char* argv[], struct nsjconf_t* nsjconf) {
.cgroup_mem_max = (size_t)0,
.cgroup_pids_mount = "/sys/fs/cgroup/pids",
.cgroup_pids_parent = "NSJAIL",
.cgroup_pids_max = (unsigned int)0,
.cgroup_pids_max = 0U,
.cgroup_net_cls_mount = "/sys/fs/cgroup/net_cls",
.cgroup_net_cls_parent = "NSJAIL",
.cgroup_net_cls_classid = (unsigned int)0,
.cgroup_net_cls_classid = 0U,
.cgroup_cpu_mount = "/sys/fs/cgroup/cpu",
.cgroup_cpu_parent = "NSJAIL",
.cgroup_cpu_ms_per_sec = (unsigned int)0,
.cgroup_cpu_ms_per_sec = 0U,
.iface_no_lo = false,
.iface_vs = NULL,
.iface_vs_ip = "0.0.0.0",