]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
abstraction-map: Add cpuset.cpu_exclusive <-> cpuset.cpus.partition mapping
authorTom Hromatka <tom.hromatka@oracle.com>
Fri, 28 Jan 2022 17:23:55 +0000 (10:23 -0700)
committerTom Hromatka <tom.hromatka@oracle.com>
Thu, 3 Feb 2022 21:42:36 +0000 (14:42 -0700)
Add custom functions to map cpuset.cpu_exclusive <->
cpuset.cpus.partition.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
src/Makefile.am
src/abstraction-common.h
src/abstraction-cpuset.c [new file with mode: 0644]
src/abstraction-map.c

index 80d95a1a3418b39a39fd588333d9ea47eba175aa..37db235c51b41a8b48f0470369837c4d91022597 100644 (file)
@@ -23,7 +23,7 @@ libcgroup_la_SOURCES = parse.h parse.y lex.l api.c config.c \
                       libcgroup-internal.h libcgroup.map wrapper.c log.c \
                       abstraction-common.c abstraction-common.h \
                       abstraction-map.c abstraction-map.h \
-                      abstraction-cpu.c
+                      abstraction-cpu.c abstraction-cpuset.c
 libcgroup_la_LIBADD = -lpthread $(CODE_COVERAGE_LIBS)
 libcgroup_la_CFLAGS = $(CODE_COVERAGE_CFLAGS) -DSTATIC=static
 libcgroup_la_LDFLAGS = -Wl,--version-script,$(srcdir)/libcgroup.map \
index 8e508e258c01ec4b42680bb349e541ecf61be894..e24b89c3dcb5875d8591aa6edc68756aabbd6d45 100644 (file)
@@ -114,6 +114,20 @@ int cgroup_convert_cpu_max_to_period(
        const char * const out_setting,
        void *in_dflt, void *out_dflt);
 
+/* cpuset */
+int cgroup_convert_cpuset_to_exclusive(
+       struct cgroup_controller * const dst_cgc,
+       const char * const in_value,
+       const char * const out_setting,
+       void *in_dflt, void *out_dflt);
+
+int cgroup_convert_cpuset_to_partition(
+       struct cgroup_controller * const dst_cgc,
+       const char * const in_value,
+       const char * const out_setting,
+       void *in_dflt, void *out_dflt);
+
+
 #ifdef __cplusplus
 } /* extern "C" */
 #endif
diff --git a/src/abstraction-cpuset.c b/src/abstraction-cpuset.c
new file mode 100644 (file)
index 0000000..7fa9bae
--- /dev/null
@@ -0,0 +1,66 @@
+/**
+ * Libcgroup abstraction layer for the cpuset controller
+ *
+ * Copyright (c) 2021-2022 Oracle and/or its affiliates.
+ * Author: Tom Hromatka <tom.hromatka@oracle.com>
+ */
+
+/*
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of version 2.1 of the GNU Lesser General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses>.
+ */
+
+#include <libcgroup.h>
+#include <libcgroup-internal.h>
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "abstraction-common.h"
+
+static const char * const MEMBER = "member";
+static const char * const ROOT = "root";
+
+int cgroup_convert_cpuset_to_exclusive(
+       struct cgroup_controller * const dst_cgc,
+       const char * const in_value,
+       const char * const out_setting,
+       void *in_dflt, void *out_dflt)
+{
+       int ret;
+
+       if (strcmp(in_value, ROOT) == 0)
+               ret = cgroup_add_value_string(dst_cgc, out_setting, "1");
+       else
+               ret = cgroup_add_value_string(dst_cgc, out_setting, "0");
+
+       return ret;
+}
+
+int cgroup_convert_cpuset_to_partition(
+       struct cgroup_controller * const dst_cgc,
+       const char * const in_value,
+       const char * const out_setting,
+       void *in_dflt, void *out_dflt)
+{
+       int ret;
+
+       if (strcmp(in_value, "1") == 0)
+               ret = cgroup_add_value_string(dst_cgc, out_setting, ROOT);
+       else
+               ret = cgroup_add_value_string(dst_cgc, out_setting, MEMBER);
+
+       return ret;
+}
index 4b792050973e841b329454339ad53eca2af16634..5e1c2c02526ac5ce2dccf80484dbb5d8a41fa55d 100644 (file)
@@ -43,6 +43,8 @@ const struct cgroup_abstraction_map cgroup_v1_to_v2_map[] = {
                "cpuset.mems.effective", NULL},
        {cgroup_convert_passthrough, "cpuset.cpus", NULL, "cpuset.cpus", NULL},
        {cgroup_convert_passthrough, "cpuset.mems", NULL, "cpuset.mems", NULL},
+       {cgroup_convert_cpuset_to_partition, "cpuset.cpu_exclusive", NULL,
+               "cpuset.cpus.partition", NULL},
 };
 const int cgroup_v1_to_v2_map_sz = sizeof(cgroup_v1_to_v2_map) /
                                   sizeof(cgroup_v1_to_v2_map[0]);
@@ -59,6 +61,8 @@ const struct cgroup_abstraction_map cgroup_v2_to_v1_map[] = {
                "cpuset.effective_mems", NULL},
        {cgroup_convert_passthrough, "cpuset.cpus", NULL, "cpuset.cpus", NULL},
        {cgroup_convert_passthrough, "cpuset.mems", NULL, "cpuset.mems", NULL},
+       {cgroup_convert_cpuset_to_exclusive, "cpuset.cpus.partition", NULL,
+               "cpuset.cpu_exclusive", NULL},
 };
 const int cgroup_v2_to_v1_map_sz = sizeof(cgroup_v2_to_v1_map) /
                                   sizeof(cgroup_v2_to_v1_map[0]);