From patchwork Mon Mar 3 07:48:53 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 25591 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f197.google.com (mail-ie0-f197.google.com [209.85.223.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E112320E7C for ; Mon, 3 Mar 2014 07:49:44 +0000 (UTC) Received: by mail-ie0-f197.google.com with SMTP id rd18sf18193568iec.8 for ; Sun, 02 Mar 2014 23:49:43 -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=gJXvWxBLph63951rsHK/TNgZ38R+D8W6q1ljMk5Wp0U=; b=L24AengPjVoyCqSP5pgr2ORtwOCDYnqWMHAnNVJ0+bQxhCR/lE8WunnIgjJbaHnSS2 WMpGlWzMFPwP/uX3sfDGRJyL+zhkFHLoUBEhxINGi04KDQxipwtnnR3gUYzXQgcd+Iic WbPtXCtFRSC7gR7rK0C/p2nPYZV7fUZvzxLcbu1I9b8zUjtMj5m9K/M6iwHHl+G2f3xI cDXs8UZreXCwZz2y7zck9bLAVksg9zPNkczfFCZICFnA9slhyvyIpFNazHsFncdLgZl2 IdQfaH4iowU6bhyfOGKfVQBbb4XfSTzeFaPr86S9pRkEhExxsb+hJNa7+Zqk8bjblGrM CZjA== X-Gm-Message-State: ALoCoQm3ziNNHDAhyB/J7i6+6TsQcSpCfKbXemA3s6gr5N9V1XemFrryp3pCNAYSA1nLu+VbBD90 X-Received: by 10.50.164.198 with SMTP id ys6mr8209236igb.2.1393832983774; Sun, 02 Mar 2014 23:49:43 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.46.98 with SMTP id j89ls2105142qga.73.gmail; Sun, 02 Mar 2014 23:49:43 -0800 (PST) X-Received: by 10.58.209.36 with SMTP id mj4mr10341vec.47.1393832983595; Sun, 02 Mar 2014 23:49:43 -0800 (PST) Received: from mail-vc0-f180.google.com (mail-vc0-f180.google.com [209.85.220.180]) by mx.google.com with ESMTPS id j20si4515315vcx.19.2014.03.02.23.49.43 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 02 Mar 2014 23:49:43 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.180 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.180; Received: by mail-vc0-f180.google.com with SMTP id ks9so3135028vcb.25 for ; Sun, 02 Mar 2014 23:49:43 -0800 (PST) X-Received: by 10.58.201.5 with SMTP id jw5mr15459341vec.6.1393832983515; Sun, 02 Mar 2014 23:49:43 -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 u1csp36227vcs; Sun, 2 Mar 2014 23:49:43 -0800 (PST) X-Received: by 10.68.239.70 with SMTP id vq6mr1742839pbc.152.1393832982547; Sun, 02 Mar 2014 23:49:42 -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.41; Sun, 02 Mar 2014 23:49:41 -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 S1753918AbaCCHtd (ORCPT + 26 others); Mon, 3 Mar 2014 02:49:33 -0500 Received: from mail-pb0-f52.google.com ([209.85.160.52]:39485 "EHLO mail-pb0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753873AbaCCHt2 (ORCPT ); Mon, 3 Mar 2014 02:49:28 -0500 Received: by mail-pb0-f52.google.com with SMTP id rr13so3417241pbb.25 for ; Sun, 02 Mar 2014 23:49:27 -0800 (PST) X-Received: by 10.68.202.230 with SMTP id kl6mr18249530pbc.55.1393832967547; Sun, 02 Mar 2014 23:49:27 -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.22 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 02 Mar 2014 23:49:27 -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 4/5] idle: Move idle conditions in cpuidle_idle main function Date: Mon, 3 Mar 2014 08:48:53 +0100 Message-Id: <1393832934-11625-4-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.220.180 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: , This patch moves the condition before entering idle into the cpuidle main function located in idle.c. That simplify the idle mainloop functions and increase the readibility of the conditions to enter truly idle. This patch is code reorganization and does not change the behavior of the function. Signed-off-by: Daniel Lezcano Cc: Peter Zijlstra --- V4: * took into account clockevents_notify(ENTER) could fail * removed an extra current_clr_polling_and_test added in V3 V3: * reorganized cpuidle_idle_call function as Suggested by Peter Zijlstra https://lkml.org/lkml/2014/2/24/492 --- kernel/sched/idle.c | 84 +++++++++++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 37 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,44 +76,59 @@ static int cpuidle_idle_call(void) int next_state, entered_state, ret; bool broadcast; + if (current_clr_polling_and_test()) { + local_irq_enable(); + __current_set_polling(); + return 0; + } + stop_critical_timings(); rcu_idle_enter(); ret = cpuidle_enabled(drv, dev); - if (ret < 0) { - arch_cpu_idle(); - goto out; - } - /* ask the governor for the next state */ - next_state = cpuidle_select(drv, dev); + if (!ret) { + /* ask the governor for the next state */ + next_state = cpuidle_select(drv, dev); + + if (current_clr_polling_and_test()) { + dev->last_residency = 0; + entered_state = next_state; + local_irq_enable(); + } else { + broadcast = !!(drv->states[next_state].flags & + CPUIDLE_FLAG_TIMER_STOP); + + if (broadcast) + ret = clockevents_notify( + CLOCK_EVT_NOTIFY_BROADCAST_ENTER, + &dev->cpu); + + if (!ret) { + trace_cpu_idle_rcuidle(next_state, dev->cpu); + + entered_state = cpuidle_enter(drv, dev, + next_state); + + trace_cpu_idle_rcuidle(PWR_EVENT_EXIT, + dev->cpu); + + if (broadcast) + clockevents_notify( + CLOCK_EVT_NOTIFY_BROADCAST_EXIT, + &dev->cpu); - if (need_resched()) { - dev->last_residency = 0; - /* give the governor an opportunity to reflect on the outcome */ - cpuidle_reflect(dev, next_state); - local_irq_enable(); - goto out; + /* give the governor an opportunity to reflect on the outcome */ + cpuidle_reflect(dev, entered_state); + } + } } - broadcast = !!(drv->states[next_state].flags & CPUIDLE_FLAG_TIMER_STOP); - - if (broadcast && - clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_ENTER, &dev->cpu)) - return -EBUSY; - - trace_cpu_idle_rcuidle(next_state, dev->cpu); - - entered_state = cpuidle_enter(drv, dev, next_state); - - trace_cpu_idle_rcuidle(PWR_EVENT_EXIT, dev->cpu); + if (ret) + arch_cpu_idle(); - if (broadcast) - clockevents_notify(CLOCK_EVT_NOTIFY_BROADCAST_EXIT, &dev->cpu); + __current_set_polling(); - /* give the governor an opportunity to reflect on the outcome */ - cpuidle_reflect(dev, entered_state); -out: if (WARN_ON_ONCE(irqs_disabled())) local_irq_enable(); @@ -150,16 +165,11 @@ static void cpu_idle_loop(void) * know that the IPI is going to arrive right * away */ - if (cpu_idle_force_poll || tick_check_broadcast_expired()) { + if (cpu_idle_force_poll || tick_check_broadcast_expired()) cpu_idle_poll(); - } else { - if (!current_clr_polling_and_test()) { - cpuidle_idle_call(); - } else { - local_irq_enable(); - } - __current_set_polling(); - } + else + cpuidle_idle_call(); + arch_cpu_idle_exit(); }