From patchwork Mon May 4 22:10:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Turquette X-Patchwork-Id: 48007 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f199.google.com (mail-lb0-f199.google.com [209.85.217.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B326421550 for ; Mon, 4 May 2015 22:11:40 +0000 (UTC) Received: by lbbrr5 with SMTP id rr5sf45804182lbb.3 for ; Mon, 04 May 2015 15:11:39 -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:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=LoPaHiLpST86bLSHgyFvfUUW+t7iiQufAFHkCfrRvWM=; b=lSOqF4MKemhWeV79jKuBj1PiQ5/7OrJkVpeunYJILvpyVKB8eoc0jY8sUfBpwKHamZ VNuJViH/RC106D8tSeVR1AKlC0JItqbR+eyzFp4tlPBusLYKegxTs0uQtleA35w/1YUq T3k5a9ScanqMqzaOfOQf+aMicxzD77JFr0UWkqF1enP8ImmKoHmVv3AWrqK9k5CigkzU uQIYQpG68XymcAx0SttondQ9Z+oliGgr+0F+ESlEoFytB5Blyq21g2efdUcCC+Os5OEl ctKCdnr0KWTAiVol1LhUgEUydoAoVfyXHgvaB7e+/mfY7uwdeVEhV2uy3ghWEzPnaf5p JCsQ== X-Gm-Message-State: ALoCoQn9+Xa+GnxRp+qWUQV2UxTEgxBUFMS/ERIdDJCJq7p8seL0GTTCE8EEgutIRyDjp/+N4Jo0 X-Received: by 10.112.53.102 with SMTP id a6mr19997732lbp.16.1430777499657; Mon, 04 May 2015 15:11:39 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.8.114 with SMTP id q18ls833337laa.8.gmail; Mon, 04 May 2015 15:11:39 -0700 (PDT) X-Received: by 10.112.135.131 with SMTP id ps3mr21208963lbb.84.1430777499517; Mon, 04 May 2015 15:11:39 -0700 (PDT) Received: from mail-lb0-f175.google.com (mail-lb0-f175.google.com. [209.85.217.175]) by mx.google.com with ESMTPS id u1si10973042lau.12.2015.05.04.15.11.39 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 May 2015 15:11:39 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.175 as permitted sender) client-ip=209.85.217.175; Received: by lbbzk7 with SMTP id zk7so115277510lbb.0 for ; Mon, 04 May 2015 15:11:39 -0700 (PDT) X-Received: by 10.152.236.40 with SMTP id ur8mr21426742lac.19.1430777499425; Mon, 04 May 2015 15:11:39 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.112.67.65 with SMTP id l1csp1903957lbt; Mon, 4 May 2015 15:11:38 -0700 (PDT) X-Received: by 10.107.13.11 with SMTP id 11mr31156660ion.70.1430777498046; Mon, 04 May 2015 15:11:38 -0700 (PDT) Received: from mail-ie0-f171.google.com (mail-ie0-f171.google.com. [209.85.223.171]) by mx.google.com with ESMTPS id rv2si5972069igb.46.2015.05.04.15.11.37 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 May 2015 15:11:38 -0700 (PDT) Received-SPF: pass (google.com: domain of mturquette@linaro.org designates 209.85.223.171 as permitted sender) client-ip=209.85.223.171; Received: by iejt8 with SMTP id t8so141526687iej.2 for ; Mon, 04 May 2015 15:11:37 -0700 (PDT) X-Received: by 10.107.135.144 with SMTP id r16mr31321698ioi.13.1430777497309; Mon, 04 May 2015 15:11:37 -0700 (PDT) Received: from quantum.home (pool-71-119-96-202.lsanca.fios.verizon.net. [71.119.96.202]) by mx.google.com with ESMTPSA id ij7sm6042583igb.18.2015.05.04.15.11.34 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 04 May 2015 15:11:36 -0700 (PDT) From: Michael Turquette To: peterz@infradead.org, mingo@kernel.org Cc: linux-kernel@vger.kernel.org, preeti@linux.vnet.ibm.com, Morten.Rasmussen@arm.com, riel@redhat.com, efault@gmx.de, nicolas.pitre@linaro.org, inaro-kernel@lists.linaro.org, daniel.lezcano@linaro.org, patches@linaro.org, eas-dev@lists.linaro.org, dietmar.eggemann@arm.com, vincent.guittot@linaro.org, amit.kucheria@linaro.org, juri.lelli@arm.com, rjw@rjwysocki.net, viresh.kumar@linaro.org, ashwin.chaugule@linaro.org, alex.shi@linaro.org, Michael Turquette Subject: [PATCH 3/4] sched: export get_cpu_usage & capacity_orig_of Date: Mon, 4 May 2015 15:10:40 -0700 Message-Id: <1430777441-15087-4-git-send-email-mturquette@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1430777441-15087-1-git-send-email-mturquette@linaro.org> References: <1430777441-15087-1-git-send-email-mturquette@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: mturquette@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.175 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , get_cpu_usage and capacity_orig_of are useful for a cpu frequency scaling policy which is based on cfs load tracking and cpu capacity metrics. Expose these calls in sched.h so that they can be used in such a policy. Signed-off-by: Michael Turquette --- kernel/sched/fair.c | 32 -------------------------------- kernel/sched/sched.h | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 32 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 75aec8d..9e37d49 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -4366,11 +4366,6 @@ static unsigned long capacity_of(int cpu) return cpu_rq(cpu)->cpu_capacity; } -static unsigned long capacity_orig_of(int cpu) -{ - return cpu_rq(cpu)->cpu_capacity_orig; -} - static unsigned long cpu_avg_load_per_task(int cpu) { struct rq *rq = cpu_rq(cpu); @@ -4784,33 +4779,6 @@ next: 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 be the one of 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 diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index e0e1299..8bf35d3 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -1396,6 +1396,39 @@ unsigned long arch_scale_freq_capacity(struct sched_domain *sd, int cpu) } #endif +static inline unsigned long capacity_orig_of(int cpu) +{ + return cpu_rq(cpu)->cpu_capacity_orig; +} + +/* + * get_cpu_usage returns the amount of capacity of a CPU that is used by CFS + * tasks. The unit of the return value must be the one of 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 inline 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; +} + static inline void sched_rt_avg_update(struct rq *rq, u64 rt_delta) { rq->rt_avg += rt_delta * arch_scale_freq_capacity(NULL, cpu_of(rq));