From patchwork Tue Oct 7 12:13:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 38397 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f71.google.com (mail-wg0-f71.google.com [74.125.82.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 31B1C202E7 for ; Tue, 7 Oct 2014 12:15:40 +0000 (UTC) Received: by mail-wg0-f71.google.com with SMTP id y10sf3969838wgg.2 for ; Tue, 07 Oct 2014 05:15:38 -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=mrf17hjo0igcbKbHwNNUyDeSNdWqMdzsIHaox4JH6nI=; b=WUlEYBi9mCO2a523uDScEXeYg7atOYmgSB96EVcfBo2v1eP97klhBkfBiUium9OOdx 2o9nmddetPE1vkwn/eRvlAco9yO3nldzSpvDbjTq+dgn3pKHo4Pvw0DdAJB9AScSkeYK N5yuG8Nmx0FohVuORS5slxcDKJeuBssTtrdI9i2CaVrzbJElrx6DNbV4SSDyTGvJHVcv 3WMBdZD3x2gT7i1Dgb2rV8SAipQShTlmXzO7KR2xPPb2hhRLuVTKtckluom6byz4mlpI lC1QyVR80c9Pq65Sm/BKn1ddhDPuWjsX+k+nm+FnEooAVxDbV23PHxZxssRuY0OuKp0B iOng== X-Gm-Message-State: ALoCoQn5fx9NiHqUvSqMOZ8EpOvlmbePMpP3quQmRB9tDf1aJuo1UvgJkasC15VmLg1ZDC0MArHz X-Received: by 10.112.74.80 with SMTP id r16mr8324lbv.21.1412684137973; Tue, 07 Oct 2014 05:15:37 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.27.225 with SMTP id w1ls727643lag.2.gmail; Tue, 07 Oct 2014 05:15:37 -0700 (PDT) X-Received: by 10.152.197.2 with SMTP id iq2mr3698528lac.87.1412684137796; Tue, 07 Oct 2014 05:15:37 -0700 (PDT) Received: from mail-lb0-f170.google.com (mail-lb0-f170.google.com [209.85.217.170]) by mx.google.com with ESMTPS id pz7si25695245lbb.88.2014.10.07.05.15.37 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 07 Oct 2014 05:15:37 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) client-ip=209.85.217.170; Received: by mail-lb0-f170.google.com with SMTP id u10so6032714lbd.1 for ; Tue, 07 Oct 2014 05:15:37 -0700 (PDT) X-Received: by 10.152.22.137 with SMTP id d9mr3781504laf.29.1412684137701; Tue, 07 Oct 2014 05:15: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.130.169 with SMTP id of9csp338917lbb; Tue, 7 Oct 2014 05:15:36 -0700 (PDT) X-Received: by 10.70.55.42 with SMTP id o10mr3556247pdp.100.1412684136086; Tue, 07 Oct 2014 05:15:36 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id rd7si15611464pab.141.2014.10.07.05.15.35 for ; Tue, 07 Oct 2014 05:15:36 -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 S1753844AbaJGMPZ (ORCPT + 27 others); Tue, 7 Oct 2014 08:15:25 -0400 Received: from mail-wi0-f176.google.com ([209.85.212.176]:63299 "EHLO mail-wi0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751334AbaJGMPT (ORCPT ); Tue, 7 Oct 2014 08:15:19 -0400 Received: by mail-wi0-f176.google.com with SMTP id hi2so7631019wib.3 for ; Tue, 07 Oct 2014 05:15:17 -0700 (PDT) X-Received: by 10.180.100.38 with SMTP id ev6mr27159347wib.83.1412684117436; Tue, 07 Oct 2014 05:15:17 -0700 (PDT) Received: from lmenx30s.lme.st.com (LPuteaux-656-01-48-212.w82-127.abo.wanadoo.fr. [82.127.83.212]) by mx.google.com with ESMTPSA id v9sm20544897wjy.14.2014.10.07.05.15.15 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 07 Oct 2014 05:15:16 -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, daniel.lezcano@linaro.org, dietmar.eggemann@arm.com, pjt@google.com, bsegall@google.com, Vincent Guittot Subject: [PATCH v7 5/7] sched: get CPU's usage statistic Date: Tue, 7 Oct 2014 14:13:35 +0200 Message-Id: <1412684017-16595-6-git-send-email-vincent.guittot@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1412684017-16595-1-git-send-email-vincent.guittot@linaro.org> References: <1412684017-16595-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.217.170 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 amount of cpu_capacity 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_avg_contrib only takes into account the running time but not the uArch so the utilization_load_avg is in the range [0..SCHED_LOAD_SCALE] to reflect the running load on the CPU. We have to scale the utilization with the capacity of the CPU to get the usage of the latter. The usage can then be compared with the available capacity. The frequency scaling invariance is not taken into account in this patchset, it will be solved in another patchset Signed-off-by: Vincent Guittot --- kernel/sched/fair.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index d3e9067..7364ed4 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -4551,6 +4551,17 @@ static int select_idle_sibling(struct task_struct *p, int target) return target; } +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 + 1; + + return (usage * capacity) >> SCHED_LOAD_SHIFT; +} + /* * select_task_rq_fair: Select target runqueue for the waking task in domains * that have the 'sd_flag' flag set. In practice, this is SD_BALANCE_WAKE, @@ -5679,6 +5690,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; @@ -6053,6 +6065,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)