[Devel] [PATCH RHEL8 COMMIT] ve/time: rework times() syscall and /proc/[pid]/stat to handle u64 time offsets

Konstantin Khorenko khorenko at virtuozzo.com
Wed Oct 14 15:50:45 MSK 2020


The commit is pushed to "branch-rh8-4.18.0-193.6.3.vz8.4.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-193.6.3.vz8.4.12
------>
commit dcfbbefff2072fa969eb5ec103748a6b74d077c6
Author: Konstantin Khorenko <khorenko at virtuozzo.com>
Date:   Tue Oct 6 19:04:32 2020 +0300

    ve/time: rework times() syscall and /proc/[pid]/stat to handle u64 time offsets
    
    ve_struct.{start_time,real_start_time} are u64 now, change the code
    correspondingly.
    
    Drop duplicated fields start_timespec/real_start_timespec in ve_struct.
    
    Fixes: f2716576136d ("ve/time: Use ve_relative_clock in times() syscall
    and /proc/[pid]/stat")
    
    Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
---
 fs/proc/array.c    |  7 ++-----
 include/linux/ve.h |  4 ----
 kernel/sys.c       | 19 ++++++++-----------
 3 files changed, 10 insertions(+), 20 deletions(-)

diff --git a/fs/proc/array.c b/fs/proc/array.c
index e85d0caa6efa..e9b6e403858a 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -546,11 +546,8 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
 
 #ifdef CONFIG_VE
 	if (!is_super) {
-		struct timespec *ve_start_ts =
-				&get_exec_env()->real_start_timespec;
-		start_time -=
-			(unsigned long long)ve_start_ts->tv_sec * NSEC_PER_SEC
-				+ ve_start_ts->tv_nsec;
+		u64 offset = get_exec_env()->real_start_time;
+		start_time -= (unsigned long long)offset;
 	}
 	/* tasks inside a CT can have negative start time e.g. if the CT was
 	 * migrated from another hw node, in which case we will report 0 in
diff --git a/include/linux/ve.h b/include/linux/ve.h
index b659e779cb49..0db98e8e08c1 100644
--- a/include/linux/ve.h
+++ b/include/linux/ve.h
@@ -52,10 +52,6 @@ struct ve_struct {
 	struct net_device	*venet_dev;
 #endif
 
-/* per VE CPU stats*/
-	struct timespec		start_timespec;		/* monotonic time */
-	struct timespec		real_start_timespec;	/* boot based time */
-
 	/* see vzcalluser.h for VE_FEATURE_XXX definitions */
 	__u64			features;
 
diff --git a/kernel/sys.c b/kernel/sys.c
index 2644090f8d4b..df02329b0e5c 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -957,16 +957,13 @@ static void do_sys_times(struct tms *tms)
 }
 
 #ifdef CONFIG_VE
-unsigned long long ve_relative_clock(struct timespec * ts)
+static u64 ve_relative_clock(u64 time)
 {
-	unsigned long long offset = 0;
+	u64 offset = 0;
+	struct ve_struct *ve = get_exec_env();
 
-	if (ts->tv_sec > get_exec_env()->start_timespec.tv_sec ||
-	    (ts->tv_sec == get_exec_env()->start_timespec.tv_sec &&
-	     ts->tv_nsec >= get_exec_env()->start_timespec.tv_nsec))
-		offset = (unsigned long long)(ts->tv_sec -
-			get_exec_env()->start_timespec.tv_sec) * NSEC_PER_SEC
-			+ ts->tv_nsec -	get_exec_env()->start_timespec.tv_nsec;
+	if (time > ve->start_time)
+		offset = time - ve->start_time;
 	return nsec_to_clock_t(offset);
 }
 #endif
@@ -974,7 +971,7 @@ unsigned long long ve_relative_clock(struct timespec * ts)
 SYSCALL_DEFINE1(times, struct tms __user *, tbuf)
 {
 #ifdef CONFIG_VE
-	struct timespec now;
+	u64 now;
 #endif
 
 	if (tbuf) {
@@ -989,9 +986,9 @@ SYSCALL_DEFINE1(times, struct tms __user *, tbuf)
 	return (long) jiffies_64_to_clock_t(get_jiffies_64());
 #else
 	/* Compare to calculation in fs/proc/array.c */
-	ktime_get_ts(&now);
+	now = ktime_get_ns();
 	force_successful_syscall_return();
-	return ve_relative_clock(&now);
+	return (long) ve_relative_clock(now);
 #endif
 }
 


More information about the Devel mailing list