From patchwork Thu Jul 3 16:26:09 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Morten Rasmussen X-Patchwork-Id: 33036 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f199.google.com (mail-ie0-f199.google.com [209.85.223.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 94748203AC for ; Thu, 3 Jul 2014 16:26:54 +0000 (UTC) Received: by mail-ie0-f199.google.com with SMTP id rl12sf2111689iec.6 for ; Thu, 03 Jul 2014 09:26:54 -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:content-type :content-transfer-encoding; bh=Gf8EyzXJtG/tEmVMT7UsXDtWHt2gIx3F80UnmQ1fahQ=; b=VQ5MJz0qzePcX1FrEm5DbmRBSaj28bF4LmfgI5RJBrpMggYila1y0SIpCUMUMwYNm4 I62TQu/hC7Jxv0DTZbXaDJHjTPSGRL/XEpd0G2WjzQ8EWA9/GwwWEXVgUQf4Byzb/VV1 wfUJwGCMOjzrTnXOlO1fSXxv4QUCaXw58IDRW7CQVzgSq75DS7WbKtK5B/Ys+BsaTrpL Kw8dfc3DXSOHcYcGWY/Eq2i3Pr4KyMWSlUiQWyMhH63irxUEZ3UBGzWQizFOgA3tAov+ pHpB1b9yK0XnoKK1VUTdbcWcBgHq85XtM4kbfU6MWO8QEaQvPLn4xfTvEc2NydXOukJ6 MOQQ== X-Gm-Message-State: ALoCoQm85+XAV2ocVXn0/v8xjQWEYXsu7csaBj8nRBl948akKtMCqckmohj5MY2tCAgC17X8Lmq8 X-Received: by 10.50.44.69 with SMTP id c5mr9339092igm.3.1404404814084; Thu, 03 Jul 2014 09:26:54 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.89.104 with SMTP id u95ls570749qgd.5.gmail; Thu, 03 Jul 2014 09:26:53 -0700 (PDT) X-Received: by 10.221.40.193 with SMTP id tr1mr2298264vcb.31.1404404813947; Thu, 03 Jul 2014 09:26:53 -0700 (PDT) Received: from mail-ve0-f182.google.com (mail-ve0-f182.google.com [209.85.128.182]) by mx.google.com with ESMTPS id g9si2417687vda.41.2014.07.03.09.26.53 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 03 Jul 2014 09:26:53 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.182 as permitted sender) client-ip=209.85.128.182; Received: by mail-ve0-f182.google.com with SMTP id oy12so497476veb.27 for ; Thu, 03 Jul 2014 09:26:53 -0700 (PDT) X-Received: by 10.221.64.80 with SMTP id xh16mr1693179vcb.35.1404404813861; Thu, 03 Jul 2014 09:26:53 -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.221.37.5 with SMTP id tc5csp390340vcb; Thu, 3 Jul 2014 09:26:53 -0700 (PDT) X-Received: by 10.69.25.69 with SMTP id io5mr5943886pbd.22.1404404812876; Thu, 03 Jul 2014 09:26:52 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ho4si33280366pbc.180.2014.07.03.09.26.52; Thu, 03 Jul 2014 09:26:52 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759399AbaGCQ0k (ORCPT + 27 others); Thu, 3 Jul 2014 12:26:40 -0400 Received: from service87.mimecast.com ([91.220.42.44]:46035 "EHLO service87.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1759368AbaGCQ01 (ORCPT ); Thu, 3 Jul 2014 12:26:27 -0400 Received: from cam-owa2.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.21]) by service87.mimecast.com; Thu, 03 Jul 2014 17:26:26 +0100 Received: from e103034-lin.cambridge.arm.com ([10.1.255.212]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 3 Jul 2014 17:26:24 +0100 From: Morten Rasmussen To: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, peterz@infradead.org, mingo@kernel.org Cc: rjw@rjwysocki.net, vincent.guittot@linaro.org, daniel.lezcano@linaro.org, preeti@linux.vnet.ibm.com, Dietmar.Eggemann@arm.com, pjt@google.com Subject: [RFCv2 PATCH 22/23] sched: Use energy to guide wakeup task placement Date: Thu, 3 Jul 2014 17:26:09 +0100 Message-Id: <1404404770-323-23-git-send-email-morten.rasmussen@arm.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1404404770-323-1-git-send-email-morten.rasmussen@arm.com> References: <1404404770-323-1-git-send-email-morten.rasmussen@arm.com> X-OriginalArrivalTime: 03 Jul 2014 16:26:24.0834 (UTC) FILETIME=[8873FA20:01CF96DB] X-MC-Unique: 114070317262600201 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: morten.rasmussen@arm.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.182 as permitted sender) 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: , Attempt to pick most energy efficient wakeup in find_idlest_{group, cpu}(). Finding the optimum target requires an exhaustive search through all cpus in the groups. Instead, the target group is determined based on load and probing the energy cost on a single cpu in each group. The target cpu is the cpu with the lowest energy cost. Signed-off-by: Morten Rasmussen --- kernel/sched/fair.c | 71 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 57 insertions(+), 14 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index a32d6eb..2acd45a 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -4662,25 +4662,27 @@ static int wake_affine(struct sched_domain *sd, struct task_struct *p, int sync) } /* - * find_idlest_group finds and returns the least busy CPU group within the - * domain. + * find_target_group finds and returns the least busy/most energy-efficient + * CPU group within the domain. */ static struct sched_group * -find_idlest_group(struct sched_domain *sd, struct task_struct *p, +find_target_group(struct sched_domain *sd, struct task_struct *p, int this_cpu, int sd_flag) { - struct sched_group *idlest = NULL, *group = sd->groups; + struct sched_group *idlest = NULL, *group = sd->groups, *energy = NULL; unsigned long min_load = ULONG_MAX, this_load = 0; int load_idx = sd->forkexec_idx; int imbalance = 100 + (sd->imbalance_pct-100)/2; + int local_nrg = 0, min_nrg = INT_MAX; if (sd_flag & SD_BALANCE_WAKE) load_idx = sd->wake_idx; do { - unsigned long load, avg_load; + unsigned long load, avg_load, util, probe_util = UINT_MAX; int local_group; int i; + int probe_cpu, nrg_diff; /* Skip over this group if it has no CPUs allowed */ if (!cpumask_intersects(sched_group_cpus(group), @@ -4692,53 +4694,94 @@ find_idlest_group(struct sched_domain *sd, struct task_struct *p, /* Tally up the load of all CPUs in the group */ avg_load = 0; + probe_cpu = cpumask_first(sched_group_cpus(group)); for_each_cpu(i, sched_group_cpus(group)) { /* Bias balancing toward cpus of our domain */ - if (local_group) + if (local_group) { load = source_load(i, load_idx, 0); - else + util = source_load(i, load_idx, 1); + } else { load = target_load(i, load_idx, 0); + util = target_load(i, load_idx, 1); + } avg_load += load; + + if (util < probe_util) { + probe_util = util; + probe_cpu = i; + } } /* Adjust by relative CPU capacity of the group */ avg_load = (avg_load * SCHED_CAPACITY_SCALE) / group->sgc->capacity; + /* + * Sample energy diff on probe_cpu. + * Finding the optimum cpu requires testing all cpus which is + * expensive. + */ + + nrg_diff = energy_diff_task(probe_cpu, p); + if (local_group) { this_load = avg_load; - } else if (avg_load < min_load) { - min_load = avg_load; - idlest = group; + local_nrg = nrg_diff; + } else { + if (avg_load < min_load) { + min_load = avg_load; + idlest = group; + } + + if (nrg_diff < min_nrg) { + min_nrg = nrg_diff; + energy = group; + } } } while (group = group->next, group != sd->groups); + if (energy_aware()) { + if (energy && min_nrg < local_nrg) + return energy; + return NULL; + } + if (!idlest || 100*this_load < imbalance*min_load) return NULL; return idlest; } /* - * find_idlest_cpu - find the idlest cpu among the cpus in group. + * find_target_cpu - find the target cpu among the cpus in group. */ static int -find_idlest_cpu(struct sched_group *group, struct task_struct *p, int this_cpu) +find_target_cpu(struct sched_group *group, struct task_struct *p, int this_cpu) { unsigned long load, min_load = ULONG_MAX; + int min_nrg = INT_MAX, nrg, least_nrg = -1; int idlest = -1; int i; /* Traverse only the allowed CPUs */ for_each_cpu_and(i, sched_group_cpus(group), tsk_cpus_allowed(p)) { load = cpu_load(i, 0); + nrg = energy_diff_task(i, p); if (load < min_load || (load == min_load && i == this_cpu)) { min_load = load; idlest = i; } + + if (nrg < min_nrg) { + min_nrg = nrg; + least_nrg = i; + } } + if (least_nrg >= 0) + return least_nrg; + return idlest; } @@ -4886,13 +4929,13 @@ select_task_rq_fair(struct task_struct *p, int prev_cpu, int sd_flag, int wake_f continue; } - group = find_idlest_group(sd, p, cpu, sd_flag); + group = find_target_group(sd, p, cpu, sd_flag); if (!group) { sd = sd->child; continue; } - new_cpu = find_idlest_cpu(group, p, cpu); + new_cpu = find_target_cpu(group, p, cpu); if (new_cpu == -1 || new_cpu == cpu) { /* Now try balancing at a lower domain level of cpu */ sd = sd->child;