Skip to contentSkip to conversation

Fix sys_time to handle intra-tick correction

PATCH In review Vinay Sridhar 2 participants 3 messages Dec 9, 2008 – Dec 10, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix sys_time to handle intra-tick correction

Hi All,

This fix changes sys_time to use do_gettimeofday instead of get_seconds. Running the stime01 test from LTP triggers this error. Calling sys_stime and then calling sys_time causes this. "do_settimeofday" subtracts the nsec offset from the nsec value(0 in this case) passed to it. Subsequently, "set_normalized_timespec" modifies sec and nsec accordingly. This compensation is handled in the do_gettimeofday path. However, sys_time does not handle this case and reports an incorrect seconds value.

signed-off by : Vinay Sridhar <[email protected]>

time.c renamed from time.c.orig +6 -1
@@ -61,7 +61,12 @@ EXPORT_SYMBOL(sys_tz);
  */
 asmlinkage long sys_time(time_t __user * tloc)
 {
-	time_t i = get_seconds();
+	struct timeval t;	
+	time_t i;
+
+	do_gettimeofday(&t);
+
+	i = t.tv_sec;
 
 	if (tloc) {
 		if (put_user(i,tloc))
#1 lore raw
Quoted 12 lines · Vinay Sridhar

Hi All,

This fix changes sys_time to use do_gettimeofday instead of get_seconds. Running the stime01 test from LTP triggers this error. Calling sys_stime and then calling sys_time causes this. "do_settimeofday" subtracts the nsec offset from the nsec value(0 in this case) passed to it. Subsequently, "set_normalized_timespec" modifies sec and nsec accordingly. This compensation is handled in the do_gettimeofday path. However, sys_time does not handle this case and reports an incorrect seconds value.

Quoted 1 line

signed-off by : Vinay Sridhar <[email protected]>

This does fix the symmetry by using the same interfaces on both sides, so it seems reasonable to me. However, since do_gettimeofday reads the clocksource hardware, this may have a slight performance impact to time() users.

I know privately I said this patch looked fine earlier, so sorry for the mixed messages, but I really think we should be able to use get_seconds() without this problem.

Looking more carefully at the code in do_settimeofday(), we should accumulate the left over cycles, then we set the current time to the specified time and update the xtime_cache.

So I'm not sure if we're really fixing the right issue here. Further, running on the x86_64 system, I don't see this issue crop up at all (for either 64 or 32 bit binaries). I think you mentioned privately that this was seen on i386, so maybe we need to dig just a bit deeper before going with this fix.

And sorry again for running hot then cold on this patch. I just didn't look deeply enough at the issue the first time around. :(

thanks
-john

Quoted 18 lines
time.c renamed from time.c.orig +6 -1
@@ -61,7 +61,12 @@ EXPORT_SYMBOL(sys_tz);
  */
 asmlinkage long sys_time(time_t __user * tloc)
 {
-	time_t i = get_seconds();
+	struct timeval t;	
+	time_t i;
+
+	do_gettimeofday(&t);
+
+	i = t.tv_sec;
 
 	if (tloc) {
 		if (put_user(i,tloc))
#2 lore raw
Quoted 28 lines · john stultz
Quoted 12 lines · Vinay Sridhar

Hi All,

This fix changes sys_time to use do_gettimeofday instead of get_seconds. Running the stime01 test from LTP triggers this error. Calling sys_stime and then calling sys_time causes this. "do_settimeofday" subtracts the nsec offset from the nsec value(0 in this case) passed to it. Subsequently, "set_normalized_timespec" modifies sec and nsec accordingly. This compensation is handled in the do_gettimeofday path. However, sys_time does not handle this case and reports an incorrect seconds value.

Quoted 1 line

signed-off by : Vinay Sridhar <[email protected]>

This does fix the symmetry by using the same interfaces on both sides, so it seems reasonable to me. However, since do_gettimeofday reads the clocksource hardware, this may have a slight performance impact to time() users.

I know privately I said this patch looked fine earlier, so sorry for the mixed messages, but I really think we should be able to use get_seconds() without this problem.

Looking more carefully at the code in do_settimeofday(), we should accumulate the left over cycles, then we set the current time to the specified time and update the xtime_cache.

Quoted 8 lines

So I'm not sure if we're really fixing the right issue here. Further, running on the x86_64 system, I don't see this issue crop up at all (for either 64 or 32 bit binaries). I think you mentioned privately that this was seen on i386, so maybe we need to dig just a bit deeper before going with this fix.

And sorry again for running hot then cold on this patch. I just didn't look deeply enough at the issue the first time around. :(

Hey Vinay,
So I spent some time checking various kernels and it seems this issue
is already resolved upstream by the clocksource_forward_now() change:
9a055117d3d9cb562f83f8d4cd88772761f4cab0

http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=9a055117d3d9cb562f83f8d4cd88772761f4cab0

thanks
-john