From patchwork Mon Nov 22 14:13:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Vehlow X-Patchwork-Id: 1558090 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=jv-coder.de header.i=@jv-coder.de header.a=rsa-sha256 header.s=dkim header.b=tTXHUAM+; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HyTm22rygz9sRR for ; Tue, 23 Nov 2021 01:14:10 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 825503C8D12 for ; Mon, 22 Nov 2021 15:14:07 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [217.194.8.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id E10DB3C0D0B for ; Mon, 22 Nov 2021 15:14:04 +0100 (CET) Received: from mail.jv-coder.de (mail.jv-coder.de [5.9.79.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id E12FC1400778 for ; Mon, 22 Nov 2021 15:14:03 +0100 (CET) Received: from ubuntu.localdomain (unknown [188.195.115.12]) by mail.jv-coder.de (Postfix) with ESMTPSA id 4DED09F6A0; Mon, 22 Nov 2021 14:14:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jv-coder.de; s=dkim; t=1637590442; bh=/W36/tIwVaAXhMf2OiberCsEVv8b/Z/iim8mbiZbAtA=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=tTXHUAM+6kXbCg0zC1Sm6qlqPOtE4n3n04g7SxhWtxNzA/P8BrnwUtSMgpIvQmyr0 /bKa9iswkGCdmMMgUoNVwaMWryllxuu8wStFEoHWh88RgZ5il3Csg499tbKqnSf08W nstuCN7j7XJBYhP7arVxRbiyvsMH7vAeB6ICo82E= From: Joerg Vehlow To: ltp@lists.linux.it, rpalethorpe@suse.de Date: Mon, 22 Nov 2021 15:13:55 +0100 Message-Id: <20211122141355.299621-1-lkml@jv-coder.de> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-6.smtp.seeweb.it X-Virus-Scanned: clamav-milter 0.102.4 at in-6.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH] cpuset_regression_test: Fix test, if cpuset groups exist already X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Joerg Vehlow Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" From: Joerg Vehlow Fix three errors: 1. read -d is not posix, but not even required, because find and read work line-based 2. Setting cpuset.cpus to an empty string is not allowed. -> If there are cpuset groups defined already, we need at least to cpus. One is used for the test, the other one is used for existing groups. 3. Existing cgroup hierarchies were not handled correctly. When setting the cpuset.cpus, it must be done breadth-first, otherwise cpu constraints for parent groups can be violated. Fixes: 6950e96eabb2 ("cpuset_regression_test: Allow running, if groups exist") Signed-off-by: Joerg Vehlow --- @Richard Sorry for so many bugs in the patch... I guess I way a bit tired .../cpuset/cpuset_regression_test.sh | 84 ++++++++++++++++--- 1 file changed, 72 insertions(+), 12 deletions(-) diff --git a/testcases/kernel/controllers/cpuset/cpuset_regression_test.sh b/testcases/kernel/controllers/cpuset/cpuset_regression_test.sh index cc6bfdc64..f6447a656 100755 --- a/testcases/kernel/controllers/cpuset/cpuset_regression_test.sh +++ b/testcases/kernel/controllers/cpuset/cpuset_regression_test.sh @@ -21,32 +21,80 @@ TST_MIN_KVER="3.18" LOCAL_MOUNTPOINT="cpuset_test" BACKUP_DIRECTORY="cpuset_backup" +cpu_num= root_cpuset_dir= cpu_exclusive="cpuset.cpu_exclusive" cpus="cpuset.cpus" old_cpu_exclusive_value=1 -# cpuset_backup_and_update +# Check if there are cpuset groups +cpuset_has_groups() +{ + local old_dir=$PWD + local result=0 + + find ${root_cpuset_dir} -mindepth 1 -type d -exec echo 1 \; -quit +} + +# cpuset_find_breadth_first +# Do a breath first find of +cpuset_find_breadth_first() +{ + local what=$1 + + # Breath first find implementation: + # Use awk to prepend the length of the path, sort it + # and remove the length again. + # Since all commands work line-based, + # this works with meta characters and spaces. + find . -mindepth 2 -name ${what} | + awk '{print length($0) " " $0}' | + sort -n | cut -d " " -f 2- +} + +# cpuset_backup_and_update # Create backup of the values of a specific file () -# in all cpuset groups and set the value to +# in all cpuset groups and set the value to 1 # The backup is written to in the same structure # as in the cpuset filesystem cpuset_backup_and_update() { local backup_dir=$1 local what=$2 - local value=$3 local old_dir=$PWD + local cpu_max=$((cpu_num - 1)) + local res cd ${root_cpuset_dir} - find . -mindepth 2 -name ${what} -print0 | - while IFS= read -r -d '' file; do + + # First do breath-first search and set all groups to use all cpus. + # Breath-first is important, because the parent groups + # must have all cpus assigned to a child group first + cpuset_find_breadth_first ${what} | + while read -r file; do + # Skip cgroups with no set cpuset + [ "$(cat "${file}")" = "" ] && continue + mkdir -p "$(dirname "${backup_dir}/${file}")" cat "${file}" > "${backup_dir}/${file}" - echo "${value}" > "${file}" + echo "0-${cpu_max}" > "${file}" || exit 1 done + if [ $? -ne 0 ]; then + cd $old_dir + return 1 + fi + + # Now do depth first and limit the cpus to cpu 1 + find . -depth -mindepth 2 -name ${what} | + while read -r file; do + [ "$(cat "${file}")" = "" ] && continue + echo "1" > "${file}" + done + res=$? cd $old_dir + + return $res } # cpuset_restore @@ -59,8 +107,12 @@ cpuset_restore() local old_dir=$PWD cd ${backup_dir} - find . -mindepth 2 -name ${what} -print0 | - while IFS= read -r -d '' file; do + + # Do a breath-first restore. + # This works, because cpusets set on parents, automatically + # limit the set for the child. + cpuset_find_breadth_first ${what} | + while read -r file; do cat "${file}" > "${root_cpuset_dir}/${file}" done @@ -91,10 +143,18 @@ setup() tst_brk TBROK "Both cpuset.cpu_exclusive and cpu_exclusive do not exist" fi - # Ensure that no group explicitely uses a cpu, - # otherwise setting cpuset.cpus for the testgroup will fail - mkdir ${BACKUP_DIRECTORY} - cpuset_backup_and_update "${PWD}/${BACKUP_DIRECTORY}" ${cpus} "" + # Ensure that we can use cpu 0 exclusively + if [ "$(cpuset_has_groups)" = "1" ]; then + cpu_num=$(tst_getconf _NPROCESSORS_ONLN) + if [ $cpu_num -lt 2 ]; then + tst_brk TCONF "There are already cpuset groups, so at least two cpus are required." + fi + + # Use cpu 1 for all existing cpuset cgroups + mkdir ${BACKUP_DIRECTORY} + cpuset_backup_and_update "${PWD}/${BACKUP_DIRECTORY}" ${cpus} + [ $? -ne 0 ] && tst_brk TBROK "Unable to prepare existing cpuset cgroups" + fi old_cpu_exclusive_value=$(cat ${root_cpuset_dir}/${cpu_exclusive}) if [ "${old_cpu_exclusive_value}" != "1" ];then