Linux MIPS Architecture development
 help / color / mirror / Atom feed
* [patch] More time fixes: do_gettimeofday() & do_settimeofday()
@ 2003-08-01 12:04 Maciej W. Rozycki
  2003-08-01 17:24 ` Jun Sun
  2003-08-02 17:05 ` Ralf Baechle
  0 siblings, 2 replies; 5+ messages in thread
From: Maciej W. Rozycki @ 2003-08-01 12:04 UTC (permalink / raw)
  To: Ralf Baechle; +Cc: linux-mips

Hello,

 Here are fixes for do_gettimeofday() and do_settimeofday() not taking the
wall time and the value of tick properly into account.  OK to apply? 

  Maciej

-- 
+  Maciej W. Rozycki, Technical University of Gdansk, Poland   +
+--------------------------------------------------------------+
+        e-mail: macro@ds2.pg.gda.pl, PGP key available        +

patch-mips-2.4.21-20030725-mips-timeofday-0
diff -up --recursive --new-file linux-mips-2.4.21-20030725.macro/arch/mips/kernel/time.c linux-mips-2.4.21-20030725/arch/mips/kernel/time.c
--- linux-mips-2.4.21-20030725.macro/arch/mips/kernel/time.c	2003-07-25 02:56:34.000000000 +0000
+++ linux-mips-2.4.21-20030725/arch/mips/kernel/time.c	2003-07-31 21:27:18.000000000 +0000
@@ -18,6 +18,7 @@
 #include <linux/sched.h>
 #include <linux/param.h>
 #include <linux/time.h>
+#include <linux/timex.h>
 #include <linux/smp.h>
 #include <linux/kernel_stat.h>
 #include <linux/spinlock.h>
