From patchwork Mon Mar 3 07:48:54 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 25589 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f199.google.com (mail-ve0-f199.google.com [209.85.128.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6FB9A20540 for ; Mon, 3 Mar 2014 07:49:45 +0000 (UTC) Received: by mail-ve0-f199.google.com with SMTP id cz12sf1572169veb.2 for ; Sun, 02 Mar 2014 23:49:44 -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=1s4z9up2FAoDAwacUKwEVkde9b26+NzPTR+qC6dbC5Y=; b=g9tqDVgT1sIf3JBZDrW6n3KjNVbunyvGy6H2Ngj64Eh4TiR1ZDtwPBhEsWoMZBl+Y5 JVJ5KckRGbAOjyj0ltSEqiaSIgWKt7wZ1AUWPt0l58On/CUJxAx0VSMrDC5IUPL+V0Bo S8WMBvduIfSsOM1Xmr0BHU009g6ICbgz5jM4v+t8ruj+zZ5lLkFaQ6OYLZCeFpAF8j/1 cO2iij2cZsOG0jE6a60yN/Pk/wWWPujcNJlsux9NfnemuOQb/ojILqqiOpaLNitSoCOc vFw8wqBhjZ7xPJPt5wgqVoh2gsyE5J/TEWlvTrjzLtd5GmlKgiaDeDdDj34IcLIZ7hRX 8xQg== X-Gm-Message-State: ALoCoQkYEPA+cVY5SPwGWnrjMpW7FHll4Z/4hCVCshuoSNswBKTbHK4DJR+KZZUAXzX4EwO810EP X-Received: by 10.52.94.47 with SMTP id cz15mr12924767vdb.0.1393832984966; Sun, 02 Mar 2014 23:49:44 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.96.52 with SMTP id j49ls1997621qge.7.gmail; Sun, 02 Mar 2014 23:49:44 -0800 (PST) X-Received: by 10.52.155.66 with SMTP id vu2mr127726vdb.50.1393832984861; Sun, 02 Mar 2014 23:49:44 -0800 (PST) Received: from mail-ve0-f179.google.com (mail-ve0-f179.google.com [209.85.128.179]) by mx.google.com with ESMTPS id uw4si3255665vdc.14.2014.03.02.23.49.44 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 02 Mar 2014 23:49:44 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.179 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.179; Received: by mail-ve0-f179.google.com with SMTP id db12so3365883veb.10 for ; Sun, 02 Mar 2014 23:49:44 -0800 (PST) X-Received: by 10.220.95.139 with SMTP id d11mr15977648vcn.21.1393832984781; Sun, 02 Mar 2014 23:49:44 -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.130.193 with SMTP id u1csp36228vcs; Sun, 2 Mar 2014 23:49:44 -0800 (PST) X-Received: by 10.68.19.164 with SMTP id g4mr18105119pbe.36.1393832983862; Sun, 02 Mar 2014 23:49:43 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id yo5si9699256pab.63.2014.03.02.23.49.43; Sun, 02 Mar 2014 23:49:43 -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 S1753947AbaCCHti (ORCPT + 26 others); Mon, 3 Mar 2014 02:49:38 -0500 Received: from mail-pd0-f181.google.com ([209.85.192.181]:42834 "EHLO mail-pd0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753873AbaCCHte (ORCPT ); Mon, 3 Mar 2014 02:49:34 -0500 Received: by mail-pd0-f181.google.com with SMTP id p10so3370003pdj.26 for ; Sun, 02 Mar 2014 23:49:33 -0800 (PST) X-Received: by 10.68.130.234 with SMTP id oh10mr4283438pbb.136.1393832973612; Sun, 02 Mar 2014 23:49:33 -0800 (PST) Received: from localhost.localdomain (z88l218.static.ctm.net. [202.175.88.218]) by mx.google.com with ESMTPSA id os1sm78855252pac.20.2014.03.02.23.49.28 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 02 Mar 2014 23:49:33 -0800 (PST) From: Daniel Lezcano To: peterz@infradead.org, mingo@kernel.org, tglx@linutronix.de, rjw@rjwysocki.net Cc: nicolas.pitre@linaro.org, preeti@linux.vnet.ibm.com, linux-kernel@vger.kernel.org, linaro-kernel@lists.linaro.org Subject: [PATCH V4 5/5] idle: Add more comments to the code Date: Mon, 3 Mar 2014 08:48:54 +0100 Message-Id: <1393832934-11625-5-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1393832934-11625-1-git-send-email-daniel.lezcano@linaro.org> References: <20140228125604.GN27965@twins.programming.kicks-ass.net> <1393832934-11625-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.128.179 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: V4: * updated comments with new code V3: * no changes V2: * fixed typo in comment --- kernel/sched/idle.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 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 @@ -76,21 +76,49 @@ static int cpuidle_idle_call(void) int next_state, entered_state, ret; bool broadcast; + /* + * 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 + */ ret = cpuidle_enabled(drv, dev); if (!ret) { - /* ask the governor for the next state */ + /* + * 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 (current_clr_polling_and_test()) { dev->last_residency = 0; entered_state = next_state; @@ -100,6 +128,14 @@ static int cpuidle_idle_call(void) CPUIDLE_FLAG_TIMER_STOP); if (broadcast) + /* + * Tell the time framework to switch + * to a broadcast timer because our + * local timer will be shutdown. If a + * local timer is used from another + * cpu as a broadcast timer, this call + * may fail if it is not available + */ ret = clockevents_notify( CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &dev->cpu); @@ -107,6 +143,14 @@ static int cpuidle_idle_call(void) if (!ret) { 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); @@ -118,17 +162,28 @@ static int cpuidle_idle_call(void) CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &dev->cpu); - /* give the governor an opportunity to reflect on the outcome */ + /* + * Give the governor an opportunity to reflect on the + * outcome + */ cpuidle_reflect(dev, entered_state); } } } + /* + * We can't use the cpuidle framework, let's use the default + * idle routine + */ if (ret) arch_cpu_idle(); __current_set_polling(); + /* + * It is up to the idle functions to enable back the local + * interrupt + */ if (WARN_ON_ONCE(irqs_disabled())) local_irq_enable();