From patchwork Thu Jan 30 14:09:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 23927 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f70.google.com (mail-qa0-f70.google.com [209.85.216.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C928F20341 for ; Thu, 30 Jan 2014 14:10:22 +0000 (UTC) Received: by mail-qa0-f70.google.com with SMTP id ii20sf6782099qab.1 for ; Thu, 30 Jan 2014 06:10:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=/OxAwa4OrkQfIIIzaPBS+1AuOJotu/lAWi8SLjuuEvc=; b=jSp08eQs+lih8T8tTSs51O2v4o0DhrOz/x6oiFESS2aOr0iCIAW4hMqMYFkQRQvjiJ CHVHJp0x2P7/z5Lv81db6/BAmnNU9UDPC2gSvIxWsyjDNyPl3JTA97OBlzFunnDMeOqR RVcXj4/x+aI2AMYw+6MD+39FTffWnMgGTjCcegWKbkBSWOths9ADWpBmJ9ev59sLCl+U g+REYGv6oGfBmPijs8pXqCynVkogArBrl2Qo8/p8TVgMLusIiF4jYQtqjsm0hYCjvdW6 mA8wIZMuYgKmKXrRPvNgsGnU0qn4weeIYRxyOwF99mzVSfS0erTgz1/Fo5OQaM4B8Zak drFw== X-Gm-Message-State: ALoCoQnI8x+2W3XhBO++ONtOFyJIy0ymYjZHCyc/PCYohRLgFyAlmykOFEiFjIjQ1/BxUOX9+Lr8 X-Received: by 10.236.53.71 with SMTP id f47mr3605741yhc.53.1391091021970; Thu, 30 Jan 2014 06:10:21 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.50.5 with SMTP id r5ls559246qga.22.gmail; Thu, 30 Jan 2014 06:10:21 -0800 (PST) X-Received: by 10.52.246.133 with SMTP id xw5mr683385vdc.32.1391091021462; Thu, 30 Jan 2014 06:10:21 -0800 (PST) Received: from mail-vc0-f178.google.com (mail-vc0-f178.google.com [209.85.220.178]) by mx.google.com with ESMTPS id tt2si2107163vdc.61.2014.01.30.06.10.21 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 30 Jan 2014 06:10:21 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.178 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.178; Received: by mail-vc0-f178.google.com with SMTP id ik5so2096275vcb.37 for ; Thu, 30 Jan 2014 06:10:21 -0800 (PST) X-Received: by 10.220.147.16 with SMTP id j16mr787719vcv.28.1391091021370; Thu, 30 Jan 2014 06:10:21 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.174.196 with SMTP id u4csp15371vcz; Thu, 30 Jan 2014 06:10:20 -0800 (PST) X-Received: by 10.66.232.68 with SMTP id tm4mr14393862pac.114.1391091020254; Thu, 30 Jan 2014 06:10:20 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ql6si6642936pbb.73.2014.01.30.06.10.19; Thu, 30 Jan 2014 06:10:19 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753697AbaA3OKL (ORCPT + 27 others); Thu, 30 Jan 2014 09:10:11 -0500 Received: from mail-ea0-f175.google.com ([209.85.215.175]:53823 "EHLO mail-ea0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753305AbaA3OJZ (ORCPT ); Thu, 30 Jan 2014 09:09:25 -0500 Received: by mail-ea0-f175.google.com with SMTP id z10so1652214ead.20 for ; Thu, 30 Jan 2014 06:09:24 -0800 (PST) X-Received: by 10.14.246.68 with SMTP id p44mr2659495eer.72.1391090964478; Thu, 30 Jan 2014 06:09:24 -0800 (PST) Received: from localhost.localdomain (AToulouse-654-1-350-230.w90-55.abo.wanadoo.fr. [90.55.189.230]) by mx.google.com with ESMTPSA id m9sm9603594eeh.3.2014.01.30.06.09.22 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 30 Jan 2014 06:09:23 -0800 (PST) From: Daniel Lezcano To: nicolas.pitre@linaro.org, peterz@infradead.org, mingo@redhat.com, tglx@linutronix.de, rjw@rjwysocki.net Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, linaro-kernel@lists.linaro.org Subject: [RFC PATCH 1/3] cpuidle: split cpuidle_idle_call main function into functions Date: Thu, 30 Jan 2014 15:09:20 +0100 Message-Id: <1391090962-15032-2-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1391090962-15032-1-git-send-email-daniel.lezcano@linaro.org> References: <1391090962-15032-1-git-send-email-daniel.lezcano@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.220.178 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 Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , In order to allow better integration between the cpuidle framework and the scheduler, reducing the distance between the sub-component helps. This patch splits the cpuidle_idle_call main entry function into 3 big chunks of API: 1. select the idle state 2. enter the idle state 3. reflect the idle state The cpuidle_idle_call now calls these three functions to implement the main idle entry function. Signed-off-by: Daniel Lezcano --- drivers/cpuidle/cpuidle.c | 105 ++++++++++++++++++++++++++++++++------------- include/linux/cpuidle.h | 7 +++ 2 files changed, 83 insertions(+), 29 deletions(-) diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c index a55e68f..a8fbb28 100644 --- a/drivers/cpuidle/cpuidle.c +++ b/drivers/cpuidle/cpuidle.c @@ -108,6 +108,74 @@ int cpuidle_enter_state(struct cpuidle_device *dev, struct cpuidle_driver *drv, } /** + * cpuidle_select - ask the cpuidle framework to choose an idle state + * + * @drv: the cpuidle driver + * @dev: the cpuidle device + * + * Returns the index of the idle state. On error it returns: + * -NODEV : the cpuidle framework is available + * -EBUSY : the cpuidle framework is not initialized + */ +int cpuidle_select(struct cpuidle_driver *drv, struct cpuidle_device *dev) +{ + if (off || !initialized) + return -ENODEV; + + if (!drv || !dev || !dev->enabled) + return -EBUSY; + + return cpuidle_curr_governor->select(drv, dev); +} +EXPORT_SYMBOL(cpuidle_select); + +/** + * cpuidle_enter - enter into the specified idle state + * + * @drv: the cpuidle driver tied with the cpu + * @dev: the cpuidle device + * @index: the index in the idle state table + * + * Returns the index in the idle state, < 0 in case of error. + * The error code depends on the backend driver + */ +int cpuidle_enter(struct cpuidle_driver *drv, struct cpuidle_device *dev, + int index) +{ + int entered_state; + bool broadcast = !!(drv->states[index].flags & CPUIDLE_FLAG_TIMER_STOP); + + if (broadcast) + clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &dev->cpu); + + if (cpuidle_state_is_coupled(dev, drv, index)) + entered_state = cpuidle_enter_state_coupled(dev, drv, index); + else + entered_state = cpuidle_enter_state(dev, drv, index); + + if (broadcast) + clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &dev->cpu); + + return entered_state; +} +EXPORT_SYMBOL(cpuidle_enter); + +/** + * cpuidle_reflect - tell the underlying governor what was the state + * we were in + * + * @dev : the cpuidle device + * @index: the index in the idle state table + * + */ +void cpuidle_reflect(struct cpuidle_device *dev, int index) +{ + if (cpuidle_curr_governor->reflect) + cpuidle_curr_governor->reflect(dev, index); +} +EXPORT_SYMBOL(cpuidle_reflect); + +/** * cpuidle_idle_call - the main idle loop * * NOTE: no locks or semaphores should be used here @@ -116,51 +184,30 @@ int cpuidle_enter_state(struct cpuidle_device *dev, struct cpuidle_driver *drv, int cpuidle_idle_call(void) { struct cpuidle_device *dev = __this_cpu_read(cpuidle_devices); - struct cpuidle_driver *drv; + struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev); int next_state, entered_state; - bool broadcast; - - if (off || !initialized) - return -ENODEV; - - /* check if the device is ready */ - if (!dev || !dev->enabled) - return -EBUSY; - - drv = cpuidle_get_cpu_driver(dev); /* ask the governor for the next state */ - next_state = cpuidle_curr_governor->select(drv, dev); + next_state = cpuidle_select(drv, dev); + if (next_state < 0) + return next_state; + if (need_resched()) { dev->last_residency = 0; /* give the governor an opportunity to reflect on the outcome */ - if (cpuidle_curr_governor->reflect) - cpuidle_curr_governor->reflect(dev, next_state); + cpuidle_reflect(dev, next_state); local_irq_enable(); return 0; } trace_cpu_idle_rcuidle(next_state, dev->cpu); - broadcast = !!(drv->states[next_state].flags & CPUIDLE_FLAG_TIMER_STOP); - - if (broadcast) - clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &dev->cpu); - - if (cpuidle_state_is_coupled(dev, drv, next_state)) - entered_state = cpuidle_enter_state_coupled(dev, drv, - next_state); - else - entered_state = cpuidle_enter_state(dev, drv, next_state); - - if (broadcast) - clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &dev->cpu); + entered_state = cpuidle_enter(drv, dev, next_state); trace_cpu_idle_rcuidle(PWR_EVENT_EXIT, dev->cpu); /* give the governor an opportunity to reflect on the outcome */ - if (cpuidle_curr_governor->reflect) - cpuidle_curr_governor->reflect(dev, entered_state); + cpuidle_reflect(dev, entered_state); return 0; } diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h index 50fcbb0..1ebe9ff 100644 --- a/include/linux/cpuidle.h +++ b/include/linux/cpuidle.h @@ -119,6 +119,13 @@ struct cpuidle_driver { #ifdef CONFIG_CPU_IDLE extern void disable_cpuidle(void); + +extern int cpuidle_select(struct cpuidle_driver *drv, + struct cpuidle_device *dev); +extern int cpuidle_enter(struct cpuidle_driver *drv, + struct cpuidle_device *dev, int index); +extern void cpuidle_reflect(struct cpuidle_device *dev, int index); + extern int cpuidle_idle_call(void); extern int cpuidle_register_driver(struct cpuidle_driver *drv); extern struct cpuidle_driver *cpuidle_get_driver(void);