Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp815711pxb; Tue, 12 Apr 2022 14:13:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxpAN2pAYKoV0M6tSFcMajNTFj0lAnRtOMA4+0K+oDpd+QPwFvkpHTWPK3yIZILNiHT6L4X X-Received: by 2002:a17:90b:17cb:b0:1ca:7772:1abe with SMTP id me11-20020a17090b17cb00b001ca77721abemr7129356pjb.162.1649798025294; Tue, 12 Apr 2022 14:13:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649798025; cv=none; d=google.com; s=arc-20160816; b=BDX1cguamZUFKa3PsB2cz2ViI5twhiF75F4JSF4pZCkRIKHhal4dp1pHDWZKF+j7yj JLeDZbVyTAusmjrYds6mJ805gcmCXzItK8xlRZfL4BKOJ7Pk0yZuRtw903lsS6fxNGBH dOmswy3uFy7WFM7nHZc9xN287kEhLz74kml3ytWmy3pSjGD7NZUX8rxh80aehetMLLJ9 KklEatc8Sp/MOw5i2fjoNxIlXFqz27sRZiCfWNygsF5g+Rwi1Q+Y8zA1GdCOKATY/udO cZhFaRdtRf7R0xMeYQtcls3iioYpZ6QFeWJKN+s+7MIpAWybbtDZgGD8lP08Mc+j2zFI qSIA== 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=c5m9Qh/hGfG+BFtTk55pGfN+DKgDhJFVDQfrtRKtjP0=; b=DVXnWCjz1+8525yF07Yl/8vMUXjXhyKaolDmLggXQmN/sfud/onW4+r2ZOQ/60sHZ9 WapatXNaf3UEJnGJqhIGgumzJMkQ/V0tNgJaaK8JtiwyszccijQOJv8wI6nOv5o203XI rYiTNHl5f0/UCK+R0yRt458Pa7kh6EQH8zorrlPRxler1ZbvxC9WFolFuaXiBCMm57qv pxVbIlT3uT6qT9zHje9QHCcjrImVlKs4r29jT8xtzJykdFVH2DnYOFUWRZdDu9sn/trw G+i106stVuqMy6ZCe2oGNpN0DNPVxbd1qwWIyBqG9TZ2ZVpGJocx6dwgZOp+K4LSEEPo HO4A== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id s12-20020a17090302cc00b0015841f23ab2si10027459plk.188.2022.04.12.14.13.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 14:13:45 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D7B2EECB36; Tue, 12 Apr 2022 13:29:26 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233715AbiDLNp3 (ORCPT + 99 others); Tue, 12 Apr 2022 09:45:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356132AbiDLNo4 (ORCPT ); Tue, 12 Apr 2022 09:44:56 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7044C4ECF1 for ; Tue, 12 Apr 2022 06:42:39 -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 298BC169C; Tue, 12 Apr 2022 06:42:39 -0700 (PDT) Received: from localhost.localdomain (unknown [10.57.94.90]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E3E553F70D; Tue, 12 Apr 2022 06:42:37 -0700 (PDT) From: Vincent Donnefort To: peterz@infradead.org, mingo@redhat.com, vincent.guittot@linaro.org Cc: linux-kernel@vger.kernel.org, dietmar.eggemann@arm.com, morten.rasmussen@arm.com, chris.redpath@arm.com, qperret@google.com Subject: [PATCH v4 5/7] sched/fair: Use the same cpumask per-PD throughout find_energy_efficient_cpu() Date: Tue, 12 Apr 2022 14:42:18 +0100 Message-Id: <20220412134220.1588482-6-vincent.donnefort@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220412134220.1588482-1-vincent.donnefort@arm.com> References: <20220412134220.1588482-1-vincent.donnefort@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 From: Dietmar Eggemann The Perf Domain (PD) cpumask (struct em_perf_domain.cpus) stays invariant after Energy Model creation, i.e. it is not updated after CPU hotplug operations. That's why the PD mask is used in conjunction with the cpu_online_mask (or Sched Domain cpumask). Thereby the cpu_online_mask is fetched multiple times (in compute_energy()) during a run-queue selection for a task. cpu_online_mask may change during this time which can lead to wrong energy calculations. To be able to avoid this, use the select_rq_mask per-cpu cpumask to create a cpumask out of PD cpumask and cpu_online_mask and pass it through the function calls of the EAS run-queue selection path. The PD cpumask for max_spare_cap_cpu/compute_prev_delta selection (find_energy_efficient_cpu()) is now ANDed not only with the SD mask but also with the cpu_online_mask. This is fine since this cpumask has to be in syc with the one used for energy computation (compute_energy()). An exclusive cpuset setup with at least one asymmetric CPU capacity island (hence the additional AND with the SD cpumask) is the obvious exception here. Signed-off-by: Dietmar Eggemann diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index f1e78f6adc98..97eb8afb336c 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -6694,14 +6694,14 @@ static unsigned long cpu_util_next(int cpu, struct task_struct *p, int dst_cpu) * task. */ static long -compute_energy(struct task_struct *p, int dst_cpu, struct perf_domain *pd) +compute_energy(struct task_struct *p, int dst_cpu, struct cpumask *cpus, + struct perf_domain *pd) { - struct cpumask *pd_mask = perf_domain_span(pd); unsigned long max_util = 0, sum_util = 0, cpu_cap; int cpu; - cpu_cap = arch_scale_cpu_capacity(cpumask_first(pd_mask)); - cpu_cap -= arch_scale_thermal_pressure(cpumask_first(pd_mask)); + cpu_cap = arch_scale_cpu_capacity(cpumask_first(cpus)); + cpu_cap -= arch_scale_thermal_pressure(cpumask_first(cpus)); /* * The capacity state of CPUs of the current rd can be driven by CPUs @@ -6712,7 +6712,7 @@ compute_energy(struct task_struct *p, int dst_cpu, struct perf_domain *pd) * If an entire pd is outside of the current rd, it will not appear in * its pd list and will not be accounted by compute_energy(). */ - for_each_cpu_and(cpu, pd_mask, cpu_online_mask) { + for_each_cpu(cpu, cpus) { unsigned long util_freq = cpu_util_next(cpu, p, dst_cpu); unsigned long cpu_util, util_running = util_freq; struct task_struct *tsk = NULL; @@ -6799,6 +6799,7 @@ compute_energy(struct task_struct *p, int dst_cpu, struct perf_domain *pd) */ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) { + struct cpumask *cpus = this_cpu_cpumask_var_ptr(select_rq_mask); unsigned long prev_delta = ULONG_MAX, best_delta = ULONG_MAX; struct root_domain *rd = cpu_rq(smp_processor_id())->rd; int cpu, best_energy_cpu = prev_cpu, target = -1; @@ -6833,7 +6834,9 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) unsigned long base_energy_pd; int max_spare_cap_cpu = -1; - for_each_cpu_and(cpu, perf_domain_span(pd), sched_domain_span(sd)) { + cpumask_and(cpus, perf_domain_span(pd), cpu_online_mask); + + for_each_cpu_and(cpu, cpus, sched_domain_span(sd)) { if (!cpumask_test_cpu(cpu, p->cpus_ptr)) continue; @@ -6870,12 +6873,12 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) continue; /* Compute the 'base' energy of the pd, without @p */ - base_energy_pd = compute_energy(p, -1, pd); + base_energy_pd = compute_energy(p, -1, cpus, pd); base_energy += base_energy_pd; /* Evaluate the energy impact of using prev_cpu. */ if (compute_prev_delta) { - prev_delta = compute_energy(p, prev_cpu, pd); + prev_delta = compute_energy(p, prev_cpu, cpus, pd); if (prev_delta < base_energy_pd) goto unlock; prev_delta -= base_energy_pd; @@ -6884,7 +6887,8 @@ 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) { - cur_delta = compute_energy(p, max_spare_cap_cpu, pd); + cur_delta = compute_energy(p, max_spare_cap_cpu, cpus, + pd); if (cur_delta < base_energy_pd) goto unlock; cur_delta -= base_energy_pd; -- 2.25.1