On Tue, Oct 17 2023 at 10:54, lakshmi.sowjanya.d@intel.com wrote:
quoted hunk ↗ jump to hunk
+/*
+ * Converts input TSC to the corresponding ART value using conversion
+ * factors discovered by detect_art().
+ *
+ * Return: 0 on success, -errno on failure.
bool indicating success / fail ?
quoted hunk ↗ jump to hunk
+ */
+int convert_tsc_to_art(const struct system_counterval_t *system_counter,
+ u64 *art)
+{
+ u64 tmp, res, rem;
+ /* ART = TSC * tsc_to_art_denominator / tsc_to_art_numerator */
+ struct u32_fract tsc_to_art = {
+ .numerator = art_to_tsc_denominator,
+ .denominator = art_to_tsc_numerator,
+ };
The purpose of this struct is to obfuscate the code, right?
The struct would make sense if a pointer would be handed to some other
function.
quoted hunk ↗ jump to hunk
+ if (system_counter->cs != art_related_clocksource)
+ return -EINVAL;
+
+ res = system_counter->cycles - art_to_tsc_offset;
+ rem = do_div(res, tsc_to_art.denominator);
+
+ tmp = rem * tsc_to_art.numerator;
+ do_div(tmp, tsc_to_art.denominator);
+ *art = res * tsc_to_art.numerator + tmp;
Yet another copy of the math in convert_art_to_tsc() and in
convert_art_ns_to_tsc(). Seriously?
Can we please have _one_ helper function which takes value, nominator,
denominator as arguments and clean up the copy&pasta instead of adding
more?
Thanks,
tglx