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

Submitted by Konstantin Khorenko on May 21, 2019, 3:29 p.m.


Message ID 201905211529.x4LFTJuB025972@finist-ce7.sw.ru
State New
Series "proc/cpu/cgroup: make boottime in CT reveal the real start time"
Headers show

Commit Message

Konstantin Khorenko May 21, 2019, 3:29 p.m.
The commit is pushed to "branch-rh7-3.10.0-957.12.2.vz7.96.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-957.12.2.vz7.96.1
commit d822c01403c5eeed69a9e46ea26bcf7559f3603e
Author: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
Date:   Tue May 21 18:29:19 2019 +0300

    proc/cpu/cgroup: make boottime in CT reveal the real start time
    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 3d0d901e89bd..3e7c8004dafd 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -10433,7 +10433,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);