[RH7] proc/cpu/cgroup: make boottime in CT reveal the real start time

Submitted by Pavel Tikhomirov on May 7, 2019, 9:05 a.m.


Message ID 20190507090547.32333-1-ptikhomirov@virtuozzo.com
State New
Series "proc/cpu/cgroup: make boottime in CT reveal the real start time"
Headers show

Commit Message

Pavel Tikhomirov May 7, 2019, 9:05 a.m.
When we call 'ps axfw -o pid,stime' in container to show the start time
of processes of CT it looks like all of them are time travelers from the
future, these happens in case the CT was recently migrated before.

These happens because ps takes the start_time from /proc/<pid>/stat
which should be relative to the boottime, so ps adds it to the boottime
taken from /proc/stat and prints the results. But before these patch
the boottime in /proc/stat in CT is just the time of cgroup creation
(after migration), and the start_time in CT is relative to the real
boottime of CT (before the migration).

So make boottime in /proc/stat in CT be a real boottime of CT to fix
these mess. Collateral damage is that we would always see host boottime
in cpu.proc.stat files from host, but I don't think that cgroup creation
times made any sense there anyway.

Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
 kernel/sched/core.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 800d295dc7d0..c35fcbef4397 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -10409,7 +10409,13 @@  int cpu_cgroup_proc_stat(struct cgroup *cgrp, struct cftype *cft,
 	unsigned long tg_nr_forks = 0;
-	jif = boottime.tv_sec + tg->start_time.tv_sec;
+	/*
+	 * In VE0 we always show host's boottime and in VEX we show real CT
+	 * start time, even across CT migrations, as we rely on userspace to
+	 * set real_start_timespec for us on resume.
+	 */
+	jif = boottime.tv_sec + get_exec_env()->real_start_timespec.tv_sec;
 	for_each_possible_cpu(i) {
 		cpu_cgroup_update_stat(cgrp, i);