File 1027-erts-Fix-calculate_cpu_quota.patch of Package erlang
From a381114fab04efea629950d03ffaaaf8bc13ef06 Mon Sep 17 00:00:00 2001
From: Lukas Larsson <lukas@erlang.org>
Date: Mon, 15 Apr 2024 10:34:15 +0200
Subject: [PATCH] erts: Fix calculate_cpu_quota
PR #8259 has swicthed the order of argument for
cpu quota calculations causing it to always
calculate 1 as the quota.
---
erts/lib_src/common/erl_misc_utils.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/erts/lib_src/common/erl_misc_utils.c b/erts/lib_src/common/erl_misc_utils.c
index 767c8579e2..5814829d42 100644
--- a/erts/lib_src/common/erl_misc_utils.c
+++ b/erts/lib_src/common/erl_misc_utils.c
@@ -119,6 +119,13 @@
#include <sys/sysctl.h>
#endif
+#ifdef DEBUG
+#include <assert.h>
+#define ASSERT(X) assert(X)
+#else
+#define ASSERT(X) do {} while(0)
+#endif
+
/* Simplify include for static functions */
#if defined(__linux__) || defined(HAVE_KSTAT) || defined(__WIN32__) || defined(__FreeBSD__)
@@ -1095,6 +1102,7 @@ get_cgroup_child_path(const char *controller, const char **out) {
break;
}
} else if (sscanf(line_buf, "%*d::%4095s\n", child_dir) == 1) {
+ ASSERT(version == ERTS_CGROUP_NONE); /* Silence codechecker */
/* An empty controller list means that this is the unified v2
* hierarchy, under which all associated controllers can be
* found. We don't know if the given controller is one of them,
@@ -1234,8 +1242,8 @@ static int read_cgroup_interface(const char *group_path, const char *if_name,
}
static int calculate_cpu_quota(int limit,
- ssize_t cfs_period_us,
- ssize_t cfs_quota_us) {
+ ssize_t cfs_quota_us,
+ ssize_t cfs_period_us) {
if (cfs_period_us > 0 && cfs_quota_us > 0) {
size_t quota = cfs_quota_us / cfs_period_us;
--
2.35.3