public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Boqun Feng <boqun.feng@gmail.com>
To: Benno Lossin <benno.lossin@proton.me>
Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Wedson Almeida Filho" <wedsonaf@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Andreas Hindborg" <a.hindborg@samsung.com>,
	"John Stultz" <jstultz@google.com>,
	"Stephen Boyd" <sboyd@kernel.org>,
	"Valentin Obst" <kernel@valentinobst.de>,
	"Heghedus Razvan" <heghedus.razvan@protonmail.com>,
	"Asahi Lina" <lina@asahilina.net>
Subject: Re: [PATCH 4/5] rust: time: Support reading CLOCK_MONOTONIC
Date: Tue, 26 Mar 2024 12:21:34 -0700	[thread overview]
Message-ID: <ZgMgPqrtc2FSkYZW@boqun-archlinux> (raw)
In-Reply-To: <4wFCQqSgpLIPmdFau6MTL1XLLB73d9Tuv5y-VFnXTDc1DFuTnmNV-GLtF582V5yz8s9ogWP_4U0NK3ei6sZlD1oLl929f8ADoT5K9bO6uKs=@proton.me>

On Tue, Mar 26, 2024 at 05:03:41PM +0000, Benno Lossin wrote:
> On 24.03.24 23:33, Boqun Feng wrote:
> > Rust Binder will need to read CLOCK_MONOTONIC to compute how many
> > milliseconds a transaction has been active for when dumping the current
> > state of the Binder driver. This replicates the logic in C Binder [1].
> > 
> > For a usage example in Rust Binder, see [2].
> > 
> > Hence add the support for CLOCK_MONOTONIC read.
> > 
> > The `ktime_get` method cannot be safely called in NMI context. This
> > requirement is not checked by these abstractions, but it is intended
> > that klint [3] or a similar tool will be used to check it in the future.
> > 
> > Link: https://lore.kernel.org/lkml/5ac8c0d09392290be789423f0dd78a520b830fab.1682333709.git.zhangchuang3@xiaomi.com/ [1]
> > Link: https://r.android.com/3004103 [2]
> > Link: https://rust-for-linux.com/klint [3]
> > Co-developed-by: Heghedus Razvan <heghedus.razvan@protonmail.com>
> > Signed-off-by: Heghedus Razvan <heghedus.razvan@protonmail.com>
> > Co-developed-by: Asahi Lina <lina@asahilina.net>
> > Signed-off-by: Asahi Lina <lina@asahilina.net>
> > Co-developed-by: Alice Ryhl <aliceryhl@google.com>
> > Signed-off-by: Alice Ryhl <aliceryhl@google.com>
> > Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
> 
> With the nit fixed:
> 
> Reviewed-by: Benno Lossin <benno.lossin@proton.me>
> 

Thanks!

> > ---
> > @Alice, I still put the link to the usage of Android binder here, if you
> > want to remove that, please let me know.
> > 
> >  rust/kernel/time.rs | 19 +++++++++++++++++++
> >  1 file changed, 19 insertions(+)
> > 
> > diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs
> > index 0f9f5605ed48..5cd669cbea01 100644
> > --- a/rust/kernel/time.rs
> > +++ b/rust/kernel/time.rs
> > @@ -113,3 +113,22 @@ fn sub(self, other: Self) -> Self::Output {
> >          Duration::new(self.inner.wrapping_sub(other.inner))
> >      }
> >  }
> > +
> > +/// Contains the various clock source types available to the kernel.
> > +pub mod clock {
> > +    use super::*;
> > +
> > +    /// A clock representing the default kernel time source (`CLOCK_MONOTONIC`).
> > +    pub struct KernelTime;
> > +
> > +    /// `CLOCK_MONOTONIC` is monotonic.
> > +    impl Monotonic for KernelTime {}
> > +
> > +    impl Clock for KernelTime {
> > +        #[inline]
> > +        fn now() -> Instant<Self> {
> > +            // SAFETY: It is always safe to call `ktime_get` outside of NMI context.
> > +            Instant::<Self>::new(unsafe { bindings::ktime_get() })
> 
> I don't think the turbofish syntax (the `::<Self>` part) is needed here.
> 

Fixed locally.

Regards,
Boqun

> -- 
> Cheers,
> Benno
> 
> > +        }
> > +    }
> > +}
> > --
> > 2.44.0
> >

  reply	other threads:[~2024-03-26 19:22 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-24 22:33 [PATCH 0/5] rust: time: Add clock read support Boqun Feng
2024-03-24 22:33 ` [PATCH 1/5] rust: time: doc: Add missing C header link to jiffies Boqun Feng
2024-03-26 16:44   ` Benno Lossin
2024-03-24 22:33 ` [PATCH 2/5] rust: time: Introduce Duration type Boqun Feng
2024-03-26 16:50   ` Benno Lossin
2024-03-26 17:11     ` Boqun Feng
2024-03-26 17:17       ` Boqun Feng
2024-03-27 11:18         ` Benno Lossin
2024-03-24 22:33 ` [PATCH 3/5] rust: time: Introduce clock reading framework Boqun Feng
2024-03-26 17:00   ` Benno Lossin
2024-03-26 19:19     ` Boqun Feng
2024-03-27 12:50       ` Benno Lossin
2024-03-27 17:49         ` Boqun Feng
2024-03-24 22:33 ` [PATCH 4/5] rust: time: Support reading CLOCK_MONOTONIC Boqun Feng
2024-03-26 17:03   ` Benno Lossin
2024-03-26 19:21     ` Boqun Feng [this message]
2024-03-24 22:33 ` [PATCH 5/5] rust: time: Add Instant::elapsed() for monotonic clocks Boqun Feng
2024-03-26 17:13   ` Benno Lossin
2024-03-26 18:00     ` Boqun Feng
2024-03-26 18:04       ` Boqun Feng
2024-03-27  1:09       ` Boqun Feng
2024-03-27 11:31         ` Benno Lossin

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=ZgMgPqrtc2FSkYZW@boqun-archlinux \
    --to=boqun.feng@gmail.com \
    --cc=a.hindborg@samsung.com \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=benno.lossin@proton.me \
    --cc=bjorn3_gh@protonmail.com \
    --cc=gary@garyguo.net \
    --cc=heghedus.razvan@protonmail.com \
    --cc=jstultz@google.com \
    --cc=kernel@valentinobst.de \
    --cc=lina@asahilina.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=sboyd@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=wedsonaf@gmail.com \
    /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