diff --git a/src/libcrun/cgroup-internal.h b/src/libcrun/cgroup-internal.h index da44b2f26e..9823c2bd08 100644 --- a/src/libcrun/cgroup-internal.h +++ b/src/libcrun/cgroup-internal.h @@ -84,4 +84,6 @@ int initialize_cpuset_subsystem (const char *path, libcrun_error_t *err); int write_cpuset_resources (int dirfd_cpuset, int cgroup2, runtime_spec_schema_config_linux_resources_cpu *cpu, libcrun_error_t *err); +int write_cpu_burst (int cpu_dirfd, bool cgroup2, runtime_spec_schema_config_linux_resources_cpu *cpu, libcrun_error_t *err); + #endif diff --git a/src/libcrun/cgroup-resources.c b/src/libcrun/cgroup-resources.c index 4bb7fb807a..d2934f3bcf 100644 --- a/src/libcrun/cgroup-resources.c +++ b/src/libcrun/cgroup-resources.c @@ -888,6 +888,20 @@ write_memory_resources (int dirfd, bool cgroup2, runtime_spec_schema_config_linu return 0; } +int +write_cpu_burst (int cpu_dirfd, bool cgroup2, runtime_spec_schema_config_linux_resources_cpu *cpu, + libcrun_error_t *err) +{ + char fmt_buf[32]; + size_t len; + + if (! cpu->burst_present) + return 0; + + len = sprintf (fmt_buf, "%" PRIi64, cpu->burst); + return write_cgroup_file (cpu_dirfd, cgroup2 ? "cpu.max.burst" : "cpu.cfs_burst_us", fmt_buf, len, err); +} + static int write_pids_resources (int dirfd, bool cgroup2, runtime_spec_schema_config_linux_resources_pids *pids, libcrun_error_t *err) @@ -1013,7 +1027,8 @@ write_cpu_resources (int dirfd_cpu, bool cgroup2, runtime_spec_schema_config_lin if (UNLIKELY (ret < 0)) return ret; } - return 0; + + return write_cpu_burst (dirfd_cpu, cgroup2, cpu, err); } int diff --git a/src/libcrun/cgroup-systemd.c b/src/libcrun/cgroup-systemd.c index b55ae0ca5d..24ce1d51d9 100644 --- a/src/libcrun/cgroup-systemd.c +++ b/src/libcrun/cgroup-systemd.c @@ -198,6 +198,41 @@ setup_rt_runtime (runtime_spec_schema_config_linux_resources *resources, return 0; } +static int +setup_missing_cpu_options_for_systemd (runtime_spec_schema_config_linux_resources *resources, bool cgroup2, const char *path, libcrun_error_t *err) +{ + cleanup_free char *cgroup_path = NULL; + cleanup_close int dirfd = -1; + int parent; + int ret; + + if (resources->cpu == NULL) + return 0; + + if (! resources->cpu->burst_present) + return 0; + + for (parent = 0; parent < 2; parent++) + { + if (cgroup2) + ret = append_paths (&cgroup_path, err, CGROUP_ROOT, path ? path : "", (parent ? ".." : NULL), NULL); + else + ret = append_paths (&cgroup_path, err, CGROUP_ROOT, "/cpu", path ? path : "", (parent ? ".." : NULL), NULL); + if (UNLIKELY (ret < 0)) + return ret; + + dirfd = open (cgroup_path, O_DIRECTORY | O_CLOEXEC); + if (UNLIKELY (dirfd < 0)) + return crun_make_error (err, errno, "open `%s`", cgroup_path); + + ret = write_cpu_burst (dirfd, cgroup2, resources->cpu, err); + if (UNLIKELY (ret < 0)) + return ret; + } + + return 0; +} + static int setup_cpuset_for_systemd_v1 (runtime_spec_schema_config_linux_resources *resources, const char *path, libcrun_error_t *err) { @@ -381,6 +416,10 @@ systemd_finalize (struct libcrun_cgroup_args *args, char **path_out, return crun_make_error (err, 0, "invalid cgroup mode `%d`", cgroup_mode); } + ret = setup_missing_cpu_options_for_systemd (resources, cgroup_mode == CGROUP_MODE_UNIFIED, path, err); + if (UNLIKELY (ret < 0)) + return ret; + *path_out = path; path = NULL; @@ -1381,6 +1420,10 @@ libcrun_update_resources_systemd (struct libcrun_cgroup_status *cgroup_status, goto exit; } + ret = setup_missing_cpu_options_for_systemd (resources, cgroup_mode == CGROUP_MODE_UNIFIED, cgroup_status->path, err); + if (UNLIKELY (ret < 0)) + goto exit; + ret = 0; exit: