Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp4389316iog; Tue, 21 Jun 2022 19:24:03 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sRp6hZjVD5Aj6TE2ItCBQ2xYIHDyrGaVSbTNmtqZ8ml202qeSzKkZaJIjSn7gsFYsgU6kC X-Received: by 2002:a05:6a00:164c:b0:50a:472a:6b0a with SMTP id m12-20020a056a00164c00b0050a472a6b0amr33277988pfc.77.1655864642949; Tue, 21 Jun 2022 19:24:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655864642; cv=none; d=google.com; s=arc-20160816; b=gmxcTTnQkg7OU9CBf8hbvSqwz0/6DQP73eENo60jNadJve1EfTAQWKOM+RHAbAk8vW hxIeZ5soYYoCXfRnSn19N41zlAX0+zWB2NkxnceBsvbiEGmmmUaz+9oOhiqniPYJsGYS v6Bbl5RqWYH5fl7Em2HwIOVZpuEqP9rkDSpleLz7Zgaw3dqQvDy/9A6lfim9YLXS/c/A XZt0B49s1sCW/gi8uLuMJhpkyZrgk0TPuVvTCqIU0ujRaIBXZoflUrmeQPHYYF4nc3H7 d11DUw5e5/Qv6+Cyjd7Zt9irdb6GWZ4ZaE3YFRN2D2ct8uDrnh1RbMMqa2Y9BEPuL7X8 mEYg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=8l0sHLsI5nt4bCI9BzXsB64fMhOx0Yd7NKy6ByuMOqg=; b=gm/7TABWztaDOtTxzQjOIQBGxiNuUlcU8UnQ5GUTJ1rtV2xKpWRBogG4OK18+SIfeK 7rXXpxyVK8R0SHwoOTTWTJd4otBQOnE7fUK0J031FRNj+CL2M4L1EUKSBxlHTVJ5g0b6 5pnCd1OrtvSi3plxPm2A43wqAAgYep5rJqIFE5NhivI/pIgf8H9E5CoHVSXnWTQAxIa5 7ard+VDVIoxwyXUJvg5DX7fvN7SvnKnfm4Kqa9tlOPlH4JuE+eznmX6gY+UVUbiZidU6 x65JtuXaTMpbWi2vkzUsmJC3BnbqhOgSwIwvn9Bn3ruWVGDvbPO+lK0+rPMSHv3Ese5C +7zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=RhuQIzEe; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r12-20020a170902ea4c00b0016a0d3b3a57si15250111plg.504.2022.06.21.19.23.51; Tue, 21 Jun 2022 19:24:02 -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; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=RhuQIzEe; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233507AbiFVB4L (ORCPT + 99 others); Tue, 21 Jun 2022 21:56:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231720AbiFVB4I (ORCPT ); Tue, 21 Jun 2022 21:56:08 -0400 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03CB32F011 for ; Tue, 21 Jun 2022 18:56:08 -0700 (PDT) Received: by mail-pg1-x52c.google.com with SMTP id f65so14755813pgc.7 for ; Tue, 21 Jun 2022 18:56:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=8l0sHLsI5nt4bCI9BzXsB64fMhOx0Yd7NKy6ByuMOqg=; b=RhuQIzEeWjGxYVLOfnWJ9uW6hf9PpTO+gr3LP0FQEMCwSoXrD9Ekkz1KtgGCc4K+eg aenMB9VbXhAKOxEAcESN6OoWbGSMHKolLvOYSkv4E+KsMOMhiDFogbpqI2f82mejinFt y/asp8JUIri/lYrodGrAk/6R0fZH+F/O4K+U/pVeFi21qN/8TlA1RpHDrABgY5OYD53T 40YG1BebjLQrNHIXvnnLRqAtWxAl/xVb7d3SEBmSTyhJLBIcj6Ili+L9MtIx/nFXEU2J TKUp26kr2M4G2QfCDrlYx7lwoJ1bc2kwISGKrJBvLKEQyp5oMARbRVS+3Vw3nN3zIHig pBHg== 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:mime-version :content-transfer-encoding; bh=8l0sHLsI5nt4bCI9BzXsB64fMhOx0Yd7NKy6ByuMOqg=; b=bDJqLmWMsFUGvuxyz7LEPaBqvUFQ2ZvjKblF50c5aG4p5+WbEuH43Xt+sh+585CTtI nx80T9OZuyjy3lEH2jVrUSBP4E1V3bbvpWJEbkduztks/A0tXRyH91qvZ34T7A+3fNIL FSA24RxVCpdMDCG9edfFJcHG61kSlx0+XdYNaUBqkoKylfcrqOZ04mliCQbrfc1JcZVz moPiaKl+j1jOE5K3JcWqcWrXUp3S/67rA3NrePXSGbtEGyvrkEfK8vTf0g77gLEsH6rn tj0oEpAfdhABirMZOkwSKP/APzB9wcW3UmY7eS8jv/Z6oWAOL/iIf7aUoUGZoUwtX673 gkzw== X-Gm-Message-State: AJIora8fgR8tpEerrjHQ3lLCIGrrFxp2IgF9OU6GoDmke6oWuHMSzoVl DwlvXRzxwpF7q7kjvU2bblOqbA== X-Received: by 2002:a63:6943:0:b0:40c:3020:d0b with SMTP id e64-20020a636943000000b0040c30200d0bmr854124pgc.34.1655862967459; Tue, 21 Jun 2022 18:56:07 -0700 (PDT) Received: from C02CV1DAMD6P.bytedance.net ([139.177.225.230]) by smtp.gmail.com with ESMTPSA id 15-20020aa7924f000000b0050dc76281d3sm12250713pfp.173.2022.06.21.18.56.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jun 2022 18:56:06 -0700 (PDT) From: Chengming Zhou To: rdunlap@infradead.org, mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, tj@kernel.org, lizefan.x@bytedance.com, hannes@cmpxchg.org, corbet@lwn.net Cc: cgroups@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Chengming Zhou Subject: [PATCH v2] sched: RT bandwidth interface for cgroup unified hierarchy Date: Wed, 22 Jun 2022 09:55:57 +0800 Message-Id: <20220622015557.7497-1-zhouchengming@bytedance.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham 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 We need to run RT threads in cgroup unified hierarchy, but we can't since the default rt_bandwidth.rt_runtime of non-root task_group is 0 and we haven't interface to update it. This patch add RT bandwidth interface "cpu.max.rt" and update the documentation accordingly. Signed-off-by: Chengming Zhou --- v2: - minor fix for documentation per Randy's review. Thanks. --- Documentation/admin-guide/cgroup-v2.rst | 13 +++++++++++ kernel/sched/core.c | 31 +++++++++++++++++++++++++ kernel/sched/rt.c | 2 +- kernel/sched/sched.h | 1 + 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admin-guide/cgroup-v2.rst index 176298f2f4de..3d67366c99e1 100644 --- a/Documentation/admin-guide/cgroup-v2.rst +++ b/Documentation/admin-guide/cgroup-v2.rst @@ -1055,6 +1055,19 @@ All time durations are in microseconds. The burst in the range [0, $MAX]. + cpu.max.rt + A read-write two-value file which exists on all cgroups when + CONFIG_RT_GROUP_SCHED is enabled, to control CPU bandwidth for + RT threads in the task group. + + The maximum bandwidth limit. It's in the following format:: + + $MAX $PERIOD + + which indicates that RT threads in the group may consume up to + $MAX in each $PERIOD duration. "max" for $MAX indicates no + limit. If only one number is written, $MAX is updated. + cpu.pressure A read-write nested-keyed file. diff --git a/kernel/sched/core.c b/kernel/sched/core.c index daadedc78fd9..c16f8cc5de08 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -11047,6 +11047,30 @@ static ssize_t cpu_max_write(struct kernfs_open_file *of, } #endif +#ifdef CONFIG_RT_GROUP_SCHED +static int cpu_max_rt_show(struct seq_file *sf, void *v) +{ + struct task_group *tg = css_tg(seq_css(sf)); + + cpu_period_quota_print(sf, sched_group_rt_period(tg), sched_group_rt_runtime(tg)); + return 0; +} + +static ssize_t cpu_max_rt_write(struct kernfs_open_file *of, + char *buf, size_t nbytes, loff_t off) +{ + struct task_group *tg = css_tg(of_css(of)); + u64 period = sched_group_rt_period(tg); + u64 runtime; + int ret; + + ret = cpu_period_quota_parse(buf, &period, &runtime); + if (!ret) + ret = tg_set_rt_bandwidth(tg, period, runtime); + return ret ?: nbytes; +} +#endif + static struct cftype cpu_files[] = { #ifdef CONFIG_FAIR_GROUP_SCHED { @@ -11082,6 +11106,13 @@ static struct cftype cpu_files[] = { .write_u64 = cpu_cfs_burst_write_u64, }, #endif +#ifdef CONFIG_RT_GROUP_SCHED + { + .name = "max.rt", + .seq_show = cpu_max_rt_show, + .write = cpu_max_rt_write, + }, +#endif #ifdef CONFIG_UCLAMP_TASK_GROUP { .name = "uclamp.min", diff --git a/kernel/sched/rt.c b/kernel/sched/rt.c index 8c9ed9664840..319ce586446f 100644 --- a/kernel/sched/rt.c +++ b/kernel/sched/rt.c @@ -2819,7 +2819,7 @@ static int __rt_schedulable(struct task_group *tg, u64 period, u64 runtime) return ret; } -static int tg_set_rt_bandwidth(struct task_group *tg, +int tg_set_rt_bandwidth(struct task_group *tg, u64 rt_period, u64 rt_runtime) { int i, err = 0; diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 7b19a72408b1..317480d535b0 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -486,6 +486,7 @@ extern int alloc_rt_sched_group(struct task_group *tg, struct task_group *parent extern void init_tg_rt_entry(struct task_group *tg, struct rt_rq *rt_rq, struct sched_rt_entity *rt_se, int cpu, struct sched_rt_entity *parent); +extern int tg_set_rt_bandwidth(struct task_group *tg, u64 rt_period, u64 rt_runtime); extern int sched_group_set_rt_runtime(struct task_group *tg, long rt_runtime_us); extern int sched_group_set_rt_period(struct task_group *tg, u64 rt_period_us); extern long sched_group_rt_runtime(struct task_group *tg); -- 2.36.1