Skip to contentSkip to conversation

cgroup: Fix rootcg cpu.stat guest double counting

PATCH In review Dan Schatzberg 4 participants 4 messages Oct 28, 2021 – Nov 15, 2021 cgroup

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cgroup: Fix rootcg cpu.stat guest double counting

In account_guest_time in kernel/sched/cputime.c guest time is attributed to both CPUTIME_NICE and CPUTIME_USER in addition to CPUTIME_GUEST_NICE and CPUTIME_GUEST respectively. Therefore, adding both to calculate usage results in double counting any guest time at the rootcg.

Fixes 936f2a70f207 ("cgroup: add cpu.stat file to root cgroup")
---
 kernel/cgroup/rstat.c | 2 --
 1 file changed, 2 deletions(-)
kernel/cgroup/rstat.c +0 -2
index b264ab5652ba..1486768f2318 100644
@@ -433,8 +433,6 @@ static void root_cgroup_cputime(struct task_cputime *cputime)
 		cputime->sum_exec_runtime += user;
 		cputime->sum_exec_runtime += sys;
 		cputime->sum_exec_runtime += cpustat[CPUTIME_STEAL];
-		cputime->sum_exec_runtime += cpustat[CPUTIME_GUEST];
-		cputime->sum_exec_runtime += cpustat[CPUTIME_GUEST_NICE];
 	}
 }
 
Signature · 1 line
2.30.2
#1 lore raw
Quoted 5 lines · Dan Schatzberg

In account_guest_time in kernel/sched/cputime.c guest time is attributed to both CPUTIME_NICE and CPUTIME_USER in addition to CPUTIME_GUEST_NICE and CPUTIME_GUEST respectively. Therefore, adding both to calculate usage results in double counting any guest time at the rootcg.

Yes, definitely a bug. The same fix was posted a couple months ago as part of a series but never picked up:

https://x-lore.kernel.org/all/20210820094005.20596-3-arbn-XoJtRXgx1JtgGdypvdXH1w@public.gmane.org/

The series also touched cputime, so we might be waiting for scheduler
folks? +Ingo +Peter +Andrey

#2 lore raw
Quoted 7 lines · Daniel Jordan
Quoted 5 lines · Dan Schatzberg

In account_guest_time in kernel/sched/cputime.c guest time is attributed to both CPUTIME_NICE and CPUTIME_USER in addition to CPUTIME_GUEST_NICE and CPUTIME_GUEST respectively. Therefore, adding both to calculate usage results in double counting any guest time at the rootcg.

Quoted 8 lines

Yes, definitely a bug. The same fix was posted a couple months ago as part of a series but never picked up:

https://x-lore.kernel.org/all/[email protected]/

The series also touched cputime, so we might be waiting for scheduler
folks? +Ingo +Peter +Andrey

Yeah, I'll do rebase and send v3

maintainer
#3 lore raw
In reply to Dan Schatzberg
Quoted 8 lines · Dan Schatzberg

In account_guest_time in kernel/sched/cputime.c guest time is attributed to both CPUTIME_NICE and CPUTIME_USER in addition to CPUTIME_GUEST_NICE and CPUTIME_GUEST respectively. Therefore, adding both to calculate usage results in double counting any guest time at the rootcg.

Fixes 936f2a70f207 ("cgroup: add cpu.stat file to root cgroup")

Applying to cgroup/for-5.16.

Thanks.

Signature · 1 line
tejun