Commit 5362a354 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] Fix sys_time() to get subtick correction from the new xtime

From: "La Monte H.P. Yarroll" <piggy@timesys.com>

This is a Scott Wood patch against 2.6.3.


Use gettimeofday() rather than xtime.tv_sec in sys_time(), since
sys_stime() uses settimeofday() and thus subtracts the subtick correction
from the new xtime.

stime() used settimeofday(), but time() did not use gettimeofday().  Since
settimeofday() subtracts out the current intra-tick correction, and nsec
was 0 (since stime() only allows seconds), this resulted in xtime being
slightly earlier than the time that was set.

If time() had used gettimeofday(), the correction would have been applied,
and everything would be fine.  However, instead time just reads the current
xtime.tv_sec, so if time() is called immediately after stime(), you'll
usually get a value one second earlier.
parent cea39746
...@@ -1090,10 +1090,11 @@ asmlinkage long ...@@ -1090,10 +1090,11 @@ asmlinkage long
sys32_time (int *tloc) sys32_time (int *tloc)
{ {
int i; int i;
struct timeval tv;
do_gettimeofday(&tv);
i = tv.tv_sec;
/* SMP: This is fairly trivial. We grab CURRENT_TIME and
stuff it to user space. No side effects */
i = get_seconds();
if (tloc) { if (tloc) {
if (put_user(i, tloc)) if (put_user(i, tloc))
i = -EFAULT; i = -EFAULT;
......
...@@ -388,14 +388,16 @@ static inline long get_ts32(struct timespec *o, struct compat_timeval *i) ...@@ -388,14 +388,16 @@ static inline long get_ts32(struct timespec *o, struct compat_timeval *i)
asmlinkage long sys32_time(compat_time_t *tloc) asmlinkage long sys32_time(compat_time_t *tloc)
{ {
time_t now = get_seconds(); struct timeval tv;
compat_time_t now32 = now;
if (tloc) do_gettimeofday(&tv);
if (put_user(now32, tloc)) compat_time_t now32 = tv.tv_sec;
now32 = -EFAULT;
return now32; if (tloc)
if (put_user(now32, tloc))
now32 = -EFAULT;
return now32;
} }
asmlinkage int asmlinkage int
......
...@@ -832,10 +832,11 @@ sys32_writev(int fd, struct compat_iovec *vector, u32 count) ...@@ -832,10 +832,11 @@ sys32_writev(int fd, struct compat_iovec *vector, u32 count)
asmlinkage long sys32_time(int * tloc) asmlinkage long sys32_time(int * tloc)
{ {
int i; int i;
struct timeval tv;
do_gettimeofday(&tv);
i = tv.tv_sec;
/* SMP: This is fairly trivial. We grab CURRENT_TIME and
stuff it to user space. No side effects */
i = get_seconds();
if (tloc) { if (tloc) {
if (put_user(i,tloc)) if (put_user(i,tloc))
i = -EFAULT; i = -EFAULT;
......
...@@ -51,10 +51,11 @@ EXPORT_SYMBOL(sys_tz); ...@@ -51,10 +51,11 @@ EXPORT_SYMBOL(sys_tz);
asmlinkage long sys_time(int * tloc) asmlinkage long sys_time(int * tloc)
{ {
int i; int i;
struct timeval tv;
do_gettimeofday(&tv);
i = tv.tv_sec;
/* SMP: This is fairly trivial. We grab CURRENT_TIME and
stuff it to user space. No side effects */
i = get_seconds();
if (tloc) { if (tloc) {
if (put_user(i,tloc)) if (put_user(i,tloc))
i = -EFAULT; i = -EFAULT;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment