From patchwork Fri Nov 21 12:35:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Morten Rasmussen X-Patchwork-Id: 41301 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f70.google.com (mail-la0-f70.google.com [209.85.215.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B6180244B0 for ; Fri, 21 Nov 2014 12:35:44 +0000 (UTC) Received: by mail-la0-f70.google.com with SMTP id q1sf2989374lam.9 for ; Fri, 21 Nov 2014 04:35:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:date:from:to:cc:subject:message-id :references:mime-version:content-type:content-disposition :in-reply-to:user-agent:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=NW86hQUbk4T5gGZoWzMnq/py4TXIXA30odQ7aA9kpwc=; b=EHZCzL9nKJ316hG1jzKt1zLjw9ubeDA14YiTXZDih4QbO6I09DsXqbVO5n7W00Btth Hgwy8hDaqtQFarh8aQd3j6XqqqBWFfoRtI/mJtSPnVq0OiUzxN+lkIhN9HSQafHzzOpY Twxz7S2LIHpozLScyDQ28DNIHLgckdWLTi6qxvJbvzsyBpBzfnVOsnu1jiAbORivRI2e gNGYrvCTnxd/9awBKSZ7OyGTWA4nNKYwiMXElpT6KJf3/zD4lO+hAlv1y9yCWdGzFbjQ NyRf/7XTJDyTemY0paAgMbRmcSXQq1nTk7MNl0EvTFN+HA5DmvHon9Hg9jhTIbUOhIWZ N89Q== X-Gm-Message-State: ALoCoQm65p56M+WSHBMjLTwaNOvbsus3v5kED62rUM22rtf9qkuL3Ku68RHLEpc72wAU6i/71ej2 X-Received: by 10.112.142.36 with SMTP id rt4mr1480194lbb.3.1416573343413; Fri, 21 Nov 2014 04:35:43 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.26.72 with SMTP id j8ls147908lag.105.gmail; Fri, 21 Nov 2014 04:35:43 -0800 (PST) X-Received: by 10.112.63.70 with SMTP id e6mr3143016lbs.93.1416573343206; Fri, 21 Nov 2014 04:35:43 -0800 (PST) Received: from mail-lb0-f182.google.com (mail-lb0-f182.google.com. [209.85.217.182]) by mx.google.com with ESMTPS id dc7si5140800lad.91.2014.11.21.04.35.43 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 21 Nov 2014 04:35:43 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.182 as permitted sender) client-ip=209.85.217.182; Received: by mail-lb0-f182.google.com with SMTP id f15so2626513lbj.41 for ; Fri, 21 Nov 2014 04:35:43 -0800 (PST) X-Received: by 10.153.7.170 with SMTP id dd10mr4259261lad.44.1416573343018; Fri, 21 Nov 2014 04:35:43 -0800 (PST) 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.184.201 with SMTP id ew9csp80311lbc; Fri, 21 Nov 2014 04:35:42 -0800 (PST) X-Received: by 10.66.227.103 with SMTP id rz7mr6452875pac.45.1416573341252; Fri, 21 Nov 2014 04:35:41 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cu3si8016849pbc.108.2014.11.21.04.35.29 for ; Fri, 21 Nov 2014 04:35:40 -0800 (PST) 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 S1758515AbaKUMfZ (ORCPT + 26 others); Fri, 21 Nov 2014 07:35:25 -0500 Received: from foss-mx-na.foss.arm.com ([217.140.108.86]:36593 "EHLO foss-mx-na.foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758488AbaKUMfW (ORCPT ); Fri, 21 Nov 2014 07:35:22 -0500 Received: from foss-smtp-na-1.foss.arm.com (unknown [10.80.61.8]) by foss-mx-na.foss.arm.com (Postfix) with ESMTP id D0E6F4E5; Fri, 21 Nov 2014 06:35:11 -0600 (CST) Received: from collaborate-mta1.arm.com (highbank-bc01-b06.austin.arm.com [10.112.81.134]) by foss-smtp-na-1.foss.arm.com (Postfix) with ESMTP id 94FB75FAD7; Fri, 21 Nov 2014 06:35:04 -0600 (CST) Received: from e105550-lin.cambridge.arm.com (e105550-lin.cambridge.arm.com [10.1.197.21]) by collaborate-mta1.arm.com (Postfix) with ESMTPS id A321713F8F5; Fri, 21 Nov 2014 06:35:02 -0600 (CST) Date: Fri, 21 Nov 2014 12:35:59 +0000 From: Morten Rasmussen To: Vincent Guittot Cc: "peterz@infradead.org" , "mingo@kernel.org" , "linux-kernel@vger.kernel.org" , "preeti@linux.vnet.ibm.com" , "kamalesh@linux.vnet.ibm.com" , "linux-arm-kernel@lists.infradead.org" , "riel@redhat.com" , "efault@gmx.de" , "nicolas.pitre@linaro.org" , "linaro-kernel@lists.linaro.org" Subject: Re: [PATCH v9 05/10] sched: make scale_rt invariant with frequency Message-ID: <20141121123559.GF23177@e105550-lin.cambridge.arm.com> References: <1415033687-23294-1-git-send-email-vincent.guittot@linaro.org> <1415033687-23294-6-git-send-email-vincent.guittot@linaro.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1415033687-23294-6-git-send-email-vincent.guittot@linaro.org> User-Agent: Mutt/1.5.21 (2010-09-15) 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.217.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: , On Mon, Nov 03, 2014 at 04:54:42PM +0000, Vincent Guittot wrote: > The average running time of RT tasks is used to estimate the remaining compute > capacity for CFS tasks. This remaining capacity is the original capacity scaled > down by a factor (aka scale_rt_capacity). This estimation of available capacity > must also be invariant with frequency scaling. > > A frequency scaling factor is applied on the running time of the RT tasks for > computing scale_rt_capacity. > > In sched_rt_avg_update, we scale the RT execution time like below: > rq->rt_avg += rt_delta * arch_scale_freq_capacity() >> SCHED_CAPACITY_SHIFT > > Then, scale_rt_capacity can be summarized by: > scale_rt_capacity = SCHED_CAPACITY_SCALE - > ((rq->rt_avg << SCHED_CAPACITY_SHIFT) / period) > > We can optimize by removing right and left shift in the computation of rq->rt_avg > and scale_rt_capacity > > The call to arch_scale_frequency_capacity in the rt scheduling path might be > a concern for RT folks because I'm not sure whether we can rely on > arch_scale_freq_capacity to be short and efficient ? It better be fast :) It is used in critical paths. However, if you really care about latency you probably don't want frequency scaling to mess around. If the architecture provides a fast-path for arch_scale_freq_capacity() returning SCHED_CAPACITY_SCALE when frequency scaling is disabled, the overhead should be minimal. If the architecture doesn't provide arch_scale_freq_capacity() it becomes a constant multiplication and should hopefully go away completely. > > Signed-off-by: Vincent Guittot > --- > kernel/sched/fair.c | 17 +++++------------ > kernel/sched/sched.h | 4 +++- > 2 files changed, 8 insertions(+), 13 deletions(-) > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index a5039da..b37c27b 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -5785,7 +5785,7 @@ unsigned long __weak arch_scale_cpu_capacity(struct sched_domain *sd, int cpu) > static unsigned long scale_rt_capacity(int cpu) > { > struct rq *rq = cpu_rq(cpu); > - u64 total, available, age_stamp, avg; > + u64 total, used, age_stamp, avg; > s64 delta; > > /* > @@ -5801,19 +5801,12 @@ static unsigned long scale_rt_capacity(int cpu) > > total = sched_avg_period() + delta; > > - if (unlikely(total < avg)) { > - /* Ensures that capacity won't end up being negative */ > - available = 0; > - } else { > - available = total - avg; > - } > + used = div_u64(avg, total); I haven't looked through all the details of the rt avg tracking, but if 'used' is in the range [0..SCHED_CAPACITY_SCALE], I believe it should work. Is it guaranteed that total > 0 so we don't get division by zero? It does get a slightly more complicated if we want to figure out the available capacity at the current frequency (current < max) later. Say, rt eats 25% of the compute capacity, but the current frequency is only 50%. In that case get: curr_avail_capacity = (arch_scale_cpu_capacity() * (arch_scale_freq_capacity() - (SCHED_SCALE_CAPACITY - scale_rt_capacity()))) >> SCHED_CAPACITY_SHIFT With numbers assuming arch_scale_cpu_capacity() = 800: curr_avail_capacity = 800 * (512 - (1024 - 758)) >> 10 = 200 Which isn't actually that bad. Anyway, it isn't needed until we start invovling energy models. > > - if (unlikely((s64)total < SCHED_CAPACITY_SCALE)) > - total = SCHED_CAPACITY_SCALE; > + if (likely(used < SCHED_CAPACITY_SCALE)) > + return SCHED_CAPACITY_SCALE - used; > > - total >>= SCHED_CAPACITY_SHIFT; > - > - return div_u64(available, total); > + return 1; > } > > static void update_cpu_capacity(struct sched_domain *sd, int cpu) > diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h > index c34bd11..fc5b152 100644 > --- a/kernel/sched/sched.h > +++ b/kernel/sched/sched.h > @@ -1312,9 +1312,11 @@ static inline int hrtick_enabled(struct rq *rq) > > #ifdef CONFIG_SMP > extern void sched_avg_update(struct rq *rq); > +extern unsigned long arch_scale_freq_capacity(struct sched_domain *sd, int cpu); I'm not sure if it makes any difference, but shouldn't it be __weak instead of extern? unsigned long __weak arch_scale_freq_capacity(...) Also, now that the function prototype definition is in the header file we can kill the local prototype in fair.c introduced in patch 4: * the * coefficients of a geometric series. To do this we sub-divide our * runnable --- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 6fd5ac6..921b174 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -2277,8 +2277,6 @@ static u32 __compute_runnable_contrib(u64 n) return contrib + runnable_avg_yN_sum[n]; } -unsigned long __weak arch_scale_freq_capacity(struct sched_domain *sd, int cpu); - /* * We can represent the historical contribution to runnable average as