Message ID | 91b9d5928cd129ebb21430a60e715113a6a6f6b7.1641376050.git.luke.nowakowskikrijger@canonical.com |
---|---|
State | Changes Requested |
Headers | show |
Series | Expand Cgroup shell library | expand |
Luke Nowakowski-Krijger <luke.nowakowskikrijger@canonical.com> wrote: > tools/cgroup/Makefile | 7 ++++ > tools/cgroup/tst_cgctl.c | 69 ++++++++++++++++++++++++++++++++++++++++ Looks like putting this tst_cgctl.c in testcase/lib/ will be better, we have no necessary to create it under a bit far directory, and that tool/ is more generic for LTP, but this process is only for shell tests. > +static int cgctl_cleanup(const char *config) > +{ > + tst_cgroup_scan(); > + tst_cgroup_load_config(config); This tst_cgroup_load_config() does not work as expected. From my manual check, the ltp and drain dir have been created but it prints " Created_Ltp_Dir=no Created_Drain_Dir=no" strings. ... Detected Roots: /sys/fs/cgroup/memory Mounted_Root=no Created_Ltp_Dir=no Created_Drain_Dir=no Test_Id=test-1801 ... > + tst_cgroup_cleanup(); This does not work as expected too, but the problem should exist in previous patches. Anyway, I will look into the details tomorrow. # ./tst_cgctl cleanup "$_cgroup_state" tst_cgroup.c:414: TBROK: Could not find root from config. Roots changing between calls? > + > + return 0; > +} -- Regards, Li Wang
Hi Li, On Tue, Jan 11, 2022 at 4:43 AM Li Wang <liwang@redhat.com> wrote: > Luke Nowakowski-Krijger <luke.nowakowskikrijger@canonical.com> wrote: > > > tools/cgroup/Makefile | 7 ++++ > > tools/cgroup/tst_cgctl.c | 69 ++++++++++++++++++++++++++++++++++++++++ > > Looks like putting this tst_cgctl.c in testcase/lib/ will be better, > we have no necessary to create it under a bit far directory, and > that tool/ is more generic for LTP, but this process is only for > shell tests. > > Yeah I will move it over here. I was not sure exactly where it should go. > +static int cgctl_cleanup(const char *config) > > +{ > > + tst_cgroup_scan(); > > + tst_cgroup_load_config(config); > > This tst_cgroup_load_config() does not work as expected. > From my manual check, the ltp and drain dir have been created > but it prints " Created_Ltp_Dir=no Created_Drain_Dir=no" strings. > > ... > Detected Roots: > /sys/fs/cgroup/memory Mounted_Root=no Created_Ltp_Dir=no > Created_Drain_Dir=no Test_Id=test-1801 > ... > > > Hm, I'm not sure what this could be. Are you sure when you were reading the printed info it was in the same invocation as when it was being created? Because the tst_cgroup_print_config is just pretty directly printing out the state of the cgroup framework. > + tst_cgroup_cleanup(); > > This does not work as expected too, but the problem should exist > in previous patches. Anyway, I will look into the details tomorrow. > > # ./tst_cgctl cleanup "$_cgroup_state" > tst_cgroup.c:414: TBROK: Could not find root from config. Roots > changing between calls? > > Was "/sys/fs/cgroup/cpu,cpuacct" one of the roots that was printed out? Because if so the way I have it now it would not be able to parse that. I will look into fixing this. > > + > > + return 0; > > +} > > > -- > Regards, > Li Wang > > Thanks again for review, - Luke
Hi Luke, >> > +static int cgctl_cleanup(const char *config) >> > +{ >> > + tst_cgroup_scan(); >> > + tst_cgroup_load_config(config); >> >> This tst_cgroup_load_config() does not work as expected. >> From my manual check, the ltp and drain dir have been created >> but it prints " Created_Ltp_Dir=no Created_Drain_Dir=no" strings. >> >> ... >> Detected Roots: >> /sys/fs/cgroup/memory Mounted_Root=no Created_Ltp_Dir=no >> Created_Drain_Dir=no Test_Id=test-1801 >> ... >> >> > > Hm, I'm not sure what this could be. Are you sure when you were reading the printed info it was in the same invocation as when it was being created? Because the tst_cgroup_print_config is just pretty directly printing out the state of the cgroup framework. I have got the reason, because I manually run Cgroup test but did not allow it to do cleanup so leaves the ltp/ and drain/ dir there, so it will not be recorded as "yes" in Created_Ltp_dir next time, that behavior is correct. > >> > + tst_cgroup_cleanup(); >> >> This does not work as expected too, but the problem should exist >> in previous patches. Anyway, I will look into the details tomorrow. >> >> # ./tst_cgctl cleanup "$_cgroup_state" >> tst_cgroup.c:414: TBROK: Could not find root from config. Roots >> changing between calls? >> > > Was "/sys/fs/cgroup/cpu,cpuacct" one of the roots that was printed out? Because if so the way I have it now it would not be able to parse that. I will look into fixing this. Yes, it was, I just cut the message to show the problem. Detected Controllers: memory V1 @ /sys/fs/cgroup/memory Required cpu V1 @ /sys/fs/cgroup/cpu,cpuacct cpuset V1 @ /sys/fs/cgroup/cpuset Detected Roots: /sys/fs/cgroup/memory Mounted_Root=no Created_Ltp_Dir=no Created_Drain_Dir=no Test_Id=test-5091 /sys/fs/cgroup/cpu,cpuacct Mounted_Root=no Created_Ltp_Dir=no Created_Drain_Dir=no Test_Id=NULL /sys/fs/cgroup/cpuset Mounted_Root=no Created_Ltp_Dir=no Created_Drain_Dir=no Test_Id=NULL From my test, the progress works well on Cgroup V2, but now fails on parsing the root config in V1. I suspect there is a bug in patch 4/6, but still checking why the "roots" is NULL at that moment.
diff --git a/tools/cgroup/Makefile b/tools/cgroup/Makefile new file mode 100644 index 000000000..81810bf4d --- /dev/null +++ b/tools/cgroup/Makefile @@ -0,0 +1,7 @@ +top_srcdir ?= ../.. + +include $(top_srcdir)/include/mk/testcases.mk + +MAKE_TARGETS := tst_cgctl + +include $(top_srcdir)/include/mk/generic_leaf_target.mk \ No newline at end of file diff --git a/tools/cgroup/tst_cgctl.c b/tools/cgroup/tst_cgctl.c new file mode 100644 index 000000000..ef20e7485 --- /dev/null +++ b/tools/cgroup/tst_cgctl.c @@ -0,0 +1,69 @@ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <stdint.h> +#include <unistd.h> +#include "tst_cgroup.h" + +static int cgctl_require(const char *ctrl, int test_pid) +{ + struct tst_cgroup_opts opts; + + memset(&opts, 0, sizeof(opts)); + opts.test_pid = test_pid; + + tst_cgroup_require(ctrl, &opts); + tst_cgroup_print_config(); + + return 0; +} + +static int cgctl_cleanup(const char *config) +{ + tst_cgroup_scan(); + tst_cgroup_load_config(config); + tst_cgroup_cleanup(); + + return 0; +} + +static int cgctl_print(void) +{ + tst_cgroup_scan(); + tst_cgroup_print_config(); + + return 0; +} + +static int cgctl_process_cmd(int argc, char *argv[]) +{ + int test_pid; + const char *cmd_name = argv[1]; + + if (!strcmp(cmd_name, "require")) { + test_pid = atoi(argv[3]); + if (!test_pid) { + fprintf(stderr, "tst_cgctl: Invalid test_pid '%s' given\n", + argv[3]); + return 1; + } + return cgctl_require(argv[2], test_pid); + } else if (!strcmp(cmd_name, "cleanup")) { + return cgctl_cleanup(argv[2]); + } else if (!strcmp(cmd_name, "print")) { + return cgctl_print(); + } + + fprintf(stderr, "tst_cgctl: Unknown command '%s' given\n", cmd_name); + return 1; +} + +int main(int argc, char *argv[]) +{ + if (argc < 2 || argc > 4) { + fprintf(stderr, "tst_cgctl: Invalid number of arguements given"); + return 1; + } + + return cgctl_process_cmd(argc, argv); +} \ No newline at end of file
Implement a binary utility that creates an interface to make calls to the cgroup C API. This will effectively allow shell scripts to make calls to the cgroup C api. Signed-off-by: Luke Nowakowski-Krijger <luke.nowakowskikrijger@canonical.com> --- tools/cgroup/Makefile | 7 ++++ tools/cgroup/tst_cgctl.c | 69 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 tools/cgroup/Makefile create mode 100644 tools/cgroup/tst_cgctl.c