From: Tom Hromatka Date: Fri, 28 Jan 2022 17:23:55 +0000 (-0700) Subject: abstraction-map: Add cpuset.cpu_exclusive <-> cpuset.cpus.partition mapping X-Git-Tag: v3.0~224 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=40fd2fb6b2116ec46fde1ec93efee478a7fd766e;p=thirdparty%2Flibcgroup.git abstraction-map: Add cpuset.cpu_exclusive <-> cpuset.cpus.partition mapping Add custom functions to map cpuset.cpu_exclusive <-> cpuset.cpus.partition. Signed-off-by: Tom Hromatka Reviewed-by: Kamalesh Babulal --- diff --git a/src/Makefile.am b/src/Makefile.am index 80d95a1a..37db235c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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 \ diff --git a/src/abstraction-common.h b/src/abstraction-common.h index 8e508e25..e24b89c3 100644 --- a/src/abstraction-common.h +++ b/src/abstraction-common.h @@ -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 index 00000000..7fa9bae5 --- /dev/null +++ b/src/abstraction-cpuset.c @@ -0,0 +1,66 @@ +/** + * Libcgroup abstraction layer for the cpuset controller + * + * Copyright (c) 2021-2022 Oracle and/or its affiliates. + * Author: Tom Hromatka + */ + +/* + * 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 . + */ + +#include +#include + +#include +#include +#include +#include +#include + +#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; +} diff --git a/src/abstraction-map.c b/src/abstraction-map.c index 4b792050..5e1c2c02 100644 --- a/src/abstraction-map.c +++ b/src/abstraction-map.c @@ -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]);