public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH RFC] timekeeping: don't use seqcount loop in ktime_mono_to_any on 64-bit arch
@ 2024-09-10 11:17 Jeff Layton
  2024-09-10 11:58 ` Thomas Gleixner
  0 siblings, 1 reply; 4+ messages in thread
From: Jeff Layton @ 2024-09-10 11:17 UTC (permalink / raw)
  To: John Stultz, Thomas Gleixner, Stephen Boyd
  Cc: Vadim Fedorenko, linux-kernel, Jeff Layton

ktime_mono_to_any only fetches the offset inside the loop. This is a
single word on 64-bit arch, and seqcount_read_begin implies a full SMP
barrier. While we do want to use the latest offset value available, a
full seqcount loop is overkill on 64-bit, where there is no possibility
of torn reads. Just do a READ_ONCE for that and don't bother with the
seqcount.

Cc: Vadim Fedorenko <vadim.fedorenko@linux.dev>
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
 kernel/time/timekeeping.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index 5391e4167d60..0693f44e064e 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -924,6 +924,15 @@ EXPORT_SYMBOL_GPL(ktime_get_coarse_with_offset);
  * @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, READ_ONCE(*offset));
+}
+EXPORT_SYMBOL_GPL(ktime_mono_to_any);
+#else /* BITS_PER_LONG == 64 */
 ktime_t ktime_mono_to_any(ktime_t tmono, enum tk_offsets offs)
 {
 	ktime_t *offset = offsets[offs];
@@ -938,6 +947,7 @@ ktime_t ktime_mono_to_any(ktime_t tmono, enum tk_offsets offs)
 	return tconv;
 }
 EXPORT_SYMBOL_GPL(ktime_mono_to_any);
+#endif /* BITS_PER_LONG == 64 */
 
 /**
  * ktime_get_raw - Returns the raw monotonic time in ktime_t format

---
base-commit: 79d4f9eb4a3c4c68736d500025423e96e212b13d
change-id: 20240910-mgtime-731eace7cca5

Best regards,
-- 
Jeff Layton <jlayton@kernel.org>


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-09-10 15:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-10 11:17 [PATCH RFC] timekeeping: don't use seqcount loop in ktime_mono_to_any on 64-bit arch Jeff Layton
2024-09-10 11:58 ` Thomas Gleixner
2024-09-10 12:32   ` Jeff Layton
2024-09-10 15:39     ` Thomas Gleixner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox