From nobody Sat Sep 26 11:46:35 2026 Received: from mta1.migadu.com (out-137.mta1.migadu.com [95.215.58.137]) (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 B5797276050 for ; Wed, 2 Sep 2026 02:48:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.137 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788317316; cv=none; b=U3XHrU7LoeY5TIhIVTtVEjp9bxm5c/0fTfbZ6hwlBr8hih88Y8aTHg4/nHhNhw1YhCWCqyiHCGi7ovLQzV6PJjTvNWV0XDJXgrU12TWiXFevZn7KwxF3kImRXIbD13lfqXQFYHPnWgZSuKVkT+uPlKuDkyq8f/zbb0QVd7n8OnI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788317316; c=relaxed/simple; bh=ST5983ll6U7hafoaFlMxWw1U9/w1gNB73r53z1PudWg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QkwqAn4Y+cnK9qXltgnjv4LcrHVPaEuVUHurrrdvitwLktkyAH00YsDIrrhzApVsd5zrInkXcWxLtYtitXYUe0RtAknJCwsw29aohb+Cg8V4GUGPIQsmLGse4/koMIWSSXMqSq3KGhOGRCwIwyo1jglAStWmynGs0CO/hqeiz/k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=OIFRM3D8; arc=none smtp.client-ip=95.215.58.137 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="OIFRM3D8" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=ST5983ll6U7hafoaFlMxWw1U9/w1gNB73r53z1PudWg=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1788317311; v=1; x=1788922111; b=OIFRM3D8EhO/vfUMUf9rwBgvuCNOvvDmhpXupqiCpV5kOA64JkJp29FjV43fNNNdgQ+714Kh KZ+erxCTVYNcqPinIpIkEsVgtdCmbKHTYK4fe2h8JeKq0ZkITI/Pf8mjPO7/vXFsDAOXaqX9P3w PnT+wRldc2Ijfhe56Wz9/dzQ= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 4da923a900d17674; Wed, 02 Sep 2026 02:48:31 +0000 X-Mizu-Trace-ID: 4da923a900d17674 X-Migadu-Flow: FLOW_OUT From: Tao Cui To: tj@kernel.org Cc: void@manifault.com, arighi@nvidia.com, changwoo@igalia.com, michalblk@google.com, liwanwu@kylinos.cn, sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, cui.tao@linux.dev, Tao Cui Subject: [PATCH v3 1/2] sched_ext: document the rolling-cursor requirement for dsq_vtime Date: Wed, 2 Sep 2026 10:48:11 +0800 Message-ID: <20260902024812.794879-2-cui.tao@linux.dev> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260902024812.794879-1-cui.tao@linux.dev> References: <20260902024812.794879-1-cui.tao@linux.dev> 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" From: Tao Cui scx_bpf_dsq_insert_vtime() orders tasks by time_before64(), which is only meaningful when the values within a given DSQ stay less than 2^63 apart. This is implicit in how a vtime scheduler works but not spelled out anywhere. Document it so BPF scheduler authors know the constraint. Signed-off-by: Tao Cui --- kernel/sched/ext/ext.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kernel/sched/ext/ext.c b/kernel/sched/ext/ext.c index 8041c87a3562..81a506a4c8ab 100644 --- a/kernel/sched/ext/ext.c +++ b/kernel/sched/ext/ext.c @@ -8903,7 +8903,9 @@ struct scx_bpf_dsq_insert_vtime_args { * * @args->vtime ordering is according to time_before64() which considers * wrapping. A numerically larger vtime may indicate an earlier position i= n the - * ordering and vice-versa. + * ordering and vice-versa. vtime is a rolling cursor and values used for + * ordering within a given DSQ should stay less than 2^63 apart for + * time_before64() ordering to remain well-defined. * * A DSQ can only be used as a FIFO or priority queue at any given time an= d this * function must not be called on a DSQ which already has one or more FIFO= tasks --=20 2.43.0 From nobody Sat Sep 26 11:46:35 2026 Received: from mta0.migadu.com (out-214.mta0.migadu.com [91.218.175.214]) (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 7E93230C14A for ; Wed, 2 Sep 2026 02:48:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.214 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788317320; cv=none; b=byAgi9KVEML8KE6MNFp4xVI0KID/1+sVzNKz0BqCAyf+iL1yM5s7geFHecOlNwQFo9U9kdLlYPZ7pvO9ikOU/00iM0E9GjvOBvYLzYjHpe+HyJucCj1ZtwRdRUMRbQdO7hEIWcp3Kr3Z6ArpMWurwqeYgAdWsEaXQ19DHYS8I/M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788317320; c=relaxed/simple; bh=7s1kUEuoRVkEalRuRbIfe8z8RfYoAvUaeXzHVf0DdbE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DZT6UhrrYIeG+qFw8wlURCsaEKtPb09z5OyCIHRt8kj2mHiPu/8LLOoEYBOmzdK9YXHJdtkITjnBvHt1bnkBGPQqk0ZpfBJKGxR3WoMkGaeXQf3y7jbzZ+1+G6hMNmJ+Re3D0CqBAshoMnWXdg8MF3zjiVIG0yfl85mGQ1UZe14= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=esQOwMBT; arc=none smtp.client-ip=91.218.175.214 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="esQOwMBT" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=7s1kUEuoRVkEalRuRbIfe8z8RfYoAvUaeXzHVf0DdbE=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1788317315; v=1; x=1788922115; b=esQOwMBTh7qjWJGSjnTuwP9bQNyCk25/njVg+vJr+8/yjhIurscV60+KSNJTRsdk3nf8B9z+ 7SrNRVumNCFvF26t3Mhh+faWg8gsJOJyrcyf4zk+uFt3ghri9krz4EhC/T9EAzCRx/1B6Gwe7hY knOy6Dn8BvwU2xzzJOoR2to0= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id f1d819361e354e7d; Wed, 02 Sep 2026 02:48:35 +0000 X-Mizu-Trace-ID: f1d819361e354e7d X-Migadu-Flow: FLOW_OUT From: Tao Cui To: tj@kernel.org Cc: void@manifault.com, arighi@nvidia.com, changwoo@igalia.com, michalblk@google.com, liwanwu@kylinos.cn, sched-ext@lists.linux.dev, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, cui.tao@linux.dev, Tao Cui , Sashiko Subject: [PATCH v3 2/2] sched_ext/scx_flatcg: make cgv_node_less() wraparound-safe Date: Wed, 2 Sep 2026 10:48:12 +0800 Message-ID: <20260902024812.794879-3-cui.tao@linux.dev> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260902024812.794879-1-cui.tao@linux.dev> References: <20260902024812.794879-1-cui.tao@linux.dev> 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" From: Tao Cui cgv_node_less() compares cvtimes with a plain <, which misorders once cvtime wraps: the wrapped node lands at the front of the tree while the unwrapped ones get stuck behind it. Each CPU picking a cgroup charges it a full slice, making wrap occur earlier than a naive estimate might suggest. Use time_before() instead. cgrp_cap_budget() bounds the lag behind cvtime_now, while the lead is bounded by the slice charge plus pending cvtime_delta on re-insertion, so the cyclic ordering assumptions of time_before() hold. Fixes: a4103eacc2ab ("sched_ext: Add a cgroup scheduler which uses flattene= d hierarchy") Reported-by: Sashiko Link: https://lore.kernel.org/r/3f1ce004-e259-4e72-a5f7-14a5050053bd@linux.= dev Signed-off-by: Tao Cui --- tools/sched_ext/scx_flatcg.bpf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/sched_ext/scx_flatcg.bpf.c b/tools/sched_ext/scx_flatcg.= bpf.c index 454ebb820c5e..5e6abd0bccb3 100644 --- a/tools/sched_ext/scx_flatcg.bpf.c +++ b/tools/sched_ext/scx_flatcg.bpf.c @@ -144,7 +144,7 @@ static bool cgv_node_less(struct bpf_rb_node *a, const = struct bpf_rb_node *b) cgc_a =3D container_of(a, struct cgv_node, rb_node); cgc_b =3D container_of(b, struct cgv_node, rb_node); =20 - return cgc_a->cvtime < cgc_b->cvtime; + return time_before(cgc_a->cvtime, cgc_b->cvtime); } =20 static struct fcg_cpu_ctx *find_cpu_ctx(void) --=20 2.43.0