From patchwork Wed Oct 2 10:26:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 20747 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f71.google.com (mail-qa0-f71.google.com [209.85.216.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 45A79238F9 for ; Wed, 2 Oct 2013 10:26:08 +0000 (UTC) Received: by mail-qa0-f71.google.com with SMTP id k15sf1510877qaq.10 for ; Wed, 02 Oct 2013 03:26:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=mime-version:x-gm-message-state:delivered-to:from:to:cc:subject :date:message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=E84MVb9fHUO3fBkIyevJk2XfCNWrLQOepP0K1d/oztE=; b=ZrQtPccsiVdKOXpDdSCkIfrLjN3KMS6z7u6wcOSohuGix55JtkLSrNiEAoH4/hrvN1 VqRkaKQUaUTiF0TLVB+VUNBYvDOVowbxHZepVEvYNTS6oaXzVn/k6ZDH9Y57XPQhzTfn pMjrimu3HNEf0+6NvKMgCqamOonWgtvX/FNs4BSE7on6mS3UVp6gPmivA+pvBJ5WbIqO Bx9oBR93F30OjFYjf5qsV9fvG29wsnDi6Qqz3kmlJWr3l8FvPYfsRp8olIDEULwoXNgt BrEvSHrxmjmG1g9PyTgKoIl0JlanSCINa8kIvEsmaBKr8R9PbLVIprO3bSRi1Dgwugar 4/yw== X-Received: by 10.236.6.134 with SMTP id 6mr1445227yhn.7.1380709567627; Wed, 02 Oct 2013 03:26:07 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.104.84 with SMTP id gc20ls420729qeb.96.gmail; Wed, 02 Oct 2013 03:26:07 -0700 (PDT) X-Received: by 10.220.237.208 with SMTP id kp16mr1360959vcb.4.1380709567523; Wed, 02 Oct 2013 03:26:07 -0700 (PDT) Received: from mail-ve0-f181.google.com (mail-ve0-f181.google.com [209.85.128.181]) by mx.google.com with ESMTPS id c11si173896vej.90.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 02 Oct 2013 03:26:07 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.181 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.181; Received: by mail-ve0-f181.google.com with SMTP id oy12so355191veb.40 for ; Wed, 02 Oct 2013 03:26:07 -0700 (PDT) X-Gm-Message-State: ALoCoQk95DUpQXZWCVXzdeTiK+0hTRI4xmm+f4E88HYefVwVFYRqVNniNFmsbap+AgsxaPqZ54uL X-Received: by 10.58.46.229 with SMTP id y5mr1340296vem.15.1380709567385; Wed, 02 Oct 2013 03:26:07 -0700 (PDT) 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.220.174.196 with SMTP id u4csp85449vcz; Wed, 2 Oct 2013 03:26:06 -0700 (PDT) X-Received: by 10.180.81.194 with SMTP id c2mr1384897wiy.11.1380709566381; Wed, 02 Oct 2013 03:26:06 -0700 (PDT) Received: from mail-wg0-f45.google.com (mail-wg0-f45.google.com [74.125.82.45]) by mx.google.com with ESMTPS id z2si3136298wiw.78.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 02 Oct 2013 03:26:06 -0700 (PDT) Received-SPF: neutral (google.com: 74.125.82.45 is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) client-ip=74.125.82.45; Received: by mail-wg0-f45.google.com with SMTP id y10so649268wgg.24 for ; Wed, 02 Oct 2013 03:26:05 -0700 (PDT) X-Received: by 10.194.11.38 with SMTP id n6mr1485319wjb.25.1380709565807; Wed, 02 Oct 2013 03:26:05 -0700 (PDT) Received: from mai.home (AToulouse-654-1-340-251.w90-55.abo.wanadoo.fr. [90.55.59.251]) by mx.google.com with ESMTPSA id c4sm2083976wiz.0.1969.12.31.16.00.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 02 Oct 2013 03:26:05 -0700 (PDT) From: Daniel Lezcano To: tglx@linutronix.de, sboyd@codeaurora.org Cc: linux-kernel@vger.kernel.org, patches@linaro.org, linaro-kernel@lists.linaro.org Subject: [PATCH V2] tick: Make sleep length calculation more accurate Date: Wed, 2 Oct 2013 12:26:05 +0200 Message-Id: <1380709565-22153-1-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.7.9.5 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: daniel.lezcano@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.181 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 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 sleep_length is computed in the tick_nohz_stop_sched_tick function but it is used later in the code with in between the local irq enabled. cpu_idle_loop tick_nohz_idle_enter [ exits with local irq enabled ] __tick_nohz_idle_enter tick_nohz_stop_sched_tick ... arch_cpu_idle menu_select [ uses here 'sleep_length' ] ... Between the computation of the sleep length and its usage, some interrupts may occur, making the sleep length shorter than actually it is because of the interrupt processing, or different if the timer itself expired. This patch fixes that by moving the sleep_length computation in the tick_nohz_get_sleep_length function and using the tick device's next_event. As the sleep_length field is no longer needed, it is removed from the tick_sched structure. Signed-off-by: Daniel Lezcano Signed-off-by: Stephen Boyd --- include/linux/tick.h | 2 -- kernel/time/tick-sched.c | 5 +++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/include/linux/tick.h b/include/linux/tick.h index 5128d33..53dbbd7 100644 --- a/include/linux/tick.h +++ b/include/linux/tick.h @@ -48,7 +48,6 @@ enum tick_nohz_mode { * @idle_exittime: Time when the idle state was left * @idle_sleeptime: Sum of the time slept in idle with sched tick stopped * @iowait_sleeptime: Sum of the time slept in idle with sched tick stopped, with IO outstanding - * @sleep_length: Duration of the current idle sleep * @do_timer_lst: CPU was the last one doing do_timer before going idle */ struct tick_sched { @@ -67,7 +66,6 @@ struct tick_sched { ktime_t idle_exittime; ktime_t idle_sleeptime; ktime_t iowait_sleeptime; - ktime_t sleep_length; unsigned long last_jiffies; unsigned long next_jiffies; ktime_t idle_expires; diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index 3612fc7..60b1dcd 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -673,7 +673,6 @@ static ktime_t tick_nohz_stop_sched_tick(struct tick_sched *ts, out: ts->next_jiffies = next_jiffies; ts->last_jiffies = last_jiffies; - ts->sleep_length = ktime_sub(dev->next_event, now); return ret; } @@ -837,8 +836,10 @@ void tick_nohz_irq_exit(void) ktime_t tick_nohz_get_sleep_length(void) { struct tick_sched *ts = &__get_cpu_var(tick_cpu_sched); + struct clock_event_device *dev = __get_cpu_var(tick_cpu_device).evtdev; + ktime_t now = ktime_get(); - return ts->sleep_length; + return ktime_sub(dev->next_event, now); } static void tick_nohz_restart(struct tick_sched *ts, ktime_t now)