mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
To: Albert Cahalan <albert@users.sourceforge.net>
Cc: linux-kernel mailing list <linux-kernel@vger.kernel.org>,
	voland@dmz.com.pl, nicolas.george@ens.fr,
	kaukasoi@elektroni.ee.tut.fi, tim@physik3.uni-rostock.de,
	george@mvista.com, johnstul@us.ibm.com,
	david+powerix@blue-labs.org, Andrew Morton OSDL <akpm@osdl.org>
Subject: Re: boot time, process start time, and NOW time
Date: Tue, 29 Jun 2004 02:56:52 +0900	[thread overview]
Message-ID: <87smcf5zx7.fsf@devron.myhome.or.jp> (raw)
In-Reply-To: <1087948634.9831.1154.camel@cube>

Albert Cahalan <albert@users.sf.net> writes:

> Even with the 2.6.7 kernel, I'm still getting reports of process
> start times wandering. Here is an example:
> 
>    "About 12 hours since reboot to 2.6.7 there was already a
>    difference of about 7 seconds between the real start time
>    and the start time reported by ps. Now, 24 hours since reboot
>    the difference is 10 seconds."
> 
> The calculation used is:
> 
>    now - uptime + time_from_boot_to_process_start

Start-time and uptime is using different source. Looks like the
jiffies was added bogus lost counts.

quick hack. Does this change the behavior?
-- 
OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>

---

 arch/i386/kernel/smpboot.c          |   16 +++++++++-------
 arch/i386/kernel/timers/timer_tsc.c |    8 ++++++--
 include/linux/time.h                |    2 +-
 3 files changed, 16 insertions(+), 10 deletions(-)

diff -puN arch/i386/kernel/timers/timer_tsc.c~uptime-fix arch/i386/kernel/timers/timer_tsc.c
--- linux-2.6.7/arch/i386/kernel/timers/timer_tsc.c~uptime-fix	2004-06-29 01:21:26.000000000 +0900
+++ linux-2.6.7-hirofumi/arch/i386/kernel/timers/timer_tsc.c	2004-06-29 01:21:26.000000000 +0900
@@ -467,8 +467,6 @@ static int __init init_tsc(char* overrid
  	 *	moaned if you have the only one in the world - you fix it!
  	 */
 
-	count2 = LATCH; /* initialize counter for mark_offset_tsc() */
-
 	if (cpu_has_tsc) {
 		unsigned long tsc_quotient;
 #ifdef CONFIG_HPET_TIMER
@@ -512,6 +510,12 @@ static int __init init_tsc(char* overrid
 				printk("Detected %lu.%03lu MHz processor.\n", cpu_khz / 1000, cpu_khz % 1000);
 			}
 			set_cyc2ns_scale(cpu_khz/1000);
+
+			/* initialize for mark_offset_tsc() */
+			count2 = LATCH;
+			rdtsc(last_tsc_low, last_tsc_high);
+			printk("initial tsc: %lu.%lu\n",
+				last_tsc_high, last_tsc_low);
 			return 0;
 		}
 	}
diff -puN include/linux/time.h~uptime-fix include/linux/time.h
--- linux-2.6.7/include/linux/time.h~uptime-fix	2004-06-29 01:21:26.000000000 +0900
+++ linux-2.6.7-hirofumi/include/linux/time.h	2004-06-29 01:21:26.000000000 +0900
@@ -41,7 +41,7 @@ struct timezone {
  * Have the 32 bit jiffies value wrap 5 minutes after boot
  * so jiffies wrap bugs show up earlier.
  */
-#define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
+#define INITIAL_JIFFIES		(-300L*HZ)
 
 /*
  * Change timeval to jiffies, trying to avoid the
diff -puN arch/i386/kernel/smpboot.c~uptime-fix arch/i386/kernel/smpboot.c
--- linux-2.6.7/arch/i386/kernel/smpboot.c~uptime-fix	2004-06-29 01:25:59.000000000 +0900
+++ linux-2.6.7-hirofumi/arch/i386/kernel/smpboot.c	2004-06-29 01:34:55.000000000 +0900
@@ -210,6 +210,8 @@ static unsigned long long __init div64 (
 	return res;
 }
 
+static unsigned long __initdata sync_tsc_high, sync_tsc_low;
+
 static void __init synchronize_tsc_bp (void)
 {
 	int i;
@@ -251,11 +253,6 @@ static void __init synchronize_tsc_bp (v
 		atomic_inc(&tsc_count_start);
 
 		rdtscll(tsc_values[smp_processor_id()]);
-		/*
-		 * We clear the TSC in the last loop:
-		 */
-		if (i == NR_LOOPS-1)
-			write_tsc(0, 0);
 
 		/*
 		 * Wait for all APs to leave the synchronization point:
@@ -264,8 +261,14 @@ static void __init synchronize_tsc_bp (v
 			mb();
 		atomic_set(&tsc_count_start, 0);
 		wmb();
+
+		/* We save the TSC in the last loop: */
+		if (i == NR_LOOPS-1)
+			rdtsc(sync_tsc_low, sync_tsc_high);
+
 		atomic_inc(&tsc_count_stop);
 	}
