From nobody Wed Dec 17 19:03:23 2025 Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (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 81C24202F67 for ; Fri, 14 Mar 2025 16:36:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741970182; cv=none; b=ggSDTLPyAhv2hqmOD3ScVt+13QLU7HxmBRMeuLqxLWaLJAbPUc/YwdGPJ/Otiywe7oFBodrbY1MWmUwKBqnZvwVvvTqTKMh0v5S8pI6cE7/IqsMgKZ29arS2i6XL056wMF+tbqV4C3DDcu9IQ7KIGisxMW21lDLNAYCzwpO2uvg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741970182; c=relaxed/simple; bh=AQWMzvVK8cK9k7Epz3rAFhaFaIaia/otULNIrgfc61Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XPM8M8Z96OYZyECd5ap5W1CmRdKaH8Sa37lrPuaDyeRuoeYkxNEP2HP32UREArB1olA+TmTFUHQNyFoubyBb4TDNhhJwNmcjNsfUzpyZxkGVjAnQFyvKUQUUKga7yjqPKMM07s9+RmPOaAMg+vibyhIjJOlqJe+WHtMzDh6dqa8= 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=DfAyqtZJ; arc=none smtp.client-ip=209.85.221.51 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="DfAyqtZJ" Received: by mail-wr1-f51.google.com with SMTP id ffacd0b85a97d-38dcac27bcbso2265021f8f.0 for ; Fri, 14 Mar 2025 09:36:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741970178; x=1742574978; 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=JcF4yJAbrfhrGVD+YO2tfOQrmlU39QTS3nRDjBtarC8=; b=DfAyqtZJu+wMuLkLOlZN25e9N33KOm7BKP/M/wdHgRwcUyyXadHVSSu10JJ+EEQXvt daPLSTyZAFAX1HrAeLSwPLLkdw27AVLqDEdD87HvzE2t0rhaqh+OyScxqw9+ovNPJqUI KFONtaSXHC1Ll0gp15n0dzpw75YFFDYWtKJYtQmFCAr5GZaQzbTjkk+pIanA5pJkAHFP S+IGj0Q7l7HehHjSkz8sAogLackRgrIKh5a/0xLlZv5ExL52CzIjY3kc2OIO+PH6hPQI lNliww/cWph2pNKG+FVk+XkbblmI+hLlflK45dgjvG21l5Zrq1JSocyP1dVw0LHHTc8w A8ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741970178; x=1742574978; 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=JcF4yJAbrfhrGVD+YO2tfOQrmlU39QTS3nRDjBtarC8=; b=CaIf2SKa1LdGKGGMluhVy31zTOMBTjryWvYk0DuTr6qExtdMvMwNm4D88NQwxQxGiA GUBN7aFYU1berKcl+EmXvhxjNkudsXgv39N4D2gl9eIFxxxB5169i9woHzY5tnoKNopL 55z1EMHMAQFuggCYxCjNdvXpxi/So4rPETz2xki1hIW3pnQHRToz8NOkxhfkAlGsPASr BZnvU7JEsQZK55pI6TAySjq+TqxYPuBTCjs+vaHIzXcG069i7TPALpkHguYb6QDM5cbx heJyDlQwGZN6zz1L4tiMVokDTkywRA0+5t5ix9AyBBLcKA1oaov4LWjseD63BF4mQUWQ jF5g== X-Forwarded-Encrypted: i=1; AJvYcCUuboDQf/XJUg1d+sq2VJDEm6du52F1FDNpnvPemlx9cZHy6Ie/bls5wuJveAEAnxSmqVYntr1wstNS8is=@vger.kernel.org X-Gm-Message-State: AOJu0Yw3VOP6wrbb0V6wQrfnYJN6fyEcOnnApzal2cGcgBj6co5hNMml 5cWEk5nAddOfHvI8/qOMZEc8/yOzGxJTAvXIw6Pcnb2F43sdFoRHANcxsuillxk= X-Gm-Gg: ASbGncvoBDrLus92TNfZ0PMo6CSn3ReXtoGZK/Mbrrdb9Je2ENeCfSl8M792rv5ewzs Ky+FAwfnxhR8eT/klpQyJx4OobKbmog0VKNV5OKehgUnc9kOgmEbyz8n2pvy/g8oZaO9mf/jP5B RljGVx3lSrNkXg177i2GQ0AL6hI2UOge831ib690IkT8Pdf8IUbrHUDC1w32JdBKX7X11M+EJiF MzgECoGwPKEhOWN+cejPixHLvw9TbOAyYXxUPnFsSxIZQtBXrdm6QktUqx2/ZERaorbpH/t0OFD YTFCF/viaksKE1H7uBaW6Ocp8hrCgXAKkpVwLb6kzybRbOyPOMdZ X-Google-Smtp-Source: AGHT+IE6dPkTW1b75/6adxw1FQ30TXIVwRMkleReJ18sF6NIv87zraP01nVtN/NbEL6PSZwUNp3/bA== X-Received: by 2002:a05:6000:18a9:b0:38d:e0a9:7e5e with SMTP id ffacd0b85a97d-395b70b6f9cmr7689449f8f.6.1741970178493; Fri, 14 Mar 2025 09:36:18 -0700 (PDT) Received: from vingu-cube.. ([2a01:e0a:f:6020:329b:9a6:20f4:3754]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-395cb40cd78sm6072925f8f.78.2025.03.14.09.36.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Mar 2025 09:36:17 -0700 (PDT) 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 v6] sched/fair: Filter false overloaded_group case for EAS Date: Fri, 14 Mar 2025 17:36:08 +0100 Message-ID: <20250314163614.1356125-2-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250314163614.1356125-1-vincent.guittot@linaro.org> References: <20250314163614.1356125-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 | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 9dafb374d76d..2eba6258a518 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -9933,6 +9933,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; @@ -10165,6 +10166,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 @@ -10348,14 +10356,12 @@ sched_reduced_capacity(struct rq *rq, struct sche= d_domain *sd) * @group: sched_group whose statistics are to be updated. * @sgs: variable to hold the statistics for this group. * @sg_overloaded: sched_group is overloaded - * @sg_overutilized: sched_group is overutilized */ static inline void update_sg_lb_stats(struct lb_env *env, struct sd_lb_stats *sds, struct sched_group *group, struct sg_lb_stats *sgs, - bool *sg_overloaded, - bool *sg_overutilized) + bool *sg_overloaded) { int i, nr_running, local_group, sd_flags =3D env->sd->flags; bool balancing_at_rd =3D !env->sd->parent; @@ -10377,7 +10383,7 @@ static inline void update_sg_lb_stats(struct lb_env= *env, sgs->sum_nr_running +=3D nr_running; =20 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 @@ -11048,13 +11054,15 @@ static inline void update_sd_lb_stats(struct lb_e= nv *env, struct sd_lb_stats *sd update_group_capacity(env->sd, env->dst_cpu); } =20 - update_sg_lb_stats(env, sds, sg, sgs, &sg_overloaded, &sg_overutilized); + update_sg_lb_stats(env, sds, sg, sgs, &sg_overloaded); =20 if (!local_group && update_sd_pick_busiest(env, sds, sg, sgs)) { sds->busiest =3D sg; sds->busiest_stat =3D *sgs; } =20 + sg_overutilized |=3D sgs->group_overutilized; + /* Now, start updating sd_lb_stats */ sds->total_load +=3D sgs->group_load; sds->total_capacity +=3D sgs->group_capacity; --=20 2.43.0 From nobody Wed Dec 17 19:03:23 2025 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 E6521202F9F for ; Fri, 14 Mar 2025 16:36:21 +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=1741970183; cv=none; b=kCajIt81Ml2tezvJ5r+LvTDZjmfGW6zzmQaZM1223b2weE0PreLhP2r9zQA9xxIBqUXZk5tstG46Gv+MJMn5GfSwGhpiDtg5xN9mvgOhiOzaaZVE+RHUGcIqOBOIi3k2sCRW+mUeLKS/wiByLnTcsTdfYp8JfOPriLAUNRohzHY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741970183; c=relaxed/simple; bh=egzu3f8lxE3MWip7YazBJRQ/Ydi5ZEOEpxWi6oXJGI4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c8uduDA06PPCk06IS8vq9VWMP/tytNlw+a7Uy6ZgbFsqpR6Tx3Eg4KVTgHKKADnPL6ik3siMb9ir+76A8HdTvFyMhg/cs0trhqotNBifS0PnoX1WgyYOkpOQKQRjAczBKEG7mHSNEqm+NFOWpvQyEz8JLeFQkqGkfXS2krVIoro= 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=eabxVA/g; 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="eabxVA/g" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-43cfe574976so14996505e9.1 for ; Fri, 14 Mar 2025 09:36:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741970180; x=1742574980; 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=eabxVA/gmnQDF4KoZfAYVd9bWc6BZoUHt3I8c11iJwJR7Bv/ujx3AMPCtJCQ+5+jYK Z4hXxsI15oE3QSt2BLyIpEw5EmsO9k7XZbuoCmouN/cXrd6ai2pYlsEthRVxG26qvwos DsLmaXCJSEPC8hfQVo0t4dP5/g5dZo3f791+Xs+kHZGyryHG6NvKTIWLhaYJ/tpycSuL Fr8gzdOUiNv1EXIxlcuCIqI33CScGTF9zQVoar3QKmVXZo6mLp8QkhN85tFNyn0OfC4/ dlEnzS7SR5IeMPzr6u0+Sm0fbThkM0bb57gVCwyZ81kGQtpOEeWoms+LCqA70xSZn5nW 6q9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741970180; x=1742574980; 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=RtWkwKKN/TbNI7VRWGqlDH3Z0L2Mm63yK3DxaNFy3r2lGbUa/zwNQmTVKhKBE2vXsI dnxEJFzt+1Cg2JzkxZuGp9Wj4SZR5r/GpWvvHaLWHZ5zpf+MdOKlenSUSkah8E500qk5 G+o5y7LQ4Nsnm85A7CWccEPC5Gm7xOvxHV+XYM6y8l3InKpNZIBp5gAAsq/P8gIZbNPd a/Whg1SKBKZhpYIJHM2reoVUtmUU/t9i6vUlSPaXkRJerQljZFJXSJokV1O4ByNPPCme UDeDt/NLr2RIfmWX8CxLsqN+kS9gdiqQ9xTLNYKDj1geqNmAASkEpRbQwvS7BbVkTqAB IXag== X-Forwarded-Encrypted: i=1; AJvYcCU+lagNEpAe/AHD2Lt4M5WluB4stpu7zGvJ5mYupBR/RwwOyQlY8+rczSt0JTEFf6FSEqmSHah+B+Mt3P0=@vger.kernel.org X-Gm-Message-State: AOJu0YyXh15OXoW1fd2Nro4T+KOto0qfSAFOPCFIbHUP3AMpX/N/+9BU dKJPvPWPClewX6jWjgbbgdI+CYypNsKyRkMIou9iOIxbt/LFQrh8ZDac61DBZbo= X-Gm-Gg: ASbGnctjLKDF0DbeGV7iKxGJLIVfZYcQ1ML3JlYq6OSkCki+swICxb4bolNGwTVYuiq jp6R7wTB6oPXpj/T9Ok9mOoQE3PAHbsZI+/WTZnjAxFmvxQs3qzeQP8rYGJF3TcnT226P+T/cPG b3gxklqNyHQ6+YLHp4nWxU29mWY/fp8rPWQ4AMDq4DHDDaSw5hEsOg2xaEbj+9IH05Xcd39q5eR NJVEkhQ9AbYc9DCPyNHRuqWBsJdTgPNrJmJ68UHdyWXo2pxrzsGCejE5Z9O43m+NYewLQbdlpRH JChUihQ51voHx5iu/uu/qZ1HgPkXe0disQtEboedU0tlr8iNNd5f X-Google-Smtp-Source: AGHT+IEV5DUzPeCkEeC9h7wBBBLB5i5/n4hnN8kMBJ9SLzM4h33dmBc6TU7P/qqC7lTt7+ZNMbfk0Q== X-Received: by 2002:a5d:5f4c:0:b0:391:10c5:d1a8 with SMTP id ffacd0b85a97d-3971d135f73mr4233147f8f.6.1741970179972; Fri, 14 Mar 2025 09:36:19 -0700 (PDT) Received: from vingu-cube.. ([2a01:e0a:f:6020:329b:9a6:20f4:3754]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-395cb40cd78sm6072925f8f.78.2025.03.14.09.36.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Mar 2025 09:36:18 -0700 (PDT) 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 v6] energy model: Add a get previous state function Date: Fri, 14 Mar 2025 17:36:09 +0100 Message-ID: <20250314163614.1356125-3-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250314163614.1356125-1-vincent.guittot@linaro.org> References: <20250314163614.1356125-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 Wed Dec 17 19:03:23 2025 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 6146920371A for ; Fri, 14 Mar 2025 16:36:23 +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=1741970186; cv=none; b=tOt1MZ6i1gL1R2jfzAdw+qfvFmWZXZGXZcczouQqhvu/AW49WUhujpL6XDjAwq8t+t2Kr9rct9AvBEoAgCDzwLvNcgCUchRWJSrr6tUsxSbnyTGE3g8cJrmhkijgxx4tNMqpeUsYOXjit5ycl1rYV8RKWRn2z9gYULPdFIqn3yI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741970186; c=relaxed/simple; bh=qFlBXSbh86xXEVqMIb6oOAHoOVTRYELwR2Ik4bb4W1c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=E97aiK6p0I1X5qIXhwWznw+Onr+484DuSbv3X4DkpgblU1u8haStqwkyGqmd162cAK0YS+Sc11P1NBjzLefZcrnKedEju8+QXNec2wGBcHyllDpu88ng4O0yq80FVKY09Ns3/buXnPHXUeP8jCfhh1TErO/AjFSS8AOG5IkqmXA= 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=sSdZX4zL; 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="sSdZX4zL" Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-3912e96c8e8so1520404f8f.2 for ; Fri, 14 Mar 2025 09:36:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741970181; x=1742574981; 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=eL1/0LtFnHYFMg19rup7tpsIDrXTZaVOPjDHWjgw4rQ=; b=sSdZX4zL5v4+tHntwN/vJZRbpV/pp/jGjwrKTFLV/fMWQ+oAAATZoTJSzPg0SYgv44 plpuyEX2NcjfPbak3nOVJVXOpJyK9zynmLPfWZTlIT3XXuqS/HsJ/JGBEVr0XzTrViEW m+dp/tVMYgFXlfnp9eNhmKkJhEwPIS0JoK5oBaS0NKz/jMMlezzV+GHQVqAGTibbF2ey WLwZ6Rx/IQGdZPK+yd37dktReSjvzRwU+OrNBiwcf+xl16wLaXGm8ryjwro5M25Do0L4 +MiDBa8AZ7U3X9GvoWEFx54CLbVKbKnpREA8XTULTHrtLYFmNYGqEXDD1S8HIho4IeOj 7b7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741970181; x=1742574981; 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=eL1/0LtFnHYFMg19rup7tpsIDrXTZaVOPjDHWjgw4rQ=; b=UcGUyopazBTV2FiyvVneH3gkX0PSC4ivd22IQjIHttjZnYKKQzecN6nO2TG1j9ep0I yFiJGJEj5YcXOz/XQ2spQuVvMW/b+xlmBPjy3UIU3BavPnKWfeNL5q+PNRqRylTvWPRm FoVb9xBL2FZWIyM226oqvDx7R8TBP0FlSIIrOGbKrhAqThnY1qnTjZZIfnVPbL4kr4uE 2ev+HvuDTm0B7vCl82yUbkPns/q9CAib+7MMGQfXXdgqcYFqrY9yQkby4tUwfG67voiX sLY1ujiqD3gH7znhJjKGjQ70CQfZfUQ+/lMfulxebjr0YCnIButqENepskb3qsb0X0EK LcCg== X-Forwarded-Encrypted: i=1; AJvYcCWvW/VPUqLOJeJKRk5V8Jd7XDshEACsBmNj2or6aZWRqJ9DiidE50fCS2q8/uAJyWvwkYCndlTuuBYi6XM=@vger.kernel.org X-Gm-Message-State: AOJu0YzwA8F4DhGqy8BroHvbTT6My7CrHDddOtOZiGn7S0DT576k2LrS /RBEVbbb8QoEPqBeKtnDpCmB1ZsqjUW5MChgbucb/2yH0a5WeaSbmVfmNF0llqQ= X-Gm-Gg: ASbGnctHXQI3Sb6OiiN82rhf4ADdjJNfHwhQzk5eeK8+DUNnDEyigMCGbKKjOf0+IHw GItaol0RmQOJ/gFHrfSB7nR9OWzsWkm90u6MVlJl12pdc30Wltb+G7PjmT81qhGBgwzJy+Kk7W8 QCeDwuQB+xBH5Na9JDDR3fRGPoIonu69IKq8q8qTFz+LT3RIdDqKhaIPqApqOhwjCWiTYvP4pTs 4MzQRw1B9YlBQQO7UEKb1j62OUIr788vihKo31wQqfXJSckJKy+t3SXXX6IFsQRn2ZrLbRyBLaZ Yp+bju6nyeearELU+iGS15rsdJDPyWYxsDYNZHz575nk7ee24emkAvmXbPyTehI= X-Google-Smtp-Source: AGHT+IHCkDluC7+g/DidtuXCj/U8wEZ20s7XGgFlVN94rj3lb1b7VY/IE1UWDosVH0BIKzHAdp8Inw== X-Received: by 2002:a05:6000:2ac:b0:390:e853:85bd with SMTP id ffacd0b85a97d-3971ffb22c0mr4667668f8f.48.1741970181419; Fri, 14 Mar 2025 09:36:21 -0700 (PDT) Received: from vingu-cube.. ([2a01:e0a:f:6020:329b:9a6:20f4:3754]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-395cb40cd78sm6072925f8f.78.2025.03.14.09.36.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Mar 2025 09:36:20 -0700 (PDT) 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 v6] sched/fair: Rework feec() to use cost instead of spare capacity Date: Fri, 14 Mar 2025 17:36:10 +0100 Message-ID: <20250314163614.1356125-4-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250314163614.1356125-1-vincent.guittot@linaro.org> References: <20250314163614.1356125-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 2eba6258a518..fa23e48c1965 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -8195,29 +8195,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)); @@ -8227,124 +8235,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 @@ -8381,17 +8418,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); @@ -8411,19 +8445,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 @@ -8434,13 +8468,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; @@ -8448,120 +8478,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 Wed Dec 17 19:03:23 2025 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 01A442040B9 for ; Fri, 14 Mar 2025 16:36:24 +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=1741970187; cv=none; b=O72Tak1cyEzWFdY5CMN88PaQP2QtmeHWD0LaNvCwI9Hec2QDxQ6a5g0cdq1glBocK6juw9Ajfvg8+5Q8b/4MRv3PeDNkDucjmRI1PAinNBSN1ajTgaBRhjaYc5v/oN/Uz6S8qoZ3h7z1jbl+pSnmzNU+KzJfHC7sHr2duQSGyig= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741970187; c=relaxed/simple; bh=V9tDjb3FRXiUNX1G6EF3G2WC8Di0nWlqSJnRURIssMU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LzJnuL1H9DrDHDjn3IT41AZFa+M53WOwWPlqATHhB2vifVGK9KNnx8OU710LnEc+FYKCIKnry5NvbBV+HmVht/wgKWJh0raMtrPAMHks9FZwIqDQVZNgxm52dD7BgpS4wdKSz9BynhBlbzoU2nA5MwLdXGZcljL+fD/Qxb88qAc= 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=jpbCqaR+; 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="jpbCqaR+" Received: by mail-wm1-f54.google.com with SMTP id 5b1f17b1804b1-4394036c0efso15619185e9.2 for ; Fri, 14 Mar 2025 09:36:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741970183; x=1742574983; 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=jpbCqaR+2n9NR5UloQpSwRAigTmaIzFx92Er6ZF7ITkjCN1AU/u9APUn34TZs/L6KW adWydoYSYOpjPG+zBuIcqzrjVnE35FiGz7DkBq8yb+jwK5zx1qJrOeai29Vxl/SqaTAA /hXjZEtF0g5hK5Fd7IkFs56tzBTff0mDfLrrYm9KMa9kz8L3RH6xa2gpedhd+j3NhjCv N+pw7yIukA6METRSciqguPftEnKSisRv1YH7E5TjnO9i8piFdoW8EifnzRMGXZpoxWdQ D2dLKPShYwDhcF8c3Xzhs+DPVvzsBoz+jx0k7SDvUe50uwA/FXsJWhFgk1aJhUyThZML 2HMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741970183; x=1742574983; 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=YjtmrayzOmrFw+GXkMozYArZ5xwbq7AeD7JYC3Cst42z0/fGSb1IpSpgt46dCBTZqI cl0/b0EOX1VnP8syeYFBQ7++Zh7rAEKUT0yr8QQ3LfNEW9rj1RVs+WGzVqVa2cEPJr82 Zt1dG2Ha5w02Jc/V4z2Hr7lu2n7CBI5+PYUtuqRH/jNPTRqCCq1SJGrP/Hr6LAD6hG1g 6LXHU5UvAjvUB0LAvSwXAMh4Z+b9eO1RbezJisW5i1PzE2+DZb7ESaZJHD+by9TOIULD sPLESPDes+tngkv8g6so9GwXlN2GpMTZ2pNfm0f1M7IiSyYtLVQV3snV9ySlDqtYvORA RU+g== X-Forwarded-Encrypted: i=1; AJvYcCXuMsBeO7x4t5Fqrf3kTzU1qOoIN+BEJFUZc/SJFa0eUV7cNycYJp+LLlqd8mRPsZLBckIgXXzgAC5MxF4=@vger.kernel.org X-Gm-Message-State: AOJu0Yxty56Yhkt3UrsiF3eA/5kzEDSxMXk1YijztEHxZRu/9sh9n2vJ n4wcZyknWXglKBkCPlWM55eOsEHDCNB5966f9Wmqnav3Ka24VH5AI8ltsqJvyYQ= X-Gm-Gg: ASbGncsbHMdRlhl4M1JqQpu9TAIHtvqGSOljS5RjTFWqzRzOyj3qU8PplbdBoeJnj6T ccLmxlAVqgBTyhUYe5q1LOmUbi78/0KTVa3q3otYxRK6jaQGQoeHGX3HXf2tHMMiwIugjZqtE/5 I/0ysL0MRD6UaLWgg5mDZ76lq+LL1FHHtFicJ+UCOQoqk3+vUhZLolkGgqCCyjW7RvooQ60mvqR VC9GXbjvyr1M7V8Nvc2sRnZwzw3nBDUipmbQtv542lMivkdvMIDA+krl6B/nOowMrvMOiKPa+3p YmblZW+itYWpQG0o6YMAFIvIZVgkDJpb3uY0JX4PKEepf+O1Py86 X-Google-Smtp-Source: AGHT+IGLcB66jFty7SmLoFDrxbGmK12tydtLPNrviGBCwl5ICgT0Zi1i8ozVSW+qz4Fk9UhL6bGBgg== X-Received: by 2002:a05:600c:150a:b0:43d:2313:7b4a with SMTP id 5b1f17b1804b1-43d23137bd4mr21196815e9.3.1741970182967; Fri, 14 Mar 2025 09:36:22 -0700 (PDT) Received: from vingu-cube.. ([2a01:e0a:f:6020:329b:9a6:20f4:3754]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-395cb40cd78sm6072925f8f.78.2025.03.14.09.36.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Mar 2025 09:36:21 -0700 (PDT) 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 v6] energy model: Remove unused em_cpu_energy() Date: Fri, 14 Mar 2025 17:36:11 +0100 Message-ID: <20250314163614.1356125-5-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250314163614.1356125-1-vincent.guittot@linaro.org> References: <20250314163614.1356125-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 Wed Dec 17 19:03:23 2025 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (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 644432045AC for ; Fri, 14 Mar 2025 16:36:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741970188; cv=none; b=krzkfkOrA4dLdw+JFThuqTdyK0IEO0/l0ZwLDBdz6vhtuoqHSBTaekPzWbwsK3MrVWLOEUcIUJWp5cpTa5FwEh7EncH4eufHDHjiYbBNGfWZGCltIIW+7TaU+MQQxS5Vj6z7rcP7kr37ri2o0Oph/7QfVVMJ5khfSDR660SRs5k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741970188; c=relaxed/simple; bh=zfPl9MyRhHUFx5JuHyEuOGpXeAcBqo+G+6qZNjgbWeY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ej7BDtvCmyPMmXALEvtxIea+gIfqT2abyDr0oynXk7TG6EpJJh5il0FSSb9YoM3MsnB0tx8OSYOWb8Jwtbeb0WBefvN8sbJgIB1yBjbRQhuCBls7TYbaelxyoe6qujNC8COrQKOck+lcgpLd6J2/61gPOqWf0eU2UVU1zUWHV1k= 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=YY5PRdk0; arc=none smtp.client-ip=209.85.221.53 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="YY5PRdk0" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-39129fc51f8so2038338f8f.0 for ; Fri, 14 Mar 2025 09:36:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741970184; x=1742574984; 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=ptn5ue5nomW76WbcZrd99QQFqHz88NDJ1b07bPRv0fA=; b=YY5PRdk0/a/oWUgglSvx8Yq2Pre+R0bPEFzDv5GSztbvcDU/5fOANo2wCDD/N+3546 LzVvRum2tjYipgWjfZJZtwOzH1q0iI8t1cw5wzqrpJ8Zt5r+AlNllykFGHzzTNK30zXU m/le3gGjV4G8GZYu4g/qs2jcpz+sac10iXihmE80sYul8jhYsOiOMO73M/nz2dB038xS P/RReeZVKTxBilEJk2z7/9FwxYdUtpGDAOm9GBRQYSOffAujye2u78r210rCjTyWHGi9 eCOHHMvPLImbLBzrcdgcByqzvZcGPGr9qZGon5sHCt0/yS/QiG3I3EOrrPdpd4GYEaq3 Cacw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741970184; x=1742574984; 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=ptn5ue5nomW76WbcZrd99QQFqHz88NDJ1b07bPRv0fA=; b=mE7FhZ/LBpKZT20Tei0ap0rVFEp2eSYVkM7/Hw2w/qk/79hAmx4zoNSL2XN8yM8+91 Xezm7aTENGtIhMyvbYgJs2yFn6AxEbhwykwxqD2jBoWlf6H8aN1T7/hC2bbIsLYje3Fw Gf7pqAV+2bM2o3rVkxU0zXk9HQJawkvRnxAiJmhU3p435tmBf0gkeMMYi+1Z8I89Izqt x0/1d27YpKRpV+hoqK+gNQk/D3rce2JXn6Q6VkOsG9wviYNGO/V+WTyA7Js7P3ME/y7L XYEfeSXUp71+uYsHxaF07X7P0qu9U+17gor6MtXE3o8vCLCxWbsskEJliGRaBDNGdLpb hDRw== X-Forwarded-Encrypted: i=1; AJvYcCWNRdLpxnPneWZrkXK6P+SFoajl5uI8M6JjIVgYPT2e7cHIp4VilIMb/BfQwUP5oR+rWnNgOpB7asnWdWk=@vger.kernel.org X-Gm-Message-State: AOJu0YzqVkEDMWMMqrTZloVJX94sz+d3f+lqeqsvrNoq1f7+42AVjunz 09tNfb4fHT+LCHGepXRcvui2jWJ4ey1vj1i6FofR1+V0eT56zm8lSNH7o7BCY4w= X-Gm-Gg: ASbGncudyit8cjVZqQ+mYadOxJE2pGdD8ALtEOdRp+DXgIRrQZtbq3jgkFdoPlkdkYY VioUxRwXSq5jDwtT6uzxBnNUyl2SOKzSOfqjCtiX5pzn705JyseqbkmGoqP2lX2C2PVGo9UpI0y XI0qKZpZUnoapPPajLDH/9giWyROplcd9PdEy48v12Qq5heMboB/mGHJZVEsInj+4A+e2jb85wQ z9fl3zDVT4SpHvdn4FRI7fcPq7YNn11WxdxUlEUyNLxKf+uCWiajPsqjWrgf3WJFoCFjd++JOIl 0KJiKJazYN5p0wfZZkhPNXQKh5E18ftim1gA/bgdJjjvlFW/f3Vn X-Google-Smtp-Source: AGHT+IEMJJw1TuZxTASB021QRnNdTISAQj7oeq45fYkNbkF8F4bcckk9ewi8RoxByDAptytLNc0sQw== X-Received: by 2002:a5d:47cc:0:b0:391:3f4f:a17f with SMTP id ffacd0b85a97d-3971ee43fc3mr4704671f8f.42.1741970184408; Fri, 14 Mar 2025 09:36:24 -0700 (PDT) Received: from vingu-cube.. ([2a01:e0a:f:6020:329b:9a6:20f4:3754]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-395cb40cd78sm6072925f8f.78.2025.03.14.09.36.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Mar 2025 09:36:23 -0700 (PDT) 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 v6] sched/fair: Add push task mechanism for EAS Date: Fri, 14 Mar 2025 17:36:12 +0100 Message-ID: <20250314163614.1356125-6-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250314163614.1356125-1-vincent.guittot@linaro.org> References: <20250314163614.1356125-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 fa23e48c1965..9a95d2eb168e 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -7053,6 +7053,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 /* @@ -7083,6 +7084,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); @@ -8591,6 +8594,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, @@ -8760,6 +8954,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 @@ -8949,6 +9147,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 @@ -9021,6 +9225,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 023b844159c9..51dd9bc55a0d 100644 --- a/kernel/sched/sched.h +++ b/kernel/sched/sched.h @@ -689,6 +689,8 @@ struct cfs_rq { unsigned long runnable_avg; } removed; =20 + struct plist_head pushable_tasks; + #ifdef CONFIG_FAIR_GROUP_SCHED u64 last_update_tg_load_avg; unsigned long tg_load_avg_contrib; --=20 2.43.0 From nobody Wed Dec 17 19:03:23 2025 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) (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 1B3B1204683 for ; Fri, 14 Mar 2025 16:36:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741970190; cv=none; b=cS5O60qoIgf0z48hBoxDoaL9975eJ59Gc+MSw5TeANxthMhXAAY4esiwshQ+nDfaOMlyGTANyn18AwJTrvG1y8Pro5ilT/DeyGQasW3XOicAa1Ve30S2Rik1GBReJICfEV/voB8jIUYyyfW15RSea+7S+l34DX9lIUvVbCmiHbU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741970190; c=relaxed/simple; bh=lWkbNwnU42/3UeHrOSQyV7bTNoivQuIxQ1vjh4Mq5ZI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=J61uWwMmRW2/gqGEVJDtYNtb3xJlwC3jQR+zYkogwjEoaob67qzoQfd9KkCCPCIZlVbKQL56qcTo2u6uanfShDqgmG/8DpCEhsnZ9edYcOtNOT5BXpTGP/POoy6UJ32q+gdbqMpOC2d+VlU2Hhe4UXF5bPOpNIX0s+l9KRLzbfw= 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=xGdU/cef; arc=none smtp.client-ip=209.85.221.44 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="xGdU/cef" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-388cae9eb9fso1307615f8f.3 for ; Fri, 14 Mar 2025 09:36:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741970186; x=1742574986; 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=HssPI0cKmc3x85MzrxtPJaiP5XP5Yw7gWJ7O5ruEo5I=; b=xGdU/ceflSxWPuMrWc8VKWaeDHspRWExWxfqP0o7eDVQIXZUzfPx+UdUrgTXZd8iDv Zsn6ZBuP2IJOerCa7TpJXrSDw39gzLn26TI6ai/fXrBn78glRmMszBDdJ8lYTSMSrVGv /E+2bXhy8dKyep+uoet4FKPuPLErgm22efqTvHweypAXtOnqiQTL+RW3966AqMBhE+tH 4cvm1q9RysD+jbG07kBufkNYQfQqS5LRWqwMPlgQk3fx/h63RHd6/B+jf2shFk2izLnn wrD4s+yTiw2so6Kn4FvFtwr2vvqisSjK61+3IYhsO+QaFbWTN4j30EBi2mlYVRD46SpS rWxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741970186; x=1742574986; 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=HssPI0cKmc3x85MzrxtPJaiP5XP5Yw7gWJ7O5ruEo5I=; b=TJVPzNBZZMofycZWKnunaGBm91Q3BlPEwEIbgp966ZhiHbBntd9l/VG04P7sDgsY4z 2yiUAzgVFbHQf7u5dN2+TbqsAMYR/nRIcAFUrXEybapB+4MvvuA4DuPB+SvuFy1mln6P lrFn5OhCiE7O/qbokzluJMJi0SjhXJlQt4Lysum7OnZrMplSZn7WJGI0nticSdy4njT2 arMUqsIa6BlYVcDvdy2k729TUzxfdevTqjFincs9a/JPcYMnxDUoMp/TgqIt7uuB1AEL l6PE7WEJcTAbklST9kTrrZHau0fR05/TndXFiwVuuP1EcXN0qNeY3Fg1Oh/fozsdppL3 HKNQ== X-Forwarded-Encrypted: i=1; AJvYcCVchhRROc2ZcYkFRcBDDRhjzemaGey81f2i+MUmJS1eayn+VfeD5nZfRMqwVeE9syq8wIOaf7hU4ytKZ4I=@vger.kernel.org X-Gm-Message-State: AOJu0YwOes2pK7Rv4KLOLrm2nXXfUjxt4PZf0BHQYIfE01JemjNBnSV8 Bzs7WSnBYd5WC5Bj59GQ/lTYS6D+emi8yA/zuwA2BtF0y58UbkLEITjLrOcZUEQ= X-Gm-Gg: ASbGnctwtbwvkK4h4GXuriX+6CpgotCUnssucXb0YL+XDa1oNMSdbNc1Mcy1RPZ86p0 cFsaTrCKLxllgXSDpYB7ykgbJsT6FmHn3YZTl+6PGA0g1+LbTc76Ag8wiAdmdky5L5PcSy73aTQ f6uS3fvHhfkNP3hiQrT4rjG4PUyBd8S8jtXTUjvsSpRW7BRJI1AVLntUoUrF3tWuvYQ1wtRYjGk TcmA4ReLtr8kneS7CtwniTWWv0FtXQjtfxfF/YA41xPUtKQ82VB773+5O652jaF25vKdUhA+uGq QV2TkoehSCHdCYJUrdngPLZ83Fp1TAcS5Sjf7z2OAN6+CxS/cOWo4+3BHaF61m0= X-Google-Smtp-Source: AGHT+IEfcbaC7/dP12XC4RIyye8JyqalwZZXx4m/QKC8CumMgy5dhoxCd5fKQUNt5trjL+7P/A45EA== X-Received: by 2002:a05:6000:1a87:b0:390:f0ff:2c1c with SMTP id ffacd0b85a97d-3971e96b183mr3622548f8f.18.1741970185902; Fri, 14 Mar 2025 09:36:25 -0700 (PDT) Received: from vingu-cube.. ([2a01:e0a:f:6020:329b:9a6:20f4:3754]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-395cb40cd78sm6072925f8f.78.2025.03.14.09.36.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Mar 2025 09:36:24 -0700 (PDT) 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 v6] sched/fair: Add misfit case to push task mecanism for EAS Date: Fri, 14 Mar 2025 17:36:13 +0100 Message-ID: <20250314163614.1356125-7-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250314163614.1356125-1-vincent.guittot@linaro.org> References: <20250314163614.1356125-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 9a95d2eb168e..81b4d09c6c5b 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -8510,6 +8510,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. @@ -8615,6 +8617,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 @@ -8626,33 +8631,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 @@ -8663,13 +8668,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) @@ -8954,7 +8961,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 Wed Dec 17 19:03:23 2025 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 259892046A9 for ; Fri, 14 Mar 2025 16:36:28 +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=1741970190; cv=none; b=btnd4WdDa3cp9aWZdiAjBmbrq+lwex0jh5BOWgC1nL+4pTY3r+sW0cIxNulUae0HybHa0tMz+7C6qHGkFmrC6c2LrGVg4DEKcpCg/DI4QKZwD1RgFyMLb7s7mHgpJiHsApY/x06HKH7yek57DSkVl1Ozct8gogUFuiwUP5GLCp0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741970190; c=relaxed/simple; bh=tf8viaA8TSt7KEXF0YCkxqhusUddFUMNOwh9LfMwBVQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oI3bVz/IKTfiavqCfDQ+H2qH7WwBmdNdHC12PNTdpfIE3GQcRPicQ1PXqKlxc/i1uLFhGL/gv7uiEbuvoZIRhWGmDGOUxco4hf3pgFfYTxS8jfcOMH10M1qtXf7UyLtvzHKRFET9Ic7a0J9GVoi+OciimMNXwBQp0PoSvrFvoVQ= 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=K1R4mrCy; 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="K1R4mrCy" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-43cfe63c592so21595295e9.2 for ; Fri, 14 Mar 2025 09:36:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1741970187; x=1742574987; 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=yFQ2HcBNdMgNlOvbPjBVDvOsboRXSnkDaPC5bffTGtU=; b=K1R4mrCybQlJ9n2cSasIPHwIq2V1MAK4I3mjyuTKtGSIDY39cqd166PKMmMnT8tu+m /sPoveNiPVRkXuuhoQVewFU0fmiGVWfsYdv0X7E+IOtHnYHWslAsK/68Rq1ygsxyedx+ WEwCzd3Bdbj0PwpAO9o+zFBd4VV0pQ0uN8IBBaY04J7U/2RKKOWlOqX0lpqxJynTXmyE 8ocqsFzAGLpbk9f1iBmLsmOxlEJWrg2CO+Dw4PiIG6cWKpS0nTxyFXY9dObfVacXW66M WbJ1aNAaPk1bwfvVEEYN4mTjh9RIqCYyM7oFddTq90hFqYnAfNVoqicXhnkOD5MMGQ4M ZBKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741970187; x=1742574987; 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=yFQ2HcBNdMgNlOvbPjBVDvOsboRXSnkDaPC5bffTGtU=; b=lmDMEhoNmY9C114rzeLa5oQHZwURvuOiedoHk4UZtC2QKCCHZruB4AW3Vw3CN//EcY fhAjMwdN2HPuaXZQ74Pcppd9m+NPchitlJerG1JGQRIzb63w1kXcjpoxxIWNpwgBULPd SZ31RGWom0GkL8+5xWPdNOykbypTAkxj0FnatG9vOU6mDpBRnO28FcDyLEszohEMKIKC cNyCkDTqQTwzHcw458MLobP2/AmHoOxD67PECL9xyKsSLmCANsNeew4HF3YvrEw5xbLE 9Efj+1Dv+AfaafNrUz3/m0JunztTprQyXhIfHtovPnxdLWUgfrSjAoPdhNAjBHTg95QF 86Eg== X-Forwarded-Encrypted: i=1; AJvYcCWn60X3obGMjFqHZpFVnolPKvaXGA41kCXU9btiNHZ7ODyfMy0nbpwb4vq5keBqEb/LKLS7GhYCQ7Q/jac=@vger.kernel.org X-Gm-Message-State: AOJu0YxAqaj0DsV114iCy8dOi2LcEIJraelF+5ONR/YFLEJnjBesBad2 +t96aLvqf9H8EyRHDPZJNvwfH8cg1CKYsBsLJGxNBaUwbl5v6zRw4XGtnyaN4Tw= X-Gm-Gg: ASbGncv8FhwYv486TwvxK2cWz1OUkfOto1wL2TRere0TH7BLNsSSusy4QU921J1zPgZ X1kWbdawBhNRaHM7jyj468UuONt4z1FiZ96+iDnKzfHWuViPaWLEH59WC/zkN8WgMlbqM9geA3I pSmpwZcQV6nRYAanH/RwSMFkvMwZQFGmy0zCJ1rtgYb6CKfEv+NBz8/UxyzaYkkBR+BF3YtA6zV Omh7vlnif2pG6KESJE1hTSD2p1zog4m0miBv1QoeS4UrjFwea4jb8Y05/Zvx/a3tnROkHuf2bS8 Rk99VxTyWwb6YOHPKVvpoOwwYY+1tHakkts2POqaQ4qTpS2cRvdp X-Google-Smtp-Source: AGHT+IHwqqbH2KKThrp6aGD27BgSua0fDndi+WcuANf1Nfq957/kPQaVHQrKzQn6hgjv6J0UTw96fQ== X-Received: by 2002:adf:ab0b:0:b0:390:d990:823 with SMTP id ffacd0b85a97d-3971d236f2bmr4341287f8f.13.1741970187365; Fri, 14 Mar 2025 09:36:27 -0700 (PDT) Received: from vingu-cube.. ([2a01:e0a:f:6020:329b:9a6:20f4:3754]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-395cb40cd78sm6072925f8f.78.2025.03.14.09.36.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Mar 2025 09:36:26 -0700 (PDT) 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 v6] sched/fair: Update overutilized detection Date: Fri, 14 Mar 2025 17:36:14 +0100 Message-ID: <20250314163614.1356125-8-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250314163614.1356125-1-vincent.guittot@linaro.org> References: <20250314163614.1356125-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 81b4d09c6c5b..761543a45510 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -6833,16 +6833,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