[CRIU] [PATCH 1/4] zdtm.sh: add ability to use a freezer cgroup

Andrey Vagin avagin at openvz.org
Thu Aug 6 02:37:25 PDT 2015


It allows to freeze processes faster

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 test/Makefile                           |  5 +++++
 test/zdtm.sh                            | 33 +++++++++++++++++++++++++++++++++
 test/zdtm/live/transition/thread-bomb.c | 16 ++++++++++++++--
 3 files changed, 52 insertions(+), 2 deletions(-)

diff --git a/test/Makefile b/test/Makefile
index ba25c13..ce8d59c 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -10,6 +10,7 @@ all:
 	$(MAKE) zdtm-pre-dump
 	$(MAKE) zdtm-snapshot
 	$(MAKE) zdtm-iter
+	$(MAKE) zdtm-freezer
 
 .PHONY: all
 
@@ -38,6 +39,10 @@ zdtm-snapshot: zdtm-tst-list
 zdtm-iter: zdtm-tst-list
 	ZDTM_ARGS="-i 3 -C" $(MAKE) -f Makefile.zdtm ns/static/pipe00
 
+zdtm-freezer:
+	ZDTM_ARGS="--freeze-cgroup /sys/fs/cgroup/freezer/test -i 3" $(MAKE) -f Makefile.zdtm transition/thread-bomb
+	ZDTM_ARGS="--freeze-cgroup /sys/fs/cgroup/freezer/test -d --frozen" $(MAKE) -f Makefile.zdtm transition/thread-bomb
+
 .PHONY: zdtm
 
 fault-injection: .FORCE
diff --git a/test/zdtm.sh b/test/zdtm.sh
index bd0c831..d0e945b 100755
--- a/test/zdtm.sh
+++ b/test/zdtm.sh
@@ -373,6 +373,7 @@ BATCH_TEST=0
 SPECIFIED_NAME_USED=0
 START_FROM="."
 RESTORE_SIBLING=""
+FREEZE_CGROUP=""
 
 zdtm_sep()
 { (
@@ -565,6 +566,12 @@ start_test()
 	fi
 
 	(
+		if [ -n "$FREEZE_CGROUP" ]; then
+			mkdir -p $FREEZE_CGROUP
+			echo 0 > $FREEZE_CGROUP/tasks || exit 1
+		else
+			export ZDTM_THREAD_BOMB=100
+		fi
 		# Here is no way to set FD_CLOEXEC on 3
 		exec 3>&-
 		make -C $tdir $tname.pid
@@ -575,6 +582,10 @@ start_test()
 		return 1
 	fi
 
+	if [ -n "$FREEZE_CGROUP" ] && [ -n "$FREEZER_STATE" ]; then
+		echo $FREEZER_STATE > $FREEZE_CGROUP/freezer.state
+	fi
+
 	[ -z "$PIDNS" ] || cd -
 
 	PID=`cat "$TPID"` || return 1
@@ -755,6 +766,10 @@ EOF
 			fi
 			[ -n "$snappdir" ] && cpt_args="$cpt_args --prev-images-dir=$snappdir"
 		fi
+		if [ -n "$FREEZE_CGROUP" ]; then
+			cpt_args="$cpt_args --freeze-cgroup $FREEZE_CGROUP --manage-cgroups"
+			rst_args="$rst_args --manage-cgroups"
+		fi
 
 		[ -n "$dump_only" ] && cpt_args="$cpt_args $POSTDUMP"
 
@@ -806,6 +821,15 @@ EOF
 				diff_maps $ddump/dump.maps $ddump/dump.maps.after || return 1
 			}
 
+			if [ -n "$FREEZE_CGROUP" ] && [ -n "$FREEZER_STATE" ]; then
+				while :; do
+					echo freezer.state=`cat $FREEZE_CGROUP/freezer.state`
+					cat $FREEZE_CGROUP/freezer.state | grep -q $FREEZER_STATE && break;
+					sleep 0.1
+				done
+			fi
+			echo THAWED > $FREEZE_CGROUP/freezer.state
+
 			rm -f ./$tdir/link_remap.*
 		else
 			# Wait while tasks are dying, otherwise PIDs would be busy.
@@ -1056,6 +1080,15 @@ while :; do
 		AUTO_DEDUP=1
 		shift
 		;;
+	  --freeze-cgroup)
+		shift
+		FREEZE_CGROUP=$1
+		shift
+		;;
+	  --frozen)
+		FREEZER_STATE=FROZEN
+		shift
+		;;
 	  -g)
 		COMPILE_ONLY=1
 		shift
diff --git a/test/zdtm/live/transition/thread-bomb.c b/test/zdtm/live/transition/thread-bomb.c
index 493de07..a21320f 100644
--- a/test/zdtm/live/transition/thread-bomb.c
+++ b/test/zdtm/live/transition/thread-bomb.c
@@ -4,11 +4,13 @@
 #include <syscall.h>
 #include <fcntl.h>
 #include <errno.h>
+#include <stdlib.h>
 
 #include "zdtmtst.h"
 
 static int p[2];
-static char buf[100]; /* the size is equal to the limit of threads */
+static char *buf;
+static int buf_size = 1024;
 
 #define exit_group(code)	\
 	syscall(__NR_exit_group, code)
@@ -40,11 +42,21 @@ err:
 
 int main(int argc, char **argv)
 {
+	char *val;
+
+	val = getenv("ZDTM_THREAD_BOMB");
+	if (val)
+		buf_size = atoi(val);
+	test_msg("%d\n", buf_size);
+	buf = malloc(buf_size);
+	if (!buf)
+		return 1;
+
 	if (pipe(p))
 		return 1;
 	fcntl(p[0], F_SETFL, O_NONBLOCK);
 
-	if (write(p[1], buf, sizeof(buf)) != sizeof(buf))
+	if (write(p[1], buf, buf_size) != buf_size)
 		return 1;
 
 	test_init(argc, argv);
-- 
2.1.0



More information about the CRIU mailing list