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: 9199967 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 ABB3F60757 for ; Mon, 27 Jun 2016 07:42:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8829B2711E for ; Mon, 27 Jun 2016 07:42:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 67EAE275A2; Mon, 27 Jun 2016 07:42:30 +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=ham 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 493092711E for ; Mon, 27 Jun 2016 07:42:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750870AbcF0Hm2 (ORCPT ); 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 X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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: