All of lore.kernel.org
 help / color / mirror / Atom feed
From: Con Kolivas <kernel@kolivas.org>
To: vatsa@in.ibm.com
Cc: linux-kernel@vger.kernel.org, akpm@osdl.org,
	ck list <ck@vds.kolivas.org>
Subject: [PATCH 2/3] dyntick - Fix lost tick calculation in timer pm.c
Date: Sat, 3 Sep 2005 01:45:18 +1000	[thread overview]
Message-ID: <200509030145.18368.kernel@kolivas.org> (raw)
In-Reply-To: <200509030143.57782.kernel@kolivas.org>

[-- Attachment #1: Type: text/plain, Size: 13 bytes --]



Con
---




[-- Attachment #2: dyntick-Fix_lost_tick_calculation_in_timer_pm_c.patch --]
[-- Type: text/x-diff, Size: 4267 bytes --]

Currently, lost tick calculation in timer_pm.c is based on number
of microseconds that has elapsed since the last tick. Calculating
the number of microseconds is approximated by cyc2us, which
basically does :

	microsec = (cycles * 286) / 1024

Consider 10 ticks lost. This amounts to 14319*10 = 143190 cycles 
(14319 = PMTMR_EXPECTED_RATE/(CALIBRATE_LATCH/LATCH)).
This amount to 39992 microseconds as per the above equation 
or 39992 / 4000 = 9 lost ticks, which is incorrect.

I feel lost ticks can be based on cycles difference directly
rather than being based on microseconds that has elapsed.

Following patch is in that direction. 

With this patch, time had kept up really well on one particular
machine (Intel 4way Pentium 3 box) overnight, while
on another newer machine (Intel 4way Xeon with HT) it didnt do so
well (time sped up after 3 or 4 hours). Hence I consider this
particular patch will need more review/work.

Fix lost tick calculation in timer_pm.c

Code by: Srivatsa Vaddagiri <vatsa@in.ibm.com>

Index: linux-2.6.13-mm1/arch/i386/kernel/timers/timer_pm.c
===================================================================
--- linux-2.6.13-mm1.orig/arch/i386/kernel/timers/timer_pm.c	2005-09-03 01:11:55.000000000 +1000
+++ linux-2.6.13-mm1/arch/i386/kernel/timers/timer_pm.c	2005-09-03 01:12:11.000000000 +1000
@@ -31,6 +31,8 @@
   ((CALIBRATE_LATCH * (PMTMR_TICKS_PER_SEC >> 10)) / (CLOCK_TICK_RATE>>10))
 
 
+static int pm_ticks_per_jiffy = PMTMR_EXPECTED_RATE / (CALIBRATE_LATCH/LATCH);
+
 /* The I/O port the PMTMR resides at.
  * The location is detected during setup_arch(),
  * in arch/i386/acpi/boot.c */
@@ -38,8 +40,7 @@ u32 pmtmr_ioport = 0;
 
 
 /* value of the Power timer at last timer interrupt */
-static u32 offset_tick;
-static u32 offset_delay;
+static u32 offset_last;
 
 static unsigned long long monotonic_base;
 static seqlock_t monotonic_lock = SEQLOCK_UNLOCKED;
@@ -128,6 +129,11 @@ pm_good:
 	if (verify_pmtmr_rate() != 0)
 		return -ENODEV;
 
+	printk ("Using %u PM timer ticks per jiffy \n", pm_ticks_per_jiffy);
+
+	offset_last = read_pmtmr();
+	setup_pit_timer();
+
 	init_cpu_khz();
 	set_dyn_tick_max_skip((0xFFFFFF / (286 * 1000000)) * 1024 * HZ);
 	return 0;
@@ -152,47 +158,37 @@ static inline u32 cyc2us(u32 cycles)
  */
 static void mark_offset_pmtmr(void)
 {
-	u32 lost, delta, last_offset;
-	static int first_run = 1;
-	last_offset = offset_tick;
+	u32 lost, delta, deltaus, offset_now;
 
 	write_seqlock(&monotonic_lock);
 
-	offset_tick = read_pmtmr();
+	offset_now = read_pmtmr();
 
 	/* calculate tick interval */
-	delta = (offset_tick - last_offset) & ACPI_PM_MASK;
+	delta = (offset_now - offset_last) & ACPI_PM_MASK;
 
 	/* convert to usecs */
-	delta = cyc2us(delta);
+	deltaus = cyc2us(delta);
 
 	/* update the monotonic base value */
-	monotonic_base += delta * NSEC_PER_USEC;
+	monotonic_base += deltaus * NSEC_PER_USEC;
 	write_sequnlock(&monotonic_lock);
 
 	/* convert to ticks */
-	delta += offset_delay;
-	lost = delta / (USEC_PER_SEC / HZ);
-	offset_delay = delta % (USEC_PER_SEC / HZ);
-
+	lost = delta / pm_ticks_per_jiffy;
+	offset_last += lost * pm_ticks_per_jiffy;
+	offset_last &= ACPI_PM_MASK;
 
 	/* compensate for lost ticks */
 	if (lost >= 2)
 		jiffies_64 += lost - 1;
-
-	/* don't calculate delay for first run,
-	   or if we've got less then a tick */
-	if (first_run || (lost < 1)) {
-		first_run = 0;
-		offset_delay = 0;
-	}
 }
 
 static int pmtmr_resume(void)
 {
 	write_seqlock(&monotonic_lock);
 	/* Assume this is the last mark offset time */
-	offset_tick = read_pmtmr();
+	offset_last = read_pmtmr();
 	write_sequnlock(&monotonic_lock);
 	return 0;
 }
@@ -207,7 +203,7 @@ static unsigned long long monotonic_cloc
 	/* atomically read monotonic base & last_offset */
 	do {
 		seq = read_seqbegin(&monotonic_lock);
-		last_offset = offset_tick;
+		last_offset = offset_last;
 		base = monotonic_base;
 	} while (read_seqretry(&monotonic_lock, seq));
 
@@ -241,11 +237,11 @@ static unsigned long get_offset_pmtmr(vo
 {
 	u32 now, offset, delta = 0;
 
-	offset = offset_tick;
+	offset = offset_last;
 	now = read_pmtmr();
 	delta = (now - offset)&ACPI_PM_MASK;
 
-	return (unsigned long) offset_delay + cyc2us(delta);
+	return (unsigned long) cyc2us(delta);
 }
 
 

  reply	other threads:[~2005-09-02 15:45 UTC|newest]

Thread overview: 96+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-31 16:58 Updated dynamic tick patches Srivatsa Vaddagiri
2005-08-31 17:12 ` [PATCH 1/3] Updated dynamic tick patches - Fix lost tick calculation in timer_pm.c Srivatsa Vaddagiri
2005-08-31 22:36   ` Zachary Amsden
2005-08-31 22:47     ` john stultz
2005-09-02 15:43   ` [PATCH 1/3] dynticks - implement no idle hz for x86 Con Kolivas
2005-09-02 15:45     ` Con Kolivas [this message]
2005-09-02 15:46       ` [PATCH 3/3] dyntick - Recover walltime upon wakeup Con Kolivas
2005-09-02 17:25       ` [PATCH 2/3] dyntick - Fix lost tick calculation in timer pm.c Srivatsa Vaddagiri
2005-09-02 20:18         ` Thomas Schlichter
2005-09-02 21:21           ` john stultz
2005-09-02 16:56     ` [PATCH 1/3] dynticks - implement no idle hz for x86 Russell King
2005-09-02 17:12       ` Srivatsa Vaddagiri
2005-09-03  6:13       ` Con Kolivas
2005-09-03  7:58         ` Russell King
2005-09-03  8:01           ` Con Kolivas
2005-09-03  8:06             ` Russell King
2005-09-03  8:14               ` Con Kolivas
2005-09-04 20:10                 ` Nishanth Aravamudan
2005-09-04 20:26                   ` Russell King
2005-09-04 20:37                     ` Nishanth Aravamudan
2005-09-04 21:17                       ` Russell King
2005-09-05  3:08                       ` Con Kolivas
2005-09-05 16:28                         ` Nishanth Aravamudan
2005-09-05  6:58                       ` Tony Lindgren
2005-09-05 16:30                         ` Nishanth Aravamudan
2005-09-04 20:41                     ` Nishanth Aravamudan
2005-09-05  5:32                     ` Srivatsa Vaddagiri
2005-09-05  5:48                       ` Nishanth Aravamudan
2005-09-05  6:32                         ` Srivatsa Vaddagiri
2005-09-05  6:44                           ` Nishanth Aravamudan
2005-09-06 20:51                             ` Nishanth Aravamudan
2005-09-07  8:13                               ` Tony Lindgren
2005-09-07 15:00                                 ` Nishanth Aravamudan
2005-09-07 15:53                                 ` Nishanth Aravamudan
2005-09-07 17:07                                   ` Srivatsa Vaddagiri
2005-09-07 17:23                                     ` Nishanth Aravamudan
2005-09-07 18:14                                       ` Srivatsa Vaddagiri
2005-09-07 18:22                                         ` Nishanth Aravamudan
2005-09-07 16:14                           ` Bill Davidsen
2005-09-07 16:42                             ` Nish Aravamudan
2005-09-07 17:17                               ` Srivatsa Vaddagiri
2005-09-07 17:27                                 ` Nish Aravamudan
2005-09-07 18:18                                   ` Srivatsa Vaddagiri
2005-09-07 18:33                                     ` Nish Aravamudan
2005-09-09 16:27                                 ` Bill Davidsen
2005-09-05  7:37                       ` Russell King
2005-09-05  7:49                         ` Srivatsa Vaddagiri
2005-09-05  8:00                           ` Russell King
2005-09-05 16:33                             ` Nishanth Aravamudan
2005-09-05  7:00                   ` Srivatsa Vaddagiri
2005-09-05  7:27                     ` Tony Lindgren
2005-09-05 17:02                       ` Nishanth Aravamudan
2005-09-07  7:37                         ` Tony Lindgren
2005-09-07 15:05                           ` Nishanth Aravamudan
2005-09-08 10:00                             ` Tony Lindgren
2005-09-08 21:22                               ` Nishanth Aravamudan
2005-09-08 22:08                                 ` Nishanth Aravamudan
2005-09-09 22:30                                   ` Nishanth Aravamudan
2005-09-20 11:06                                   ` Srivatsa Vaddagiri
2005-09-20 14:58                                     ` Nishanth Aravamudan
2005-09-22 13:38                                       ` Martin Schwidefsky
2005-09-22 14:52                                         ` Nishanth Aravamudan
2005-09-22 18:32                                           ` Srivatsa Vaddagiri
2005-09-26 15:08                                             ` Srivatsa Vaddagiri
2005-09-23  6:55                                         ` Srivatsa Vaddagiri
2005-09-05  7:44                     ` Russell King
2005-09-05  8:19                       ` Srivatsa Vaddagiri
2005-09-05  8:32                         ` Russell King
2005-09-05  9:24                           ` Srivatsa Vaddagiri
2005-09-05 17:06                           ` Nishanth Aravamudan
2005-09-05 17:04                       ` Nishanth Aravamudan
2005-09-05 17:27                         ` Srivatsa Vaddagiri
2005-09-05 18:06                           ` Nishanth Aravamudan
2005-09-05 13:19                     ` Srivatsa Vaddagiri
2005-09-05 16:57                     ` Nishanth Aravamudan
2005-09-05 17:25                       ` Srivatsa Vaddagiri
2005-09-05 18:11                         ` Nishanth Aravamudan
2005-09-03  4:05   ` [PATCH 1/3] Updated dynamic tick patches - Fix lost tick calculation in timer_pm.c Lee Revell
2005-09-03  4:18     ` Peter Williams
2005-09-03  4:34       ` Lee Revell
2005-09-03  4:48         ` Peter Williams
2005-09-03  5:15     ` Parag Warudkar
2005-09-03  5:30       ` Lee Revell
2005-09-03  5:20     ` Srivatsa Vaddagiri
2005-09-06 10:32     ` Pavel Machek
2005-09-06 10:46       ` Srivatsa Vaddagiri
2005-09-06 18:04     ` john stultz
2005-08-31 17:26 ` [PATCH 2/3] Updated dynamic tick patches - Cleanup Srivatsa Vaddagiri
2005-08-31 17:27 ` [PATCH 3/3] Updated dynamic tick patches - Recover walltime upon wakeup Srivatsa Vaddagiri
2005-09-01  5:23 ` Updated dynamic tick patches Con Kolivas
2005-09-01 13:07   ` Tony Lindgren
2005-09-01 13:19     ` David Weinehall
2005-09-01 13:46       ` Tony Lindgren
2005-09-01 14:11     ` Srivatsa Vaddagiri
2005-09-02 17:34     ` Srivatsa Vaddagiri
2005-09-03 10:16       ` Tony Lindgren

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=200509030145.18368.kernel@kolivas.org \
    --to=kernel@kolivas.org \
    --cc=akpm@osdl.org \
    --cc=ck@vds.kolivas.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=vatsa@in.ibm.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.