teknoraver / rpms / systemd

Forked from rpms/systemd 2 months ago
Clone

Blame SOURCES/0279-test-execute-use-CPUSet-too.patch

4fbe94
From 5e6b616ed2708391752ba8c45f183ceb38573d7d Mon Sep 17 00:00:00 2001
4fbe94
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
4fbe94
Date: Tue, 28 May 2019 21:38:41 +0200
4fbe94
Subject: [PATCH] test-execute: use CPUSet too
4fbe94
4fbe94
cpu_set_malloc() was the last user. It doesn't seem useful to keep
4fbe94
it just to save the allocation of a few hundred bytes in a test, so
4fbe94
it is dropped and a fixed maximum is allocated (1024 bytes).
4fbe94
4fbe94
(cherry picked from commit 167a776dbe9d033523bd6881e5a695f2155dc321)
4fbe94
4fbe94
Related: #1734787
4fbe94
---
4fbe94
 src/basic/cpu-set-util.c | 31 +------------------------------
4fbe94
 src/basic/cpu-set-util.h |  3 +--
4fbe94
 src/test/test-execute.c  | 13 ++++++-------
4fbe94
 3 files changed, 8 insertions(+), 39 deletions(-)
4fbe94
4fbe94
diff --git a/src/basic/cpu-set-util.c b/src/basic/cpu-set-util.c
4fbe94
index 1803539ac6..c297eab032 100644
4fbe94
--- a/src/basic/cpu-set-util.c
4fbe94
+++ b/src/basic/cpu-set-util.c
4fbe94
@@ -37,36 +37,7 @@ char* cpu_set_to_string(const CPUSet *a) {
4fbe94
         return TAKE_PTR(str) ?: strdup("");
4fbe94
 }
4fbe94
 
4fbe94
-cpu_set_t* cpu_set_malloc(unsigned *ncpus) {
4fbe94
-        cpu_set_t *c;
4fbe94
-        unsigned n = 1024;
4fbe94
-
4fbe94
-        /* Allocates the cpuset in the right size */
4fbe94
-
4fbe94
-        for (;;) {
4fbe94
-                c = CPU_ALLOC(n);
4fbe94
-                if (!c)
4fbe94
-                        return NULL;
4fbe94
-
4fbe94
-                if (sched_getaffinity(0, CPU_ALLOC_SIZE(n), c) >= 0) {
4fbe94
-                        CPU_ZERO_S(CPU_ALLOC_SIZE(n), c);
4fbe94
-
4fbe94
-                        if (ncpus)
4fbe94
-                                *ncpus = n;
4fbe94
-
4fbe94
-                        return c;
4fbe94
-                }
4fbe94
-
4fbe94
-                CPU_FREE(c);
4fbe94
-
4fbe94
-                if (errno != EINVAL)
4fbe94
-                        return NULL;
4fbe94
-
4fbe94
-                n *= 2;
4fbe94
-        }
4fbe94
-}
4fbe94
-
4fbe94
-static int cpu_set_realloc(CPUSet *cpu_set, unsigned ncpus) {
4fbe94
+int cpu_set_realloc(CPUSet *cpu_set, unsigned ncpus) {
4fbe94
         size_t need;
4fbe94
 
4fbe94
         assert(cpu_set);
4fbe94
diff --git a/src/basic/cpu-set-util.h b/src/basic/cpu-set-util.h
4fbe94
index 9b026aca09..b54e737110 100644
4fbe94
--- a/src/basic/cpu-set-util.h
4fbe94
+++ b/src/basic/cpu-set-util.h
4fbe94
@@ -12,8 +12,6 @@
4fbe94
 DEFINE_TRIVIAL_CLEANUP_FUNC(cpu_set_t*, CPU_FREE);
4fbe94
 #define _cleanup_cpu_free_ _cleanup_(CPU_FREEp)
4fbe94
 
4fbe94
-cpu_set_t* cpu_set_malloc(unsigned *ncpus);
4fbe94
-
4fbe94
 /* This wraps the libc interface with a variable to keep the allocated size. */
4fbe94
 typedef struct CPUSet {
4fbe94
         cpu_set_t *set;
4fbe94
@@ -30,6 +28,7 @@ static inline void cpu_set_reset(CPUSet *a) {
4fbe94
 int cpu_set_add_all(CPUSet *a, const CPUSet *b);
4fbe94
 
4fbe94
 char* cpu_set_to_string(const CPUSet *a);
4fbe94
+int cpu_set_realloc(CPUSet *cpu_set, unsigned ncpus);
4fbe94
 int parse_cpu_set_full(
4fbe94
                 const char *rvalue,
4fbe94
                 CPUSet *cpu_set,
4fbe94
diff --git a/src/test/test-execute.c b/src/test/test-execute.c
4fbe94
index fa8efdddd2..6c22995b1e 100644
4fbe94
--- a/src/test/test-execute.c
4fbe94
+++ b/src/test/test-execute.c
4fbe94
@@ -144,13 +144,12 @@ static void test_exec_bindpaths(Manager *m) {
4fbe94
 }
4fbe94
 
4fbe94
 static void test_exec_cpuaffinity(Manager *m) {
4fbe94
-        _cleanup_cpu_free_ cpu_set_t *c = NULL;
4fbe94
-        unsigned n;
4fbe94
+        _cleanup_(cpu_set_reset) CPUSet c = {};
4fbe94
 
4fbe94
-        assert_se(c = cpu_set_malloc(&n);;
4fbe94
-        assert_se(sched_getaffinity(0, CPU_ALLOC_SIZE(n), c) >= 0);
4fbe94
+        assert_se(cpu_set_realloc(&c, 8192) >= 0); /* just allocate the maximum possible size */
4fbe94
+        assert_se(sched_getaffinity(0, c.allocated, c.set) >= 0);
4fbe94
 
4fbe94
-        if (CPU_ISSET_S(0, CPU_ALLOC_SIZE(n), c) == 0) {
4fbe94
+        if (!CPU_ISSET_S(0, c.allocated, c.set)) {
4fbe94
                 log_notice("Cannot use CPU 0, skipping %s", __func__);
4fbe94
                 return;
4fbe94
         }
4fbe94
@@ -158,8 +157,8 @@ static void test_exec_cpuaffinity(Manager *m) {
4fbe94
         test(m, "exec-cpuaffinity1.service", 0, CLD_EXITED);
4fbe94
         test(m, "exec-cpuaffinity2.service", 0, CLD_EXITED);
4fbe94
 
4fbe94
-        if (CPU_ISSET_S(1, CPU_ALLOC_SIZE(n), c) == 0 ||
4fbe94
-            CPU_ISSET_S(2, CPU_ALLOC_SIZE(n), c) == 0) {
4fbe94
+        if (!CPU_ISSET_S(1, c.allocated, c.set) ||
4fbe94
+            !CPU_ISSET_S(2, c.allocated, c.set)) {
4fbe94
                 log_notice("Cannot use CPU 1 or 2, skipping remaining tests in %s", __func__);
4fbe94
                 return;
4fbe94
         }