[v1,3/6] x86/tsc: Check if the current clock source is related to ART(Always Running Timer)

Message ID 20231017052457.25287-4-lakshmi.sowjanya.d@intel.com
State New
Headers
Series Add support for Intel PPS Generator |

Commit Message

D, Lakshmi Sowjanya Oct. 17, 2023, 5:24 a.m. UTC
  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

Thomas Gleixner Oct. 17, 2023, 11:16 a.m. UTC | #1
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
  

Patch

diff --git a/arch/x86/include/asm/tsc.h b/arch/x86/include/asm/tsc.h
index f5cff8d4f61e..cdfe34e55cf3 100644
--- a/arch/x86/include/asm/tsc.h
+++ b/arch/x86/include/asm/tsc.h
@@ -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);
diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
index 92b800015d8f..2d6b1b5b5b3e 100644
--- a/arch/x86/kernel/tsc.c
+++ b/arch/x86/kernel/tsc.c
@@ -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().
diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h
index e5eb6699d691..9bf7970b3b2f 100644
--- a/include/linux/timekeeping.h
+++ b/include/linux/timekeeping.h
@@ -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
  */
diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
index ff6a4c7387ee..986089d36ba5 100644
--- a/kernel/time/timekeeping.c
+++ b/kernel/time/timekeeping.c
@@ -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