From patchwork Tue Dec 16 06:52:06 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Len Brown X-Patchwork-Id: 5499541 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A6CDABEEA8 for ; Tue, 16 Dec 2014 06:52:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 353D220A1C for ; Tue, 16 Dec 2014 06:52:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 32FF820A14 for ; Tue, 16 Dec 2014 06:52:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751043AbaLPGwT (ORCPT ); Tue, 16 Dec 2014 01:52:19 -0500 Received: from mail-yh0-f54.google.com ([209.85.213.54]:34099 "EHLO mail-yh0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750916AbaLPGwR (ORCPT ); Tue, 16 Dec 2014 01:52:17 -0500 Received: by mail-yh0-f54.google.com with SMTP id 29so6304295yhl.27 for ; Mon, 15 Dec 2014 22:52:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :reply-to:organization; bh=h5XsK8HkdqcLdedoszP8WMQoufgGq7rBYhdVlGTXtwg=; b=z/taoBWQfts1Uh8r29Xm2KaLtV9Kd2l5+/tvdgHlD+Aw7+wooEShKwzNiAMUQIPUDt BLtI6+ne09jDfhBQjMSboa/4Aa77CzjaFNbnDLWDkwg/x4HFioNTCvVSrv+lEY4CoOZK 4HM45qLO7wy2LMIjwe5Q+frGCRW/X/12xW0YV4IsbJu8E8t+hJtxuajNpsTdrftKu5Xl XzL0u/ThnMlD69mOr9repH4q2D7pVDRgLgba8BDGHlHtZtE3Y11MQmnHw3cbsLlhmAli 6NpyE3joVOqtWuJeMKk2iGrjY6npsM6izt5XIMjYFrMWLklZHjxyzxGXpKevPMLrx2Ho TecQ== X-Received: by 10.236.206.8 with SMTP id k8mr24922497yho.23.1418712737081; Mon, 15 Dec 2014 22:52:17 -0800 (PST) Received: from localhost.localdomain (pool-108-20-130-222.bstnma.fios.verizon.net. [108.20.130.222]) by mx.google.com with ESMTPSA id v68sm7336009yhp.2.2014.12.15.22.52.16 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 15 Dec 2014 22:52:16 -0800 (PST) From: Len Brown To: linux-pm@vger.kernel.org, linux-acpi@vger.kernel.org Cc: Len Brown , Daniel Lezcano Subject: [PATCH 1/3] cpuidle menu: Better idle duration measurement without using CPUIDLE_FLAG_TIME_INVALID Date: Tue, 16 Dec 2014 01:52:06 -0500 Message-Id: X-Mailer: git-send-email 2.1.2.451.g98349e5 In-Reply-To: <1418712728-2193-1-git-send-email-lenb@kernel.org> References: <1418712728-2193-1-git-send-email-lenb@kernel.org> Reply-To: Len Brown Organization: Intel Open Source Technology Center Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_RP_MATCHES_RCVD,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Len Brown When menu sees CPUIDLE_FLAG_TIME_INVALID, it ignores its timestamps, and assumes that idle lasted as long as the time till next predicted timer expiration. But if an interrupt was seen and serviced before that duration, it would actually be more accurate to use the measured time rather than rounding up to the next predicted timer expiration. And if an interrupt is seen and serviced such that the mesured time exceeds the time till next predicted timer expiration, then truncating to that expiration is the right thing to do -- since we can never stay idle past that timer expiration. So the code can do a better job without checking for CPUIDLE_FLAG_TIME_INVALID. Signed-off-by: Len Brown Cc: Daniel Lezcano Acked-by: Daniel Lezcano Reviewed-by: Tuukka Tikkanen --- drivers/cpuidle/governors/menu.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c index 659d7b0..4058079 100644 --- a/drivers/cpuidle/governors/menu.c +++ b/drivers/cpuidle/governors/menu.c @@ -396,8 +396,8 @@ static void menu_update(struct cpuidle_driver *drv, struct cpuidle_device *dev) * power state and occurrence of the wakeup event. * * If the entered idle state didn't support residency measurements, - * we are basically lost in the dark how much time passed. - * As a compromise, assume we slept for the whole expected time. + * we use them anyway if they are short, and if long, + * truncate to the whole expected time. * * Any measured amount of time will include the exit latency. * Since we are interested in when the wakeup begun, not when it @@ -405,22 +405,17 @@ static void menu_update(struct cpuidle_driver *drv, struct cpuidle_device *dev) * the measured amount of time is less than the exit latency, * assume the state was never reached and the exit latency is 0. */ - if (unlikely(target->flags & CPUIDLE_FLAG_TIME_INVALID)) { - /* Use timer value as is */ - measured_us = data->next_timer_us; - } else { - /* Use measured value */ - measured_us = cpuidle_get_last_residency(dev); + /* measured value */ + measured_us = cpuidle_get_last_residency(dev); - /* Deduct exit latency */ - if (measured_us > target->exit_latency) - measured_us -= target->exit_latency; + /* Deduct exit latency */ + if (measured_us > target->exit_latency) + measured_us -= target->exit_latency; - /* Make sure our coefficients do not exceed unity */ - if (measured_us > data->next_timer_us) - measured_us = data->next_timer_us; - } + /* Make sure our coefficients do not exceed unity */ + if (measured_us > data->next_timer_us) + measured_us = data->next_timer_us; /* Update our correction ratio */ new_factor = data->correction_factor[data->bucket];