From 4d1caefe1d319e2798f3f71926e608e7ee1202ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 5 Nov 2019 20:18:11 +0100 Subject: 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. --- src/core/dbus-cgroup.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/core/dbus-cgroup.c b/src/core/dbus-cgroup.c index 4a9206076a..776dee5ea2 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 }; 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; -- cgit v1.2.1