From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D3B7EC4167D for ; Thu, 2 Nov 2023 17:37:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232166AbjKBRhs (ORCPT ); Thu, 2 Nov 2023 13:37:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232902AbjKBRho (ORCPT ); Thu, 2 Nov 2023 13:37:44 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3B01D184 for ; Thu, 2 Nov 2023 10:37:37 -0700 (PDT) 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 389A72F4; Thu, 2 Nov 2023 10:38:19 -0700 (PDT) Received: from [192.168.178.6] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 1B2D23F738; Thu, 2 Nov 2023 10:37:34 -0700 (PDT) Message-ID: Date: Thu, 2 Nov 2023 18:37:33 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH 4/6] sched/fair: Rewrite util_fits_cpu() Content-Language: en-US To: Hongyan Xia , Ingo Molnar , Peter Zijlstra , Vincent Guittot , Juri Lelli Cc: Qais Yousef , Morten Rasmussen , Lukasz Luba , Christian Loehle , linux-kernel@vger.kernel.org References: From: Dietmar Eggemann In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04/10/2023 11:04, Hongyan Xia wrote: > From: Hongyan Xia > > Currently, there's no way to distinguish the difference between 1) a CPU > that is actually maxed out at its highest frequency, or 2) one that is > throttled because of UCLAMP_MAX, since both present util_avg values of > 1024. This is problematic because when we try to pick a CPU for a task > to run, we would like to give 2) a chance, or at least prefer 2) to 1). > > Current upstream gives neither a chance because the spare capacity is 0 > for either case. There are patches to fix this problem by considering 0 > capacities [1], but this might still be inefficient because this ends > up treating 1) and 2) equally, and will always pick the same one because > we don't change how we iterate through all CPUs. If we end up putting > many tasks on 1), then this creates a seriously unbalanced load for the > two CPUs. > > Fix by using util_avg_uclamp for util_fits_cpu(). This way, case 1) will > still keep its utilization at 1024 whereas 2) shows spare capacities if > the sum of util_avg_uclamp values is still under the CPU capacity. > Note that this is roughly what the sum aggregation does in the Android > kernel [2] (although we clamp UCLAMP_MIN as well in this patch, which > may need some discussions), which shows superior energy savings because > there's more chance that a task can get scheduled on 2) instead of > finding a big CPU to run on. > > Under sum aggregation, checking whether a task fits a CPU becomes much > simpler. We simply do fits_capacity() and there does not need to be code > checking all corner cases for uclamp. This means util_fits_cpu() returns > to true and false instead of tri-state, simplifying a significant amount > of code. You could remove util_fits_cpu() and task_fits_cpu() and call fits_capacity() directly. We should try to keep the zoo of util-related functions as small as possible. [...]