@@ -8,6 +8,8 @@
#include <asm/processor.h>
#include <asm/cpufeature.h>
+struct system_counterval_t;
+
/*
* Standard way to access the cycle counter.
*/
@@ -29,6 +31,7 @@ static inline cycles_t get_cycles(void)
}
extern u64 read_art_time(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);
@@ -1231,22 +1231,43 @@ int unsynchronized_tsc(void)
}
/*
- * Converts the current TSC to the current ART value using conversion
+ * Converts input TSC to the corresponding ART value using conversion
* factors discovered by detect_art()
*/
-u64 read_art_time(void)
+int convert_tsc_to_art(const struct system_counterval_t *system_counter, u64 *art)
{
- u64 tsc, tmp, res, rem;
+ u64 tmp, res, rem;
+
+ if (system_counter->cs != art_related_clocksource)
+ return -EINVAL;
- tsc = read_tsc(NULL) - art_to_tsc_offset;
- rem = do_div(tsc, art_to_tsc_numerator);
+ res = system_counter->cycles - art_to_tsc_offset;
+ rem = do_div(res, art_to_tsc_numerator);
- res = tsc * art_to_tsc_denominator;
+ *art = res * art_to_tsc_denominator;
tmp = rem * art_to_tsc_denominator;
do_div(tmp, art_to_tsc_numerator);
+ *art += tmp;
+
+ return 0;
+}
+EXPORT_SYMBOL(convert_tsc_to_art);
+
+/*
+ * Converts the current TSC to the current ART value using conversion
+ * factors discovered by detect_art()
+ */
+u64 read_art_time(void)
+{
+ struct system_counterval_t tsc;
+ u64 art = 0;
+
+ tsc.cs = art_related_clocksource;
+ tsc.cycles = read_tsc(NULL);
+ convert_tsc_to_art(&tsc, &art);
- return res + tmp;
+ return art;
}
EXPORT_SYMBOL(read_art_time);