Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp5565867rwp; Mon, 17 Jul 2023 06:18:27 -0700 (PDT) X-Google-Smtp-Source: APBJJlEEvEd76zlDp1cwH6Tn5kNtpburY/0c9/TSPe2gopiOU6gH/kZahKVmE1S/sInabnTz6fXJ X-Received: by 2002:a2e:9583:0:b0:2b5:1b80:263a with SMTP id w3-20020a2e9583000000b002b51b80263amr11181751ljh.47.1689599907616; Mon, 17 Jul 2023 06:18:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689599907; cv=none; d=google.com; s=arc-20160816; b=vfrprfBNGfKNBj2HlGMDXBgH8vPE+IEw6CW+ezH9DiOnvhBwZCsXk8JPQZdshA99fK m648Yxs8rToSSY8W+iM52RZlAmjZuFjpx4awfPPvVkEk6R32nQpW3i/ERWD/bg8cnFL7 oHThZcXldf6yJkyYP4XaYbt4uIGOEH3UgrnMFxR7bBfVUOoFaII1t/ApuHYl8xsH8P+Y 2gLJCusTyaB0i0aZaHitnAhFSUJJ2YDKz3BmEKEWMslVOAPgb8FsJ1Pzb9nelLQxPmRh hsvnX82t8WsCSy09uhiT3GYOVRxticzieJurjExMITqyQC9SKKhd1gDSWiLyvGA7DSYs GHOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=oaYAAOjfyi4fSbHjYzAAIzNL+EJVRTa62d71dD8b2+g=; fh=9BETjUNLxKfKf6DJp22edHRPqmtDjkC1vjd8yq+xge0=; b=KlxNh/kam5i7TQIknT1z6jmP8EdGlx2U8psu+/RHkEI4UCnXoNpWWNp2LJUPQjPD/J noHQ2fV2aN2raOh4uCP09khghqhTc7ZWAUQZ9SpnaGOUKIvPk4IplbP6haJKASpt/2c2 MUTE1JWDQUBos7pqcHnDSZ8s5hqujxXteJNC+tCYHI5/74I+BAuvoNbTmkeXd61QngSr 8TIGvi/FsKRkz9k20RvIVvQxxm48zYkjga6AncqGPoLsM06+pEfU7VvPm3P/q1dV0DXA UmXeAf/h4oLAKQ9ja+YL0jaevfAtCpU4Vo+4xZuReaABQQE1LUOkGdzo0GhfCpky1E/7 rpsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=iZxYaiui; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kf14-20020a17090776ce00b0099316613780si13768672ejc.1038.2023.07.17.06.18.03; Mon, 17 Jul 2023 06:18:27 -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=@linutronix.de header.s=2020 header.b=iZxYaiui; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231164AbjGQM5r (ORCPT + 99 others); Mon, 17 Jul 2023 08:57:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231342AbjGQM5d (ORCPT ); Mon, 17 Jul 2023 08:57:33 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDFC71725; Mon, 17 Jul 2023 05:57:05 -0700 (PDT) Date: Mon, 17 Jul 2023 12:56:15 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1689598575; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oaYAAOjfyi4fSbHjYzAAIzNL+EJVRTa62d71dD8b2+g=; b=iZxYaiuiI/lC9fBYA+/xWEKq5DD1+5aG8ekNb2u8AeH/owug6xnooRdhClIess1rLCWPi/ EQzbolKRx+C/9r973KarrBIN0S2hi9Xq40NCOJTwAF/C6GnlEg8Z/cINiKTrJRYvZU+FeQ 8gH/LzYVqtjNLYp74BP3hRIa4TTVajDxzWQSMzXDQwucCq4w6y4m8eMG+cM4GMkVUFdpkv ExBRsuBTvJwmKMP84dePutp+WQk8IWgxwV7l6zyyW3VQW7z0q7KBbTp1FuxVSdSf6fZ8Qk WpfrZIrkAKDPxfzdRdkL8ff5cbPk+6vv3NoKLGfiBzT7WfAwNEj3JCk4UlOlVg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1689598575; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oaYAAOjfyi4fSbHjYzAAIzNL+EJVRTa62d71dD8b2+g=; b=TptSdbtPnO2KhazmC84rFF4uKdyLVK3Hcq9jY3RofmGriLi301Ut7DGE2Tp16ThH3bsozz WcdFm/svGTOTLWDw== From: "tip-bot2 for Josh Don" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] sched: add throttled time stat for throttled children Cc: Josh Don , "Peter Zijlstra (Intel)" , Tejun Heo , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230620183247.737942-2-joshdon@google.com> References: <20230620183247.737942-2-joshdon@google.com> MIME-Version: 1.0 Message-ID: <168959857513.28540.14955186299342817688.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, 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 The following commit has been merged into the sched/core branch of tip: Commit-ID: 677ea015f231aa38b3972aa7be54ecd2637e99fd Gitweb: https://git.kernel.org/tip/677ea015f231aa38b3972aa7be54ecd2637e99fd Author: Josh Don AuthorDate: Tue, 20 Jun 2023 11:32:47 -07:00 Committer: Peter Zijlstra CommitterDate: Thu, 13 Jul 2023 15:21:49 +02:00 sched: add throttled time stat for throttled children We currently export the total throttled time for cgroups that are given a bandwidth limit. This patch extends this accounting to also account the total time that each children cgroup has been throttled. This is useful to understand the degree to which children have been affected by the throttling control. Children which are not runnable during the entire throttled period, for example, will not show any self-throttling time during this period. Expose this in a new interface, 'cpu.stat.local', which is similar to how non-hierarchical events are accounted in 'memory.events.local'. Signed-off-by: Josh Don Signed-off-by: Peter Zijlstra (Intel) Acked-by: Tejun Heo Link: https://lore.kernel.org/r/20230620183247.737942-2-joshdon@google.com --- include/linux/cgroup-defs.h | 2 ++- kernel/cgroup/cgroup.c | 34 ++++++++++++++++++++++++++++- kernel/sched/core.c | 44 ++++++++++++++++++++++++++++++++++++- kernel/sched/fair.c | 21 ++++++++++++++++- kernel/sched/sched.h | 2 ++- 5 files changed, 102 insertions(+), 1 deletion(-) diff --git a/include/linux/cgroup-defs.h b/include/linux/cgroup-defs.h index 8a0d546..ae20dbb 100644 --- a/include/linux/cgroup-defs.h +++ b/include/linux/cgroup-defs.h @@ -661,6 +661,8 @@ struct cgroup_subsys { void (*css_rstat_flush)(struct cgroup_subsys_state *css, int cpu); int (*css_extra_stat_show)(struct seq_file *seq, struct cgroup_subsys_state *css); + int (*css_local_stat_show)(struct seq_file *seq, + struct cgroup_subsys_state *css); int (*can_attach)(struct cgroup_taskset *tset); void (*cancel_attach)(struct cgroup_taskset *tset); diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index bfe3cd8..4e3ee13 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -3685,6 +3685,36 @@ static int cpu_stat_show(struct seq_file *seq, void *v) return ret; } +static int __maybe_unused cgroup_local_stat_show(struct seq_file *seq, + struct cgroup *cgrp, int ssid) +{ + struct cgroup_subsys *ss = cgroup_subsys[ssid]; + struct cgroup_subsys_state *css; + int ret; + + if (!ss->css_local_stat_show) + return 0; + + css = cgroup_tryget_css(cgrp, ss); + if (!css) + return 0; + + ret = ss->css_local_stat_show(seq, css); + css_put(css); + return ret; +} + +static int cpu_local_stat_show(struct seq_file *seq, void *v) +{ + struct cgroup __maybe_unused *cgrp = seq_css(seq)->cgroup; + int ret = 0; + +#ifdef CONFIG_CGROUP_SCHED + ret = cgroup_local_stat_show(seq, cgrp, cpu_cgrp_id); +#endif + return ret; +} + #ifdef CONFIG_PSI static int cgroup_io_pressure_show(struct seq_file *seq, void *v) { @@ -5235,6 +5265,10 @@ static struct cftype cgroup_base_files[] = { .name = "cpu.stat", .seq_show = cpu_stat_show, }, + { + .name = "cpu.stat.local", + .seq_show = cpu_local_stat_show, + }, { } /* terminate */ }; diff --git a/kernel/sched/core.c b/kernel/sched/core.c index c52c2eb..2291f9d 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -11139,6 +11139,27 @@ static int cpu_cfs_stat_show(struct seq_file *sf, void *v) return 0; } + +static u64 throttled_time_self(struct task_group *tg) +{ + int i; + u64 total = 0; + + for_each_possible_cpu(i) { + total += READ_ONCE(tg->cfs_rq[i]->throttled_clock_self_time); + } + + return total; +} + +static int cpu_cfs_local_stat_show(struct seq_file *sf, void *v) +{ + struct task_group *tg = css_tg(seq_css(sf)); + + seq_printf(sf, "throttled_time %llu\n", throttled_time_self(tg)); + + return 0; +} #endif /* CONFIG_CFS_BANDWIDTH */ #endif /* CONFIG_FAIR_GROUP_SCHED */ @@ -11215,6 +11236,10 @@ static struct cftype cpu_legacy_files[] = { .name = "stat", .seq_show = cpu_cfs_stat_show, }, + { + .name = "stat.local", + .seq_show = cpu_cfs_local_stat_show, + }, #endif #ifdef CONFIG_RT_GROUP_SCHED { @@ -11271,6 +11296,24 @@ static int cpu_extra_stat_show(struct seq_file *sf, return 0; } +static int cpu_local_stat_show(struct seq_file *sf, + struct cgroup_subsys_state *css) +{ +#ifdef CONFIG_CFS_BANDWIDTH + { + struct task_group *tg = css_tg(css); + u64 throttled_self_usec; + + throttled_self_usec = throttled_time_self(tg); + do_div(throttled_self_usec, NSEC_PER_USEC); + + seq_printf(sf, "throttled_usec %llu\n", + throttled_self_usec); + } +#endif + return 0; +} + #ifdef CONFIG_FAIR_GROUP_SCHED static u64 cpu_weight_read_u64(struct cgroup_subsys_state *css, struct cftype *cft) @@ -11449,6 +11492,7 @@ struct cgroup_subsys cpu_cgrp_subsys = { .css_released = cpu_cgroup_css_released, .css_free = cpu_cgroup_css_free, .css_extra_stat_show = cpu_extra_stat_show, + .css_local_stat_show = cpu_local_stat_show, #ifdef CONFIG_RT_GROUP_SCHED .can_attach = cpu_cgroup_can_attach, #endif diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 51ccae7..159b202 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -4878,8 +4878,12 @@ enqueue_entity(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags) list_add_leaf_cfs_rq(cfs_rq); } else { #ifdef CONFIG_CFS_BANDWIDTH + struct rq *rq = rq_of(cfs_rq); + if (cfs_rq_throttled(cfs_rq) && !cfs_rq->throttled_clock) - cfs_rq->throttled_clock = rq_clock(rq_of(cfs_rq)); + cfs_rq->throttled_clock = rq_clock(rq); + if (!cfs_rq->throttled_clock_self) + cfs_rq->throttled_clock_self = rq_clock(rq); #endif } } @@ -5384,6 +5388,17 @@ static int tg_unthrottle_up(struct task_group *tg, void *data) /* Add cfs_rq with load or one or more already running entities to the list */ if (!cfs_rq_is_decayed(cfs_rq)) list_add_leaf_cfs_rq(cfs_rq); + + if (cfs_rq->throttled_clock_self) { + u64 delta = rq_clock(rq) - cfs_rq->throttled_clock_self; + + cfs_rq->throttled_clock_self = 0; + + if (SCHED_WARN_ON((s64)delta < 0)) + delta = 0; + + cfs_rq->throttled_clock_self_time += delta; + } } return 0; @@ -5398,6 +5413,10 @@ static int tg_throttle_down(struct task_group *tg, void *data) if (!cfs_rq->throttle_count) { cfs_rq->throttled_clock_pelt = rq_clock_pelt(rq); list_del_leaf_cfs_rq(cfs_rq); + + SCHED_WARN_ON(cfs_rq->throttled_clock_self); + if (cfs_rq->nr_running) + cfs_rq->throttled_clock_self = rq_clock(rq); } cfs_rq->throttle_count++; diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index e93e006..1dcea9b 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -636,6 +636,8 @@ struct cfs_rq { u64 throttled_clock; u64 throttled_clock_pelt; u64 throttled_clock_pelt_time; + u64 throttled_clock_self; + u64 throttled_clock_self_time; int throttled; int throttle_count; struct list_head throttled_list;