From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1161812AbbBDSdx (ORCPT ); Wed, 4 Feb 2015 13:33:53 -0500 Received: from foss-mx-na.foss.arm.com ([217.140.108.86]:41735 "EHLO foss-mx-na.foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967048AbbBDSbx (ORCPT ); Wed, 4 Feb 2015 13:31:53 -0500 From: Morten Rasmussen To: peterz@infradead.org, mingo@redhat.com Cc: vincent.guittot@linaro.org, dietmar.eggemann@arm.com, yuyang.du@intel.com, preeti@linux.vnet.ibm.com, mturquette@linaro.org, nico@linaro.org, rjw@rjwysocki.net, juri.lelli@arm.com, linux-kernel@vger.kernel.org Subject: [RFCv3 PATCH 37/48] sched: Determine the current sched_group idle-state Date: Wed, 4 Feb 2015 18:31:14 +0000 Message-Id: <1423074685-6336-38-git-send-email-morten.rasmussen@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1423074685-6336-1-git-send-email-morten.rasmussen@arm.com> References: <1423074685-6336-1-git-send-email-morten.rasmussen@arm.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org To estimate the energy consumption of a sched_group in sched_group_energy() it is necessary to know which idle-state the group is in when it is idle. For now, it is assumed that this is the current idle-state (though it might be wrong). Based on the individual cpu idle-states group_idle_state() finds the group idle-state. cc: Ingo Molnar cc: Peter Zijlstra Signed-off-by: Morten Rasmussen --- kernel/sched/fair.c | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 4251e75..0e95eb5 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -4719,6 +4719,28 @@ static int find_new_capacity(struct energy_env *eenv, return idx; } +static int group_idle_state(struct sched_group *sg) +{ + struct sched_group_energy *sge = sg->sge; + int shallowest_state = sge->idle_states_below + sge->nr_idle_states; + int i; + + for_each_cpu(i, sched_group_cpus(sg)) { + int cpuidle_idx = idle_get_state_idx(cpu_rq(i)); + int group_idx = cpuidle_idx - sge->idle_states_below + 1; + + if (group_idx <= 0) + return 0; + + shallowest_state = min(shallowest_state, group_idx); + } + + if (shallowest_state >= sge->nr_idle_states) + return sge->nr_idle_states - 1; + + return shallowest_state; +} + /* * sched_group_energy(): Returns absolute energy consumption of cpus belonging * to the sched_group including shared resources shared only by members of the @@ -4762,7 +4784,7 @@ static unsigned int sched_group_energy(struct energy_env *eenv) do { unsigned group_util; int sg_busy_energy, sg_idle_energy; - int cap_idx; + int cap_idx, idle_idx; if (sg_shared_cap && sg_shared_cap->group_weight >= sg->group_weight) eenv->sg_cap = sg_shared_cap; @@ -4770,11 +4792,13 @@ static unsigned int sched_group_energy(struct energy_env *eenv) eenv->sg_cap = sg; cap_idx = find_new_capacity(eenv, sg->sge); + idle_idx = group_idle_state(sg); group_util = group_norm_usage(eenv, sg); sg_busy_energy = (group_util * sg->sge->cap_states[cap_idx].power) - >> SCHED_CAPACITY_SHIFT; - sg_idle_energy = ((SCHED_LOAD_SCALE-group_util) * sg->sge->idle_states[0].power) - >> SCHED_CAPACITY_SHIFT; + >> SCHED_CAPACITY_SHIFT; + sg_idle_energy = ((SCHED_LOAD_SCALE-group_util) + * sg->sge->idle_states[idle_idx].power) + >> SCHED_CAPACITY_SHIFT; total_energy += sg_busy_energy + sg_idle_energy; -- 1.9.1