From patchwork Mon Feb 24 13:55:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 25192 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f200.google.com (mail-pd0-f200.google.com [209.85.192.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 11B5D2066C for ; Mon, 24 Feb 2014 13:56:31 +0000 (UTC) Received: by mail-pd0-f200.google.com with SMTP id p10sf5721898pdj.7 for ; Mon, 24 Feb 2014 05:56:31 -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=6ZwKZ8HSdjD5QIKPycor8g+QCuwm4weAuRXCYY9wvmg=; b=avrsI7XmOQky8yhP/PsliZh9Q0VD7hsYntssno43HRK68WV67Zxn8cT0QBcTGUcpHB VBaxRixkc7lHxXgZ4DjcLgcEbDhHf08JqAFa+ejbOY/zyKQE7EsJiumDc/7Z/YIwaDip aoI5itG7qMTwyHYKDauFOzlX63kKZKkEtYjrRM2MBK3rNEa4EkXiEGco5etqlj3WM63x uHkOoR7sDcaGiMb/Ai+KU6o4S4O78hYyONsbtr2vtG0ZzRFfEXCyQped0IERIPspy+xH BtlNsdQ2slAB1tMg+WZNmb7Azg21AoYC6x2JUFGG9/ilxxRHtWl1iLAtijjQB04u/EwG rIBA== X-Gm-Message-State: ALoCoQmvmccTQVYwOH81HiTO3yenJJJXwts1Wnu4zUvGF5FUB0ARn2AjfCJoVcWD23x3YczIjTjK X-Received: by 10.68.216.230 with SMTP id ot6mr10885141pbc.3.1393250191267; Mon, 24 Feb 2014 05:56:31 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.42.138 with SMTP id c10ls1862749qga.63.gmail; Mon, 24 Feb 2014 05:56:31 -0800 (PST) X-Received: by 10.52.110.166 with SMTP id ib6mr10133160vdb.47.1393250191066; Mon, 24 Feb 2014 05:56:31 -0800 (PST) Received: from mail-vc0-f171.google.com (mail-vc0-f171.google.com [209.85.220.171]) by mx.google.com with ESMTPS id cx4si5855202vcb.5.2014.02.24.05.56.31 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 24 Feb 2014 05:56:31 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.171 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.171; Received: by mail-vc0-f171.google.com with SMTP id le5so5788050vcb.2 for ; Mon, 24 Feb 2014 05:56:31 -0800 (PST) X-Received: by 10.220.53.66 with SMTP id l2mr12645877vcg.33.1393250190882; Mon, 24 Feb 2014 05:56:30 -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 u4csp62791vcz; Mon, 24 Feb 2014 05:56:30 -0800 (PST) X-Received: by 10.66.146.199 with SMTP id te7mr25422253pab.106.1393250189105; Mon, 24 Feb 2014 05:56:29 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k7si49016pbl.221.2014.02.24.05.56.28; Mon, 24 Feb 2014 05:56:28 -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 S1753006AbaBXN4Q (ORCPT + 26 others); Mon, 24 Feb 2014 08:56:16 -0500 Received: from mail-wg0-f44.google.com ([74.125.82.44]:37120 "EHLO mail-wg0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752949AbaBXNz5 (ORCPT ); Mon, 24 Feb 2014 08:55:57 -0500 Received: by mail-wg0-f44.google.com with SMTP id k14so4618428wgh.11 for ; Mon, 24 Feb 2014 05:55:56 -0800 (PST) X-Received: by 10.180.105.41 with SMTP id gj9mr14497084wib.28.1393250156333; Mon, 24 Feb 2014 05:55:56 -0800 (PST) Received: from localhost.localdomain (AToulouse-654-1-343-25.w90-55.abo.wanadoo.fr. [90.55.62.25]) by mx.google.com with ESMTPSA id f7sm42338516wjb.7.2014.02.24.05.55.55 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 24 Feb 2014 05:55:55 -0800 (PST) From: Daniel Lezcano To: mingo@kernel.org, peterz@infradead.org, tglx@linutronix.de, rjw@rjwysocki.net Cc: nicolas.pitre@linaro.org, preeti@linux.vnet.ibm.com, linux-kernel@vger.kernel.org Subject: [PATCH V2 5/5] idle: Add more comments to the code Date: Mon, 24 Feb 2014 14:55:51 +0100 Message-Id: <1393250151-6982-5-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1393250151-6982-1-git-send-email-daniel.lezcano@linaro.org> References: <1393250151-6982-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.171 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: , The idle main function is a complex and a critical function. Added more comments to the code. Signed-off-by: Daniel Lezcano Acked-by: Nicolas Pitre --- Changelog: V2: * fixed typo in comment --- kernel/sched/idle.c | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ Index: cpuidle-next/kernel/sched/idle.c =================================================================== --- cpuidle-next.orig/kernel/sched/idle.c +++ cpuidle-next/kernel/sched/idle.c @@ -86,15 +86,34 @@ static int cpuidle_idle_call(void) if (cpu_idle_force_poll || tick_check_broadcast_expired()) return cpu_idle_poll(); + /* + * Check if the idle task must be rescheduled. If it is the case, + * exit the function after re-enabling the local irq and set again + * the polling flag + */ if (current_clr_polling_and_test()) { local_irq_enable(); __current_set_polling(); return 0; } + /* + * During the idle period, stop measuring the disabled irqs + * critical sections latencies + */ stop_critical_timings(); + + /* + * Tell the RCU framework we are entering an idle section, + * so no more rcu read side critical sections and one more + * step to the grace period + */ rcu_idle_enter(); + /* + * Check if the cpuidle framework is ready, otherwise fallback + * to the default arch specific idle method + */ next_state = cpuidle_enabled(drv, dev); if (next_state < 0) { arch_cpu_idle(); @@ -102,13 +121,16 @@ static int cpuidle_idle_call(void) } /* - * Ask the governor for the next state, this call can fail for - * different reasons: cpuidle is not enabled or an idle state - * fulfilling the constraints was not found. In this case, we - * fall back to the default idle function + * Ask the governor to choose an idle state it thinks it is + * convenient to go to. There is *always* a convenient idle + * state */ next_state = cpuidle_select(drv, dev); + /* + * The idle task must be scheduled, it is pointless to go to idle, + * just update no idle residency and get out of this function + */ if (need_resched()) { dev->last_residency = 0; /* give the governor an opportunity to reflect on the outcome */ @@ -119,6 +141,12 @@ static int cpuidle_idle_call(void) trace_cpu_idle_rcuidle(next_state, dev->cpu); + /* + * Enter the idle state previously returned by the governor + * decision. This function will block until an interrupt + * occurs and will take care of re-enabling the local + * interrupts + */ entered_state = cpuidle_enter(drv, dev, next_state); trace_cpu_idle_rcuidle(PWR_EVENT_EXIT, dev->cpu); @@ -155,6 +183,10 @@ static void cpu_idle_loop(void) local_irq_disable(); arch_cpu_idle_enter(); + /* + * It is up to the underlying functions to + * enable the local interrupts again + */ cpuidle_idle_call(); arch_cpu_idle_exit();