+	write_tsc(sync_tsc_low, sync_tsc_high);
 
 	sum = 0;
 	for (i = 0; i < NR_CPUS; i++) {
@@ -323,12 +326,11 @@ static void __init synchronize_tsc_ap (v
 			mb();
 
 		rdtscll(tsc_values[smp_processor_id()]);
-		if (i == NR_LOOPS-1)
-			write_tsc(0, 0);
 
 		atomic_inc(&tsc_count_stop);
 		while (atomic_read(&tsc_count_stop) != num_booting_cpus()) mb();
 	}
+	write_tsc(sync_tsc_low, sync_tsc_high);
 }
 #undef NR_LOOPS
 

_

  reply	other threads:[~2004-06-28 17:58 UTC|newest]

Thread overview: 57+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-22 23:57 Albert Cahalan
2004-06-28 17:56 ` OGAWA Hirofumi [this message]
2004-08-16 19:41   ` Andrew Morton
2004-08-16 21:49     ` john stultz
2004-08-16 23:08     ` Tim Schmielau
2004-08-16 23:56       ` Tim Schmielau
2004-08-17  0:21       ` john stultz
2004-08-17  0:37         ` George Anzinger
2004-08-17  0:49           ` john stultz
2004-08-17  0:31       ` George Anzinger
2004-08-16 22:32         ` Albert Cahalan
2004-08-17  1:26           ` George Anzinger
2004-08-16 23:08             ` Albert Cahalan
2004-08-17  1:54               ` James Courtier-Dutton
2004-08-17  2:03                 ` Lee Revell
2004-08-17 20:52                 ` George Anzinger
2004-08-17  6:56         ` Tim Schmielau
2004-08-17 20:07           ` john stultz
2004-08-17 20:13             ` [RFC] New timeofday implementation proposal john stultz
2004-08-17 20:58               ` [RFC] New timeofday code john stultz
2004-09-01 23:16               ` [RFC] New timeofday implementation proposal Christoph Lameter
2004-08-16 23:24     ` boot time, process start time, and NOW time Albert Cahalan
2004-08-17 19:00       ` john stultz
2004-08-17 17:41         ` Albert Cahalan
2004-08-17 20:58           ` john stultz
2004-08-17 20:25     ` [PATCH] " Tim Schmielau
2004-08-17 22:24       ` George Anzinger
2004-08-17 22:37         ` john stultz
2004-08-17 23:07           ` Tim Schmielau
2004-08-18  0:11             ` john stultz
2004-08-17 22:19               ` Albert Cahalan
2004-08-18  1:09                 ` john stultz
2004-08-17 22:45                   ` Albert Cahalan
2004-08-18  7:42                   ` Tim Schmielau
2004-08-19 19:15                     ` Petri Kaukasoina
2004-08-26 11:04                       ` Andrew Morton
2004-08-26 12:07                         ` Tim Schmielau
2004-08-30 23:00                           ` Tim Schmielau
2004-08-30 23:38                             ` john stultz
2004-08-31  0:37                               ` Albert Cahalan
2004-08-31  0:49                                 ` Tim Schmielau
2004-08-31  0:45                               ` Tim Schmielau
2004-08-31  1:23                                 ` john stultz
2004-08-31  1:34                             ` john stultz
2004-08-31  6:07                               ` Tim Schmielau
2004-08-31 19:27                                 ` George Anzinger
2004-08-31 20:56                                   ` john stultz
2004-08-31 21:10                                     ` David Ford
2004-09-02 20:39                                     ` George Anzinger
2004-09-01 19:14                                 ` OGAWA Hirofumi
2004-09-02 20:58                                   ` George Anzinger
2004-09-02 21:38                                     ` OGAWA Hirofumi
2004-09-03  0:59                                       ` George Anzinger
2004-09-03  3:35                                         ` OGAWA Hirofumi
2004-09-03  7:31                                           ` George Anzinger
2004-09-03  7:51                                             ` Tim Schmielau
2004-09-03  7:15                                       ` Tim Schmielau

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87smcf5zx7.fsf@devron.myhome.or.jp \
    --to=hirofumi@mail.parknet.co.jp \
    --cc=akpm@osdl.org \
    --cc=albert@users.sourceforge.net \
    --cc=david+powerix@blue-labs.org \
    --cc=george@mvista.com \
    --cc=johnstul@us.ibm.com \
    --cc=kaukasoi@elektroni.ee.tut.fi \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nicolas.george@ens.fr \
    --cc=tim@physik3.uni-rostock.de \
    --cc=voland@dmz.com.pl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome