From nobody Thu Dec 18 19:25:05 2025 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 521C714532D; Mon, 29 Jul 2024 10:34:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722249251; cv=none; b=uZPFMZsU+1mXpZgG4dVWeu0Jc6BY/GMA3oW+KF29B5GCq0ME0+3I7VoGQTaxAU50goRnXfLhvt1RV/ncVNV7h64Hab4JnwLHpP/rl7zz0O8v8cNG569DtBvZckRpcay0zg8esKLuJMejcb/XDBYqOh/ZBPmXwuS2FddCA6gVadw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722249251; c=relaxed/simple; bh=6KRNB7s0XBKUkjQvF0uHWhhZniC64aGkAhQp8xDN/kw=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=F9RW1U0RzggkNy9LDeUzRdqU3wuCku6Vs0s1V91oW+LD2u0Dduac4/Nm3gjSfE960JliFqoGToy/Q2zO35OFPq6LJmphFR7//vUcQVkhPJDToVqjxECvERPY69Ky/6w7ak47/1jSmtmlPq4AV5xV9sjciPXfjPuUGuSwFe+9Mw0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=k3qZEWkP; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Of9tHNR1; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="k3qZEWkP"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Of9tHNR1" Date: Mon, 29 Jul 2024 10:34:06 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1722249246; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Y8a9GIUd146QY2xQn6jjhyc9q8K1xcZNbLabwnGoOl4=; b=k3qZEWkPePK2rwDkL3Q4OONm+SSvyEnQWg7J/Q17TP/MTkbzI+G0VB6FiLev7psQb+KEq6 0pfNptcTgTlZvpRgKtLxnrghHcXI0ozjDuSCCmCKAod3PWZQt9R1lD3zHerv+8ecpAi4um BsytYCHY64lqsJw7zPsMB3Ilbw7fUrFZraT+Es/tFCfujsWvsRIuNsu5ahIpJEtHJK6oZM itGzBdiOo1lWdPLPrfTekXIpIllpjkdNR/FA51uIIFST5nrTv8bP5RLZzjt2/37BZoMhuJ ZlA0WWP1U1koT3iuhl1LDw9izzMH/XeT2eykzeiFDmCedM5Iz9+WyZcCNqPu6g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1722249246; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Y8a9GIUd146QY2xQn6jjhyc9q8K1xcZNbLabwnGoOl4=; b=Of9tHNR1RGA62VmaVObuhwn4z5kOMcOJfoB0Ez/rgyQ/9KuF4u4dYvVwbWsxCElVKFcB6o kD/E8+hLWr/Sk1Cw== From: "tip-bot2 for Tianchen Ding" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] sched/fair: Make SCHED_IDLE entity be preempted in strict hierarchy Cc: Tianchen Ding , "Peter Zijlstra (Intel)" , Josh Don , Vincent Guittot , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20240626023505.1332596-1-dtcccc@linux.alibaba.com> References: <20240626023505.1332596-1-dtcccc@linux.alibaba.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <172224924632.2215.7502536289804369136.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the sched/core branch of tip: Commit-ID: faa42d29419def58d3c3e5b14ad4037f0af3b496 Gitweb: https://git.kernel.org/tip/faa42d29419def58d3c3e5b14ad4037f0= af3b496 Author: Tianchen Ding AuthorDate: Wed, 26 Jun 2024 10:35:05 +08:00 Committer: Peter Zijlstra CommitterDate: Mon, 29 Jul 2024 12:22:35 +02:00 sched/fair: Make SCHED_IDLE entity be preempted in strict hierarchy Consider the following cgroup: root | ------------------------ | | normal_cgroup idle_cgroup | | SCHED_IDLE task_A SCHED_NORMAL task_B According to the cgroup hierarchy, A should preempt B. But current check_preempt_wakeup_fair() treats cgroup se and task separately, so B will preempt A unexpectedly. Unify the wakeup logic by {c,p}se_is_idle only. This makes SCHED_IDLE of a task a relative policy that is effective only within its own cgroup, similar to the behavior of NICE. Also fix se_is_idle() definition when !CONFIG_FAIR_GROUP_SCHED. Fixes: 304000390f88 ("sched: Cgroup SCHED_IDLE support") Signed-off-by: Tianchen Ding Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Josh Don Reviewed-by: Vincent Guittot Link: https://lkml.kernel.org/r/20240626023505.1332596-1-dtcccc@linux.aliba= ba.com --- kernel/sched/fair.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 02694fc..99c80ab 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -511,7 +511,7 @@ static int cfs_rq_is_idle(struct cfs_rq *cfs_rq) =20 static int se_is_idle(struct sched_entity *se) { - return 0; + return task_has_idle_policy(task_of(se)); } =20 #endif /* CONFIG_FAIR_GROUP_SCHED */ @@ -8381,16 +8381,7 @@ static void check_preempt_wakeup_fair(struct rq *rq,= struct task_struct *p, int=20 if (test_tsk_need_resched(curr)) return; =20 - /* Idle tasks are by definition preempted by non-idle tasks. */ - if (unlikely(task_has_idle_policy(curr)) && - likely(!task_has_idle_policy(p))) - goto preempt; - - /* - * Batch and idle tasks do not preempt non-idle tasks (their preemption - * is driven by the tick): - */ - if (unlikely(p->policy !=3D SCHED_NORMAL) || !sched_feat(WAKEUP_PREEMPTIO= N)) + if (!sched_feat(WAKEUP_PREEMPTION)) return; =20 find_matching_se(&se, &pse); @@ -8400,7 +8391,7 @@ static void check_preempt_wakeup_fair(struct rq *rq, = struct task_struct *p, int=20 pse_is_idle =3D se_is_idle(pse); =20 /* - * Preempt an idle group in favor of a non-idle group (and don't preempt + * Preempt an idle entity in favor of a non-idle entity (and don't preempt * in the inverse case). */ if (cse_is_idle && !pse_is_idle) @@ -8408,9 +8399,14 @@ static void check_preempt_wakeup_fair(struct rq *rq,= struct task_struct *p, int=20 if (cse_is_idle !=3D pse_is_idle) return; =20 + /* + * BATCH and IDLE tasks do not preempt others. + */ + if (unlikely(p->policy !=3D SCHED_NORMAL)) + return; + cfs_rq =3D cfs_rq_of(se); update_curr(cfs_rq); - /* * XXX pick_eevdf(cfs_rq) !=3D se ? */