[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220410214951.55294-2-Jason@zx2c4.com>
Date: Sun, 10 Apr 2022 23:49:41 +0200
From: "Jason A. Donenfeld" <Jason@...c4.com>
To: linux-kernel@...r.kernel.org, linux-crypto@...r.kernel.org,
tglx@...utronix.de, arnd@...db.de
Cc: "Jason A. Donenfeld" <Jason@...c4.com>,
Theodore Ts'o <tytso@....edu>,
Dominik Brodowski <linux@...inikbrodowski.net>,
Russell King <linux@...linux.org.uk>,
Catalin Marinas <catalin.marinas@....com>,
Will Deacon <will@...nel.org>,
Geert Uytterhoeven <geert@...ux-m68k.org>,
Thomas Bogendoerfer <tsbogend@...ha.franken.de>,
Paul Walmsley <paul.walmsley@...ive.com>,
Palmer Dabbelt <palmer@...belt.com>,
Albert Ou <aou@...s.berkeley.edu>,
"David S . Miller" <davem@...emloft.net>,
Richard Weinberger <richard@....at>,
Anton Ivanov <anton.ivanov@...bridgegreys.com>,
Johannes Berg <johannes@...solutions.net>,
Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
Dave Hansen <dave.hansen@...ux.intel.com>,
"H . Peter Anvin" <hpa@...or.com>, Chris Zankel <chris@...kel.net>,
Max Filippov <jcmvbkbc@...il.com>,
John Stultz <john.stultz@...aro.org>,
Stephen Boyd <sboyd@...nel.org>,
Dinh Nguyen <dinguyen@...nel.org>,
linux-arm-kernel@...ts.infradead.org,
linux-m68k@...ts.linux-m68k.org, linux-mips@...r.kernel.org,
linux-riscv@...ts.infradead.org, sparclinux@...r.kernel.org,
linux-um@...ts.infradead.org, x86@...nel.org,
linux-xtensa@...ux-xtensa.org
Subject: [PATCH v2 01/11] timekeeping: add accessor for raw clock
This provides access to whichever time source has the highest frequency,
which is useful for gathering entropy on platforms without available
cycle counters. It's not necessarily as good as being able to quickly
access a cycle counter that the CPU has, but it's still something, even
when it falls back to being jiffies-based.
It's defined in linux/timex.h rather than linux/timekeeping.h, because
the latter cannot be included easily from asm/ headers, and generally
shouldn't be used outside of this rather narrow purpose. It's a ktime
function, but it's not the usual ktime API.
Suggested-by: Thomas Gleixner <tglx@...utronix.de>
Cc: Arnd Bergmann <arnd@...db.de>
Cc: Theodore Ts'o <tytso@....edu>
Signed-off-by: Jason A. Donenfeld <Jason@...c4.com>
---
include/linux/timex.h | 2 ++
kernel/time/timekeeping.c | 8 ++++++++
2 files changed, 10 insertions(+)
diff --git a/include/linux/timex.h b/include/linux/timex.h
index 5745c90c8800..56502b338287 100644
--- a/include/linux/timex.h
+++ b/include/linux/timex.h
@@ -62,6 +62,8 @@
#include <linux/types.h>
#include <linux/param.h>
+extern u64 ktime_read_raw_clock(void);
+
#include <asm/timex.h>
#ifndef random_get_entropy
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index dcdcb85121e4..0d04d2e8b94b 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -939,6 +939,14 @@ ktime_t ktime_get_raw(void)
}
EXPORT_SYMBOL_GPL(ktime_get_raw);
+/**
+ * ktime_read_raw_clock - Returns the raw clock source value
+ */
+u64 ktime_read_raw_clock(void)
+{
+ return tk_clock_read(&tk_core.timekeeper.tkr_mono);
+}
+
/**
* ktime_get_ts64 - get the monotonic clock in timespec64 format
* @ts: pointer to timespec variable
--
2.35.1
Powered by blists - more mailing lists