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: 70902 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp939975qgy; Mon, 27 Jun 2016 00:42:44 -0700 (PDT) X-Received: by 10.66.121.136 with SMTP id lk8mr31074134pab.51.1467013364042; Mon, 27 Jun 2016 00:42:44 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i8si25096202paw.129.2016.06.27.00.42.43; Mon, 27 Jun 2016 00:42:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-owner@vger.kernel.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751879AbcF0Hmk (ORCPT + 14 others); 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 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(+) -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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; }