From patchwork Fri Mar 28 12:29:56 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 27278 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yk0-f199.google.com (mail-yk0-f199.google.com [209.85.160.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B437920062 for ; Fri, 28 Mar 2014 12:30:55 +0000 (UTC) Received: by mail-yk0-f199.google.com with SMTP id 200sf6486341ykr.2 for ; Fri, 28 Mar 2014 05:30:55 -0700 (PDT) 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=hiKyQqriq5QFnqgwllRu9wumTZn66F32J+nxxx93BWs=; b=GsgCbrhMRqep2tnYhSSpGg1ovKHeG7CbjEJfDqHALLN1emnbejd7l8jls3FXVZTVYX kocveKJr51fN6TTYXVqp3C3LjnJ0uvw3RkB9UaD4d3JcsK90t1kPDa64gj29pQ6CxxVA xqukUV0Sfd30gOpzMOxX12WefDJ9/TQEl+Uff6sxotRhtDIhYlBesybsTAwSalXystnn 1M1pSOE3FZTAUYGkJJnr3VEaBR0RAS24xoKvbvvObsad/+3hPZ2o2M3dG6kGLUTxKXn6 hr6QNonbrGMb3ltZwqZi82Lg7/2SzE6GdfQ5pZxjUQhgO3touuUa9Jm7Zx6mWsdkIcn9 rHlg== X-Gm-Message-State: ALoCoQkCdw4bFBtM134Ck8dbI0FhTr/re2IYjrBLPriV2ECO7zGAYfEFCjpOiF3gHzwAv1nSTlnw X-Received: by 10.58.248.99 with SMTP id yl3mr1977008vec.9.1396009855499; Fri, 28 Mar 2014 05:30:55 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.83.85 with SMTP id i79ls1571813qgd.21.gmail; Fri, 28 Mar 2014 05:30:55 -0700 (PDT) X-Received: by 10.52.104.7 with SMTP id ga7mr327468vdb.29.1396009855423; Fri, 28 Mar 2014 05:30:55 -0700 (PDT) Received: from mail-vc0-f178.google.com (mail-vc0-f178.google.com [209.85.220.178]) by mx.google.com with ESMTPS id m14si1222147vcn.17.2014.03.28.05.30.55 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 28 Mar 2014 05:30:55 -0700 (PDT) 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 im17so5667099vcb.23 for ; Fri, 28 Mar 2014 05:30:55 -0700 (PDT) X-Received: by 10.52.15.132 with SMTP id x4mr288277vdc.31.1396009855320; Fri, 28 Mar 2014 05:30:55 -0700 (PDT) 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.12.8 with SMTP id v8csp4616vcv; Fri, 28 Mar 2014 05:30:54 -0700 (PDT) X-Received: by 10.68.171.4 with SMTP id aq4mr8386876pbc.150.1396009854592; Fri, 28 Mar 2014 05:30:54 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id iu9si3585425pac.330.2014.03.28.05.30.53; Fri, 28 Mar 2014 05:30:54 -0700 (PDT) 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 S1752054AbaC1Map (ORCPT + 27 others); Fri, 28 Mar 2014 08:30:45 -0400 Received: from mail-wi0-f176.google.com ([209.85.212.176]:45582 "EHLO mail-wi0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751367AbaC1M3u (ORCPT ); Fri, 28 Mar 2014 08:29:50 -0400 Received: by mail-wi0-f176.google.com with SMTP id r20so689064wiv.3 for ; Fri, 28 Mar 2014 05:29:49 -0700 (PDT) X-Received: by 10.180.100.72 with SMTP id ew8mr47595082wib.16.1396009789215; Fri, 28 Mar 2014 05:29:49 -0700 (PDT) Received: from localhost.localdomain (AToulouse-654-1-301-183.w86-199.abo.wanadoo.fr. [86.199.84.183]) by mx.google.com with ESMTPSA id u6sm6805514wif.6.2014.03.28.05.29.47 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 28 Mar 2014 05:29:48 -0700 (PDT) From: Daniel Lezcano To: linux-kernel@vger.kernel.org, mingo@elte.hu, peterz@infradead.org Cc: rjw@rjwysocki.net, nicolas.pitre@linaro.org, linux-pm@vger.kernel.org, alex.shi@linaro.org, vincent.guittot@linaro.org, morten.rasmussen@arm.com Subject: [RFC PATCHC 3/3] sched/fair: use the idle state info to choose the idlest cpu Date: Fri, 28 Mar 2014 13:29:56 +0100 Message-Id: <1396009796-31598-4-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1396009796-31598-1-git-send-email-daniel.lezcano@linaro.org> References: <1396009796-31598-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: , As we know in which idle state the cpu is, we can investigate the following: 1. when did the cpu entered the idle state ? the longer the cpu is idle, the deeper it is idle 2. what exit latency is ? the greater the exit latency is, the deeper it is With both information, when all cpus are idle, we can choose the idlest cpu. When one cpu is not idle, the old check against weighted load applies. Signed-off-by: Daniel Lezcano --- kernel/sched/fair.c | 46 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 16042b5..068e503 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -4336,20 +4337,53 @@ static int find_idlest_cpu(struct sched_group *group, struct task_struct *p, int this_cpu) { unsigned long load, min_load = ULONG_MAX; - int idlest = -1; + unsigned int min_exit_latency = UINT_MAX; + u64 idle_stamp, min_idle_stamp = ULONG_MAX; + + struct rq *rq; + struct cpuidle_power *power; + + int cpu_idle = -1; + int cpu_busy = -1; int i; /* Traverse only the allowed CPUs */ for_each_cpu_and(i, sched_group_cpus(group), tsk_cpus_allowed(p)) { - load = weighted_cpuload(i); - if (load < min_load || (load == min_load && i == this_cpu)) { - min_load = load; - idlest = i; + if (idle_cpu(i)) { + + rq = cpu_rq(i); + power = rq->power; + idle_stamp = rq->idle_stamp; + + /* The cpu is idle since a shorter time */ + if (idle_stamp < min_idle_stamp) { + min_idle_stamp = idle_stamp; + cpu_idle = i; + continue; + } + + /* The cpu is idle but the exit_latency is shorter */ + if (power && power->exit_latency < min_exit_latency) { + min_exit_latency = power->exit_latency; + cpu_idle = i; + continue; + } + } else { + + load = weighted_cpuload(i); + + if (load < min_load || + (load == min_load && i == this_cpu)) { + min_load = load; + cpu_busy = i; + continue; + } } } - return idlest; + /* Busy cpus are considered less idle than idle cpus ;) */ + return cpu_busy != -1 ? cpu_busy : cpu_idle; } /*