From nobody Tue Oct 7 22:40:48 2025 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 A1DB682C60 for ; Fri, 4 Jul 2025 14:36:19 +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=1751639781; cv=none; b=GN6CXiyQUNMaz9Ms4NEah/8C0UrhKYS8cdTrrMXUr1xBKRBfGXb6d3fuKyRCJUDddPTEg5gEYAegaoRG7qPTc5xjq+EFIZlKxEehjAAV45S2iVqH2rzRc/oQNzR5x+Du6xFSoYzBBUfL7u1xlTw+4gyVF8MD3pTyWaw6/WJt5RY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751639781; c=relaxed/simple; bh=AhbBIgHkLNVCNMm17JJi+tNpziBECUFPFNFEnQtPCi0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MRqLl0Eh5vSTv3tZNTfurajoP4dzWOHQwZx5qsREIGaEuKkaBAgUZdBNdK5FO28XZ7f5483bxz7x8Q7oBf1UoZ71IQM/fyBi+uIowdJzH1ViEB5obwTYZLacrZ8A94o9kwd0N0vPL4gusQ5tyeUFjpspYtIHyDlmfDVFJXIoL28= 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=LBrjTStw; 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="LBrjTStw" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-451d7b50815so7776945e9.2 for ; Fri, 04 Jul 2025 07:36:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1751639778; x=1752244578; 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=4Hs2oYF3e3J4FN8zRTDauoaC2/4C3r7PLe1ATMwxGhY=; b=LBrjTStwPVZTMHr4KltOxl/G/bDJqOq7OpNs5sFhYwOAtT5X8J2xFNTnfVB70KkXwr UStiVz+lIFq2cM+fMni5XI3ui1Z9kOPa/dvhpPkON3A85Y6BRT2eMCntIffVmLkqWhg/ IXKSCSG4XwR5QlZyfNGbzZ+6sYaCFlkp9br+b9OTX5a8De31AkpMRQE4CedTWeSANInX JoIDB0c3q7qgIhVsHfNND9vve4Mdy8t2S4/FY7bOz9F+DOed7XWLELflveoG9Ie32Hd7 gcaDB3dXStdlY24x1HbCPECspOA+wDrzJ1mqHJydBR5yyFFyMBmgj0fkXvl9rtSyDiup SCrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751639778; x=1752244578; 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=4Hs2oYF3e3J4FN8zRTDauoaC2/4C3r7PLe1ATMwxGhY=; b=Zr9jHhn1PWDkKJ++MVRxO1n3e4qntFtzCVLyU8jOJg29L0b+HNnrevb8jRCB3bUbpu avy1jkab3h6kOf0OCTAN+BaY5SPnsNzblRtQMpRsr/WlFcrYpDCaB92g1qy2CzTe1xw8 /Z4m22xGQa73iGN1E2UFhDFafU4YMM6OfUp+voI9c0OBtKDDW6vuhRQfsxI7idlTLwDG 9EM+7sdb1V/A5ADFkzEF9dvzmZC2Yjnbui6shjCW6mKGYey6Lm8ChnUz+WJH+cz3xuIL 55r5n0C57ND2xHUbxYEgCLpS+ugcJz3NBdxxE0g4C5j1FJWC1EWBm5KHXO2LBDrCS5hg vJJg== X-Forwarded-Encrypted: i=1; AJvYcCW/zi1FnJvjLY8qKe1yPhfuOQ9/Ca6L87DTqVazxriLd98/qbnpjXFqC+SNjZZeXJC7zqXQp2mUa65NpIM=@vger.kernel.org X-Gm-Message-State: AOJu0YwMvSV2Xh3y1NPpCjEm3IVhb2YoyiswgO4Oe1OGdBWPmX1ApPeT yraRhaDtT45Hm7MpgaNPLI6LaqGiRUuW2Kd3HGZeuIFZu1Om/3oojr3xqp3KlIKvO30= X-Gm-Gg: ASbGncs9wra5O2QrpS300nGRmAaeAOOzmDIVJhJiJw7a8dgobwzetutn0RSvekFvMuE vy/xAxDbRdtVAaP9VU2B0Hmbo8k5f5KcAmuSk8f9mn962YuVhwF2WPH5JrvM1JcoZIb5C5R8DYh p/Viwp+XrIxwzohKcR82bUq++AuUFAeG4lam4FXGCit2gVqafvs0VAtW3CWkSvrPPx3rU3Cxs8m RDLeEKzvmNm329zh2F1RCj7Hp4IpCkYHJjNOCUdVbDFBRuLLJ/nz8bWFHBI4v1IOzJ/Lu+D5cCL zYngDXGK3GjRhoo20AeidVDqP1pQV0KwSindW9ohXEAWm/0Ps34bNDx8f359QdwEl3s1clwV1/v 3VHGjYA== X-Google-Smtp-Source: AGHT+IGVXJLNTqwK5LP3uMmOBu1FgMt6ZJr2cqez2v1jW6Q3YnHqoor2gU+ujcF9q8/DDUaMcLVpiw== X-Received: by 2002:a05:600c:8b84:b0:442:f4a3:9388 with SMTP id 5b1f17b1804b1-454b929f15emr4298475e9.19.1751639777949; Fri, 04 Jul 2025 07:36:17 -0700 (PDT) Received: from vingu-cube.. ([2a01:e0a:f:6020:7ff5:bbf8:9357:784a]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b4708d0beesm2690186f8f.36.2025.07.04.07.36.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Jul 2025 07:36:16 -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 v2 1/6] sched/fair: Use protect_slice() instead of direct comparison Date: Fri, 4 Jul 2025 16:36:07 +0200 Message-ID: <20250704143612.998419-2-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250704143612.998419-1-vincent.guittot@linaro.org> References: <20250704143612.998419-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" Replace the test by the relevant protect_slice() function. Signed-off-by: Vincent Guittot Reviewed-by: Dhaval Giani (AMD) --- kernel/sched/fair.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 7e2963efe800..43712403ec98 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -1161,7 +1161,7 @@ static inline bool did_preempt_short(struct cfs_rq *c= fs_rq, struct sched_entity if (!sched_feat(PREEMPT_SHORT)) return false; =20 - if (curr->vlag =3D=3D curr->deadline) + if (protect_slice(curr)) return false; =20 return !entity_eligible(cfs_rq, curr); --=20 2.43.0 From nobody Tue Oct 7 22:40:48 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 61EFC1D5160 for ; Fri, 4 Jul 2025 14:36:21 +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=1751639783; cv=none; b=SZN7tJyxYqAN9YwLc5P9aj7gnvoEB6Q5lgKYFbdYQ3fhCTEb8rqQuaH1AnZwTiS3crFF8dOW6vL5f01CK9ftsQ88HuBeHa0pQ6KtrofoswHQj8GCFOQlcwZe6SauR/ddTZwKhy/yfP2leNLwYK0BwMxFSR/JLluwERPCv+/3t18= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751639783; c=relaxed/simple; bh=IMei/8c6pmBRsKoOsdcBeLsytStZSh1iZmG6LyRhsE8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kp05G1iApLl08fdJylScvxe7jht6FFoHrtmEG52DHadVoZnwiYCjgJ4C/vGXMpnCCPd2CNnLT/5BLRA+wfFqlGB7B11RPYX9rWPLBWXoisqNUz6J722NLtObebIPtaycdcVprkoSSAWGAldh91OJ1uah8cazGEXN3A9gIOP0IsQ= 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=wANgeTTj; 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="wANgeTTj" Received: by mail-wr1-f44.google.com with SMTP id ffacd0b85a97d-3a6e8b1fa37so750212f8f.2 for ; Fri, 04 Jul 2025 07:36:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1751639780; x=1752244580; 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=bRdhy0PS9cNMbTKE1Nz2Cs1tq+5xbD9yaeYP0EZmAec=; b=wANgeTTj9beYhVEVRR+ZP5wb9NhD71gSh3+k1WbOuEntYduQqd7C9Z3pEIcuZR6o5P 4TTvzSGY/4OcH6v0wkI4jYgsVjSj+XzlmxsoQMnbjvMS6wnem8tvOIdtRKmj69pYfngs PAKNYSrIDjvWCktSo2FC7+zX5HQpPLdPw9CQijkCx4hAD9wHW32XC6C8+dA67l/LIcEc +sJV0i7HCURce5HTj7sXtBrZVxFJbRsG9+8I0KMWiG57KJRMrWB0baNR+jTW8TvV/mpJ IXncZMyqD0X4ix+2Tz1BGiqqxMi7eU8aBD10F/LhICLD2oANr4KMveugXKbTcBMTSa/B gA2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751639780; x=1752244580; 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=bRdhy0PS9cNMbTKE1Nz2Cs1tq+5xbD9yaeYP0EZmAec=; b=Yl42jg/RT2rDKrxqY26xaxy8/3lEsUAo9HZAVy6fhZue5ijmnthpOyfUr6XLCxzh6S i2t/AqB0M8efg3E6gVR9zHYqG6IJeL3i/pWhMTIGA0Flt4RMj7pgCRfkdbTJwenFNxK5 SeGn0UCQEhGaYplWN3+AZ8S0ovogqBZYI6PBTWlUxr/xVRGMiqOPIvzShvhLpW3YWnjk 5qP5LOEdW3gpbKmkl5cod+6S7ibP02dS7ghps7vWRKeLWe8UeXBLU9M3gWASIzeE71Tu LJXtFElvgXixQlHTCM6fWJK2Dt2wT1O/RPGGsgC5qv4MRDHZWOcpoIsB4vOcN3S9dimO 5tRQ== X-Forwarded-Encrypted: i=1; AJvYcCU4bo1VbwXl/2GCBi78LEuQBLOAPKkNcjKaW8tZbxmiHHq+fneMNu3nlUAlvCoRmQIBRD59erqYDK6qhLU=@vger.kernel.org X-Gm-Message-State: AOJu0YyjqLUKP+4x+/wdp4MciiJFE8TySt56e8BAHcdDkMN+L739mjii TJfobksm7RBzuXERI/z21xlM8VXXJEIcdxTgNE78twIsOZB1oemyyauKsDEMzz3ao0Q= X-Gm-Gg: ASbGnctfze3xa991fDcIzVXA+zbFbeB9nWCC0ZBCalKvh8aq8P9ZvoJrb5BD2UC185d m2LutiUH2DEyGWkU4IO+v5UXMfsC0Qb6TbVlNN3XAB5i8MurH9fVH1yvn5Top5SnyYSCNyhdz6x 0D/D+gXjshoWOzItLfz0xg7Zt5n6c1Q8f7Y+ESLmQfACyDjLG6V6QVg/0OisVwyBmyZEpHFXz01 NQOCCC28DIlg3lRZ9JW/LTbYX0+LExp04z4ZQmo48PWaK9nqpV6zv63o9uVZXwtDfJhDEYACW1C L+CW63I8OCZTZ6JeMIJI6FWG94rCA0mGN6U5H6PANs3g1CopbD2bl3G/CZQXsSIMHBj0aR9pr7s CT3Ofrg== X-Google-Smtp-Source: AGHT+IHujtNrBdBkPZltMcNKHstTitn0yuqfdi6VLO7pfyAgbQrIZyeba2N0/ZXwe11lmXMVQDfC8g== X-Received: by 2002:a05:6000:18ab:b0:3a4:eb7a:2cda with SMTP id ffacd0b85a97d-3b49660bfbdmr2674200f8f.30.1751639779682; Fri, 04 Jul 2025 07:36:19 -0700 (PDT) Received: from vingu-cube.. ([2a01:e0a:f:6020:7ff5:bbf8:9357:784a]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b4708d0beesm2690186f8f.36.2025.07.04.07.36.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Jul 2025 07: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, dhaval@gianis.ca, linux-kernel@vger.kernel.org Cc: Vincent Guittot Subject: [PATCH 2/6] sched/fair: Fix NO_RUN_TO_PARITY case Date: Fri, 4 Jul 2025 16:36:08 +0200 Message-ID: <20250704143612.998419-3-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250704143612.998419-1-vincent.guittot@linaro.org> References: <20250704143612.998419-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 minim time has elapsed. Reuse the slice protection of run to parity to ensure such runtime quantum. Signed-off-by: Vincent Guittot --- kernel/sched/fair.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 43712403ec98..0c1abb079ebb 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. + * HACK, Set the vruntime up to which an entity can run before picking ano= ther + * one, in vlag, which isn't used until dequeue. + * In case of run to parity, we let the entity run 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->vlag =3D min(se->deadline, se->vruntime + calc_delta_fair(quantum, s= e)); + else + se->vlag =3D se->deadline; } =20 static inline bool protect_slice(struct sched_entity *se) { - return se->vlag =3D=3D se->deadline; + return ((s64)(se->vlag - 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->vlag =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 From nobody Tue Oct 7 22:40:48 2025 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.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 2D0BF277C87 for ; Fri, 4 Jul 2025 14:36:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751639785; cv=none; b=fpvscjGd2161UgDggsA0tIDtQRJOjTzhfFlKDyiKGAOs7bOe/wvY8dYg2sdIbxPc3ta7WaukoycD7QHrRr0WwntIQiuZSGz9RRmEhxf4Y3vozphFICfzc8lncIhWj4n+gCot62/tKwfwqcCXqS30WgJA3q/9fpuYvw2vdTli/HM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751639785; c=relaxed/simple; bh=SmX4X7jKxJ5nUVgxLet7QD+gkKR7OJDqWd/BGi4oyAo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DWVozgXjsqfHanW3NbD8qHl6nJjqonZiJDqcIskRp8PxKSuW+IjM/5UVyaOuQFLkFepF8IPNAhsC3j4xUpZbYAoQQXKB9vei0OOGRqkXWlAju/H7c07WpW72p45nd3n2eF78P+llnDM5KdmufrcbpcuJC1HSbBamrTy/Tcwi+F0= 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=RxGvzKhe; arc=none smtp.client-ip=209.85.128.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="RxGvzKhe" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-450cb2ddd46so5425015e9.2 for ; Fri, 04 Jul 2025 07:36:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1751639781; x=1752244581; 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=gTVfhwaTdFeDSqwW2OxB6k98i/VGElPyJ4deZ0hrVio=; b=RxGvzKheMVjYxh9SG+bcCIUfUh7pC/3X4JSb35VYFm28QAq3uJ9XM2MD5FyzOj4nN+ 8om8fzmtPOUqRxyFLTy4hDbprgvkdETHpaINHLh7aBcrMycyjd7w+TeCtvqA/5sN5xEa DPo66o4CyTSbLgpRs5hdaON+tKt+jEpaBpmJa6L4cGETFqCbEp/V1r2/uWOUjbH8Ec/D pVTXSHkq/pJ3thf+S7/+0DnGispojIwZ1RB3+ewCpppTmK6jt+tJqXc7VkRPbuDhzRZH eSpaGTdnP6k9H+dFkbjTVlbFuiLjmoBfuB2kb6n8o9/8wfP3aFrOR20XCfvLFh30em5b kwkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751639781; x=1752244581; 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=gTVfhwaTdFeDSqwW2OxB6k98i/VGElPyJ4deZ0hrVio=; b=M3yVbYU5XiTFL851c/dxhQms+O5ebb4i+qHimQG4A2L40UrQN7aqYtPxYp9Y4RNLMo ItXGMSjd6Xc1gAa5uwNlRQmD4CckOn06rQPgJXEPRH2RokKY5D9LdHwVdRF8KBeBMeOI wSw+8LSoGSH7Vy5NXiQ5awZNHvuEeJh+KLmyEz+XQGE3KuFTmm0QC1u7DC/hKdd5/Gll IzZnjDskOwxzUj3zNNwpxKe6W7AonMmdM071Lye8HOI3FS3hDLittB374h0plv6yFa9u bD2F+A8rAkLWi96ZWCAC9Ehdw/HDG7Z4KGOW3HEx6vEVWpRD6hZoJZ3bNj5o6ZEFwJRX u22A== X-Forwarded-Encrypted: i=1; AJvYcCX7+FgpvfaUXRbztTi+/g3z/txc6r0w+N9tTxxwuw0/oda8Wn6biYQF9EBr/q8EevvD8rdi7yOjNkQvjtc=@vger.kernel.org X-Gm-Message-State: AOJu0Yxqvl9zB/gC1wF1qHhIdMl7Pg7BZUl1d4xEV64mLOWQ2Snaax+J hpOQTTuUckoBclygxrq/EDlAnHHxk59peJDLkFfXBx1VDF7FDeqGFsc73+6GGa4x9Uc= X-Gm-Gg: ASbGncvpCPI1CO/g6/mwmSA/Shm878WWmUaN1KmH9Ml/HWmxHiBED1xP7tAbz+YhAjf H0676iP5Ta8XpfKAzVsVnGCPG6e9qhMYzAM+FXAKNjKwrC0FUNq+u5uaQjJOofV26h/0DUO7BK5 U9BgHUU0zYWlTIAikTpEtAQHB1u9Q77/bipgCyB7h1Nbe2RA0Yv2Lc7NF7ZOSCRty9I2x8VYHTW JM/q2trLKXenXONIco+pHHeQ6M9FmjAUS4Anl2HaAfFiLav8qZNFUtqvIHDE8MXPlkQc17SBw8e 5EWy9uHtTXtv//nSV4e1pkY2+K3qBJUxTg5HWfhSd60gdvqzwo8M48F/mx8gerkQgusbQVXb+Uw aFYN2Mw== X-Google-Smtp-Source: AGHT+IFvFB0VeJyxN/6532jT3ADchtzSmPWDTvhxX9uwYcL7DOeuanxIvtxAGrRXPpFk4ndeXddrsg== X-Received: by 2002:a05:600c:820c:b0:453:23fe:ca86 with SMTP id 5b1f17b1804b1-454b8ea7cefmr7010495e9.4.1751639781382; Fri, 04 Jul 2025 07:36:21 -0700 (PDT) Received: from vingu-cube.. ([2a01:e0a:f:6020:7ff5:bbf8:9357:784a]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b4708d0beesm2690186f8f.36.2025.07.04.07.36.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Jul 2025 07:36:19 -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 v2 3/6] sched/fair: Remove spurious shorter slice preemption Date: Fri, 4 Jul 2025 16:36:09 +0200 Message-ID: <20250704143612.998419-4-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250704143612.998419-1-vincent.guittot@linaro.org> References: <20250704143612.998419-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" Even if the waking task can preempt current, it might not be the one selected by pick_task_fair. Check that the waking task will be selected if we cancel the slice protection before doing so. Signed-off-by: Vincent Guittot --- kernel/sched/fair.c | 44 ++++++++++++++------------------------------ 1 file changed, 14 insertions(+), 30 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 0c1abb079ebb..2e624a769b86 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -931,7 +931,7 @@ static inline void cancel_protect_slice(struct sched_en= tity *se) * * Which allows tree pruning through eligibility. */ -static struct sched_entity *pick_eevdf(struct cfs_rq *cfs_rq) +static struct sched_entity *__pick_eevdf(struct cfs_rq *cfs_rq, bool prote= ct) { struct rb_node *node =3D cfs_rq->tasks_timeline.rb_root.rb_node; struct sched_entity *se =3D __pick_first_entity(cfs_rq); @@ -948,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 (curr && protect_slice(curr)) + if (curr && protect && protect_slice(curr)) return curr; =20 /* Pick the leftmost entity if it's eligible */ @@ -992,6 +992,11 @@ static struct sched_entity *pick_eevdf(struct cfs_rq *= cfs_rq) return best; } =20 +static struct sched_entity *pick_eevdf(struct cfs_rq *cfs_rq) +{ + return __pick_eevdf(cfs_rq, true); +} + struct sched_entity *__pick_last_entity(struct cfs_rq *cfs_rq) { struct rb_node *last =3D rb_last(&cfs_rq->tasks_timeline.rb_root); @@ -1175,27 +1180,6 @@ static inline bool resched_next_quantum(struct cfs_r= q *cfs_rq, struct sched_enti return !entity_eligible(cfs_rq, curr); } =20 -static inline bool do_preempt_short(struct cfs_rq *cfs_rq, - struct sched_entity *pse, struct sched_entity *se) -{ - if (!sched_feat(PREEMPT_SHORT)) - return false; - - if (pse->slice >=3D se->slice) - return false; - - if (!entity_eligible(cfs_rq, pse)) - return false; - - if (entity_before(pse, se)) - return true; - - if (!entity_eligible(cfs_rq, se)) - return true; - - return false; -} - /* * Used by other classes to account runtime. */ @@ -8666,6 +8650,7 @@ static void check_preempt_wakeup_fair(struct rq *rq, = struct task_struct *p, int struct sched_entity *se =3D &donor->se, *pse =3D &p->se; struct cfs_rq *cfs_rq =3D task_cfs_rq(donor); int cse_is_idle, pse_is_idle; + bool do_preempt_short =3D false; =20 if (unlikely(se =3D=3D pse)) return; @@ -8714,7 +8699,7 @@ static void check_preempt_wakeup_fair(struct rq *rq, = struct task_struct *p, int * When non-idle entity preempt an idle entity, * don't give idle entity slice protection. */ - cancel_protect_slice(se); + do_preempt_short =3D true; goto preempt; } =20 @@ -8732,22 +8717,21 @@ static void check_preempt_wakeup_fair(struct rq *rq= , struct task_struct *p, int /* * If @p has a shorter slice than current and @p is eligible, override * current's slice protection in order to allow preemption. - * - * Note that even if @p does not turn out to be the most eligible - * task at this moment, current's slice protection will be lost. */ - if (do_preempt_short(cfs_rq, pse, se)) - cancel_protect_slice(se); + do_preempt_short =3D sched_feat(PREEMPT_SHORT) && (pse->slice < se->slic= e); =20 /* * If @p has become the most eligible task, force preemption. */ - if (pick_eevdf(cfs_rq) =3D=3D pse) + if (__pick_eevdf(cfs_rq, !do_preempt_short) =3D=3D pse) goto preempt; =20 return; =20 preempt: + if (do_preempt_short) + cancel_protect_slice(se); + resched_curr_lazy(rq); } =20 --=20 2.43.0 From nobody Tue Oct 7 22:40:48 2025 Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.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 11E172C3258 for ; Fri, 4 Jul 2025 14:36:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751639786; cv=none; b=Z5rCiDvFp5ILXTYv3mJjIljcMBrUN9+lAnBgQsXDFvES390V2hThza2S+kEMEPRexxGUvggGMGEFA/DkELhZiVozrutSJsjoDmOMxc+zzXtrxCVdnM7tV4Xf9QIWvq1pULhTsMOVZBr2yh8lBZ2r3SI0TJCj8gTEyStVd0o7nPQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751639786; c=relaxed/simple; bh=nb4um9P8hUoqYEaIVbgAm/x5zCvPnr2ef9UlSlIIiMA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AQmNkLP3tIZQupexBQpEatMY4RmX6kqlT9QqAAFYMvDhm9HBZasXmOv0VSTpv+5ugGGilhy3tc++F6MKE69tbOv649z/DEASmNfajq19zOai8wVrDqPY49W8lkU41zwfxOTHZhFe8xPpel6FJw2WJ+ZQTPTbdFLhlvHsondT51o= 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=rjvLs4rx; arc=none smtp.client-ip=209.85.128.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="rjvLs4rx" Received: by mail-wm1-f51.google.com with SMTP id 5b1f17b1804b1-4538bc52a8dso7604315e9.2 for ; Fri, 04 Jul 2025 07:36:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1751639783; x=1752244583; 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=aYfIWQe8S3zIoB06sVdRdEn43/CQJKSFHRiqx/zs5CE=; b=rjvLs4rxrnhdfSwpwXJHcITwz72ommLyNbf9zwXj6zC/3HIDPdfrFDmVQ4wjfmTc9X 9iULlDzksTSgFOj4M5cqb5tdUePogAFZk3KXmb8Qg6+Up6GekOUZ9E7RqC70tv0yRVWx ip581Dv3ybN3GCGucpS9wIH9hc9EL/lmsrEYOXwPXhtu1LA819VqscTeQDOQQJtBUAPe sCHsaVMXzePaBWTr3kZRavFBp/QPu8o4jaIhC/Gf84z1SrNpmGQnCw1Zv+E2ubYcDNHJ nSjuvcAB0LK4BLdXd9YQ131R97gXCmUtX7NwC0K4rATn1TSDzPax+FDylGKgEMSqQ/eH MX+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751639783; x=1752244583; 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=aYfIWQe8S3zIoB06sVdRdEn43/CQJKSFHRiqx/zs5CE=; b=UfXoIRcZ5Aqy+LwZufSbvsyCt2Dgknvg491d8HQ9L1GNIszzyszVL8nIB4yuT/ZSmt oErBG0+WVXSj5yb4whmcAiWsgzyV5Z+sE57Yzu9XXQHN43+Kn3Kx2AoeKD00Ys+efR+W AhJpx2/57Jyt6m9qnyY+Hb1nRMW679V1yNlpmHn2SaL4whKorktOO0AhnnQGYDTfXNDh mrf4TAsP2mnATHZelWJC5V2VrT3MgMDVV115akWRsnFbkF+WI9M4TctG3Fwp1kgxWMAV amIYs+3DJ5c79cI3nIfLid/zT3oFylQ8AxlUJ4gskCo4zmjkOp5mFLiUxkdubiRMi/MK KUiQ== X-Forwarded-Encrypted: i=1; AJvYcCV1e/lcQ21lKdWud0OyPZ8TtqSsvnj+OHD59XNoEZ0re3ZDiAoROUdyfTN+eK4sRZFDbI5zLiikkJ9xxYo=@vger.kernel.org X-Gm-Message-State: AOJu0YzssHXfn2PjmNeaN5p2NIDsOHpMeaGllQIr/tFdv+rtMrSdGAte wb+sElb5k5Iudym5pSfXIOeCWWgNzjGGnJS3JXYb6rDErd52ZJQdDvK4MypKrxZOUUU0yQZQpuC 4nVPy X-Gm-Gg: ASbGncsd5E3aw858goJIf5CrTX7sHqhnbnID2G3bVwDy5Mo8VSM/AUi/7J5Jwq0CTLa yuLywupnR3oP61rMz8XCxRClBpnzYZrhbYDWdCiQnAve3O4DgbptC5aPPiNRXWyIeboU9bQv7V1 V+mu6H0F3dWRFMeL4uH+dDEhEcsrwsZRQgNw2hhmetjfNmHOwL4R/3zd3rD6cNiGdT45xsLYnkY b1rFIHPjxyHLfaRcLYcgAK0tad1/oazgAFn2Olq9cY0orhdQtXVJ+eMbYRX8DaF0/RX/zVA8gH5 nOFcuf94R62klYEXyQwoUOdWd2imvQBeqcr8Hytd9DaXXxqhXl8NLtqqibWR/UoyRfsd/fc= X-Google-Smtp-Source: AGHT+IEvxKudST1vPPvq53xQ78WkR/ilZX9FnxePFKofGNqwn70qdcXs4eLbY09PRDLMzHgEG2j4DA== X-Received: by 2002:a05:600c:c492:b0:442:f4a3:b5ec with SMTP id 5b1f17b1804b1-454b3108998mr32960635e9.4.1751639783310; Fri, 04 Jul 2025 07:36:23 -0700 (PDT) Received: from vingu-cube.. ([2a01:e0a:f:6020:7ff5:bbf8:9357:784a]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b4708d0beesm2690186f8f.36.2025.07.04.07.36.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Jul 2025 07: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, dhaval@gianis.ca, linux-kernel@vger.kernel.org Cc: Vincent Guittot Subject: [PATCH v2 4/6] sched/fair: Limit run to parity to the min slice of enqueued entities Date: Fri, 4 Jul 2025 16:36:10 +0200 Message-ID: <20250704143612.998419-5-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250704143612.998419-1-vincent.guittot@linaro.org> References: <20250704143612.998419-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" Run to parity ensures that current will get a chance to run its full slice in one go but this can create large latency and/or lag for entities with shorter slice that has exhausted their previous slice and wait to run their next slice. Clamp the run to parity to the shortest slice of all enqueued entities. Signed-off-by: Vincent Guittot --- kernel/sched/fair.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 2e624a769b86..2a0348b0cc3d 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -884,16 +884,20 @@ struct sched_entity *__pick_first_entity(struct cfs_r= q *cfs_rq) /* * HACK, Set the vruntime up to which an entity can run before picking ano= ther * one, in vlag, which isn't used until dequeue. - * In case of run to parity, we let the entity run to its deadline. + * In case of run to parity, we use the shortest slice of the enqueued ent= ities + * to define the longest runtime. * 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) { - u64 quantum =3D se->slice; + u64 quantum; =20 - if (!sched_feat(RUN_TO_PARITY)) - quantum =3D min(quantum, normalized_sysctl_sched_base_slice); + if (sched_feat(RUN_TO_PARITY)) + quantum =3D cfs_rq_min_slice(cfs_rq_of(se)); + else + quantum =3D normalized_sysctl_sched_base_slice; + quantum =3D min(quantum, se->slice); =20 if (quantum !=3D se->slice) se->vlag =3D min(se->deadline, se->vruntime + calc_delta_fair(quantum, s= e)); --=20 2.43.0 From nobody Tue Oct 7 22:40:48 2025 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 0C5FE2D8DC8 for ; Fri, 4 Jul 2025 14:36:26 +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=1751639788; cv=none; b=G9UKDIpTbmim3+8rE8ESfQhCEDtUdIEuenCtxJ9MxvWl8UwmJDGLyiAYt7IMf35dDAGGDiP+tPZyTU8ZyI1lHZbTfJUj4FrwipMqJnJpTBnCkxcEmkB0JZSYcuYc2/0vVArlVymlUM2PqKwcD8vOKR6e1TcJ4EepzDSvpfl1Ezk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751639788; c=relaxed/simple; bh=K3IdBv+el5XcgNdSoavpeFZhuDRUnWvXjoODKRwd5TY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=P8c02rdGzWdCcI8crbCUUvkjoBp/7vDD83xJIwv2OxufJ/HhMpIWWMsSAhPZhfnDhJnODZEfCaE7fa2oig2f9q/N8Wc+6zTLeULmgG9hqg2toTI4EE9GrWQ6e7XaayM4NEOMfv7ZdGqvB8A/RSt6Rviaa14GE86p0A3crmT5KkI= 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=mGSbXR2M; 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="mGSbXR2M" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-453749af004so4930065e9.1 for ; Fri, 04 Jul 2025 07:36:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1751639785; x=1752244585; 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=HlHWzk+mMbngQROsiCm7HVXVg8kCE36dvYmeJzMAcTk=; b=mGSbXR2MwFiVeQVFaoE8/z5Wp+RkM21Sae4tmKmulcqPCN1tCRP4aTBn2U2DsReza9 jCdi5uAZEF31EClaeHZori12nTHaqlGLE/oFk6p/SNir6JisE1m/rBlXkHVIllxeWq3N LBlaylIkeHX8JuARjRLLmSv0UCpm+hWKfZ8SJRokADL7ejx7Un8fTpVAaTwEXfUrNftL vVdIYNH/cGJZCGwsfOKlZ1XtEGlP0CaeWPmD65ca6chXRjY3IQ7FrStS69BturUfUo8u 8AMAJHWlDCUWDFLRlQ7zzm4FeB6UUKPBW3JSR/1KnmOppEx2jQSMw0r+xtSeBQcxpG6A wfzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751639785; x=1752244585; 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=HlHWzk+mMbngQROsiCm7HVXVg8kCE36dvYmeJzMAcTk=; b=dWMfsxQsUs4w1Ikf8y922BOu1DdooipW2g51qcsGRuz9Jtq4KYTz34oDDr2HvZEVPt 8W+cvwywxkLsd/ysQ0VOAtxTtGtPkXv5h/wxGCNj2kXZnik/pDdqNALK4/mH0bo7v/ET P23DegTf6GmZ7LDFSVm9IGEINRX51eIbbH2VNyxCCMclXbUWBVJ94ljZUvokwmseA5fN Ub+W0BmQ3m2RPiFn7bqzOB5lM+qgQT7g1UlfAHYIuPWebceDPDVRl67mC7bwNZTtOu4h HtGK6ZAdQTd0J5XZsMcX1uUbyl2lcOszo/2L4YmTI9s05HAsVZUWXmlISGC3cL5Qg5Ys h4eQ== X-Forwarded-Encrypted: i=1; AJvYcCUNQMIIAeCd6rVIwI5D4noQMU4iuNFoTe/Mpip2Tpe9y6pKvcJwG6gkPCBl5T//MDP0GozRHoUGest+ejo=@vger.kernel.org X-Gm-Message-State: AOJu0YwdlLDmFMKNx2Bitj6uJIkCPiFG9C2nnLIfh98P8qkj2r+7kku9 uTQI90PHUeI8b4cuCyIZ81hIJppe/rmn6k4oLC/A+QENV9miXdxQpL8qH67iE2nILR8= X-Gm-Gg: ASbGncvYshll2w9mIaQxC2NY0ngj5FcnZ1tgyX9lfeQna/E3cLk6GROH8nqCBwRhj1N RyUW7DihbHpu3Aq9LpyU1rUbMu6rbOZAXe9V3QsRcijXWmZFR3L6cJ/M+9WP5LNfLz6KcXg8lPP TzqXV2XkV6Y8WDKi95uxl9WJ/AvUaJgF3yesJhPqM3Oy+Su3H24+FpgIbJiPIpKFUxGMJyAUrOi QLOE8QeHgrcEGch+rc0DO5jIxjUOZF3mFI3V+tIjtlzmwAKy7NGUcDqIc1IeWH25zVR7l//Gcd4 k/JgDkl/hQoMOpY3E9OMibBx+b7pQYAzmFdpvrBnHgv2CJ7iZbqf9PHWJY/mx+NibRsSBwE= X-Google-Smtp-Source: AGHT+IGvvno6QlrWBE/NdjghYUhex+mwx0AnVdFXd2l6QiVmsJOhVKLHywWVUqvnXSGBpQ40EPsH5Q== X-Received: by 2002:a05:600c:4e8f:b0:450:d614:cb with SMTP id 5b1f17b1804b1-454b31158e6mr27299975e9.33.1751639785291; Fri, 04 Jul 2025 07:36:25 -0700 (PDT) Received: from vingu-cube.. ([2a01:e0a:f:6020:7ff5:bbf8:9357:784a]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b4708d0beesm2690186f8f.36.2025.07.04.07.36.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Jul 2025 07: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, dhaval@gianis.ca, linux-kernel@vger.kernel.org Cc: Vincent Guittot Subject: [PATCH v2 5/6] sched/fair: Fix entity's lag with run to parity Date: Fri, 4 Jul 2025 16:36:11 +0200 Message-ID: <20250704143612.998419-6-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250704143612.998419-1-vincent.guittot@linaro.org> References: <20250704143612.998419-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" When an entity is enqueued without preempting current, we must ensure that the slice protection is updated to take into account the slice duration of the newly enqueued task so that its lag will not exceed its slice (+ tick). Signed-off-by: Vincent Guittot --- kernel/sched/fair.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 2a0348b0cc3d..58f25f0be25f 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -889,12 +889,12 @@ struct sched_entity *__pick_first_entity(struct cfs_r= q *cfs_rq) * 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) +static inline void set_protect_slice(struct cfs_rq *cfs_rq, struct sched_e= ntity *se) { u64 quantum; =20 if (sched_feat(RUN_TO_PARITY)) - quantum =3D cfs_rq_min_slice(cfs_rq_of(se)); + quantum =3D cfs_rq_min_slice(cfs_rq); else quantum =3D normalized_sysctl_sched_base_slice; quantum =3D min(quantum, se->slice); @@ -905,6 +905,13 @@ static inline void set_protect_slice(struct sched_enti= ty *se) se->vlag =3D se->deadline; } =20 +static inline void update_protect_slice(struct cfs_rq *cfs_rq, struct sche= d_entity *se) +{ + u64 quantum =3D cfs_rq_min_slice(cfs_rq); + + se->vlag =3D min(se->vlag, (s64)(se->vruntime + calc_delta_fair(quantum, = se))); +} + static inline bool protect_slice(struct sched_entity *se) { return ((s64)(se->vlag - se->vruntime) > 0); @@ -5468,7 +5475,7 @@ set_next_entity(struct cfs_rq *cfs_rq, struct sched_e= ntity *se) __dequeue_entity(cfs_rq, se); update_load_avg(cfs_rq, se, UPDATE_TG); =20 - set_protect_slice(se); + set_protect_slice(cfs_rq, se); } =20 update_stats_curr_start(cfs_rq, se); @@ -8730,6 +8737,9 @@ static void check_preempt_wakeup_fair(struct rq *rq, = struct task_struct *p, int if (__pick_eevdf(cfs_rq, !do_preempt_short) =3D=3D pse) goto preempt; =20 + if (sched_feat(RUN_TO_PARITY) && do_preempt_short) + update_protect_slice(cfs_rq, se); + return; =20 preempt: --=20 2.43.0 From nobody Tue Oct 7 22:40:48 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 9E5F8277C87 for ; Fri, 4 Jul 2025 14:36:28 +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=1751639790; cv=none; b=FWQ1alIcocrIlpkUx68XSdbVySy6dhrmq/okT1cBtLvXAKi1U6+ZUJXKv25Lz6RPUmWjlohcCksQKbalJ589wgxZGOJSA5p6/Nnjvye9eS9nbC/u6IpsR15vM/gKgf7OaoYS+w/p9x3EIPV09WuMd4/Talh90I1UXhHLFe0RdA0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751639790; c=relaxed/simple; bh=zon+2bZeFZ3I7M92hXQ659ByBgia0BgvZL3f6vbsv30=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bd84W0S1xuYZrVIa/f5OIevXzUgXtYqCVEY/wM54F3e8FGEqpcTTJqeg85PN1/mZwHNDp93+OsMdLHb+USDDTCzcLq8a0vA9rTuaTAxXdOjBb1mPf9VvBpb5dAFXIVZyNHEXIpJL2LTW8qbW06CWivG2MJyA3uyf8RO+wjwWk4M= 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=j3e41Xn3; 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="j3e41Xn3" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-450ce3a2dd5so8663015e9.3 for ; Fri, 04 Jul 2025 07:36:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1751639787; x=1752244587; 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=fYNAQQahuUMGDz22rnH2lh9atASoN+pd5LzktjQrHhM=; b=j3e41Xn3fsLycsvLDVyoK+BTSyrCYbqAMePMkGCw8M+1mx1Lt15J+/NaacK/9tPCE/ w3nc10Z2qResc1m4USKJLd3Q9boE4Q2XNV+zJbnHECieIDGfd1kltXVDYpcQXTGCHXrI nowWbYg8ZnOjHy6p8bwG8ZmhPDPAyiwI0Og0xpTwgwv3NyWo8RC/bBN/u6xkef1uQkW0 nnuBJY6btrD/SR2qMeDlPOuMCJ9/XpPL2QeKTIZlD69jql6V+pVzR4q5HXr95wc0k6oE rrqE3SJzP42kKXPTosRJSRIzfhJ5a8hiNGsQihObN5NQGsCEfM2u/IZlQLHanSjeVXdO YFOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751639787; x=1752244587; 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=fYNAQQahuUMGDz22rnH2lh9atASoN+pd5LzktjQrHhM=; b=Q1Pz53c6I3lsN99LuH3ismjITId+CDTJdtRxn0+AwN9nIHJGM7C48lJsWHQV//iiXu BJ4uDq82wHMweyT9DXnSrZH9/XgMuUxT+H4FlMOfyO10QRy05BOEcyntZwAqpQHvWKML nO8GRkIuMgWPwSBttzrWqv7aOpF/RbxzK48r5crPu5MuD1/ObefFXAmouHTcehXBK1Go i7SrN7wrII86LLSvVL4LWIIQbi9O2v6mRG8MxqETpPIq/KQribI3K0ZJ1JA9ZXplFziw hVikUfErnpeY/Sd9HZOV+EP12D7Tu6f8rVNnpy14pGcpffqz/MVa55hvl7Ri0KK2KOix oPpQ== X-Forwarded-Encrypted: i=1; AJvYcCULAz9Vnhqtt6xBuuJkKUW3nj++kDWSHKXcrm2orViJLGO5agsxF+ThuAZHyJu2+pktJZ0JEZucTJyJbCM=@vger.kernel.org X-Gm-Message-State: AOJu0YwDS7O5pEtzorQ/T5I3a31IgWxK2PImSLCraUbkRzUbkXuu/BQL p50nVrqAYmPAc2fHlnRmUAJGU+a7C/w8meW+8x5qtpQkfgRL387a5hufFv2yicSR/2U= X-Gm-Gg: ASbGnctHDDMsJ6sM8DcqoVJMU+kHaglilFra2l2OyvmQN/aP1QELqt/U4UJSBMvAEC5 QCTiJiNVe5t7bqWdecDZgB4dbeNizfPs8MbBWHUg3NJ6ShEacjSYgphWU/mg7fwcT4McpCRL51P /FkQdGNukY4QCSaP6qr19EyakiT27Xts894Inm+UpQ4HHH21UKrVNdhD7yS2hvEW4aJ2juj6XNx E0EypIZnubwZiU3j73jLrFEz0QpjcDhmUxxn+hU+Qzmg81UxjW9HErdQ6uMmfCPmjadAVaA4ZOJ pP4bz1HA/7AvTzU/aIiSciBNzWjzIXrWduULKf0I4hYwGjGqHT4Uc+kGnbw0wtll7oA+R2PuKhO rBNALkQ== X-Google-Smtp-Source: AGHT+IEbOXsOsFrWj3VhBwyGUbOHwXo35WngYlxUc9cqgxLa6FBhnGGYCW+1X3Dqe26+x/f41H1UnA== X-Received: by 2002:a05:600c:8411:b0:442:e147:bea7 with SMTP id 5b1f17b1804b1-454b7813f2amr16064945e9.29.1751639786941; Fri, 04 Jul 2025 07:36:26 -0700 (PDT) Received: from vingu-cube.. ([2a01:e0a:f:6020:7ff5:bbf8:9357:784a]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3b4708d0beesm2690186f8f.36.2025.07.04.07.36.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Jul 2025 07:36:25 -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 v2 6/6] sched/fair: Always trigger resched at the end of a protected period Date: Fri, 4 Jul 2025 16:36:12 +0200 Message-ID: <20250704143612.998419-7-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250704143612.998419-1-vincent.guittot@linaro.org> References: <20250704143612.998419-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" Always trigger a resched after a protected period even if the entity is still eligible. It can happen that an entity remains eligible at the end of the protected period but must let an entity with a shorter slice to run in order to keep its lag shorter than slice. This is particulalry true with run to parity which tries to maximize the lag. Signed-off-by: Vincent Guittot --- kernel/sched/fair.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 58f25f0be25f..debcc136f1c8 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -1188,7 +1188,7 @@ static inline bool resched_next_quantum(struct cfs_rq= *cfs_rq, struct sched_enti if (protect_slice(curr)) return false; =20 - return !entity_eligible(cfs_rq, curr); + return true; } =20 /* --=20 2.43.0