diff --git a/man/kernel-command-line.xml b/man/kernel-command-line.xml index a2a045d209..54213d31c6 100644 --- a/man/kernel-command-line.xml +++ b/man/kernel-command-line.xml @@ -802,11 +802,10 @@ systemd 252 + Kernel command-line arguments systemd.unified_cgroup_hierarchy and systemd.legacy_systemd_cgroup_controller were deprecated. Please switch to - the unified cgroup hierarchy. - - + the unified cgroup hierarchy. diff --git a/man/org.freedesktop.systemd1.xml b/man/org.freedesktop.systemd1.xml index 4c6b1a54d1..384d0aa330 100644 --- a/man/org.freedesktop.systemd1.xml +++ b/man/org.freedesktop.systemd1.xml @@ -469,8 +469,6 @@ node /org/freedesktop/systemd1 { @org.freedesktop.DBus.Property.EmitsChangedSignal("const") readonly u DefaultStartLimitBurst = ...; @org.freedesktop.DBus.Property.EmitsChangedSignal("const") - readonly b DefaultCPUAccounting = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("const") readonly b DefaultIOAccounting = ...; @org.freedesktop.DBus.Property.EmitsChangedSignal("const") readonly b DefaultIPAccounting = ...; @@ -707,8 +705,6 @@ node /org/freedesktop/systemd1 { - - @@ -1151,8 +1147,6 @@ node /org/freedesktop/systemd1 { - - @@ -2884,8 +2878,6 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2eservice { @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly s DelegateSubgroup = '...'; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly b CPUAccounting = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly t CPUWeight = ...; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly t StartupCPUWeight = ...; @@ -3525,8 +3517,6 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2eservice { - - @@ -4179,8 +4169,6 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2eservice { - - @@ -5037,8 +5025,6 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2esocket { @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly s DelegateSubgroup = '...'; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly b CPUAccounting = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly t CPUWeight = ...; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly t StartupCPUWeight = ...; @@ -5690,8 +5676,6 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2esocket { - - @@ -6316,8 +6300,6 @@ node /org/freedesktop/systemd1/unit/avahi_2ddaemon_2esocket { - - @@ -7006,8 +6988,6 @@ node /org/freedesktop/systemd1/unit/home_2emount { @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly s DelegateSubgroup = '...'; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly b CPUAccounting = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly t CPUWeight = ...; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly t StartupCPUWeight = ...; @@ -7589,8 +7569,6 @@ node /org/freedesktop/systemd1/unit/home_2emount { - - @@ -8131,8 +8109,6 @@ node /org/freedesktop/systemd1/unit/home_2emount { - - @@ -8948,8 +8924,6 @@ node /org/freedesktop/systemd1/unit/dev_2dsda3_2eswap { @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly s DelegateSubgroup = '...'; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly b CPUAccounting = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly t CPUWeight = ...; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly t StartupCPUWeight = ...; @@ -9513,8 +9487,6 @@ node /org/freedesktop/systemd1/unit/dev_2dsda3_2eswap { - - @@ -10037,8 +10009,6 @@ node /org/freedesktop/systemd1/unit/dev_2dsda3_2eswap { - - @@ -10713,8 +10683,6 @@ node /org/freedesktop/systemd1/unit/system_2eslice { @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly s DelegateSubgroup = '...'; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly b CPUAccounting = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly t CPUWeight = ...; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly t StartupCPUWeight = ...; @@ -10894,8 +10862,6 @@ node /org/freedesktop/systemd1/unit/system_2eslice { - - @@ -11082,8 +11048,6 @@ node /org/freedesktop/systemd1/unit/system_2eslice { - - @@ -11295,8 +11259,6 @@ node /org/freedesktop/systemd1/unit/session_2d1_2escope { @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly s DelegateSubgroup = '...'; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") - readonly b CPUAccounting = ...; - @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly t CPUWeight = ...; @org.freedesktop.DBus.Property.EmitsChangedSignal("false") readonly t StartupCPUWeight = ...; @@ -11490,8 +11452,6 @@ node /org/freedesktop/systemd1/unit/session_2d1_2escope { - - @@ -11702,8 +11662,6 @@ node /org/freedesktop/systemd1/unit/session_2d1_2escope { - - diff --git a/man/systemd-cgtop.xml b/man/systemd-cgtop.xml index 9ed60e2edc..d734ccd283 100644 --- a/man/systemd-cgtop.xml +++ b/man/systemd-cgtop.xml @@ -46,11 +46,9 @@ given, is honored. This mode is suitable for scripting. Resource usage is only accounted for control groups with the appropriate controllers turned on: - cpu controller for CPU usage, memory controller for memory usage, - and io controller for disk I/O consumption. If resource monitoring for these resources - is required, it is recommended to add the CPUAccounting=1, - MemoryAccounting=1 and IOAccounting=1 settings in the unit files in - question. See + memory controller for memory usage and io controller for disk I/O consumption. + If resource monitoring for these resources is required, it is recommended to add the MemoryAccounting=1 + and IOAccounting=1 settings in the unit files in question. See systemd.resource-control5 for details. @@ -59,10 +57,9 @@ the CPU load value is going to be between 0% and 800%. The number of processors can be found in /proc/cpuinfo. - To emphasize: unless CPUAccounting=1, MemoryAccounting=1, and - IOAccounting=1 are enabled for the services in question, no resource accounting will - be available for system services and the data shown by systemd-cgtop will be - incomplete. + To emphasize: unless MemoryAccounting=1 and IOAccounting=1 + are enabled for the services in question, no resource accounting will be available for system services + and the data shown by systemd-cgtop will be incomplete. diff --git a/man/systemd-run.xml b/man/systemd-run.xml index a9ccc167b6..4ea9a719a3 100644 --- a/man/systemd-run.xml +++ b/man/systemd-run.xml @@ -485,9 +485,10 @@ start request for the transient unit is verified, enqueued, and waited for. Subsequently the invoked unit is monitored, and it is waited until it is deactivated again (most likely because the specified command completed). On exit, terse information about the unit's runtime is shown, including total runtime (as well as - CPU usage, if was set) and the exit code and status of the main - process. This output may be suppressed with . This option may not be combined with - , or the various path, socket, or timer options. + CPU, memory, IO, and IP accounting data, if the corresponding cgroup accounting settings are enabled) + and the exit code and status of the main process. This output may be suppressed with . + This option may not be combined with , or the various + path, socket, or timer options. diff --git a/man/systemd-system.conf.xml b/man/systemd-system.conf.xml index f7b414da5c..23c422df80 100644 --- a/man/systemd-system.conf.xml +++ b/man/systemd-system.conf.xml @@ -201,7 +201,6 @@ - DefaultCPUAccounting= DefaultMemoryAccounting= DefaultTasksAccounting= DefaultIOAccounting= @@ -209,14 +208,12 @@ Configure the default resource accounting settings, as configured per-unit by - CPUAccounting=, MemoryAccounting=, - TasksAccounting=, IOAccounting= and - IPAccounting=. See + MemoryAccounting=, TasksAccounting=, IOAccounting=, + and IPAccounting=. See systemd.resource-control5 for details on the per-unit settings. - DefaultCPUAccounting= defaults to yes when running on kernel ≥4.15, and no on older versions. - DefaultMemoryAccounting= defaults to &MEMORY_ACCOUNTING_DEFAULT;. + DefaultMemoryAccounting= defaults to &MEMORY_ACCOUNTING_DEFAULT;. DefaultTasksAccounting= defaults to yes. The other settings default to no. @@ -754,10 +751,18 @@ systemd 252 - Option DefaultBlockIOAccounting= was deprecated. Please switch - to the unified cgroup hierarchy. - + Option DefaultBlockIOAccounting= was deprecated. Please switch + to the unified cgroup hierarchy. + + + + + + systemd 258 + + DefaultCPUAccounting= setting is deprecated, because CPU accounting + is always available on the unified cgroup hierarchy and such setting has no effect. diff --git a/man/systemd.resource-control.xml b/man/systemd.resource-control.xml index a2f1bc02ba..07c2f617ca 100644 --- a/man/systemd.resource-control.xml +++ b/man/systemd.resource-control.xml @@ -179,30 +179,10 @@ CPUWeight=20 DisableControllers=cpu / \ Units of the types listed above can have settings for resource control configuration: - CPU Accounting and Control + CPU Control - - CPUAccounting= - - - Turn on CPU usage accounting for this unit. Takes a - boolean argument. Note that turning on CPU accounting for - one unit will also implicitly turn it on for all units - contained in the same slice and for all its parent slices - and the units contained therein. The system default for this - setting may be controlled with - DefaultCPUAccounting= in - systemd-system.conf5. - - Under the unified cgroup hierarchy, CPU accounting is available for all units and this - setting has no effect. - - - - - CPUWeight=weight StartupCPUWeight=weight @@ -1689,7 +1669,8 @@ DeviceAllow=/dev/loop-control systemd 252 - Options for controlling the Legacy Control Group Hierarchy (Options for controlling the Legacy Control Group Hierarchy (Control Groups version 1) are now fully deprecated: CPUShares=weight, @@ -1703,9 +1684,16 @@ DeviceAllow=/dev/loop-control BlockIOReadBandwidth=device bytes, BlockIOWriteBandwidth=device bytes. - Please switch to the unified cgroup hierarchy. + Please switch to the unified cgroup hierarchy. + + - + + + systemd 258 + + CPUAccounting= setting is deprecated, because it is always available + on the unified cgroup hierarchy and such setting has no effect. diff --git a/man/systemd.xml b/man/systemd.xml index 88dd158021..857c942eed 100644 --- a/man/systemd.xml +++ b/man/systemd.xml @@ -1507,11 +1507,10 @@ systemd 252 + Kernel command-line arguments systemd.unified_cgroup_hierarchy and systemd.legacy_systemd_cgroup_controller were deprecated. Please switch to - the unified cgroup hierarchy. - - + the unified cgroup hierarchy. diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c index cd13b70519..3287c11f7d 100644 --- a/src/basic/cgroup-util.c +++ b/src/basic/cgroup-util.c @@ -2181,57 +2181,6 @@ static const char *const cgroup_controller_table[_CGROUP_CONTROLLER_MAX] = { DEFINE_STRING_TABLE_LOOKUP(cgroup_controller, CGroupController); -CGroupMask get_cpu_accounting_mask(void) { - static CGroupMask needed_mask = (CGroupMask) -1; - - /* On kernel ≥4.15 with unified hierarchy, cpu.stat's usage_usec is - * provided externally from the CPU controller, which means we don't - * need to enable the CPU controller just to get metrics. This is good, - * because enabling the CPU controller comes at a minor performance - * hit, especially when it's propagated deep into large hierarchies. - * There's also no separate CPU accounting controller available within - * a unified hierarchy. - * - * This combination of factors results in the desired cgroup mask to - * enable for CPU accounting varying as follows: - * - * ╔═════════════════════╤═════════════════════╗ - * ║ Linux ≥4.15 │ Linux <4.15 ║ - * ╔═══════════════╬═════════════════════╪═════════════════════╣ - * ║ Unified ║ nothing │ CGROUP_MASK_CPU ║ - * ╟───────────────╫─────────────────────┼─────────────────────╢ - * ║ Hybrid/Legacy ║ CGROUP_MASK_CPUACCT │ CGROUP_MASK_CPUACCT ║ - * ╚═══════════════╩═════════════════════╧═════════════════════╝ - * - * We check kernel version here instead of manually checking whether - * cpu.stat is present for every cgroup, as that check in itself would - * already be fairly expensive. - * - * Kernels where this patch has been backported will therefore have the - * CPU controller enabled unnecessarily. This is more expensive than - * necessary, but harmless. ☺️ - */ - - if (needed_mask == (CGroupMask) -1) { - if (cg_all_unified()) { - struct utsname u; - assert_se(uname(&u) >= 0); - - if (strverscmp_improved(u.release, "4.15") < 0) - needed_mask = CGROUP_MASK_CPU; - else - needed_mask = 0; - } else - needed_mask = CGROUP_MASK_CPUACCT; - } - - return needed_mask; -} - -bool cpu_accounting_is_cheap(void) { - return get_cpu_accounting_mask() == 0; -} - static const char* const managed_oom_mode_table[_MANAGED_OOM_MODE_MAX] = { [MANAGED_OOM_AUTO] = "auto", [MANAGED_OOM_KILL] = "kill", diff --git a/src/basic/cgroup-util.h b/src/basic/cgroup-util.h index 24da02022f..5af7643b6f 100644 --- a/src/basic/cgroup-util.h +++ b/src/basic/cgroup-util.h @@ -86,9 +86,6 @@ static inline CGroupMask CGROUP_MASK_EXTEND_JOINED(CGroupMask mask) { return mask; } -CGroupMask get_cpu_accounting_mask(void); -bool cpu_accounting_is_cheap(void); - /* Special values for all weight knobs on unified hierarchy */ #define CGROUP_WEIGHT_INVALID UINT64_MAX #define CGROUP_WEIGHT_IDLE UINT64_C(0) diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c index 705a32df0b..fc5707e5a3 100644 --- a/src/cgtop/cgtop.c +++ b/src/cgtop/cgtop.c @@ -140,8 +140,167 @@ static bool is_root_cgroup(const char *path) { return empty_or_root(path); } +static int process_memory(Group *g) { + int r; + + assert(g); + + if (is_root_cgroup(g->path)) + r = procfs_memory_get_used(&g->memory); + else { + _cleanup_free_ char *p = NULL, *v = NULL; + + r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, g->path, "memory.current", &p); + if (r < 0) + return r; + + r = read_one_line_file(p, &v); + if (r == -ENOENT) + return 0; + if (r < 0) + return r; + + r = safe_atou64(v, &g->memory); + } + if (r < 0) + return r; + + if (g->memory > 0) + g->memory_valid = true; + + return 0; +} + +static int process_io(Group *g, unsigned iteration) { + _cleanup_fclose_ FILE *f = NULL; + _cleanup_free_ char *p = NULL; + uint64_t wr = 0, rd = 0; + nsec_t timestamp; + int r; + + assert(g); + + r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, g->path, "io.stat", &p); + if (r < 0) + return r; + + f = fopen(p, "re"); + if (!f) { + if (errno == ENOENT) + return 0; + + return -errno; + } + + for (;;) { + _cleanup_free_ char *line = NULL; + uint64_t k; + char *l; + + r = read_stripped_line(f, LONG_LINE_MAX, &line); + if (r < 0) + return r; + if (r == 0) + break; + + /* Skip the device */ + l = line + strcspn(line, WHITESPACE); + l += strspn(l, WHITESPACE); + + while (!isempty(l)) { + if (sscanf(l, "rbytes=%" SCNu64, &k) == 1) + rd += k; + else if (sscanf(l, "wbytes=%" SCNu64, &k) == 1) + wr += k; + + l += strcspn(l, WHITESPACE); + l += strspn(l, WHITESPACE); + } + } + + timestamp = now_nsec(CLOCK_MONOTONIC); + + if (g->io_iteration == iteration - 1) { + uint64_t x, yr, yw; + + x = (uint64_t) (timestamp - g->io_timestamp); + if (x < 1) + x = 1; + + if (rd > g->io_input) + yr = rd - g->io_input; + else + yr = 0; + + if (wr > g->io_output) + yw = wr - g->io_output; + else + yw = 0; + + if (yr > 0 || yw > 0) { + g->io_input_bps = (yr * 1000000000ULL) / x; + g->io_output_bps = (yw * 1000000000ULL) / x; + g->io_valid = true; + } + } + + g->io_input = rd; + g->io_output = wr; + g->io_timestamp = timestamp; + g->io_iteration = iteration; + + return 0; +} + +static int process_cpu(Group *g, unsigned iteration) { + nsec_t new_usage, timestamp; + int r; + + assert(g); + + if (is_root_cgroup(g->path)) { + r = procfs_cpu_get_usage(&new_usage); + if (r < 0) + return r; + } else { + _cleanup_free_ char *val = NULL; + uint64_t u; + + r = cg_get_keyed_attribute(SYSTEMD_CGROUP_CONTROLLER, g->path, "cpu.stat", STRV_MAKE("usage_usec"), &val); + if (IN_SET(r, -ENOENT, -ENXIO)) + return 0; + if (r < 0) + return r; + + r = safe_atou64(val, &u); + if (r < 0) + return r; + + new_usage = u * NSEC_PER_USEC; + } + + timestamp = now_nsec(CLOCK_MONOTONIC); + + if (g->cpu_iteration == iteration - 1 && new_usage > g->cpu_usage) { + nsec_t x, y; + + x = timestamp - g->cpu_timestamp; + if (x < 1) + x = 1; + + y = new_usage - g->cpu_usage; + g->cpu_fraction = (double) y / (double) x; + g->cpu_valid = true; + } + + g->cpu_usage = new_usage; + g->cpu_timestamp = timestamp; + g->cpu_iteration = iteration; + + return 0; +} + static int process( - const char *controller, const char *path, Hashmap *a, Hashmap *b, @@ -149,16 +308,11 @@ static int process( Group **ret) { Group *g; - int r, all_unified; + int r; - assert(controller); assert(path); assert(a); - all_unified = cg_all_unified(); - if (all_unified < 0) - return all_unified; - g = hashmap_get(a, path); if (!g) { g = hashmap_get(b, path); @@ -187,253 +341,77 @@ static int process( } } - if (streq(controller, SYSTEMD_CGROUP_CONTROLLER) && - IN_SET(arg_count, COUNT_ALL_PROCESSES, COUNT_USERSPACE_PROCESSES)) { + if (IN_SET(arg_count, COUNT_ALL_PROCESSES, COUNT_USERSPACE_PROCESSES)) { _cleanup_fclose_ FILE *f = NULL; pid_t pid; - r = cg_enumerate_processes(controller, path, &f); - if (r == -ENOENT) - return 0; - if (r < 0) + r = cg_enumerate_processes(SYSTEMD_CGROUP_CONTROLLER, path, &f); + if (r < 0 && r != -ENOENT) return r; + if (r >= 0) { + g->n_tasks = 0; + while (cg_read_pid(f, &pid, CGROUP_DONT_SKIP_UNMAPPED) > 0) { - g->n_tasks = 0; - while (cg_read_pid(f, &pid, CGROUP_DONT_SKIP_UNMAPPED) > 0) { + if (arg_count == COUNT_USERSPACE_PROCESSES && pid_is_kernel_thread(pid) > 0) + continue; - if (arg_count == COUNT_USERSPACE_PROCESSES && pid_is_kernel_thread(pid) > 0) - continue; + g->n_tasks++; + } - g->n_tasks++; + if (g->n_tasks > 0) + g->n_tasks_valid = true; } - if (g->n_tasks > 0) - g->n_tasks_valid = true; - - } else if (streq(controller, "pids") && arg_count == COUNT_PIDS) { + } else if (arg_count == COUNT_PIDS) { if (is_root_cgroup(path)) { r = procfs_tasks_get_current(&g->n_tasks); if (r < 0) return r; - } else { - _cleanup_free_ char *p = NULL, *v = NULL; - r = cg_get_path(controller, path, "pids.current", &p); - if (r < 0) - return r; - - r = read_one_line_file(p, &v); - if (r == -ENOENT) - return 0; - if (r < 0) - return r; - - r = safe_atou64(v, &g->n_tasks); - if (r < 0) - return r; - } - - if (g->n_tasks > 0) g->n_tasks_valid = true; - - } else if (streq(controller, "memory")) { - - if (is_root_cgroup(path)) { - r = procfs_memory_get_used(&g->memory); - if (r < 0) - return r; } else { _cleanup_free_ char *p = NULL, *v = NULL; - if (all_unified) - r = cg_get_path(controller, path, "memory.current", &p); - else - r = cg_get_path(controller, path, "memory.usage_in_bytes", &p); + r = cg_get_path(SYSTEMD_CGROUP_CONTROLLER, path, "pids.current", &p); if (r < 0) return r; r = read_one_line_file(p, &v); - if (r == -ENOENT) - return 0; - if (r < 0) + if (r < 0 && r != -ENOENT) return r; - - r = safe_atou64(v, &g->memory); - if (r < 0) - return r; - } - - if (g->memory > 0) - g->memory_valid = true; - - } else if ((streq(controller, "io") && all_unified) || - (streq(controller, "blkio") && !all_unified)) { - _cleanup_fclose_ FILE *f = NULL; - _cleanup_free_ char *p = NULL; - uint64_t wr = 0, rd = 0; - nsec_t timestamp; - - r = cg_get_path(controller, path, all_unified ? "io.stat" : "blkio.io_service_bytes", &p); - if (r < 0) - return r; - - f = fopen(p, "re"); - if (!f) { - if (errno == ENOENT) - return 0; - return -errno; - } - - for (;;) { - _cleanup_free_ char *line = NULL; - uint64_t k, *q; - char *l; - - r = read_stripped_line(f, LONG_LINE_MAX, &line); - if (r < 0) - return r; - if (r == 0) - break; - - /* Skip the device */ - l = line + strcspn(line, WHITESPACE); - l += strspn(l, WHITESPACE); - - if (all_unified) { - while (!isempty(l)) { - if (sscanf(l, "rbytes=%" SCNu64, &k) == 1) - rd += k; - else if (sscanf(l, "wbytes=%" SCNu64, &k) == 1) - wr += k; - - l += strcspn(l, WHITESPACE); - l += strspn(l, WHITESPACE); - } - } else { - if (first_word(l, "Read")) { - l += 4; - q = &rd; - } else if (first_word(l, "Write")) { - l += 5; - q = ≀ - } else - continue; - - l += strspn(l, WHITESPACE); - r = safe_atou64(l, &k); + if (r >= 0) { + r = safe_atou64(v, &g->n_tasks); if (r < 0) - continue; + return r; - *q += k; + if (g->n_tasks > 0) + g->n_tasks_valid = true; } } - timestamp = now_nsec(CLOCK_MONOTONIC); + } else + assert_not_reached(); - if (g->io_iteration == iteration - 1) { - uint64_t x, yr, yw; + r = process_memory(g); + if (r < 0) + return r; - x = (uint64_t) (timestamp - g->io_timestamp); - if (x < 1) - x = 1; + r = process_io(g, iteration); + if (r < 0) + return r; - if (rd > g->io_input) - yr = rd - g->io_input; - else - yr = 0; - - if (wr > g->io_output) - yw = wr - g->io_output; - else - yw = 0; - - if (yr > 0 || yw > 0) { - g->io_input_bps = (yr * 1000000000ULL) / x; - g->io_output_bps = (yw * 1000000000ULL) / x; - g->io_valid = true; - } - } - - g->io_input = rd; - g->io_output = wr; - g->io_timestamp = timestamp; - g->io_iteration = iteration; - } else if (STR_IN_SET(controller, "cpu", "cpuacct") || cpu_accounting_is_cheap()) { - _cleanup_free_ char *p = NULL, *v = NULL; - uint64_t new_usage; - nsec_t timestamp; - - if (is_root_cgroup(path)) { - r = procfs_cpu_get_usage(&new_usage); - if (r < 0) - return r; - } else if (all_unified) { - _cleanup_free_ char *val = NULL; - - if (!streq(controller, "cpu")) - return 0; - - r = cg_get_keyed_attribute("cpu", path, "cpu.stat", STRV_MAKE("usage_usec"), &val); - if (IN_SET(r, -ENOENT, -ENXIO)) - return 0; - if (r < 0) - return r; - - r = safe_atou64(val, &new_usage); - if (r < 0) - return r; - - new_usage *= NSEC_PER_USEC; - } else { - if (!streq(controller, "cpuacct")) - return 0; - - r = cg_get_path(controller, path, "cpuacct.usage", &p); - if (r < 0) - return r; - - r = read_one_line_file(p, &v); - if (r == -ENOENT) - return 0; - if (r < 0) - return r; - - r = safe_atou64(v, &new_usage); - if (r < 0) - return r; - } - - timestamp = now_nsec(CLOCK_MONOTONIC); - - if (g->cpu_iteration == iteration - 1 && - (nsec_t) new_usage > g->cpu_usage) { - - nsec_t x, y; - - x = timestamp - g->cpu_timestamp; - if (x < 1) - x = 1; - - y = (nsec_t) new_usage - g->cpu_usage; - g->cpu_fraction = (double) y / (double) x; - g->cpu_valid = true; - } - - g->cpu_usage = (nsec_t) new_usage; - g->cpu_timestamp = timestamp; - g->cpu_iteration = iteration; - - } + r = process_cpu(g, iteration); + if (r < 0) + return r; if (ret) *ret = g; - return 0; + return 1; } -static int refresh_one( - const char *controller, +static int refresh( const char *path, Hashmap *a, Hashmap *b, @@ -442,29 +420,34 @@ static int refresh_one( Group **ret) { _cleanup_closedir_ DIR *d = NULL; - Group *ours = NULL; + Group *ours; int r; - assert(controller); assert(path); assert(a); - if (depth > arg_depth) + if (depth > arg_depth) { + if (ret) + *ret = NULL; return 0; + } - r = process(controller, path, a, b, iteration, &ours); + r = process(path, a, b, iteration, &ours); if (r < 0) return r; - r = cg_enumerate_subgroups(controller, path, &d); - if (r == -ENOENT) + r = cg_enumerate_subgroups(SYSTEMD_CGROUP_CONTROLLER, path, &d); + if (r == -ENOENT) { + if (ret) + *ret = NULL; return 0; + } if (r < 0) return r; for (;;) { _cleanup_free_ char *fn = NULL, *p = NULL; - Group *child = NULL; + Group *child; r = cg_read_subgroup(d, &fn); if (r < 0) @@ -478,15 +461,13 @@ static int refresh_one( path_simplify(p); - r = refresh_one(controller, p, a, b, iteration, depth + 1, &child); + r = refresh(p, a, b, iteration, depth + 1, &child); if (r < 0) return r; - - if (arg_recursive && + if (r > 0 && + arg_recursive && IN_SET(arg_count, COUNT_ALL_PROCESSES, COUNT_USERSPACE_PROCESSES) && - child && - child->n_tasks_valid && - streq(controller, SYSTEMD_CGROUP_CONTROLLER)) { + child->n_tasks_valid) { /* Recursively sum up processes */ @@ -505,18 +486,6 @@ static int refresh_one( return 1; } -static int refresh(const char *root, Hashmap *a, Hashmap *b, unsigned iteration) { - int r; - - FOREACH_STRING(c, SYSTEMD_CGROUP_CONTROLLER, "cpu", "cpuacct", "memory", "io", "blkio", "pids") { - r = refresh_one(c, root, a, b, iteration, 0, NULL); - if (r < 0) - return r; - } - - return 0; -} - static int group_compare(Group * const *a, Group * const *b) { const Group *x = *a, *y = *b; int r; @@ -923,7 +892,7 @@ static int loop(const char *root) { if (t >= usec_add(last_refresh, arg_delay) || immediate_refresh) { - r = refresh(root, a, b, iteration++); + r = refresh(root, a, b, iteration++, /* depth = */ 0, /* ret = */ NULL); if (r < 0) return log_error_errno(r, "Failed to refresh: %m"); diff --git a/src/core/cgroup.c b/src/core/cgroup.c index dbab38c3c0..2050494a85 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -477,7 +477,6 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) { startup_cpuset_mems = cpu_set_to_range_string(&c->startup_cpuset_mems); fprintf(f, - "%sCPUAccounting: %s\n" "%sIOAccounting: %s\n" "%sMemoryAccounting: %s\n" "%sTasksAccounting: %s\n" @@ -516,7 +515,6 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) { "%sManagedOOMPreference: %s\n" "%sMemoryPressureWatch: %s\n" "%sCoredumpReceive: %s\n", - prefix, yes_no(c->cpu_accounting), prefix, yes_no(c->io_accounting), prefix, yes_no(c->memory_accounting), prefix, yes_no(c->tasks_accounting), @@ -1698,9 +1696,6 @@ static CGroupMask unit_get_cgroup_mask(Unit *u) { /* Figure out which controllers we need, based on the cgroup context object */ - if (c->cpu_accounting) - mask |= get_cpu_accounting_mask(); - if (cgroup_context_has_cpu_weight(c) || c->cpu_quota_per_sec_usec != USEC_INFINITY) mask |= CGROUP_MASK_CPU; @@ -3628,10 +3623,6 @@ static int unit_get_cpu_usage_raw(const Unit *u, const CGroupRuntime *crt, nsec_ if (unit_has_host_root_cgroup(u)) return procfs_cpu_get_usage(ret); - /* Requisite controllers for CPU accounting are not enabled */ - if ((get_cpu_accounting_mask() & ~crt->cgroup_realized_mask) != 0) - return -ENODATA; - _cleanup_free_ char *val = NULL; uint64_t us; @@ -3660,9 +3651,6 @@ int unit_get_cpu_usage(Unit *u, nsec_t *ret) { * started. If the cgroup has been removed already, returns the last cached value. To cache the value, simply * call this function with a NULL return value. */ - if (!UNIT_CGROUP_BOOL(u, cpu_accounting)) - return -ENODATA; - CGroupRuntime *crt = unit_get_cgroup_runtime(u); if (!crt) return -ENODATA; diff --git a/src/core/cgroup.h b/src/core/cgroup.h index 88e9085152..bdd4a2236b 100644 --- a/src/core/cgroup.h +++ b/src/core/cgroup.h @@ -123,7 +123,6 @@ typedef enum CGroupPressureWatch { * manager is running (except for an occasional SetProperty() configuration change), outside of reload * cycles. */ struct CGroupContext { - bool cpu_accounting; bool io_accounting; bool memory_accounting; bool tasks_accounting; diff --git a/src/core/dbus-cgroup.c b/src/core/dbus-cgroup.c index 713bd30265..326c440cf9 100644 --- a/src/core/dbus-cgroup.c +++ b/src/core/dbus-cgroup.c @@ -384,7 +384,6 @@ const sd_bus_vtable bus_cgroup_vtable[] = { SD_BUS_PROPERTY("Delegate", "b", bus_property_get_bool, offsetof(CGroupContext, delegate), 0), SD_BUS_PROPERTY("DelegateControllers", "as", property_get_delegate_controllers, 0, 0), SD_BUS_PROPERTY("DelegateSubgroup", "s", NULL, offsetof(CGroupContext, delegate_subgroup), 0), - SD_BUS_PROPERTY("CPUAccounting", "b", bus_property_get_bool, offsetof(CGroupContext, cpu_accounting), 0), SD_BUS_PROPERTY("CPUWeight", "t", NULL, offsetof(CGroupContext, cpu_weight), 0), SD_BUS_PROPERTY("StartupCPUWeight", "t", NULL, offsetof(CGroupContext, startup_cpu_weight), 0), SD_BUS_PROPERTY("CPUQuotaPerSecUSec", "t", bus_property_get_usec, offsetof(CGroupContext, cpu_quota_per_sec_usec), 0), @@ -441,6 +440,7 @@ const sd_bus_vtable bus_cgroup_vtable[] = { SD_BUS_PROPERTY("MemoryPressureThresholdUSec", "t", bus_property_get_usec, offsetof(CGroupContext, memory_pressure_threshold_usec), 0), SD_BUS_PROPERTY("NFTSet", "a(iiss)", property_get_cgroup_nft_set, 0, 0), SD_BUS_PROPERTY("CoredumpReceive", "b", bus_property_get_bool, offsetof(CGroupContext, coredump_receive), 0), + /* deprecated cgroup v1 properties */ SD_BUS_PROPERTY("MemoryLimit", "t", bus_property_get_uint64_max, 0, SD_BUS_VTABLE_DEPRECATED|SD_BUS_VTABLE_HIDDEN), SD_BUS_PROPERTY("CPUShares", "t", bus_property_get_uint64_max, 0, SD_BUS_VTABLE_DEPRECATED|SD_BUS_VTABLE_HIDDEN), @@ -451,6 +451,9 @@ const sd_bus_vtable bus_cgroup_vtable[] = { SD_BUS_PROPERTY("BlockIODeviceWeight", "a(st)", property_get_blockio_ast, 0, SD_BUS_VTABLE_DEPRECATED|SD_BUS_VTABLE_HIDDEN), SD_BUS_PROPERTY("BlockIOReadBandwidth", "a(st)", property_get_blockio_ast, 0, SD_BUS_VTABLE_DEPRECATED|SD_BUS_VTABLE_HIDDEN), SD_BUS_PROPERTY("BlockIOWriteBandwidth", "a(st)", property_get_blockio_ast, 0, SD_BUS_VTABLE_DEPRECATED|SD_BUS_VTABLE_HIDDEN), + /* since kernel v4.15 CPU accounting requires no controller, i.e. is available everywhere */ + SD_BUS_PROPERTY("CPUAccounting", "b", bus_property_get_bool_true, 0, SD_BUS_VTABLE_DEPRECATED|SD_BUS_VTABLE_HIDDEN), + SD_BUS_VTABLE_END }; @@ -1038,9 +1041,6 @@ int bus_cgroup_set_property( flags |= UNIT_PRIVATE; - if (streq(name, "CPUAccounting")) - return bus_cgroup_set_boolean(u, name, &c->cpu_accounting, get_cpu_accounting_mask(), message, flags, error); - if (streq(name, "CPUWeight")) return bus_cgroup_set_cpu_weight(u, name, &c->cpu_weight, message, flags, error); @@ -2038,7 +2038,8 @@ int bus_cgroup_set_property( "StartupBlockIOWeight", "BlockIODeviceWeight", "BlockIOReadBandwidth", - "BlockIOWriteBandwidth")) { + "BlockIOWriteBandwidth", + "CPUAccounting")) { /* see comment in bus_cgroup_vtable */ r = sd_bus_message_skip(message, NULL); if (r < 0) diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index b2705e04ce..24b08b1a5d 100644 --- a/src/core/dbus-manager.c +++ b/src/core/dbus-manager.c @@ -2887,7 +2887,6 @@ const sd_bus_vtable bus_manager_vtable[] = { SD_BUS_PROPERTY("DefaultStartLimitIntervalSec", "t", bus_property_get_usec, offsetof(Manager, defaults.start_limit.interval), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), SD_BUS_PROPERTY("DefaultStartLimitInterval", "t", bus_property_get_usec, offsetof(Manager, defaults.start_limit.interval), SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_HIDDEN), SD_BUS_PROPERTY("DefaultStartLimitBurst", "u", bus_property_get_unsigned, offsetof(Manager, defaults.start_limit.burst), SD_BUS_VTABLE_PROPERTY_CONST), - SD_BUS_PROPERTY("DefaultCPUAccounting", "b", bus_property_get_bool, offsetof(Manager, defaults.cpu_accounting), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("DefaultIOAccounting", "b", bus_property_get_bool, offsetof(Manager, defaults.io_accounting), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("DefaultIPAccounting", "b", bus_property_get_bool, offsetof(Manager, defaults.ip_accounting), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("DefaultMemoryAccounting", "b", bus_property_get_bool, offsetof(Manager, defaults.memory_accounting), SD_BUS_VTABLE_PROPERTY_CONST), @@ -2932,8 +2931,11 @@ const sd_bus_vtable bus_manager_vtable[] = { SD_BUS_PROPERTY("DefaultOOMScoreAdjust", "i", property_get_oom_score_adjust, 0, SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("CtrlAltDelBurstAction", "s", bus_property_get_emergency_action, offsetof(Manager, cad_burst_action), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("SoftRebootsCount", "u", bus_property_get_unsigned, offsetof(Manager, soft_reboots_count), SD_BUS_VTABLE_PROPERTY_CONST), + /* deprecated cgroup v1 property */ SD_BUS_PROPERTY("DefaultBlockIOAccounting", "b", bus_property_get_bool_false, 0, SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_DEPRECATED|SD_BUS_VTABLE_HIDDEN), + /* see comment in bus_cgroup_vtable */ + SD_BUS_PROPERTY("DefaultCPUAccounting", "b", bus_property_get_bool_true, 0, SD_BUS_VTABLE_PROPERTY_CONST|SD_BUS_VTABLE_DEPRECATED|SD_BUS_VTABLE_HIDDEN), SD_BUS_METHOD_WITH_ARGS("GetUnit", SD_BUS_ARGS("s", name), diff --git a/src/core/execute-serialize.c b/src/core/execute-serialize.c index 18ec06b6a4..2a91a6fadb 100644 --- a/src/core/execute-serialize.c +++ b/src/core/execute-serialize.c @@ -34,10 +34,6 @@ static int exec_cgroup_context_serialize(const CGroupContext *c, FILE *f) { if (!c) return 0; - r = serialize_bool_elide(f, "exec-cgroup-context-cpu-accounting", c->cpu_accounting); - if (r < 0) - return r; - r = serialize_bool_elide(f, "exec-cgroup-context-io-accounting", c->io_accounting); if (r < 0) return r; @@ -445,12 +441,7 @@ static int exec_cgroup_context_deserialize(CGroupContext *c, FILE *f) { if (r == 0) /* eof or end marker */ break; - if ((val = startswith(l, "exec-cgroup-context-cpu-accounting="))) { - r = parse_boolean(val); - if (r < 0) - return r; - c->cpu_accounting = r; - } else if ((val = startswith(l, "exec-cgroup-context-io-accounting="))) { + if ((val = startswith(l, "exec-cgroup-context-io-accounting="))) { r = parse_boolean(val); if (r < 0) return r; diff --git a/src/core/load-fragment-gperf.gperf.in b/src/core/load-fragment-gperf.gperf.in index 2c0a0b629a..aeccf07d55 100644 --- a/src/core/load-fragment-gperf.gperf.in +++ b/src/core/load-fragment-gperf.gperf.in @@ -201,7 +201,7 @@ {{type}}.StartupAllowedCPUs, config_parse_allowed_cpuset, 0, offsetof({{type}}, cgroup_context.startup_cpuset_cpus) {{type}}.AllowedMemoryNodes, config_parse_allowed_cpuset, 0, offsetof({{type}}, cgroup_context.cpuset_mems) {{type}}.StartupAllowedMemoryNodes, config_parse_allowed_cpuset, 0, offsetof({{type}}, cgroup_context.startup_cpuset_mems) -{{type}}.CPUAccounting, config_parse_bool, 0, offsetof({{type}}, cgroup_context.cpu_accounting) +{{type}}.CPUAccounting, config_parse_warn_compat, DISABLED_LEGACY, 0 {{type}}.CPUWeight, config_parse_cg_cpu_weight, 0, offsetof({{type}}, cgroup_context.cpu_weight) {{type}}.StartupCPUWeight, config_parse_cg_cpu_weight, 0, offsetof({{type}}, cgroup_context.startup_cpu_weight) {{type}}.CPUShares, config_parse_warn_compat, DISABLED_LEGACY, 0 diff --git a/src/core/main.c b/src/core/main.c index 3ffacc8ccc..cb846367c2 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -791,7 +791,7 @@ static int parse_config_file(void) { { "Manager", "DefaultLimitNICE", config_parse_rlimit, RLIMIT_NICE, arg_defaults.rlimit }, { "Manager", "DefaultLimitRTPRIO", config_parse_rlimit, RLIMIT_RTPRIO, arg_defaults.rlimit }, { "Manager", "DefaultLimitRTTIME", config_parse_rlimit, RLIMIT_RTTIME, arg_defaults.rlimit }, - { "Manager", "DefaultCPUAccounting", config_parse_bool, 0, &arg_defaults.cpu_accounting }, + { "Manager", "DefaultCPUAccounting", config_parse_warn_compat, DISABLED_LEGACY, NULL }, { "Manager", "DefaultIOAccounting", config_parse_bool, 0, &arg_defaults.io_accounting }, { "Manager", "DefaultIPAccounting", config_parse_bool, 0, &arg_defaults.ip_accounting }, { "Manager", "DefaultBlockIOAccounting", config_parse_warn_compat, DISABLED_LEGACY, NULL }, diff --git a/src/core/manager-varlink.c b/src/core/manager-varlink.c index 3c7e746640..c38c4b1947 100644 --- a/src/core/manager-varlink.c +++ b/src/core/manager-varlink.c @@ -58,8 +58,6 @@ static int manager_context_build_json(sd_json_variant **ret, const char *name, v JSON_BUILD_PAIR_FINITE_USEC("DefaultDeviceTimeoutUSec", m->defaults.device_timeout_usec), JSON_BUILD_PAIR_FINITE_USEC("DefaultRestartUSec", m->defaults.restart_usec), JSON_BUILD_PAIR_RATELIMIT("DefaultStartLimit", &m->defaults.start_limit), - SD_JSON_BUILD_PAIR_BOOLEAN("DefaultCPUAccounting", m->defaults.cpu_accounting), - SD_JSON_BUILD_PAIR_BOOLEAN("DefaultBlockIOAccounting", m->defaults.blockio_accounting), SD_JSON_BUILD_PAIR_BOOLEAN("DefaultIOAccounting", m->defaults.io_accounting), SD_JSON_BUILD_PAIR_BOOLEAN("DefaultIPAccounting", m->defaults.ip_accounting), SD_JSON_BUILD_PAIR_BOOLEAN("DefaultMemoryAccounting", m->defaults.memory_accounting), diff --git a/src/core/manager.c b/src/core/manager.c index 1000818c7a..4f6232e8ad 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -4197,10 +4197,8 @@ int manager_set_unit_defaults(Manager *m, const UnitDefaults *defaults) { m->defaults.start_limit = defaults->start_limit; - m->defaults.cpu_accounting = defaults->cpu_accounting; m->defaults.memory_accounting = defaults->memory_accounting; m->defaults.io_accounting = defaults->io_accounting; - m->defaults.blockio_accounting = defaults->blockio_accounting; m->defaults.tasks_accounting = defaults->tasks_accounting; m->defaults.ip_accounting = defaults->ip_accounting; @@ -5096,12 +5094,8 @@ void unit_defaults_init(UnitDefaults *defaults, RuntimeScope scope) { .device_timeout_usec = manager_default_timeout(scope), .start_limit = { DEFAULT_START_LIMIT_INTERVAL, DEFAULT_START_LIMIT_BURST }, - /* On 4.15+ with unified hierarchy, CPU accounting is essentially free as it doesn't require the CPU - * controller to be enabled, so the default is to enable it unless we got told otherwise. */ - .cpu_accounting = cpu_accounting_is_cheap(), .memory_accounting = MEMORY_ACCOUNTING_DEFAULT, .io_accounting = false, - .blockio_accounting = false, .tasks_accounting = true, .ip_accounting = false, diff --git a/src/core/manager.h b/src/core/manager.h index 27783d06bb..31b4b59c0b 100644 --- a/src/core/manager.h +++ b/src/core/manager.h @@ -149,10 +149,8 @@ typedef struct UnitDefaults { RateLimit start_limit; - bool cpu_accounting; bool memory_accounting; bool io_accounting; - bool blockio_accounting; bool tasks_accounting; bool ip_accounting; diff --git a/src/core/slice.c b/src/core/slice.c index a4a82118dd..361ef84a38 100644 --- a/src/core/slice.c +++ b/src/core/slice.c @@ -334,7 +334,6 @@ static void slice_enumerate_perpetual(Manager *m) { * means the kernel will track CPU/tasks/memory for us anyway, and it is all available in /proc. Let's * hence turn accounting on here, so that our APIs to query this data are available. */ - s->cgroup_context.cpu_accounting = true; s->cgroup_context.tasks_accounting = true; s->cgroup_context.memory_accounting = true; } diff --git a/src/core/system.conf.in b/src/core/system.conf.in index 1c08aa4d22..051a18bd21 100644 --- a/src/core/system.conf.in +++ b/src/core/system.conf.in @@ -54,7 +54,6 @@ #DefaultStartLimitIntervalSec=10s #DefaultStartLimitBurst=5 #DefaultEnvironment= -#DefaultCPUAccounting=yes #DefaultIOAccounting=no #DefaultIPAccounting=no #DefaultMemoryAccounting={{ 'yes' if MEMORY_ACCOUNTING_DEFAULT else 'no' }} diff --git a/src/core/unit.c b/src/core/unit.c index 7e3eaa4c92..6b19947df0 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -173,7 +173,6 @@ static void unit_init(Unit *u) { * context, _before_ the rest of the settings have * been initialized */ - cc->cpu_accounting = u->manager->defaults.cpu_accounting; cc->io_accounting = u->manager->defaults.io_accounting; cc->memory_accounting = u->manager->defaults.memory_accounting; cc->tasks_accounting = u->manager->defaults.tasks_accounting; diff --git a/src/shared/bus-get-properties.c b/src/shared/bus-get-properties.c index de23611ac4..5be6bbc906 100644 --- a/src/shared/bus-get-properties.c +++ b/src/shared/bus-get-properties.c @@ -8,6 +8,7 @@ #include "string-util.h" BUS_DEFINE_PROPERTY_GET_GLOBAL(bus_property_get_bool_false, "b", 0); +BUS_DEFINE_PROPERTY_GET_GLOBAL(bus_property_get_bool_true, "b", 1); BUS_DEFINE_PROPERTY_GET_GLOBAL(bus_property_get_uint64_max, "t", UINT64_MAX); int bus_property_get_bool( diff --git a/src/shared/bus-get-properties.h b/src/shared/bus-get-properties.h index 73e85cd2c8..95eab4a4bf 100644 --- a/src/shared/bus-get-properties.h +++ b/src/shared/bus-get-properties.h @@ -5,10 +5,6 @@ #include "macro.h" -/* For deprecated properties. */ -int bus_property_get_bool_false(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error); -int bus_property_get_uint64_max(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error); - int bus_property_get_bool(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error); int bus_property_set_bool(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *value, void *userdata, sd_bus_error *error); int bus_property_get_tristate(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error); @@ -105,3 +101,8 @@ int bus_property_get_string_set(sd_bus *bus, const char *path, const char *inter #define BUS_PROPERTY_DUAL_TIMESTAMP(name, offset, flags) \ SD_BUS_PROPERTY(name, "t", bus_property_get_usec, (offset) + offsetof(struct dual_timestamp, realtime), (flags)), \ SD_BUS_PROPERTY(name "Monotonic", "t", bus_property_get_usec, (offset) + offsetof(struct dual_timestamp, monotonic), (flags)) + +/* For deprecated properties. */ +int bus_property_get_bool_false(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error); +int bus_property_get_bool_true(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error); +int bus_property_get_uint64_max(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error); diff --git a/src/shared/bus-print-properties.c b/src/shared/bus-print-properties.c index 9ac6ddb3a9..ec7e2c9543 100644 --- a/src/shared/bus-print-properties.c +++ b/src/shared/bus-print-properties.c @@ -164,7 +164,6 @@ static int bus_print_property(const char *name, const char *expected_value, sd_b else if ((STR_IN_SET(name, "CPUWeight", "StartupCPUWeight", "IOWeight", "StartupIOWeight") && u == CGROUP_WEIGHT_INVALID) || (STR_IN_SET(name, "CPUShares", "StartupCPUShares") && u == CGROUP_CPU_SHARES_INVALID) || - (STR_IN_SET(name, "BlockIOWeight", "StartupBlockIOWeight") && u == CGROUP_BLKIO_WEIGHT_INVALID) || (STR_IN_SET(name, "MemoryCurrent", "MemoryAvailable", "TasksCurrent") && u == UINT64_MAX) || (startswith(name, "Memory") && ENDSWITH_SET(name, "Current", "Peak") && u == CGROUP_LIMIT_MAX) || (startswith(name, "IO") && ENDSWITH_SET(name, "Bytes", "Operations") && u == UINT64_MAX) || diff --git a/src/shared/varlink-io.systemd.Manager.c b/src/shared/varlink-io.systemd.Manager.c index bc6a607746..c27eff6e21 100644 --- a/src/shared/varlink-io.systemd.Manager.c +++ b/src/shared/varlink-io.systemd.Manager.c @@ -53,10 +53,6 @@ static SD_VARLINK_DEFINE_STRUCT_TYPE( SD_VARLINK_DEFINE_FIELD(DefaultRestartUSec, SD_VARLINK_INT, 0), SD_VARLINK_FIELD_COMMENT("https://www.freedesktop.org/software/systemd/man/"PROJECT_VERSION_STR"/systemd-system.conf.html#DefaultStartLimit="), SD_VARLINK_DEFINE_FIELD_BY_TYPE(DefaultStartLimit, RateLimit, SD_VARLINK_NULLABLE), - SD_VARLINK_FIELD_COMMENT("https://www.freedesktop.org/software/systemd/man/"PROJECT_VERSION_STR"/systemd-system.conf.html#DefaultCPUAccounting="), - SD_VARLINK_DEFINE_FIELD(DefaultCPUAccounting, SD_VARLINK_BOOL, 0), - SD_VARLINK_FIELD_COMMENT("https://www.freedesktop.org/software/systemd/man/"PROJECT_VERSION_STR"/systemd-system.conf.html#DefaultBlockIOAccounting="), - SD_VARLINK_DEFINE_FIELD(DefaultBlockIOAccounting, SD_VARLINK_BOOL, 0), SD_VARLINK_FIELD_COMMENT("https://www.freedesktop.org/software/systemd/man/"PROJECT_VERSION_STR"/systemd-system.conf.html#DefaultIOAccounting="), SD_VARLINK_DEFINE_FIELD(DefaultIOAccounting, SD_VARLINK_BOOL, 0), SD_VARLINK_FIELD_COMMENT("https://www.freedesktop.org/software/systemd/man/"PROJECT_VERSION_STR"/systemd-system.conf.html#DefaultIPAccounting="), diff --git a/src/systemctl/systemctl-show.c b/src/systemctl/systemctl-show.c index 84dc1ff9ea..47d519a4ab 100644 --- a/src/systemctl/systemctl-show.c +++ b/src/systemctl/systemctl-show.c @@ -1505,8 +1505,7 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m return 1; - } else if (contents[0] == SD_BUS_TYPE_STRUCT_BEGIN && - STR_IN_SET(name, "IODeviceWeight", "BlockIODeviceWeight")) { + } else if (contents[0] == SD_BUS_TYPE_STRUCT_BEGIN && streq(name, "IODeviceWeight")) { const char *path; uint64_t weight; @@ -1526,8 +1525,7 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m return 1; } else if (contents[0] == SD_BUS_TYPE_STRUCT_BEGIN && - (cgroup_io_limit_type_from_string(name) >= 0 || - STR_IN_SET(name, "BlockIOReadBandwidth", "BlockIOWriteBandwidth"))) { + cgroup_io_limit_type_from_string(name) >= 0) { const char *path; uint64_t bandwidth; diff --git a/src/test/test-cgroup-mask.c b/src/test/test-cgroup-mask.c index 1050c4f47d..f73372d631 100644 --- a/src/test/test-cgroup-mask.c +++ b/src/test/test-cgroup-mask.c @@ -31,7 +31,6 @@ TEST_RET(cgroup_mask, .sd_booted = true) { _cleanup_(manager_freep) Manager *m = NULL; Unit *son, *daughter, *parent, *root, *grandchild, *parent_deep, *nomem_parent, *nomem_leaf; int r; - CGroupMask cpu_accounting_mask = get_cpu_accounting_mask(); r = enter_cgroup_subroot(NULL); if (r == -ENOMEDIUM) @@ -53,9 +52,7 @@ TEST_RET(cgroup_mask, .sd_booted = true) { /* Turn off all kinds of default accounting, so that we can * verify the masks resulting of our configuration and nothing * else. */ - m->defaults.cpu_accounting = - m->defaults.memory_accounting = - m->defaults.blockio_accounting = + m->defaults.memory_accounting = m->defaults.io_accounting = m->defaults.tasks_accounting = false; m->defaults.tasks_max = CGROUP_TASKS_MAX_UNSET; @@ -80,7 +77,6 @@ TEST_RET(cgroup_mask, .sd_booted = true) { /* Verify per-unit cgroups settings. */ ASSERT_CGROUP_MASK_JOINED(unit_get_own_mask(son), CGROUP_MASK_CPU); - ASSERT_CGROUP_MASK_JOINED(unit_get_own_mask(daughter), cpu_accounting_mask); ASSERT_CGROUP_MASK_JOINED(unit_get_own_mask(grandchild), 0); ASSERT_CGROUP_MASK_JOINED(unit_get_own_mask(parent_deep), CGROUP_MASK_MEMORY); ASSERT_CGROUP_MASK_JOINED(unit_get_own_mask(parent), (CGROUP_MASK_IO | CGROUP_MASK_BLKIO)); @@ -93,40 +89,40 @@ TEST_RET(cgroup_mask, .sd_booted = true) { ASSERT_CGROUP_MASK_JOINED(unit_get_members_mask(daughter), 0); ASSERT_CGROUP_MASK_JOINED(unit_get_members_mask(grandchild), 0); ASSERT_CGROUP_MASK_JOINED(unit_get_members_mask(parent_deep), 0); - ASSERT_CGROUP_MASK_JOINED(unit_get_members_mask(parent), (CGROUP_MASK_CPU | cpu_accounting_mask | CGROUP_MASK_MEMORY)); + ASSERT_CGROUP_MASK_JOINED(unit_get_members_mask(parent), (CGROUP_MASK_CPU | CGROUP_MASK_MEMORY)); ASSERT_CGROUP_MASK_JOINED(unit_get_members_mask(nomem_parent), (CGROUP_MASK_IO | CGROUP_MASK_BLKIO | CGROUP_MASK_MEMORY)); ASSERT_CGROUP_MASK_JOINED(unit_get_members_mask(nomem_leaf), 0); - ASSERT_CGROUP_MASK_JOINED(unit_get_members_mask(root), (CGROUP_MASK_CPU | cpu_accounting_mask | CGROUP_MASK_IO | CGROUP_MASK_BLKIO | CGROUP_MASK_MEMORY)); + ASSERT_CGROUP_MASK_JOINED(unit_get_members_mask(root), (CGROUP_MASK_CPU | CGROUP_MASK_IO | CGROUP_MASK_BLKIO | CGROUP_MASK_MEMORY)); /* Verify aggregation of sibling masks. */ - ASSERT_CGROUP_MASK_JOINED(unit_get_siblings_mask(son), (CGROUP_MASK_CPU | cpu_accounting_mask | CGROUP_MASK_MEMORY)); - ASSERT_CGROUP_MASK_JOINED(unit_get_siblings_mask(daughter), (CGROUP_MASK_CPU | cpu_accounting_mask | CGROUP_MASK_MEMORY)); + ASSERT_CGROUP_MASK_JOINED(unit_get_siblings_mask(son), (CGROUP_MASK_CPU | CGROUP_MASK_MEMORY)); + ASSERT_CGROUP_MASK_JOINED(unit_get_siblings_mask(daughter), (CGROUP_MASK_CPU | CGROUP_MASK_MEMORY)); ASSERT_CGROUP_MASK_JOINED(unit_get_siblings_mask(grandchild), 0); - ASSERT_CGROUP_MASK_JOINED(unit_get_siblings_mask(parent_deep), (CGROUP_MASK_CPU | cpu_accounting_mask | CGROUP_MASK_MEMORY)); - ASSERT_CGROUP_MASK_JOINED(unit_get_siblings_mask(parent), (CGROUP_MASK_CPU | cpu_accounting_mask | CGROUP_MASK_IO | CGROUP_MASK_BLKIO | CGROUP_MASK_MEMORY)); + ASSERT_CGROUP_MASK_JOINED(unit_get_siblings_mask(parent_deep), (CGROUP_MASK_CPU | CGROUP_MASK_MEMORY)); + ASSERT_CGROUP_MASK_JOINED(unit_get_siblings_mask(parent), (CGROUP_MASK_CPU | CGROUP_MASK_IO | CGROUP_MASK_BLKIO | CGROUP_MASK_MEMORY)); ASSERT_CGROUP_MASK_JOINED(unit_get_siblings_mask(nomem_parent), (CGROUP_MASK_CPU | CGROUP_MASK_CPUACCT | CGROUP_MASK_IO | CGROUP_MASK_BLKIO | CGROUP_MASK_MEMORY)); ASSERT_CGROUP_MASK_JOINED(unit_get_siblings_mask(nomem_leaf), (CGROUP_MASK_IO | CGROUP_MASK_BLKIO | CGROUP_MASK_MEMORY)); - ASSERT_CGROUP_MASK_JOINED(unit_get_siblings_mask(root), (CGROUP_MASK_CPU | cpu_accounting_mask | CGROUP_MASK_IO | CGROUP_MASK_BLKIO | CGROUP_MASK_MEMORY)); + ASSERT_CGROUP_MASK_JOINED(unit_get_siblings_mask(root), (CGROUP_MASK_CPU | CGROUP_MASK_IO | CGROUP_MASK_BLKIO | CGROUP_MASK_MEMORY)); /* Verify aggregation of target masks. */ - ASSERT_CGROUP_MASK(unit_get_target_mask(son), (CGROUP_MASK_EXTEND_JOINED(CGROUP_MASK_CPU | cpu_accounting_mask | CGROUP_MASK_MEMORY) & m->cgroup_supported)); - ASSERT_CGROUP_MASK(unit_get_target_mask(daughter), (CGROUP_MASK_EXTEND_JOINED(CGROUP_MASK_CPU | cpu_accounting_mask | CGROUP_MASK_MEMORY) & m->cgroup_supported)); + ASSERT_CGROUP_MASK(unit_get_target_mask(son), (CGROUP_MASK_EXTEND_JOINED(CGROUP_MASK_CPU | CGROUP_MASK_MEMORY) & m->cgroup_supported)); + ASSERT_CGROUP_MASK(unit_get_target_mask(daughter), (CGROUP_MASK_EXTEND_JOINED(CGROUP_MASK_CPU | CGROUP_MASK_MEMORY) & m->cgroup_supported)); ASSERT_CGROUP_MASK(unit_get_target_mask(grandchild), 0); - ASSERT_CGROUP_MASK(unit_get_target_mask(parent_deep), (CGROUP_MASK_EXTEND_JOINED(CGROUP_MASK_CPU | cpu_accounting_mask | CGROUP_MASK_MEMORY) & m->cgroup_supported)); - ASSERT_CGROUP_MASK(unit_get_target_mask(parent), (CGROUP_MASK_EXTEND_JOINED(CGROUP_MASK_CPU | cpu_accounting_mask | CGROUP_MASK_IO | CGROUP_MASK_BLKIO | CGROUP_MASK_MEMORY) & m->cgroup_supported)); + ASSERT_CGROUP_MASK(unit_get_target_mask(parent_deep), (CGROUP_MASK_EXTEND_JOINED(CGROUP_MASK_CPU | CGROUP_MASK_MEMORY) & m->cgroup_supported)); + ASSERT_CGROUP_MASK(unit_get_target_mask(parent), (CGROUP_MASK_EXTEND_JOINED(CGROUP_MASK_CPU | CGROUP_MASK_IO | CGROUP_MASK_BLKIO | CGROUP_MASK_MEMORY) & m->cgroup_supported)); ASSERT_CGROUP_MASK(unit_get_target_mask(nomem_parent), (CGROUP_MASK_EXTEND_JOINED(CGROUP_MASK_CPU | CGROUP_MASK_CPUACCT | CGROUP_MASK_IO | CGROUP_MASK_BLKIO) & m->cgroup_supported)); ASSERT_CGROUP_MASK(unit_get_target_mask(nomem_leaf), (CGROUP_MASK_EXTEND_JOINED(CGROUP_MASK_IO | CGROUP_MASK_BLKIO) & m->cgroup_supported)); - ASSERT_CGROUP_MASK(unit_get_target_mask(root), (CGROUP_MASK_EXTEND_JOINED(CGROUP_MASK_CPU | cpu_accounting_mask | CGROUP_MASK_IO | CGROUP_MASK_BLKIO | CGROUP_MASK_MEMORY) & m->cgroup_supported)); + ASSERT_CGROUP_MASK(unit_get_target_mask(root), (CGROUP_MASK_EXTEND_JOINED(CGROUP_MASK_CPU | CGROUP_MASK_IO | CGROUP_MASK_BLKIO | CGROUP_MASK_MEMORY) & m->cgroup_supported)); /* Verify aggregation of enable masks. */ ASSERT_CGROUP_MASK(unit_get_enable_mask(son), 0); ASSERT_CGROUP_MASK(unit_get_enable_mask(daughter), 0); ASSERT_CGROUP_MASK(unit_get_enable_mask(grandchild), 0); ASSERT_CGROUP_MASK(unit_get_enable_mask(parent_deep), 0); - ASSERT_CGROUP_MASK(unit_get_enable_mask(parent), (CGROUP_MASK_EXTEND_JOINED(CGROUP_MASK_CPU | cpu_accounting_mask | CGROUP_MASK_MEMORY) & m->cgroup_supported)); + ASSERT_CGROUP_MASK(unit_get_enable_mask(parent), (CGROUP_MASK_EXTEND_JOINED(CGROUP_MASK_CPU | CGROUP_MASK_MEMORY) & m->cgroup_supported)); ASSERT_CGROUP_MASK(unit_get_enable_mask(nomem_parent), (CGROUP_MASK_EXTEND_JOINED(CGROUP_MASK_IO | CGROUP_MASK_BLKIO) & m->cgroup_supported)); ASSERT_CGROUP_MASK(unit_get_enable_mask(nomem_leaf), 0); - ASSERT_CGROUP_MASK(unit_get_enable_mask(root), (CGROUP_MASK_EXTEND_JOINED(CGROUP_MASK_CPU | cpu_accounting_mask | CGROUP_MASK_IO | CGROUP_MASK_BLKIO | CGROUP_MASK_MEMORY) & m->cgroup_supported)); + ASSERT_CGROUP_MASK(unit_get_enable_mask(root), (CGROUP_MASK_EXTEND_JOINED(CGROUP_MASK_CPU | CGROUP_MASK_IO | CGROUP_MASK_BLKIO | CGROUP_MASK_MEMORY) & m->cgroup_supported)); return 0; } diff --git a/test/units/TEST-26-SYSTEMCTL.sh b/test/units/TEST-26-SYSTEMCTL.sh index 8e895aa9ae..cc6b844989 100755 --- a/test/units/TEST-26-SYSTEMCTL.sh +++ b/test/units/TEST-26-SYSTEMCTL.sh @@ -249,12 +249,12 @@ systemctl revert "$UNIT_NAME" (! grep -r "IPAccounting=" "/etc/systemd/system.control/${UNIT_NAME}.d/") (! grep -r "MemoryMax=" "/etc/systemd/system.control/${UNIT_NAME}.d/") # Same stuff, but with --runtime, which should use /run -systemctl set-property --runtime "$UNIT_NAME" CPUAccounting=no CPUQuota=10% +systemctl set-property --runtime "$UNIT_NAME" IOAccounting=no CPUQuota=10% systemctl cat "$UNIT_NAME" -grep -r "CPUAccounting=no" "/run/systemd/system.control/${UNIT_NAME}.d/" +grep -r "IOAccounting=no" "/run/systemd/system.control/${UNIT_NAME}.d/" grep -r "CPUQuota=10.00%" "/run/systemd/system.control/${UNIT_NAME}.d/" systemctl revert "$UNIT_NAME" -(! grep -r "CPUAccounting=" "/run/systemd/system.control/${UNIT_NAME}.d/") +(! grep -r "IOAccounting=" "/run/systemd/system.control/${UNIT_NAME}.d/") (! grep -r "CPUQuota=" "/run/systemd/system.control/${UNIT_NAME}.d/") # Failed-unit related tests diff --git a/test/units/TEST-55-OOMD-workload.slice b/test/units/TEST-55-OOMD-workload.slice index 1558073604..dae4e6ce66 100644 --- a/test/units/TEST-55-OOMD-workload.slice +++ b/test/units/TEST-55-OOMD-workload.slice @@ -3,7 +3,6 @@ Description=Test slice for memory pressure kills [Slice] -CPUAccounting=true MemoryAccounting=true IOAccounting=true TasksAccounting=true diff --git a/test/units/daughter.service b/test/units/daughter.service index 0ee4f24a4e..bf02f8e9f6 100644 --- a/test/units/daughter.service +++ b/test/units/daughter.service @@ -6,4 +6,3 @@ Description=Daughter Service Slice=parent.slice Type=oneshot ExecStart=true -CPUAccounting=true diff --git a/tools/check-version-history.py b/tools/check-version-history.py index efd7023762..dce2b6abd1 100644 --- a/tools/check-version-history.py +++ b/tools/check-version-history.py @@ -75,9 +75,12 @@ def find_undocumented_commands(pages, ignorelist): parent = listitem if listitem is not None else varlistentry rev = parent.getchildren()[-1] - if rev.get("href") != "version-info.xml": - if (filename, path) not in ignorelist: + if ( + rev.get("href") != "version-info.xml" and + not path.startswith(tuple(entry[1] for entry in ignorelist if entry[0] == filename)) + ): undocumented.append((filename, path)) + return undocumented diff --git a/tools/command_ignorelist b/tools/command_ignorelist index 9408d5a5f9..0159054b8d 100644 --- a/tools/command_ignorelist +++ b/tools/command_ignorelist @@ -14,6 +14,7 @@ journald.conf.xml ./refsect1[title="Options"]/variablelist/varlistentry[term="Co journald.conf.xml ./refsect1[title="Options"]/variablelist/varlistentry[term="RateLimitIntervalSec="] journald.conf.xml ./refsect1[title="Options"]/variablelist/varlistentry[term="SystemMaxUse="] journald.conf.xml ./refsect1[title="Options"]/variablelist/varlistentry[term="ForwardToSyslog="] +kernel-command-line.xml ./refsect1[title="History"]/ kernel-install.xml ./refsect1[title="Commands"]/variablelist/varlistentry[term="add [[[KERNEL-VERSION] KERNEL-IMAGE] [INITRD-FILE ...]]"]/listitem/variablelist/varlistentry[term="50-depmod.install"] kernel-install.xml ./refsect1[title="Commands"]/variablelist/varlistentry[term="add [[[KERNEL-VERSION] KERNEL-IMAGE] [INITRD-FILE ...]]"]/listitem/variablelist/varlistentry[term="90-loaderentry.install"] kernel-install.xml ./refsect1[title="Commands"]/variablelist/varlistentry[term="add [[[KERNEL-VERSION] KERNEL-IMAGE] [INITRD-FILE ...]]"]/listitem/variablelist/varlistentry[term="90-uki-copy.install"] @@ -129,6 +130,7 @@ systemctl.xml ./refsect1[title="Commands"]/refsect2[title="System Commands"]/var systemctl.xml ./refsect1[title="Commands"]/refsect2[title="System Commands"]/variablelist/varlistentry[term="suspend"] systemctl.xml ./refsect1[title="Commands"]/refsect2[title="System Commands"]/variablelist/varlistentry[term="hibernate"] systemctl.xml ./refsect1[title="Commands"]/refsect2[title="System Commands"]/variablelist/varlistentry[term="switch-root ROOT INIT"] +systemd.xml ./refsect1[title="History"]/ systemd-ask-password.xml ./refsect1[title="Options"]/variablelist/varlistentry[term="--icon="] systemd-ask-password.xml ./refsect1[title="Options"]/variablelist/varlistentry[term="--timeout="] systemd-ask-password.xml ./refsect1[title="Options"]/variablelist/varlistentry[term="--no-tty"] @@ -175,6 +177,7 @@ systemd-nspawn.xml ./refsect1[title="Options"]/refsect2[title="Execution Options systemd-nspawn.xml ./refsect1[title="Options"]/refsect2[title="System Identity Options"]/variablelist/varlistentry[term="--uuid="] systemd-nspawn.xml ./refsect1[title="Options"]/refsect2[title="Networking Options"]/variablelist/varlistentry[term="--private-network"] systemd-nspawn.xml ./refsect1[title="Options"]/refsect2[title="Image Options"]/variablelist/varlistentry[term="--read-only"] +systemd-system.conf.xml ./refsect1[title="History"]/ systemd-tmpfiles.xml ./refsect1[title="Commands and options"]/variablelist/varlistentry[term="--create"] systemd-tmpfiles.xml ./refsect1[title="Commands and options"]/variablelist/varlistentry[term="--clean"] systemd-tmpfiles.xml ./refsect1[title="Commands and options"]/variablelist/varlistentry[term="--remove"] @@ -249,6 +252,7 @@ systemd.path.xml ./refsect1[title="Options"]/variablelist/varlistentry[term="Pat systemd.path.xml ./refsect1[title="Options"]/variablelist/varlistentry[term="Unit="] systemd.path.xml ./refsect1[title="Options"]/variablelist/varlistentry[term="MakeDirectory="] systemd.path.xml ./refsect1[title="Options"]/variablelist/varlistentry[term="DirectoryMode="] +systemd.resource-control.xml ./refsect1[title="History"]/ systemd.service.xml ./refsect1[title="Options"]/variablelist/varlistentry[term="Type="] systemd.service.xml ./refsect1[title="Options"]/variablelist/varlistentry[term="RemainAfterExit="] systemd.service.xml ./refsect1[title="Options"]/variablelist/varlistentry[term="GuessMainPID="]