From patchwork Tue Dec 12 14:27:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 13489336 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 62AC7C4167D for ; Tue, 12 Dec 2023 14:28:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=c6+N6iQkUq5XHP5+qcYOEK95Uh71c8sqAS3sGEV4fDo=; b=Sb8aHIwUUdrGkk n6P3lUEf/+VKvjrukuG+bVNmt8Bj07oTsZQ47hkwmH1Mi4OaZFNZ67tl7AvvomyaxvZrCX7x5UkpM wHaXEl0XQlZmhc2fEv+s/bigAzjqeQuzZhqax3yLJm8sq73Byq0psBCcEaq+nTS0WZBYnfo6FQ6hN DpA3MK0QNZVmZ+7/3Y0gLMXHLOKu2k96lSmyhK3ZKGJLFw72jsAYUl3l0WrUHE02/Y5v5a6inLNA+ ntpXI5L/EEuquS2ZtLUdW890AjvsQca25AseFpIC7pRGxlwMEKt+l9/Ui69l3K47E981EaUD7vZHi RbV4R/YTVCVOXCu7pDlg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rD3jj-00Bu3F-2G; Tue, 12 Dec 2023 14:27:51 +0000 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rD3jb-00BtyX-1l for linux-arm-kernel@lists.infradead.org; Tue, 12 Dec 2023 14:27:45 +0000 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-40c317723a8so47875005e9.3 for ; Tue, 12 Dec 2023 06:27:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1702391259; x=1702996059; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kLQdXWxqcE8aKZEzrPx5c+qhH1Q+ID9rmLaxmd4LW08=; b=ufH1J9OVdDK0g2jSqf1FOMAPIU86ulFiuBcIj57gDKsWgpmOgxH3VjieOiT9SSSAA8 ZbHkAbG040/J8LyfgeIgRkU6GJWflYlwQjzldzf1KMdaGSS7qKGumSMLf3HGYB9j3Vez SU3CPSYz+mUJ56jf4QDypsztjV8Bt5BBcbhDuI0XZx9h94TphPAHv61OQZ8I35CVdOvG 4yMmrqxJxq7cQIy6H0sVfOqHLTiWhJPUcK0lSVyyOJL2FmenA/QKceglJq4Uez8OcmUK gJHUD97onJTGxYY6JS55mEvUTh16IY9ykfRDYa2goSSOLKAFTfBuX5r7cKho40XeuWMG eEPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702391259; x=1702996059; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kLQdXWxqcE8aKZEzrPx5c+qhH1Q+ID9rmLaxmd4LW08=; b=pSQ5JKWz9VBWlnPvd6sQ0DRPMPNbCTcQv1bCVt575bu5C0JOO7bySCrNy1oYrD8Hg/ ebvmhpLpNSwXAvI+YbpWZCqd6TcMXo5XpSdtbwUBYmEnCGGiwEAZsC1Qev/sKwyE3TcB VgPyL0Fd+Wru6VecsLRaQ0IBZe5CTQAHLR/YyMHV77R17SNIiCnyNLZRmYoa8LMo/Zt5 u5gV2RiwWZx4sC5M5md29p+4byKt6wQr7D1fA/+aYGk9wdiK/hpjkrLVpuG9+I0GR4MD ywIta58HGJvEE11BzvRgHUWhzYFpaOLL9oeSdvX849HNrBHuc0GDtKxt2H+hxSZVAtSW AnIQ== X-Gm-Message-State: AOJu0YzugJAumvFkZwX97ExDtrcJlWT2Vze/4Ffd7FETTc6RPkszwzUW f3cqnw83Ws+bow/ABRW8vaAY4g== X-Google-Smtp-Source: AGHT+IHbqScGd7JjGKcWeC3RSyHp3cCEg8NG5/xmphu8ZwSRPr7mgum3HD3ooekcumPPTTr74rJr8w== X-Received: by 2002:a05:600c:1827:b0:40c:3828:b8cb with SMTP id n39-20020a05600c182700b0040c3828b8cbmr2852611wmp.101.1702391259009; Tue, 12 Dec 2023 06:27:39 -0800 (PST) Received: from vingu-book.. ([2a01:e0a:f:6020:a004:6e24:43ee:dd81]) by smtp.gmail.com with ESMTPSA id fc7-20020a05600c524700b0040c44cb251dsm9078291wmb.46.2023.12.12.06.27.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 06:27:38 -0800 (PST) From: Vincent Guittot To: catalin.marinas@arm.com, will@kernel.org, sudeep.holla@arm.com, rafael@kernel.org, viresh.kumar@linaro.org, agross@kernel.org, andersson@kernel.org, konrad.dybcio@linaro.org, mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, lukasz.luba@arm.com, rui.zhang@intel.com, mhiramat@kernel.org, daniel.lezcano@linaro.org, amit.kachhap@gmail.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-trace-kernel@vger.kernel.org Cc: Vincent Guittot Subject: [PATCH 2/4] sched: Take cpufreq feedback into account Date: Tue, 12 Dec 2023 15:27:28 +0100 Message-Id: <20231212142730.998913-3-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231212142730.998913-1-vincent.guittot@linaro.org> References: <20231212142730.998913-1-vincent.guittot@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231212_062743_656138_7812B15F X-CRM114-Status: GOOD ( 17.99 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Aggregate the different pressures applied on the capacity of CPUs and create a new function that returns the actual capacity of the CPU: get_actual_cpu_capacity() Signed-off-by: Vincent Guittot Reviewed-by: Lukasz Luba --- kernel/sched/fair.c | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index bcea3d55d95d..11d3be829302 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -4932,12 +4932,20 @@ static inline void util_est_update(struct cfs_rq *cfs_rq, trace_sched_util_est_se_tp(&p->se); } +static inline unsigned long get_actual_cpu_capacity(int cpu) +{ + unsigned long capacity = arch_scale_cpu_capacity(cpu); + + capacity -= max(thermal_load_avg(cpu_rq(cpu)), cpufreq_get_pressure(cpu)); + + return capacity; +} static inline int util_fits_cpu(unsigned long util, unsigned long uclamp_min, unsigned long uclamp_max, int cpu) { - unsigned long capacity_orig, capacity_orig_thermal; + unsigned long capacity_orig; unsigned long capacity = capacity_of(cpu); bool fits, uclamp_max_fits; @@ -4970,7 +4978,6 @@ static inline int util_fits_cpu(unsigned long util, * goal is to cap the task. So it's okay if it's getting less. */ capacity_orig = arch_scale_cpu_capacity(cpu); - capacity_orig_thermal = capacity_orig - arch_scale_thermal_pressure(cpu); /* * We want to force a task to fit a cpu as implied by uclamp_max. @@ -5045,7 +5052,7 @@ static inline int util_fits_cpu(unsigned long util, * handle the case uclamp_min > uclamp_max. */ uclamp_min = min(uclamp_min, uclamp_max); - if (fits && (util < uclamp_min) && (uclamp_min > capacity_orig_thermal)) + if (fits && (util < uclamp_min) && (uclamp_min > get_actual_cpu_capacity(cpu))) return -1; return fits; @@ -7426,7 +7433,7 @@ select_idle_capacity(struct task_struct *p, struct sched_domain *sd, int target) * Look for the CPU with best capacity. */ else if (fits < 0) - cpu_cap = arch_scale_cpu_capacity(cpu) - thermal_load_avg(cpu_rq(cpu)); + cpu_cap = get_actual_cpu_capacity(cpu); /* * First, select CPU which fits better (-1 being better than 0). @@ -7919,8 +7926,8 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) struct root_domain *rd = this_rq()->rd; int cpu, best_energy_cpu, target = -1; int prev_fits = -1, best_fits = -1; - unsigned long best_thermal_cap = 0; - unsigned long prev_thermal_cap = 0; + unsigned long best_actual_cap = 0; + unsigned long prev_actual_cap = 0; struct sched_domain *sd; struct perf_domain *pd; struct energy_env eenv; @@ -7950,7 +7957,7 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) for (; pd; pd = pd->next) { unsigned long util_min = p_util_min, util_max = p_util_max; - unsigned long cpu_cap, cpu_thermal_cap, util; + unsigned long cpu_cap, cpu_actual_cap, util; long prev_spare_cap = -1, max_spare_cap = -1; unsigned long rq_util_min, rq_util_max; unsigned long cur_delta, base_energy; @@ -7962,18 +7969,17 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) if (cpumask_empty(cpus)) continue; - /* Account thermal pressure for the energy estimation */ + /* Account external pressure for the energy estimation */ cpu = cpumask_first(cpus); - cpu_thermal_cap = arch_scale_cpu_capacity(cpu); - cpu_thermal_cap -= arch_scale_thermal_pressure(cpu); + cpu_actual_cap = get_actual_cpu_capacity(cpu); - eenv.cpu_cap = cpu_thermal_cap; + eenv.cpu_cap = cpu_actual_cap; eenv.pd_cap = 0; for_each_cpu(cpu, cpus) { struct rq *rq = cpu_rq(cpu); - eenv.pd_cap += cpu_thermal_cap; + eenv.pd_cap += cpu_actual_cap; if (!cpumask_test_cpu(cpu, sched_domain_span(sd))) continue; @@ -8044,7 +8050,7 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) if (prev_delta < base_energy) goto unlock; prev_delta -= base_energy; - prev_thermal_cap = cpu_thermal_cap; + prev_actual_cap = cpu_actual_cap; best_delta = min(best_delta, prev_delta); } @@ -8059,7 +8065,7 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) * but best energy cpu has better capacity. */ if ((max_fits < 0) && - (cpu_thermal_cap <= best_thermal_cap)) + (cpu_actual_cap <= best_actual_cap)) continue; cur_delta = compute_energy(&eenv, pd, cpus, p, @@ -8080,14 +8086,14 @@ static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) best_delta = cur_delta; best_energy_cpu = max_spare_cap_cpu; best_fits = max_fits; - best_thermal_cap = cpu_thermal_cap; + best_actual_cap = cpu_actual_cap; } } rcu_read_unlock(); if ((best_fits > prev_fits) || ((best_fits > 0) && (best_delta < prev_delta)) || - ((best_fits < 0) && (best_thermal_cap > prev_thermal_cap))) + ((best_fits < 0) && (best_actual_cap > prev_actual_cap))) target = best_energy_cpu; return target; @@ -9466,7 +9472,7 @@ static inline void init_sd_lb_stats(struct sd_lb_stats *sds) static unsigned long scale_rt_capacity(int cpu) { struct rq *rq = cpu_rq(cpu); - unsigned long max = arch_scale_cpu_capacity(cpu); + unsigned long max = get_actual_cpu_capacity(cpu); unsigned long used, free; unsigned long irq; @@ -9478,12 +9484,9 @@ static unsigned long scale_rt_capacity(int cpu) /* * avg_rt.util_avg and avg_dl.util_avg track binary signals * (running and not running) with weights 0 and 1024 respectively. - * avg_thermal.load_avg tracks thermal pressure and the weighted - * average uses the actual delta max capacity(load). */ used = READ_ONCE(rq->avg_rt.util_avg); used += READ_ONCE(rq->avg_dl.util_avg); - used += thermal_load_avg(rq); if (unlikely(used >= max)) return 1;