From: Thomas Gleixner <tglx@linutronix.de>
To: lakshmi.sowjanya.d@intel.com, jstultz@google.com,
giometti@enneenne.com, corbet@lwn.net,
linux-kernel@vger.kernel.org
Cc: x86@kernel.org, linux-doc@vger.kernel.org,
andriy.shevchenko@linux.intel.com, eddie.dong@intel.com,
christopher.s.hall@intel.com, pandith.n@intel.com,
mallikarjunappa.sangannavar@intel.com,
thejesh.reddy.t.r@intel.com, lakshmi.sowjanya.d@intel.com
Subject: Re: [PATCH v1 2/6] x86/tsc: Convert Time Stamp Counter (TSC) value to Always Running Timer (ART)
Date: Tue, 17 Oct 2023 11:29:10 +0200 [thread overview]
Message-ID: <87wmvl61i1.ffs@tglx> (raw)
In-Reply-To: <20231017052457.25287-3-lakshmi.sowjanya.d@intel.com>
On Tue, Oct 17 2023 at 10:54, lakshmi.sowjanya.d@intel.com wrote:
>
> +/*
> + * 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 ?
> + */
> +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.
> + 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
next prev parent reply other threads:[~2023-10-17 9:29 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-17 5:24 [PATCH v1 0/6] Add support for Intel PPS Generator lakshmi.sowjanya.d
2023-10-17 5:24 ` [PATCH v1 1/6] kernel/time: Add system time to system counter conversion lakshmi.sowjanya.d
2023-10-17 8:42 ` Thomas Gleixner
2023-10-17 5:24 ` [PATCH v1 2/6] x86/tsc: Convert Time Stamp Counter (TSC) value to Always Running Timer (ART) lakshmi.sowjanya.d
2023-10-17 9:29 ` Thomas Gleixner [this message]
2023-10-17 5:24 ` [PATCH v1 3/6] x86/tsc: Check if the current clock source is related to ART(Always Running Timer) lakshmi.sowjanya.d
2023-10-17 11:16 ` Thomas Gleixner
2023-10-17 5:24 ` [PATCH v1 4/6] pps: generators: Add PPS Generator TIO Driver lakshmi.sowjanya.d
2023-10-17 16:27 ` Thomas Gleixner
2023-10-17 22:58 ` Thomas Gleixner
2023-10-20 15:41 ` Peter Hilber
2023-12-01 10:22 ` D, Lakshmi Sowjanya
2023-12-01 11:18 ` Peter Hilber
2023-11-22 8:53 ` D, Lakshmi Sowjanya
2023-10-17 5:24 ` [PATCH v1 5/6] Documentation: driver-api: pps: Add Intel Timed I/O PPS generator lakshmi.sowjanya.d
2023-10-17 5:24 ` [PATCH v1 6/6] ABI: pps: Add ABI documentation for Intel TIO lakshmi.sowjanya.d
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87wmvl61i1.ffs@tglx \
--to=tglx@linutronix.de \
--cc=andriy.shevchenko@linux.intel.com \
--cc=christopher.s.hall@intel.com \
--cc=corbet@lwn.net \
--cc=eddie.dong@intel.com \
--cc=giometti@enneenne.com \
--cc=jstultz@google.com \
--cc=lakshmi.sowjanya.d@intel.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mallikarjunappa.sangannavar@intel.com \
--cc=pandith.n@intel.com \
--cc=thejesh.reddy.t.r@intel.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.