From patchwork Mon Jun 27 07:42:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhaoyang Huang X-Patchwork-Id: 9199973 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3F89460757 for ; Mon, 27 Jun 2016 07:42:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 31F262711E for ; Mon, 27 Jun 2016 07:42:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 26700275A2; Mon, 27 Jun 2016 07:42:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E845A2711E for ; Mon, 27 Jun 2016 07:42:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751879AbcF0Hmk (ORCPT ); Mon, 27 Jun 2016 03:42:40 -0400 Received: from mail-pf0-f182.google.com ([209.85.192.182]:34056 "EHLO mail-pf0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751876AbcF0Hmi (ORCPT ); Mon, 27 Jun 2016 03:42:38 -0400 Received: by mail-pf0-f182.google.com with SMTP id h14so59426681pfe.1 for ; Mon, 27 Jun 2016 00:42:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=ixf+xoR0JYX4ZoOeZaeOElXH9BzKkpA1NYjUN/zIeyA=; b=HNXCU/k1ybvM0rcwz5ZQD27Ah6vsiLpwfYquXnENnoT2vp13oGc7i54ZARyR4y7JuS d3epfLOT556H6oSOPysNvLqVj0/MjULUjFxi27ErrfhZBo2ZT/S/b0Gn00J/gzc7NDa8 5xo2UXLxBS8lZmRRicfcY+aphBsZKWaLT0oAQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=ixf+xoR0JYX4ZoOeZaeOElXH9BzKkpA1NYjUN/zIeyA=; b=Z2w1M7cZUW7tl3wKAChOxW0rhF8ibdmvSimW5E/mFEyctJ0YwLRiPLbgsytzIrQfRl 980hwmzSlpS+0GFQd9R+4/GCX1d+kj55vTrmcnXx1NBA4kk4j7WDUyFNo57ntSqy2Ylp keB7UN/nieYJq9sDBRoHyVryx0azVXptgx6Qce1Zd+IkXiGR7egBczjZuiYH2u0WZ6dz /tnApJUWiWzVvNT9QnZYj98qbA6dro3tQXUx5uTUcahexqMTInv6a7tP9mDaikM/mE+F otq42uIvhE0jOCOeJpPkDPA+i2nJ766qU27entmChIGTWojXwr7qyyKapro4vg95ATaG M+gg== X-Gm-Message-State: ALyK8tLwQa6LL07qXlK/VRiZvy+MhifQ1a4JhGKEo+YyfW90es7EFQpT/c6avbXv58xd7vDD X-Received: by 10.98.54.198 with SMTP id d189mr31345780pfa.39.1467013352598; Mon, 27 Jun 2016 00:42:32 -0700 (PDT) Received: from bj03382pcu.spreadtrum.com ([175.111.195.49]) by smtp.gmail.com with ESMTPSA id ql1sm4618218pac.2.2016.06.27.00.42.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 27 Jun 2016 00:42:32 -0700 (PDT) From: Zhaoyang Huang X-Google-Original-From: Zhaoyang Huang To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, mingo@redhat.com, peterz@infradead.org, zhaoyang.huang@spreadtrum.com, private-pmwg@lists.linaro.org, tglx@linutronix.de Subject: [RFC PATCH v3 2/2] power/idle: enhance the precision of sleep_length Date: Mon, 27 Jun 2016 15:42:16 +0800 Message-Id: <1467013336-19966-2-git-send-email-zhaoyang.huang@spreadtrum.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1467013336-19966-1-git-send-email-zhaoyang.huang@spreadtrum.com> References: <1467013336-19966-1-git-send-email-zhaoyang.huang@spreadtrum.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP As shown in bellowing chart, there should be a gap between tick_nohz_idle_enter(step '1') and tick_nohz_get_sleep_length (step '3') when idle, which comprise of the execution time of the code behind step '1' and a series of notify call(step2,4). Yes, for most of the scenarios, it would NOT be a problem. However,all time consumed by the steps above will cause the sleep_length is not very precised in the scenario where the idle state is shallow(imagin an idle state last less than 500us under a 200Mhz's P-state). Change it in this series of patch. Please refer to bellowing chart for detailed information current approach: static void cpu_idle_loop(void) { while (1) { tick_nohz_idle_enter(); --->__tick_nohz_idle_enter --->tick_nohz_stop_sched_tick { ... ts->sleep_length = ktime_sub(dev->next_event, now); /*1*/ ... } while (!need_resched()) { ... local_irq_disable(); arch_cpu_idle_enter(); --->idle_notifier_call_chain(IDLE_START); /*2*/ cpuidle_idle_call(); --->next_state = cpuidle_select(drv, dev); /*3*/ --->static int arm_enter_idle_state(...) { ... ret = cpu_pm_enter(); /*4*/ } } ---------|----------------------|----------------------------|------------------------------------|--------------------------------------------|-------------------- 1.now 2.IDLE_START 3.select idle state 4.CPU_PM_ENTER next_event (sleep_length) modified approach: static void cpu_idle_loop(void) { while (1) { tick_nohz_idle_enter(); --->__tick_nohz_idle_enter --->tick_nohz_stop_sched_tick { ... ... } while (!need_resched()) { ... local_irq_disable(); arch_cpu_idle_enter(); --->idle_notifier_call_chain(IDLE_START); /*1*/ cpuidle_idle_call(); --->ret = cpu_pm_enter(); /*2*/ --->tick_nohz_get_sleep_length { ts->sleep_length = ktime_sub(dev->next_event, now); /*3*/ } --->next_state = cpuidle_select(drv, dev); /*4*/ --->static int arm_enter_idle_state(...) } ----------------|---------------------------------------|---------------------|------------------|--------------------------------------------|-------------------- 1.IDLE_START 2.CPU_PM_ENTER 3.now 4.select idle state next_event (sleep_length) Signed-off-by: Zhaoyang Huang --- kernel/time/tick-sched.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kernel/time/tick-sched.c b/kernel/time/tick-sched.c index 536ada8..ee3be3d 100644 --- a/kernel/time/tick-sched.c +++ b/kernel/time/tick-sched.c @@ -975,6 +975,11 @@ void tick_nohz_irq_exit(void) ktime_t tick_nohz_get_sleep_length(void) { struct tick_sched *ts = this_cpu_ptr(&tick_cpu_sched); + struct clock_event_device *dev = __this_cpu_read(tick_cpu_device.evtdev); + ktime_t now; + + now = ktime_get(); + ts->sleep_length = ktime_sub(dev->next_event, now); return ts->sleep_length; }