diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2019-11-05 20:18:11 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2019-11-05 21:06:15 +0100 |
commit | 4d1caefe1d319e2798f3f71926e608e7ee1202ef (patch) | |
tree | 515ea0235d8fcdc40ad505551e98a81f195c413c | |
parent | b03fa16bd0342aa50aa897e71d050d05dddaa298 (diff) | |
download | systemd-4d1caefe1d319e2798f3f71926e608e7ee1202ef.tar.gz |
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.
-rw-r--r-- | src/core/dbus-cgroup.c | 10 |
1 files 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; |