richardphibel / rpms / systemd

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