From nobody Mon Feb 9 11:34:09 2026 Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.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 3E9B11D63E1 for ; Sun, 2 Mar 2025 21:05:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740949548; cv=none; b=cvl9HKUoOxPn0BxNxWT0F7y9piy7zqAP/9iRIOKhImml+xYZ3y0LOj1fkQ+Lp2PXM8JsW3ScVKdr0kyWRtOxyFsw/F/VUqDJBRrKG/HxKMNQ2Hl9uh+s6pY2YSrgI6YeoxhVcRSWcxDExHS3Hazr4er/+hY5uKCA7ChMWf1bUNc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740949548; c=relaxed/simple; bh=l6s2K8nye6CHRRRLfb5EYZPGV2XdU8BZngWM9TLpnUk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EPDAq23vfvFLX3ydSpUIRnw7ND0FDtQjpwfREq4674oQdR3u2QiOSYAujdq1lVHEN8h8QwA0O3rGCDUpe7UeAAGMwPsl+Wani9NHyjfE3azTukH+kdT0OGsc48FLCbmf5HFSDuow2FZy4V2Zf8+YP7bZOhdssTbwBXOsMOpYTLA= 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=Fg69tIDK; arc=none smtp.client-ip=209.85.221.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="Fg69tIDK" Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-38a8b17d7a7so2223313f8f.2 for ; Sun, 02 Mar 2025 13:05:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740949544; x=1741554344; 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=Fg69tIDKCSuc80syMUKax6N8B+2YG94jJnfTZIpoNgvv4HvkqvieGu8WzXboG8E70N n415Pfcs38Lm5L9Mx1v/lxwRv23HTfTI5sB/gqInMqdQQLQE1C4mog44oUNU/+Ff7CUu 2XUA8D+xQiwPF2lhGHu6sts8jb5HJHZz63CIvmVOHLd9pYZplPqg0jZQXMceLL4uWvk1 Kl9MhR6pBS508m77M42Vo5inKrFwWQatq/f6dHN8Q4TWMRTaUpzN5o7UEYmRxiGEo36d 7Fbylpae0IgpRlaV6KTkQyqzd0ovnYhpH+06pZ95M1eTDGam61LrgmqDQpejlZWuxQal 6M+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740949544; x=1741554344; 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=WPDrfjeTIOexGcT7adCzOYvf++pvOMMsHv7/Whr7CyyM+UM94T8W8u1fpZxmAdS9LX 1z2b1+efB+eoNcl0oXT83AunPxGOy9bGLhlNgi2OpeYF1+v6lrNw8zl+6m2tX71QaJ9W wWPXObFvnB45nFKqaWLwk9NAe8yheHksrpwlWAlS7TdVLYH+dDXpCVMWawdigw0TmtCg WFaLTaKe/VaH15FZkl9pvO3kpekzXcox+BzYpeyiAQokAoPx7JXjlqe5UXJsSzJN4dKd AgkqyqRP+MDfAorV/FA/IGXJOI+dpvAkDIfl558PqWQqsONReLq9PkWI1qnq9J0HkgNu QR0g== X-Forwarded-Encrypted: i=1; AJvYcCVgqSphCnhpbpF5ac0RxcPcDk/b5t2KGg+aIFi+yckIDnNdEzb1XR7DCDbyXEH4RZ7Fm2bc3IsMt07KR2M=@vger.kernel.org X-Gm-Message-State: AOJu0YzFVZEc7OcPr/A8/8dncE6b6Wpwt++VPgRimTaGjupr4tRQ/ECA WKKVUwVtdxz+bNGb51L3qAZdxoOrfO3LTIpjt1Dlxy7qs0RZHQAp+gIeC5/NwGU= X-Gm-Gg: ASbGnctGvW6sSgmZvDpfO5bmo6pO+0Uxl/QAGKlJ33xP6p5yOVHnSwB3PJR36qLBm7G 4kUqJsCTVk8ga68L1x74JyUeW3LMHYpdilywA+rvfJ3eiiOv84UFWtFp+QSZhzXyLK9+I4jnm5Y bJbvEwE0WcAWaWlJ/1XUza+Tx6ghGgofkA8ZYDCTUUTwiozyQfzNjDlzSVka+tfChxpNd8C2Boa L313YR87v6xbsr12Nj8r9gOiM4SpFIx2cy16h7NcpkzRlNSEC99zcPAbRzQYv9OMD6Q2FRRS1Yc Q7PYnXiz8NHlsHsOY7Ixr6u3o1yTShsz1pLbfbK/UqxzpKt9PzOl X-Google-Smtp-Source: AGHT+IFBQimuZNAU6pbDQF7JzTPxywA8zGvVoMza33W1wNrVxLc5yidGK/0ih2DJA/ZQgo0f/SlHBA== X-Received: by 2002:a05:6000:1882:b0:38f:3b41:c944 with SMTP id ffacd0b85a97d-390ec7c978emr10620473f8f.11.1740949544504; Sun, 02 Mar 2025 13:05:44 -0800 (PST) Received: from vingu-cube.. ([2a01:e0a:f:6020:cbb1:d64:4932:5446]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-390e485e045sm12480923f8f.99.2025.03.02.13.05.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Mar 2025 13:05:42 -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 v5] sched/fair: Filter false overloaded_group case for EAS Date: Sun, 2 Mar 2025 22:05:33 +0100 Message-ID: <20250302210539.1563190-2-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250302210539.1563190-1-vincent.guittot@linaro.org> References: <20250302210539.1563190-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 11:34:09 2026 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.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 91C4E1EC01B for ; Sun, 2 Mar 2025 21:05:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740949549; cv=none; b=WFj+5RD6jDWiL5jUNiPIqV9deYiJm8yYa81IaKU7M1UJPGlfJvPmNL2YR0+Hs6T1iegIwAvp96XIE/guIlGEKG417qqO67V5vfz/p5eOIRnWMYDJU9iw2K75UD9RNb+dGAt+8thSoiY3JEF5ptlx0pGUyziY6ZiyZLtUaIKRS8k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740949549; c=relaxed/simple; bh=egzu3f8lxE3MWip7YazBJRQ/Ydi5ZEOEpxWi6oXJGI4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V+ilQT4JEmZJkVnsg/HmtgM7kAQOkRGzzGxLCKKBKUXrveri4ZNMo+jZwbty3LhA8pMdvi9ugeY2ZopAOtUFwGwb0TRKnn8mLbtCC6cpGrDop6Ny+Mxj9+UDu2iSwHR57yjHs+z1tTUtuCwTSlHg1gL8Z0oHRVA72Y/aLn7WGoM= 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=x8/KE57r; arc=none smtp.client-ip=209.85.221.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="x8/KE57r" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-390e88caa4dso1589322f8f.1 for ; Sun, 02 Mar 2025 13:05:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740949546; x=1741554346; 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=w/6kLY6RaSrrdr4jkNO3fwWS6bRx5SKAp4IQp7qj4jQ=; b=x8/KE57rN+dpFpOi3u7+mbScwuaxA+hwCtyW6zTLht/V74r3GsCWjEBOi77qR5aGJQ iIFJf3TO45DPcJvaxtjBJIFKwkaCxyZaUBnFLxPGrDjTzDe7UHJJ3or6ASbEcpJUhZsn aJclIP4b33Ep2QMleNem6VsrXKatyfsRmRR9+E77zDugWJ8eizQxwUjw/vr9HD8Up2v/ XbgxlaIFHzo4ERE8ZXsgW99CtwrKsClfbt3lu+RGaRW51FCXrLicqCdMzrw9CzkJ/ip6 Tzn5gCu2DElHJYtv7jYU8YidO3z6IQVMtneLO4ddzjiMfAstVeS4lhQ5YHLY6tX3TCQx F0Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740949546; x=1741554346; 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=w/6kLY6RaSrrdr4jkNO3fwWS6bRx5SKAp4IQp7qj4jQ=; b=igf9A28HXKY47SW2Iacz7uvqSfB+j445BA2mpRLe1hiDuPe/CQlHOCce6EdZAWIgOG A/jEO9Do7m8XTOwuF6nAKXCtKXL33wfd3IslEmQCtG7oD5ZPOXjgItmONeno8GHcbX8O ySXMKzFNtu7XSNQkHY3MeFI1mx5zhXCUT9Bj2bn7u/rXmRqFdmcL/w1l2E1LZX6Kn8Pl 9z5QlOpqanjNQZnx6c3m3Kn31U1kUzAtMM5L+2HMbzXjyPA6m8lbU0Y/l3D7orSH8ZeY Dz3+LOkaYepVHlOQGS3wRnLZdIj14sUON3Nl9bBu0i4TppDzNH1sL5HMNKg5IFoSkmSk Q0KA== X-Forwarded-Encrypted: i=1; AJvYcCW80Os1ALkOuotDvp1jS0ATHGCGrlvSMR4QbbpS/z0DT4wb7UUd1pRNDB1wFjb4kTDn6RvxoCa+NmLmhd8=@vger.kernel.org X-Gm-Message-State: AOJu0YwjVZz+uXfCfdKkzEEWbXFWp6/I0gHXmMz0hwT7Hvn9fx3UZSZE b5M3yLUV6K9PL45QRT6IzKda4wFrpWv0OIMp/34rqv2ZJ/2tGEMEgcN3wCxvhzk= X-Gm-Gg: ASbGncuHBP50mr9dNHfA0uCvosoFMr8e9a9asWinv6h0VzeH1Aih/dZmAbraODjOsi2 cCacp/XBBg0kewoRBLLLCogRMxAA9xjDhwsCDcvQB+fvOYZeMhAdlMA6KEmR9C4+TcYBmGV1uJQ 6ycRAhf8qK60sRk1Dk8quwx++5OmUEWrGm+jL0bWZg4FS9lPVx3SfKfuztdhnGTQFMIAcB/ORyC RVUbibQUqakKXKYzWNz0Zrx9eSoEtakT0No2DdbQQJFhOWTS+y/s9yyizofQIevoOYWTn6oZ5jU AurJ37ASBpn/o9qTFCuPMOU7ueaGQUd268KMFs7a38XnXlIv6z7E X-Google-Smtp-Source: AGHT+IGBqyShoxMkIc7PsWPTrDt9QVABYrNclde3OourMlt6pgA0mXf4zgm+/3ZLXolqMJNWsmmiRw== X-Received: by 2002:a05:6000:1ac9:b0:390:ea2f:92a5 with SMTP id ffacd0b85a97d-390ec9bbfefmr9763940f8f.31.1740949545859; Sun, 02 Mar 2025 13:05:45 -0800 (PST) Received: from vingu-cube.. ([2a01:e0a:f:6020:cbb1:d64:4932:5446]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-390e485e045sm12480923f8f.99.2025.03.02.13.05.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Mar 2025 13:05:44 -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 v5] energy model: Add a get previous state function Date: Sun, 2 Mar 2025 22:05:34 +0100 Message-ID: <20250302210539.1563190-3-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250302210539.1563190-1-vincent.guittot@linaro.org> References: <20250302210539.1563190-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 | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/include/linux/energy_model.h b/include/linux/energy_model.h index 78318d49276d..551e243b9c43 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,18 @@ 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, + struct em_perf_domain *pd, int idx) +{ + 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 11:34:09 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 B320F1EE7D8 for ; Sun, 2 Mar 2025 21:05:49 +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=1740949552; cv=none; b=YeNRC0j7htsGw1K4hW2K/MQxYKBB2UCvvHo2BltlQH6B6FBOf7jNGAk0IkMCsX0L0Xh/scCx+UrUurQOpLcV/67utQkomHyfUES83hXS3whe1BbbLlp+grg9foMc12omknaGeE3a6rBIyuX+VmTBKbX2eLbSSfDfZocpnagohkY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740949552; c=relaxed/simple; bh=PsixIBRYtomDMf+aa69pSUIIBXLsyccZplM+BMuxbl8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nbf41f7045mUJqi4jiWgAWCjYcCVciX5Ve4wNPSv5dxpDHBEc6RXDn2iT+7bn6w8S6RPN09ZjaahE6Ht2FQYNlDZEeQY0T+eKLYVzGCqEt10P/qulFjyPz9O1fXJDiBxe+uX7vfZQRcl/0shK8tWk59kp9iu3K0ASsOZORBfvVM= 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=eIYPB9cN; 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="eIYPB9cN" Received: by mail-wr1-f45.google.com with SMTP id ffacd0b85a97d-390e3b3d3f4so1799639f8f.2 for ; Sun, 02 Mar 2025 13:05:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740949548; x=1741554348; 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=eIYPB9cNmoVjV/vqXxCJsVR0dOPHMN4TgCb2nu1An7F2MDNZRpxyQSrn5kg6I2imbJ Ciokv5/Apx8mNmLDnaIS1jBJcL9061G/vCTyeFbFKNA64xJxJ/PnqA5Q4P1NL4zxPQnm xj6B+fCZtZwAW4boeVZLjKCDatBYSsr05iBPLv0tHVnqFS1rF4v+mnH3qDz+XryLMAxf 5lwRemaliW9NgHzDIMef2f7MkYyMjhcjaH23hIshyeXMMKHt9QGcbfCWlr6iKS5v+S1o XLqSAfKpjkI0HozUEdPGBmz5tbFy1kWatIOu9e8sgr4eVPQXw7EoRNDWF2rGfJg2GXot x/4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740949548; x=1741554348; 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=jToOGch2dPrf6vtmealSHDl1tMsQL9mx05q9GjetiCaHDYMmsO4/Q6Q5fChWf9ttsG EGSBIVXh5g+sPOjr9Gm5omJOUqa8m74FCV/vJ61vE0Bm5BFKra/PTunzQRay67tVMX9P SRD5Te2HDVvbkU9ffbi6zDZaoGXqKFzMPsVWj9JM6niNiCTQMfYZ+AZxJ0PbwlEn18Ov pruNyOdwGb3pvSZBRxnE17IUYbMxGi1kxqFQD2tswEF3rC5zZboazHLlOqfiQNGYKQSW 5b1CEdQ2XqBs3ioig+Nkt5LqbbAJVQNR+vIRnx8z0cHPErnPaliqPLr0oPquP+KZCASx OrzQ== X-Forwarded-Encrypted: i=1; AJvYcCUp4ofMEyOi6DIw5czQFT4TB01knhfZJezIOcRBGVh0BoRXqw+Zs9w6uuCXUWKTv2BA31IPdVy5KvBixZs=@vger.kernel.org X-Gm-Message-State: AOJu0YxzsSjz6NU1+NThrCNB+ZcHNWvtxOZwnfMFSuTr3heTCjX0yGSm PQgsSxNVNTZar/wBt2ljnplNIB1MZyiN1b6pJAColQON1vP1IDwHlJWw6ZmYow0= X-Gm-Gg: ASbGnculQ6QX/M9/G2bQ23roKlIA6ZN9dWzHiuWUIjiloZ9tztp2Ji7y5oeBNXg+KBO veD/77z1srRa/aFL76fvphzpWwCNEskK2JtsVLCt7bRh3QIBkEYdPFaOV9/x5mFTIyCynfg9WnG cQdpt2r3jmrz1/L4J5AvkdAI0UoS5AouSNoEvwpoGvnwKPJ/ezhTIBB6N7y2FaGHtf+tJcT6HDJ DNzJ1rXlWj/4iia2Vlbc9pQW4S0l2IAZeh3Qm+Apxnp02AHJGYrWbakLcYySoVzv+8O32H/mX3A 3IWnPnD2bY5ZD9KZDP8iV8G8pwYuSd7ty3PkItxQwbrAPaa5dIIM X-Google-Smtp-Source: AGHT+IFqPmBkE0Zw6JrZDKlXlxWmOOvhUoq4WzTtkK1FXHdNU8qmtYYimBqKiCzKDBS2Sog2SJmWHQ== X-Received: by 2002:a5d:6da3:0:b0:390:e9ea:59a with SMTP id ffacd0b85a97d-390ec7c8eb6mr9273385f8f.5.1740949547866; Sun, 02 Mar 2025 13:05:47 -0800 (PST) Received: from vingu-cube.. ([2a01:e0a:f:6020:cbb1:d64:4932:5446]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-390e485e045sm12480923f8f.99.2025.03.02.13.05.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Mar 2025 13:05:46 -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 v5] sched/fair: Rework feec() to use cost instead of spare capacity Date: Sun, 2 Mar 2025 22:05:35 +0100 Message-ID: <20250302210539.1563190-4-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250302210539.1563190-1-vincent.guittot@linaro.org> References: <20250302210539.1563190-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 11:34:09 2026 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.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 A07011EEA51 for ; Sun, 2 Mar 2025 21:05:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740949553; cv=none; b=uEJnHTjLfoQwl2OwajBAxf+TzP2vnDU8FSCYAnydIm+5ydjMZHhnEFQPdKjNjk4B/VhoUQ5fE2gd5luHygQCQq8YgEY0PZzSdV/oh0xLlpKb7SlhkcX+LfWDkWlZ2n7jLdT3cWRKhca/yt6visb08DnssSLtJH2exi/mKEexsh4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740949553; c=relaxed/simple; bh=V9tDjb3FRXiUNX1G6EF3G2WC8Di0nWlqSJnRURIssMU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mnl4YlYjjOQOcLhwTVwKYXym9ca1zXygYypTPzcKfe2kj9NMb4pM9G/hl3Jbui06dYM7vypWS4h/e/u37st9g2FiPLb8leZnCwA5Erd4Gj4+RMeKdeS/KunMGcYEUjonio5Tt8xHSwjY7utc78JrlWosP3PcTeEOMzWVw1EC+VU= 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=Ign2MD9a; arc=none smtp.client-ip=209.85.221.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="Ign2MD9a" Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-390edaee0cfso1717822f8f.2 for ; Sun, 02 Mar 2025 13:05:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740949550; x=1741554350; 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=77SPkZNldmHxco8GhowPmzvPBBBG99U0AlIpE+I1iiY=; b=Ign2MD9aiDPH8BWifXH8j7cRr8OV89o3f82hkVKEXBxMdXyAWDLUPLNTxzviotxGCQ G4Z0luYd036xwmD+D8b0py9vUabUcc4M02jTwfJPv8098EgTeJ/l7LvLiTZVPG6uTDJu PQbImb94NEA5/+6wccV/tUWTqy/yzMOlVmOwSpc3jXYK+NxfHLLDfsrbzzBIE4qoRDN3 tqzhfAGTAhfGh4ZfTrIcb0GzFSRZYt9g7kxYORWjgDY+jp2yxzW9JABzdMl/4aNgyLCQ km+iY6ndrY40x6npOV0j0TSqw+cKtEuXgQJxcNPqhPZS0DhIkB7xXAWntW6mfSV0Elna qL1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740949550; x=1741554350; 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=77SPkZNldmHxco8GhowPmzvPBBBG99U0AlIpE+I1iiY=; b=biPDOcsK7MUpKRFP+kfrPcxkHAnnpo1V/uJ9JmBnIlAtRxUwFtc7/L98smv3GsHcsY aqJlffH9pEbJ/Di2I/Ca0fWaN08VpYcrdVtSrT16gawi+ex3heC9CD/Y2MJEux4aevjV 1CrOdGJNT1NAlIcKVGmBwymuPl1qprmkMS5rNm5Pk4/6WD/Zg+4pG9KeyjXDbfC0hx+M BQFPj/N/eixQ9aP2SycPkIm+2KM14S+/bM+PCZJcg3FOoJ5faAOQdYcHDGihP3RExUtC J/hIIjW7yapr8a+JYPhhoUMOIuozEaRDQALTOIWpE0fBUTJznMWf0tQMhki4U+XUYDo1 qrGQ== X-Forwarded-Encrypted: i=1; AJvYcCXenUBNIdvZseKZDjTWQgWiiWJbBLQO/1owapvNh9+z8VwM+9sS63zXDi6u6vLQeuGJJRNpnhg7aVSdA4w=@vger.kernel.org X-Gm-Message-State: AOJu0Yy2/CxGL2zI3TpfUtGRpTtE0yIBLRM4VvomQFiaLhLhsq6FdujT StVTBhDG1HuVlMW2tCLAkX+DRC1eJ0t+tRHdXyioOUdLm15Di6/gV5LxteuZt2U= X-Gm-Gg: ASbGncur8g1R3ydfeHo1pRhFdhalRIE/z7SeUB7cgHbqyTG4CtrCNF+Lg0LtneHfeDe CiIcnmIxl9lz42c1nr82bXlKAwhN2HfjwU5N4QUcyBx5F1bCTpZA9yMkfSEUrIAvYQoJepy/6K6 l5E7d793DGceFWNjfwuyxAcTLPd8ru8rgcyXz6SHHeERW0hcT8Pvhfv7YTjaAwMFWNuhRwwr3c9 k2YKAsp85o+Tl85+DGSYWCVI/VAEPBK17uuD3iJVp0c1Z440YWhdyts0epDDb5drReD+bK32Atg LUusGIIlhpvUkgjO049239aroKqo6uViwur/5UYEj3l8MKKVUJuQ X-Google-Smtp-Source: AGHT+IGK5wekiNqAoJE1NYQX8gdazZGXPjjRXEstlsyt8yut0bKqVOabEsssGAUTvvcSf1utDCYUvw== X-Received: by 2002:a5d:5f89:0:b0:390:f6be:af1d with SMTP id ffacd0b85a97d-390f6beb35bmr7061041f8f.41.1740949549895; Sun, 02 Mar 2025 13:05:49 -0800 (PST) Received: from vingu-cube.. ([2a01:e0a:f:6020:cbb1:d64:4932:5446]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-390e485e045sm12480923f8f.99.2025.03.02.13.05.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Mar 2025 13:05:48 -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 v5] energy model: Remove unused em_cpu_energy() Date: Sun, 2 Mar 2025 22:05:36 +0100 Message-ID: <20250302210539.1563190-5-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250302210539.1563190-1-vincent.guittot@linaro.org> References: <20250302210539.1563190-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 551e243b9c43..d0adabba2c56 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 @@ -394,12 +301,6 @@ em_pd_get_previous_state(struct em_perf_state *table, { 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 11:34:09 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 18A161EF082 for ; Sun, 2 Mar 2025 21:05:52 +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=1740949555; cv=none; b=esLvS+iGbMCXqxvk/1JoD9K6dgfKTkAwj9xMW3kWt4xENIxRCsAO+KICMgNn/VTJTEPJGL8dNoSYXJqLvXeqkaVYg7id4Cpa71S4s5zIQWQ8xLh46IhAKiqS5hO7IvZhdePjOVPoVhPwnKwjsM6af+X/tfV4IRflrZirSqSksWQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740949555; c=relaxed/simple; bh=y5FCWfFLmsduRKElpG7HovceQUJ3S158eZxC8JqxkvQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=f0rwEQYhzhOySGBF1U4s9jLnAg6WdOOXRPWeA5f9h4z8d2GZrynfrVpj40iJlAbKwBjcME1/8NybFlwwzV9iZdLS3QUbEE9z9VUABATdZZ7vlpQ0pLzbH9haxByQWj4zFZwRLeq8Eyfnz0k15216XptPnKToypTIIMYA23bQsh8= 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=oWRwkJf5; 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="oWRwkJf5" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-4398e839cd4so29337345e9.0 for ; Sun, 02 Mar 2025 13:05:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740949551; x=1741554351; 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=9QJDWaAxbTaZ06HQKgT3VZ8iGIVgt7TTKEF4KOjm0kA=; b=oWRwkJf55IkkqrAYEbX1ZKt8bn9QDcmIc4AajHLmlUNifkFC7O5LTI7iIAv+u5CkR8 q77aC/WQtxO7A+V2Mq44JG58yNr2/RulZAuTbEpVhyoNX5HD0qhEQc7DYAFS1F7be4JG rqHy0lqX9xw3ELCFmxABy98XtDd4+3Kg0/a7QV+38HmyMK/lQRwJi8+k725EXSvM2O5a I+Rb0OD044I0wPcDXHDAbY+Ppg9/Uhw2lREeoIfRFTjmeDyBb7tSb+nwsdFauxFUbpCd sT/G+Bi9HhJHNcwWbX0DoBSBaa6M2Qwz3kVyWXXa3t2JLxIV7tLtGx9KzZeIODpsY8m/ 0fnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740949551; x=1741554351; 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=9QJDWaAxbTaZ06HQKgT3VZ8iGIVgt7TTKEF4KOjm0kA=; b=kT5sDO1R461JpC8oTOtl2apaY3A01dMp6kP4L96iPqGxUBya4KP3uAaJ//Oi+Ldxv1 odOhfx38HqIMHGwGr0bN8NR7cv63bILjuKhlSnQTUNZtAacbURimnsm4aDb82mUn6Zx1 KXBjtM0Byvu8lDYTQNKtxCwJfREkz4rz7amIK7TWmCiv3MaCLuvqdJk1f4TItEK+i1QU qPp0cOG2UaE8G+126k+8L1qu3ddV8DjE+OaxhfYRKRwfU6/HtUs4CSbLHJLtQxlZvIMi mdankDKx61pkTpY8QKC/LFpPfuXo2JOkSdyC/3PKAf8zlRgl9zC8NdOeZA0mvFF2ISNk IHAA== X-Forwarded-Encrypted: i=1; AJvYcCW3o7WsniJIS03lUVuy42Jm7Ur+ILqkyKvnuxPMKabswKZgq8klsuKFZt//m4kM3zE6drSKg39T/iEiNBk=@vger.kernel.org X-Gm-Message-State: AOJu0YyyTR5IDxakQdkvHLAmUPSEYkBXkdZ338/xSTgaSc2zCRaXmoXn jT+ztejOsQoTdYjQsocHwg22Gy1HRuXTNF+OsFbYiffY3lNK8iXoW0+6WVwB/pI= X-Gm-Gg: ASbGnct3Ur6AX9Gtqu2bFLiIpQPMxCNZsouPAEbOGcq2algmazYPHhywtmcDU35kTLI daWpww9Z1tNWH0Ex/utoRuBpfl2WpiQVcsQoimNlCn1qAD7ent3zFuYQAPKnCedDM0hWN8MtPd3 uOP6u1eARu/0u9IlYtF7jhQ+Pc+CrFHxOaA6GPB6YLlDuc08jdXh+tV0U4uQHiEuKdymwbNq0Vj iBfQzg/g3/9Iyw04axFHbVW7VOpdKCJ9TIJJsDlCnttfy2bWzRWwqkTs42UQLrEBnk3vTJPc3Gt XiI4ayJVot/X5taNKdABE+cjT2it8A/y2uiQ0ge/tItxf6UOa499 X-Google-Smtp-Source: AGHT+IGjd6BIceegy9HIwkPCGMTEy3jwNSZ3NA7b5PdurtKAnd1Hz/NZcOgC+TLiteMcMHCtSXxdOw== X-Received: by 2002:a05:600c:1392:b0:439:98fd:a4b6 with SMTP id 5b1f17b1804b1-43ba629a811mr93860895e9.15.1740949551258; Sun, 02 Mar 2025 13:05:51 -0800 (PST) Received: from vingu-cube.. ([2a01:e0a:f:6020:cbb1:d64:4932:5446]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-390e485e045sm12480923f8f.99.2025.03.02.13.05.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Mar 2025 13:05:50 -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 v5] sched/fair: Add push task mechanism for EAS Date: Sun, 2 Mar 2025 22:05:37 +0100 Message-ID: <20250302210539.1563190-6-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250302210539.1563190-1-vincent.guittot@linaro.org> References: <20250302210539.1563190-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..c3e383b86808 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 rq *rq, struct task_struct *p= ) {} +static inline void fair_add_pushable_task(struct rq *rq, struct task_struc= t *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 11:34:09 2026 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.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 CEF381EE002 for ; Sun, 2 Mar 2025 21:05:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740949557; cv=none; b=UuQeeTiKPBsehqLSIV4qUFine/aMxh5Mxsk9LO+9Et0a9mrmQ6jobpHqe6/eqNZhOKa/L+boygcIbH51oJeP/RGm4AR1+Q98YAKtfWTs5tICUeSiw42HRC3B65PG74+GI5MGQEr/dmB2365Fo7f32rkHDctTzmXEzwCoHe1jv9o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740949557; c=relaxed/simple; bh=mYD+5wpDOEjCHe7SLqpycP+Ms/nkEueyBuD5lomGr8A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g+suRDKsmRMcVAFcrEPYW0vEDkBStZNsdcnGMhoR/4IFhrXAJXLX9QGXlCFC33uRRBgZ3aM+eTcupbWfgURuX7d9zDq1hr9IrwgWA1teN1Af/nlH16owq1yi4jVCOxJ6E0LdqUp/LC3RQCCLnn2lkkGqzdDR8u90ulfOQZYvni8= 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=J7yGBPub; arc=none smtp.client-ip=209.85.128.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="J7yGBPub" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4399a1eada3so34871575e9.2 for ; Sun, 02 Mar 2025 13:05:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740949553; x=1741554353; 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=YwUN4HVHeJlZ7MbhuW0mt9rOr3uOjQJOwaCCI8I09rc=; b=J7yGBPub8uxWyUB5cepAo5FD3BDwYFnVG28VZpblCIQokzyXlhzVDqfxr1wlKzTgqG doRMzY/XLBGse0nwTzK7nNuKeBMyr6uH37YIIDKE1lojCADMRT5tvEvc7YHHM5xjcgH5 qcRZPaA9Y8Cjj6gccKIx8VAv4l0BX0F+im64qZaD6gpdSjLobsimN15WvXeTbKPyZZ26 QFukuwjV89UydoVtfU69K0Vl088nVp5zogEmdLNrFiHuaQAoNShMAKlZu4T0507Nxc86 mrqjDXj1Tiq+9pd0p0jEs6eORpZeBWFl27Z50qrjNPERKQ6aQbewmrLOhvodNRK6oq04 BSHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740949553; x=1741554353; 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=YwUN4HVHeJlZ7MbhuW0mt9rOr3uOjQJOwaCCI8I09rc=; b=RZrEzVlPXjca9Kj/qu5f5/QSFYuAGcWSc2gj97xk5sl1Ex1gmL8uWUZsx4xkn5gfPk 9nyudgDYc+rhlDagVRZJgC09cU2J11yPZ/SvCnRTKdyKaEZLEASPeg0PHp+orVlXQ0dH viUw8rlb8ga9FT2rLnGuD+SODT5h18pW0UAD0RNm/FPmywKxeU+seMSosujc+Wds38C+ Fo3bs3RwKqV3SDWLczznYBqNKwYo7szy8yGEFWqE8j/llcVEqsFma8prgatlRakygBUk WchtKxwr30k7JzgXo9POEX9I0xaMVGjZMJHUNt0QoKULLju/p+TvxiIPnUD9EQvGRQB4 3oCA== X-Forwarded-Encrypted: i=1; AJvYcCUN9G31/yJIC4XPwSelMfLpYBGWXHw0BM0kpANrO1zASAJMVG5Ml+2FwhsrCsnaJvuDsOWCL8uzGaxSw/s=@vger.kernel.org X-Gm-Message-State: AOJu0Yza6gnr96vAB3YN3Wq/JHIweRoFNVEGFv8+wK07+St6ntUlpigb FPpGUhILNcm8/f8tfV1NkfTJES76sd+1Oy+JFp0gg8PZO+OEaHvq+0mrC9QwPo8= X-Gm-Gg: ASbGncsG2Aj5Ar6ejmtxEq8otT0Yl9qRTlA72EyqaujtAkZ7cb2lsd+pCnX6ufNw/wZ F2GhlozaHCT5ZpfR4x3jElWnwhVexfUmR9jS6zLWdw/PoYfvEJiLYav2O10uBSmBg0tsDGhErvv lS2em/waG6LhBgIIKvjIcd99j8gW2PnwkrzOS/z7U4uUcO4Ym6H+/8bcP5CzLi8+7XZKwZd6Xm7 TxF7d0pMJfdnjkLlyoY6BJ+NgmvjHy5Alisczu6s/XNiE2OTxotFu7MoIcl9rfBE6BBtDwRwhpZ 4b9Df32av9XhIiEdQTE42XnGwpVhTHPARCKavPk5VuDeyVkml3p8 X-Google-Smtp-Source: AGHT+IGsre+4yt+K927E11a+Tl0KuAxhKq6njMFM6kDrAbaFIfBYMLy6cHnN7923nY9vPJ98QeC6uw== X-Received: by 2002:a05:6000:400d:b0:390:f898:92be with SMTP id ffacd0b85a97d-390f8989367mr6051642f8f.8.1740949553071; Sun, 02 Mar 2025 13:05:53 -0800 (PST) Received: from vingu-cube.. ([2a01:e0a:f:6020:cbb1:d64:4932:5446]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-390e485e045sm12480923f8f.99.2025.03.02.13.05.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Mar 2025 13:05:51 -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 v5] sched/fair: Add misfit case to push task mecanism for EAS Date: Sun, 2 Mar 2025 22:05:38 +0100 Message-ID: <20250302210539.1563190-7-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250302210539.1563190-1-vincent.guittot@linaro.org> References: <20250302210539.1563190-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 | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index c3e383b86808..d21fe0a26633 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,11 @@ 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) +{ + return false; +} + static inline void fair_queue_pushable_tasks(struct rq *rq) {} static void fair_remove_pushable_task(struct rq *rq, struct task_struct *p= ) {} static inline void fair_add_pushable_task(struct rq *rq, struct task_struc= t *p) {} @@ -13362,9 +13373,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 11:34:09 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 9437B1EE02E for ; Sun, 2 Mar 2025 21:05:56 +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=1740949559; cv=none; b=tVV+ZDv+zDKEDUL4zoujOOOiZUzbhNbinN2Y3Zb5O7+7U47gvO+C79FKcKkOVbfmjGlUx/mEhTkKqYPuRFvvl8bgWPNBw+FM/hU6vejrqCQ3BWrq798d+44nt29/aHG/Pz9aUhZgjuHqmRDaJr36QsdeEm8rK5M50ZdomauVx3c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740949559; c=relaxed/simple; bh=csJHFJUyCsftMCmpGFQeCYBIfeJ5ABaV3LQxV4Rm3ec=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Cr/B/Js3aJDQAxKPzkAgilvlMFIdmcDHNlV9xeki4JSRBPW2TWnVPKEC8yBheKp844Mw5Z4irBjN+aC0LjcxoKlAp5r3Dsvln/WrPl6VxqFk7cuNBLuB986yWftqzsxTsnY89XcNTRR1KEpIoTBFAEkMYjVE5/CWSUvG2ha9kko= 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=feGxIr6e; 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="feGxIr6e" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-439946a49e1so23563895e9.0 for ; Sun, 02 Mar 2025 13:05:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1740949555; x=1741554355; 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=fjzhsMMWFb7O14Znxkn5qAGqxHoEDm7OLKD4SmZn2Eg=; b=feGxIr6e1I3ps2jibHkPvY7UpsvIMsS9s0ilddPqug06xFBHtkF4Jew1DerAkO2/eh ykDe6LQAp2SDrgHHvfs+rj1+FkwLw6tl6sFiuLyoLpq8muOCLCQTLuDre8l04jvo/bEZ XG8c6I0G6+wgG+CXYpTndxjpmXfL7yOCXvjCO+ga5hj3nLss1QzAV/g15WO4DU+JEOt9 sAvoUNdpfL8si+yhUZkCRIb6qVtZPYKYgPd4lJQPGrZL5xhASftY8FATtYSILaOxUCXC c8ybW6luTg3io38sktRWGMZNqNrv+IiGi255IlONzqlJh7NHAdxB4Ll2orqjzsAPfQir wxjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1740949555; x=1741554355; 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=fjzhsMMWFb7O14Znxkn5qAGqxHoEDm7OLKD4SmZn2Eg=; b=wSzl7rrg6ujUCzg1hztWwXtkD0uikAtLy4p96lCgqFjCv+TNGzv1IF4knns6mdxCDt fUwCuTrttYmNwyYW6Bxjlr7qkfS66xJZPP7JrhOb4r/cmc9d1C1zGGgfC6Fu7Od2Rmrn xrFLPTgK8BpXzWfhfDMmu7O+Kea2Nmelpp5nrFO2CWsGs3KB8FptrIP6q3RUDwECd5Az bsS1y+0Uk4fUQuottMUSU8J9e6ciJ3fR8XDjQs0JIE8m6pY1e0xntga77mB/A87weCqV F1rrpaD+ED0Y4wzoZW5kuwd0a+0UgR0J3jAXpkGU644oHMHfgdqiIli0zZ6dAeIFBV89 ifVw== X-Forwarded-Encrypted: i=1; AJvYcCUpZ9JQXrgnYhuFWkRgAGHMZyv2zVRY2rTRb2RwLvMfLGTwKOS8d8MVoKWcJv8xGf0D0GUq6FVREJA1ZYE=@vger.kernel.org X-Gm-Message-State: AOJu0YxNTfk1pwOCVEXXtIup9KNX0Z9xKFIld6cwu6wwM2FFKyr6F5sj IBhLTS3O2ODxD4zKhh1cVo+xkc+Gj89qjpG0CGmMQp/z2ulD5Xh8Pt7QoHBDw64= X-Gm-Gg: ASbGnctZkfzKbZFyKOQIa3lCu8OjLaa28c9p1aF4f7IvypRsMaJqGXWTQXL1iHNhhf+ IwZXDgcVGYNbbTsAX5esqhaRN+pQS0kAFMJmn78lhM18fcxs96Hzkl7uUCz0OzJRfjfM9VG0Mmx ylafajHERJh89gVgp5gpfeCNxNaE4kXZRKyrJp631L0hwRgAyIQjG8pK//XovkRaW1EijXuwhbZ WS0d4gSJ55dMmN/8ZAiDGMIzK1V7AZ7W0qQq0TgNL9mYVT53UurwP61MISrvOh1Zr68SWD5JNAx BRrW6lp4vNCXvlH0Gl9SMLMGBw2dYw44+gVC36L7UiyLo7p9GM3G X-Google-Smtp-Source: AGHT+IH6WW/pR4ORqXlwWAdvHlQynFbHAHxZ0vcbhGBXAgkz8brrkiohxCfeHRC8Muq2hQiyBaw+ng== X-Received: by 2002:a05:600c:4f16:b0:439:88bb:d024 with SMTP id 5b1f17b1804b1-43ba675a8a9mr75614145e9.25.1740949554865; Sun, 02 Mar 2025 13:05:54 -0800 (PST) Received: from vingu-cube.. ([2a01:e0a:f:6020:cbb1:d64:4932:5446]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-390e485e045sm12480923f8f.99.2025.03.02.13.05.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Mar 2025 13:05:53 -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 v5] sched/fair: Update overutilized detection Date: Sun, 2 Mar 2025 22:05:39 +0100 Message-ID: <20250302210539.1563190-8-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250302210539.1563190-1-vincent.guittot@linaro.org> References: <20250302210539.1563190-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 d21fe0a26633..79f505492215 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