From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from flow-a7-smtp.messagingengine.com (flow-a7-smtp.messagingengine.com [103.168.172.142]) (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 46006394792 for ; Sat, 8 Aug 2026 06:29:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.142 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786170574; cv=none; b=npxPrbEqoPGTfKAky6j/kqy0AQB0WvVeMr5ASBe7SZAG+AubhnGvGRDF5QXaw6/hgK+Zyhoig0ZskElM7Kci4NpWabSIA29pOj+IfxpKdirWhlTHvEBiBVD0EAE0ukOZAyUmHLHfwqYCJpetJDGWpcTocnwYXyZxnpij6pbwORU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786170574; c=relaxed/simple; bh=Cq6CHfD1VDn8enm92sBhYVT/TK0WSnStJY+D4LOpLL4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=vB3YIwZOwkeS/5xBmmaxucgWx3xv9M3aBaCx/4CNndRTiDDslSg8GGNXPUi+kYe8w5OD4LECxsSZ//Ram8adrD/uUW2/cAE1nJDUyXpWmQ/2oUGkLSehH5FcHpOnf5IW7QSxDbUhvmEjfriYZ0ITSPeH/vRuYGgyMC/IBEHQSLA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=flapping.org; spf=pass smtp.mailfrom=flapping.org; dkim=pass (2048-bit key) header.d=flapping.org header.i=@flapping.org header.b=VKOebWJa; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=cdEQ3URy; arc=none smtp.client-ip=103.168.172.142 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=flapping.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flapping.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=flapping.org header.i=@flapping.org header.b="VKOebWJa"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="cdEQ3URy" Received: from phl-compute-12.internal (phl-compute-12.internal [10.202.2.52]) by mailflow.phl.internal (Postfix) with ESMTP id 626D613801CB; Sat, 8 Aug 2026 02:29:32 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-12.internal (MEProxy); Sat, 08 Aug 2026 02:29:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flapping.org; h= cc:cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1786170572; x= 1786174172; bh=YnvpxGjUdDPnwVdv39sCuVHJeYJIDj388v7/Pjvrdcg=; b=V KOebWJaZDFw3NUyhx/ykVfYgXOugcL7YGxwGMERfvJf1RlMU5pwYmMH93SbnvUli 34DWdXVH0cViRKrLBZJINA+shDgpT0MsjaD2DCyKlinSUc15l+z0GehFBwJLuUvb 8osQLotqYoCe1UOOnMxFeqp5OwIaqSA/XSAgTvvYyWakAu6K21wEbpwDrnvhko6p xfUdIZEgrePZ6ymEQXZlt76zZvjcw4NKA1NB68K5N5pS0XJ5umBPUuLO6DivjJS3 aBdJrWZ5OWBPOG5r0QAXK+JcFTq/PiAxYh2iw/YEv0kpJ4ZTAptHuC4o0zA/ERyt o8mAzcR7a5k6uQJlchPYw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1786170572; x=1786174172; bh=Y nvpxGjUdDPnwVdv39sCuVH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wWWVSahHLk2+yQQ/g X-ME-Proxy: Feedback-ID: i51fe4b43:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 8 Aug 2026 02:29:26 -0400 (EDT) From: FUJITA Tomonori To: a.hindborg@kernel.org, aliceryhl@google.com, arve@android.com, boqun@kernel.org, brauner@kernel.org, cmllamas@google.com, gary@garyguo.net, gregkh@linuxfoundation.org, ojeda@kernel.org, tkjos@android.com Cc: acourbot@nvidia.com, anna-maria@linutronix.de, bjorn3_gh@protonmail.com, dakr@kernel.org, daniel.almeida@collabora.com, frederic@kernel.org, jstultz@google.com, lossin@kernel.org, lyude@redhat.com, sboyd@kernel.org, tamird@kernel.org, tglx@kernel.org, tmgross@umich.edu, work@onurozkan.dev, rust-for-linux@vger.kernel.org, FUJITA Tomonori Subject: [PATCH v6 5/7] rust: workqueue: take a Delta for the enqueue delay Date: Sat, 8 Aug 2026 15:28:37 +0900 Message-ID: <20260808062839.1159990-6-tomo@flapping.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260808062839.1159990-1-tomo@flapping.org> References: <20260808062839.1159990-1-tomo@flapping.org> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: FUJITA Tomonori enqueue_delayed() takes the delay as a raw Jiffies (c_ulong). That is the C representation rather than a kernel time type, so it neither carries the unit in its type nor composes with the Delta arithmetic used elsewhere for expressing spans, and it forces callers to hand the API a bare integer. Change the delay parameter to Delta so a delay is expressed in the same time vocabulary as the rest of the kernel crate. A signed Delta can be negative, so clamp it to zero before handing it to the C side, which keeps "no delay" the natural meaning of a non-positive span. Reviewed-by: Gary Guo Signed-off-by: FUJITA Tomonori --- rust/kernel/workqueue.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/rust/kernel/workqueue.rs b/rust/kernel/workqueue.rs index 7e253b6f299c..d4f8a3ea5acb 100644 --- a/rust/kernel/workqueue.rs +++ b/rust/kernel/workqueue.rs @@ -171,7 +171,7 @@ //! /// This method will enqueue the struct for execution on the system workqueue, where its value //! /// will be printed 12 jiffies later. //! fn print_later(val: Arc) { -//! let _ = workqueue::system().enqueue_delayed(val, 12); +//! let _ = workqueue::system().enqueue_delayed(val, kernel::time::Delta::from_jiffies(12)); //! } //! //! /// It is also possible to use the ordinary `enqueue` method together with `DelayedWork`. This @@ -197,7 +197,10 @@ Arc, LockClassKey, // }, - time::Jiffies, + time::{ + Delta, + Jiffy, // + }, types::Opaque, }; use core::{marker::PhantomData, ptr::NonNull}; @@ -303,11 +306,14 @@ pub fn enqueue(&self, w: W) -> W::EnqueueOutput /// This may fail if the work item is already enqueued in a workqueue. /// /// The work item will be submitted using `WORK_CPU_UNBOUND`. - pub fn enqueue_delayed(&self, w: W, delay: Jiffies) -> W::EnqueueOutput + pub fn enqueue_delayed(&self, w: W, delta: Delta) -> W::EnqueueOutput where W: RawDelayedWorkItem + Send + 'static, { let queue_ptr = self.0.get(); + // CAST: A negative delay is clamped to `0`, so the value is non-negative + // and fits in `c_ulong`. + let delay = delta.as_jiffies().max(0) as ffi::c_ulong; // SAFETY: We only return `false` if the `work_struct` is already in a workqueue. The other // `__enqueue` requirements are not relevant since `W` is `Send` and static. -- 2.43.0