]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Move cpus_in_affinity_mask() to cpu-set-util.[ch]
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 28 May 2019 19:28:31 +0000 (21:28 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 29 May 2019 08:26:00 +0000 (10:26 +0200)
It just seems to fit better there and it's always better to have things
in shared/ rather than basic/.

src/basic/process-util.c
src/basic/process-util.h
src/shared/condition.c
src/shared/cpu-set-util.c
src/shared/cpu-set-util.h
src/test/test-condition.c

index 3dc3534e1ab21556b2bc81918345ed93c3876ad5..85ea3cf1d1195ea23df657108d07ea2524a79f6d 100644 (file)
@@ -4,7 +4,6 @@
 #include <errno.h>
 #include <limits.h>
 #include <linux/oom.h>
 #include <errno.h>
 #include <limits.h>
 #include <linux/oom.h>
-#include <sched.h>
 #include <signal.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <signal.h>
 #include <stdbool.h>
 #include <stdio.h>
@@ -1534,45 +1533,11 @@ int set_oom_score_adjust(int value) {
                                  WRITE_STRING_FILE_VERIFY_ON_FAILURE|WRITE_STRING_FILE_DISABLE_BUFFER);
 }
 
                                  WRITE_STRING_FILE_VERIFY_ON_FAILURE|WRITE_STRING_FILE_DISABLE_BUFFER);
 }
 
-int cpus_in_affinity_mask(void) {
-        size_t n = 16;
-        int r;
-
-        for (;;) {
-                cpu_set_t *c;
-
-                c = CPU_ALLOC(n);
-                if (!c)
-                        return -ENOMEM;
-
-                if (sched_getaffinity(0, CPU_ALLOC_SIZE(n), c) >= 0) {
-                        int k;
-
-                        k = CPU_COUNT_S(CPU_ALLOC_SIZE(n), c);
-                        CPU_FREE(c);
-
-                        if (k <= 0)
-                                return -EINVAL;
-
-                        return k;
-                }
-
-                r = -errno;
-                CPU_FREE(c);
-
-                if (r != -EINVAL)
-                        return r;
-                if (n > SIZE_MAX/2)
-                        return -ENOMEM;
-                n *= 2;
-        }
-}
-
 static const char *const ioprio_class_table[] = {
         [IOPRIO_CLASS_NONE] = "none",
         [IOPRIO_CLASS_RT] = "realtime",
         [IOPRIO_CLASS_BE] = "best-effort",
 static const char *const ioprio_class_table[] = {
         [IOPRIO_CLASS_NONE] = "none",
         [IOPRIO_CLASS_RT] = "realtime",
         [IOPRIO_CLASS_BE] = "best-effort",
-        [IOPRIO_CLASS_IDLE] = "idle"
+        [IOPRIO_CLASS_IDLE] = "idle",
 };
 
 DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(ioprio_class, int, IOPRIO_N_CLASSES);
 };
 
 DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(ioprio_class, int, IOPRIO_N_CLASSES);
@@ -1593,7 +1558,7 @@ static const char* const sched_policy_table[] = {
         [SCHED_BATCH] = "batch",
         [SCHED_IDLE] = "idle",
         [SCHED_FIFO] = "fifo",
         [SCHED_BATCH] = "batch",
         [SCHED_IDLE] = "idle",
         [SCHED_FIFO] = "fifo",
-        [SCHED_RR] = "rr"
+        [SCHED_RR] = "rr",
 };
 
 DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(sched_policy, int, INT_MAX);
 };
 
 DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(sched_policy, int, INT_MAX);
index 7e1d65a7bf1b3c52c9b7c8d3e982d72be127308d..1571f1a65298f96246952959c608aba60fbea0d6 100644 (file)
@@ -194,5 +194,3 @@ assert_cc(TASKS_MAX <= (unsigned long) PID_T_MAX)
                 (pid) = 0;                      \
                 _pid_;                          \
         })
                 (pid) = 0;                      \
                 _pid_;                          \
         })
-
-int cpus_in_affinity_mask(void);
index d1ac9de7565804368a37458da149b5924cb2783d..2d521bc8c69aa0c277e7c02f1cffce7e7bdc2f5c 100644 (file)
@@ -21,6 +21,7 @@
 #include "cap-list.h"
 #include "cgroup-util.h"
 #include "condition.h"
 #include "cap-list.h"
 #include "cgroup-util.h"
 #include "condition.h"
+#include "cpu-set-util.h"
 #include "efivars.h"
 #include "env-file.h"
 #include "extract-word.h"
 #include "efivars.h"
 #include "env-file.h"
 #include "extract-word.h"
index b8d13a2ba62de3c3f3a2568529772f0fd4063f75..b0c7acd78932c5112f2b4c2b3ea2e5bc521e92ee 100644 (file)
@@ -201,3 +201,37 @@ int parse_cpu_set_extend(
 
         return cpu_set_add_all(old, &cpuset);
 }
 
         return cpu_set_add_all(old, &cpuset);
 }
+
+int cpus_in_affinity_mask(void) {
+        size_t n = 16;
+        int r;
+
+        for (;;) {
+                cpu_set_t *c;
+
+                c = CPU_ALLOC(n);
+                if (!c)
+                        return -ENOMEM;
+
+                if (sched_getaffinity(0, CPU_ALLOC_SIZE(n), c) >= 0) {
+                        int k;
+
+                        k = CPU_COUNT_S(CPU_ALLOC_SIZE(n), c);
+                        CPU_FREE(c);
+
+                        if (k <= 0)
+                                return -EINVAL;
+
+                        return k;
+                }
+
+                r = -errno;
+                CPU_FREE(c);
+
+                if (r != -EINVAL)
+                        return r;
+                if (n > SIZE_MAX/2)
+                        return -ENOMEM;
+                n *= 2;
+        }
+}
index 4c1c81fc59392295dd8572f91873161530971320..602c983ae303922127ae7b21ccb56b527e47445a 100644 (file)
@@ -45,3 +45,5 @@ int parse_cpu_set_extend(
 static inline int parse_cpu_set(const char *rvalue, CPUSet *cpu_set){
         return parse_cpu_set_full(rvalue, cpu_set, false, NULL, NULL, 0, NULL);
 }
 static inline int parse_cpu_set(const char *rvalue, CPUSet *cpu_set){
         return parse_cpu_set_full(rvalue, cpu_set, false, NULL, NULL, 0, NULL);
 }
+
+int cpus_in_affinity_mask(void);
index 2a5e3aba807e4130d27ead7fdaa6542edaed012f..4bbca2074f5869803fc5facfbd20c7147c6cede0 100644 (file)
@@ -13,6 +13,7 @@
 #include "audit-util.h"
 #include "cgroup-util.h"
 #include "condition.h"
 #include "audit-util.h"
 #include "cgroup-util.h"
 #include "condition.h"
+#include "cpu-set-util.h"
 #include "efivars.h"
 #include "hostname-util.h"
 #include "id128-util.h"
 #include "efivars.h"
 #include "hostname-util.h"
 #include "id128-util.h"