public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Thomas Schlichter <thomas.schlichter@web.de>
To: Srivatsa Vaddagiri <vatsa@in.ibm.com>, john stultz <johnstul@us.ibm.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] Updated dynamic tick patches - Fix lost tick
Date: Thu, 1 Sep 2005 08:29:32 +0200	[thread overview]
Message-ID: <200509010829.35958.thomas.schlichter@web.de> (raw)


[-- Attachment #1.1: body text --]
[-- Type: text/plain, Size: 1096 bytes --]

Hi Srivatsa, 

on LKML I did see your patch trying to increase the accuracy of tme pmtmr by 
directly converting the PM-timer-ticks to jiffies. I think this is a good 
idea but as you already recognized, it is not completely correct...

There are at least these issues:
1. "offset_last" corresponds to the time when the last recognized
   jiffyoccoured. So "delta" always corresponds to the time from the last
   recognized jiffy to _now_. "monotonic_base" is increased by delta, so after
   the first run it will correspond to _now_. But the next time the
   offset-time between the last recognized jiffy and the last _now_ is added
   _again_. So the monotonic clock ist too fast...
2. "offset_last is modified outside the "monotonic_lock", what is not allowed.

I fixed these issues by using most of the old code, but simply changed "delta" 
and "offset_delay" to always contain PM-timer-ticks and compute the lost 
jiffies directly using PMTMR_TICKS_PER_JIFFY.

I tested the attached patch during the last night and it sems to work...

Best regards
  Thomas Schlichter

[-- Attachment #1.2: pmtmr_accuracy.patch --]
[-- Type: text/x-diff, Size: 2166 bytes --]

--- linux-2.6.13/arch/i386/kernel/timers/timer_pm.c.orig	2005-08-31 23:34:11.000000000 +0200
+++ linux-2.6.13/arch/i386/kernel/timers/timer_pm.c	2005-09-01 00:08:20.000000000 +0200
@@ -28,6 +28,7 @@
 #define PMTMR_TICKS_PER_SEC 3579545
 #define PMTMR_EXPECTED_RATE \
   ((CALIBRATE_LATCH * (PMTMR_TICKS_PER_SEC >> 10)) / (CLOCK_TICK_RATE>>10))
+#define PMTMR_TICKS_PER_JIFFY (PMTMR_TICKS_PER_SEC / HZ)
 
 
 /* The I/O port the PMTMR resides at.
@@ -128,6 +129,11 @@ pm_good:
 		return -ENODEV;
 
 	init_cpu_khz();
+
+	printk ("Using %u PM timer ticks per jiffy \n", PMTMR_TICKS_PER_JIFFY);
+
+	offset_tick = read_pmtmr();
+
 	return 0;
 }
 
@@ -151,7 +157,6 @@ 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;
 
 	write_seqlock(&monotonic_lock);
@@ -161,29 +166,23 @@ static void mark_offset_pmtmr(void)
 	/* calculate tick interval */
 	delta = (offset_tick - last_offset) & ACPI_PM_MASK;
 
-	/* convert to usecs */
-	delta = cyc2us(delta);
-
 	/* update the monotonic base value */
-	monotonic_base += delta * NSEC_PER_USEC;
+	monotonic_base += cyc2us(delta) * 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 / PMTMR_TICKS_PER_JIFFY;
+	offset_delay = delta % PMTMR_TICKS_PER_JIFFY;
 
 
 	/* 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;
+	/* don't calculate delay if we've got less then a tick */
+	if (lost < 1)
 		offset_delay = 0;
-	}
 }
 
 
@@ -233,9 +232,9 @@ static unsigned long get_offset_pmtmr(vo
 
 	offset = offset_tick;
 	now = read_pmtmr();
-	delta = (now - offset)&ACPI_PM_MASK;
+	delta = (now - offset) & ACPI_PM_MASK;
 
-	return (unsigned long) offset_delay + cyc2us(delta);
+	return (unsigned long) cyc2us(delta + offset_delay);
 }
 
 

[-- Attachment #2: signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

             reply	other threads:[~2005-09-01  6:30 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-01  6:29 Thomas Schlichter [this message]
2005-09-01  7:23 ` [PATCH 1/3] Updated dynamic tick patches - Fix lost tick Srivatsa Vaddagiri
2005-09-01  7:42   ` Thomas Schlichter
2005-09-01 10:28     ` Srivatsa Vaddagiri
2005-09-01 11:05       ` Thomas Schlichter
2005-09-01 11:33         ` Srivatsa Vaddagiri

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=200509010829.35958.thomas.schlichter@web.de \
    --to=thomas.schlichter@web.de \
    --cc=johnstul@us.ibm.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox