From patchwork Fri Oct 31 08:47:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 39872 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 448F2202FE for ; Fri, 31 Oct 2014 08:50:38 +0000 (UTC) Received: by mail-wg0-f70.google.com with SMTP id x13sf3825418wgg.1 for ; Fri, 31 Oct 2014 01:50:37 -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=6NxsRo5S2s8tva3n4SmMMCaMByZEqGeobJdTgoDFxns=; b=Ig3Xo3kDTptEyztKqF/mgJBYO/sDraIdCdk4orJQc0YzCtMoG02PQFDaWQTBq9vJOR foGElb2SgkbcWfiq5hAf13QRGsiYWpvXpD25twtsdckm+8hEnbP4aDfjrKnN3aRSQmfV 8GPU6c39kKLYACRlnl/ITZeTGLcRsukH0RXhSq5uFKbbHn0Dp2CZTaLxqujFxoF2+/83 STsbUiKjH/7FG2hd0t9J6qLl0HVPGsIQhcoEdMC6qWi5sTPepOs4xeVd2hHtzUJCp8dX BIQ3aYbtz9QF329FmA/q4T5vgmFfy8i370irQLUN4ss8x4si1vOA4Fr1VYV+fZRfvWAc 5J6Q== X-Gm-Message-State: ALoCoQmQ/FWtdyn7pb6D3CYjQabxtfAoebj8lOVaYAJLWbYH65y8SxxNgKnZhNWM9Tol5HOS4hW8 X-Received: by 10.112.166.2 with SMTP id zc2mr17513lbb.24.1414745437471; Fri, 31 Oct 2014 01:50:37 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.29.170 with SMTP id l10ls371344lah.18.gmail; Fri, 31 Oct 2014 01:50:37 -0700 (PDT) X-Received: by 10.152.29.41 with SMTP id g9mr24897964lah.83.1414745437297; Fri, 31 Oct 2014 01:50:37 -0700 (PDT) Received: from mail-la0-f50.google.com (mail-la0-f50.google.com. [209.85.215.50]) by mx.google.com with ESMTPS id r5si15687971lal.3.2014.10.31.01.50.37 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 31 Oct 2014 01:50:37 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.50 as permitted sender) client-ip=209.85.215.50; Received: by mail-la0-f50.google.com with SMTP id hz20so3234668lab.23 for ; Fri, 31 Oct 2014 01:50:37 -0700 (PDT) X-Received: by 10.152.116.102 with SMTP id jv6mr24685214lab.40.1414745437171; Fri, 31 Oct 2014 01:50:37 -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.112.84.229 with SMTP id c5csp168258lbz; Fri, 31 Oct 2014 01:50:36 -0700 (PDT) X-Received: by 10.68.206.98 with SMTP id ln2mr23000365pbc.83.1414745435438; Fri, 31 Oct 2014 01:50:35 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id un1si8782165pac.76.2014.10.31.01.50.34 for ; Fri, 31 Oct 2014 01:50:35 -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 S1757564AbaJaIua (ORCPT + 26 others); Fri, 31 Oct 2014 04:50:30 -0400 Received: from mail-wg0-f45.google.com ([74.125.82.45]:41211 "EHLO mail-wg0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752765AbaJaIsN (ORCPT ); Fri, 31 Oct 2014 04:48:13 -0400 Received: by mail-wg0-f45.google.com with SMTP id x12so6006969wgg.32 for ; Fri, 31 Oct 2014 01:48:12 -0700 (PDT) X-Received: by 10.194.82.74 with SMTP id g10mr1158571wjy.116.1414745292354; Fri, 31 Oct 2014 01:48:12 -0700 (PDT) Received: from lmenx30s.st.com. (pas72-3-88-189-71-117.fbx.proxad.net. [88.189.71.117]) by mx.google.com with ESMTPSA id u5sm11636547wiz.9.2014.10.31.01.48.10 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 31 Oct 2014 01:48:11 -0700 (PDT) From: Vincent Guittot To: peterz@infradead.org, mingo@kernel.org, linux-kernel@vger.kernel.org, preeti@linux.vnet.ibm.com, Morten.Rasmussen@arm.com, kamalesh@linux.vnet.ibm.com, linux@arm.linux.org.uk, linux-arm-kernel@lists.infradead.org Cc: riel@redhat.com, efault@gmx.de, nicolas.pitre@linaro.org, linaro-kernel@lists.linaro.org, Vincent Guittot Subject: [PATCH v8 06/10] sched: get CPU's usage statistic Date: Fri, 31 Oct 2014 09:47:28 +0100 Message-Id: <1414745252-4895-7-git-send-email-vincent.guittot@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1414745252-4895-1-git-send-email-vincent.guittot@linaro.org> References: <1414745252-4895-1-git-send-email-vincent.guittot@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: vincent.guittot@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.50 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: , Monitor the usage level of each group of each sched_domain level. The usage is the portion of cpu_capacity_orig that is currently used on a CPU or group of CPUs. We use the utilization_load_avg to evaluate the usage level of each group. The utilization_load_avg only takes into account the running time of the CFS tasks on a CPU with a maximum value of SCHED_LOAD_SCALE when the CPU is fully utilized. Nevertheless, we must cap utilization_load_avg which can be temporaly greater than SCHED_LOAD_SCALE after the migration of a task on this CPU and until the metrics are stabilized. The utilization_load_avg is in the range [0..SCHED_LOAD_SCALE] to reflect the running load on the CPU whereas the available capacity for the CFS task is in the range [0..cpu_capacity_orig]. In order to test if a CPU is fully utilized by CFS tasks, we have to scale the utilization in the cpu_capacity_orig range of the CPU to get the usage of the latter. The usage can then be compared with the available capacity (ie cpu_capacity) to deduct the usage level of a CPU. The frequency scaling invariance of the usage is not taken into account in this patch, it will be solved in another patch which will deal with frequency scaling invariance on the running_load_avg. Signed-off-by: Vincent Guittot --- kernel/sched/fair.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 9ab5233..7ca5656 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -4552,6 +4552,33 @@ static int select_idle_sibling(struct task_struct *p, int target) done: return target; } +/* + * get_cpu_usage returns the amount of capacity of a CPU that is used by CFS + * tasks. The unit of the return value must capacity so we can compare the + * usage with the capacity of the CPU that is available for CFS task (ie + * cpu_capacity). + * cfs.utilization_load_avg is the sum of running time of runnable tasks on a + * CPU. It represents the amount of utilization of a CPU in the range + * [0..SCHED_LOAD_SCALE]. The usage of a CPU can't be higher than the full + * capacity of the CPU because it's about the running time on this CPU. + * Nevertheless, cfs.utilization_load_avg can be higher than SCHED_LOAD_SCALE + * because of unfortunate rounding in avg_period and running_load_avg or just + * after migrating tasks until the average stabilizes with the new running + * time. So we need to check that the usage stays into the range + * [0..cpu_capacity_orig] and cap if necessary. + * Without capping the usage, a group could be seen as overloaded (CPU0 usage + * at 121% + CPU1 usage at 80%) whereas CPU1 has 20% of available capacity/ + */ +static int get_cpu_usage(int cpu) +{ + unsigned long usage = cpu_rq(cpu)->cfs.utilization_load_avg; + unsigned long capacity = capacity_orig_of(cpu); + + if (usage >= SCHED_LOAD_SCALE) + return capacity; + + return (usage * capacity) >> SCHED_LOAD_SHIFT; +} /* * select_task_rq_fair: Select target runqueue for the waking task in domains @@ -5681,6 +5708,7 @@ struct sg_lb_stats { unsigned long sum_weighted_load; /* Weighted load of group's tasks */ unsigned long load_per_task; unsigned long group_capacity; + unsigned long group_usage; /* Total usage of the group */ unsigned int sum_nr_running; /* Nr tasks running in the group */ unsigned int group_capacity_factor; unsigned int idle_cpus; @@ -6048,6 +6076,7 @@ static inline void update_sg_lb_stats(struct lb_env *env, load = source_load(i, load_idx); sgs->group_load += load; + sgs->group_usage += get_cpu_usage(i); sgs->sum_nr_running += rq->cfs.h_nr_running; if (rq->nr_running > 1)