Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp317525lqd; Wed, 24 Apr 2024 03:23:07 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW1VsytEq4V+ZADhVyUgCCoUNYXIH6VNSXmDI84Nw8WgyD08nIxRvwILWdYJPW7mChNzI6kcoWmVMEF5fNVbfR7TM16WQQFdhJeD/HhXg== X-Google-Smtp-Source: AGHT+IH//AC/W0aYERi/8Um9Fq7J0IHdikqFjDxngx3FSyj3jJRGnHzciAsx6aU+c2I7QXRWdkCs X-Received: by 2002:a17:906:f59f:b0:a55:bd0a:9ddb with SMTP id cm31-20020a170906f59f00b00a55bd0a9ddbmr1558684ejd.63.1713954187358; Wed, 24 Apr 2024 03:23:07 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713954187; cv=pass; d=google.com; s=arc-20160816; b=nXEsjtijEpkaGupuU69xhxFVwgWO08kERQ+TC/0dGyinF+H99rdq5b8Xv2GEqmkRAk H7Q2ivfR873QzO90Zg2Wv0aS/UxHcnowuXDyc3gPGn92qwxykfXGg0d1oYhlK+3oBsIq GnyhLgQbf1DAzjb1yTNkY3evlKy4OPBzb8dTtoT9B0MVeIpCuAG0Cd+ee1ihoe4bwjsy qlS0g1IFBZRc9FHOQonvNhNZ+4eqRQo50bOQJSFf9OQBFPMf8rjJuuvp5Mz5iX7jWWlm bSxMrFZd9O1HuQfsDaNdaC+J6aFPtnZpuCmlHILecBS9oQ0RDETzSBJ1QLsBnfsvoqH0 vAAA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:precedence:robot-unsubscribe:robot-id :message-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:in-reply-to:cc:subject:to:reply-to:sender :from:dkim-signature:dkim-signature:date; bh=9am5/VqSEo+Eh/iGqW+GSu3vRZew2I2risZrB+5kw+I=; fh=roYHTfQ2Fh2RHTCBAuEnwlXhT2syDIcbAP6smDkEYWM=; b=FKpJN9HMqYAwB3ryam33DArQNDTZNObkJkY41s/v6QZ9ApNMOGy1OFs9BXHKiKV8pD jpQraspcUoaz2vfcp4ikwo91lkOfJtVCHzHucZkF9bVfO7UfQznYYLxipxZK6jM7c4C6 1tJD5m2cBWAS+uNyoYHnZ7X7DTvhi82Z6NKeVN4IQNYwhosJ/1KAjxHGKpEcIH3SvAFQ TIts9pXoGnUL2lBR5DzqqeIun0Omx4Cfoz+V3ofjyvp0FY6HLEv2TwH5bAP3Vt1q7y+M zl4yVz8UL/p5OqkIUJIQr0l5CNPxY1n3qC071Ex7YxX83hZNACxfUS/6iPwreyS86l8i Iuog==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=3WNH8hsR; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-156715-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-156715-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id qb39-20020a1709077ea700b00a5892ba09d0si720199ejc.755.2024.04.24.03.23.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Apr 2024 03:23:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-156715-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=3WNH8hsR; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-156715-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-156715-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id E70A41F228F4 for ; Wed, 24 Apr 2024 10:23:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7B6D315A4A8; Wed, 24 Apr 2024 10:22:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="3WNH8hsR"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Fie8rTcI" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B2F261598EF; Wed, 24 Apr 2024 10:22:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713954140; cv=none; b=M/0vitxmj8UH+gZVAreicjCNQjS0ENus6xw1NHdWFGwMC5XCwUSXOZoOgauZEHvuIXDHO1DWHeaLksfA4lUoPO94VNPIEZ1HxJgJzdVYUamU0B4zqgf5R1Vr/23J5kQXDWsEHMdjN7vM2OQAyK9VOPu10B4sYj07cRreC1W+2sM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713954140; c=relaxed/simple; bh=4UPH9s3oZicDEY2CGtRRC9fG/NcIDaxINdf5JSl5DsM=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=cN6QAqC339bSPw1OE4/Dx08NoGcz7DKZvZYfNfLMzTPNRIrps0RaePvCzrIXvBdUgMDNLLOT64sKZz1gyWbsJ0fspe3X0gJXEcNiaeKndrYntGIqLPEikS8Gzvmp3mqBr5R3Ai9kIxGk/Nz3YBKrgPAMpeBNg4Y8rBHrnm3v8D8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=3WNH8hsR; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Fie8rTcI; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Date: Wed, 24 Apr 2024 10:22:16 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1713954137; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9am5/VqSEo+Eh/iGqW+GSu3vRZew2I2risZrB+5kw+I=; b=3WNH8hsRCy2/mIO1jdSE6yD+b5ZXo+1VwPtig2DJ/LAjbCz6VLK08slIBVMuVwLeTEQCYf NHSiTrQV8fvkweTTos9N77RP8FzMGGOub2n72g1nfiVvunIqHDow3pJq/KV0B1iRiYENTK kTezA2YKSrGWTEBVJRti6BJbqNaR05o+nDTmLwMQ4Hd2EjZ/mHT+1A/SP54gj8vutjNNqA a6loOwI3RoZJnllOxdZi9YUmtPTGxZ64qQ6h4C9xSz+NeRl+PPXJMwvuVnmewM1Q83AeTp 5IVcMjXvUs/FvOquDcypMyUJ4EFMmi8DPwEyfw2cA+8Z07bLC+QfWsPANDTNnA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1713954137; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9am5/VqSEo+Eh/iGqW+GSu3vRZew2I2risZrB+5kw+I=; b=Fie8rTcI03FGZVzQiFsfuDJeyUhUGL9eF3BBzjelTdPGPSbBbRV8gn/vYXnK4jVFe7Ordr iLq7TAi/ObD8WLCA== From: "tip-bot2 for Vincent Guittot" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] sched/cpufreq: Take cpufreq feedback into account Cc: Vincent Guittot , Ingo Molnar , Lukasz Luba , Qais Yousef , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20240326091616.3696851-3-vincent.guittot@linaro.org> References: <20240326091616.3696851-3-vincent.guittot@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <171395413633.10875.16094014250688559073.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit The following commit has been merged into the sched/core branch of tip: Commit-ID: f1f8d0a224227e4f19a8a8881dc6355bdfc51230 Gitweb: https://git.kernel.org/tip/f1f8d0a224227e4f19a8a8881dc6355bdfc51230 Author: Vincent Guittot AuthorDate: Tue, 26 Mar 2024 10:16:13 +01:00 Committer: Ingo Molnar CommitterDate: Wed, 24 Apr 2024 12:07:59 +02:00 sched/cpufreq: Take cpufreq feedback into account 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 Signed-off-by: Ingo Molnar Tested-by: Lukasz Luba Reviewed-by: Lukasz Luba Reviewed-by: Qais Yousef Link: https://lore.kernel.org/r/20240326091616.3696851-3-vincent.guittot@linaro.org --- kernel/sched/fair.c | 45 ++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index bb1ae4e..19199c1 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -4965,13 +4965,22 @@ done: 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 = capacity_of(cpu); + unsigned long capacity_orig; bool fits, uclamp_max_fits; /* @@ -5003,7 +5012,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. @@ -5078,7 +5086,8 @@ 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; @@ -7494,7 +7503,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). @@ -7987,8 +7996,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; @@ -8018,7 +8027,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; @@ -8030,18 +8039,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; @@ -8112,7 +8120,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); } @@ -8127,7 +8135,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, @@ -8148,14 +8156,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; @@ -9560,8 +9568,8 @@ static inline void init_sd_lb_stats(struct sd_lb_stats *sds) static unsigned long scale_rt_capacity(int cpu) { + unsigned long max = get_actual_cpu_capacity(cpu); struct rq *rq = cpu_rq(cpu); - unsigned long max = arch_scale_cpu_capacity(cpu); unsigned long used, free; unsigned long irq; @@ -9573,12 +9581,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 = cpu_util_rt(rq); used += cpu_util_dl(rq); - used += thermal_load_avg(rq); if (unlikely(used >= max)) return 1;