From patchwork Fri Jun 24 15:12:01 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell King - ARM Linux X-Patchwork-Id: 916762 Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p5OFGOqg029871 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 24 Jun 2011 15:16:45 GMT Received: from canuck.infradead.org ([2001:4978:20e::1]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1Qa86d-0007y3-J5; Fri, 24 Jun 2011 15:15:39 +0000 Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1Qa86b-0006yr-Qp; Fri, 24 Jun 2011 15:15:37 +0000 Received: from [2002:4e20:1eda::1] (helo=caramon.arm.linux.org.uk) by canuck.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1Qa86W-0006yY-DB for linux-arm-kernel@lists.infradead.org; Fri, 24 Jun 2011 15:15:33 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=arm.linux.org.uk; s=caramon; h=Sender:In-Reply-To:Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date; bh=O5qaeXEvREr5cbiu4YOQJaCfUlgAfdXHrg1Yf0tSjic=; b=hoqHAft1N9w4RRDqTjYtE9+rJpy5PORoNW9VOu7O2nNZKLBwcGaLlQbWAA3eIQxNHFB8Tfz9n7izEYy3UaUHZaeims5EEsCzvuV61sEEjPVjsaFocRdwXa0GazSiLJsufiwFVX0GZkmXcroyh49B9zYNTOCQ9OpfpeeGqnbG910=; Received: from n2100.arm.linux.org.uk ([2002:4e20:1eda:1:214:fdff:fe10:4f86]) by caramon.arm.linux.org.uk with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.72) (envelope-from ) id 1Qa839-0006NU-4Y; Fri, 24 Jun 2011 16:12:03 +0100 Received: from linux by n2100.arm.linux.org.uk with local (Exim 4.72) (envelope-from ) id 1Qa837-0005Xa-Oq; Fri, 24 Jun 2011 16:12:01 +0100 Date: Fri, 24 Jun 2011 16:12:01 +0100 From: Russell King - ARM Linux To: "Premi, Sanjeev" Subject: Re: [PATCHv2] omap2+: pm: cpufreq: Fix loops_per_jiffy calculation Message-ID: <20110624151201.GO9449@n2100.arm.linux.org.uk> References: <1308923618-5333-1-git-send-email-premi@ti.com> <20110624140142.GM9449@n2100.arm.linux.org.uk> <20110624141402.GN9449@n2100.arm.linux.org.uk> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20110624141402.GN9449@n2100.arm.linux.org.uk> User-Agent: Mutt/1.5.19 (2009-01-05) X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.7.6 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110624_111533_045935_0F3E2F1C X-CRM114-Status: GOOD ( 12.59 ) X-Spam-Score: 1.2 (+) X-Spam-Report: SpamAssassin version 3.3.1 on canuck.infradead.org summary: Content analysis details: (1.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 1.3 RDNS_NONE Delivered to internal network by a host with no rDNS Cc: "linux-omap@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Fri, 24 Jun 2011 15:16:45 +0000 (UTC) Right, thanks for the file. Here's the patch. 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. --- 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 */