@@ -70,22 +71,23 @@ int (*rtc_set_mmss)(unsigned long);
  */
 void do_gettimeofday(struct timeval *tv)
 {
-	unsigned long flags;
+	unsigned long flags, lost;
 
 	read_lock_irqsave(&xtime_lock, flags);
+
 	*tv = xtime;
 	tv->tv_usec += do_gettimeoffset();
-
 	/*
-	 * xtime is atomically updated in timer_bh. jiffies - wall_jiffies
-	 * is nonzero if the timer bottom half hasnt executed yet.
+	 * xtime is atomically updated in timer_bh.  jiffies - wall_jiffies
+	 * is nonzero if the timer bottom half hasn't executed yet.
 	 */
-	if (jiffies - wall_jiffies)
-		tv->tv_usec += USECS_PER_JIFFY;
+	lost = jiffies - wall_jiffies;
+	if (lost)
+		tv->tv_usec += lost * tick;
 
 	read_unlock_irqrestore(&xtime_lock, flags);
 
-	if (tv->tv_usec >= 1000000) {
+	while (tv->tv_usec >= 1000000) {
 		tv->tv_usec -= 1000000;
 		tv->tv_sec++;
 	}
@@ -95,18 +97,20 @@ void do_settimeofday(struct timeval *tv)
 {
 	write_lock_irq(&xtime_lock);
 
-	/* This is revolting. We need to set the xtime.tv_usec
-	 * correctly. However, the value in this location is
-	 * is value at the last tick.
-	 * Discover what correction gettimeofday
-	 * would have done, and then undo it!
+	/*
+	 * This is revolting.  We need to set "xtime" correctly.  However,
+	 * the value in this location is the value at the most recent update
+	 * of wall time.  Discover what correction gettimeofday() would have
+	 * done, and then undo it!
 	 */
 	tv->tv_usec -= do_gettimeoffset();
+	tv->tv_usec -= (jiffies - wall_jiffies) * tick;
 
-	if (tv->tv_usec < 0) {
+	while (tv->tv_usec < 0) {
 		tv->tv_usec += 1000000;
 		tv->tv_sec--;
 	}
+
 	xtime = *tv;
 	time_adjust = 0;			/* stop active adjtime() */
 	time_status |= STA_UNSYNC;

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [patch] More time fixes: do_gettimeofday() & do_settimeofday()
  2003-08-01 12:04 [patch] More time fixes: do_gettimeofday() & do_settimeofday() Maciej W. Rozycki
@ 2003-08-01 17:24 ` Jun Sun
  2003-08-04 14:29   ` Maciej W. Rozycki
  2003-08-02 17:05 ` Ralf Baechle
  1 sibling, 1 reply; 5+ messages in thread
From: Jun Sun @ 2003-08-01 17:24 UTC (permalink / raw)
  To: Maciej W. Rozycki; +Cc: Ralf Baechle, linux-mips, jsun

On Fri, Aug 01, 2003 at 02:04:29PM +0200, Maciej W. Rozycki wrote:
> Hello,
> 
>  Here are fixes for do_gettimeofday() and do_settimeofday() not taking the
> wall time and the value of tick properly into account.  OK to apply? 
>

That looks right to me.  I have fixed them internally, but never get around
to push into the linux-mips tree.

To be nit-picking, I might want to replace 'tick' with 'USECS_PER_JIFFY'.

Jun

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [patch] More time fixes: do_gettimeofday() & do_settimeofday()
  2003-08-01 12:04 [patch] More time fixes: do_gettimeofday() & do_settimeofday() Maciej W. Rozycki
  2003-08-01 17:24 ` Jun Sun
@ 2003-08-02 17:05 ` Ralf Baechle
  2003-08-04 14:31   ` Maciej W. Rozycki
  1 sibling, 1 reply; 5+ messages in thread
From: Ralf Baechle @ 2003-08-02 17:05 UTC (permalink / raw)
  To: Maciej W. Rozycki; +Cc: linux-mips

On Fri, Aug 01, 2003 at 02:04:29PM +0200, Maciej W. Rozycki wrote:

>  Here are fixes for do_gettimeofday() and do_settimeofday() not taking the
> wall time and the value of tick properly into account.  OK to apply? 

Yes, looks good.  One user less of USECS_PER_JIFFY ...

  Ralf

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [patch] More time fixes: do_gettimeofday() & do_settimeofday()
  2003-08-01 17:24 ` Jun Sun
@ 2003-08-04 14:29   ` Maciej W. Rozycki
  0 siblings, 0 replies; 5+ messages in thread
From: Maciej W. Rozycki @ 2003-08-04 14:29 UTC (permalink / raw)
  To: Jun Sun; +Cc: Ralf Baechle, linux-mips

On Fri, 1 Aug 2003, Jun Sun wrote:

> To be nit-picking, I might want to replace 'tick' with 'USECS_PER_JIFFY'.

 OK -- since I want to keep USECS_PER_JIFFY_FRAC as otherwise
unrecoverable, I decided to keep USECS_PER_JIFFY as well for consistency. 
But that's only after (or together with) the next patch. 

-- 
+  Maciej W. Rozycki, Technical University of Gdansk, Poland   +
+--------------------------------------------------------------+
+        e-mail: macro@ds2.pg.gda.pl, PGP key available        +

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [patch] More time fixes: do_gettimeofday() & do_settimeofday()
  2003-08-02 17:05 ` Ralf Baechle
@ 2003-08-04 14:31   ` Maciej W. Rozycki
  0 siblings, 0 replies; 5+ messages in thread
From: Maciej W. Rozycki @ 2003-08-04 14:31 UTC (permalink / raw)
  To: Ralf Baechle; +Cc: linux-mips

On Sat, 2 Aug 2003, Ralf Baechle wrote:

> >  Here are fixes for do_gettimeofday() and do_settimeofday() not taking the
> > wall time and the value of tick properly into account.  OK to apply? 
> 
> Yes, looks good.  One user less of USECS_PER_JIFFY ...

 Actually, I decided to keep USECS_PER_JIFFY, only redefining it more
sanely.

-- 
+  Maciej W. Rozycki, Technical University of Gdansk, Poland   +
+--------------------------------------------------------------+
+        e-mail: macro@ds2.pg.gda.pl, PGP key available        +

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-08-04 14:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-08-01 12:04 [patch] More time fixes: do_gettimeofday() & do_settimeofday() Maciej W. Rozycki
2003-08-01 17:24 ` Jun Sun
2003-08-04 14:29   ` Maciej W. Rozycki
2003-08-02 17:05 ` Ralf Baechle
2003-08-04 14:31   ` Maciej W. Rozycki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox