Received: from flow-b1-smtp.messagingengine.com (flow-b1-smtp.messagingengine.com [202.12.124.136]) (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 AE6443128D9 for ; Wed, 22 Jul 2026 21:51:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.12.124.136 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784757113; cv=none; b=uWGab/GFqfk80qwgBKKbNs8B1qwYHv+ymmszwfwhulXlKxcmpY+pTwSskhx6SULUKh/OhwTlDFwqGAp3+3sB1oznHQoMTPZuM6w6TDDE0y80Mj7MGXAUTFndETBNeF/jGAcabfHZLurrUWmUig2Rzd32kA9ZaAKRoUO+WcxiBo0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784757113; c=relaxed/simple; bh=z7wk8z3fKgY3Y/3sqEDTjSHS8OoXxx4nWGG27uKB7zM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S9TouITeGUvksFqXIvTZFOUStYi63sqCWy4rwwt4g6wb/ExZguA+XcE8aUvebHHMV6P++FqmEmPIF0SFzMPWbgKFnZawqZOubDAZf1/3m14eAW4MbVjVvbNuXRHV0tSjhJDmbPBuYN+40d6laEq7tYfcOESOi1H5htlOYagMRt8= 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=N8TJCdrc; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=mdq26PWX; arc=none smtp.client-ip=202.12.124.136 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="N8TJCdrc"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="mdq26PWX" Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44]) by mailflow.stl.internal (Postfix) with ESMTP id 895CB13001FF; Wed, 22 Jul 2026 17:51:50 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Wed, 22 Jul 2026 17:51:51 -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=1784757110; x= 1784760710; bh=vNm/Q8af0obcOcWOukkB3ja9JtroCMxF15RaYJ9nMwE=; b=N 8TJCdrcHsRBEBDVXimKfjJWsK5e7Gu1A82NcweiEk0P6HJcQSsDS6McPY/MQk21s Bl6WBZctkLWcllol2gEAtTUxvEJWI3lZbR3/Wr5tU/BwLOspl+bCCKOuRFxkxTFI z6sgQEN/ByUPGGTvr3F+pUFVis4guWmyhleLFUfsy5M5qaz2/BLU9sfFcPc67aUG 833s7NYhiW9McFIYRoIolhMXm33vi7mYZP7NmAg/OK4wwZAzNmDbaGIBc2Dqvog+ RJq8luzvd2qykxmRmSbzmxffycy1bsQFWCHl7n7WhQGqHjesbukQEJu9esun7PrM tYXzHkFClw8ZFphZ4MseQ== 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=fm2; t=1784757110; x=1784760710; bh=v Nm/Q8af0obcOcWOukkB3ja9JtroCMxF15RaYJ9nMwE=; b=mdq26PWXM0fIcg729 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i51fe4b43:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 22 Jul 2026 17:51:44 -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 v4 5/7] rust: workqueue: take a Delta for the enqueue delay Date: Thu, 23 Jul 2026 06:49:49 +0900 Message-ID: <20260722214951.72941-6-tomo@flapping.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260722214951.72941-1-tomo@flapping.org> References: <20260722214951.72941-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. 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