| 1 | |
| 2 |
|
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 |
|
| 11 | |
| 12 | pub const NSEC_PER_MSEC: i64 = bindings::NSEC_PER_MSEC as i64;
|
| 13 |
|
| 14 | |
| 15 | pub type Jiffies = crate::ffi::c_ulong;
|
| 16 |
|
| 17 | |
| 18 | pub type Msecs = crate::ffi::c_uint;
|
| 19 |
|
| 20 | |
| 21 | #[inline]
|
| 22 | pub fn msecs_to_jiffies(msecs: Msecs) -> Jiffies {
|
| 23 | |
| 24 | |
| 25 | unsafe { bindings::__msecs_to_jiffies(msecs) }
|
| 26 | }
|
| 27 |
|
| 28 | |
| 29 | #[repr(transparent)]
|
| 30 | #[derive(Copy, Clone)]
|
| 31 | pub struct Ktime {
|
| 32 | inner: bindings::ktime_t,
|
| 33 | }
|
| 34 |
|
| 35 | impl Ktime {
|
| 36 | |
| 37 | #[inline]
|
| 38 | pub fn from_raw(inner: bindings::ktime_t) -> Self {
|
| 39 | Self { inner }
|
| 40 | }
|
| 41 |
|
| 42 | |
| 43 | #[inline]
|
| 44 | pub fn ktime_get() -> Self {
|
| 45 | |
| 46 | Self::from_raw(unsafe { bindings::ktime_get() })
|
| 47 | }
|
| 48 |
|
| 49 | |
| 50 | #[inline]
|
| 51 | fn divns_constant<const DIV: i64>(self) -> i64 {
|
| 52 | self.to_ns() / DIV
|
| 53 | }
|
| 54 |
|
| 55 | |
| 56 | #[inline]
|
| 57 | pub fn to_ns(self) -> i64 {
|
| 58 | self.inner
|
| 59 | }
|
| 60 |
|
| 61 | |
| 62 | #[inline]
|
| 63 | pub fn to_ms(self) -> i64 {
|
| 64 | self.divns_constant::<NSEC_PER_MSEC>()
|
| 65 | }
|
| 66 | }
|
| 67 |
|
| 68 | |
| 69 | #[inline]
|
| 70 | pub fn ktime_ms_delta(later: Ktime, earlier: Ktime) -> i64 {
|
| 71 | (later - earlier).to_ms()
|
| 72 | }
|
| 73 |
|
| 74 | impl core::ops::Sub for Ktime {
|
| 75 | type Output = Ktime;
|
| 76 |
|
| 77 | #[inline]
|
| 78 | fn sub(self, other: Ktime) -> Ktime {
|
| 79 | Self {
|
| 80 | inner: self.inner - other.inner,
|
| 81 | }
|
| 82 | }
|
| 83 | }
|