From patchwork Fri Nov 7 14:31:26 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 40412 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D8A40240F7 for ; Fri, 7 Nov 2014 14:31:48 +0000 (UTC) Received: by mail-lb0-f197.google.com with SMTP id w7sf1954823lbi.4 for ; Fri, 07 Nov 2014 06:31:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=ybf0hfwN2Sq9E0z1moWbA8a0+CM5+E8VqWVqiFUrnZ4=; b=iUV7R7BMD7wn5udm57YAHJElTkoFxfLGoZc66aSEOF1nLT4LMAMTmCHxJ+SUuQixQe srf3ugbZGh7YZwyuJLLVqkt6rlhDR0s+Yn2CQiox4ukaClMVOWLCGGT398q3T3ytRds9 1zpes3iKhssQVsOXbaykZgCbN/WM2oGHAJcvwG7oYg/78ycJp85LLyrJpxq1j9pgJ7WX FPL+qgr7JcWJCjn6flASAePHkksp6fKqEMPwiWayaNW8oy2RMdJAivekty7YXtRiRmow khn4dr3BWFv/KgNgbfDdmugF84ExNXZ8mzvurGkOYDRcHZR4t6Uy4NMZNvnRSJjM3pxw T/0A== X-Gm-Message-State: ALoCoQmezVgD3kl4Iz0j4qHqabB6np3+YQI6e4/ogkB3OW3fc/MqGZKMw0USkEusomgOixAFCu8P X-Received: by 10.112.146.104 with SMTP id tb8mr62154lbb.22.1415370707104; Fri, 07 Nov 2014 06:31:47 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.29.135 with SMTP id k7ls191236lah.78.gmail; Fri, 07 Nov 2014 06:31:46 -0800 (PST) X-Received: by 10.112.239.12 with SMTP id vo12mr2974181lbc.81.1415370706626; Fri, 07 Nov 2014 06:31:46 -0800 (PST) Received: from mail-lb0-f176.google.com (mail-lb0-f176.google.com. [209.85.217.176]) by mx.google.com with ESMTPS id j4si15204636lbn.98.2014.11.07.06.31.46 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 07 Nov 2014 06:31:46 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.176 as permitted sender) client-ip=209.85.217.176; Received: by mail-lb0-f176.google.com with SMTP id 10so2691670lbg.7 for ; Fri, 07 Nov 2014 06:31:46 -0800 (PST) X-Received: by 10.152.29.8 with SMTP id f8mr11623226lah.56.1415370706532; Fri, 07 Nov 2014 06:31:46 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.184.201 with SMTP id ew9csp206768lbc; Fri, 7 Nov 2014 06:31:45 -0800 (PST) X-Received: by 10.194.187.77 with SMTP id fq13mr17316560wjc.14.1415370705609; Fri, 07 Nov 2014 06:31:45 -0800 (PST) Received: from mail-wi0-f176.google.com (mail-wi0-f176.google.com. [209.85.212.176]) by mx.google.com with ESMTPS id l10si15441588wjx.160.2014.11.07.06.31.45 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 07 Nov 2014 06:31:45 -0800 (PST) Received-SPF: pass (google.com: domain of daniel.lezcano@linaro.org designates 209.85.212.176 as permitted sender) client-ip=209.85.212.176; Received: by mail-wi0-f176.google.com with SMTP id h11so4719057wiw.15 for ; Fri, 07 Nov 2014 06:31:45 -0800 (PST) X-Received: by 10.194.82.74 with SMTP id g10mr17186027wjy.116.1415370705370; Fri, 07 Nov 2014 06:31:45 -0800 (PST) Received: from localhost.localdomain (AToulouse-656-1-898-91.w109-223.abo.wanadoo.fr. [109.223.3.91]) by mx.google.com with ESMTPSA id bl9sm2231926wib.24.2014.11.07.06.31.43 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 07 Nov 2014 06:31:44 -0800 (PST) From: Daniel Lezcano To: rjw@rjwysocki.net Cc: preeti@linux.vnet.ibm.com, nicolas.pitre@linaro.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, peterz@infradead.org, linaro-kernel@lists.linaro.org, patches@linaro.org, lenb@kernel.org Subject: [PATCH V3 5/6] cpuidle: menu: Fix the get_typical_interval Date: Fri, 7 Nov 2014 15:31:26 +0100 Message-Id: <1415370687-18688-6-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1415370687-18688-1-git-send-email-daniel.lezcano@linaro.org> References: <1415370687-18688-1-git-send-email-daniel.lezcano@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: daniel.lezcano@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.176 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The first time the 'get_typical_function' is called, it computes an average of zero as no data is filled yet. That leads the 'data->predicted_us' variable to be set to zero too. The caller, 'menu_select' will then do: interactivity_req = data->predicted_us / performance_multiplier(nr_iowaiters, cpu_load); That sets the interactivity_req to zero (0/performance...). and then if (latency_req > interactivity_req) latency_req = interactivity_req; ... setting 'latency_req' to zero too. No idle state will fulfill this constraint and we will go the C1 state as default and leading to an update. So the next calls will compute an average different from zero. Even if that works with the current code but with a broken semantic, it will just break with the next patches where we are stricter with the latencies check: the first check will fail (latency_req is zero), then no update will occur leading to always falling to choose an idle state. As there are no previous values and it is pointless to compute a standard deviation for these unexisting values. Change the function to return the computed value and use it only if it is different from zero and greater than the next timer expiration. Signed-off-by: Daniel Lezcano --- drivers/cpuidle/governors/menu.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c index 2e4a315..163e63b 100644 --- a/drivers/cpuidle/governors/menu.c +++ b/drivers/cpuidle/governors/menu.c @@ -198,7 +198,7 @@ static u64 div_round64(u64 dividend, u32 divisor) * of points is below a threshold. If it is... then use the * average of these 8 points as the estimated value. */ -static void get_typical_interval(struct menu_device *data) +static unsigned int get_typical_interval(struct menu_device *data) { int i, divisor; unsigned int max, thresh; @@ -255,11 +255,8 @@ again: if (likely(stddev <= ULONG_MAX)) { stddev = int_sqrt(stddev); if (((avg > stddev * 6) && (divisor * 4 >= INTERVALS * 3)) - || stddev <= 20) { - if (data->next_timer_us > avg) - data->predicted_us = avg; - return; - } + || stddev <= 20) + return avg; } /* @@ -272,7 +269,7 @@ again: * with sporadic activity with a bunch of short pauses. */ if ((divisor * 4) <= INTERVALS * 3) - return; + return 0; thresh = max - 1; goto again; @@ -289,6 +286,7 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, struct menu_device *data = this_cpu_ptr(&menu_devices); int i; unsigned int interactivity_req; + unsigned int interactivity_overrride_us; unsigned long nr_iowaiters, cpu_load; if (data->needs_update) { @@ -313,7 +311,10 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, data->correction_factor[data->bucket], RESOLUTION * DECAY); - get_typical_interval(data); + interactivity_overrride_us = get_typical_interval(data); + if (interactivity_overrride_us && + data->next_timer_us > interactivity_overrride_us) + data->predicted_us = interactivity_overrride_us; /* * Performance multiplier defines a minimum predicted idle