From patchwork Tue Jun 4 07:01:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 165702 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp5456531ili; Tue, 4 Jun 2019 00:02:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqwb1xXBxKtoOT7WuydM4dEMJFbTr+dUMHvUV87dBfT03QHG17OcL8S8zIl0X5HUDvDhSpCu X-Received: by 2002:a63:f551:: with SMTP id e17mr33879759pgk.329.1559631720991; Tue, 04 Jun 2019 00:02:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559631720; cv=none; d=google.com; s=arc-20160816; b=KrP+M89HIsabFY9ucF0fi5aR8LabeJ2wvlqfv4ug+9Gno2hlo8JqPgVzDCxDFyBQBJ wYNQjjQMHMR492Lxue8SGPCM1t6nlU5Imb+ZOpUBwB1bOqn6aoXFlmCdjSQU9FUSq1Oj YCNbJr5wuDkDOwHd4ZS2C6aHAjw/6Tr9i+9j2le4VdCLCUXc7enGfgcK2LPNDv/jDWrS SQwX8Qp4D4QJq64jDGRnZKwG8oy8mTOzYRzvdTM62mBHbFa+1nI+Uu8grYTQwQgpImEu CLWkfge0Kw5w857mmeu2VI8XbUTKNSlEtzIn1XrzlsKi1ayBYdDxgelW9eYE8X26i3bm Dtqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=LitjvBr4bQliAtyzrQ3myX1ZLOUmkF/pxyOjBUuK5wI=; b=uLxGiKZKf5E63qOsblEmINWmVPWSzPj+MTwLK43WuamZpdHff2qsjwfuuwbVWRYY7z 5584C4ol6vL3M/LxIndt8K91zs3eF60I8MpeSddibkA3VD1ljlenwEaOQjio7qYZHBnk LICMarnrZ0FAqvOhNOYiLP3rh2YZDwIVWWIU5yco+CQP2xyTcTvo2nqSS6pNkVBKSaak 4LSTYG+Xrm/JSEexFJSHgYYXY455EexsZ+OQZMPBItd6B1I1RZeXRNBFkeWChtqh8Jms dYq2nLvegreTRVT5ehCIezbJbfZi0YO68W2L4A685eCljen1sxItkGwdlsYXvIX++Te6 L6mw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cgSw4BkY; 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 r16si11175048pgj.530.2019.06.04.00.02.00; Tue, 04 Jun 2019 00:02:00 -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=cgSw4BkY; 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 S1726729AbfFDHB7 (ORCPT + 30 others); Tue, 4 Jun 2019 03:01:59 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:39886 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726547AbfFDHB7 (ORCPT ); Tue, 4 Jun 2019 03:01:59 -0400 Received: by mail-pf1-f194.google.com with SMTP id j2so12099031pfe.6 for ; Tue, 04 Jun 2019 00:01:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=LitjvBr4bQliAtyzrQ3myX1ZLOUmkF/pxyOjBUuK5wI=; b=cgSw4BkYceLudx3qOurpScu2yKys2klZc/YFTk0GmoCddDhw6tOPdNwdDuzpizVmow ulPVFKjwur1S6ghfyYcF6EkKFXwFfbPHFxOJG0TP6S4dLIyOrvPES1hZpgqWIaWQUlUE J8Tl9kUXODEpMtYgiWyG5ntFqhUwDBXqA7SssqczE082P2RojzxjLZb7ARTBKg+jKnwm l6gI4ymR8SisEqbrU8eEW2F2m5KuJ7SvT0FJdmW3YeFeeS7vG4B94tggLkp5XKccloga De68CUivRr3EalYUSnHSXFxJNEzA5CH8hT8TWqgFi1NOCy2OcuRvS/wWiAjJ0PlB+l0J q2UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=LitjvBr4bQliAtyzrQ3myX1ZLOUmkF/pxyOjBUuK5wI=; b=tficY7qNQsfAE1Isy9zLil85AczMsRo5nbeKig+yHHyMqukW7QBZKVYznclq2yr8El hgmY+oPu410guZBJTqI29qRciThQgJ2547Y00oJ1n3OqBgMQXpWAAe6Sc3mK6hhTzLw3 S794oVHWjnWnvHW0kjCSZUI5QbN3wbIMUgz7c0B3Pe032cCBJer6rrgb3lZB7v9B9CMv iYhulZ0FxH0HVGRwHbHw2XVw7rAz1eHCM9lDVsvjUQqXjejfBe6tJr/0Be0A8D+G84m8 VZNIZWNCZ8yx6+G5h3JFBfaXxhdd/PXLge+kzDhqDjtCTqhCdIyl8lcTlsEcB9TMXyfE WHqg== X-Gm-Message-State: APjAAAXJLfsErfICXR6cVkdSf+a7FPIOpkhZk3m9cAkAAeLCTcfuhPyb 2BFqG61FuhT0B0LxJCRjXgtlzA== X-Received: by 2002:a63:144e:: with SMTP id 14mr33175907pgu.304.1559631718309; Tue, 04 Jun 2019 00:01:58 -0700 (PDT) Received: from localhost ([122.172.66.84]) by smtp.gmail.com with ESMTPSA id h12sm8007109pfr.38.2019.06.04.00.01.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Jun 2019 00:01:57 -0700 (PDT) From: Viresh Kumar To: Ingo Molnar , Peter Zijlstra Cc: Viresh Kumar , linux-kernel@vger.kernel.org, Vincent Guittot Subject: [PATCH] sched/fair: Introduce fits_capacity() Date: Tue, 4 Jun 2019 12:31:52 +0530 Message-Id: X-Mailer: git-send-email 2.21.0.rc0.269.g1a574e7a288b MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(-) -- 2.21.0.rc0.269.g1a574e7a288b 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)); } 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