teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame SOURCES/0349-basic-use-comma-as-separator-in-cpuset-cgroup-cpu-ra.patch

c2dfb7
From 9fe3b9c7165afeedcf9f31959c436bcec233bb4d Mon Sep 17 00:00:00 2001
c2dfb7
From: =?UTF-8?q?Michal=20Sekleta=CC=81r?= <msekleta@redhat.com>
c2dfb7
Date: Tue, 14 Apr 2020 16:16:45 +0200
c2dfb7
Subject: [PATCH] basic: use comma as separator in cpuset cgroup cpu ranges
c2dfb7
c2dfb7
This is a workaround for
c2dfb7
https://bugzilla.redhat.com/show_bug.cgi?id=1819152 and should be
c2dfb7
reverted in RHEL-8.3.
c2dfb7
c2dfb7
RHEL-only
c2dfb7
c2dfb7
Related: #1818054
c2dfb7
---
c2dfb7
 src/basic/cpu-set-util.c | 45 ++++++++++++++++++++++++++++++++++++++++
c2dfb7
 src/basic/cpu-set-util.h |  1 +
c2dfb7
 src/core/cgroup.c        |  2 +-
c2dfb7
 3 files changed, 47 insertions(+), 1 deletion(-)
c2dfb7
c2dfb7
diff --git a/src/basic/cpu-set-util.c b/src/basic/cpu-set-util.c
c2dfb7
index 36cb017ae7..51752ad1a6 100644
c2dfb7
--- a/src/basic/cpu-set-util.c
c2dfb7
+++ b/src/basic/cpu-set-util.c
c2dfb7
@@ -86,6 +86,51 @@ char *cpu_set_to_range_string(const CPUSet *set) {
c2dfb7
         return TAKE_PTR(str) ?: strdup("");
c2dfb7
 }
c2dfb7
 
c2dfb7
+/* XXX(msekleta): this is the workaround for https://bugzilla.redhat.com/show_bug.cgi?id=1819152, remove in 8.3 */
c2dfb7
+char *cpu_set_to_range_string_kernel(const CPUSet *set) {
c2dfb7
+        unsigned range_start = 0, range_end;
c2dfb7
+        _cleanup_free_ char *str = NULL;
c2dfb7
+        size_t allocated = 0, len = 0;
c2dfb7
+        bool in_range = false;
c2dfb7
+        int r;
c2dfb7
+
c2dfb7
+        for (unsigned i = 0; i < set->allocated * 8; i++)
c2dfb7
+                if (CPU_ISSET_S(i, set->allocated, set->set)) {
c2dfb7
+                        if (in_range)
c2dfb7
+                                range_end++;
c2dfb7
+                        else {
c2dfb7
+                                range_start = range_end = i;
c2dfb7
+                                in_range = true;
c2dfb7
+                        }
c2dfb7
+                } else if (in_range) {
c2dfb7
+                        in_range = false;
c2dfb7
+
c2dfb7
+                        if (!GREEDY_REALLOC(str, allocated, len + 2 + 2 * DECIMAL_STR_MAX(unsigned)))
c2dfb7
+                                return NULL;
c2dfb7
+
c2dfb7
+                        if (range_end > range_start)
c2dfb7
+                                r = sprintf(str + len, len > 0 ? ",%d-%d" : "%d-%d", range_start, range_end);
c2dfb7
+                        else
c2dfb7
+                                r = sprintf(str + len, len > 0 ? ",%d" : "%d", range_start);
c2dfb7
+                        assert_se(r > 0);
c2dfb7
+                        len += r;
c2dfb7
+                }
c2dfb7
+
c2dfb7
+        if (in_range) {
c2dfb7
+                if (!GREEDY_REALLOC(str, allocated, len + 2 + 2 * DECIMAL_STR_MAX(int)))
c2dfb7
+                        return NULL;
c2dfb7
+
c2dfb7
+                if (range_end > range_start)
c2dfb7
+                        r = sprintf(str + len, len > 0 ? ",%d-%d" : "%d-%d", range_start, range_end);
c2dfb7
+                else
c2dfb7
+                        r = sprintf(str + len, len > 0 ? ",%d" : "%d", range_start);
c2dfb7
+                assert_se(r > 0);
c2dfb7
+        }
c2dfb7
+
c2dfb7
+        return TAKE_PTR(str) ?: strdup("");
c2dfb7
+}
c2dfb7
+
c2dfb7
+
c2dfb7
 int cpu_set_realloc(CPUSet *cpu_set, unsigned ncpus) {
c2dfb7
         size_t need;
c2dfb7
 
c2dfb7
diff --git a/src/basic/cpu-set-util.h b/src/basic/cpu-set-util.h
c2dfb7
index 295028cb54..8519a9b6c8 100644
c2dfb7
--- a/src/basic/cpu-set-util.h
c2dfb7
+++ b/src/basic/cpu-set-util.h
c2dfb7
@@ -27,6 +27,7 @@ int cpu_set_add_all(CPUSet *a, const CPUSet *b);
c2dfb7
 
c2dfb7
 char* cpu_set_to_string(const CPUSet *a);
c2dfb7
 char *cpu_set_to_range_string(const CPUSet *a);
c2dfb7
+char *cpu_set_to_range_string_kernel(const CPUSet *a);
c2dfb7
 int cpu_set_realloc(CPUSet *cpu_set, unsigned ncpus);
c2dfb7
 
c2dfb7
 int parse_cpu_set_full(
c2dfb7
diff --git a/src/core/cgroup.c b/src/core/cgroup.c
c2dfb7
index 3f7665b755..9e4c3c7dac 100644
c2dfb7
--- a/src/core/cgroup.c
c2dfb7
+++ b/src/core/cgroup.c
c2dfb7
@@ -557,7 +557,7 @@ static void cgroup_apply_unified_cpuset(Unit *u, CPUSet cpus, const char *name)
c2dfb7
         _cleanup_free_ char *buf = NULL;
c2dfb7
         int r;
c2dfb7
 
c2dfb7
-        buf = cpu_set_to_range_string(&cpus);
c2dfb7
+        buf = cpu_set_to_range_string_kernel(&cpus);
c2dfb7
         if (!buf)
c2dfb7
             return;
c2dfb7