From: Zbigniew Jędrzejewski-Szmek Date: Tue, 5 Nov 2019 19:18:11 +0000 (+0100) Subject: core: write cgroup limits as permilles X-Git-Tag: v244-rc1~27^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0877d4e0cf8ee02bd460045a77cbe1b7aa497239;p=thirdparty%2Fsystemd.git core: write cgroup limits as permilles We allow expressing configuration as a fraction with granularity of 0.001, but when writing out the unit file, we'd round that up to 0.01. Longer term, I think it'd be nicer to simply use floats and do away with arbitrary restrictions on precision. --- diff --git a/src/core/dbus-cgroup.c b/src/core/dbus-cgroup.c index 591c5dd7f52..27dc9e43c3e 100644 --- a/src/core/dbus-cgroup.c +++ b/src/core/dbus-cgroup.c @@ -698,9 +698,10 @@ static int bus_cgroup_set_boolean( /* Prepare to chop off suffix */ \ assert_se(endswith(name, "Scale")); \ \ - unit_write_settingf(u, flags, name, "%.*s=%" PRIu32 "%%", \ + uint32_t scaled = DIV_ROUND_UP((uint64_t) raw * 1000, (uint64_t) UINT32_MAX); \ + unit_write_settingf(u, flags, name, "%.*s=%" PRIu32 ".%" PRIu32 "%%", \ (int)(strlen(name) - strlen("Scale")), name, \ - (uint32_t) (DIV_ROUND_UP((uint64_t) raw * 100U, (uint64_t) UINT32_MAX))); \ + scaled / 10, scaled % 10); \ } \ \ return 1; \ @@ -778,8 +779,9 @@ static int bus_cgroup_set_tasks_max_scale( *p = (TasksMax) { v, UINT32_MAX }; /* .scale is not 0, so this is interpreted as v/UINT32_MAX. */ unit_invalidate_cgroup(u, CGROUP_MASK_PIDS); - unit_write_settingf(u, flags, name, "%s=%" PRIu32 "%%", "TasksMax", - (uint32_t) (DIV_ROUND_UP((uint64_t) v * 100U, (uint64_t) UINT32_MAX))); + uint32_t scaled = DIV_ROUND_UP((uint64_t) v * 100U, (uint64_t) UINT32_MAX); + unit_write_settingf(u, flags, name, "%s=%" PRIu32 ".%" PRIu32 "%%", "TasksMax", + scaled / 10, scaled % 10); } return 1;