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: 916892 X-Patchwork-Delegate: khilman@deeprootsystems.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p5OGgrH5013610 for ; Fri, 24 Jun 2011 16:42:55 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751625Ab1FXQmy (ORCPT ); Fri, 24 Jun 2011 12:42:54 -0400 Received: from hera.kernel.org ([140.211.167.34]:36043 "EHLO hera.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750983Ab1FXQmv (ORCPT ); Fri, 24 Jun 2011 12:42:51 -0400 Received: from caramon.arm.linux.org.uk (caramon.arm.linux.org.uk [78.32.30.218] (may be forged)) by hera.kernel.org (8.14.4/8.14.3) with ESMTP id p5OFDWHH029059 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 24 Jun 2011 15:14:49 GMT X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.97 at hera.kernel.org 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" Cc: "linux-omap@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" 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-Spam-Status: No, score=-3.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, MAY_BE_FORGED,NO_DNS_FOR_FROM,RCVD_IN_DNSWL_MED,T_DKIM_INVALID, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on hera.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Fri, 24 Jun 2011 16:42:55 +0000 (UTC) X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (hera.kernel.org [140.211.167.34]); Fri, 24 Jun 2011 15:15:29 +0000 (UTC) Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org 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. --- To unsubscribe from this list: send the line "unsubscribe linux-omap" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- 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 */