From nobody Sun Feb 8 09:12:40 2026 Received: from out0-198.mail.aliyun.com (out0-198.mail.aliyun.com [140.205.0.198]) (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 B105076905 for ; Wed, 31 Jan 2024 12:03:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=140.205.0.198 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706702643; cv=none; b=m8GKp9YW5NAS4Ax06V9CNZ6jR4Rkl+aXIXXDZOd04fesioZJhE9x9zM4NPSPfk8wBmAZ1vHGmpIYAUbZGPOb8VHDNKBv6EcUZyYMBiQdZDQWfMRfr+O9yBcwTYIqQ+7Sp0eF6RXnh4MFTVrKSIeRc8itlTNcZUOxxBpz48zMNVA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706702643; c=relaxed/simple; bh=IN90uWH2gKJ9vO4bKf8+8xSF4Zj8oAe2pWZ1Il9B05Y=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=A7h7PDk5pbla7zwsx9hsBJYtVYZMpYgWLyilKbw69QrQpBxTr+pjWda27Wqngj3Q+vrqbvfrrBJ9xhgac8De10KqNtaWit8lKLDSY7ZluiqfNZOEE5DxwpokBcNtEWd8XrDjcUCI+Ewac1XGR/g+S3G39u2h85qPylJB0oqXa/4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=antgroup.com; spf=pass smtp.mailfrom=antgroup.com; arc=none smtp.client-ip=140.205.0.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=antgroup.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=antgroup.com X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R181e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018047208;MF=tiwei.btw@antgroup.com;NM=1;PH=DS;RN=13;SR=0;TI=SMTPD_---.WKHfWWO_1706702630; Received: from ubuntu..(mailfrom:tiwei.btw@antgroup.com fp:SMTPD_---.WKHfWWO_1706702630) by smtp.aliyun-inc.com; Wed, 31 Jan 2024 20:03:55 +0800 From: "Tiwei Bie" To: peterz@infradead.org, mingo@redhat.com, wuyun.abel@bytedance.com Cc: "Tiwei Bie" , "Juri Lelli" , "Vincent Guittot" , "Dietmar Eggemann" , "Steven Rostedt" , "Ben Segall" , "Mel Gorman" , "Daniel Bristot de Oliveira" , "Valentin Schneider" , Subject: [PATCH v2] sched/fair: Sanity check 'best' in pick_eevdf() Date: Wed, 31 Jan 2024 20:03:40 +0800 Message-Id: <20240131120340.76461-1-tiwei.btw@antgroup.com> X-Mailer: git-send-email 2.34.1 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" Before commit 2227a957e1d5 ("sched/eevdf: Sort the rbtree by virtual deadline"), there was a sanity check to catch unexpected failures in the EEVDF scheduling, which was helpful in identifying problems. It would be better to restore its previous capability. Signed-off-by: Tiwei Bie --- Refer: https://lore.kernel.org/lkml/23cbb613-c8a2-4f07-b83b-fa3104bef642@bytedance= .com/ v1 -> v2: - improve commit log and error message; kernel/sched/fair.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 533547e3c90a..aeb3b8fee641 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -878,7 +878,7 @@ struct sched_entity *__pick_first_entity(struct cfs_rq = *cfs_rq) static struct sched_entity *pick_eevdf(struct cfs_rq *cfs_rq) { struct rb_node *node =3D cfs_rq->tasks_timeline.rb_root.rb_node; - struct sched_entity *se =3D __pick_first_entity(cfs_rq); + struct sched_entity *first =3D __pick_first_entity(cfs_rq); struct sched_entity *curr =3D cfs_rq->curr; struct sched_entity *best =3D NULL; =20 @@ -887,7 +887,7 @@ static struct sched_entity *pick_eevdf(struct cfs_rq *c= fs_rq) * in this cfs_rq, saving some cycles. */ if (cfs_rq->nr_running =3D=3D 1) - return curr && curr->on_rq ? curr : se; + return curr && curr->on_rq ? curr : first; =20 if (curr && (!curr->on_rq || !entity_eligible(cfs_rq, curr))) curr =3D NULL; @@ -900,14 +900,15 @@ static struct sched_entity *pick_eevdf(struct cfs_rq = *cfs_rq) return curr; =20 /* Pick the leftmost entity if it's eligible */ - if (se && entity_eligible(cfs_rq, se)) { - best =3D se; + if (first && entity_eligible(cfs_rq, first)) { + best =3D first; goto found; } =20 /* Heap search for the EEVD entity */ while (node) { struct rb_node *left =3D node->rb_left; + struct sched_entity *se; =20 /* * Eligible entities in left subtree are always better @@ -937,6 +938,16 @@ static struct sched_entity *pick_eevdf(struct cfs_rq *= cfs_rq) if (!best || (curr && entity_before(curr, best))) best =3D curr; =20 + /* This is not expected to happen. */ + if (unlikely(!best)) { + if (printk_ratelimit()) { + printk_deferred(KERN_ERR + "EEVDF scheduling failed on CPU%d, picking leftmost\n", + cpu_of(rq_of(cfs_rq))); + } + best =3D first; + } + return best; } =20 --=20 2.34.1