Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp715400imm; Thu, 4 Oct 2018 02:02:50 -0700 (PDT) X-Google-Smtp-Source: ACcGV63EiC+P8VnLb2gnjDYoSImr0fJuTWmCCQiFR0TAosSypJhXqHuKIlJrN4zusvR7lQivdHbd X-Received: by 2002:a63:d917:: with SMTP id r23-v6mr4983035pgg.0.1538643770527; Thu, 04 Oct 2018 02:02:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538643770; cv=none; d=google.com; s=arc-20160816; b=exSmi1Mr4jJ9f3pjZ/uOxoc29NHhNbIz7hyBcJJhHfhdIAHDIw7gAvqfqNuxVqI8ee K6VCjsaLZhGDSBc0DmcDLu3s6ZKG26MToiwffwaco9M2K9HvinUkOMVQRFmwgoyxk+am DH+HKmoRWHy5yB1B8N1VAIS5zBEm+lTwAF4inDGHf2qpeNleXvEaXWIrokNK5GyDePrI Tl5oF3mCbEFQkLznFCou/Z5aI0Jt9UMaK352NFNMRa6HBrxIppINE931WOa3IWdDbykj HY+bw0Z0/aNSI/EUc67m2Qmisl6Pf1nd7uybzlqfuMkEMIeu914lMC7uj38tskhmzvjL 6poQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=6tHRPGxhtELo97CTOoBgwhrXWJM23o2EIBHTvfDP/hI=; b=e/1MVJB+Ko+g4ybm67DrzdRtQjxh/p4KDZzzuafNGR8WOeaVoXJd3g7FYUDafxK9vp uCCkLDRh/C88/NKT4Up/gEyCJiTCdTtFCkFpFPUpuo7DW98TmHW87sGZvhPjw6EItX9t DX4mXwcz325Nd5ogl1e4GSCkfpmQwEUFa5XdBP3x75tACT6972z4QS1cyJjWwzsWxh4r xprveYIiwHj9jCJSvHFj0iniKskRXzGI6ClUafQMc8rmQsXKvPT1bNFHxQIorv8EFN9j 20UZSx9+hvswoYCZJC6fXI9sqwCawx7qKkWkZz4UHxU+z8m0BiEp/h/GohoFTXaSUk4b MTzQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z11-v6si4147585pgs.323.2018.10.04.02.02.34; Thu, 04 Oct 2018 02:02:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727949AbeJDPym (ORCPT + 99 others); Thu, 4 Oct 2018 11:54:42 -0400 Received: from foss.arm.com ([217.140.101.70]:60890 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727190AbeJDPyl (ORCPT ); Thu, 4 Oct 2018 11:54:41 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 68A6B80D; Thu, 4 Oct 2018 02:02:24 -0700 (PDT) Received: from queper01-lin (queper01-lin.Emea.Arm.com [10.4.13.27]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 49B063F5A0; Thu, 4 Oct 2018 02:02:20 -0700 (PDT) Date: Thu, 4 Oct 2018 10:02:13 +0100 From: Quentin Perret To: Peter Zijlstra Cc: rjw@rjwysocki.net, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, gregkh@linuxfoundation.org, mingo@redhat.com, dietmar.eggemann@arm.com, morten.rasmussen@arm.com, chris.redpath@arm.com, patrick.bellasi@arm.com, valentin.schneider@arm.com, vincent.guittot@linaro.org, thara.gopinath@linaro.org, viresh.kumar@linaro.org, tkjos@google.com, joel@joelfernandes.org, smuckle@google.com, adharmap@codeaurora.org, skannan@codeaurora.org, pkondeti@codeaurora.org, juri.lelli@redhat.com, edubezval@gmail.com, srinivas.pandruvada@linux.intel.com, currojerez@riseup.net, javi.merino@kernel.org Subject: Re: [PATCH v7 11/14] sched/fair: Introduce an energy estimation helper function Message-ID: <20181004090211.ponos72a26ybemjh@queper01-lin> References: <20180912091309.7551-1-quentin.perret@arm.com> <20180912091309.7551-12-quentin.perret@arm.com> <20181004083457.GC19252@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181004083457.GC19252@hirez.programming.kicks-ass.net> User-Agent: NeoMutt/20171215 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Peter, On Thursday 04 Oct 2018 at 10:34:57 (+0200), Peter Zijlstra wrote: > On Wed, Sep 12, 2018 at 10:13:06AM +0100, Quentin Perret wrote: > > +static unsigned long cpu_util_next(int cpu, struct task_struct *p, int dst_cpu) > > +{ > > + struct cfs_rq *cfs_rq = &cpu_rq(cpu)->cfs; > > + unsigned long util_est, util = READ_ONCE(cfs_rq->avg.util_avg); > > + > > + /* > > + * If @p migrates from @cpu to another, remove its contribution. Or, > > + * if @p migrates from another CPU to @cpu, add its contribution. In > > + * the other cases, @cpu is not impacted by the migration, so the > > + * util_avg should already be correct. > > + */ > > + if (task_cpu(p) == cpu && dst_cpu != cpu) > > + util = max_t(long, util - task_util(p), 0); > > That's not quite right; what you want to check for is underflow, but the > above also results in 0 if util - task_util() > LONG_MAX without an > underflow. Hmm, I basically took that from capacity_spare_wake(). So I guess that function wants fixing too ... :/ Now, is it actually possible to hit that case (util - task_util() > LONG_MAX) given that util numbers are in the 1024 scale ? I guess that _could_ become a problem if we decided to increase the resolution one day. > You could write: sub_positive(&util, task_util(p)); Ah right, I forgot about that macro. It seems to have a slightly stronger semantics than what I need here though. I don't really care if the intermediate value hits the memory and task_util() already has a READ_ONCE. Not sure if that's a big deal. > > > + else if (task_cpu(p) != cpu && dst_cpu == cpu) > > + util += task_util(p); > > + > > + if (sched_feat(UTIL_EST)) { > > + util_est = READ_ONCE(cfs_rq->avg.util_est.enqueued); > > + > > + /* > > + * During wake-up, the task isn't enqueued yet and doesn't > > + * appear in the cfs_rq->avg.util_est.enqueued of any rq, > > + * so just add it (if needed) to "simulate" what will be > > + * cpu_util() after the task has been enqueued. > > + */ > > + if (dst_cpu == cpu) > > + util_est += _task_util_est(p); > > + > > + util = max(util, util_est); > > + } > > + > > + return min_t(unsigned long, util, capacity_orig_of(cpu)); > > AFAICT both @util and capacity_orig_of() have 'unsigned long' as type. Indeed, no need for min_t. > > +} > > + > > +/* > > + * compute_energy(): Estimates the energy that would be consumed if @p was > > + * migrated to @dst_cpu. compute_energy() predicts what will be the utilization > > + * landscape of the * CPUs after the task migration, and uses the Energy Model > > + * to compute what would be the energy if we decided to actually migrate that > > + * task. > > + */ > > +static long compute_energy(struct task_struct *p, int dst_cpu, > > + struct perf_domain *pd) > > static long > compute_energy(struct task_struct *p, int dst_cpu, struct perf_domain *pd) OK. > > +{ > > + long util, max_util, sum_util, energy = 0; > > + int cpu; > > + > > + while (pd) { > > + max_util = sum_util = 0; > > + /* > > + * The capacity state of CPUs of the current rd can be driven by > > + * CPUs of another rd if they belong to the same performance > > + * domain. So, account for the utilization of these CPUs too > > + * by masking pd with cpu_online_mask instead of the rd span. > > + * > > + * If an entire performance domain is outside of the current rd, > > + * it will not appear in its pd list and will not be accounted > > + * by compute_energy(). > > + */ > > + for_each_cpu_and(cpu, perf_domain_span(pd), cpu_online_mask) { > > + util = cpu_util_next(cpu, p, dst_cpu); > > + util = schedutil_freq_util(cpu, util, ENERGY_UTIL); > > + max_util = max(util, max_util); > > + sum_util += util; > > + } > > + > > + energy += em_pd_energy(pd->obj, max_util, sum_util); > > + pd = pd->next; > > + } > > No real strong preference, but you could write that like: > > for (; pd; pd = pd->next) { > } And OK for that one too. That saves one line. The next patch has the same pattern, I'll change it too. Thanks, Quentin