public inbox for linux-omap@vger.kernel.org
 help / color / mirror / Atom feed
From: Russell King - ARM Linux <linux@arm.linux.org.uk>
To: "Premi, Sanjeev" <premi@ti.com>
Cc: "linux-omap@vger.kernel.org" <linux-omap@vger.kernel.org>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCHv2] omap2+: pm: cpufreq: Fix loops_per_jiffy calculation
Date: Fri, 24 Jun 2011 16:12:01 +0100	[thread overview]
Message-ID: <20110624151201.GO9449@n2100.arm.linux.org.uk> (raw)
In-Reply-To: <20110624141402.GN9449@n2100.arm.linux.org.uk>

Right, thanks for the file.  Here's the patch.

--- omap2plus-cpufreq.c~	2011-06-24 15:50:32.000000000 +0100
+++ omap2plus-cpufreq.c	2011-06-24 16:00:08.000000000 +0100
@@ -44,6 +44,16 @@
 static char *mpu_clk_name;
 static struct device *mpu_dev;
 
+#ifdef CONFIG_SMP
+struct lpj_info {
+	unsigned long	ref;
+	unsigned int	freq;
+};
+
+static DEFINE_PER_CPU(struct lpj_info, lpj_ref);
+static struct lpj_info global_lpj_ref;
+#endif
+
 static int omap_verify_speed(struct cpufreq_policy *policy)
 {
 	if (!freq_table)
@@ -109,14 +119,25 @@
 	freqs.new = omap_getspeed(policy->cpu);
 
 #ifdef CONFIG_SMP
-	/* Adjust jiffies before transition */
+	/* Adjust per-cpu loops_per_jiffy before transition */
 	for_each_cpu(i, policy->cpus) {
-		unsigned long lpj = per_cpu(cpu_data, i).loops_per_jiffy;
-
-		per_cpu(cpu_data, i).loops_per_jiffy = cpufreq_scale(lpj,
-							freqs.old,
-							freqs.new);
+		struct lpj_info *lpj = &per_cpu(lpj_ref, i);
+		if (!lpj->freq) {
+			lpj->ref = per_cpu(cpu_data, i).loops_per_jiffy;
+			lpj->freq = freqs.old;
+		}
+
+		per_cpu(cpu_data, i).loops_per_jiffy =
+			cpufreq_scale(lpj->ref, lpj->freq, freqs.new);
+	}
+
+	/* And don't forget to adjust the global one */
+	if (!global_lpj_ref.freq) {
+		global_lpj_ref.ref = loops_per_jiffy;
+		global_lpj_ref.freq = freqs.old;
 	}
+	loops_per_jiffy = cpufreq_scale(global_lpj_ref.ref, global_lpj_ref.freq,
+					freqs.new);
 #endif
 
 	/* Notify transitions */


Notice how we adjust _both_ the per-cpu loops_per_jiffy, and that we
adjust them with reference to the initial values.

If you adjust lpj with reference to the last, then you _will_ build up
a progressively bigger and bigger error in the value over time.

  reply	other threads:[~2011-06-24 15:12 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-24 13:53 [PATCHv2] omap2+: pm: cpufreq: Fix loops_per_jiffy calculation Sanjeev Premi
2011-06-24 13:59 ` Premi, Sanjeev
2011-06-24 14:01 ` Russell King - ARM Linux
2011-06-24 14:09   ` Premi, Sanjeev
2011-06-24 14:14     ` Russell King - ARM Linux
2011-06-24 15:12       ` Russell King - ARM Linux [this message]
2011-06-24 15:34         ` Premi, Sanjeev
2011-06-24 17:50         ` Premi, Sanjeev
2011-06-24 18:51           ` Russell King - ARM Linux
2011-06-24 20:14             ` Kevin Hilman
2011-06-25 16:20               ` Premi, Sanjeev
2011-06-24 18:48         ` Santosh Shilimkar
2011-06-25 18:53           ` Premi, Sanjeev
2011-06-25 19:09             ` Russell King - ARM Linux
2011-06-27  4:54               ` Premi, Sanjeev
2011-06-27  7:40                 ` Russell King - ARM Linux
2011-06-24 14:35 ` Santosh Shilimkar
2011-06-24 14:40   ` Premi, Sanjeev
2011-06-24 14:47     ` Santosh Shilimkar
2011-06-28 22:29 ` Colin Cross
2011-06-28 22:45   ` Santosh Shilimkar
2011-06-28 22:56     ` Colin Cross
     [not found]     ` <CAMbhsRRctHC2wSi7cWjO2Fn_rM7=dMtTrt6PbsVehrgx9SKwzw@mail.gmail.com>
2011-06-28 23:00       ` Santosh Shilimkar
2011-06-28 23:04         ` Santosh Shilimkar
2011-06-28 23:03     ` Russell King - ARM Linux
2011-06-28 23:07       ` Santosh Shilimkar
2011-06-28 22:55   ` Russell King - ARM Linux
2011-06-28 22:58     ` Colin Cross
2011-06-28 23:17       ` Russell King - ARM Linux
2011-06-28 23:37         ` Colin Cross
2011-06-28 23:46           ` Russell King - ARM Linux
2011-06-28 23:59             ` Colin Cross
2011-06-29 14:00               ` Russell King - ARM Linux
2011-06-29 16:57                 ` Colin Cross
2011-06-29 18:29         ` Stephen Boyd
2011-06-29 18:43           ` Russell King - ARM Linux

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=20110624151201.GO9449@n2100.arm.linux.org.uk \
    --to=linux@arm.linux.org.uk \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=premi@ti.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