rust-for-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lyude Paul <lyude@redhat.com>
To: rust-for-linux@vger.kernel.org,
	Andreas Hindborg <a.hindborg@kernel.org>,
	linux-kernel@vger.kernel.org
Cc: "Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <benno.lossin@proton.me>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Thomas Gleixner" <tglx@linutronix.de>
Subject: [PATCH 1/6] rust: time: Add Ktime::from_ns()
Date: Wed,  2 Apr 2025 17:40:29 -0400	[thread overview]
Message-ID: <20250402214109.653341-2-lyude@redhat.com> (raw)
In-Reply-To: <20250402214109.653341-1-lyude@redhat.com>

A simple function to turn the provided value in nanoseconds into a Ktime
value. We allow any type which implements Into<bindings::ktime_t>, which
resolves to Into<i64>.

This is useful for some of the older DRM APIs that never got moved to
Ktime.

Signed-off-by: Lyude Paul <lyude@redhat.com>
Signed-off-by: Andreas Hindborg <a.hindborg@kernel.org>
---
 rust/kernel/time.rs | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs
index f509cb0eb71e0..c05afda07a05f 100644
--- a/rust/kernel/time.rs
+++ b/rust/kernel/time.rs
@@ -1,5 +1,4 @@
-// SPDX-License-Identifier: GPL-2.0
-
+// SPDX-License-Identifier: GPL-2.0 
 //! Time related primitives.
 //!
 //! This module contains the kernel APIs related to time and timers that
@@ -9,6 +8,7 @@
 //! C header: [`include/linux/ktime.h`](srctree/include/linux/ktime.h).
 
 pub mod hrtimer;
+use core::convert::Into;
 
 /// The number of nanoseconds per millisecond.
 pub const NSEC_PER_MSEC: i64 = bindings::NSEC_PER_MSEC as i64;
@@ -65,6 +65,12 @@ pub fn to_ns(self) -> i64 {
     pub fn to_ms(self) -> i64 {
         self.divns_constant::<NSEC_PER_MSEC>()
     }
+
+    /// Creates a new Ktime from the given duration in nanoseconds.
+    #[inline]
+    pub fn from_nanos(ns: impl Into<bindings::ktime_t>) -> Self {
+        Self { inner: ns.into() }
+    }
 }
 
 /// Returns the number of milliseconds between two ktimes.
-- 
2.48.1


  reply	other threads:[~2025-04-02 21:41 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <f6qilrOyPKqI41LxEG6tS9lHm1gKZ1uxYBqonJEDGUzfNeg7JTLx0ygMtZCymEQv07RW8nGgFqhspMslAh8hAg==@protonmail.internalid>
2025-04-02 21:40 ` [PATCH 0/6] rust/hrtimer: Various hrtimer + time additions Lyude Paul
2025-04-02 21:40   ` Lyude Paul [this message]
2025-04-02 21:40   ` [PATCH 2/6] rust: hrtimer: Add HrTimerCallbackContext and ::forward() Lyude Paul
2025-04-03 11:25     ` Thomas Gleixner
2025-04-08 11:47     ` Andreas Hindborg
2025-04-08 21:55       ` Lyude Paul
2025-04-09  7:49         ` Andreas Hindborg
2025-04-09 16:58           ` Lyude Paul
2025-04-09 17:15             ` Lyude Paul
2025-04-10  6:21               ` Andreas Hindborg
2025-04-11 20:48                 ` Lyude Paul
2025-04-02 21:40   ` [PATCH 3/6] rust: hrtimer: Add HrTimerClockBase Lyude Paul
2025-04-08 11:58     ` Andreas Hindborg
2025-04-02 21:40   ` [PATCH 4/6] rust: hrtimer: Add HrTimerClockBase::time() Lyude Paul
2025-04-08 12:00     ` Andreas Hindborg
2025-04-09 18:39       ` Lyude Paul
2025-04-02 21:40   ` [PATCH 5/6] rust: hrtimer: Add HrTimerCallbackContext::forward_now() Lyude Paul
2025-04-08 12:05     ` Andreas Hindborg
2025-04-02 21:40   ` [PATCH 6/6] rust: hrtimer: Add HrTimerCallback::expires() Lyude Paul
2025-04-08 12:16     ` Andreas Hindborg
2025-04-08 11:51   ` [PATCH 0/6] rust/hrtimer: Various hrtimer + time additions Andreas Hindborg
2025-04-08 21:47     ` Lyude Paul

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=20250402214109.653341-2-lyude@redhat.com \
    --to=lyude@redhat.com \
    --cc=a.hindborg@kernel.org \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=benno.lossin@proton.me \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=tmgross@umich.edu \
    /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;
as well as URLs for NNTP newsgroup(s).