From: Andreas Hindborg <a.hindborg@kernel.org>
To: "FUJITA Tomonori" <fujita.tomonori@gmail.com>
Cc: <alex.gaynor@gmail.com>, <ojeda@kernel.org>,
<aliceryhl@google.com>, <anna-maria@linutronix.de>,
<bjorn3_gh@protonmail.com>, <boqun.feng@gmail.com>,
<dakr@kernel.org>, <frederic@kernel.org>, <gary@garyguo.net>,
<jstultz@google.com>, <linux-kernel@vger.kernel.org>,
<lossin@kernel.org>, <lyude@redhat.com>,
<rust-for-linux@vger.kernel.org>, <sboyd@kernel.org>,
<tglx@linutronix.de>, <tmgross@umich.edu>
Subject: Re: [PATCH v3 3/3] rust: time: Add ktime_get() to ClockSource trait
Date: Tue, 10 Jun 2025 11:34:00 +0200 [thread overview]
Message-ID: <87h60o2b5j.fsf@kernel.org> (raw)
In-Reply-To: <20250610.171506.1930082951902279512.fujita.tomonori@gmail.com> (FUJITA Tomonori's message of "Tue, 10 Jun 2025 17:15:06 +0900")
"FUJITA Tomonori" <fujita.tomonori@gmail.com> writes:
> On Tue, 10 Jun 2025 10:01:57 +0200
> Andreas Hindborg <a.hindborg@kernel.org> wrote:
>
>> "FUJITA Tomonori" <fujita.tomonori@gmail.com> writes:
>>
>>> Introduce the ktime_get() associated function to the ClockSource
>>> trait, allowing each clock source to specify how it retrieves the
>>> current time. This enables Instant::now() to be implemented
>>> generically using the type-level ClockSource abstraction.
>>>
>>> This change enhances the type safety and extensibility of timekeeping
>>> by statically associating time retrieval mechanisms with their
>>> respective clock types. It also reduces the reliance on hardcoded
>>> clock logic within Instant.
>>>
>>> Reviewed-by: Andreas Hindborg <a.hindborg@kernel.org>
>>> Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
>>> ---
>>> rust/helpers/helpers.c | 1 +
>>> rust/helpers/time.c | 18 ++++++++++++++++++
>>> rust/kernel/time.rs | 32 ++++++++++++++++++++++++++++----
>>> 3 files changed, 47 insertions(+), 4 deletions(-)
>>> create mode 100644 rust/helpers/time.c
>>>
>>> diff --git a/rust/helpers/helpers.c b/rust/helpers/helpers.c
>>> index 0f1b5d115985..0613a849e05c 100644
>>> --- a/rust/helpers/helpers.c
>>> +++ b/rust/helpers/helpers.c
>>> @@ -39,6 +39,7 @@
>>> #include "spinlock.c"
>>> #include "sync.c"
>>> #include "task.c"
>>> +#include "time.c"
>>> #include "uaccess.c"
>>> #include "vmalloc.c"
>>> #include "wait.c"
>>> diff --git a/rust/helpers/time.c b/rust/helpers/time.c
>>> new file mode 100644
>>> index 000000000000..9c296e93a560
>>> --- /dev/null
>>> +++ b/rust/helpers/time.c
>>> @@ -0,0 +1,18 @@
>>> +// SPDX-License-Identifier: GPL-2.0
>>> +
>>> +#include <linux/timekeeping.h>
>>> +
>>> +ktime_t rust_helper_ktime_get_real(void)
>>> +{
>>> + return ktime_get_with_offset(TK_OFFS_REAL);
>>> +}
>>> +
>>> +ktime_t rust_helper_ktime_get_boottime(void)
>>> +{
>>> + return ktime_get_with_offset(TK_OFFS_BOOT);
>>> +}
>>> +
>>> +ktime_t rust_helper_ktime_get_clocktai(void)
>>> +{
>>> + return ktime_get_with_offset(TK_OFFS_TAI);
>>> +}
>>
>> This just caught my eye. I think policy is to make helpers as much 1:1 as
>> possible. We should not inject arguments here. Instead, we should have
>> just one function that passes the argument along.
>
> Indeed, you're right. It should have been as follows:
>
> +++ b/rust/helpers/time.c
> @@ -0,0 +1,18 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +#include <linux/timekeeping.h>
> +
> +ktime_t rust_helper_ktime_get_real(void)
> +{
> + return ktime_get_real();
> +}
> +
> +ktime_t rust_helper_ktime_get_boottime(void)
> +{
> + return ktime_get_boottime();
> +}
> +
> +ktime_t rust_helper_ktime_get_clocktai(void)
> +{
> + return ktime_get_clocktai();
> +}
Yes, even better 👍
Best regards,
Andreas Hindborg
next prev parent reply other threads:[~2025-06-10 10:25 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-09 1:04 [PATCH v3 0/3] rust: time: Introduce typed clock sources and generalize Instant FUJITA Tomonori
2025-06-09 1:04 ` [PATCH v3 1/3] rust: time: Replace ClockId enum with ClockSource trait FUJITA Tomonori
2025-06-09 1:04 ` [PATCH v3 2/3] rust: time: Make Instant generic over ClockSource FUJITA Tomonori
2025-06-09 1:04 ` [PATCH v3 3/3] rust: time: Add ktime_get() to ClockSource trait FUJITA Tomonori
2025-06-10 8:01 ` Andreas Hindborg
2025-06-10 8:15 ` FUJITA Tomonori
2025-06-10 9:34 ` Andreas Hindborg [this message]
2025-06-09 2:55 ` [PATCH v3 0/3] rust: time: Introduce typed clock sources and generalize Instant Boqun Feng
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=87h60o2b5j.fsf@kernel.org \
--to=a.hindborg@kernel.org \
--cc=alex.gaynor@gmail.com \
--cc=aliceryhl@google.com \
--cc=anna-maria@linutronix.de \
--cc=bjorn3_gh@protonmail.com \
--cc=boqun.feng@gmail.com \
--cc=dakr@kernel.org \
--cc=frederic@kernel.org \
--cc=fujita.tomonori@gmail.com \
--cc=gary@garyguo.net \
--cc=jstultz@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lossin@kernel.org \
--cc=lyude@redhat.com \
--cc=ojeda@kernel.org \
--cc=rust-for-linux@vger.kernel.org \
--cc=sboyd@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).