From patchwork Mon Feb 24 06:29:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tuukka Tikkanen X-Patchwork-Id: 25172 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-oa0-f70.google.com (mail-oa0-f70.google.com [209.85.219.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 155E22066C for ; Mon, 24 Feb 2014 07:45:43 +0000 (UTC) Received: by mail-oa0-f70.google.com with SMTP id m1sf175488oag.1 for ; Sun, 23 Feb 2014 23:45:43 -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:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=T3NB0lzfb30DjFZc4xMr857Ve8ZSj6iE5nxIiJsDJ2Y=; b=U2i2cbssLqay4xAJoae1EiLJiz3MRkHDV/Ts5S4pPb1GsTgnSj4MWsKctC0q4OXOtv V0B7zPu14X9IECaotuqpt+NAlMZAK0RIfeh0t6BNqicQpimMoJG6MTiv92mH9ImxKIGk YOtB/zxDu82mxKUaZHQ/V0ySri6B4MHtwtFbCI3BL2AgYVNKYiKHFKVX+TepXS79B15+ WziM1fzhJ84HNeyWKHFeJKF5TvyUAZ1M3FnUtyDYPCkpDj4gUcBPFUxe2wTtj++1ZAZJ X8gUSDiq2Bbn1ONIayhU85J//WdlVK+9P58cztigI0nIHEJwx+LhHE5Fno+GiXRLWuHo GIFA== X-Gm-Message-State: ALoCoQkNZt99qA3e4l9gA3U/j2ubgQcq6b8Lomh/2pKN2nxpZDAYA8hyyv94XMFVRGV3U9brirbU X-Received: by 10.182.219.226 with SMTP id pr2mr8104750obc.44.1393227943335; Sun, 23 Feb 2014 23:45:43 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.21.8 with SMTP id 8ls1870976qgk.51.gmail; Sun, 23 Feb 2014 23:45:43 -0800 (PST) X-Received: by 10.52.63.233 with SMTP id j9mr9654779vds.69.1393227943198; Sun, 23 Feb 2014 23:45:43 -0800 (PST) Received: from mail-ve0-f175.google.com (mail-ve0-f175.google.com [209.85.128.175]) by mx.google.com with ESMTPS id n15si5631134vcy.102.2014.02.23.23.45.43 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 23 Feb 2014 23:45:43 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.175 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.175; Received: by mail-ve0-f175.google.com with SMTP id oy12so1062745veb.20 for ; Sun, 23 Feb 2014 23:45:43 -0800 (PST) X-Received: by 10.52.185.196 with SMTP id fe4mr9648708vdc.27.1393227943072; Sun, 23 Feb 2014 23:45:43 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.174.196 with SMTP id u4csp43366vcz; Sun, 23 Feb 2014 23:45:42 -0800 (PST) X-Received: by 10.68.212.161 with SMTP id nl1mr23516613pbc.142.1393227942302; Sun, 23 Feb 2014 23:45:42 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i7si15994975pav.304.2014.02.23.23.45.40; Sun, 23 Feb 2014 23:45:40 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752264AbaBXHoH (ORCPT + 26 others); Mon, 24 Feb 2014 02:44:07 -0500 Received: from mx.mmd.net ([80.83.0.3]:55321 "EHLO mx.mmd.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751781AbaBXHoE (ORCPT ); Mon, 24 Feb 2014 02:44:04 -0500 Received: from istutuskone.tic0.net (verkonrikkoja.tic0.net [80.83.5.104]) by mx.mmd.net (Postfix) with ESMTP id BEA1BFCB; Mon, 24 Feb 2014 09:26:35 +0200 (EET) From: Tuukka Tikkanen To: linux-pm@vger.kernel.org, rjw@rjwysocki.net Cc: daniel.lezcano@linaro.org, tuukka.tikkanen@linaro.org, linux-kernel@vger.kernel.org Subject: [PATCH 6/7] Cpuidle: Deal with timer expiring in the past Date: Mon, 24 Feb 2014 08:29:36 +0200 Message-Id: <1393223377-5744-7-git-send-email-tuukka.tikkanen@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1393223377-5744-1-git-send-email-tuukka.tikkanen@linaro.org> References: <1393223377-5744-1-git-send-email-tuukka.tikkanen@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: tuukka.tikkanen@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.175 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Sometimes (fairly often) when the cpuidle menu governor is making a decision about idle state to enter the next timer for the cpu appears to expire in the past. The menu governor expects the expiry to always be in the future and in fact stores the time delta in an unsigned variable. However, when the expiry is in the past, the value returned by tick_nohz_get_sleep_length can be negative. This patch prevents using negative values, instead making the governor return immediately similar to having latency requirement set to 0. Note: As with latency == 0, the return value is 0 with no check to see if the state 0 has been disabled or not. Signed-off-by: Tuukka Tikkanen --- drivers/cpuidle/governors/menu.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/cpuidle/governors/menu.c b/drivers/cpuidle/governors/menu.c index 71b5232..c414468 100644 --- a/drivers/cpuidle/governors/menu.c +++ b/drivers/cpuidle/governors/menu.c @@ -302,8 +302,16 @@ static int menu_select(struct cpuidle_driver *drv, struct cpuidle_device *dev) if (unlikely(latency_req == 0)) return 0; - /* determine the expected residency time, round up */ + /* + * Determine the expected residency time. If the time is negative, + * a timer interrupt has probably just expired after disabling + * interrupts. Return as quickly as possible in the most shallow + * state possible. tv_nsec is always positive, so only check the + * seconds. + */ t = ktime_to_timespec(tick_nohz_get_sleep_length()); + if (t.tv_sec < 0) + return 0; data->next_timer_us = t.tv_sec * USEC_PER_SEC + t.tv_nsec / NSEC_PER_USEC;