Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5598153ybi; Tue, 4 Jun 2019 09:01:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqzkyP0vbu2MtsgJSpbt745lACm0esoWE6YejtziOpm3gU8Nye1ub8hAXtLSdsbFQ8sHAlex X-Received: by 2002:a17:90a:8a91:: with SMTP id x17mr10519925pjn.95.1559664107659; Tue, 04 Jun 2019 09:01:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559664107; cv=none; d=google.com; s=arc-20160816; b=oO0c/XxnS8/zJOc/xQ33fMSC8t4TH1eNlPBoOhzkHrqLUcokoRKfRX6XFuAz2uoQx3 3W8l0tsOzmDQ+jY13nkNZQ1dg6uEQ9dT83HJnCV67FyVY8HyDhZnYqhi/MWAVitdelim 85+gdbx6a2CrwezWE0wdM2namHh8ST9SuGrjyHEXcT1E07Z3rag+EKBdX3RahUlieB1H F5+zcGbzicogb34FCl7o6DTNmcSmvEUPuxiN9RBelFeCPocSd9BbjXmOJW6oY/JtPaiu PUcT8dWdrymdfZuSLp4NWI8cKFFmb1V3dR1py8gbpx4XIwadwXwfBumdw03Hx8Q1p9K+ R8vQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=pNSmlxy+hHS9DdorXvCYVqoqTtmJb7A32aLQZ8rGLog=; b=X2oLtki97ZylWeGneF1igy/TElqq6jALGOkhhdz+Te72qPVvMo02bpidzm2XH4inMg eecs4nw5HDvwvBmN5AB1LHfA8wF1tb44a/TcybWOVhWbh5BDQA5LsCu7iPJOEvkeJDNn zjWwovgUtOPHYh1Z5ceOk0EL2U7Qomjo6m9U4IzQu+ZrTv9dv7qd8lg5EVGbABknaJQE uJS3gKq5nznYnPFRXDbzpKTX89KL5IJZKAFtvDyh8zNLSctbFX0dQCkZ/ALXWvXnPzHV RIEbIodE6fkEzajb9yeL4A3ldBwcSp3ajTu5IVtmf6lEx8a7n7e1zO/LJ4P/b8k7dAmZ g5cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@posk.io header.s=google header.b=RfsnL1Cb; 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 y7si2078277pfm.262.2019.06.04.09.01.30; Tue, 04 Jun 2019 09:01:47 -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=@posk.io header.s=google header.b=RfsnL1Cb; 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 S1728205AbfFDP7l (ORCPT + 99 others); Tue, 4 Jun 2019 11:59:41 -0400 Received: from mail-vs1-f66.google.com ([209.85.217.66]:39169 "EHLO mail-vs1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727422AbfFDP7k (ORCPT ); Tue, 4 Jun 2019 11:59:40 -0400 Received: by mail-vs1-f66.google.com with SMTP id n2so5432779vso.6 for ; Tue, 04 Jun 2019 08:59:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=posk.io; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=pNSmlxy+hHS9DdorXvCYVqoqTtmJb7A32aLQZ8rGLog=; b=RfsnL1Cbm3++1fTT2oGbQiSR45EERV453FCrAn8rOCd28WFS7LG/EAeJ2yCFN2XybD XI8/icvh2H2QI6+HRCPUlTjo4pZVdlgKgMQGLdWd/jG/oLKHWp2/lZGEBzUGqtLQRxh3 FG0t4K2f7GbVj8ORugI7RNhutqiBPT3PXLsLWQwdWj7jSwutVlADqPYeWTb39h6z689z 5XoNsGqZZAlEMLOLskrBAOx+0Zj06NIaRHTlXl+WEmjPcnO/K3p+oa7Me394MngtPSjm QWTSLWFF7YZmdOGLaJzrQf6c6T/n//nr51idY2+OMa4CUH5fYUxP7EPaptsRdVt6c1j1 5hMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=pNSmlxy+hHS9DdorXvCYVqoqTtmJb7A32aLQZ8rGLog=; b=lCEVnSVq5frlRMx55l+ubU7f/j1VKCVViGU8ho/VwX6IUbogcWjOxkiFjOlfv0MZ9i 2l5SM2z/t3e1xMcjWNYUtUXqPYSkYmaUBsvYR6UIcDwdDgzQCIaZhot+Uv7PtR5uUjNJ YgdVQuMcer5F7z5HOj0tIgIHgRrfSxm8hpNIhv1hFvhT8S96/6AmrF5vPf6mWPjstCgU SlqZBzP2bXHsOt5JRaj0x1o0WpK6b6q/0sGXvDO1LRhHtf8C7CgEgSBZA/+0m4wZRPHE UxjOx3G+m1Ih6t/izkGky0EQsQYC5pA7RChF+3mxK6Pss2k3TUAg6WJXGL7k/OYg04oM FXSQ== X-Gm-Message-State: APjAAAVtru1ri+LfYV1KO2ihQIFKT65csj868BTlc9SuWjcJ3oZooAZY jKirJq82qiF5BYkn6jTFuYTEdXfeXP3XyuMr6gooxQ== X-Received: by 2002:a67:ea58:: with SMTP id r24mr16770160vso.60.1559663979613; Tue, 04 Jun 2019 08:59:39 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Peter Oskolkov Date: Tue, 4 Jun 2019 08:59:28 -0700 Message-ID: Subject: Re: [PATCH] sched/fair: Introduce fits_capacity() To: Viresh Kumar Cc: Ingo Molnar , Peter Zijlstra , Linux Kernel Mailing List , Vincent Guittot Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jun 4, 2019 at 12:02 AM 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) Any reason to have this as a macro and not as an inline function? > #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)); > } > > 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)) > 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 >