All Virtuozzo development lists (kernel + QEMU)
 help / color / mirror / Atom feed
From: Vasileios Almpanis <vasileios.almpanis@virtuozzo.com>
To: Konstantin Khorenko <khorenko@virtuozzo.com>,
	Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Cc: devel@openvz.org
Subject: [Devel] [PATCH hci-8.1 3/4] sched: account sleep and block time of a task group entity
Date: Wed, 14 Oct 2026 11:16:26 +0000	[thread overview]
Message-ID: <20261014-ct-iowait-v1-3-9d65fe37cf89@virtuozzo.com> (raw)
In-Reply-To: <20261014-ct-iowait-v1-0-9d65fe37cf89@virtuozzo.com>

CT idle and iowait in cpu.proc.stat come from the schedstats of the
group entity: cpu_cgroup_update_stat() reads iowait_sum and
sum_sleep_runtime. But only tasks get sleep_start/block_start, so for
a group both stay 0 and the CT shows 0 idle and 0 iowait.
fixup_vcpustat_delta() then gives all idle time of the CT's /proc/stat
to IDLE, so iowait there is always 0 too.

vz7 dequeue_sleeper() had a branch for group entities that was lost
when porting to newer kernels. Restore it in update_stats_dequeue_fair():
when a group entity is dequeued on sleep, start a block period if its
cfs_rq has iowait sleepers and a sleep period otherwise. The existing
enqueue path closes it.

Like on vz7, skip throttled groups, they are not idle, just waiting
for bandwidth. If a group has nothing to run when it is unthrottled,
tg_unthrottle_up() doesn't enqueue it, so start its period there.

https://virtuozzo.atlassian.net/browse/VSTOR-147823
Fixes: 095994c57b84 ("ve/sched/stat: Introduce functions to calculate vcpustat data")
Signed-off-by: Vasileios Almpanis <vasileios.almpanis@virtuozzo.com>

Feature: sched: emulate virtual cpus for Containers
---
 kernel/sched/fair.c | 30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index df296edb828d..2df5a9b47480 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -1332,6 +1332,21 @@ update_stats_enqueue_fair(struct cfs_rq *cfs_rq, struct sched_entity *se, int fl
 		update_stats_enqueue_sleeper_fair(cfs_rq, se);
 }
 
+static inline int throttled_hierarchy(struct cfs_rq *cfs_rq);
+
+/* The group goes idle, blocked if it has iowait sleepers */
+static inline void
+update_stats_group_sleep_start(struct cfs_rq *cfs_rq, struct sched_entity *se)
+{
+	struct sched_statistics *stats;
+
+	stats = __schedstats_from_se(se);
+	if (group_cfs_rq(se)->nr_iowait)
+		__schedstat_set(stats->block_start, rq_clock(rq_of(cfs_rq)));
+	else
+		__schedstat_set(stats->sleep_start, rq_clock(rq_of(cfs_rq)));
+}
+
 static inline void
 update_stats_dequeue_fair(struct cfs_rq *cfs_rq, struct sched_entity *se, int flags)
 {
@@ -1358,6 +1373,9 @@ update_stats_dequeue_fair(struct cfs_rq *cfs_rq, struct sched_entity *se, int fl
 		if (state & TASK_UNINTERRUPTIBLE)
 			__schedstat_set(tsk->stats.block_start,
 				      rq_clock(rq_of(cfs_rq)));
+	} else if ((flags & DEQUEUE_SLEEP) &&
+		   !throttled_hierarchy(group_cfs_rq(se))) {
+		update_stats_group_sleep_start(cfs_rq, se);
 	}
 }
 
@@ -3825,8 +3843,6 @@ static void reweight_task_fair(struct rq *rq, struct task_struct *p,
 	load->inv_weight = lw->inv_weight;
 }
 
-static inline int throttled_hierarchy(struct cfs_rq *cfs_rq);
-
 #ifdef CONFIG_FAIR_GROUP_SCHED
 /*
  * All this does is approximate the hierarchical proportion which includes that
@@ -5904,6 +5920,7 @@ static int tg_unthrottle_up(struct task_group *tg, void *data)
 {
 	struct rq *rq = data;
 	struct cfs_rq *cfs_rq = tg->cfs_rq[cpu_of(rq)];
+	struct sched_entity *se = tg->se[cpu_of(rq)];
 	struct task_struct *p, *tmp;
 
 	if (--cfs_rq->throttle_count)
@@ -5933,6 +5950,15 @@ static int tg_unthrottle_up(struct task_group *tg, void *data)
 		enqueue_task_fair(rq_of(cfs_rq), p, ENQUEUE_WAKEUP);
 	}
 
+	/*
+	 * The group may have gone idle while throttled, when no sleep or
+	 * block period is started for it. Start it now if nothing runs.
+	 */
+	if (schedstat_enabled() && se && !se->on_rq && !cfs_rq->nr_queued &&
+	    !schedstat_val(__schedstats_from_se(se)->sleep_start) &&
+	    !schedstat_val(__schedstats_from_se(se)->block_start))
+		update_stats_group_sleep_start(cfs_rq_of(se), se);
+
 	/* 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);

-- 
2.43.0

_______________________________________________
Devel mailing list
Devel@openvz.org
https://lists.openvz.org/mailman/listinfo/devel

  parent reply	other threads:[~2026-10-14 11:18 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-14 11:16 [Devel] [PATCH hci-8.1 0/4] sched: restore Container iowait accounting Vasileios Almpanis
2026-10-14 11:16 ` [Devel] [PATCH hci-8.1 1/4] sched: fix cfs_rq::nr_iowait leak on the remote wakeup path Vasileios Almpanis
2026-10-14 11:23   ` no-reply
2026-10-14 11:16 ` [Devel] [PATCH hci-8.1 2/4] sched: keep cfs_rq::nr_iowait balanced for throttled and class changing tasks Vasileios Almpanis
2026-10-14 11:24   ` no-reply
2026-10-14 11:16 ` Vasileios Almpanis [this message]
2026-10-14 11:28   ` [Devel] [PATCH hci-8.1 3/4] sched: account sleep and block time of a task group entity no-reply
2026-10-14 11:36     ` Vasileios Almpanis
2026-10-14 11:16 ` [Devel] [PATCH hci-8.1 4/4] sched: switch a sleeping task group entity between idle and iowait Vasileios Almpanis
2026-10-14 11:27   ` no-reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261014-ct-iowait-v1-3-9d65fe37cf89@virtuozzo.com \
    --to=vasileios.almpanis@virtuozzo.com \
    --cc=devel@openvz.org \
    --cc=khorenko@virtuozzo.com \
    --cc=ptikhomirov@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.