From: Jeff Layton <jlayton@kernel.org>
To: John Stultz <jstultz@google.com>,
Thomas Gleixner <tglx@linutronix.de>,
Stephen Boyd <sboyd@kernel.org>
Cc: Vadim Fedorenko <vadim.fedorenko@linux.dev>,
linux-kernel@vger.kernel.org, Jeff Layton <jlayton@kernel.org>
Subject: [PATCH v2] timekeeping: don't use seqcount loop in ktime_mono_to_any on 64-bit systems
Date: Tue, 10 Sep 2024 08:55:39 -0400 [thread overview]
Message-ID: <20240910-mgtime-v2-1-e96826ac56f0@kernel.org> (raw)
ktime_mono_to_any only fetches the offset inside the loop. This is a
single word on 64-bit hosts, and seqcount_read_begin implies a full SMP
barrier.
When BITS_PER_LONG == 64, just do a simple ktime_add instead as there
is no possibility of getting a torn offset value.
Cc: Vadim Fedorenko <vadim.fedorenko@linux.dev>
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
Thanks for the review so far, Thomas! Hopefully this looks better.
Disregard my earlier question about making this a static inline too.
That would require making offsets[] a global symbol, which I don't think
we want to do.
---
Changes in v2:
- drop the READ_ONCE
- clean up changelog
- Link to v1: https://lore.kernel.org/r/20240910-mgtime-v1-1-35fb64bd0af5@kernel.org
---
kernel/time/timekeeping.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 3f524d43d685..a3872f087fbc 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -946,6 +946,14 @@ EXPORT_SYMBOL_GPL(ktime_get_coarse_with_offset_and_floor);
* @tmono: time to convert.
* @offs: which offset to use
*/
+#if BITS_PER_LONG == 64
+ktime_t ktime_mono_to_any(ktime_t tmono, enum tk_offsets offs)
+{
+ ktime_t *offset = offsets[offs];
+
+ return ktime_add(tmono, *offset);
+}
+#else /* BITS_PER_LONG == 64 */
ktime_t ktime_mono_to_any(ktime_t tmono, enum tk_offsets offs)
{
ktime_t *offset = offsets[offs];
@@ -959,6 +967,7 @@ ktime_t ktime_mono_to_any(ktime_t tmono, enum tk_offsets offs)
return tconv;
}
+#endif /* BITS_PER_LONG == 64 */
EXPORT_SYMBOL_GPL(ktime_mono_to_any);
/**
---
base-commit: dc8f9bbf6ceb160c7fc5e1a03c5a9318cb61bbd7
change-id: 20240910-mgtime-731eace7cca5
Best regards,
--
Jeff Layton <jlayton@kernel.org>
next reply other threads:[~2024-09-10 12:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-10 12:55 Jeff Layton [this message]
2024-09-10 17:46 ` [PATCH v2] timekeeping: don't use seqcount loop in ktime_mono_to_any on 64-bit systems Thomas Gleixner
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=20240910-mgtime-v2-1-e96826ac56f0@kernel.org \
--to=jlayton@kernel.org \
--cc=jstultz@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=sboyd@kernel.org \
--cc=tglx@linutronix.de \
--cc=vadim.fedorenko@linux.dev \
/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