Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp750600pxf; Thu, 1 Apr 2021 12:33:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyUrI/ng2ba9E6OLgy8STE2LtmN8wexOPQMxSZcZNLaVRl1H9x0ZndHrkKTTTfNJFIzWLml X-Received: by 2002:a05:6402:382:: with SMTP id o2mr11979126edv.238.1617305632187; Thu, 01 Apr 2021 12:33:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617305632; cv=none; d=google.com; s=arc-20160816; b=DzL9dJT8zYQb1hf9PfxvXo+EYdumiB3QAL5mG+ayP/RPWL2JKs+UBqDe/g7ajhLHPK LghJbLLalEd8jZC4GVXPH2/FY6UaK9eoGvmuYxNyj9vrVHj6G+XthiyjX9z7jJ4oJEnh InO3gXJ97GT/1qVBJ0LEmqyhKXStY0tv8eFqXyW111P5aYvw5V20E7munY9DqjZllJ0m V4Kk8Kjy+muVEZoWE8yByf5iqWpomKf0gRUOi1HAPH9Uq6xUT1OjMouvrUE7Hsr4gfL0 YAkN0HdrnhL/VEBWU0pWs69iYAjIAnsLZakIdL0Ua43J0M8KTyb9yO3fjyfBEzD8nmIC RraQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=OGG1XOg+KNkHNWZXew8shmmw18OO7n69SlqTyhmqX6o=; b=yzQE10sH4w2oSh1yPrY0cPZqy+lb0vHLk7HiXEAlyGBDpfwKsbadlA2r9jKUOpVISe 7aKcUKW5JToUeW8y9lBf6MEmqX4IFDGPBVcfc9ILIh1ZnBfdJyYIeUg7O5RDTYnX8gJd 9ald4MeEQsTsZvwemK52AG6DWPLMEEiyAfsP8OPYxYvMyccHosPyDGdkNwNmMSA6m6oh my7DXeC6c7HDdt1JVIGSg5xeF8M5UwwN3WYGGpYvuiuSc/SIzOLnsYsHA3xfOKTGGsCW AbKS1ZZR+/QAaaGS5n+dz4UWmCxkbumKIaW10h+ciOBxyQA60Pv6xO5cplnMoGn2lNRS FvCQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lt10si4628663ejb.16.2021.04.01.12.33.29; Thu, 01 Apr 2021 12:33:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235232AbhDATam (ORCPT + 99 others); Thu, 1 Apr 2021 15:30:42 -0400 Received: from foss.arm.com ([217.140.110.172]:48214 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234613AbhDATaa (ORCPT ); Thu, 1 Apr 2021 15:30:30 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 12C8411FB; Thu, 1 Apr 2021 12:30:30 -0700 (PDT) Received: from e113632-lin.cambridge.arm.com (e113632-lin.cambridge.arm.com [10.1.194.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 819153F719; Thu, 1 Apr 2021 12:30:28 -0700 (PDT) From: Valentin Schneider To: linux-kernel@vger.kernel.org Cc: Qais Yousef , Lingutla Chandrasekhar , Peter Zijlstra , Ingo Molnar , Vincent Guittot , Dietmar Eggemann , Morten Rasmussen , Quentin Perret , Pavan Kondeti , Rik van Riel Subject: [PATCH v4 3/3] sched/fair: Introduce a CPU capacity comparison helper Date: Thu, 1 Apr 2021 20:30:06 +0100 Message-Id: <20210401193006.3392788-4-valentin.schneider@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210401193006.3392788-1-valentin.schneider@arm.com> References: <20210401193006.3392788-1-valentin.schneider@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org During load-balance, groups classified as group_misfit_task are filtered out if they do not pass group_smaller_max_cpu_capacity(, ); which itself employs fits_capacity() to compare the sgc->max_capacity of both groups. Due to the underlying margin, fits_capacity(X, 1024) will return false for any X > 819. Tough luck, the capacity_orig's on e.g. the Pixel 4 are {261, 871, 1024}. If a CPU-bound task ends up on one of those "medium" CPUs, misfit migration will never intentionally upmigrate it to a CPU of higher capacity due to the aforementioned margin. One may argue the 20% margin of fits_capacity() is excessive in the advent of counter-enhanced load tracking (APERF/MPERF, AMUs), but one point here is that fits_capacity() is meant to compare a utilization value to a capacity value, whereas here it is being used to compare two capacity values. As CPU capacity and task utilization have different dynamics, a sensible approach here would be to add a new helper dedicated to comparing CPU capacities. While at it, replace group_smaller_{min, max}_cpu_capacity() with comparisons of the source group's min/max capacity and the destination CPU's capacity. Reviewed-by: Qais Yousef Tested-by: Lingutla Chandrasekhar Signed-off-by: Valentin Schneider --- kernel/sched/fair.c | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index d8077f82a380..c9c5c2697998 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -113,6 +113,13 @@ int __weak arch_asym_cpu_priority(int cpu) */ #define fits_capacity(cap, max) ((cap) * 1280 < (max) * 1024) +/* + * The margin used when comparing CPU capacities. + * is 'cap1' noticeably greater than 'cap2' + * + * (default: ~5%) + */ +#define capacity_greater(cap1, cap2) ((cap1) * 1024 > (cap2) * 1078) #endif #ifdef CONFIG_CFS_BANDWIDTH @@ -8364,26 +8371,6 @@ group_is_overloaded(unsigned int imbalance_pct, struct sg_lb_stats *sgs) return false; } -/* - * group_smaller_min_cpu_capacity: Returns true if sched_group sg has smaller - * per-CPU capacity than sched_group ref. - */ -static inline bool -group_smaller_min_cpu_capacity(struct sched_group *sg, struct sched_group *ref) -{ - return fits_capacity(sg->sgc->min_capacity, ref->sgc->min_capacity); -} - -/* - * group_smaller_max_cpu_capacity: Returns true if sched_group sg has smaller - * per-CPU capacity_orig than sched_group ref. - */ -static inline bool -group_smaller_max_cpu_capacity(struct sched_group *sg, struct sched_group *ref) -{ - return fits_capacity(sg->sgc->max_capacity, ref->sgc->max_capacity); -} - static inline enum group_type group_classify(unsigned int imbalance_pct, struct sched_group *group, @@ -8539,7 +8526,7 @@ static bool update_sd_pick_busiest(struct lb_env *env, * internally or be covered by avg_load imbalance (eventually). */ if (sgs->group_type == group_misfit_task && - (!group_smaller_max_cpu_capacity(sg, sds->local) || + (!capacity_greater(capacity_of(env->dst_cpu), sg->sgc->max_capacity) || sds->local_stat.group_type != group_has_spare)) return false; @@ -8623,7 +8610,7 @@ static bool update_sd_pick_busiest(struct lb_env *env, */ if ((env->sd->flags & SD_ASYM_CPUCAPACITY) && (sgs->group_type <= group_fully_busy) && - (group_smaller_min_cpu_capacity(sds->local, sg))) + (capacity_greater(sg->sgc->min_capacity, capacity_of(env->dst_cpu)))) return false; return true; @@ -9423,7 +9410,7 @@ static struct rq *find_busiest_queue(struct lb_env *env, * average load. */ if (env->sd->flags & SD_ASYM_CPUCAPACITY && - capacity_of(env->dst_cpu) < capacity && + !capacity_greater(capacity_of(env->dst_cpu), capacity) && nr_running == 1) continue; -- 2.25.1