kill01: New case cgroup kill
PATCH 1/1 kill01: New case cgroup kill
Move basic test from kernel for cgroup kill button.
--- runtest/controllers | 1 + testcases/kernel/controllers/kill/.gitignore | 3 + testcases/kernel/controllers/kill/Makefile | 13 + .../kernel/controllers/kill/cgroup_util.c | 668 ++++++++++++++++++ .../kernel/controllers/kill/cgroup_util.h | 59 ++ testcases/kernel/controllers/kill/kill01.c | 336 +++++++++ 6 files changed, 1080 insertions(+) create mode 100644 testcases/kernel/controllers/kill/.gitignore create mode 100644 testcases/kernel/controllers/kill/Makefile create mode 100644 testcases/kernel/controllers/kill/cgroup_util.c create mode 100644 testcases/kernel/controllers/kill/cgroup_util.h create mode 100644 testcases/kernel/controllers/kill/kill01.c
runtest/controllers +1 -0
@@ -23,6 +23,7 @@ memcontrol01 memcontrol01 memcontrol02 memcontrol02 memcontrol03 memcontrol03 memcontrol04 memcontrol04 +kill01 kill01 cgroup_fj_function_debug cgroup_fj_function.sh debug cgroup_fj_function_cpuset cgroup_fj_function.sh cpuset
testcases/kernel/controllers/kill/.gitignore new file +3 -0
@@ -0,0 +1,3 @@ +/kill01 +/kill01.o +/cgroup_util.o
testcases/kernel/controllers/kill/Makefile new file +13 -0
@@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk + +MAKE_TARGETS := kill01 +kill01: cgroup_util.o kill01.o + $(LINK.o) $^ $(LOADLIBES) $(LDLIBS) $(OUTPUT_OPTION) + +kill01.o cgroup_util.o : %.o: %.c + +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/controllers/kill/cgroup_util.c new file +668 -0
668 lines not on this page · raw message
testcases/kernel/controllers/kill/cgroup_util.h new file +59 -0
59 lines not on this page · raw message
testcases/kernel/controllers/kill/kill01.c new file +336 -0
336 lines not on this page · raw message
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
We already have a library for cgroup manipulations see include/tst_cgroup.h in the LTP git tree.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 3 lines · Cyril Hrubis
Hi!
We already have a library for cgroup manipulations seeinclude/tst_cgroup.hin the LTP git tree.
Thanks a lot, will check it.
Quoted 4 lines
Signature · 3 lines
-- Cyril Hrubis [email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 1/1 kill01: New case cgroup kill
In reply to Wei Gao via ltp--- lib/tst_cgroup.c | 1 + runtest/controllers | 1 + testcases/kernel/controllers/kill/.gitignore | 1 + testcases/kernel/controllers/kill/Makefile | 6 + testcases/kernel/controllers/kill/kill01.c | 130 +++++++++++++++++++ 5 files changed, 139 insertions(+) create mode 100644 testcases/kernel/controllers/kill/.gitignore create mode 100644 testcases/kernel/controllers/kill/Makefile create mode 100644 testcases/kernel/controllers/kill/kill01.c
lib/tst_cgroup.c +1 -0
@@ -166,6 +166,7 @@ static const struct cgroup_file cgroup_ctrl_files[] = { { "cgroup.controllers", NULL, 0 }, { "cgroup.subtree_control", NULL, 0 }, { "cgroup.clone_children", "cgroup.clone_children", 0 }, + { "cgroup.kill", NULL, 0 }, { } };
runtest/controllers +1 -0
@@ -23,6 +23,7 @@ memcontrol01 memcontrol01 memcontrol02 memcontrol02 memcontrol03 memcontrol03 memcontrol04 memcontrol04 +kill01 kill01 cgroup_fj_function_debug cgroup_fj_function.sh debug cgroup_fj_function_cpuset cgroup_fj_function.sh cpuset
testcases/kernel/controllers/kill/.gitignore new file +1 -0
@@ -0,0 +1 @@ +/kill01
testcases/kernel/controllers/kill/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/controllers/kill/kill01.c new file +130 -0
130 lines not on this page · raw message
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 82 lines · Wei Gao via ltp
Signed-off-by Wei Gao <[email protected]>--- lib/tst_cgroup.c | 1 + runtest/controllers | 1 + testcases/kernel/controllers/kill/.gitignore | 1 + testcases/kernel/controllers/kill/Makefile | 6 + testcases/kernel/controllers/kill/kill01.c | 130 +++++++++++++++++++ 5 files changed, 139 insertions(+) create mode 100644 testcases/kernel/controllers/kill/.gitignore create mode 100644 testcases/kernel/controllers/kill/Makefile create mode 100644 testcases/kernel/controllers/kill/kill01.clib/tst_cgroup.c +1
-0@@ -166,6 +166,7 @@ static const struct cgroup_file cgroup_ctrl_files[] = { { "cgroup.controllers", NULL, 0 }, { "cgroup.subtree_control", NULL, 0 }, { "cgroup.clone_children", "cgroup.clone_children", 0 }, + { "cgroup.kill", NULL, 0 }, { } };runtest/controllers +1
-0@@ -23,6 +23,7 @@ memcontrol01 memcontrol01 memcontrol02 memcontrol02 memcontrol03 memcontrol03 memcontrol04 memcontrol04 +kill01 kill01 cgroup_fj_function_debug cgroup_fj_function.sh debug cgroup_fj_function_cpuset cgroup_fj_function.sh cpusettestcases/kernel/controllers/kill/.gitignore new file +1
-0@@ -0,0 +1 @@ +/kill01testcases/kernel/controllers/kill/Makefile new file +6
-0@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mktestcases/kernel/controllers/kill/kill01.c new file +17
-0@@ -0,0 +1,130 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2012 Christian Brauner <brauner-AT-kernel.org> +* Copyright (c) 2023 SUSE LLC <[email protected]> +*/ + +/*\ +* [Description] +* +* Basic cgroup kill test. +* +*/ + +#include <errno.h> +#include <linux/limits.h> +#include <stdbool.h> +#include <stdio.h>
testcases/kernel/controllers/kill/kill01.c line 27
Quoted 10 lines
testcases/kernel/controllers/kill/kill01.c new file +10
-0+#include <stdlib.h> +#include <string.h> +#include <sys/types.h> +#include <unistd.h> +#include <sys/wait.h> + +#include "lapi/syscalls.h" +#include "tst_test.h" + +#define pid_num 100
My concern about defining pid_num as a fixed variable is that the test may spend a long time on a single_cpu or slower system. A sanity way is probably to use a dynamical number according to the test bed available CPUs (e.g. tst_ncpus_available() + 1).
Quoted 25 lines
testcases/kernel/controllers/kill/kill01.c new file +24
-0+static struct tst_cg_group *cg_child_test_simple; + + +static int wait_for_pid (pid_t pid) +{ +int status, ret; + +again: + ret =waitpid (pid, &status,0 ); +if (ret ==-1 ) { +if (errno ==EINTR ) + goto again; + +return -1 ; + } + +if (!WIFEXITED (status)) +return -1 ; + +return WEXITSTATUS (status); +} + +/* +* A simple process running in a sleep loop until being
testcases/kernel/controllers/kill/kill01.c line 61
Quoted 10 lines
testcases/kernel/controllers/kill/kill01.c new file +10
-0+* re-parented. +*/ +static int child_fn (void ) +{ +int ppid =getppid (); + +while (getppid () == ppid) +usleep (1000 ); + +return getppid () == ppid;
why do we need to return the value of this comparison? I suppose most time the child does _not_ have a chance to get here.
testcases/kernel/controllers/kill/kill01.c line 69
Quoted 9 lines
testcases/kernel/controllers/kill/kill01.c new file +8
-0+} + +static int cg_run_nowait (const struct tst_cg_group *const cg, +int (*fn)(void )) +{ +int pid; + + pid =fork ();
use SAFE_FORK() maybe better.
Quoted 19 lines
testcases/kernel/controllers/kill/kill01.c new file +9
-0+if (pid ==0 ) { +SAFE_CG_PRINTF (cg,"cgroup.procs" ,"%d" ,getpid ()); +exit (fn ()); + } + +return pid; +} + +static int cg_wait_for_proc_count(const struct tst_cg_group *cg, intcount)
testcases/kernel/controllers/kill/kill01.c new file +8
-0+{ +char buf[20 * pid_num] = {0 }; +int attempts; +char *ptr; + +for (attempts =10 ; attempts >=0 ; attempts--) { +int nr =0 ; +
testcases/kernel/controllers/kill/kill01.c line 96
Quoted 10 lines
testcases/kernel/controllers/kill/kill01.c new file +10
-0+SAFE_CG_READ (cg,"cgroup.procs" , buf,sizeof (buf)); + +for (ptr = buf; *ptr; ptr++) +if (*ptr =='\n' ) + nr++; + +if (nr >= count) +return 0 ; + +usleep (100000 );
In this loop, there is only 1 second for waiting for children ready. So, if test on a slower/overload machine that is a bit longer than this time,
what will happen? shouldn't we handle this as a corner case failure?
Quoted 43 lines
testcases/kernel/controllers/kill/kill01.c new file +17
-0+ } + +return -1 ; +} + +static void run (void ) +{ + +pid_t pids[100 ]; +int i; + + cg_child_test_simple =tst_cg_group_mk (tst_cg,"cg_test_simple" ); + +for (i =0 ; i < pid_num; i++) + pids[i] =cg_run_nowait (cg_child_test_simple, child_fn); + + TST_EXP_PASS(cg_wait_for_proc_count(cg_child_test_simple,
pid_num));testcases/kernel/controllers/kill/kill01.c new file +17
-1+SAFE_CG_PRINTF (cg_child_test_simple,"cgroup.kill" ,"%d" ,1 ); + +for (i =0 ; i < pid_num; i++) { +/* wait_for_pid(pids[i]); */ +TST_EXP_PASS_SILENT (wait_for_pid (pids[i]) ==SIGKILL ); + } + + cg_child_test_simple =tst_cg_group_rm (cg_child_test_simple); +} + +static struct tst_test test = { + .test_all = run, + .forks_child =1 , + .max_runtime =5 , + .needs_cgroup_ctrls = (const char *const []){"memory" ,NULL }, + .needs_cgroup_ver =TST_CG_V2 , +}; --2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 11 lines · Li Wang
Quoted 4 lines · Wei Gao via ltp
Signed-off-by Wei Gao <[email protected]>---
+#definepid_num100My concern about defining
pid_numas a fixed variable is that the test may spend a long time on asingle_cpuor slower system. A sanity way is probably to use a dynamical number according to the test bed available CPUs (e.g.tst_ncpus_available()+ 1).
good idea!
Quoted 34 lines
Quoted 34 lines
testcases/kernel/controllers/kill/kill01.c new file +31
-0+static struct tst_cg_group *cg_child_test_simple; + + +static int wait_for_pid (pid_t pid) +{ +int status, ret; + +again: + ret =waitpid (pid, &status,0 ); +if (ret ==-1 ) { +if (errno ==EINTR ) + goto again; + +return -1 ; + } + +if (!WIFEXITED (status)) +return -1 ; + +return WEXITSTATUS (status); +} + +/* +* A simple process running in a sleep loop until being +* re-parented. +*/ +static int child_fn (void ) +{ +int ppid =getppid (); + +while (getppid () == ppid)
Quoted 8 lines
testcases/kernel/controllers/kill/kill01.c line 61
Quoted 4 lines
testcases/kernel/controllers/kill/kill01.c new file +3
-0+usleep (1000 ); + +return getppid () == ppid;why do we need to return the value of this comparison? I suppose most time the child does _not_ have a chance to get here.
yes, chance to reach here is small in our scenario, remove the logic here.
Quoted 14 lines
testcases/kernel/controllers/kill/kill01.c line 69
Quoted 12 lines
testcases/kernel/controllers/kill/kill01.c new file +8
-0+} + +static int cg_run_nowait (const struct tst_cg_group *const cg, +int (*fn)(void )) +{ +int pid; + + pid =fork ();use
SAFE_FORK()maybe better.
good catch!
Quoted 29 lines
Quoted 29 lines
testcases/kernel/controllers/kill/kill01.c new file +9
-0+if (pid ==0 ) { +SAFE_CG_PRINTF (cg,"cgroup.procs" ,"%d" ,getpid ()); +exit (fn ()); + } + +return pid; +} + +static int cg_wait_for_proc_count(const struct tst_cg_group *cg, intcount)
testcases/kernel/controllers/kill/kill01.c new file +16
-0+{ +char buf[20 * pid_num] = {0 }; +int attempts; +char *ptr; + +for (attempts =10 ; attempts >=0 ; attempts--) { +int nr =0 ; + +SAFE_CG_READ (cg,"cgroup.procs" , buf,sizeof (buf)); + +for (ptr = buf; *ptr; ptr++) +if (*ptr =='\n' ) + nr++; + +if (nr >= count) +return 0 ;
Quoted 8 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ + usleep(100000);In this loop, there is only 1 second for waiting for children ready. So, if test on a slower/overload machine that is a bit longer than this time,
what will happen? shouldn't we handle this as a corner case failure?
I will increase to 10 second, then if all the children processes can not ready in correct cgroup we will take this as a failure case.
Quoted 50 lines
Quoted 46 lines
testcases/kernel/controllers/kill/kill01.c new file +17
-0+ } + +return -1 ; +} + +static void run (void ) +{ + +pid_t pids[100 ]; +int i; + + cg_child_test_simple =tst_cg_group_mk (tst_cg,"cg_test_simple" ); + +for (i =0 ; i < pid_num; i++) + pids[i] =cg_run_nowait (cg_child_test_simple, child_fn); + + TST_EXP_PASS(cg_wait_for_proc_count(cg_child_test_simple,
pid_num));testcases/kernel/controllers/kill/kill01.c new file +17
-1+SAFE_CG_PRINTF (cg_child_test_simple,"cgroup.kill" ,"%d" ,1 ); + +for (i =0 ; i < pid_num; i++) { +/* wait_for_pid(pids[i]); */ +TST_EXP_PASS_SILENT (wait_for_pid (pids[i]) ==SIGKILL ); + } + + cg_child_test_simple =tst_cg_group_rm (cg_child_test_simple); +} + +static struct tst_test test = { + .test_all = run, + .forks_child =1 , + .max_runtime =5 , + .needs_cgroup_ctrls = (const char *const []){"memory" ,NULL }, + .needs_cgroup_ver =TST_CG_V2 , +}; --2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltpSignature · 2 lines
Regards, Li Wang
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v3 1/1 kill01: New case cgroup kill
In reply to Wei Gao via ltp--- lib/tst_cgroup.c | 1 + runtest/controllers | 1 + testcases/kernel/controllers/kill/.gitignore | 1 + testcases/kernel/controllers/kill/Makefile | 6 + testcases/kernel/controllers/kill/kill01.c | 143 +++++++++++++++++++ 5 files changed, 152 insertions(+) create mode 100644 testcases/kernel/controllers/kill/.gitignore create mode 100644 testcases/kernel/controllers/kill/Makefile create mode 100644 testcases/kernel/controllers/kill/kill01.c
lib/tst_cgroup.c +1 -0
@@ -166,6 +166,7 @@ static const struct cgroup_file cgroup_ctrl_files[] = { { "cgroup.controllers", NULL, 0 }, { "cgroup.subtree_control", NULL, 0 }, { "cgroup.clone_children", "cgroup.clone_children", 0 }, + { "cgroup.kill", NULL, 0 }, { } };
runtest/controllers +1 -0
@@ -23,6 +23,7 @@ memcontrol01 memcontrol01 memcontrol02 memcontrol02 memcontrol03 memcontrol03 memcontrol04 memcontrol04 +kill01 kill01 cgroup_fj_function_debug cgroup_fj_function.sh debug cgroup_fj_function_cpuset cgroup_fj_function.sh cpuset
testcases/kernel/controllers/kill/.gitignore new file +1 -0
@@ -0,0 +1 @@ +/kill01
testcases/kernel/controllers/kill/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/controllers/kill/kill01.c new file +143 -0
143 lines not on this page · raw message
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 1/1 kill01: New case cgroup kill
--- lib/tst_cgroup.c | 1 + runtest/controllers | 1 + testcases/kernel/controllers/kill/.gitignore | 1 + testcases/kernel/controllers/kill/Makefile | 6 + testcases/kernel/controllers/kill/kill01.c | 143 +++++++++++++++++++ 5 files changed, 152 insertions(+) create mode 100644 testcases/kernel/controllers/kill/.gitignore create mode 100644 testcases/kernel/controllers/kill/Makefile create mode 100644 testcases/kernel/controllers/kill/kill01.c
lib/tst_cgroup.c +1 -0
@@ -166,6 +166,7 @@ static const struct cgroup_file cgroup_ctrl_files[] = { { "cgroup.controllers", NULL, 0 }, { "cgroup.subtree_control", NULL, 0 }, { "cgroup.clone_children", "cgroup.clone_children", 0 }, + { "cgroup.kill", NULL, 0 }, { } };
runtest/controllers +1 -0
@@ -23,6 +23,7 @@ memcontrol01 memcontrol01 memcontrol02 memcontrol02 memcontrol03 memcontrol03 memcontrol04 memcontrol04 +kill01 kill01 cgroup_fj_function_debug cgroup_fj_function.sh debug cgroup_fj_function_cpuset cgroup_fj_function.sh cpuset
testcases/kernel/controllers/kill/.gitignore new file +1 -0
@@ -0,0 +1 @@ +/kill01
testcases/kernel/controllers/kill/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/controllers/kill/kill01.c new file +143 -0
143 lines not on this page · raw message
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Wei,
The new test generally looks good to me.
I'm thinking maybe we make use of guarded buffers which could remove the setup/cleanup function then. And doing memset(buf,...) before reading into buf[] is quite necessary, to avoid someone running this test with parameter '-i N' that the buf[] is polluted by the first time.
https://github.com/linux-test-project/ltp/blob/master/doc/c-test-api.txt#L1799
<https://github.com/linux-test-project/ltp/blob/master/doc/c-test-api.txt#L1799>
e.g.
testcases/kernel/controllers/kill/kill01.c +1 -2
@@ -26,7 +26,7 @@#define MAX_PID_NUM 100#define pid_num MIN(MAX_PID_NUM, (tst_ncpus_available() + 1)) -#define buf_len (20 * pid_num) +#define buf_len (10 * MAX_PID_NUM)static char *buf;static struct tst_cg_group *cg_child_test_simple;
@@ -60,7 +60,6 @@ static void child_fn(void)while (getppid () == ppid)usleep (1000 ); - } static int cg_run_nowait(const struct tst_cg_group *const cg,
@@ -82,6 +81,8 @@ static int cg_wait_for_proc_count(const struct
tst_cg_group *cg, int count)
int attempts;
char *ptr;+ memset(buf, 0, buf_len);
+
for (attempts = 100; attempts >= 0; attempts--) {
int nr = 0;@@ -121,23 +122,14 @@ static void run(void)
cg_child_test_simple = tst_cg_group_rm(cg_child_test_simple);
}
-static void setup(void)
-{
- buf = SAFE_MALLOC(buf_len);
- memset(buf, 0, buf_len);
-}
-
-static void cleanup(void)
-{
- free(buf);
-}
-
static struct tst_test test = {
.test_all = run,
- .setup = setup,
- .cleanup = cleanup,
.forks_child = 1,
.max_runtime = 15,
.needs_cgroup_ctrls = (const char *const []){ "memory", NULL },
.needs_cgroup_ver = TST_CG_V2,+ .bufs = (struct tst_buffers []) {
+ {&buf, .size = buf_len},
+ {}
+ }
};
Anyway this version you could add my reviewed-by:
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 10 lines · Li Wang
Hi Wei,
The new test generally looks good to me.
I'm thinking maybe we make use of guarded buffers which could remove the setup/cleanup function then. And doing
memset(buf,...)before reading into buf[] is quite necessary, to avoid someone running this test with parameter '-i N' that the buf[] is polluted by the first time.
Quoted 4 lines
https://github.com/linux-test-project/ltp/blob/master/doc/c-test-api.txt#L1799
<https://github.com/linux-test-project/ltp/blob/master/doc/c-test-api.txt#L1799>
e.g.
I have tried use guarded buffers but compile can not pass.
Following error will trigger since buf_len is caculate instead of FIX constant. So I suppose we can not use guarded buffers?
kill01.c:131:34: error: initializer element is not constant
.bufs = (struct tst_buffers []) {
For memset before reading buf issue, i will update in next patch.
Quoted 67 lines
testcases/kernel/controllers/kill/kill01.c +7
-15@@ -26,7 +26,7 @@#define MAX_PID_NUM 100#define pid_num MIN(MAX_PID_NUM, (tst_ncpus_available() + 1)) -#define buf_len (20 * pid_num) +#define buf_len (10 * MAX_PID_NUM)static char *buf;static struct tst_cg_group *cg_child_test_simple;@@ -60,7 +60,6 @@ static void child_fn(void)while (getppid () == ppid)usleep (1000 ); - } static int cg_run_nowait(const struct tst_cg_group *const cg,@@ -82,6 +81,8 @@ static int cg_wait_for_proc_count(const struct tst_cg_group *cg, int count) int attempts;char *ptr; +memset (buf,0 , buf_len); +for (attempts =100 ; attempts >=0 ; attempts--) {int nr =0 ;@@ -121,23 +122,14 @@ static void run(void) cg_child_test_simple =tst_cg_group_rm (cg_child_test_simple); } -static void setup (void ) -{ - buf =SAFE_MALLOC (buf_len); -memset (buf,0 , buf_len); -} - -static void cleanup (void ) -{ -free (buf); -} -static struct tst_test test = { .test_all = run, - .setup = setup, - .cleanup = cleanup, .forks_child =1 , .max_runtime =15 , .needs_cgroup_ctrls = (const char *const []){"memory" ,NULL }, .needs_cgroup_ver =TST_CG_V2 , + .bufs = (struct tst_buffers []) { + {&buf, .size = buf_len}, + {} + } };Anyway this version you could add my reviewed-by:
Reviewed-by Li Wang <[email protected]>Signature · 2 lines
Regards, Li Wang
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 15 lines · Wei Gao
Quoted 11 lines · Li Wang
Hi Wei,
The new test generally looks good to me.
I'm thinking maybe we make use of guarded buffers which could remove the setup/cleanup function then. And doing
memset(buf,...)before reading into buf[] is quite necessary, to avoid someone running this test with parameter '-i N' that the buf[] is polluted by the first time.https://github.com/linux-test-project/ltp/blob/master/doc/c-test-api.txt#L1799
Quoted 2 lines
<
Quoted 9 lines
https://github.com/linux-test-project/ltp/blob/master/doc/c-test-api.txt#L1799
Quoted 2 lines
e.g.
I have tried use guarded buffers but compile can not pass. Following error will trigger since
buf_lenis caculate instead of FIX constant. So
I suppose we can not use guarded buffers?
Sure, it doesn't matter.
You used an uncertain variable in .size of tst_buffer, that's why it throws out the compiling error.
Quoted 75 lines
kill01.c:131:34: error: initializer element is not constant
.bufs = (structtst_buffers[]) {For memset before reading buf issue, i will update in next patch.
Quoted 67 lines
testcases/kernel/controllers/kill/kill01.c +7
-15@@ -26,7 +26,7 @@#define MAX_PID_NUM 100#define pid_num MIN(MAX_PID_NUM, (tst_ncpus_available() + 1)) -#define buf_len (20 * pid_num) +#define buf_len (10 * MAX_PID_NUM)static char *buf;static struct tst_cg_group *cg_child_test_simple;@@ -60,7 +60,6 @@ static void child_fn(void)while (getppid () == ppid)usleep (1000 ); - } static int cg_run_nowait(const struct tst_cg_group *const cg,@@ -82,6 +81,8 @@ static int cg_wait_for_proc_count(const struct tst_cg_group *cg, int count) int attempts;char *ptr; +memset (buf,0 , buf_len); +for (attempts =100 ; attempts >=0 ; attempts--) {int nr =0 ;@@ -121,23 +122,14 @@ static void run(void) cg_child_test_simple =tst_cg_group_rm (cg_child_test_simple); } -static void setup (void ) -{ - buf =SAFE_MALLOC (buf_len); -memset (buf,0 , buf_len); -} - -static void cleanup (void ) -{ -free (buf); -} -static struct tst_test test = { .test_all = run, - .setup = setup, - .cleanup = cleanup, .forks_child =1 , .max_runtime =15 , .needs_cgroup_ctrls = (const char *const []){"memory" ,NULL }, .needs_cgroup_ver =TST_CG_V2 , + .bufs = (struct tst_buffers []) { + {&buf, .size = buf_len}, + {} + } };Anyway this version you could add my reviewed-by:
Reviewed-by Li Wang <[email protected]>--
Regards,
Li Wang
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v5 1/1 kill01: New case cgroup kill
In reply to Wei Gao via ltp--- lib/tst_cgroup.c | 1 + runtest/controllers | 1 + testcases/kernel/controllers/kill/.gitignore | 1 + testcases/kernel/controllers/kill/Makefile | 6 + testcases/kernel/controllers/kill/kill01.c | 138 +++++++++++++++++++ 5 files changed, 147 insertions(+) create mode 100644 testcases/kernel/controllers/kill/.gitignore create mode 100644 testcases/kernel/controllers/kill/Makefile create mode 100644 testcases/kernel/controllers/kill/kill01.c
lib/tst_cgroup.c +1 -0
@@ -166,6 +166,7 @@ static const struct cgroup_file cgroup_ctrl_files[] = { { "cgroup.controllers", NULL, 0 }, { "cgroup.subtree_control", NULL, 0 }, { "cgroup.clone_children", "cgroup.clone_children", 0 }, + { "cgroup.kill", NULL, 0 }, { } };
runtest/controllers +1 -0
@@ -23,6 +23,7 @@ memcontrol01 memcontrol01 memcontrol02 memcontrol02 memcontrol03 memcontrol03 memcontrol04 memcontrol04 +kill01 kill01 cgroup_fj_function_debug cgroup_fj_function.sh debug cgroup_fj_function_cpuset cgroup_fj_function.sh cpuset
testcases/kernel/controllers/kill/.gitignore new file +1 -0
@@ -0,0 +1 @@ +/kill01
testcases/kernel/controllers/kill/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/controllers/kill/kill01.c new file +138 -0
138 lines not on this page · raw message
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 2 lines · Wei Gao
Signed-off-by Wei Gao <[email protected]>
Quoted 207 lines
--- lib/tst_cgroup.c | 1 + runtest/controllers | 1 + testcases/kernel/controllers/kill/.gitignore | 1 + testcases/kernel/controllers/kill/Makefile | 6 + testcases/kernel/controllers/kill/kill01.c | 138 +++++++++++++++++++ 5 files changed, 147 insertions(+) create mode 100644 testcases/kernel/controllers/kill/.gitignore create mode 100644 testcases/kernel/controllers/kill/Makefile create mode 100644 testcases/kernel/controllers/kill/kill01.clib/tst_cgroup.c +1
-0@@ -166,6 +166,7 @@ static const struct cgroup_file cgroup_ctrl_files[] = { { "cgroup.controllers", NULL, 0 }, { "cgroup.subtree_control", NULL, 0 }, { "cgroup.clone_children", "cgroup.clone_children", 0 }, + { "cgroup.kill", NULL, 0 }, { } };runtest/controllers +1
-0@@ -23,6 +23,7 @@ memcontrol01 memcontrol01 memcontrol02 memcontrol02 memcontrol03 memcontrol03 memcontrol04 memcontrol04 +kill01 kill01 cgroup_fj_function_debug cgroup_fj_function.sh debug cgroup_fj_function_cpuset cgroup_fj_function.sh cpusettestcases/kernel/controllers/kill/.gitignore new file +1
-0@@ -0,0 +1 @@ +/kill01testcases/kernel/controllers/kill/Makefile new file +6
-0@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mktestcases/kernel/controllers/kill/kill01.c new file +80
-0@@ -0,0 +1,138 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2012 Christian Brauner <brauner-AT-kernel.org> +* Copyright (c) 2023 SUSE LLC <[email protected]> +*/ + +/*\ +* [Description] +* +* Basic cgroup kill test. +* +*/ + +#include <errno.h> +#include <linux/limits.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/types.h> +#include <unistd.h> +#include <sys/wait.h> + +#include "lapi/syscalls.h" +#include "tst_test.h" + +#define MAX_PID_NUM 100 +#define pid_num MIN(MAX_PID_NUM, (tst_ncpus_available() + 1)) +#define buf_len (20 * pid_num) + +static char *buf; +static struct tst_cg_group *cg_child_test_simple; + +static int wait_for_pid (pid_t pid) +{ +int status, ret; + +again: + ret =waitpid (pid, &status,0 ); +if (ret ==-1 ) { +if (errno ==EINTR ) + goto again; + +return -1 ; + } + +if (!WIFEXITED (status)) +return -1 ; + +return WEXITSTATUS (status); +} + +/* +* A simple process running in a sleep loop until being +* re-parented. +*/ +static void child_fn (void ) +{ +int ppid =getppid (); + +while (getppid () == ppid) +usleep (1000 ); + +} + +static int cg_run_nowait (const struct tst_cg_group *const cg, +void (*fn)(void )) +{ +int pid; + + pid =SAFE_FORK (); +if (pid ==0 ) { +SAFE_CG_PRINTF (cg,"cgroup.procs" ,"%d" ,getpid ()); +fn (); + } + +return pid; +} + +static int cg_wait_for_proc_count(const struct tst_cg_group *cg, intcount)
testcases/kernel/controllers/kill/kill01.c new file +35
-0+{ +int attempts; +char *ptr; + +for (attempts =100 ; attempts >=0 ; attempts--) { +int nr =0 ; + +SAFE_CG_READ (cg,"cgroup.procs" , buf, buf_len); + +for (ptr = buf; *ptr; ptr++) +if (*ptr =='\n' ) + nr++; + +if (nr >= count) +return 0 ; + +usleep (100000 ); + } + +return -1 ; +} + +static void run (void ) +{ +pid_t pids[MAX_PID_NUM ]; +int i; + + cg_child_test_simple =tst_cg_group_mk (tst_cg,"cg_test_simple" ); + +memset (buf,0 , buf_len); + +for (i =0 ; i < pid_num; i++) + pids[i] =cg_run_nowait (cg_child_test_simple, child_fn); + + TST_EXP_PASS(cg_wait_for_proc_count(cg_child_test_simple,
pid_num));testcases/kernel/controllers/kill/kill01.c new file +23
-1+SAFE_CG_PRINTF (cg_child_test_simple,"cgroup.kill" ,"%d" ,1 ); + +for (i =0 ; i < pid_num; i++) { +/* wait_for_pid(pids[i]); */ +TST_EXP_PASS_SILENT (wait_for_pid (pids[i]) ==SIGKILL ); + } + + cg_child_test_simple =tst_cg_group_rm (cg_child_test_simple); +} + +static void setup (void ) +{ + buf =tst_alloc (buf_len); +} + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .forks_child =1 , + .max_runtime =15 , + .needs_cgroup_ctrls = (const char *const []){"memory" ,NULL }, + .needs_cgroup_ver =TST_CG_V2 , +}; --2.35.3
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Wei,
Test LGTM.
...
testcases/kernel/controllers/kill/kill01.c line 3
Quoted 3 lines
testcases/kernel/controllers/kill/kill01.c new file +3
-0+// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2012 Christian Brauner <brauner-AT-kernel.org>
Is it based on some Christian's reproducer?
I haven't noticed any in https://lwn.net/Articles/855049/ (linked in #846) nor in the patch
https://lwn.net/ml/cgroups/[email protected]/.
But maybe I just overlooked it.
testcases/kernel/controllers/kill/kill01.c line 16
Quoted 13 lines
+ * Copyright (c) 2023 SUSE LLC <[email protected]>
+ */testcases/kernel/controllers/kill/kill01.c new file +11
-0+ +/*\ +* [Description] +* +* Basic cgroup kill test. +* +*/ + +#include <errno.h> +#include <linux/limits.h> +#include <stdbool.h>
nit: stdbool.h is not needed (can be removed before merge).
...
Quoted 7 lines
testcases/kernel/controllers/kill/kill01.c new file +7
-0+static void run (void ) +{ +pid_t pids[MAX_PID_NUM ]; +int i; + + cg_child_test_simple =tst_cg_group_mk (tst_cg,"cg_test_simple" ); +
testcases/kernel/controllers/kill/kill01.c line 119
Quoted 10 lines
testcases/kernel/controllers/kill/kill01.c new file +10
-0+memset (buf,0 , buf_len); + +for (i =0 ; i < pid_num; i++) + pids[i] =cg_run_nowait (cg_child_test_simple, child_fn); + +TST_EXP_PASS (cg_wait_for_proc_count (cg_child_test_simple, pid_num)); +SAFE_CG_PRINTF (cg_child_test_simple,"cgroup.kill" ,"%d" ,1 ); + +for (i =0 ; i < pid_num; i++) { +/* wait_for_pid(pids[i]); */
I guess this comment should be removed before merge.
testcases/kernel/controllers/kill/kill01.c line 124
Quoted 5 lines
testcases/kernel/controllers/kill/kill01.c new file +5
-0+TST_EXP_PASS_SILENT (wait_for_pid (pids[i]) ==SIGKILL ); + } + + cg_child_test_simple =tst_cg_group_rm (cg_child_test_simple); +}
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 7 lines · Petr Vorel
Hi Wei,
Test LGTM.
...
Quoted 8 lines
testcases/kernel/controllers/kill/kill01.c line 3
Quoted 3 lines
testcases/kernel/controllers/kill/kill01.c new file +3
-0+// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2012 Christian Brauner <brauner-AT-kernel.org> Is it based on some Christian's reproducer?
I haven't noticed any in https://lwn.net/Articles/855049/ (linked in #846) nor in the patch
https://lwn.net/ml/cgroups/[email protected]/.
But maybe I just overlooked it.
This case base kernel self test, will add more description here.
Quoted 15 lines
Quoted 4 lines
+ * Copyright (c) 2023 SUSE LLC <[email protected]>
+ */testcases/kernel/controllers/kill/kill01.c new file +1
-0+testcases/kernel/controllers/kill/kill01.c line 16
Quoted 10 lines
testcases/kernel/controllers/kill/kill01.c new file +10
-0+/*\ +* [Description] +* +* Basic cgroup kill test. +* +*/ + +#include <errno.h> +#include <linux/limits.h> +#include <stdbool.h> nit:
stdbool.his not needed (can be removed before merge).
ack
Quoted 12 lines
...
Quoted 10 lines
testcases/kernel/controllers/kill/kill01.c new file +10
-0+static void run (void ) +{ +pid_t pids[MAX_PID_NUM ]; +int i; + + cg_child_test_simple =tst_cg_group_mk (tst_cg,"cg_test_simple" ); + +memset (buf,0 , buf_len); + +for (i =0 ; i < pid_num; i++)
Quoted 8 lines
testcases/kernel/controllers/kill/kill01.c line 119
Quoted 7 lines
testcases/kernel/controllers/kill/kill01.c new file +7
-0+ pids[i] =cg_run_nowait (cg_child_test_simple, child_fn); + +TST_EXP_PASS (cg_wait_for_proc_count (cg_child_test_simple, pid_num)); +SAFE_CG_PRINTF (cg_child_test_simple,"cgroup.kill" ,"%d" ,1 ); + +for (i =0 ; i < pid_num; i++) { +/* wait_for_pid(pids[i]); */ I guess this comment should be removed before merge.
ack
Quoted 8 lines
testcases/kernel/controllers/kill/kill01.c line 124
Quoted 5 lines
testcases/kernel/controllers/kill/kill01.c new file +5
-0+TST_EXP_PASS_SILENT (wait_for_pid (pids[i]) ==SIGKILL ); + } + + cg_child_test_simple =tst_cg_group_rm (cg_child_test_simple); +}Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hello,
Quoted 7 lines · Wei Gao via ltp
Signed-off-by Wei Gao <[email protected]>--- lib/tst_cgroup.c | 1 + runtest/controllers | 1 + testcases/kernel/controllers/kill/.gitignore | 1 + testcases/kernel/controllers/kill/Makefile | 6 + testcases/kernel/controllers/kill/kill01.c | 138 +++++++++++++++++++
nit: kill is not a controller, it is a core function. This should go in controllers/cgroup.
Quoted 56 lines
5 files changed, 147 insertions(+) create mode 100644 testcases/kernel/controllers/kill/.gitignore create mode 100644 testcases/kernel/controllers/kill/Makefile create mode 100644 testcases/kernel/controllers/kill/kill01.clib/tst_cgroup.c +1
-0@@ -166,6 +166,7 @@ static const struct cgroup_file cgroup_ctrl_files[] = { { "cgroup.controllers", NULL, 0 }, { "cgroup.subtree_control", NULL, 0 }, { "cgroup.clone_children", "cgroup.clone_children", 0 }, + { "cgroup.kill", NULL, 0 }, { } };runtest/controllers +1
-0@@ -23,6 +23,7 @@ memcontrol01 memcontrol01 memcontrol02 memcontrol02 memcontrol03 memcontrol03 memcontrol04 memcontrol04 +kill01 kill01 cgroup_fj_function_debug cgroup_fj_function.sh debug cgroup_fj_function_cpuset cgroup_fj_function.sh cpusettestcases/kernel/controllers/kill/.gitignore new file +1
-0@@ -0,0 +1 @@ +/kill01testcases/kernel/controllers/kill/Makefile new file +6
-0@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mktestcases/kernel/controllers/kill/kill01.c new file +2
-0@@ -0,0 +1,138 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/*
testcases/kernel/controllers/kill/kill01.c line 12
Quoted 10 lines
testcases/kernel/controllers/kill/kill01.c new file +10
-0+* Copyright (c) 2012 Christian Brauner <brauner-AT-kernel.org> +* Copyright (c) 2023 SUSE LLC <[email protected]> +*/ + +/*\ +* [Description] +* +* Basic cgroup kill test. +* +*/
I guess this is copied from the self tests and you can mention that in the description and link to the original.
Quoted 29 lines
testcases/kernel/controllers/kill/kill01.c new file +29
-0+ +#include <errno.h> +#include <linux/limits.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/types.h> +#include <unistd.h> +#include <sys/wait.h> + +#include "lapi/syscalls.h" +#include "tst_test.h" + +#define MAX_PID_NUM 100 +#define pid_num MIN(MAX_PID_NUM, (tst_ncpus_available() + 1)) +#define buf_len (20 * pid_num) + +static char *buf; +static struct tst_cg_group *cg_child_test_simple; + +static int wait_for_pid (pid_t pid) +{ +int status, ret; + +again: + ret =waitpid (pid, &status,0 ); +if (ret ==-1 ) { +if (errno ==EINTR )
testcases/kernel/controllers/kill/kill01.c line 51
Quoted 10 lines
testcases/kernel/controllers/kill/kill01.c new file +10
-0+ goto again; + +return -1 ; + } + +if (!WIFEXITED (status)) +return -1 ; + +return WEXITSTATUS (status); +}
We have tst_reap_children for this, but this just appears to be wrong for this test.
Quoted 6 lines
testcases/kernel/controllers/kill/kill01.c new file +6
-0+ +/* +* A simple process running in a sleep loop until being +* re-parented. +*/ +static void child_fn (void )
testcases/kernel/controllers/kill/kill01.c line 67
Quoted 10 lines
testcases/kernel/controllers/kill/kill01.c new file +10
-0+{ +int ppid =getppid (); + +while (getppid () == ppid) +usleep (1000 ); + +} + +static int cg_run_nowait (const struct tst_cg_group *const cg, +void (*fn)(void ))
Why keep this function?
If you want to convert tests to LTP, then don't do the minimum possible to use the LTP API. Use as much of it as possible otherwise we are just importing brittle self tests.
Quoted 20 lines
testcases/kernel/controllers/kill/kill01.c new file +20
-0+{ +int pid; + + pid =SAFE_FORK (); +if (pid ==0 ) { +SAFE_CG_PRINTF (cg,"cgroup.procs" ,"%d" ,getpid ()); +fn (); + } + +return pid; +} + +static int cg_wait_for_proc_count (const struct tst_cg_group *cg,int count) +{ +int attempts; +char *ptr; + +for (attempts =100 ; attempts >=0 ; attempts--) { +int nr =0 ; +
testcases/kernel/controllers/kill/kill01.c line 97
Quoted 10 lines
testcases/kernel/controllers/kill/kill01.c new file +10
-0+SAFE_CG_READ (cg,"cgroup.procs" , buf, buf_len); + +for (ptr = buf; *ptr; ptr++) +if (*ptr =='\n' ) + nr++; + +if (nr >= count) +return 0 ; + +usleep (100000 );
It's best to avoid arbitrary sleep values and attempts. You could use TST_CHECKPOINT* or increment a counter in some shared memory with SAFE_MMAP and tst_atomic_inc.
Quoted 12 lines
testcases/kernel/controllers/kill/kill01.c new file +11
-0+ } + +return -1 ; +} + +static void run (void ) +{ +pid_t pids[MAX_PID_NUM ]; +int i; + + cg_child_test_simple = tst_cg_group_mk(tst_cg,"
cg_test_simple");
testcases/kernel/controllers/kill/kill01.c
Quoted 2 lines
testcases/kernel/controllers/kill/kill01.c new file +2
-0+ +memset (buf,0 , buf_len);
IIRC guarded buffers are zeroed already.
testcases/kernel/controllers/kill/kill01.c line 113
Quoted 3 lines
testcases/kernel/controllers/kill/kill01.c new file +3
-0+ +for (i =0 ; i < pid_num; i++) + pids[i] =cg_run_nowait (cg_child_test_simple, child_fn);
If the parent is killed and the children are moved then they will return and cause a fork bomb.
This is not obvious because of the unecessary indirection (function pointer and functions).
Quoted 3 lines
testcases/kernel/controllers/kill/kill01.c new file +2
-0+ + TST_EXP_PASS(cg_wait_for_proc_count(cg_child_test_simple,
pid_num));
If this fails then there will be little information to debug it. This is a common issue with the self tests which we will be importing into the LTP.
testcases/kernel/controllers/kill/kill01.c line 120
Quoted 5 lines
testcases/kernel/controllers/kill/kill01.c new file +5
-0+SAFE_CG_PRINTF (cg_child_test_simple,"cgroup.kill" ,"%d" ,1 ); + +for (i =0 ; i < pid_num; i++) { +/* wait_for_pid(pids[i]); */ +TST_EXP_PASS_SILENT (wait_for_pid (pids[i]) ==SIGKILL );
It seems wait_for_pid will never == SIGKILL. The function does not inspect the signal a process was killed with at all.
The test passes becaues this is not the correct use of TST_EXP_PASS*.
testcases/kernel/controllers/kill/kill01.c line 128
Quoted 8 lines
testcases/kernel/controllers/kill/kill01.c new file +8
-0+ } + + cg_child_test_simple =tst_cg_group_rm (cg_child_test_simple); +} + +static void setup (void ) +{ + buf =tst_alloc (buf_len);
Simple allocations like this can be done in the test struct.
testcases/kernel/controllers/kill/kill01.c line 136
Quoted 8 lines
testcases/kernel/controllers/kill/kill01.c new file +8
-0+} + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .forks_child =1 , + .max_runtime =15 , + .needs_cgroup_ctrls = (const char *const []){"memory" ,NULL },
Why do we need the memory controller?
If it is just to make the LTP library happy, then you can change the library instead (e.g. add a "cgroup" pseudo controller if we didn't do that already).
Quoted 4 lines
testcases/kernel/controllers/kill/kill01.c new file +2
-0+ .needs_cgroup_ver = TST_CG_V2, +};Signature · 1 line
2.35.3
Signature · 5 lines
Thank you, Richard. -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 12 lines · Richard Palethorpe
Review
Quoted 9 lines
testcases/kernel/controllers/kill/kill01.c new file +6
-0+static void run (void ) +{ +pid_t pids[MAX_PID_NUM ]; +int i; + + cg_child_test_simple = tst_cg_group_mk(tst_cg,"
cg_test_simple");(quoted diff) +2
-0+ + memset(buf, 0, buf_len);IIRC guarded buffers are zeroed already.
The memset() is necessary since there is probably run test with '-i N' which lead to buf[] being impacted by last time.
Quoted 6 lines
testcases/kernel/controllers/kill/kill01.c line 128
Quoted 3 lines
testcases/kernel/controllers/kill/kill01.c new file +3
-0+static void setup (void ) +{ + buf =tst_alloc (buf_len);Simple allocations like this can be done in the test struct.
I pointed out this before but he seems don't want to use constant for the buf_len definition (to bypass compile error in tst_test).
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 15 lines · Richard Palethorpe
Hello,
Quoted 13 lines
testcases/kernel/controllers/kill/kill01.c new file +13
-0+static int wait_for_pid (pid_t pid) +{ +int status, ret; + +again: + ret =waitpid (pid, &status,0 ); +if (ret ==-1 ) { +if (errno ==EINTR ) + goto again; + +return -1 ; + } +
Quoted 8 lines
testcases/kernel/controllers/kill/kill01.c line 51
Quoted 5 lines
testcases/kernel/controllers/kill/kill01.c new file +5
-0+if (!WIFEXITED (status)) +return -1 ; + +return WEXITSTATUS (status); +}We have
tst_reap_childrenfor this, but this just appears to be wrong for this test.
tst_reap_children can not return reason of status, such as i need call WIFSIGNALED(wstatus) in next patch to make sure children is killed by signal.
Quoted 17 lines
Quoted 4 lines
+ * A simple process running in a sleep loop until being
+ * re-parented.
+ */testcases/kernel/controllers/kill/kill01.c new file +1
-0+static void child_fn (void )testcases/kernel/controllers/kill/kill01.c line 67
Quoted 10 lines
testcases/kernel/controllers/kill/kill01.c new file +10
-0+{ +int ppid =getppid (); + +while (getppid () == ppid) +usleep (1000 ); + +} + +static int cg_run_nowait (const struct tst_cg_group *const cg, +void (*fn)(void ))Why keep this function?
Quoted 4 lines
If you want to convert tests to LTP, then don't do the minimum possible to use the LTP API. Use as much of it as possible otherwise we are just importing brittle self tests.
function is useful and wrap the fork action & put pid into cgroup.procs, is there any LTP API can replace this function? Could you help give example.
Quoted 26 lines
Quoted 26 lines
testcases/kernel/controllers/kill/kill01.c new file +26
-0+{ +int pid; + + pid =SAFE_FORK (); +if (pid ==0 ) { +SAFE_CG_PRINTF (cg,"cgroup.procs" ,"%d" ,getpid ()); +fn (); + } + +return pid; +} + +static int cg_wait_for_proc_count (const struct tst_cg_group *cg,int count) +{ +int attempts; +char *ptr; + +for (attempts =100 ; attempts >=0 ; attempts--) { +int nr =0 ; + +SAFE_CG_READ (cg,"cgroup.procs" , buf, buf_len); + +for (ptr = buf; *ptr; ptr++) +if (*ptr =='\n' ) + nr++; +
Quoted 9 lines
testcases/kernel/controllers/kill/kill01.c line 97
Quoted 4 lines
testcases/kernel/controllers/kill/kill01.c new file +4
-0+if (nr >= count) +return 0 ; + +usleep (100000 );It's best to avoid arbitrary sleep values and attempts. You could use TST_CHECKPOINT* or increment a counter in some shared memory with
SAFE_MMAPandtst_atomic_inc.
I will try to use TST_CHECKPOINT* to sync before call this function
Quoted 8 lines
Quoted 8 lines
testcases/kernel/controllers/kill/kill01.c new file +8
-0+ } + +return -1 ; +} + +static void run (void ) +{ +pid_t pids[MAX_PID_NUM ];
Quoted 8 lines
Review
Quoted 6 lines
testcases/kernel/controllers/kill/kill01.c new file +3
-0+int i; + + cg_child_test_simple = tst_cg_group_mk(tst_cg,"
cg_test_simple");(quoted diff) +2
-0+ + memset(buf, 0, buf_len);IIRC guarded buffers are zeroed already.
Already explained by Li Wang in other email.
Quoted 7 lines
testcases/kernel/controllers/kill/kill01.c line 113
Quoted 4 lines
testcases/kernel/controllers/kill/kill01.c new file +3
-0+ +for (i =0 ; i < pid_num; i++) + pids[i] =cg_run_nowait (cg_child_test_simple, child_fn);If the parent is killed and the children are moved then they will return and cause a fork bomb.
There is no extra fork action in child_fn so all child_fn will reparent and exit. So i do not think fork bomb will happen.
Quoted 11 lines
This is not obvious because of the unecessary indirection (function pointer and functions).
Quoted 3 lines
(quoted diff) +2
-0+ + TST_EXP_PASS(cg_wait_for_proc_count(cg_child_test_simple,
pid_num));If this fails then there will be little information to debug it. This is a common issue with the self tests which we will be importing into the LTP.
Add extra log info into this function maybe help, what's your suggestion?
Quoted 10 lines
testcases/kernel/controllers/kill/kill01.c line 120
Quoted 5 lines
testcases/kernel/controllers/kill/kill01.c new file +5
-0+SAFE_CG_PRINTF (cg_child_test_simple,"cgroup.kill" ,"%d" ,1 ); + +for (i =0 ; i < pid_num; i++) { +/* wait_for_pid(pids[i]); */ +TST_EXP_PASS_SILENT (wait_for_pid (pids[i]) ==SIGKILL );It seems
wait_for_pidwill never == SIGKILL. The function does not inspect the signal a process was killed with at all.The test passes becaues this is not the correct use of TST_EXP_PASS*.
Good catch! Thanks a lot for finding this, i should use WIFSIGNALED to translate status and check children killed by SIGKILL, will fix this in next patch.
Quoted 11 lines
testcases/kernel/controllers/kill/kill01.c line 128
Quoted 9 lines
testcases/kernel/controllers/kill/kill01.c new file +8
-0+ } + + cg_child_test_simple =tst_cg_group_rm (cg_child_test_simple); +} + +static void setup (void ) +{ + buf =tst_alloc (buf_len);Simple allocations like this can be done in the test struct.
This already discussed with Wang Li, compile error will happen since buf_len not fixed in my case.
Quoted 12 lines
testcases/kernel/controllers/kill/kill01.c line 136
Quoted 9 lines
testcases/kernel/controllers/kill/kill01.c new file +8
-0+} + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .forks_child =1 , + .max_runtime =15 , + .needs_cgroup_ctrls = (const char *const []){"memory" ,NULL },Why do we need the memory controller?
Quoted 3 lines
If it is just to make the LTP library happy, then you can change the library instead (e.g. add a "cgroup" pseudo controller if we didn't do that already).
You guess right, i just go quick way to let LTP happy xD I will check library and try to implement this.
Thanks again for your valuable feedback!
Quoted 9 lines
Quoted 5 lines
testcases/kernel/controllers/kill/kill01.c new file +2
-0+ .needs_cgroup_ver = TST_CG_V2, +};Signature · 1 line
2.35.3Signature · 2 lines
Thank you, Richard.
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 45 lines · Wei Gao
Quoted 15 lines · Richard Palethorpe
Hello,
Quoted 13 lines
testcases/kernel/controllers/kill/kill01.c new file +13
-0+static int wait_for_pid (pid_t pid) +{ +int status, ret; + +again: + ret =waitpid (pid, &status,0 ); +if (ret ==-1 ) { +if (errno ==EINTR ) + goto again; + +return -1 ; + } +Quoted 8 lines
testcases/kernel/controllers/kill/kill01.c line 51
Quoted 5 lines
testcases/kernel/controllers/kill/kill01.c new file +5
-0+if (!WIFEXITED (status)) +return -1 ; + +return WEXITSTATUS (status); +}We have
tst_reap_childrenfor this, but this just appears to be wrong for this test.
tst_reap_childrencan not return reason of status, such as i need call WIFSIGNALED(wstatus) in next patch to make sure children is killed by signal.Quoted 17 lines
Quoted 4 lines
+ * A simple process running in a sleep loop until being
+ * re-parented.
+ */testcases/kernel/controllers/kill/kill01.c new file +1
-0+static void child_fn (void )testcases/kernel/controllers/kill/kill01.c line 67
Quoted 10 lines
testcases/kernel/controllers/kill/kill01.c new file +10
-0+{ +int ppid =getppid (); + +while (getppid () == ppid) +usleep (1000 ); + +} + +static int cg_run_nowait (const struct tst_cg_group *const cg, +void (*fn)(void ))Why keep this function?
Quoted 7 lines
Quoted 4 lines
If you want to convert tests to LTP, then don't do the minimum possible to use the LTP API. Use as much of it as possible otherwise we are just importing brittle self tests.
function is useful and wrap the fork action & put pid into cgroup.procs, is there any LTP API can replace this function? Could you help give example.
IMO you don't need to wrap fork or SAFE_CG_PRINTF, just write it inline.
Quoted 54 lines
Quoted 26 lines
Quoted 26 lines
testcases/kernel/controllers/kill/kill01.c new file +26
-0+{ +int pid; + + pid =SAFE_FORK (); +if (pid ==0 ) { +SAFE_CG_PRINTF (cg,"cgroup.procs" ,"%d" ,getpid ()); +fn (); + } + +return pid; +} + +static int cg_wait_for_proc_count (const struct tst_cg_group *cg,int count) +{ +int attempts; +char *ptr; + +for (attempts =100 ; attempts >=0 ; attempts--) { +int nr =0 ; + +SAFE_CG_READ (cg,"cgroup.procs" , buf, buf_len); + +for (ptr = buf; *ptr; ptr++) +if (*ptr =='\n' ) + nr++; +Quoted 9 lines
testcases/kernel/controllers/kill/kill01.c line 97
Quoted 4 lines
testcases/kernel/controllers/kill/kill01.c new file +4
-0+if (nr >= count) +return 0 ; + +usleep (100000 );It's best to avoid arbitrary sleep values and attempts. You could use TST_CHECKPOINT* or increment a counter in some shared memory with
SAFE_MMAPandtst_atomic_inc.I will try to use TST_CHECKPOINT* to sync before call this function
Quoted 8 lines
Quoted 8 lines
testcases/kernel/controllers/kill/kill01.c new file +8
-0+ } + +return -1 ; +} + +static void run (void ) +{ +pid_t pids[MAX_PID_NUM ];Quoted 8 lines
Review
Quoted 6 lines
testcases/kernel/controllers/kill/kill01.c new file +3
-0+int i; + + cg_child_test_simple = tst_cg_group_mk(tst_cg,"
cg_test_simple");(quoted diff) +2
-0+ + memset(buf, 0, buf_len);IIRC guarded buffers are zeroed already.
Already explained by Li Wang in other email.
Quoted 1 line
Quoted 8 lines
Quoted 6 lines
testcases/kernel/controllers/kill/kill01.c line 113
Quoted 3 lines
testcases/kernel/controllers/kill/kill01.c new file +3
-0+ +for (i =0 ; i < pid_num; i++) + pids[i] =cg_run_nowait (cg_child_test_simple, child_fn);If the parent is killed and the children are moved then they will return and cause a fork bomb.
There is no extra fork action in
child_fnso allchild_fnwill reparent and exit.
I don't see how it will exit? It seems like it will just return.
Possibly I just missed it, but that's why I have an issue with the function pointer as well.
Quoted 12 lines
So i do not think fork bomb will happen.
Quoted 11 lines
This is not obvious because of the unecessary indirection (function pointer and functions).
Quoted 3 lines
(quoted diff) +2
-0+ + TST_EXP_PASS(cg_wait_for_proc_count(cg_child_test_simple,
pid_num));If this fails then there will be little information to debug it. This is a common issue with the self tests which we will be importing into the LTP.
Quoted 2 lines
Add extra log info into this function maybe help, what's your suggestion?
Yes, something like that.
Quoted 38 lines
Quoted 10 lines
testcases/kernel/controllers/kill/kill01.c line 120
Quoted 5 lines
testcases/kernel/controllers/kill/kill01.c new file +5
-0+SAFE_CG_PRINTF (cg_child_test_simple,"cgroup.kill" ,"%d" ,1 ); + +for (i =0 ; i < pid_num; i++) { +/* wait_for_pid(pids[i]); */ +TST_EXP_PASS_SILENT (wait_for_pid (pids[i]) ==SIGKILL );It seems
wait_for_pidwill never == SIGKILL. The function does not inspect the signal a process was killed with at all.The test passes becaues this is not the correct use of TST_EXP_PASS*.
Good catch! Thanks a lot for finding this, i should use WIFSIGNALED to translate status and check children killed by SIGKILL, will fix this in next patch.
Quoted 11 lines
testcases/kernel/controllers/kill/kill01.c line 128
Quoted 9 lines
testcases/kernel/controllers/kill/kill01.c new file +8
-0+ } + + cg_child_test_simple =tst_cg_group_rm (cg_child_test_simple); +} + +static void setup (void ) +{ + buf =tst_alloc (buf_len);Simple allocations like this can be done in the test struct.
This already discussed with Wang Li, compile error will happen since
buf_lennot fixed in my case.Quoted 12 lines
testcases/kernel/controllers/kill/kill01.c line 136
Quoted 9 lines
testcases/kernel/controllers/kill/kill01.c new file +8
-0+} + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .forks_child =1 , + .max_runtime =15 , + .needs_cgroup_ctrls = (const char *const []){"memory" ,NULL },Why do we need the memory controller?
Quoted 7 lines
Quoted 3 lines
If it is just to make the LTP library happy, then you can change the library instead (e.g. add a "cgroup" pseudo controller if we didn't do that already).
You guess right, i just go quick way to let LTP happy xD I will check library and try to implement this.
Thanks again for your valuable feedback!
Thanks!
Quoted 9 lines
Quoted 9 lines
Quoted 5 lines
testcases/kernel/controllers/kill/kill01.c new file +2
-0+ .needs_cgroup_ver = TST_CG_V2, +};Signature · 1 line
2.35.3Signature · 2 lines
Thank you, Richard.
Signature · 5 lines
Thank you, Richard. -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 12 lines · Richard Palethorpe
Quoted 9 lines · Wei Gao
Quoted 9 lines
testcases/kernel/controllers/kill/kill01.c line 67
Quoted 2 lines
testcases/kernel/controllers/kill/kill01.c new file +2
-0+static int cg_run_nowait (const struct tst_cg_group *const cg, +void (*fn)(void ))Why keep this function?
If you want to convert tests to LTP, then don't do the minimum possible to use the LTP API. Use as much of it as possible otherwise we are just importing brittle self tests.
Quoted 5 lines
Quoted 3 lines
function is useful and wrap the fork action & put pid into cgroup.procs, is there any LTP API can replace this function? Could you help give example.
IMO you don't need to wrap fork or
SAFE_CG_PRINTF, just write it inline.
More logic added into this function in latest patch v6, i prefer keep it currently.
Quoted 11 lines
Quoted 9 lines
Quoted 7 lines
testcases/kernel/controllers/kill/kill01.c line 113
Quoted 4 lines
testcases/kernel/controllers/kill/kill01.c new file +3
-0+ +for (i =0 ; i < pid_num; i++) + pids[i] =cg_run_nowait (cg_child_test_simple, child_fn);If the parent is killed and the children are moved then they will return and cause a fork bomb.
There is no extra fork action in
child_fnso allchild_fnwill reparent and exit.I don't see how it will exit? It seems like it will just return.
The child_fun will exit if parent id is changed like below
+static void child_fn(void)
+{
+ int ppid = getppid();
+
+ while (getppid() == ppid)
+ usleep(1000);
+
+}
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi all,
Quoted 8 lines
Quoted 5 lines
lib/tst_cgroup.c | 1 + runtest/controllers | 1 + testcases/kernel/controllers/kill/.gitignore | 1 + testcases/kernel/controllers/kill/Makefile | 6 + testcases/kernel/controllers/kill/kill01.c | 138 +++++++++++++++++++nit: kill is not a controller, it is a core function. This should go in controllers/cgroup.
Very good point!
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v6 1/1 kill01: New case cgroup kill
In reply to Wei Gao via ltp--- lib/tst_cgroup.c | 55 ++++--- runtest/controllers | 1 + .../kernel/controllers/cgroup/kill/.gitignore | 1 + .../kernel/controllers/cgroup/kill/Makefile | 6 + .../kernel/controllers/cgroup/kill/kill01.c | 149 ++++++++++++++++++ 5 files changed, 193 insertions(+), 19 deletions(-) create mode 100644 testcases/kernel/controllers/cgroup/kill/.gitignore create mode 100644 testcases/kernel/controllers/cgroup/kill/Makefile create mode 100644 testcases/kernel/controllers/cgroup/kill/kill01.c
lib/tst_cgroup.c +36 -19
@@ -94,9 +94,10 @@ enum cgroup_ctrl_indx {CTRL_MISC ,CTRL_PERFEVENT ,CTRL_DEBUG , - CTRL_RDMA +CTRL_RDMA , + CTRL_PSEUDO }; -#define CTRLS_MAX CTRL_RDMA +#define CTRLS_MAX CTRL_PSEUDO/* At most we can have one cgroup V1 tree for each controller and one * (empty) v2 tree.
@@ -166,6 +167,7 @@ static const struct cgroup_file cgroup_ctrl_files[] = { { "cgroup.controllers", NULL, 0 }, { "cgroup.subtree_control", NULL, 0 }, { "cgroup.clone_children", "cgroup.clone_children", 0 }, + { "cgroup.kill", NULL, 0 }, { } };
@@ -258,6 +260,10 @@ static const struct cgroup_file rdma_ctrl_files[] = { { } }; +static const struct cgroup_file cgroup_pseudo_ctrl_files[] = { + { } +}; +#define CTRL_NAME_MAX 31#define CGROUP_CTRL_MEMBER (x, y)[y] = { .ctrl_name = #x, .files = \ x ## _ctrl_files, .ctrl_indx = y, NULL, 0 }
@@ -281,6 +287,7 @@ static struct cgroup_ctrl controllers[] = {CGROUP_CTRL_MEMBER (perf_event,CTRL_PERFEVENT ),CGROUP_CTRL_MEMBER (debug,CTRL_DEBUG ),CGROUP_CTRL_MEMBER (rdma,CTRL_RDMA ), + CGROUP_CTRL_MEMBER(cgroup_pseudo, CTRL_PSEUDO), { } };
@@ -826,6 +833,10 @@ void tst_cg_require(const char *const ctrl_name,if (options->needs_ver !=TST_CG_V2 )cgroup_mount_v1 (ctrl); +if (!strcmp (ctrl->ctrl_name,"cgroup_pseudo" )) { + ctrl->ctrl_root = roots; + } +if (!ctrl->ctrl_root) { tst_brk(TCONF, "'%s' controller required, but not available",
@@ -848,13 +859,15 @@ mkdirs: ctrl->ctrl_name); } -if (cgroup_ctrl_on_v2 (ctrl)) { -if (root->we_mounted_it) { -SAFE_FILE_PRINTFAT (root->mnt_dir.dir_fd, - cgsc,"+%s" , ctrl->ctrl_name); - }else { -tst_file_printfat (root->mnt_dir.dir_fd, - cgsc,"+%s" , ctrl->ctrl_name); +if (strcmp (ctrl->ctrl_name,"cgroup_pseudo" )) { +if (cgroup_ctrl_on_v2 (ctrl)) { +if (root->we_mounted_it) { +SAFE_FILE_PRINTFAT (root->mnt_dir.dir_fd, + cgsc,"+%s" , ctrl->ctrl_name); + }else { +tst_file_printfat (root->mnt_dir.dir_fd, + cgsc,"+%s" , ctrl->ctrl_name); + } } }
@@ -863,15 +876,17 @@ mkdirs:else root->ltp_dir.ctrl_field |= root->mnt_dir.ctrl_field; -if (cgroup_ctrl_on_v2 (ctrl)) { -SAFE_FILE_PRINTFAT (root->ltp_dir.dir_fd, - cgsc,"+%s" , ctrl->ctrl_name); - }else { -SAFE_FILE_PRINTFAT (root->ltp_dir.dir_fd, -"cgroup.clone_children" ,"%d" ,1 ); +if (strcmp (ctrl->ctrl_name,"cgroup_pseudo" )) { +if (cgroup_ctrl_on_v2 (ctrl)) { +SAFE_FILE_PRINTFAT (root->ltp_dir.dir_fd, + cgsc,"+%s" , ctrl->ctrl_name); + }else { +SAFE_FILE_PRINTFAT (root->ltp_dir.dir_fd, +"cgroup.clone_children" ,"%d" ,1 ); -if (ctrl->ctrl_indx ==CTRL_CPUSET ) -cgroup_copy_cpuset (root); +if (ctrl->ctrl_indx ==CTRL_CPUSET ) +cgroup_copy_cpuset (root); + } }cgroup_dir_mk (&root->ltp_dir, cgroup_ltp_drain_dir, &root->drain_dir);
@@ -1049,8 +1064,10 @@ static void cgroup_group_add_dir(const struct tst_cg_group *const parent,if (!parent || dir->dir_root->ver ==TST_CG_V1 )continue ; -SAFE_CG_PRINTF (parent,"cgroup.subtree_control" , -"+%s" , ctrl->ctrl_name); +if (strcmp (ctrl->ctrl_name,"cgroup_pseudo" )) { +SAFE_CG_PRINTF (parent,"cgroup.subtree_control" , +"+%s" , ctrl->ctrl_name); + } }for (i =0 ; cg->dirs[i]; i++)
runtest/controllers +1 -0
@@ -23,6 +23,7 @@ memcontrol01 memcontrol01 memcontrol02 memcontrol02 memcontrol03 memcontrol03 memcontrol04 memcontrol04 +kill01 kill01 cgroup_fj_function_debug cgroup_fj_function.sh debug cgroup_fj_function_cpuset cgroup_fj_function.sh cpuset
testcases/kernel/controllers/cgroup/kill/.gitignore new file +1 -0
@@ -0,0 +1 @@ +/kill01
testcases/kernel/controllers/cgroup/kill/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +top_srcdir ?= ../../../../../ + +include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/controllers/cgroup/kill/kill01.c new file +149 -0
149 lines not on this page · raw message
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Wei,
NOTE: it's slightly easier to review if you write sum of changes from previous version.
...
lib/tst_cgroup.c enum cgroup_ctrl_indx { · line 100
Quoted 11 lines
+++
b/lib/tst_cgroup.clib/tst_cgroup.c +3
-2@@ -94,9 +94,10 @@ enum cgroup_ctrl_indx {CTRL_MISC ,CTRL_PERFEVENT ,CTRL_DEBUG , - CTRL_RDMA +CTRL_RDMA , + CTRL_PSEUDO }; -#define CTRLS_MAX CTRL_RDMA +#define CTRLS_MAX CTRL_PSEUDO
Maybe CTRL_PSEUDO should be added as a separate commit with a proper description why it's needed.
...
Quoted 16 lines
lib/tst_cgroup.c +5
-0+static const struct cgroup_file cgroup_pseudo_ctrl_files[] = { + { } +}; +#define CTRL_NAME_MAX 31#define CGROUP_CTRL_MEMBER (x, y)[y] = { .ctrl_name = #x, .files = \ x ## _ctrl_files, .ctrl_indx = y, NULL, 0 }@@ -281,6 +287,7 @@ static struct cgroup_ctrl controllers[] = {CGROUP_CTRL_MEMBER (perf_event,CTRL_PERFEVENT ),CGROUP_CTRL_MEMBER (debug,CTRL_DEBUG ),CGROUP_CTRL_MEMBER (rdma,CTRL_RDMA ), + CGROUP_CTRL_MEMBER(cgroup_pseudo, CTRL_PSEUDO), { } };
lib/tst_cgroup.c void tst_cg_require(const char *const ctrl_name, · line 838
Quoted 6 lines
lib/tst_cgroup.c +3
-0@@ -826,6 +833,10 @@ void tst_cg_require(const char *const ctrl_name,if (options->needs_ver !=TST_CG_V2 )cgroup_mount_v1 (ctrl); +if (!strcmp (ctrl->ctrl_name,"cgroup_pseudo" )) { + ctrl->ctrl_root = roots; + }
tst_cgroup.c:836: WARNING: braces {} are not necessary for single statement blocks => please remove { }
Also strcmp for "cgroup_pseudo" is checked 3x in tst_cg_require(), why not creating a variable and use it in if ()?
int cgroup_pseudo = !strcmp(ctrl->ctrl_name, "cgroup_pseudo");
Quoted 6 lines
lib/tst_cgroup.c +1
-0+if (!ctrl->ctrl_root) { tst_brk(TCONF, "'%s' controller required, but not available",@@ -848,13 +859,15 @@ mkdirs: ctrl->ctrl_name);
lib/tst_cgroup.c mkdirs: · line 862
Quoted 10 lines
lib/tst_cgroup.c +1
-7} -if (cgroup_ctrl_on_v2 (ctrl)) { -if (root->we_mounted_it) { -SAFE_FILE_PRINTFAT (root->mnt_dir.dir_fd, - cgsc,"+%s" , ctrl->ctrl_name); - }else { -tst_file_printfat (root->mnt_dir.dir_fd, - cgsc,"+%s" , ctrl->ctrl_name); +if (strcmp (ctrl->ctrl_name,"cgroup_pseudo" )) {
nit: missing space after comma. I actually found by searching for previous strcmp line (with comma) and it found just 2 places instead of 3, but make check would report it for you:
make check-tst_cgroup
tst_cgroup.c:836: WARNING: braces {} are not necessary for single statement blocks tst_cgroup.c:862: ERROR: space required after that ',' (ctx:VxV) tst_cgroup.c:879: ERROR: space required after that ',' (ctx:VxV)
Quoted 87 lines
lib/tst_cgroup.c +22
-10+if (cgroup_ctrl_on_v2 (ctrl)) { +if (root->we_mounted_it) { +SAFE_FILE_PRINTFAT (root->mnt_dir.dir_fd, + cgsc,"+%s" , ctrl->ctrl_name); + }else { +tst_file_printfat (root->mnt_dir.dir_fd, + cgsc,"+%s" , ctrl->ctrl_name); + } } }@@ -863,15 +876,17 @@ mkdirs:else root->ltp_dir.ctrl_field |= root->mnt_dir.ctrl_field; -if (cgroup_ctrl_on_v2 (ctrl)) { -SAFE_FILE_PRINTFAT (root->ltp_dir.dir_fd, - cgsc,"+%s" , ctrl->ctrl_name); - }else { -SAFE_FILE_PRINTFAT (root->ltp_dir.dir_fd, -"cgroup.clone_children" ,"%d" ,1 ); +if (strcmp (ctrl->ctrl_name,"cgroup_pseudo" )) { +if (cgroup_ctrl_on_v2 (ctrl)) { +SAFE_FILE_PRINTFAT (root->ltp_dir.dir_fd, + cgsc,"+%s" , ctrl->ctrl_name); + }else { +SAFE_FILE_PRINTFAT (root->ltp_dir.dir_fd, +"cgroup.clone_children" ,"%d" ,1 ); -if (ctrl->ctrl_indx ==CTRL_CPUSET ) -cgroup_copy_cpuset (root); +if (ctrl->ctrl_indx ==CTRL_CPUSET ) +cgroup_copy_cpuset (root); + } }cgroup_dir_mk (&root->ltp_dir, cgroup_ltp_drain_dir, &root->drain_dir);@@ -1049,8 +1064,10 @@ static void cgroup_group_add_dir(const struct tst_cg_group *const parent,if (!parent || dir->dir_root->ver ==TST_CG_V1 )continue ; -SAFE_CG_PRINTF (parent,"cgroup.subtree_control" , -"+%s" , ctrl->ctrl_name); +if (strcmp (ctrl->ctrl_name,"cgroup_pseudo" )) { +SAFE_CG_PRINTF (parent,"cgroup.subtree_control" , +"+%s" , ctrl->ctrl_name); + } }for (i =0 ; cg->dirs[i]; i++)runtest/controllers +1
-0@@ -23,6 +23,7 @@ memcontrol01 memcontrol01 memcontrol02 memcontrol02 memcontrol03 memcontrol03 memcontrol04 memcontrol04 +kill01 kill01 cgroup_fj_function_debug cgroup_fj_function.sh debug cgroup_fj_function_cpuset cgroup_fj_function.sh cpusettestcases/kernel/controllers/cgroup/kill/.gitignore new file +1
-0@@ -0,0 +1 @@ +/kill01testcases/kernel/controllers/cgroup/kill/Makefile new file +6
-0@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +top_srcdir ?= ../../../../../ + +include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mktestcases/kernel/controllers/cgroup/kill/kill01.c new file +0
-0
testcases/kernel/controllers/cgroup/kill/kill01.c line 10
Quoted 10 lines
testcases/kernel/controllers/cgroup/kill/kill01.c new file +10
-0@@ -0,0 +1,149 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2012 Christian Brauner <brauner-AT-kernel.org> +* Copyright (c) 2023 SUSE LLC <[email protected]> +*/ + +/*\ +* [Description] +* +* This test is copied from kernel self test case
nit: I'd just wrote kselftest instead of "kernel self test case".
testcases/kernel/controllers/cgroup/kill/kill01.c line 11
Quoted 1 line
testcases/kernel/controllers/cgroup/kill/kill01.c new file +1
-0+* tools/testing/selftests/cgroup/test_kill.c
BTW am I correct that you converted only test_cgkill_simple() ? There are 2 other: test_cgkill_tree() and test_cgkill_forkbomb(),
I have no idea if they are worth to be implemented or should be implemented now. But maybe it'd be worth to mention that only simple test case was backported.
testcases/kernel/controllers/cgroup/kill/kill01.c line 22
Quoted 11 lines
testcases/kernel/controllers/cgroup/kill/kill01.c new file +11
-0+* +*/ + +#include <errno.h> +#include <linux/limits.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/types.h> +#include <unistd.h> +#include <sys/wait.h>
nit: only <sys/wait.h> is needed (others either imported by tst_test.h or needed in the original kselftest but not in LTP port).
testcases/kernel/controllers/cgroup/kill/kill01.c line 29
Quoted 7 lines
testcases/kernel/controllers/cgroup/kill/kill01.c new file +7
-0+ +#include "lapi/syscalls.h" +#include "tst_test.h" + +#define MAX_PID_NUM 100 +#define pid_num MIN(MAX_PID_NUM, (tst_ncpus_available() + 1)) +#define buf_len (20 * pid_num)
constants should be upper case (PID_NUM and BUF_LEN).
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
v7 cover kill01: New case cgroup kill
In reply to Wei Gao via ltpWei Gao (2):
kill01: New case cgroup kill
tst_cgroup.c: Add a cgroup pseudo controller
lib/tst_cgroup.c | 55 ++++--- runtest/controllers | 1 + .../kernel/controllers/cgroup/kill/.gitignore | 1 + .../kernel/controllers/cgroup/kill/Makefile | 6 + .../kernel/controllers/cgroup/kill/kill01.c | 144 ++++++++++++++++++ 5 files changed, 188 insertions(+), 19 deletions(-) create mode 100644 testcases/kernel/controllers/cgroup/kill/.gitignore create mode 100644 testcases/kernel/controllers/cgroup/kill/Makefile create mode 100644 testcases/kernel/controllers/cgroup/kill/kill01.c
base-commit: 1eda2532d8a7409f591d259e440f4e06f55615f2
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v7 1/2 kill01: New case cgroup kill
--- runtest/controllers | 1 + .../kernel/controllers/cgroup/kill/.gitignore | 1 + .../kernel/controllers/cgroup/kill/Makefile | 6 + .../kernel/controllers/cgroup/kill/kill01.c | 144 ++++++++++++++++++ 4 files changed, 152 insertions(+) create mode 100644 testcases/kernel/controllers/cgroup/kill/.gitignore create mode 100644 testcases/kernel/controllers/cgroup/kill/Makefile create mode 100644 testcases/kernel/controllers/cgroup/kill/kill01.c
runtest/controllers +1 -0
@@ -23,6 +23,7 @@ memcontrol01 memcontrol01 memcontrol02 memcontrol02 memcontrol03 memcontrol03 memcontrol04 memcontrol04 +kill01 kill01 cgroup_fj_function_debug cgroup_fj_function.sh debug cgroup_fj_function_cpuset cgroup_fj_function.sh cpuset
testcases/kernel/controllers/cgroup/kill/.gitignore new file +1 -0
@@ -0,0 +1 @@ +/kill01
testcases/kernel/controllers/cgroup/kill/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +top_srcdir ?= ../../../../../ + +include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/controllers/cgroup/kill/kill01.c new file +144 -0
144 lines not on this page · raw message
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v7 2/2 tst_cgroup.c: Add a cgroup pseudo controller
In reply to Wei Gao via ltpFor new test case such as kill01.c no need specific controller, it just need LTP cgroup library start work, so we need add a "cgroup" pseudo controller.
--- lib/tst_cgroup.c | 55 +++++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 19 deletions(-)
lib/tst_cgroup.c +36 -19
@@ -94,9 +94,10 @@ enum cgroup_ctrl_indx {CTRL_MISC ,CTRL_PERFEVENT ,CTRL_DEBUG , - CTRL_RDMA +CTRL_RDMA , + CTRL_PSEUDO }; -#define CTRLS_MAX CTRL_RDMA +#define CTRLS_MAX CTRL_PSEUDO/* At most we can have one cgroup V1 tree for each controller and one * (empty) v2 tree.
@@ -166,6 +167,7 @@ static const struct cgroup_file cgroup_ctrl_files[] = { { "cgroup.controllers", NULL, 0 }, { "cgroup.subtree_control", NULL, 0 }, { "cgroup.clone_children", "cgroup.clone_children", 0 }, + { "cgroup.kill", NULL, 0 }, { } };
@@ -258,6 +260,10 @@ static const struct cgroup_file rdma_ctrl_files[] = { { } }; +static const struct cgroup_file cgroup_pseudo_ctrl_files[] = { + { } +}; +#define CTRL_NAME_MAX 31#define CGROUP_CTRL_MEMBER (x, y)[y] = { .ctrl_name = #x, .files = \ x ## _ctrl_files, .ctrl_indx = y, NULL, 0 }
@@ -281,6 +287,7 @@ static struct cgroup_ctrl controllers[] = {CGROUP_CTRL_MEMBER (perf_event,CTRL_PERFEVENT ),CGROUP_CTRL_MEMBER (debug,CTRL_DEBUG ),CGROUP_CTRL_MEMBER (rdma,CTRL_RDMA ), + CGROUP_CTRL_MEMBER(cgroup_pseudo, CTRL_PSEUDO), { } };
@@ -797,6 +804,7 @@ void tst_cg_require(const char *const ctrl_name,const char *const cgsc ="cgroup.subtree_control" ;struct cgroup_ctrl *const ctrl =cgroup_find_ctrl (ctrl_name);struct cgroup_root *root; +int cgroup_pseudo = !strcmp (ctrl->ctrl_name,"cgroup_pseudo" );if (!ctrl) {tst_brk (TBROK ,"'%s' controller is unknown to LTP" , ctrl_name);
@@ -826,6 +834,9 @@ void tst_cg_require(const char *const ctrl_name,if (options->needs_ver !=TST_CG_V2 )cgroup_mount_v1 (ctrl); +if (cgroup_pseudo) + ctrl->ctrl_root = roots; +if (!ctrl->ctrl_root) { tst_brk(TCONF, "'%s' controller required, but not available",
@@ -848,13 +859,15 @@ mkdirs: ctrl->ctrl_name); } -if (cgroup_ctrl_on_v2 (ctrl)) { -if (root->we_mounted_it) { -SAFE_FILE_PRINTFAT (root->mnt_dir.dir_fd, - cgsc,"+%s" , ctrl->ctrl_name); - }else { -tst_file_printfat (root->mnt_dir.dir_fd, - cgsc,"+%s" , ctrl->ctrl_name); +if (!cgroup_pseudo) { +if (cgroup_ctrl_on_v2 (ctrl)) { +if (root->we_mounted_it) { +SAFE_FILE_PRINTFAT (root->mnt_dir.dir_fd, + cgsc,"+%s" , ctrl->ctrl_name); + }else { +tst_file_printfat (root->mnt_dir.dir_fd, + cgsc,"+%s" , ctrl->ctrl_name); + } } }
@@ -863,15 +876,17 @@ mkdirs:else root->ltp_dir.ctrl_field |= root->mnt_dir.ctrl_field; -if (cgroup_ctrl_on_v2 (ctrl)) { -SAFE_FILE_PRINTFAT (root->ltp_dir.dir_fd, - cgsc,"+%s" , ctrl->ctrl_name); - }else { -SAFE_FILE_PRINTFAT (root->ltp_dir.dir_fd, -"cgroup.clone_children" ,"%d" ,1 ); +if (!cgroup_pseudo) { +if (cgroup_ctrl_on_v2 (ctrl)) { +SAFE_FILE_PRINTFAT (root->ltp_dir.dir_fd, + cgsc,"+%s" , ctrl->ctrl_name); + }else { +SAFE_FILE_PRINTFAT (root->ltp_dir.dir_fd, +"cgroup.clone_children" ,"%d" ,1 ); -if (ctrl->ctrl_indx ==CTRL_CPUSET ) -cgroup_copy_cpuset (root); +if (ctrl->ctrl_indx ==CTRL_CPUSET ) +cgroup_copy_cpuset (root); + } }cgroup_dir_mk (&root->ltp_dir, cgroup_ltp_drain_dir, &root->drain_dir);
@@ -1049,8 +1064,10 @@ static void cgroup_group_add_dir(const struct tst_cg_group *const parent,if (!parent || dir->dir_root->ver ==TST_CG_V1 )continue ; -SAFE_CG_PRINTF (parent,"cgroup.subtree_control" , -"+%s" , ctrl->ctrl_name); +if (strcmp (ctrl->ctrl_name,"cgroup_pseudo" )) { +SAFE_CG_PRINTF (parent,"cgroup.subtree_control" , +"+%s" , ctrl->ctrl_name); + } }for (i =0 ; cg->dirs[i]; i++)
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
v8 cover kill01: New case cgroup kill
In reply to Wei Gao via ltpWei Gao (2):
kill01: New case cgroup kill
tst_cgroup.c: Add a cgroup pseudo controller
lib/tst_cgroup.c | 55 ++++--- runtest/controllers | 1 + .../kernel/controllers/cgroup/kill/.gitignore | 1 + .../kernel/controllers/cgroup/kill/Makefile | 6 + .../kernel/controllers/cgroup/kill/kill01.c | 144 ++++++++++++++++++ 5 files changed, 188 insertions(+), 19 deletions(-) create mode 100644 testcases/kernel/controllers/cgroup/kill/.gitignore create mode 100644 testcases/kernel/controllers/cgroup/kill/Makefile create mode 100644 testcases/kernel/controllers/cgroup/kill/kill01.c
base-commit: b67facdd9c3f0ef471d74dd59ac276139e63f4c4
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v8 1/2 kill01: New case cgroup kill
--- lib/tst_cgroup.c | 1 + runtest/controllers | 1 + .../kernel/controllers/cgroup/kill/.gitignore | 1 + .../kernel/controllers/cgroup/kill/Makefile | 6 + .../kernel/controllers/cgroup/kill/kill01.c | 144 ++++++++++++++++++ 5 files changed, 153 insertions(+) create mode 100644 testcases/kernel/controllers/cgroup/kill/.gitignore create mode 100644 testcases/kernel/controllers/cgroup/kill/Makefile create mode 100644 testcases/kernel/controllers/cgroup/kill/kill01.c
lib/tst_cgroup.c +1 -0
@@ -166,6 +166,7 @@ static const struct cgroup_file cgroup_ctrl_files[] = { { "cgroup.controllers", NULL, 0 }, { "cgroup.subtree_control", NULL, 0 }, { "cgroup.clone_children", "cgroup.clone_children", 0 }, + { "cgroup.kill", NULL, 0 }, { } };
runtest/controllers +1 -0
@@ -23,6 +23,7 @@ memcontrol01 memcontrol01 memcontrol02 memcontrol02 memcontrol03 memcontrol03 memcontrol04 memcontrol04 +kill01 kill01 cgroup_fj_function_debug cgroup_fj_function.sh debug cgroup_fj_function_cpuset cgroup_fj_function.sh cpuset
testcases/kernel/controllers/cgroup/kill/.gitignore new file +1 -0
@@ -0,0 +1 @@ +/kill01
testcases/kernel/controllers/cgroup/kill/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +top_srcdir ?= ../../../../../ + +include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/controllers/cgroup/kill/kill01.c new file +144 -0
144 lines not on this page · raw message
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 52 lines · Wei Gao via ltp
Signed-off-by Wei Gao <[email protected]>--- lib/tst_cgroup.c | 1 + runtest/controllers | 1 + .../kernel/controllers/cgroup/kill/.gitignore | 1 + .../kernel/controllers/cgroup/kill/Makefile | 6 + .../kernel/controllers/cgroup/kill/kill01.c | 144 ++++++++++++++++++ 5 files changed, 153 insertions(+) create mode 100644 testcases/kernel/controllers/cgroup/kill/.gitignore create mode 100644 testcases/kernel/controllers/cgroup/kill/Makefile create mode 100644 testcases/kernel/controllers/cgroup/kill/kill01.clib/tst_cgroup.c +1
-0@@ -166,6 +166,7 @@ static const struct cgroup_file cgroup_ctrl_files[] = { { "cgroup.controllers", NULL, 0 }, { "cgroup.subtree_control", NULL, 0 }, { "cgroup.clone_children", "cgroup.clone_children", 0 }, + { "cgroup.kill", NULL, 0 }, { } };runtest/controllers +1
-0@@ -23,6 +23,7 @@ memcontrol01 memcontrol01 memcontrol02 memcontrol02 memcontrol03 memcontrol03 memcontrol04 memcontrol04 +kill01 kill01 cgroup_fj_function_debug cgroup_fj_function.sh debug cgroup_fj_function_cpuset cgroup_fj_function.sh cpusettestcases/kernel/controllers/cgroup/kill/.gitignore new file +1
-0@@ -0,0 +1 @@ +/kill01testcases/kernel/controllers/cgroup/kill/Makefile new file +0
-0
testcases/kernel/controllers/cgroup/kill/Makefile line 3
Quoted 3 lines
testcases/kernel/controllers/cgroup/kill/Makefile new file +3
-0@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + +top_srcdir ?= ../../../../../
The depth of top_srcdir is incorrect, also the upper dir Makefile should be changed to include generic_trunk_target.mk.
i.e.
# git diff
(quoted diff) +0 -0
b/testcases/kernel/controllers/cgroup/Makefile
index 0db0a7d..1592d8e 100644
testcases/kernel/controllers/cgroup/Makefile +1 -1
@@ -9,4 +9,4 @@ include $(abs_srcdir)/../Makefile.inc INSTALL_TARGETS := *.sh -include $(top_srcdir)/include/mk/generic_leaf_target.mk +include $(top_srcdir)/include/mk/generic_trunk_target.mk
(quoted diff) +0 -0
b/testcases/kernel/controllers/cgroup/kill/Makefile index bf5aea9..2f198e6 100644
testcases/kernel/controllers/cgroup/kill/Makefile +1 -1
@@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-or-later -top_srcdir ?= ../../../../../ +top_srcdir ?= ../../../../.. include $(top_srcdir)/include/mk/testcases.mk include $(top_srcdir)/include/mk/generic_leaf_target.mk
But I guess the suggestion of Richard is probably to rename kill01.c to cgroup_core03.c/cgroup_kill01.c and put it into ".../controllers/cgroup/" directly.
Then we don't need to create a subdir or Makefile for kill/ anymore.
Quoted 146 lines
testcases/kernel/controllers/cgroup/kill/Makefile new file +3
-0+ +include $(top_srcdir)/include/mk/testcases.mk +include $(top_srcdir)/include/mk/generic_leaf_target.mktestcases/kernel/controllers/cgroup/kill/kill01.c new file +79
-0@@ -0,0 +1,144 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2012 Christian Brauner <brauner-AT-kernel.org> +* Copyright (c) 2023 SUSE LLC <[email protected]> +*/ + +/*\ +* [Description] +* +* This test is copied from kselftest +* tools/testing/selftests/cgroup/test_kill.c +* Only simple test implemented within current case, the other cases such +* as test_cgkill_tree and test_cgkill_forkbomb can be created later. +* +*/ + +#include <sys/wait.h> + +#include "lapi/syscalls.h" +#include "tst_test.h" + +#define MAX_PID_NUM 100 +#define PID_NUM MIN(MAX_PID_NUM, (tst_ncpus_available() + 1)) +#define BUF_LEN (20 * PID_NUM) + +static int *data_ptr; +static char *buf; +static struct tst_cg_group *cg_child_test_simple; + +static int wait_for_pid (pid_t pid) +{ +int status, ret; + +again: + ret =waitpid (pid, &status,0 ); +if (ret ==-1 ) { +if (errno ==EINTR ) + goto again; + +return -1 ; + } + +if (WIFSIGNALED (status)) +return 0 ; + +return -1 ; +} + +/* +* A simple process running in a sleep loop until being +* re-parented. +*/ +static void child_fn (void ) +{ +int ppid =getppid (); + +while (getppid () == ppid) +usleep (1000 ); + +} + +static int cg_run_nowait (const struct tst_cg_group *const cg, +void (*fn)(void )) +{ +int pid; + + pid =SAFE_FORK (); +if (pid ==0 ) { +SAFE_CG_PRINTF (cg,"cgroup.procs" ,"%d" ,getpid ()); +tst_atomic_inc (data_ptr); +if (tst_atomic_load (data_ptr) ==PID_NUM ) +TST_CHECKPOINT_WAKE (0 ); +fn (); + } + +return pid; +} + +static int cg_wait_for_proc_count(const struct tst_cg_group *cg, intcount)
testcases/kernel/controllers/cgroup/kill/kill01.c new file +34
-0+{ +char *ptr; + +int nr =0 ; + +SAFE_CG_READ (cg,"cgroup.procs" , buf,BUF_LEN ); + +for (ptr = buf; *ptr; ptr++) +if (*ptr =='\n' ) + nr++; + +if (nr >= count) +return 0 ; + +tst_res (TINFO ,"Expect process num is %d but get %d" , count, nr); + +return -1 ; +} + +static void run (void ) +{ +pid_t pids[MAX_PID_NUM ]; +int i; + *data_ptr =0 ; + + cg_child_test_simple =tst_cg_group_mk (tst_cg,"cg_test_simple" ); + +memset (buf,0 ,BUF_LEN ); + +for (i =0 ; i <PID_NUM ; i++) + pids[i] =cg_run_nowait (cg_child_test_simple, child_fn); + +TST_CHECKPOINT_WAIT (0 ); + TST_EXP_PASS(cg_wait_for_proc_count(cg_child_test_simple,
PID_NUM));testcases/kernel/controllers/cgroup/kill/kill01.c new file +12
-0+SAFE_CG_PRINTF (cg_child_test_simple,"cgroup.kill" ,"%d" ,1 ); + +for (i =0 ; i <PID_NUM ; i++) +TST_EXP_PASS_SILENT (wait_for_pid (pids[i])); + + cg_child_test_simple =tst_cg_group_rm (cg_child_test_simple); +} + +static void setup (void ) +{ + buf =tst_alloc (BUF_LEN ); + data_ptr = SAFE_MMAP(NULL, sizeof(uintptr_t), PROT_READ |
PROT_WRITE,
+MAP_SHARED|MAP_ANONYMOUS, -1, 0);testcases/kernel/controllers/cgroup/kill/kill01.c new file +5
-0+} + +static void cleanup (void ) +{ +if (data_ptr)
testcases/kernel/controllers/cgroup/kill/kill01.c
Quoted 10 lines
testcases/kernel/controllers/cgroup/kill/kill01.c new file +10
-0+SAFE_MUNMAP (data_ptr,sizeof (uintptr_t )); +} + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .cleanup = cleanup, + .forks_child =1 , + .max_runtime =20 , + .needs_cgroup_ctrls = (const char *const []){"memory" ,NULL },
Obviously, we shouldn't request "memory" controller anymore.
.needs_cgroup_ctrls = (const char *const []){ "pseudo", NULL },Quoted 11 lines
testcases/kernel/controllers/cgroup/kill/kill01.c new file +3
-1+ .needs_cgroup_ver = TST_CG_V2, + .needs_checkpoints = 1, +}; --2.35.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v8 2/2 tst_cgroup.c: Add a cgroup pseudo controller
In reply to Wei Gao via ltpFor new test case such as kill01.c no need specific controller, it just need LTP cgroup library start work, so we need add a "cgroup" pseudo controller.
--- lib/tst_cgroup.c | 54 +++++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 19 deletions(-)
lib/tst_cgroup.c +35 -19
@@ -94,9 +94,10 @@ enum cgroup_ctrl_indx {CTRL_MISC ,CTRL_PERFEVENT ,CTRL_DEBUG , - CTRL_RDMA +CTRL_RDMA , + CTRL_PSEUDO }; -#define CTRLS_MAX CTRL_RDMA +#define CTRLS_MAX CTRL_PSEUDO/* At most we can have one cgroup V1 tree for each controller and one * (empty) v2 tree.
@@ -259,6 +260,10 @@ static const struct cgroup_file rdma_ctrl_files[] = { { } }; +static const struct cgroup_file cgroup_pseudo_ctrl_files[] = { + { } +}; +#define CTRL_NAME_MAX 31#define CGROUP_CTRL_MEMBER (x, y)[y] = { .ctrl_name = #x, .files = \ x ## _ctrl_files, .ctrl_indx = y, NULL, 0 }
@@ -282,6 +287,7 @@ static struct cgroup_ctrl controllers[] = {CGROUP_CTRL_MEMBER (perf_event,CTRL_PERFEVENT ),CGROUP_CTRL_MEMBER (debug,CTRL_DEBUG ),CGROUP_CTRL_MEMBER (rdma,CTRL_RDMA ), + CGROUP_CTRL_MEMBER(cgroup_pseudo, CTRL_PSEUDO), { } };
@@ -798,6 +804,7 @@ void tst_cg_require(const char *const ctrl_name,const char *const cgsc ="cgroup.subtree_control" ;struct cgroup_ctrl *const ctrl =cgroup_find_ctrl (ctrl_name);struct cgroup_root *root; +int cgroup_pseudo = !strcmp (ctrl->ctrl_name,"cgroup_pseudo" );if (!ctrl) {tst_brk (TBROK ,"'%s' controller is unknown to LTP" , ctrl_name);
@@ -827,6 +834,9 @@ void tst_cg_require(const char *const ctrl_name,if (options->needs_ver !=TST_CG_V2 )cgroup_mount_v1 (ctrl); +if (cgroup_pseudo) + ctrl->ctrl_root = roots; +if (!ctrl->ctrl_root) { tst_brk(TCONF, "'%s' controller required, but not available",
@@ -849,13 +859,15 @@ mkdirs: ctrl->ctrl_name); } -if (cgroup_ctrl_on_v2 (ctrl)) { -if (root->we_mounted_it) { -SAFE_FILE_PRINTFAT (root->mnt_dir.dir_fd, - cgsc,"+%s" , ctrl->ctrl_name); - }else { -tst_file_printfat (root->mnt_dir.dir_fd, - cgsc,"+%s" , ctrl->ctrl_name); +if (!cgroup_pseudo) { +if (cgroup_ctrl_on_v2 (ctrl)) { +if (root->we_mounted_it) { +SAFE_FILE_PRINTFAT (root->mnt_dir.dir_fd, + cgsc,"+%s" , ctrl->ctrl_name); + }else { +tst_file_printfat (root->mnt_dir.dir_fd, + cgsc,"+%s" , ctrl->ctrl_name); + } } }
@@ -864,15 +876,17 @@ mkdirs:else root->ltp_dir.ctrl_field |= root->mnt_dir.ctrl_field; -if (cgroup_ctrl_on_v2 (ctrl)) { -SAFE_FILE_PRINTFAT (root->ltp_dir.dir_fd, - cgsc,"+%s" , ctrl->ctrl_name); - }else { -SAFE_FILE_PRINTFAT (root->ltp_dir.dir_fd, -"cgroup.clone_children" ,"%d" ,1 ); +if (!cgroup_pseudo) { +if (cgroup_ctrl_on_v2 (ctrl)) { +SAFE_FILE_PRINTFAT (root->ltp_dir.dir_fd, + cgsc,"+%s" , ctrl->ctrl_name); + }else { +SAFE_FILE_PRINTFAT (root->ltp_dir.dir_fd, +"cgroup.clone_children" ,"%d" ,1 ); -if (ctrl->ctrl_indx ==CTRL_CPUSET ) -cgroup_copy_cpuset (root); +if (ctrl->ctrl_indx ==CTRL_CPUSET ) +cgroup_copy_cpuset (root); + } }cgroup_dir_mk (&root->ltp_dir, cgroup_ltp_drain_dir, &root->drain_dir);
@@ -1050,8 +1064,10 @@ static void cgroup_group_add_dir(const struct tst_cg_group *const parent,if (!parent || dir->dir_root->ver ==TST_CG_V1 )continue ; -SAFE_CG_PRINTF (parent,"cgroup.subtree_control" , -"+%s" , ctrl->ctrl_name); +if (strcmp (ctrl->ctrl_name,"cgroup_pseudo" )) { +SAFE_CG_PRINTF (parent,"cgroup.subtree_control" , +"+%s" , ctrl->ctrl_name); + } }for (i =0 ; cg->dirs[i]; i++)
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v8 2/2] tst_cgroup.c: Add a cgroup pseudo controller
Quoted 27 lines · Wei Gao via ltp
For new test case such as
kill01.cno need specific controller, it just need LTP cgroup library start work, so we need add a "cgroup" pseudo controller.Signed-off-by Wei Gao <[email protected]>--- lib/tst_cgroup.c | 54 +++++++++++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 19 deletions(-)lib/tst_cgroup.c +3
-2@@ -94,9 +94,10 @@ enum cgroup_ctrl_indx {CTRL_MISC ,CTRL_PERFEVENT ,CTRL_DEBUG , - CTRL_RDMA +CTRL_RDMA , + CTRL_PSEUDO }; -#define CTRLS_MAX CTRL_RDMA +#define CTRLS_MAX CTRL_PSEUDO/* At most we can have one cgroup V1 tree for each controller and one * (empty) v2 tree.
lib/tst_cgroup.c static const struct cgroup_file rdma_ctrl_files[] = { · line 264
Quoted 5 lines
lib/tst_cgroup.c +1
-0@@ -259,6 +260,10 @@ static const struct cgroup_file rdma_ctrl_files[] = { { } }; +static const struct cgroup_file cgroup_pseudo_ctrl_files[] = {
As the controller defined CTRL_PSEUDO here may be better to use pseudo_ctrl_files without "cgroup_" prefix.
lib/tst_cgroup.c static struct cgroup_ctrl controllers[] = { · line 291
Quoted 12 lines
lib/tst_cgroup.c +3
-0+ { } +}; +#define CTRL_NAME_MAX 31#define CGROUP_CTRL_MEMBER (x, y)[y] = { .ctrl_name = #x, .files = \x ## _ctrl_files, .ctrl_indx = y, NULL, 0 }lib/tst_cgroup.c +1
-0@@ -282,6 +287,7 @@ static struct cgroup_ctrl controllers[] = {CGROUP_CTRL_MEMBER (perf_event,CTRL_PERFEVENT ),CGROUP_CTRL_MEMBER (debug,CTRL_DEBUG ),CGROUP_CTRL_MEMBER (rdma,CTRL_RDMA ), + CGROUP_CTRL_MEMBER(cgroup_pseudo, CTRL_PSEUDO),
use pseudo directly without "cgroup_" prefix.
lib/tst_cgroup.c void tst_cg_require(const char *const ctrl_name, · line 808
Quoted 9 lines
lib/tst_cgroup.c +1
-0{ } };@@ -798,6 +804,7 @@ void tst_cg_require(const char *const ctrl_name,const char *const cgsc ="cgroup.subtree_control" ;struct cgroup_ctrl *const ctrl =cgroup_find_ctrl (ctrl_name);struct cgroup_root *root; +int cgroup_pseudo = !strcmp (ctrl->ctrl_name,"cgroup_pseudo" );
int cgroup_pseudo = !strcmp(ctrl->ctrl_name, "pseudo");
Quoted 18 lines
lib/tst_cgroup.c +0
-0if (!ctrl) { tst_brk(TBROK, "'%s' controller is unknown to LTP",
ctrl_name);lib/tst_cgroup.c +3
-0@@ -827,6 +834,9 @@ void tst_cg_require(const char *const ctrl_name,if (options->needs_ver !=TST_CG_V2 )cgroup_mount_v1 (ctrl); +if (cgroup_pseudo) + ctrl->ctrl_root = roots; +if (!ctrl->ctrl_root) { tst_brk(TCONF, "'%s' controller required, but not available",@@ -849,13 +859,15 @@ mkdirs: ctrl->ctrl_name); }
lib/tst_cgroup.c mkdirs: · line 864
Quoted 10 lines
lib/tst_cgroup.c +2
-7-if (cgroup_ctrl_on_v2 (ctrl)) { -if (root->we_mounted_it) { -SAFE_FILE_PRINTFAT (root->mnt_dir.dir_fd, - cgsc,"+%s" , ctrl->ctrl_name); - }else { -tst_file_printfat (root->mnt_dir.dir_fd, - cgsc,"+%s" , ctrl->ctrl_name); +if (!cgroup_pseudo) { +if (cgroup_ctrl_on_v2 (ctrl)) {
This makes things more complicated, what about:
if (cgroup_ctrl_on_v2(ctrl) && !cgroup_pseudo) {to reduce one nested.
Quoted 15 lines
lib/tst_cgroup.c +7
-0+if (root->we_mounted_it) { +SAFE_FILE_PRINTFAT (root->mnt_dir.dir_fd, + cgsc,"+%s" , ctrl->ctrl_name); + }else { +tst_file_printfat (root->mnt_dir.dir_fd, + cgsc,"+%s" , ctrl->ctrl_name); + }} }lib/tst_cgroup.c +0
-0@@ -864,15 +876,17 @@ mkdirs:else root->ltp_dir.ctrl_field |= root->mnt_dir.ctrl_field;
lib/tst_cgroup.c mkdirs: · line 881
Quoted 10 lines
lib/tst_cgroup.c +2
-6-if (cgroup_ctrl_on_v2 (ctrl)) { -SAFE_FILE_PRINTFAT (root->ltp_dir.dir_fd, - cgsc,"+%s" , ctrl->ctrl_name); - }else { -SAFE_FILE_PRINTFAT (root->ltp_dir.dir_fd, -"cgroup.clone_children" ,"%d" ,1 ); +if (!cgroup_pseudo) { +if (cgroup_ctrl_on_v2 (ctrl)) {
if (cgroup_ctrl_on_v2(ctrl) && !cgroup_pseudo) {
Quoted 16 lines
lib/tst_cgroup.c +8
-2+SAFE_FILE_PRINTFAT (root->ltp_dir.dir_fd, + cgsc,"+%s" , ctrl->ctrl_name); + }else { +SAFE_FILE_PRINTFAT (root->ltp_dir.dir_fd, +"cgroup.clone_children" ,"%d" ,1 ); -if (ctrl->ctrl_indx ==CTRL_CPUSET ) -cgroup_copy_cpuset (root); +if (ctrl->ctrl_indx ==CTRL_CPUSET ) +cgroup_copy_cpuset (root); + } }cgroup_dir_mk(&root->ltp_dir, cgroup_ltp_drain_dir,
&root->drain_dir);
lib/tst_cgroup.c static void cgroup_group_add_dir(const struct · line 1069
Quoted 8 lines
lib/tst_cgroup.c +1
-2@@ -1050,8 +1064,10 @@ static void cgroup_group_add_dir(const struct tst_cg_group *const parent, if (!parent || dir->dir_root->ver == TST_CG_V1) continue; -SAFE_CG_PRINTF (parent,"cgroup.subtree_control" , -"+%s" , ctrl->ctrl_name); +if (strcmp (ctrl->ctrl_name,"cgroup_pseudo" )) {
Remove "cgroup_" prefix.
Quoted 6 lines
lib/tst_cgroup.c +3
-0+SAFE_CG_PRINTF (parent,"cgroup.subtree_control" , +"+%s" , ctrl->ctrl_name); + } }for (i = 0; cg->dirs[i]; i++)
Quoted 8 lines
--
2.35.3--
Mailing list info: https://lists.linux.it/listinfo/ltpOther two issues we have to resolve:
1. We'd better guarantee the "pseudo" controller is safely ignored by Cgroup_V1 in case of '.needs_cgroup_ver = TST_CG_V1'. Because cgroup_mount_v1(ctrl) will try to mount a 'pseudo' controller once a system without any available (V1 and V2) ctrls, which ultimately caused the test to break.
2. Assume the test running on a CgroupV1 supported system, which will try to mount CgroupV2 because pseudo is not detected exist in V1 controllers, so it by default thinks we need to mount CgroupV2 and test there.
But the fact is that CgroupV1-only system is not fully supported CgroupV2, even if we mount the V2 successfully the function is limited and this ultimately
uses a lack of cgroup.kill file and failed again.
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v8 2/2] tst_cgroup.c: Add a cgroup pseudo controller
In reply to Wei Gao via ltpHi!
lib/tst_cgroup.c enum cgroup_ctrl_indx { · line 98
Quoted 11 lines
lib/tst_cgroup.c +2
-1@@ -94,9 +94,10 @@ enum cgroup_ctrl_indx {CTRL_MISC ,CTRL_PERFEVENT ,CTRL_DEBUG , -CTRL_RDMA +CTRL_RDMA , +CTRL_PSEUDO
I wonder if PSEUDO is the right name here. Maybe CTRL_BASE as we do not mount any controller to access the control files.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
v9 cover kill01: New case cgroup kill
In reply to Wei Gao via ltpWei Gao (2):
kill01: New case cgroup kill
tst_cgroup.c: Add a cgroup pseudo controller
lib/tst_cgroup.c | 48 ++++-- runtest/controllers | 1 + .../kernel/controllers/cgroup/.gitignore | 1 + .../kernel/controllers/cgroup/cgroup_core03.c | 144 ++++++++++++++++++ 4 files changed, 179 insertions(+), 15 deletions(-) create mode 100644 testcases/kernel/controllers/cgroup/cgroup_core03.c
base-commit: b67facdd9c3f0ef471d74dd59ac276139e63f4c4
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v9 1/2 kill01: New case cgroup kill
--- lib/tst_cgroup.c | 1 + runtest/controllers | 1 + .../kernel/controllers/cgroup/.gitignore | 1 + .../kernel/controllers/cgroup/cgroup_core03.c | 144 ++++++++++++++++++ 4 files changed, 147 insertions(+) create mode 100644 testcases/kernel/controllers/cgroup/cgroup_core03.c
lib/tst_cgroup.c +1 -0
@@ -166,6 +166,7 @@ static const struct cgroup_file cgroup_ctrl_files[] = { { "cgroup.controllers", NULL, 0 }, { "cgroup.subtree_control", NULL, 0 }, { "cgroup.clone_children", "cgroup.clone_children", 0 }, + { "cgroup.kill", NULL, 0 }, { } };
runtest/controllers +1 -0
@@ -1,6 +1,7 @@ #DESCRIPTION:Resource Management testing cgroup_core01 cgroup_core01 cgroup_core02 cgroup_core02 +cgroup_core03 cgroup_core03 cgroup cgroup_regression_test.sh memcg_regression memcg_regression_test.sh memcg_test_3 memcg_test_3
testcases/kernel/controllers/cgroup/.gitignore +1 -0
@@ -2,3 +2,4 @@ /cgroup_regression_getdelays /cgroup_core01 /cgroup_core02 +/cgroup_core03
testcases/kernel/controllers/cgroup/cgroup_core03.c new file +144 -0
144 lines not on this page · raw message
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 96 lines
--- lib/tst_cgroup.c | 1 + runtest/controllers | 1 + .../kernel/controllers/cgroup/.gitignore | 1 + .../kernel/controllers/cgroup/cgroup_core03.c | 144 ++++++++++++++++++ 4 files changed, 147 insertions(+) create mode 100644 testcases/kernel/controllers/cgroup/cgroup_core03.clib/tst_cgroup.c +1
-0@@ -166,6 +166,7 @@ static const struct cgroup_file cgroup_ctrl_files[] = { { "cgroup.controllers", NULL, 0 }, { "cgroup.subtree_control", NULL, 0 }, { "cgroup.clone_children", "cgroup.clone_children", 0 }, + { "cgroup.kill", NULL, 0 }, { } };runtest/controllers +1
-0@@ -1,6 +1,7 @@ #DESCRIPTION:Resource Management testing cgroup_core01 cgroup_core01 cgroup_core02 cgroup_core02 +cgroup_core03 cgroup_core03 cgroup cgroup_regression_test.sh memcg_regression memcg_regression_test.sh memcg_test_3 memcg_test_3testcases/kernel/controllers/cgroup/.gitignore +1
-0@@ -2,3 +2,4 @@ /cgroup_regression_getdelays /cgroup_core01 /cgroup_core02 +/cgroup_core03testcases/kernel/controllers/cgroup/cgroup_core03.c new file +49
-0@@ -0,0 +1,144 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (c) 2012 Christian Brauner <brauner-AT-kernel.org> +* Copyright (c) 2023 SUSE LLC <[email protected]> +*/ + +/*\ +* [Description] +* +* This test is copied from kselftest +* tools/testing/selftests/cgroup/test_kill.c +* Only simple test implemented within current case, the other cases such +* as test_cgkill_tree and test_cgkill_forkbomb can be created later. +* +*/ + +#include <sys/wait.h> + +#include "lapi/syscalls.h" +#include "tst_test.h" + +#define MAX_PID_NUM 100 +#define PID_NUM MIN(MAX_PID_NUM, (tst_ncpus_available() + 1)) +#define BUF_LEN (20 * PID_NUM) + +static int *data_ptr; +static char *buf; +static struct tst_cg_group *cg_child_test_simple; + +static int wait_for_pid (pid_t pid) +{ +int status, ret; + +again: + ret =waitpid (pid, &status,0 ); +if (ret ==-1 ) { +if (errno ==EINTR ) + goto again; + +return -1 ; + } + +if (WIFSIGNALED (status)) +return 0 ; + +return -1 ; +} + +/*
testcases/kernel/controllers/cgroup/cgroup_core03.c line 59
Quoted 10 lines
testcases/kernel/controllers/cgroup/cgroup_core03.c new file +10
-0+* A simple process running in a sleep loop until being +* re-parented. +*/ +static void child_fn (void ) +{ +int ppid =getppid (); + +while (getppid () == ppid) +usleep (1000 ); +
What's the reason we are waiting for reparenting here? Aren't these processes killed anyways? I suppose that we can just call pause() here instead.
testcases/kernel/controllers/cgroup/cgroup_core03.c line 72
Quoted 13 lines
testcases/kernel/controllers/cgroup/cgroup_core03.c new file +13
-0+} + +static int cg_run_nowait (const struct tst_cg_group *const cg, +void (*fn)(void )) +{ +int pid; + + pid =SAFE_FORK (); +if (pid ==0 ) { +SAFE_CG_PRINTF (cg,"cgroup.procs" ,"%d" ,getpid ()); +tst_atomic_inc (data_ptr); +if (tst_atomic_load (data_ptr) ==PID_NUM ) +TST_CHECKPOINT_WAKE (0 );
I do not think that this is 100% correct, as it is we may end up calling the TST_CHECKOPOINT_WAKE(0) more than once here, since there is a race between increment and load. An if that happens only one of the calls to TST_CHECKPOINT_WAKE(0) will succeeds, while the rest would fail and break the test.
First of all the tst_atomic_inc() returns the value after the increment, so that we can actually get the counter value without a race.
Secondly I think that we can get rid of the atomic operations completely, we just have to loop N times over the TST_CHECKPOINT_WAIT() in the run() function and call TST_CHECKPOINT_WAKE() in each child instance. We can also add TST_CHECKPOINT_WAIT_NR() to the test library that would also take a number of wait calls passed as a parameter.
testcases/kernel/controllers/cgroup/cgroup_core03.c line 79
Quoted 7 lines
testcases/kernel/controllers/cgroup/cgroup_core03.c new file +7
-0+fn (); + } + +return pid; +} + +static int cg_wait_for_proc_count (const struct tst_cg_group *cg,int count)
The function does not wait for anything, so it should be called cg_count_procs() or similar.
Quoted 25 lines
testcases/kernel/controllers/cgroup/cgroup_core03.c new file +25
-0+{ +char *ptr; + +int nr =0 ; + +SAFE_CG_READ (cg,"cgroup.procs" , buf,BUF_LEN ); + +for (ptr = buf; *ptr; ptr++) +if (*ptr =='\n' ) + nr++; + +if (nr >= count) +return 0 ; + +tst_res (TINFO ,"Expect process num is %d but get %d" , count, nr); + +return -1 ; +} + +static void run (void ) +{ +pid_t pids[MAX_PID_NUM ]; +int i; + *data_ptr =0 ; +
testcases/kernel/controllers/cgroup/cgroup_core03.c
Quoted 10 lines
testcases/kernel/controllers/cgroup/cgroup_core03.c new file +10
-0+ cg_child_test_simple =tst_cg_group_mk (tst_cg,"cg_test_simple" ); + +memset (buf,0 ,BUF_LEN ); + +for (i =0 ; i <PID_NUM ; i++) + pids[i] =cg_run_nowait (cg_child_test_simple, child_fn); + +TST_CHECKPOINT_WAIT (0 ); + +TST_EXP_PASS (cg_wait_for_proc_count (cg_child_test_simple,PID_NUM ));
This is very minor, but I would make the function return the number of pids found in the cgroup and called it as:
TST_EXP_VAL(cg_count_procs(cg_child_test_simple), pid_num);
testcases/kernel/controllers/cgroup/cgroup_core03.c line 117
Quoted 4 lines
testcases/kernel/controllers/cgroup/cgroup_core03.c new file +4
-0+SAFE_CG_PRINTF (cg_child_test_simple,"cgroup.kill" ,"%d" ,1 ); + +for (i =0 ; i <PID_NUM ; i++) +TST_EXP_PASS_SILENT (wait_for_pid (pids[i]));
Then we can do here:
TST_EXP_VAL(cg_count_procs(cg_child_test_simple), 0);
Quoted 32 lines
testcases/kernel/controllers/cgroup/cgroup_core03.c new file +26
-0+ cg_child_test_simple =tst_cg_group_rm (cg_child_test_simple); +} + +static void setup (void ) +{ + buf =tst_alloc (BUF_LEN ); + data_ptr =SAFE_MMAP (NULL ,sizeof (uintptr_t ),PROT_READ |PROT_WRITE , +MAP_SHARED |MAP_ANONYMOUS ,-1 ,0 ); +} + +static void cleanup (void ) +{ +if (data_ptr) +SAFE_MUNMAP (data_ptr,sizeof (uintptr_t )); +} + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .cleanup = cleanup, + .forks_child =1 , + .max_runtime =20 , + .needs_cgroup_ctrls = (const char *const []){"pseudo" ,NULL }, + .needs_cgroup_ver =TST_CG_V2 , + .needs_checkpoints =1 , +};Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Please remove me from your mailing list. I’m not from your team. Why are you sending all this to me. Just remove me from your list.
Quoted 250 lines · Cyril Hrubis
Hi!
lib/tst_cgroup.c static const struct cgroup_file cgroup_ctrl_files[]
Quoted 13 lines
--- lib/tst_cgroup.c | 1 + runtest/controllers | 1 + .../kernel/controllers/cgroup/.gitignore | 1 + .../kernel/controllers/cgroup/cgroup_core03.c | 144 ++++++++++++++++++ 4 files changed, 147 insertions(+) create mode 100644 testcases/kernel/controllers/cgroup/cgroup_core03.clib/tst_cgroup.c +0
-0@@ -166,6 +166,7 @@ static const struct cgroup_file cgroup_ctrl_files[]= {
Review
Quoted 20 lines
lib/tst_cgroup.c +1
-0{ "cgroup.controllers", NULL, 0 }, { "cgroup.subtree_control", NULL, 0 }, { "cgroup.clone_children", "cgroup.clone_children", 0 }, + { "cgroup.kill", NULL, 0 }, { } };runtest/controllers +1
-0@@ -1,6 +1,7 @@ #DESCRIPTION:Resource Management testing cgroup_core01 cgroup_core01 cgroup_core02 cgroup_core02 +cgroup_core03 cgroup_core03 cgroup cgroup_regression_test.sh memcg_regression memcg_regression_test.sh memcg_test_3 memcg_test_3(quoted diff) +0
-0b/testcases/kernel/controllers/cgroup/.gitignore
Review
Quoted 9 lines
index
8deae77da..9f1d1ada9100644testcases/kernel/controllers/cgroup/.gitignore +1
-0@@ -2,3 +2,4 @@ /cgroup_regression_getdelays /cgroup_core01 /cgroup_core02 +/cgroup_core03(quoted diff) +0
-0
b/testcases/kernel/controllers/cgroup/cgroup_core03.cQuoted 7 lines
new file mode 100644
index 000000000..2a6941c44testcases/kernel/controllers/cgroup/cgroup_core03.c new file +2
-0@@ -0,0 +1,144 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* testcases/kernel/controllers/cgroup/cgroup_core03.c line 12
Quoted 10 lines
testcases/kernel/controllers/cgroup/cgroup_core03.c new file +10
-0+* Copyright (c) 2012 Christian Brauner <brauner-AT-kernel.org> +* Copyright (c) 2023 SUSE LLC <[email protected]> +*/ + +/*\ +* [Description] +* +* This test is copied from kselftest +* tools/testing/selftests/cgroup/test_kill.c +* Only simple test implemented within current case, the other cases such
Quoted 37 lines
testcases/kernel/controllers/cgroup/cgroup_core03.c new file +37
-0+* as test_cgkill_tree and test_cgkill_forkbomb can be created later. +* +*/ + +#include <sys/wait.h> + +#include "lapi/syscalls.h" +#include "tst_test.h" + +#define MAX_PID_NUM 100 +#define PID_NUM MIN(MAX_PID_NUM, (tst_ncpus_available() + 1)) +#define BUF_LEN (20 * PID_NUM) + +static int *data_ptr; +static char *buf; +static struct tst_cg_group *cg_child_test_simple; + +static int wait_for_pid (pid_t pid) +{ +int status, ret; + +again: + ret =waitpid (pid, &status,0 ); +if (ret ==-1 ) { +if (errno ==EINTR ) + goto again; + +return -1 ; + } + +if (WIFSIGNALED (status)) +return 0 ; + +return -1 ; +} + +/* testcases/kernel/controllers/cgroup/cgroup_core03.c line 59
Quoted 10 lines
testcases/kernel/controllers/cgroup/cgroup_core03.c new file +10
-0+* A simple process running in a sleep loop until being +* re-parented. +*/ +static void child_fn (void ) +{ +int ppid =getppid (); + +while (getppid () == ppid) +usleep (1000 ); +What's the reason we are waiting for reparenting here? Aren't these processes killed anyways? I suppose that we can just call
pause()here instead.testcases/kernel/controllers/cgroup/cgroup_core03.c line 72
Quoted 13 lines
testcases/kernel/controllers/cgroup/cgroup_core03.c new file +13
-0+} + +static int cg_run_nowait (const struct tst_cg_group *const cg, +void (*fn)(void )) +{ +int pid; + + pid =SAFE_FORK (); +if (pid ==0 ) { +SAFE_CG_PRINTF (cg,"cgroup.procs" ,"%d" ,getpid ()); +tst_atomic_inc (data_ptr); +if (tst_atomic_load (data_ptr) ==PID_NUM ) +TST_CHECKPOINT_WAKE (0 );I do not think that this is 100% correct, as it is we may end up calling the
TST_CHECKOPOINT_WAKE(0)more than once here, since there is a race between increment and load. An if that happens only one of the calls toTST_CHECKPOINT_WAKE(0)will succeeds, while the rest would fail and break the test.First of all the
tst_atomic_inc()returns the value after the increment, so that we can actually get the counter value without a race.Secondly I think that we can get rid of the atomic operations completely, we just have to loop N times over the
TST_CHECKPOINT_WAIT()in therun()function and callTST_CHECKPOINT_WAKE()in each child instance. We can also addTST_CHECKPOINT_WAIT_NR()to the test library that would also take a number of wait calls passed as a parameter.testcases/kernel/controllers/cgroup/cgroup_core03.c
Quoted 7 lines
testcases/kernel/controllers/cgroup/cgroup_core03.c new file +7
-0+fn (); + } + +return pid; +} + +static int cg_wait_for_proc_count(const struct tst_cg_group *cg, intcount)
The function does not wait for anything, so it should be called
cg_count_procs()or similar.Quoted 25 lines
testcases/kernel/controllers/cgroup/cgroup_core03.c new file +25
-0+{ +char *ptr; + +int nr =0 ; + +SAFE_CG_READ (cg,"cgroup.procs" , buf,BUF_LEN ); + +for (ptr = buf; *ptr; ptr++) +if (*ptr =='\n' ) + nr++; + +if (nr >= count) +return 0 ; + +tst_res (TINFO ,"Expect process num is %d but get %d" , count, nr); + +return -1 ; +} + +static void run (void ) +{ +pid_t pids[MAX_PID_NUM ]; +int i; + *data_ptr =0 ; +testcases/kernel/controllers/cgroup/cgroup_core03.c
Quoted 10 lines
testcases/kernel/controllers/cgroup/cgroup_core03.c new file +10
-0+ cg_child_test_simple =tst_cg_group_mk (tst_cg,"cg_test_simple" ); + +memset (buf,0 ,BUF_LEN ); + +for (i =0 ; i <PID_NUM ; i++) + pids[i] =cg_run_nowait (cg_child_test_simple, child_fn); + +TST_CHECKPOINT_WAIT (0 ); + + TST_EXP_PASS(cg_wait_for_proc_count(cg_child_test_simple,
PID_NUM));This is very minor, but I would make the function return the number of pids found in the cgroup and called it as:
TST_EXP_VAL(cg_count_procs(cg_child_test_simple), pid_num);testcases/kernel/controllers/cgroup/cgroup_core03.c line 117
Quoted 4 lines
testcases/kernel/controllers/cgroup/cgroup_core03.c new file +4
-0+SAFE_CG_PRINTF (cg_child_test_simple,"cgroup.kill" ,"%d" ,1 ); + +for (i =0 ; i <PID_NUM ; i++) +TST_EXP_PASS_SILENT (wait_for_pid (pids[i]));Then we can do here:
TST_EXP_VAL(cg_count_procs(cg_child_test_simple), 0);testcases/kernel/controllers/cgroup/cgroup_core03.c
Quoted 7 lines
testcases/kernel/controllers/cgroup/cgroup_core03.c new file +7
-0+ cg_child_test_simple =tst_cg_group_rm (cg_child_test_simple); +} + +static void setup (void ) +{ + buf =tst_alloc (BUF_LEN ); + data_ptr = SAFE_MMAP(NULL, sizeof(uintptr_t), PROT_READ |
PROT_WRITE,testcases/kernel/controllers/cgroup/cgroup_core03.c line 126
Quoted 1 line
testcases/kernel/controllers/cgroup/cgroup_core03.c new file +1
-0+ MAP_SHARED |
MAP_ANONYMOUS, -1, 0);Quoted 22 lines
testcases/kernel/controllers/cgroup/cgroup_core03.c new file +18
-1+} + +static void cleanup (void ) +{ +if (data_ptr) +SAFE_MUNMAP (data_ptr,sizeof (uintptr_t )); +} + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .cleanup = cleanup, + .forks_child =1 , + .max_runtime =20 , + .needs_cgroup_ctrls = (const char *const []){"pseudo" ,NULL }, + .needs_cgroup_ver =TST_CG_V2 , + .needs_checkpoints =1 , +}; --2.35.3
Quoted 2 lines
--
Mailing list info: https://lists.linux.it/listinfo/ltp--
Cyril Hrubis
[email protected]--
Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 2 lines
Please remove me from your mailing list. I’m not from your team. Why are you sending all this to me. Just remove me from your list.
I'm a bit confused here, you apparenlty subscribed yourself to this mailing list and then you are complaining that you are getting emails?
Moreover if you have subscribed yourself you should be able to unsubscribe as well. No need to spam the mailing list with such requests.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v9 2/2 tst_cgroup.c: Add a cgroup pseudo controller
In reply to Wei Gao via ltpFor new test case such as kill01.c no need specific controller, it just need LTP cgroup library start work, so we need add a "cgroup" pseudo controller.
--- lib/tst_cgroup.c | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-)
lib/tst_cgroup.c +32 -15
@@ -94,9 +94,10 @@ enum cgroup_ctrl_indx {CTRL_MISC ,CTRL_PERFEVENT ,CTRL_DEBUG , - CTRL_RDMA +CTRL_RDMA , + CTRL_PSEUDO }; -#define CTRLS_MAX CTRL_RDMA +#define CTRLS_MAX CTRL_PSEUDO/* At most we can have one cgroup V1 tree for each controller and one * (empty) v2 tree.
@@ -259,6 +260,10 @@ static const struct cgroup_file rdma_ctrl_files[] = { { } }; +static const struct cgroup_file pseudo_ctrl_files[] = { + { } +}; +#define CTRL_NAME_MAX 31#define CGROUP_CTRL_MEMBER (x, y)[y] = { .ctrl_name = #x, .files = \ x ## _ctrl_files, .ctrl_indx = y, NULL, 0 }
@@ -282,6 +287,7 @@ static struct cgroup_ctrl controllers[] = {CGROUP_CTRL_MEMBER (perf_event,CTRL_PERFEVENT ),CGROUP_CTRL_MEMBER (debug,CTRL_DEBUG ),CGROUP_CTRL_MEMBER (rdma,CTRL_RDMA ), + CGROUP_CTRL_MEMBER(pseudo, CTRL_PSEUDO), { } };
@@ -798,6 +804,10 @@ void tst_cg_require(const char *const ctrl_name,const char *const cgsc ="cgroup.subtree_control" ;struct cgroup_ctrl *const ctrl =cgroup_find_ctrl (ctrl_name);struct cgroup_root *root; +int pseudo = !strcmp (ctrl->ctrl_name,"pseudo" ); + +if (pseudo && options->needs_ver !=TST_CG_V2 ) +tst_brk (TCONF ,"pseudo control only support needs_ver TST_CG_V2!" );if (!ctrl) {tst_brk (TBROK ,"'%s' controller is unknown to LTP" , ctrl_name);
@@ -827,6 +837,9 @@ void tst_cg_require(const char *const ctrl_name,if (options->needs_ver !=TST_CG_V2 )cgroup_mount_v1 (ctrl); +if (pseudo) + ctrl->ctrl_root = roots; +if (!ctrl->ctrl_root) { tst_brk(TCONF, "'%s' controller required, but not available",
@@ -849,13 +862,13 @@ mkdirs: ctrl->ctrl_name); } -if (cgroup_ctrl_on_v2 (ctrl)) { +if (cgroup_ctrl_on_v2 (ctrl) && !pseudo) {if (root->we_mounted_it) {SAFE_FILE_PRINTFAT (root->mnt_dir.dir_fd, - cgsc,"+%s" , ctrl->ctrl_name); + cgsc,"+%s" , ctrl->ctrl_name); }else {tst_file_printfat (root->mnt_dir.dir_fd, - cgsc,"+%s" , ctrl->ctrl_name); + cgsc,"+%s" , ctrl->ctrl_name); } }
@@ -864,15 +877,17 @@ mkdirs:else root->ltp_dir.ctrl_field |= root->mnt_dir.ctrl_field; -if (cgroup_ctrl_on_v2 (ctrl)) { -SAFE_FILE_PRINTFAT (root->ltp_dir.dir_fd, - cgsc,"+%s" , ctrl->ctrl_name); - }else { -SAFE_FILE_PRINTFAT (root->ltp_dir.dir_fd, -"cgroup.clone_children" ,"%d" ,1 ); +if (!pseudo) { +if (cgroup_ctrl_on_v2 (ctrl)) { +SAFE_FILE_PRINTFAT (root->ltp_dir.dir_fd, + cgsc,"+%s" , ctrl->ctrl_name); + }else { +SAFE_FILE_PRINTFAT (root->ltp_dir.dir_fd, +"cgroup.clone_children" ,"%d" ,1 ); -if (ctrl->ctrl_indx ==CTRL_CPUSET ) -cgroup_copy_cpuset (root); +if (ctrl->ctrl_indx ==CTRL_CPUSET ) +cgroup_copy_cpuset (root); + } }cgroup_dir_mk (&root->ltp_dir, cgroup_ltp_drain_dir, &root->drain_dir);
@@ -1050,8 +1065,10 @@ static void cgroup_group_add_dir(const struct tst_cg_group *const parent,if (!parent || dir->dir_root->ver ==TST_CG_V1 )continue ; -SAFE_CG_PRINTF (parent,"cgroup.subtree_control" , -"+%s" , ctrl->ctrl_name); +if (strcmp (ctrl->ctrl_name,"pseudo" )) { +SAFE_CG_PRINTF (parent,"cgroup.subtree_control" , +"+%s" , ctrl->ctrl_name); + } }for (i =0 ; cg->dirs[i]; i++)
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v9 2/2] tst_cgroup.c: Add a cgroup pseudo controller
Hi Wei,
Quoted 14 lines · Wei Gao via ltp
For new test case such as
kill01.cno need specific controller, it just need LTP cgroup library start work, so we need add a "cgroup" pseudo controller.Signed-off-by Wei Gao <[email protected]>--- lib/tst_cgroup.c | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-)lib/tst_cgroup.c +0
-0
lib/tst_cgroup.c enum cgroup_ctrl_indx { · line 101
Quoted 10 lines
lib/tst_cgroup.c +3
-2@@ -94,9 +94,10 @@ enum cgroup_ctrl_indx {CTRL_MISC ,CTRL_PERFEVENT ,CTRL_DEBUG , - CTRL_RDMA +CTRL_RDMA , + CTRL_PSEUDO }; -#define CTRLS_MAX CTRL_RDMA +#define CTRLS_MAX CTRL_PSEUDO
I vote for considering use of 'CTRL_BASE' (suggested by Cryil), because here we indeed use the basic functionality of CgroupV
but not a pseudo controller.
Otherwise, the rest looks good to me.
=======================
@Cryil, @Richard
Apart from that, there is another problem with the test logic of this library, that it potentially mixed Cgroup V1 and V2 together to be mounted at the same time. The scenario happens once someone just requests CTRL_BASE
(or controllers not mounted) on a V1-mounted system.
Upstream always objected to enabling Cgroup like that, which brings many unexpected issue during the test.
So I would strongly suggest avoiding LTP mount V1&V2 even if there is no overlap in controllers.
Which should be achieved in a separate patch:
(document should be updated as well)
lib/tst_cgroup.c +3 -2
@@ -828,13 +828,14 @@ void tst_cg_require(const char *const ctrl_name,if (ctrl->ctrl_root) goto mkdirs; -if (!cgroup_v2_mounted () && options->needs_ver !=TST_CG_V1 ) +if (!cgroup_v2_mounted () && options->needs_ver !=TST_CG_V1 + && !cgroup_v1_mounted ())cgroup_mount_v2 ();if (ctrl->ctrl_root) goto mkdirs; -if (options->needs_ver !=TST_CG_V2 ) +if (options->needs_ver !=TST_CG_V2 && !cgroup_v2_mounted ())cgroup_mount_v1 (ctrl);if (pseudo)
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v9 2/2] tst_cgroup.c: Add a cgroup pseudo controller
In reply to Wei Gao via ltpHi!
Quoted 3 lines
For new test case such as
kill01.cno need specific controller, it just need LTP cgroup library start work, so we need add a "cgroup" pseudo controller.
Can we please call it "base" controller? Or something better fitting?
Quoted 124 lines
Signed-off-by Wei Gao <[email protected]>--- lib/tst_cgroup.c | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-)lib/tst_cgroup.c +32
-15@@ -94,9 +94,10 @@ enum cgroup_ctrl_indx {CTRL_MISC ,CTRL_PERFEVENT ,CTRL_DEBUG , - CTRL_RDMA +CTRL_RDMA , + CTRL_PSEUDO }; -#define CTRLS_MAX CTRL_RDMA +#define CTRLS_MAX CTRL_PSEUDO/* At most we can have one cgroup V1 tree for each controller and one * (empty) v2 tree. @@ -259,6 +260,10 @@ static const struct cgroup_file rdma_ctrl_files[] = { { } }; +static const struct cgroup_file pseudo_ctrl_files[] = { + { } +}; +#define CTRL_NAME_MAX 31#define CGROUP_CTRL_MEMBER (x, y)[y] = { .ctrl_name = #x, .files = \ x ## _ctrl_files, .ctrl_indx = y, NULL, 0 }@@ -282,6 +287,7 @@ static struct cgroup_ctrl controllers[] = {CGROUP_CTRL_MEMBER (perf_event,CTRL_PERFEVENT ),CGROUP_CTRL_MEMBER (debug,CTRL_DEBUG ),CGROUP_CTRL_MEMBER (rdma,CTRL_RDMA ), + CGROUP_CTRL_MEMBER(pseudo, CTRL_PSEUDO), { } };@@ -798,6 +804,10 @@ void tst_cg_require(const char *const ctrl_name,const char *const cgsc ="cgroup.subtree_control" ;struct cgroup_ctrl *const ctrl =cgroup_find_ctrl (ctrl_name);struct cgroup_root *root; +int pseudo = !strcmp (ctrl->ctrl_name,"pseudo" ); + +if (pseudo && options->needs_ver !=TST_CG_V2 ) +tst_brk (TCONF ,"pseudo control only support needs_ver TST_CG_V2!" );if (!ctrl) {tst_brk (TBROK ,"'%s' controller is unknown to LTP" , ctrl_name);@@ -827,6 +837,9 @@ void tst_cg_require(const char *const ctrl_name,if (options->needs_ver !=TST_CG_V2 )cgroup_mount_v1 (ctrl); +if (pseudo) + ctrl->ctrl_root = roots; +if (!ctrl->ctrl_root) { tst_brk(TCONF, "'%s' controller required, but not available",@@ -849,13 +862,13 @@ mkdirs: ctrl->ctrl_name); } -if (cgroup_ctrl_on_v2 (ctrl)) { +if (cgroup_ctrl_on_v2 (ctrl) && !pseudo) {if (root->we_mounted_it) {SAFE_FILE_PRINTFAT (root->mnt_dir.dir_fd, - cgsc,"+%s" , ctrl->ctrl_name); + cgsc,"+%s" , ctrl->ctrl_name); }else {tst_file_printfat (root->mnt_dir.dir_fd, - cgsc,"+%s" , ctrl->ctrl_name); + cgsc,"+%s" , ctrl->ctrl_name); } }@@ -864,15 +877,17 @@ mkdirs:else root->ltp_dir.ctrl_field |= root->mnt_dir.ctrl_field; -if (cgroup_ctrl_on_v2 (ctrl)) { -SAFE_FILE_PRINTFAT (root->ltp_dir.dir_fd, - cgsc,"+%s" , ctrl->ctrl_name); - }else { -SAFE_FILE_PRINTFAT (root->ltp_dir.dir_fd, -"cgroup.clone_children" ,"%d" ,1 ); +if (!pseudo) { +if (cgroup_ctrl_on_v2 (ctrl)) { +SAFE_FILE_PRINTFAT (root->ltp_dir.dir_fd, + cgsc,"+%s" , ctrl->ctrl_name); + }else { +SAFE_FILE_PRINTFAT (root->ltp_dir.dir_fd, +"cgroup.clone_children" ,"%d" ,1 ); -if (ctrl->ctrl_indx ==CTRL_CPUSET ) -cgroup_copy_cpuset (root); +if (ctrl->ctrl_indx ==CTRL_CPUSET ) +cgroup_copy_cpuset (root); + } }cgroup_dir_mk (&root->ltp_dir, cgroup_ltp_drain_dir, &root->drain_dir);@@ -1050,8 +1065,10 @@ static void cgroup_group_add_dir(const struct tst_cg_group *const parent,if (!parent || dir->dir_root->ver ==TST_CG_V1 )continue ; -SAFE_CG_PRINTF (parent,"cgroup.subtree_control" , -"+%s" , ctrl->ctrl_name); +if (strcmp (ctrl->ctrl_name,"pseudo" )) { +SAFE_CG_PRINTF (parent,"cgroup.subtree_control" , +"+%s" , ctrl->ctrl_name); + } }for (i =0 ; cg->dirs[i]; i++)Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
v10 cover kill01: New case cgroup kill
In reply to Wei Gao via ltpWei Gao (2):
kill01: New case cgroup kill
tst_cgroup.c: Add a cgroup base controller
lib/tst_cgroup.c | 48 ++++--- runtest/controllers | 1 + .../kernel/controllers/cgroup/.gitignore | 1 + .../kernel/controllers/cgroup/cgroup_core03.c | 125 ++++++++++++++++++ 4 files changed, 160 insertions(+), 15 deletions(-) create mode 100644 testcases/kernel/controllers/cgroup/cgroup_core03.c
base-commit: b67facdd9c3f0ef471d74dd59ac276139e63f4c4
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v10 1/2 kill01: New case cgroup kill
--- lib/tst_cgroup.c | 1 + runtest/controllers | 1 + .../kernel/controllers/cgroup/.gitignore | 1 + .../kernel/controllers/cgroup/cgroup_core03.c | 125 ++++++++++++++++++ 4 files changed, 128 insertions(+) create mode 100644 testcases/kernel/controllers/cgroup/cgroup_core03.c
lib/tst_cgroup.c +1 -0
@@ -166,6 +166,7 @@ static const struct cgroup_file cgroup_ctrl_files[] = { { "cgroup.controllers", NULL, 0 }, { "cgroup.subtree_control", NULL, 0 }, { "cgroup.clone_children", "cgroup.clone_children", 0 }, + { "cgroup.kill", NULL, 0 }, { } };
runtest/controllers +1 -0
@@ -1,6 +1,7 @@ #DESCRIPTION:Resource Management testing cgroup_core01 cgroup_core01 cgroup_core02 cgroup_core02 +cgroup_core03 cgroup_core03 cgroup cgroup_regression_test.sh memcg_regression memcg_regression_test.sh memcg_test_3 memcg_test_3
testcases/kernel/controllers/cgroup/.gitignore +1 -0
@@ -2,3 +2,4 @@ /cgroup_regression_getdelays /cgroup_core01 /cgroup_core02 +/cgroup_core03
testcases/kernel/controllers/cgroup/cgroup_core03.c new file +125 -0
125 lines not on this page · raw message
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Wei,
this commit should be second, after "tst_cgroup.c: Add a cgroup base controller". Because it depends on it. With the current (wrong) order, it compiles, but it fails in runtime:
$ ./cgroup_core03 tst_cgroup.c:803: TBROK: 'base' controller is unknown to LTP
We try to have each commit "working": 1) possible to compile
2) test actually working. This is needed when we try to search for error with git bisect.
You can mention in "tst_cgroup.c: Add a cgroup base controller", that it will be needed in the test added in following commit.
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v10 2/2 tst_cgroup.c: Add a cgroup base controller
In reply to Wei Gao via ltpFor new test case such as kill01.c no need specific controller, it just need LTP cgroup library start work, so we need add a "cgroup" base controller.
--- lib/tst_cgroup.c | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-)
lib/tst_cgroup.c +32 -15
@@ -94,9 +94,10 @@ enum cgroup_ctrl_indx {CTRL_MISC ,CTRL_PERFEVENT ,CTRL_DEBUG , - CTRL_RDMA +CTRL_RDMA , + CTRL_BASE }; -#define CTRLS_MAX CTRL_RDMA +#define CTRLS_MAX CTRL_BASE/* At most we can have one cgroup V1 tree for each controller and one * (empty) v2 tree.
@@ -259,6 +260,10 @@ static const struct cgroup_file rdma_ctrl_files[] = { { } }; +static const struct cgroup_file base_ctrl_files[] = { + { } +}; +#define CTRL_NAME_MAX 31#define CGROUP_CTRL_MEMBER (x, y)[y] = { .ctrl_name = #x, .files = \ x ## _ctrl_files, .ctrl_indx = y, NULL, 0 }
@@ -282,6 +287,7 @@ static struct cgroup_ctrl controllers[] = {CGROUP_CTRL_MEMBER (perf_event,CTRL_PERFEVENT ),CGROUP_CTRL_MEMBER (debug,CTRL_DEBUG ),CGROUP_CTRL_MEMBER (rdma,CTRL_RDMA ), + CGROUP_CTRL_MEMBER(base, CTRL_BASE), { } };
@@ -798,6 +804,10 @@ void tst_cg_require(const char *const ctrl_name,const char *const cgsc ="cgroup.subtree_control" ;struct cgroup_ctrl *const ctrl =cgroup_find_ctrl (ctrl_name);struct cgroup_root *root; +int base = !strcmp (ctrl->ctrl_name,"base" ); + +if (base && options->needs_ver !=TST_CG_V2 ) +tst_brk (TCONF ,"Base control only support needs_ver TST_CG_V2!" );if (!ctrl) {tst_brk (TBROK ,"'%s' controller is unknown to LTP" , ctrl_name);
@@ -827,6 +837,9 @@ void tst_cg_require(const char *const ctrl_name,if (options->needs_ver !=TST_CG_V2 )cgroup_mount_v1 (ctrl); +if (base) + ctrl->ctrl_root = roots; +if (!ctrl->ctrl_root) { tst_brk(TCONF, "'%s' controller required, but not available",
@@ -849,13 +862,13 @@ mkdirs: ctrl->ctrl_name); } -if (cgroup_ctrl_on_v2 (ctrl)) { +if (cgroup_ctrl_on_v2 (ctrl) && !base) {if (root->we_mounted_it) {SAFE_FILE_PRINTFAT (root->mnt_dir.dir_fd, - cgsc,"+%s" , ctrl->ctrl_name); + cgsc,"+%s" , ctrl->ctrl_name); }else {tst_file_printfat (root->mnt_dir.dir_fd, - cgsc,"+%s" , ctrl->ctrl_name); + cgsc,"+%s" , ctrl->ctrl_name); } }
@@ -864,15 +877,17 @@ mkdirs:else root->ltp_dir.ctrl_field |= root->mnt_dir.ctrl_field; -if (cgroup_ctrl_on_v2 (ctrl)) { -SAFE_FILE_PRINTFAT (root->ltp_dir.dir_fd, - cgsc,"+%s" , ctrl->ctrl_name); - }else { -SAFE_FILE_PRINTFAT (root->ltp_dir.dir_fd, -"cgroup.clone_children" ,"%d" ,1 ); +if (!base) { +if (cgroup_ctrl_on_v2 (ctrl)) { +SAFE_FILE_PRINTFAT (root->ltp_dir.dir_fd, + cgsc,"+%s" , ctrl->ctrl_name); + }else { +SAFE_FILE_PRINTFAT (root->ltp_dir.dir_fd, +"cgroup.clone_children" ,"%d" ,1 ); -if (ctrl->ctrl_indx ==CTRL_CPUSET ) -cgroup_copy_cpuset (root); +if (ctrl->ctrl_indx ==CTRL_CPUSET ) +cgroup_copy_cpuset (root); + } }cgroup_dir_mk (&root->ltp_dir, cgroup_ltp_drain_dir, &root->drain_dir);
@@ -1050,8 +1065,10 @@ static void cgroup_group_add_dir(const struct tst_cg_group *const parent,if (!parent || dir->dir_root->ver ==TST_CG_V1 )continue ; -SAFE_CG_PRINTF (parent,"cgroup.subtree_control" , -"+%s" , ctrl->ctrl_name); +if (strcmp (ctrl->ctrl_name,"base" )) { +SAFE_CG_PRINTF (parent,"cgroup.subtree_control" , +"+%s" , ctrl->ctrl_name); + } }for (i =0 ; cg->dirs[i]; i++)
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v10 2/2] tst_cgroup.c: Add a cgroup base controller
Hi Wei,
Quoted 1 line
lib/tst_cgroup.c | 47 ++++++++++++++++++++++++++++++++---------------
...
Quoted 22 lines
lib/tst_cgroup.c +7
-0@@ -798,6 +804,10 @@ void tst_cg_require(const char *const ctrl_name,const char *const cgsc ="cgroup.subtree_control" ;struct cgroup_ctrl *const ctrl =cgroup_find_ctrl (ctrl_name);struct cgroup_root *root; +int base = !strcmp (ctrl->ctrl_name,"base" ); + +if (base && options->needs_ver !=TST_CG_V2 ) +tst_brk (TCONF ,"Base control only support needs_ver TST_CG_V2!" );if (!ctrl) {tst_brk (TBROK ,"'%s' controller is unknown to LTP" , ctrl_name);@@ -827,6 +837,9 @@ void tst_cg_require(const char *const ctrl_name,if (options->needs_ver !=TST_CG_V2 )cgroup_mount_v1 (ctrl); +if (base) + ctrl->ctrl_root = roots; +if (!ctrl->ctrl_root) { tst_brk(TCONF, "'%s' controller required, but not available",
lib/tst_cgroup.c mkdirs: · line 868
Quoted 9 lines
lib/tst_cgroup.c +2
-2@@ -849,13 +862,13 @@ mkdirs: ctrl->ctrl_name); } -if (cgroup_ctrl_on_v2 (ctrl)) { +if (cgroup_ctrl_on_v2 (ctrl) && !base) {if (root->we_mounted_it) {SAFE_FILE_PRINTFAT (root->mnt_dir.dir_fd, - cgsc,"+%s" , ctrl->ctrl_name); + cgsc,"+%s" , ctrl->ctrl_name);
This is just unneeded whitespace change, it should be reverted. I guess you changed it just by accident, right?
lib/tst_cgroup.c mkdirs: · line 871
Quoted 4 lines
lib/tst_cgroup.c +1
-1}else {tst_file_printfat (root->mnt_dir.dir_fd, - cgsc,"+%s" , ctrl->ctrl_name); + cgsc,"+%s" , ctrl->ctrl_name);
Here as well.
Kind regards,
Petr
Quoted 2 lines
(quoted diff) +0
-0} }
...
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
v11 cover New case test cgroup kill feature
In reply to Wei Gao via ltpWei Gao (2):
tst_cgroup.c: Add a cgroup base controller cgroup_core03.c: New case test cgroup kill feature
lib/tst_cgroup.c | 44 ++++-- runtest/controllers | 1 + .../kernel/controllers/cgroup/.gitignore | 1 + .../kernel/controllers/cgroup/cgroup_core03.c | 125 ++++++++++++++++++ 4 files changed, 158 insertions(+), 13 deletions(-) create mode 100644 testcases/kernel/controllers/cgroup/cgroup_core03.c
base-commit: b67facdd9c3f0ef471d74dd59ac276139e63f4c4
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v11 1/2 tst_cgroup.c: Add a cgroup base controller
For new test case such as kill01.c no need specific controller, it just need LTP cgroup library start work, so we need add a "cgroup" base controller.
--- lib/tst_cgroup.c | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-)
lib/tst_cgroup.c +30 -13
@@ -94,9 +94,10 @@ enum cgroup_ctrl_indx {CTRL_MISC ,CTRL_PERFEVENT ,CTRL_DEBUG , - CTRL_RDMA +CTRL_RDMA , + CTRL_BASE }; -#define CTRLS_MAX CTRL_RDMA +#define CTRLS_MAX CTRL_BASE/* At most we can have one cgroup V1 tree for each controller and one * (empty) v2 tree.
@@ -258,6 +259,10 @@ static const struct cgroup_file rdma_ctrl_files[] = { { } }; +static const struct cgroup_file base_ctrl_files[] = { + { } +}; +#define CTRL_NAME_MAX 31#define CGROUP_CTRL_MEMBER (x, y)[y] = { .ctrl_name = #x, .files = \ x ## _ctrl_files, .ctrl_indx = y, NULL, 0 }
@@ -281,6 +286,7 @@ static struct cgroup_ctrl controllers[] = {CGROUP_CTRL_MEMBER (perf_event,CTRL_PERFEVENT ),CGROUP_CTRL_MEMBER (debug,CTRL_DEBUG ),CGROUP_CTRL_MEMBER (rdma,CTRL_RDMA ), + CGROUP_CTRL_MEMBER(base, CTRL_BASE), { } };
@@ -797,6 +803,10 @@ void tst_cg_require(const char *const ctrl_name,const char *const cgsc ="cgroup.subtree_control" ;struct cgroup_ctrl *const ctrl =cgroup_find_ctrl (ctrl_name);struct cgroup_root *root; +int base = !strcmp (ctrl->ctrl_name,"base" ); + +if (base && options->needs_ver !=TST_CG_V2 ) +tst_brk (TCONF ,"Base control only support needs_ver TST_CG_V2!" );if (!ctrl) {tst_brk (TBROK ,"'%s' controller is unknown to LTP" , ctrl_name);
@@ -826,6 +836,9 @@ void tst_cg_require(const char *const ctrl_name,if (options->needs_ver !=TST_CG_V2 )cgroup_mount_v1 (ctrl); +if (base) + ctrl->ctrl_root = roots; +if (!ctrl->ctrl_root) { tst_brk(TCONF, "'%s' controller required, but not available",
@@ -848,7 +861,7 @@ mkdirs: ctrl->ctrl_name); } -if (cgroup_ctrl_on_v2 (ctrl)) { +if (cgroup_ctrl_on_v2 (ctrl) && !base) {if (root->we_mounted_it) {SAFE_FILE_PRINTFAT (root->mnt_dir.dir_fd, cgsc,"+%s" , ctrl->ctrl_name);
@@ -863,15 +876,17 @@ mkdirs:else root->ltp_dir.ctrl_field |= root->mnt_dir.ctrl_field; -if (cgroup_ctrl_on_v2 (ctrl)) { -SAFE_FILE_PRINTFAT (root->ltp_dir.dir_fd, - cgsc,"+%s" , ctrl->ctrl_name); - }else { -SAFE_FILE_PRINTFAT (root->ltp_dir.dir_fd, -"cgroup.clone_children" ,"%d" ,1 ); +if (!base) { +if (cgroup_ctrl_on_v2 (ctrl)) { +SAFE_FILE_PRINTFAT (root->ltp_dir.dir_fd, + cgsc,"+%s" , ctrl->ctrl_name); + }else { +SAFE_FILE_PRINTFAT (root->ltp_dir.dir_fd, +"cgroup.clone_children" ,"%d" ,1 ); -if (ctrl->ctrl_indx ==CTRL_CPUSET ) -cgroup_copy_cpuset (root); +if (ctrl->ctrl_indx ==CTRL_CPUSET ) +cgroup_copy_cpuset (root); + } }cgroup_dir_mk (&root->ltp_dir, cgroup_ltp_drain_dir, &root->drain_dir);
@@ -1049,8 +1064,10 @@ static void cgroup_group_add_dir(const struct tst_cg_group *const parent,if (!parent || dir->dir_root->ver ==TST_CG_V1 )continue ; -SAFE_CG_PRINTF (parent,"cgroup.subtree_control" , -"+%s" , ctrl->ctrl_name); +if (strcmp (ctrl->ctrl_name,"base" )) { +SAFE_CG_PRINTF (parent,"cgroup.subtree_control" , +"+%s" , ctrl->ctrl_name); + } }for (i =0 ; cg->dirs[i]; i++)
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v11 2/2 cgroup_core03.c: New case test cgroup kill feature
In reply to Wei Gao via ltp--- lib/tst_cgroup.c | 1 + runtest/controllers | 1 + .../kernel/controllers/cgroup/.gitignore | 1 + .../kernel/controllers/cgroup/cgroup_core03.c | 125 ++++++++++++++++++ 4 files changed, 128 insertions(+) create mode 100644 testcases/kernel/controllers/cgroup/cgroup_core03.c
lib/tst_cgroup.c +1 -0
@@ -167,6 +167,7 @@ static const struct cgroup_file cgroup_ctrl_files[] = { { "cgroup.controllers", NULL, 0 }, { "cgroup.subtree_control", NULL, 0 }, { "cgroup.clone_children", "cgroup.clone_children", 0 }, + { "cgroup.kill", NULL, 0 }, { } };
runtest/controllers +1 -0
@@ -1,6 +1,7 @@ #DESCRIPTION:Resource Management testing cgroup_core01 cgroup_core01 cgroup_core02 cgroup_core02 +cgroup_core03 cgroup_core03 cgroup cgroup_regression_test.sh memcg_regression memcg_regression_test.sh memcg_test_3 memcg_test_3
testcases/kernel/controllers/cgroup/.gitignore +1 -0
@@ -2,3 +2,4 @@ /cgroup_regression_getdelays /cgroup_core01 /cgroup_core02 +/cgroup_core03
testcases/kernel/controllers/cgroup/cgroup_core03.c new file +125 -0
125 lines not on this page · raw message
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
v12 cover cgroup_core03.c: New case test cgroup kill feature
In reply to Wei Gao via ltpWei Gao (2):
tst_cgroup.c: Add a cgroup base controller cgroup_core03.c: New case test cgroup kill feature
lib/tst_cgroup.c | 44 ++++-- runtest/controllers | 1 + .../kernel/controllers/cgroup/.gitignore | 1 + .../kernel/controllers/cgroup/cgroup_core03.c | 130 ++++++++++++++++++ 4 files changed, 163 insertions(+), 13 deletions(-) create mode 100644 testcases/kernel/controllers/cgroup/cgroup_core03.c
base-commit: b67facdd9c3f0ef471d74dd59ac276139e63f4c4
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v12 1/2 tst_cgroup.c: Add a cgroup base controller
For new test case such as kill01.c no need specific controller, it just need LTP cgroup library start work, so we need add a "cgroup" base controller.
--- lib/tst_cgroup.c | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-)
lib/tst_cgroup.c +30 -13
@@ -94,9 +94,10 @@ enum cgroup_ctrl_indx {CTRL_MISC ,CTRL_PERFEVENT ,CTRL_DEBUG , - CTRL_RDMA +CTRL_RDMA , + CTRL_BASE }; -#define CTRLS_MAX CTRL_RDMA +#define CTRLS_MAX CTRL_BASE/* At most we can have one cgroup V1 tree for each controller and one * (empty) v2 tree.
@@ -258,6 +259,10 @@ static const struct cgroup_file rdma_ctrl_files[] = { { } }; +static const struct cgroup_file base_ctrl_files[] = { + { } +}; +#define CTRL_NAME_MAX 31#define CGROUP_CTRL_MEMBER (x, y)[y] = { .ctrl_name = #x, .files = \ x ## _ctrl_files, .ctrl_indx = y, NULL, 0 }
@@ -281,6 +286,7 @@ static struct cgroup_ctrl controllers[] = {CGROUP_CTRL_MEMBER (perf_event,CTRL_PERFEVENT ),CGROUP_CTRL_MEMBER (debug,CTRL_DEBUG ),CGROUP_CTRL_MEMBER (rdma,CTRL_RDMA ), + CGROUP_CTRL_MEMBER(base, CTRL_BASE), { } };
@@ -797,6 +803,10 @@ void tst_cg_require(const char *const ctrl_name,const char *const cgsc ="cgroup.subtree_control" ;struct cgroup_ctrl *const ctrl =cgroup_find_ctrl (ctrl_name);struct cgroup_root *root; +int base = !strcmp (ctrl->ctrl_name,"base" ); + +if (base && options->needs_ver !=TST_CG_V2 ) +tst_brk (TCONF ,"Base control only support needs_ver TST_CG_V2!" );if (!ctrl) {tst_brk (TBROK ,"'%s' controller is unknown to LTP" , ctrl_name);
@@ -826,6 +836,9 @@ void tst_cg_require(const char *const ctrl_name,if (options->needs_ver !=TST_CG_V2 )cgroup_mount_v1 (ctrl); +if (base) + ctrl->ctrl_root = roots; +if (!ctrl->ctrl_root) { tst_brk(TCONF, "'%s' controller required, but not available",
@@ -848,7 +861,7 @@ mkdirs: ctrl->ctrl_name); } -if (cgroup_ctrl_on_v2 (ctrl)) { +if (cgroup_ctrl_on_v2 (ctrl) && !base) {if (root->we_mounted_it) {SAFE_FILE_PRINTFAT (root->mnt_dir.dir_fd, cgsc,"+%s" , ctrl->ctrl_name);
@@ -863,15 +876,17 @@ mkdirs:else root->ltp_dir.ctrl_field |= root->mnt_dir.ctrl_field; -if (cgroup_ctrl_on_v2 (ctrl)) { -SAFE_FILE_PRINTFAT (root->ltp_dir.dir_fd, - cgsc,"+%s" , ctrl->ctrl_name); - }else { -SAFE_FILE_PRINTFAT (root->ltp_dir.dir_fd, -"cgroup.clone_children" ,"%d" ,1 ); +if (!base) { +if (cgroup_ctrl_on_v2 (ctrl)) { +SAFE_FILE_PRINTFAT (root->ltp_dir.dir_fd, + cgsc,"+%s" , ctrl->ctrl_name); + }else { +SAFE_FILE_PRINTFAT (root->ltp_dir.dir_fd, +"cgroup.clone_children" ,"%d" ,1 ); -if (ctrl->ctrl_indx ==CTRL_CPUSET ) -cgroup_copy_cpuset (root); +if (ctrl->ctrl_indx ==CTRL_CPUSET ) +cgroup_copy_cpuset (root); + } }cgroup_dir_mk (&root->ltp_dir, cgroup_ltp_drain_dir, &root->drain_dir);
@@ -1049,8 +1064,10 @@ static void cgroup_group_add_dir(const struct tst_cg_group *const parent,if (!parent || dir->dir_root->ver ==TST_CG_V1 )continue ; -SAFE_CG_PRINTF (parent,"cgroup.subtree_control" , -"+%s" , ctrl->ctrl_name); +if (strcmp (ctrl->ctrl_name,"base" )) { +SAFE_CG_PRINTF (parent,"cgroup.subtree_control" , +"+%s" , ctrl->ctrl_name); + } }for (i =0 ; cg->dirs[i]; i++)
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v12 1/2] tst_cgroup.c: Add a cgroup base controller
Hi Wei,
Seems we have to skip the cgroup.subtree_control cleanup process inside tst_cg_cleanup(), otherwise, test complains that there is error operation in line#1020 if the unified cgroup-V2 was mounted by LTP.
(no need to resend another patch, someone who merge this can help fix.)
lib/tst_cgroup.c +0 -1
@@ -1012,7 +1012,8 @@ void tst_cg_cleanup(void) }for_each_ctrl (ctrl) { - if (!cgroup_ctrl_on_v2(ctrl) ||
!ctrl->ctrl_root->we_mounted_it)
+ if (!cgroup_ctrl_on_v2(ctrl) ||
!ctrl->ctrl_root->we_mounted_it
+ || !strcmp(ctrl->ctrl_name, "base"))
continue;
SAFE_FILE_PRINTFAT(ctrl->ctrl_root->mnt_dir.dir_fd,With above fix:
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v12 1/2] tst_cgroup.c: Add a cgroup base controller
Quoted 8 lines · Li Wang
Hi Wei,
Seems we have to skip the cgroup.subtree_control cleanup process inside
tst_cg_cleanup(), otherwise, test complains that there is error operation in line#1020 if the unified cgroup-V2 was mounted by LTP.(no need to resend another patch, someone who merge this can help fix.)
Thanks a lot :)
Quoted 23 lines
lib/tst_cgroup.c +1
-1@@ -1012,7 +1012,8 @@ void tst_cg_cleanup(void) }for_each_ctrl (ctrl) { -if (!cgroup_ctrl_on_v2 (ctrl) || !ctrl->ctrl_root->we_mounted_it) + if (!cgroup_ctrl_on_v2(ctrl) ||!ctrl->ctrl_root->we_mounted_it
+ || !strcmp(ctrl->ctrl_name, "base"))continue; SAFE_FILE_PRINTFAT(ctrl->ctrl_root->mnt_dir.dir_fd,With above fix:
Reviewed-by Li Wang <[email protected]>Signature · 2 lines
Regards, Li Wang
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Petr Vorel
Reviewed-byRe: [LTP] [PATCH v12 1/2] tst_cgroup.c: Add a cgroup base controller
In reply to Li WangHi Wei, Li,
Quoted 20 lines
Hi Wei,
Seems we have to skip the cgroup.subtree_control cleanup process inside
tst_cg_cleanup(), otherwise, test complains that there is error operation in line#1020 if the unified cgroup-V2 was mounted by LTP.(no need to resend another patch, someone who merge this can help fix.)
lib/tst_cgroup.c +1
-1@@ -1012,7 +1012,8 @@ void tst_cg_cleanup(void) }for_each_ctrl (ctrl) { -if (!cgroup_ctrl_on_v2 (ctrl) || !ctrl->ctrl_root->we_mounted_it) + if (!cgroup_ctrl_on_v2(ctrl) ||!ctrl->ctrl_root->we_mounted_it
+ || !strcmp(ctrl->ctrl_name, "base"))
Quoted 1 line
continue;
Agree.
Kind regards,
Petr
Quoted 3 lines
SAFE_FILE_PRINTFAT(ctrl->ctrl_root->mnt_dir.dir_fd,With above fix:
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v12 1/2] tst_cgroup.c: Add a cgroup base controller
In reply to Li WangHi Li, Wei,
Quoted 20 lines
Hi Wei,
Seems we have to skip the cgroup.subtree_control cleanup process inside
tst_cg_cleanup(), otherwise, test complains that there is error operation in line#1020 if the unified cgroup-V2 was mounted by LTP.(no need to resend another patch, someone who merge this can help fix.)
lib/tst_cgroup.c +1
-1@@ -1012,7 +1012,8 @@ void tst_cg_cleanup(void) }for_each_ctrl (ctrl) { -if (!cgroup_ctrl_on_v2 (ctrl) || !ctrl->ctrl_root->we_mounted_it) + if (!cgroup_ctrl_on_v2(ctrl) ||!ctrl->ctrl_root->we_mounted_it
+ || !strcmp(ctrl->ctrl_name, "base"))
Quoted 3 lines
continue;
SAFE_FILE_PRINTFAT(ctrl->ctrl_root->mnt_dir.dir_fd,Merged with this change. Thanks to both!
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v12 2/2 cgroup_core03.c: New case test cgroup kill feature
In reply to Wei Gao via ltp---v11->v12: skip the test gracefully if there is no 'cgroup.kill' interface.
lib/tst_cgroup.c | 1 + runtest/controllers | 1 + .../kernel/controllers/cgroup/.gitignore | 1 + .../kernel/controllers/cgroup/cgroup_core03.c | 130 ++++++++++++++++++ 4 files changed, 133 insertions(+) create mode 100644 testcases/kernel/controllers/cgroup/cgroup_core03.c
lib/tst_cgroup.c +1 -0
@@ -167,6 +167,7 @@ static const struct cgroup_file cgroup_ctrl_files[] = { { "cgroup.controllers", NULL, 0 }, { "cgroup.subtree_control", NULL, 0 }, { "cgroup.clone_children", "cgroup.clone_children", 0 }, + { "cgroup.kill", NULL, 0 }, { } };
runtest/controllers +1 -0
@@ -1,6 +1,7 @@ #DESCRIPTION:Resource Management testing cgroup_core01 cgroup_core01 cgroup_core02 cgroup_core02 +cgroup_core03 cgroup_core03 cgroup cgroup_regression_test.sh memcg_regression memcg_regression_test.sh memcg_test_3 memcg_test_3
testcases/kernel/controllers/cgroup/.gitignore +1 -0
@@ -2,3 +2,4 @@ /cgroup_regression_getdelays /cgroup_core01 /cgroup_core02 +/cgroup_core03
testcases/kernel/controllers/cgroup/cgroup_core03.c new file +130 -0
130 lines not on this page · raw message
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v12 2/2] cgroup_core03.c: New case test cgroup kill feature
Signature · 5 lines
Regards, Li Wang -- Mailing list info: https://lists.linux.it/listinfo/ltp