Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp589284rwb; Thu, 6 Oct 2022 01:24:21 -0700 (PDT) X-Google-Smtp-Source: AMsMyM43b2t7JBi/i12/pNwdWoc/mV61UkVhoTQd/5YV82ycB9CUsJl5CLQegpUY4CdK5PK/Pt/K X-Received: by 2002:a63:5a08:0:b0:43c:9fcc:cc54 with SMTP id o8-20020a635a08000000b0043c9fcccc54mr3423795pgb.229.1665044661691; Thu, 06 Oct 2022 01:24:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665044661; cv=none; d=google.com; s=arc-20160816; b=ZD1jv3nIlkqa4ETdKo2u1J4q+ZN+eBQl8MFJF9nLX2pzLpviQLURQzlkTfZ/vobeEr p7JVBqNmsqxkkS/d3WZauMUNMg7UQOYEF1bJOEYNfqw+iWg2ON95KFAm+svBcTzRCbgx LGt+BajLCDeiFnRU1VHwDezWiOGCUxZrTLes8D+3T5z8jjWgPV44BT+bjjoBYl3Yx4pv isyptghtcqIFw+syJtvYsi/9QNm4evkD37H5JD1gjGIzTr6TYLKyy2aZ7NZPH++p8yJ4 HurtplBnWnrev8pLbOQLV/M0TYbKs1luF/5xnsgIv92dZEn7grjYquNJetFY7fP30u4o D3sw== 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=zClWfRolwAofduR0U034gRwQaWBMlMZL0sFmMaVXM40=; b=S71wcSwd3Hxp7i/7BtC24ZL7CVoahHaAMfYw9o7OUDT4KrOJQubx7c76r5M3eq1H2d Aqj7dquDy7q9omQG8zfDBn48MFKXhSssRNIg+GwvR9Lh2JUrbdgA67wBNZsZPlNDv7KY bqx1hLGEjvq8wT9gZrQCBS9omvlreGJl6NAzzAMPmIOMlLnEErXXmFQgcypEY3xcJoZr f5EtYpyOvkccgVrx43MAJxrbBDpRSUrxLEOiD200kbwfWReEsOzqrTo2NhBNHVkRDzHZ pH7dS0durMMG9JEHKthsxfD/AggJT8vJDOXTno+1y6b2vIcv0oPqLL0jGx6AJssHJIlU AOLA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i1-20020a632201000000b004344ef377a6si15369978pgi.660.2022.10.06.01.24.09; Thu, 06 Oct 2022 01:24:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S230283AbiJFILH (ORCPT + 99 others); Thu, 6 Oct 2022 04:11:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229731AbiJFILD (ORCPT ); Thu, 6 Oct 2022 04:11:03 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4A2273BC4A for ; Thu, 6 Oct 2022 01:11:02 -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 3F4E71BF7; Thu, 6 Oct 2022 01:11:08 -0700 (PDT) Received: from pierre123.arm.com (unknown [10.57.35.228]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 587A33F792; Thu, 6 Oct 2022 01:10:59 -0700 (PDT) From: Pierre Gondois To: linux-kernel@vger.kernel.org Cc: Pierre Gondois , Dietmar Eggemann , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider Subject: [PATCH v2 1/1] sched/fair: Check if prev_cpu has highest spare cap in feec() Date: Thu, 6 Oct 2022 10:10:52 +0200 Message-Id: <20221006081052.3862167-2-pierre.gondois@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221006081052.3862167-1-pierre.gondois@arm.com> References: <20221006081052.3862167-1-pierre.gondois@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When evaluating the CPU candidates in the perf domain (pd) containing the previously used CPU (prev_cpu), find_energy_efficient_cpu() evaluates the energy of the pd: - without the task (base_energy) - with the task placed on prev_cpu (if the task fits) - with the task placed on the CPU with the highest spare capacity, prev_cpu being excluded from this set If prev_cpu is already the CPU with the highest spare capacity, max_spare_cap_cpu will be the CPU with the second highest spare capacity. On an Arm64 Juno-r2, with a workload of 10 tasks at a 10% duty cycle, when prev_cpu and max_spare_cap_cpu are both valid candidates, prev_spare_cap > max_spare_cap at ~82%. Thus the energy of the pd when placing the task on max_spare_cap_cpu is computed with no possible positive outcome 82% most of the time. Do not consider max_spare_cap_cpu as a valid candidate if prev_spare_cap > max_spare_cap. Reviewed-by: Dietmar Eggemann Signed-off-by: Pierre Gondois --- kernel/sched/fair.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 914096c5b1ae..bcae7bdd5582 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -6900,7 +6900,7 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) for (; pd; pd = pd->next) { unsigned long cpu_cap, cpu_thermal_cap, util; unsigned long cur_delta, max_spare_cap = 0; - bool compute_prev_delta = false; + unsigned long prev_spare_cap = 0; int max_spare_cap_cpu = -1; unsigned long base_energy; @@ -6944,18 +6944,19 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) if (cpu == prev_cpu) { /* Always use prev_cpu as a candidate. */ - compute_prev_delta = true; + prev_spare_cap = cpu_cap; } else if (cpu_cap > max_spare_cap) { /* * Find the CPU with the maximum spare capacity - * in the performance domain. + * among the remaining CPUs in the performance + * domain. */ max_spare_cap = cpu_cap; max_spare_cap_cpu = cpu; } } - if (max_spare_cap_cpu < 0 && !compute_prev_delta) + if (max_spare_cap_cpu < 0 && prev_spare_cap == 0) continue; eenv_pd_busy_time(&eenv, cpus, p); @@ -6963,7 +6964,7 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) base_energy = compute_energy(&eenv, pd, cpus, p, -1); /* Evaluate the energy impact of using prev_cpu. */ - if (compute_prev_delta) { + if (prev_spare_cap > 0) { prev_delta = compute_energy(&eenv, pd, cpus, p, prev_cpu); /* CPU utilization has changed */ @@ -6974,7 +6975,7 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) } /* Evaluate the energy impact of using max_spare_cap_cpu. */ - if (max_spare_cap_cpu >= 0) { + if (max_spare_cap_cpu >= 0 && max_spare_cap > prev_spare_cap) { cur_delta = compute_energy(&eenv, pd, cpus, p, max_spare_cap_cpu); /* CPU utilization has changed */ -- 2.25.1