Skip to content

Commit 1116f0c

Browse files
fujitaAndreas Hindborg
authored andcommitted
rust: hrtimer: Add Ktime temporarily
Add Ktime temporarily until hrtimer is refactored to use Instant and Delta types. Reviewed-by: Andreas Hindborg <[email protected]> Reviewed-by: Boqun Feng <[email protected]> Signed-off-by: FUJITA Tomonori <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Andreas Hindborg <[email protected]>
1 parent 9c32cda commit 1116f0c

File tree

5 files changed

+22
-6
lines changed

5 files changed

+22
-6
lines changed

rust/kernel/time/hrtimer.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,26 @@
6868
//! `start` operation.
6969
7070
use super::ClockId;
71-
use crate::{prelude::*, time::Ktime, types::Opaque};
71+
use crate::{prelude::*, types::Opaque};
7272
use core::marker::PhantomData;
7373
use pin_init::PinInit;
7474

75+
/// A Rust wrapper around a `ktime_t`.
76+
// NOTE: Ktime is going to be removed when hrtimer is converted to Instant/Delta.
77+
#[repr(transparent)]
78+
#[derive(Copy, Clone, PartialEq, PartialOrd, Eq, Ord)]
79+
pub struct Ktime {
80+
inner: bindings::ktime_t,
81+
}
82+
83+
impl Ktime {
84+
/// Returns the number of nanoseconds.
85+
#[inline]
86+
pub fn to_ns(self) -> i64 {
87+
self.inner
88+
}
89+
}
90+
7591
/// A timer backed by a C `struct hrtimer`.
7692
///
7793
/// # Invariants

rust/kernel/time/hrtimer/arc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ use super::HrTimer;
55
use super::HrTimerCallback;
66
use super::HrTimerHandle;
77
use super::HrTimerPointer;
8+
use super::Ktime;
89
use super::RawHrTimerCallback;
910
use crate::sync::Arc;
1011
use crate::sync::ArcBorrow;
11-
use crate::time::Ktime;
1212

1313
/// A handle for an `Arc<HasHrTimer<T>>` returned by a call to
1414
/// [`HrTimerPointer::start`].

rust/kernel/time/hrtimer/pin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use super::HasHrTimer;
44
use super::HrTimer;
55
use super::HrTimerCallback;
66
use super::HrTimerHandle;
7+
use super::Ktime;
78
use super::RawHrTimerCallback;
89
use super::UnsafeHrTimerPointer;
9-
use crate::time::Ktime;
1010
use core::pin::Pin;
1111

1212
/// A handle for a `Pin<&HasHrTimer>`. When the handle exists, the timer might be

rust/kernel/time/hrtimer/pin_mut.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// SPDX-License-Identifier: GPL-2.0
22

33
use super::{
4-
HasHrTimer, HrTimer, HrTimerCallback, HrTimerHandle, RawHrTimerCallback, UnsafeHrTimerPointer,
4+
HasHrTimer, HrTimer, HrTimerCallback, HrTimerHandle, Ktime, RawHrTimerCallback,
5+
UnsafeHrTimerPointer,
56
};
6-
use crate::time::Ktime;
77
use core::{marker::PhantomData, pin::Pin, ptr::NonNull};
88

99
/// A handle for a `Pin<&mut HasHrTimer>`. When the handle exists, the timer might

rust/kernel/time/hrtimer/tbox.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ use super::HrTimer;
55
use super::HrTimerCallback;
66
use super::HrTimerHandle;
77
use super::HrTimerPointer;
8+
use super::Ktime;
89
use super::RawHrTimerCallback;
910
use crate::prelude::*;
10-
use crate::time::Ktime;
1111
use core::ptr::NonNull;
1212

1313
/// A handle for a [`Box<HasHrTimer<T>>`] returned by a call to

0 commit comments

Comments
 (0)