From patchwork Mon Jun 27 07:42:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhaoyang Huang X-Patchwork-Id: 70901 Delivered-To: patch@linaro.org Received: by 10.140.28.4 with SMTP id 4csp939903qgy; Mon, 27 Jun 2016 00:42:29 -0700 (PDT) X-Received: by 10.98.48.198 with SMTP id w189mr30580918pfw.125.1467013349764; Mon, 27 Jun 2016 00:42:29 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ww9si25105052pab.83.2016.06.27.00.42.29; Mon, 27 Jun 2016 00:42:29 -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 S1750870AbcF0Hm2 (ORCPT + 14 others); Mon, 27 Jun 2016 03:42:28 -0400 Received: from mail-pa0-f46.google.com ([209.85.220.46]:35528 "EHLO mail-pa0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751385AbcF0Hm1 (ORCPT ); Mon, 27 Jun 2016 03:42:27 -0400 Received: by mail-pa0-f46.google.com with SMTP id hl6so56625807pac.2 for ; Mon, 27 Jun 2016 00:42:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id; bh=H9Tcs30nfpXUDzh/BI4dvHh1yxI3Ly34OKjjikhCjkI=; b=O/rxIl8vOnSDELV9rOblmIsoPPWzX0CHcX0IAdjLL38DCwzWoDQVGdrHmmmjNop4sp tiQyoqzjd3KpewTfZlTnJVLNm78CWCze/yn84xQdkYINiAN0ienzDKXYucstiAdsXZ4d qp4VHr8U8tlTVfr2JMCxvirsw/HuBTbJogqDg= 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; bh=H9Tcs30nfpXUDzh/BI4dvHh1yxI3Ly34OKjjikhCjkI=; b=ExChlj29L79+TmvKM4QUVVMbdwIl1pSL4uCdWQVGzuzqbn7B4bPbW2smsxC/k96TTK ggaa+DduspIgNSbetWVF+QfZySPVPba/u4cePIf8Pv4430X/u9wEhwaReHA86YpqTofO mHbJ1rLOnxlhLV6tdcpZCiM21skbdFYDZhLFXQrwJP6OQH0GwwqGeqqsS+mEJ/JoRrH5 KaZcC/tI84p2US9NXAJHzBpc3BYlFGyajFFR8taTi0L82cuK/EMeU6HelMrfqHa6Xisg GRjYcJOY2BOPD7Ya8b0HZ4RyyWqH4J4z0IjHh1Pa3YjTRhOT+RQAhCpUmKwG4dvgSsHf zA/g== X-Gm-Message-State: ALyK8tKcAcBbLql5VpVdKqFQfRuxnsn1PAh+JeMaFt46nt6rU9D8b7TABnjnOca/kJ90AIK/ X-Received: by 10.66.171.173 with SMTP id av13mr31273019pac.117.1467013346371; Mon, 27 Jun 2016 00:42:26 -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.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 27 Jun 2016 00:42:24 -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 1/2] power/cpuidle: enhance the precision of state select Date: Mon, 27 Jun 2016 15:42:15 +0800 Message-Id: <1467013336-19966-1-git-send-email-zhaoyang.huang@spreadtrum.com> X-Mailer: git-send-email 1.7.9.5 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org In previous version, cpu_pm_enter is invoked after the governor select the state, which cause the executing time of cpu_pm_enter is included in the idle time. Moving it before the state selection. 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/sched/idle.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) -- 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/sched/idle.c b/kernel/sched/idle.c index bd12c6c..929da2e 100644 --- a/kernel/sched/idle.c +++ b/kernel/sched/idle.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -130,6 +131,7 @@ static void cpuidle_idle_call(void) struct cpuidle_device *dev = __this_cpu_read(cpuidle_devices); struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev); int next_state, entered_state; + int ret; /* * Check if the idle task must be rescheduled. If it is the @@ -174,12 +176,16 @@ static void cpuidle_idle_call(void) /* * Ask the cpuidle framework to choose a convenient idle state. */ - next_state = cpuidle_select(drv, dev); - entered_state = call_cpuidle(drv, dev, next_state); - /* - * Give the governor an opportunity to reflect on the outcome - */ - cpuidle_reflect(dev, entered_state); + ret = cpu_pm_enter(); + if (!ret) { + next_state = cpuidle_select(drv, dev); + entered_state = call_cpuidle(drv, dev, next_state); + cpu_pm_exit(); + /* + * Give the governor an opportunity to reflect on the outcome + */ + cpuidle_reflect(dev, entered_state); + } } exit_idle: