[RFC][PATCH 0/1] sched/cputime: Improve getrusage(RUSAGE_THREAD) with nohz_full

From: Hasegawa Hitomi
Date: Tue Sep 28 2021 - 01:15:50 EST


Frederic, seems busy, so I create the proper patch, would you please add
your Signed-off-by: if this fix is okey.
This patch is a fix proposed in the following thread [1].


The getrusage(RUSAGE_THREAD) with nohz_full returns shorter utime/stime
than the actual time.

In the current implementation, task_cputime_adjusted() calls task_cputime()
to get the "current" utime and stime, then calls cputime_adjust () to adjust
the sum of utime and stime to be equal to cputime.sum_exec_runtime.
In nohz_full, sum_exec_runtime is not updated regularly, which is the cause
of this discrepancy.

This patch add a process to update sum_exec_runtime after getting
the information from "current" and before adjusting.
This addition applies only when run with nohz_full.

Thanks.
Hitomi Hasegawa

[1] https://lore.kernel.org/lkml/OSBPR01MB21837C8931D90AE55AF4A955EB529@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/

--

Hasegawa Hitomi (1):
sched/cputime: Improve getrusage(RUSAGE_THREAD) with nohz_full

include/linux/sched/cputime.h | 5 +++--
kernel/sched/cputime.c | 12 +++++++++---
2 files changed, 12 insertions(+), 5 deletions(-)

--
2.25.1