From: FUJITA Tomonori <tomo@aliasing.net>
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 <fujita.tomonori@gmail.com>
Subject: [PATCH v1 2/2] rust: sync: use Delta for CondVar timeout API
Date: Sat, 4 Jul 2026 22:25:58 +0900 [thread overview]
Message-ID: <20260704132558.2253275-3-tomo@aliasing.net> (raw)
In-Reply-To: <20260704132558.2253275-1-tomo@aliasing.net>
From: FUJITA Tomonori <fujita.tomonori@gmail.com>
wait_interruptible_timeout() and CondVarTimeoutResult take/return a
raw jiffies count (a plain c_ulong alias with no type safety). Callers
have to know on their own that the value meant jiffies and convert
to/from it themselves, which is easy to get wrong (e.g. passing a
millisecond value where a jiffies value is expected).
Switch to Delta, the duration type already used elsewhere, so the unit
is part of the type instead of a caller convention.
Use as_jiffies_ceil() rather than a plain truncating conversion: a
caller that passes a nonzero Delta expects the call to actually sleep
for roughly that long (or return earlier via a wakeup or signal).
Update binder's ioctl_freeze(), the only caller, accordingly.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
---
drivers/android/binder/process.rs | 12 ++++++------
rust/kernel/sync/condvar.rs | 20 ++++++++++++--------
2 files changed, 18 insertions(+), 14 deletions(-)
diff --git a/drivers/android/binder/process.rs b/drivers/android/binder/process.rs
index 96b8440ceac6..cc693484489a 100644
--- a/drivers/android/binder/process.rs
+++ b/drivers/android/binder/process.rs
@@ -1468,25 +1468,25 @@ pub(crate) fn ioctl_freeze(&self, info: &BinderFreezeInfo) -> Result {
inner.is_frozen = IsFrozen::InProgress;
if info.timeout_ms > 0 {
- let mut jiffies = kernel::time::msecs_to_jiffies(info.timeout_ms);
- while jiffies > 0 {
+ let mut delta = kernel::time::Delta::from_millis(info.timeout_ms.into());
+ while !delta.is_zero() {
if inner.outstanding_txns == 0 {
break;
}
match self
.freeze_wait
- .wait_interruptible_timeout(&mut inner, jiffies)
+ .wait_interruptible_timeout(&mut inner, delta)
{
CondVarTimeoutResult::Signal { .. } => {
inner.is_frozen = IsFrozen::No;
return Err(ERESTARTSYS);
}
- CondVarTimeoutResult::Woken { jiffies: remaining } => {
- jiffies = remaining;
+ CondVarTimeoutResult::Woken { delta: remaining } => {
+ delta = remaining;
}
CondVarTimeoutResult::Timeout => {
- jiffies = 0;
+ delta = kernel::time::Delta::ZERO;
}
}
}
diff --git a/rust/kernel/sync/condvar.rs b/rust/kernel/sync/condvar.rs
index 69d58dfbad7b..c94ae83a583f 100644
--- a/rust/kernel/sync/condvar.rs
+++ b/rust/kernel/sync/condvar.rs
@@ -12,7 +12,7 @@
task::{
MAX_SCHEDULE_TIMEOUT, TASK_FREEZABLE, TASK_INTERRUPTIBLE, TASK_NORMAL, TASK_UNINTERRUPTIBLE,
},
- time::Jiffies,
+ time::Delta,
types::Opaque,
};
use core::{marker::PhantomPinned, pin::Pin, ptr};
@@ -186,15 +186,19 @@ pub fn wait_interruptible_freezable<T: ?Sized, B: Backend>(
pub fn wait_interruptible_timeout<T: ?Sized, B: Backend>(
&self,
guard: &mut Guard<'_, T, B>,
- jiffies: Jiffies,
+ delta: Delta,
) -> CondVarTimeoutResult {
- let jiffies = jiffies.try_into().unwrap_or(MAX_SCHEDULE_TIMEOUT);
+ let jiffies = c_long::try_from(delta.as_jiffies_ceil()).unwrap_or(MAX_SCHEDULE_TIMEOUT);
let res = self.wait_internal(TASK_INTERRUPTIBLE, guard, jiffies);
- match (res as Jiffies, crate::current!().signal_pending()) {
- (jiffies, true) => CondVarTimeoutResult::Signal { jiffies },
+ match (res, crate::current!().signal_pending()) {
+ (jiffies, true) => CondVarTimeoutResult::Signal {
+ delta: Delta::from_jiffies(jiffies as u64),
+ },
(0, false) => CondVarTimeoutResult::Timeout,
- (jiffies, false) => CondVarTimeoutResult::Woken { jiffies },
+ (jiffies, false) => CondVarTimeoutResult::Woken {
+ delta: Delta::from_jiffies(jiffies as u64),
+ },
}
}
@@ -248,11 +252,11 @@ pub enum CondVarTimeoutResult {
/// Somebody woke us up.
Woken {
/// Remaining sleep duration.
- jiffies: Jiffies,
+ delta: Delta,
},
/// A signal occurred.
Signal {
/// Remaining sleep duration.
- jiffies: Jiffies,
+ delta: Delta,
},
}
--
2.43.0
prev parent reply other threads:[~2026-07-04 13:27 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-04 13:25 [PATCH v1 0/2] rust: switch CondVar's timeout API to Delta FUJITA Tomonori
2026-07-04 13:25 ` [PATCH v1 1/2] rust: time: add jiffies conversion helpers " FUJITA Tomonori
2026-07-04 13:25 ` FUJITA Tomonori [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260704132558.2253275-3-tomo@aliasing.net \
--to=tomo@aliasing.net \
--cc=a.hindborg@kernel.org \
--cc=acourbot@nvidia.com \
--cc=aliceryhl@google.com \
--cc=anna-maria@linutronix.de \
--cc=arve@android.com \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun@kernel.org \
--cc=brauner@kernel.org \
--cc=cmllamas@google.com \
--cc=dakr@kernel.org \
--cc=daniel.almeida@collabora.com \
--cc=frederic@kernel.org \
--cc=fujita.tomonori@gmail.com \
--cc=gary@garyguo.net \
--cc=gregkh@linuxfoundation.org \
--cc=jstultz@google.com \
--cc=lossin@kernel.org \
--cc=lyude@redhat.com \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=sboyd@kernel.org \
--cc=tamird@kernel.org \
--cc=tglx@kernel.org \
--cc=tkjos@android.com \
--cc=tmgross@umich.edu \
--cc=work@onurozkan.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox