Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp7524908ybi; Wed, 5 Jun 2019 19:54:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqw4iCMd/NF5S2CXYYy5b4nvAIBIMyoWmXpIGP7tZ+G2/DRJ5yzc19cNNJJURnh+srUyIMlJ X-Received: by 2002:a17:90a:b00b:: with SMTP id x11mr19783957pjq.120.1559789644960; Wed, 05 Jun 2019 19:54:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559789644; cv=none; d=google.com; s=arc-20160816; b=Elj1BH2MIejbq17x1Woo9g9Ug9g2ttJCvBfpT7RZpf272Z6DEWm3mE+SGAdxxwN1b6 zjM4GnaHY0K/UEePydP5njeH6zQUN+STyELZfthd8bmPPZXM+nu1NXPgl/49onVbJhHc YEAh3ScEllfMIYKmVtGCTt6mNWCdFS81FFHmw7TCCtfriRk+CW4JAUI6Hbz3wicLmh5a N9fBQ6srCsmFYsK8v+h2JUPPx7xwVl1YCtMTaikvy9Q/Nw9PwcFlI7S7eQ8dODqkHZZK ocWHkywgEbh5gxNyFP0ZgC4JuuHmlEHK765MIBky8AF4AasdQSW0cRFMbvj0zZiVvLyp yu2A== 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:dkim-signature; bh=MuJrLKq3f8R6SA2gbKnAdIV2BIlVwoZY7490xsEPP08=; b=i2QCTEFS+O1MZht+4dLxqzfSrJZ8Sab9JJYClcc0H3SP8cP3gSoNOqbkZq7jiYA/JH Fmtzre1DoRkkemUu3zh9yI9W4obufMMBCbzg4jP2k2CD0ax+zfJyYx/AMoWuncWV3t93 OB6nMUV/a2izvOVwONXbDaQgnRophU95BzKPVWi+hfGpH+wSPYprxlrNWUJgE81I379x lBrgeUZFTTuQVDaND8NFr8NDBW/HyNu2HDQmAslhMpoYZwtgYIbCjGp8ViwkAmqx+oqn /5+YBhHj372SM2qt8ZV+6ytiCB6Hbpn93LD2gISS5vwE3g8LprDiK7Ipt59PHrVEwRtT iBWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uYmVkKuh; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n18si528364pff.40.2019.06.05.19.53.48; Wed, 05 Jun 2019 19:54:04 -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; dkim=pass header.i=@linaro.org header.s=google header.b=uYmVkKuh; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726664AbfFFCwJ (ORCPT + 99 others); Wed, 5 Jun 2019 22:52:09 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:41490 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726427AbfFFCwJ (ORCPT ); Wed, 5 Jun 2019 22:52:09 -0400 Received: by mail-pf1-f194.google.com with SMTP id q17so530388pfq.8 for ; Wed, 05 Jun 2019 19:52:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=MuJrLKq3f8R6SA2gbKnAdIV2BIlVwoZY7490xsEPP08=; b=uYmVkKuhwcbANYnBr6B2uIgMzAVRUGKggE3YuQOteX9cRZ3/MYu2dsdKF3jnwQDUYm D+ukL0++ZQEVfZy4gM0IjEYrZrifZmJvcNMbU3tK3dEvzSXxMNpBtyZlO4nEAWkG5nuD qoK0F8AdpfAgM+wjubvszGA6KPry2IJ8qZ7+Nv9l96u4aaL9OLcRffpgFdtVxXp4GfFD 5zuSDNCrtcbsPIYnnfH1gFc5YfoPcxm67FU1rSWJJXJyEhcmiU54BIS8geWtNPC2keZH SeDFTERBIkaUif4psQfyAKfKrF+YhA8N8UK/lVc05iCGCpUkUVQ62nSLM3Qrdn9U/8Ig 6g+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=MuJrLKq3f8R6SA2gbKnAdIV2BIlVwoZY7490xsEPP08=; b=Dk3ReKSdVamOORHq3LSDwXFgTZmk7nRpfCQmJ4MIvK6UZj9HurZGpRnvihZyzOOCJz ZwtN5pZcAC0gav1+/yblWFqWXckNWQ/62ys/LmDxqU19IALNQflYiYAsf+ogQ3P83bTo 3R1JvSF3ZbiKfPrjeJblQOlSjygx6H6Ye7AqzI2ZvMSETOpM0fkjphkNjk+iexOfCkmJ P31aT2YPZDua7RTNJU+QqIrt3csXJVXfBh4l96ylKqd+Ci0xjd30ozUq+7ySBr05wbWn GrGUT7oHDlAj5i9kIdJXSzoo3mRZQsObcwUEOapGS3f7qFRaOrBh6hsgx8YakPcryxmM So1A== X-Gm-Message-State: APjAAAUy0oraCX2VZX9Cs70AlYm+z26zPiMmQDsMMMPu9J+59IOAzZGQ Hz/A1Ov9lWjVjf0lp8pTiDcL/Cf+ElM= X-Received: by 2002:a17:90a:ba81:: with SMTP id t1mr42998175pjr.139.1559789528005; Wed, 05 Jun 2019 19:52:08 -0700 (PDT) Received: from localhost ([122.172.66.84]) by smtp.gmail.com with ESMTPSA id j37sm245914pgj.58.2019.06.05.19.52.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Jun 2019 19:52:07 -0700 (PDT) Date: Thu, 6 Jun 2019 08:22:04 +0530 From: Viresh Kumar To: Quentin Perret Cc: Ingo Molnar , Peter Zijlstra , linux-kernel@vger.kernel.org, Vincent Guittot Subject: Re: [PATCH] sched/fair: Introduce fits_capacity() Message-ID: <20190606025204.qe5v7j6fysjkgxc6@vireshk-i7> References: <20190605091644.w3g7hc7r3eiscz4f@queper01-lin> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190605091644.w3g7hc7r3eiscz4f@queper01-lin> User-Agent: NeoMutt/20180716-391-311a52 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 05-06-19, 10:16, Quentin Perret wrote: > Hi Viresh, > > On Tuesday 04 Jun 2019 at 12:31:52 (+0530), Viresh Kumar wrote: > > The same formula to check utilization against capacity (after > > considering capacity_margin) is already used at 5 different locations. > > > > This patch creates a new macro, fits_capacity(), which can be used from > > all these locations without exposing the details of it and hence > > simplify code. > > > > All the 5 code locations are updated as well to use it.. > > > > Signed-off-by: Viresh Kumar > > --- > > kernel/sched/fair.c | 14 +++++++------- > > 1 file changed, 7 insertions(+), 7 deletions(-) > > > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > > index 7f8d477f90fe..db3a218b7928 100644 > > --- a/kernel/sched/fair.c > > +++ b/kernel/sched/fair.c > > @@ -102,6 +102,8 @@ int __weak arch_asym_cpu_priority(int cpu) > > * (default: ~20%) > > */ > > static unsigned int capacity_margin = 1280; > > + > > +#define fits_capacity(cap, max) ((cap) * capacity_margin < (max) * 1024) > > #endif > > > > #ifdef CONFIG_CFS_BANDWIDTH > > @@ -3727,7 +3729,7 @@ util_est_dequeue(struct cfs_rq *cfs_rq, struct task_struct *p, bool task_sleep) > > > > static inline int task_fits_capacity(struct task_struct *p, long capacity) > > { > > - return capacity * 1024 > task_util_est(p) * capacity_margin; > > + return fits_capacity(task_util_est(p), capacity); > > } > > > > static inline void update_misfit_status(struct task_struct *p, struct rq *rq) > > @@ -5143,7 +5145,7 @@ static inline unsigned long cpu_util(int cpu); > > > > static inline bool cpu_overutilized(int cpu) > > { > > - return (capacity_of(cpu) * 1024) < (cpu_util(cpu) * capacity_margin); > > + return !fits_capacity(cpu_util(cpu), capacity_of(cpu)); > > This ... > > > } > > > > static inline void update_overutilized_status(struct rq *rq) > > @@ -6304,7 +6306,7 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) > > /* Skip CPUs that will be overutilized. */ > > util = cpu_util_next(cpu, p, cpu); > > cpu_cap = capacity_of(cpu); > > - if (cpu_cap * 1024 < util * capacity_margin) > > + if (!fits_capacity(util, cpu_cap)) > > ... and this isn't _strictly_ equivalent to the existing code but I > guess we can live with the difference :-) Yes, I missed the == part it seems. Good catch. Though as you said, maybe we don't need to take that into account and can live with the new macro :) > > > continue; > > > > /* Always use prev_cpu as a candidate. */ > > @@ -7853,8 +7855,7 @@ group_is_overloaded(struct lb_env *env, struct sg_lb_stats *sgs) > > static inline bool > > group_smaller_min_cpu_capacity(struct sched_group *sg, struct sched_group *ref) > > { > > - return sg->sgc->min_capacity * capacity_margin < > > - ref->sgc->min_capacity * 1024; > > + return fits_capacity(sg->sgc->min_capacity, ref->sgc->min_capacity); > > } > > > > /* > > @@ -7864,8 +7865,7 @@ group_smaller_min_cpu_capacity(struct sched_group *sg, struct sched_group *ref) > > static inline bool > > group_smaller_max_cpu_capacity(struct sched_group *sg, struct sched_group *ref) > > { > > - return sg->sgc->max_capacity * capacity_margin < > > - ref->sgc->max_capacity * 1024; > > + return fits_capacity(sg->sgc->max_capacity, ref->sgc->max_capacity); > > } > > > > static inline enum > > -- > > 2.21.0.rc0.269.g1a574e7a288b > > > > Also, since we're talking about making the capacity_margin code more > consistent, one small thing I had in mind: we have a capacity margin > in sugov too, which happens to be 1.25 has well (see map_util_freq()). > Conceptually, capacity_margin in fair.c and the sugov margin are both > about answering: "do I have enough CPU capacity to serve X of util, or > do I need more ?" > > So perhaps we should factorize the capacity_margin code some more to use > it in both places in a consistent way ? This could be done in a separate > patch, though. Hmm, even if the values are same currently I am not sure if we want the same for ever. I will write a patch for it though, if Peter/Rafael feel the same as you. Thanks Quentin. -- viresh