From nobody Mon Feb 9 06:50:28 2026 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 82CB32686A0 for ; Fri, 28 Feb 2025 13:40:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740750008; cv=none; b=J+BOAlWuXQYALB1EMNZDFg6/hPq017FVqmArdViIyWIIsQhqm5VRPmi3vJ/6I4bvP7zpull9KNLG3G/yy+XPMLFJ2s9TKGhgkhSpzgnqQdL8+b/JSVgg0nw2MSDciSz2wEDcMW/u5q2PihdQy9Rth3xBwzx2TuIr/wRkbFkx8Ek= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740750008; c=relaxed/simple; bh=l6s2K8nye6CHRRRLfb5EYZPGV2XdU8BZngWM9TLpnUk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EqIPwst3JIj195iTI/PtV+GBrBXFQs2DCeNUCxUB72V8C5DnvoqIQp4ODCrMoFebc72l0m+7KVsixAjtu/NMGHxtgej0oeW5jyEN8Pl+6pA7+qzkQy3ImIirQwM03MX879C7CfFSkHzXR7UQUn0M3Wx5APz8EVSEQVJqn7j+fdc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=J1vKNXhm; arc=none smtp.client-ip=209.85.128.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="J1vKNXhm" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-4399d14334aso19911225e9.0 for ; Fri, 28 Feb 2025 05:40:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740750005; x=1741354805; darn=vger.kernel.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=R7Qe15dxMfjDnNi0r7cCotARJKXbVAoEJ27P5CWqzBU=; b=J1vKNXhm9MmvNCcQRS3f1GKNlFr1kx7Wv8fyFqo0ESfcvvLw5+EIxt71l8LHgEFv7L M+ZLHspA9fdHpW1elsSwVm+RZjIcgmS6NBakkXZmP2SwxBWX4ierPXCifeQqh3MwEjvE 2gxD3znU4OHyKfh4UrrxYyiUPxP9+cT1IGDgbtEdaEmWoJj+p20vu66wQzVZTV4urln6 /qHX7f+ZWjCsv7OlbjCjLhH4H/oUs8RznUd1IoSP+m6QHVUBZ3JTWmRmz5c2b4zCYdbH UlmEVBSHULm09E1qFaCywEXsN0BraC8mk2CHhka+oT7XAEt0o3fAGgh+lYMq+UVmuhk3 33RQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740750005; x=1741354805; 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=R7Qe15dxMfjDnNi0r7cCotARJKXbVAoEJ27P5CWqzBU=; b=uVyIqJ8Gv3WugvUTCfGx6RkjZViw3p22T80h/F1RDY1PlllFYwCE1jPFKHsWckZTRk RVHOipY4x4R9q8Nd1dO78Xcc1evrv7oXL/fQMaKm10CwGgBFQ18trIekf+3zj8J91hhU 7u5dS3gQpuCW8akyvaStVu1bFLv65caB4pzB3kH/gbWmYfj6wTPQkliHyPe4nfYOQYgH hqftSVbgDv5Q1HrKeC+ZWVN1//MrOI5E6PXIYK659uz267LlDv805fG2g7KFAy7zyJfI 2/LdWCSvpzigJ5GWzM1xp0zgnYQK1TnV2Eym5HyciYsJzvIAonajFd3KCWZumh1ltoVs 21Gw== X-Forwarded-Encrypted: i=1; AJvYcCVe4E8SbrwAponp6/+f1qVkbZqwTk9td7roIfR3F2IrSThz18xJ1Oiv01t90F5SUUfChv1BSX+im9oGgFg=@vger.kernel.org X-Gm-Message-State: AOJu0YyIWjPtZZb3oZAlFFSwOTICdSbItayCv2a7rBmjmH2hAPOsQQ/R uxTODATLPpH54CL3LGkVX+mX4z8IgDpcL8PF0Z1Z08vOUdztR4E2WOa/jIVBIC0= X-Gm-Gg: ASbGncsoOdEHJEbbYTxpta/1nZRqKaOeU3riMc4tfnfSlBJqVp6r41pdF8ZgcSR5W25 gxEBXLntyOdWXtA5cJZeyTO1s7Erm+WZKzhgqVaigDFmPKotSGR+akESBqvgKUhCfQ6eBlVBzh4 HbKQgHMSO107vdkL42UdOfwXMjgWfkYYkhhlhhHZa342pYBy+Gw2jioWi9jismqPqDrVHGA/GLd LOaAuE6+FCrTuBV2Rb93VBAxBwI90tAqWu/uxDxFy2VXNXswprdywExiO36ivWjVHFRncCrHYX8 SY3CphyO2Ocm8VVAwAJmZf2OGjb+44PI7A== X-Google-Smtp-Source: AGHT+IH5FG8AQ6D+64sFGHfe3tHwWw2ntFHIUnyirsKoQY14AoDqBIkyyts2MWqQVEWC51mEK7nJmg== X-Received: by 2002:a05:600c:3ba8:b0:43a:9ef6:77ec with SMTP id 5b1f17b1804b1-43ba697ef79mr25704955e9.23.1740750004759; Fri, 28 Feb 2025 05:40:04 -0800 (PST) Received: from vingu-cube.. ([2a01:e0a:f:6020:d4b:473f:a962:e9e2]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43b73717171sm55984405e9.18.2025.02.28.05.40.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Feb 2025 05:40:03 -0800 (PST) From: Vincent Guittot To: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com, lukasz.luba@arm.com, rafael.j.wysocki@intel.com, pierre.gondois@arm.com, linux-kernel@vger.kernel.org Cc: qyousef@layalina.io, hongyan.xia2@arm.com, christian.loehle@arm.com, luis.machado@arm.com, qperret@google.com, Vincent Guittot Subject: [PATCH 1/7 v3] sched/fair: Filter false overloaded_group case for EAS Date: Fri, 28 Feb 2025 14:39:54 +0100 Message-ID: <20250228134000.1226665-2-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250228134000.1226665-1-vincent.guittot@linaro.org> References: <20250228134000.1226665-1-vincent.guittot@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" With EAS, a group should be set overloaded if at least 1 CPU in the group is overutilized but it can happen that a CPU is fully utilized by tasks because of clamping the compute capacity of the CPU. In such case, the CPU is not overutilized and as a result should not be set overloaded as well. group_overloaded being a higher priority than group_misfit, such group can be selected as the busiest group instead of a group with a mistfit task and prevents load_balance to select the CPU with the misfit task to pull the latter on a fitting CPU. Signed-off-by: Vincent Guittot Tested-by: Pierre Gondois --- kernel/sched/fair.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 857808da23d8..d3d1a2ba6b1a 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -9931,6 +9931,7 @@ struct sg_lb_stats { unsigned int group_asym_packing; /* Tasks should be moved to preferred CP= U */ unsigned int group_smt_balance; /* Task on busy SMT be moved */ unsigned long group_misfit_task_load; /* A CPU has a task too big for its= capacity */ + unsigned int group_overutilized; /* At least one CPU is overutilized in t= he group */ #ifdef CONFIG_NUMA_BALANCING unsigned int nr_numa_running; unsigned int nr_preferred_running; @@ -10163,6 +10164,13 @@ group_has_capacity(unsigned int imbalance_pct, str= uct sg_lb_stats *sgs) static inline bool group_is_overloaded(unsigned int imbalance_pct, struct sg_lb_stats *sgs) { + /* + * With EAS and uclamp, 1 CPU in the group must be overutilized to + * consider the group overloaded. + */ + if (sched_energy_enabled() && !sgs->group_overutilized) + return false; + if (sgs->sum_nr_running <=3D sgs->group_weight) return false; =20 @@ -10374,8 +10382,10 @@ static inline void update_sg_lb_stats(struct lb_en= v *env, nr_running =3D rq->nr_running; sgs->sum_nr_running +=3D nr_running; =20 - if (cpu_overutilized(i)) + if (cpu_overutilized(i)) { *sg_overutilized =3D 1; + sgs->group_overutilized =3D 1; + } =20 /* * No need to call idle_cpu() if nr_running is not 0 --=20 2.43.0 From nobody Mon Feb 9 06:50:28 2026 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06F7B26D5A2 for ; Fri, 28 Feb 2025 13:40:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740750009; cv=none; b=lmenhuOifAFAJExzd0O3IS0p/WXdNdfkdUILrkSyPt0GtDZdMsrH+lOJcUgi/9d6YM5P+zBA3swva8fqwOFqO9/b5GyKcDUCExH9kM/ui3U3P/fdaq1PLsgRzg5nBv4eclVA1YxaMWzvxjuKeXqfw75lLeClMcLXrv2VlF/Fyb8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740750009; c=relaxed/simple; bh=BIANFdS2G59gFgyF18cu7TQxo7ed8WKfM/z9xd5aqyE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A2oJj+AKB+lHeOjvYKi7WqxTMUArrEmhUS0jTS59vtHNF1ufbry1ogzjjZnEZICnTe7C7vaPXm6xJwpg0+sSwgIvQHoBqfFMF+aCHdWMMOkj4zqwD2saG+aMw2O/b6y5whLkb3LUMrB0gAdtYhNR1S7rYPhL7chhe0ki1TJgiAQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=A8NX+VS4; arc=none smtp.client-ip=209.85.128.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="A8NX+VS4" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4398e839cd4so20330185e9.0 for ; Fri, 28 Feb 2025 05:40:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740750006; x=1741354806; darn=vger.kernel.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=E0f9s7NROJ8fq5WoWUVEhIJcFKUOaWVTVNLDozZ75KA=; b=A8NX+VS4JyZb+BjzJLYURfNfTDLMnFAG1GvBBDqggdDI1oHMlOJLPnkL2v8DANDElv MoErqzx9WhZ/T3bkJaEHKLZqJQbvVbleoLNQvTqWFeMoVBfRoEkLLS0I/fO801rwPpAD rSjP6EN3eeF5WtoH01d3NVQzciySjSX8SgYWzpCIMAH1pY/whH95QR58iKORn38qFtGa j/AWUw4p+U34cIPCnXuR9IKJBVrsK8bKOSysJzRDKVrAjhxGuNu6DMU/jMpjDkf8HvHV 2TVphlNbSEhjbmcBUYd3T/RjUstcBr2xLQtUF8MEtB4s56DDOEqJuU37l+vu0EP13yCN Qz+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740750006; x=1741354806; 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=E0f9s7NROJ8fq5WoWUVEhIJcFKUOaWVTVNLDozZ75KA=; b=BrdecRdKyLJCaIUhIRcCwsK15TR9Jq6xQx+UNEQqWyLt0t+7U5KJklEryWVMg8P6PP N7YSSXIede4ey800jclg86tFTxkt8zJQvsvJiS5VSLH2FZPnELtYwzlh27SqZX60NUf+ fDHA8WbFX7XF41fAr8o0GNdhoGVjZdoJn7Xj1GmYhsaIUcjy0WXnFf2AyjaTDZtM7y8U 8Ax//5hDTYdwYcLkR6KIqNdtNpcaNrZNcAN5Y+S4BP8gG0euEbpHxkp3+nY7oDUOyhD6 NPsGdWWzACP5vTpOzvk9xEQITYIQpVgQuOEf0k81S5fmJvxxR9ogOjPIXfg3D+sdLLG0 IzCg== X-Forwarded-Encrypted: i=1; AJvYcCUPwxYmdjWhfzw4+b7zRE3MAez5LQth8pH2RwVX9NVq+Lag3Is48cVhulL1ix5CADN6CNLWQWHX0SToyi0=@vger.kernel.org X-Gm-Message-State: AOJu0YwbRjWwTHrkxEcbc0xXZq06L5g+QmbPWDoZ2FtwEFKItbO6Oq8a VT5n/wYiT4FaFiyu8nf8XAkHE9KLRPEqjcqIpT0CnGHzloDe5+YjyKQKNhszTaU= X-Gm-Gg: ASbGncs9dq2NSE9LhRLKEGnMGWkEl3NnlMtkaooI6sa0aec9sNc7PAXEvMPdTJOlVBu zS7NE9Txbq7RcrTZR0UY+vp3IDqHCpW8lyNFof1A0fMaA2jbw2kjhGI+B693hiQNkHqw5nPL7sU VTUdTAjhy09cryf7N8UC7xNpukc/fzu5oa6CWuhj64wLDG/bMuSLtsCenXYQRcNfJ6zLO7xa5qg VCOyHefl7iL5UU6r2HZ5DceMwwtnG0eaUDwgLgUQ5qSxGsyuxNagcBHv5vDTbWd+nIPkNH39i2P /+yD0AfD9DYCsnmBA/kzt2Ua0rxdOZlD6g== X-Google-Smtp-Source: AGHT+IFhgqPKyxi/6XA1Evr5XU3hym4zZCuFuOCuZ2Y8cdmfrSJZbM8SIUokKRqMnUfbdWNpgZ/v+g== X-Received: by 2002:a05:600c:5594:b0:439:8605:6d7c with SMTP id 5b1f17b1804b1-43af790fa9emr60491555e9.0.1740750006276; Fri, 28 Feb 2025 05:40:06 -0800 (PST) Received: from vingu-cube.. ([2a01:e0a:f:6020:d4b:473f:a962:e9e2]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43b73717171sm55984405e9.18.2025.02.28.05.40.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Feb 2025 05:40:05 -0800 (PST) From: Vincent Guittot To: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com, lukasz.luba@arm.com, rafael.j.wysocki@intel.com, pierre.gondois@arm.com, linux-kernel@vger.kernel.org Cc: qyousef@layalina.io, hongyan.xia2@arm.com, christian.loehle@arm.com, luis.machado@arm.com, qperret@google.com, Vincent Guittot Subject: [PATCH 2/7 v3] energy model: Add a get previous state function Date: Fri, 28 Feb 2025 14:39:55 +0100 Message-ID: <20250228134000.1226665-3-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250228134000.1226665-1-vincent.guittot@linaro.org> References: <20250228134000.1226665-1-vincent.guittot@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Instead of parsing the entire EM table everytime, add a function to get the previous state. Will be used in the scheduler feec() function. Signed-off-by: Vincent Guittot --- include/linux/energy_model.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index 78318d49276d..967650726619 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -216,6 +216,26 @@ em_pd_get_efficient_state(struct em_perf_state *table, return max_ps; } =20 +static inline int +em_pd_get_previous_state(struct em_perf_state *table, + struct em_perf_domain *pd, int idx) +{ + unsigned long pd_flags =3D pd->flags; + int min_ps =3D pd->min_perf_state; + struct em_perf_state *ps; + int i; + + for (i =3D idx - 1; i >=3D min_ps; i--) { + ps =3D &table[i]; + if (pd_flags & EM_PERF_DOMAIN_SKIP_INEFFICIENCIES && + ps->flags & EM_PERF_STATE_INEFFICIENT) + continue; + return i; + } + + return -1; +} + /** * em_cpu_energy() - Estimates the energy consumed by the CPUs of a * performance domain @@ -362,6 +382,19 @@ static inline struct em_perf_domain *em_pd_get(struct = device *dev) { return NULL; } +static inline int +em_pd_get_efficient_state(struct em_perf_state *table, + struct em_perf_domain *pd, unsigned long max_util) +{ + return 0; +} + +static inline int +em_pd_get_previous_state(struct em_perf_state *table, int nr_perf_states, + int idx, unsigned long pd_flags) +{ + return -1; +} static inline unsigned long em_cpu_energy(struct em_perf_domain *pd, unsigned long max_util, unsigned long sum_util, unsigned long allowed_cpu_cap) --=20 2.43.0 From nobody Mon Feb 9 06:50:28 2026 Received: from mail-wr1-f45.google.com (mail-wr1-f45.google.com [209.85.221.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ADA3E26E152 for ; Fri, 28 Feb 2025 13:40:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740750012; cv=none; b=fFGptvW4GZNTpGfBhuRqFAZGaAYl3zfcfveg2sLwoBRjGu52QAGXVdXNjVRfpD6fqZ6d23o3LJYOr1AkWJQQKNpjhdUIYWmqL6FdDoYOLDPUWNWf4GXLQOR2B/1h7mtxGzT2ZRnTd8ZzQKcpCslGspVvmDEaSFCJze3O6y5isxQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740750012; c=relaxed/simple; bh=PsixIBRYtomDMf+aa69pSUIIBXLsyccZplM+BMuxbl8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aryPhaxYAM/nL27WG0hDJx0AJ0YVUe43byvrJZVkXByLNJdKHhurzZrxlWduJj3Trf0WcC9acKDMIUcj+ClIkBGWSLtntF7LJW3vH63i5vvb6PT6Zpp4Z9ag0/44xyQ7M2VPtRljzMwMmqwwwJ2xQE3Q63CzeNnRWzpyd879pIg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=lY5ul3Ir; arc=none smtp.client-ip=209.85.221.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="lY5ul3Ir" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-390effd3e85so664357f8f.0 for ; Fri, 28 Feb 2025 05:40:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740750008; x=1741354808; darn=vger.kernel.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=w0wS9NNaT48S3voEP7Ca12jv6d8Skrd9dbmu26/lMYU=; b=lY5ul3Ir0t+FkMWT7LniuU+AMsT0gJZPh2PHDunmUji0M1NhciAweLWbYv10p77Mjp q0alX3re4tPOif8p9g2KTbYTxDxHZX0MgxRZGFgVrGpRcPbzlWaTBj03LW0+QNApqqw3 xbIY0z8gmsvvvMZ5eFW1Ydb94lUWeMp1KgCvE3R5nI6kQxevjjU084i0gEftNXMS5/J7 vBrE1105Cfg5hDJLkOmrC0x4pxv1xDyDrg7G9FEqIAYa4xePTWBdVjWNm3ZsjDQlYD8W YH5XN0eRevpBnuL2GVwbsnLnh0hFDmxwQrUkxLsd5GkgO9PEG6lOFLt2GKh3jweZSHhV 5lMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740750008; x=1741354808; 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=w0wS9NNaT48S3voEP7Ca12jv6d8Skrd9dbmu26/lMYU=; b=Rb9ZXW4x+Bip2vq4WNA6LoCrRkao3n+wUD6qy/ZjoHudF6YXKLq9+glu6PjqKqa4qP q30V/tRU+s0cO+WvtAq5fxor5COKrhq1wtgPhYZmZoTEu02/7GxLdoCgj2XwftYm5f1c p4Fih1AyVWxN6OBwvwmKEj/3U8YD7o17TX8YzljDY/16/jDJJ5ZP/FN6dMXpy4yW82TL Zu8aG6q5EFfS2RjQPYBHwWSkqTzzYEp+6Pepyi2/yjVEpMM3HP4lv9HFXqRQOdUg2zKC Gk+pEtZsXWPVpWNzRNjCTND1QBOHfIUWWYEeO2rBqReSeLoElOQTy5JzJNuStwcIraWx nEcg== X-Forwarded-Encrypted: i=1; AJvYcCX4UBbE0spKWiRTTuTxBcbjPwsuxoitzEBcK23KWvY5ny5fphXSt611hdRILIgxIZrTtscu4f235nmvFSo=@vger.kernel.org X-Gm-Message-State: AOJu0YwmOGavhFaX3uyX7EmkQUt4dU0Ig6g3ftDrEJyYuoTI6E6nKNgi rDpZ7tNZY877E9/ehBYm53dhILAM3D/EkkiIX2ES6zB8Q0iBoxz7S89gWDNohOc= X-Gm-Gg: ASbGncvJBMbou29EQLXdBvfDRHKQ3h3ZFiwYFnyTTOODgA+faeEDkWaIzAFD2PhAzwM T8/uyIOOwEVJSEvq3dnQ4guXdZATdW42pssYFDeSumOk/4aKevfrYzwUyGcT7nyJVYqb+NBxW/F 02b7B9t1jl3WBi0vn0qb0/YuxVEysFihJiXkiKYu0DdRsNMzTN0akYzBS5Gi2H3Ro4Kf/zCf0Hf 9Oe5Oz4Fjhg4N2OxE5XNbu9WT0atFf8Sak7ua7Yzi3X/UuBsm8Db4f4w5mP5IJmDKpfePms07qV BG1uJbNBkdhf+j0EVN/YcefYvJHeHp1w1Q== X-Google-Smtp-Source: AGHT+IF7x4AnOeOpnmNGS+9mlTSN6LoUEvvf222LCvsjzyHDrJCQ9CMXxz2855nY0UxQ7rCP3pW1Ig== X-Received: by 2002:a5d:64a6:0:b0:390:eb32:3fd2 with SMTP id ffacd0b85a97d-390ec7748c9mr3106012f8f.0.1740750007745; Fri, 28 Feb 2025 05:40:07 -0800 (PST) Received: from vingu-cube.. ([2a01:e0a:f:6020:d4b:473f:a962:e9e2]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43b73717171sm55984405e9.18.2025.02.28.05.40.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Feb 2025 05:40:06 -0800 (PST) From: Vincent Guittot To: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com, lukasz.luba@arm.com, rafael.j.wysocki@intel.com, pierre.gondois@arm.com, linux-kernel@vger.kernel.org Cc: qyousef@layalina.io, hongyan.xia2@arm.com, christian.loehle@arm.com, luis.machado@arm.com, qperret@google.com, Vincent Guittot Subject: [PATCH 3/7 v3] sched/fair: Rework feec() to use cost instead of spare capacity Date: Fri, 28 Feb 2025 14:39:56 +0100 Message-ID: <20250228134000.1226665-4-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250228134000.1226665-1-vincent.guittot@linaro.org> References: <20250228134000.1226665-1-vincent.guittot@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" feec() looks for the CPU with highest spare capacity in a PD assuming that it will be the best CPU from a energy efficiency PoV because it will require the smallest increase of OPP. Although this is true generally speaking, this policy also filters some others CPUs which will be as efficients because of using the same OPP. In fact, we really care about the cost of the new OPP that will be selected to handle the waking task. In many cases, several CPUs will end up selecting the same OPP and as a result using the same energy cost. In these cases, we can use other metrics to select the best CPU for the same energy cost. Rework feec() to look 1st for the lowest cost in a PD and then the most performant CPU between CPUs. The cost of the OPP remains the only comparison criteria between Performance Domains. Signed-off-by: Vincent Guittot --- kernel/sched/fair.c | 466 +++++++++++++++++++++++--------------------- 1 file changed, 246 insertions(+), 220 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index d3d1a2ba6b1a..a9b97bbc085f 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -8193,29 +8193,37 @@ unsigned long sched_cpu_util(int cpu) } =20 /* - * energy_env - Utilization landscape for energy estimation. - * @task_busy_time: Utilization contribution by the task for which we test= the - * placement. Given by eenv_task_busy_time(). - * @pd_busy_time: Utilization of the whole perf domain without the task - * contribution. Given by eenv_pd_busy_time(). - * @cpu_cap: Maximum CPU capacity for the perf domain. - * @pd_cap: Entire perf domain capacity. (pd->nr_cpus * cpu_cap). - */ -struct energy_env { - unsigned long task_busy_time; - unsigned long pd_busy_time; - unsigned long cpu_cap; - unsigned long pd_cap; + * energy_cpu_stat - Utilization landscape for energy estimation. + * @idx : Index of the OPP in the performance domain + * @cost : Cost of the OPP + * @max_perf : Compute capacity of OPP + * @min_perf : Compute capacity of the previous OPP + * @capa : Capacity of the CPU + * @runnable : runnable_avg of the CPU + * @nr_running : Number of cfs running task + * @fits : Fits level of the CPU + * @cpu : Current best CPU + */ +struct energy_cpu_stat { + unsigned long idx; + unsigned long cost; + unsigned long max_perf; + unsigned long min_perf; + unsigned long capa; + unsigned long util; + unsigned long runnable; + unsigned int nr_running; + int fits; + int cpu; }; =20 /* - * Compute the task busy time for compute_energy(). This time cannot be - * injected directly into effective_cpu_util() because of the IRQ scaling. + * Compute the task busy time for computing its energy impact. This time c= annot + * be injected directly into effective_cpu_util() because of the IRQ scali= ng. * The latter only makes sense with the most recent CPUs where the task has * run. */ -static inline void eenv_task_busy_time(struct energy_env *eenv, - struct task_struct *p, int prev_cpu) +static inline unsigned long task_busy_time(struct task_struct *p, int prev= _cpu) { unsigned long busy_time, max_cap =3D arch_scale_cpu_capacity(prev_cpu); unsigned long irq =3D cpu_util_irq(cpu_rq(prev_cpu)); @@ -8225,124 +8233,153 @@ static inline void eenv_task_busy_time(struct ene= rgy_env *eenv, else busy_time =3D scale_irq_capacity(task_util_est(p), irq, max_cap); =20 - eenv->task_busy_time =3D busy_time; + return busy_time; } =20 -/* - * Compute the perf_domain (PD) busy time for compute_energy(). Based on t= he - * utilization for each @pd_cpus, it however doesn't take into account - * clamping since the ratio (utilization / cpu_capacity) is already enough= to - * scale the EM reported power consumption at the (eventually clamped) - * cpu_capacity. - * - * The contribution of the task @p for which we want to estimate the - * energy cost is removed (by cpu_util()) and must be calculated - * separately (see eenv_task_busy_time). This ensures: - * - * - A stable PD utilization, no matter which CPU of that PD we want to = place - * the task on. - * - * - A fair comparison between CPUs as the task contribution (task_util(= )) - * will always be the same no matter which CPU utilization we rely on - * (util_avg or util_est). - * - * Set @eenv busy time for the PD that spans @pd_cpus. This busy time can't - * exceed @eenv->pd_cap. - */ -static inline void eenv_pd_busy_time(struct energy_env *eenv, - struct cpumask *pd_cpus, - struct task_struct *p) +/* Estimate the utilization of the CPU that is then used to select the OPP= */ +static unsigned long find_cpu_max_util(int cpu, struct task_struct *p, int= dst_cpu) { - unsigned long busy_time =3D 0; - int cpu; + unsigned long util =3D cpu_util(cpu, p, dst_cpu, 1); + unsigned long eff_util, min, max; + + /* + * Performance domain frequency: utilization clamping + * must be considered since it affects the selection + * of the performance domain frequency. + */ + eff_util =3D effective_cpu_util(cpu, util, &min, &max); =20 - for_each_cpu(cpu, pd_cpus) { - unsigned long util =3D cpu_util(cpu, p, -1, 0); + /* Task's uclamp can modify min and max value */ + if (uclamp_is_used() && cpu =3D=3D dst_cpu) { + min =3D max(min, uclamp_eff_value(p, UCLAMP_MIN)); =20 - busy_time +=3D effective_cpu_util(cpu, util, NULL, NULL); + /* + * If there is no active max uclamp constraint, + * directly use task's one, otherwise keep max. + */ + if (uclamp_rq_is_idle(cpu_rq(cpu))) + max =3D uclamp_eff_value(p, UCLAMP_MAX); + else + max =3D max(max, uclamp_eff_value(p, UCLAMP_MAX)); } =20 - eenv->pd_busy_time =3D min(eenv->pd_cap, busy_time); + eff_util =3D sugov_effective_cpu_perf(cpu, eff_util, min, max); + return eff_util; } =20 -/* - * Compute the maximum utilization for compute_energy() when the task @p - * is placed on the cpu @dst_cpu. - * - * Returns the maximum utilization among @eenv->cpus. This utilization can= 't - * exceed @eenv->cpu_cap. - */ -static inline unsigned long -eenv_pd_max_util(struct energy_env *eenv, struct cpumask *pd_cpus, - struct task_struct *p, int dst_cpu) +/* Estimate the utilization of the CPU without the task */ +static unsigned long find_cpu_actual_util(int cpu, struct task_struct *p) { - unsigned long max_util =3D 0; - int cpu; + unsigned long util =3D cpu_util(cpu, p, -1, 0); + unsigned long eff_util; =20 - for_each_cpu(cpu, pd_cpus) { - struct task_struct *tsk =3D (cpu =3D=3D dst_cpu) ? p : NULL; - unsigned long util =3D cpu_util(cpu, p, dst_cpu, 1); - unsigned long eff_util, min, max; + eff_util =3D effective_cpu_util(cpu, util, NULL, NULL); =20 - /* - * Performance domain frequency: utilization clamping - * must be considered since it affects the selection - * of the performance domain frequency. - * NOTE: in case RT tasks are running, by default the min - * utilization can be max OPP. - */ - eff_util =3D effective_cpu_util(cpu, util, &min, &max); + return eff_util; +} =20 - /* Task's uclamp can modify min and max value */ - if (tsk && uclamp_is_used()) { - min =3D max(min, uclamp_eff_value(p, UCLAMP_MIN)); +/* Find the cost of a performance domain for the estimated utilization */ +static inline void find_pd_cost(struct em_perf_domain *pd, + unsigned long max_util, + struct energy_cpu_stat *stat) +{ + struct em_perf_table *em_table; + struct em_perf_state *ps; + int i; =20 - /* - * If there is no active max uclamp constraint, - * directly use task's one, otherwise keep max. - */ - if (uclamp_rq_is_idle(cpu_rq(cpu))) - max =3D uclamp_eff_value(p, UCLAMP_MAX); - else - max =3D max(max, uclamp_eff_value(p, UCLAMP_MAX)); - } + /* + * Find the lowest performance state of the Energy Model above the + * requested performance. + */ + em_table =3D rcu_dereference(pd->em_table); + i =3D em_pd_get_efficient_state(em_table->state, pd, max_util); + ps =3D &em_table->state[i]; =20 - eff_util =3D sugov_effective_cpu_perf(cpu, eff_util, min, max); - max_util =3D max(max_util, eff_util); + /* Save the cost and performance range of the OPP */ + stat->max_perf =3D ps->performance; + stat->cost =3D ps->cost; + i =3D em_pd_get_previous_state(em_table->state, pd, i); + if (i < 0) + stat->min_perf =3D 0; + else { + ps =3D &em_table->state[i]; + stat->min_perf =3D ps->performance; } +} + +/*Check if the CPU can handle the waking task */ +static int check_cpu_with_task(struct task_struct *p, int cpu) +{ + unsigned long p_util_min =3D uclamp_is_used() ? uclamp_eff_value(p, UCLAM= P_MIN) : 0; + unsigned long p_util_max =3D uclamp_is_used() ? uclamp_eff_value(p, UCLAM= P_MAX) : 1024; + unsigned long util_min =3D p_util_min; + unsigned long util_max =3D p_util_max; + unsigned long util =3D cpu_util(cpu, p, cpu, 0); + struct rq *rq =3D cpu_rq(cpu); =20 - return min(max_util, eenv->cpu_cap); + /* + * Skip CPUs that cannot satisfy the capacity request. + * IOW, placing the task there would make the CPU + * overutilized. Take uclamp into account to see how + * much capacity we can get out of the CPU; this is + * aligned with sched_cpu_util(). + */ + if (uclamp_is_used() && !uclamp_rq_is_idle(rq)) { + unsigned long rq_util_min, rq_util_max; + /* + * Open code uclamp_rq_util_with() except for + * the clamp() part. I.e.: apply max aggregation + * only. util_fits_cpu() logic requires to + * operate on non clamped util but must use the + * max-aggregated uclamp_{min, max}. + */ + rq_util_min =3D uclamp_rq_get(rq, UCLAMP_MIN); + rq_util_max =3D uclamp_rq_get(rq, UCLAMP_MAX); + util_min =3D max(rq_util_min, p_util_min); + util_max =3D max(rq_util_max, p_util_max); + } + return util_fits_cpu(util, util_min, util_max, cpu); } =20 /* - * compute_energy(): Use the Energy Model to estimate the energy that @pd = would - * consume for a given utilization landscape @eenv. When @dst_cpu < 0, the= task - * contribution is ignored. + * For the same cost, select the CPU that will povide best performance for= the + * task. */ -static inline unsigned long -compute_energy(struct energy_env *eenv, struct perf_domain *pd, - struct cpumask *pd_cpus, struct task_struct *p, int dst_cpu) +static bool update_best_cpu(struct energy_cpu_stat *target, + struct energy_cpu_stat *min, + int prev, struct sched_domain *sd) { - unsigned long max_util =3D eenv_pd_max_util(eenv, pd_cpus, p, dst_cpu); - unsigned long busy_time =3D eenv->pd_busy_time; - unsigned long energy; - - if (dst_cpu >=3D 0) - busy_time =3D min(eenv->pd_cap, busy_time + eenv->task_busy_time); + /* Select the one with the least number of running tasks */ + if (target->nr_running < min->nr_running) + return true; + if (target->nr_running > min->nr_running) + return false; =20 - energy =3D em_cpu_energy(pd->em_pd, max_util, busy_time, eenv->cpu_cap); + /* Favor previous CPU otherwise */ + if (target->cpu =3D=3D prev) + return true; + if (min->cpu =3D=3D prev) + return false; =20 - trace_sched_compute_energy_tp(p, dst_cpu, energy, max_util, busy_time); + /* + * Choose CPU with lowest contention. One might want to consider load + * instead of runnable but we are supposed to not be overutilized so + * there is enough compute capacity for everybody. + */ + if ((target->runnable * min->capa * sd->imbalance_pct) >=3D + (min->runnable * target->capa * 100)) + return false; =20 - return energy; + return true; } =20 /* * find_energy_efficient_cpu(): Find most energy-efficient target CPU for = the - * waking task. find_energy_efficient_cpu() looks for the CPU with maximum - * spare capacity in each performance domain and uses it as a potential - * candidate to execute the task. Then, it uses the Energy Model to figure - * out which of the CPU candidates is the most energy-efficient. + * waking task. find_energy_efficient_cpu() looks for the CPU with the low= est + * power cost (usually with maximum spare capacity but not always) in each + * performance domain and uses it as a potential candidate to execute the = task. + * Then, it uses the Energy Model to figure out which of the CPU candidate= s is + * the most energy-efficient. * * The rationale for this heuristic is as follows. In a performance domain, * all the most energy efficient CPU candidates (according to the Energy @@ -8379,17 +8416,14 @@ compute_energy(struct energy_env *eenv, struct perf= _domain *pd, static int find_energy_efficient_cpu(struct task_struct *p, int prev_cpu) { struct cpumask *cpus =3D this_cpu_cpumask_var_ptr(select_rq_mask); - unsigned long prev_delta =3D ULONG_MAX, best_delta =3D ULONG_MAX; - unsigned long p_util_min =3D uclamp_is_used() ? uclamp_eff_value(p, UCLAM= P_MIN) : 0; - unsigned long p_util_max =3D uclamp_is_used() ? uclamp_eff_value(p, UCLAM= P_MAX) : 1024; struct root_domain *rd =3D this_rq()->rd; - int cpu, best_energy_cpu, target =3D -1; - int prev_fits =3D -1, best_fits =3D -1; - unsigned long best_actual_cap =3D 0; - unsigned long prev_actual_cap =3D 0; + unsigned long best_nrg =3D ULONG_MAX; + unsigned long task_util; struct sched_domain *sd; struct perf_domain *pd; - struct energy_env eenv; + int cpu, target =3D -1; + int best_fits =3D -1; + int best_cpu =3D -1; =20 rcu_read_lock(); pd =3D rcu_dereference(rd->pd); @@ -8409,19 +8443,19 @@ static int find_energy_efficient_cpu(struct task_st= ruct *p, int prev_cpu) target =3D prev_cpu; =20 sync_entity_load_avg(&p->se); - if (!task_util_est(p) && p_util_min =3D=3D 0) - goto unlock; - - eenv_task_busy_time(&eenv, p, prev_cpu); + task_util =3D task_busy_time(p, prev_cpu); =20 for (; pd; pd =3D pd->next) { - unsigned long util_min =3D p_util_min, util_max =3D p_util_max; - unsigned long cpu_cap, cpu_actual_cap, util; - long prev_spare_cap =3D -1, max_spare_cap =3D -1; - unsigned long rq_util_min, rq_util_max; - unsigned long cur_delta, base_energy; - int max_spare_cap_cpu =3D -1; - int fits, max_fits =3D -1; + unsigned long pd_actual_util =3D 0, delta_nrg =3D 0; + unsigned long cpu_actual_cap, max_cost =3D 0; + struct energy_cpu_stat target_stat; + struct energy_cpu_stat min_stat =3D { + .cost =3D ULONG_MAX, + .max_perf =3D ULONG_MAX, + .min_perf =3D ULONG_MAX, + .fits =3D -2, + .cpu =3D -1, + }; =20 cpumask_and(cpus, perf_domain_span(pd), cpu_online_mask); =20 @@ -8432,13 +8466,9 @@ static int find_energy_efficient_cpu(struct task_str= uct *p, int prev_cpu) cpu =3D cpumask_first(cpus); cpu_actual_cap =3D get_actual_cpu_capacity(cpu); =20 - eenv.cpu_cap =3D cpu_actual_cap; - eenv.pd_cap =3D 0; - + /* In a PD, the CPU with the lowest cost will be the most efficient */ for_each_cpu(cpu, cpus) { - struct rq *rq =3D cpu_rq(cpu); - - eenv.pd_cap +=3D cpu_actual_cap; + unsigned long target_perf; =20 if (!cpumask_test_cpu(cpu, sched_domain_span(sd))) continue; @@ -8446,120 +8476,116 @@ static int find_energy_efficient_cpu(struct task_= struct *p, int prev_cpu) if (!cpumask_test_cpu(cpu, p->cpus_ptr)) continue; =20 - util =3D cpu_util(cpu, p, cpu, 0); - cpu_cap =3D capacity_of(cpu); + target_stat.fits =3D check_cpu_with_task(p, cpu); + + if (!target_stat.fits) + continue; + + /* 1st select the CPU that fits best */ + if (target_stat.fits < min_stat.fits) + continue; + + /* Then select the CPU with lowest cost */ + + /* Get the performance of the CPU w/ the waking task */ + target_perf =3D find_cpu_max_util(cpu, p, cpu); + target_perf =3D min(target_perf, cpu_actual_cap); + + /* Needing a higher OPP means a higher cost */ + if (target_perf > min_stat.max_perf) + continue; =20 /* - * Skip CPUs that cannot satisfy the capacity request. - * IOW, placing the task there would make the CPU - * overutilized. Take uclamp into account to see how - * much capacity we can get out of the CPU; this is - * aligned with sched_cpu_util(). + * At this point, target's cost can be either equal or + * lower than the current minimum cost. */ - if (uclamp_is_used() && !uclamp_rq_is_idle(rq)) { - /* - * Open code uclamp_rq_util_with() except for - * the clamp() part. I.e.: apply max aggregation - * only. util_fits_cpu() logic requires to - * operate on non clamped util but must use the - * max-aggregated uclamp_{min, max}. - */ - rq_util_min =3D uclamp_rq_get(rq, UCLAMP_MIN); - rq_util_max =3D uclamp_rq_get(rq, UCLAMP_MAX); =20 - util_min =3D max(rq_util_min, p_util_min); - util_max =3D max(rq_util_max, p_util_max); - } + /* Gather more statistics */ + target_stat.cpu =3D cpu; + target_stat.runnable =3D cpu_runnable(cpu_rq(cpu)); + target_stat.capa =3D capacity_of(cpu); + target_stat.nr_running =3D cpu_rq(cpu)->cfs.h_nr_runnable; =20 - fits =3D util_fits_cpu(util, util_min, util_max, cpu); - if (!fits) + /* If the target needs a lower OPP, then look up for + * the corresponding OPP and its associated cost. + * Otherwise at same cost level, select the CPU which + * provides best performance. + */ + if (target_perf < min_stat.min_perf) + find_pd_cost(pd->em_pd, target_perf, &target_stat); + else if (!update_best_cpu(&target_stat, &min_stat, prev_cpu, sd)) continue; =20 - lsub_positive(&cpu_cap, util); - - if (cpu =3D=3D prev_cpu) { - /* Always use prev_cpu as a candidate. */ - prev_spare_cap =3D cpu_cap; - prev_fits =3D fits; - } else if ((fits > max_fits) || - ((fits =3D=3D max_fits) && ((long)cpu_cap > max_spare_cap))) { - /* - * Find the CPU with the maximum spare capacity - * among the remaining CPUs in the performance - * domain. - */ - max_spare_cap =3D cpu_cap; - max_spare_cap_cpu =3D cpu; - max_fits =3D fits; - } + /* Save the new most efficient CPU of the PD */ + min_stat =3D target_stat; } =20 - if (max_spare_cap_cpu < 0 && prev_spare_cap < 0) + if (min_stat.cpu =3D=3D -1) continue; =20 - eenv_pd_busy_time(&eenv, cpus, p); - /* Compute the 'base' energy of the pd, without @p */ - base_energy =3D compute_energy(&eenv, pd, cpus, p, -1); + if (min_stat.fits < best_fits) + continue; =20 - /* Evaluate the energy impact of using prev_cpu. */ - if (prev_spare_cap > -1) { - prev_delta =3D compute_energy(&eenv, pd, cpus, p, - prev_cpu); - /* CPU utilization has changed */ - if (prev_delta < base_energy) - goto unlock; - prev_delta -=3D base_energy; - prev_actual_cap =3D cpu_actual_cap; - best_delta =3D min(best_delta, prev_delta); - } + /* Idle system costs nothing */ + target_stat.max_perf =3D 0; + target_stat.cost =3D 0; =20 - /* Evaluate the energy impact of using max_spare_cap_cpu. */ - if (max_spare_cap_cpu >=3D 0 && max_spare_cap > prev_spare_cap) { - /* Current best energy cpu fits better */ - if (max_fits < best_fits) - continue; + /* Estimate utilization and cost without p */ + for_each_cpu(cpu, cpus) { + unsigned long target_util; =20 - /* - * Both don't fit performance hint (i.e. uclamp_min) - * but best energy cpu has better capacity. - */ - if ((max_fits < 0) && - (cpu_actual_cap <=3D best_actual_cap)) - continue; + /* Accumulate actual utilization w/o task p */ + pd_actual_util +=3D find_cpu_actual_util(cpu, p); =20 - cur_delta =3D compute_energy(&eenv, pd, cpus, p, - max_spare_cap_cpu); - /* CPU utilization has changed */ - if (cur_delta < base_energy) - goto unlock; - cur_delta -=3D base_energy; + /* Get the max utilization of the CPU w/o task p */ + target_util =3D find_cpu_max_util(cpu, p, -1); + target_util =3D min(target_util, cpu_actual_cap); =20 - /* - * Both fit for the task but best energy cpu has lower - * energy impact. - */ - if ((max_fits > 0) && (best_fits > 0) && - (cur_delta >=3D best_delta)) + /* Current OPP is enough */ + if (target_util <=3D target_stat.max_perf) continue; =20 - best_delta =3D cur_delta; - best_energy_cpu =3D max_spare_cap_cpu; - best_fits =3D max_fits; - best_actual_cap =3D cpu_actual_cap; + /* Compute and save the cost of the OPP */ + find_pd_cost(pd->em_pd, target_util, &target_stat); + max_cost =3D target_stat.cost; } - } - rcu_read_unlock(); =20 - if ((best_fits > prev_fits) || - ((best_fits > 0) && (best_delta < prev_delta)) || - ((best_fits < 0) && (best_actual_cap > prev_actual_cap))) - target =3D best_energy_cpu; + /* Add the energy cost of p */ + delta_nrg =3D task_util * min_stat.cost; =20 - return target; + /* + * Compute the energy cost of others running at higher OPP + * because of p. + */ + if (min_stat.cost > max_cost) + delta_nrg +=3D pd_actual_util * (min_stat.cost - max_cost); + + /* Delta energy with p */ + trace_sched_compute_energy_tp(p, min_stat.cpu, delta_nrg, + min_stat.max_perf, pd_actual_util + task_util); + + /* + * The probability that delta energies are equals is almost + * null. PDs being sorted by max capacity, keep the one with + * highest max capacity if this happens. + * TODO: add a margin in energy cost and take into account + * other stats. + */ + if ((min_stat.fits =3D=3D best_fits) && + (delta_nrg >=3D best_nrg)) + continue; + + best_fits =3D min_stat.fits; + best_nrg =3D delta_nrg; + best_cpu =3D min_stat.cpu; + } =20 unlock: rcu_read_unlock(); =20 + if (best_cpu >=3D 0) + target =3D best_cpu; + return target; } =20 --=20 2.43.0 From nobody Mon Feb 9 06:50:28 2026 Received: from mail-wm1-f50.google.com (mail-wm1-f50.google.com [209.85.128.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A30C26E65D for ; Fri, 28 Feb 2025 13:40:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740750014; cv=none; b=bikBARZ0jHHM31r21sR8uEYdiLr8H20UsscfMTR02whG0t9ly+a5rfJSGeoEeUqogDPKAl1MjD36qXPIKbDPDxDY3BqKieRJ4zOv0elYERDAVoUzheHRi3mAl0gNKCmrtS434s+/QYdo6xXEiA/MxwzCM4kqPKUsdIxtcvc9eEA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740750014; c=relaxed/simple; bh=Xmva/6LU+q5ofCXOu82pO85MaWOQLN+nYYMzbRGjP+s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZumqdE8CEnZB2vN6DL1AHEsh9XcBlCa5R1/FCLmIg3jZpIJcFUo8b0Y2CaPXeEHwMCY8ua9UXqWCbY/Vk1Kol4r7IVlCqGWMukknhFqhvgq/eK4DcMSQm1DS2DvHdLBKDx2Byt8UBKwjIwiArgzlRf2Wlk5pEWOY3Az49QWn7Gk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=PqgO/7A0; arc=none smtp.client-ip=209.85.128.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="PqgO/7A0" Received: by mail-wm1-f50.google.com with SMTP id 5b1f17b1804b1-439a4dec9d5so22609015e9.0 for ; Fri, 28 Feb 2025 05:40:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740750009; x=1741354809; darn=vger.kernel.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=LK+rrGR2quDL9JjMcxK/liubM/wUresKs/lEfFGsSzU=; b=PqgO/7A0OHEdRMc5V56lggM8zCs7+HTzKfGQG6bUInUN1SESpyxVWbWtwG+QgXdHGi 8ByfCJuxbiDJm4r/1AIUHwfnTnRyG/upOwss2z43jYy61bXM5Xj03cNa0t1+xIDTVsIu HZ1sr2GSrF0ZzkHn/1dPB0g0FT2r7m90s5zECYgnWcObCjNRwTmi0B440L8+SBtsVfSP PZpQAhUv+ladDUU0cp2ojN16cO3CNDN3kFY1xUMRb2GbLe7Vz5647mz1/w5PloV2hw/w kzGi/jNFKF7mYNb9jajorL5k119yl11z2qG7fPqL01LLVKe9fBsy9dhtLlD4aS7M5ZDm 45kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740750009; x=1741354809; 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=LK+rrGR2quDL9JjMcxK/liubM/wUresKs/lEfFGsSzU=; b=vdmXwXuD9+OTdVy9WTr/UUEZijqiGfw/NHfej97p2la+MxnJI4O1jZ+bYfa3YHCBeS hHFw0DO4RJFe/vQBI2nmwVQF/H4K01nFV/oFWX1Qf8vGtO13VTRU7lwoQr+84M+YDfnl 0RfyD2qhsK39Oevx9dcXEF69gZuCxOOGs2nR25IZur0No7rv3p55w//2dAab/xlPNubK +ouK3rjTyNZkq5/1qsOogKCDpdnB1IswLS2dRc0CKFFkG0WdL0azlKBMGabhLEPVV3Nz YzNfQW4sjFrpn2JJaXH2lfXpA44lSAwdeSz4OrhQgXXeUFaB8eBDnRNxTW9C+BleTfmE nEnA== X-Forwarded-Encrypted: i=1; AJvYcCXN8td67VJhwXAp275+4Sk1sOJfCOcs2A8C+XdSYPv5ZWioTVxDIwiq+zxdhkOA4DOZrMCTGRxiDIyRb/o=@vger.kernel.org X-Gm-Message-State: AOJu0Yx+lLNxDiVGN6hmY+ZzrNUYF7d89LXXeiBdbcCbFYtYfTSg7i2F rOCsigC4qA7ao6tWUJQAWrOJ7eCzOaLWQ5EdXM4JT2DMeCU//dkNcOeaR9Hogic= X-Gm-Gg: ASbGncslzkUa8gtoZVKokWU7m1ppU/5vUn798upVcA5JQjjJsSgkN9oC7v2IfaZt7p1 aZG/G4WgzBcJ98kImCydR6DJkj4TlcQEp9cW4LJi5uD29+BDruR6TQwtp/W9LXWmbWz6LLhISAt iw73N+fHdcrq5KdNO4UfR0IJYvUEZkLXtNesjpFXzoDKbaQ4daMsaVSCh8ijtUB9ulGLroANARK b1fCPPD9ZQOYoMjE/DEPc5H10J1Vq1FNRnhlrE2MbKMUaB6PdAPCPfA8rUzIDh/n4MkHtDi5q3o br8aZ/FOkECH3RLJUqKwfiU4atbG0oAq2A== X-Google-Smtp-Source: AGHT+IEnyzbCtUoYq8vfwx1B7Ej0lohDGCadUrYOnbl2iji40RWMxmCmoEcu4DiYubtSr7yGOHsTCg== X-Received: by 2002:a05:600c:46d1:b0:439:8544:1903 with SMTP id 5b1f17b1804b1-43ba674c80fmr32058565e9.20.1740750009474; Fri, 28 Feb 2025 05:40:09 -0800 (PST) Received: from vingu-cube.. ([2a01:e0a:f:6020:d4b:473f:a962:e9e2]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43b73717171sm55984405e9.18.2025.02.28.05.40.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Feb 2025 05:40:08 -0800 (PST) From: Vincent Guittot To: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com, lukasz.luba@arm.com, rafael.j.wysocki@intel.com, pierre.gondois@arm.com, linux-kernel@vger.kernel.org Cc: qyousef@layalina.io, hongyan.xia2@arm.com, christian.loehle@arm.com, luis.machado@arm.com, qperret@google.com, Vincent Guittot Subject: [PATCH 4/7 v3] energy model: Remove unused em_cpu_energy() Date: Fri, 28 Feb 2025 14:39:57 +0100 Message-ID: <20250228134000.1226665-5-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250228134000.1226665-1-vincent.guittot@linaro.org> References: <20250228134000.1226665-1-vincent.guittot@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Remove the unused function em_cpu_energy() Signed-off-by: Vincent Guittot --- include/linux/energy_model.h | 99 ------------------------------------ 1 file changed, 99 deletions(-) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index 967650726619..441100686f1b 100644 --- a/include/linux/energy_model.h +++ b/include/linux/energy_model.h @@ -236,99 +236,6 @@ em_pd_get_previous_state(struct em_perf_state *table, return -1; } =20 -/** - * em_cpu_energy() - Estimates the energy consumed by the CPUs of a - * performance domain - * @pd : performance domain for which energy has to be estimated - * @max_util : highest utilization among CPUs of the domain - * @sum_util : sum of the utilization of all CPUs in the domain - * @allowed_cpu_cap : maximum allowed CPU capacity for the @pd, which - * might reflect reduced frequency (due to thermal) - * - * This function must be used only for CPU devices. There is no validation, - * i.e. if the EM is a CPU type and has cpumask allocated. It is called fr= om - * the scheduler code quite frequently and that is why there is not checks. - * - * Return: the sum of the energy consumed by the CPUs of the domain assumi= ng - * a capacity state satisfying the max utilization of the domain. - */ -static inline unsigned long em_cpu_energy(struct em_perf_domain *pd, - unsigned long max_util, unsigned long sum_util, - unsigned long allowed_cpu_cap) -{ - struct em_perf_table *em_table; - struct em_perf_state *ps; - int i; - -#ifdef CONFIG_SCHED_DEBUG - WARN_ONCE(!rcu_read_lock_held(), "EM: rcu read lock needed\n"); -#endif - - if (!sum_util) - return 0; - - /* - * In order to predict the performance state, map the utilization of - * the most utilized CPU of the performance domain to a requested - * performance, like schedutil. Take also into account that the real - * performance might be set lower (due to thermal capping). Thus, clamp - * max utilization to the allowed CPU capacity before calculating - * effective performance. - */ - max_util =3D min(max_util, allowed_cpu_cap); - - /* - * Find the lowest performance state of the Energy Model above the - * requested performance. - */ - em_table =3D rcu_dereference(pd->em_table); - i =3D em_pd_get_efficient_state(em_table->state, pd, max_util); - ps =3D &em_table->state[i]; - - /* - * The performance (capacity) of a CPU in the domain at the performance - * state (ps) can be computed as: - * - * ps->freq * scale_cpu - * ps->performance =3D -------------------- (1) - * cpu_max_freq - * - * So, ignoring the costs of idle states (which are not available in - * the EM), the energy consumed by this CPU at that performance state - * is estimated as: - * - * ps->power * cpu_util - * cpu_nrg =3D -------------------- (2) - * ps->performance - * - * since 'cpu_util / ps->performance' represents its percentage of busy - * time. - * - * NOTE: Although the result of this computation actually is in - * units of power, it can be manipulated as an energy value - * over a scheduling period, since it is assumed to be - * constant during that interval. - * - * By injecting (1) in (2), 'cpu_nrg' can be re-expressed as a product - * of two terms: - * - * ps->power * cpu_max_freq - * cpu_nrg =3D ------------------------ * cpu_util (3) - * ps->freq * scale_cpu - * - * The first term is static, and is stored in the em_perf_state struct - * as 'ps->cost'. - * - * Since all CPUs of the domain have the same micro-architecture, they - * share the same 'ps->cost', and the same CPU capacity. Hence, the - * total energy of the domain (which is the simple sum of the energy of - * all of its CPUs) can be factorized as: - * - * pd_nrg =3D ps->cost * \Sum cpu_util (4) - */ - return ps->cost * sum_util; -} - /** * em_pd_nr_perf_states() - Get the number of performance states of a perf. * domain @@ -395,12 +302,6 @@ em_pd_get_previous_state(struct em_perf_state *table, = int nr_perf_states, { return -1; } -static inline unsigned long em_cpu_energy(struct em_perf_domain *pd, - unsigned long max_util, unsigned long sum_util, - unsigned long allowed_cpu_cap) -{ - return 0; -} static inline int em_pd_nr_perf_states(struct em_perf_domain *pd) { return 0; --=20 2.43.0 From nobody Mon Feb 9 06:50:28 2026 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F0A4C26E943 for ; Fri, 28 Feb 2025 13:40:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740750015; cv=none; b=lZOQOckGS9Qd8x8cVKogMGqfMMPSsdOXvtCnB8jxX8AxXzd5bYqXsuwm2hX0U406f1rqzOl5+gWci2LoNeIJWaaQjMFAB5joZhFOOvlNe4ygVstfuCXsae+1NOfiZ/CdofPgDm7T+6P+mpKya+Ucd/h5FRJhXn8SktHNHIV8yo4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740750015; c=relaxed/simple; bh=umTYL4W4cZfX8t+2Ez2iNTlcHSIIHsZqYG0LouysSLg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DL3V70Hqp4wu7AvPOi+Jf0lo64x4bi2ZahldiwZLQwgv1/wazIweS5jqPbLbNdeoiyX558nzNHz78Hk8f50AxvVBt0Kl/yoVNc0AnEK6vU/TJi0jZ3UED3KyrGH890P+DkQAj9BMQsJTidE+gsZ+F3oz3K5hH2hHp7hRPxcbuDw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=FcdYlGFz; arc=none smtp.client-ip=209.85.128.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="FcdYlGFz" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-438a39e659cso14952745e9.2 for ; Fri, 28 Feb 2025 05:40:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740750011; x=1741354811; darn=vger.kernel.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=Cc2Ypfc/Sz6V0BRbe/jsN+wH2zlV5O0h6oEq0/eF1gI=; b=FcdYlGFz7uGPzsHEOw111gdxSSTvNMX/gv7efBe9Sm6hDha8HsxIlvhPRevqGA3XDz fa9152TTMrT3JLn3sJ5RWpFp0mUn0JxQV1QssPee0UJwDtEH2C4aeV8zd3/+kd+vER0u c2aOPYhWa4jvVTojRxFa+ri3BOuG0sVq64T04imCLDutBxEaPwkLEk0zIk0C3gCHoXHq 99kB3vMR6jbVlb11h5CwQYsR14ZshX6+UixGWXtztfk5tSwtgeHlE/pTBj2wDk2P7T1f JI/KKPOCr6kg5feBZca1jmMu04G5TWsxnZcz6tbpXCAau57G078xH6nYjcLPaJRQQSMS XArA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740750011; x=1741354811; 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=Cc2Ypfc/Sz6V0BRbe/jsN+wH2zlV5O0h6oEq0/eF1gI=; b=nhuy+YTTbSUn8F1VBG3BnXM1IaZsu7KElQCarYYNto1QAEHeU0pxdRaf+r4yEyngYS xkIUZx/pZ2ArTj1ccHi2D/cqy1gaOOpfzNeRoaBCBHSfAk0IwwpWPq9GnfIzgSXzstIH K0nWteLdZI9/Ckp6wCTw/LSFBLHGVNSTqYQtPgz6jdnROUulG/PVG8MqMPQ37062va4l nN+DlBr1lwjXMsd0zHqTA+7mARc6KJgm1Vavg3220oJya0lKSELJKRex5NopxcblCeFx PNjQf1eucY6tdg1BRre7jveKInEYssj/dYSiDBYXNjFmK34vYIp+Rx6giRpWXVV64DLS W86Q== X-Forwarded-Encrypted: i=1; AJvYcCW5ZQTGT8X3tz+KHRzRuCw8NWX1RBkp9vlg0ksbf2xwz+pYEeeP2mh6MDnTNmMPGHWqm26Gh+fjma+dUm4=@vger.kernel.org X-Gm-Message-State: AOJu0YwwcyccfkfcIzM22kk8kdE9aMpY2/KTfjKoHS3OEtjRLTaECmWE cZo/geMMyEPm9i9NTpsf+kMZkxSvnT+DqwuV7r59TwZWRpqtuqbwX7Vid5jNOFY= X-Gm-Gg: ASbGncvenfZrCwxtyhkpy1oQjB+deIaPl+XNJYMf7xQ2YFzFtIUEuZtrXCh3fygWoQb nkubLd7XP6WHoFqkGAaJrlWEFOxi/dP8tCym9rCuM5Tg8k1meb457J9Gmwa2OslQxMSvACGa+Z8 p8H8hLNz+euICA34PZWegaYvsB7siW9VpYlDx1p+l6U+zdAvJVe6pOon4gYoQwEe8McKsdlDozr uVM+N3TxdPQHmauDvkfWh3drhKCa9+tXJ2u6ElltQspWCf1dm+dmCZn2jZCZYjeACvEaPB4kJFC A+5DUsxgRfkotBnamlrNnCqA02WGMAN7Kw== X-Google-Smtp-Source: AGHT+IF5hzRzB2yZTJaK7tWdJmZgcje2G1GYUnb6JB6jKU6HofKVIN4Kx0JghlmUytM7sq/VR2IF0A== X-Received: by 2002:a05:600c:3507:b0:439:884c:96ae with SMTP id 5b1f17b1804b1-43ba6774658mr25872755e9.27.1740750011038; Fri, 28 Feb 2025 05:40:11 -0800 (PST) Received: from vingu-cube.. ([2a01:e0a:f:6020:d4b:473f:a962:e9e2]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43b73717171sm55984405e9.18.2025.02.28.05.40.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Feb 2025 05:40:09 -0800 (PST) From: Vincent Guittot To: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com, lukasz.luba@arm.com, rafael.j.wysocki@intel.com, pierre.gondois@arm.com, linux-kernel@vger.kernel.org Cc: qyousef@layalina.io, hongyan.xia2@arm.com, christian.loehle@arm.com, luis.machado@arm.com, qperret@google.com, Vincent Guittot Subject: [PATCH 5/7 v3] sched/fair: Add push task mechanism for EAS Date: Fri, 28 Feb 2025 14:39:58 +0100 Message-ID: <20250228134000.1226665-6-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250228134000.1226665-1-vincent.guittot@linaro.org> References: <20250228134000.1226665-1-vincent.guittot@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" EAS is based on wakeup events to efficiently place tasks on the system, but there are cases where a task doesn't have wakeup events anymore or at a far too low pace. For such situation, we can take advantage of the task being put back in the enqueued list to check if it should be pushed on another CPU. When the task is alone on the CPU, it's never put back in the enqueued list; In this special case, we use the tick to run the check. Wake up events remain the main way to migrate tasks but we now detect situation where a task is stuck on a CPU by checking that its utilization is larger than the max available compute capacity (max cpu capacity or uclamp max setting) Signed-off-by: Vincent Guittot --- kernel/sched/fair.c | 220 +++++++++++++++++++++++++++++++++++++++++++ kernel/sched/sched.h | 2 + 2 files changed, 222 insertions(+) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index a9b97bbc085f..5b2f88dec70e 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -7051,6 +7051,7 @@ enqueue_task_fair(struct rq *rq, struct task_struct *= p, int flags) hrtick_update(rq); } =20 +static void fair_remove_pushable_task(struct rq *rq, struct task_struct *p= ); static void set_next_buddy(struct sched_entity *se); =20 /* @@ -7081,6 +7082,8 @@ static int dequeue_entities(struct rq *rq, struct sch= ed_entity *se, int flags) h_nr_idle =3D task_has_idle_policy(p); if (task_sleep || task_delayed || !se->sched_delayed) h_nr_runnable =3D 1; + + fair_remove_pushable_task(rq, p); } else { cfs_rq =3D group_cfs_rq(se); slice =3D cfs_rq_min_slice(cfs_rq); @@ -8589,6 +8592,197 @@ static int find_energy_efficient_cpu(struct task_st= ruct *p, int prev_cpu) return target; } =20 +static inline bool task_stuck_on_cpu(struct task_struct *p, int cpu) +{ + unsigned long max_capa, util; + + max_capa =3D min(get_actual_cpu_capacity(cpu), + uclamp_eff_value(p, UCLAMP_MAX)); + util =3D max(task_util_est(p), task_runnable(p)); + + /* + * Return true only if the task might not sleep/wakeup because of a low + * compute capacity. Tasks, which wake up regularly, will be handled by + * feec(). + */ + return (util > max_capa); +} + +static inline bool sched_energy_push_task(struct task_struct *p, struct rq= *rq) +{ + if (p->nr_cpus_allowed =3D=3D 1) + return false; + + if (is_rd_overutilized(rq->rd)) + return false; + + if (task_stuck_on_cpu(p, cpu_of(rq))) + return true; + + return false; +} + +static int active_load_balance_cpu_stop(void *data); + +static inline void check_pushable_task(struct task_struct *p, struct rq *r= q) +{ + int new_cpu, cpu =3D cpu_of(rq); + + if (!sched_energy_enabled()) + return; + + if (WARN_ON(!p)) + return; + + if (WARN_ON(!task_current(rq, p))) + return; + + if (is_migration_disabled(p)) + return; + + /* If there are several task, wait for being put back */ + if (rq->nr_running > 1) + return; + + if (!sched_energy_push_task(p, rq)) + return; + + new_cpu =3D find_energy_efficient_cpu(p, cpu); + + if (new_cpu =3D=3D cpu) + return; + + /* + * ->active_balance synchronizes accesses to + * ->active_balance_work. Once set, it's cleared + * only after active load balance is finished. + */ + if (!rq->active_balance) { + rq->active_balance =3D 1; + rq->push_cpu =3D new_cpu; + } else + return; + + raw_spin_rq_unlock(rq); + stop_one_cpu_nowait(cpu, + active_load_balance_cpu_stop, rq, + &rq->active_balance_work); + raw_spin_rq_lock(rq); +} + +static inline int has_pushable_tasks(struct rq *rq) +{ + return !plist_head_empty(&rq->cfs.pushable_tasks); +} + +static struct task_struct *pick_next_pushable_fair_task(struct rq *rq) +{ + struct task_struct *p; + + if (!has_pushable_tasks(rq)) + return NULL; + + p =3D plist_first_entry(&rq->cfs.pushable_tasks, + struct task_struct, pushable_tasks); + + WARN_ON_ONCE(rq->cpu !=3D task_cpu(p)); + WARN_ON_ONCE(task_current(rq, p)); + WARN_ON_ONCE(p->nr_cpus_allowed <=3D 1); + WARN_ON_ONCE(!task_on_rq_queued(p)); + + /* + * Remove task from the pushable list as we try only once after that + * the task has been put back in enqueued list. + */ + plist_del(&p->pushable_tasks, &rq->cfs.pushable_tasks); + + return p; +} + +/* + * See if the non running fair tasks on this rq can be sent on other CPUs + * that fits better with their profile. + */ +static bool push_fair_task(struct rq *rq) +{ + struct task_struct *next_task; + int prev_cpu, new_cpu; + struct rq *new_rq; + + next_task =3D pick_next_pushable_fair_task(rq); + if (!next_task) + return false; + + if (is_migration_disabled(next_task)) + return true; + + /* We might release rq lock */ + get_task_struct(next_task); + + prev_cpu =3D rq->cpu; + + new_cpu =3D find_energy_efficient_cpu(next_task, prev_cpu); + + if (new_cpu =3D=3D prev_cpu) + goto out; + + new_rq =3D cpu_rq(new_cpu); + + if (double_lock_balance(rq, new_rq)) { + /* The task has already migrated in between */ + if (task_cpu(next_task) !=3D rq->cpu) { + double_unlock_balance(rq, new_rq); + goto out; + } + + deactivate_task(rq, next_task, 0); + set_task_cpu(next_task, new_cpu); + activate_task(new_rq, next_task, 0); + + resched_curr(new_rq); + + double_unlock_balance(rq, new_rq); + } + +out: + put_task_struct(next_task); + + return true; +} + +static void push_fair_tasks(struct rq *rq) +{ + /* push_fair_task() will return true if it moved a fair task */ + while (push_fair_task(rq)) + ; +} + +static DEFINE_PER_CPU(struct balance_callback, fair_push_head); + +static inline void fair_queue_pushable_tasks(struct rq *rq) +{ + if (!sched_energy_enabled() || !has_pushable_tasks(rq)) + return; + + queue_balance_callback(rq, &per_cpu(fair_push_head, rq->cpu), push_fair_t= asks); +} +static void fair_remove_pushable_task(struct rq *rq, struct task_struct *p) +{ + if (sched_energy_enabled()) + plist_del(&p->pushable_tasks, &rq->cfs.pushable_tasks); +} + +static void fair_add_pushable_task(struct rq *rq, struct task_struct *p) +{ + if (sched_energy_enabled() && task_on_rq_queued(p) && !p->se.sched_delaye= d) { + if (sched_energy_push_task(p, rq)) { + plist_del(&p->pushable_tasks, &rq->cfs.pushable_tasks); + plist_node_init(&p->pushable_tasks, p->prio); + plist_add(&p->pushable_tasks, &rq->cfs.pushable_tasks); + } + } +} + /* * select_task_rq_fair: Select target runqueue for the waking task in doma= ins * that have the relevant SD flag set. In practice, this is SD_BALANCE_WAK= E, @@ -8758,6 +8952,10 @@ balance_fair(struct rq *rq, struct task_struct *prev= , struct rq_flags *rf) return sched_balance_newidle(rq, rf) !=3D 0; } #else +static inline void check_pushable_task(struct task_struct *p, struct rq *r= q) {} +static inline void fair_queue_pushable_tasks(struct rq *rq) {} +static void fair_remove_pushable_task(struct cfs_rq *cfs_rq, struct task_s= truct *p) {} +static inline void fair_add_pushable_task(struct cfs_rq *cfs_rq, struct ta= sk_struct *p) {} static inline void set_task_max_allowed_capacity(struct task_struct *p) {} #endif /* CONFIG_SMP */ =20 @@ -8947,6 +9145,12 @@ pick_next_task_fair(struct rq *rq, struct task_struc= t *prev, struct rq_flags *rf put_prev_entity(cfs_rq, pse); set_next_entity(cfs_rq, se); =20 + /* + * The previous task might be eligible for being pushed on + * another cpu if it is still active. + */ + fair_add_pushable_task(rq, prev); + __set_next_task_fair(rq, p, true); } =20 @@ -9019,6 +9223,13 @@ static void put_prev_task_fair(struct rq *rq, struct= task_struct *prev, struct t cfs_rq =3D cfs_rq_of(se); put_prev_entity(cfs_rq, se); } + + /* + * The previous task might be eligible for being pushed on another cpu + * if it is still active. + */ + fair_add_pushable_task(rq, prev); + } =20 /* @@ -13151,6 +13362,7 @@ static void task_tick_fair(struct rq *rq, struct ta= sk_struct *curr, int queued) if (static_branch_unlikely(&sched_numa_balancing)) task_tick_numa(rq, curr); =20 + check_pushable_task(curr, rq); update_misfit_status(curr, rq); check_update_overutilized_status(task_rq(curr)); =20 @@ -13303,6 +13515,8 @@ static void __set_next_task_fair(struct rq *rq, str= uct task_struct *p, bool firs { struct sched_entity *se =3D &p->se; =20 + fair_remove_pushable_task(rq, p); + #ifdef CONFIG_SMP if (task_on_rq_queued(p)) { /* @@ -13320,6 +13534,11 @@ static void __set_next_task_fair(struct rq *rq, st= ruct task_struct *p, bool firs if (hrtick_enabled_fair(rq)) hrtick_start_fair(rq, p); =20 + /* + * Try to push prev task before checking misfit for next task as + * the migration of prev can make next fitting the CPU + */ + fair_queue_pushable_tasks(rq); update_misfit_status(p, rq); sched_fair_update_stop_tick(rq, p); } @@ -13350,6 +13569,7 @@ void init_cfs_rq(struct cfs_rq *cfs_rq) cfs_rq->tasks_timeline =3D RB_ROOT_CACHED; cfs_rq->min_vruntime =3D (u64)(-(1LL << 20)); #ifdef CONFIG_SMP + plist_head_init(&cfs_rq->pushable_tasks); raw_spin_lock_init(&cfs_rq->removed.lock); #endif } diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h index ab16d3d0e51c..2db198dccf21 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -722,6 +722,8 @@ struct cfs_rq { struct list_head leaf_cfs_rq_list; struct task_group *tg; /* group that "owns" this runqueue */ =20 + struct plist_head pushable_tasks; + /* Locally cached copy of our task_group's idle value */ int idle; =20 --=20 2.43.0 From nobody Mon Feb 9 06:50:28 2026 Received: from mail-wm1-f54.google.com (mail-wm1-f54.google.com [209.85.128.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E1E0726D5BF for ; Fri, 28 Feb 2025 13:40:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740750018; cv=none; b=OovMLdeihNwRp6Y3glxH71lSurMNfqHjPA3ftioSW7DR/1SAQ83RBRe/9QLRPH2hrDFFdcaHCvlXCLrhZyAO62/fQ79ZLlQxwNkp6Dwo+8fM2M3uINSt6LqdrPt+2uG2dpk0Kad4Wg7gAsbGjANWBp74VlXklbjljE5egI6Lamo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740750018; c=relaxed/simple; bh=8PzAsPt7+hK+rtjikvk7exCgte/EY5wdhrXBAOoMwLk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sVmx6SRjVaYLt7aKqsg+ewbx2WOyzm5B+IjVrJUJIIXGnEvZ7wcJi9wx+XXROEP7nkEFixhOnJpe3gv1C2nGVt+1k4yorKxeuXgqR6ZEheSOC1nYlH7DZM45x47n0w9KKIznNTncccTpAMvvAjsYljZM4uGXI1aQLYiJlbmXg9U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=aVhodTFF; arc=none smtp.client-ip=209.85.128.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="aVhodTFF" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-4398738217aso19030155e9.3 for ; Fri, 28 Feb 2025 05:40:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740750013; x=1741354813; darn=vger.kernel.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=vn4DL6lNoF03xrDB47bBVdVlyRNbpJRyEArZG5HgRw4=; b=aVhodTFFfKyxAH0B76NLLhO9bv2nALq2h9NCzN5FQKXr7I6M1PFhC7d9w/TDqN9Roh 4uV976Tb/P2qcc4QRf/MrJMNdYCxGZpx127VdShZ6+zKFmu8Vs2fn8z+jJW+ULniku+i E/Qtt8p/pZP2k5oAZuNzKARQI2tzdA1AASj1Y/6JqzgJvSt87cdKXGXOLJUxB58JCj3h EGYh6ajmu1VmU99D3dSBOtOLprQZbX6VfWC6/sd+a3ew0varYEaqs9KEvezcOPsFIj9m 6YHpD8RS189f5vrqzo/SKzeivLQ3350kgqulTH+Z96M9qVUkSWiCT4ZcEgs6Ndwcmf/8 DFAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740750013; x=1741354813; 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=vn4DL6lNoF03xrDB47bBVdVlyRNbpJRyEArZG5HgRw4=; b=pBOBogb1B793WxZpOJWWIdcZwl+l7jd2ApNtbfDFJ0me1a+iYQbgSPlUDuIxijwIDI vx3zFqdtlvVgAU+v7NbKnKWanzOU0ebOSuTScVI6e3JdL0874QyleoY5gdV1qWdhkrZN 0pGd88I7/H9oGzaMloAAQQFiYVF9sF6RnujWtLsNSmarr5dH5SvTsfDmzY71XdKJ9Uh7 iOpD3guoRkSrYWw/dDVKjRSoIsTktcXDt7yagAulpKS0PzGMI/uNsksxfHja38ZVyASF ItmUZlQxJmsvVfd1+EjCQzfHAMNNRJZl1N06v7P8DP9b0Uq7OoH5fu/TZgS8kapIQI7J gbhQ== X-Forwarded-Encrypted: i=1; AJvYcCX+LZBviaJYf7NFVbKwEhXFGV9A+rpE/ZOhq/anIIpIqOF/hIqX6eCFsKreNv9U5mKVVJXGfJsmrB3ZWTs=@vger.kernel.org X-Gm-Message-State: AOJu0Yy4XFbFPYYd7zXQyi/ZooUp1DyDKtwLT3SxPNPstRO1tFrYyBnG ysXV3l26PqylxlWqysQPK/XJA+g0vRtq/jMedANXOsIWY9wL+8Mzk1Xt11NyEy8= X-Gm-Gg: ASbGncuZ744rgmr2NhqTKyC3tvUQuCYgOPgfrF2lktqKnlrQQyXfC8X0NwuMtZ3yJx4 1KMxz//dDD3Zr8L6mg7RXmpsN1plp1SgSE+c3kYfNDa422Uc5xFH9rTR10PA/WYSYGHq9eFbLdb 4ayAmPzYTY1sVFfR/9GXmlxfqYOReqLpR10ufsZXIQMddSy2ppNM9SIX8BVhIuFAf1Sfuvx+xc4 ekmer4gCRY9egFxwSaox7nmof50IOzk8tW4g2gMNtEUkospEZMekk+AzksQrkdRVN5/CurZHomg jM3GJvZpDKA7+EDMFwOt7ubXYc8OjVnD6Q== X-Google-Smtp-Source: AGHT+IGRXwA8HxsfM6ZV66UcJ4rVlcju9x0PNpHLiYU1/3zMhmGNGexVhvIGBVxWuDwJy/w+JKRohw== X-Received: by 2002:a05:600c:a03:b0:439:6712:643d with SMTP id 5b1f17b1804b1-43ba66df7d6mr28639075e9.9.1740750013143; Fri, 28 Feb 2025 05:40:13 -0800 (PST) Received: from vingu-cube.. ([2a01:e0a:f:6020:d4b:473f:a962:e9e2]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43b73717171sm55984405e9.18.2025.02.28.05.40.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Feb 2025 05:40:11 -0800 (PST) From: Vincent Guittot To: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com, lukasz.luba@arm.com, rafael.j.wysocki@intel.com, pierre.gondois@arm.com, linux-kernel@vger.kernel.org Cc: qyousef@layalina.io, hongyan.xia2@arm.com, christian.loehle@arm.com, luis.machado@arm.com, qperret@google.com, Vincent Guittot Subject: [PATCH 6/7 v3] sched/fair: Add misfit case to push task mecanism for EAS Date: Fri, 28 Feb 2025 14:39:59 +0100 Message-ID: <20250228134000.1226665-7-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250228134000.1226665-1-vincent.guittot@linaro.org> References: <20250228134000.1226665-1-vincent.guittot@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Some task misfit cases can be handled directly by the push mecanism instead of triggering an idle load balance to pull the task on a better CPU. Signed-off-by: Vincent Guittot --- kernel/sched/fair.c | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 5b2f88dec70e..87bf054cf36b 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -8508,6 +8508,8 @@ static int find_energy_efficient_cpu(struct task_stru= ct *p, int prev_cpu) target_stat.runnable =3D cpu_runnable(cpu_rq(cpu)); target_stat.capa =3D capacity_of(cpu); target_stat.nr_running =3D cpu_rq(cpu)->cfs.h_nr_runnable; + if ((p->on_rq) && (!p->se.sched_delayed) && (cpu =3D=3D prev_cpu)) + target_stat.nr_running--; =20 /* If the target needs a lower OPP, then look up for * the corresponding OPP and its associated cost. @@ -8613,6 +8615,9 @@ static inline bool sched_energy_push_task(struct task= _struct *p, struct rq *rq) if (p->nr_cpus_allowed =3D=3D 1) return false; =20 + if (!task_fits_cpu(p, cpu_of(rq))) + return true; + if (is_rd_overutilized(rq->rd)) return false; =20 @@ -8624,33 +8629,33 @@ static inline bool sched_energy_push_task(struct ta= sk_struct *p, struct rq *rq) =20 static int active_load_balance_cpu_stop(void *data); =20 -static inline void check_pushable_task(struct task_struct *p, struct rq *r= q) +static inline bool check_pushable_task(struct task_struct *p, struct rq *r= q) { int new_cpu, cpu =3D cpu_of(rq); =20 if (!sched_energy_enabled()) - return; + return false; =20 if (WARN_ON(!p)) - return; + return false; =20 if (WARN_ON(!task_current(rq, p))) - return; + return false; =20 if (is_migration_disabled(p)) - return; + return false; =20 /* If there are several task, wait for being put back */ if (rq->nr_running > 1) - return; + return false; =20 if (!sched_energy_push_task(p, rq)) - return; + return false; =20 new_cpu =3D find_energy_efficient_cpu(p, cpu); =20 if (new_cpu =3D=3D cpu) - return; + return false; =20 /* * ->active_balance synchronizes accesses to @@ -8661,13 +8666,15 @@ static inline void check_pushable_task(struct task_= struct *p, struct rq *rq) rq->active_balance =3D 1; rq->push_cpu =3D new_cpu; } else - return; + return false; =20 raw_spin_rq_unlock(rq); stop_one_cpu_nowait(cpu, active_load_balance_cpu_stop, rq, &rq->active_balance_work); raw_spin_rq_lock(rq); + + return true; } =20 static inline int has_pushable_tasks(struct rq *rq) @@ -8952,7 +8959,7 @@ balance_fair(struct rq *rq, struct task_struct *prev,= struct rq_flags *rf) return sched_balance_newidle(rq, rf) !=3D 0; } #else -static inline void check_pushable_task(struct task_struct *p, struct rq *r= q) {} +static inline bool check_pushable_task(struct task_struct *p, struct rq *r= q) {} static inline void fair_queue_pushable_tasks(struct rq *rq) {} static void fair_remove_pushable_task(struct cfs_rq *cfs_rq, struct task_s= truct *p) {} static inline void fair_add_pushable_task(struct cfs_rq *cfs_rq, struct ta= sk_struct *p) {} @@ -13362,9 +13369,10 @@ static void task_tick_fair(struct rq *rq, struct t= ask_struct *curr, int queued) if (static_branch_unlikely(&sched_numa_balancing)) task_tick_numa(rq, curr); =20 - check_pushable_task(curr, rq); - update_misfit_status(curr, rq); - check_update_overutilized_status(task_rq(curr)); + if (!check_pushable_task(curr, rq)) { + update_misfit_status(curr, rq); + check_update_overutilized_status(task_rq(curr)); + } =20 task_tick_core(rq, curr); } --=20 2.43.0 From nobody Mon Feb 9 06:50:28 2026 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 55AD326FD8A for ; Fri, 28 Feb 2025 13:40:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740750020; cv=none; b=g50wurlbWuPpRwRwp81oa2tsdqBUDJJi5vwsKnHfWSLZiANm11Toi5051UmBJTxyd2lxBlfqmHfEaf0z5JbaizIWR5jku/VN9Ur4AmzEWyh9FMdU5xiD/C/81NNKlYpc3VnLqhEU4nbXIkjZ8Z6R/PX+OMqpPk2kKjjwBv5dRyM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740750020; c=relaxed/simple; bh=nCeGF9ItVUNdwPlWOzTVsny3+ZdTra5J1FFq4P2sUNM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kbvfizU/ptOxPrl6QSdW9c43i9GdvZIwWzZVWTlKkhQPCjnzr990BCsfxmMsK12osxSTYtHhkaIYd0Gn9laTCvlfg53d4ID/ZUiDdq0ji1DodB79Pyx4+sWgVdwG6Nmh/++9CH02+knBq5mPsYyBiAd5cwT8RKsj4DjGpy8uR8k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=nNztYLKH; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="nNztYLKH" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-4398e839cd4so20331375e9.0 for ; Fri, 28 Feb 2025 05:40:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740750015; x=1741354815; darn=vger.kernel.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=rw934CEn6tbK6lv9WMG+8m0C783kJwL1DMa/2ldwyiA=; b=nNztYLKHoSy7aWE6pJoWJdpg0JdZLaFWnMaEC8ls89xjcTS6ZTyRbWoq6SP27SEI4E pIfyLdEFSN1hQVtrMYTeSyQkdzax3FKM4NNDwL8s0xnmqevLcbQRjMCmZRg//3VAy8Ur iepR+BBpcB5rgIgAVhNI7yO66q8dvRodUhQWvsekoHlPTweNEv2xrbF6ysqwwnJACT2M a4in8N1+YWVYb1fESN4KOkTJ0ybIjstlCgpAuDa38NIK7C8UxvBFoE+HzGYpAGNxZNYM PRUQu8tPaPEYshWq9gZFjNKohyBMUjQZja3D5zTZyMGEFNEke7Vm6bW0zzWGiUhGE+xT N5aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740750015; x=1741354815; 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=rw934CEn6tbK6lv9WMG+8m0C783kJwL1DMa/2ldwyiA=; b=aL3cJSqnIhKaxLf3KmmMugGtm+WHdhpGdtYnGaS8nGedeHCf4/ZSVkGIByqeG8XGTt sp59U2Lu4LvCafKVIDo1Zxv1qOf8V9UW+21vNBFlNvQ2h28kQdnUlsetNEozswLk14P7 mqat/dYc5cok3zSeoEpDsTmykJf0zjUiY3SZ6670q3bxo8Yl8wR2tMu4z4q1G4jtxvV0 mYunajtggzpGdzzCMMSDtLTR4yT+e60fVTlbaB/l2W84XXH+H2bNip4yGd6XOw1GD4td 2eoymwjh06D3EmMhohD67mywUfQCF6kysFUVK/BqgyubXUTjBc716tMtevNfBaWn53Xq brzw== X-Forwarded-Encrypted: i=1; AJvYcCV8jmjrmh1EnuMpvr5G4hEiPvEFV+pWVCQI/eslJJjVl4ni3S6Pkppt99oFnxE1GZHk78zd78EmW9FcZFQ=@vger.kernel.org X-Gm-Message-State: AOJu0YxN/DRqPLRzX4BO+XTz47cpO9pdId0e4T+Xd25uRLb0eYzNy414 ynyGa5dFIp5HFxVb9bqfGWsFTLbdkoLR9LeFtZgKpeZXsIsdLR5wm5s0yl0rcAo= X-Gm-Gg: ASbGncv4QIUbw0HzSopN9Z/5oj49jkyZ9zPojjpMHrhZIJIS+EYPF6TVtqxGhPOAmAC bReidWVzuJLxOjBGf63erB8+lQnIPzYuNYB5eZXvLJeijSO2dSkHwcfdugc1+omRwz0dtUQhgV9 TGM6x7XtBgjYXNu0gOVZU0wQQvlVBY8wjdYo0owxLG9sJrRAPH71tHLjRVwxgPbAgw7uPfdD3GG cUwoMVGijM0gpZYctTExfD7H8u6l5FG74EPq3lmhVrHu9P5U4ttj7iL5kuTNyEr+MZ8OnkWvcWv wOEV1glwZl6C8SaKZtjD3CubxmFuXORwHg== X-Google-Smtp-Source: AGHT+IGkdNXJ4tFpT+fJ2vIB2cK3pcIEZUV15iurW0BGYuP7ZBxOP27p3nyFC4feakr1HKn80ekYCg== X-Received: by 2002:a05:600c:4fc2:b0:439:873a:1114 with SMTP id 5b1f17b1804b1-43ba624af40mr27194085e9.6.1740750014610; Fri, 28 Feb 2025 05:40:14 -0800 (PST) Received: from vingu-cube.. ([2a01:e0a:f:6020:d4b:473f:a962:e9e2]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43b73717171sm55984405e9.18.2025.02.28.05.40.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 28 Feb 2025 05:40:13 -0800 (PST) From: Vincent Guittot To: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com, lukasz.luba@arm.com, rafael.j.wysocki@intel.com, pierre.gondois@arm.com, linux-kernel@vger.kernel.org Cc: qyousef@layalina.io, hongyan.xia2@arm.com, christian.loehle@arm.com, luis.machado@arm.com, qperret@google.com, Vincent Guittot Subject: [PATCH 7/7 v3] sched/fair: Update overutilized detection Date: Fri, 28 Feb 2025 14:40:00 +0100 Message-ID: <20250228134000.1226665-8-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250228134000.1226665-1-vincent.guittot@linaro.org> References: <20250228134000.1226665-1-vincent.guittot@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Checking uclamp_min is useless and counterproductive for overutilized state as misfit can now happen without being in overutilized state Signed-off-by: Vincent Guittot --- kernel/sched/fair.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 87bf054cf36b..2219db9636c2 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -6831,16 +6831,15 @@ static inline void hrtick_update(struct rq *rq) #ifdef CONFIG_SMP static inline bool cpu_overutilized(int cpu) { - unsigned long rq_util_min, rq_util_max; + unsigned long rq_util_max; =20 if (!sched_energy_enabled()) return false; =20 - rq_util_min =3D uclamp_rq_get(cpu_rq(cpu), UCLAMP_MIN); rq_util_max =3D uclamp_rq_get(cpu_rq(cpu), UCLAMP_MAX); =20 /* Return true only if the utilization doesn't fit CPU's capacity */ - return !util_fits_cpu(cpu_util_cfs(cpu), rq_util_min, rq_util_max, cpu); + return !util_fits_cpu(cpu_util_cfs(cpu), 0, rq_util_max, cpu); } =20 /* --=20 2.43.0