From: Kevin Hilman Subject: Re: [PATCH v2] pm: Add runtime PM statistics Date: Thu, 05 Aug 2010 16:20:28 -0700 Message-ID: <87bp9gpryb.fsf__6735.76894118941$1281050643$gmane$org@deeprootsystems.com> References: <20100710095254.5ab7291c@infradead.org> <201007112326.07541.rjw@sisk.pl> <20100711221646.35f11b70@infradead.org> <201007132328.28853.rjw@sisk.pl> <4C3F2CEF.2090404@linux.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <4C3F2CEF.2090404@linux.intel.com> (Arjan van de Ven's message of "Thu, 15 Jul 2010 08:44:47 -0700") List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-pm-bounces@lists.linux-foundation.org Errors-To: linux-pm-bounces@lists.linux-foundation.org To: Arjan van de Ven Cc: "linux-kernel@vger.kernel.org" , "linux-pm@lists.linux-foundation.org" , Arjan van de Ven List-Id: linux-pm@vger.kernel.org Arjan van de Ven writes: > + > +/** > + * update_pm_runtime_accounting - Update the time accounting of power > states > + * @dev: Device to update the accounting for > + * > + * In order to be able to have time accounting of the various power states > + * (as used by programs such as PowerTOP to show the effectiveness of > runtime > + * PM), we need to track the time spent in each state. > + * update_pm_runtime_accounting must be called each time before the > + * runtime_status field is updated, to account the time in the old state > + * correctly. > + */ > +void update_pm_runtime_accounting(struct device *dev) > +{ > + unsigned long now = jiffies; > + int delta; > + > + delta = now - dev->power.accounting_timestamp; > + > + if (delta < 0) > + delta = 0; > + > + dev->power.accounting_timestamp = now; > + > + if (dev->power.disable_depth > 0) > + return; > + > + if (dev->power.runtime_status == RPM_SUSPENDED) > + dev->power.suspended_jiffies += delta; > + else > + dev->power.active_jiffies += delta; > +} By using jiffies, I think we might miss events in drivers that are doing runtime PM transitions in short bursts. On embedded systems with slow HZ, there could potentially be lots of transitions between ticks. It would be nicer to use clocksource-based time so transitions between jiffies could still be factored into the accounting. Kevin