From patchwork Fri Jan 17 09:04:04 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 23305 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ob0-f198.google.com (mail-ob0-f198.google.com [209.85.214.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 55C2C20540 for ; Fri, 17 Jan 2014 09:05:15 +0000 (UTC) Received: by mail-ob0-f198.google.com with SMTP id wm4sf12920629obc.9 for ; Fri, 17 Jan 2014 01:05:14 -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=XOv7XmUhbUI7h0xClINd6NHX/ESNPtN14YJUSoJn71k=; b=gL4FKcFysEekgl0AP2yHaXbGoOh20KZNAxYol376N6MIwQ9nbEx/8iC4nfl6C/SPAn Ack0tScJUPmHp4ZDYjRgAamDomf6zLMKgRtZ+QznG8ciOcesi+nXb1Gsfw9ZjHkCEnYW pcSOC3xzh724ssdeBYlHwx1a3HbEhKOqr2JRpiQcuLXIvniL/BT4jGRFSl6OffbsknEP Cr4D2zMT1D7OX0Czh9ViuZyVlV3g+d2OtDqK1gnXCjpLYM7thUsy2TPDTp+Swgt0TVHV 9EqDC4goecdLoMy8UCa8yLIdwaMhpLYRDVVZi2dsEhwmon6X8H1+9AO4VY+sTLpHuq/d NBvA== X-Gm-Message-State: ALoCoQn/HQ3Iqma6zG4/eWWPdIk0KAr1S9vAStoLgq18INQr8ldSHYLsQw3AC+jUoYP57vEgvpG3 X-Received: by 10.42.240.19 with SMTP id ky19mr265246icb.4.1389949514479; Fri, 17 Jan 2014 01:05:14 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.122.101 with SMTP id lr5ls1046759qeb.82.gmail; Fri, 17 Jan 2014 01:05:14 -0800 (PST) X-Received: by 10.220.97.145 with SMTP id l17mr319286vcn.35.1389949514354; Fri, 17 Jan 2014 01:05:14 -0800 (PST) Received: from mail-vc0-f182.google.com (mail-vc0-f182.google.com [209.85.220.182]) by mx.google.com with ESMTPS id a15si4604258vew.121.2014.01.17.01.05.14 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 17 Jan 2014 01:05:14 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.182 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.182; Received: by mail-vc0-f182.google.com with SMTP id id10so1420091vcb.41 for ; Fri, 17 Jan 2014 01:05:14 -0800 (PST) X-Received: by 10.52.92.115 with SMTP id cl19mr270140vdb.43.1389949514265; Fri, 17 Jan 2014 01:05:14 -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.59.13.131 with SMTP id ey3csp4882ved; Fri, 17 Jan 2014 01:05:12 -0800 (PST) X-Received: by 10.66.246.130 with SMTP id xw2mr915989pac.84.1389949512025; Fri, 17 Jan 2014 01:05:12 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id tr4si9549823pab.237.2014.01.17.01.05.10; Fri, 17 Jan 2014 01:05:10 -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 S1752273AbaAQJFC (ORCPT + 26 others); Fri, 17 Jan 2014 04:05:02 -0500 Received: from mail-wg0-f43.google.com ([74.125.82.43]:42547 "EHLO mail-wg0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751548AbaAQJEK (ORCPT ); Fri, 17 Jan 2014 04:04:10 -0500 Received: by mail-wg0-f43.google.com with SMTP id y10so4154969wgg.34 for ; Fri, 17 Jan 2014 01:04:09 -0800 (PST) X-Received: by 10.194.142.231 with SMTP id rz7mr496249wjb.89.1389949449897; Fri, 17 Jan 2014 01:04:09 -0800 (PST) Received: from localhost.localdomain (AToulouse-654-1-359-206.w90-60.abo.wanadoo.fr. [90.60.118.206]) by mx.google.com with ESMTPSA id ju6sm8671745wjc.1.2014.01.17.01.04.08 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 17 Jan 2014 01:04:09 -0800 (PST) From: Daniel Lezcano To: peterz@infradead.org, mingo@kernel.org Cc: linux-kernel@vger.kernel.org, linaro-kernel@lists.linaro.org, alex.shi@linaro.org Subject: [PATCH 4/4] sched: Idle task shortcut optimization Date: Fri, 17 Jan 2014 10:04:04 +0100 Message-Id: <1389949444-14821-4-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1389949444-14821-1-git-send-email-daniel.lezcano@linaro.org> References: <1389949444-14821-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.182 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: , With the previous patch, we have no ambiguity on going to idle. So we can pick directly the idle task instead of looking up all the domains which will in any case return no task except the idle_task. Signed-off-by: Daniel Lezcano --- kernel/sched/core.c | 43 ++++++++++++++++++++++++++++++++++++++----- kernel/sched/idle_task.c | 15 +++++---------- 2 files changed, 43 insertions(+), 15 deletions(-) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index b7e3635..c7a8f4e 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -2586,7 +2586,43 @@ pick_next_task(struct rq *rq) return p; } - BUG(); /* the idle class will always have a runnable task */ + /* + * We must have at least one task to run, the idle task is + * returned by the shortcut in pick_next_task_or_idle. If we + * fall here, we don't have any task to run, so something is + * wrong when we thought the cpu was not going to idle. + */ + BUG(); +} + +static inline struct task_struct *pick_next_task_or_idle(struct rq *rq) +{ + if (likely(rq->nr_running)) + return pick_next_task(rq); + + rq->idle_stamp = 0; + + /* + * If there is a task balanced on this cpu, pick the next task, + * otherwise fall in the optimization by picking the idle task + * directly. + */ + if (idle_balance(rq)) + return pick_next_task(rq); + + rq->idle_stamp = rq_clock(rq); + + /* + * Optimization: pick_next_task will return rq->idle in any case but + * after walking through the different sched domains. Let's add a + * shortcut to directly return the idle task. + */ + schedstat_inc(rq, sched_goidle); +#ifdef CONFIG_SMP + /* Trigger the post schedule to do an idle_enter for CFS */ + rq->post_schedule = 1; +#endif + return rq->idle; } /* @@ -2679,11 +2715,8 @@ need_resched: pre_schedule(rq, prev); - if (unlikely(!rq->nr_running)) - rq->idle_stamp = idle_balance(rq) ? 0 : rq_clock(rq); - put_prev_task(rq, prev); - next = pick_next_task(rq); + next = pick_next_task_or_idle(rq); clear_tsk_need_resched(prev); clear_preempt_need_resched(); rq->skip_clock_update = 0; diff --git a/kernel/sched/idle_task.c b/kernel/sched/idle_task.c index 516c3d9..0b4c94b 100644 --- a/kernel/sched/idle_task.c +++ b/kernel/sched/idle_task.c @@ -33,16 +33,6 @@ static void check_preempt_curr_idle(struct rq *rq, struct task_struct *p, int fl resched_task(rq->idle); } -static struct task_struct *pick_next_task_idle(struct rq *rq) -{ - schedstat_inc(rq, sched_goidle); -#ifdef CONFIG_SMP - /* Trigger the post schedule to do an idle_enter for CFS */ - rq->post_schedule = 1; -#endif - return rq->idle; -} - /* * It is not legal to sleep in the idle task - print a warning * message if some code attempts to do it: @@ -60,6 +50,11 @@ static void put_prev_task_idle(struct rq *rq, struct task_struct *prev) { } +static struct task_struct *pick_next_task_idle(struct rq *rq) +{ + return NULL; +} + static void task_tick_idle(struct rq *rq, struct task_struct *curr, int queued) { }