[v1,3/6] x86/tsc: Check if the current clock source is related to ART(Always Running Timer)
Commit Message
From: Lakshmi Sowjanya D <lakshmi.sowjanya.d@intel.com>
Add interface 'is_current_clocksource_art_related()' in tsc.c to check
if the current clock source is ART related.
Add helper function 'is_current_clocksource(clock)' in timekeeping.c to
check if the provided clock matches the current clock source.
Co-developed-by: Christopher Hall <christopher.s.hall@intel.com>
Signed-off-by: Christopher Hall <christopher.s.hall@intel.com>
Signed-off-by: Lakshmi Sowjanya D <lakshmi.sowjanya.d@intel.com>
---
arch/x86/include/asm/tsc.h | 1 +
arch/x86/kernel/tsc.c | 12 ++++++++++++
include/linux/timekeeping.h | 2 ++
kernel/time/timekeeping.c | 15 +++++++++++++++
4 files changed, 30 insertions(+)
Comments
On Tue, Oct 17 2023 at 10:54, lakshmi.sowjanya.d@intel.com wrote:
> From: Lakshmi Sowjanya D <lakshmi.sowjanya.d@intel.com>
>
> Add interface 'is_current_clocksource_art_related()' in tsc.c to check
> if the current clock source is ART related.
> Add helper function 'is_current_clocksource(clock)' in timekeeping.c to
> check if the provided clock matches the current clock source.
Again. That's the WHAT not the WHY.
Also the Subject suggests that a check is added at some random place,
but that's not what the patch does.
> +/*
> + * Checks if the current clocksource is ART related clocksource
> + *
> + * Return: 1 on success, 0 on failure.
> + */
> +bool is_current_clocksource_art_related(void)
> +{
> + return is_current_clocksource(art_related_clocksource);
> +}
> +EXPORT_SYMBOL_GPL(is_current_clocksource_art_related);
> +bool is_current_clocksource(struct clocksource *clock)
> +{
> + struct tk_read_base *tkr = &tk_core.timekeeper.tkr_mono;
> + return clock == READ_ONCE(tkr->clock);
> +}
> +EXPORT_SYMBOL_GPL(is_current_clocksource);
Aside of the horrible function names (new global functions want
$NAMESPACE_* convention) this really starts to become hilarious.
Two exported helpers which are completely unexplained. That smells badly
of broken data representations.
But let me see what this is used for.
Thanks,
tglx
@@ -32,6 +32,7 @@ static inline cycles_t get_cycles(void)
extern int convert_tsc_to_art(const struct system_counterval_t *tsc, u64 *art);
extern struct system_counterval_t convert_art_to_tsc(u64 art);
extern struct system_counterval_t convert_art_ns_to_tsc(u64 art_ns);
+extern bool is_current_clocksource_art_related(void);
extern void tsc_early_init(void);
extern void tsc_init(void);
@@ -16,6 +16,7 @@
#include <linux/timex.h>
#include <linux/static_key.h>
#include <linux/static_call.h>
+#include <linux/timekeeping.h>
#include <asm/hpet.h>
#include <asm/timer.h>
@@ -1295,6 +1296,17 @@ int unsynchronized_tsc(void)
return 0;
}
+/*
+ * Checks if the current clocksource is ART related clocksource
+ *
+ * Return: 1 on success, 0 on failure.
+ */
+bool is_current_clocksource_art_related(void)
+{
+ return is_current_clocksource(art_related_clocksource);
+}
+EXPORT_SYMBOL_GPL(is_current_clocksource_art_related);
+
/*
* Converts input TSC to the corresponding ART value using conversion
* factors discovered by detect_art().
@@ -292,6 +292,8 @@ extern int get_device_system_crosststamp(
extern int ktime_convert_real_to_system_counter(ktime_t sys_realtime,
struct system_counterval_t *ret);
+extern bool is_current_clocksource(struct clocksource *clock);
+
/*
* Simultaneously snapshot realtime and monotonic raw clocks
*/
@@ -1357,6 +1357,21 @@ int ktime_convert_real_to_system_counter(ktime_t sys_realtime,
}
EXPORT_SYMBOL_GPL(ktime_convert_real_to_system_counter);
+/**
+ * is_current_clocksource - Checks if the supplied clock source matches with the
+ * MONOTONIC clock.
+ *
+ * @clock: pointer to the clocksource to be checked
+ *
+ * Return: true if the clocks match, false otherwise.
+ */
+bool is_current_clocksource(struct clocksource *clock)
+{
+ struct tk_read_base *tkr = &tk_core.timekeeper.tkr_mono;
+ return clock == READ_ONCE(tkr->clock);
+}
+EXPORT_SYMBOL_GPL(is_current_clocksource);
+
/**
* do_settimeofday64 - Sets the time of day.
* @ts: pointer to the timespec64 variable containing the new time