Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp1505338pxb; Sat, 23 Apr 2022 08:25:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzDcQBcp5QGt7C9YMopHRoCo9knm8VH8nL7RRR6PvM9Zuqpi8MUQwnv29qLZPrjtvOK+8J8 X-Received: by 2002:aa7:920b:0:b0:505:66a5:3029 with SMTP id 11-20020aa7920b000000b0050566a53029mr10258822pfo.40.1650727547357; Sat, 23 Apr 2022 08:25:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650727547; cv=none; d=google.com; s=arc-20160816; b=Pn1qoxSJUo+Y0tPmiOqh4LHXZrPJZk48PKbhmsX0qDD05rUPMyPsUAPH5Yea5/+Adc MlLoFVXwQQYSksfInTQm9QWxMvej4nugJbB9FmSIA5vBRBFV6fOmgEgi6XyWGcs5jdGp HLdzIOIbJcyxDNiVKkYPyEs3rN/G6sXY12qAIL5lzH0lLQiu5vVk0sKmZMCKSELojfDp nzKYLSfi46AsfGjLHyjk4soF+8s1zt1YkDh+lxw6HTXz+RnktG+4rfMjL7BVoFQ+cWV/ 1h+NgRFwIWShHJrsPz/HDJ6sSg8jPn3ksGOi+XxYiOqs1ubsqYY1/ha8SWppPFUKkt8L avbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=yElsKBK3uV3FIG02XGPOUL6cQVNqHPl51yiT0znHIN0=; b=ACAxQpIwg3J51ZWkavzrwSXR18OFuAoMu/hEPEYiq8ia1J2oTnzb+FnS+jSl3QIpbC 0639WVNjtw3eihk+f3pw3DVhCNvoYAbC7MGh0Ig3Nf4aXszaKUnR3egSmUjk2tmpEX8Z vSjFyQwmXc9TZ58y/nCNGlVa79ZCOBlCAFWpCIH+N+OmQ76IrGgKOoAw/Pcaf3rzWvdp kocuklXqDcixGsgm4ILSNtwpKhMDrSuOUqUd0elsbEzIklrTcGPjGBW3tWyZJFGyY4ix zLnlJuPwMwd/oXY2An5mv8lntg49T7p/YjqGWuUjJCTe9++LFD7kVc7yahUmwvMtD3/z 7Nkw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f17-20020a056a00239100b004fa662b24c0si11988718pfc.330.2022.04.23.08.25.30; Sat, 23 Apr 2022 08:25:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235483AbiDWMf3 (ORCPT + 99 others); Sat, 23 Apr 2022 08:35:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235436AbiDWMfP (ORCPT ); Sat, 23 Apr 2022 08:35:15 -0400 Received: from mail-qt1-f170.google.com (mail-qt1-f170.google.com [209.85.160.170]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99F6F1A0B01; Sat, 23 Apr 2022 05:32:18 -0700 (PDT) Received: by mail-qt1-f170.google.com with SMTP id bz24so7297521qtb.2; Sat, 23 Apr 2022 05:32:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yElsKBK3uV3FIG02XGPOUL6cQVNqHPl51yiT0znHIN0=; b=oZejJCUC/bDG7FwxZDXgCXKZZ0FvGU7PxQpNwJjj1E9DWnPyywNUHExTQqvmBv9XPF hKYn487qXGUbjgWwHCYwyOCuJwO6lvZy5+vGtXyMKLG42z2cqJsSfIZ9AmO9yeorVQB+ I6a5X1L7WihQW8kcuIBDdklczeMaGrUTccpRSamCB1rvP1YC+GBUabYjpJJ9etlUCkfp +jWLzkYk+v5hRDA5FbfKYOfhqq80c4OC3J+Y6keVTwSzS8wiHgmSwZ5dP1CwoTJO4M88 5KWhcr+23vG0YlM7XOIU/Ye3S3XzFNzjXTkIYL8VWc/Ub7e87UREnaEtVPuxijPNUds+ x3bw== X-Gm-Message-State: AOAM531kw+DY/ADEUitaUJxjZt04KeX+JO5BFWRQSfRzqX4iYpUbZCer yx4qY3US6Vt/bhtd06nG0Jk= X-Received: by 2002:ac8:5754:0:b0:2e1:eee8:be0b with SMTP id 20-20020ac85754000000b002e1eee8be0bmr6307255qtx.349.1650717137717; Sat, 23 Apr 2022 05:32:17 -0700 (PDT) Received: from localhost (fwdproxy-ash-016.fbsv.net. [2a03:2880:20ff:10::face:b00c]) by smtp.gmail.com with ESMTPSA id w4-20020a05620a0e8400b0067b1bcd081csm2131328qkm.66.2022.04.23.05.32.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Apr 2022 05:32:17 -0700 (PDT) From: David Vernet To: tj@kernel.org, lizefan.x@bytedance.com, hannes@cmpxchg.org Cc: cgroups@vger.kernel.org, peterz@infradead.org, mingo@redhat.com, linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 4/5] Add test_cpucg_max_nested() testcase Date: Sat, 23 Apr 2022 05:30:53 -0700 Message-Id: <20220423123053.2982931-4-void@manifault.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220423123053.2982931-1-void@manifault.com> References: <20220423123053.2982931-1-void@manifault.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The cgroup cpu controller selftests have a test_cpucg_max() testcase that validates the behavior of the cpu.max knob. Let's also add a testcase that verifies that the behavior works correctly when set on a nested cgroup. Signed-off-by: David Vernet --- tools/testing/selftests/cgroup/test_cpu.c | 63 +++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/tools/testing/selftests/cgroup/test_cpu.c b/tools/testing/selftests/cgroup/test_cpu.c index 715922c15c78..24020a2c68dc 100644 --- a/tools/testing/selftests/cgroup/test_cpu.c +++ b/tools/testing/selftests/cgroup/test_cpu.c @@ -617,6 +617,68 @@ static int test_cpucg_max(const char *root) return ret; } +/* + * This test verifies that a process inside of a nested cgroup whose parent + * group has a cpu.max value set, is properly throttled. + */ +static int test_cpucg_max_nested(const char *root) +{ + int ret = KSFT_FAIL; + long usage_usec, user_usec; + long usage_seconds = 1; + long expected_usage_usec = usage_seconds * USEC_PER_SEC; + char *parent, *child; + + parent = cg_name(root, "cpucg_parent"); + child = cg_name(parent, "cpucg_child"); + if (!parent || !child) + goto cleanup; + + if (cg_create(parent)) + goto cleanup; + + if (cg_write(parent, "cgroup.subtree_control", "+cpu")) + goto cleanup; + + if (cg_create(child)) + goto cleanup; + + if (cg_write(parent, "cpu.max", "1000")) + goto cleanup; + + struct cpu_hog_func_param param = { + .nprocs = 1, + .ts = { + .tv_sec = usage_seconds, + .tv_nsec = 0, + }, + .clock_type = CPU_HOG_CLOCK_WALL, + }; + if (cg_run(child, hog_cpus_timed, (void *)¶m)) + goto cleanup; + + usage_usec = cg_read_key_long(child, "cpu.stat", "usage_usec"); + user_usec = cg_read_key_long(child, "cpu.stat", "user_usec"); + if (user_usec <= 0) + goto cleanup; + + if (user_usec >= expected_usage_usec) + goto cleanup; + + if (values_close(usage_usec, expected_usage_usec, 95)) + goto cleanup; + + ret = KSFT_PASS; + +cleanup: + cg_destroy(child); + free(child); + cg_destroy(parent); + free(parent); + + return ret; +} + #define T(x) { x, #x } struct cpucg_test { int (*fn)(const char *root); @@ -629,6 +691,7 @@ struct cpucg_test { T(test_cpucg_nested_weight_overprovisioned), T(test_cpucg_nested_weight_underprovisioned), T(test_cpucg_max), + T(test_cpucg_max_nested), }; #undef T -- 2.30.2