|
8 | 8 | /// The time unit of Linux kernel. One jiffy equals (1/HZ) second. |
9 | 9 | pub type Jiffies = core::ffi::c_ulong; |
10 | 10 |
|
| 11 | +/// Jiffies, but with a fixed width of 32bit. |
| 12 | +pub type Jiffies32 = u32; |
| 13 | + |
11 | 14 | /// The millisecond time unit. |
12 | 15 | pub type Msecs = core::ffi::c_uint; |
13 | 16 |
|
| 17 | +/// The milliseconds time unit with a fixed width of 32bit. |
| 18 | +/// |
| 19 | +/// This is used in networking. |
| 20 | +pub type Msecs32 = u32; |
| 21 | + |
| 22 | +/// The microseconds time unit. |
| 23 | +pub type Usecs = u64; |
| 24 | + |
| 25 | +/// Microseconds per millisecond. |
| 26 | +pub const USEC_PER_MSEC: Usecs = 1000; |
| 27 | + |
| 28 | +/// The microseconds time unit with a fixed width of 32bit. |
| 29 | +/// |
| 30 | +/// This is used in networking. |
| 31 | +pub type Usecs32 = u32; |
| 32 | + |
| 33 | +/// The nanosecond time unit. |
| 34 | +pub type Nsecs = u64; |
| 35 | + |
| 36 | +/// Nanoseconds per microsecond. |
| 37 | +pub const NSEC_PER_USEC: Nsecs = 1000; |
| 38 | + |
14 | 39 | /// Converts milliseconds to jiffies. |
15 | 40 | #[inline] |
16 | 41 | pub fn msecs_to_jiffies(msecs: Msecs) -> Jiffies { |
17 | 42 | // SAFETY: The `__msecs_to_jiffies` function is always safe to call no |
18 | 43 | // matter what the argument is. |
19 | 44 | unsafe { bindings::__msecs_to_jiffies(msecs) } |
20 | 45 | } |
| 46 | + |
| 47 | +/// Converts jiffies to milliseconds. |
| 48 | +#[inline] |
| 49 | +pub fn jiffies_to_msecs(jiffies: Jiffies) -> Msecs { |
| 50 | + // SAFETY: The `__msecs_to_jiffies` function is always safe to call no |
| 51 | + // matter what the argument is. |
| 52 | + unsafe { bindings::jiffies_to_msecs(jiffies) } |
| 53 | +} |
| 54 | + |
| 55 | +/// Returns the current time in 32bit jiffies. |
| 56 | +#[inline] |
| 57 | +pub fn jiffies32() -> Jiffies32 { |
| 58 | + // SAFETY: It is always atomic to read the lower 32bit of jiffies. |
| 59 | + unsafe { bindings::jiffies as u32 } |
| 60 | +} |
| 61 | + |
| 62 | +/// Returns the time elapsed since system boot, in nanoseconds. Does include the |
| 63 | +/// time the system was suspended. |
| 64 | +#[inline] |
| 65 | +pub fn ktime_get_boot_fast_ns() -> Nsecs { |
| 66 | + // SAFETY: FFI call without safety requirements. |
| 67 | + unsafe { bindings::ktime_get_boot_fast_ns() } |
| 68 | +} |
0 commit comments