From nobody Tue Oct 7 17:48:35 2025 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (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 C94D12E5439 for ; Tue, 8 Jul 2025 16:56:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751993800; cv=none; b=kC5OzVoKHhOI8ZenihZVim8MevnB69PE1uz9jq9N6KWbkIV6yTGBX/S2qW68W9WXGKN/E0NUxtdqLiImnr0RHT6qET4i9I5OGO7GRz4mqp0MKrSCmOblEfoKvtcESfWOhzkNhmhQJ5mChL4HdAl0pG5UdY3g4XbJhnIHdycJw2k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751993800; c=relaxed/simple; bh=ydZRP6+llQn1XG0Wed/Oa5HzhIcOTAV7GgM8Xhyvv10=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YtgupIR5aFe12aeqDZ1/AYzNB1GngNzMryWorrWB5ywM2dQ5qWAMbYW4JDxTfL9tpPyfbTLkkk08yPzcx5n24V63sMVFydqGFhhAuXSWL4O2s+67ngwewAfFnCuzcJ/UJsT1UkYlc66tudrkauIcIsRxo4FSMkZ1nT6n21ePBgo= 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=KGGbi5My; arc=none smtp.client-ip=209.85.128.52 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="KGGbi5My" Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-453066fad06so33051975e9.2 for ; Tue, 08 Jul 2025 09:56:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1751993797; x=1752598597; 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=AkQp02knqPCKiukiiHCeRaV1SL9ZYAgdUSB+fSbfNIY=; b=KGGbi5My0ceUWYViUlK6m8kbO4tUbQxojY22lnE5EQYrrGy2fCuoD/TpaV67jfL2m+ AjsSWbKgLNmbOikil2AKmZleYqpWep+C9eEhGpk7bHFW2AEm333ucqEmh6Joiwxuu+L6 33EqcSfk6juOY3Mvv79TXzbPZj6CVVJL2lK8fi0xe+2iHjUbEt3xam6UqEhUj7uHAxtn PrsYy04v4F6rDHC+uuq3NchGU1LFPAEL//jkQlnjRw/2UxB6EUzLByHc2szqFZr8HvB6 X2TvSh0iAno1Hn6+ro63hwZeMhk1cl+ypyLhb6RoYoSpd+Olpqb9rbMjVzN3sPXnVUXL L8aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751993797; x=1752598597; 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=AkQp02knqPCKiukiiHCeRaV1SL9ZYAgdUSB+fSbfNIY=; b=fufziMA/5NEmliiDMBhcAyOJ1JSRvat0iH+uvban+HSDRleOnVCHxEvwvNLVH8kOaj bAO5sKaRfxe/wsnkVFdWgzlLuEFRo0DoF1dtuUZ9t1Q3JhLqlrDfnh7bq1fsmZwQ0E/f eaVB3F/abYth3GcJDLmr63TyuL3XQ8OpY2y1e6UyBlF1p6LbLpoxt3YcW+5qzJTFWx4X tD8+tIyo50v0uyD4pigcr25T29nHi41PCSOSp+znZ7xV+T6akwrOHztdndOmTxiCug3h RjgW8lt3r+JUep13L+E6cbg/9Wn6Hbt00B1Tv/Bw+23fuKr+L0HGgeBX63mz/rdd2arW Zagg== X-Forwarded-Encrypted: i=1; AJvYcCV3cug+hQcVPMTki8+HoeRkAt/jqaOt5yvKgDRvL/gKNl3/WDoNeFsB1dNxtY+1evlpN7dLwnfQyelhph8=@vger.kernel.org X-Gm-Message-State: AOJu0YwjpdfqpjMw7QO1eFzrGhMCFYacNB/lUv4txEpAK9AWG23SM0S6 1wCY2/QP3ObMh5o5JNUvK3RTBzrlVsQgLlot4jOyNkZ7jEcFzLMldnYZuwn7WXL6aN0= X-Gm-Gg: ASbGncukhr6qeaabDJgQh64eiIM4MZIumYRgkRQpkK5WwA7Xma4iQ77E85IRJE5fUID ePaWe0F9KgqxP5xR8AVjVQspJG/uCXUWC8/DqnX0yfEjqWhYxBaMv53EfHNlHsOie7WR401CDns 9YJYMS6YS8khO2NHsiypLIpt+OJ/AP1jSSt2ScEM9ynkZNt65M4rcEMJvNKlxRxnsv8Kock2Q+g Rf2ZbyFU9Qoft89LABggnCNB7iERacK92Wge7YKXAEExt1RlhClr65ch2Zg5GetIz4zbS0pL+IC EyLbPncMuSCWAiLvqcYRQquiJ70MH0WK7LeUpTsdg1xZOWv0AQxiHz2E7Wcjl8XhSbnptWg= X-Google-Smtp-Source: AGHT+IElq5a9wfG2FKaD6LJBmCIfVXPss7CPTB2Oy9YVsJNsJezn70nwkPSvkFe5k+j5shzq9IiDZA== X-Received: by 2002:a05:600c:1c1b:b0:445:1984:2479 with SMTP id 5b1f17b1804b1-454d3882436mr2357545e9.5.1751993796936; Tue, 08 Jul 2025 09:56:36 -0700 (PDT) Received: from vingu-cube.. ([2a01:e0a:f:6020:2a4a:c4af:2315:5f08]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-454cd3d7d51sm27295965e9.29.2025.07.08.09.56.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Jul 2025 09:56:34 -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, dhaval@gianis.ca, linux-kernel@vger.kernel.org Cc: Vincent Guittot Subject: [PATCH v3 2/6] sched/fair: Fix NO_RUN_TO_PARITY case Date: Tue, 8 Jul 2025 18:56:26 +0200 Message-ID: <20250708165630.1948751-3-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250708165630.1948751-1-vincent.guittot@linaro.org> References: <20250708165630.1948751-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" EEVDF expects the scheduler to allocate a time quantum to the selected entity and then pick a new entity for next quantum. Although this notion of time quantum is not strictly doable in our case, we can ensure a minimum runtime for each task most of the time and pick a new entity after a minimum time has elapsed. Reuse the slice protection of run to parity to ensure such runtime quantum. Signed-off-by: Vincent Guittot --- include/linux/sched.h | 10 +++++++++- kernel/sched/fair.c | 30 +++++++++++++++++++----------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/include/linux/sched.h b/include/linux/sched.h index eec6b225e9d1..75579f2fb009 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -583,7 +583,15 @@ struct sched_entity { u64 sum_exec_runtime; u64 prev_sum_exec_runtime; u64 vruntime; - s64 vlag; + union { + /* + * When !@on_rq this field is vlag. + * When cfs_rq->curr =3D=3D se (which implies @on_rq) + * this field is vprot. See protect_slice(). + */ + s64 vlag; + u64 vprot; + }; u64 slice; =20 u64 nr_migrations; diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 43712403ec98..97cf99bb71d6 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -882,23 +882,34 @@ struct sched_entity *__pick_first_entity(struct cfs_r= q *cfs_rq) } =20 /* - * HACK, stash a copy of deadline at the point of pick in vlag, - * which isn't used until dequeue. + * Set the vruntime up to which an entity can run before looking + * for another entity to pick. + * In case of run to parity, we protect the entity up to its deadline. + * When run to parity is disabled, we give a minimum quantum to the running + * entity to ensure progress. */ static inline void set_protect_slice(struct sched_entity *se) { - se->vlag =3D se->deadline; + u64 quantum =3D se->slice; + + if (!sched_feat(RUN_TO_PARITY)) + quantum =3D min(quantum, normalized_sysctl_sched_base_slice); + + if (quantum !=3D se->slice) + se->vprot =3D min_vruntime(se->deadline, se->vruntime + calc_delta_fair(= quantum, se)); + else + se->vprot =3D se->deadline; } =20 static inline bool protect_slice(struct sched_entity *se) { - return se->vlag =3D=3D se->deadline; + return ((s64)(se->vprot - se->vruntime) > 0); } =20 static inline void cancel_protect_slice(struct sched_entity *se) { if (protect_slice(se)) - se->vlag =3D se->deadline + 1; + se->vprot =3D se->vruntime; } =20 /* @@ -937,7 +948,7 @@ static struct sched_entity *pick_eevdf(struct cfs_rq *c= fs_rq) if (curr && (!curr->on_rq || !entity_eligible(cfs_rq, curr))) curr =3D NULL; =20 - if (sched_feat(RUN_TO_PARITY) && curr && protect_slice(curr)) + if (curr && protect_slice(curr)) return curr; =20 /* Pick the leftmost entity if it's eligible */ @@ -1156,11 +1167,8 @@ static inline void update_curr_task(struct task_stru= ct *p, s64 delta_exec) cgroup_account_cputime(p, delta_exec); } =20 -static inline bool did_preempt_short(struct cfs_rq *cfs_rq, struct sched_e= ntity *curr) +static inline bool resched_next_quantum(struct cfs_rq *cfs_rq, struct sche= d_entity *curr) { - if (!sched_feat(PREEMPT_SHORT)) - return false; - if (protect_slice(curr)) return false; =20 @@ -1248,7 +1256,7 @@ static void update_curr(struct cfs_rq *cfs_rq) if (cfs_rq->nr_queued =3D=3D 1) return; =20 - if (resched || did_preempt_short(cfs_rq, curr)) { + if (resched || resched_next_quantum(cfs_rq, curr)) { resched_curr_lazy(rq); clear_buddies(cfs_rq, curr); } --=20 2.43.0