From patchwork Thu Jun 15 11:38:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 108454 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp575852vqr; Thu, 15 Jun 2023 05:00:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7n2zT5d5RSRYASbbjeKn3Wa0qmMJ5nck1Y47zD8lU95zWUAG9v8GIIaeobEsbxcWBWfFW7 X-Received: by 2002:a17:907:8a1f:b0:982:a2dd:4543 with SMTP id sc31-20020a1709078a1f00b00982a2dd4543mr1430977ejc.18.1686830442484; Thu, 15 Jun 2023 05:00:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686830442; cv=none; d=google.com; s=arc-20160816; b=gYQu88aei7WtucUqcJfs4krO+YIg7KoACEqcyHsK5UzJKD/qeiQ79zCh4eppJMWwOZ U95KSuJDYQU8pnKLTE0Zgn+qVErNu2rOiYa18hJFitSLoTy0mF7PnxgEGhSLSKPIMPby 1Ai4HDFzobRH96Y6rSlGOzWkvjfnFSFFPg1LVtNL5HLqUU/jCskSK8Zsjvjqg98g6b8M Aqdjx9+qRoU9thqM24+L0Yz+J2d9O6YgZ+qAoxEFVK0PCH7Cm4AMndnJ8S+GVQv2mxks KdJmYsMTXiqK1xycC7rpxFzx9Peu+LiCZD/X76OeWxXDMeY+7j6z1RwIW5i2unQK4NOt DPbA== 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=Myq8Q7URsY1/q1U+vXYUUEZfSehvUfElllJNvNzU0b0=; b=eQ/m3ebtg/0aRMePa6FzVWzSoCp5hdliU4aGrp8ulBEvBIMMgaVl5z6V4VhRcXeRiA Mvfbp9/dE4BxNjVj5pdilYPshCKJ7SsgHcaGIQnod/8K1KvaDC5fv/t2+BOXUMRqp9rz CkbkNKx6YluDaSP1o3+Z8ByIEPykRTLrA3TEwVKqhiRIZ2AU+N8ftSj30Obl5hkFrqzu OfA6y9nrVrRVn2yXp3O0zfsuNaYNnNbeNaVOObe6vfwk4lG9fU3/37mYZVcCmBCAXkaQ QbnGmWvW4aBo9dbj6drDBEzGGf7aq6nNUKJrmEEyFimNAzdGBqJv/SfSsh7MNoey2TIU Zx1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=2cUrbUdl; dkim=neutral (no key) header.i=@linutronix.de; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z3-20020a1709063a0300b0097ea92f4cd9si6838649eje.417.2023.06.15.05.00.15; Thu, 15 Jun 2023 05:00:42 -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=2cUrbUdl; dkim=neutral (no key) header.i=@linutronix.de; 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 S1344188AbjFOLjt (ORCPT + 99 others); Thu, 15 Jun 2023 07:39:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344072AbjFOLi5 (ORCPT ); Thu, 15 Jun 2023 07:38:57 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CB4330F6; Thu, 15 Jun 2023 04:38:16 -0700 (PDT) Date: Thu, 15 Jun 2023 11:38:14 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1686829094; 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=Myq8Q7URsY1/q1U+vXYUUEZfSehvUfElllJNvNzU0b0=; b=2cUrbUdlXaLvYvN6UDQQsMf0xyeEl82oKJdP//u3lPm1J/dKk5Nbvv6Bd2sg7fmEqVWO0p +Ay/mmo6f67vKIHKVWpuXNQTeOoZsUGsN1vs+Vz5GO+PAd+lUz+mTLHkM6bTWyLt6zDINe MEqacGSaR+6/EufDPPOXSu1XJwLhGxHFUWFGpg5I+3RuBaifiW1ttjkgBCm2/rKTFPeVHN KFeMn+kTuhjlWG+DO30XrNUkycWRP1CXWaO3SFlV014EwHGBM7QIaf9zFGnftPeDTQD/Dm i2JCjleQERVaaYJKp1jy/XVwv/IX80XBdKEuV+0n64OR7kuO3s9QJfczjevfnQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1686829094; 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=Myq8Q7URsY1/q1U+vXYUUEZfSehvUfElllJNvNzU0b0=; b=8JSqd2GIYnLX67sfWfWVSjEeSHMPGXVW+yJxKgJs7ctyY2JpfXcfytcD5i+3q3AisdZ8+O 2GhIguwQ7usYOJBw== 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)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230612232748.3948659-2-joshdon@google.com> References: <20230612232748.3948659-2-joshdon@google.com> MIME-Version: 1.0 Message-ID: <168682909407.404.10776337626527086205.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768769918016599507?= X-GMAIL-MSGID: =?utf-8?q?1768769918016599507?= The following commit has been merged into the sched/core branch of tip: Commit-ID: 06f5576bf513824b40d535d6b872c0265bb44c0d Gitweb: https://git.kernel.org/tip/06f5576bf513824b40d535d6b872c0265bb44c0d Author: Josh Don AuthorDate: Mon, 12 Jun 2023 16:27:48 -07:00 Committer: Peter Zijlstra CommitterDate: Thu, 15 Jun 2023 13:28:20 +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) Link: https://lkml.kernel.org/r/20230612232748.3948659-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 b26ae20..eafbdb5 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -3726,6 +3726,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) { @@ -5276,6 +5306,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 ac38225..962a8d0 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -11140,6 +11140,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 */ @@ -11216,6 +11237,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 { @@ -11272,6 +11297,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) @@ -11450,6 +11493,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 b56c86c..819efad 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -4877,8 +4877,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_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 } } @@ -5385,6 +5389,17 @@ static int tg_unthrottle_up(struct task_group *tg, void *data) 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; } @@ -5400,6 +5415,10 @@ static int tg_throttle_down(struct task_group *tg, void *data) } cfs_rq->throttle_count++; + SCHED_WARN_ON(cfs_rq->throttled_clock_self); + if (cfs_rq->nr_running) + cfs_rq->throttled_clock_self = rq_clock(rq); + return 0; } diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index 556496c..46f8a01 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;